ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilObjForumGUI.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2012 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 require_once 'Services/Object/classes/class.ilObjectGUI.php';
5 require_once 'Services/Table/classes/class.ilTable2GUI.php';
6 require_once 'Modules/Forum/classes/class.ilForumProperties.php';
7 require_once 'Services/Form/classes/class.ilPropertyFormGUI.php';
8 require_once 'Modules/Forum/classes/class.ilForumPost.php';
9 require_once 'Modules/Forum/classes/class.ilForum.php';
10 require_once 'Modules/Forum/classes/class.ilForumTopic.php';
11 require_once 'Services/RTE/classes/class.ilRTE.php';
12 require_once 'Services/PersonalDesktop/interfaces/interface.ilDesktopItemHandling.php';
13 
14 
28 {
33 
38 
42  private $objCurrentPost;
43 
48 
52  private $is_moderator = false;
53 
58 
63 
67  private $replyEditForm;
68 
73 
77  private $hideToolbar = false;
78 
82  private $forum_overview_setting = null;
83 
87  public $object;
88 
92  public $ilias;
93 
97  private $forumObjects;
98 
103 
104  public function __construct($a_data, $a_id, $a_call_by_reference, $a_prepare_output = true)
105  {
111  global $ilCtrl, $ilAccess, $ilObjDataCache;
112 
113  $this->ctrl = $ilCtrl;
114  $this->ctrl->saveParameter($this, array('ref_id', 'cmdClass'));
115 
116  $this->type = 'frm';
117  parent::__construct($a_data, $a_id, $a_call_by_reference, false);
118 
119  $this->lng->loadLanguageModule('forum');
120 
121  $this->initSessionStorage();
122 
123  // Forum properties
124  $this->objProperties = ilForumProperties::getInstance($ilObjDataCache->lookupObjId($_GET['ref_id']));
125 
126  // Stored due to performance issues
127  $this->is_moderator = $ilAccess->checkAccess('moderate_frm', '', $_GET['ref_id']);
128 
129  // Model of current topic/thread
130  $this->objCurrentTopic = new ilForumTopic((int) $_GET['thr_pk'], $this->is_moderator);
131 
132  // Model of current post
133  $this->objCurrentPost = new ilForumPost((int) $_GET['pos_pk'], $this->is_moderator);
134 
135  $frma_set = new ilSetting('frma');
136  $this->forum_overview_setting = $frma_set->get('forum_overview');
137  }
138 
139  protected function initSessionStorage()
140  {
141  $sess = ilSession::get('frm');
142  if(!is_array($sess))
143  {
144  $sess = array();
145  ilSession::set('frm', $sess);
146  }
147 
148  if(isset($_GET['thr_fk']) && !is_array($sess[(int)$_GET['thr_fk']]))
149  {
150  $sess[(int)$_GET['thr_fk']] = array();
151  ilSession::set('frm', $sess);
152  }
153  }
154 
155  public function executeCommand()
156  {
163  global $ilNavigationHistory, $ilAccess, $ilCtrl, $ilTabs;
164 
165  $next_class = $this->ctrl->getNextClass($this);
166  $cmd = $this->ctrl->getCmd();
167 
168  $exclude_cmds = array(
169  'viewThread', 'markPostUnread','markPostRead', 'showThreadNotification',
170  'cancelPostActivation', 'cancelPostDeactivation',
171  'performPostActivation', 'performPostDeactivation', 'performPostAndChildPostsActivation',
172  'askForPostActivation', 'askForPostDeactivation',
173  'toggleThreadNotification', 'toggleThreadNotificationTab',
174  'toggleStickiness', 'cancelPost', 'savePost', 'quotePost', 'getQuotationHTMLAsynch',
175  'setTreeStateAsynch', 'fetchTreeChildrenAsync'
176  );
177 
178  if(!in_array($cmd, $exclude_cmds))
179  {
180  $this->prepareOutput();
181  }
182 
183  // add entry to navigation history
184  if(!$this->getCreationMode() && !$ilCtrl->isAsynch() && $ilAccess->checkAccess('read', '', $_GET['ref_id']))
185  {
186  $ilNavigationHistory->addItem($_GET['ref_id'],
187  'ilias.php?baseClass=ilRepositoryGUI&amp;cmd=showThreads&amp;ref_id='.$_GET['ref_id'], 'frm');
188  }
189 
190  switch ($next_class)
191  {
192  case 'ilpermissiongui':
193  require_once 'Services/AccessControl/classes/class.ilPermissionGUI.php';
194  $perm_gui = new ilPermissionGUI($this);
195  $this->ctrl->forwardCommand($perm_gui);
196  break;
197 
198  case 'ilforumexportgui':
199  require_once 'Modules/Forum/classes/class.ilForumExportGUI.php';
200  $fex_gui = new ilForumExportGUI($this);
201  $this->ctrl->forwardCommand($fex_gui);
202  exit();
203  break;
204 
205  case 'ilforummoderatorsgui':
206  require_once 'Modules/Forum/classes/class.ilForumModeratorsGUI.php';
207  $fm_gui = new ilForumModeratorsGUI($this);
208  $this->ctrl->forwardCommand($fm_gui);
209  break;
210 
211  case 'ilinfoscreengui':
212  $this->infoScreen();
213  break;
214 
215  case 'ilcolumngui':
216  $this->showThreadsObject();
217  break;
218 
219  case 'ilpublicuserprofilegui':
220  include_once 'Services/User/classes/class.ilPublicUserProfileGUI.php';
221  $profile_gui = new ilPublicUserProfileGUI((int)$_GET['user']);
222  $add = $this->getUserProfileAdditional((int)$_GET['ref_id'], (int)$_GET['user']);
223  $profile_gui->setAdditional($add);
224  $ret = $this->ctrl->forwardCommand($profile_gui);
225  $this->tpl->setContent($ret);
226  break;
227 
228  case 'ilobjectcopygui':
229  include_once 'Services/Object/classes/class.ilObjectCopyGUI.php';
230  $cp = new ilObjectCopyGUI($this);
231  $cp->setType('frm');
232  $this->ctrl->forwardCommand($cp);
233  break;
234 
235  case 'ilexportgui':
236  $ilTabs->setTabActive('export');
237  include_once 'Services/Export/classes/class.ilExportGUI.php';
238  $exp = new ilExportGUI($this);
239  $exp->addFormat('xml');
240  $this->ctrl->forwardCommand($exp);
241  break;
242 
243  case 'ilcommonactiondispatchergui':
244  include_once 'Services/Object/classes/class.ilCommonActionDispatcherGUI.php';
246  $this->ctrl->forwardCommand($gui);
247  break;
248 
249  default:
250  // alex, 11 Jan 2011:
251  // I inserted this workaround due to bug report 6971.
252  // In general the command handling is quite obscure here.
253  // The form action of the table should be filled
254  // with $ilCtrl->getFormAction(..) not with $ilCtrl->getLinkTarget(..)
255  // Commands should be determined with $ilCtrl->getCmd() not
256  // with accessing $_POST['selected_cmd'], since this is internal
257  // of ilTable2GUI/ilCtrl and may change.
258  if(isset($_POST['select_cmd2']))
259  {
260  $_POST['selected_cmd'] = $_POST["selected_cmd2"];
261  }
262 
263  if(isset($_POST['selected_cmd']) && $_POST['selected_cmd'] != null)
264  {
265  $member_cmd = array('enableAdminForceNoti', 'disableAdminForceNoti', 'enableHideUserToggleNoti', 'disableHideUserToggleNoti');
266  in_array($_POST['selected_cmd'], $member_cmd) ? $cmd = $_POST['selected_cmd'] : $cmd = 'performThreadsAction';
267  }
268  else if(!$cmd && !$_POST['selected_cmd'] )
269  {
270  $cmd = 'showThreads';
271  }
272 
273  $cmd .= 'Object';
274  $this->$cmd();
275 
276  break;
277  }
278 
279  // suppress for topic level
280  if($cmd != 'viewThreadObject' && $cmd != 'showUserObject')
281  {
282  $this->addHeaderAction();
283  }
284  }
285 
286  protected function initEditCustomForm(ilPropertyFormGUI $a_form)
287  {
291  global $ilSetting;
292 
293  $this->settingsTabs();
294 
295  $rg_pro = new ilRadioGroupInputGUI($this->lng->txt('frm_default_view'), 'default_view');
296 
297  $rg_pro->addOption(new ilRadioOption($this->lng->txt('sort_by_posts'), ilForumProperties::VIEW_TREE));
298  $rg_sort_by_date = new ilRadioOption($this->lng->txt('sort_by_date'), ilForumProperties::VIEW_DATE);
299  $rg_pro->addOption($rg_sort_by_date);
300 
301  $view_direction_group_gui = new ilRadioGroupInputGUI('', 'default_view_sort_dir');
302  $view_desc = new ilRadioOption($this->lng->txt('descending_order'), ilForumProperties::VIEW_DATE_DESC);
303  $view_asc = new ilRadioOption($this->lng->txt('ascending_order'), ilForumProperties::VIEW_DATE_ASC);
304  $view_direction_group_gui->addOption($view_desc);
305  $view_direction_group_gui->addOption($view_asc);
306 
307  $rg_sort_by_date->addSubItem($view_direction_group_gui);
308  $a_form->addItem($rg_pro);
309 
310  if($ilSetting->get('enable_anonymous_fora') || $this->objProperties->isAnonymized())
311  {
312  $cb_prop = new ilCheckboxInputGUI($this->lng->txt('frm_anonymous_posting'), 'anonymized');
313  $cb_prop->setValue('1');
314  $cb_prop->setInfo($this->lng->txt('frm_anonymous_posting_desc'));
315  $a_form->addItem($cb_prop);
316  }
317 
318  if($ilSetting->get('enable_fora_statistics', false))
319  {
320  $cb_prop = new ilCheckboxInputGUI($this->lng->txt('frm_statistics_enabled'), 'statistics_enabled');
321  $cb_prop->setValue('1');
322  $cb_prop->setInfo($this->lng->txt('frm_statistics_enabled_desc'));
323  $a_form->addItem($cb_prop);
324  }
325 
326  $cb_prop = new ilCheckboxInputGUI($this->lng->txt('activate_new_posts'), 'post_activation');
327  $cb_prop->setValue('1');
328  $cb_prop->setInfo($this->lng->txt('post_activation_desc'));
329  $a_form->addItem($cb_prop);
330 
331  $frm_subject = new ilRadioGroupInputGUI($this->lng->txt('frm_subject_setting'), 'subject_setting');
332  $frm_subject->addOption(new ilRadioOption($this->lng->txt('preset_subject'), 'preset_subject'));
333  $frm_subject->addOption(new ilRadioOption($this->lng->txt('add_re_to_subject'), 'add_re_to_subject'));
334  $frm_subject->addOption(new ilRadioOption($this->lng->txt('empty_subject'), 'empty_subject'));
335 
336  $a_form->addItem($frm_subject);
337 
338  $cb_prop = new ilCheckboxInputGUI($this->lng->txt('mark_moderator_posts'), 'mark_mod_posts');
339  $cb_prop->setValue('1');
340  $cb_prop->setInfo($this->lng->txt('mark_moderator_posts_desc'));
341  $a_form->addItem($cb_prop);
342  }
343 
344  protected function getEditFormCustomValues(Array &$a_values)
345  {
346  $a_values["desc"] = $this->object->getLongDescription();
347  $a_values['default_view'] = $this->objProperties->getDefaultView();
348  $a_values['anonymized'] = $this->objProperties->isAnonymized();
349  $a_values['statistics_enabled'] = $this->objProperties->isStatisticEnabled();
350  $a_values['post_activation'] = $this->objProperties->isPostActivationEnabled();
351  $a_values['subject_setting'] = $this->objProperties->getSubjectSetting();
352  $a_values['mark_mod_posts'] = $this->objProperties->getMarkModeratorPosts();
353 
354  $default_view =
355  in_array((int)$this->objProperties->getDefaultView(), array(ilForumProperties::VIEW_DATE_ASC, ilForumProperties::VIEW_DATE_DESC))
358  $a_values['default_view'] = $default_view;
359 
360  $default_view_sort_dir =
361  (int)$this->objProperties->getDefaultView() != (int)ilForumProperties::VIEW_TREE
362  ? (int)$this->objProperties->getDefaultView()
364 
365  $a_values['default_view_sort_dir'] = $default_view_sort_dir;
366  }
367 
368  protected function updateCustom(ilPropertyFormGUI $a_form)
369  {
373  global $ilSetting;
374 
375  $view = (int)$_POST['default_view'];
376  if($view == ilForumProperties::VIEW_DATE)
377  {
379  if((int)$_POST['default_view_sort_dir'] == ilForumProperties::VIEW_DATE_DESC)
380  {
382  }
383  }
384  $this->objProperties->setDefaultView($view);
385 
386  // BUGFIX FOR 11271
387  if(isset($_SESSION['viewmode']))
388  {
389  $_SESSION['viewmode'] = $view;
390  }
391 
392  if($ilSetting->get('enable_anonymous_fora') || $this->objProperties->isAnonymized())
393  {
394  $this->objProperties->setAnonymisation((int) $a_form->getInput('anonymized'));
395  }
396  if($ilSetting->get('enable_fora_statistics', false))
397  {
398  $this->objProperties->setStatisticsStatus((int) $a_form->getInput('statistics_enabled'));
399  }
400  $this->objProperties->setPostActivation((int) $a_form->getInput('post_activation'));
401  $this->objProperties->setSubjectSetting( $a_form->getInput('subject_setting'));
402  $this->objProperties->setMarkModeratorPosts((int) $a_form->getInput('mark_mod_posts'));
403  $this->objProperties->update();
404  }
405 
410  private function getThreadEditingForm($a_thread_id)
411  {
412  $form = new ilPropertyFormGUI();
413  $this->ctrl->setParameter($this, 'thr_pk', $a_thread_id);
414  $form->setFormAction($this->ctrl->getFormAction($this, 'updateThread'));
415 
416  $ti_prop = new ilTextInputGUI($this->lng->txt('title'), 'title');
417  $ti_prop->setRequired(true);
418  $ti_prop->setMaxLength(255);
419  $ti_prop->setSize(50);
420  $form->addItem($ti_prop);
421 
422  $form->addCommandButton('updateThread', $this->lng->txt('save'));
423  $form->addCommandButton('showThreads', $this->lng->txt('cancel'));
424 
425  return $form;
426  }
427 
432  public function editThreadObject($a_thread_id, ilPropertyFormGUI $form = null)
433  {
437  global $ilTabs;
438 
439  if(!$this->is_moderator)
440  {
441  $this->ilias->raiseError($this->lng->txt('permission_denied'), $this->ilias->error_obj->MESSAGE);
442  }
443 
444  $ilTabs->setTabActive('forums_threads');
445 
446  if(!($form instanceof ilPropertyFormGUI))
447  {
448  $form = $this->getThreadEditingForm($a_thread_id);
449  $form->setValuesByArray(array(
450  'title' => ilForumTopic::_lookupTitle($a_thread_id)
451  ));
452  }
453 
454  $this->tpl->setContent($form->getHTML());
455  }
456 
460  public function updateThreadObject()
461  {
462  if(!$this->is_moderator)
463  {
464  $this->ilias->raiseError($this->lng->txt('permission_denied'), $this->ilias->error_obj->MESSAGE);
465  }
466 
467  if(!$this->objCurrentTopic->getId())
468  {
469  $this->showThreadsObject();
470  return;
471  }
472 
473  $forum_id = ilObjForum::lookupForumIdByObjId($this->object->getId());
474  if($this->objCurrentTopic->getForumId() != $forum_id)
475  {
476  $this->ilias->raiseError($this->lng->txt('permission_denied'), $this->ilias->error_obj->MESSAGE);
477  }
478 
479  $form = $this->getThreadEditingForm($this->objCurrentTopic->getId());
480  if(!$form->checkInput())
481  {
482  $form->setValuesByPost();
483  $this->editThreadObject($this->objCurrentTopic->getId(), $form);
484  return;
485  }
486 
487  $this->objCurrentTopic->setSubject($form->getInput('title'));
488  $this->objCurrentTopic->updateThreadTitle();
489 
490  ilUtil::sendSuccess($this->lng->txt('saved_successfully'));
491  $this->showThreadsObject();
492  }
493 
494  public function markAllReadObject()
495  {
499  global $ilUser;
500 
501  $this->object->markAllThreadsRead($ilUser->getId());
502 
503  ilUtil::sendInfo($this->lng->txt('forums_all_threads_marked_read'));
504 
505  $this->showThreadsObject();
506  }
507 
508  public function showThreadsObject()
509  {
510  $this->tpl->setRightContent($this->getRightColumnHTML());
511  $this->getCenterColumnHTML();
512  }
513 
514  public function getContent()
515  {
522  global $ilUser, $ilAccess, $lng, $ilToolbar;
523 
524  if(!$ilAccess->checkAccess('read', '', $this->object->getRefId()))
525  {
526  $this->ilias->raiseError($lng->txt('permission_denied'), $this->ilias->error_obj->MESSAGE);
527  }
528 
529  $frm = $this->object->Forum;
530  $frm->setForumId($this->object->getId());
531  $frm->setForumRefId($this->object->getRefId());
532  $frm->setMDB2Wherecondition('top_frm_fk = %s ', array('integer'), array($frm->getForumId()));
533 
534  $this->tpl->addBlockFile('ADM_CONTENT', 'adm_content', 'tpl.forums_threads_liste.html', 'Modules/Forum');
535 
536  if((int)strlen($this->confirmation_gui_html))
537  {
538  $this->tpl->setVariable('CONFIRMATION_GUI', $this->confirmation_gui_html);
539  }
540 
541  // Create topic button
542  if($ilAccess->checkAccess('add_thread', '', $this->object->getRefId()) && !$this->hideToolbar())
543  {
544  $ilToolbar->addButton($this->lng->txt('forums_new_thread'), $this->ctrl->getLinkTarget($this, 'createThread'));
545  }
546 
547  // Mark all topics as read button
548  include_once 'Services/Accessibility/classes/class.ilAccessKeyGUI.php';
549  if($ilUser->getId() != ANONYMOUS_USER_ID && !(int)strlen($this->confirmation_gui_html))
550  {
551  $ilToolbar->addButton(
552  $this->lng->txt('forums_mark_read'),
553  $this->ctrl->getLinkTarget($this, 'markAllRead'),
554  '',
556  );
557  $this->ctrl->clearParameters($this);
558  }
559 
560  // Import information: Topic (variable $topicData) means frm object, not thread
561  $topicData = $frm->getOneTopic();
562  if($topicData)
563  {
564  // Visit-Counter
565  $frm->setDbTable('frm_data');
566  $frm->setMDB2WhereCondition('top_pk = %s ', array('integer'), array($topicData['top_pk']));
567  $frm->updateVisits($topicData['top_pk']);
568 
569  include_once 'Modules/Forum/classes/class.ilForumTopicTableGUI.php';
570  $tbl = new ilForumTopicTableGUI($this, 'showThreads', '', (int) $_GET['ref_id'], $topicData, $this->is_moderator, $this->forum_overview_setting);
571  $tbl->setMapper($frm)->fetchData();
572  $this->tpl->setVariable('THREADS_TABLE', $tbl->getHTML());
573  }
574 
575  // Permanent link
576  include_once 'Services/PermanentLink/classes/class.ilPermanentLinkGUI.php';
577  $permalink = new ilPermanentLinkGUI('frm', $this->object->getRefId());
578  $this->tpl->setVariable('PRMLINK', $permalink->getHTML());
579  }
580 
584  private function initForumCreateForm($object_type)
585  {
586  $this->create_form_gui = new ilPropertyFormGUI();
587  $this->create_form_gui->setTableWidth('600px');
588 
589  $this->create_form_gui->setTitle($this->lng->txt('frm_new'));
590  $this->create_form_gui->setTitleIcon(ilUtil::getImagePath('icon_frm.png'));
591 
592  // form action
593  $this->ctrl->setParameter($this, 'new_type', $object_type);
594  $this->create_form_gui->setFormAction($this->ctrl->getFormAction($this, 'save'));
595 
596  // title
597  $title_gui = new ilTextInputGUI($this->lng->txt('title'), 'title');
598  $title_gui->setMaxLength(128);
599  $this->create_form_gui->addItem($title_gui);
600 
601  // description
602  $description_gui = new ilTextAreaInputGUI($this->lng->txt('desc'), 'desc');
603  $description_gui->setCols(40);
604  $description_gui->setRows(2);
605  $this->create_form_gui->addItem($description_gui);
606 
607  // view
608  $view_group_gui = new ilRadioGroupInputGUI($this->lng->txt('frm_default_view'), 'sort');
609  $view_hir = new ilRadioOption($this->lng->txt('order_by').' '.$this->lng->txt('answers'), ilForumProperties::VIEW_TREE);
610  $view_group_gui->addOption($view_hir);
611  $view_dat = new ilRadioOption($this->lng->txt('order_by').' '.$this->lng->txt('date'), ilForumProperties::VIEW_DATE);
612  $view_group_gui->addOption($view_dat);
613  $this->create_form_gui->addItem($view_group_gui);
614  $view_direction_group_gui = new ilRadioGroupInputGUI('', 'default_view_sort_dir');
615  $view_desc = new ilRadioOption($this->lng->txt('frm_post_sort_desc'), ilForumProperties::VIEW_DATE_DESC);
616  $view_direction_group_gui->addOption($view_desc);
617  $view_asc = new ilRadioOption($this->lng->txt('frm_post_sort_asc'), ilForumProperties::VIEW_DATE_ASC);
618  $view_direction_group_gui->addOption($view_asc);
619  $view_dat->addSubItem($view_direction_group_gui);
620 
621  // anonymized or not
622  $anonymize_gui = new ilCheckboxInputGUI($this->lng->txt('frm_anonymous_posting'), 'anonymized');
623  $anonymize_gui->setInfo($this->lng->txt('frm_anonymous_posting_desc'));
624  $anonymize_gui->setValue(1);
625 
626  if($this->ilias->getSetting('enable_anonymous_fora', false))
627  $anonymize_gui->setDisabled(true);
628  $this->create_form_gui->addItem($anonymize_gui);
629 
630  // statistics enabled or not
631  $statistics_gui = new ilCheckboxInputGUI($this->lng->txt('frm_statistics_enabled'), 'statistics_enabled');
632  $statistics_gui->setInfo($this->lng->txt('frm_statistics_enabled_desc'));
633  $statistics_gui->setValue(1);
634  if(!$this->ilias->getSetting('enable_fora_statistics', false))
635  $statistics_gui->setDisabled(true);
636  $this->create_form_gui->addItem($statistics_gui);
637 
638  $cb_prop = new ilCheckboxInputGUI($this->lng->txt('activate_new_posts'), 'post_activation');
639  $cb_prop->setValue('1');
640  $cb_prop->setInfo($this->lng->txt('post_activation_desc'));
641  $this->create_form_gui->addItem($cb_prop);
642 
643  $this->create_form_gui->addCommandButton('save', $this->lng->txt('save'));
644  $this->create_form_gui->addCommandButton('cancel', $this->lng->txt('cancel'));
645  }
646 
647  public function cancelObject($in_rep = false)
648  {
649  ilUtil::sendInfo($this->lng->txt('msg_cancel'), true);
650  ilUtil::redirect('ilias.php?baseClass=ilRepositoryGUI&cmd=frameset&ref_id='.$_GET['ref_id']);
651  }
652 
653  protected function afterSave(ilObjForum $forumObj)
654  {
658  global $rbacadmin;
659 
660  // save settings
661  $this->objProperties->setObjId($forumObj->getId());
662  $this->objProperties->setDefaultView(1);
663  $this->objProperties->setAnonymisation(0);
664  $this->objProperties->setStatisticsStatus(0);
665  $this->objProperties->setPostActivation(0);
666  $this->objProperties->insert();
667 
668  $forumObj->createSettings();
669 
670  // ...finally assign moderator role to creator of forum object
671  $roles = array();
672  $roles[0] = ilObjForum::_lookupModeratorRole($forumObj->getRefId());
673 
674  $rbacadmin->assignUser($roles[0], $forumObj->getOwner(), 'n');
675 
676  // insert new forum as new topic into frm_data
677  $forumObj->saveData($roles);
678 
679  // always send a message
680  ilUtil::sendSuccess($this->lng->txt('frm_added'), true);
681 
682  $this->ctrl->setParameter($this, 'ref_id', $forumObj->getRefId());
683  ilUtil::redirect($this->ctrl->getLinkTarget($this, 'createThread', '', false, false));
684  }
685 
686  public function getTabs(ilTabsGUI $tabs_gui)
687  {
693  global $ilAccess, $ilHelp, $ilCtrl;
694 
695  $ilHelp->setScreenIdComponent("frm");
696 
697  $this->ctrl->setParameter($this, 'ref_id', $this->ref_id);
698 
699  include_once 'Services/Repository/classes/class.ilRepositoryExplorer.php';
700  $active = array(
701  '', 'showThreads', 'view', 'markAllRead',
702  'enableForumNotification', 'disableForumNotification', 'moveThreads', 'performMoveThreads',
703  'cancelMoveThreads', 'performThreadsAction', 'createThread', 'addThread',
704  'showUser', 'confirmDeleteThreads'
705  );
706 
707  (in_array($ilCtrl->getCmd(), $active)) ? $force_active = true : $force_active = false;
708  $tabs_gui->addTarget('forums_threads', $this->ctrl->getLinkTarget($this,'showThreads'), $ilCtrl->getCmd(), get_class($this), '', $force_active);
709 
710  // info tab
711  if($ilAccess->checkAccess('visible', '', $this->ref_id))
712  {
713  $force_active = ($this->ctrl->getNextClass() == 'ilinfoscreengui' || strtolower($_GET['cmdClass']) == 'ilnotegui') ? true : false;
714  $tabs_gui->addTarget('info_short',
715  $this->ctrl->getLinkTargetByClass(
716  array('ilobjforumgui', 'ilinfoscreengui'), 'showSummary'),
717  array('showSummary', 'infoScreen'),
718  '', '', $force_active);
719  }
720 
721  if($ilAccess->checkAccess('write', '', $this->ref_id))
722  {
723  $force_active = ($ilCtrl->getCmd() == 'edit') ? true : false;
724  $tabs_gui->addTarget('settings', $this->ctrl->getLinkTarget($this, 'edit'), 'edit', get_class($this), '', $force_active);
725  }
726 
727  if($ilAccess->checkAccess('write', '', $this->ref_id))
728  {
729  $tabs_gui->addTarget('frm_moderators', $this->ctrl->getLinkTargetByClass('ilForumModeratorsGUI', 'showModerators'), 'showModerators', get_class($this));
730  }
731 
732  if($this->ilias->getSetting('enable_fora_statistics', false) &&
733  ($this->objProperties->isStatisticEnabled() || $ilAccess->checkAccess('write', '', $this->ref_id)))
734  {
735  $force_active = ($ilCtrl->getCmd() == 'showStatistics') ? true : false;
736  $tabs_gui->addTarget('frm_statistics', $this->ctrl->getLinkTarget($this, 'showStatistics'), 'showStatistics', get_class($this), '', $force_active); //false
737  }
738 
739  if($ilAccess->checkAccess('write', '', $this->object->getRefId()))
740  {
741  $tabs_gui->addTarget('export', $this->ctrl->getLinkTargetByClass('ilexportgui', ''), '', 'ilexportgui');
742  }
743 
744  if($ilAccess->checkAccess('edit_permission', '', $this->ref_id))
745  {
746  $tabs_gui->addTarget('perm_settings', $this->ctrl->getLinkTargetByClass(array(get_class($this),'ilpermissiongui'), 'perm'), array('perm', 'info', 'owner'), 'ilpermissiongui');
747  }
748  }
749 
750  public function settingsTabs()
751  {
757  global $ilTabs, $ilAccess, $tree;
758 
759  $ilTabs->setTabActive('settings');
760  $ilTabs->addSubTabTarget('basic_settings', $this->ctrl->getLinkTarget($this, 'edit'), 'edit', get_class($this), '', $_GET['cmd']=='edit'? true : false );
761 
762  // notification tab
763  if($this->ilias->getSetting('forum_notification') > 0)
764  {
765  // check if there a parent-node is a grp or crs
766  $grp_ref_id = $tree->checkForParentType($this->object->getRefId(), 'grp');
767  $crs_ref_id = $tree->checkForParentType($this->object->getRefId(), 'crs');
768 
769  if((int)$grp_ref_id > 0 || (int)$crs_ref_id > 0 )
770  {
771  #show member-tab for notification if forum-notification is enabled in administration
772  if($ilAccess->checkAccess('write', '', $this->ref_id))
773  {
774  $mem_active = array('showMembers', 'forums_notification_settings');
775  (in_array($_GET['cmd'],$mem_active)) ? $force_mem_active = true : $force_mem_active = false;
776 
777  $ilTabs->addSubTabTarget('notifications', $this->ctrl->getLinkTarget($this, 'showMembers'), $_GET['cmd'], get_class($this), '', $force_mem_active);
778  }
779  }
780  }
781  return true;
782  }
783 
784  public function showStatisticsObject()
785  {
789  global $ilAccess;
790 
792  if(!$this->ilias->getSetting('enable_fora_statistics', false))
793  {
794  $this->ilias->raiseError($this->lng->txt('permission_denied'), $this->ilias->error_obj->MESSAGE);
795  }
796 
797  // if no read access -> intrusion detected
798  if(!$ilAccess->checkAccess('read', '', $_GET['ref_id']))
799  {
800  $this->ilias->raiseError($this->lng->txt('permission_denied'), $this->ilias->error_obj->MESSAGE);
801  }
802 
803  // if read access and statistics disabled -> intrusion detected
804  if(!$ilAccess->checkAccess('read', '', $_GET['ref_id']) && !$this->objProperties->isStatisticEnabled())
805  {
806  $this->ilias->raiseError($this->lng->txt('permission_denied'), $this->ilias->error_obj->MESSAGE);
807  }
808 
809  // if write access and statistics disabled -> ok, for forum admin
810  if($ilAccess->checkAccess('write', '', $_GET['ref_id']) &&
811  !$this->objProperties->isStatisticEnabled())
812  {
813  ilUtil::sendInfo($this->lng->txt('frm_statistics_disabled_for_participants'));
814  }
815 
816  $this->object->Forum->setForumId($this->object->getId());
817 
818  require_once 'Modules/Forum/classes/class.ilForumStatisticsTableGUI.php';
819 
820  $tbl = new ilForumStatisticsTableGUI($this, 'showStatistics');
821  $tbl->setId('il_frm_statistic_table_'.(int) $_GET['ref_id']);
822  $tbl->setTitle($this->lng->txt('statistic'), 'icon_usr_b.png', $this->lng->txt('obj_'.$this->object->getType()));
823 
824  $data = $this->object->Forum->getUserStatistic($this->is_moderator);
825  $result = array();
826  $counter = 0;
827  foreach($data as $row)
828  {
829  $result[$counter]['ranking'] = $row[0];
830  $result[$counter]['login'] = $row[1];
831  $result[$counter]['lastname'] = $row[2];
832  $result[$counter]['firstname'] = $row[3];
833 
834  ++$counter;
835  }
836  $tbl->setData($result);
837 
838  $this->tpl->setContent($tbl->getHTML());
839  }
840 
841  public static function _goto($a_target, $a_thread = 0, $a_posting = 0)
842  {
848  global $ilAccess, $ilErr, $lng;
849 
850  if($ilAccess->checkAccess('read', '', $a_target))
851  {
852  if($a_thread != 0)
853  {
854  $objTopic = new ilForumTopic($a_thread);
855  if ($objTopic->getFrmObjId() &&
856  $objTopic->getFrmObjId() != ilObject::_lookupObjectId($a_target))
857  {
858  $ref_ids = ilObject::_getAllReferences($objTopic->getFrmObjId());
859  foreach($ref_ids as $ref_id)
860  {
861  if($ilAccess->checkAccess('read', '', $ref_id))
862  {
863  $new_ref_id = $ref_id;
864  break;
865  }
866  }
867 
868  if (isset($new_ref_id) && $new_ref_id != $a_target)
869  {
870  ilUtil::redirect(ILIAS_HTTP_PATH."/goto.php?target=frm_".$new_ref_id."_".$a_thread."_".$a_posting);
871  }
872  }
873 
874  $_GET['ref_id'] = $a_target;
875  $_GET['pos_pk'] = $a_posting;
876  $_GET['thr_pk'] = $a_thread;
877  $_GET['anchor'] = $a_posting;
878  $_GET['cmdClass'] = 'ilObjForumGUI';
879  $_GET['cmd'] = 'viewThread';
880  $_GET['baseClass'] = 'ilRepositoryGUI';
881 
882  include_once('ilias.php');
883  exit();
884  }
885  else
886  {
887 
888  $_GET['ref_id'] = $a_target;
889  $_GET['baseClass'] = 'ilRepositoryGUI';
890  include_once('ilias.php');
891  exit();
892  }
893  }
894  else if($ilAccess->checkAccess('read', '', ROOT_FOLDER_ID))
895  {
896  $_GET['target'] = '';
897  $_GET['ref_id'] = ROOT_FOLDER_ID;
898  ilUtil::sendInfo(sprintf($lng->txt('msg_no_perm_read_item'),
900  $_GET['baseClass'] = 'ilRepositoryGUI';
901  include('ilias.php');
902  exit();
903  }
904 
905  $ilErr->raiseError($lng->txt('msg_no_perm_read'), $ilErr->FATAL);
906  }
907 
908  public function performDeleteThreadsObject()
909  {
913  global $lng;
914 
915  if(!$this->is_moderator)
916  {
917  $this->ilias->raiseError($lng->txt('permission_denied'), $this->ilias->error_obj->MESSAGE);
918  return $this->showThreadsObject();
919  }
920 
921  if(!isset($_POST['thread_ids']) || !is_array($_POST['thread_ids']))
922  {
923  ilUtil::sendInfo($this->lng->txt('select_at_least_one_thread'));
924  return $this->showThreadsObject();
925  }
926 
927  require_once 'Modules/Forum/classes/class.ilForum.php';
928  require_once 'Modules/Forum/classes/class.ilObjForum.php';
929 
930  $forumObj = new ilObjForum($_GET['ref_id']);
931 
932  $this->objProperties->setObjId($forumObj->getId());
933 
934  $frm = new ilForum();
935  foreach($_POST['thread_ids'] as $topic_id)
936  {
937  $frm->setForumId($forumObj->getId());
938  $frm->setForumRefId($forumObj->getRefId());
939 
940  $first_node = $frm->getFirstPostNode($topic_id);
941  if((int)$first_node['pos_pk'])
942  {
943  $frm->deletePost($first_node['pos_pk']);
944  ilUtil::sendInfo($lng->txt('forums_post_deleted'), true);
945  }
946  }
947 
948  $this->ctrl->redirect($this, 'showThreads');
949  }
950 
951  public function confirmDeleteThreads()
952  {
956  global $lng;
957 
958  if(!isset($_POST['thread_ids']) || !is_array($_POST['thread_ids']))
959  {
960  ilUtil::sendInfo($this->lng->txt('select_at_least_one_thread'));
961  return $this->showThreadsObject();
962  }
963 
964  if(!$this->is_moderator)
965  {
966  $this->ilias->raiseError($lng->txt('permission_denied'), $this->ilias->error_obj->MESSAGE);
967  return $this->showThreadsObject();
968  }
969 
970  include_once('Services/Utilities/classes/class.ilConfirmationGUI.php');
971  $c_gui = new ilConfirmationGUI();
972 
973  $c_gui->setFormAction($this->ctrl->getFormAction($this, 'performDeleteThreads'));
974  $c_gui->setHeaderText($this->lng->txt('frm_sure_delete_threads'));
975  $c_gui->setCancel($this->lng->txt('cancel'), 'showThreads');
976  $c_gui->setConfirm($this->lng->txt('confirm'), 'performDeleteThreads');
977 
978  foreach((array)$_POST['thread_ids'] as $thread_id)
979  {
980  $c_gui->addItem('thread_ids[]', $thread_id, ilForumTopic::_lookupTitle($thread_id));
981  }
982 
983  $this->confirmation_gui_html = $c_gui->getHTML();
984 
985  $this->hideToolbar(true);
986 
987  return $this->tpl->setContent($c_gui->getHTML());
988  }
989 
990  public function prepareThreadScreen(ilObjForum $a_forum_obj)
991  {
998  global $tpl, $lng, $ilTabs, $ilHelp;
999 
1000  $ilHelp->setScreenIdComponent("frm");
1001 
1002  $tpl->getStandardTemplate();
1003  ilUtil::sendInfo();
1005 
1006  $tpl->setTitleIcon(ilUtil::getImagePath('icon_frm_b.png'));
1007 
1008  $ilTabs->setBackTarget($lng->txt('all_topics'),
1009  'ilias.php?baseClass=ilRepositoryGUI&amp;ref_id='.$_GET['ref_id']);
1010 
1011  // by answer view
1012  $this->ctrl->setParameter($this, 'thr_pk', $this->objCurrentTopic->getId());
1013  $this->ctrl->setParameter($this, 'pos_pk', $this->objCurrentPost->getId());
1014  $this->ctrl->setParameter($this, 'viewmode', ilForumProperties::VIEW_TREE);
1015 
1016  $ilTabs->addTarget('sort_by_posts', $this->ctrl->getLinkTarget($this, 'viewThread'));
1017 
1018  // by date view
1019  $this->ctrl->setParameter($this, 'viewmode', ilForumProperties::VIEW_DATE);
1020 
1021  $this->ctrl->setParameter($this, 'thr_pk', $this->objCurrentTopic->getId());
1022  $this->ctrl->setParameter($this, 'pos_pk', $this->objCurrentPost->getId());
1023  $ilTabs->addTarget('order_by_date', $this->ctrl->getLinkTarget($this, 'viewThread'));
1024  $this->ctrl->clearParameters($this);
1025 
1026  if($_SESSION['viewmode']== 'date'
1027  ||$_SESSION['viewmode']== ilForumProperties::VIEW_DATE)
1028  {
1029  $ilTabs->setTabActive('order_by_date');
1030  }
1031  else
1032  {
1033  $ilTabs->setTabActive('sort_by_posts');
1034  }
1035 
1039  $frm = $a_forum_obj->Forum;
1040  $frm->setForumId($a_forum_obj->getId());
1041  }
1042 
1044  {
1045  if($this->is_moderator)
1046  {
1047  $this->objCurrentPost->activatePostAndChildPosts();
1048  ilUtil::sendInfo($this->lng->txt('forums_post_and_children_were_activated'), true);
1049  }
1050 
1051  $this->viewThreadObject();
1052  }
1053 
1055  {
1056  if($this->is_moderator)
1057  {
1058  $this->objCurrentPost->activatePost();
1059  ilUtil::sendInfo($this->lng->txt('forums_post_was_activated'), true);
1060  }
1061 
1062  $this->viewThreadObject();
1063  }
1064 
1065  public function cancelPostActivationObject()
1066  {
1067  $this->viewThreadObject();
1068  }
1069 
1070  public function askForPostActivationObject()
1071  {
1072  if($this->is_moderator)
1073  {
1074  $this->setDisplayConfirmPostActivation(true);
1075  }
1076 
1077  $this->viewThreadObject();
1078  }
1079 
1080  public function setDisplayConfirmPostActivation($status = 0)
1081  {
1082  $this->display_confirm_post_activation = $status;
1083  }
1084 
1086  {
1088  }
1089 
1090  public function toggleThreadNotificationObject()
1091  {
1095  global $ilUser;
1096 
1097  if($this->objCurrentTopic->isNotificationEnabled($ilUser->getId()))
1098  {
1099  $this->objCurrentTopic->disableNotification($ilUser->getId());
1100  ilUtil::sendInfo($this->lng->txt('forums_notification_disabled'), true);
1101  }
1102  else
1103  {
1104  $this->objCurrentTopic->enableNotification($ilUser->getId());
1105  ilUtil::sendInfo($this->lng->txt('forums_notification_enabled'), true);
1106  }
1107 
1108  $this->viewThreadObject();
1109  }
1110 
1111  public function toggleStickinessObject()
1112  {
1113  if($this->is_moderator)
1114  {
1115  if($this->objCurrentTopic->isSticky())
1116  {
1117  $this->objCurrentTopic->unmakeSticky();
1118  }
1119  else
1120  {
1121  $this->objCurrentTopic->makeSticky();
1122  }
1123  }
1124 
1125  $this->viewThreadObject();
1126  }
1127 
1128  public function cancelPostObject()
1129  {
1130  $_GET['action'] = '';
1131 
1132  $this->viewThreadObject();
1133  }
1134 
1135  public function getDeleteFormHTML()
1136  {
1140  global $lng;
1141 
1143  $form_tpl = new ilTemplate('tpl.frm_delete_post_form.html', true, true, 'Modules/Forum');
1144 
1145  $form_tpl->setVariable('ANKER', $this->objCurrentPost->getId());
1146  $form_tpl->setVariable('SPACER', '<hr noshade="noshade" width="100%" size="1" align="center" />');
1147  $form_tpl->setVariable('TXT_DELETE', $lng->txt('forums_info_delete_post'));
1148  $this->ctrl->setParameter($this, 'action', 'ready_delete');
1149  $this->ctrl->setParameter($this, 'pos_pk', $this->objCurrentPost->getId());
1150  $this->ctrl->setParameter($this, 'thr_pk', $this->objCurrentPost->getThreadId());
1151  $this->ctrl->setParameter($this, 'orderby', $_GET['orderby']);
1152  $form_tpl->setVariable('FORM_ACTION', $this->ctrl->getLinkTarget($this, 'viewThread'));
1153  $this->ctrl->clearParameters($this);
1154  $form_tpl->setVariable('CANCEL_BUTTON', $lng->txt('cancel'));
1155  $form_tpl->setVariable('CONFIRM_BUTTON', $lng->txt('confirm'));
1156 
1157  return $form_tpl->get();
1158  }
1159 
1160  public function getActivationFormHTML()
1161  {
1165  global $lng;
1166 
1167  $form_tpl = new ilTemplate('tpl.frm_activation_post_form.html', true, true, 'Modules/Forum');
1168 
1169  $this->ctrl->setParameter($this, 'pos_pk', $this->objCurrentPost->getId());
1170  $this->ctrl->setParameter($this, 'thr_pk', $this->objCurrentPost->getThreadId());
1171  $this->ctrl->setParameter($this, 'orderby', $_GET['orderby']);
1172  $form_tpl->setVariable('FORM_ACTION', $this->ctrl->getFormAction($this, 'performPostActivation'));
1173  $form_tpl->setVariable('SPACER', '<hr noshade="noshade" width="100%" size="1" align="center" />');
1174  $form_tpl->setVariable('ANCHOR', $this->objCurrentPost->getId());
1175  $form_tpl->setVariable('TXT_ACT', $lng->txt('activate_post_txt'));
1176  $form_tpl->setVariable('CONFIRM_BUTTON', $lng->txt('activate_only_current'));
1177  $form_tpl->setVariable('CMD_CONFIRM', 'performPostActivation');
1178  $form_tpl->setVariable('CONFIRM_BRANCH_BUTTON', $lng->txt('activate_current_and_childs'));
1179  $form_tpl->setVariable('CMD_CONFIRM_BRANCH', 'performPostAndChildPostsActivation');
1180  $form_tpl->setVariable('CANCEL_BUTTON',$lng->txt('cancel'));
1181  $form_tpl->setVariable('CMD_CANCEL', 'cancelPostActivation');
1182  $this->ctrl->clearParameters($this);
1183 
1184  return $form_tpl->get();
1185  }
1186 
1187  public function getDeactivationFormHTML()
1188  {
1192  global $lng;
1193 
1194  $form_tpl = new ilTemplate('tpl.frm_deactivation_post_form.html', true, true, 'Modules/Forum');
1195 
1196  $this->ctrl->setParameter($this, 'pos_pk', $this->objCurrentPost->getId());
1197  $this->ctrl->setParameter($this, 'thr_pk', $this->objCurrentPost->getThreadId());
1198  $this->ctrl->setParameter($this, 'orderby', $_GET['orderby']);
1199  $form_tpl->setVariable('FORM_ACTION', $this->ctrl->getFormAction($this, 'performPostDeactivation'));
1200  $form_tpl->setVariable('SPACER', '<hr noshade="noshade" width="100%" size="1" align="center" />');
1201  $form_tpl->setVariable('ANCHOR', $this->objCurrentPost->getId());
1202  $form_tpl->setVariable('TXT_DEACT', $lng->txt('deactivate_post_txt'));
1203  $form_tpl->setVariable('CONFIRM_BUTTON', $lng->txt('deactivate_current_and_childs'));
1204  $form_tpl->setVariable('CMD_CONFIRM', 'performPostDeactivation');
1205  $form_tpl->setVariable('CANCEL_BUTTON',$lng->txt('cancel'));
1206  $form_tpl->setVariable('CMD_CANCEL', 'cancelPostDeactivation');
1207  $this->ctrl->clearParameters($this);
1208 
1209  return $form_tpl->get();
1210  }
1211 
1212  public function getCensorshipFormHTML()
1213  {
1218  global $lng, $frm;
1219 
1220  $form_tpl = new ilTemplate('tpl.frm_censorship_post_form.html', true, true, 'Modules/Forum');
1221 
1222  $form_tpl->setVariable('ANCHOR', $this->objCurrentPost->getId());
1223  $form_tpl->setVariable('SPACER', '<hr noshade="noshade" width="100%" size="1" align="center" />');
1224  $this->ctrl->setParameter($this, 'action', 'ready_censor');
1225  $this->ctrl->setParameter($this, 'pos_pk', $this->objCurrentPost->getId());
1226  $this->ctrl->setParameter($this, 'thr_pk', $this->objCurrentPost->getThreadId());
1227  $this->ctrl->setParameter($this, 'orderby', $_GET['orderby']);
1228  $form_tpl->setVariable('FORM_ACTION', $this->ctrl->getLinkTarget($this, 'viewThread'));
1229  $this->ctrl->clearParameters($this);
1230  $form_tpl->setVariable('TXT_CENS_MESSAGE', $lng->txt('forums_the_post'));
1231  $form_tpl->setVariable('TXT_CENS_COMMENT', $lng->txt('forums_censor_comment').':');
1232  $form_tpl->setVariable('CENS_MESSAGE', $frm->prepareText($this->objCurrentPost->getCensorshipComment(), 2));
1233 
1234 
1235  if($this->objCurrentPost->isCensored())
1236  {
1237  $form_tpl->setVariable('TXT_CENS', $lng->txt('forums_info_censor2_post'));
1238  $form_tpl->setVariable('YES_BUTTON', $lng->txt('yes'));
1239  $form_tpl->setVariable('NO_BUTTON', $lng->txt('no'));
1240  }
1241  else
1242  {
1243  $form_tpl->setVariable('TXT_CENS', $lng->txt('forums_info_censor_post'));
1244  $form_tpl->setVariable('CANCEL_BUTTON', $lng->txt('cancel'));
1245  $form_tpl->setVariable('CONFIRM_BUTTON', $lng->txt('confirm'));
1246  }
1247 
1248  return $form_tpl->get();
1249  }
1250 
1251  private function initReplyEditForm()
1252  {
1258  global $ilUser, $rbacsystem, $ilSetting;
1259 
1260  // init objects
1261  $oForumObjects = $this->getForumObjects();
1265  $frm = $oForumObjects['frm'];
1269  $oFDForum = $oForumObjects['file_obj'];
1270 
1271  require_once 'Services/Form/classes/class.ilPropertyFormGUI.php';
1272  $this->replyEditForm = new ilPropertyFormGUI();
1273  $this->replyEditForm->setTableWidth('100%');
1274 
1275  // titel
1276  if($_GET['action'] == 'showreply' || $_GET['action'] == 'ready_showreply')
1277  {
1278  $this->ctrl->setParameter($this, 'action', 'ready_showreply');
1279  }
1280  else
1281  {
1282  $this->ctrl->setParameter($this, 'action', 'ready_showedit');
1283  }
1284 
1285  // form action
1286  $this->ctrl->setParameter($this, 'pos_pk', $this->objCurrentPost->getId());
1287  $this->ctrl->setParameter($this, 'thr_pk', $this->objCurrentPost->getThreadId());
1288  $this->ctrl->setParameter($this, 'offset', (int)$_GET['offset']);
1289  $this->ctrl->setParameter($this, 'orderby', $_GET['orderby']);
1290  $this->replyEditForm->setFormAction($this->ctrl->getFormAction($this, 'savePost', $this->objCurrentPost->getId()));
1291  $this->ctrl->clearParameters($this);
1292 
1293  if($_GET['action'] == 'showreply' || $_GET['action'] == 'ready_showreply')
1294  {
1295  $this->replyEditForm->setTitle($this->lng->txt('forums_your_reply'));
1296  }
1297  else
1298  {
1299  $this->replyEditForm->setTitle($this->lng->txt('forums_edit_post'));
1300  }
1301 
1302  // alias
1303  if($this->objProperties->isAnonymized() &&
1304  in_array($_GET['action'], array('showreply', 'ready_showreply')))
1305  {
1306  $oAnonymousNameGUI = new ilTextInputGUI($this->lng->txt('forums_your_name'), 'alias');
1307  $oAnonymousNameGUI->setMaxLength(64);
1308  $oAnonymousNameGUI->setInfo($this->lng->txt('forums_use_alias'));
1309 
1310  $this->replyEditForm->addItem($oAnonymousNameGUI);
1311  }
1312 
1313  // subject
1314  $oSubjectGUI = new ilTextInputGUI($this->lng->txt('forums_subject'), 'subject');
1315  $oSubjectGUI->setMaxLength(64);
1316  $oSubjectGUI->setRequired(true);
1317 
1318  if($this->objProperties->getSubjectSetting() == 'empty_subject')
1319  $oSubjectGUI->setInfo($this->lng->txt('enter_new_subject'));
1320 
1321  $this->replyEditForm->addItem($oSubjectGUI);
1322 
1323  // post
1324  $oPostGUI = new ilTextAreaInputGUI(
1325  $_GET['action'] == 'showreply' || $_GET['action'] == 'ready_showreply' ? $this->lng->txt('forums_your_reply') : $this->lng->txt('forums_edit_post'),
1326  'message'
1327  );
1328  $oPostGUI->setRequired(true);
1329  $oPostGUI->setCols(50);
1330  $oPostGUI->setRows(15);
1331  $oPostGUI->setUseRte(true);
1332  $oPostGUI->addPlugin('latex');
1333  $oPostGUI->addButton('latex');
1334  $oPostGUI->addButton('pastelatex');
1335  $oPostGUI->addPlugin('ilfrmquote');
1336 
1337  //$oPostGUI->addPlugin('code');
1338  if($_GET['action'] == 'showreply' || $_GET['action'] == 'ready_showreply')
1339  {
1340  $oPostGUI->addButton('ilFrmQuoteAjaxCall');
1341  }
1342  $oPostGUI->removePlugin('advlink');
1343  $oPostGUI->setRTERootBlockElement('');
1344  $oPostGUI->usePurifier(true);
1345  $oPostGUI->disableButtons(array(
1346  'charmap',
1347  'undo',
1348  'redo',
1349  'justifyleft',
1350  'justifycenter',
1351  'justifyright',
1352  'justifyfull',
1353  'anchor',
1354  'fullscreen',
1355  'cut',
1356  'copy',
1357  'paste',
1358  'pastetext',
1359  'formatselect'
1360  ));
1361 
1362  if($_GET['action'] == 'showreply' || $_GET['action'] == 'ready_showreply')
1363  {
1364  $oPostGUI->setRTESupport($ilUser->getId(), 'frm~', 'frm_post', 'tpl.tinymce_frm_post.html', false, '3.4.7');
1365  }
1366  else
1367  {
1368  $oPostGUI->setRTESupport($this->objCurrentPost->getId(), 'frm', 'frm_post', 'tpl.tinymce_frm_post.html', false, '3.4.7');
1369  }
1370  // purifier
1371  require_once 'Services/Html/classes/class.ilHtmlPurifierFactory.php';
1372  $oPostGUI->setPurifier(ilHtmlPurifierFactory::_getInstanceByType('frm_post'));
1373 
1374  $this->replyEditForm->addItem($oPostGUI);
1375 
1376  // notification only if gen. notification is disabled and forum isn't anonymous
1377  include_once 'Services/Mail/classes/class.ilMail.php';
1378  $umail = new ilMail($ilUser->getId());
1379  if($rbacsystem->checkAccess('internal_mail', $umail->getMailObjectReferenceId()) &&
1380  !$frm->isThreadNotificationEnabled($ilUser->getId(), $this->objCurrentPost->getThreadId()) &&
1381  !$this->objProperties->isAnonymized())
1382  {
1383  $oNotificationGUI = new ilCheckboxInputGUI('', 'notify');
1384  $oNotificationGUI->setInfo($this->lng->txt('forum_notify_me'));
1385 
1386  $this->replyEditForm->addItem($oNotificationGUI);
1387  }
1388 
1389  // attachments
1390  $oFileUploadGUI = new ilFileWizardInputGUI($this->lng->txt('forums_attachments_add'), 'userfile');
1391  $oFileUploadGUI->setFilenames(array(0 => ''));
1392  $this->replyEditForm->addItem($oFileUploadGUI);
1393 
1394  if ($ilUser->getId() == ANONYMOUS_USER_ID &&
1395  $ilSetting->get('activate_captcha_anonym'))
1396  {
1397  include_once("./Services/Captcha/classes/class.ilCaptchaInputGUI.php");
1398  $captcha = new ilCaptchaInputGUI($this->lng->txt("cont_captcha_code"), 'captcha_code');
1399  $captcha->setRequired(true);
1400  $this->replyEditForm->addItem($captcha);
1401  }
1402 
1403  // edit attachments
1404  if(count($oFDForum->getFilesOfPost()) && ($_GET['action'] == 'showedit' || $_GET['action'] == 'ready_showedit'))
1405  {
1406  $oExistingAttachmentsGUI = new ilCheckboxGroupInputGUI($this->lng->txt('forums_delete_file'), 'del_file');
1407 
1408  foreach($oFDForum->getFilesOfPost() as $file)
1409  {
1410  $oAttachmentGUI = new ilCheckboxInputGUI($file['name'], 'del_file');
1411  $oAttachmentGUI->setValue($file['md5']);
1412  $oExistingAttachmentsGUI->addOption($oAttachmentGUI);
1413  }
1414  $this->replyEditForm->addItem($oExistingAttachmentsGUI);
1415  }
1416 
1417  // buttons
1418  $this->replyEditForm->addCommandButton('savePost', $this->lng->txt('submit'));
1419  if($_GET['action'] == 'showreply' || $_GET['action'] == 'ready_showreply')
1420  {
1421  include_once 'Services/RTE/classes/class.ilRTE.php';
1422  $rtestring = ilRTE::_getRTEClassname();
1423 
1424  if(array_key_exists('show_rte', $_POST))
1425  {
1427  }
1428 
1429  if(strtolower($rtestring) != 'iltinymce' || !ilObjAdvancedEditing::_getRichTextEditorUserState())
1430  {
1431  $this->replyEditForm->addCommandButton('quotePost', $this->lng->txt('forum_add_quote'));
1432  }
1433  }
1434  $this->replyEditForm->addCommandButton('cancelPost', $this->lng->txt('cancel'));
1435  }
1436 
1437  private function getReplyEditForm()
1438  {
1439  if(null === $this->replyEditForm)
1440  {
1441  $this->initReplyEditForm();
1442  }
1443 
1444  return $this->replyEditForm;
1445  }
1446 
1447  public function savePostObject()
1448  {
1454  global $ilUser, $ilAccess, $lng;
1455 
1456  if(!isset($_POST['del_file']) || !is_array($_POST['del_file'])) $_POST['del_file'] = array();
1457 
1458  if($this->objCurrentTopic->isClosed())
1459  {
1460  $_GET['action'] = '';
1461  return $this->viewThreadObject();
1462  }
1463 
1464  $oReplyEditForm = $this->getReplyEditForm();
1465  if($oReplyEditForm->checkInput())
1466  {
1467  // init objects
1468  $oForumObjects = $this->getForumObjects();
1472  $forumObj = $oForumObjects['forumObj'];
1476  $frm = $oForumObjects['frm'];
1477  $frm->setMDB2WhereCondition(' top_frm_fk = %s ', array('integer'), array($frm->getForumId()));
1478  $topicData = $frm->getOneTopic();
1479 
1480  // Generating new posting
1481  if($_GET['action'] == 'ready_showreply')
1482  {
1483  if(!$ilAccess->checkAccess('add_reply', '', (int)$_GET['ref_id']))
1484  {
1485  $this->ilias->raiseError($lng->txt('permission_denied'), $this->ilias->error_obj->MESSAGE);
1486  }
1487 
1488  // reply: new post
1489  $status = 1;
1490  $send_activation_mail = 0;
1491 
1492  if($this->objProperties->isPostActivationEnabled())
1493  {
1494  if(!$this->is_moderator)
1495  {
1496  $status = 0;
1497  $send_activation_mail = 1;
1498  }
1499  else if($this->objCurrentPost->isAnyParentDeactivated())
1500  {
1501  $status = 0;
1502  }
1503  }
1504 
1505  if($this->objProperties->isAnonymized())
1506  {
1507  if(!strlen($oReplyEditForm->getInput('alias')))
1508  {
1509  $user_alias = $this->lng->txt('forums_anonymous');
1510  }
1511  else
1512  {
1513  $user_alias = $oReplyEditForm->getInput('alias');
1514  }
1515  }
1516  else
1517  {
1518  $user_alias = $ilUser->getLogin();
1519  }
1520 
1521  $newPost = $frm->generatePost(
1522  $topicData['top_pk'],
1523  $this->objCurrentTopic->getId(),
1524  ($this->objProperties->isAnonymized() ? 0 : $ilUser->getId()),
1525  ilRTE::_replaceMediaObjectImageSrc($oReplyEditForm->getInput('message'), 0),
1526  $this->objCurrentPost->getId(),
1527  (int)$oReplyEditForm->getInput('notify'),
1528  $this->handleFormInput($oReplyEditForm->getInput('subject'), false),
1529  $user_alias,
1530  '',
1531  $status,
1532  $send_activation_mail
1533  );
1534 
1535  // mantis #8115: Mark parent as read
1536  $this->object->markPostRead($ilUser->getId(), (int) $this->objCurrentTopic->getId(), (int) $this->objCurrentPost->getId());
1537 
1538  // copy temporary media objects (frm~)
1539  include_once 'Services/MediaObjects/classes/class.ilObjMediaObject.php';
1540  $mediaObjects = ilRTE::_getMediaObjects($oReplyEditForm->getInput('message'), 0);
1541  $myMediaObjects = ilObjMediaObject::_getMobsOfObject('frm~:html', $ilUser->getId());
1542  foreach($mediaObjects as $mob)
1543  {
1544  foreach($myMediaObjects as $myMob)
1545  {
1546  if($mob == $myMob)
1547  {
1548  // change usage
1549  ilObjMediaObject::_removeUsage($mob, 'frm~:html', $ilUser->getId());
1550  break;
1551  }
1552  }
1553  ilObjMediaObject::_saveUsage($mob, 'frm:html', $newPost);
1554  }
1555 
1556  $oFDForum = new ilFileDataForum($forumObj->getId(), $newPost);
1557  $file = $_FILES['userfile'];
1558  if(is_array($file) && !empty($file))
1559  {
1560  $oFDForum->storeUploadedFile($file);
1561  }
1562 
1563  // FINALLY SEND MESSAGE
1564  if ($this->ilias->getSetting("forum_notification") == 1 && (int)$status )
1565  {
1566  $objPost = new ilForumPost((int)$newPost, $this->is_moderator);
1567 
1568  $post_data = array();
1569  $post_data = $objPost->getDataAsArray();
1570  $titles = $this->getTitlesByRefId(array($this->object->getRefId()));
1571  $post_data["top_name"] = $titles[0];
1572  $post_data["ref_id"] = $this->object->getRefId();
1573 
1574  $frm->__sendMessage($objPost->getParentId(), $post_data);
1575 
1576  $frm->sendForumNotifications($post_data);
1577  $frm->sendThreadNotifications($post_data);
1578  }
1579 
1580  $message = '';
1581  if(!$this->is_moderator && !$status)
1582  {
1583  $message .= $lng->txt('forums_post_needs_to_be_activated');
1584  }
1585  else
1586  {
1587  $message .= $lng->txt('forums_post_new_entry');
1588  }
1589 
1590  $_SESSION['frm'][(int)$_GET['thr_pk']]['openTreeNodes'][] = (int)$this->objCurrentPost->getId();
1591 
1592  ilUtil::sendSuccess($message, true);
1593  $this->ctrl->setParameter($this, 'pos_pk', $newPost);
1594  $this->ctrl->setParameter($this, 'thr_pk', $this->objCurrentPost->getThreadId());
1595  $this->ctrl->redirect($this, 'viewThread');
1596  }
1597  else
1598  {
1599  if((!$this->is_moderator &&
1600  !$this->objCurrentPost->isOwner($ilUser->getId())) || $this->objCurrentPost->isCensored() ||
1601  $ilUser->getId() == ANONYMOUS_USER_ID)
1602  {
1603  $this->ilias->raiseError($lng->txt('permission_denied'), $this->ilias->error_obj->MESSAGE);
1604  }
1605 
1606  // remove usage of deleted media objects
1607  include_once 'Services/MediaObjects/classes/class.ilObjMediaObject.php';
1608  $oldMediaObjects = ilObjMediaObject::_getMobsOfObject('frm:html', $this->objCurrentPost->getId());
1609  $curMediaObjects = ilRTE::_getMediaObjects($oReplyEditForm->getInput('message'), 0);
1610  foreach($oldMediaObjects as $oldMob)
1611  {
1612  $found = false;
1613  foreach($curMediaObjects as $curMob)
1614  {
1615  if($oldMob == $curMob)
1616  {
1617  $found = true;
1618  break;
1619  }
1620  }
1621  if(!$found)
1622  {
1623  if(ilObjMediaObject::_exists($oldMob))
1624  {
1625  ilObjMediaObject::_removeUsage($oldMob, 'frm:html', $this->objCurrentPost->getId());
1626  $mob_obj = new ilObjMediaObject($oldMob);
1627  $mob_obj->delete();
1628  }
1629  }
1630  }
1631 
1632  // if post has been edited posting mus be activated again by moderator
1633  $status = 1;
1634  $send_activation_mail = 0;
1635 
1636  if($this->objProperties->isPostActivationEnabled())
1637  {
1638  if(!$this->is_moderator)
1639  {
1640  $status = 0;
1641  $send_activation_mail = 1;
1642  }
1643  else if($this->objCurrentPost->isAnyParentDeactivated())
1644  {
1645  $status = 0;
1646  }
1647  }
1648  $this->objCurrentPost->setStatus($status);
1649 
1650  $this->objCurrentPost->setSubject($this->handleFormInput($oReplyEditForm->getInput('subject'), false));
1651  $this->objCurrentPost->setMessage(ilRTE::_replaceMediaObjectImageSrc($oReplyEditForm->getInput('message'), 0));
1652  $this->objCurrentPost->setNotification((int)$oReplyEditForm->getInput('notify'));
1653  $this->objCurrentPost->setChangeDate(date('Y-m-d H:i:s'));
1654  $this->objCurrentPost->setUpdateUserId($ilUser->getId());
1655 
1656  // edit: update post
1657  if($this->objCurrentPost->update())
1658  {
1659  $this->objCurrentPost->reload();
1660 
1661  // Change news item accordingly
1662  include_once 'Services/News/classes/class.ilNewsItem.php';
1663  // note: $this->objCurrentPost->getForumId() does not give us the forum ID here (why?)
1664  $news_id = ilNewsItem::getFirstNewsIdForContext($forumObj->getId(),
1665  'frm', $this->objCurrentPost->getId(), 'pos');
1666  if($news_id > 0)
1667  {
1668  $news_item = new ilNewsItem($news_id);
1669  $news_item->setTitle($this->objCurrentPost->getSubject());
1670  $news_item->setContent(ilRTE::_replaceMediaObjectImageSrc($frm->prepareText(
1671  $this->objCurrentPost->getMessage(), 0), 1)
1672  );
1673  $news_item->update();
1674  }
1675 
1676  // attachments
1677  $oFDForum = $oForumObjects['file_obj'];
1678 
1679  $file = $_FILES['userfile'];
1680  if(is_array($file) && !empty($file))
1681  {
1682  $oFDForum->storeUploadedFile($file);
1683  }
1684 
1685  $file2delete = $oReplyEditForm->getInput('del_file');
1686  if(is_array($file2delete) && count($file2delete))
1687  {
1688  $oFDForum->unlinkFilesByMD5Filenames($file2delete);
1689  }
1690  }
1691 
1692  if (!$status && $send_activation_mail)
1693  {
1694  $pos_data = $this->objCurrentPost->getDataAsArray();
1695  $pos_data["top_name"] = $this->object->getTitle();
1696  $frm->sendPostActivationNotification($pos_data);
1697  }
1698 
1699  ilUtil::sendSuccess($lng->txt('forums_post_modified'), true);
1700  $this->ctrl->setParameter($this, 'pos_pk', $this->objCurrentPost->getId());
1701  $this->ctrl->setParameter($this, 'thr_pk', $this->objCurrentPost->getThreadId());
1702  $this->ctrl->setParameter($this, 'viewmode', $_SESSION['viewmode']);
1703  $this->ctrl->redirect($this, 'viewThread');
1704  }
1705  }
1706  else
1707  {
1708  $_GET['action'] = substr($_GET['action'], 6);
1709  }
1710  return $this->viewThreadObject();
1711  }
1712 
1713  private function hideToolbar($a_flag = null)
1714  {
1715  if(null === $a_flag)
1716  {
1717  return $this->hideToolbar;
1718  }
1719 
1720  $this->hideToolbar = $a_flag;
1721  return $this;
1722  }
1723 
1724  public function quotePostObject()
1725  {
1726  if(!is_array($_POST['del_file'])) $_POST['del_file'] = array();
1727 
1728  if($this->objCurrentTopic->isClosed())
1729  {
1730  $_GET['action'] = '';
1731  return $this->viewThreadObject();
1732  }
1733 
1734  $oReplyEditForm = $this->getReplyEditForm();
1735 
1736  // remove mandatory fields
1737  $oReplyEditForm->getItemByPostVar('subject')->setRequired(false);
1738  $oReplyEditForm->getItemByPostVar('message')->setRequired(false);
1739 
1740  $oReplyEditForm->checkInput();
1741 
1742  // add mandatory fields
1743  $oReplyEditForm->getItemByPostVar('subject')->setRequired(true);
1744  $oReplyEditForm->getItemByPostVar('message')->setRequired(true);
1745 
1746  $_GET['action'] = 'showreply';
1747 
1748  $this->viewThreadObject();
1749  }
1750 
1751  public function getQuotationHTMLAsynchObject()
1752  {
1753  $oForumObjects = $this->getForumObjects();
1757  $frm = $oForumObjects['frm'];
1758 
1759  require_once 'Modules/Forum/classes/class.ilForumAuthorInformation.php';
1760  $authorinfo = new ilForumAuthorInformation(
1761  $this->objCurrentPost->getUserId(),
1762  $this->objCurrentPost->getUserAlias(),
1763  $this->objCurrentPost->getImportName()
1764  );
1765 
1766  $html = ilRTE::_replaceMediaObjectImageSrc($frm->prepareText($this->objCurrentPost->getMessage(), 1, $authorinfo->getAuthorName()), 1);
1767  echo $html;
1768  exit();
1769  }
1770 
1771  private function getForumObjects()
1772  {
1773  if(null === $this->forumObjects)
1774  {
1775  $forumObj = $this->object;
1776  $file_obj = new ilFileDataForum($forumObj->getId(), $this->objCurrentPost->getId());
1777  $frm = $forumObj->Forum;
1778  $frm->setForumId($forumObj->getId());
1779  $frm->setForumRefId($forumObj->getRefId());
1780 
1781  $this->forumObjects['forumObj'] = $forumObj;
1782  $this->forumObjects['frm'] = $frm;
1783  $this->forumObjects['file_obj'] = $file_obj;
1784  }
1785 
1786  return $this->forumObjects;
1787  }
1788 
1789  public function getForumExplorer()
1790  {
1791  include_once 'Modules/Forum/classes/class.ilForumExplorer.php';
1792 
1793  $explorer = new ilForumExplorer(
1794  $this,
1795  $this->objCurrentTopic,
1796  $this->objProperties
1797  );
1798 
1799  return $explorer->render()->getHtml();
1800  }
1801 
1803  {
1804  include_once 'Services/JSON/classes/class.ilJsonUtil.php';
1805  include_once 'Modules/Forum/classes/class.ilForumExplorer.php';
1806 
1807  $response = new stdClass();
1808  $response->success = false;
1809 
1810  if( $_GET['nodeId'] )
1811  {
1812  $response->success = true;
1813  $response->children = array();
1814 
1815  $key = array_search((int)$_GET['nodeId'], (array)$_SESSION['frm'][(int)$_GET['thr_pk']]['openTreeNodes']);
1816  if( false === $key )
1817  {
1818  $_SESSION['frm'][(int)$_GET['thr_pk']]['openTreeNodes'][] = (int)$_GET['nodeId'];
1819  }
1820 
1821  $children = $this->objCurrentTopic->getNestedSetPostChildren(
1822  (int)$_GET['nodeId'],
1823  (array)$_SESSION['frm'][(int)$_GET['thr_pk']]['openTreeNodes']
1824  );
1825 
1826  $frm = new ilForum();
1827  $pageHits = $frm->getPageHits();
1828 
1829  $fetchedNodes = array();
1830 
1831  foreach( $children as $child )
1832  {
1833  if($child['parent_pos'] != (int)$_GET['nodeId'] &&
1834  !in_array($child['parent_pos'], $fetchedNodes))
1835  {
1836  continue;
1837  }
1838 
1839  $fetchedNodes[] = $child['pos_pk'];
1840 
1841  $this->ctrl->setParameter($this, 'thr_pk', (int)$_GET['thr_pk']);
1842 
1844  $child,
1845  $this,
1846  $pageHits
1847  );
1848 
1849  $responseChild = new stdClass();
1850  $responseChild->nodeId = $child['pos_pk'];
1851  $responseChild->parentId = $child['parent_pos'];
1852  $responseChild->hasChildren = ($child['children'] >= 1);
1853  $responseChild->fetchedWithChildren = in_array((int)$child['pos_pk'], (array)$_SESSION['frm'][(int)$_GET['thr_pk']]['openTreeNodes']);
1854  $responseChild->html = $html;
1855 
1856  $response->children[] = $responseChild;
1857  }
1858  }
1859 
1860  echo ilJsonUtil::encode($response);
1861  exit();
1862  }
1863 
1864  public function setTreeStateAsynchObject()
1865  {
1866  include_once 'Services/JSON/classes/class.ilJsonUtil.php';
1867 
1868  $response = new stdClass();
1869  $response->success = true;
1870 
1871  if( $_GET['nodeId'] )
1872  {
1873  if( $_GET['nodeId'] > 0 )
1874  {
1875  $key = array_search((int)$_GET['nodeId'], (array)$_SESSION['frm'][(int)$_GET['thr_pk']]['openTreeNodes']);
1876  if( false === $key )
1877  {
1878  $_SESSION['frm'][(int)$_GET['thr_pk']]['openTreeNodes'][] = (int)$_GET['nodeId'];
1879  }
1880  }
1881  else
1882  {
1883  $key = array_search((int)abs($_GET['nodeId']), (array)$_SESSION['frm'][(int)$_GET['thr_pk']]['openTreeNodes']);
1884  if( false !== $key )
1885  {
1886  unset($_SESSION['frm'][(int)$_GET['thr_pk']]['openTreeNodes'][$key]);
1887  }
1888  }
1889  }
1890 
1891  // Guarantee continuous keys
1892  shuffle($_SESSION['frm'][(int)$_GET['thr_pk']]['openTreeNodes']);
1893  exit();
1894  }
1895 
1896  public function viewThreadObject()
1897  {
1908  global $tpl, $lng, $ilUser, $ilAccess, $rbacreview, $ilNavigationHistory, $ilCtrl, $frm, $ilToolbar, $ilLocator;
1909 
1910  $tpl->addCss('./Modules/Forum/css/forum_tree.css');
1911  if(!isset($_SESSION['viewmode']))
1912  {
1913  $_SESSION['viewmode'] = $this->objProperties->getDefaultView();
1914  }
1915 
1916  // quick and dirty: check for treeview
1917  if(!isset($_SESSION['thread_control']['old']))
1918  {
1919  $_SESSION['thread_control']['old'] = $_GET['thr_pk'];
1920  $_SESSION['thread_control']['new'] = $_GET['thr_pk'];
1921  }
1922  else
1923  if(isset($_SESSION['thread_control']['old']) && $_GET['thr_pk'] != $_SESSION['thread_control']['old'])
1924  {
1925  $_SESSION['thread_control']['new'] = $_GET['thr_pk'];
1926  }
1927 
1928  if(isset($_GET['viewmode']) && $_GET['viewmode'] != $_SESSION['viewmode'])
1929  {
1930  $_SESSION['viewmode'] = $_GET['viewmode'];
1931  }
1932 
1933  if( (isset($_GET['action']) && $_SESSION['viewmode'] != ilForumProperties::VIEW_DATE)
1934  ||($_SESSION['viewmode'] == ilForumProperties::VIEW_TREE))
1935  {
1937  }
1938  else
1939  {
1941  }
1942 
1943  if(!$ilAccess->checkAccess('read', '', $this->object->getRefId()))
1944  {
1945  $this->ilias->raiseError($lng->txt('permission_denied'), $this->ilias->error_obj->MESSAGE);
1946  }
1947 
1948  // init objects
1949  $oForumObjects = $this->getForumObjects();
1953  $forumObj = $oForumObjects['forumObj'];
1957  $frm = $oForumObjects['frm'];
1961  $file_obj = $oForumObjects['file_obj'];
1962 
1963  // download file
1964  if($_GET['file'])
1965  {
1966  if(!$path = $file_obj->getFileDataByMD5Filename($_GET['file']))
1967  {
1968  ilUtil::sendFailure('error_reading_file');
1969  }
1970  else
1971  {
1972  ilUtil::deliverFile($path['path'], $path['clean_filename']);
1973  }
1974  }
1975 
1976  if(!$this->objCurrentTopic->getId())
1977  {
1978  $ilCtrl->redirect($this, 'showThreads');
1979  }
1980 
1981  // Set context for login
1982  $append = '_'.$this->objCurrentTopic->getId().
1983  ($this->objCurrentPost->getId() ? '_'.$this->objCurrentPost->getId() : '');
1984  $tpl->setLoginTargetPar('frm_'.$_GET['ref_id'].$append);
1985 
1986  // delete temporary media object (not in case a user adds media objects and wants to save an invalid form)
1987  if($_GET['action'] != 'showreply' && $_GET['action'] != 'showedit')
1988  {
1989  try
1990  {
1991  include_once 'Services/MediaObjects/classes/class.ilObjMediaObject.php';
1992  $mobs = ilObjMediaObject::_getMobsOfObject('frm~:html', $ilUser->getId());
1993  foreach($mobs as $mob)
1994  {
1995  if(ilObjMediaObject::_exists($mob))
1996  {
1997  ilObjMediaObject::_removeUsage($mob, 'frm~:html', $ilUser->getId());
1998  $mob_obj = new ilObjMediaObject($mob);
1999  $mob_obj->delete();
2000  }
2001  }
2002  }
2003  catch(Exception $e)
2004  {
2005  }
2006  }
2007 
2008  require_once './Modules/Forum/classes/class.ilObjForum.php';
2009  require_once './Modules/Forum/classes/class.ilFileDataForum.php';
2010 
2011  $lng->loadLanguageModule('forum');
2012 
2013  // add entry to navigation history
2014  if (!$this->getCreationMode() &&
2015  $ilAccess->checkAccess('read', '', $this->object->getRefId()))
2016  {
2017  $ilCtrl->setParameter($this, 'thr_pk', $this->objCurrentTopic->getId());
2018  $ilNavigationHistory->addItem($this->object->getRefId(), $ilCtrl->getLinkTarget($this, 'showThreads'), 'frm');
2019  }
2020 
2021  // save last access
2022  $forumObj->updateLastAccess($ilUser->getId(), (int) $this->objCurrentTopic->getId());
2023 
2024  $this->prepareThreadScreen($forumObj);
2025 
2026  $tpl->addBlockFile('ADM_CONTENT', 'adm_content', 'tpl.forums_threads_view.html', 'Modules/Forum');
2027 
2028  if(isset($_GET['anchor']))
2029  {
2030  $tpl->setVariable('JUMP2ANCHOR_ID', (int)$_GET['anchor']);
2031  }
2032 
2033  if ($_SESSION['viewmode'] == 'date'
2034  || $_SESSION['viewmode'] == ilForumProperties::VIEW_DATE)
2035  {
2036  $orderField = 'frm_posts_tree.fpt_date';
2037  $this->objCurrentTopic->setOrderDirection(
2038  in_array($this->objProperties->getDefaultView(), array(ilForumProperties::VIEW_DATE_ASC, ilForumProperties::VIEW_TREE))
2039  ? 'ASC' : 'DESC'
2040  );
2041  }
2042  else
2043  {
2044  $orderField = 'frm_posts_tree.rgt';
2045  $this->objCurrentTopic->setOrderDirection('DESC');
2046  }
2047 
2048  // get forum- and thread-data
2049  $frm->setMDB2WhereCondition('top_frm_fk = %s ', array('integer'), array($frm->getForumId()));
2050 
2051  if(is_array($topicData = $frm->getOneTopic()))
2052  {
2053  // Visit-Counter for topic
2054  $this->objCurrentTopic->updateVisits();
2055 
2056  $tpl->setTitle($lng->txt('forums_thread')." \"".$this->objCurrentTopic->getSubject()."\"");
2057 
2058  // ********************************************************************************
2059  // build location-links
2060  $ilLocator->addRepositoryItems();
2061  $ilLocator->addItem($this->object->getTitle(), $ilCtrl->getLinkTarget($this, ""), "_top");
2062  $tpl->setLocator();
2063 
2064  // set tabs
2065  // menu template (contains linkbar)
2067  $menutpl = new ilTemplate('tpl.forums_threads_menu.html', true, true, 'Modules/Forum');
2068 
2069  include_once("./Services/Accessibility/classes/class.ilAccessKeyGUI.php");
2070 
2071  // mark all as read
2072  if($ilUser->getId() != ANONYMOUS_USER_ID &&
2073  $forumObj->getCountUnread($ilUser->getId(), (int) $this->objCurrentTopic->getId()))
2074  {
2075  $this->ctrl->setParameter($this, 'mark_read', '1');
2076  $this->ctrl->setParameter($this, 'thr_pk', $this->objCurrentTopic->getId());
2077  $ilToolbar->addButton(
2078  $this->lng->txt('forums_mark_read'),
2079  $this->ctrl->getLinkTarget($this, 'viewThread'),
2080  '',
2082  );
2083  $this->ctrl->clearParameters($this);
2084  }
2085 
2086  // print thread
2087  $this->ctrl->setParameterByClass('ilforumexportgui', 'print_thread', $this->objCurrentTopic->getId());
2088  $this->ctrl->setParameterByClass('ilforumexportgui', 'thr_top_fk', $this->objCurrentTopic->getForumId());
2089  $ilToolbar->addButton($this->lng->txt('forums_print_thread'),
2090  $this->ctrl->getLinkTargetByClass('ilforumexportgui', 'printThread')
2091  );
2092  $this->ctrl->clearParametersByClass('ilforumexportgui');
2093 
2094  $this->addHeaderAction();
2095 
2096  if($_GET['mark_read'])
2097  {
2098  $forumObj->markThreadRead($ilUser->getId(), (int)$this->objCurrentTopic->getId());
2099  ilUtil::sendInfo($lng->txt('forums_thread_marked'), true);
2100  }
2101 
2102  // delete post and its sub-posts
2103  require_once './Modules/Forum/classes/class.ilForum.php';
2104 
2105  if ($_GET['action'] == 'ready_delete' && $_POST['confirm'] != '')
2106  {
2107  if(!$this->objCurrentTopic->isClosed() &&
2108  ($this->is_moderator ||
2109  ($this->objCurrentPost->isOwner($ilUser->getId()) && !$this->objCurrentPost->hasReplies())) &&
2110  $ilUser->getId() != ANONYMOUS_USER_ID)
2111  {
2112  $frm = new ilForum();
2113 
2114  $frm->setForumId($forumObj->getId());
2115  $frm->setForumRefId($forumObj->getRefId());
2116 
2117  $dead_thr = $frm->deletePost($this->objCurrentPost->getId());
2118 
2119  // if complete thread was deleted ...
2120  if ($dead_thr == $this->objCurrentTopic->getId())
2121  {
2122 
2123  $frm->setMDB2WhereCondition('top_frm_fk = %s ', array('integer'), array($forumObj->getId()));
2124 
2125  $topicData = $frm->getOneTopic();
2126 
2127  ilUtil::sendInfo($lng->txt('forums_post_deleted'), true);
2128 
2129  if ($topicData['top_num_threads'] > 0)
2130  {
2131  $this->ctrl->redirect($this, 'showThreads');
2132  }
2133  else
2134  {
2135  $this->ctrl->redirect($this, 'createThread');
2136  }
2137  }
2138  ilUtil::sendInfo($lng->txt('forums_post_deleted'));
2139  }
2140  }
2141 
2142  // form processing (censor)
2143  if(!$this->objCurrentTopic->isClosed() && $_GET['action'] == 'ready_censor')
2144  {
2145  if(($_POST['confirm'] != '' || $_POST['no_cs_change'] != '') && $_GET['action'] == 'ready_censor')
2146  {
2147  $frm->postCensorship($this->handleFormInput($_POST['formData']['cens_message']), $this->objCurrentPost->getId(), 1);
2148  }
2149  else if(($_POST['cancel'] != '' || $_POST['yes_cs_change'] != '') && $_GET['action'] == 'ready_censor')
2150  {
2151  $frm->postCensorship($this->handleFormInput($_POST['formData']['cens_message']), $this->objCurrentPost->getId());
2152  }
2153  }
2154 
2155  // get complete tree of thread
2156  $first_node = $this->objCurrentTopic->getFirstPostNode();
2157  $this->objCurrentTopic->setOrderField($orderField);
2158  $subtree_nodes = $this->objCurrentTopic->getPostTree($first_node);
2159 
2160  // no posts
2161  if (!$posNum = count($subtree_nodes))
2162  {
2163  ilUtil::sendInfo($this->lng->txt('forums_no_posts_available'));
2164  }
2165 
2166  $pageHits = $frm->getPageHits();
2167 
2168  $z = 0;
2169 
2170  // navigation to browse
2171  if ($posNum > $pageHits)
2172  {
2173  $params = array(
2174  'ref_id' => $_GET['ref_id'],
2175  'thr_pk' => $this->objCurrentTopic->getId(),
2176  'orderby' => $_GET['orderby']
2177  );
2178 
2179  if (!$_GET['offset'])
2180  {
2181  $Start = 0;
2182  }
2183  else
2184  {
2185  $Start = $_GET['offset'];
2186  }
2187 
2188  $linkbar = ilUtil::Linkbar($ilCtrl->getLinkTarget($this, 'viewThread'), $posNum, $pageHits, $Start, $params);
2189 
2190  if($linkbar != '')
2191  {
2192  $menutpl->setCurrentBlock('linkbar');
2193  $menutpl->setVariable('LINKBAR', $linkbar);
2194  $menutpl->parseCurrentBlock();
2195  }
2196  }
2197 
2198  $tpl->setVariable('THREAD_MENU', $menutpl->get());
2199 
2200  // assistance val for anchor-links
2201  $jump = 0;
2202 
2203  // generate post-dates
2204  foreach($subtree_nodes as $node)
2205  {
2210  $this->ctrl->clearParameters($this);
2211 
2212  if($this->objCurrentPost->getId() && $this->objCurrentPost->getId() == $node->getId())
2213  {
2214  $jump++;
2215  }
2216 
2217  if ($posNum > $pageHits && $z >= ($Start + $pageHits))
2218  {
2219  // if anchor-link was not found ...
2220  if ($this->objCurrentPost->getId() && $jump < 1)
2221  {
2222  $this->ctrl->setParameter($this, 'thr_pk', $this->objCurrentTopic->getId());
2223  $this->ctrl->setParameter($this, 'pos_pk', $this->objCurrentPost->getId());
2224  $this->ctrl->setParameter($this, 'offset', ($Start + $pageHits));
2225  $this->ctrl->setParameter($this, 'orderby', $_GET['orderby']);
2226  $this->ctrl->redirect($this, 'viewThread', $this->objCurrentPost->getId());
2227  exit();
2228  }
2229  else
2230  {
2231  break;
2232  }
2233  }
2234 
2235  if(($posNum > $pageHits && $z >= $Start) || $posNum <= $pageHits)
2236  {
2237  if($this->objCurrentPost->getId() == $node->getId())
2238  {
2239  # actions for "active" post
2240  if($this->is_moderator || $node->isActivated())
2241  {
2242  // reply/edit
2243  if(!$this->objCurrentTopic->isClosed() && ($_GET['action'] == 'showreply' || $_GET['action'] == 'showedit'))
2244  {
2245  if($_GET['action'] == 'showedit' &&
2246  ((!$this->is_moderator &&
2247  !$node->isOwner($ilUser->getId()) || $ilUser->getId() == ANONYMOUS_USER_ID) || $node->isCensored()))
2248  {
2249  $this->ilias->raiseError($lng->txt('permission_denied'), $this->ilias->error_obj->MESSAGE);
2250  }
2251  else if($_GET['action'] == 'showreply' && !$ilAccess->checkAccess('add_reply', '', (int)$_GET['ref_id']))
2252  {
2253  $this->ilias->raiseError($lng->txt('permission_denied'), $this->ilias->error_obj->MESSAGE);
2254  }
2255 
2256  $tpl->setVariable('REPLY_ANKER', $this->objCurrentPost->getId());
2257  $oEditReplyForm = $this->getReplyEditForm();
2258 
2259  switch($this->objProperties->getSubjectSetting())
2260  {
2261  case 'add_re_to_subject':
2262  $subject = $this->getModifiedReOnSubject(true);
2263  break;
2264 
2265  case 'preset_subject':
2266  $subject = $this->objCurrentPost->getSubject();
2267  break;
2268 
2269  case 'empty_subject':
2270  default:
2271  $subject = NULL;
2272  break;
2273  }
2274 
2275  switch($_GET['action'])
2276  {
2277  case 'showreply':
2278  if($this->ctrl->getCmd() == 'savePost')
2279  {
2280  $oEditReplyForm->setValuesByPost();
2281  }
2282  else if($this->ctrl->getCmd() == 'quotePost')
2283  {
2284  require_once 'Modules/Forum/classes/class.ilForumAuthorInformation.php';
2285  $authorinfo = new ilForumAuthorInformation(
2286  $node->getUserId(),
2287  $node->getUserAlias(),
2288  $node->getImportName()
2289  );
2290 
2291  $oEditReplyForm->setValuesByPost();
2292  $oEditReplyForm->getItemByPostVar('message')->setValue(
2294  $frm->prepareText($node->getMessage(), 1, $authorinfo->getAuthorName())."\n".$oEditReplyForm->getInput('message'), 1
2295  )
2296  );
2297  }
2298  else
2299  {
2300  $oEditReplyForm->setValuesByArray(array(
2301  'alias' => '',
2302  'subject' => $subject,
2303  'message' => '',
2304  'notify' => 0,
2305  'userfile' => '',
2306  'del_file' => array()
2307  ));
2308  }
2309 
2310  $this->ctrl->setParameter($this, 'pos_pk', $this->objCurrentPost->getId());
2311  $this->ctrl->setParameter($this, 'thr_pk', $this->objCurrentPost->getThreadId());
2312 
2313  $jsTpl = new ilTemplate('tpl.forum_post_quoation_ajax_handler.html', true, true, 'Modules/Forum/');
2314  $jsTpl->setVariable('IL_FRM_QUOTE_CALLBACK_SRC',
2315  $this->ctrl->getLinkTarget($this, 'getQuotationHTMLAsynch', '', true));
2316  $this->ctrl->clearParameters($this);
2317  $this->tpl->setVariable('FORM_ADDITIONAL_JS', $jsTpl->get());
2318  break;
2319  case 'showedit':
2320  if($this->ctrl->getCmd() == 'savePost')
2321  {
2322  $oEditReplyForm->setValuesByPost();
2323  }
2324  else
2325  {
2326  $oEditReplyForm->setValuesByArray(array(
2327  'alias' => '',
2328  'subject' => $this->objCurrentPost->getSubject(),
2329  'message' => ilRTE::_replaceMediaObjectImageSrc($frm->prepareText($this->objCurrentPost->getMessage(), 2), 1),
2330  'notify' => $this->objCurrentPost->isNotificationEnabled() ? true : false,
2331  'userfile' => '',
2332  'del_file' => array()
2333  ));
2334  }
2335  break;
2336  }
2337  $this->ctrl->setParameter($this, 'pos_pk', $this->objCurrentPost->getId());
2338  $this->ctrl->setParameter($this, 'thr_pk', $this->objCurrentPost->getThreadId());
2339  $this->ctrl->setParameter($this, 'offset', (int)$_GET['offset']);
2340  $this->ctrl->setParameter($this, 'orderby', $_GET['orderby']);
2341  $this->ctrl->setParameter($this, 'action', $_GET['action']);
2342  $tpl->setVariable('FORM', $oEditReplyForm->getHTML());
2343  $this->ctrl->clearParameters($this);
2344 
2345  } // if ($_GET['action'] == 'showreply' || $_GET['action'] == 'showedit')
2346  else if(!$this->objCurrentTopic->isClosed() && $_GET['action'] == 'delete')
2347  {
2348  if($this->is_moderator ||
2349  ($node->isOwner($ilUser->getId()) && !$node->hasReplies()) &&
2350  $ilUser->getId() != ANONYMOUS_USER_ID)
2351  {
2352  // confirmation: delete
2353  $tpl->setVariable('FORM', $this->getDeleteFormHTML());
2354  }
2355  } // else if ($_GET['action'] == 'delete')
2356  else if(!$this->objCurrentTopic->isClosed() && $_GET['action'] == 'censor')
2357  {
2358  if($this->is_moderator)
2359  {
2360  // confirmation: censor / remove censorship
2361  $tpl->setVariable('FORM', $this->getCensorshipFormHTML());
2362  }
2363  }
2364  else if (!$this->objCurrentTopic->isClosed() && $this->displayConfirmPostActivation())
2365  {
2366  if ($this->is_moderator)
2367  {
2368  // confirmation: activate
2369  $tpl->setVariable('FORM', $this->getActivationFormHTML());
2370  }
2371  }
2372  }
2373  } // if ($this->objCurrentPost->getId() == $node->getId())
2374 
2375  if ($this->objCurrentPost->getId() != $node->getId() ||
2376  ($_GET['action'] != 'showreply' &&
2377  $_GET['action'] != 'showedit' &&
2378  $_GET['action'] != 'censor' &&
2379  $_GET['action'] != 'delete' &&
2380  #!$this->displayConfirmPostDeactivation() &&
2382  ))
2383  {
2384  if($this->is_moderator || $node->isActivated())
2385  {
2386  // button: reply
2387  if(!$this->objCurrentTopic->isClosed() &&
2388  $ilAccess->checkAccess('add_reply', '', (int)$_GET['ref_id']) &&
2389  !$node->isCensored()
2390  )
2391  {
2392  $tpl->setCurrentBlock('commands');
2393  $this->ctrl->setParameter($this, 'action', 'showreply');
2394  $this->ctrl->setParameter($this, 'pos_pk', $node->getId());
2395  $this->ctrl->setParameter($this, 'offset', $Start);
2396  $this->ctrl->setParameter($this, 'orderby', $_GET['orderby']);
2397  $this->ctrl->setParameter($this, 'thr_pk', $node->getThreadId());
2398  $tpl->setVariable('COMMANDS_COMMAND', $this->ctrl->getLinkTarget($this, 'viewThread', $node->getId()));
2399  $tpl->setVariable('COMMANDS_TXT', $lng->txt('reply'));
2400  $this->ctrl->clearParameters($this);
2401  $tpl->parseCurrentBlock();
2402  }
2403 
2404  // button: edit article
2405  if (!$this->objCurrentTopic->isClosed() &&
2406  ($node->isOwner($ilUser->getId()) || $this->is_moderator) &&
2407  !$node->isCensored() &&
2408  $ilUser->getId() != ANONYMOUS_USER_ID)
2409  {
2410  $tpl->setCurrentBlock('commands');
2411  $this->ctrl->setParameter($this, 'action', 'showedit');
2412  $this->ctrl->setParameter($this, 'pos_pk', $node->getId());
2413  $this->ctrl->setParameter($this, 'thr_pk', $node->getThreadId());
2414  $this->ctrl->setParameter($this, 'offset', $Start);
2415  $this->ctrl->setParameter($this, 'orderby', $_GET['orderby']);
2416  $tpl->setVariable('COMMANDS_COMMAND', $this->ctrl->getLinkTarget($this, 'viewThread', $node->getId()));
2417  $tpl->setVariable('COMMANDS_TXT', $lng->txt('edit'));
2418  $this->ctrl->clearParameters($this);
2419  $tpl->parseCurrentBlock();
2420  }
2421 
2422  // button: print
2423  if (!$node->isCensored())
2424  {
2425  $tpl->setCurrentBlock('commands');
2426  $this->ctrl->setParameterByClass('ilforumexportgui', 'print_post', $node->getId());
2427  $this->ctrl->setParameterByClass('ilforumexportgui', 'top_pk', $node->getForumId());
2428  $this->ctrl->setParameterByClass('ilforumexportgui', 'thr_pk', $node->getThreadId());
2429  $tpl->setVariable('COMMANDS_COMMAND', $this->ctrl->getLinkTargetByClass('ilforumexportgui', 'printPost'));
2430  $tpl->setVariable('COMMANDS_TXT', $lng->txt('print'));
2431  $this->ctrl->clearParameters($this);
2432  $tpl->parseCurrentBlock();
2433  }
2434 
2435  # buttons for every post except the "active"
2436  if (!$this->objCurrentTopic->isClosed() &&
2437  ($this->is_moderator ||
2438  ($node->isOwner($ilUser->getId()) && !$node->hasReplies())) &&
2439  $ilUser->getId() != ANONYMOUS_USER_ID)
2440  {
2441  // button: delete
2442  $tpl->setCurrentBlock('commands');
2443  $this->ctrl->setParameter($this, 'action', 'delete');
2444  $this->ctrl->setParameter($this, 'pos_pk', $node->getId());
2445  $this->ctrl->setParameter($this, 'thr_pk', $node->getThreadId());
2446  $this->ctrl->setParameter($this, 'offset', $Start);
2447  $this->ctrl->setParameter($this, 'orderby', $_GET['orderby']);
2448  $tpl->setVariable('COMMANDS_COMMAND', $this->ctrl->getLinkTarget($this, 'viewThread', $node->getId()));
2449  $tpl->setVariable('COMMANDS_TXT', $lng->txt('delete'));
2450  $this->ctrl->clearParameters($this);
2451  $tpl->parseCurrentBlock();
2452  }
2453 
2454  if (!$this->objCurrentTopic->isClosed() && $this->is_moderator)
2455  {
2456  // button: censor
2457  $tpl->setCurrentBlock('commands');
2458  $this->ctrl->setParameter($this, 'action', 'censor');
2459  $this->ctrl->setParameter($this, 'pos_pk', $node->getId());
2460  $this->ctrl->setParameter($this, 'thr_pk', $node->getThreadId());
2461  $this->ctrl->setParameter($this, 'offset', $Start);
2462  $this->ctrl->setParameter($this, 'orderby', $_GET['orderby']);
2463  $tpl->setVariable('COMMANDS_COMMAND', $this->ctrl->getLinkTarget($this, 'viewThread', $node->getId()));
2464  $tpl->setVariable('COMMANDS_TXT', $lng->txt('censorship'));
2465  $this->ctrl->clearParameters($this);
2466  $tpl->parseCurrentBlock();
2467 
2468  // button: activation/deactivation
2469  $tpl->setCurrentBlock('commands');
2470  $this->ctrl->setParameter($this, 'pos_pk', $node->getId());
2471  $this->ctrl->setParameter($this, 'thr_pk', $node->getThreadId());
2472  $this->ctrl->setParameter($this, 'offset', $Start);
2473  $this->ctrl->setParameter($this, 'orderby', $_GET['orderby']);
2474 
2475  if (!$node->isActivated())
2476  {
2477  $tpl->setVariable('COMMANDS_COMMAND', $this->ctrl->getLinkTarget($this, 'askForPostActivation', $node->getId()));
2478  $tpl->setVariable('COMMANDS_TXT', $lng->txt('activate_post'));
2479  }
2480  $this->ctrl->clearParameters($this);
2481  $tpl->parseCurrentBlock();
2482  }
2483 
2484  // button: mark read
2485  if ($ilUser->getId() != ANONYMOUS_USER_ID &&
2486  !$node->isPostRead())
2487  {
2488  $tpl->setCurrentBlock('commands');
2489  $this->ctrl->setParameter($this, 'pos_pk', $node->getId());
2490  $this->ctrl->setParameter($this, 'thr_pk', $node->getThreadId());
2491  $this->ctrl->setParameter($this, 'offset', $Start);
2492  $this->ctrl->setParameter($this, 'orderby', $_GET['orderby']);
2493  $this->ctrl->setParameter($this, 'viewmode', $_SESSION['viewmode']);
2494  $tpl->setVariable('COMMANDS_COMMAND', $this->ctrl->getLinkTarget($this, 'markPostRead', $node->getId()));
2495  $tpl->setVariable('COMMANDS_TXT', $lng->txt('is_read'));
2496  $this->ctrl->clearParameters($this);
2497  $tpl->parseCurrentBlock();
2498  }
2499 
2500  // button: mark unread
2501  if ($ilUser->getId() != ANONYMOUS_USER_ID &&
2502  $node->isPostRead())
2503  {
2504  $tpl->setCurrentBlock('commands');
2505  $this->ctrl->setParameter($this, 'pos_pk', $node->getId());
2506  $this->ctrl->setParameter($this, 'thr_pk', $node->getThreadId());
2507  $this->ctrl->setParameter($this, 'offset', $Start);
2508  $this->ctrl->setParameter($this, 'orderby', $_GET['orderby']);
2509  $this->ctrl->setParameter($this, 'viewmode', $_SESSION['viewmode']);
2510  $tpl->setVariable('COMMANDS_COMMAND', $this->ctrl->getLinkTarget($this, 'markPostUnread', $node->getId()));
2511  $tpl->setVariable('COMMANDS_TXT', $lng->txt('unread'));
2512  $this->ctrl->clearParameters($this);
2513  $tpl->parseCurrentBlock();
2514  }
2515  }
2516  } // if ($this->objCurrentPost->getId() != $node->getId())
2517 
2518  // download post attachments
2519  $tmp_file_obj = new ilFileDataForum($forumObj->getId(), $node->getId());
2520  if (count($tmp_file_obj->getFilesOfPost()))
2521  {
2522  if ($node->getId() != $this->objCurrentPost->getId() || $_GET['action'] != 'showedit')
2523  {
2524  foreach ($tmp_file_obj->getFilesOfPost() as $file)
2525  {
2526  $tpl->setCurrentBlock('attachment_download_row');
2527  $this->ctrl->setParameter($this, 'pos_pk', $node->getId());
2528  $this->ctrl->setParameter($this, 'file', $file['md5']);
2529  $tpl->setVariable('HREF_DOWNLOAD', $this->ctrl->getLinkTarget($this, 'viewThread'));
2530  $tpl->setVariable('TXT_FILENAME', $file['name']);
2531  $this->ctrl->clearParameters($this);
2532  $tpl->parseCurrentBlock();
2533  }
2534  $tpl->setCurrentBlock('attachments');
2535  $tpl->setVariable('TXT_ATTACHMENTS_DOWNLOAD',$lng->txt('forums_attachments'));
2536  $tpl->setVariable('DOWNLOAD_IMG', ilUtil::getImagePath('icon_attachment.png'));
2537  $tpl->setVariable('TXT_DOWNLOAD_ATTACHMENT', $lng->txt('forums_download_attachment'));
2538  $tpl->parseCurrentBlock();
2539  }
2540  }
2541 
2542  $tpl->setCurrentBlock('posts_row');
2543 
2544  // anker for every post
2545  $tpl->setVariable('POST_ANKER', $node->getId());
2546 
2547  //permanent link for every post
2548  // $tpl->setVariable('PERMA_LINK', ILIAS_HTTP_PATH."/goto.php?target="."frm"."_".$this->object->getRefId()."_".$node->getThreadId()."_".$node->getId()."&client_id=".CLIENT_ID);
2549  $tpl->setVariable('TXT_PERMA_LINK', $lng->txt('perma_link'));
2550  $tpl->setVariable('PERMA_TARGET', '_top');
2551 
2552  if($this->objProperties->getMarkModeratorPosts() == 1)
2553  {
2554  $is_moderator = ilForum::_isModerator($_GET['ref_id'], $node->getUserId());
2555  if($is_moderator)
2556  {
2557  $rowCol = 'ilHighlighted';
2558  }
2559  else $rowCol = ilUtil::switchColor($z, 'tblrow1', 'tblrow2');
2560  }
2561  else $rowCol = ilUtil::switchColor($z, 'tblrow1', 'tblrow2');
2562  if (( $_GET['action'] != 'delete' && $_GET['action'] != 'censor' &&
2563  #!$this->displayConfirmPostDeactivation() &&
2565  )
2566  || $this->objCurrentPost->getId() != $node->getId())
2567  {
2568  $tpl->setVariable('ROWCOL', ' '.$rowCol);
2569  }
2570  else
2571  {
2572  // highlight censored posts
2573  $rowCol = 'tblrowmarked';
2574  }
2575 
2576  // post is censored
2577  if ($node->isCensored())
2578  {
2579  // display censorship advice
2580  if ($_GET['action'] != 'censor')
2581  {
2582  $tpl->setVariable('TXT_CENSORSHIP_ADVICE', $this->lng->txt('post_censored_comment_by_moderator'));
2583  }
2584 
2585  // highlight censored posts
2586  $rowCol = 'tblrowmarked';
2587  }
2588 
2589  // set row color
2590  $tpl->setVariable('ROWCOL', ' '.$rowCol);
2591  // if post is not activated display message for the owner
2592  if(!$node->isActivated() && $node->isOwner($ilUser->getId()))
2593  {
2594  $tpl->setVariable('POST_NOT_ACTIVATED_YET', $this->lng->txt('frm_post_not_activated_yet'));
2595  }
2596 
2597 
2598  // Author
2599  $this->ctrl->setParameter($this, 'pos_pk', $node->getId());
2600  $this->ctrl->setParameter($this, 'thr_pk', $node->getThreadId());
2601  $backurl = urlencode($this->ctrl->getLinkTarget($this, 'viewThread', $node->getId()));
2602  $this->ctrl->clearParameters($this);
2603 
2604  $this->ctrl->setParameter($this, 'backurl', $backurl);
2605  $this->ctrl->setParameter($this, 'thr_pk', $node->getThreadId());
2606  $this->ctrl->setParameter($this, 'user', $node->getUserId());
2607 
2608  require_once 'Modules/Forum/classes/class.ilForumAuthorInformation.php';
2609  $authorinfo = new ilForumAuthorInformation(
2610  $node->getUserId(),
2611  $node->getUserAlias(),
2612  $node->getImportName(),
2613  array(
2614  'href' => $this->ctrl->getLinkTarget($this, 'showUser')
2615  )
2616  );
2617 
2618  $this->ctrl->clearParameters($this);
2619 
2620  $tpl->setVariable('AUTHOR', $authorinfo->getLinkedAuthorShortName());
2621  if($authorinfo->getAuthorName(true))
2622  {
2623  $tpl->setVariable('USR_NAME', $authorinfo->getAuthorName(true));
2624  }
2625 
2626  $tpl->setVariable('USR_IMAGE', $authorinfo->getProfilePicture());
2627  if($authorinfo->getAuthor()->getId() && ilForum::_isModerator((int)$_GET['ref_id'], $authorinfo->getAuthor()->getId()))
2628  {
2629  if($authorinfo->getAuthor()->getGender() == 'f')
2630  {
2631  $tpl->setVariable('ROLE', $this->lng->txt('frm_moderator_f'));
2632  }
2633  else if($authorinfo->getAuthor()->getGender() == 'm')
2634  {
2635  $tpl->setVariable('ROLE', $this->lng->txt('frm_moderator_m'));
2636  }
2637  }
2638 
2639  // get create- and update-dates
2640  if ($node->getUpdateUserId() > 0)
2641  {
2642  $spanClass = '';
2643 
2644  // last update from moderator?
2645  $posMod = $frm->getModeratorFromPost($node->getId());
2646 
2647  if (is_array($posMod) && $posMod['top_mods'] > 0)
2648  {
2649  $MODS = $rbacreview->assignedUsers($posMod['top_mods']);
2650 
2651  if (is_array($MODS))
2652  {
2653  if (in_array($node->getUpdateUserId(), $MODS))
2654  $spanClass = 'moderator_small';
2655  }
2656  }
2657 
2658  $node->setChangeDate($node->getChangeDate());
2659 
2660  if ($spanClass == '') $spanClass = 'small';
2661 
2662  $this->ctrl->setParameter($this, 'backurl', $backurl);
2663  $this->ctrl->setParameter($this, 'thr_pk', $node->getThreadId());
2664  $this->ctrl->setParameter($this, 'user', $node->getUpdateUserId());
2665 
2666  require_once 'Modules/Forum/classes/class.ilForumAuthorInformation.php';
2667  $authorinfo = new ilForumAuthorInformation(
2668  $node->getUpdateUserId(),
2669  '',
2670  '',
2671  array(
2672  'href' => $this->ctrl->getLinkTarget($this, 'showUser')
2673  )
2674  );
2675 
2676  $this->ctrl->clearParameters($this);
2677 
2678  $tpl->setVariable('POST_UPDATE_TXT', $lng->txt('edited_on').': '.$frm->convertDate($node->getChangeDate()).' - '.strtolower($lng->txt('by')));
2679  $tpl->setVariable('UPDATE_AUTHOR', $authorinfo->getLinkedAuthorShortName());
2680  if($authorinfo->getAuthorName(true))
2681  {
2682  $tpl->setVariable('UPDATE_USR_NAME', $authorinfo->getAuthorName(true));
2683  }
2684 
2685  } // if ($node->getUpdateUserId() > 0)*/
2686  // Author end
2687 
2688  // prepare post
2689  $node->setMessage($frm->prepareText($node->getMessage()));
2690 
2691  if($ilUser->getId() == ANONYMOUS_USER_ID ||
2692  $node->isPostRead())
2693  {
2694  $tpl->setVariable('SUBJECT', $node->getSubject());
2695  }
2696  else
2697  {
2698  $this->ctrl->setParameter($this, 'pos_pk', $node->getId());
2699  $this->ctrl->setParameter($this, 'thr_pk', $node->getThreadId());
2700  $this->ctrl->setParameter($this, 'offset', $Start);
2701  $this->ctrl->setParameter($this, 'orderby', $_GET['orderby']);
2702  $this->ctrl->setParameter($this, 'viewmode', $_SESSION['viewmode']);
2703  $mark_post_target = $this->ctrl->getLinkTarget($this, 'markPostRead', $node->getId());
2704 
2705  $tpl->setVariable('SUBJECT',"<a href=\"".$mark_post_target."\"><b>".$node->getSubject()."</b></a>");
2706 
2707  }
2708 
2709  $tpl->setVariable('POST_DATE', $frm->convertDate($node->getCreateDate()));
2710 
2711  if (!$node->isCensored() ||
2712  ($this->objCurrentPost->getId() == $node->getId() && $_GET['action'] == 'censor'))
2713  {
2714  // post from moderator?
2715  $modAuthor = $frm->getModeratorFromPost($node->getId());
2716 
2717  $spanClass = "";
2718 
2719  if (is_array($modAuthor) && $modAuthor['top_mods'] > 0)
2720  {
2721  unset($MODS);
2722 
2723  $MODS = $rbacreview->assignedUsers($modAuthor['top_mods']);
2724 
2725  if (is_array($MODS))
2726  {
2727  if (in_array($node->getUserId(), $MODS))
2728  $spanClass = 'moderator';
2729  }
2730  }
2731 
2732  // possible bugfix for mantis #8223
2733  if($node->getMessage() == strip_tags($node->getMessage()))
2734  {
2735  // We can be sure, that there are not html tags
2736  $node->setMessage(nl2br($node->getMessage()));
2737  }
2738 
2739  if ($spanClass != "")
2740  {
2741  $tpl->setVariable('POST', "<span class=\"".$spanClass."\">".ilRTE::_replaceMediaObjectImageSrc($node->getMessage(), 1)."</span>");
2742  }
2743  else
2744  {
2745  $tpl->setVariable('POST', ilRTE::_replaceMediaObjectImageSrc($node->getMessage(), 1));
2746  }
2747  }
2748  else
2749  {
2750  $tpl->setVariable('POST', "<span class=\"moderator\">".nl2br($node->getCensorshipComment())."</span>");
2751  }
2752 
2753  $tpl->parseCurrentBlock();
2754 
2755  }
2756  $z++;
2757  }
2758  }
2759  else
2760  {
2761  $tpl->setCurrentBlock('posts_no');
2762  $tpl->setVariable('TXT_MSG_NO_POSTS_AVAILABLE', $lng->txt('forums_posts_not_available'));
2763  $tpl->parseCurrentBlock();
2764  }
2765 
2766  $oThreadToolbar = clone $ilToolbar;
2767  $oThreadToolbar->addSeparator();
2768  $oThreadToolbar->addButton($this->lng->txt('top_of_page'),'#frm_page_top');
2769  $tpl->setVariable('THREAD_TOOLBAR', $oThreadToolbar->getHTML());
2770 
2771  $tpl->setVariable('TPLPATH', $tpl->vars['TPLPATH']);
2772 
2773  // permanent link
2774  include_once 'Services/PermanentLink/classes/class.ilPermanentLinkGUI.php';
2775  $permalink = new ilPermanentLinkGUI('frm', $this->object->getRefId(), '_'.$this->objCurrentTopic->getId());
2776  $this->tpl->setVariable('PRMLINK', $permalink->getHTML());
2777 
2778  // Render tree
2779  if($_SESSION['viewmode'] == 'answers'
2780  || $_SESSION['viewmode'] == ilForumProperties::VIEW_TREE)
2781  {
2782  $tpl->setLeftNavContent($this->getForumExplorer());
2783  }
2784 
2785  return true;
2786  }
2787 
2788  private function getModifiedReOnSubject($on_reply = false)
2789  {
2790  $subject = $this->objCurrentPost->getSubject();
2791  $re_txt = $this->lng->txt('post_reply');
2792 
2793  $re_txt_with_num = str_replace(':', '(',$re_txt);
2794  $search_length = strlen($re_txt_with_num);
2795  $comp = substr_compare($re_txt_with_num, substr($subject, 0 , $search_length), 0, $search_length);
2796 
2797  if($comp == 0)
2798  {
2799  $modified_subject = $subject;
2800  if($on_reply == true)
2801  {
2802  // i.e. $subject = "Re(12):"
2803  $str_pos_start = strpos($subject,'(');
2804  $str_pos_end = strpos($subject,')');
2805  $length = ((int)$str_pos_end - (int)$str_pos_start);
2806  $str_pos_start++;
2807  $txt_number = substr($subject,$str_pos_start, $length-1);
2808 
2809  $re_count = (int)$txt_number + 1;
2810 
2811  $modified_subject = str_replace($txt_number, $re_count, $subject);
2812  }
2813  }
2814  else
2815  {
2816  $re_count = substr_count($subject, $re_txt);
2817  if($re_count >= 1 && $on_reply == true)
2818  {
2819  $subject = str_replace($re_txt, '', $subject);
2820 
2821  // i.e. $subject = "Re: Re: Re: ... " -> "Re(4):"
2822  $re_count++;
2823  $modified_subject = sprintf($this->lng->txt('post_reply_count'), $re_count).' '.trim($subject);
2824  }
2825  else if($re_count >= 1 && $on_reply == false)
2826  {
2827  // possibility to modify the subject only for output
2828  // i.e. $subject = "Re: Re: Re: ... " -> "Re(3):"
2829  $modified_subject = sprintf($this->lng->txt('post_reply_count'), $re_count).' '.trim($subject);
2830  }
2831  else if($re_count == 0)
2832  {
2833  // the first reply to a thread
2834  $modified_subject = $this->lng->txt('post_reply').' '. $this->objCurrentPost->getSubject();
2835  }
2836  }
2837  return $modified_subject;
2838  }
2839 
2840  public function showUserObject()
2841  {
2845  global $tpl;
2846 
2847  // we could actually call ilpublicuserprofilegui directly, this method
2848  // is not needed - but sadly used throughout the forum code
2849  // see above in execute command
2850 
2851  include_once 'Services/User/classes/class.ilPublicUserProfileGUI.php';
2852  $profile_gui = new ilPublicUserProfileGUI($_GET['user']);
2853  $add = $this->getUserProfileAdditional($_GET['ref_id'], $_GET['user']);
2854  $profile_gui->setAdditional($add);
2855  $profile_gui->setBackUrl($_GET['backurl']);
2856  $tpl->setContent($this->ctrl->getHTML($profile_gui));
2857  }
2858 
2859  protected function getUserProfileAdditional($a_forum_ref_id, $a_user_id)
2860  {
2865  global $lng, $ilAccess;
2866 
2867  if(!$ilAccess->checkAccess('read', '', $a_forum_ref_id))
2868  {
2869  $this->ilias->raiseError($lng->txt('permission_denied'), $this->ilias->error_obj->MESSAGE);
2870  }
2871 
2872  require_once 'Modules/Forum/classes/class.ilForum.php';
2873 
2874  $lng->loadLanguageModule('forum');
2875 
2879  $ref_obj = ilObjectFactory::getInstanceByRefId($a_forum_ref_id);
2880  if($ref_obj->getType() == 'frm')
2881  {
2882  $forumObj = new ilObjForum($a_forum_ref_id);
2883  $frm = $forumObj->Forum;
2884  $frm->setForumId($forumObj->getId());
2885  $frm->setForumRefId($forumObj->getRefId());
2886  }
2887  else
2888  {
2889  $frm = new ilForum();
2890  }
2891 
2892  // count articles of user
2893  if($ilAccess->checkAccess('moderate_frm', '', $a_forum_ref_id))
2894  {
2895  $numPosts = $frm->countUserArticles(addslashes($a_user_id));
2896  }
2897  else
2898  {
2899  $numPosts = $frm->countActiveUserArticles(addslashes($a_user_id));
2900  }
2901 
2902  return array($lng->txt('forums_posts') => $numPosts);
2903  }
2904 
2905  public function performThreadsActionObject()
2906  {
2910  global $ilUser;
2911 
2912  unset($_SESSION['threads2move']);
2913  unset($_SESSION['frm_topic_paste_expand']);
2914 
2915  if(isset($_POST['thread_ids']) && is_array($_POST['thread_ids']))
2916  {
2917  if(isset($_POST['selected_cmd']) && $_POST['selected_cmd'] == 'move')
2918  {
2919  if($this->is_moderator)
2920  {
2921  $_SESSION['threads2move'] = $_POST['thread_ids'];
2922  $this->moveThreadsObject();
2923  }
2924  }
2925  else if($_POST['selected_cmd'] == 'enable_notifications' && $this->ilias->getSetting('forum_notification') != 0)
2926  {
2927  for($i = 0; $i < count($_POST['thread_ids']); $i++)
2928  {
2929  $tmp_obj = new ilForumTopic($_POST['thread_ids'][$i]);
2930  $tmp_obj->enableNotification($ilUser->getId());
2931  unset($tmp_obj);
2932  }
2933 
2934  $this->ctrl->redirect($this, 'showThreads');
2935  }
2936  else if($_POST['selected_cmd'] == 'disable_notifications' && $this->ilias->getSetting('forum_notification') != 0)
2937  {
2938  for($i = 0; $i < count($_POST['thread_ids']); $i++)
2939  {
2940  $tmp_obj = new ilForumTopic($_POST['thread_ids'][$i]);
2941  $tmp_obj->disableNotification($ilUser->getId());
2942  unset($tmp_obj);
2943  }
2944 
2945  $this->ctrl->redirect($this, 'showThreads');
2946  }
2947 
2948  else if($_POST['selected_cmd'] == 'close')
2949  {
2950  if($this->is_moderator)
2951  {
2952  for($i = 0; $i < count($_POST['thread_ids']); $i++)
2953  {
2954  $tmp_obj = new ilForumTopic($_POST['thread_ids'][$i]);
2955  $tmp_obj->close();
2956  unset($tmp_obj);
2957  }
2958  }
2959 
2960  $this->ctrl->redirect($this, 'showThreads');
2961  }
2962  else if($_POST['selected_cmd'] == 'reopen')
2963  {
2964  if($this->is_moderator)
2965  {
2966  for($i = 0; $i < count($_POST['thread_ids']); $i++)
2967  {
2968  $tmp_obj = new ilForumTopic($_POST['thread_ids'][$i]);
2969  $tmp_obj->reopen();
2970  unset($tmp_obj);
2971  }
2972  }
2973 
2974  $this->ctrl->redirect($this, 'showThreads');
2975  }
2976  else if($_POST['selected_cmd'] == 'makesticky')
2977  {
2978  if($this->is_moderator)
2979  {
2980  for($i = 0; $i < count($_POST['thread_ids']); $i++)
2981  {
2982  $tmp_obj = new ilForumTopic($_POST['thread_ids'][$i]);
2983  $tmp_obj->makeSticky();
2984  unset($tmp_obj);
2985  }
2986  }
2987 
2988  $this->ctrl->redirect($this, 'showThreads');
2989  }
2990  else if($_POST['selected_cmd'] == 'unmakesticky')
2991  {
2992  if($this->is_moderator)
2993  {
2994  for($i = 0; $i < count($_POST['thread_ids']); $i++)
2995  {
2996  $tmp_obj = new ilForumTopic($_POST['thread_ids'][$i]);
2997  $tmp_obj->unmakeSticky();
2998  unset($tmp_obj);
2999  }
3000  }
3001 
3002  $this->ctrl->redirect($this, 'showThreads');
3003  }
3004  else if($_POST['selected_cmd'] == 'editThread')
3005  {
3006  if($this->is_moderator)
3007  {
3008  $count = count($_POST['thread_ids']);
3009  if($count != 1)
3010  {
3011  ilUtil::sendInfo($this->lng->txt('select_max_one_thread'), true);
3012  $this->ctrl->redirect($this, 'showThreads');
3013  }
3014  else
3015  {
3016  foreach($_POST['thread_ids'] as $thread_id)
3017  {
3018  return $this->editThreadObject($thread_id, null);
3019  }
3020  }
3021  }
3022 
3023  $this->ctrl->redirect($this, 'showThreads');
3024  }
3025  else if($_POST['selected_cmd'] == 'html')
3026  {
3027  $this->ctrl->setCmd('exportHTML');
3028  $this->ctrl->setCmdClass('ilForumExportGUI');
3029  $this->executeCommand();
3030  }
3031  else if($_POST['selected_cmd'] == 'confirmDeleteThreads')
3032  {
3033  $this->confirmDeleteThreads();
3034  }
3035  else
3036  {
3037  ilUtil::sendInfo($this->lng->txt('topics_please_select_one_action'), true);
3038  $this->ctrl->redirect($this, 'showThreads');
3039  }
3040  }
3041  else
3042  {
3043  ilUtil::sendInfo($this->lng->txt('select_at_least_one_thread'), true);
3044  $this->ctrl->redirect($this, 'showThreads');
3045  }
3046  }
3047 
3048  public function performMoveThreadsObject()
3049  {
3054  global $lng, $ilObjDataCache;
3055 
3056  if(!$this->is_moderator)
3057  {
3058  $this->ilias->raiseError($lng->txt('permission_denied'), $this->ilias->error_obj->MESSAGE);
3059  }
3060 
3061  if(isset($_POST['frm_ref_id']) && (int) $_POST['frm_ref_id'])
3062  {
3063  $this->object->Forum->moveThreads((array) $_SESSION['threads2move'], $this->object->getRefId(), $ilObjDataCache->lookupObjId($_POST['frm_ref_id']));
3064 
3065  unset($_SESSION['threads2move']);
3066  unset($_SESSION['frm_topic_paste_expand']);
3067  ilUtil::sendInfo($lng->txt('threads_moved_successfully'), true);
3068  $this->ctrl->redirect($this, 'showThreads');
3069  }
3070  else
3071  {
3072  ilUtil::sendInfo($lng->txt('no_forum_selected'));
3073  $this->moveThreadsObject();
3074  }
3075  }
3076 
3077  public function cancelMoveThreadsObject()
3078  {
3082  global $lng;
3083 
3084  if(!$this->is_moderator)
3085  {
3086  $this->ilias->raiseError($lng->txt('permission_denied'), $this->ilias->error_obj->MESSAGE);
3087  }
3088 
3089  unset($_SESSION['threads2move']);
3090  unset($_SESSION['frm_topic_paste_expand']);
3091 
3092  $this->ctrl->redirect($this, 'showThreads');
3093  }
3094 
3095  public function moveThreadsObject()
3096  {
3102  global $lng, $ilToolbar, $tree;
3103 
3104  if(!$this->is_moderator)
3105  {
3106  $this->ilias->raiseError($lng->txt('permission_denied'), $this->ilias->error_obj->MESSAGE);
3107  }
3108 
3109  $threads2move = $_SESSION['threads2move'];
3110 
3111  if(empty($threads2move))
3112  {
3113  ilUtil::sendInfo($this->lng->txt('select_at_least_one_thread'), true);
3114  $this->ctrl->redirect($this, 'showThreads');
3115  }
3116 
3117  $this->tpl->addBlockFile('ADM_CONTENT', 'adm_content', 'tpl.forums_threads_move.html', 'Modules/Forum');
3118 
3119  if(!$this->hideToolbar())
3120  $ilToolbar->addButton($this->lng->txt('back'), $this->ctrl->getLinkTarget($this));
3121 
3122  $tblThr = new ilTable2GUI($this);
3123  $tblThr->setId('il_frm_thread_move_table_'.$this->object->getRefId());
3124  $tblThr->setTitle($this->lng->txt('move_chosen_topics'));
3125  $tblThr->addColumn($this->lng->txt('subject'), 'top_name', '100%');
3126  $tblThr->disable('header');
3127  $tblThr->disable('footer');
3128  $tblThr->disable('linkbar');
3129  $tblThr->disable('sort');
3130  $tblThr->disable('linkbar');
3131  $tblThr->setLimit(0);
3132  $tblThr->setRowTemplate('tpl.forums_threads_move_thr_row.html', 'Modules/Forum');
3133  $tblThr->setDefaultOrderField('is_sticky');
3134  $counter = 0;
3135  $result = array();
3136  foreach($threads2move as $thr_pk)
3137  {
3138  $objCurrentTopic = new ilForumTopic($thr_pk, $this->is_moderator);
3139 
3140  $result[$counter]['num'] = $counter + 1;
3141  $result[$counter]['thr_subject'] = $objCurrentTopic->getSubject();
3142 
3143  unset($objCurrentTopic);
3144  ++$counter;
3145  }
3146  $tblThr->setData($result);
3147  $this->tpl->setVariable('THREADS_TABLE', $tblThr->getHTML());
3148 
3149  // selection tree
3150  require_once 'Modules/Forum/classes/class.ilForumMoveTopicsExplorer.php';
3151  $exp = new ilForumMoveTopicsExplorer($this->ctrl->getLinkTarget($this, 'moveThreads'), 'frm_topic_paste_expand');
3152  $exp->setExpandTarget($this->ctrl->getLinkTarget($this, 'moveThreads'));
3153  $exp->setTargetGet('ref_id');
3154  $exp->setPostVar('frm_ref_id');
3155  $exp->excludeObjIdFromSelection($this->object->getId());
3156  $exp->setCheckedItem(isset($_POST['frm_ref_id']) && (int) $_POST['frm_ref_id'] ? (int) $_POST['frm_ref_id'] : 0);
3157 
3158  // open current position in tree
3159  if(!is_array($_SESSION['frm_topic_paste_expand']))
3160  {
3161  $_SESSION['frm_topic_paste_expand'] = array();
3162 
3163  $path = $tree->getPathId($this->object->getRefId());
3164  foreach((array)$path as $node_id)
3165  {
3166  if(!in_array($node_id, $_SESSION['frm_topic_paste_expand']))
3167  $_SESSION['frm_topic_paste_expand'][] = $node_id;
3168  }
3169  }
3170 
3171  if(!isset($_GET['frm_topic_paste_expand']) || $_GET['frm_topic_paste_expand'] == '')
3172  {
3173  $expanded = $tree->readRootId();
3174  }
3175  else
3176  {
3177  $expanded = $_GET['frm_topic_paste_expand'];
3178  }
3179 
3180  $exp->setExpand($expanded);
3181  // build html-output
3182  $exp->setOutput(0);
3183  $output = $exp->getOutput();
3184  $this->tpl->setVariable('FRM_SELECTION_TREE', $output);
3185  $this->tpl->setVariable('CMD_SUBMIT', 'performMoveThreads');
3186  $this->tpl->setVariable('TXT_SUBMIT', $this->lng->txt('move'));
3187  $this->tpl->setVariable('FORMACTION', $this->ctrl->getFormAction($this, 'performMoveThreads'));
3188 
3189  return true;
3190  }
3191 
3192  private function initTopicCreateForm()
3193  {
3200  global $ilUser, $rbacsystem, $ilias, $ilSetting;
3201 
3202  $this->create_topic_form_gui = new ilPropertyFormGUI();
3203 
3204  $this->create_topic_form_gui->setTitle($this->lng->txt('forums_new_thread'));
3205  $this->create_topic_form_gui->setTitleIcon(ilUtil::getImagePath('icon_frm.png'));
3206  $this->create_topic_form_gui->setTableWidth('100%');
3207 
3208  // form action
3209  $this->create_topic_form_gui->setFormAction($this->ctrl->getFormAction($this, 'addThread'));
3210 
3211  if($this->objProperties->isAnonymized() == 1)
3212  {
3213  $alias_gui = new ilTextInputGUI($this->lng->txt('forums_your_name'), 'alias');
3214  $alias_gui->setInfo($this->lng->txt('forums_use_alias'));
3215  $alias_gui->setMaxLength(255);
3216  $alias_gui->setSize(50);
3217  $this->create_topic_form_gui->addItem($alias_gui);
3218  }
3219  else
3220  {
3221  $alias_gui = new ilNonEditableValueGUI($this->lng->txt('forums_your_name'), 'alias');
3222  $alias_gui->setValue($ilUser->getLogin());
3223  $this->create_topic_form_gui->addItem($alias_gui);
3224  }
3225 
3226  // topic
3227  $subject_gui = new ilTextInputGUI($this->lng->txt('forums_thread'), 'subject');
3228  $subject_gui->setMaxLength(255);
3229  $subject_gui->setSize(50);
3230  $subject_gui->setRequired(true);
3231  $this->create_topic_form_gui->addItem($subject_gui);
3232 
3233  // message
3234  $post_gui = new ilTextAreaInputGUI($this->lng->txt('forums_the_post'), 'message');
3235  $post_gui->setCols(50);
3236  $post_gui->setRows(15);
3237  $post_gui->setRequired(true);
3238  $post_gui->setUseRte(true);
3239  $post_gui->addPlugin('latex');
3240  $post_gui->addButton('latex');
3241  $post_gui->addButton('pastelatex');
3242  $post_gui->addPlugin('ilfrmquote');
3243  //$post_gui->addPlugin('code');
3244  $post_gui->removePlugin('advlink');
3245  $post_gui->usePurifier(true);
3246  $post_gui->setRTERootBlockElement('');
3247  $post_gui->setRTESupport($ilUser->getId(), 'frm~', 'frm_post', 'tpl.tinymce_frm_post.html', false, '3.4.7');
3248  $post_gui->disableButtons(array(
3249  'charmap',
3250  'undo',
3251  'redo',
3252  'justifyleft',
3253  'justifycenter',
3254  'justifyright',
3255  'justifyfull',
3256  'anchor',
3257  'fullscreen',
3258  'cut',
3259  'copy',
3260  'paste',
3261  'pastetext',
3262  'formatselect'
3263  ));
3264 
3265  // purifier
3266  require_once 'Services/Html/classes/class.ilHtmlPurifierFactory.php';
3267  $post_gui->setPurifier(ilHtmlPurifierFactory::_getInstanceByType('frm_post'));
3268  $this->create_topic_form_gui->addItem($post_gui);
3269 
3270  // file
3271  $fi = new ilFileWizardInputGUI($this->lng->txt('forums_attachments_add'), 'userfile');
3272  $fi->setFilenames(array(0 => ''));
3273  $this->create_topic_form_gui->addItem($fi);
3274 
3275  include_once 'Services/Mail/classes/class.ilMail.php';
3276  $umail = new ilMail($ilUser->getId());
3277  // catch hack attempts
3278  if($rbacsystem->checkAccess('internal_mail', $umail->getMailObjectReferenceId()) &&
3279  !$this->objProperties->isAnonymized())
3280  {
3281  // direct notification
3282  $dir_notification_gui = new ilCheckboxInputGUI($this->lng->txt('forum_direct_notification'), 'notify');
3283  $dir_notification_gui->setInfo($this->lng->txt('forum_notify_me_directly'));
3284  $dir_notification_gui->setValue(1);
3285  $this->create_topic_form_gui->addItem($dir_notification_gui);
3286 
3287  if($ilias->getSetting('forum_notification') != 0)
3288  {
3289  // gen. notification
3290  $gen_notification_gui = new ilCheckboxInputGUI($this->lng->txt('forum_general_notification'), 'notify_posts');
3291  $gen_notification_gui->setInfo($this->lng->txt('forum_notify_me_generally'));
3292  $gen_notification_gui->setValue(1);
3293  $this->create_topic_form_gui->addItem($gen_notification_gui);
3294  }
3295  }
3296 
3297  if ($ilUser->getId() == ANONYMOUS_USER_ID &&
3298  $ilSetting->get('activate_captcha_anonym'))
3299  {
3300  include_once("./Services/Captcha/classes/class.ilCaptchaInputGUI.php");
3301  $captcha = new ilCaptchaInputGUI($this->lng->txt("cont_captcha_code"), 'captcha_code');
3302  $captcha->setRequired(true);
3303  $this->create_topic_form_gui->addItem($captcha);
3304  }
3305  $this->create_topic_form_gui->addCommandButton('addThread', $this->lng->txt('submit'));
3306  $this->create_topic_form_gui->addCommandButton('showThreads', $this->lng->txt('cancel'));
3307  }
3308 
3309  private function setTopicCreateDefaultValues()
3310  {
3311  $this->create_topic_form_gui->setValuesByArray(array(
3312  'subject' => '',
3313  'message' => '',
3314  'userfile' => '',
3315  'notify' => 0,
3316  'notify_posts' => 0
3317  ));
3318  }
3319 
3320  public function createThreadObject()
3321  {
3326  global $ilAccess, $lng;
3327 
3328  if(!$ilAccess->checkAccess('add_thread', '', $this->object->getRefId()))
3329  {
3330  $this->ilias->raiseError($lng->txt('permission_denied'), $this->ilias->error_obj->MESSAGE);
3331  }
3332 
3333  $this->initTopicCreateForm();
3334  $this->setTopicCreateDefaultValues();
3335 
3336  $create_form = new ilTemplate('tpl.create_thread_form.html', true, true, 'Modules/Forum');
3337  $create_form->setVariable('CREATE_FORM',$this->create_topic_form_gui->getHTML());
3338  $create_form->parseCurrentBlock();
3339 
3340  $this->tpl->setContent($create_form->get());
3341  }
3342 
3343  public function addThreadObject($a_prevent_redirect = false)
3344  {
3350  global $ilUser, $ilAccess, $lng;
3351 
3352  $frm = $this->object->Forum;
3353  $frm->setForumId($this->object->getId());
3354  $frm->setForumRefId($this->object->getRefId());
3355 
3356  if(!$ilAccess->checkAccess('add_thread', '', $this->object->getRefId()))
3357  {
3358  $this->ilias->raiseError($lng->txt('permission_denied'), $this->ilias->error_obj->MESSAGE);
3359  }
3360 
3361  $frm->setMDB2WhereCondition('top_frm_fk = %s ', array('integer'), array($frm->getForumId()));
3362 
3363  $topicData = $frm->getOneTopic();
3364 
3365  $this->initTopicCreateForm();
3366  if($this->create_topic_form_gui->checkInput())
3367  {
3368  if($this->objProperties->isAnonymized())
3369  {
3370  if(!strlen($this->create_topic_form_gui->getInput('alias')))
3371  {
3372  $user_alias = $this->lng->txt('forums_anonymous');
3373  }
3374  else
3375  {
3376  $user_alias = $this->create_topic_form_gui->getInput('alias');
3377  }
3378  }
3379  else
3380  {
3381  $user_alias = $ilUser->getLogin();
3382  }
3383 
3384  // build new thread
3385  $newPost = $frm->generateThread(
3386  $topicData['top_pk'],
3387  ($this->objProperties->isAnonymized() ? 0 : $ilUser->getId()),
3388  $this->handleFormInput($this->create_topic_form_gui->getInput('subject'), false),
3389  ilRTE::_replaceMediaObjectImageSrc($this->create_topic_form_gui->getInput('message'), 0),
3390  $this->create_topic_form_gui->getItemByPostVar('notify') ? (int)$this->create_topic_form_gui->getInput('notify') : 0,
3391  $this->create_topic_form_gui->getItemByPostVar('notify_posts') ? (int)$this->create_topic_form_gui->getInput('notify_posts') : 0,
3392  $user_alias
3393  );
3394 
3395  $file = $_FILES['userfile'];
3396 
3397  // file upload
3398  if(is_array($file) && !empty($file))
3399  {
3400  $tmp_file_obj = new ilFileDataForum($this->object->getId(), $newPost);
3401  $tmp_file_obj->storeUploadedFile($file);
3402  }
3403 
3404  // Visit-Counter
3405  $frm->setDbTable('frm_data');
3406  $frm->setMDB2WhereCondition('top_pk = %s ', array('integer'), array($topicData['top_pk']));
3407  $frm->updateVisits($topicData['top_pk']);
3408 
3409  $frm->setMDB2WhereCondition('thr_top_fk = %s AND thr_subject = %s AND thr_num_posts = 1 ',
3410  array('integer', 'text'), array($topicData['top_pk'], $this->create_topic_form_gui->getInput('subject')));
3411 
3412  // copy temporary media objects (frm~)
3413  include_once 'Services/MediaObjects/classes/class.ilObjMediaObject.php';
3414  $mediaObjects = ilRTE::_getMediaObjects($this->create_topic_form_gui->getInput('message'), 0);
3415  foreach($mediaObjects as $mob)
3416  {
3417  if(ilObjMediaObject::_exists($mob))
3418  {
3419  ilObjMediaObject::_removeUsage($mob, 'frm~:html', $ilUser->getId());
3420  ilObjMediaObject::_saveUsage($mob, 'frm:html', $newPost);
3421  }
3422  }
3423 
3424  if($this->ilias->getSetting('forum_notification') == 1)
3425  {
3426  // send notification about new topic
3427  $objPost = new ilForumPost((int)$newPost, $this->is_moderator);
3428  $post_data = array();
3429  $post_data = $objPost->getDataAsArray();
3430  $titles = $this->getTitlesByRefId(array($this->object->getRefId()));
3431  $post_data["top_name"] = $titles[0];
3432  $post_data["ref_id"] =$this->object->getRefId();
3433 
3434  $frm->sendForumNotifications($post_data);
3435  }
3436  if(!$a_prevent_redirect)
3437  {
3438  ilUtil::sendSuccess($this->lng->txt('forums_thread_new_entry'), true);
3439  $this->ctrl->redirect($this);
3440  }
3441  else
3442  {
3443  return $newPost;
3444  }
3445  }
3446  else
3447  {
3448  $this->create_topic_form_gui->setValuesByPost();
3449 
3450  if(!$this->objProperties->isAnonymized())
3451  {
3452  $this->create_topic_form_gui->getItemByPostVar('alias')->setValue($ilUser->getLogin());
3453  }
3454 
3455  return $this->tpl->setContent($this->create_topic_form_gui->getHTML());
3456  }
3457  }
3458 
3459  public function enableForumNotificationObject()
3460  {
3464  global $ilUser;
3465 
3466  $frm = $this->object->Forum;
3467  $frm->setForumId($this->object->getId());
3468  $frm->enableForumNotification($ilUser->getId());
3469 
3470  if(!$this->objCurrentTopic->getId())
3471  {
3472  ilUtil::sendInfo($this->lng->txt('forums_forum_notification_enabled'));
3473  $this->showThreadsObject();
3474  }
3475  else
3476  {
3477  $this->ctrl->setParameter($this, 'thr_pk', $this->objCurrentTopic->getId());
3478  ilUtil::sendInfo($this->lng->txt('forums_forum_notification_enabled'), true);
3479  $this->ctrl->redirect($this, 'viewThread');
3480  }
3481  }
3482 
3483  public function disableForumNotificationObject()
3484  {
3488  global $ilUser;
3489 
3490  $frm = $this->object->Forum;
3491  $frm->setForumId($this->object->getId());
3492  $frm->disableForumNotification($ilUser->getId());
3493 
3494  if(!$this->objCurrentTopic->getId())
3495  {
3496  $this->showThreadsObject();
3497  ilUtil::sendInfo($this->lng->txt('forums_forum_notification_disabled'));
3498  }
3499  else
3500  {
3501  $this->ctrl->setParameter($this, 'thr_pk', $this->objCurrentTopic->getId());
3502  ilUtil::sendInfo($this->lng->txt('forums_forum_notification_disabled'), true);
3503  $this->ctrl->redirect($this, 'viewThread');
3504  }
3505  }
3506 
3507  public function checkEnableColumnEdit()
3508  {
3509  return false;
3510  }
3511 
3512  public function setColumnSettings(ilColumnGUI $column_gui)
3513  {
3518  global $lng, $ilAccess;
3519 
3520  $column_gui->setBlockProperty('news', 'title', $lng->txt('frm_latest_postings'));
3521  $column_gui->setBlockProperty('news', 'prevent_aggregation', true);
3522  $column_gui->setRepositoryMode(true);
3523 
3524  if($ilAccess->checkAccess('write', '', $this->object->getRefId()))
3525  {
3526  $news_set = new ilSetting('news');
3527  $enable_internal_rss = $news_set->get('enable_rss_for_internal');
3528  if($enable_internal_rss)
3529  {
3530  $column_gui->setBlockProperty('news', 'settings', true);
3531  $column_gui->setBlockProperty('news', 'public_notifications_option', true);
3532  }
3533  }
3534  }
3535 
3536 
3537  public function cloneWizardPageObject()
3538  {
3539  global $ilObjDataCache;
3540 
3541  if (!$_POST['clone_source'])
3542  {
3543  ilUtil::sendInfo($this->lng->txt('select_one'));
3544  if (isset($_SESSION['wizard_search_title']))
3545  {
3546  $this->searchCloneSourceObject();
3547  }
3548  else
3549  {
3550  $this->createObject();
3551  }
3552  return false;
3553  }
3554  $source_id = $_POST['clone_source'];
3555 
3556  $new_type = $_REQUEST['new_type'];
3557  $this->ctrl->setParameter($this, 'clone_source', (int) $_POST['clone_source']);
3558  $this->ctrl->setParameter($this, 'new_type', $new_type);
3559 
3560  $this->tpl->addBlockFile('ADM_CONTENT', 'adm_content', 'tpl.frm_wizard_page.html', 'Modules/Forum');
3561  $this->tpl->setVariable('FORMACTION', $this->ctrl->getFormAction($this));
3562  $this->tpl->setVariable('TYPE_IMG', ilUtil::getImagePath('icon_'.$new_type.'.png'));
3563  $this->tpl->setVariable('ALT_IMG', $this->lng->txt('obj_'.$new_type));
3564  $this->tpl->setVariable('TXT_DUPLICATE', $this->lng->txt('frm_wizard_page'));
3565  $this->tpl->setVariable('INFO_THREADS', $this->lng->txt('fmr_copy_threads_info'));
3566  $this->tpl->setVariable('THREADS', $this->lng->txt('forums_threads'));
3567 
3568  $forum_id = $ilObjDataCache->lookupObjId((int) $_POST['clone_source']);
3569  include_once('Modules/Forum/classes/class.ilForum.php');
3570  $threads = ilForum::_getThreads($forum_id, ilForum::SORT_TITLE);
3571  foreach ($threads as $thread_id => $title)
3572  {
3573  $this->tpl->setCurrentBlock('thread_row');
3574  $this->tpl->setVariable('CHECK_THREAD', ilUtil::formCheckbox(0, 'cp_options['.$source_id.'][threads][]', $thread_id));
3575  $this->tpl->setVariable('NAME_THREAD', $title);
3576  $this->tpl->parseCurrentBlock();
3577  }
3578  $this->tpl->setVariable('SELECT_ALL', $this->lng->txt('select_all'));
3579  $this->tpl->setVariable('JS_FIELD', 'cp_options['.$source_id.'][threads]');
3580  $this->tpl->setVariable('BTN_COPY', $this->lng->txt('obj_'.$new_type.'_duplicate'));
3581  if (isset($_SESSION['wizard_search_title']))
3582  {
3583  $this->tpl->setVariable('BACK_CMD', 'searchCloneSource');
3584  }
3585  else
3586  {
3587  $this->tpl->setVariable('BACK_CMD', 'create');
3588  }
3589  $this->tpl->setVariable('BTN_BACK', $this->lng->txt('btn_back'));
3590  }
3591 
3592  public function addLocatorItems()
3593  {
3596  global $ilLocator;
3597 
3598  if($this->object instanceof ilObject)
3599  {
3600  $ilLocator->addItem($this->object->getTitle(), $this->ctrl->getLinkTarget($this, ''), '', $this->object->getRefId());
3601  }
3602  }
3603 
3604  public function handleFormInput($a_text, $a_stripslashes = true)
3605  {
3606  $a_text = str_replace("<", "&lt;", $a_text);
3607  $a_text = str_replace(">", "&gt;", $a_text);
3608  if($a_stripslashes)
3609  $a_text = ilUtil::stripSlashes($a_text);
3610 
3611  return $a_text;
3612  }
3613 
3614  public function prepareFormOutput($a_text)
3615  {
3616  $a_text = str_replace("&lt;", "<", $a_text);
3617  $a_text = str_replace("&gt;", ">", $a_text);
3618  $a_text = ilUtil::prepareFormOutput($a_text);
3619  return $a_text;
3620  }
3621 
3627  public function infoScreenObject()
3628  {
3629  $this->ctrl->setCmd('showSummary');
3630  $this->ctrl->setCmdClass('ilinfoscreengui');
3631  $this->infoScreen();
3632  }
3633 
3634  public function infoScreen()
3635  {
3639  global $ilAccess;
3640 
3641  if(!$ilAccess->checkAccess('visible', '', $this->object->getRefId()))
3642  {
3643  $this->ilias->raiseError($this->lng->txt('msg_no_perm_read'), $this->ilias->error_obj->MESSAGE);
3644  }
3645 
3646  include_once 'Services/InfoScreen/classes/class.ilInfoScreenGUI.php';
3647  $info = new ilInfoScreenGUI($this);
3648 
3649  $info->enablePrivateNotes();
3650 
3651  // standard meta data
3652  $info->addMetaDataSections($this->object->getId(), 0, $this->object->getType());
3653 
3654  // forward the command
3655  $this->ctrl->forwardCommand($info);
3656  }
3657 
3658  public function updateNotificationSettingsObject()
3659  {
3664  global $ilAccess, $ilErr;
3665  if(!$ilAccess->checkAccess('write', '', $this->ref_id))
3666  {
3667  $ilErr->raiseError($this->lng->txt('msg_no_perm_read'),$ilErr->MESSAGE);
3668  }
3669 
3670  // instantiate the property form
3672 
3673  // check input
3674  if($this->notificationSettingsForm->checkInput())
3675  {
3676  if(isset($_POST['notification_type']) && $_POST['notification_type']== 'all_users')
3677  {
3678  // set values and call update
3679  $this->objProperties->setAdminForceNoti(1);
3680  $this->objProperties->setUserToggleNoti((int) $this->notificationSettingsForm->getInput('usr_toggle'));
3681  $this->objProperties->setNotificationType('all_users');
3682  $this->updateUserNotifications(true);
3683  }
3684  else if($_POST['notification_type']== 'per_user')
3685  {
3686  $this->objProperties->setNotificationType('per_user');
3687  $this->objProperties->setAdminForceNoti(1);
3688  $this->objProperties->setUserToggleNoti(0);
3689  $this->updateUserNotifications();
3690  }
3691  else // if($_POST['notification_type'] == 'default')
3692  {
3693  $this->objProperties->setNotificationType('default');
3694  $this->objProperties->setAdminForceNoti(0);
3695  $this->objProperties->setUserToggleNoti(0);
3696  include_once 'Modules/Forum/classes/class.ilForumNotification.php';
3697  $frm_noti = new ilForumNotification($this->object->getRefId());
3698  $frm_noti->deleteNotificationAllUsers();
3699  }
3700 
3701  $this->objProperties->update();
3702 
3703  // print success message
3704  ilUtil::sendSuccess($this->lng->txt('saved_successfully'));
3705  }
3706  $this->notificationSettingsForm->setValuesByPost();
3707 
3708  return $this->showMembersObject();
3709  }
3710 
3711  private function updateUserNotifications($update_all_users = false)
3712  {
3713  include_once 'Modules/Forum/classes/class.ilForumNotification.php';
3714 
3715  $oParticipants = $this->getParticipantsObject();
3716 
3717  $frm_noti = new ilForumNotification($this->object->getRefId());
3718  $moderator_ids = $frm_noti->_getModerators($this->object->getRefId());
3719 
3720  $admin_ids = $oParticipants->getAdmins();
3721  $member_ids = $oParticipants->getMembers();
3722  $tutor_ids = $oParticipants->getTutors();
3723 
3724  $all_forum_users = array_merge($moderator_ids, $admin_ids, $member_ids, $tutor_ids);
3725  $all_forum_users= array_unique($all_forum_users);
3726 
3727  $all_notis = $frm_noti->read();
3728 
3729  foreach($all_forum_users as $user_id)
3730  {
3731  $frm_noti->setUserId($user_id);
3732 
3733  $frm_noti->setAdminForce(1);
3734  $frm_noti->setUserToggle($this->objProperties->isUserToggleNoti());
3735 
3736  if(array_key_exists($user_id, $all_notis) && $update_all_users)
3737  {
3738  $frm_noti->update();
3739  }
3740  else if($frm_noti->existsNotification() == false)
3741  {
3742  $frm_noti->insertAdminForce();
3743  }
3744  }
3745  }
3746 
3747  private function initNotificationSettingsForm()
3748  {
3749  if(null === $this->notificationSettingsForm)
3750  {
3751  $form = new ilPropertyFormGUI();
3752  $form->setFormAction($this->ctrl->getFormAction($this, 'updateNotificationSettings'));
3753  $form->setTitle($this->lng->txt('forums_notification_settings'));
3754 
3755  $radio_grp = new ilRadioGroupInputGUI('','notification_type');
3756  $radio_grp->setValue('default');
3757 
3758  $opt_default = new ilRadioOption($this->lng->txt("user_decides_notification"), 'default');
3759  $opt_0 = new ilRadioOption($this->lng->txt("settings_for_all_members"), 'all_users');
3760  $opt_1 = new ilRadioOption($this->lng->txt("settings_per_users"), 'per_user');
3761 
3762  $radio_grp->addOption($opt_default, 'default');
3763  $radio_grp->addOption($opt_0, 'all_users');
3764  $radio_grp->addOption($opt_1, 'per_user');
3765 
3766  $chb_2 = new ilCheckboxInputGUI($this->lng->txt('user_toggle_noti'), 'usr_toggle');
3767  $chb_2->setValue(1);
3768 
3769  $opt_0->addSubItem($chb_2);
3770  $form->addItem($radio_grp);
3771 
3772  $form->addCommandButton('updateNotificationSettings', $this->lng->txt('save'));
3773 
3774  $this->notificationSettingsForm = $form;
3775 
3776  return false;
3777  }
3778 
3779  return true;
3780  }
3781 
3782  public function getIcon($user_toggle_noti)
3783  {
3784  $icon = $user_toggle_noti
3785  ? "<img src=\"".ilUtil::getImagePath("icon_ok.png")."\" alt=\"".$this->lng->txt("enabled")."\" title=\"".$this->lng->txt("enabled")."\" border=\"0\" vspace=\"0\"/>"
3786  : "<img src=\"".ilUtil::getImagePath("icon_not_ok.png")."\" alt=\"".$this->lng->txt("disabled")."\" title=\"".$this->lng->txt("disabled")."\" border=\"0\" vspace=\"0\"/>";
3787  return $icon;
3788  }
3789 
3790  public function showMembersObject()
3791  {
3799  global $tree, $tpl, $ilTabs, $ilAccess, $ilErr;
3800 
3801  if(!$ilAccess->checkAccess('write', '', $this->ref_id))
3802  {
3803  $ilErr->raiseError($this->lng->txt('msg_no_perm_read'),$ilErr->MESSAGE);
3804  }
3805 
3806  $tpl->addBlockFile('ADM_CONTENT', 'adm_content', 'tpl.forums_members_list.html', 'Modules/Forum');
3807 
3808  $ilTabs->setTabActive('settings');
3809  $this->settingsTabs();
3810 
3811  // instantiate the property form
3812  if(!$this->initNotificationSettingsForm())
3813  {
3814  // if the form was just created set the values fetched from database
3815  $this->notificationSettingsForm->setValuesByArray(array(
3816  'notification_type' => $this->objProperties->getNotificationType(),
3817  'adm_force' => (bool) $this->objProperties->isAdminForceNoti(),
3818  'usr_toggle' => (bool) $this->objProperties->isUserToggleNoti()
3819  ));
3820  }
3821 
3822  // set form html into template
3823  $tpl->setVariable('NOTIFICATIONS_SETTINGS_FORM', $this->notificationSettingsForm->getHTML());
3824 
3825  include_once 'Modules/Forum/classes/class.ilForumNotification.php';
3826  include_once 'Modules/Forum/classes/class.ilObjForum.php';
3827 
3828  $frm_noti = new ilForumNotification($this->object->getRefId());
3829  $oParticipants = $this->getParticipantsObject();
3830 
3831  $moderator_ids = $frm_noti->_getModerators($this->object->getRefId());
3832 
3833  $admin_ids = $oParticipants->getAdmins();
3834  $member_ids = $oParticipants->getMembers();
3835  $tutor_ids = $oParticipants->getTutors();
3836 
3837  if($this->objProperties->getNotificationType() == 'default')
3838  {
3839  // update forum_notification table
3840  include_once 'Modules/Forum/classes/class.ilForumNotification.php';
3841  $forum_noti = new ilForumNotification($this->object->getRefId());
3842  $forum_noti->setAdminForce($this->objProperties->isAdminForceNoti());
3843  $forum_noti->setUserToggle($this->objProperties->isUserToggleNoti());
3844  $forum_noti->setForumId($this->objProperties->getObjId());
3845  }
3846  else if($this->objProperties->getNotificationType() == 'per_user')
3847  {
3848  $moderators = $this->getUserNotificationTableData($moderator_ids, $frm_noti);
3849  $admins = $this->getUserNotificationTableData($admin_ids, $frm_noti);
3850  $members = $this->getUserNotificationTableData($member_ids, $frm_noti);
3851  $tutors = $this->getUserNotificationTableData($tutor_ids, $frm_noti);
3852 
3853  $this->__showMembersTable($moderators, $admins, $members, $tutors);
3854  }
3855  }
3856 
3857  private function getUserNotificationTableData($user_ids, ilForumNotification $frm_noti)
3858  {
3859  $counter = 0;
3860  $users = array();
3861  foreach($user_ids as $user_id)
3862  {
3863  $frm_noti->setUserId($user_id);
3864  $user_toggle_noti = $frm_noti->isUserToggleNotification();
3865  $icon_ok = $this->getIcon(!$user_toggle_noti);
3866 
3867  $users[$counter]['user_id'] = ilUtil::formCheckbox(0, 'user_id[]', $user_id);
3868  $users[$counter]['login'] = ilObjUser::_lookupLogin($user_id);
3869  $name = ilObjUser::_lookupName($user_id);
3870  $users[$counter]['firstname'] = $name['firstname'];
3871  $users[$counter]['lastname'] = $name['lastname'];
3872  $users[$counter]['user_toggle_noti'] = $icon_ok;
3873  $counter++;
3874  }
3875  return $users;
3876  }
3877 
3878  private function __showMembersTable($moderators, $admins, $members, $tutors)
3879  {
3885  global $lng, $tpl, $ilCtrl;
3886 
3887  if($moderators)
3888  {
3889  $tbl_mod = new ilTable2GUI($this);
3890  $tbl_mod->setId('tbl_id_mod');
3891  $tbl_mod->setFormAction($ilCtrl->getFormAction($this, 'showMembers'));
3892  $tbl_mod->setTitle($lng->txt('moderators'));
3893 
3894  $tbl_mod->addColumn('', '', '1%', true);
3895  $tbl_mod->addColumn($lng->txt('login'), '', '10%');
3896  $tbl_mod->addColumn($lng->txt('firstname'), '', '10%');
3897  $tbl_mod->addColumn($lng->txt('lastname'), '', '10%');
3898  $tbl_mod->addColumn($lng->txt('allow_user_toggle_noti'), '', '10%');
3899  $tbl_mod->setSelectAllCheckbox('user_id');
3900 
3901  $tbl_mod->setRowTemplate('tpl.forums_members_row.html', 'Modules/Forum');
3902  $tbl_mod->setData($moderators);
3903 
3904  $tbl_mod->addMultiCommand('enableHideUserToggleNoti',$lng->txt('enable_hide_user_toggle'));
3905  $tbl_mod->addMultiCommand('disableHideUserToggleNoti',$lng->txt('disable_hide_user_toggle'));
3906 
3907  $tpl->setCurrentBlock('moderators_table');
3908  $tpl->setVariable('MODERATORS',$tbl_mod->getHTML());
3909  }
3910 
3911  if($admins)
3912  {
3913  $tbl_adm = new ilTable2GUI($this);
3914  $tbl_adm->setId('tbl_id_adm');
3915  $tbl_adm->setFormAction($ilCtrl->getFormAction($this, 'showMembers'));
3916  $tbl_adm->setTitle($lng->txt('administrator'));
3917 
3918  $tbl_adm->addColumn('', '', '1%', true);
3919  $tbl_adm->addColumn($lng->txt('login'), '', '10%');
3920  $tbl_adm->addColumn($lng->txt('firstname'), '', '10%');
3921  $tbl_adm->addColumn($lng->txt('lastname'), '', '10%');
3922  $tbl_adm->addColumn($lng->txt('allow_user_toggle_noti'), '', '10%');
3923  $tbl_adm->setSelectAllCheckbox('user_id');
3924  $tbl_adm->setRowTemplate('tpl.forums_members_row.html', 'Modules/Forum');
3925 
3926  $tbl_adm->setData($admins);
3927  $tbl_adm->addMultiCommand('enableHideUserToggleNoti',$lng->txt('enable_hide_user_toggle'));
3928  $tbl_adm->addMultiCommand('disableHideUserToggleNoti',$lng->txt('disable_hide_user_toggle'));
3929 
3930  $tpl->setCurrentBlock('admins_table');
3931  $tpl->setVariable('ADMINS',$tbl_adm->getHTML());
3932  }
3933 
3934  if($members)
3935  {
3936  $tbl_mem = new ilTable2GUI($this);
3937  $tbl_mem->setId('tbl_id_mem');
3938  $tbl_mem->setFormAction($ilCtrl->getFormAction($this, 'showMembers'));
3939  $tbl_mem->setTitle($lng->txt('members'));
3940 
3941  $tbl_mem->addColumn('', '', '1%', true);
3942  $tbl_mem->addColumn($lng->txt('login'), '', '10%');
3943  $tbl_mem->addColumn($lng->txt('firstname'), '', '10%');
3944  $tbl_mem->addColumn($lng->txt('lastname'), '', '10%');
3945  $tbl_mem->addColumn($lng->txt('allow_user_toggle_noti'), '', '10%');
3946  $tbl_mem->setSelectAllCheckbox('user_id');
3947  $tbl_mem->setRowTemplate('tpl.forums_members_row.html', 'Modules/Forum');
3948  $tbl_mem->setData($members);
3949 
3950  $tbl_mem->addMultiCommand('enableHideUserToggleNoti',$lng->txt('enable_hide_user_toggle'));
3951  $tbl_mem->addMultiCommand('disableHideUserToggleNoti',$lng->txt('disable_hide_user_toggle'));
3952 
3953  $tpl->setCurrentBlock('members_table');
3954  $tpl->setVariable('MEMBERS',$tbl_mem->getHTML());
3955  }
3956 
3957  if($tutors)
3958  {
3959  $tbl_tut = new ilTable2GUI($this);
3960  $tbl_tut->setId('tbl_id_tut');
3961  $tbl_tut->setFormAction($ilCtrl->getFormAction($this, 'showMembers'));
3962  $tbl_tut->setTitle($lng->txt('tutors'));
3963 
3964  $tbl_tut->addColumn('', '', '1%', true);
3965  $tbl_tut->addColumn($lng->txt('login'), '', '10%');
3966  $tbl_tut->addColumn($lng->txt('firstname'), '', '10%');
3967  $tbl_tut->addColumn($lng->txt('lastname'), '', '10%');
3968  $tbl_tut->addColumn($lng->txt('allow_user_toggle_noti'), '', '10%');
3969  $tbl_tut->setSelectAllCheckbox('user_id');
3970  $tbl_tut->setRowTemplate('tpl.forums_members_row.html', 'Modules/Forum');
3971  $tbl_tut->setData($tutors);
3972 
3973  $tbl_tut->addMultiCommand('enableHideUserToggleNoti',$lng->txt('enable_hide_user_toggle'));
3974  $tbl_tut->addMultiCommand('disableHideUserToggleNoti',$lng->txt('disable_hide_user_toggle'));
3975 
3976  $tpl->setCurrentBlock('tutors_table');
3977  $tpl->setVariable('TUTORS',$tbl_tut->getHTML());
3978  }
3979  }
3980 
3981  public function enableAdminForceNotiObject()
3982  {
3987  global $ilAccess, $ilErr;
3988  if(!$ilAccess->checkAccess('write', '', $this->ref_id))
3989  {
3990  $ilErr->raiseError($this->lng->txt('msg_no_perm_read'),$ilErr->MESSAGE);
3991  }
3992 
3993  if(!isset($_POST['user_id']) || !is_array($_POST['user_id']))
3994  {
3995  ilUtil::sendInfo($this->lng->txt('time_limit_no_users_selected'), true);
3996  }
3997  else
3998  {
3999  include_once 'Modules/Forum/classes/class.ilForumNotification.php';
4000  $frm_noti = new ilForumNotification($this->object->getRefId());
4001 
4002  foreach($_POST['user_id'] as $user_id)
4003  {
4004  $frm_noti->setUserId((int) $user_id);
4005  $is_enabled = $frm_noti->isAdminForceNotification();
4006 
4007  $frm_noti->setUserToggle(0);
4008  if(!$is_enabled)
4009  {
4010  $frm_noti->setAdminForce(1);
4011  $frm_noti->insertAdminForce();
4012  }
4013  }
4014 
4015  ilUtil::sendSuccess($this->lng->txt('saved_successfully'));
4016  }
4017 
4018  $this->showMembersObject();
4019  }
4020 
4021  public function disableAdminForceNotiObject()
4022  {
4027  global $ilAccess, $ilErr;
4028  if(!$ilAccess->checkAccess('write', '', $this->ref_id))
4029  {
4030  $ilErr->raiseError($this->lng->txt('msg_no_perm_read'),$ilErr->MESSAGE);
4031  }
4032 
4033  if(!isset($_POST['user_id']) || !is_array($_POST['user_id']))
4034  {
4035  ilUtil::sendInfo($this->lng->txt('time_limit_no_users_selected'));
4036  }
4037  else
4038  {
4039  include_once 'Modules/Forum/classes/class.ilForumNotification.php';
4040  $frm_noti = new ilForumNotification($this->object->getRefId());
4041 
4042  foreach($_POST['user_id'] as $user_id)
4043  {
4044  $frm_noti->setUserId((int) $user_id);
4045  $is_enabled = $frm_noti->isAdminForceNotification();
4046 
4047  if($is_enabled)
4048  {
4049  $frm_noti->deleteAdminForce();
4050  }
4051  }
4052 
4053  ilUtil::sendSuccess($this->lng->txt('saved_successfully'));
4054  }
4055 
4056  $this->showMembersObject();
4057  }
4058 
4059  public function enableHideUserToggleNotiObject()
4060  {
4065  global $ilAccess, $ilErr;
4066  if(!$ilAccess->checkAccess('write', '', $this->ref_id))
4067  {
4068  $ilErr->raiseError($this->lng->txt('msg_no_perm_read'),$ilErr->MESSAGE);
4069  }
4070  if(!isset($_POST['user_id']) || !is_array($_POST['user_id']))
4071  {
4072  ilUtil::sendInfo($this->lng->txt('time_limit_no_users_selected'));
4073  }
4074  else
4075  {
4076  include_once 'Modules/Forum/classes/class.ilForumNotification.php';
4077  $frm_noti = new ilForumNotification($this->object->getRefId());
4078 
4079  foreach($_POST['user_id'] as $user_id)
4080  {
4081  $frm_noti->setUserId((int) $user_id);
4082  $is_enabled = $frm_noti->isAdminForceNotification();
4083  $frm_noti->setUserToggle(1);
4084 
4085  if(!$is_enabled)
4086  {
4087  $frm_noti->setAdminForce(1);
4088  $frm_noti->insertAdminForce();
4089  }
4090  else
4091  {
4092  $frm_noti->updateUserToggle();
4093  }
4094  }
4095 
4096  ilUtil::sendSuccess($this->lng->txt('saved_successfully'));
4097  }
4098 
4099  $this->showMembersObject();
4100  }
4101 
4102  public function disableHideUserToggleNotiObject()
4103  {
4108  global $ilAccess, $ilErr;
4109  if(!$ilAccess->checkAccess('write', '', $this->ref_id))
4110  {
4111  $ilErr->raiseError($this->lng->txt('msg_no_perm_read'),$ilErr->MESSAGE);
4112  }
4113 
4114  if(!isset($_POST['user_id']) || !is_array($_POST['user_id']))
4115  {
4116  ilUtil::sendInfo($this->lng->txt('time_limit_no_users_selected'));
4117  }
4118  else
4119  {
4120  include_once 'Modules/Forum/classes/class.ilForumNotification.php';
4121  $frm_noti = new ilForumNotification($this->object->getRefId());
4122 
4123  foreach($_POST['user_id'] as $user_id)
4124  {
4125  $frm_noti->setUserId((int) $user_id);
4126  $is_enabled = $frm_noti->isAdminForceNotification();
4127  $frm_noti->setUserToggle(0);
4128  if($is_enabled)
4129  {
4130  $frm_noti->updateUserToggle();
4131  }
4132  else
4133  {
4134  $frm_noti->setAdminForce(1);
4135  $frm_noti->insertAdminForce();
4136  }
4137  }
4138 
4139  ilUtil::sendSuccess($this->lng->txt('saved_successfully'));
4140  }
4141 
4142  $this->showMembersObject();
4143  }
4144 
4145  public function markPostUnreadObject()
4146  {
4150  global $ilUser;
4151 
4152  if(isset($_GET['pos_pk']))
4153  {
4154  $this->object->markPostUnread($ilUser->getId(), (int) $_GET['pos_pk']);
4155  }
4156 
4157  $this->viewThreadObject();
4158  }
4159 
4160  public function markPostReadObject()
4161  {
4165  global $ilUser;
4166 
4167  $this->object->markPostRead($ilUser->getId(), (int) $this->objCurrentTopic->getId(), (int) $this->objCurrentPost->getId());
4168  $this->viewThreadObject();
4169  }
4170 
4171  protected function initHeaderAction($a_sub_type = null, $a_sub_id = null)
4172  {
4176  global $ilUser;
4177 
4178  $lg = parent::initHeaderAction();
4179 
4180  // Workaround: Do not show "desktop actions" in thread view
4181  if($this->objCurrentTopic->getId())
4182  {
4183  $container_obj = null;
4184  $lg->setContainerObject($container_obj);
4185  }
4186 
4187  if($lg instanceof ilObjForumListGUI)
4188  {
4189  if($ilUser->getId() != ANONYMOUS_USER_ID && $this->ilias->getSetting('forum_notification') != 0 )
4190  {
4191  $is_user_allowed_to_deactivate_notification = $this->isUserAllowedToDeactivateNotification();
4192 
4193  $frm = $this->object->Forum;
4194  $frm->setForumId($this->object->getId());
4195  $frm->setForumRefId($this->object->getRefId());
4196  $frm->setMDB2Wherecondition('top_frm_fk = %s ', array('integer'), array($frm->getForumId()));
4197  $frm_notificiation_enabled = $frm->isForumNotificationEnabled($ilUser->getId());
4198 
4199  if($this->objCurrentTopic->getId())
4200  {
4201  $this->ctrl->setParameter($this, 'thr_pk', $this->objCurrentTopic->getId());
4202  }
4203 
4204  if($this->isParentObjectCrsOrGrp())
4205  {
4206  // special behaviour for CRS/GRP-Forum notification!!
4207  if(
4208  $frm_notificiation_enabled &&
4209  $is_user_allowed_to_deactivate_notification
4210  )
4211  {
4212  $lg->addCustomCommand($this->ctrl->getLinkTarget($this, 'disableForumNotification'), "forums_disable_forum_notification");
4213  }
4214  else
4215  {
4216  $lg->addCustomCommand($this->ctrl->getLinkTarget($this, 'enableForumNotification'), "forums_enable_forum_notification");
4217  }
4218  }
4219  else
4220  {
4221  if($frm_notificiation_enabled)
4222  {
4223  $lg->addCustomCommand($this->ctrl->getLinkTarget($this, 'disableForumNotification'), "forums_disable_forum_notification");
4224  }
4225  else
4226  {
4227  $lg->addCustomCommand($this->ctrl->getLinkTarget($this, 'enableForumNotification'), "forums_enable_forum_notification");
4228  }
4229  }
4230 
4231  $topic_notification_enabled = false;
4232  if($this->objCurrentTopic->getId())
4233  {
4234  $topic_notification_enabled = $this->objCurrentTopic->isNotificationEnabled($ilUser->getId());
4235  if($topic_notification_enabled)
4236  {
4237  $lg->addCustomCommand($this->ctrl->getLinkTarget($this, 'toggleThreadNotification'), "forums_disable_notification");
4238  }
4239  else
4240  {
4241  $lg->addCustomCommand($this->ctrl->getLinkTarget($this, 'toggleThreadNotification'), "forums_enable_notification");
4242  }
4243  }
4244  $this->ctrl->setParameter($this, 'thr_pk', '');
4245 
4246  if($frm_notificiation_enabled || $topic_notification_enabled)
4247  {
4248  $lg->addHeaderIcon(
4249  "not_icon",
4250  ilUtil::getImagePath("notification_on.png"),
4251  $this->lng->txt("frm_notification_activated")
4252  );
4253  }
4254  else
4255  {
4256  $lg->addHeaderIcon(
4257  "not_icon",
4258  ilUtil::getImagePath("notification_off.png"),
4259  $this->lng->txt("frm_notification_deactivated")
4260  );
4261  }
4262  }
4263  }
4264 
4265  return $lg;
4266  }
4267 
4269  {
4270  if($this->objProperties->getNotificationType() == 'default')
4271  {
4272  return true;
4273  }
4274 
4275  if($this->objProperties->isUserToggleNoti() == 0)
4276  {
4277  return true;
4278  }
4279 
4280  if($this->isParentObjectCrsOrGrp());
4281  {
4282  global $ilUser;
4283 
4284  include_once 'Modules/Forum/classes/class.ilForumNotification.php';
4285 
4286  $frm_noti = new ilForumNotification((int) $_GET['ref_id']);
4287  $frm_noti->setUserId($ilUser->getId());
4288 
4289  $user_toggle = (int)$frm_noti->isUserToggleNotification();
4290  if($user_toggle == 0)
4291  {
4292  return true;
4293  }
4294  }
4295 
4296  return false;
4297  }
4298 
4299  private function isParentObjectCrsOrGrp()
4300  {
4301  global $tree;
4302 
4303  // check if there a parent-node is a grp or crs
4304  $grp_ref_id = $tree->checkForParentType($this->object->getRefId(), 'grp');
4305  $crs_ref_id = $tree->checkForParentType($this->object->getRefId(), 'crs');
4306 
4307  if($grp_ref_id == 0 && $crs_ref_id == 0)
4308  {
4309  return false;
4310  }
4311  return true;
4312  }
4313 
4317  public function getParticipantsObject()
4318  {
4319  global $tree, $ilErr;
4320 
4321  $grp_ref_id = $tree->checkForParentType($this->object->getRefId(), 'grp');
4322  $crs_ref_id = $tree->checkForParentType($this->object->getRefId(), 'crs');
4323 
4324  if($this->isParentObjectCrsOrGrp() == false)
4325  {
4326  $ilErr->raiseError($this->lng->txt('msg_no_perm_read'), $ilErr->MESSAGE);
4327  }
4328 
4332  $oParticipants = null;
4333 
4334  if($grp_ref_id > 0)
4335  {
4336  $parent_obj = ilObjectFactory::getInstanceByRefId($grp_ref_id);
4337  include_once 'Modules/Group/classes/class.ilGroupParticipants.php';
4338  $oParticipants = ilGroupParticipants::_getInstanceByObjId($parent_obj->getId());
4339  return $oParticipants;
4340  }
4341  else if($crs_ref_id > 0)
4342  {
4343  $parent_obj = ilObjectFactory::getInstanceByRefId($crs_ref_id);
4344 
4345  include_once 'Modules/Course/classes/class.ilCourseParticipants.php';
4346  $oParticipants = ilCourseParticipants::_getInstanceByObjId($parent_obj->getId());
4347  return $oParticipants;
4348  }
4349 
4350  return $oParticipants;
4351  }
4352 
4356  public function addToDeskObject()
4357  {
4362  global $ilSetting, $lng;
4363 
4364  if((int)$ilSetting->get('disable_my_offers'))
4365  {
4366  return $this->showThreadsObject();
4367  }
4368 
4369  include_once './Services/PersonalDesktop/classes/class.ilDesktopItemGUI.php';
4371  ilUtil::sendSuccess($lng->txt("added_to_desktop"));
4372  $this->showThreadsObject();
4373  }
4374 
4378  public function removeFromDeskObject()
4379  {
4380  global $ilSetting, $lng;
4381 
4382  if((int)$ilSetting->get('disable_my_offers'))
4383  {
4384  return $this->showThreadsObject();
4385  }
4386 
4387  include_once './Services/PersonalDesktop/classes/class.ilDesktopItemGUI.php';
4389  ilUtil::sendSuccess($lng->txt("removed_from_desktop"));
4390  $this->showThreadsObject();
4391  }
4392 }