Fix #5642 - Report designer - hebe
[Pman.Base] / Pman / Roo.php
index d03b25c..78c897f 100644 (file)
@@ -32,8 +32,8 @@ require_once 'Pman.php';
  * - beforeInsert($request,$roo) - before insert - jerr() will stop insert..
  *
  *  AFTER
- * - onUpdate($old, $request,$roo) - after update // return value ignored
- * - onInsert($request,$roo) - after insert
+ * - onUpdate($old, $request,$roo, $event) - after update // return value ignored
+ * - onInsert($request,$roo, $event) - after insert
  * - onDelete($req, $roo) - after delete
  * - onUpload($roo)
  * 
@@ -51,8 +51,7 @@ class Pman_Roo extends Pman
     
     var $key; // used by update currenly to store primary key.
     
-    var $transObj = false ; // the transaction BEGIN / ROLLBACK / COMMIT Dataobject.
-    
+     
     var $max_limit = 10000;
     
     var $debugEnabled = true; // disable this for public versions of this code.
@@ -74,7 +73,7 @@ class Pman_Roo extends Pman
         return true;
     }
     /**
-     * GET method   Roo/TABLENAME.php
+     * GET method   Roo/TABLENAME
      *
      * Generally for SELECT or Single SELECT
      *
@@ -166,7 +165,6 @@ class Pman_Roo extends Pman
      */
     function get($tab, $opts = Array())
     {
-        
          //  $this->jerr("Not authenticated", array('authFailure' => true));
        //echo '<PRE>';print_R($_GET);
       //DB_DataObject::debuglevel(1);
@@ -283,7 +281,7 @@ class Pman_Roo extends Pman
         $this->sessionState(0);
         $res = $x->find();
         $this->sessionState(1);
-        
+                
         if (false === $res) {
             $this->jerr($x->_lastError->toString());
             
@@ -456,11 +454,18 @@ class Pman_Roo extends Pman
                 if ($cols == '*') {  /// did we get cols sent to us?
                     $cols = array_keys($x);
                 }
+                
+                if(!is_array($cols)) {
+                    $cols = explode(',', $cols);
+                }
                
                 if ($titles !== false) {
                     if ($titles== '*') {
                         $titles= array_keys($x);
                     }
+                    if(!is_array($titles)) {
+                        $titles = explode(',', $titles);
+                    }
                     foreach($cols as $i=>$col) {
                         $se_config['cols'][] = array(
                             'header'=> isset($titles[$i]) ? $titles[$i] : $col,
@@ -496,13 +501,24 @@ class Pman_Roo extends Pman
         foreach($data as $x) {
             //echo "<PRE>"; print_r(array($_REQUEST['csvCols'], $x->toArray())); exit;
             $line = array();
-            if ($titles== '*') {
-                $titles= array_keys($x);
-            }
+            
             if ($cols== '*') {
                 $cols= array_keys($x);
             }
+            
+            if(!is_array($cols)) {
+                $cols = explode(',', $cols);
+            }
+
             if ($titles !== false) {
+                if ($titles== '*') {
+                    $titles= array_keys($x);
+                }
+
+                if(!is_array($titles)) {
+                    $titles = explode(',', $titles);
+                }
+
                 foreach($cols as $i=>$col) {
                     $se_config['cols'][] = array(
                         'header'=> isset($titles[$i]) ? $titles[$i] : $col,
@@ -522,17 +538,15 @@ class Pman_Roo extends Pman
                 $titles = false;
             }
             
-            
-            
             $se->addLine($se_config['workbook'], $x);
         }
+        
         if(!$se){
             $this->jerr('no data found');
         }
+        
         $se->send($fn .'.xls');
         exit;
-    
-        
         
     }
     
@@ -642,7 +656,7 @@ class Pman_Roo extends Pman
         $this->init(); // for pman.
          
         $x = $this->dataObject($tab);
-        
+
         $this->transObj = clone($x);
         
         $this->transObj->query('BEGIN');
@@ -659,20 +673,21 @@ class Pman_Roo extends Pman
             // do we really delete stuff!?!?!?
             return $this->delete($x,$_REQUEST);
         } 
-         
+        
+        
+        
         
         $old = false;
         
         // not sure if this is a good idea here...
-        
+
         if (!empty($_REQUEST['_ids'])) {
             $ids = explode(',',$_REQUEST['_ids']);
             $x->whereAddIn($this->key, $ids, 'int');
             $ar = $x->fetchAll();
             
             foreach($ar as $x) {
-                $this->update($x, $_REQUEST);
-                
+                $this->update($x, $_REQUEST);  
             }
             // all done..
             $this->jok("UPDATED");
@@ -680,7 +695,7 @@ class Pman_Roo extends Pman
             
         }
          
-        if (!empty($_REQUEST[$this->key])) {
+        if (!empty($_REQUEST[$this->key])) { 
             // it's a create..
             if (!$x->get($this->key, $_REQUEST[$this->key]))  {
                 $this->jerr("Invalid request (id does not point to  a record.)");
@@ -691,7 +706,7 @@ class Pman_Roo extends Pman
             if (empty($_POST)) {
                 $this->jerr("No data recieved for inserting");
             }
-            
+
             $this->jok($this->insert($x, $_REQUEST));
             
         }
@@ -846,7 +861,7 @@ class Pman_Roo extends Pman
         } else if (method_exists($x, 'applyFilters')) {
             // always call apply filters even after update/insert...
             // however arguments are not passed.
-            $x->applyFilters(array(), $this->authUser, $this);
+            $x->applyFilters(array('_is_update_request' => true), $this->authUser, $this);
         }
         
         // DB_DataObject::DebugLevel(1);
@@ -934,13 +949,15 @@ class Pman_Roo extends Pman
         }
         
         $res = $x->insert();
+
         if ($res === false) {
             $this->jerr($x->_lastError->toString());
         }
+        $ev = $this->addEvent("ADD", $x);
         if (method_exists($x, 'onInsert')) {
-            $x->onInsert($_REQUEST, $this);
+            $x->onInsert($_REQUEST, $this, $ev);
         }
-        $ev = $this->addEvent("ADD", $x);
+        
         if ($ev) { 
             $ev->audit($x);
         }
@@ -1065,7 +1082,7 @@ class Pman_Roo extends Pman
         //print_r($old);
         
         $cols = $x->tableColumns();
-        //print_r($cols);
+
         if (isset($cols['modified'])) {
             $x->modified = date('Y-m-d H:i:s');
         }
@@ -1099,11 +1116,11 @@ class Pman_Roo extends Pman
         if ($res === false) {
             $this->jerr($x->_lastError->toString());
         }
-        
+        $ev = $this->addEvent("EDIT", $x);
+
         if (method_exists($x, 'onUpdate')) {
-            $x->onUpdate($old, $req, $this);
+            $x->onUpdate($old, $req, $this, $ev);
         }
-        $ev = $this->addEvent("EDIT", $x);
         if ($ev) { 
             $ev->audit($x, $old);
         }
@@ -1122,11 +1139,13 @@ class Pman_Roo extends Pman
      */
     
     function delete($x, $req)
-    {
+    { 
         // do we really delete stuff!?!?!?
         if (empty($req['_delete'])) {
             $this->jerr("Delete Requested with no value");
         }
+        
+        
         // build a list of tables to queriy for dependant data..
         $map = $x->links();
         
@@ -1149,7 +1168,7 @@ class Pman_Roo extends Pman
        // echo '<PRE>';print_r($affects);exit;
        // DB_Dataobject::debugLevel(1);
        
-
+        
         
         
         $bits = array_map(function($v) { return (int)$v; } , explode(',', $req['_delete']));
@@ -1174,6 +1193,7 @@ class Pman_Roo extends Pman
             $match_ar = array();
             foreach($affects as $k=> $true) {
                 $ka = explode('.', $k);
+                
                 $chk = DB_DataObject::factory($ka[0]);
                 if (!is_a($chk,'DB_DataObject') && !is_a($chk,'PDO_DataObject'))  {
                     $this->jerr('Unable to load referenced table, check the links config: ' .$ka[0]);
@@ -1194,11 +1214,12 @@ class Pman_Roo extends Pman
                     continue;
                 }          
             }
-         
+            
+            
             $has_beforeDelete = method_exists($xx, 'beforeDelete');
             // before delte = allows us to trash dependancies if needed..
             $match_total = 0;
-        
+            
             if ( $has_beforeDelete ) {
                 if ($xx->beforeDelete($match_ar, $this) === false) {
                     $errs[] = "Delete failed ({$xx->id})\n".
@@ -1214,7 +1235,7 @@ class Pman_Roo extends Pman
                     if (!is_a($chk,'DB_DataObject') && !is_a($chk,'PDO_DataObject'))  {
                         $this->jerr('Unable to load referenced table, check the links config: ' .$ka[0]);
                     }
-                    $chk->{$ka[1]} =  $xx->{$this->key};                   
+                    $chk->{$ka[1]} =  $xx->{$this->key};
                     $matches = $chk->count();
                     $match_total += $matches;
                     if ($matches) {
@@ -1226,8 +1247,6 @@ class Pman_Roo extends Pman
                 
             }
             
-            //
-
             if (!empty($match_ar)) {
                 $chk = $match_ar[0];
                 $chk->limit(1);
@@ -1385,7 +1404,7 @@ class Pman_Roo extends Pman
         $q_filtered = array();
         
         $keys = $x->keys();
-        // var_dump($keys);exit;
+
         foreach($q as $key=>$val) {
             
             if (in_array($key,$keys) && !is_array($val)) {
@@ -1453,7 +1472,7 @@ class Pman_Roo extends Pman
                 
             }
             
-            
+                
             
             switch($key) {
                     
@@ -1563,34 +1582,8 @@ class Pman_Roo extends Pman
         
     }
     
-     
-    // our handlers to commit / rollback.
-    
       
     
-    function jok($str)
-    {
-        // note that commit will only work if an insert/update was done,
-        // so some stored proc calls may not have flagged this.
-        
-        if ($this->transObj ) {
-            $this->transObj->query( connection_aborted() ? 'ROLLBACK' :  'COMMIT');
-        }
-        return parent::jok($str);
-    }
-    
-    
-    function jerr($str, $errors=array(), $content_type = false)
-    {
-        // standard error reporting..
-        if ($this->transObj) {
-            $this->transObj->query('ROLLBACK');
-        }
-        return parent::jerr($str,$errors,$content_type);
-    
-    }
-    
-