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!!!!
53 // should we allow url links to lock things???
54 $this->jerr("invalid request");
57 function post($action)
60 // default action is to attempt to lock..
61 $action = empty($action) || $action == 'lock' ? 'lock' : 'unlock';
69 if (empty($_REQUEST['id'])) {
70 $this->jerr("No lock id");
72 $curlock = DB_DataObject::factory('Core_locking');
73 if (!$curlock->get($_REQUEST['id'])) {
74 $this->jerr("No lock exists");
77 if ($curlock->person_id != $this->authUser->id) {
78 $this->jerr("Lock id is invalid");
83 $this->jok('unlocked');
88 if (empty($_REQUEST['on_id']) || empty($_REQUEST['on_table'])) {
89 $this->jerr("Missing table or id");
92 $tab = str_replace('/', '',$_REQUEST['on_table']); // basic protection??
93 $x = DB_DataObject::factory($tab);
94 if (!$x->get($_REQUEST['on_id'])) {
95 $this->jerr("Item does not exist");
97 // is there a current lock on the item..
99 $curlock = DB_DataObject::factory('Core_locking');
100 $curlock->setFrom(array(
101 'on_id' => $_REQUEST['on_id'],
102 'on_table' => $_REQUEST['on_table']
106 $nlocks = $curlock->count() ;
107 if ($nlocks && empty($_REQUEST['force'])) {
109 $ar = $curlock->fetchAll('person_id', 'created');
110 $p = DB_DataObject::factory('Person');
111 $p->whereAddIn('id', $ar, 'int');
114 while ($p->fetch()) {
115 $ret[$p->id] = $p->toRooArray();
116 $ret[$p->id]->lock_created = $ar[$p->id];
118 $this->jok(array_values($ret));
122 // trash all the locks..
124 while($curlock->fetch()) {
125 $cc =clone($curlock);
132 $curlock = DB_DataObject::factory('Core_locking');
133 $curlock->setFrom(array(
134 'on_id' => $_REQUEST['on_id'],
135 'on_table' => $_REQUEST['on_table'],
136 'created' => date('Y-m-d H:i:s'),
137 'person_id' => $this->authUser->id,
139 $id = $curlock->insert();