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