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
30 require_once 'Pman.php';
32 class Pman_Core_Lock extends Pman
37 $au = $this->getAuthUser();
39 $this->jerr("Not authenticated", array('authFailure' => true));
41 $this->authUser = $au;
42 // check that it's a supplier!!!!
50 // default action is to attempt to lock..
51 $action = empty($action) ? 'lock' : 'unlock';
52 $this->$action($curlock);
59 function unlock($curlock)
62 if (empty($_REQUEST['id'])) {
63 $this->jerr("No lock id");
65 $curlock = DB_DataObject::factory('Core_locking');
66 if (!$curlock->get($_REQUEST['id'])) {
67 $this->jerr("No lock exists");
70 if ($curlock->person_id != $this->authUser->id) {
71 $this->jerr("Lock id is invalid");
76 $this->jok('unlocked');
81 if (empty($_REQUEST['on_id']) || empty($_REQUEST['on_table'])) {
82 $this->jerr("Missing table or id");
85 $tab = str_replace('/', '',$_REQUEST['on_table']); // basic protection??
86 $x = DB_DataObject::factory($tab);
87 if (!$x->get($_REQUEST['on_id'])) {
88 $this->jerr("Item does not exist");
90 // is there a current lock on the item..
92 $curlock = DB_DataObject::factory('Core_locking');
93 $curlock->setFrom(array(
94 'on_id' => $_REQUEST['on_id'],
95 'on_table' => $_REQUEST['on_table']
99 $nlocks = $curlock->count()
100 if ($nlocks && empty($_REQUEST['force'])) {
101 $curlock->selectAdd();
102 $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');
109 while ($p->fetch()) {
110 $ret[$p->id] = $p->toRooArray();
111 $ret[$p->id]->lock_created = $ar[$p->id];
117 // trash all the locks..
119 while($curlock->fetch()) {
120 $cc =clone($curlock);
127 $curlock = DB_DataObject::factory('Core_locking');
128 $curlock->setFrom(array(
129 'on_id' => $_REQUEST['on_id'],
130 'on_table' => $_REQUEST['on_table'],
131 'created' => date('Y-m-d H:i:s'),
132 'person_id' => $this->authUser->id,
134 $id = $curlock->insert();