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: (strlen($ar['day']) < 2) ? $ar['day'] = $nullstring . $ar['day'] : '';
68: (strlen($ar['month']) < 2) ? $ar['month'] = $nullstring . $ar['month'] : '';
69: (strlen($ar['minute']) < 2) ? $ar['minute'] = $nullstring . $ar['minute'] : '';
70: (strlen($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: public function (&$result, $mod = null) {
180: $table = new cHTMLTable();
181: if (count($result) < 1) {
182: return new cHTMLTable();
183: }
184: $table->setCellPadding('100px');
185: global $area;
186: $table->updateAttributes(array(
187: "class" => "generic",
188: "cellspacing" => "0",
189: "cellpadding" => "2"
190: ));
191:
192: if (count($result) > 0) {
193: $tr = new cHTMLTableRow();
194: $th = new cHTMLTableHead();
195: $th->setContent(i18n("FORUM_POST", "user_forum"));
196: $th->setStyle('text-align: center');
197: $tr->appendContent($th);
198:
199: $th = new cHTMLTableHead();
200: $th->setContent(i18n("ACTIONS", "user_forum"));
201: $th->setStyle('widht:20px');
202: $th->setStyle('text-align: center');
203: $th->setAttribute('valign', 'top');
204: $tr->appendContent($th);
205:
206: $table->appendContent($tr);
207: }
208:
209: $menu = new cGuiMenu();
210: $cfg = cRegistry::getConfig();
211:
212: foreach ($result as $key => $cont) {
213:
214: $set = false;
215: $like = $cont['like'];
216: $dislike = $cont['dislike'];
217: $timestamp = $cont['timestamp'];
218:
219: $datearray = $this->formatTimeString($cont['timestamp']);
220: $date = (empty($datearray)) ? '' : $datearray['day'] . '.' . $datearray['month'] . '.' . $datearray['year'] . ' ' . UserForum::i18n("AT") . ' ' . $datearray['hour'] . ':' . $datearray['minute'] . ' ' . UserForum::i18n("CLOCK");
221:
222: $buttons = array();
223: $buttons = $this->buildOnlineButtonBackendListMode($key, $cont, $cfg, $mod);
224:
225: $online = $buttons['online'];
226: $edit = $buttons['edit'];
227: $delete = $buttons['delete'];
228:
229:
230: $tr = new cHTMLTableRow();
231: $trLike = new cHTMLTableRow();
232:
233: $likeButton = new cHTMLImage($cfg['path']['images'] . 'like.png');
234:
235: $dislikeButton = new cHTMLImage($cfg['path']['images'] . 'dislike.png');
236:
237:
238: $maili = $this->checkValidEmail($cont['email'], $cont['realname']);
239: $text = $cont['forum'];
240:
241: $timestamp = $cont['editedat'];
242:
243: $editarray = $this->formatTimeString($cont['editedat']);
244: $editdate = (empty($editarray)) ? '' : $editarray['day'] . '.' . $editarray['month'] . '.' . $editarray['year'] . ' ' . UserForum::i18n("AT") . ' ' . $editarray['hour'] . ':' . $editarray['minute'] . ' ' . UserForum::i18n("CLOCK");
245:
246: $userColl = new cApiUserCollection();
247: $user = $userColl->loadItem($cont['editedby'])->get('username');
248:
249: if (($cont['editedby'] != '') && ($cont['editedat'] != '') && $cont['editedat'] != "0000-00-00 00:00:00") {
250: $edit_information = (UserForum::i18n("EDITED") . $editdate . ' ' . UserForum::i18n("FROM") . $user);
251: $edit_information = "<em>$edit_information</em>";
252: } else {
253: $edit_information = "<br>";
254: }
255:
256: $tdEmpty = new cHTMLTableData();
257: $tdEmpty->appendContent($edit_information);
258: $tdLike = new cHTMLTableData();
259: $tdEmpty->setAttribute('valign', 'top');
260: $tdLike->setAttribute('valign', 'top');
261: $tdLike->setStyle('text-align: center');
262:
263:
264: $tdLike->appendContent($likeButton);
265: $tdLike->appendContent(" $like ");
266: $tdLike->appendContent($dislikeButton);
267: $tdLike->appendContent(" $dislike");
268:
269:
270: $trLike->appendContent($tdEmpty);
271: $trLike->appendContent($tdLike);
272:
273:
274: $form = new cHTMLForm($cont['id_user_forum']);
275: $form->setAttribute('action', 'main.php?' . "area=" . $area . '&frame=4');
276:
277: $tdForm = new cHTMLTableData();
278: $tdForm->setStyle('padding-left:' . $cont['level'] * $this->_indentFactor . 'px');
279:
280:
281: $tdButtons = new cHTMLTableData();
282: $tdButtons->setAttribute('valign', 'top');
283: $tdButtons->setStyle(' text-align: center');
284:
285: $tdButtons->appendContent($online);
286:
287:
288: $tdButtons->appendContent($edit);
289: if (!isset($mod)) {
290: $tdButtons->appendContent($delete);
291: }
292:
293: $tdButtons->appendContent('<br>');
294: $tdButtons->appendContent('<br>');
295:
296:
297: $hiddenIdart = new cHTMLHiddenField('idart');
298: $hiddenIdcat = new cHTMLHiddenField('idcat');
299: $hiddenId_user_forum = new cHTMLHiddenField('id_user_forum');
300: $hiddenLike = new cHTMLHiddenField('like');
301: $hiddenDislike = new cHTMLHiddenField('dislike');
302: $hiddenName = new cHTMLHiddenField('realname');
303: $hiddenEmail = new cHTMLHiddenField('email');
304: $hiddenLevel = new cHTMLHiddenField('level');
305: $hiddenEditdat = new cHTMLHiddenField('editedat');
306: $hiddenEditedby = new cHTMLHiddenField('editedby');
307: $hiddenTimestamp = new cHTMLHiddenField('timestamp');
308: $hiddenForum = new cHTMLHiddenField('forum');
309: $hiddenOnline = new cHTMLHiddenField('online');
310: $hiddenMode = new cHTMLHiddenField('mode');
311: $hiddenKey = new cHTMLHiddenField('key');
312: $hiddenaction = new cHTMLHiddenField('action');
313:
314:
315: $hiddenIdart->setValue($cont['idart']);
316: $hiddenIdcat->setValue($cont['idcat']);
317: $hiddenId_user_forum->setValue($cont['id_user_forum']);
318: $hiddenLike->setValue($cont['like']);
319: $hiddenDislike->setValue($cont['dislike']);
320: $hiddenName->setValue(str_replace('\\', '', conHtmlSpecialChars($cont['realname'])));
321: $hiddenEmail->setValue(str_replace('\\', '', conHtmlSpecialChars($cont['email'])));
322: $hiddenLevel->setValue($cont['level']);
323: $hiddenEditdat->setValue($cont['editedat']);
324: $hiddenEditedby->setValue($cont['editedby']);
325: $hiddenTimestamp->setValue($date);
326: $hiddenForum->setValue(str_replace('\\', '', conHtmlSpecialChars($cont['forum'])));
327: $hiddenOnline->setValue($cont['online']);
328: $hiddenMode->setValue('edit');
329: $hiddenKey->setValue($key);
330: $hiddenaction->setValue('edit');
331:
332:
333: $form->appendContent($hiddenIdart);
334: $form->appendContent($hiddenIdcat);
335: $form->appendContent($hiddenId_user_forum);
336: $form->appendContent($hiddenLike);
337: $form->appendContent($hiddenDislike);
338: $form->appendContent($hiddenName);
339: $form->appendContent($hiddenEmail);
340: $form->appendContent($hiddenLevel);
341: $form->appendContent($hiddenForum);
342: $form->appendContent($hiddenEditdat);
343: $form->appendContent($hiddenEditedby);
344: $form->appendContent($hiddenTimestamp);
345: $form->appendContent($hiddenMode);
346: $form->appendContent($hiddenOnline);
347: $form->appendContent($hiddenKey);
348: $form->appendContent($hiddenaction);
349:
350: if (isset($mod)) {
351: $form->appendContent(new cHTMLHiddenField('mod'));
352: }
353:
354:
355: $form->appendContent($date . " von " . str_replace('\\', '', $maili) . " <br><br>");
356: $form->appendContent((str_replace('\\', '', $text)) . "<br><br>");
357:
358: $tdForm->setContent($form);
359: $tdForm->setAttribute('valign', 'top');
360: $tr->setContent($tdForm);
361: $tr->appendContent($tdButtons);
362: $tr->appendContent($trLike);
363: $table->appendContent($tr);
364: }
365:
366: $this->appendContent($table);
367:
368: return $this;
369: }
370:
371: 372: 373: 374: 375: 376:
377: protected function ($post) {
378:
379: global $area;
380: $changes = 0;
381: $cfg = cRegistry::getConfig();
382: $idart = cRegistry::getArticleId();
383: $idcat = cRegistry::getCategoryId();
384: $menu = new cGuiMenu();
385: $tr = new cHTMLTableRow();
386:
387: $th = new cHTMLTableHead();
388: $th->setContent(UserForum::i18n("PARAMETER"));
389:
390: $th2 = new cHTMLTableHead();
391: $th2->setContent(UserForum::i18n("CONTENT"));
392: $th2->setStyle('widht:50px');
393: $th2->setAttribute('valign', 'top');
394: $tr->appendContent($th);
395: $tr->appendContent($th2);
396:
397:
398: $form1 = new cGuiTableForm("comment", "main.php?area=user_forum&frame=4", "post");
399: $form1->addHeader($tr);
400: $form1->setTableID("table");
401:
402: $user = new cApiUser();
403: $user->loadByPrimaryKey($post['editedby']);
404: $username = $user->getField('username');
405:
406: $id = $post['id_user_forum'];
407:
408: $likeButton = new cHTMLImage($cfg['path']['images'] . 'like.png');
409: $dislikeButton = new cHTMLImage($cfg['path']['images'] . 'dislike.png');
410:
411:
412: $name = new cHTMLTextBox("realname", str_replace('\\', '',(conHtmlSpecialChars($post['realname']))), 30, 255);
413: $email = new cHTMLTextBox("email", $post['email'], 30, 255);
414: $like = new cHTMLTextBox("like", $post['like'], 7, 7);
415: $dislike = new cHTMLTextBox("dislike", $post['dislike'], 7, 7);
416:
417: $text = str_replace("<br />", "\n", conHtmlSpecialChars($post['forum']));
418: $text = str_replace('\\', '', $text);
419:
420: $forum = new cHTMLTextArea("forum", $text);
421:
422: $datearray = $this->formatTimeString($post['timestamp']);
423: $date = (empty($datearray)) ? '' : $datearray['day'] . '.' . $datearray['month'] . '.' . $datearray['year'] . ' ' . UserForum::i18n("AT") . ' ' . $datearray['hour'] . ':' . $datearray['minute'] . ' ' . UserForum::i18n("CLOCK");
424:
425: $editedatearray = $this->formatTimeString($post['editedat']);
426: $editedat = (empty($editedatearray)) ? '' : $editedatearray['day'] . '.' . $editedatearray['month'] . '.' . $editedatearray['year'] . ' ' . UserForum::i18n("AT") . ' ' . $editedatearray['hour'] . ':' . $editedatearray['minute'] . ' ' . UserForum::i18n("CLOCK");
427:
428: $timestamp = new cHTMLTextBox("timestamp", $date, 30, 255);
429: $editedat = new cHTMLTextBox("editedat", $editedat, 30, 255);
430: $editedby = new cHTMLTextBox("editedby", $username, 30, 255);
431:
432: $editedat->setDisabled(true);
433: $timestamp->setDisabled(true);
434: $editedby->setDisabled(true);
435:
436:
437: $form1->add(UserForum::i18n("USER"), $name, '');
438: $form1->add(UserForum::i18n("EMAIL"), $email, '');
439: $form1->add(UserForum::i18n("LIKE"), $like, '');
440: $form1->add(UserForum::i18n("DISLIKE"), $dislike, '');
441: $form1->add(UserForum::i18n("TIME"), $timestamp, '');
442: $form1->add(UserForum::i18n("EDITDAT"), $editedat, '');
443: $form1->add(UserForum::i18n("EDITEDBY"), $editedby, '');
444:
445:
446: if (isset($post['mod'])) {
447: $form1->setVar('mod', 'mod');
448: $form1->addCancel("main.php?area=user_forum&frame=4&action=back&mod=mod");
449: } else {
450: $form1->addCancel("main.php?area=user_forum&frame=4&action=back&idart=$idart&idcat=$idcat");
451: }
452:
453: $onlineBox = new cHTMLCheckbox("onlineState", "");
454:
455: $onlineBox->setChecked(($post['online'] == 1) ? true : false);
456: $form1->add(UserForum::i18n("ONLINE"), $onlineBox, '');
457:
458: $idart = $post['idart'];
459: $idcat = $post['idcat'];
460:
461: $form1->add(UserForum::i18n("COMMENT"), $forum, '');
462:
463:
464: $form1->setVar("id_user_forum", $post['id_user_forum']);
465: $form1->setVar("idart", $post['idart']);
466: $form1->setVar("idcat", $post['idcat']);
467: $form1->setVar("action", 'update');
468: $form1->setVar("mode", "list");
469: $form1->setVar("activeChanges", $changes);
470:
471: $this->appendContent($form1);
472:
473: return $this;
474: }
475:
476: 477: 478: 479: 480: 481: 482:
483: public function getForum($id_cat, $id_art, $id_lang) {
484: $arrUsers = $this->_collection->getExistingforum();
485:
486: $arrforum = array();
487:
488: $this->_collection->getTreeLevel($id_cat, $id_art, $id_lang, $arrUsers, $arrforum);
489: $result = array();
490: $this->normalizeArray($arrforum, $result);
491:
492: $ret = $this->getMenu($result);
493:
494: return $ret;
495: }
496:
497: 498: 499: 500: 501:
502: protected function normalizeArray($arrforum, &$result, $level = 0) {
503: if (is_array($arrforum)) {
504: foreach ($arrforum as $key => $value) {
505: $value['level'] = $level;
506: unset($value['children']);
507: $result[$key] = $value;
508: $this->normalizeArray($arrforum[$key]['children'], $result, $level + 1);
509: }
510: }
511: }
512:
513: 514: 515: 516: 517: 518: 519: 520:
521: public function receiveData(&$get, &$post) {
522: if (isset($_REQUEST['action']) && $_REQUEST['action'] != NULL) {
523: $this->switchActions();
524: }
525: }
526:
527:
528: 529:
530: public function getStartpage() {
531:
532:
533: $cGuiNotification = new cGuiNotification();
534: echo $cGuiNotification->returnNotification(cGuiNotification::LEVEL_INFO, UserForum::i18n('MODMODE'));
535: echo '<br />';
536:
537: $comments = $this->_collection->getUnmoderatedComments();
538: $this->getMenu($comments, 'mod');
539:
540: }
541:
542:
543: 544: 545: 546: 547:
548: protected function switchActions() {
549:
550: $lang = cRegistry::getLanguageId();
551: $idart = $_REQUEST['idart'];
552: $idcat = $_REQUEST['idcat'];
553: $action = $_REQUEST["action"];
554: $online = (isset($_REQUEST['onlineState'])) ? 1 : 0;
555:
556:
557: switch ($action) {
558:
559:
560: case 'online_toggle':
561: $this->_collection->toggleOnlineState($_REQUEST['online'], $_REQUEST['id_user_forum'], $idart);
562:
563: if(!isset($_REQUEST['mod'])) {
564: $this->getForum($idcat, $idart, $lang);
565: } else{
566: $this->getStartpage();
567: }
568:
569: break;
570:
571: case 'deleteComment':
572: $this->_collection->deleteHierarchy($_REQUEST['key'], $_REQUEST['level'], $idart, $idcat, $lang);
573: $this->getForum($idcat, $idart, $lang);
574: break;
575:
576: case 'update':
577: $this->_collection->updateValues($_POST['id_user_forum'], $_POST['realname'], $_POST['email'], $_POST['like'], $_POST['dislike'], $_POST['forum'], $online);
578: if(!isset($_REQUEST['mod'])) {
579: $this->getForum($idcat, $idart, $lang);
580: } else{
581: $this->getStartpage();
582: }
583:
584: break;
585: case 'show_form':
586:
587: $this->getForum($idcat, $idart, $lang);
588: break;
589: case 'edit':
590:
591: $this->getEditModeMenu($_POST);
592: break;
593:
594: case 'back':
595: if(!isset($_REQUEST['mod'])) {
596: $this->getForum($idcat, $idart, $lang);
597: } else{
598: $this->getStartpage();
599: }
600:
601: break;
602: case 'empty':
603:
604: break;
605: default:
606: $this->getForum($idcat, $idart, $lang);
607: throw new Exception('$_GET["action"] type ' . $_REQUEST["action"] . ' not implemented');
608: }
609: }
610:
611: }
612:
613: ?>