DataObjects/Core_notify.php
[Pman.Core] / DataObjects / Events.php
index 00b247b..05b5f67 100644 (file)
@@ -35,8 +35,28 @@ class Pman_Core_DataObjects_Events extends DB_DataObject
     //  ------------ROO HOOKS------------------------------------
     function applyFilters($q, $au ,$roo)
     {
-     
         $tn = $this->tableName();
+        // if not empty on_table
+        if(!empty($q['person_table'])){
+            $jt = DB_DataObject::factory($q['person_table']);
+        
+            $this->_join = "LEFT JOIN {$jt->tableName()} AS join_person_id_id ON (join_person_id_id.id=Events.person_id)";
+            $this->selectAdd();
+            $this->selectAs();
+            
+            $this->selectAs($jt, 'person_id_%s', 'join_person_id_id');
+        
+        } else {
+            $jt = DB_DataObject::factory('Person');
+            $this->whereAdd("
+                    person_table  = '{$jt->tableName()}'
+                    OR
+                    person_table = ''
+                    OR person_table IS NULL"
+            ); // default to  our standard.. - unless otherwise requested..
+        }
+        
+        
         if (!empty($q['query']['from'])) {
             $dt = date('Y-m-d' , strtotime($q['query']['from']));
             $this->whereAdd(" {$tn}.event_when >=  '$dt' ");
@@ -75,27 +95,7 @@ class Pman_Core_DataObjects_Events extends DB_DataObject
             $this->whereAdd("$tn.on_table = ''");
         }
         
-        // if not empty on_table
-        if(!empty($q['person_table'])){
-            $jt = DB_DataObject::factory($q['person_table']);
-        
-            //$jt = DB_DataObjec factory person_ontable
-            
-            $this->_join = "LEFT JOIN {$jt->tableName()} AS join_person_id_id ON (join_person_id_id.id=Events.person_id)";
-            $item = DB_DataObject::factory('')
-            $this->_join .= '
-                LEFT JOIN
-                    crm_action as join_crm_action_updated
-                ON
-                    join_crm_action_updated.id = join_person_id_id.crm_updated_action_id
-            ';
-            //$item = DB_DataObject::Factory('crm_action');
-            $this->selectAs($jt, 'join_person_id_id_%s', 'join_crm_action_updated');
-
-            //$this->person_table = $q['person_table'];
-            // $this->_join
         
-        }
         
         if (isset($q['query']['person_sum'])) {
             //DB_DataObject::debugLevel(1);
@@ -228,66 +228,7 @@ class Pman_Core_DataObjects_Events extends DB_DataObject
         
             
     }
-     
-//    function autoJoinExtra()
-//    {
-//        //$ret = parent::autoJoin();
-//        // DB_DataObject::debugLevel(1);
-//        
-//        // now try and magically join person_table to the right table..
-//        return;
-//        // this does not work on postgres.. 
-//        $tn = $this->tableName();
-//        $pt = DB_DataObject::Factory($this->tableName());
-//        $pt->selectAdD();
-//        $pt->selectAdD('distinct(person_table) as person_table');
-//        $pt->whereAdd('person_table IS NOT NULL AND LENGTH(person_table) > 0');
-//        $tbls = $pt->fetchAll('person_table');
-//        $pers = DB_DataObject::Factory('Person');
-//        $ptbl = $pers->tableName();
-//        if (!in_array($ptbl,$tbls)) {
-//            $tbls[] = $ptbl;
-//            
-//        }
-//        foreach($tbls as $tbl) {
-//            
-//            // find all the columns from the joined table..
-//            $st = DB_DataObject::Factory($tbl);
-//            $tcols = array_keys($st->table());
-//            
-//            $cond = "{$tn}.person_table = '{$tbl}'";
-//            if ($tbl == $ptbl) {
-//                $cond = "( $cond OR {$tn}.person_table  = '')";
-//            }
-//            
-//            foreach($tcols as $col) {
-//                if ($col == 'passwd') {
-//                    continue;
-//                }
-//                $cols[$col]  = isset($cols[$col] ) ? $cols[$col]  : array();
-//                $cols[$col][] = "WHEN $cond  THEN join_person_table_{$tbl}.{$col}";
-//            }
-//            // id's are hard coded...
-//            
-//            $this->_join .= "
-//                LEFT JOIN {$tbl} AS  join_person_table_{$tbl}
-//                    ON {$tn}.person_id = join_person_table_{$tbl}.id
-//                        AND $cond
-//            ";
-//        }
-//        foreach($cols as $col=>$whens) {
-//            
-//            $this->selectAdd("
-//                    CASE
-//                        ". implode("\n", $whens) ." 
-//                        ELSE ''
-//                    END
-//                    as person_table_{$col}"
-//            );
-//        }
-//        //return $ret;
-//         
-//    }
+      
     
     
     /**
@@ -342,6 +283,10 @@ class Pman_Core_DataObjects_Events extends DB_DataObject
         $this->person_id = $au ? $au->id : -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;
@@ -442,21 +387,28 @@ class Pman_Core_DataObjects_Events extends DB_DataObject
         
         // 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();
+         
+        $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;
-            $files[$k]['tmp_name'] = $this->id . '.file_'. $i.'.jpg';
-            $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");
             }
@@ -464,11 +416,13 @@ class Pman_Core_DataObjects_Events extends DB_DataObject
         
         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,
         )));
         
+        
     }