Pman/Roo.php
[Pman.Base] / Pman / Roo.php
index f74a02d..7bd95bf 100644 (file)
@@ -73,7 +73,7 @@ class Pman_Roo extends Pman
     function get($tab)
     {
          //  $this->jerr("Not authenticated", array('authFailure' => true));
-        // DB_DataObject::debuglevel(1);
+       //echo '<PRE>';print_R($_GET);  DB_DataObject::debuglevel(1);
         
         $this->init(); // from pnan.
         
@@ -148,7 +148,7 @@ class Pman_Roo extends Pman
             $this->jok("Updated");
             
         }
-       DB_DataObject::debugLevel(1);
+       //DB_DataObject::debugLevel(1);
         if (method_exists($x, 'checkPerm') && !$x->checkPerm('S', $this->authUser))  {
             $this->jerr("PERMISSION DENIED");
         }
@@ -157,15 +157,14 @@ class Pman_Roo extends Pman
         $this->loadMap($x, $_columns, empty($_REQUEST['_distinct']) ? false:  $_REQUEST['_distinct']);
         
         $this->setFilters($x,$_REQUEST);
-        
-         
-        
+      
+         //print_r($x);
         // build join if req.
-         
+          //DB_DataObject::debugLevel(1);
         $total = $x->count($this->countWhat);
         // sorting..
-      //   DB_DataObject::debugLevel(1);
-        
+      //   
+        //var_dump($total);exit;
         $this->applySort($x);
         
         
@@ -260,12 +259,13 @@ class Pman_Roo extends Pman
      * @arg   DB_DataObject $x
      * 
      */
-    function applySort($x)
+    function applySort($x, $sort = '', $dir ='')
     {
         
        // Db_DataObject::debugLevel(1);
-        $sort = empty($_REQUEST['sort']) ? '' : $_REQUEST['sort'];
-        $dir = (empty($_REQUEST['dir']) || strtoupper($_REQUEST['dir']) == 'ASC' ? 'ASC' : 'DESC');
+        $sort = empty($_REQUEST['sort']) ? $sort : $_REQUEST['sort'];
+        $dir = empty($_REQUEST['dir']) ? $dir : $_REQUEST['dir'];
+        $dir = $dir == 'ASC' ? 'ASC' : 'DESC';
         
         
         
@@ -566,7 +566,21 @@ class Pman_Roo extends Pman
         while ($x->fetch()) {
             $xx = clone($x);
             
+           
+            // perms first.
+            
+            if (method_exists($x, 'checkPerm') && !$x->checkPerm('D', $this->authUser))  {
+                $this->jerr("PERMISSION DENIED");
+            }
+            
+            // before delte = allows us to trash dependancies if needed..
+            if ( method_exists($xx, 'beforeDelete') && ($xx->beforeDelete() === false)) {
+                $errs[] = "Delete failed ({$xx->id})\n". (isset($xx->err) ? $xx->err : '');
+                continue;
+            }
             
+            // now check deps.
+             
             foreach($affects as $k=> $true) {
                 $ka = explode('.', $k);
                 $chk = DB_DataObject::factory($ka[0]);
@@ -579,17 +593,8 @@ class Pman_Roo extends Pman
                 }
             }
             
-            
-            
-            if (method_exists($x, 'checkPerm') && !$x->checkPerm('D', $this->authUser))  {
-                $this->jerr("PERMISSION DENIED");
-            }
-            
             $this->addEvent("DELETE", $x, $x->toEventString());
-            if ( method_exists($xx, 'beforeDelete') && ($xx->beforeDelete() === false)) {
-                $errs[] = "Delete failed ({$xx->id})\n". (isset($xx->err) ? $xx->err : '');
-                continue;
-            }
+            
             $xx->delete();
         }
         if ($errs) {
@@ -653,7 +658,7 @@ class Pman_Roo extends Pman
         $xx = array_keys($tabdef);
         $do->selectAdd(); // we need thsi as normally it's only cleared by an empty selectAs call.
         
-        $selectAs = array(array(  $xx , '%s'));
+        $selectAs = array(array(  $xx , '%s', false));
         $this->countWhat = false;
         $has_distinct = false;
         if ($filter || $distinct) {
@@ -671,7 +676,7 @@ class Pman_Roo extends Pman
             }
             
             
-            $selectAs = empty($cols) ?  array() : array(array(  $cols , '%s')) ;
+            $selectAs = empty($cols) ?  array() : array(array(  $cols , '%s', false)) ;
             
             
             
@@ -744,12 +749,12 @@ class Pman_Roo extends Pman
         }
         
         if ($has_distinct) {
-            $this->selectAdd($has_distinct);
+            $do->selectAdd($has_distinct);
         }
         //DB_DataObject::debugLevel(1);
         // we do select as after everything else as we need to plop distinct at the beginning??
         /// well I assume..
-       // echo '<PRE>';print_r($selectAs );exit;
+       // echo '<PRE>';print_r($this->colsJname);exit;
         foreach($selectAs as $ar) {
             $do->selectAs($ar[0], $ar[1], $ar[2]);
         }
@@ -841,9 +846,9 @@ class Pman_Roo extends Pman
                     
                     
                     $x->whereAddIn(
-                        isset($this->colsJoinName[$key]) ? 
-                            $this->colsJoinName[$key] :
-                            $x->tableName(). '.'.$key,
+                        isset($this->colsJname[$key]) ? 
+                            $this->colsJname[$key] :
+                            ($x->tableName(). '.'.$key),
                         $ar, $quote ? 'string' : 'int');
                 }
                 
@@ -857,8 +862,8 @@ class Pman_Roo extends Pman
                 $key  = substr($key, 1) ;
                 
                 $x->whereAdd(   (
-                        isset($this->colsJoinName[$key]) ? 
-                            $this->colsJoinName[$key] :
+                        isset($this->colsJname[$key]) ? 
+                            $this->colsJname[$key] :
                             $x->tableName(). '.'.$key ) . ' != ' .
                     (is_numeric($val) ? $val : "'".  $x->escape($val) . "'")
                 );