1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12:
13:
14: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
15:
16: 17: 18: 19: 20: 21: 22:
23: class NoteCollection extends cApiCommunicationCollection {
24: 25: 26: 27: 28:
29: public function __construct() {
30: parent::__construct();
31: $this->_setItemClass('NoteItem');
32: }
33:
34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55:
56: public function select($where = '', $group_by = '', $order_by = '', $limit = '') {
57: if ($where == '') {
58: $where = "comtype='note'";
59: } else {
60: $where .= " AND comtype='note'";
61: }
62:
63: return parent::select($where, $group_by, $order_by, $limit);
64: }
65:
66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85:
86: public function createItem($itemtype, $itemid, $idlang, $message, $category = '') {
87: $item = parent::create();
88:
89: $item->set('subject', 'Note Item');
90: $item->set('message', $message);
91: $item->set('comtype', 'note');
92: $item->store();
93:
94: $item->setProperty('note', 'itemtype', $itemtype);
95: $item->setProperty('note', 'itemid', $itemid);
96: $item->setProperty('note', 'idlang', $idlang);
97:
98: if ($category != '') {
99: $item->setProperty('note', 'category', $category);
100: }
101:
102: return $item;
103: }
104: }
105:
106: 107: 108: 109: 110: 111:
112: class NoteItem extends cApiCommunication {
113: }
114:
115: 116: 117: 118: 119: 120:
121: class NoteView extends cHTMLIFrame {
122:
123: 124: 125: 126: 127:
128: public function __construct($sItemType, $sItemId) {
129: global $sess;
130: parent::__construct();
131: $this->setSrc($sess->url("main.php?itemtype=$sItemType&itemid=$sItemId&area=note&frame=2"));
132: $this->setBorder(0);
133: }
134: }
135:
136: 137: 138: 139: 140: 141:
142: class NoteList extends cHTMLDiv {
143: 144: 145:
146: protected $_bDeleteable;
147:
148: 149: 150:
151: protected $_sItemType;
152:
153: 154: 155:
156: protected $_sItemId;
157:
158: 159: 160: 161: 162: 163:
164: public function __construct($sItemType, $sItemId) {
165: parent::__construct();
166:
167: $this->_sItemType = $sItemType;
168: $this->_sItemId = $sItemId;
169:
170: $this->appendStyleDefinition('width', '100%');
171: }
172:
173: 174: 175: 176:
177: public function setDeleteable($bDeleteable) {
178: $this->_bDeleteable = $bDeleteable;
179: }
180:
181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191:
192: public function toHtml() {
193: global $lang;
194:
195: $sItemType = $this->_sItemType;
196: $sItemId = $this->_sItemId;
197:
198: $oPropertyCollection = new cApiPropertyCollection();
199: $oPropertyCollection->select("itemtype = 'idcommunication' AND type = 'note' AND name = 'idlang' AND value = " . (int) $lang);
200:
201: $items = array();
202:
203: while ($oProperty = $oPropertyCollection->next()) {
204: $items[] = $oProperty->get('itemid');
205: }
206:
207: $oNoteItems = new NoteCollection();
208:
209: if (count($items) == 0) {
210: $items[] = 0;
211: }
212:
213: $oNoteItems->select('idcommunication IN (' . implode(', ', $items) . ')', '', 'created DESC');
214:
215: $i = array();
216: $dark = false;
217: while ($oNoteItem = $oNoteItems->next()) {
218: if ($oNoteItem->getProperty('note', 'itemtype') == $sItemType && $oNoteItem->getProperty('note', 'itemid') == $sItemId) {
219: $j = new NoteListItem($sItemType, $sItemId, $oNoteItem->get('idcommunication'));
220: $j->setAuthor($oNoteItem->get('author'));
221: $j->setDate($oNoteItem->get('created'));
222: $j->setMessage($oNoteItem->get('message'));
223: $j->setBackground($dark);
224: $j->setDeleteable($this->_bDeleteable);
225: $dark = !$dark;
226: $i[] = $j;
227: }
228: }
229:
230: $this->setContent($i);
231:
232: $result = parent::toHtml();
233:
234: return '<table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td>' . $result . '</td></tr></table>';
235: }
236: }
237:
238: 239: 240: 241: 242: 243:
244: class NoteListItem extends cHTMLDiv {
245:
246: 247: 248: 249: 250: 251: 252:
253: public function __construct($sItemType, $sItemId, $iDeleteItem) {
254: parent::__construct();
255: $this->appendStyleDefinition('padding', '2px');
256: $this->setBackground();
257: $this->setDeleteable(true);
258:
259: $this->_iDeleteItem = $iDeleteItem;
260: $this->_sItemType = $sItemType;
261: $this->_sItemId = $sItemId;
262: }
263:
264: 265: 266: 267:
268: public function setDeleteable($bDeleteable) {
269: $this->_bDeleteable = $bDeleteable;
270: }
271:
272: 273: 274: 275:
276: public function setBackground($dark = false) {
277: }
278:
279: 280: 281: 282:
283: public function setAuthor($sAuthor) {
284: if (cString::getStringLength($sAuthor) == 32) {
285: $result = getGroupOrUserName($sAuthor);
286:
287: if ($result !== false) {
288: $sAuthor = $result;
289: }
290: }
291:
292: $this->_sAuthor = $sAuthor;
293: }
294:
295: 296: 297: 298:
299: public function setDate($iDate) {
300: $dateformat = getEffectiveSetting('dateformat', 'full', 'Y-m-d H:i:s');
301:
302: if (cSecurity::isString($iDate)) {
303: $iDate = strtotime($iDate);
304: }
305: $this->_sDate = date($dateformat, $iDate);
306: }
307:
308: 309: 310: 311:
312: public function setMessage($sMessage) {
313: $this->_sMessage = $sMessage;
314: }
315:
316: 317: 318: 319: 320: 321:
322: public function render() {
323: global $sess;
324: $itemtype = $this->_sItemType;
325: $itemid = $this->_sItemId;
326: $deleteitem = $this->_iDeleteItem;
327:
328: $table = '<table border="0" cellspacing="0" cellpadding="0" width="100%"><tr><td><b>';
329: $table .= $this->_sAuthor;
330: $table .= '</b></td><td align="right">';
331: $table .= $this->_sDate;
332:
333: if ($this->_bDeleteable == true) {
334: $oDeleteable = new cHTMLLink();
335: $oDeleteable->setClass("vAlignMiddle tableElement");
336: $oDeletePic = new cHTMLImage(cRegistry::getBackendUrl() . '/images/delete.gif');
337: $oDeleteable->setContent($oDeletePic);
338: $oDeleteable->setLink($sess->url("main.php?frame=2&area=note&itemtype=$itemtype&itemid=$itemid&action=note_delete&deleteitem=$deleteitem"));
339:
340: $table .= '</td><td width="1">' . $oDeleteable->render();
341: }
342: $table .= '</td></tr></table>';
343:
344: $oMessage = new cHTMLDiv();
345: $oMessage->setContent($this->_sMessage);
346: $oMessage->setStyle("padding-bottom: 8px; margin-top: 4px;");
347:
348: $this->setContent(array(
349: $table,
350: $oMessage
351: ));
352:
353: return parent::render();
354: }
355: }
356:
357: 358: 359: 360: 361: 362:
363: class NoteLink extends cHTMLLink {
364:
365: 366: 367: 368:
369: private $_sItemType;
370:
371: 372: 373: 374:
375: private $_sItemID;
376:
377: 378: 379: 380:
381: private $_bShowHistory;
382:
383: 384: 385: 386:
387: private $_bDeleteHistoryItems;
388:
389: 390: 391: 392: 393: 394: 395: 396: 397: 398: 399:
400: public function __construct($sItemType, $sItemID) {
401: parent::__construct();
402:
403: $img = new cHTMLImage('images/note.gif');
404: $img->setStyle('padding-left: 2px; padding-right: 2px;');
405:
406: $img->setAlt(i18n('View notes / add note'));
407: $this->setLink('#');
408: $this->setContent($img->render());
409: $this->setAlt(i18n('View notes / add note'));
410:
411: $this->_sItemType = $sItemType;
412: $this->_sItemID = $sItemID;
413: $this->_bShowHistory = false;
414: $this->_bDeleteHistoryItems = false;
415: }
416:
417: 418: 419:
420: public function enableHistory() {
421: $this->_bShowHistory = true;
422: }
423:
424: 425: 426:
427: public function disableHistory() {
428: $this->_bShowHistory = false;
429: }
430:
431: 432: 433:
434: public function enableHistoryDelete() {
435: $this->_bDeleteHistoryItems = true;
436: }
437:
438: 439: 440:
441: public function disableHistoryDelete() {
442: $this->_bDeleteHistoryItems = false;
443: }
444:
445: 446: 447: 448: 449:
450: public function render() {
451: global $sess;
452:
453: $itemtype = $this->_sItemType;
454: $itemid = $this->_sItemID;
455:
456: $url = $sess->url("main.php?area=note&frame=1&itemtype=$itemtype&itemid=$itemid");
457: $this->setEvent('click', "javascript:window.open('$url', 'todo', 'resizable=yes,scrollbars=yes,height=360,width=550');");
458:
459: return parent::render();
460: }
461: }
462: