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 * baseURL + /Core/Lock/lock?on_id=...&on_table=...&force=1
28 * Unlock - call when window is closed..
29 * baseURL + /Core/Lock/unlock?on_id=...&on_table=...&force=1
30 * - returns jerr or jok
33 require_once 'Pman.php';
35 class Pman_Core_Lock extends Pman
40 $au = $this->getAuthUser();
42 $this->jerr("Not authenticated", array('authFailure' => true));
44 $this->authUser = $au;
45 // check that it's a supplier!!!!
53 // default action is to attempt to lock..
54 $action = empty($action) ? 'lock' : 'unlock';
55 $this->$action($curlock);
62 function unlock($curlock)
65 if (empty($_REQUEST['id'])) {
66 $this->jerr("No lock id");
68 $curlock = DB_DataObject::factory('Core_locking');
69 if (!$curlock->get($_REQUEST['id'])) {
70 $this->jerr("No lock exists");
73 if ($curlock->person_id != $this->authUser->id) {
74 $this->jerr("Lock id is invalid");
79 $this->jok('unlocked');
84 if (empty($_REQUEST['on_id']) || empty($_REQUEST['on_table'])) {
85 $this->jerr("Missing table or id");
88 $tab = str_replace('/', '',$_REQUEST['on_table']); // basic protection??
89 $x = DB_DataObject::factory($tab);
90 if (!$x->get($_REQUEST['on_id'])) {
91 $this->jerr("Item does not exist");
93 // is there a current lock on the item..
95 $curlock = DB_DataObject::factory('Core_locking');
96 $curlock->setFrom(array(
97 'on_id' => $_REQUEST['on_id'],
98 'on_table' => $_REQUEST['on_table']
102 $nlocks = $curlock->count()
103 if ($nlocks && empty($_REQUEST['force'])) {
104 $curlock->selectAdd();
105 $curlock->selectAdd('distinct(person_id), created');
108 $ar = $curlock->fetchAll('person_id', 'created');
109 $p = DB_DataObject::factory('Person');
110 $p->whereAddIn('id', $ar, 'int');
112 while ($p->fetch()) {
113 $ret[$p->id] = $p->toRooArray();
114 $ret[$p->id]->lock_created = $ar[$p->id];
120 // trash all the locks..
122 while($curlock->fetch()) {
123 $cc =clone($curlock);
130 $curlock = DB_DataObject::factory('Core_locking');
131 $curlock->setFrom(array(
132 'on_id' => $_REQUEST['on_id'],
133 'on_table' => $_REQUEST['on_table'],
134 'created' => date('Y-m-d H:i:s'),
135 'person_id' => $this->authUser->id,
137 $id = $curlock->insert();