Pman/Images.php
[Pman.Base] / Pman / Roo.php
index e2923df..7597356 100644 (file)
@@ -46,7 +46,7 @@ class Pman_Roo extends Pman
      * -- defaults to listing data. with args.
      * 
      * !colname=....                 => colname != ....
-     * colname[0]=... colname[1]=... => colname IN (.....)
+     * colname[0]=... colname[1]=... => colname IN (.....) ** only supports main table at present..
      * 
      * other opts:
      * _post      = simulate a post with debuggin on.
@@ -73,7 +73,7 @@ class Pman_Roo extends Pman
     function get($tab)
     {
          //  $this->jerr("Not authenticated", array('authFailure' => true));
-         //DB_DataObject::debuglevel(1);
+        // DB_DataObject::debuglevel(1);
         
         // debugging...
         if (!empty($_GET['_post'])) {
@@ -343,8 +343,7 @@ class Pman_Roo extends Pman
             // do we really delete stuff!?!?!?
             return $this->delete($x,$_REQUEST);
         } 
-        
-        
+         
         
         $old = false;
         
@@ -370,6 +369,11 @@ class Pman_Roo extends Pman
             }
             $this->jok($this->update($x, $_REQUEST));
         } else {
+            
+            if (empty($_POST)) {
+                $this->jerr("No data recieved for inserting");
+            }
+            
             $this->jok($this->insert($x, $_REQUEST));
             
         }
@@ -531,7 +535,7 @@ class Pman_Roo extends Pman
         if (empty($req['_delete'])) {
             $this->jerr("Delete Requested with no value");
             
-           }
+        }
         // build a list of tables to queriy for dependant data..
         $map = $x->links();
         
@@ -551,7 +555,7 @@ class Pman_Roo extends Pman
         // collect tables
         
        // echo '<PRE>';print_r($affects);exit;
-        //DB_Dataobject::debugLevel(1);
+       //DB_Dataobject::debugLevel(1);
        
         
         $clean = create_function('$v', 'return (int)$v;');
@@ -559,9 +563,14 @@ class Pman_Roo extends Pman
         $bits = array_map($clean, explode(',', $req['_delete']));
         
        // print_r($bits);exit;
+         $pk = $x->keys();
+        // let's assume it has a key!!!
+        $pk = $pk[0];
         
-        $x->whereAdd('id IN ('. implode(',', $bits) .')');
-        $x->find();
+        $x->whereAdd($pk .'  IN ('. implode(',', $bits) .')');
+        if (!$x->find()) {
+            $this->jerr("Nothing found to delete");
+        }
         $errs = array();
         while ($x->fetch()) {
             $xx = clone($x);
@@ -570,9 +579,12 @@ class Pman_Roo extends Pman
             foreach($affects as $k=> $true) {
                 $ka = explode('.', $k);
                 $chk = DB_DataObject::factory($ka[0]);
-                $chk->{$ka[1]} =  $xx->id;
+                if (!is_a($chk,'DB_DataObject')) {
+                    $this->jerr('Unable to load referenced table, check the links config: ' .$ka[0]);
+                }
+                $chk->{$ka[1]} =  $xx->$pk;
                 if ($chk->count()) {
-                    $this->jerr('Delete Dependant records first');
+                    $this->jerr('Delete Dependant records first ('. $ka[0]. ':' . $ka[1] .'='.$xx->$pk.')');
                 }
             }
             
@@ -799,7 +811,7 @@ class Pman_Roo extends Pman
                     
                 }
                 if (count($ar)) {
-                    $x->whereAddIn($key,$ar, $quote ? 'string' : 'int');
+                    $x->whereAddIn($x->tableName(). '.'.$key,$ar, $quote ? 'string' : 'int');
                 }
                 
                 continue;