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