/**
  * Handle an event in a listener.
  *
  * @param	string	$a_component	component, e.g. "Modules/Forum" or "Services/User"
  * @param	string	$a_event		event e.g. "createUser", "updateUser", "deleteUser", ...
  * @param	array	$a_parameter	parameter array (assoc), array("name" => ..., "phone_office" => ...)
  */
 static function handleEvent($a_component, $a_event, $a_parameter)
 {
     switch ($a_component) {
         case "Services/News":
             switch ($a_event) {
                 case "readNews":
                     // here we could set postings to read, if news is
                     // read (has to be implemented)
                     break;
             }
             break;
         case "Services/Tree":
             switch ($a_event) {
                 case "moveTree":
                     include_once './Modules/Forum/classes/class.ilForumNotification.php';
                     ilForumNotification::_clearForcedForumNotifications($a_parameter);
                     break;
             }
             break;
     }
 }
 /**
  * @see ilMembershipRegistrationCodes::register()
  * @param int user_id
  * @param int role
  * @param bool force registration and do not check registration constraints.
  */
 public function register($a_user_id, $a_role = ilCourseConstants::CRS_MEMBER, $a_force_registration = false)
 {
     global $ilCtrl, $tree;
     include_once './Services/Membership/exceptions/class.ilMembershipRegistrationException.php';
     include_once "./Modules/Course/classes/class.ilCourseParticipants.php";
     $part = ilCourseParticipants::_getInstanceByObjId($this->getId());
     if ($part->isAssigned($a_user_id)) {
         return true;
     }
     if (!$a_force_registration) {
         // Availability
         if ($this->getSubscriptionLimitationType() == IL_CRS_SUBSCRIPTION_DEACTIVATED) {
             include_once './Modules/Group/classes/class.ilObjGroupAccess.php';
             if (!ilObjCourseAccess::_usingRegistrationCode()) {
                 throw new ilMembershipRegistrationException('Cant registrate to course ' . $this->getId() . ', course subscription is deactivated.', '456');
             }
         }
         // Time Limitation
         if ($this->getSubscriptionLimitationType() == IL_CRS_SUBSCRIPTION_LIMITED) {
             if (!$this->inSubscriptionTime()) {
                 throw new ilMembershipRegistrationException('Cant registrate to course ' . $this->getId() . ', course is out of registration time.', '789');
             }
         }
         // Max members
         if ($this->isSubscriptionMembershipLimited()) {
             $free = max(0, $this->getSubscriptionMaxMembers() - $part->getCountMembers());
             include_once './Modules/Course/classes/class.ilCourseWaitingList.php';
             $waiting_list = new ilCourseWaitingList($this->getId());
             if ($this->enabledWaitingList() and (!$free or $waiting_list->getCountUsers())) {
                 $waiting_list->addToList($a_user_id);
                 $this->lng->loadLanguageModule("crs");
                 $info = sprintf($this->lng->txt('crs_added_to_list'), $waiting_list->getPosition($a_user_id));
                 include_once './Modules/Course/classes/class.ilCourseParticipants.php';
                 $participants = ilCourseParticipants::_getInstanceByObjId($this->getId());
                 $participants->sendNotification($participants->NOTIFY_WAITING_LIST, $a_user_id);
                 throw new ilMembershipRegistrationException($info, '124');
             }
             if (!$this->enabledWaitingList() && !$free) {
                 throw new ilMembershipRegistrationException('Cant registrate to course ' . $this->getId() . ', membership is limited.', '123');
             }
         }
     }
     $part->add($a_user_id, $a_role);
     $part->sendNotification($part->NOTIFY_ACCEPT_USER, $a_user_id);
     $part->sendNotification($part->NOTIFY_ADMINS, $a_user_id);
     include_once './Modules/Forum/classes/class.ilForumNotification.php';
     ilForumNotification::checkForumsExistsInsert($this->getRefId(), $a_user_id);
     return true;
 }
 public function confirmedUnsubscribe()
 {
     global $ilCtrl, $ilAccess, $ilUser;
     if (!sizeof($_POST["ref_id"])) {
         $ilCtrl->redirect($this, "manage");
     }
     foreach ($_POST["ref_id"] as $ref_id) {
         if ($ilAccess->checkAccess("leave", "", $ref_id)) {
             switch (ilObject::_lookupType($ref_id, true)) {
                 case "crs":
                     // see ilObjCourseGUI:performUnsubscribeObject()
                     include_once "Modules/Course/classes/class.ilCourseParticipants.php";
                     $members = new ilCourseParticipants(ilObject::_lookupObjId($ref_id));
                     $members->delete($ilUser->getId());
                     $members->sendUnsubscribeNotificationToAdmins($ilUser->getId());
                     $members->sendNotification($members->NOTIFY_UNSUBSCRIBE, $ilUser->getId());
                     break;
                 case "grp":
                     // see ilObjGroupGUI:performUnsubscribeObject()
                     include_once "Modules/Group/classes/class.ilGroupParticipants.php";
                     $members = new ilGroupParticipants(ilObject::_lookupObjId($ref_id));
                     $members->delete($ilUser->getId());
                     include_once './Modules/Group/classes/class.ilGroupMembershipMailNotification.php';
                     $members->sendNotification(ilGroupMembershipMailNotification::TYPE_UNSUBSCRIBE_MEMBER, $ilUser->getId());
                     $members->sendNotification(ilGroupMembershipMailNotification::TYPE_NOTIFICATION_UNSUBSCRIBE, $ilUser->getId());
                     break;
                 default:
                     // do nothing
                     continue;
             }
             include_once './Modules/Forum/classes/class.ilForumNotification.php';
             ilForumNotification::checkForumsExistsDelete($ref_id, $ilUser->getId());
         }
     }
     ilUtil::sendSuccess($this->lng->txt("settings_saved"), true);
     $ilCtrl->redirectByClass("ilpersonaldesktopgui", "show");
 }
 public static function checkForumsExistsDelete($ref_id, $user_id = 0)
 {
     global $ilUser;
     $node_data = self::getCachedNodeData($ref_id);
     include_once 'Modules/Forum/classes/class.ilForumModerators.php';
     foreach ($node_data as $data) {
         //check frm_properties if frm_noti is enabled
         $frm_noti = new ilForumNotification($data['ref_id']);
         $objFrmMods = new ilForumModerators($data['ref_id']);
         $moderator_ids = $objFrmMods->getCurrentModerators();
         if ($user_id != 0) {
             $frm_noti->setUserId($user_id);
         } else {
             $frm_noti->setUserId($ilUser->getId());
         }
         $frm_noti->setForumId($data['obj_id']);
         if (!in_array($frm_noti->getUserId(), $moderator_ids)) {
             $frm_noti->deleteAdminForce();
         }
     }
 }
 /**
  * Handle an event in a listener.
  *
  * @param	string	$a_component	component, e.g. "Modules/Forum" or "Services/User"
  * @param	string	$a_event		event e.g. "createUser", "updateUser", "deleteUser", ...
  * @param	array	$a_parameter	parameter array (assoc), array("name" => ..., "phone_office" => ...)
  */
 static function handleEvent($a_component, $a_event, $a_parameter)
 {
     switch ($a_component) {
         case "Services/News":
             switch ($a_event) {
                 case "readNews":
                     // here we could set postings to read, if news is
                     // read (has to be implemented)
                     break;
             }
             break;
         case "Services/Tree":
             switch ($a_event) {
                 case "moveTree":
                     include_once './Modules/Forum/classes/class.ilForumNotification.php';
                     ilForumNotification::_clearForcedForumNotifications($a_parameter);
                     break;
             }
             break;
         case "Modules/Course":
             switch ($a_event) {
                 case "addParticipant":
                     include_once './Modules/Forum/classes/class.ilForumNotification.php';
                     $ref_ids = self::getCachedReferences($a_parameter['obj_id']);
                     foreach ($ref_ids as $ref_id) {
                         ilForumNotification::checkForumsExistsInsert($ref_id, $a_parameter['usr_id']);
                         break;
                     }
                     break;
                 case 'deleteParticipant':
                     include_once './Modules/Forum/classes/class.ilForumNotification.php';
                     $ref_ids = self::getCachedReferences($a_parameter['obj_id']);
                     foreach ($ref_ids as $ref_id) {
                         ilForumNotification::checkForumsExistsDelete($ref_id, $a_parameter['usr_id']);
                         break;
                     }
                     break;
             }
             break;
         case "Modules/Group":
             switch ($a_event) {
                 case "addParticipant":
                     include_once './Modules/Forum/classes/class.ilForumNotification.php';
                     $ref_ids = self::getCachedReferences($a_parameter['obj_id']);
                     foreach ($ref_ids as $ref_id) {
                         ilForumNotification::checkForumsExistsInsert($ref_id, $a_parameter['usr_id']);
                         break;
                     }
                     break;
                 case 'deleteParticipant':
                     include_once './Modules/Forum/classes/class.ilForumNotification.php';
                     $ref_ids = self::getCachedReferences($a_parameter['obj_id']);
                     foreach ($ref_ids as $ref_id) {
                         ilForumNotification::checkForumsExistsDelete($ref_id, $a_parameter['usr_id']);
                         break;
                     }
                     break;
             }
             break;
     }
 }
 /**
  * @see ilMembershipRegistrationCodes::register()
  * @param int user_id
  * @param int role
  * @param bool force registration and do not check registration constraints.
  */
 public function register($a_user_id, $a_role = ilCourseConstants::CRS_MEMBER, $a_force_registration = false)
 {
     include_once './Services/Membership/exceptions/class.ilMembershipRegistrationException.php';
     include_once "./Modules/Course/classes/class.ilCourseParticipants.php";
     $part = ilCourseParticipants::_getInstanceByObjId($this->getId());
     if ($part->isAssigned($a_user_id)) {
         return true;
     }
     if (!$a_force_registration) {
         // Availability
         if (!self::_registrationEnabled($this->getId())) {
             $this->lng->loadLanguageModule('crs');
             throw new ilMembershipRegistrationException($this->lng->txt('crs_info_reg_deactivated'), $this->getRefId());
         }
         // Max members
         if ($this->isSubscriptionMembershipLimited()) {
             $free = max(0, $this->getSubscriptionMaxMembers() - $part->getCountMembers());
             include_once './Modules/Course/classes/class.ilCourseWaitingList.php';
             $waiting_list = new ilCourseWaitingList($this->getId());
             if ($this->enabledWaitingList() and (!$free or $waiting_list->getCountUsers())) {
                 throw new ilMembershipRegistrationException('', $this->getRefId());
             }
         }
     }
     $part->add($a_user_id, $a_role);
     $part->sendNotification($part->NOTIFY_ACCEPT_USER, $a_user_id);
     include_once './Modules/Forum/classes/class.ilForumNotification.php';
     ilForumNotification::checkForumsExistsInsert($this->getRefId(), $a_user_id);
     return true;
 }
 public function isUserAllowedToDeactivateNotification()
 {
     if ($this->objProperties->getNotificationType() == 'default') {
         return true;
     }
     if ($this->objProperties->isUserToggleNoti() == 0) {
         return true;
     }
     if ($this->isParentObjectCrsOrGrp()) {
     }
     global $ilUser;
     include_once 'Modules/Forum/classes/class.ilForumNotification.php';
     $frm_noti = new ilForumNotification((int) $_GET['ref_id']);
     $frm_noti->setUserId($ilUser->getId());
     $user_toggle = (int) $frm_noti->isUserToggleNotification();
     if ($user_toggle == 0) {
         return true;
     }
     return false;
 }
 /**
  * add user 
  *
  * @access protected
  * @param
  * @return
  */
 protected function add()
 {
     global $ilUser, $tree, $ilCtrl;
     // TODO: language vars
     // set aggreement accepted
     $this->setAccepted(true);
     include_once './Modules/Course/classes/class.ilCourseWaitingList.php';
     $free = max(0, $this->container->getSubscriptionMaxMembers() - $this->participants->getCountMembers());
     $waiting_list = new ilCourseWaitingList($this->container->getId());
     if ($this->container->isSubscriptionMembershipLimited() and $this->container->enabledWaitingList() and (!$free or $waiting_list->getCountUsers())) {
         $waiting_list->addToList($ilUser->getId());
         $info = sprintf($this->lng->txt('crs_added_to_list'), $waiting_list->getPosition($ilUser->getId()));
         ilUtil::sendSuccess($info, true);
         $this->participants->sendNotification($this->participants->NOTIFY_SUBSCRIPTION_REQUEST, $ilUser->getId());
         $this->participants->sendNotification($this->participants->NOTIFY_WAITING_LIST, $ilUser->getId());
         $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id", $tree->getParentId($this->container->getRefId()));
         $ilCtrl->redirectByClass("ilrepositorygui", "");
     }
     switch ($this->container->getSubscriptionType()) {
         case IL_CRS_SUBSCRIPTION_CONFIRMATION:
             $this->participants->addSubscriber($ilUser->getId());
             $this->participants->updateSubscriptionTime($ilUser->getId(), time());
             $this->participants->updateSubject($ilUser->getId(), ilUtil::stripSlashes($_POST['subject']));
             $this->participants->sendNotification($this->participants->NOTIFY_SUBSCRIPTION_REQUEST, $ilUser->getId());
             ilUtil::sendSuccess($this->lng->txt("application_completed"), true);
             $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id", $tree->getParentId($this->container->getRefId()));
             $ilCtrl->redirectByClass("ilrepositorygui", "");
             break;
         default:
             $this->participants->add($ilUser->getId(), IL_CRS_MEMBER);
             $this->participants->sendNotification($this->participants->NOTIFY_ADMINS, $ilUser->getId());
             $this->participants->sendNotification($this->participants->NOTIFY_REGISTERED, $ilUser->getId());
             include_once './Modules/Forum/classes/class.ilForumNotification.php';
             ilForumNotification::checkForumsExistsInsert($this->container->getRefId(), $ilUser->getId());
             if ($this->container->getType() == "crs") {
                 $this->container->checkLPStatusSync($ilUser->getId());
             }
             if (!$_SESSION["pending_goto"]) {
                 ilUtil::sendSuccess($this->lng->txt("crs_subscription_successful"), true);
                 $this->ctrl->returnToParent($this);
             } else {
                 $tgt = $_SESSION["pending_goto"];
                 unset($_SESSION["pending_goto"]);
                 ilUtil::redirect($tgt);
             }
             break;
     }
 }
 public static function checkForumsExistsDelete($ref_id, $user_id = 0)
 {
     global $tree, $ilUser;
     $node_data = $tree->getChildsByType($ref_id, 'frm');
     foreach ($node_data as $data) {
         //check frm_properties if frm_noti is enabled
         $frm_noti = new ilForumNotification($data['ref_id']);
         if ($user_id != 0) {
             $frm_noti->setUserId($user_id);
         } else {
             $frm_noti->setUserId($ilUser->getId());
         }
         $frm_noti->setForumId($data['obj_id']);
         $frm_noti->deleteAdminForce();
     }
 }
 protected function initHeaderAction($a_sub_type = null, $a_sub_id = null)
 {
     /**
      * @var $ilUser ilObjUser
      */
     global $ilUser;
     $lg = parent::initHeaderAction();
     // Workaround: Do not show "desktop actions" in thread view
     if ($this->objCurrentTopic->getId()) {
         $container_obj = null;
         $lg->setContainerObject($container_obj);
     }
     if ($lg instanceof ilObjForumListGUI) {
         include_once 'Modules/Forum/classes/class.ilForumNotification.php';
         $frm_noti = new ilForumNotification((int) $_GET['ref_id']);
         $frm_noti->setUserId($ilUser->getId());
         $user_toggle = $frm_noti->isUserToggleNotification();
         // Notification button
         $notificiation_enabled = false;
         if ($ilUser->getId() != ANONYMOUS_USER_ID && $this->ilias->getSetting('forum_notification') != 0 && $user_toggle != 1) {
             $frm = $this->object->Forum;
             $frm->setForumId($this->object->getId());
             $frm->setForumRefId($this->object->getRefId());
             $frm->setMDB2Wherecondition('top_frm_fk = %s ', array('integer'), array($frm->getForumId()));
             if ($this->objCurrentTopic->getId()) {
                 $this->ctrl->setParameter($this, 'thr_pk', $this->objCurrentTopic->getId());
             }
             if ($frm->isForumNotificationEnabled($ilUser->getId())) {
                 $lg->addCustomCommand($this->ctrl->getLinkTarget($this, 'disableForumNotification'), "forums_disable_forum_notification");
                 $notificiation_enabled = true;
             } else {
                 $lg->addCustomCommand($this->ctrl->getLinkTarget($this, 'enableForumNotification'), "forums_enable_forum_notification");
             }
             if ($this->objCurrentTopic->getId()) {
                 if ($this->objCurrentTopic->isNotificationEnabled($ilUser->getId())) {
                     $lg->addCustomCommand($this->ctrl->getLinkTarget($this, 'toggleThreadNotification'), "forums_disable_notification");
                     $notificiation_enabled = true;
                 } else {
                     $lg->addCustomCommand($this->ctrl->getLinkTarget($this, 'toggleThreadNotification'), "forums_enable_notification");
                 }
             }
             $this->ctrl->setParameter($this, 'thr_pk', '');
             if ($notificiation_enabled) {
                 $lg->addHeaderIcon("not_icon", ilUtil::getImagePath("notification_on.png"), $this->lng->txt("frm_notification_activated"));
             } else {
                 $lg->addHeaderIcon("not_icon", ilUtil::getImagePath("notification_off.png"), $this->lng->txt("frm_notification_deactivated"));
             }
         }
     }
     return $lg;
 }
 /**
  * displays confirmation formular with users that shall be assigned to group
  * @access public
  */
 function addUserObject($user_ids, $a_type)
 {
     include_once 'Services/Mail/classes/class.ilMail.php';
     $mail = new ilMail($_SESSION["AccountId"]);
     if (empty($user_ids[0])) {
         $GLOBALS['lng']->loadLanguageModule('search');
         ilUtil::sendFailure($this->lng->txt('search_err_user_not_exist'), true);
         return false;
     }
     foreach ($user_ids as $new_member) {
         switch ($a_type) {
             case ilObjGroup::GRP_MEMBER:
                 if (!$this->object->addMember($new_member, $this->object->getDefaultMemberRole())) {
                     $this->ilErr->raiseError("An Error occured while assigning user to group !", $this->ilErr->MESSAGE);
                 }
                 break;
             case ilObjGroup::GRP_ADMIN:
                 if (!$this->object->addMember($new_member, $this->object->getDefaultAdminRole())) {
                     $this->ilErr->raiseError("An Error occured while assigning user to group !", $this->ilErr->MESSAGE);
                 }
                 break;
         }
         ilObjUser::_addDesktopItem($new_member, $this->object->getRefId(), 'grp');
         include_once './Modules/Group/classes/class.ilGroupMembershipMailNotification.php';
         $this->object->members_obj->sendNotification(ilGroupMembershipMailNotification::TYPE_ADMISSION_MEMBER, $new_member);
         include_once './Modules/Forum/classes/class.ilForumNotification.php';
         ilForumNotification::checkForumsExistsInsert($this->object->getRefId(), $new_member);
     }
     unset($_SESSION["saved_post"]);
     unset($_SESSION['grp_usr_search_result']);
     ilUtil::sendSuccess($this->lng->txt("grp_msg_member_assigned"), true);
     $this->ctrl->redirect($this, 'members');
 }
 /**
  *
  */
 public function detachModeratorRole()
 {
     if (!isset($_POST['usr_id']) || !is_array($_POST['usr_id'])) {
         ilUtil::sendFailure($this->lng->txt('frm_moderators_select_at_least_one'));
         return $this->showModerators();
     }
     $entries = $this->oForumModerators->getCurrentModerators();
     if (count($_POST['usr_id']) == count($entries)) {
         ilUtil::sendFailure($this->lng->txt('frm_at_least_one_moderator'));
         return $this->showModerators();
     }
     include_once "Modules/Forum/classes/class.ilForumNotification.php";
     $isCrsGrp = ilForumNotification::_isParentNodeGrpCrs($this->ref_id);
     if ($isCrsGrp) {
         global $tree;
         $parent_ref_id = $tree->getParentId($this->ref_id);
         include_once "Services/Membership/classes/class.ilParticipants.php";
     }
     include_once "Modules/Forum/classes/class.ilForumProperties.php";
     $objFrmProps = ilForumProperties::getInstance(ilObject::_lookupObjId($this->ref_id));
     $frm_noti_type = $objFrmProps->getNotificationType();
     foreach ($_POST['usr_id'] as $usr_id) {
         $this->oForumModerators->detachModeratorRole((int) $usr_id);
         if ($isCrsGrp && $frm_noti_type != 'default') {
             if (!ilParticipants::_isParticipant($this->ref_id, $usr_id)) {
                 $tmp_frm_noti = new ilForumNotification($this->ref_id);
                 $tmp_frm_noti->setUserId((int) $usr_id);
                 $tmp_frm_noti->setForumId(ilObject::_lookupObjId($this->ref_id));
                 $tmp_frm_noti->deleteAdminForce();
             }
         }
     }
     ilUtil::sendSuccess($this->lng->txt('frm_moderators_detached_role_successfully'), true);
     $this->ctrl->redirect($this, 'showModerators');
 }
 function add()
 {
     global $ilErr, $ilObjDataCache, $lng, $ilAccess;
     if (sizeof($_POST["usrs"])) {
         if (!$ilAccess->checkAccess("write", "", $_POST["grp_id"])) {
             ilUtil::sendFailure($lng->txt("permission_denied"), true);
             $this->show();
             return;
         }
         include_once './Modules/Group/classes/class.ilGroupParticipants.php';
         $members_obj = ilGroupParticipants::_getInstanceByObjId($ilObjDataCache->lookupObjId($_POST["grp_id"]));
         foreach ($_POST["usrs"] as $new_member) {
             if (!$members_obj->add($new_member, IL_GRP_MEMBER)) {
                 $ilErr->raiseError("An Error occured while assigning user to group !", $ilErr->MESSAGE);
             }
             include_once './Modules/Group/classes/class.ilGroupMembershipMailNotification.php';
             $members_obj->sendNotification(ilGroupMembershipMailNotification::TYPE_ADMISSION_MEMBER, $new_member);
             include_once './Modules/Forum/classes/class.ilForumNotification.php';
             ilForumNotification::checkForumsExistsInsert($this->ref_id, $new_member);
         }
         ilUtil::sendSuccess($lng->txt("grp_msg_member_assigned"));
     }
     $this->show();
 }
 /**
  * Remove members
  * @global ilRbacReview $rbacreview
  * @global ilRbacSystem $rbacsystem
  * @return boolean
  */
 protected function removeMembersObject()
 {
     global $rbacreview, $rbacsystem, $ilAccess, $ilUser;
     $this->checkPermission('write');
     if (!is_array($_POST["participants"]) or !count($_POST["participants"])) {
         ilUtil::sendFailure($this->lng->txt("crs_no_member_selected"));
         $this->membersObject();
         return false;
     }
     // If the user doesn't have the edit_permission and is not administrator, he may not remove
     // members who have the course administrator role
     if (!$ilAccess->checkAccess('edit_permission', '', $this->object->getRefId()) and !ilCourseParticipants::_getInstanceByObjId($this->object->getId())->isAdmin($ilUser->getId())) {
         // Determine the role id of the course administrator role.
         $courseAdminRoleId = null;
         foreach ($this->object->getLocalCourseRoles(false) as $title => $role_id) {
             if (substr($title, 0, 12) == 'il_crs_admin') {
                 $courseAdminRoleId = $role_id;
             }
         }
         foreach ($_POST['participants'] as $usr_id) {
             if ($rbacreview->isAssigned($usr_id, $courseAdminRoleId)) {
                 ilUtil::sendFailure($this->lng->txt("msg_no_perm_perm"));
                 $this->membersObject();
                 return false;
             }
         }
     }
     if (!$this->object->getMembersObject()->deleteParticipants($_POST["participants"])) {
         ilUtil::sendFailure($this->object->getMessage());
         $this->membersObject();
         return false;
     } else {
         include_once './Modules/Forum/classes/class.ilForumNotification.php';
         // SEND NOTIFICATION
         foreach ($_POST["participants"] as $usr_id) {
             $this->object->getMembersObject()->sendNotification($this->object->getMembersObject()->NOTIFY_DISMISS_MEMBER, $usr_id);
             ilForumNotification::checkForumsExistsDelete($this->object->getRefId(), $usr_id);
         }
     }
     ilUtil::sendSuccess($this->lng->txt("crs_members_deleted"));
     $this->membersObject();
     return true;
 }
