Lock.php
authorAlan Knowles <alan@akbkhome.com>
Thu, 18 Nov 2010 08:32:57 +0000 (16:32 +0800)
committerAlan Knowles <alan@akbkhome.com>
Thu, 18 Nov 2010 08:32:57 +0000 (16:32 +0800)
Lock.php

index f0849cf..ffc88f7 100644 (file)
--- a/Lock.php
+++ b/Lock.php
@@ -22,45 +22,61 @@ class Pman_Core_Lock extends Pman
     {
         
         // default action is to attempt to lock..
+        $action = empty($action) ? 'lock' : 'unlock';
+        $this->$action($curlock);
+        
+       
+        
+        
+    }
+    
+    function unlock($curlock)
+    {
+    
+        if (empty($_REQUEST['id'])) {
+            $this->jerr("No lock id");
+        }
+        $curlock = DB_DataObject::factory('Core_locking');
+        if (!$curlock->get($_REQUEST['id'])) {
+            $this->jerr("No lock exists");
+        }
+        
+        if ($curlock->person_id != $this->authUser->id) {
+            $this->jerr("Lock id is invalid")
+        }
+        
+        $curlock->delete();
+        
+        $this->jok('unlocked');
+    }
+    function lock()
+    {
+        
         if (empty($_REQUEST['on_id']) || empty($_REQUEST['on_table'])) {
             $this->jerr("Missing table or id");
         }
-        $action = empty($action) ? 'lock' : 'unlock';
+       
         $tab = str_replace('/', '',$_REQUEST['on_table']); // basic protection??
         $x = DB_DataObject::factory($tab);
         if (!$x->get($_REQUEST['on_id'])) {
             $this->jerr("Item does not exist");
         }
+        // is there a current lock on the item..
         
-        $locked = false;
-        if ($curlock->find(true)) {
-            $locked = true;
-        }
-        $this->$action($curlock);
-        
-    }
-    
-    function unlock($curlock)
-    {
-    
         $curlock = DB_DataObject::factory('Core_locking');
         $curlock->setFrom(array(
             'on_id' => $_REQUEST['on_id'],
-            'on_table' => $_REQUEST['on_table'],
-            'person_id' => $this->authUser->id,
+            'on_table' => $_REQUEST['on_table']
         ));
-        
-        
-        if (!$curlock->find()) {
-            $this->jok("No lock");
-        }    
-        while ($curlock->fetch()) {
-            $cc = clone($curlock);
-            $cc->delete();
+        if ($curlock->count()) {
+            $err  = $this->canunlock()
+            if ($err !== true) {
+                $this->jerr($err);
+            }
         }
+        // make a lock..
+         
+        
         
-        $this->jok('unlocked');
-    }
-    
     
 }
\ No newline at end of file