Lock.php
[Pman.Core] / Lock.php
1 <?php
2
3
4 require_once 'Pman.php';
5
6 class Pman_Core_Lock extends Pman
7 {
8     
9     function getAuth()
10     {
11          $au = $this->getAuthUser();
12         if (!$au) {
13              $this->jerr("Not authenticated", array('authFailure' => true));
14         }
15         $this->authUser = $au;
16         // check that it's a supplier!!!! 
17         
18         return true; 
19     }
20     
21     function get($action)
22     {
23         
24         // default action is to attempt to lock..
25         if (empty($_REQUEST['on_id']) || empty($_REQUEST['on_table'])) {
26             $this->jerr("Missing table or id");
27         }
28         $action = empty($action) ? 'lock' : 'unlock';
29         $tab = str_replace('/', '',$_REQUEST['on_table']); // basic protection??
30         $x = DB_DataObject::factory($tab);
31         if (!$x->get($_REQUEST['on_id'])) {
32             $this->jerr("Item does not exist");
33         }
34         
35         $locked = false;
36         if ($curlock->find(true)) {
37             $locked = true;
38         }
39         $this->$action($curlock);
40         
41     }
42     
43     function unlock($curlock)
44     {
45     
46         $curlock = DB_DataObject::factory('Core_locking');
47         $curlock->setFrom(array(
48             'on_id' => $_REQUEST['on_id'],
49             'on_table' => $_REQUEST['on_table'],
50             'person_id' => $this->authUser->id,
51         ));
52         
53         
54         if (!$curlock->find()) {
55             $this->jok("No lock");
56         }    
57         while ($curlock->fetch()) {
58             $cc = clone($curlock);
59             $cc->delete();
60         }
61         
62         $this->jok('unlocked');
63     }
64     
65     
66 }