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