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:
26: global $area;
27: class ArticleForumRightBottom extends cGuiPage {
28:
29: private $_indentFactor = 20;
30:
31: protected $_collection;
32:
33: function __construct() {
34:
35: $this->_collection = new ArticleForumCollection();
36: parent::__construct('right_bottom', 'user_forum');
37: $this->addStyle('right_bottom.css');
38: $this->addScript('location.js');
39:
40: $this->setReload();
41: }
42:
43: protected function formatTimeString($timeStamp) {
44: $nullstring = '0';
45: if ($timeStamp == "0000-00-00 00:00:00") {
46: return array();
47: } else {
48: $ar = (date_parse($timeStamp));
49:
50:
51: (strlen($ar['day']) < 2) ? $ar['day'] = $nullstring . $ar['day'] : '';
52: (strlen($ar['month']) < 2) ? $ar['month'] = $nullstring . $ar['month'] : '';
53: (strlen($ar['minute']) < 2) ? $ar['minute'] = $nullstring . $ar['minute'] : '';
54: (strlen($ar['hour']) < 2) ? $ar['hour'] = $nullstring . $ar['hour'] : '';
55: }
56:
57: return $ar;
58: }
59:
60: 61: 62: 63: 64: 65: 66: 67:
68: protected function checkValidEmail($emailadr, $realname) {
69: $regex = '/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/';
70:
71: if (preg_match($regex, $emailadr)) {
72: $mail = new cHTMLLink();
73: $mail->setClass('emailactive');
74: $mail->setLink("mailto:" . $emailadr);
75: $mail->setContent($realname);
76: } else {
77: $mail = new cHTMLLink();
78: $mail->setLink('#');
79: $mail->setClass('emaildeactive');
80: $mail->setContent($realname);
81: }
82: return $mail;
83: }
84:
85: 86: 87: 88: 89: 90: 91: 92: 93: 94:
95: protected function buildOnlineButtonBackendListMode(&$key, &$cont, &$cfg) {
96: global $area;
97: $buttons = array();
98:
99: $id = $cont['id_user_forum'];
100:
101:
102: $online = new cHTMLLink();
103: if ($cont['online'] == 1) {
104: $online->setImage($cfg['path']['images'] . 'online.gif');
105: $online->setCustom('action', 'online_toggle');
106: $online->setAlt(UserForum::i18n('SETOFFLINE'));
107: } else {
108: $online->setImage($cfg['path']['images'] . 'offline.gif');
109: $online->setCustom('action', 'offline_toggle');
110: $online->setAlt(UserForum::i18n('SETONLINE'));
111: }
112:
113: $online->setCLink($area, 4, 'show_form');
114: $online->setTargetFrame('right_bottom');
115: $online->setStyle('margin-right:10px;');
116:
117: $online->setCustom('action', 'online_toggle');
118: $online->setCustom('idart', $cont['idart']);
119: $online->setCustom('id_user_forum', $cont['id_user_forum']);
120: $online->setCustom('idcat', $cont['idcat']);
121: $online->setCustom('online', $cont['online']);
122: $online->setAttribute('method', 'get');
123:
124:
125: $edit = new cHTMLButton("edit");
126: $edit->setImageSource($cfg['path']['images'] . 'but_todo.gif');
127: $edit->setEvent('click', "$('form[name=$id]').submit()");
128: $edit->setStyle('margin-right:10px; ');
129: $edit->setMode('image');
130: $edit->setAlt(UserForum::i18n('EDIT'));
131:
132: $message = UserForum::i18n('ALLDELETEFROMCATHIER');
133: $level = $cont['level'];
134: $keyy = $key;
135: $id = $cont['id_user_forum'];
136: $idacat = $cont['idcat'];
137: $idaart = $cont['idart'];
138:
139:
140: $deleteButton = '<a title="' . $cont['title'] . '" href="javascript:void(0)" onclick="Con.showConfirmation("' . $message . '", function(){ deleteArticlesByIdRight(' . $level . ', ' . $keyy . ', ' . $id . ', ' . $idacat . ', ' . $idaart . '); });return false;"><img src="' . $cfg['path']['images'] . 'delete.gif" border="0" title="' . $message . '" alt="' . $message . '"></a>';
141:
142:
143: $buttons['online'] = $online;
144: $buttons['edit'] = $edit;
145: $buttons['delete'] = $deleteButton;
146:
147: return $buttons;
148: }
149:
150: 151: 152: 153: 154: 155:
156: protected function (&$result) {
157: $table = new cHTMLTable();
158: if (count($result) < 1) {
159: return new cHTMLTable();
160: }
161: $table->setCellPadding('100px');
162: global $area;
163: $table->updateAttributes(array(
164: "class" => "generic",
165: "cellspacing" => "0",
166: "cellpadding" => "2"
167: ));
168:
169: if (count($result) > 0) {
170: $tr = new cHTMLTableRow();
171: $th = new cHTMLTableHead();
172: $th->setContent(i18n("FORUM_POST", "user_forum"));
173: $th->setStyle('text-align: center');
174: $tr->appendContent($th);
175:
176: $th = new cHTMLTableHead();
177: $th->setContent(i18n("ACTIONS", "user_forum"));
178: $th->setStyle('widht:20px');
179: $th->setStyle('text-align: center');
180: $th->setAttribute('valign', 'top');
181: $tr->appendContent($th);
182:
183: $table->appendContent($tr);
184: }
185:
186: $menu = new cGuiMenu();
187: $cfg = cRegistry::getConfig();
188:
189: foreach ($result as $key => $cont) {
190:
191: $set = false;
192: $like = $cont['like'];
193: $dislike = $cont['dislike'];
194: $timestamp = $cont['timestamp'];
195:
196: $datearray = $this->formatTimeString($cont['timestamp']);
197: $date = (empty($datearray)) ? '' : $datearray['day'] . '.' . $datearray['month'] . '.' . $datearray['year'] . ' ' . UserForum::i18n("AT") . ' ' . $datearray['hour'] . ':' . $datearray['minute'] . ' ' . UserForum::i18n("CLOCK");
198:
199: $buttons = array();
200: $buttons = $this->buildOnlineButtonBackendListMode($key, $cont, $cfg);
201:
202: $online = $buttons['online'];
203: $edit = $buttons['edit'];
204: $delete = $buttons['delete'];
205:
206:
207: $tr = new cHTMLTableRow();
208: $trLike = new cHTMLTableRow();
209:
210: $likeButton = new cHTMLImage($cfg['path']['images'] . 'like.png');
211:
212: $dislikeButton = new cHTMLImage($cfg['path']['images'] . 'dislike.png');
213:
214:
215: $maili = $this->checkValidEmail($cont['email'], $cont['realname']);
216: $text = $cont['forum'];
217:
218: $timestamp = $cont['editedat'];
219:
220: $editarray = $this->formatTimeString($cont['editedat']);
221: $editdate = (empty($editarray)) ? '' : $editarray['day'] . '.' . $editarray['month'] . '.' . $editarray['year'] . ' ' . UserForum::i18n("AT") . ' ' . $editarray['hour'] . ':' . $editarray['minute'] . ' ' . UserForum::i18n("CLOCK");
222:
223: $userColl = new cApiUserCollection();
224: $user = $userColl->loadItem($cont['editedby'])->get('username');
225:
226: if (($cont['editedby'] != '') && ($cont['editedat'] != '') && $cont['editedat'] != "0000-00-00 00:00:00") {
227: $edit_information = (UserForum::i18n("EDITED") . $editdate . ' ' . UserForum::i18n("FROM") . $user);
228: $edit_information = "<em>$edit_information</em>";
229: } else {
230: $edit_information = "<br>";
231: }
232:
233: $tdEmpty = new cHTMLTableData();
234: $tdEmpty->appendContent($edit_information);
235: $tdLike = new cHTMLTableData();
236: $tdEmpty->setAttribute('valign', 'top');
237: $tdLike->setAttribute('valign', 'top');
238: $tdLike->setStyle('text-align: center');
239:
240:
241: $tdLike->appendContent($likeButton);
242: $tdLike->appendContent(" $like ");
243: $tdLike->appendContent($dislikeButton);
244: $tdLike->appendContent(" $dislike");
245:
246:
247: $trLike->appendContent($tdEmpty);
248: $trLike->appendContent($tdLike);
249:
250:
251: $form = new cHTMLForm($cont['id_user_forum']);
252: $form->setAttribute('action', 'main.php?' . "area=" . $area . '&frame=4');
253:
254: $tdForm = new cHTMLTableData();
255: $tdForm->setStyle('padding-left:' . $cont['level'] * $this->_indentFactor . 'px');
256:
257:
258: $tdButtons = new cHTMLTableData();
259: $tdButtons->setAttribute('valign', 'top');
260: $tdButtons->setStyle(' text-align: center');
261:
262: $tdButtons->appendContent($online);
263: $tdButtons->appendContent($edit);
264: $tdButtons->appendContent($delete);
265: $tdButtons->appendContent('<br>');
266: $tdButtons->appendContent('<br>');
267:
268:
269: $hiddenIdart = new cHTMLHiddenField('idart');
270: $hiddenIdcat = new cHTMLHiddenField('idcat');
271: $hiddenId_user_forum = new cHTMLHiddenField('id_user_forum');
272: $hiddenLike = new cHTMLHiddenField('like');
273: $hiddenDislike = new cHTMLHiddenField('dislike');
274: $hiddenName = new cHTMLHiddenField('realname');
275: $hiddenEmail = new cHTMLHiddenField('email');
276: $hiddenLevel = new cHTMLHiddenField('level');
277: $hiddenEditdat = new cHTMLHiddenField('editedat');
278: $hiddenEditedby = new cHTMLHiddenField('editedby');
279: $hiddenTimestamp = new cHTMLHiddenField('timestamp');
280: $hiddenForum = new cHTMLHiddenField('forum');
281: $hiddenOnline = new cHTMLHiddenField('online');
282: $hiddenMode = new cHTMLHiddenField('mode');
283: $hiddenKey = new cHTMLHiddenField('key');
284: $hiddenaction = new cHTMLHiddenField('action');
285:
286:
287: $hiddenIdart->setValue($cont['idart']);
288: $hiddenIdcat->setValue($cont['idcat']);
289: $hiddenId_user_forum->setValue($cont['id_user_forum']);
290: $hiddenLike->setValue($cont['like']);
291: $hiddenDislike->setValue($cont['dislike']);
292: $hiddenName->setValue(str_replace('\\', '', conHtmlSpecialChars($cont['realname'])));
293: $hiddenEmail->setValue(str_replace('\\', '', conHtmlSpecialChars($cont['email'])));
294: $hiddenLevel->setValue($cont['level']);
295: $hiddenEditdat->setValue($cont['editedat']);
296: $hiddenEditedby->setValue($cont['editedby']);
297: $hiddenTimestamp->setValue($date);
298: $hiddenForum->setValue(str_replace('\\', '', conHtmlSpecialChars($cont['forum'])));
299: $hiddenOnline->setValue($cont['online']);
300: $hiddenMode->setValue('edit');
301: $hiddenKey->setValue($key);
302: $hiddenaction->setValue('edit');
303:
304:
305: $form->appendContent($hiddenIdart);
306: $form->appendContent($hiddenIdcat);
307: $form->appendContent($hiddenId_user_forum);
308: $form->appendContent($hiddenLike);
309: $form->appendContent($hiddenDislike);
310: $form->appendContent($hiddenName);
311: $form->appendContent($hiddenEmail);
312: $form->appendContent($hiddenLevel);
313: $form->appendContent($hiddenForum);
314: $form->appendContent($hiddenEditdat);
315: $form->appendContent($hiddenEditedby);
316: $form->appendContent($hiddenTimestamp);
317: $form->appendContent($hiddenMode);
318: $form->appendContent($hiddenOnline);
319: $form->appendContent($hiddenKey);
320: $form->appendContent($hiddenaction);
321:
322:
323: $form->appendContent($date . " von " . str_replace('\\', '', $maili) . " <br><br>");
324: $form->appendContent((str_replace('\\', '', $text)) . "<br><br>");
325: $tdForm->setContent($form);
326: $tdForm->setAttribute('valign', 'top');
327: $tr->setContent($tdForm);
328: $tr->appendContent($tdButtons);
329: $tr->appendContent($trLike);
330: $table->appendContent($tr);
331: }
332: $this->appendContent($table);
333:
334: return $this;
335: }
336:
337: 338: 339: 340: 341: 342:
343: protected function ($post) {
344:
345: global $area;
346: $changes = 0;
347: $cfg = cRegistry::getConfig();
348: $idart = cRegistry::getArticleId();
349: $idcat = cRegistry::getCategoryId();
350: $menu = new cGuiMenu();
351: $tr = new cHTMLTableRow();
352:
353: $th = new cHTMLTableHead();
354: $th->setContent(UserForum::i18n("PARAMETER", "user_forum"));
355:
356: $th2 = new cHTMLTableHead();
357: $th2->setContent(UserForum::i18n("CONTENT", "user_forum"));
358: $th2->setStyle('widht:50px');
359: $th2->setAttribute('valign', 'top');
360: $tr->appendContent($th);
361: $tr->appendContent($th2);
362:
363:
364: $form1 = new cGuiTableForm("comment", "main.php?area=user_forum&frame=4", "post");
365: $form1->addHeader($tr);
366: $form1->setTableID("table");
367:
368: $user = new cApiUser();
369: $user->loadByPrimaryKey($post['editedby']);
370: $username = $user->getField('username');
371:
372: $id = $post['id_user_forum'];
373:
374: $likeButton = new cHTMLImage($cfg['path']['images'] . 'like.png');
375: $dislikeButton = new cHTMLImage($cfg['path']['images'] . 'dislike.png');
376:
377:
378: $name = new cHTMLTextBox("realname", str_replace('\\', '',(conHtmlSpecialChars($post['realname']))), 30, 255);
379: $email = new cHTMLTextBox("email", $post['email'], 30, 255);
380: $like = new cHTMLTextBox("like", $post['like'], 7, 7);
381: $dislike = new cHTMLTextBox("dislike", $post['dislike'], 7, 7);
382:
383: $text = str_replace("<br />", "\n", conHtmlSpecialChars($post['forum']));
384: $text = str_replace('\\', '', $text);
385:
386: $forum = new cHTMLTextArea("forum", $text);
387:
388: $datearray = $this->formatTimeString($post['timestamp']);
389: $date = (empty($datearray)) ? '' : $datearray['day'] . '.' . $datearray['month'] . '.' . $datearray['year'] . ' ' . UserForum::i18n("AT") . ' ' . $datearray['hour'] . ':' . $datearray['minute'] . ' ' . UserForum::i18n("CLOCK");
390:
391: $editedatearray = $this->formatTimeString($post['editedat']);
392: $editedat = (empty($editedatearray)) ? '' : $editedatearray['day'] . '.' . $editedatearray['month'] . '.' . $editedatearray['year'] . ' ' . UserForum::i18n("AT") . ' ' . $editedatearray['hour'] . ':' . $editedatearray['minute'] . ' ' . UserForum::i18n("CLOCK");
393:
394: $timestamp = new cHTMLTextBox("timestamp", $date, 30, 255);
395: $editedat = new cHTMLTextBox("editedat", $editedat, 30, 255);
396: $editedby = new cHTMLTextBox("editedby", $username, 30, 255);
397:
398: $editedat->setDisabled(true);
399: $timestamp->setDisabled(true);
400: $editedby->setDisabled(true);
401:
402: $form1->addCancel("main.php?area=user_forum&frame=4&action=back&idart=$idart&idcat=$idcat");
403: $form1->add(UserForum::i18n("USER"), $name, '');
404: $form1->add(UserForum::i18n("EMAIL"), $email, '');
405: $form1->add(UserForum::i18n("LIKE"), $like, '');
406: $form1->add(UserForum::i18n("DISLIKE"), $dislike, '');
407: $form1->add(UserForum::i18n("TIME"), $timestamp, '');
408: $form1->add(UserForum::i18n("EDITDAT"), $editedat, '');
409: $form1->add(UserForum::i18n("EDITEDBY"), $editedby, '');
410:
411: $onlineBox = new cHTMLCheckbox("onlineState", "");
412:
413: $onlineBox->setChecked(($post['online'] == 1) ? true : false);
414: $form1->add(UserForum::i18n("ONLINE"), $onlineBox, '');
415:
416: $idart = $post['idart'];
417: $idcat = $post['idcat'];
418:
419: $form1->add(UserForum::i18n("COMMENT"), $forum, '');
420:
421:
422: $form1->setVar("id_user_forum", $post['id_user_forum']);
423: $form1->setVar("idart", $post['idart']);
424: $form1->setVar("idcat", $post['idcat']);
425: $form1->setVar("action", 'update');
426: $form1->setVar("mode", "list");
427: $form1->setVar("activeChanges", $changes);
428:
429: $this->appendContent($form1);
430:
431: return $this;
432: }
433:
434: protected function getForum($id_cat, $id_art, $id_lang) {
435: $arrUsers = $this->_collection->getExistingforum($id_cat, $id_art, $id_lang);
436:
437: $arrforum = array();
438:
439: $this->_collection->getTreeLevel($id_cat, $id_art, $id_lang, $arrUsers, $arrforum);
440: $result = array();
441: $this->normalizeArray($arrforum, $result);
442: $ret = $this->getMenu($result);
443:
444: return $ret;
445: }
446:
447: protected function normalizeArray($arrforum, &$result, $level = 0) {
448: if (is_array($arrforum)) {
449: foreach ($arrforum as $key => $value) {
450: $value['level'] = $level;
451: unset($value['children']);
452: $result[$key] = $value;
453: $this->normalizeArray($arrforum[$key]['children'], $result, $level + 1);
454: }
455: }
456: }
457:
458: 459: 460: 461: 462: 463: 464: 465:
466: public function receiveData(&$get, &$post) {
467: if (isset($_REQUEST['action']) && $_REQUEST['action'] != NULL) {
468: $this->switchActions();
469: }
470: }
471:
472: 473: 474: 475: 476:
477: protected function switchActions() {
478: $lang = cRegistry::getLanguageId();
479: $idart = $_REQUEST['idart'];
480: $idcat = $_REQUEST['idcat'];
481: $action = $_REQUEST["action"];
482: $online = (isset($_REQUEST['onlineState'])) ? 1 : 0;
483:
484: switch ($action) {
485:
486:
487: case 'online_toggle':
488: $this->_collection->toggleOnlineState($_REQUEST['online'], $_REQUEST['id_user_forum']);
489: $this->getForum($idcat, $idart, $lang);
490: break;
491:
492: case 'deleteComment':
493: $this->_collection->deleteHierarchie($_REQUEST['key'], $_REQUEST['level'], $idart, $idcat, $lang);
494: $this->getForum($idcat, $idart, $lang);
495: break;
496:
497: case 'update':
498: $this->_collection->updateValues($_POST['id_user_forum'], $_POST['realname'], $_POST['email'], $_POST['like'], $_POST['dislike'], $_POST['forum'], $online, $_POST['onlineState']);
499: $this->getForum($idcat, $idart, $lang);
500: break;
501: case 'show_form':
502:
503: $this->getForum($idcat, $idart, $lang);
504: break;
505: case 'edit':
506:
507: $this->getEditModeMenu($_POST);
508: break;
509:
510: case 'back':
511: $this->getForum($idcat, $idart, $lang);
512: break;
513: case 'empty':
514:
515: break;
516: default:
517: $this->getForum($idcat, $idart, $lang);
518: throw new Exception('$_GET["action"] type ' . $_REQUEST["action"] . ' not implemented');
519: }
520: }
521:
522: }
523:
524: ?>