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