Exemple #15
0
 /**
  * @param $obj_id
  * @param $source_id
  * @param $target_id
  * @throws ilException
  */
 public static function mergeThreads($obj_id, $source_id, $target_id)
 {
     // selected source & target objects
     $source_thread_obj = new ilForumTopic((int) $source_id);
     $target_thread_obj = new ilForumTopic((int) $target_id);
     if ($source_thread_obj->getForumId() != $target_thread_obj->getForumId()) {
         throw new ilException('not_allowed_to_merge_into_another_forum');
     }
     // use the "older" thread as target
     if ($source_thread_obj->getCreateDate() > $target_thread_obj->getCreateDate()) {
         $merge_thread_source = $source_thread_obj;
         $merge_thread_target = $target_thread_obj;
     } else {
         $merge_thread_source = $target_thread_obj;
         $merge_thread_target = $source_thread_obj;
     }
     $thread_subject = $target_thread_obj->getSubject();
     // remember if the threads are open or closed and then close both threads !
     $targed_was_closed = $merge_thread_target->isClosed();
     $merge_thread_source->close();
     if ($targed_was_closed == false) {
         $merge_thread_target->close();
     }
     $source_all_posts = $merge_thread_source->getAllPosts();
     $source_root_node = $merge_thread_source->getFirstPostNode();
     $target_root_node = $merge_thread_target->getFirstPostNode();
     $add_difference = $target_root_node->getRgt();
     // update target root node rgt
     include_once 'Modules/Forum/classes/class.ilForumPostsTree.php';
     //		$new_target_rgt = ($target_root_node->getRgt() + $source_root_node->getRgt() + 1);
     $new_target_rgt = $target_root_node->getRgt() + $source_root_node->getRgt();
     ilForumPostsTree::updateTargetRootRgt($target_root_node->getId(), $new_target_rgt);
     $new_target_root = $target_root_node->getId();
     // get source post tree and update posts tree
     foreach ($source_all_posts as $post) {
         $post_obj = new ilForumPost($post->pos_pk);
         $posts_tree_obj = new ilForumPostsTree();
         $posts_tree_obj->setPosFk($post->pos_pk);
         if ($post_obj->getParentId() == 0) {
             $posts_tree_obj->setParentPos($new_target_root);
             //$posts_tree_obj->setRgt(($post_obj->getRgt() + $add_difference));
             $posts_tree_obj->setRgt($post_obj->getRgt() + $add_difference - 1);
             $posts_tree_obj->setLft($target_root_node->getRgt());
             $posts_tree_obj->setDepth($post_obj->getDepth() + 1);
             $posts_tree_obj->setSourceThreadId($merge_thread_source->getId());
             $posts_tree_obj->setTargetThreadId($merge_thread_target->getId());
             $posts_tree_obj->mergeParentPos();
         } else {
             $posts_tree_obj->setRgt($post_obj->getRgt() + $add_difference - 1);
             $posts_tree_obj->setLft($post_obj->getLft() + $add_difference - 1);
             $posts_tree_obj->setDepth($post_obj->getDepth() + 1);
             $posts_tree_obj->setSourceThreadId($merge_thread_source->getId());
             $posts_tree_obj->setParentPos($post_obj->getParentId());
             $posts_tree_obj->setTargetThreadId($merge_thread_target->getId());
             $posts_tree_obj->merge();
         }
     }
     // update frm_posts pos_thr_fk = target_thr_id
     include_once 'Modules/Forum/classes/class.ilForumPost.php';
     ilForumPost::mergePosts($merge_thread_source->getId(), $merge_thread_target->getId());
     // check notifications
     include_once 'Modules/Forum/classes/class.ilForumNotification.php';
     ilForumNotification::mergeThreadNotificiations($merge_thread_source->getId(), $merge_thread_target->getId());
     // delete frm_thread_access entries
     include_once './Modules/Forum/classes/class.ilObjForum.php';
     ilObjForum::_deleteAccessEntries($merge_thread_source->getId());
     // update frm_user_read
     ilObjForum::mergeForumUserRead($merge_thread_source->getId(), $merge_thread_target->getId());
     // update visits, thr_num_posts, last_post, subject
     $post_date_source = $merge_thread_source->getLastPost()->getCreateDate();
     $post_date_target = $merge_thread_target->getLastPost()->getCreateDate();
     $target_last_post = $merge_thread_target->getLastPostString();
     $exp = explode('#', $target_last_post);
     if ($post_date_source > $post_date_target) {
         $exp[2] = $merge_thread_source->getLastPost()->getId();
     } else {
         $exp[2] = $merge_thread_target->getLastPost()->getId();
     }
     $new_thr_last_post = implode('#', $exp);
     $num_posts_source = (int) $merge_thread_source->getNumPosts();
     $num_visits_source = (int) $merge_thread_source->getVisits();
     $num_posts_target = (int) $merge_thread_target->getNumPosts();
     $num_visits_target = (int) $merge_thread_source->getVisits();
     $frm_topic_obj = new ilForumTopic(0, false, true);
     $frm_topic_obj->setNumPosts($num_posts_source + $num_posts_target);
     $frm_topic_obj->setVisits($num_visits_source + $num_visits_target);
     $frm_topic_obj->setLastPostString($new_thr_last_post);
     $frm_topic_obj->setSubject($thread_subject);
     $frm_topic_obj->setId($merge_thread_target->getId());
     $frm_topic_obj->updateMergedThread();
     // update frm_data:  top_last_post , top_num_threads
     ilForum::updateLastPostByObjId($obj_id);
     // reopen target if was not "closed" before merging
     if (!$targed_was_closed) {
         $merge_thread_target->reopen();
     }
     // delete source thread
     ilForumTopic::deleteByThreadId($merge_thread_source->getId());
 }
 /**
  * add user 
  *
  * @access protected
  * @param
  * @return
  */
 protected function add()
 {
     global $ilUser, $tree, $rbacreview, $lng, $ilCtrl;
     // set aggreement accepted
     $this->setAccepted(true);
     include_once './Modules/Group/classes/class.ilGroupWaitingList.php';
     $free = max(0, $this->container->getMaxMembers() - $this->participants->getCountMembers());
     $waiting_list = new ilGroupWaitingList($this->container->getId());
     if ($this->container->isMembershipLimited() and $this->container->isWaitingListEnabled() and (!$free or $waiting_list->getCountUsers())) {
         $waiting_list->addToList($ilUser->getId());
         $info = sprintf($this->lng->txt('grp_added_to_list'), $this->container->getTitle(), $waiting_list->getPosition($ilUser->getId()));
         $this->participants->sendNotification(ilGroupMembershipMailNotification::TYPE_WAITING_LIST_MEMBER, $ilUser->getId());
         ilUtil::sendSuccess($info, true);
         $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id", $tree->getParentId($this->container->getRefId()));
         $ilCtrl->redirectByClass("ilrepositorygui", "");
     }
     switch ($this->container->getRegistrationType()) {
         case GRP_REGISTRATION_REQUEST:
             $this->participants->addSubscriber($ilUser->getId());
             $this->participants->updateSubscriptionTime($ilUser->getId(), time());
             $this->participants->updateSubject($ilUser->getId(), ilUtil::stripSlashes($_POST['subject']));
             $this->participants->sendNotification(ilGroupMembershipMailNotification::TYPE_NOTIFICATION_REGISTRATION_REQUEST, $ilUser->getId());
             ilUtil::sendSuccess($this->lng->txt("application_completed"), true);
             $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id", $tree->getParentId($this->container->getRefId()));
             $ilCtrl->redirectByClass("ilrepositorygui", "");
             break;
         default:
             $this->participants->add($ilUser->getId(), IL_GRP_MEMBER);
             $this->participants->sendNotification(ilGroupMembershipMailNotification::TYPE_NOTIFICATION_REGISTRATION, $ilUser->getId());
             $this->participants->sendNotification(ilGroupMembershipMailNotification::TYPE_SUBSCRIBE_MEMBER, $ilUser->getId());
             include_once './Modules/Forum/classes/class.ilForumNotification.php';
             ilForumNotification::checkForumsExistsInsert($this->container->getRefId(), $ilUser->getId());
             if (!$_SESSION["pending_goto"]) {
                 ilUtil::sendSuccess($this->lng->txt("grp_registration_completed"), true);
                 $this->ctrl->returnToParent($this);
             } else {
                 $tgt = $_SESSION["pending_goto"];
                 unset($_SESSION["pending_goto"]);
                 ilUtil::redirect($tgt);
             }
             break;
     }
 }