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 require_once 'Pman.php';
24 class Pman_Core_Lock extends Pman
29 $au = $this->getAuthUser();
31 $this->jerr("Not authenticated", array('authFailure' => true));
33 $this->authUser = $au;
34 // check that it's a supplier!!!!
42 // default action is to attempt to lock..
43 $action = empty($action) ? 'lock' : 'unlock';
44 $this->$action($curlock);
51 function unlock($curlock)
54 if (empty($_REQUEST['id'])) {
55 $this->jerr("No lock id");
57 $curlock = DB_DataObject::factory('Core_locking');
58 if (!$curlock->get($_REQUEST['id'])) {
59 $this->jerr("No lock exists");
62 if ($curlock->person_id != $this->authUser->id) {
63 $this->jerr("Lock id is invalid");
68 $this->jok('unlocked');
73 if (empty($_REQUEST['on_id']) || empty($_REQUEST['on_table'])) {
74 $this->jerr("Missing table or id");
77 $tab = str_replace('/', '',$_REQUEST['on_table']); // basic protection??
78 $x = DB_DataObject::factory($tab);
79 if (!$x->get($_REQUEST['on_id'])) {
80 $this->jerr("Item does not exist");
82 // is there a current lock on the item..
84 $curlock = DB_DataObject::factory('Core_locking');
85 $curlock->setFrom(array(
86 'on_id' => $_REQUEST['on_id'],
87 'on_table' => $_REQUEST['on_table']
92 if ($curlock->count() && empty($_REQUEST['force'])) {
93 $curlock->selectAdd();
94 $curlock->selectAdd('distinct(person_id)');
95 $ar = $curlock->fetchAll('person_id');
96 $p = DB_DataObject::factory('Person');
99 $err = $this->canUnlock();
106 $curlock = DB_DataObject::factory('Core_locking');
107 $curlock->setFrom(array(
108 'on_id' => $_REQUEST['on_id'],
109 'on_table' => $_REQUEST['on_table'],
110 'created' => date('Y-m-d H:i:s'),
111 'person_id' => $this->authUser->id,
113 $id = $curlock->insert();