$this->selectAs($jt, 'person_id_%s', 'join_person_id_id');
+ if (method_exists($jt,'nameColumn')) {
+ $this->selectAdd("join_person_id_id.{$jt->nameColumn()} as person_id_name");
+ }
+
+
} else {
- $jt = DB_DataObject::factory('Person');
+ $person = 'Person';
+ $cfg = HTML_FlexyFramework::get()->Pman;
+ if (!empty($cfg['authTable'])) {
+ $person =$cfg['authTable'];
+ }
+
+ $jt = DB_DataObject::factory($person);
$this->whereAdd("
person_table = '{$jt->tableName()}'
OR
$this->selectAs($x, 'on_id_%s', "join_on_id_{$jtn}");
}
}
-
-
-
+
}
//$this->autoJoinExtra();
}
+ if(!empty($q['query']['action'])) {
+ $act = $this->escape($q['query']['action']);
+ $this->whereAdd("Events.action LIKE '%{$act}%'");
+ }
+ if(!empty($q['query']['on_table'])) {
+ $tnb = $this->escape($q['query']['on_table']);
+ $this->whereAdd("Events.on_table LIKE '%{$tnb}%'");
+ }
-
}
}
$this->person_name = $au && !empty($au->name) ? $au->name : '';
- $this->person_id = $au ? $au->id : -1;
+ if (isset($au->id) && empty($au->id)) {
+ // not authenticated - and a standard id based object
+ $this->person_id = 0;
+ } else {
+ $this->person_id = $au ? (!empty($au->id) ? $au->id : $au->pid()) : -1;
+ }
$this->person_table = $au ? $au->tableName() : '';
$this->ipaddr = isset($_SERVER["REMOTE_ADDR"]) ? $_SERVER["REMOTE_ADDR"] : 'cli';
+ if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
+ $this->ipaddr = $_SERVER['HTTP_X_FORWARDED_FOR'];
+ }
+
$this->action = $act;
$this->on_table = $obj ? $obj->tableName() : '';
$pk = $obj ? $obj->keys() : false;
}
-
+ function beforeInsert($request,$roo)
+ {
+ if(empty($this->event_when)){
+ $this->event_when = $this->sqlValue("NOW()");
+ }
+
+ if(empty($this->person_id)){
+ $this->person_id = $roo->authUser->id;
+ $this->person_name = $roo->authUser->name;
+ $this->person_table = $roo->authUser->tableName();
+ }
+
+ if(empty($this->ipaddr)){
+ $this->ipaddr = isset($_SERVER["REMOTE_ADDR"]) ? $_SERVER["REMOTE_ADDR"] : 'cli';
+ if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
+ $this->ipaddr = $_SERVER['HTTP_X_FORWARDED_FOR'];
+ }
+ }
+ }
function onInsert($request,$roo)
{
// Remove all the password from logs...
$p = empty($_POST) ? array() : $_POST;
- foreach(array('passwd', 'password', 'passwd2', 'password2') as $rm) {
+ foreach(array('passwd', 'password','passwd1', 'passwd2','password1', 'password2') as $rm) {
if (isset($p[$rm])) {
- $p['passwd'] = '******';
+ $p[$rm] = '******';
}
}
+
+
$i=0;
$files = array();
- require_once 'File/MimeType.php';
-
- $mt = new File_MimeType();
-//var_dump($y->toExt('application/x-pdf'));
-
+
+ $i = 0;
foreach ($_FILES as $k=>$f){
+ // does not handle any other file[] arrary very well..
if (empty($f['tmp_name']) || !file_exists($f['tmp_name'])) {
continue;
}
$i++;
$files[$k] = $f;
- $name = basename($f['name']);
- if (empty($name)) {
- $name = 'unknown.txt';
- }
- $files[$k]['tmp_name'] = $this->id . '.$name;
- $nf = $ff->Pman['event_log_dir']. '/'. $this->id . ".file_$i.jpg";
+
+ $files[$k]['tmp_name'] = $this->id . '-'. $i;
+ $nf = $ff->Pman['event_log_dir']. '/'. $user. date('/Y/m/d/'). $files[$k]['tmp_name'];
if (!copy($f['tmp_name'], $nf)) {
print_r("failed to copy {$f['tmp_name']}...\n");
}
file_put_contents($file, json_encode(array(
'REQUEST_URI' => empty($_SERVER['REQUEST_URI']) ? 'cli' : $_SERVER['REQUEST_URI'],
+ 'HTTP_USER_AGENT' => empty($_SERVER['HTTP_USER_AGENT']) ? '' : $_SERVER['HTTP_USER_AGENT'],
'GET' => empty($_GET) ? array() : $_GET,
'POST' =>$p,
'FILES' => $files,
)));
+
}
+ function toRooSingleArray($au, $q)
+ {
+ $ret = $this->toArray();
+
+ if(empty($q['_retrieve_source'])){
+ return $ret;
+ }
+
+ $file = $this->retrieveEventLog();
+
+ if(!$file){
+ return "No records?!";
+ }
+
+ $source = json_decode(file_get_contents($file));
+
+ return $source;
+ }
+ function retrieveEventLog()
+ {
+ $ff = HTML_FlexyFramework::get();
+ if (empty($ff->Pman['event_log_dir'])) {
+ return false;
+ }
+
+ if (function_exists('posix_getpwuid')) {
+ $uinfo = posix_getpwuid( posix_getuid () );
+
+ $user = $uinfo['name'];
+ } else {
+ $user = getenv('USERNAME'); // windows.
+ }
+
+ $date = date('/Y/m/d/', strtotime($this->event_when));
+
+ $file = $ff->Pman['event_log_dir']. '/'. $user. $date. $this->id . ".json";
+ if (!file_exists(dirname($file))) {
+ return false;
+ }
+
+ return $file;
+ }
}