ILIAS  release_4-4 Revision
All Data Structures Namespaces Files Functions Variables Modules 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  //sorting for threads
296  $rg_thr = new ilRadioGroupInputGUI($this->lng->txt('frm_sorting_threads'), 'thread_sorting');
297  $rg_thr->addOption(new ilRadioOption($this->lng->txt('order_by').' '.$this->lng->txt('date'), '0'));
298  $rg_thr->addOption(new ilRadioOption($this->lng->txt('sorting_manual_sticky'), '1'));
299  $a_form->addItem($rg_thr);
300  $rg_thr->setInfo($this->lng->txt('sticky_threads_always_on_top'));
301 
302  // sorting for postings
303  $rg_pro = new ilRadioGroupInputGUI($this->lng->txt('frm_default_view'), 'default_view');
304 
305  $rg_pro->addOption(new ilRadioOption($this->lng->txt('sort_by_posts'), ilForumProperties::VIEW_TREE));
306  $rg_sort_by_date = new ilRadioOption($this->lng->txt('sort_by_date'), ilForumProperties::VIEW_DATE);
307  $rg_pro->addOption($rg_sort_by_date);
308 
309  $view_direction_group_gui = new ilRadioGroupInputGUI('', 'default_view_sort_dir');
310  $view_desc = new ilRadioOption($this->lng->txt('descending_order'), ilForumProperties::VIEW_DATE_DESC);
311  $view_asc = new ilRadioOption($this->lng->txt('ascending_order'), ilForumProperties::VIEW_DATE_ASC);
312  $view_direction_group_gui->addOption($view_desc);
313  $view_direction_group_gui->addOption($view_asc);
314 
315  $rg_sort_by_date->addSubItem($view_direction_group_gui);
316  $a_form->addItem($rg_pro);
317 
318  if($ilSetting->get('enable_anonymous_fora') || $this->objProperties->isAnonymized())
319  {
320  $cb_prop = new ilCheckboxInputGUI($this->lng->txt('frm_anonymous_posting'), 'anonymized');
321  $cb_prop->setValue('1');
322  $cb_prop->setInfo($this->lng->txt('frm_anonymous_posting_desc'));
323  $a_form->addItem($cb_prop);
324  }
325 
326  if($ilSetting->get('enable_fora_statistics', false))
327  {
328  $cb_prop = new ilCheckboxInputGUI($this->lng->txt('frm_statistics_enabled'), 'statistics_enabled');
329  $cb_prop->setValue('1');
330  $cb_prop->setInfo($this->lng->txt('frm_statistics_enabled_desc'));
331  $a_form->addItem($cb_prop);
332  }
333 
334  $cb_prop = new ilCheckboxInputGUI($this->lng->txt('activate_new_posts'), 'post_activation');
335  $cb_prop->setValue('1');
336  $cb_prop->setInfo($this->lng->txt('post_activation_desc'));
337  $a_form->addItem($cb_prop);
338 
339  $frm_subject = new ilRadioGroupInputGUI($this->lng->txt('frm_subject_setting'), 'subject_setting');
340  $frm_subject->addOption(new ilRadioOption($this->lng->txt('preset_subject'), 'preset_subject'));
341  $frm_subject->addOption(new ilRadioOption($this->lng->txt('add_re_to_subject'), 'add_re_to_subject'));
342  $frm_subject->addOption(new ilRadioOption($this->lng->txt('empty_subject'), 'empty_subject'));
343 
344  $a_form->addItem($frm_subject);
345 
346  $cb_prop = new ilCheckboxInputGUI($this->lng->txt('mark_moderator_posts'), 'mark_mod_posts');
347  $cb_prop->setValue('1');
348  $cb_prop->setInfo($this->lng->txt('mark_moderator_posts_desc'));
349  $a_form->addItem($cb_prop);
350  }
351 
352  protected function getEditFormCustomValues(Array &$a_values)
353  {
354  $a_values["desc"] = $this->object->getLongDescription();
355  $a_values['default_view'] = $this->objProperties->getDefaultView();
356  $a_values['anonymized'] = $this->objProperties->isAnonymized();
357  $a_values['statistics_enabled'] = $this->objProperties->isStatisticEnabled();
358  $a_values['post_activation'] = $this->objProperties->isPostActivationEnabled();
359  $a_values['subject_setting'] = $this->objProperties->getSubjectSetting();
360  $a_values['mark_mod_posts'] = $this->objProperties->getMarkModeratorPosts();
361  $a_values['thread_sorting'] = $this->objProperties->getThreadSorting();
362 
363  $default_view =
364  in_array((int)$this->objProperties->getDefaultView(), array(ilForumProperties::VIEW_DATE_ASC, ilForumProperties::VIEW_DATE_DESC))
367  $a_values['default_view'] = $default_view;
368 
369  $default_view_sort_dir =
370  (int)$this->objProperties->getDefaultView() != (int)ilForumProperties::VIEW_TREE
371  ? (int)$this->objProperties->getDefaultView()
373 
374  $a_values['default_view_sort_dir'] = $default_view_sort_dir;
375  }
376 
377  protected function updateCustom(ilPropertyFormGUI $a_form)
378  {
382  global $ilSetting;
383 
384  $view = (int)$_POST['default_view'];
385  if($view == ilForumProperties::VIEW_DATE)
386  {
388  if((int)$_POST['default_view_sort_dir'] == ilForumProperties::VIEW_DATE_DESC)
389  {
391  }
392  }
393  $this->objProperties->setDefaultView($view);
394 
395  // BUGFIX FOR 11271
396  if(isset($_SESSION['viewmode']))
397  {
398  $_SESSION['viewmode'] = $view;
399  }
400 
401  if($ilSetting->get('enable_anonymous_fora') || $this->objProperties->isAnonymized())
402  {
403  $this->objProperties->setAnonymisation((int) $a_form->getInput('anonymized'));
404  }
405  if($ilSetting->get('enable_fora_statistics', false))
406  {
407  $this->objProperties->setStatisticsStatus((int) $a_form->getInput('statistics_enabled'));
408  }
409  $this->objProperties->setPostActivation((int) $a_form->getInput('post_activation'));
410  $this->objProperties->setSubjectSetting( $a_form->getInput('subject_setting'));
411  $this->objProperties->setMarkModeratorPosts((int) $a_form->getInput('mark_mod_posts'));
412  $this->objProperties->setThreadSorting((int)$a_form->getInput('thread_sorting'));
413 
414  $this->objProperties->update();
415  }
416 
421  private function getThreadEditingForm($a_thread_id)
422  {
423  $form = new ilPropertyFormGUI();
424  $this->ctrl->setParameter($this, 'thr_pk', $a_thread_id);
425  $form->setFormAction($this->ctrl->getFormAction($this, 'updateThread'));
426 
427  $ti_prop = new ilTextInputGUI($this->lng->txt('title'), 'title');
428  $ti_prop->setRequired(true);
429  $ti_prop->setMaxLength(255);
430  $ti_prop->setSize(50);
431  $form->addItem($ti_prop);
432 
433  $form->addCommandButton('updateThread', $this->lng->txt('save'));
434  $form->addCommandButton('showThreads', $this->lng->txt('cancel'));
435 
436  return $form;
437  }
438 
443  public function editThreadObject($a_thread_id, ilPropertyFormGUI $form = null)
444  {
448  global $ilTabs;
449 
450  if(!$this->is_moderator)
451  {
452  $this->ilias->raiseError($this->lng->txt('permission_denied'), $this->ilias->error_obj->MESSAGE);
453  }
454 
455  $ilTabs->setTabActive('forums_threads');
456 
457  if(!($form instanceof ilPropertyFormGUI))
458  {
459  $form = $this->getThreadEditingForm($a_thread_id);
460  $form->setValuesByArray(array(
461  'title' => ilForumTopic::_lookupTitle($a_thread_id)
462  ));
463  }
464 
465  $this->tpl->setContent($form->getHTML());
466  }
467 
471  public function updateThreadObject()
472  {
473  if(!$this->is_moderator)
474  {
475  $this->ilias->raiseError($this->lng->txt('permission_denied'), $this->ilias->error_obj->MESSAGE);
476  }
477 
478  if(!$this->objCurrentTopic->getId())
479  {
480  $this->showThreadsObject();
481  return;
482  }
483 
484  $forum_id = ilObjForum::lookupForumIdByObjId($this->object->getId());
485  if($this->objCurrentTopic->getForumId() != $forum_id)
486  {
487  $this->ilias->raiseError($this->lng->txt('permission_denied'), $this->ilias->error_obj->MESSAGE);
488  }
489 
490  $form = $this->getThreadEditingForm($this->objCurrentTopic->getId());
491  if(!$form->checkInput())
492  {
493  $form->setValuesByPost();
494  $this->editThreadObject($this->objCurrentTopic->getId(), $form);
495  return;
496  }
497 
498  $this->objCurrentTopic->setSubject($form->getInput('title'));
499  $this->objCurrentTopic->updateThreadTitle();
500 
501  ilUtil::sendSuccess($this->lng->txt('saved_successfully'));
502  $this->showThreadsObject();
503  }
504 
505  public function markAllReadObject()
506  {
510  global $ilUser;
511 
512  $this->object->markAllThreadsRead($ilUser->getId());
513 
514  ilUtil::sendInfo($this->lng->txt('forums_all_threads_marked_read'));
515 
516  $this->showThreadsObject();
517  }
518 
519  public function showThreadsObject()
520  {
521  $this->getSubTabs('showThreads');
522  $this->tpl->setRightContent($this->getRightColumnHTML());
523  $this->getCenterColumnHTML();
524  }
525  public function sortThreadsObject()
526  {
527  $this->getSubTabs('sortThreads');
528  $this->tpl->setRightContent($this->getRightColumnHTML());
529  $this->getCenterColumnHTML(true);
530  }
531 
532 
533  public function getSubTabs($subtab = 'showThreads')
534  {
535  global $ilTabs;
536 
537  if($this->objProperties->getThreadSorting() == 1 && $this->is_moderator)
538  {
539  $ilTabs->addSubTabTarget('show', $this->ctrl->getLinkTarget($this, 'showThreads'), 'showThreads', get_class($this), '', $subtab=='showThreads'? true : false );
540  $ilTabs->addSubTabTarget('sorting_header', $this->ctrl->getLinkTarget($this, 'sortThreads'), 'sortThreads', get_class($this), '', $subtab=='sortThreads'? true : false );
541  }
542  }
543  public function getContent()
544  {
551  global $ilUser, $ilAccess, $lng, $ilToolbar;
552 
553  if(!$ilAccess->checkAccess('read', '', $this->object->getRefId()))
554  {
555  $this->ilias->raiseError($lng->txt('permission_denied'), $this->ilias->error_obj->MESSAGE);
556  }
557 
558  $cmd = $this->ctrl->getCmd();
559  $frm = $this->object->Forum;
560  $frm->setForumId($this->object->getId());
561  $frm->setForumRefId($this->object->getRefId());
562  $frm->setMDB2Wherecondition('top_frm_fk = %s ', array('integer'), array($frm->getForumId()));
563 
564  $this->tpl->addBlockFile('ADM_CONTENT', 'adm_content', 'tpl.forums_threads_liste.html', 'Modules/Forum');
565 
566  if((int)strlen($this->confirmation_gui_html))
567  {
568  $this->tpl->setVariable('CONFIRMATION_GUI', $this->confirmation_gui_html);
569  }
570 
571  // Create topic button
572  if($ilAccess->checkAccess('add_thread', '', $this->object->getRefId()) && !$this->hideToolbar())
573  {
574  $ilToolbar->addButton($this->lng->txt('forums_new_thread'), $this->ctrl->getLinkTarget($this, 'createThread'));
575  }
576 
577  // Mark all topics as read button
578  include_once 'Services/Accessibility/classes/class.ilAccessKeyGUI.php';
579  if($ilUser->getId() != ANONYMOUS_USER_ID && !(int)strlen($this->confirmation_gui_html))
580  {
581  $ilToolbar->addButton(
582  $this->lng->txt('forums_mark_read'),
583  $this->ctrl->getLinkTarget($this, 'markAllRead'),
584  '',
586  );
587  $this->ctrl->clearParameters($this);
588  }
589 
590  // Import information: Topic (variable $topicData) means frm object, not thread
591  $topicData = $frm->getOneTopic();
592  if($topicData)
593  {
594  // Visit-Counter
595  $frm->setDbTable('frm_data');
596  $frm->setMDB2WhereCondition('top_pk = %s ', array('integer'), array($topicData['top_pk']));
597  $frm->updateVisits($topicData['top_pk']);
598 
599  include_once 'Modules/Forum/classes/class.ilForumTopicTableGUI.php';
600  if(!in_array($cmd, array('showThreads', 'sortThreads') ))
601  {
602  $cmd = 'showThreads';
603  }
604  $tbl = new ilForumTopicTableGUI($this, $cmd, '', (int) $_GET['ref_id'], $topicData, $this->is_moderator, $this->forum_overview_setting);
605  $tbl->setMapper($frm)->fetchData();
606  $tbl->populate();
607  $this->tpl->setVariable('THREADS_TABLE', $tbl->getHTML());
608  }
609 
610  // Permanent link
611  include_once 'Services/PermanentLink/classes/class.ilPermanentLinkGUI.php';
612  $permalink = new ilPermanentLinkGUI('frm', $this->object->getRefId());
613  $this->tpl->setVariable('PRMLINK', $permalink->getHTML());
614  }
615 
619  private function initForumCreateForm($object_type)
620  {
621  $this->create_form_gui = new ilPropertyFormGUI();
622  $this->create_form_gui->setTableWidth('600px');
623 
624  $this->create_form_gui->setTitle($this->lng->txt('frm_new'));
625  $this->create_form_gui->setTitleIcon(ilUtil::getImagePath('icon_frm.png'));
626 
627  // form action
628  $this->ctrl->setParameter($this, 'new_type', $object_type);
629  $this->create_form_gui->setFormAction($this->ctrl->getFormAction($this, 'save'));
630 
631  // title
632  $title_gui = new ilTextInputGUI($this->lng->txt('title'), 'title');
633  $title_gui->setSize(min(40, ilObject::TITLE_LENGTH));
634  $title_gui->setMaxLength(ilObject::TITLE_LENGTH);
635  $this->create_form_gui->addItem($title_gui);
636 
637  // description
638  $description_gui = new ilTextAreaInputGUI($this->lng->txt('desc'), 'desc');
639  $description_gui->setCols(40);
640  $description_gui->setRows(2);
641  $this->create_form_gui->addItem($description_gui);
642 
643  // view sorting threads
644  $sorting_threads_gui = new ilRadioGroupInputGUI($this->lng->txt('frm_sorting_threads'), 'thread_sorting');
645  $sort_dat = new ilRadioOption($this->lng->txt('order_by').' '.$this->lng->txt('date'), 0);
646  $sorting_threads_gui->addOption($sort_dat);
647 
648  $sort_man = new ilRadioOption($this->lng->txt('sorting_manual_sticky'), 1);
649  $sorting_threads_gui->addOption($sort_man);
650  $sorting_threads_gui->setInfo($this->lng->txt('sticky_threads_always_on_top'));
651  $this->create_form_gui->addItem($sorting_threads_gui);
652 
653  // view
654  $view_group_gui = new ilRadioGroupInputGUI($this->lng->txt('frm_default_view'), 'sort');
655  $view_hir = new ilRadioOption($this->lng->txt('order_by').' '.$this->lng->txt('answers'), ilForumProperties::VIEW_TREE);
656  $view_group_gui->addOption($view_hir);
657  $view_dat = new ilRadioOption($this->lng->txt('order_by').' '.$this->lng->txt('date'), ilForumProperties::VIEW_DATE);
658  $view_group_gui->addOption($view_dat);
659  $this->create_form_gui->addItem($view_group_gui);
660  $view_direction_group_gui = new ilRadioGroupInputGUI('', 'default_view_sort_dir');
661  $view_desc = new ilRadioOption($this->lng->txt('frm_post_sort_desc'), ilForumProperties::VIEW_DATE_DESC);
662  $view_direction_group_gui->addOption($view_desc);
663  $view_asc = new ilRadioOption($this->lng->txt('frm_post_sort_asc'), ilForumProperties::VIEW_DATE_ASC);
664  $view_direction_group_gui->addOption($view_asc);
665  $view_dat->addSubItem($view_direction_group_gui);
666 
667  // anonymized or not
668  $anonymize_gui = new ilCheckboxInputGUI($this->lng->txt('frm_anonymous_posting'), 'anonymized');
669  $anonymize_gui->setInfo($this->lng->txt('frm_anonymous_posting_desc'));
670  $anonymize_gui->setValue(1);
671 
672  if($this->ilias->getSetting('enable_anonymous_fora', false))
673  $anonymize_gui->setDisabled(true);
674  $this->create_form_gui->addItem($anonymize_gui);
675 
676  // statistics enabled or not
677  $statistics_gui = new ilCheckboxInputGUI($this->lng->txt('frm_statistics_enabled'), 'statistics_enabled');
678  $statistics_gui->setInfo($this->lng->txt('frm_statistics_enabled_desc'));
679  $statistics_gui->setValue(1);
680  if(!$this->ilias->getSetting('enable_fora_statistics', false))
681  $statistics_gui->setDisabled(true);
682  $this->create_form_gui->addItem($statistics_gui);
683 
684  $cb_prop = new ilCheckboxInputGUI($this->lng->txt('activate_new_posts'), 'post_activation');
685  $cb_prop->setValue('1');
686  $cb_prop->setInfo($this->lng->txt('post_activation_desc'));
687  $this->create_form_gui->addItem($cb_prop);
688 
689  $this->create_form_gui->addCommandButton('save', $this->lng->txt('save'));
690  $this->create_form_gui->addCommandButton('cancel', $this->lng->txt('cancel'));
691  }
692 
693  public function cancelObject($in_rep = false)
694  {
695  ilUtil::sendInfo($this->lng->txt('msg_cancel'), true);
696  ilUtil::redirect('ilias.php?baseClass=ilRepositoryGUI&cmd=frameset&ref_id='.$_GET['ref_id']);
697  }
698 
699  protected function afterSave(ilObjForum $forumObj)
700  {
704  global $rbacadmin;
705 
706  // save settings
707  $this->objProperties->setObjId($forumObj->getId());
708  $this->objProperties->setDefaultView(1);
709  $this->objProperties->setAnonymisation(0);
710  $this->objProperties->setStatisticsStatus(0);
711  $this->objProperties->setPostActivation(0);
712  $this->objProperties->setThreadSorting(0);
713  $this->objProperties->insert();
714 
715  $forumObj->createSettings();
716 
717  // ...finally assign moderator role to creator of forum object
718  $roles = array();
719  $roles[0] = ilObjForum::_lookupModeratorRole($forumObj->getRefId());
720 
721  $rbacadmin->assignUser($roles[0], $forumObj->getOwner(), 'n');
722 
723  // insert new forum as new topic into frm_data
724  $forumObj->saveData($roles);
725 
726  // always send a message
727  ilUtil::sendSuccess($this->lng->txt('frm_added'), true);
728 
729  $this->ctrl->setParameter($this, 'ref_id', $forumObj->getRefId());
730  ilUtil::redirect($this->ctrl->getLinkTarget($this, 'createThread', '', false, false));
731  }
732 
733  public function getTabs(ilTabsGUI $tabs_gui)
734  {
740  global $ilAccess, $ilHelp, $ilCtrl;
741 
742  $ilHelp->setScreenIdComponent("frm");
743 
744  $this->ctrl->setParameter($this, 'ref_id', $this->ref_id);
745 
746  include_once 'Services/Repository/classes/class.ilRepositoryExplorer.php';
747  $active = array(
748  '', 'showThreads', 'view', 'markAllRead',
749  'enableForumNotification', 'disableForumNotification', 'moveThreads', 'performMoveThreads',
750  'cancelMoveThreads', 'performThreadsAction', 'createThread', 'addThread',
751  'showUser', 'confirmDeleteThreads',
752  'merge','mergeThreads', 'cancelMergeThreads', 'performMergeThreads'
753  );
754 
755  (in_array($ilCtrl->getCmd(), $active)) ? $force_active = true : $force_active = false;
756  $tabs_gui->addTarget('forums_threads', $this->ctrl->getLinkTarget($this,'showThreads'), $ilCtrl->getCmd(), get_class($this), '', $force_active);
757 
758  // info tab
759  if($ilAccess->checkAccess('visible', '', $this->ref_id))
760  {
761  $force_active = ($this->ctrl->getNextClass() == 'ilinfoscreengui' || strtolower($_GET['cmdClass']) == 'ilnotegui') ? true : false;
762  $tabs_gui->addTarget('info_short',
763  $this->ctrl->getLinkTargetByClass(
764  array('ilobjforumgui', 'ilinfoscreengui'), 'showSummary'),
765  array('showSummary', 'infoScreen'),
766  '', '', $force_active);
767  }
768 
769  if($ilAccess->checkAccess('write', '', $this->ref_id))
770  {
771  $force_active = ($ilCtrl->getCmd() == 'edit') ? true : false;
772  $tabs_gui->addTarget('settings', $this->ctrl->getLinkTarget($this, 'edit'), 'edit', get_class($this), '', $force_active);
773  }
774 
775  if($ilAccess->checkAccess('write', '', $this->ref_id))
776  {
777  $tabs_gui->addTarget('frm_moderators', $this->ctrl->getLinkTargetByClass('ilForumModeratorsGUI', 'showModerators'), 'showModerators', get_class($this));
778  }
779 
780  if($this->ilias->getSetting('enable_fora_statistics', false) &&
781  ($this->objProperties->isStatisticEnabled() || $ilAccess->checkAccess('write', '', $this->ref_id)))
782  {
783  $force_active = ($ilCtrl->getCmd() == 'showStatistics') ? true : false;
784  $tabs_gui->addTarget('frm_statistics', $this->ctrl->getLinkTarget($this, 'showStatistics'), 'showStatistics', get_class($this), '', $force_active); //false
785  }
786 
787  if($ilAccess->checkAccess('write', '', $this->object->getRefId()))
788  {
789  $tabs_gui->addTarget('export', $this->ctrl->getLinkTargetByClass('ilexportgui', ''), '', 'ilexportgui');
790  }
791 
792  if($ilAccess->checkAccess('edit_permission', '', $this->ref_id))
793  {
794  $tabs_gui->addTarget('perm_settings', $this->ctrl->getLinkTargetByClass(array(get_class($this),'ilpermissiongui'), 'perm'), array('perm', 'info', 'owner'), 'ilpermissiongui');
795  }
796  }
797 
798  public function settingsTabs()
799  {
805  global $ilTabs, $ilAccess, $tree;
806 
807  $ilTabs->setTabActive('settings');
808  $ilTabs->addSubTabTarget('basic_settings', $this->ctrl->getLinkTarget($this, 'edit'), 'edit', get_class($this), '', $_GET['cmd']=='edit'? true : false );
809 
810  // notification tab
811  if($this->ilias->getSetting('forum_notification') > 0)
812  {
813  // check if there a parent-node is a grp or crs
814  $grp_ref_id = $tree->checkForParentType($this->object->getRefId(), 'grp');
815  $crs_ref_id = $tree->checkForParentType($this->object->getRefId(), 'crs');
816 
817  if((int)$grp_ref_id > 0 || (int)$crs_ref_id > 0 )
818  {
819  #show member-tab for notification if forum-notification is enabled in administration
820  if($ilAccess->checkAccess('write', '', $this->ref_id))
821  {
822  $mem_active = array('showMembers', 'forums_notification_settings');
823  (in_array($_GET['cmd'],$mem_active)) ? $force_mem_active = true : $force_mem_active = false;
824 
825  $ilTabs->addSubTabTarget('notifications', $this->ctrl->getLinkTarget($this, 'showMembers'), $_GET['cmd'], get_class($this), '', $force_mem_active);
826  }
827  }
828  }
829  return true;
830  }
831 
832  public function showStatisticsObject()
833  {
837  global $ilAccess;
838 
840  if(!$this->ilias->getSetting('enable_fora_statistics', false))
841  {
842  $this->ilias->raiseError($this->lng->txt('permission_denied'), $this->ilias->error_obj->MESSAGE);
843  }
844 
845  // if no read access -> intrusion detected
846  if(!$ilAccess->checkAccess('read', '', $_GET['ref_id']))
847  {
848  $this->ilias->raiseError($this->lng->txt('permission_denied'), $this->ilias->error_obj->MESSAGE);
849  }
850 
851  // if read access and statistics disabled -> intrusion detected
852  if(!$ilAccess->checkAccess('read', '', $_GET['ref_id']) && !$this->objProperties->isStatisticEnabled())
853  {
854  $this->ilias->raiseError($this->lng->txt('permission_denied'), $this->ilias->error_obj->MESSAGE);
855  }
856 
857  // if write access and statistics disabled -> ok, for forum admin
858  if($ilAccess->checkAccess('write', '', $_GET['ref_id']) &&
859  !$this->objProperties->isStatisticEnabled())
860  {
861  ilUtil::sendInfo($this->lng->txt('frm_statistics_disabled_for_participants'));
862  }
863 
864  $this->object->Forum->setForumId($this->object->getId());
865 
866  require_once 'Modules/Forum/classes/class.ilForumStatisticsTableGUI.php';
867 
868  $tbl = new ilForumStatisticsTableGUI($this, 'showStatistics');
869  $tbl->setId('il_frm_statistic_table_'.(int) $_GET['ref_id']);
870  $tbl->setTitle($this->lng->txt('statistic'), 'icon_usr_b.png', $this->lng->txt('obj_'.$this->object->getType()));
871 
872  $data = $this->object->Forum->getUserStatistic($this->is_moderator);
873  $result = array();
874  $counter = 0;
875  foreach($data as $row)
876  {
877  $result[$counter]['ranking'] = $row[0];
878  $result[$counter]['login'] = $row[1];
879  $result[$counter]['lastname'] = $row[2];
880  $result[$counter]['firstname'] = $row[3];
881 
882  ++$counter;
883  }
884  $tbl->setData($result);
885 
886  $this->tpl->setContent($tbl->getHTML());
887  }
888 
889  public static function _goto($a_target, $a_thread = 0, $a_posting = 0)
890  {
896  global $ilAccess, $ilErr, $lng;
897 
898  if($ilAccess->checkAccess('read', '', $a_target))
899  {
900  if($a_thread != 0)
901  {
902  $objTopic = new ilForumTopic($a_thread);
903  if ($objTopic->getFrmObjId() &&
904  $objTopic->getFrmObjId() != ilObject::_lookupObjectId($a_target))
905  {
906  $ref_ids = ilObject::_getAllReferences($objTopic->getFrmObjId());
907  foreach($ref_ids as $ref_id)
908  {
909  if($ilAccess->checkAccess('read', '', $ref_id))
910  {
911  $new_ref_id = $ref_id;
912  break;
913  }
914  }
915 
916  if (isset($new_ref_id) && $new_ref_id != $a_target)
917  {
918  ilUtil::redirect(ILIAS_HTTP_PATH."/goto.php?target=frm_".$new_ref_id."_".$a_thread."_".$a_posting);
919  }
920  }
921 
922  $_GET['ref_id'] = $a_target;
923  $_GET['pos_pk'] = $a_posting;
924  $_GET['thr_pk'] = $a_thread;
925  $_GET['anchor'] = $a_posting;
926  $_GET['cmdClass'] = 'ilObjForumGUI';
927  $_GET['cmd'] = 'viewThread';
928  $_GET['baseClass'] = 'ilRepositoryGUI';
929 
930  include_once('ilias.php');
931  exit();
932  }
933  else
934  {
935 
936  $_GET['ref_id'] = $a_target;
937  $_GET['baseClass'] = 'ilRepositoryGUI';
938  include_once('ilias.php');
939  exit();
940  }
941  }
942  else if($ilAccess->checkAccess('read', '', ROOT_FOLDER_ID))
943  {
944  $_GET['target'] = '';
945  $_GET['ref_id'] = ROOT_FOLDER_ID;
946  ilUtil::sendInfo(sprintf($lng->txt('msg_no_perm_read_item'),
948  $_GET['baseClass'] = 'ilRepositoryGUI';
949  include('ilias.php');
950  exit();
951  }
952 
953  $ilErr->raiseError($lng->txt('msg_no_perm_read'), $ilErr->FATAL);
954  }
955 
956  public function performDeleteThreadsObject()
957  {
961  global $lng;
962 
963  if(!$this->is_moderator)
964  {
965  $this->ilias->raiseError($lng->txt('permission_denied'), $this->ilias->error_obj->MESSAGE);
966  return $this->showThreadsObject();
967  }
968 
969  if(!isset($_POST['thread_ids']) || !is_array($_POST['thread_ids']))
970  {
971  ilUtil::sendInfo($this->lng->txt('select_at_least_one_thread'));
972  return $this->showThreadsObject();
973  }
974 
975  require_once 'Modules/Forum/classes/class.ilForum.php';
976  require_once 'Modules/Forum/classes/class.ilObjForum.php';
977 
978  $forumObj = new ilObjForum($_GET['ref_id']);
979 
980  $this->objProperties->setObjId($forumObj->getId());
981 
982  $frm = new ilForum();
983  foreach($_POST['thread_ids'] as $topic_id)
984  {
985  $frm->setForumId($forumObj->getId());
986  $frm->setForumRefId($forumObj->getRefId());
987 
988  $first_node = $frm->getFirstPostNode($topic_id);
989  if((int)$first_node['pos_pk'])
990  {
991  $frm->deletePost($first_node['pos_pk']);
992  ilUtil::sendInfo($lng->txt('forums_post_deleted'), true);
993  }
994  }
995 
996  $this->ctrl->redirect($this, 'showThreads');
997  }
998 
999  public function confirmDeleteThreads()
1000  {
1004  global $lng;
1005 
1006  if(!isset($_POST['thread_ids']) || !is_array($_POST['thread_ids']))
1007  {
1008  ilUtil::sendInfo($this->lng->txt('select_at_least_one_thread'));
1009  return $this->showThreadsObject();
1010  }
1011 
1012  if(!$this->is_moderator)
1013  {
1014  $this->ilias->raiseError($lng->txt('permission_denied'), $this->ilias->error_obj->MESSAGE);
1015  return $this->showThreadsObject();
1016  }
1017 
1018  include_once('Services/Utilities/classes/class.ilConfirmationGUI.php');
1019  $c_gui = new ilConfirmationGUI();
1020 
1021  $c_gui->setFormAction($this->ctrl->getFormAction($this, 'performDeleteThreads'));
1022  $c_gui->setHeaderText($this->lng->txt('frm_sure_delete_threads'));
1023  $c_gui->setCancel($this->lng->txt('cancel'), 'showThreads');
1024  $c_gui->setConfirm($this->lng->txt('confirm'), 'performDeleteThreads');
1025 
1026  foreach((array)$_POST['thread_ids'] as $thread_id)
1027  {
1028  $c_gui->addItem('thread_ids[]', $thread_id, ilForumTopic::_lookupTitle($thread_id));
1029  }
1030 
1031  $this->confirmation_gui_html = $c_gui->getHTML();
1032 
1033  $this->hideToolbar(true);
1034 
1035  return $this->tpl->setContent($c_gui->getHTML());
1036  }
1037 
1038  public function prepareThreadScreen(ilObjForum $a_forum_obj)
1039  {
1046  global $tpl, $lng, $ilTabs, $ilHelp;
1047 
1048  $ilHelp->setScreenIdComponent("frm");
1049 
1050  $tpl->getStandardTemplate();
1051  ilUtil::sendInfo();
1053 
1054  $tpl->setTitleIcon(ilUtil::getImagePath('icon_frm_b.png'));
1055 
1056  $ilTabs->setBackTarget($lng->txt('all_topics'),
1057  'ilias.php?baseClass=ilRepositoryGUI&amp;ref_id='.$_GET['ref_id']);
1058 
1059  // by answer view
1060  $this->ctrl->setParameter($this, 'thr_pk', $this->objCurrentTopic->getId());
1061  $this->ctrl->setParameter($this, 'pos_pk', $this->objCurrentPost->getId());
1062  $this->ctrl->setParameter($this, 'viewmode', ilForumProperties::VIEW_TREE);
1063 
1064  $ilTabs->addTarget('sort_by_posts', $this->ctrl->getLinkTarget($this, 'viewThread'));
1065 
1066  // by date view
1067  $this->ctrl->setParameter($this, 'viewmode', ilForumProperties::VIEW_DATE);
1068 
1069  $this->ctrl->setParameter($this, 'thr_pk', $this->objCurrentTopic->getId());
1070  $this->ctrl->setParameter($this, 'pos_pk', $this->objCurrentPost->getId());
1071  $ilTabs->addTarget('order_by_date', $this->ctrl->getLinkTarget($this, 'viewThread'));
1072  $this->ctrl->clearParameters($this);
1073 
1074  if($_SESSION['viewmode']== 'date'
1075  ||$_SESSION['viewmode']== ilForumProperties::VIEW_DATE)
1076  {
1077  $ilTabs->setTabActive('order_by_date');
1078  }
1079  else
1080  {
1081  $ilTabs->setTabActive('sort_by_posts');
1082  }
1083 
1087  $frm = $a_forum_obj->Forum;
1088  $frm->setForumId($a_forum_obj->getId());
1089  }
1090 
1092  {
1093  if($this->is_moderator)
1094  {
1095  $this->objCurrentPost->activatePostAndChildPosts();
1096  ilUtil::sendInfo($this->lng->txt('forums_post_and_children_were_activated'), true);
1097  }
1098 
1099  $this->viewThreadObject();
1100  }
1101 
1103  {
1104  if($this->is_moderator)
1105  {
1106  $this->objCurrentPost->activatePost();
1107  ilUtil::sendInfo($this->lng->txt('forums_post_was_activated'), true);
1108  }
1109 
1110  $this->viewThreadObject();
1111  }
1112 
1113  public function cancelPostActivationObject()
1114  {
1115  $this->viewThreadObject();
1116  }
1117 
1118  public function askForPostActivationObject()
1119  {
1120  if($this->is_moderator)
1121  {
1122  $this->setDisplayConfirmPostActivation(true);
1123  }
1124 
1125  $this->viewThreadObject();
1126  }
1127 
1128  public function setDisplayConfirmPostActivation($status = 0)
1129  {
1130  $this->display_confirm_post_activation = $status;
1131  }
1132 
1134  {
1136  }
1137 
1138  public function toggleThreadNotificationObject()
1139  {
1143  global $ilUser;
1144 
1145  if($this->objCurrentTopic->isNotificationEnabled($ilUser->getId()))
1146  {
1147  $this->objCurrentTopic->disableNotification($ilUser->getId());
1148  ilUtil::sendInfo($this->lng->txt('forums_notification_disabled'), true);
1149  }
1150  else
1151  {
1152  $this->objCurrentTopic->enableNotification($ilUser->getId());
1153  ilUtil::sendInfo($this->lng->txt('forums_notification_enabled'), true);
1154  }
1155 
1156  $this->viewThreadObject();
1157  }
1158 
1159  public function toggleStickinessObject()
1160  {
1161  if($this->is_moderator)
1162  {
1163  if($this->objCurrentTopic->isSticky())
1164  {
1165  $this->objCurrentTopic->unmakeSticky();
1166  }
1167  else
1168  {
1169  $this->objCurrentTopic->makeSticky();
1170  }
1171  }
1172 
1173  $this->viewThreadObject();
1174  }
1175 
1176  public function cancelPostObject()
1177  {
1178  $_GET['action'] = '';
1179 
1180  $this->viewThreadObject();
1181  }
1182 
1183  public function getDeleteFormHTML()
1184  {
1188  global $lng;
1189 
1191  $form_tpl = new ilTemplate('tpl.frm_delete_post_form.html', true, true, 'Modules/Forum');
1192 
1193  $form_tpl->setVariable('ANKER', $this->objCurrentPost->getId());
1194  $form_tpl->setVariable('SPACER', '<hr noshade="noshade" width="100%" size="1" align="center" />');
1195  $form_tpl->setVariable('TXT_DELETE', $lng->txt('forums_info_delete_post'));
1196  $this->ctrl->setParameter($this, 'action', 'ready_delete');
1197  $this->ctrl->setParameter($this, 'pos_pk', $this->objCurrentPost->getId());
1198  $this->ctrl->setParameter($this, 'thr_pk', $this->objCurrentPost->getThreadId());
1199  $this->ctrl->setParameter($this, 'orderby', $_GET['orderby']);
1200  $form_tpl->setVariable('FORM_ACTION', $this->ctrl->getLinkTarget($this, 'viewThread'));
1201  $this->ctrl->clearParameters($this);
1202  $form_tpl->setVariable('CANCEL_BUTTON', $lng->txt('cancel'));
1203  $form_tpl->setVariable('CONFIRM_BUTTON', $lng->txt('confirm'));
1204 
1205  return $form_tpl->get();
1206  }
1207 
1208  public function getActivationFormHTML()
1209  {
1213  global $lng;
1214 
1215  $form_tpl = new ilTemplate('tpl.frm_activation_post_form.html', true, true, 'Modules/Forum');
1216 
1217  $this->ctrl->setParameter($this, 'pos_pk', $this->objCurrentPost->getId());
1218  $this->ctrl->setParameter($this, 'thr_pk', $this->objCurrentPost->getThreadId());
1219  $this->ctrl->setParameter($this, 'orderby', $_GET['orderby']);
1220  $form_tpl->setVariable('FORM_ACTION', $this->ctrl->getFormAction($this, 'performPostActivation'));
1221  $form_tpl->setVariable('SPACER', '<hr noshade="noshade" width="100%" size="1" align="center" />');
1222  $form_tpl->setVariable('ANCHOR', $this->objCurrentPost->getId());
1223  $form_tpl->setVariable('TXT_ACT', $lng->txt('activate_post_txt'));
1224  $form_tpl->setVariable('CONFIRM_BUTTON', $lng->txt('activate_only_current'));
1225  $form_tpl->setVariable('CMD_CONFIRM', 'performPostActivation');
1226  $form_tpl->setVariable('CONFIRM_BRANCH_BUTTON', $lng->txt('activate_current_and_childs'));
1227  $form_tpl->setVariable('CMD_CONFIRM_BRANCH', 'performPostAndChildPostsActivation');
1228  $form_tpl->setVariable('CANCEL_BUTTON',$lng->txt('cancel'));
1229  $form_tpl->setVariable('CMD_CANCEL', 'cancelPostActivation');
1230  $this->ctrl->clearParameters($this);
1231 
1232  return $form_tpl->get();
1233  }
1234 
1235  public function getDeactivationFormHTML()
1236  {
1240  global $lng;
1241 
1242  $form_tpl = new ilTemplate('tpl.frm_deactivation_post_form.html', true, true, 'Modules/Forum');
1243 
1244  $this->ctrl->setParameter($this, 'pos_pk', $this->objCurrentPost->getId());
1245  $this->ctrl->setParameter($this, 'thr_pk', $this->objCurrentPost->getThreadId());
1246  $this->ctrl->setParameter($this, 'orderby', $_GET['orderby']);
1247  $form_tpl->setVariable('FORM_ACTION', $this->ctrl->getFormAction($this, 'performPostDeactivation'));
1248  $form_tpl->setVariable('SPACER', '<hr noshade="noshade" width="100%" size="1" align="center" />');
1249  $form_tpl->setVariable('ANCHOR', $this->objCurrentPost->getId());
1250  $form_tpl->setVariable('TXT_DEACT', $lng->txt('deactivate_post_txt'));
1251  $form_tpl->setVariable('CONFIRM_BUTTON', $lng->txt('deactivate_current_and_childs'));
1252  $form_tpl->setVariable('CMD_CONFIRM', 'performPostDeactivation');
1253  $form_tpl->setVariable('CANCEL_BUTTON',$lng->txt('cancel'));
1254  $form_tpl->setVariable('CMD_CANCEL', 'cancelPostDeactivation');
1255  $this->ctrl->clearParameters($this);
1256 
1257  return $form_tpl->get();
1258  }
1259 
1260  public function getCensorshipFormHTML()
1261  {
1266  global $lng, $frm;
1267 
1268  $form_tpl = new ilTemplate('tpl.frm_censorship_post_form.html', true, true, 'Modules/Forum');
1269 
1270  $form_tpl->setVariable('ANCHOR', $this->objCurrentPost->getId());
1271  $form_tpl->setVariable('SPACER', '<hr noshade="noshade" width="100%" size="1" align="center" />');
1272  $this->ctrl->setParameter($this, 'action', 'ready_censor');
1273  $this->ctrl->setParameter($this, 'pos_pk', $this->objCurrentPost->getId());
1274  $this->ctrl->setParameter($this, 'thr_pk', $this->objCurrentPost->getThreadId());
1275  $this->ctrl->setParameter($this, 'orderby', $_GET['orderby']);
1276  $form_tpl->setVariable('FORM_ACTION', $this->ctrl->getLinkTarget($this, 'viewThread'));
1277  $this->ctrl->clearParameters($this);
1278  $form_tpl->setVariable('TXT_CENS_MESSAGE', $lng->txt('forums_the_post'));
1279  $form_tpl->setVariable('TXT_CENS_COMMENT', $lng->txt('forums_censor_comment').':');
1280  $form_tpl->setVariable('CENS_MESSAGE', $frm->prepareText($this->objCurrentPost->getCensorshipComment(), 2));
1281 
1282 
1283  if($this->objCurrentPost->isCensored())
1284  {
1285  $form_tpl->setVariable('TXT_CENS', $lng->txt('forums_info_censor2_post'));
1286  $form_tpl->setVariable('YES_BUTTON', $lng->txt('yes'));
1287  $form_tpl->setVariable('NO_BUTTON', $lng->txt('no'));
1288  }
1289  else
1290  {
1291  $form_tpl->setVariable('TXT_CENS', $lng->txt('forums_info_censor_post'));
1292  $form_tpl->setVariable('CANCEL_BUTTON', $lng->txt('cancel'));
1293  $form_tpl->setVariable('CONFIRM_BUTTON', $lng->txt('confirm'));
1294  }
1295 
1296  return $form_tpl->get();
1297  }
1298 
1299  private function initReplyEditForm()
1300  {
1306  global $ilUser, $rbacsystem, $ilSetting;
1307 
1308  // init objects
1309  $oForumObjects = $this->getForumObjects();
1313  $frm = $oForumObjects['frm'];
1317  $oFDForum = $oForumObjects['file_obj'];
1318 
1319  require_once 'Services/Form/classes/class.ilPropertyFormGUI.php';
1320  $this->replyEditForm = new ilPropertyFormGUI();
1321  $this->replyEditForm->setTableWidth('100%');
1322 
1323  // titel
1324  if($_GET['action'] == 'showreply' || $_GET['action'] == 'ready_showreply')
1325  {
1326  $this->ctrl->setParameter($this, 'action', 'ready_showreply');
1327  }
1328  else
1329  {
1330  $this->ctrl->setParameter($this, 'action', 'ready_showedit');
1331  }
1332 
1333  // form action
1334  $this->ctrl->setParameter($this, 'pos_pk', $this->objCurrentPost->getId());
1335  $this->ctrl->setParameter($this, 'thr_pk', $this->objCurrentPost->getThreadId());
1336  $this->ctrl->setParameter($this, 'offset', (int)$_GET['offset']);
1337  $this->ctrl->setParameter($this, 'orderby', $_GET['orderby']);
1338  $this->replyEditForm->setFormAction($this->ctrl->getFormAction($this, 'savePost', $this->objCurrentPost->getId()));
1339  $this->ctrl->clearParameters($this);
1340 
1341  if($_GET['action'] == 'showreply' || $_GET['action'] == 'ready_showreply')
1342  {
1343  $this->replyEditForm->setTitle($this->lng->txt('forums_your_reply'));
1344  }
1345  else
1346  {
1347  $this->replyEditForm->setTitle($this->lng->txt('forums_edit_post'));
1348  }
1349 
1350  // alias
1351  if($this->objProperties->isAnonymized() &&
1352  in_array($_GET['action'], array('showreply', 'ready_showreply')))
1353  {
1354  $oAnonymousNameGUI = new ilTextInputGUI($this->lng->txt('forums_your_name'), 'alias');
1355  $oAnonymousNameGUI->setMaxLength(64);
1356  $oAnonymousNameGUI->setInfo($this->lng->txt('forums_use_alias'));
1357 
1358  $this->replyEditForm->addItem($oAnonymousNameGUI);
1359  }
1360 
1361  // subject
1362  $oSubjectGUI = new ilTextInputGUI($this->lng->txt('forums_subject'), 'subject');
1363  $oSubjectGUI->setMaxLength(64);
1364  $oSubjectGUI->setRequired(true);
1365 
1366  if($this->objProperties->getSubjectSetting() == 'empty_subject')
1367  $oSubjectGUI->setInfo($this->lng->txt('enter_new_subject'));
1368 
1369  $this->replyEditForm->addItem($oSubjectGUI);
1370 
1371  // post
1372  $oPostGUI = new ilTextAreaInputGUI(
1373  $_GET['action'] == 'showreply' || $_GET['action'] == 'ready_showreply' ? $this->lng->txt('forums_your_reply') : $this->lng->txt('forums_edit_post'),
1374  'message'
1375  );
1376  $oPostGUI->setRequired(true);
1377  $oPostGUI->setCols(50);
1378  $oPostGUI->setRows(15);
1379  $oPostGUI->setUseRte(true);
1380  $oPostGUI->addPlugin('latex');
1381  $oPostGUI->addButton('latex');
1382  $oPostGUI->addButton('pastelatex');
1383  $oPostGUI->addPlugin('ilfrmquote');
1384 
1385  //$oPostGUI->addPlugin('code');
1386  if($_GET['action'] == 'showreply' || $_GET['action'] == 'ready_showreply')
1387  {
1388  $oPostGUI->addButton('ilFrmQuoteAjaxCall');
1389  }
1390  $oPostGUI->removePlugin('advlink');
1391  $oPostGUI->setRTERootBlockElement('');
1392  $oPostGUI->usePurifier(true);
1393  $oPostGUI->disableButtons(array(
1394  'charmap',
1395  'undo',
1396  'redo',
1397  'justifyleft',
1398  'justifycenter',
1399  'justifyright',
1400  'justifyfull',
1401  'anchor',
1402  'fullscreen',
1403  'cut',
1404  'copy',
1405  'paste',
1406  'pastetext',
1407  'formatselect'
1408  ));
1409 
1410  if($_GET['action'] == 'showreply' || $_GET['action'] == 'ready_showreply')
1411  {
1412  $oPostGUI->setRTESupport($ilUser->getId(), 'frm~', 'frm_post', 'tpl.tinymce_frm_post.html', false, '3.4.7');
1413  }
1414  else
1415  {
1416  $oPostGUI->setRTESupport($this->objCurrentPost->getId(), 'frm', 'frm_post', 'tpl.tinymce_frm_post.html', false, '3.4.7');
1417  }
1418  // purifier
1419  require_once 'Services/Html/classes/class.ilHtmlPurifierFactory.php';
1420  $oPostGUI->setPurifier(ilHtmlPurifierFactory::_getInstanceByType('frm_post'));
1421 
1422  $this->replyEditForm->addItem($oPostGUI);
1423 
1424  // notification only if gen. notification is disabled and forum isn't anonymous
1425  include_once 'Services/Mail/classes/class.ilMail.php';
1426  $umail = new ilMail($ilUser->getId());
1427  if($rbacsystem->checkAccess('internal_mail', $umail->getMailObjectReferenceId()) &&
1428  !$frm->isThreadNotificationEnabled($ilUser->getId(), $this->objCurrentPost->getThreadId()) &&
1429  !$this->objProperties->isAnonymized())
1430  {
1431  $oNotificationGUI = new ilCheckboxInputGUI('', 'notify');
1432  $oNotificationGUI->setInfo($this->lng->txt('forum_notify_me'));
1433 
1434  $this->replyEditForm->addItem($oNotificationGUI);
1435  }
1436 
1437  // attachments
1438  $oFileUploadGUI = new ilFileWizardInputGUI($this->lng->txt('forums_attachments_add'), 'userfile');
1439  $oFileUploadGUI->setFilenames(array(0 => ''));
1440  $this->replyEditForm->addItem($oFileUploadGUI);
1441 
1442  require_once 'Services/Captcha/classes/class.ilCaptchaUtil.php';
1443  if(
1444  $ilUser->isAnonymous() &&
1445  !$ilUser->isCaptchaVerified() &&
1446  ilCaptchaUtil::isActiveForForum()
1447  )
1448  {
1449  require_once 'Services/Captcha/classes/class.ilCaptchaInputGUI.php';
1450  $captcha = new ilCaptchaInputGUI($this->lng->txt('cont_captcha_code'), 'captcha_code');
1451  $captcha->setRequired(true);
1452  $this->replyEditForm->addItem($captcha);
1453  }
1454 
1455  // edit attachments
1456  if(count($oFDForum->getFilesOfPost()) && ($_GET['action'] == 'showedit' || $_GET['action'] == 'ready_showedit'))
1457  {
1458  $oExistingAttachmentsGUI = new ilCheckboxGroupInputGUI($this->lng->txt('forums_delete_file'), 'del_file');
1459 
1460  foreach($oFDForum->getFilesOfPost() as $file)
1461  {
1462  $oAttachmentGUI = new ilCheckboxInputGUI($file['name'], 'del_file');
1463  $oAttachmentGUI->setValue($file['md5']);
1464  $oExistingAttachmentsGUI->addOption($oAttachmentGUI);
1465  }
1466  $this->replyEditForm->addItem($oExistingAttachmentsGUI);
1467  }
1468 
1469  // buttons
1470  $this->replyEditForm->addCommandButton('savePost', $this->lng->txt('create'));
1471  if($_GET['action'] == 'showreply' || $_GET['action'] == 'ready_showreply')
1472  {
1473  include_once 'Services/RTE/classes/class.ilRTE.php';
1474  $rtestring = ilRTE::_getRTEClassname();
1475 
1476  if(array_key_exists('show_rte', $_POST))
1477  {
1479  }
1480 
1481  if(strtolower($rtestring) != 'iltinymce' || !ilObjAdvancedEditing::_getRichTextEditorUserState())
1482  {
1483  $this->replyEditForm->addCommandButton('quotePost', $this->lng->txt('forum_add_quote'));
1484  }
1485  }
1486  $this->replyEditForm->addCommandButton('cancelPost', $this->lng->txt('cancel'));
1487  }
1488 
1489  private function getReplyEditForm()
1490  {
1491  if(null === $this->replyEditForm)
1492  {
1493  $this->initReplyEditForm();
1494  }
1495 
1496  return $this->replyEditForm;
1497  }
1498 
1499  public function savePostObject()
1500  {
1506  global $ilUser, $ilAccess, $lng;
1507 
1508  if(!isset($_POST['del_file']) || !is_array($_POST['del_file'])) $_POST['del_file'] = array();
1509 
1510  if($this->objCurrentTopic->isClosed())
1511  {
1512  $_GET['action'] = '';
1513  return $this->viewThreadObject();
1514  }
1515 
1516  $oReplyEditForm = $this->getReplyEditForm();
1517  if($oReplyEditForm->checkInput())
1518  {
1519  require_once 'Services/Captcha/classes/class.ilCaptchaUtil.php';
1520  if(
1521  $ilUser->isAnonymous() &&
1522  !$ilUser->isCaptchaVerified() &&
1523  ilCaptchaUtil::isActiveForForum()
1524  )
1525  {
1526  $ilUser->setCaptchaVerified(true);
1527  }
1528 
1529  // init objects
1530  $oForumObjects = $this->getForumObjects();
1534  $forumObj = $oForumObjects['forumObj'];
1538  $frm = $oForumObjects['frm'];
1539  $frm->setMDB2WhereCondition(' top_frm_fk = %s ', array('integer'), array($frm->getForumId()));
1540  $topicData = $frm->getOneTopic();
1541 
1542  // Generating new posting
1543  if($_GET['action'] == 'ready_showreply')
1544  {
1545  if(!$ilAccess->checkAccess('add_reply', '', (int)$_GET['ref_id']))
1546  {
1547  $this->ilias->raiseError($lng->txt('permission_denied'), $this->ilias->error_obj->MESSAGE);
1548  }
1549 
1550  // reply: new post
1551  $status = 1;
1552  $send_activation_mail = 0;
1553 
1554  if($this->objProperties->isPostActivationEnabled())
1555  {
1556  if(!$this->is_moderator)
1557  {
1558  $status = 0;
1559  $send_activation_mail = 1;
1560  }
1561  else if($this->objCurrentPost->isAnyParentDeactivated())
1562  {
1563  $status = 0;
1564  }
1565  }
1566 
1567  if($this->objProperties->isAnonymized())
1568  {
1569  if(!strlen($oReplyEditForm->getInput('alias')))
1570  {
1571  $user_alias = $this->lng->txt('forums_anonymous');
1572  }
1573  else
1574  {
1575  $user_alias = $oReplyEditForm->getInput('alias');
1576  }
1577  }
1578  else
1579  {
1580  $user_alias = $ilUser->getLogin();
1581  }
1582 
1583  $newPost = $frm->generatePost(
1584  $topicData['top_pk'],
1585  $this->objCurrentTopic->getId(),
1586  ($this->objProperties->isAnonymized() ? 0 : $ilUser->getId()),
1587  ilRTE::_replaceMediaObjectImageSrc($oReplyEditForm->getInput('message'), 0),
1588  $this->objCurrentPost->getId(),
1589  (int)$oReplyEditForm->getInput('notify'),
1590  $this->handleFormInput($oReplyEditForm->getInput('subject'), false),
1591  $user_alias,
1592  '',
1593  $status,
1594  $send_activation_mail
1595  );
1596 
1597  // mantis #8115: Mark parent as read
1598  $this->object->markPostRead($ilUser->getId(), (int) $this->objCurrentTopic->getId(), (int) $this->objCurrentPost->getId());
1599 
1600  // copy temporary media objects (frm~)
1601  include_once 'Services/MediaObjects/classes/class.ilObjMediaObject.php';
1602  $mediaObjects = ilRTE::_getMediaObjects($oReplyEditForm->getInput('message'), 0);
1603  $myMediaObjects = ilObjMediaObject::_getMobsOfObject('frm~:html', $ilUser->getId());
1604  foreach($mediaObjects as $mob)
1605  {
1606  foreach($myMediaObjects as $myMob)
1607  {
1608  if($mob == $myMob)
1609  {
1610  // change usage
1611  ilObjMediaObject::_removeUsage($mob, 'frm~:html', $ilUser->getId());
1612  break;
1613  }
1614  }
1615  ilObjMediaObject::_saveUsage($mob, 'frm:html', $newPost);
1616  }
1617 
1618  $oFDForum = new ilFileDataForum($forumObj->getId(), $newPost);
1619  $file = $_FILES['userfile'];
1620  if(is_array($file) && !empty($file))
1621  {
1622  $oFDForum->storeUploadedFile($file);
1623  }
1624 
1625  // FINALLY SEND MESSAGE
1626  if ($this->ilias->getSetting("forum_notification") == 1 && (int)$status )
1627  {
1628  $objPost = new ilForumPost((int)$newPost, $this->is_moderator);
1629 
1630  $post_data = array();
1631  $post_data = $objPost->getDataAsArray();
1632  $titles = $this->getTitlesByRefId(array($this->object->getRefId()));
1633  $post_data["top_name"] = $titles[0];
1634  $post_data["ref_id"] = $this->object->getRefId();
1635 
1636  $frm->__sendMessage($objPost->getParentId(), $post_data);
1637 
1638  $frm->sendForumNotifications($post_data);
1639  $frm->sendThreadNotifications($post_data);
1640  }
1641 
1642  $message = '';
1643  if(!$this->is_moderator && !$status)
1644  {
1645  $message .= $lng->txt('forums_post_needs_to_be_activated');
1646  }
1647  else
1648  {
1649  $message .= $lng->txt('forums_post_new_entry');
1650  }
1651 
1652  $_SESSION['frm'][(int)$_GET['thr_pk']]['openTreeNodes'][] = (int)$this->objCurrentPost->getId();
1653 
1654  ilUtil::sendSuccess($message, true);
1655  $this->ctrl->setParameter($this, 'pos_pk', $newPost);
1656  $this->ctrl->setParameter($this, 'thr_pk', $this->objCurrentPost->getThreadId());
1657  $this->ctrl->redirect($this, 'viewThread');
1658  }
1659  else
1660  {
1661  if((!$this->is_moderator &&
1662  !$this->objCurrentPost->isOwner($ilUser->getId())) || $this->objCurrentPost->isCensored() ||
1663  $ilUser->getId() == ANONYMOUS_USER_ID)
1664  {
1665  $this->ilias->raiseError($lng->txt('permission_denied'), $this->ilias->error_obj->MESSAGE);
1666  }
1667 
1668  // remove usage of deleted media objects
1669  include_once 'Services/MediaObjects/classes/class.ilObjMediaObject.php';
1670  $oldMediaObjects = ilObjMediaObject::_getMobsOfObject('frm:html', $this->objCurrentPost->getId());
1671  $curMediaObjects = ilRTE::_getMediaObjects($oReplyEditForm->getInput('message'), 0);
1672  foreach($oldMediaObjects as $oldMob)
1673  {
1674  $found = false;
1675  foreach($curMediaObjects as $curMob)
1676  {
1677  if($oldMob == $curMob)
1678  {
1679  $found = true;
1680  break;
1681  }
1682  }
1683  if(!$found)
1684  {
1685  if(ilObjMediaObject::_exists($oldMob))
1686  {
1687  ilObjMediaObject::_removeUsage($oldMob, 'frm:html', $this->objCurrentPost->getId());
1688  $mob_obj = new ilObjMediaObject($oldMob);
1689  $mob_obj->delete();
1690  }
1691  }
1692  }
1693 
1694  // if post has been edited posting mus be activated again by moderator
1695  $status = 1;
1696  $send_activation_mail = 0;
1697 
1698  if($this->objProperties->isPostActivationEnabled())
1699  {
1700  if(!$this->is_moderator)
1701  {
1702  $status = 0;
1703  $send_activation_mail = 1;
1704  }
1705  else if($this->objCurrentPost->isAnyParentDeactivated())
1706  {
1707  $status = 0;
1708  }
1709  }
1710  $this->objCurrentPost->setStatus($status);
1711 
1712  $this->objCurrentPost->setSubject($this->handleFormInput($oReplyEditForm->getInput('subject'), false));
1713  $this->objCurrentPost->setMessage(ilRTE::_replaceMediaObjectImageSrc($oReplyEditForm->getInput('message'), 0));
1714  $this->objCurrentPost->setNotification((int)$oReplyEditForm->getInput('notify'));
1715  $this->objCurrentPost->setChangeDate(date('Y-m-d H:i:s'));
1716  $this->objCurrentPost->setUpdateUserId($ilUser->getId());
1717 
1718  // edit: update post
1719  if($this->objCurrentPost->update())
1720  {
1721  $this->objCurrentPost->reload();
1722 
1723  // Change news item accordingly
1724  include_once 'Services/News/classes/class.ilNewsItem.php';
1725  // note: $this->objCurrentPost->getForumId() does not give us the forum ID here (why?)
1726  $news_id = ilNewsItem::getFirstNewsIdForContext($forumObj->getId(),
1727  'frm', $this->objCurrentPost->getId(), 'pos');
1728  if($news_id > 0)
1729  {
1730  $news_item = new ilNewsItem($news_id);
1731  $news_item->setTitle($this->objCurrentPost->getSubject());
1732  $news_item->setContent(ilRTE::_replaceMediaObjectImageSrc($frm->prepareText(
1733  $this->objCurrentPost->getMessage(), 0), 1)
1734  );
1735  $news_item->update();
1736  }
1737 
1738  // attachments
1739  $oFDForum = $oForumObjects['file_obj'];
1740 
1741  $file = $_FILES['userfile'];
1742  if(is_array($file) && !empty($file))
1743  {
1744  $oFDForum->storeUploadedFile($file);
1745  }
1746 
1747  $file2delete = $oReplyEditForm->getInput('del_file');
1748  if(is_array($file2delete) && count($file2delete))
1749  {
1750  $oFDForum->unlinkFilesByMD5Filenames($file2delete);
1751  }
1752  }
1753 
1754  if (!$status && $send_activation_mail)
1755  {
1756  $pos_data = $this->objCurrentPost->getDataAsArray();
1757  $pos_data["top_name"] = $this->object->getTitle();
1758  $frm->sendPostActivationNotification($pos_data);
1759  }
1760 
1761  ilUtil::sendSuccess($lng->txt('forums_post_modified'), true);
1762  $this->ctrl->setParameter($this, 'pos_pk', $this->objCurrentPost->getId());
1763  $this->ctrl->setParameter($this, 'thr_pk', $this->objCurrentPost->getThreadId());
1764  $this->ctrl->setParameter($this, 'viewmode', $_SESSION['viewmode']);
1765  $this->ctrl->redirect($this, 'viewThread');
1766  }
1767  }
1768  else
1769  {
1770  $_GET['action'] = substr($_GET['action'], 6);
1771  }
1772  return $this->viewThreadObject();
1773  }
1774 
1775  private function hideToolbar($a_flag = null)
1776  {
1777  if(null === $a_flag)
1778  {
1779  return $this->hideToolbar;
1780  }
1781 
1782  $this->hideToolbar = $a_flag;
1783  return $this;
1784  }
1785 
1786  public function quotePostObject()
1787  {
1788  if(!is_array($_POST['del_file'])) $_POST['del_file'] = array();
1789 
1790  if($this->objCurrentTopic->isClosed())
1791  {
1792  $_GET['action'] = '';
1793  return $this->viewThreadObject();
1794  }
1795 
1796  $oReplyEditForm = $this->getReplyEditForm();
1797 
1798  // remove mandatory fields
1799  $oReplyEditForm->getItemByPostVar('subject')->setRequired(false);
1800  $oReplyEditForm->getItemByPostVar('message')->setRequired(false);
1801 
1802  $oReplyEditForm->checkInput();
1803 
1804  // add mandatory fields
1805  $oReplyEditForm->getItemByPostVar('subject')->setRequired(true);
1806  $oReplyEditForm->getItemByPostVar('message')->setRequired(true);
1807 
1808  $_GET['action'] = 'showreply';
1809 
1810  $this->viewThreadObject();
1811  }
1812 
1813  public function getQuotationHTMLAsynchObject()
1814  {
1815  $oForumObjects = $this->getForumObjects();
1819  $frm = $oForumObjects['frm'];
1820 
1821  require_once 'Modules/Forum/classes/class.ilForumAuthorInformation.php';
1822  $authorinfo = new ilForumAuthorInformation(
1823  $this->objCurrentPost->getUserId(),
1824  $this->objCurrentPost->getUserAlias(),
1825  $this->objCurrentPost->getImportName()
1826  );
1827 
1828  $html = ilRTE::_replaceMediaObjectImageSrc($frm->prepareText($this->objCurrentPost->getMessage(), 1, $authorinfo->getAuthorName()), 1);
1829  echo $html;
1830  exit();
1831  }
1832 
1833  private function getForumObjects()
1834  {
1835  if(null === $this->forumObjects)
1836  {
1837  $forumObj = $this->object;
1838  $file_obj = new ilFileDataForum($forumObj->getId(), $this->objCurrentPost->getId());
1839  $frm = $forumObj->Forum;
1840  $frm->setForumId($forumObj->getId());
1841  $frm->setForumRefId($forumObj->getRefId());
1842 
1843  $this->forumObjects['forumObj'] = $forumObj;
1844  $this->forumObjects['frm'] = $frm;
1845  $this->forumObjects['file_obj'] = $file_obj;
1846  }
1847 
1848  return $this->forumObjects;
1849  }
1850 
1851  public function getForumExplorer()
1852  {
1853  include_once 'Modules/Forum/classes/class.ilForumExplorer.php';
1854 
1855  $explorer = new ilForumExplorer(
1856  $this,
1857  $this->objCurrentTopic,
1858  $this->objProperties
1859  );
1860 
1861  return $explorer->render()->getHtml();
1862  }
1863 
1865  {
1866  include_once 'Services/JSON/classes/class.ilJsonUtil.php';
1867  include_once 'Modules/Forum/classes/class.ilForumExplorer.php';
1868 
1869  $response = new stdClass();
1870  $response->success = false;
1871 
1872  if( $_GET['nodeId'] )
1873  {
1874  $response->success = true;
1875  $response->children = array();
1876 
1877  $key = array_search((int)$_GET['nodeId'], (array)$_SESSION['frm'][(int)$_GET['thr_pk']]['openTreeNodes']);
1878  if( false === $key )
1879  {
1880  $_SESSION['frm'][(int)$_GET['thr_pk']]['openTreeNodes'][] = (int)$_GET['nodeId'];
1881  }
1882 
1883  $children = $this->objCurrentTopic->getNestedSetPostChildren(
1884  (int)$_GET['nodeId'],
1885  (array)$_SESSION['frm'][(int)$_GET['thr_pk']]['openTreeNodes']
1886  );
1887 
1888  $frm = new ilForum();
1889  $pageHits = $frm->getPageHits();
1890 
1891  $fetchedNodes = array();
1892 
1893  foreach( $children as $child )
1894  {
1895  if($child['parent_pos'] != (int)$_GET['nodeId'] &&
1896  !in_array($child['parent_pos'], $fetchedNodes))
1897  {
1898  continue;
1899  }
1900 
1901  $fetchedNodes[] = $child['pos_pk'];
1902 
1903  $this->ctrl->setParameter($this, 'thr_pk', (int)$_GET['thr_pk']);
1904 
1906  $child,
1907  $this,
1908  $pageHits
1909  );
1910 
1911  $responseChild = new stdClass();
1912  $responseChild->nodeId = $child['pos_pk'];
1913  $responseChild->parentId = $child['parent_pos'];
1914  $responseChild->hasChildren = ($child['children'] >= 1);
1915  $responseChild->fetchedWithChildren = in_array((int)$child['pos_pk'], (array)$_SESSION['frm'][(int)$_GET['thr_pk']]['openTreeNodes']);
1916  $responseChild->html = $html;
1917 
1918  $response->children[] = $responseChild;
1919  }
1920  }
1921 
1922  echo ilJsonUtil::encode($response);
1923  exit();
1924  }
1925 
1926  public function setTreeStateAsynchObject()
1927  {
1928  include_once 'Services/JSON/classes/class.ilJsonUtil.php';
1929 
1930  $response = new stdClass();
1931  $response->success = true;
1932 
1933  if( $_GET['nodeId'] )
1934  {
1935  if( $_GET['nodeId'] > 0 )
1936  {
1937  $key = array_search((int)$_GET['nodeId'], (array)$_SESSION['frm'][(int)$_GET['thr_pk']]['openTreeNodes']);
1938  if( false === $key )
1939  {
1940  $_SESSION['frm'][(int)$_GET['thr_pk']]['openTreeNodes'][] = (int)$_GET['nodeId'];
1941  }
1942  }
1943  else
1944  {
1945  $key = array_search((int)abs($_GET['nodeId']), (array)$_SESSION['frm'][(int)$_GET['thr_pk']]['openTreeNodes']);
1946  if( false !== $key )
1947  {
1948  unset($_SESSION['frm'][(int)$_GET['thr_pk']]['openTreeNodes'][$key]);
1949  }
1950  }
1951  }
1952 
1953  // Guarantee continuous keys
1954  shuffle($_SESSION['frm'][(int)$_GET['thr_pk']]['openTreeNodes']);
1955  exit();
1956  }
1957 
1958  public function viewThreadObject()
1959  {
1970  global $tpl, $lng, $ilUser, $ilAccess, $rbacreview, $ilNavigationHistory, $ilCtrl, $frm, $ilToolbar, $ilLocator;
1971 
1972  $tpl->addCss('./Modules/Forum/css/forum_tree.css');
1973  if(!isset($_SESSION['viewmode']))
1974  {
1975  $_SESSION['viewmode'] = $this->objProperties->getDefaultView();
1976  }
1977 
1978  // quick and dirty: check for treeview
1979  if(!isset($_SESSION['thread_control']['old']))
1980  {
1981  $_SESSION['thread_control']['old'] = $_GET['thr_pk'];
1982  $_SESSION['thread_control']['new'] = $_GET['thr_pk'];
1983  }
1984  else
1985  if(isset($_SESSION['thread_control']['old']) && $_GET['thr_pk'] != $_SESSION['thread_control']['old'])
1986  {
1987  $_SESSION['thread_control']['new'] = $_GET['thr_pk'];
1988  }
1989 
1990  if(isset($_GET['viewmode']) && $_GET['viewmode'] != $_SESSION['viewmode'])
1991  {
1992  $_SESSION['viewmode'] = $_GET['viewmode'];
1993  }
1994 
1995  if( (isset($_GET['action']) && $_SESSION['viewmode'] != ilForumProperties::VIEW_DATE)
1996  ||($_SESSION['viewmode'] == ilForumProperties::VIEW_TREE))
1997  {
1999  }
2000  else
2001  {
2003  }
2004 
2005  if(!$ilAccess->checkAccess('read', '', $this->object->getRefId()))
2006  {
2007  $this->ilias->raiseError($lng->txt('permission_denied'), $this->ilias->error_obj->MESSAGE);
2008  }
2009 
2010  // init objects
2011  $oForumObjects = $this->getForumObjects();
2015  $forumObj = $oForumObjects['forumObj'];
2019  $frm = $oForumObjects['frm'];
2023  $file_obj = $oForumObjects['file_obj'];
2024 
2025  // download file
2026  if($_GET['file'])
2027  {
2028  if(!$path = $file_obj->getFileDataByMD5Filename($_GET['file']))
2029  {
2030  ilUtil::sendFailure($this->lng->txt('error_reading_file'));
2031  }
2032  else
2033  {
2034  ilUtil::deliverFile($path['path'], $path['clean_filename']);
2035  }
2036  }
2037 
2038  if(!$this->objCurrentTopic->getId())
2039  {
2040  $ilCtrl->redirect($this, 'showThreads');
2041  }
2042 
2043  // Set context for login
2044  $append = '_'.$this->objCurrentTopic->getId().
2045  ($this->objCurrentPost->getId() ? '_'.$this->objCurrentPost->getId() : '');
2046  $tpl->setLoginTargetPar('frm_'.$_GET['ref_id'].$append);
2047 
2048  // delete temporary media object (not in case a user adds media objects and wants to save an invalid form)
2049  if($_GET['action'] != 'showreply' && $_GET['action'] != 'showedit')
2050  {
2051  try
2052  {
2053  include_once 'Services/MediaObjects/classes/class.ilObjMediaObject.php';
2054  $mobs = ilObjMediaObject::_getMobsOfObject('frm~:html', $ilUser->getId());
2055  foreach($mobs as $mob)
2056  {
2057  if(ilObjMediaObject::_exists($mob))
2058  {
2059  ilObjMediaObject::_removeUsage($mob, 'frm~:html', $ilUser->getId());
2060  $mob_obj = new ilObjMediaObject($mob);
2061  $mob_obj->delete();
2062  }
2063  }
2064  }
2065  catch(Exception $e)
2066  {
2067  }
2068  }
2069 
2070  require_once './Modules/Forum/classes/class.ilObjForum.php';
2071  require_once './Modules/Forum/classes/class.ilFileDataForum.php';
2072 
2073  $lng->loadLanguageModule('forum');
2074 
2075  // add entry to navigation history
2076  if (!$this->getCreationMode() &&
2077  $ilAccess->checkAccess('read', '', $this->object->getRefId()))
2078  {
2079  $ilCtrl->setParameter($this, 'thr_pk', $this->objCurrentTopic->getId());
2080  $ilNavigationHistory->addItem($this->object->getRefId(), $ilCtrl->getLinkTarget($this, 'showThreads'), 'frm');
2081  }
2082 
2083  // save last access
2084  $forumObj->updateLastAccess($ilUser->getId(), (int) $this->objCurrentTopic->getId());
2085 
2086  $this->prepareThreadScreen($forumObj);
2087 
2088  $tpl->addBlockFile('ADM_CONTENT', 'adm_content', 'tpl.forums_threads_view.html', 'Modules/Forum');
2089 
2090  if(isset($_GET['anchor']))
2091  {
2092  $tpl->setVariable('JUMP2ANCHOR_ID', (int)$_GET['anchor']);
2093  }
2094 
2095  if ($_SESSION['viewmode'] == 'date'
2096  || $_SESSION['viewmode'] == ilForumProperties::VIEW_DATE)
2097  {
2098  $orderField = 'frm_posts_tree.fpt_date';
2099  $this->objCurrentTopic->setOrderDirection(
2100  in_array($this->objProperties->getDefaultView(), array(ilForumProperties::VIEW_DATE_ASC, ilForumProperties::VIEW_TREE))
2101  ? 'ASC' : 'DESC'
2102  );
2103  }
2104  else
2105  {
2106  $orderField = 'frm_posts_tree.rgt';
2107  $this->objCurrentTopic->setOrderDirection('DESC');
2108  }
2109 
2110  // get forum- and thread-data
2111  $frm->setMDB2WhereCondition('top_frm_fk = %s ', array('integer'), array($frm->getForumId()));
2112 
2113  if(is_array($topicData = $frm->getOneTopic()))
2114  {
2115  // Visit-Counter for topic
2116  $this->objCurrentTopic->updateVisits();
2117 
2118  $tpl->setTitle($lng->txt('forums_thread')." \"".$this->objCurrentTopic->getSubject()."\"");
2119 
2120  // ********************************************************************************
2121  // build location-links
2122  $ilLocator->addRepositoryItems();
2123  $ilLocator->addItem($this->object->getTitle(), $ilCtrl->getLinkTarget($this, ""), "_top");
2124  $tpl->setLocator();
2125 
2126  // set tabs
2127  // menu template (contains linkbar)
2129  $menutpl = new ilTemplate('tpl.forums_threads_menu.html', true, true, 'Modules/Forum');
2130 
2131  include_once("./Services/Accessibility/classes/class.ilAccessKeyGUI.php");
2132 
2133  // mark all as read
2134  if($ilUser->getId() != ANONYMOUS_USER_ID &&
2135  $forumObj->getCountUnread($ilUser->getId(), (int) $this->objCurrentTopic->getId()))
2136  {
2137  $this->ctrl->setParameter($this, 'mark_read', '1');
2138  $this->ctrl->setParameter($this, 'thr_pk', $this->objCurrentTopic->getId());
2139  $ilToolbar->addButton(
2140  $this->lng->txt('forums_mark_read'),
2141  $this->ctrl->getLinkTarget($this, 'viewThread'),
2142  '',
2144  );
2145  $this->ctrl->clearParameters($this);
2146  }
2147 
2148  // print thread
2149  $this->ctrl->setParameterByClass('ilforumexportgui', 'print_thread', $this->objCurrentTopic->getId());
2150  $this->ctrl->setParameterByClass('ilforumexportgui', 'thr_top_fk', $this->objCurrentTopic->getForumId());
2151  $ilToolbar->addButton($this->lng->txt('forums_print_thread'),
2152  $this->ctrl->getLinkTargetByClass('ilforumexportgui', 'printThread')
2153  );
2154  $this->ctrl->clearParametersByClass('ilforumexportgui');
2155 
2156  $this->addHeaderAction();
2157 
2158  if($_GET['mark_read'])
2159  {
2160  $forumObj->markThreadRead($ilUser->getId(), (int)$this->objCurrentTopic->getId());
2161  ilUtil::sendInfo($lng->txt('forums_thread_marked'), true);
2162  }
2163 
2164  // delete post and its sub-posts
2165  require_once './Modules/Forum/classes/class.ilForum.php';
2166 
2167  if ($_GET['action'] == 'ready_delete' && $_POST['confirm'] != '')
2168  {
2169  if(!$this->objCurrentTopic->isClosed() &&
2170  ($this->is_moderator ||
2171  ($this->objCurrentPost->isOwner($ilUser->getId()) && !$this->objCurrentPost->hasReplies())) &&
2172  $ilUser->getId() != ANONYMOUS_USER_ID)
2173  {
2174  $frm = new ilForum();
2175 
2176  $frm->setForumId($forumObj->getId());
2177  $frm->setForumRefId($forumObj->getRefId());
2178 
2179  $dead_thr = $frm->deletePost($this->objCurrentPost->getId());
2180 
2181  // if complete thread was deleted ...
2182  if ($dead_thr == $this->objCurrentTopic->getId())
2183  {
2184 
2185  $frm->setMDB2WhereCondition('top_frm_fk = %s ', array('integer'), array($forumObj->getId()));
2186 
2187  $topicData = $frm->getOneTopic();
2188 
2189  ilUtil::sendInfo($lng->txt('forums_post_deleted'), true);
2190 
2191  if ($topicData['top_num_threads'] > 0)
2192  {
2193  $this->ctrl->redirect($this, 'showThreads');
2194  }
2195  else
2196  {
2197  $this->ctrl->redirect($this, 'createThread');
2198  }
2199  }
2200  ilUtil::sendInfo($lng->txt('forums_post_deleted'));
2201  }
2202  }
2203 
2204  // form processing (censor)
2205  if(!$this->objCurrentTopic->isClosed() && $_GET['action'] == 'ready_censor')
2206  {
2207  if(($_POST['confirm'] != '' || $_POST['no_cs_change'] != '') && $_GET['action'] == 'ready_censor')
2208  {
2209  $frm->postCensorship($this->handleFormInput($_POST['formData']['cens_message']), $this->objCurrentPost->getId(), 1);
2210  }
2211  else if(($_POST['cancel'] != '' || $_POST['yes_cs_change'] != '') && $_GET['action'] == 'ready_censor')
2212  {
2213  $frm->postCensorship($this->handleFormInput($_POST['formData']['cens_message']), $this->objCurrentPost->getId());
2214  }
2215  }
2216 
2217  // get complete tree of thread
2218  $first_node = $this->objCurrentTopic->getFirstPostNode();
2219  $this->objCurrentTopic->setOrderField($orderField);
2220  $subtree_nodes = $this->objCurrentTopic->getPostTree($first_node);
2221 
2222  // no posts
2223  if (!$posNum = count($subtree_nodes))
2224  {
2225  ilUtil::sendInfo($this->lng->txt('forums_no_posts_available'));
2226  }
2227 
2228  $pageHits = $frm->getPageHits();
2229 
2230  $z = 0;
2231 
2232  // navigation to browse
2233  if ($posNum > $pageHits)
2234  {
2235  $params = array(
2236  'ref_id' => $_GET['ref_id'],
2237  'thr_pk' => $this->objCurrentTopic->getId(),
2238  'orderby' => $_GET['orderby']
2239  );
2240 
2241  if (!$_GET['offset'])
2242  {
2243  $Start = 0;
2244  }
2245  else
2246  {
2247  $Start = $_GET['offset'];
2248  }
2249 
2250  $linkbar = ilUtil::Linkbar($ilCtrl->getLinkTarget($this, 'viewThread'), $posNum, $pageHits, $Start, $params);
2251 
2252  if($linkbar != '')
2253  {
2254  $menutpl->setCurrentBlock('linkbar');
2255  $menutpl->setVariable('LINKBAR', $linkbar);
2256  $menutpl->parseCurrentBlock();
2257  }
2258  }
2259 
2260  $tpl->setVariable('THREAD_MENU', $menutpl->get());
2261 
2262  // assistance val for anchor-links
2263  $jump = 0;
2264 
2265  // generate post-dates
2266  foreach($subtree_nodes as $node)
2267  {
2272  $this->ctrl->clearParameters($this);
2273 
2274  if($this->objCurrentPost->getId() && $this->objCurrentPost->getId() == $node->getId())
2275  {
2276  $jump++;
2277  }
2278 
2279  if ($posNum > $pageHits && $z >= ($Start + $pageHits))
2280  {
2281  // if anchor-link was not found ...
2282  if ($this->objCurrentPost->getId() && $jump < 1)
2283  {
2284  $this->ctrl->setParameter($this, 'thr_pk', $this->objCurrentTopic->getId());
2285  $this->ctrl->setParameter($this, 'pos_pk', $this->objCurrentPost->getId());
2286  $this->ctrl->setParameter($this, 'offset', ($Start + $pageHits));
2287  $this->ctrl->setParameter($this, 'orderby', $_GET['orderby']);
2288  $this->ctrl->redirect($this, 'viewThread', $this->objCurrentPost->getId());
2289  exit();
2290  }
2291  else
2292  {
2293  break;
2294  }
2295  }
2296 
2297  if(($posNum > $pageHits && $z >= $Start) || $posNum <= $pageHits)
2298  {
2299  if($this->objCurrentPost->getId() == $node->getId())
2300  {
2301  # actions for "active" post
2302  if($this->is_moderator || $node->isActivated())
2303  {
2304  // reply/edit
2305  if(!$this->objCurrentTopic->isClosed() && ($_GET['action'] == 'showreply' || $_GET['action'] == 'showedit'))
2306  {
2307  if($_GET['action'] == 'showedit' &&
2308  ((!$this->is_moderator &&
2309  !$node->isOwner($ilUser->getId()) || $ilUser->getId() == ANONYMOUS_USER_ID) || $node->isCensored()))
2310  {
2311  $this->ilias->raiseError($lng->txt('permission_denied'), $this->ilias->error_obj->MESSAGE);
2312  }
2313  else if($_GET['action'] == 'showreply' && !$ilAccess->checkAccess('add_reply', '', (int)$_GET['ref_id']))
2314  {
2315  $this->ilias->raiseError($lng->txt('permission_denied'), $this->ilias->error_obj->MESSAGE);
2316  }
2317 
2318  $tpl->setVariable('REPLY_ANKER', $this->objCurrentPost->getId());
2319  $oEditReplyForm = $this->getReplyEditForm();
2320 
2321  switch($this->objProperties->getSubjectSetting())
2322  {
2323  case 'add_re_to_subject':
2324  $subject = $this->getModifiedReOnSubject(true);
2325  break;
2326 
2327  case 'preset_subject':
2328  $subject = $this->objCurrentPost->getSubject();
2329  break;
2330 
2331  case 'empty_subject':
2332  default:
2333  $subject = NULL;
2334  break;
2335  }
2336 
2337  switch($_GET['action'])
2338  {
2339  case 'showreply':
2340  if($this->ctrl->getCmd() == 'savePost')
2341  {
2342  $oEditReplyForm->setValuesByPost();
2343  }
2344  else if($this->ctrl->getCmd() == 'quotePost')
2345  {
2346  require_once 'Modules/Forum/classes/class.ilForumAuthorInformation.php';
2347  $authorinfo = new ilForumAuthorInformation(
2348  $node->getUserId(),
2349  $node->getUserAlias(),
2350  $node->getImportName()
2351  );
2352 
2353  $oEditReplyForm->setValuesByPost();
2354  $oEditReplyForm->getItemByPostVar('message')->setValue(
2356  $frm->prepareText($node->getMessage(), 1, $authorinfo->getAuthorName())."\n".$oEditReplyForm->getInput('message'), 1
2357  )
2358  );
2359  }
2360  else
2361  {
2362  $oEditReplyForm->setValuesByArray(array(
2363  'alias' => '',
2364  'subject' => $subject,
2365  'message' => '',
2366  'notify' => 0,
2367  'userfile' => '',
2368  'del_file' => array()
2369  ));
2370  }
2371 
2372  $this->ctrl->setParameter($this, 'pos_pk', $this->objCurrentPost->getId());
2373  $this->ctrl->setParameter($this, 'thr_pk', $this->objCurrentPost->getThreadId());
2374 
2375  $jsTpl = new ilTemplate('tpl.forum_post_quoation_ajax_handler.html', true, true, 'Modules/Forum/');
2376  $jsTpl->setVariable('IL_FRM_QUOTE_CALLBACK_SRC',
2377  $this->ctrl->getLinkTarget($this, 'getQuotationHTMLAsynch', '', true));
2378  $this->ctrl->clearParameters($this);
2379  $this->tpl->setVariable('FORM_ADDITIONAL_JS', $jsTpl->get());
2380  break;
2381  case 'showedit':
2382  if($this->ctrl->getCmd() == 'savePost')
2383  {
2384  $oEditReplyForm->setValuesByPost();
2385  }
2386  else
2387  {
2388  $oEditReplyForm->setValuesByArray(array(
2389  'alias' => '',
2390  'subject' => $this->objCurrentPost->getSubject(),
2391  'message' => ilRTE::_replaceMediaObjectImageSrc($frm->prepareText($this->objCurrentPost->getMessage(), 2), 1),
2392  'notify' => $this->objCurrentPost->isNotificationEnabled() ? true : false,
2393  'userfile' => '',
2394  'del_file' => array()
2395  ));
2396  }
2397  break;
2398  }
2399  $this->ctrl->setParameter($this, 'pos_pk', $this->objCurrentPost->getId());
2400  $this->ctrl->setParameter($this, 'thr_pk', $this->objCurrentPost->getThreadId());
2401  $this->ctrl->setParameter($this, 'offset', (int)$_GET['offset']);
2402  $this->ctrl->setParameter($this, 'orderby', $_GET['orderby']);
2403  $this->ctrl->setParameter($this, 'action', $_GET['action']);
2404  $tpl->setVariable('FORM', $oEditReplyForm->getHTML());
2405  $this->ctrl->clearParameters($this);
2406 
2407  } // if ($_GET['action'] == 'showreply' || $_GET['action'] == 'showedit')
2408  else if(!$this->objCurrentTopic->isClosed() && $_GET['action'] == 'delete')
2409  {
2410  if($this->is_moderator ||
2411  ($node->isOwner($ilUser->getId()) && !$node->hasReplies()) &&
2412  $ilUser->getId() != ANONYMOUS_USER_ID)
2413  {
2414  // confirmation: delete
2415  $tpl->setVariable('FORM', $this->getDeleteFormHTML());
2416  }
2417  } // else if ($_GET['action'] == 'delete')
2418  else if(!$this->objCurrentTopic->isClosed() && $_GET['action'] == 'censor')
2419  {
2420  if($this->is_moderator)
2421  {
2422  // confirmation: censor / remove censorship
2423  $tpl->setVariable('FORM', $this->getCensorshipFormHTML());
2424  }
2425  }
2426  else if (!$this->objCurrentTopic->isClosed() && $this->displayConfirmPostActivation())
2427  {
2428  if ($this->is_moderator)
2429  {
2430  // confirmation: activate
2431  $tpl->setVariable('FORM', $this->getActivationFormHTML());
2432  }
2433  }
2434  }
2435  } // if ($this->objCurrentPost->getId() == $node->getId())
2436 
2437  if ($this->objCurrentPost->getId() != $node->getId() ||
2438  ($_GET['action'] != 'showreply' &&
2439  $_GET['action'] != 'showedit' &&
2440  $_GET['action'] != 'censor' &&
2441  $_GET['action'] != 'delete' &&
2442  #!$this->displayConfirmPostDeactivation() &&
2444  ))
2445  {
2446  if($this->is_moderator || $node->isActivated())
2447  {
2448  // button: reply
2449  if(!$this->objCurrentTopic->isClosed() &&
2450  $ilAccess->checkAccess('add_reply', '', (int)$_GET['ref_id']) &&
2451  !$node->isCensored()
2452  )
2453  {
2454  $tpl->setCurrentBlock('commands');
2455  $this->ctrl->setParameter($this, 'action', 'showreply');
2456  $this->ctrl->setParameter($this, 'pos_pk', $node->getId());
2457  $this->ctrl->setParameter($this, 'offset', $Start);
2458  $this->ctrl->setParameter($this, 'orderby', $_GET['orderby']);
2459  $this->ctrl->setParameter($this, 'thr_pk', $node->getThreadId());
2460  $tpl->setVariable('COMMANDS_COMMAND', $this->ctrl->getLinkTarget($this, 'viewThread', $node->getId()));
2461  $tpl->setVariable('COMMANDS_TXT', $lng->txt('reply'));
2462  $this->ctrl->clearParameters($this);
2463  $tpl->parseCurrentBlock();
2464  }
2465 
2466  // button: edit article
2467  if (!$this->objCurrentTopic->isClosed() &&
2468  ($node->isOwner($ilUser->getId()) || $this->is_moderator) &&
2469  !$node->isCensored() &&
2470  $ilUser->getId() != ANONYMOUS_USER_ID)
2471  {
2472  $tpl->setCurrentBlock('commands');
2473  $this->ctrl->setParameter($this, 'action', 'showedit');
2474  $this->ctrl->setParameter($this, 'pos_pk', $node->getId());
2475  $this->ctrl->setParameter($this, 'thr_pk', $node->getThreadId());
2476  $this->ctrl->setParameter($this, 'offset', $Start);
2477  $this->ctrl->setParameter($this, 'orderby', $_GET['orderby']);
2478  $tpl->setVariable('COMMANDS_COMMAND', $this->ctrl->getLinkTarget($this, 'viewThread', $node->getId()));
2479  $tpl->setVariable('COMMANDS_TXT', $lng->txt('edit'));
2480  $this->ctrl->clearParameters($this);
2481  $tpl->parseCurrentBlock();
2482  }
2483 
2484  // button: print
2485  if (!$node->isCensored())
2486  {
2487  $tpl->setCurrentBlock('commands');
2488  $this->ctrl->setParameterByClass('ilforumexportgui', 'print_post', $node->getId());
2489  $this->ctrl->setParameterByClass('ilforumexportgui', 'top_pk', $node->getForumId());
2490  $this->ctrl->setParameterByClass('ilforumexportgui', 'thr_pk', $node->getThreadId());
2491  $tpl->setVariable('COMMANDS_COMMAND', $this->ctrl->getLinkTargetByClass('ilforumexportgui', 'printPost'));
2492  $tpl->setVariable('COMMANDS_TXT', $lng->txt('print'));
2493  $this->ctrl->clearParameters($this);
2494  $tpl->parseCurrentBlock();
2495  }
2496 
2497  # buttons for every post except the "active"
2498  if (!$this->objCurrentTopic->isClosed() &&
2499  ($this->is_moderator ||
2500  ($node->isOwner($ilUser->getId()) && !$node->hasReplies())) &&
2501  $ilUser->getId() != ANONYMOUS_USER_ID)
2502  {
2503  // button: delete
2504  $tpl->setCurrentBlock('commands');
2505  $this->ctrl->setParameter($this, 'action', 'delete');
2506  $this->ctrl->setParameter($this, 'pos_pk', $node->getId());
2507  $this->ctrl->setParameter($this, 'thr_pk', $node->getThreadId());
2508  $this->ctrl->setParameter($this, 'offset', $Start);
2509  $this->ctrl->setParameter($this, 'orderby', $_GET['orderby']);
2510  $tpl->setVariable('COMMANDS_COMMAND', $this->ctrl->getLinkTarget($this, 'viewThread', $node->getId()));
2511  $tpl->setVariable('COMMANDS_TXT', $lng->txt('delete'));
2512  $this->ctrl->clearParameters($this);
2513  $tpl->parseCurrentBlock();
2514  }
2515 
2516  if (!$this->objCurrentTopic->isClosed() && $this->is_moderator)
2517  {
2518  // button: censor
2519  $tpl->setCurrentBlock('commands');
2520  $this->ctrl->setParameter($this, 'action', 'censor');
2521  $this->ctrl->setParameter($this, 'pos_pk', $node->getId());
2522  $this->ctrl->setParameter($this, 'thr_pk', $node->getThreadId());
2523  $this->ctrl->setParameter($this, 'offset', $Start);
2524  $this->ctrl->setParameter($this, 'orderby', $_GET['orderby']);
2525  $tpl->setVariable('COMMANDS_COMMAND', $this->ctrl->getLinkTarget($this, 'viewThread', $node->getId()));
2526  $tpl->setVariable('COMMANDS_TXT', $lng->txt('censorship'));
2527  $this->ctrl->clearParameters($this);
2528  $tpl->parseCurrentBlock();
2529 
2530  // button: activation/deactivation
2531  $tpl->setCurrentBlock('commands');
2532  $this->ctrl->setParameter($this, 'pos_pk', $node->getId());
2533  $this->ctrl->setParameter($this, 'thr_pk', $node->getThreadId());
2534  $this->ctrl->setParameter($this, 'offset', $Start);
2535  $this->ctrl->setParameter($this, 'orderby', $_GET['orderby']);
2536 
2537  if (!$node->isActivated())
2538  {
2539  $tpl->setVariable('COMMANDS_COMMAND', $this->ctrl->getLinkTarget($this, 'askForPostActivation', $node->getId()));
2540  $tpl->setVariable('COMMANDS_TXT', $lng->txt('activate_post'));
2541  }
2542  $this->ctrl->clearParameters($this);
2543  $tpl->parseCurrentBlock();
2544  }
2545 
2546  // button: mark read
2547  if ($ilUser->getId() != ANONYMOUS_USER_ID &&
2548  !$node->isPostRead())
2549  {
2550  $tpl->setCurrentBlock('commands');
2551  $this->ctrl->setParameter($this, 'pos_pk', $node->getId());
2552  $this->ctrl->setParameter($this, 'thr_pk', $node->getThreadId());
2553  $this->ctrl->setParameter($this, 'offset', $Start);
2554  $this->ctrl->setParameter($this, 'orderby', $_GET['orderby']);
2555  $this->ctrl->setParameter($this, 'viewmode', $_SESSION['viewmode']);
2556  $tpl->setVariable('COMMANDS_COMMAND', $this->ctrl->getLinkTarget($this, 'markPostRead', $node->getId()));
2557  $tpl->setVariable('COMMANDS_TXT', $lng->txt('is_read'));
2558  $this->ctrl->clearParameters($this);
2559  $tpl->parseCurrentBlock();
2560  }
2561 
2562  // button: mark unread
2563  if ($ilUser->getId() != ANONYMOUS_USER_ID &&
2564  $node->isPostRead())
2565  {
2566  $tpl->setCurrentBlock('commands');
2567  $this->ctrl->setParameter($this, 'pos_pk', $node->getId());
2568  $this->ctrl->setParameter($this, 'thr_pk', $node->getThreadId());
2569  $this->ctrl->setParameter($this, 'offset', $Start);
2570  $this->ctrl->setParameter($this, 'orderby', $_GET['orderby']);
2571  $this->ctrl->setParameter($this, 'viewmode', $_SESSION['viewmode']);
2572  $tpl->setVariable('COMMANDS_COMMAND', $this->ctrl->getLinkTarget($this, 'markPostUnread', $node->getId()));
2573  $tpl->setVariable('COMMANDS_TXT', $lng->txt('unread'));
2574  $this->ctrl->clearParameters($this);
2575  $tpl->parseCurrentBlock();
2576  }
2577  }
2578  } // if ($this->objCurrentPost->getId() != $node->getId())
2579 
2580  // download post attachments
2581  $tmp_file_obj = new ilFileDataForum($forumObj->getId(), $node->getId());
2582  if (count($tmp_file_obj->getFilesOfPost()))
2583  {
2584  if ($node->getId() != $this->objCurrentPost->getId() || $_GET['action'] != 'showedit')
2585  {
2586  foreach ($tmp_file_obj->getFilesOfPost() as $file)
2587  {
2588  $tpl->setCurrentBlock('attachment_download_row');
2589  $this->ctrl->setParameter($this, 'pos_pk', $node->getId());
2590  $this->ctrl->setParameter($this, 'file', $file['md5']);
2591  $tpl->setVariable('HREF_DOWNLOAD', $this->ctrl->getLinkTarget($this, 'viewThread'));
2592  $tpl->setVariable('TXT_FILENAME', $file['name']);
2593  $this->ctrl->clearParameters($this);
2594  $tpl->parseCurrentBlock();
2595  }
2596  $tpl->setCurrentBlock('attachments');
2597  $tpl->setVariable('TXT_ATTACHMENTS_DOWNLOAD',$lng->txt('forums_attachments'));
2598  $tpl->setVariable('DOWNLOAD_IMG', ilUtil::getImagePath('icon_attachment.png'));
2599  $tpl->setVariable('TXT_DOWNLOAD_ATTACHMENT', $lng->txt('forums_download_attachment'));
2600  $tpl->parseCurrentBlock();
2601  }
2602  }
2603 
2604  $tpl->setCurrentBlock('posts_row');
2605 
2606  // anker for every post
2607  $tpl->setVariable('POST_ANKER', $node->getId());
2608 
2609  //permanent link for every post
2610  // $tpl->setVariable('PERMA_LINK', ILIAS_HTTP_PATH."/goto.php?target="."frm"."_".$this->object->getRefId()."_".$node->getThreadId()."_".$node->getId()."&client_id=".CLIENT_ID);
2611  $tpl->setVariable('TXT_PERMA_LINK', $lng->txt('perma_link'));
2612  $tpl->setVariable('PERMA_TARGET', '_top');
2613 
2614  if($this->objProperties->getMarkModeratorPosts() == 1)
2615  {
2616  $is_moderator = ilForum::_isModerator($_GET['ref_id'], $node->getUserId());
2617  if($is_moderator)
2618  {
2619  $rowCol = 'ilModeratorPosting';
2620  }
2621  else $rowCol = ilUtil::switchColor($z, 'tblrow1', 'tblrow2');
2622  }
2623  else $rowCol = ilUtil::switchColor($z, 'tblrow1', 'tblrow2');
2624  if (( $_GET['action'] != 'delete' && $_GET['action'] != 'censor' &&
2625  #!$this->displayConfirmPostDeactivation() &&
2627  )
2628  || $this->objCurrentPost->getId() != $node->getId())
2629  {
2630  $tpl->setVariable('ROWCOL', ' '.$rowCol);
2631  }
2632  else
2633  {
2634  // highlight censored posts
2635  $rowCol = 'tblrowmarked';
2636  }
2637 
2638  // post is censored
2639  if ($node->isCensored())
2640  {
2641  // display censorship advice
2642  if ($_GET['action'] != 'censor')
2643  {
2644  $tpl->setVariable('TXT_CENSORSHIP_ADVICE', $this->lng->txt('post_censored_comment_by_moderator'));
2645  }
2646 
2647  // highlight censored posts
2648  $rowCol = 'tblrowmarked';
2649  }
2650 
2651  // set row color
2652  $tpl->setVariable('ROWCOL', ' '.$rowCol);
2653  // if post is not activated display message for the owner
2654  if(!$node->isActivated() && $node->isOwner($ilUser->getId()))
2655  {
2656  $tpl->setVariable('POST_NOT_ACTIVATED_YET', $this->lng->txt('frm_post_not_activated_yet'));
2657  }
2658 
2659  // Author
2660  $this->ctrl->setParameter($this, 'pos_pk', $node->getId());
2661  $this->ctrl->setParameter($this, 'thr_pk', $node->getThreadId());
2662  $backurl = urlencode($this->ctrl->getLinkTarget($this, 'viewThread', $node->getId()));
2663  $this->ctrl->clearParameters($this);
2664 
2665  $this->ctrl->setParameter($this, 'backurl', $backurl);
2666  $this->ctrl->setParameter($this, 'thr_pk', $node->getThreadId());
2667  $this->ctrl->setParameter($this, 'user', $node->getUserId());
2668 
2669  require_once 'Modules/Forum/classes/class.ilForumAuthorInformation.php';
2670  $authorinfo = new ilForumAuthorInformation(
2671  $node->getUserId(),
2672  $node->getUserAlias(),
2673  $node->getImportName(),
2674  array(
2675  'href' => $this->ctrl->getLinkTarget($this, 'showUser')
2676  )
2677  );
2678 
2679  $this->ctrl->clearParameters($this);
2680 
2681  $tpl->setVariable('AUTHOR', $authorinfo->getLinkedAuthorShortName());
2682  if($authorinfo->getAuthorName(true))
2683  {
2684  $tpl->setVariable('USR_NAME', $authorinfo->getAuthorName(true));
2685  }
2686 
2687  $tpl->setVariable('USR_IMAGE', $authorinfo->getProfilePicture());
2688  if($authorinfo->getAuthor()->getId() && ilForum::_isModerator((int)$_GET['ref_id'], $authorinfo->getAuthor()->getId()))
2689  {
2690  if($authorinfo->getAuthor()->getGender() == 'f')
2691  {
2692  $tpl->setVariable('ROLE', $this->lng->txt('frm_moderator_f'));
2693  }
2694  else if($authorinfo->getAuthor()->getGender() == 'm')
2695  {
2696  $tpl->setVariable('ROLE', $this->lng->txt('frm_moderator_m'));
2697  }
2698  }
2699 
2700  // get create- and update-dates
2701  if ($node->getUpdateUserId() > 0)
2702  {
2703  $spanClass = '';
2704 
2705  // last update from moderator?
2706  $posMod = $frm->getModeratorFromPost($node->getId());
2707 
2708  if (is_array($posMod) && $posMod['top_mods'] > 0)
2709  {
2710  $MODS = $rbacreview->assignedUsers($posMod['top_mods']);
2711 
2712  if (is_array($MODS))
2713  {
2714  if (in_array($node->getUpdateUserId(), $MODS))
2715  $spanClass = 'moderator_small';
2716  }
2717  }
2718 
2719  $node->setChangeDate($node->getChangeDate());
2720 
2721  if ($spanClass == '') $spanClass = 'small';
2722 
2723  $this->ctrl->setParameter($this, 'backurl', $backurl);
2724  $this->ctrl->setParameter($this, 'thr_pk', $node->getThreadId());
2725  $this->ctrl->setParameter($this, 'user', $node->getUpdateUserId());
2726 
2727  require_once 'Modules/Forum/classes/class.ilForumAuthorInformation.php';
2728  $authorinfo = new ilForumAuthorInformation(
2729  $node->getUpdateUserId(),
2730  '',
2731  '',
2732  array(
2733  'href' => $this->ctrl->getLinkTarget($this, 'showUser')
2734  )
2735  );
2736 
2737  $this->ctrl->clearParameters($this);
2738 
2739  $tpl->setVariable('POST_UPDATE_TXT', $lng->txt('edited_on').': '.$frm->convertDate($node->getChangeDate()).' - '.strtolower($lng->txt('by')));
2740  $tpl->setVariable('UPDATE_AUTHOR', $authorinfo->getLinkedAuthorShortName());
2741  if($authorinfo->getAuthorName(true))
2742  {
2743  $tpl->setVariable('UPDATE_USR_NAME', $authorinfo->getAuthorName(true));
2744  }
2745 
2746  } // if ($node->getUpdateUserId() > 0)*/
2747  // Author end
2748 
2749  // prepare post
2750  $node->setMessage($frm->prepareText($node->getMessage()));
2751 
2752  if($ilUser->getId() == ANONYMOUS_USER_ID ||
2753  $node->isPostRead())
2754  {
2755  $tpl->setVariable('SUBJECT', $node->getSubject());
2756  }
2757  else
2758  {
2759  $this->ctrl->setParameter($this, 'pos_pk', $node->getId());
2760  $this->ctrl->setParameter($this, 'thr_pk', $node->getThreadId());
2761  $this->ctrl->setParameter($this, 'offset', $Start);
2762  $this->ctrl->setParameter($this, 'orderby', $_GET['orderby']);
2763  $this->ctrl->setParameter($this, 'viewmode', $_SESSION['viewmode']);
2764  $mark_post_target = $this->ctrl->getLinkTarget($this, 'markPostRead', $node->getId());
2765 
2766  $tpl->setVariable('SUBJECT',"<a href=\"".$mark_post_target."\"><b>".$node->getSubject()."</b></a>");
2767 
2768  }
2769 
2770  $tpl->setVariable('POST_DATE', $frm->convertDate($node->getCreateDate()));
2771 
2772  if (!$node->isCensored() ||
2773  ($this->objCurrentPost->getId() == $node->getId() && $_GET['action'] == 'censor'))
2774  {
2775  // post from moderator?
2776  $modAuthor = $frm->getModeratorFromPost($node->getId());
2777 
2778  $spanClass = "";
2779 
2780  if (is_array($modAuthor) && $modAuthor['top_mods'] > 0)
2781  {
2782  unset($MODS);
2783 
2784  $MODS = $rbacreview->assignedUsers($modAuthor['top_mods']);
2785 
2786  if (is_array($MODS))
2787  {
2788  if (in_array($node->getUserId(), $MODS))
2789  $spanClass = 'moderator';
2790  }
2791  }
2792 
2793  // possible bugfix for mantis #8223
2794  if($node->getMessage() == strip_tags($node->getMessage()))
2795  {
2796  // We can be sure, that there are not html tags
2797  $node->setMessage(nl2br($node->getMessage()));
2798  }
2799 
2800  if ($spanClass != "")
2801  {
2802  $tpl->setVariable('POST', "<span class=\"".$spanClass."\">".ilRTE::_replaceMediaObjectImageSrc($node->getMessage(), 1)."</span>");
2803  }
2804  else
2805  {
2806  $tpl->setVariable('POST', ilRTE::_replaceMediaObjectImageSrc($node->getMessage(), 1));
2807  }
2808  }
2809  else
2810  {
2811  $tpl->setVariable('POST', "<span class=\"moderator\">".nl2br($node->getCensorshipComment())."</span>");
2812  }
2813 
2814  $tpl->parseCurrentBlock();
2815 
2816  }
2817  $z++;
2818  }
2819  }
2820  else
2821  {
2822  $tpl->setCurrentBlock('posts_no');
2823  $tpl->setVariable('TXT_MSG_NO_POSTS_AVAILABLE', $lng->txt('forums_posts_not_available'));
2824  $tpl->parseCurrentBlock();
2825  }
2826 
2827  $oThreadToolbar = clone $ilToolbar;
2828  $oThreadToolbar->addSeparator();
2829  $oThreadToolbar->addButton($this->lng->txt('top_of_page'),'#frm_page_top');
2830  $tpl->setVariable('THREAD_TOOLBAR', $oThreadToolbar->getHTML());
2831 
2832  $tpl->setVariable('TPLPATH', $tpl->vars['TPLPATH']);
2833 
2834  // permanent link
2835  include_once 'Services/PermanentLink/classes/class.ilPermanentLinkGUI.php';
2836  $permalink = new ilPermanentLinkGUI('frm', $this->object->getRefId(), '_'.$this->objCurrentTopic->getId());
2837  $this->tpl->setVariable('PRMLINK', $permalink->getHTML());
2838 
2839  // Render tree
2840  if($_SESSION['viewmode'] == 'answers'
2841  || $_SESSION['viewmode'] == ilForumProperties::VIEW_TREE)
2842  {
2843  $tpl->setLeftNavContent($this->getForumExplorer());
2844  }
2845 
2846  return true;
2847  }
2848 
2849  private function getModifiedReOnSubject($on_reply = false)
2850  {
2851  $subject = $this->objCurrentPost->getSubject();
2852  $re_txt = $this->lng->txt('post_reply');
2853 
2854  $re_txt_with_num = str_replace(':', '(',$re_txt);
2855  $search_length = strlen($re_txt_with_num);
2856  $comp = substr_compare($re_txt_with_num, substr($subject, 0 , $search_length), 0, $search_length);
2857 
2858  if($comp == 0)
2859  {
2860  $modified_subject = $subject;
2861  if($on_reply == true)
2862  {
2863  // i.e. $subject = "Re(12):"
2864  $str_pos_start = strpos($subject, '(');
2865  $str_pos_end = strpos($subject, ')');
2866 
2867  $length = ((int)$str_pos_end - (int)$str_pos_start);
2868  $str_pos_start++;
2869  $txt_number = substr($subject, $str_pos_start, $length - 1);
2870 
2871  if(is_numeric($txt_number))
2872  {
2873  $re_count = (int)$txt_number + 1;
2874  $modified_subject = substr($subject, 0, $str_pos_start) . $re_count . substr($subject, $str_pos_end);
2875  }
2876  }
2877  }
2878  else
2879  {
2880  $re_count = substr_count($subject, $re_txt);
2881  if($re_count >= 1 && $on_reply == true)
2882  {
2883  $subject = str_replace($re_txt, '', $subject);
2884 
2885  // i.e. $subject = "Re: Re: Re: ... " -> "Re(4):"
2886  $re_count++;
2887  $modified_subject = sprintf($this->lng->txt('post_reply_count'), $re_count).' '.trim($subject);
2888  }
2889  else if($re_count >= 1 && $on_reply == false)
2890  {
2891  // possibility to modify the subject only for output
2892  // i.e. $subject = "Re: Re: Re: ... " -> "Re(3):"
2893  $modified_subject = sprintf($this->lng->txt('post_reply_count'), $re_count).' '.trim($subject);
2894  }
2895  else if($re_count == 0)
2896  {
2897  // the first reply to a thread
2898  $modified_subject = $this->lng->txt('post_reply').' '. $this->objCurrentPost->getSubject();
2899  }
2900  }
2901  return $modified_subject;
2902  }
2903 
2904  public function showUserObject()
2905  {
2909  global $tpl;
2910 
2911  // we could actually call ilpublicuserprofilegui directly, this method
2912  // is not needed - but sadly used throughout the forum code
2913  // see above in execute command
2914 
2915  include_once 'Services/User/classes/class.ilPublicUserProfileGUI.php';
2916  $profile_gui = new ilPublicUserProfileGUI($_GET['user']);
2917  $add = $this->getUserProfileAdditional($_GET['ref_id'], $_GET['user']);
2918  $profile_gui->setAdditional($add);
2919  $profile_gui->setBackUrl($_GET['backurl']);
2920  $tpl->setContent($this->ctrl->getHTML($profile_gui));
2921  }
2922 
2923  protected function getUserProfileAdditional($a_forum_ref_id, $a_user_id)
2924  {
2929  global $lng, $ilAccess;
2930 
2931  if(!$ilAccess->checkAccess('read', '', $a_forum_ref_id))
2932  {
2933  $this->ilias->raiseError($lng->txt('permission_denied'), $this->ilias->error_obj->MESSAGE);
2934  }
2935 
2936  require_once 'Modules/Forum/classes/class.ilForum.php';
2937 
2938  $lng->loadLanguageModule('forum');
2939 
2943  $ref_obj = ilObjectFactory::getInstanceByRefId($a_forum_ref_id);
2944  if($ref_obj->getType() == 'frm')
2945  {
2946  $forumObj = new ilObjForum($a_forum_ref_id);
2947  $frm = $forumObj->Forum;
2948  $frm->setForumId($forumObj->getId());
2949  $frm->setForumRefId($forumObj->getRefId());
2950  }
2951  else
2952  {
2953  $frm = new ilForum();
2954  }
2955 
2956  // count articles of user
2957  if($ilAccess->checkAccess('moderate_frm', '', $a_forum_ref_id))
2958  {
2959  $numPosts = $frm->countUserArticles(addslashes($a_user_id));
2960  }
2961  else
2962  {
2963  $numPosts = $frm->countActiveUserArticles(addslashes($a_user_id));
2964  }
2965 
2966  return array($lng->txt('forums_posts') => $numPosts);
2967  }
2968 
2969  public function performThreadsActionObject()
2970  {
2974  global $ilUser;
2975 
2976  unset($_SESSION['threads2move']);
2977 
2978  if(isset($_POST['thread_ids']) && is_array($_POST['thread_ids']))
2979  {
2980  if(isset($_POST['selected_cmd']) && $_POST['selected_cmd'] == 'move')
2981  {
2982  if($this->is_moderator)
2983  {
2984  $_SESSION['threads2move'] = $_POST['thread_ids'];
2985  $this->moveThreadsObject();
2986  }
2987  }
2988  else if($_POST['selected_cmd'] == 'enable_notifications' && $this->ilias->getSetting('forum_notification') != 0)
2989  {
2990  for($i = 0; $i < count($_POST['thread_ids']); $i++)
2991  {
2992  $tmp_obj = new ilForumTopic($_POST['thread_ids'][$i]);
2993  $tmp_obj->enableNotification($ilUser->getId());
2994  unset($tmp_obj);
2995  }
2996 
2997  $this->ctrl->redirect($this, 'showThreads');
2998  }
2999  else if($_POST['selected_cmd'] == 'disable_notifications' && $this->ilias->getSetting('forum_notification') != 0)
3000  {
3001  for($i = 0; $i < count($_POST['thread_ids']); $i++)
3002  {
3003  $tmp_obj = new ilForumTopic($_POST['thread_ids'][$i]);
3004  $tmp_obj->disableNotification($ilUser->getId());
3005  unset($tmp_obj);
3006  }
3007 
3008  $this->ctrl->redirect($this, 'showThreads');
3009  }
3010 
3011  else if($_POST['selected_cmd'] == 'close')
3012  {
3013  if($this->is_moderator)
3014  {
3015  for($i = 0; $i < count($_POST['thread_ids']); $i++)
3016  {
3017  $tmp_obj = new ilForumTopic($_POST['thread_ids'][$i]);
3018  $tmp_obj->close();
3019  unset($tmp_obj);
3020  }
3021  }
3022 
3023  $this->ctrl->redirect($this, 'showThreads');
3024  }
3025  else if($_POST['selected_cmd'] == 'reopen')
3026  {
3027  if($this->is_moderator)
3028  {
3029  for($i = 0; $i < count($_POST['thread_ids']); $i++)
3030  {
3031  $tmp_obj = new ilForumTopic($_POST['thread_ids'][$i]);
3032  $tmp_obj->reopen();
3033  unset($tmp_obj);
3034  }
3035  }
3036 
3037  $this->ctrl->redirect($this, 'showThreads');
3038  }
3039  else if($_POST['selected_cmd'] == 'makesticky')
3040  {
3041  if($this->is_moderator)
3042  {
3043  for($i = 0; $i < count($_POST['thread_ids']); $i++)
3044  {
3045  $tmp_obj = new ilForumTopic($_POST['thread_ids'][$i]);
3046  $tmp_obj->makeSticky();
3047  unset($tmp_obj);
3048  }
3049  }
3050 
3051  $this->ctrl->redirect($this, 'showThreads');
3052  }
3053  else if($_POST['selected_cmd'] == 'unmakesticky')
3054  {
3055  if($this->is_moderator)
3056  {
3057  for($i = 0; $i < count($_POST['thread_ids']); $i++)
3058  {
3059  $tmp_obj = new ilForumTopic($_POST['thread_ids'][$i]);
3060  $tmp_obj->unmakeSticky();
3061  unset($tmp_obj);
3062  }
3063  }
3064 
3065  $this->ctrl->redirect($this, 'showThreads');
3066  }
3067  else if($_POST['selected_cmd'] == 'editThread')
3068  {
3069  if($this->is_moderator)
3070  {
3071  $count = count($_POST['thread_ids']);
3072  if($count != 1)
3073  {
3074  ilUtil::sendInfo($this->lng->txt('select_max_one_thread'), true);
3075  $this->ctrl->redirect($this, 'showThreads');
3076  }
3077  else
3078  {
3079  foreach($_POST['thread_ids'] as $thread_id)
3080  {
3081  return $this->editThreadObject($thread_id, null);
3082  }
3083  }
3084  }
3085 
3086  $this->ctrl->redirect($this, 'showThreads');
3087  }
3088  else if($_POST['selected_cmd'] == 'html')
3089  {
3090  $this->ctrl->setCmd('exportHTML');
3091  $this->ctrl->setCmdClass('ilForumExportGUI');
3092  $this->executeCommand();
3093  }
3094  else if($_POST['selected_cmd'] == 'confirmDeleteThreads')
3095  {
3096  $this->confirmDeleteThreads();
3097  }
3098  else if($_POST['selected_cmd'] == 'merge')
3099  {
3100  $this->mergeThreadsObject();
3101  }
3102  else
3103  {
3104  ilUtil::sendInfo($this->lng->txt('topics_please_select_one_action'), true);
3105  $this->ctrl->redirect($this, 'showThreads');
3106  }
3107  }
3108  else
3109  {
3110  ilUtil::sendInfo($this->lng->txt('select_at_least_one_thread'), true);
3111  $this->ctrl->redirect($this, 'showThreads');
3112  }
3113  }
3114 
3115  public function performMoveThreadsObject()
3116  {
3121  global $lng, $ilObjDataCache;
3122 
3123  if(!$this->is_moderator)
3124  {
3125  $this->ilias->raiseError($lng->txt('permission_denied'), $this->ilias->error_obj->MESSAGE);
3126  }
3127 
3128  if(isset($_POST['frm_ref_id']) && (int) $_POST['frm_ref_id'])
3129  {
3130  $this->object->Forum->moveThreads((array) $_SESSION['threads2move'], $this->object->getRefId(), $ilObjDataCache->lookupObjId($_POST['frm_ref_id']));
3131 
3132  unset($_SESSION['threads2move']);
3133  ilUtil::sendInfo($lng->txt('threads_moved_successfully'), true);
3134  $this->ctrl->redirect($this, 'showThreads');
3135  }
3136  else
3137  {
3138  ilUtil::sendInfo($lng->txt('no_forum_selected'));
3139  $this->moveThreadsObject();
3140  }
3141  }
3142 
3143  public function cancelMoveThreadsObject()
3144  {
3148  global $lng;
3149 
3150  if(!$this->is_moderator)
3151  {
3152  $this->ilias->raiseError($lng->txt('permission_denied'), $this->ilias->error_obj->MESSAGE);
3153  }
3154 
3155  unset($_SESSION['threads2move']);
3156 
3157  $this->ctrl->redirect($this, 'showThreads');
3158  }
3159 
3160  public function moveThreadsObject()
3161  {
3167  global $lng, $ilToolbar, $tree;
3168 
3169  if(!$this->is_moderator)
3170  {
3171  $this->ilias->raiseError($lng->txt('permission_denied'), $this->ilias->error_obj->MESSAGE);
3172  }
3173 
3174  $threads2move = $_SESSION['threads2move'];
3175  if(!count($threads2move))
3176  {
3177  ilUtil::sendInfo($this->lng->txt('select_at_least_one_thread'), true);
3178  $this->ctrl->redirect($this, 'showThreads');
3179  }
3180 
3181  require_once 'Modules/Forum/classes/class.ilForumMoveTopicsExplorer.php';
3182  $exp = new ilForumMoveTopicsExplorer($this, 'moveThreads');
3183  $exp->setPathOpen($this->object->getRefId());
3184  $exp->setNodeSelected(isset($_POST['frm_ref_id']) && (int)$_POST['frm_ref_id'] ? (int)$_POST['frm_ref_id'] : 0);
3185  $exp->setCurrentFrmRefId($this->object->getRefId());
3186  $exp->setHighlightedNode($this->object->getRefId());
3187  if(!$exp->handleCommand())
3188  {
3189  $this->tpl->addBlockFile('ADM_CONTENT', 'adm_content', 'tpl.forums_threads_move.html', 'Modules/Forum');
3190 
3191  if(!$this->hideToolbar())
3192  $ilToolbar->addButton($this->lng->txt('back'), $this->ctrl->getLinkTarget($this));
3193 
3194  $tblThr = new ilTable2GUI($this);
3195  $tblThr->setId('il_frm_thread_move_table_'.$this->object->getRefId());
3196  $tblThr->setTitle($this->lng->txt('move_chosen_topics'));
3197  $tblThr->addColumn($this->lng->txt('subject'), 'top_name', '100%');
3198  $tblThr->disable('header');
3199  $tblThr->disable('footer');
3200  $tblThr->disable('linkbar');
3201  $tblThr->disable('sort');
3202  $tblThr->disable('linkbar');
3203  $tblThr->setLimit(PHP_INT_MAX);
3204  $tblThr->setRowTemplate('tpl.forums_threads_move_thr_row.html', 'Modules/Forum');
3205  $tblThr->setDefaultOrderField('is_sticky');
3206  $counter = 0;
3207  $result = array();
3208  foreach($threads2move as $thr_pk)
3209  {
3210  $objCurrentTopic = new ilForumTopic($thr_pk, $this->is_moderator);
3211 
3212  $result[$counter]['num'] = $counter + 1;
3213  $result[$counter]['thr_subject'] = $objCurrentTopic->getSubject();
3214 
3215  unset($objCurrentTopic);
3216  ++$counter;
3217  }
3218  $tblThr->setData($result);
3219  $this->tpl->setVariable('THREADS_TABLE', $tblThr->getHTML());
3220 
3221  $this->tpl->setVariable('FRM_SELECTION_TREE', $exp->getHTML());
3222  $this->tpl->setVariable('CMD_SUBMIT', 'performMoveThreads');
3223  $this->tpl->setVariable('TXT_SUBMIT', $this->lng->txt('move'));
3224  $this->tpl->setVariable('FORMACTION', $this->ctrl->getFormAction($this, 'performMoveThreads'));
3225  }
3226 
3227  return true;
3228  }
3229 
3230  private function initTopicCreateForm()
3231  {
3238  global $ilUser, $rbacsystem, $ilias, $ilSetting;
3239 
3240  $this->create_topic_form_gui = new ilPropertyFormGUI();
3241 
3242  $this->create_topic_form_gui->setTitle($this->lng->txt('forums_new_thread'));
3243  $this->create_topic_form_gui->setTitleIcon(ilUtil::getImagePath('icon_frm.png'));
3244  $this->create_topic_form_gui->setTableWidth('100%');
3245 
3246  // form action
3247  $this->create_topic_form_gui->setFormAction($this->ctrl->getFormAction($this, 'addThread'));
3248 
3249  if($this->objProperties->isAnonymized() == 1)
3250  {
3251  $alias_gui = new ilTextInputGUI($this->lng->txt('forums_your_name'), 'alias');
3252  $alias_gui->setInfo($this->lng->txt('forums_use_alias'));
3253  $alias_gui->setMaxLength(255);
3254  $alias_gui->setSize(50);
3255  $this->create_topic_form_gui->addItem($alias_gui);
3256  }
3257  else
3258  {
3259  $alias_gui = new ilNonEditableValueGUI($this->lng->txt('forums_your_name'), 'alias');
3260  $alias_gui->setValue($ilUser->getLogin());
3261  $this->create_topic_form_gui->addItem($alias_gui);
3262  }
3263 
3264  // topic
3265  $subject_gui = new ilTextInputGUI($this->lng->txt('forums_thread'), 'subject');
3266  $subject_gui->setMaxLength(255);
3267  $subject_gui->setSize(50);
3268  $subject_gui->setRequired(true);
3269  $this->create_topic_form_gui->addItem($subject_gui);
3270 
3271  // message
3272  $post_gui = new ilTextAreaInputGUI($this->lng->txt('forums_the_post'), 'message');
3273  $post_gui->setCols(50);
3274  $post_gui->setRows(15);
3275  $post_gui->setRequired(true);
3276  $post_gui->setUseRte(true);
3277  $post_gui->addPlugin('latex');
3278  $post_gui->addButton('latex');
3279  $post_gui->addButton('pastelatex');
3280  $post_gui->addPlugin('ilfrmquote');
3281  //$post_gui->addPlugin('code');
3282  $post_gui->removePlugin('advlink');
3283  $post_gui->usePurifier(true);
3284  $post_gui->setRTERootBlockElement('');
3285  $post_gui->setRTESupport($ilUser->getId(), 'frm~', 'frm_post', 'tpl.tinymce_frm_post.html', false, '3.4.7');
3286  $post_gui->disableButtons(array(
3287  'charmap',
3288  'undo',
3289  'redo',
3290  'justifyleft',
3291  'justifycenter',
3292  'justifyright',
3293  'justifyfull',
3294  'anchor',
3295  'fullscreen',
3296  'cut',
3297  'copy',
3298  'paste',
3299  'pastetext',
3300  'formatselect'
3301  ));
3302 
3303  // purifier
3304  require_once 'Services/Html/classes/class.ilHtmlPurifierFactory.php';
3305  $post_gui->setPurifier(ilHtmlPurifierFactory::_getInstanceByType('frm_post'));
3306  $this->create_topic_form_gui->addItem($post_gui);
3307 
3308  // file
3309  $fi = new ilFileWizardInputGUI($this->lng->txt('forums_attachments_add'), 'userfile');
3310  $fi->setFilenames(array(0 => ''));
3311  $this->create_topic_form_gui->addItem($fi);
3312 
3313  include_once 'Services/Mail/classes/class.ilMail.php';
3314  $umail = new ilMail($ilUser->getId());
3315  // catch hack attempts
3316  if($rbacsystem->checkAccess('internal_mail', $umail->getMailObjectReferenceId()) &&
3317  !$this->objProperties->isAnonymized())
3318  {
3319  // direct notification
3320  $dir_notification_gui = new ilCheckboxInputGUI($this->lng->txt('forum_direct_notification'), 'notify');
3321  $dir_notification_gui->setInfo($this->lng->txt('forum_notify_me_directly'));
3322  $dir_notification_gui->setValue(1);
3323  $this->create_topic_form_gui->addItem($dir_notification_gui);
3324 
3325  if($ilias->getSetting('forum_notification') != 0)
3326  {
3327  // gen. notification
3328  $gen_notification_gui = new ilCheckboxInputGUI($this->lng->txt('forum_general_notification'), 'notify_posts');
3329  $gen_notification_gui->setInfo($this->lng->txt('forum_notify_me_generally'));
3330  $gen_notification_gui->setValue(1);
3331  $this->create_topic_form_gui->addItem($gen_notification_gui);
3332  }
3333  }
3334 
3335  require_once 'Services/Captcha/classes/class.ilCaptchaUtil.php';
3336  if(
3337  $ilUser->isAnonymous() &&
3338  !$ilUser->isCaptchaVerified() &&
3339  ilCaptchaUtil::isActiveForForum()
3340  )
3341  {
3342  require_once 'Services/Captcha/classes/class.ilCaptchaInputGUI.php';
3343  $captcha = new ilCaptchaInputGUI($this->lng->txt('cont_captcha_code'), 'captcha_code');
3344  $captcha->setRequired(true);
3345  $this->create_topic_form_gui->addItem($captcha);
3346  }
3347  $this->create_topic_form_gui->addCommandButton('addThread', $this->lng->txt('create'));
3348  $this->create_topic_form_gui->addCommandButton('showThreads', $this->lng->txt('cancel'));
3349  }
3350 
3351  private function setTopicCreateDefaultValues()
3352  {
3353  $this->create_topic_form_gui->setValuesByArray(array(
3354  'subject' => '',
3355  'message' => '',
3356  'userfile' => '',
3357  'notify' => 0,
3358  'notify_posts' => 0
3359  ));
3360  }
3361 
3362  public function createThreadObject()
3363  {
3368  global $ilAccess, $lng;
3369 
3370  if(!$ilAccess->checkAccess('add_thread', '', $this->object->getRefId()))
3371  {
3372  $this->ilias->raiseError($lng->txt('permission_denied'), $this->ilias->error_obj->MESSAGE);
3373  }
3374 
3375  $this->initTopicCreateForm();
3376  $this->setTopicCreateDefaultValues();
3377 
3378  $create_form = new ilTemplate('tpl.create_thread_form.html', true, true, 'Modules/Forum');
3379  $create_form->setVariable('CREATE_FORM',$this->create_topic_form_gui->getHTML());
3380  $create_form->parseCurrentBlock();
3381 
3382  $this->tpl->setContent($create_form->get());
3383  }
3384 
3385  public function addThreadObject($a_prevent_redirect = false)
3386  {
3392  global $ilUser, $ilAccess, $lng;
3393 
3394  $frm = $this->object->Forum;
3395  $frm->setForumId($this->object->getId());
3396  $frm->setForumRefId($this->object->getRefId());
3397 
3398  if(!$ilAccess->checkAccess('add_thread', '', $this->object->getRefId()))
3399  {
3400  $this->ilias->raiseError($lng->txt('permission_denied'), $this->ilias->error_obj->MESSAGE);
3401  }
3402 
3403  $frm->setMDB2WhereCondition('top_frm_fk = %s ', array('integer'), array($frm->getForumId()));
3404 
3405  $topicData = $frm->getOneTopic();
3406 
3407  $this->initTopicCreateForm();
3408  if($this->create_topic_form_gui->checkInput())
3409  {
3410  require_once 'Services/Captcha/classes/class.ilCaptchaUtil.php';
3411  if(
3412  $ilUser->isAnonymous() &&
3413  !$ilUser->isCaptchaVerified() &&
3414  ilCaptchaUtil::isActiveForForum()
3415  )
3416  {
3417  $ilUser->setCaptchaVerified(true);
3418  }
3419 
3420  if($this->objProperties->isAnonymized())
3421  {
3422  if(!strlen($this->create_topic_form_gui->getInput('alias')))
3423  {
3424  $user_alias = $this->lng->txt('forums_anonymous');
3425  }
3426  else
3427  {
3428  $user_alias = $this->create_topic_form_gui->getInput('alias');
3429  }
3430  }
3431  else
3432  {
3433  $user_alias = $ilUser->getLogin();
3434  }
3435 
3436  $status = 1;
3437  if(
3438  $this->objProperties->isPostActivationEnabled() &&
3439  !$this->is_moderator || $this->objCurrentPost->isAnyParentDeactivated()
3440  )
3441  {
3442  $status = 0;
3443  }
3444 
3445  // build new thread
3446  $newPost = $frm->generateThread(
3447  $topicData['top_pk'],
3448  ($this->objProperties->isAnonymized() ? 0 : $ilUser->getId()),
3449  $this->handleFormInput($this->create_topic_form_gui->getInput('subject'), false),
3450  ilRTE::_replaceMediaObjectImageSrc($this->create_topic_form_gui->getInput('message'), 0),
3451  $this->create_topic_form_gui->getItemByPostVar('notify') ? (int)$this->create_topic_form_gui->getInput('notify') : 0,
3452  $this->create_topic_form_gui->getItemByPostVar('notify_posts') ? (int)$this->create_topic_form_gui->getInput('notify_posts') : 0,
3453  $user_alias,
3454  '',
3455  $status
3456  );
3457 
3458  $file = $_FILES['userfile'];
3459 
3460  // file upload
3461  if(is_array($file) && !empty($file))
3462  {
3463  $tmp_file_obj = new ilFileDataForum($this->object->getId(), $newPost);
3464  $tmp_file_obj->storeUploadedFile($file);
3465  }
3466 
3467  // Visit-Counter
3468  $frm->setDbTable('frm_data');
3469  $frm->setMDB2WhereCondition('top_pk = %s ', array('integer'), array($topicData['top_pk']));
3470  $frm->updateVisits($topicData['top_pk']);
3471 
3472  $frm->setMDB2WhereCondition('thr_top_fk = %s AND thr_subject = %s AND thr_num_posts = 1 ',
3473  array('integer', 'text'), array($topicData['top_pk'], $this->create_topic_form_gui->getInput('subject')));
3474 
3475  // copy temporary media objects (frm~)
3476  include_once 'Services/MediaObjects/classes/class.ilObjMediaObject.php';
3477  $mediaObjects = ilRTE::_getMediaObjects($this->create_topic_form_gui->getInput('message'), 0);
3478  foreach($mediaObjects as $mob)
3479  {
3480  if(ilObjMediaObject::_exists($mob))
3481  {
3482  ilObjMediaObject::_removeUsage($mob, 'frm~:html', $ilUser->getId());
3483  ilObjMediaObject::_saveUsage($mob, 'frm:html', $newPost);
3484  }
3485  }
3486 
3487  if($this->ilias->getSetting('forum_notification') == 1)
3488  {
3489  // send notification about new topic
3490  $objPost = new ilForumPost((int)$newPost, $this->is_moderator);
3491  $post_data = array();
3492  $post_data = $objPost->getDataAsArray();
3493  $titles = $this->getTitlesByRefId(array($this->object->getRefId()));
3494  $post_data["top_name"] = $titles[0];
3495  $post_data["ref_id"] =$this->object->getRefId();
3496 
3497  $frm->sendForumNotifications($post_data);
3498  }
3499  if(!$a_prevent_redirect)
3500  {
3501  ilUtil::sendSuccess($this->lng->txt('forums_thread_new_entry'), true);
3502  $this->ctrl->redirect($this);
3503  }
3504  else
3505  {
3506  return $newPost;
3507  }
3508  }
3509  else
3510  {
3511  $this->create_topic_form_gui->setValuesByPost();
3512 
3513  if(!$this->objProperties->isAnonymized())
3514  {
3515  $this->create_topic_form_gui->getItemByPostVar('alias')->setValue($ilUser->getLogin());
3516  }
3517 
3518  return $this->tpl->setContent($this->create_topic_form_gui->getHTML());
3519  }
3520  }
3521 
3522  public function enableForumNotificationObject()
3523  {
3527  global $ilUser;
3528 
3529  $frm = $this->object->Forum;
3530  $frm->setForumId($this->object->getId());
3531  $frm->enableForumNotification($ilUser->getId());
3532 
3533  if(!$this->objCurrentTopic->getId())
3534  {
3535  ilUtil::sendInfo($this->lng->txt('forums_forum_notification_enabled'));
3536  $this->showThreadsObject();
3537  }
3538  else
3539  {
3540  $this->ctrl->setParameter($this, 'thr_pk', $this->objCurrentTopic->getId());
3541  ilUtil::sendInfo($this->lng->txt('forums_forum_notification_enabled'), true);
3542  $this->ctrl->redirect($this, 'viewThread');
3543  }
3544  }
3545 
3546  public function disableForumNotificationObject()
3547  {
3551  global $ilUser;
3552 
3553  $frm = $this->object->Forum;
3554  $frm->setForumId($this->object->getId());
3555  $frm->disableForumNotification($ilUser->getId());
3556 
3557  if(!$this->objCurrentTopic->getId())
3558  {
3559  $this->showThreadsObject();
3560  ilUtil::sendInfo($this->lng->txt('forums_forum_notification_disabled'));
3561  }
3562  else
3563  {
3564  $this->ctrl->setParameter($this, 'thr_pk', $this->objCurrentTopic->getId());
3565  ilUtil::sendInfo($this->lng->txt('forums_forum_notification_disabled'), true);
3566  $this->ctrl->redirect($this, 'viewThread');
3567  }
3568  }
3569 
3570  public function checkEnableColumnEdit()
3571  {
3572  return false;
3573  }
3574 
3575  public function setColumnSettings(ilColumnGUI $column_gui)
3576  {
3581  global $lng, $ilAccess;
3582 
3583  $column_gui->setBlockProperty('news', 'title', $lng->txt('frm_latest_postings'));
3584  $column_gui->setBlockProperty('news', 'prevent_aggregation', true);
3585  $column_gui->setRepositoryMode(true);
3586 
3587  if($ilAccess->checkAccess('write', '', $this->object->getRefId()))
3588  {
3589  $news_set = new ilSetting('news');
3590  $enable_internal_rss = $news_set->get('enable_rss_for_internal');
3591  if($enable_internal_rss)
3592  {
3593  $column_gui->setBlockProperty('news', 'settings', true);
3594  $column_gui->setBlockProperty('news', 'public_notifications_option', true);
3595  }
3596  }
3597  }
3598 
3599 
3600  public function cloneWizardPageObject()
3601  {
3602  global $ilObjDataCache;
3603 
3604  if (!$_POST['clone_source'])
3605  {
3606  ilUtil::sendInfo($this->lng->txt('select_one'));
3607  if (isset($_SESSION['wizard_search_title']))
3608  {
3609  $this->searchCloneSourceObject();
3610  }
3611  else
3612  {
3613  $this->createObject();
3614  }
3615  return false;
3616  }
3617  $source_id = $_POST['clone_source'];
3618 
3619  $new_type = $_REQUEST['new_type'];
3620  $this->ctrl->setParameter($this, 'clone_source', (int) $_POST['clone_source']);
3621  $this->ctrl->setParameter($this, 'new_type', $new_type);
3622 
3623  $this->tpl->addBlockFile('ADM_CONTENT', 'adm_content', 'tpl.frm_wizard_page.html', 'Modules/Forum');
3624  $this->tpl->setVariable('FORMACTION', $this->ctrl->getFormAction($this));
3625  $this->tpl->setVariable('TYPE_IMG', ilUtil::getImagePath('icon_'.$new_type.'.png'));
3626  $this->tpl->setVariable('ALT_IMG', $this->lng->txt('obj_'.$new_type));
3627  $this->tpl->setVariable('TXT_DUPLICATE', $this->lng->txt('frm_wizard_page'));
3628  $this->tpl->setVariable('INFO_THREADS', $this->lng->txt('fmr_copy_threads_info'));
3629  $this->tpl->setVariable('THREADS', $this->lng->txt('forums_threads'));
3630 
3631  $forum_id = $ilObjDataCache->lookupObjId((int) $_POST['clone_source']);
3632  include_once('Modules/Forum/classes/class.ilForum.php');
3633  $threads = ilForum::_getThreads($forum_id, ilForum::SORT_TITLE);
3634  foreach ($threads as $thread_id => $title)
3635  {
3636  $this->tpl->setCurrentBlock('thread_row');
3637  $this->tpl->setVariable('CHECK_THREAD', ilUtil::formCheckbox(0, 'cp_options['.$source_id.'][threads][]', $thread_id));
3638  $this->tpl->setVariable('NAME_THREAD', $title);
3639  $this->tpl->parseCurrentBlock();
3640  }
3641  $this->tpl->setVariable('SELECT_ALL', $this->lng->txt('select_all'));
3642  $this->tpl->setVariable('JS_FIELD', 'cp_options['.$source_id.'][threads]');
3643  $this->tpl->setVariable('BTN_COPY', $this->lng->txt('obj_'.$new_type.'_duplicate'));
3644  if (isset($_SESSION['wizard_search_title']))
3645  {
3646  $this->tpl->setVariable('BACK_CMD', 'searchCloneSource');
3647  }
3648  else
3649  {
3650  $this->tpl->setVariable('BACK_CMD', 'create');
3651  }
3652  $this->tpl->setVariable('BTN_BACK', $this->lng->txt('btn_back'));
3653  }
3654 
3655  public function addLocatorItems()
3656  {
3659  global $ilLocator;
3660 
3661  if($this->object instanceof ilObject)
3662  {
3663  $ilLocator->addItem($this->object->getTitle(), $this->ctrl->getLinkTarget($this, ''), '', $this->object->getRefId());
3664  }
3665  }
3666 
3667  public function handleFormInput($a_text, $a_stripslashes = true)
3668  {
3669  $a_text = str_replace("<", "&lt;", $a_text);
3670  $a_text = str_replace(">", "&gt;", $a_text);
3671  if($a_stripslashes)
3672  $a_text = ilUtil::stripSlashes($a_text);
3673 
3674  return $a_text;
3675  }
3676 
3677  public function prepareFormOutput($a_text)
3678  {
3679  $a_text = str_replace("&lt;", "<", $a_text);
3680  $a_text = str_replace("&gt;", ">", $a_text);
3681  $a_text = ilUtil::prepareFormOutput($a_text);
3682  return $a_text;
3683  }
3684 
3690  public function infoScreenObject()
3691  {
3692  $this->ctrl->setCmd('showSummary');
3693  $this->ctrl->setCmdClass('ilinfoscreengui');
3694  $this->infoScreen();
3695  }
3696 
3697  public function infoScreen()
3698  {
3702  global $ilAccess;
3703 
3704  if(!$ilAccess->checkAccess('visible', '', $this->object->getRefId()))
3705  {
3706  $this->ilias->raiseError($this->lng->txt('msg_no_perm_read'), $this->ilias->error_obj->MESSAGE);
3707  }
3708 
3709  include_once 'Services/InfoScreen/classes/class.ilInfoScreenGUI.php';
3710  $info = new ilInfoScreenGUI($this);
3711 
3712  $info->enablePrivateNotes();
3713 
3714  // standard meta data
3715  $info->addMetaDataSections($this->object->getId(), 0, $this->object->getType());
3716 
3717  // forward the command
3718  $this->ctrl->forwardCommand($info);
3719  }
3720 
3721  public function updateNotificationSettingsObject()
3722  {
3727  global $ilAccess, $ilErr;
3728  if(!$ilAccess->checkAccess('write', '', $this->ref_id))
3729  {
3730  $ilErr->raiseError($this->lng->txt('msg_no_perm_read'),$ilErr->MESSAGE);
3731  }
3732 
3733  // instantiate the property form
3735 
3736  // check input
3737  if($this->notificationSettingsForm->checkInput())
3738  {
3739  if(isset($_POST['notification_type']) && $_POST['notification_type']== 'all_users')
3740  {
3741  // set values and call update
3742  $this->objProperties->setAdminForceNoti(1);
3743  $this->objProperties->setUserToggleNoti((int) $this->notificationSettingsForm->getInput('usr_toggle'));
3744  $this->objProperties->setNotificationType('all_users');
3745  $this->updateUserNotifications(true);
3746  }
3747  else if($_POST['notification_type']== 'per_user')
3748  {
3749  $this->objProperties->setNotificationType('per_user');
3750  $this->objProperties->setAdminForceNoti(1);
3751  $this->objProperties->setUserToggleNoti(0);
3752  $this->updateUserNotifications();
3753  }
3754  else // if($_POST['notification_type'] == 'default')
3755  {
3756  $this->objProperties->setNotificationType('default');
3757  $this->objProperties->setAdminForceNoti(0);
3758  $this->objProperties->setUserToggleNoti(0);
3759  include_once 'Modules/Forum/classes/class.ilForumNotification.php';
3760  $frm_noti = new ilForumNotification($this->object->getRefId());
3761  $frm_noti->deleteNotificationAllUsers();
3762  }
3763 
3764  $this->objProperties->update();
3765 
3766  // print success message
3767  ilUtil::sendSuccess($this->lng->txt('saved_successfully'));
3768  }
3769  $this->notificationSettingsForm->setValuesByPost();
3770 
3771  return $this->showMembersObject();
3772  }
3773 
3774  private function updateUserNotifications($update_all_users = false)
3775  {
3776  include_once 'Modules/Forum/classes/class.ilForumNotification.php';
3777 
3778  $oParticipants = $this->getParticipantsObject();
3779 
3780  $frm_noti = new ilForumNotification($this->object->getRefId());
3781  $moderator_ids = $frm_noti->_getModerators($this->object->getRefId());
3782 
3783  $admin_ids = $oParticipants->getAdmins();
3784  $member_ids = $oParticipants->getMembers();
3785  $tutor_ids = $oParticipants->getTutors();
3786 
3787  $all_forum_users = array_merge($moderator_ids, $admin_ids, $member_ids, $tutor_ids);
3788  $all_forum_users= array_unique($all_forum_users);
3789 
3790  $all_notis = $frm_noti->read();
3791 
3792  foreach($all_forum_users as $user_id)
3793  {
3794  $frm_noti->setUserId($user_id);
3795 
3796  $frm_noti->setAdminForce(1);
3797  $frm_noti->setUserToggle($this->objProperties->isUserToggleNoti());
3798 
3799  if(array_key_exists($user_id, $all_notis) && $update_all_users)
3800  {
3801  $frm_noti->update();
3802  }
3803  else if($frm_noti->existsNotification() == false)
3804  {
3805  $frm_noti->insertAdminForce();
3806  }
3807  }
3808  }
3809 
3810  private function initNotificationSettingsForm()
3811  {
3812  if(null === $this->notificationSettingsForm)
3813  {
3814  $form = new ilPropertyFormGUI();
3815  $form->setFormAction($this->ctrl->getFormAction($this, 'updateNotificationSettings'));
3816  $form->setTitle($this->lng->txt('forums_notification_settings'));
3817 
3818  $radio_grp = new ilRadioGroupInputGUI('','notification_type');
3819  $radio_grp->setValue('default');
3820 
3821  $opt_default = new ilRadioOption($this->lng->txt("user_decides_notification"), 'default');
3822  $opt_0 = new ilRadioOption($this->lng->txt("settings_for_all_members"), 'all_users');
3823  $opt_1 = new ilRadioOption($this->lng->txt("settings_per_users"), 'per_user');
3824 
3825  $radio_grp->addOption($opt_default, 'default');
3826  $radio_grp->addOption($opt_0, 'all_users');
3827  $radio_grp->addOption($opt_1, 'per_user');
3828 
3829  $chb_2 = new ilCheckboxInputGUI($this->lng->txt('user_toggle_noti'), 'usr_toggle');
3830  $chb_2->setValue(1);
3831 
3832  $opt_0->addSubItem($chb_2);
3833  $form->addItem($radio_grp);
3834 
3835  $form->addCommandButton('updateNotificationSettings', $this->lng->txt('save'));
3836 
3837  $this->notificationSettingsForm = $form;
3838 
3839  return false;
3840  }
3841 
3842  return true;
3843  }
3844 
3845  public function getIcon($user_toggle_noti)
3846  {
3847  $icon = $user_toggle_noti
3848  ? "<img src=\"".ilUtil::getImagePath("icon_ok.png")."\" alt=\"".$this->lng->txt("enabled")."\" title=\"".$this->lng->txt("enabled")."\" border=\"0\" vspace=\"0\"/>"
3849  : "<img src=\"".ilUtil::getImagePath("icon_not_ok.png")."\" alt=\"".$this->lng->txt("disabled")."\" title=\"".$this->lng->txt("disabled")."\" border=\"0\" vspace=\"0\"/>";
3850  return $icon;
3851  }
3852 
3853  public function showMembersObject()
3854  {
3862  global $tree, $tpl, $ilTabs, $ilAccess, $ilErr;
3863 
3864  if(!$ilAccess->checkAccess('write', '', $this->ref_id))
3865  {
3866  $ilErr->raiseError($this->lng->txt('msg_no_perm_read'),$ilErr->MESSAGE);
3867  }
3868 
3869  $tpl->addBlockFile('ADM_CONTENT', 'adm_content', 'tpl.forums_members_list.html', 'Modules/Forum');
3870 
3871  $ilTabs->setTabActive('settings');
3872  $this->settingsTabs();
3873 
3874  // instantiate the property form
3875  if(!$this->initNotificationSettingsForm())
3876  {
3877  // if the form was just created set the values fetched from database
3878  $this->notificationSettingsForm->setValuesByArray(array(
3879  'notification_type' => $this->objProperties->getNotificationType(),
3880  'adm_force' => (bool) $this->objProperties->isAdminForceNoti(),
3881  'usr_toggle' => (bool) $this->objProperties->isUserToggleNoti()
3882  ));
3883  }
3884 
3885  // set form html into template
3886  $tpl->setVariable('NOTIFICATIONS_SETTINGS_FORM', $this->notificationSettingsForm->getHTML());
3887 
3888  include_once 'Modules/Forum/classes/class.ilForumNotification.php';
3889  include_once 'Modules/Forum/classes/class.ilObjForum.php';
3890 
3891  $frm_noti = new ilForumNotification($this->object->getRefId());
3892  $oParticipants = $this->getParticipantsObject();
3893 
3894  $moderator_ids = $frm_noti->_getModerators($this->object->getRefId());
3895 
3896  $admin_ids = $oParticipants->getAdmins();
3897  $member_ids = $oParticipants->getMembers();
3898  $tutor_ids = $oParticipants->getTutors();
3899 
3900  if($this->objProperties->getNotificationType() == 'default')
3901  {
3902  // update forum_notification table
3903  include_once 'Modules/Forum/classes/class.ilForumNotification.php';
3904  $forum_noti = new ilForumNotification($this->object->getRefId());
3905  $forum_noti->setAdminForce($this->objProperties->isAdminForceNoti());
3906  $forum_noti->setUserToggle($this->objProperties->isUserToggleNoti());
3907  $forum_noti->setForumId($this->objProperties->getObjId());
3908  }
3909  else if($this->objProperties->getNotificationType() == 'per_user')
3910  {
3911  $moderators = $this->getUserNotificationTableData($moderator_ids, $frm_noti);
3912  $admins = $this->getUserNotificationTableData($admin_ids, $frm_noti);
3913  $members = $this->getUserNotificationTableData($member_ids, $frm_noti);
3914  $tutors = $this->getUserNotificationTableData($tutor_ids, $frm_noti);
3915 
3916  $this->__showMembersTable($moderators, $admins, $members, $tutors);
3917  }
3918  }
3919 
3920  private function getUserNotificationTableData($user_ids, ilForumNotification $frm_noti)
3921  {
3922  $counter = 0;
3923  $users = array();
3924  foreach($user_ids as $user_id)
3925  {
3926  $frm_noti->setUserId($user_id);
3927  $user_toggle_noti = $frm_noti->isUserToggleNotification();
3928  $icon_ok = $this->getIcon(!$user_toggle_noti);
3929 
3930  $users[$counter]['user_id'] = ilUtil::formCheckbox(0, 'user_id[]', $user_id);
3931  $users[$counter]['login'] = ilObjUser::_lookupLogin($user_id);
3932  $name = ilObjUser::_lookupName($user_id);
3933  $users[$counter]['firstname'] = $name['firstname'];
3934  $users[$counter]['lastname'] = $name['lastname'];
3935  $users[$counter]['user_toggle_noti'] = $icon_ok;
3936  $counter++;
3937  }
3938  return $users;
3939  }
3940 
3941  private function __showMembersTable($moderators, $admins, $members, $tutors)
3942  {
3948  global $lng, $tpl, $ilCtrl;
3949 
3950  if($moderators)
3951  {
3952  $tbl_mod = new ilTable2GUI($this);
3953  $tbl_mod->setId('tbl_id_mod');
3954  $tbl_mod->setFormAction($ilCtrl->getFormAction($this, 'showMembers'));
3955  $tbl_mod->setTitle($lng->txt('moderators'));
3956 
3957  $tbl_mod->addColumn('', '', '1%', true);
3958  $tbl_mod->addColumn($lng->txt('login'), '', '10%');
3959  $tbl_mod->addColumn($lng->txt('firstname'), '', '10%');
3960  $tbl_mod->addColumn($lng->txt('lastname'), '', '10%');
3961  $tbl_mod->addColumn($lng->txt('allow_user_toggle_noti'), '', '10%');
3962  $tbl_mod->setSelectAllCheckbox('user_id');
3963 
3964  $tbl_mod->setRowTemplate('tpl.forums_members_row.html', 'Modules/Forum');
3965  $tbl_mod->setData($moderators);
3966 
3967  $tbl_mod->addMultiCommand('enableHideUserToggleNoti',$lng->txt('enable_hide_user_toggle'));
3968  $tbl_mod->addMultiCommand('disableHideUserToggleNoti',$lng->txt('disable_hide_user_toggle'));
3969 
3970  $tpl->setCurrentBlock('moderators_table');
3971  $tpl->setVariable('MODERATORS',$tbl_mod->getHTML());
3972  }
3973 
3974  if($admins)
3975  {
3976  $tbl_adm = new ilTable2GUI($this);
3977  $tbl_adm->setId('tbl_id_adm');
3978  $tbl_adm->setFormAction($ilCtrl->getFormAction($this, 'showMembers'));
3979  $tbl_adm->setTitle($lng->txt('administrator'));
3980 
3981  $tbl_adm->addColumn('', '', '1%', true);
3982  $tbl_adm->addColumn($lng->txt('login'), '', '10%');
3983  $tbl_adm->addColumn($lng->txt('firstname'), '', '10%');
3984  $tbl_adm->addColumn($lng->txt('lastname'), '', '10%');
3985  $tbl_adm->addColumn($lng->txt('allow_user_toggle_noti'), '', '10%');
3986  $tbl_adm->setSelectAllCheckbox('user_id');
3987  $tbl_adm->setRowTemplate('tpl.forums_members_row.html', 'Modules/Forum');
3988 
3989  $tbl_adm->setData($admins);
3990  $tbl_adm->addMultiCommand('enableHideUserToggleNoti',$lng->txt('enable_hide_user_toggle'));
3991  $tbl_adm->addMultiCommand('disableHideUserToggleNoti',$lng->txt('disable_hide_user_toggle'));
3992 
3993  $tpl->setCurrentBlock('admins_table');
3994  $tpl->setVariable('ADMINS',$tbl_adm->getHTML());
3995  }
3996 
3997  if($members)
3998  {
3999  $tbl_mem = new ilTable2GUI($this);
4000  $tbl_mem->setId('tbl_id_mem');
4001  $tbl_mem->setFormAction($ilCtrl->getFormAction($this, 'showMembers'));
4002  $tbl_mem->setTitle($lng->txt('members'));
4003 
4004  $tbl_mem->addColumn('', '', '1%', true);
4005  $tbl_mem->addColumn($lng->txt('login'), '', '10%');
4006  $tbl_mem->addColumn($lng->txt('firstname'), '', '10%');
4007  $tbl_mem->addColumn($lng->txt('lastname'), '', '10%');
4008  $tbl_mem->addColumn($lng->txt('allow_user_toggle_noti'), '', '10%');
4009  $tbl_mem->setSelectAllCheckbox('user_id');
4010  $tbl_mem->setRowTemplate('tpl.forums_members_row.html', 'Modules/Forum');
4011  $tbl_mem->setData($members);
4012 
4013  $tbl_mem->addMultiCommand('enableHideUserToggleNoti',$lng->txt('enable_hide_user_toggle'));
4014  $tbl_mem->addMultiCommand('disableHideUserToggleNoti',$lng->txt('disable_hide_user_toggle'));
4015 
4016  $tpl->setCurrentBlock('members_table');
4017  $tpl->setVariable('MEMBERS',$tbl_mem->getHTML());
4018  }
4019 
4020  if($tutors)
4021  {
4022  $tbl_tut = new ilTable2GUI($this);
4023  $tbl_tut->setId('tbl_id_tut');
4024  $tbl_tut->setFormAction($ilCtrl->getFormAction($this, 'showMembers'));
4025  $tbl_tut->setTitle($lng->txt('tutors'));
4026 
4027  $tbl_tut->addColumn('', '', '1%', true);
4028  $tbl_tut->addColumn($lng->txt('login'), '', '10%');
4029  $tbl_tut->addColumn($lng->txt('firstname'), '', '10%');
4030  $tbl_tut->addColumn($lng->txt('lastname'), '', '10%');
4031  $tbl_tut->addColumn($lng->txt('allow_user_toggle_noti'), '', '10%');
4032  $tbl_tut->setSelectAllCheckbox('user_id');
4033  $tbl_tut->setRowTemplate('tpl.forums_members_row.html', 'Modules/Forum');
4034  $tbl_tut->setData($tutors);
4035 
4036  $tbl_tut->addMultiCommand('enableHideUserToggleNoti',$lng->txt('enable_hide_user_toggle'));
4037  $tbl_tut->addMultiCommand('disableHideUserToggleNoti',$lng->txt('disable_hide_user_toggle'));
4038 
4039  $tpl->setCurrentBlock('tutors_table');
4040  $tpl->setVariable('TUTORS',$tbl_tut->getHTML());
4041  }
4042  }
4043 
4044  public function enableAdminForceNotiObject()
4045  {
4050  global $ilAccess, $ilErr;
4051  if(!$ilAccess->checkAccess('write', '', $this->ref_id))
4052  {
4053  $ilErr->raiseError($this->lng->txt('msg_no_perm_read'),$ilErr->MESSAGE);
4054  }
4055 
4056  if(!isset($_POST['user_id']) || !is_array($_POST['user_id']))
4057  {
4058  ilUtil::sendInfo($this->lng->txt('time_limit_no_users_selected'), true);
4059  }
4060  else
4061  {
4062  include_once 'Modules/Forum/classes/class.ilForumNotification.php';
4063  $frm_noti = new ilForumNotification($this->object->getRefId());
4064 
4065  foreach($_POST['user_id'] as $user_id)
4066  {
4067  $frm_noti->setUserId((int) $user_id);
4068  $is_enabled = $frm_noti->isAdminForceNotification();
4069 
4070  $frm_noti->setUserToggle(0);
4071  if(!$is_enabled)
4072  {
4073  $frm_noti->setAdminForce(1);
4074  $frm_noti->insertAdminForce();
4075  }
4076  }
4077 
4078  ilUtil::sendSuccess($this->lng->txt('saved_successfully'));
4079  }
4080 
4081  $this->showMembersObject();
4082  }
4083 
4084  public function disableAdminForceNotiObject()
4085  {
4090  global $ilAccess, $ilErr;
4091  if(!$ilAccess->checkAccess('write', '', $this->ref_id))
4092  {
4093  $ilErr->raiseError($this->lng->txt('msg_no_perm_read'),$ilErr->MESSAGE);
4094  }
4095 
4096  if(!isset($_POST['user_id']) || !is_array($_POST['user_id']))
4097  {
4098  ilUtil::sendInfo($this->lng->txt('time_limit_no_users_selected'));
4099  }
4100  else
4101  {
4102  include_once 'Modules/Forum/classes/class.ilForumNotification.php';
4103  $frm_noti = new ilForumNotification($this->object->getRefId());
4104 
4105  foreach($_POST['user_id'] as $user_id)
4106  {
4107  $frm_noti->setUserId((int) $user_id);
4108  $is_enabled = $frm_noti->isAdminForceNotification();
4109 
4110  if($is_enabled)
4111  {
4112  $frm_noti->deleteAdminForce();
4113  }
4114  }
4115 
4116  ilUtil::sendSuccess($this->lng->txt('saved_successfully'));
4117  }
4118 
4119  $this->showMembersObject();
4120  }
4121 
4122  public function enableHideUserToggleNotiObject()
4123  {
4128  global $ilAccess, $ilErr;
4129  if(!$ilAccess->checkAccess('write', '', $this->ref_id))
4130  {
4131  $ilErr->raiseError($this->lng->txt('msg_no_perm_read'),$ilErr->MESSAGE);
4132  }
4133  if(!isset($_POST['user_id']) || !is_array($_POST['user_id']))
4134  {
4135  ilUtil::sendInfo($this->lng->txt('time_limit_no_users_selected'));
4136  }
4137  else
4138  {
4139  include_once 'Modules/Forum/classes/class.ilForumNotification.php';
4140  $frm_noti = new ilForumNotification($this->object->getRefId());
4141 
4142  foreach($_POST['user_id'] as $user_id)
4143  {
4144  $frm_noti->setUserId((int) $user_id);
4145  $is_enabled = $frm_noti->isAdminForceNotification();
4146  $frm_noti->setUserToggle(1);
4147 
4148  if(!$is_enabled)
4149  {
4150  $frm_noti->setAdminForce(1);
4151  $frm_noti->insertAdminForce();
4152  }
4153  else
4154  {
4155  $frm_noti->updateUserToggle();
4156  }
4157  }
4158 
4159  ilUtil::sendSuccess($this->lng->txt('saved_successfully'));
4160  }
4161 
4162  $this->showMembersObject();
4163  }
4164 
4165  public function disableHideUserToggleNotiObject()
4166  {
4171  global $ilAccess, $ilErr;
4172  if(!$ilAccess->checkAccess('write', '', $this->ref_id))
4173  {
4174  $ilErr->raiseError($this->lng->txt('msg_no_perm_read'),$ilErr->MESSAGE);
4175  }
4176 
4177  if(!isset($_POST['user_id']) || !is_array($_POST['user_id']))
4178  {
4179  ilUtil::sendInfo($this->lng->txt('time_limit_no_users_selected'));
4180  }
4181  else
4182  {
4183  include_once 'Modules/Forum/classes/class.ilForumNotification.php';
4184  $frm_noti = new ilForumNotification($this->object->getRefId());
4185 
4186  foreach($_POST['user_id'] as $user_id)
4187  {
4188  $frm_noti->setUserId((int) $user_id);
4189  $is_enabled = $frm_noti->isAdminForceNotification();
4190  $frm_noti->setUserToggle(0);
4191  if($is_enabled)
4192  {
4193  $frm_noti->updateUserToggle();
4194  }
4195  else
4196  {
4197  $frm_noti->setAdminForce(1);
4198  $frm_noti->insertAdminForce();
4199  }
4200  }
4201 
4202  ilUtil::sendSuccess($this->lng->txt('saved_successfully'));
4203  }
4204 
4205  $this->showMembersObject();
4206  }
4207 
4208  public function markPostUnreadObject()
4209  {
4213  global $ilUser;
4214 
4215  if(isset($_GET['pos_pk']))
4216  {
4217  $this->object->markPostUnread($ilUser->getId(), (int) $_GET['pos_pk']);
4218  }
4219 
4220  $this->viewThreadObject();
4221  }
4222 
4223  public function markPostReadObject()
4224  {
4228  global $ilUser;
4229 
4230  $this->object->markPostRead($ilUser->getId(), (int) $this->objCurrentTopic->getId(), (int) $this->objCurrentPost->getId());
4231  $this->viewThreadObject();
4232  }
4233 
4234  protected function initHeaderAction($a_sub_type = null, $a_sub_id = null)
4235  {
4239  global $ilUser;
4240 
4241  $lg = parent::initHeaderAction();
4242 
4243  // Workaround: Do not show "desktop actions" in thread view
4244  if($this->objCurrentTopic->getId())
4245  {
4246  $container_obj = null;
4247  $lg->setContainerObject($container_obj);
4248  }
4249 
4250  if($lg instanceof ilObjForumListGUI)
4251  {
4252  if($ilUser->getId() != ANONYMOUS_USER_ID && $this->ilias->getSetting('forum_notification') != 0 )
4253  {
4254  $is_user_allowed_to_deactivate_notification = $this->isUserAllowedToDeactivateNotification();
4255 
4256  $frm = $this->object->Forum;
4257  $frm->setForumId($this->object->getId());
4258  $frm->setForumRefId($this->object->getRefId());
4259  $frm->setMDB2Wherecondition('top_frm_fk = %s ', array('integer'), array($frm->getForumId()));
4260  $frm_notificiation_enabled = $frm->isForumNotificationEnabled($ilUser->getId());
4261 
4262  if($this->objCurrentTopic->getId())
4263  {
4264  $this->ctrl->setParameter($this, 'thr_pk', $this->objCurrentTopic->getId());
4265  }
4266 
4267  if($this->isParentObjectCrsOrGrp())
4268  {
4269  // special behaviour for CRS/GRP-Forum notification!!
4270  if(
4271  $frm_notificiation_enabled &&
4272  $is_user_allowed_to_deactivate_notification
4273  )
4274  {
4275  $lg->addCustomCommand($this->ctrl->getLinkTarget($this, 'disableForumNotification'), "forums_disable_forum_notification");
4276  }
4277  else
4278  {
4279  $lg->addCustomCommand($this->ctrl->getLinkTarget($this, 'enableForumNotification'), "forums_enable_forum_notification");
4280  }
4281  }
4282  else
4283  {
4284  if($frm_notificiation_enabled)
4285  {
4286  $lg->addCustomCommand($this->ctrl->getLinkTarget($this, 'disableForumNotification'), "forums_disable_forum_notification");
4287  }
4288  else
4289  {
4290  $lg->addCustomCommand($this->ctrl->getLinkTarget($this, 'enableForumNotification'), "forums_enable_forum_notification");
4291  }
4292  }
4293 
4294  $topic_notification_enabled = false;
4295  if($this->objCurrentTopic->getId())
4296  {
4297  $topic_notification_enabled = $this->objCurrentTopic->isNotificationEnabled($ilUser->getId());
4298  if($topic_notification_enabled)
4299  {
4300  $lg->addCustomCommand($this->ctrl->getLinkTarget($this, 'toggleThreadNotification'), "forums_disable_notification");
4301  }
4302  else
4303  {
4304  $lg->addCustomCommand($this->ctrl->getLinkTarget($this, 'toggleThreadNotification'), "forums_enable_notification");
4305  }
4306  }
4307  $this->ctrl->setParameter($this, 'thr_pk', '');
4308 
4309  if($frm_notificiation_enabled || $topic_notification_enabled)
4310  {
4311  $lg->addHeaderIcon(
4312  "not_icon",
4313  ilUtil::getImagePath("notification_on.png"),
4314  $this->lng->txt("frm_notification_activated")
4315  );
4316  }
4317  else
4318  {
4319  $lg->addHeaderIcon(
4320  "not_icon",
4321  ilUtil::getImagePath("notification_off.png"),
4322  $this->lng->txt("frm_notification_deactivated")
4323  );
4324  }
4325  }
4326  }
4327 
4328  return $lg;
4329  }
4330 
4332  {
4333  if($this->objProperties->getNotificationType() == 'default')
4334  {
4335  return true;
4336  }
4337 
4338  if($this->objProperties->isUserToggleNoti() == 0)
4339  {
4340  return true;
4341  }
4342 
4343  if($this->isParentObjectCrsOrGrp());
4344  {
4345  global $ilUser;
4346 
4347  include_once 'Modules/Forum/classes/class.ilForumNotification.php';
4348 
4349  $frm_noti = new ilForumNotification((int) $_GET['ref_id']);
4350  $frm_noti->setUserId($ilUser->getId());
4351 
4352  $user_toggle = (int)$frm_noti->isUserToggleNotification();
4353  if($user_toggle == 0)
4354  {
4355  return true;
4356  }
4357  }
4358 
4359  return false;
4360  }
4361 
4362  private function isParentObjectCrsOrGrp()
4363  {
4364  global $tree;
4365 
4366  // check if there a parent-node is a grp or crs
4367  $grp_ref_id = $tree->checkForParentType($this->object->getRefId(), 'grp');
4368  $crs_ref_id = $tree->checkForParentType($this->object->getRefId(), 'crs');
4369 
4370  if($grp_ref_id == 0 && $crs_ref_id == 0)
4371  {
4372  return false;
4373  }
4374  return true;
4375  }
4376 
4380  public function getParticipantsObject()
4381  {
4382  global $tree, $ilErr;
4383 
4384  $grp_ref_id = $tree->checkForParentType($this->object->getRefId(), 'grp');
4385  $crs_ref_id = $tree->checkForParentType($this->object->getRefId(), 'crs');
4386 
4387  if($this->isParentObjectCrsOrGrp() == false)
4388  {
4389  $ilErr->raiseError($this->lng->txt('msg_no_perm_read'), $ilErr->MESSAGE);
4390  }
4391 
4395  $oParticipants = null;
4396 
4397  if($grp_ref_id > 0)
4398  {
4399  $parent_obj = ilObjectFactory::getInstanceByRefId($grp_ref_id);
4400  include_once 'Modules/Group/classes/class.ilGroupParticipants.php';
4401  $oParticipants = ilGroupParticipants::_getInstanceByObjId($parent_obj->getId());
4402  return $oParticipants;
4403  }
4404  else if($crs_ref_id > 0)
4405  {
4406  $parent_obj = ilObjectFactory::getInstanceByRefId($crs_ref_id);
4407 
4408  include_once 'Modules/Course/classes/class.ilCourseParticipants.php';
4409  $oParticipants = ilCourseParticipants::_getInstanceByObjId($parent_obj->getId());
4410  return $oParticipants;
4411  }
4412 
4413  return $oParticipants;
4414  }
4415 
4419  public function addToDeskObject()
4420  {
4425  global $ilSetting, $lng;
4426 
4427  if((int)$ilSetting->get('disable_my_offers'))
4428  {
4429  $this->showThreadsObject();
4430  return;
4431  }
4432 
4433  include_once './Services/PersonalDesktop/classes/class.ilDesktopItemGUI.php';
4435  ilUtil::sendSuccess($lng->txt("added_to_desktop"));
4436  $this->showThreadsObject();
4437  }
4438 
4442  public function removeFromDeskObject()
4443  {
4444  global $ilSetting, $lng;
4445 
4446  if((int)$ilSetting->get('disable_my_offers'))
4447  {
4448  $this->showThreadsObject();
4449  return;
4450  }
4451 
4452  include_once './Services/PersonalDesktop/classes/class.ilDesktopItemGUI.php';
4454  ilUtil::sendSuccess($lng->txt("removed_from_desktop"));
4455  $this->showThreadsObject();
4456  }
4457 
4458  public function saveThreadSortingObject()
4459  {
4460  $_POST['thread_sorting'] ? $thread_sorting = $_POST['thread_sorting'] :$thread_sorting = array();
4461 
4462  foreach($thread_sorting as $thr_pk=>$sorting_value)
4463  {
4464  $sorting_value = str_replace(',','.',$sorting_value);
4465  $sorting_value = (float)$sorting_value * 100;
4466  $this->object->setThreadSorting($thr_pk,$sorting_value);
4467  }
4468  ilUtil::sendSuccess($this->lng->txt('saved_successfully'));
4469  $this->showThreadsObject();
4470  return true;
4471  }
4472 
4476  public function mergeThreadsObject()
4477  {
4478  if(!$this->is_moderator)
4479  {
4480  $this->ilias->raiseError($this->lng->txt('permission_denied'), $this->ilias->error_obj->MESSAGE);
4481  }
4482 
4483  $selected_thread_id = 0;
4484  if(isset($_GET['merge_thread_id']) && (int)$_GET['merge_thread_id'])
4485  {
4486  $selected_thread_id = (int)$_GET['merge_thread_id'];
4487  }
4488  else if(isset($_POST['thread_ids']) && count((array)$_POST['thread_ids']) == 1)
4489  {
4490  $selected_thread_id = (int)current($_POST['thread_ids']);
4491  }
4492  else
4493  {
4494  ilUtil::sendInfo($this->lng->txt('select_one'));
4495  $this->showThreadsObject();
4496  return;
4497  }
4498 
4499  if($selected_thread_id)
4500  {
4501  $frm = $this->object->Forum;
4502  $frm->setForumId($this->object->getId());
4503  $frm->setForumRefId($this->object->getRefId());
4504 
4505  $selected_thread_obj = new ilForumTopic($selected_thread_id);
4506 
4507  if(ilForum::_lookupObjIdForForumId($selected_thread_obj->getForumId()) != $frm->getForumId())
4508  {
4509  ilUtil::sendFailure($this->lng->txt('not_allowed_to_merge_into_another_forum'));
4510  $this->showThreadsObject();
4511  return;
4512  }
4513 
4514  $frm->setMDB2Wherecondition('top_frm_fk = %s ', array('integer'), array($frm->getForumId()));
4515 
4516  $this->tpl->addBlockFile('ADM_CONTENT', 'adm_content', 'tpl.forums_threads_liste.html', 'Modules/Forum');
4517 
4518  $topicData = $frm->getOneTopic();
4519  if($topicData)
4520  {
4521  include_once 'Modules/Forum/classes/class.ilForumTopicTableGUI.php';
4522  $this->ctrl->setParameter($this, 'merge_thread_id', $selected_thread_id);
4523  $tbl = new ilForumTopicTableGUI($this, 'mergeThreads', '', (int)$_GET['ref_id'], $topicData, $this->is_moderator, $this->forum_overview_setting);
4524  $tbl->setSelectedThread($selected_thread_obj);
4525  $tbl->setMapper($frm)->fetchData();
4526  $tbl->populate();
4527  $this->tpl->setVariable('THREADS_TABLE', $tbl->getHTML());
4528  }
4529  else
4530  {
4531  ilUtil::sendFailure($this->lng->txt('select_one'));
4532  $this->showThreadsObject();
4533  return;
4534  }
4535  }
4536  }
4537 
4541  public function confirmMergeThreadsObject()
4542  {
4543  if(!$this->is_moderator)
4544  {
4545  $this->ilias->raiseError($this->lng->txt('permission_denied'), $this->ilias->error_obj->MESSAGE);
4546  }
4547 
4548  if(!isset($_GET['merge_thread_id']) || !(int)$_GET['merge_thread_id'] || !is_array($_POST['thread_ids']) || count($_POST['thread_ids']) != 1)
4549  {
4550  ilUtil::sendFailure($this->lng->txt('select_one'));
4551  $this->mergeThreadsObject();
4552  return;
4553  }
4554 
4555  $source_thread_id = (int)$_GET['merge_thread_id'];
4556  $target_thread_id = (int)current($_POST['thread_ids']);
4557 
4558  if($source_thread_id == $target_thread_id)
4559  {
4560  ilUtil::sendFailure($this->lng->txt('error_same_thread_ids'));
4561  $this->showThreadsObject();
4562  return;
4563  }
4564 
4565  if(ilForumTopic::lookupForumIdByTopicId($source_thread_id) != ilForumTopic::lookupForumIdByTopicId($target_thread_id))
4566  {
4567  ilUtil::sendFailure($this->lng->txt('not_allowed_to_merge_into_another_forum'));
4568  $this->ctrl->clearParameters($this);
4569  $this->showThreadsObject();
4570  return;
4571  }
4572 
4573  if(ilForumTopic::_lookupDate($source_thread_id) < ilForumTopic::_lookupDate($target_thread_id))
4574  {
4575  ilUtil::sendInfo($this->lng->txt('switch_threads_for_merge'));
4576  }
4577 
4578  include_once 'Services/Utilities/classes/class.ilConfirmationGUI.php';
4579  $c_gui = new ilConfirmationGUI();
4580 
4581  $c_gui->setFormAction($this->ctrl->getFormAction($this, 'performMergeThreads'));
4582  $c_gui->setHeaderText($this->lng->txt('frm_sure_merge_threads'));
4583  $c_gui->setCancel($this->lng->txt('cancel'), 'showThreads');
4584  $c_gui->setConfirm($this->lng->txt('confirm'), 'performMergeThreads');
4585 
4586  $c_gui->addItem('thread_ids[]', $source_thread_id, sprintf($this->lng->txt('frm_merge_src'), ilForumTopic::_lookupTitle($source_thread_id)));
4587  $c_gui->addItem('thread_ids[]', $target_thread_id, sprintf($this->lng->txt('frm_merge_target'), ilForumTopic::_lookupTitle($target_thread_id)));
4588 
4589  $this->tpl->setContent($c_gui->getHTML());
4590  return;
4591  }
4592 
4596  public function performMergeThreadsObject()
4597  {
4601  global $lng;
4602 
4603  if(!$this->is_moderator)
4604  {
4605  $this->ilias->raiseError($this->lng->txt('permission_denied'), $this->ilias->error_obj->MESSAGE);
4606  }
4607 
4608  if(!isset($_POST['thread_ids']) || !is_array($_POST['thread_ids']) || count($_POST['thread_ids']) != 2)
4609  {
4610  ilUtil::sendFailure($this->lng->txt('select_one'));
4611  $this->showThreadsObject();
4612  return;
4613  }
4614 
4615  if((int)$_POST['thread_ids'][0] == (int)$_POST['thread_ids'][1])
4616  {
4617  ilUtil::sendFailure($this->lng->txt('error_same_thread_ids'));
4618  $this->showThreadsObject();
4619  return;
4620  }
4621 
4622  try
4623  {
4624  ilForum::mergeThreads($this->object->id, (int)$_POST['thread_ids'][0], (int)$_POST['thread_ids'][1]);
4625  ilUtil::sendSuccess($this->lng->txt('merged_threads_successfully'));
4626  }
4627  catch(ilException $e)
4628  {
4629  return ilUtil::sendFailure($lng->txt($e->getMessage()));
4630  }
4631  $this->showThreadsObject();
4632  }
4633 
4637  public function cancelMergeThreads()
4638  {
4639  $this->showThreadsObject();
4640  }
4641 }
< a tabindex="-1" style="border-style: none;" href="#" title="Refresh Image" onclick="document.getElementById('siimage').src = './securimage_show.php?sid=' + Math.random(); this.blur(); return false">< img src="./images/refresh.png" alt="Reload Image" height="32" width="32" onclick="this.blur()" align="bottom" border="0"/></a >< br/>< strong > Enter Code *if($_SERVER['REQUEST_METHOD']=='POST' &&@ $_POST['do']=='contact') $_SESSION['ctform']['success']
Class ilForumStatisticsTableGUI.
static _getMediaObjects($a_text, $a_direction=0)
Returns all media objects found in the passed string.
static _getRTEClassname()
static sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
static _lookupName($a_user_id)
lookup user name
static _isModerator($a_ref_id, $a_usr_id)
checks whether a user is moderator of a given forum object
static prepareFormOutput($a_str, $a_strip=false)
prepares string output for html forms public
static _lookupDate($thread_id)
This class represents an option in a radio group.
ILIAS Setting Class.
_getModerators($a_ref_id)
get all users assigned to local role il_frm_moderator_<frm_ref_id> (static)
print $file
const SORT_TITLE
static _lookupObjIdForForumId($a_for_id)
Class Forum core functions for forum.
static getTreeNodeHtml($object, ilObjForumGUI $gui, $pageHits)
Returns the html used for a single forum tree node public.
exit
Definition: login.php:54
Class ilForumExplorer class for explorer view of forum posts.
Base class for ILIAS Exception handling.
setBlockProperty($a_block_type, $a_property, $a_value)
This function is supposed to be used for block type specific properties, that should be passed to ilB...
Class ilInfoScreenGUI.
$_POST['username']
Definition: cron.php:12
setDisplayConfirmPostActivation($status=0)
Class for permanent links.
static lookupForumIdByObjId($obj_id)
getTitlesByRefId($a_ref_ids)
get Titles of objects this method is used for error messages in methods cut/copy/paste ...
getInstanceByRefId($a_ref_id, $stop_on_error=true)
get an instance of an Ilias object by reference id
$result
Tabs GUI.
static mergeThreads($obj_id, $source_id, $target_id)
This class represents a property form user interface.
GUI class for the workflow of copying objects.
This class represents a captcha input in a property form.
getIcon($user_toggle_noti)
const TITLE_LENGTH
max length of object title
static getFirstNewsIdForContext($a_context_obj_id, $a_context_obj_type, $a_context_sub_obj_id="", $a_context_sub_obj_type="")
Get first new id of news set related to a certain context.
$_GET["client_id"]
Class ilObject Basic functions for all objects.
static Linkbar($AScript, $AHits, $ALimit, $AOffset, $AParams=array(), $ALayout=array(), $prefix='')
Linkbar Diese Funktion erzeugt einen typischen Navigationsbalken mit "Previous"- und "Next"-Links und...
initHeaderAction($a_sub_type=null, $a_sub_id=null)
Add header action menu.
Class ilObjForumListGUI.
This class represents a file wizard property in a property form.
$cmd
Definition: sahs_server.php:35
static _getInstanceByObjId($a_obj_id)
Get singleton instance.
getSubTabs($subtab='showThreads')
static get($a_var)
Get a value.
static set($a_var, $a_val)
Set a value.
infoScreenObject()
this one is called from the info button in the repository not very nice to set cmdClass/Cmd manually...
This class represents a checkbox property in a property form.
static _lookupTitle($a_id)
lookup object title
addItem($a_item)
Add Item (Property, SectionHeader).
createObject()
create new object form
afterSave(ilObject $a_new_object)
Post (successful) object creation hook.
Class ilForumNotification.
addTarget($a_text, $a_link, $a_cmd="", $a_cmdClass="", $a_frame="", $a_activate=false, $a_dir_text=false)
DEPRECATED.
getOwner()
get object owner
static addToDesktop()
Add desktop item public.
setInfo($a_info)
Set Info.
initForumCreateForm($object_type)
static _setRichTextEditorUserState($a_state)
Sets the state of the rich text editor visibility for the current user.
static _getAllReferences($a_id)
get all reference ids of object
_removeUsage($a_mob_id, $a_type, $a_id, $a_usage_hist_nr=0, $a_lang="-")
Remove usage of mob in another container.
Class ilForumTopicTableGUI.
static _lookupObjectId($a_ref_id)
lookup object id
global $ilCtrl
Definition: ilias.php:18
$mobs
setInfo($a_info)
Set Information Text.
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
getCenterColumnHTML()
Get center column.
updateCustom(ilPropertyFormGUI $a_form)
Insert custom update form values into object.
Export User Interface Class.
GUI class for public user profile presentation.
static getInstance($a_obj_id=0)
hideToolbar($a_flag=null)
_saveUsage($a_mob_id, $a_type, $a_id, $a_usage_hist_nr=0, $a_lang="-")
Save usage of mob within another container (e.g.
This class represents a property in a property form.
addOption($a_option)
Add Option.
static encode($mixed, $suppress_native=false)
Class ilTable2GUI.
& executeCommand()
execute command
getId()
get object id public
Class ilForumModeratorsGUI.
addSubItem($a_item)
Add Subitem.
Forum export to HTML and Print.
static _exists($a_id)
checks wether a lm content object with specified id exists or not
Column user interface class.
static getImagePath($img, $module_path="", $mode="output", $offline=false)
get image path (for images located in a template directory)
Class Mail this class handles base functions for mail handling.
getTabs(&$tabs_gui)
get tabs abstract method.
Class ilObjectGUI Basic methods of all Output classes.
static _lookupObjId($a_id)
Class ilObjForumGUI.
setRepositoryMode($a_repositorymode)
Set RepositoryMode.
setValue($a_value)
Set Value.
special template class to simplify handling of ITX/PEAR
setSize($a_size)
Set Size.
This class represents a text property in a property form.
static infoPanel($a_keep=true)
redirection script todo: (a better solution should control the processing via a xml file) ...
_lookupLogin($a_user_id)
lookup login
Class ilObjMediaObject.
setMaxLength($a_maxlength)
Set Max Length.
This class represents a property in a property form.
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
updateUserNotifications($update_all_users=false)
getInput($a_post_var, $ensureValidation=true)
Returns the value of a HTTP-POST variable, identified by the passed id.
static deliverFile($a_file, $a_filename, $a_mime='', $isInline=false, $removeAfterDelivery=false, $a_exit_after=true)
deliver file for download via browser.
static _getThreads($a_obj_id, $a_sort_mode=self::SORT_DATE)
Get thread infos of object.
prepareOutput()
prepare output
static _getInstanceByObjId($a_obj_id)
Get singleton instance.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
_getMobsOfObject($a_type, $a_id, $a_usage_hist_nr=0, $a_lang="-")
get mobs of object
getModifiedReOnSubject($on_reply=false)
static removeFromDesktop()
Remove item from personal desktop public.
static _replaceMediaObjectImageSrc($a_text, $a_direction=0)
replaces image source from mob image urls with the mob id or replaces mob id with the correct image s...
static _getInstanceByType($a_type)
Factory method for creating purifier instances.
getRightColumnHTML()
Display right column.
cancelObject($in_rep=false)
global $ilUser
Definition: imgupload.php:15
setColumnSettings($column_gui)
May be overwritten in subclasses.
This class represents a non editable value in a property form.
Interface for gui classes (e.g ilLuceneSearchGUI) that offer add/remove to/from desktop.
global $ilSetting
Definition: privfeed.php:40
setFilenames($a_filenames)
Set filenames.
static _getRichTextEditorUserState()
Gets the state of the rich text editor visibility for the current user.
$path
Definition: index.php:22
This class represents a text area property in a property form.
static switchColor($a_num, $a_css1, $a_css2)
switches style sheets for each even $a_num (used for changing colors of different result rows) ...
This class handles all operations on files for the forum object.
addToDeskObject()
Add desktop item public.
getCreationMode()
get creation mode
getRefId()
get reference id public
handleFormInput($a_text, $a_stripslashes=true)
New PermissionGUI (extends from old ilPermission2GUI) RBAC related output.
if($_REQUEST['ilias_path']) define('ILIAS_HTTP_PATH' $_REQUEST['ilias_path']
Definition: index.php:7
static _lookupTitle($a_topic_id)
Looks up the title/subject of a topic/thread.
Class ilObjForum.
getEditFormCustomValues(Array &$a_values)
static redirect($a_script)
http redirect to other script
addHeaderAction()
Add header action menu.
getThreadEditingForm($a_thread_id)
initEditCustomForm(ilPropertyFormGUI $a_form)
Add custom fields to update form.
setRequired($a_required)
Set Required.
static getInstanceFromAjaxCall()
(Re-)Build instance from ajax call
storeUploadedFile($files)
Store uploaded files in filesystem.
static formCheckbox($checked, $varname, $value, $disabled=false)
??? public
getUserNotificationTableData($user_ids, ilForumNotification $frm_noti)
static lookupForumIdByTopicId($a_topic_id)
addLocatorItems()
should be overwritten to add object specific items (repository items are preloaded) ...
Confirmation screen class.