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) || $action == 'lock' ? 'lock' : 'unlock';
63 if (empty($_REQUEST['id'])) {
64 $this->jerr("No lock id");
66 $curlock = DB_DataObject::factory('Core_locking');
67 if (!$curlock->get($_REQUEST['id'])) {
68 $this->jerr("No lock exists");
71 if ($curlock->person_id != $this->authUser->id) {
72 $this->jerr("Lock id is invalid");
77 $this->jok('unlocked');
82 if (empty($_REQUEST['on_id']) || empty($_REQUEST['on_table'])) {
83 $this->jerr("Missing table or id");
86 $tab = str_replace('/', '',$_REQUEST['on_table']); // basic protection??
87 $x = DB_DataObject::factory($tab);
88 if (!$x->get($_REQUEST['on_id'])) {
89 $this->jerr("Item does not exist");
91 // is there a current lock on the item..
93 $curlock = DB_DataObject::factory('Core_locking');
94 $curlock->setFrom(array(
95 'on_id' => $_REQUEST['on_id'],
96 'on_table' => $_REQUEST['on_table']
100 $nlocks = $curlock->count() ;
101 if ($nlocks && empty($_REQUEST['force'])) {
102 $curlock->selectAdd();
103 $curlock->selectAdd('distinct(person_id), created');
105 $ar = $curlock->fetchAll('person_id', 'created');
106 $p = DB_DataObject::factory('Person');
107 $p->whereAddIn('id', $ar, 'int');
110 while ($p->fetch()) {
111 $ret[$p->id] = $p->toRooArray();
112 $ret[$p->id]->lock_created = $ar[$p->id];
114 $this->jok(array_values($ret));
118 // trash all the locks..
120 while($curlock->fetch()) {
121 $cc =clone($curlock);
128 $curlock = DB_DataObject::factory('Core_locking');
129 $curlock->setFrom(array(
130 'on_id' => $_REQUEST['on_id'],
131 'on_table' => $_REQUEST['on_table'],
132 'created' => date('Y-m-d H:i:s'),
133 'person_id' => $this->authUser->id,
135 $id = $curlock->insert();