4 require_once 'Pman.php';
6 class Pman_Core_Lock extends Pman
11 $au = $this->getAuthUser();
13 $this->jerr("Not authenticated", array('authFailure' => true));
15 $this->authUser = $au;
16 // check that it's a supplier!!!!
24 // default action is to attempt to lock..
25 $action = empty($action) ? 'lock' : 'unlock';
26 $this->$action($curlock);
33 function unlock($curlock)
36 if (empty($_REQUEST['id'])) {
37 $this->jerr("No lock id");
39 $curlock = DB_DataObject::factory('Core_locking');
40 if (!$curlock->get($_REQUEST['id'])) {
41 $this->jerr("No lock exists");
44 if ($curlock->person_id != $this->authUser->id) {
45 $this->jerr("Lock id is invalid");
50 $this->jok('unlocked');
55 if (empty($_REQUEST['on_id']) || empty($_REQUEST['on_table'])) {
56 $this->jerr("Missing table or id");
59 $tab = str_replace('/', '',$_REQUEST['on_table']); // basic protection??
60 $x = DB_DataObject::factory($tab);
61 if (!$x->get($_REQUEST['on_id'])) {
62 $this->jerr("Item does not exist");
64 // is there a current lock on the item..
66 $curlock = DB_DataObject::factory('Core_locking');
67 $curlock->setFrom(array(
68 'on_id' => $_REQUEST['on_id'],
69 'on_table' => $_REQUEST['on_table']
71 if ($curlock->count()) {
72 $err = $this->canUnlock();
79 $curlock = DB_DataObject::factory('Core_locking');
80 $curlock->setFrom(array(
81 'on_id' => $_REQUEST['on_id'],
82 'on_table' => $_REQUEST['on_table'],
83 'created' => date('Y-m-d H:i:s'),
84 'person_id' => $this->authUser->id,
86 $id = $curlock->insert();
93 // the only scenario where we can automatically unlock is:::
95 // this user owns the lock.
97 $curlock = DB_DataObject::factory('Core_locking');
98 $curlock->setFrom(array(
99 'on_id' => $_REQUEST['on_id'],
100 'on_table' => $_REQUEST['on_table']
102 $cc = clone($curlock);
103 // the user who owns the lock is not logged in.. ?? - their last
106 while ($curlock->fetch()) {
107 $u = DB_DataObject::factory('Person');
108 $u->get($curlock->person_id);
109 if (!$u->isCurrentlyLoggedIn()) {
110 $cc = clone($curlock);
114 $users[] = clone($u);
123 //- the user is logged in, and we can clear it..
125 //- the user is logged in multiple times, on different browser..
127 //- the user is logged in multiple times on the same browser..
131 // one of two error messages..
133 $this->jerr("Item is Locked by " . $u->name . ' (' . $u->email . "), Try asking them to log out");