Example #1
0
 public function addThreadObject($a_prevent_redirect = false)
 {
     /**
      * @var $ilUser ilObjUser
      * @var $ilAccess ilAccessHandler
      * @var $lng ilLanguage
      */
     global $ilUser, $ilAccess, $lng;
     $frm = $this->object->Forum;
     $frm->setForumId($this->object->getId());
     $frm->setForumRefId($this->object->getRefId());
     if (!$ilAccess->checkAccess('add_thread', '', $this->object->getRefId())) {
         $this->ilias->raiseError($lng->txt('permission_denied'), $this->ilias->error_obj->MESSAGE);
     }
     $frm->setMDB2WhereCondition('top_frm_fk = %s ', array('integer'), array($frm->getForumId()));
     $topicData = $frm->getOneTopic();
     $this->initTopicCreateForm();
     if ($this->create_topic_form_gui->checkInput()) {
         require_once 'Services/Captcha/classes/class.ilCaptchaUtil.php';
         if ($ilUser->isAnonymous() && !$ilUser->isCaptchaVerified() && ilCaptchaUtil::isActiveForForum()) {
             $ilUser->setCaptchaVerified(true);
         }
         if ($this->objProperties->isAnonymized()) {
             if (!strlen($this->create_topic_form_gui->getInput('alias'))) {
                 $user_alias = $this->lng->txt('forums_anonymous');
             } else {
                 $user_alias = $this->create_topic_form_gui->getInput('alias');
             }
         } else {
             $user_alias = $ilUser->getLogin();
         }
         $status = 1;
         if ($this->objProperties->isPostActivationEnabled() && !$this->is_moderator || $this->objCurrentPost->isAnyParentDeactivated()) {
             $status = 0;
         }
         // build new thread
         $newPost = $frm->generateThread($topicData['top_pk'], $ilUser->getId(), $this->objProperties->isAnonymized() ? 0 : $ilUser->getId(), $this->handleFormInput($this->create_topic_form_gui->getInput('subject'), false), ilRTE::_replaceMediaObjectImageSrc($this->create_topic_form_gui->getInput('message'), 0), $this->create_topic_form_gui->getItemByPostVar('notify') ? (int) $this->create_topic_form_gui->getInput('notify') : 0, $this->create_topic_form_gui->getItemByPostVar('notify_posts') ? (int) $this->create_topic_form_gui->getInput('notify_posts') : 0, $user_alias, '', $status);
         $file = $_FILES['userfile'];
         // file upload
         if (is_array($file) && !empty($file)) {
             $tmp_file_obj = new ilFileDataForum($this->object->getId(), $newPost);
             $tmp_file_obj->storeUploadedFile($file);
         }
         // Visit-Counter
         $frm->setDbTable('frm_data');
         $frm->setMDB2WhereCondition('top_pk = %s ', array('integer'), array($topicData['top_pk']));
         $frm->updateVisits($topicData['top_pk']);
         $frm->setMDB2WhereCondition('thr_top_fk = %s AND thr_subject = %s AND thr_num_posts = 1 ', array('integer', 'text'), array($topicData['top_pk'], $this->create_topic_form_gui->getInput('subject')));
         // copy temporary media objects (frm~)
         include_once 'Services/MediaObjects/classes/class.ilObjMediaObject.php';
         $mediaObjects = ilRTE::_getMediaObjects($this->create_topic_form_gui->getInput('message'), 0);
         foreach ($mediaObjects as $mob) {
             if (ilObjMediaObject::_exists($mob)) {
                 ilObjMediaObject::_removeUsage($mob, 'frm~:html', $ilUser->getId());
                 ilObjMediaObject::_saveUsage($mob, 'frm:html', $newPost);
             }
         }
         if ($this->ilias->getSetting('forum_notification') == 1) {
             // send notification about new topic
             $objPost = new ilForumPost((int) $newPost, $this->is_moderator);
             $post_data = array();
             $post_data = $objPost->getDataAsArray();
             $titles = $this->getTitlesByRefId(array($this->object->getRefId()));
             $post_data["top_name"] = $titles[0];
             $post_data["ref_id"] = $this->object->getRefId();
             $frm->sendForumNotifications($post_data);
         }
         if (!$a_prevent_redirect) {
             ilUtil::sendSuccess($this->lng->txt('forums_thread_new_entry'), true);
             $this->ctrl->redirect($this);
         } else {
             return $newPost;
         }
     } else {
         $this->create_topic_form_gui->setValuesByPost();
         if (!$this->objProperties->isAnonymized()) {
             $this->create_topic_form_gui->getItemByPostVar('alias')->setValue($ilUser->getLogin());
         }
         return $this->tpl->setContent($this->create_topic_form_gui->getHTML());
     }
 }