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