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