Pman/Roo.php
[Pman.Base] / Pman / Roo.php
index 37cfe2b..fe3a6ac 100644 (file)
@@ -26,7 +26,7 @@ require_once 'Pman.php';
  * - onUpload($roo)
  * - setFromRoo($ar) - values from post (deal with dates etc.) - return true|error string.
  * 
- * - toEventString (for logging)
+ * - toEventString (for logging - this is generically prefixed to all database operations.)
  */
 
 class Pman_Roo extends Pman
@@ -433,7 +433,7 @@ class Pman_Roo extends Pman
         if (method_exists($x, 'onInsert')) {
             $x->onInsert($_REQUEST, $this);
         }
-        $this->addEvent("ADD", $x, $x->toEventString());
+        $this->addEvent("ADD", $x);
         
         // note setFrom might handle this before hand...!??!
         if (!empty($_FILES) && method_exists($x, 'onUpload')) {
@@ -461,6 +461,35 @@ class Pman_Roo extends Pman
             $this->jerr("PERMISSION DENIED");
         }
        
+        // check any locks..
+        // only done if we recieve a lock_id.
+        // we are very trusing here.. that someone has not messed around with locks..
+        // the object might want to check in their checkPerm - if locking is essential..
+        
+        $lock = DB_DataObjecT::factory('Core_locking');
+        if (is_a($lock,'DB_DataObject'))  {
+                 
+            $lock->on_id = $x->id;
+            $lock->on_table= $x->tableName();
+            if (!empty($_REQUEST['_lock_id'])) {
+                $lock->whereAdd('id != ' . ((int)$_REQUEST['_lock_id']));
+            }
+            $lock->limit(1);
+            if ($lock->find(true)) {
+                // it's locked by someone else..
+                $p = $lock->person();
+                $this->jerr("Your lock is invalid, This record is locked by " . $p->name . " at " .$lock->created);
+            }
+            // check the users lock.. - no point.. ??? - if there are no other locks and it's not the users, then they can 
+            // edit it anyways...
+            
+        }
+        
+         
+        
+        
+        
+       
         $_columns = !empty($req['_columns']) ? explode(',', $req['_columns']) : false;
 
        
@@ -475,7 +504,7 @@ class Pman_Roo extends Pman
         } else {
             $x->setFrom($req);
         }
-        $this->addEvent("EDIT", $x, $x->toEventString());
+        $this->addEvent("EDIT", $x);
         //print_r($x);
         //print_r($old);
         
@@ -594,7 +623,7 @@ class Pman_Roo extends Pman
             }
             // finally log it.. 
             
-            $this->addEvent("DELETE", $x, $x->toEventString());
+            $this->addEvent("DELETE", $x);
             
             $xx->delete();
         }