1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14:
15:
16: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
17:
18: 19: 20: 21: 22: 23:
24: class cApiInUseCollection extends ItemCollection {
25:
26: 27: 28:
29: public function __construct() {
30: global $cfg;
31: parent::__construct($cfg['tab']['inuse'], 'idinuse');
32: $this->_setItemClass('cApiInUse');
33: }
34:
35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47:
48: public function markInUse($type, $objectid, $session, $user) {
49: $type = $this->escape($type);
50: $objectid = $this->escape($objectid);
51: $session = $this->escape($session);
52: $user = $this->escape($user);
53:
54: $this->select("type='" . $type . "' AND objectid='" . $objectid . "'");
55:
56: $newitem = NULL;
57: if (!$this->next()) {
58: $newitem = parent::createNewItem();
59: $newitem->set('type', $type);
60: $newitem->set('objectid', $objectid);
61: $newitem->set('session', $session);
62: $newitem->set('userid', $user);
63: $newitem->set('timestamp', time());
64: $newitem->store();
65: }
66: return $newitem;
67: }
68:
69: 70: 71: 72: 73: 74: 75: 76:
77: public function removeMark($type, $objectid, $session) {
78: $type = $this->escape($type);
79: $objectid = $this->escape($objectid);
80: $session = $this->escape($session);
81:
82: $this->select("type='" . $type . "' AND objectid='" . $objectid . "' AND session='" . $session . "'");
83:
84: if (($obj = $this->next()) !== false) {
85:
86: $this->delete($obj->get('idinuse'));
87: unset($obj);
88: }
89: }
90:
91: 92: 93: 94: 95: 96: 97:
98: public function removeTypeMarks($type, $session) {
99: $type = $this->escape($type);
100: $session = $this->escape($session);
101:
102: $this->select("type='" . $type . "' AND session='" . $session . "'");
103:
104: while (($obj = $this->next()) !== false) {
105:
106: $this->delete($obj->get('idinuse'));
107: unset($obj);
108: }
109: }
110:
111: 112: 113: 114: 115: 116:
117: public function removeItemMarks($type, $itemid) {
118: $type = $this->escape($type);
119: $itemid = $this->escape($itemid);
120:
121: $this->select("type='" . $type . "' AND objectid='" . $itemid . "'");
122:
123: while (($obj = $this->next()) !== false) {
124:
125: $this->delete($obj->get('idinuse'));
126: unset($obj);
127: }
128: }
129:
130: 131: 132: 133: 134:
135: public function removeUserMarks($userId) {
136: $userId = $this->escape($userId);
137: $this->select("userid='" . $userId . "'");
138:
139: while (($obj = $this->next()) !== false) {
140:
141: $this->delete($obj->get('idinuse'));
142: unset($obj);
143: }
144: }
145:
146: 147: 148:
149: public function removeOldMarks() {
150: $cfg = cRegistry::getConfig();
151: $expire = time() - $cfg['inuse']['lifetime'];
152:
153: $this->select("timestamp < " . $expire);
154:
155: while (($obj = $this->next()) !== false) {
156:
157: $this->delete($obj->get('idinuse'));
158: unset($obj);
159: }
160: }
161:
162: 163: 164: 165: 166: 167:
168: public function removeSessionMarks($session) {
169: $session = $this->escape($session);
170: $this->select("session='" . $session . "'");
171:
172: while (($obj = $this->next()) !== false) {
173:
174: $this->delete($obj->get('idinuse'));
175: unset($obj);
176: }
177: }
178:
179: 180: 181: 182: 183: 184: 185: 186:
187: public function checkMark($type, $objectid) {
188: $type = $this->escape($type);
189: $objectid = $this->escape($objectid);
190:
191: $this->select("type='" . $type . "' AND objectid='" . $objectid . "'");
192:
193: if (($obj = $this->next()) !== false) {
194: return $obj;
195: } else {
196: return false;
197: }
198: }
199:
200: 201: 202: 203: 204: 205: 206: 207: 208: 209: 210: 211: 212: 213: 214: 215: 216: 217: 218: 219:
220: public function checkAndMark($type, $objectid, $returnWarning = false, $warningTemplate = '', $allowOverride = false, $location = '') {
221: global $sess, $auth, $notification, $area, $frame, $perm;
222:
223: if ((($obj = $this->checkMark($type, $objectid)) === false) || ($auth->auth['uid'] == $obj->get('userid'))) {
224: $this->markInUse($type, $objectid, $sess->id, $auth->auth['uid']);
225: $inUse = false;
226: $disabled = '';
227: $noti = '';
228: } else {
229: if ($returnWarning == true) {
230: $vuser = new cApiUser($obj->get('userid'));
231: $inUseUser = $vuser->getField('username');
232: $inUseUserRealName = $vuser->getField('realname');
233:
234: $message = sprintf($warningTemplate, $inUseUser, $inUseUserRealName);
235:
236: if ($allowOverride == true && ($auth->auth['uid'] == $obj->get('userid') || $perm->have_perm())) {
237: $alt = i18n("Click here if you want to override the lock");
238:
239: $link = $sess->url($location . "&overridetype=" . $type . "&overrideid=" . $objectid);
240:
241: $warnmessage = i18n("Do you really want to override the lock?");
242: $script = "javascript:if (window.confirm('" . $warnmessage . "') == true) { window.location.href = '" . $link . "';}";
243: $override = '<br><br><a alt="' . $alt . '" title="' . $alt . '" href="' . $script . '" class="standard">[' . i18n("Override lock") . ']</a> <a href="javascript://" class="standard" onclick="elem = document.getElementById(\'contenido_notification\'); elem.style.display=\'none\'">[' . i18n("Hide notification") . ']</a>';
244: } else {
245: $override = '';
246: }
247:
248: if (!is_object($notification)) {
249: $notification = new cGuiNotification();
250: }
251:
252: $noti = $notification->returnMessageBox('warning', $message . $override, 0);
253: $inUse = true;
254: }
255: }
256:
257: if ($returnWarning == true) {
258: return (array(
259: $inUse,
260: $noti
261: ));
262: } else {
263: return $inUse;
264: }
265: }
266:
267: }
268:
269: 270: 271: 272: 273: 274:
275: class cApiInUse extends Item {
276:
277: 278: 279: 280: 281:
282: public function __construct($mId = false) {
283: global $cfg;
284: parent::__construct($cfg['tab']['inuse'], 'idinuse');
285: if ($mId !== false) {
286: $this->loadByPrimaryKey($mId);
287: }
288: }
289:
290: }
291: