10 * This page is locked by XXXXXXX..
11 * Do you to prevent them saving and lock it yourself..
17 * -- interacts with Roo and _lock = id..
22 * baseURL + /Core/Lock/lock?on_id=...&on_table=...
23 * - returns id or an array of who has the locks.
25 * Force an unlock after a warning..
26 * baseURL + /Core/Lock/lock?on_id=...&on_table=...&force=1
29 * Unlock - call when window is closed..
30 * baseURL + /Core/Lock/unlock?on_id=...&on_table=...&force=1
31 * - returns jerr or jok
34 require_once 'Pman.php';
36 class Pman_Core_Lock extends Pman
41 $au = $this->getAuthUser();
43 $this->jerr("Not authenticated", array('authFailure' => true));
45 $this->authUser = $au;
46 // check that it's a supplier!!!!
54 // default action is to attempt to lock..
55 $action = empty($action) ? 'lock' : 'unlock';
66 if (empty($_REQUEST['id'])) {
67 $this->jerr("No lock id");
69 $curlock = DB_DataObject::factory('Core_locking');
70 if (!$curlock->get($_REQUEST['id'])) {
71 $this->jerr("No lock exists");
74 if ($curlock->person_id != $this->authUser->id) {
75 $this->jerr("Lock id is invalid");
80 $this->jok('unlocked');
85 if (empty($_REQUEST['on_id']) || empty($_REQUEST['on_table'])) {
86 $this->jerr("Missing table or id");
89 $tab = str_replace('/', '',$_REQUEST['on_table']); // basic protection??
90 $x = DB_DataObject::factory($tab);
91 if (!$x->get($_REQUEST['on_id'])) {
92 $this->jerr("Item does not exist");
94 // is there a current lock on the item..
96 $curlock = DB_DataObject::factory('Core_locking');
97 $curlock->setFrom(array(
98 'on_id' => $_REQUEST['on_id'],
99 'on_table' => $_REQUEST['on_table']
103 $nlocks = $curlock->count() ;
104 if ($nlocks && empty($_REQUEST['force'])) {
105 $curlock->selectAdd();
106 $curlock->selectAdd('distinct(person_id), created');
109 $ar = $curlock->fetchAll('person_id', 'created');
110 $p = DB_DataObject::factory('Person');
111 $p->whereAddIn('id', $ar, 'int');
113 while ($p->fetch()) {
114 $ret[$p->id] = $p->toRooArray();
115 $ret[$p->id]->lock_created = $ar[$p->id];
117 $this->jok(array_values($ret));
121 // trash all the locks..
123 while($curlock->fetch()) {
124 $cc =clone($curlock);
131 $curlock = DB_DataObject::factory('Core_locking');
132 $curlock->setFrom(array(
133 'on_id' => $_REQUEST['on_id'],
134 'on_table' => $_REQUEST['on_table'],
135 'created' => date('Y-m-d H:i:s'),
136 'person_id' => $this->authUser->id,
138 $id = $curlock->insert();