10 * This page is locked by XXXXXXX..
11 * Do you to prevent them saving and lock it yourself..
14 * -- interacts with Roo and _lock = id..
19 require_once 'Pman.php';
21 class Pman_Core_Lock extends Pman
26 $au = $this->getAuthUser();
28 $this->jerr("Not authenticated", array('authFailure' => true));
30 $this->authUser = $au;
31 // check that it's a supplier!!!!
39 // default action is to attempt to lock..
40 $action = empty($action) ? 'lock' : 'unlock';
41 $this->$action($curlock);
48 function unlock($curlock)
51 if (empty($_REQUEST['id'])) {
52 $this->jerr("No lock id");
54 $curlock = DB_DataObject::factory('Core_locking');
55 if (!$curlock->get($_REQUEST['id'])) {
56 $this->jerr("No lock exists");
59 if ($curlock->person_id != $this->authUser->id) {
60 $this->jerr("Lock id is invalid");
65 $this->jok('unlocked');
70 if (empty($_REQUEST['on_id']) || empty($_REQUEST['on_table'])) {
71 $this->jerr("Missing table or id");
74 $tab = str_replace('/', '',$_REQUEST['on_table']); // basic protection??
75 $x = DB_DataObject::factory($tab);
76 if (!$x->get($_REQUEST['on_id'])) {
77 $this->jerr("Item does not exist");
79 // is there a current lock on the item..
81 $curlock = DB_DataObject::factory('Core_locking');
82 $curlock->setFrom(array(
83 'on_id' => $_REQUEST['on_id'],
84 'on_table' => $_REQUEST['on_table']
86 if ($curlock->count()) {
87 $err = $this->canUnlock();
94 $curlock = DB_DataObject::factory('Core_locking');
95 $curlock->setFrom(array(
96 'on_id' => $_REQUEST['on_id'],
97 'on_table' => $_REQUEST['on_table'],
98 'created' => date('Y-m-d H:i:s'),
99 'person_id' => $this->authUser->id,
101 $id = $curlock->insert();
108 // the only scenario where we can automatically unlock is:::
110 // this user owns the lock.
112 $curlock = DB_DataObject::factory('Core_locking');
113 $curlock->setFrom(array(
114 'on_id' => $_REQUEST['on_id'],
115 'on_table' => $_REQUEST['on_table']
117 $cc = clone($curlock);
118 // the user who owns the lock is not logged in.. ?? - their last
121 while ($curlock->fetch()) {
122 $u = DB_DataObject::factory('Person');
123 $u->get($curlock->person_id);
124 if (!$u->isCurrentlyLoggedIn()) {
125 $cc = clone($curlock);
129 $users[] = clone($u);
138 //- the user is logged in, and we can clear it..
140 //- the user is logged in multiple times, on different browser..
142 //- the user is logged in multiple times on the same browser..
146 // one of two error messages..
148 $this->jerr("Item is Locked by " . $u->name . ' (' . $u->email . "), Try asking them to log out");