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