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