A place for users and developers of the Xataface to discuss and receive support.
by xzq » Tue Apr 07, 2009 4:27 pm
Hello,
could not find it and my brain is going to explode. Sorry if this has been answered. Maybe someone can help.
How can i write the username or user id of the user who is logged into xataface into the table. For instance when a new record is added i would like to save who added it.
thanks,
Christian
-
xzq
-
- Posts: 1
- Joined: Tue Apr 07, 2009 4:24 pm
by Martin Pruss » Wed Apr 08, 2009 12:17 am
hi xzq
code not tested:
- Code: Select all
class tables_yourtable{
function afterSave(&$record){
$app =& Dataface_Application::getInstance(); $user =& $auth->getLoggedInUser(); $id = $record->val('id'); $res = mysql_query("UPDATE your_usertable SET id = '" . $id . "' WHERE user = '" . $user . "' "", $app->db()); } }
to be placed in the tables delegate class..
if it does not work search for trigger or update in the forum
cheers
martin
-
Martin Pruss
-
- Posts: 61
- Joined: Tue Oct 23, 2007 2:22 pm
- Location: Berlin
by fantomasdm » Thu Apr 09, 2009 11:51 pm
I write this class for log in text file, for use it you have to extend table class,
- Code: Select all
<? class audit { var $handle; static function logArray(&$arr) { $ret=""; foreach ( $arr as $val) { $ret=$ret.$val." "; } return $ret; } static function auditing($tipo,&$record,&$io) { $auth =& Dataface_AuthenticationTool::getInstance(); $user =& $auth->getLoggedInUser(); //e:\Programmi\OCS Inventory NG\xampp\htdocs\GestFarm $handle = fopen("logGenerale.txt", "a") or die ("errore di creazione file log"); //chi fwrite($handle, "Nome:".$user->val('UserName')." Ruolo:".$user->val('Role')." Host:".$_SERVER['REMOTE_ADDR']." ".str_replace ('_',':',get_class($io))." Date:" ); //quando $today = getdate(); fwrite($handle,$today['mday'].'/'.$today['mon'].'/'.$today['year'].' '.$today['hours'].':'.$today['minutes'].':'.$today['seconds']."\n"); //Cosa fwrite($handle,"$tipo:\n"); foreach ( array_keys($record->getValues()) as $col) { fwrite($handle, sprintf("%-12s\t", $col)."\t"); } fwrite($handle,"\n"); foreach ( array_values($record->getValues()) as $val) { if (is_array($val)) fwrite($handle, sprintf("%-12s\t", self::logArray($val)."\t")); else fwrite($handle, sprintf("%-12s\t", $val)."\t"); } fwrite($handle,"\n"); /* if (fwrite($handle, print_r ($record->getValues(),true)) ===FALSE) { die ("Non si riesce a scrivere nel file di log!!"); } */ fclose($handle); } //Auditing Function function afterSave (&$record) { self::auditing("OnSave",$record,$this); } function afterDelete (&$record) { self::auditing("OnDelete",$record,$this); } function afterAddRelatedRecord (&$record) { self::auditing("OnAddRelatedRecord",$record,$this); } function manualLog($tipo) { $auth =& Dataface_AuthenticationTool::getInstance(); $user =& $auth->getLoggedInUser(); //e:\Programmi\OCS Inventory NG\xampp\htdocs\GestFarm $this->handle = fopen("logGenerale.txt", "a") or die ("errore di creazione file log"); //chi fwrite($this->handle, "Nome:".$user->val('UserName')." Ruolo:".$user->val('Role')." Host:".$_SERVER['REMOTE_ADDR']."=>".$tipo." Date:"); //quando $today = getdate(); fwrite($this->handle,$today['mday'].'/'.$today['mon'].'/'.$today['year'].' '.$today['hours'].':'.$today['minutes'].':'.$today['seconds']."\n"); //Cosa fwrite($this->handle,"$tipo:\n"); } function writeLog($obj) { fwrite($this->handle,$obj); } function writeLogDate() { $today = getdate(); fwrite($this->handle,$today['mday'].'/'.$today['mon'].'/'.$today['year'].' '.$today['hours'].':'.$today['minutes'].':'.$today['seconds']); } function closeLog() { fclose($this->handle); } }
class GioDebug { var $handle; function __construct() { $this->handle = fopen("debug.txt", "a") or die ("errore di creazione file debug.txt"); } function __destruct() { fclose($this->handle); } function pwrite($obj) { fwrite($this->handle,$obj); }
function pwrite_r($obj) { fwrite($this->handle,print_r($obj,true)); } //Static function static function write($obj) { $handle = fopen("debug.txt", "a") or die ("errore di creazione file debug.txt"); fwrite($handle,$obj); fclose($handle); }
static function write_r($obj) { $handle = fopen("debug.txt", "a") or die ("errore di creazione file debug.txt"); fwrite($handle,print_r($obj,true)); fclose($handle); } } ?>
Sorry for my english!!
-
fantomasdm
-
- Posts: 114
- Joined: Thu Mar 13, 2008 2:35 pm
Return to Xataface Users
Who is online
Users browsing this forum: No registered users and 14 guests
|