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