Пример #1
0
    /**
     * Returns the number of bytes used on the harddisk by the specified forum
     * @static
     * @param int $a_obj_id
     * @return int
     */
    public static function _lookupDiskUsage($a_obj_id)
    {
        /**
         * @var $ilDB ilDB
         */
        global $ilDB;
        require_once 'Modules/Forum/classes/class.ilFileDataForum.php';
        $res = $ilDB->queryf('SELECT top_frm_fk, pos_pk FROM frm_posts p
			JOIN frm_data d ON d.top_pk = p.pos_top_fk
			WHERE top_frm_fk = %s', array('integer'), array($a_obj_id));
        $size = 0;
        while ($row = $ilDB->fetchAssoc($res)) {
            $fileDataForum = new ilFileDataForum($row['top_frm_fk'], $row['pos_pk']);
            $filesOfPost = $fileDataForum->getFilesOfPost();
            foreach ($filesOfPost as $attachment) {
                $size += $attachment['size'];
            }
            unset($fileDataForum);
            unset($filesOfPost);
        }
        return $size;
    }
Пример #2
0
 public function viewThreadObject()
 {
     /**
      * @var $tpl ilTemplate
      * @var $lng ilLanguage
      * @var $ilUser ilObjUser
      * @var $ilAccess ilAccessHandler
      * @var $rbacreview ilRbacReview
      * @var $ilNavigationHistory ilNavigationHistory
      * @var $ilCtrl ilCtrl
      * @var $ilToolbar ilToolbarGUI
      */
     global $tpl, $lng, $ilUser, $ilAccess, $rbacreview, $ilNavigationHistory, $ilCtrl, $frm, $ilToolbar, $ilLocator;
     $tpl->addCss('./Modules/Forum/css/forum_tree.css');
     if (!isset($_SESSION['viewmode'])) {
         $_SESSION['viewmode'] = $this->objProperties->getDefaultView();
     }
     // quick and dirty: check for treeview
     if (!isset($_SESSION['thread_control']['old'])) {
         $_SESSION['thread_control']['old'] = $_GET['thr_pk'];
         $_SESSION['thread_control']['new'] = $_GET['thr_pk'];
     } else {
         if (isset($_SESSION['thread_control']['old']) && $_GET['thr_pk'] != $_SESSION['thread_control']['old']) {
             $_SESSION['thread_control']['new'] = $_GET['thr_pk'];
         }
     }
     if (isset($_GET['viewmode']) && $_GET['viewmode'] != $_SESSION['viewmode']) {
         $_SESSION['viewmode'] = $_GET['viewmode'];
     }
     if (isset($_GET['action']) && $_SESSION['viewmode'] != ilForumProperties::VIEW_DATE || $_SESSION['viewmode'] == ilForumProperties::VIEW_TREE) {
         $_SESSION['viewmode'] = ilForumProperties::VIEW_TREE;
     } else {
         $_SESSION['viewmode'] = ilForumProperties::VIEW_DATE;
     }
     if (!$ilAccess->checkAccess('read', '', $this->object->getRefId())) {
         $this->ilias->raiseError($lng->txt('permission_denied'), $this->ilias->error_obj->MESSAGE);
     }
     // init objects
     $oForumObjects = $this->getForumObjects();
     /**
      * @var $forumObj ilObjForum
      */
     $forumObj = $oForumObjects['forumObj'];
     /**
      * @var $frm ilForum
      */
     $frm = $oForumObjects['frm'];
     /**
      * @var $file_obj ilFileDataForum
      */
     $file_obj = $oForumObjects['file_obj'];
     // download file
     if ($_GET['file']) {
         if (!($path = $file_obj->getFileDataByMD5Filename($_GET['file']))) {
             ilUtil::sendFailure($this->lng->txt('error_reading_file'));
         } else {
             ilUtil::deliverFile($path['path'], $path['clean_filename']);
         }
     }
     if (!$this->objCurrentTopic->getId()) {
         $ilCtrl->redirect($this, 'showThreads');
     }
     // Set context for login
     $append = '_' . $this->objCurrentTopic->getId() . ($this->objCurrentPost->getId() ? '_' . $this->objCurrentPost->getId() : '');
     $tpl->setLoginTargetPar('frm_' . $_GET['ref_id'] . $append);
     // delete temporary media object (not in case a user adds media objects and wants to save an invalid form)
     if ($_GET['action'] != 'showreply' && $_GET['action'] != 'showedit') {
         try {
             include_once 'Services/MediaObjects/classes/class.ilObjMediaObject.php';
             $mobs = ilObjMediaObject::_getMobsOfObject('frm~:html', $ilUser->getId());
             foreach ($mobs as $mob) {
                 if (ilObjMediaObject::_exists($mob)) {
                     ilObjMediaObject::_removeUsage($mob, 'frm~:html', $ilUser->getId());
                     $mob_obj = new ilObjMediaObject($mob);
                     $mob_obj->delete();
                 }
             }
         } catch (Exception $e) {
         }
     }
     require_once './Modules/Forum/classes/class.ilObjForum.php';
     require_once './Modules/Forum/classes/class.ilFileDataForum.php';
     $lng->loadLanguageModule('forum');
     // add entry to navigation history
     if (!$this->getCreationMode() && $ilAccess->checkAccess('read', '', $this->object->getRefId())) {
         $ilCtrl->setParameter($this, 'thr_pk', $this->objCurrentTopic->getId());
         $ilNavigationHistory->addItem($this->object->getRefId(), $ilCtrl->getLinkTarget($this, 'showThreads'), 'frm');
     }
     // save last access
     $forumObj->updateLastAccess($ilUser->getId(), (int) $this->objCurrentTopic->getId());
     $this->prepareThreadScreen($forumObj);
     $tpl->addBlockFile('ADM_CONTENT', 'adm_content', 'tpl.forums_threads_view.html', 'Modules/Forum');
     if (isset($_GET['anchor'])) {
         $tpl->setVariable('JUMP2ANCHOR_ID', (int) $_GET['anchor']);
     }
     if ($_SESSION['viewmode'] == 'date' || $_SESSION['viewmode'] == ilForumProperties::VIEW_DATE) {
         $orderField = 'frm_posts_tree.fpt_date';
         $this->objCurrentTopic->setOrderDirection(in_array($this->objProperties->getDefaultView(), array(ilForumProperties::VIEW_DATE_ASC, ilForumProperties::VIEW_TREE)) ? 'ASC' : 'DESC');
     } else {
         $orderField = 'frm_posts_tree.rgt';
         $this->objCurrentTopic->setOrderDirection('DESC');
     }
     // get forum- and thread-data
     $frm->setMDB2WhereCondition('top_frm_fk = %s ', array('integer'), array($frm->getForumId()));
     if (is_array($topicData = $frm->getOneTopic())) {
         // Visit-Counter for topic
         $this->objCurrentTopic->updateVisits();
         $tpl->setTitle($lng->txt('forums_thread') . " \"" . $this->objCurrentTopic->getSubject() . "\"");
         // ********************************************************************************
         // build location-links
         $ilLocator->addRepositoryItems();
         $ilLocator->addItem($this->object->getTitle(), $ilCtrl->getLinkTarget($this, ""), "_top");
         $tpl->setLocator();
         // set tabs
         // menu template (contains linkbar)
         /** @var $menutpl ilTemplate */
         $menutpl = new ilTemplate('tpl.forums_threads_menu.html', true, true, 'Modules/Forum');
         include_once "./Services/Accessibility/classes/class.ilAccessKeyGUI.php";
         // mark all as read
         if ($ilUser->getId() != ANONYMOUS_USER_ID && $forumObj->getCountUnread($ilUser->getId(), (int) $this->objCurrentTopic->getId())) {
             $this->ctrl->setParameter($this, 'mark_read', '1');
             $this->ctrl->setParameter($this, 'thr_pk', $this->objCurrentTopic->getId());
             $ilToolbar->addButton($this->lng->txt('forums_mark_read'), $this->ctrl->getLinkTarget($this, 'viewThread'), '', ilAccessKey::MARK_ALL_READ);
             $this->ctrl->clearParameters($this);
         }
         // print thread
         $this->ctrl->setParameterByClass('ilforumexportgui', 'print_thread', $this->objCurrentTopic->getId());
         $this->ctrl->setParameterByClass('ilforumexportgui', 'thr_top_fk', $this->objCurrentTopic->getForumId());
         $ilToolbar->addButton($this->lng->txt('forums_print_thread'), $this->ctrl->getLinkTargetByClass('ilforumexportgui', 'printThread'));
         $this->ctrl->clearParametersByClass('ilforumexportgui');
         $this->addHeaderAction();
         if ($_GET['mark_read']) {
             $forumObj->markThreadRead($ilUser->getId(), (int) $this->objCurrentTopic->getId());
             ilUtil::sendInfo($lng->txt('forums_thread_marked'), true);
         }
         // delete post and its sub-posts
         require_once './Modules/Forum/classes/class.ilForum.php';
         if ($_GET['action'] == 'ready_delete' && $_POST['confirm'] != '') {
             if (!$this->objCurrentTopic->isClosed() && ($this->is_moderator || $this->objCurrentPost->isOwner($ilUser->getId()) && !$this->objCurrentPost->hasReplies()) && $ilUser->getId() != ANONYMOUS_USER_ID) {
                 $frm = new ilForum();
                 $frm->setForumId($forumObj->getId());
                 $frm->setForumRefId($forumObj->getRefId());
                 $dead_thr = $frm->deletePost($this->objCurrentPost->getId());
                 // if complete thread was deleted ...
                 if ($dead_thr == $this->objCurrentTopic->getId()) {
                     $frm->setMDB2WhereCondition('top_frm_fk = %s ', array('integer'), array($forumObj->getId()));
                     $topicData = $frm->getOneTopic();
                     ilUtil::sendInfo($lng->txt('forums_post_deleted'), true);
                     if ($topicData['top_num_threads'] > 0) {
                         $this->ctrl->redirect($this, 'showThreads');
                     } else {
                         $this->ctrl->redirect($this, 'createThread');
                     }
                 }
                 ilUtil::sendInfo($lng->txt('forums_post_deleted'));
             }
         }
         // form processing (censor)
         if (!$this->objCurrentTopic->isClosed() && $_GET['action'] == 'ready_censor') {
             if (($_POST['confirm'] != '' || $_POST['no_cs_change'] != '') && $_GET['action'] == 'ready_censor') {
                 $frm->postCensorship($this->handleFormInput($_POST['formData']['cens_message']), $this->objCurrentPost->getId(), 1);
             } else {
                 if (($_POST['cancel'] != '' || $_POST['yes_cs_change'] != '') && $_GET['action'] == 'ready_censor') {
                     $frm->postCensorship($this->handleFormInput($_POST['formData']['cens_message']), $this->objCurrentPost->getId());
                 }
             }
         }
         // get complete tree of thread
         $first_node = $this->objCurrentTopic->getFirstPostNode();
         $this->objCurrentTopic->setOrderField($orderField);
         $subtree_nodes = $this->objCurrentTopic->getPostTree($first_node);
         // no posts
         if (!($posNum = count($subtree_nodes))) {
             ilUtil::sendInfo($this->lng->txt('forums_no_posts_available'));
         }
         $pageHits = $frm->getPageHits();
         $z = 0;
         // navigation to browse
         if ($posNum > $pageHits) {
             $params = array('ref_id' => $_GET['ref_id'], 'thr_pk' => $this->objCurrentTopic->getId(), 'orderby' => $_GET['orderby']);
             if (!$_GET['offset']) {
                 $Start = 0;
             } else {
                 $Start = $_GET['offset'];
             }
             $linkbar = ilUtil::Linkbar($ilCtrl->getLinkTarget($this, 'viewThread'), $posNum, $pageHits, $Start, $params);
             if ($linkbar != '') {
                 $menutpl->setCurrentBlock('linkbar');
                 $menutpl->setVariable('LINKBAR', $linkbar);
                 $menutpl->parseCurrentBlock();
             }
         }
         $tpl->setVariable('THREAD_MENU', $menutpl->get());
         // assistance val for anchor-links
         $jump = 0;
         // generate post-dates
         foreach ($subtree_nodes as $node) {
             /**
              * @var $node ilForumPost 
              */
             $this->ctrl->clearParameters($this);
             if ($this->objCurrentPost->getId() && $this->objCurrentPost->getId() == $node->getId()) {
                 $jump++;
             }
             if ($posNum > $pageHits && $z >= $Start + $pageHits) {
                 // if anchor-link was not found ...
                 if ($this->objCurrentPost->getId() && $jump < 1) {
                     $this->ctrl->setParameter($this, 'thr_pk', $this->objCurrentTopic->getId());
                     $this->ctrl->setParameter($this, 'pos_pk', $this->objCurrentPost->getId());
                     $this->ctrl->setParameter($this, 'offset', $Start + $pageHits);
                     $this->ctrl->setParameter($this, 'orderby', $_GET['orderby']);
                     $this->ctrl->redirect($this, 'viewThread', $this->objCurrentPost->getId());
                     exit;
                 } else {
                     break;
                 }
             }
             if ($posNum > $pageHits && $z >= $Start || $posNum <= $pageHits) {
                 if ($this->objCurrentPost->getId() == $node->getId()) {
                     # actions for "active" post
                     if ($this->is_moderator || $node->isActivated()) {
                         // reply/edit
                         if (!$this->objCurrentTopic->isClosed() && ($_GET['action'] == 'showreply' || $_GET['action'] == 'showedit')) {
                             if ($_GET['action'] == 'showedit' && (!$this->is_moderator && !$node->isOwner($ilUser->getId()) || $ilUser->getId() == ANONYMOUS_USER_ID || $node->isCensored())) {
                                 $this->ilias->raiseError($lng->txt('permission_denied'), $this->ilias->error_obj->MESSAGE);
                             } else {
                                 if ($_GET['action'] == 'showreply' && !$ilAccess->checkAccess('add_reply', '', (int) $_GET['ref_id'])) {
                                     $this->ilias->raiseError($lng->txt('permission_denied'), $this->ilias->error_obj->MESSAGE);
                                 }
                             }
                             $tpl->setVariable('REPLY_ANKER', $this->objCurrentPost->getId());
                             $oEditReplyForm = $this->getReplyEditForm();
                             switch ($this->objProperties->getSubjectSetting()) {
                                 case 'add_re_to_subject':
                                     $subject = $this->getModifiedReOnSubject(true);
                                     break;
                                 case 'preset_subject':
                                     $subject = $this->objCurrentPost->getSubject();
                                     break;
                                 case 'empty_subject':
                                 default:
                                     $subject = NULL;
                                     break;
                             }
                             switch ($_GET['action']) {
                                 case 'showreply':
                                     if ($this->ctrl->getCmd() == 'savePost') {
                                         $oEditReplyForm->setValuesByPost();
                                     } else {
                                         if ($this->ctrl->getCmd() == 'quotePost') {
                                             require_once 'Modules/Forum/classes/class.ilForumAuthorInformation.php';
                                             $authorinfo = new ilForumAuthorInformation($node->getPosAuthorId(), $node->getDisplayUserId(), $node->getUserAlias(), $node->getImportName());
                                             $oEditReplyForm->setValuesByPost();
                                             $oEditReplyForm->getItemByPostVar('message')->setValue(ilRTE::_replaceMediaObjectImageSrc($frm->prepareText($node->getMessage(), 1, $authorinfo->getAuthorName()) . "\n" . $oEditReplyForm->getInput('message'), 1));
                                         } else {
                                             $oEditReplyForm->setValuesByArray(array('alias' => '', 'subject' => $subject, 'message' => '', 'notify' => 0, 'userfile' => '', 'del_file' => array()));
                                         }
                                     }
                                     $this->ctrl->setParameter($this, 'pos_pk', $this->objCurrentPost->getId());
                                     $this->ctrl->setParameter($this, 'thr_pk', $this->objCurrentPost->getThreadId());
                                     $jsTpl = new ilTemplate('tpl.forum_post_quoation_ajax_handler.html', true, true, 'Modules/Forum/');
                                     $jsTpl->setVariable('IL_FRM_QUOTE_CALLBACK_SRC', $this->ctrl->getLinkTarget($this, 'getQuotationHTMLAsynch', '', true));
                                     $this->ctrl->clearParameters($this);
                                     $this->tpl->setVariable('FORM_ADDITIONAL_JS', $jsTpl->get());
                                     break;
                                 case 'showedit':
                                     if ($this->ctrl->getCmd() == 'savePost') {
                                         $oEditReplyForm->setValuesByPost();
                                     } else {
                                         $oEditReplyForm->setValuesByArray(array('alias' => '', 'subject' => $this->objCurrentPost->getSubject(), 'message' => ilRTE::_replaceMediaObjectImageSrc($frm->prepareText($this->objCurrentPost->getMessage(), 2), 1), 'notify' => $this->objCurrentPost->isNotificationEnabled() ? true : false, 'userfile' => '', 'del_file' => array()));
                                     }
                                     break;
                             }
                             $this->ctrl->setParameter($this, 'pos_pk', $this->objCurrentPost->getId());
                             $this->ctrl->setParameter($this, 'thr_pk', $this->objCurrentPost->getThreadId());
                             $this->ctrl->setParameter($this, 'offset', (int) $_GET['offset']);
                             $this->ctrl->setParameter($this, 'orderby', $_GET['orderby']);
                             $this->ctrl->setParameter($this, 'action', $_GET['action']);
                             $tpl->setVariable('FORM', $oEditReplyForm->getHTML());
                             $this->ctrl->clearParameters($this);
                         } else {
                             if (!$this->objCurrentTopic->isClosed() && $_GET['action'] == 'delete') {
                                 if ($this->is_moderator || $node->isOwner($ilUser->getId()) && !$node->hasReplies() && $ilUser->getId() != ANONYMOUS_USER_ID) {
                                     // confirmation: delete
                                     $tpl->setVariable('FORM', $this->getDeleteFormHTML());
                                 }
                             } else {
                                 if (!$this->objCurrentTopic->isClosed() && $_GET['action'] == 'censor') {
                                     if ($this->is_moderator) {
                                         // confirmation: censor / remove censorship
                                         $tpl->setVariable('FORM', $this->getCensorshipFormHTML());
                                     }
                                 } else {
                                     if (!$this->objCurrentTopic->isClosed() && $this->displayConfirmPostActivation()) {
                                         if ($this->is_moderator) {
                                             // confirmation: activate
                                             $tpl->setVariable('FORM', $this->getActivationFormHTML());
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
                 // if ($this->objCurrentPost->getId() == $node->getId())
                 if ($this->objCurrentPost->getId() != $node->getId() || $_GET['action'] != 'showreply' && $_GET['action'] != 'showedit' && $_GET['action'] != 'censor' && $_GET['action'] != 'delete' && !$this->displayConfirmPostActivation()) {
                     if ($this->is_moderator || $node->isActivated()) {
                         // button: reply
                         if (!$this->objCurrentTopic->isClosed() && $ilAccess->checkAccess('add_reply', '', (int) $_GET['ref_id']) && !$node->isCensored()) {
                             $tpl->setCurrentBlock('commands');
                             $this->ctrl->setParameter($this, 'action', 'showreply');
                             $this->ctrl->setParameter($this, 'pos_pk', $node->getId());
                             $this->ctrl->setParameter($this, 'offset', $Start);
                             $this->ctrl->setParameter($this, 'orderby', $_GET['orderby']);
                             $this->ctrl->setParameter($this, 'thr_pk', $node->getThreadId());
                             $tpl->setVariable('COMMANDS_COMMAND', $this->ctrl->getLinkTarget($this, 'viewThread', $node->getId()));
                             $tpl->setVariable('COMMANDS_TXT', $lng->txt('reply'));
                             $this->ctrl->clearParameters($this);
                             $tpl->parseCurrentBlock();
                         }
                         // button: edit article
                         if (!$this->objCurrentTopic->isClosed() && ($node->isOwner($ilUser->getId()) || $this->is_moderator) && !$node->isCensored() && $ilUser->getId() != ANONYMOUS_USER_ID) {
                             $tpl->setCurrentBlock('commands');
                             $this->ctrl->setParameter($this, 'action', 'showedit');
                             $this->ctrl->setParameter($this, 'pos_pk', $node->getId());
                             $this->ctrl->setParameter($this, 'thr_pk', $node->getThreadId());
                             $this->ctrl->setParameter($this, 'offset', $Start);
                             $this->ctrl->setParameter($this, 'orderby', $_GET['orderby']);
                             $tpl->setVariable('COMMANDS_COMMAND', $this->ctrl->getLinkTarget($this, 'viewThread', $node->getId()));
                             $tpl->setVariable('COMMANDS_TXT', $lng->txt('edit'));
                             $this->ctrl->clearParameters($this);
                             $tpl->parseCurrentBlock();
                         }
                         // button: print
                         if (!$node->isCensored()) {
                             $tpl->setCurrentBlock('commands');
                             $this->ctrl->setParameterByClass('ilforumexportgui', 'print_post', $node->getId());
                             $this->ctrl->setParameterByClass('ilforumexportgui', 'top_pk', $node->getForumId());
                             $this->ctrl->setParameterByClass('ilforumexportgui', 'thr_pk', $node->getThreadId());
                             $tpl->setVariable('COMMANDS_COMMAND', $this->ctrl->getLinkTargetByClass('ilforumexportgui', 'printPost'));
                             $tpl->setVariable('COMMANDS_TXT', $lng->txt('print'));
                             $this->ctrl->clearParameters($this);
                             $tpl->parseCurrentBlock();
                         }
                         # buttons for every post except the "active"
                         if (!$this->objCurrentTopic->isClosed() && ($this->is_moderator || $node->isOwner($ilUser->getId()) && !$node->hasReplies()) && $ilUser->getId() != ANONYMOUS_USER_ID) {
                             // button: delete
                             $tpl->setCurrentBlock('commands');
                             $this->ctrl->setParameter($this, 'action', 'delete');
                             $this->ctrl->setParameter($this, 'pos_pk', $node->getId());
                             $this->ctrl->setParameter($this, 'thr_pk', $node->getThreadId());
                             $this->ctrl->setParameter($this, 'offset', $Start);
                             $this->ctrl->setParameter($this, 'orderby', $_GET['orderby']);
                             $tpl->setVariable('COMMANDS_COMMAND', $this->ctrl->getLinkTarget($this, 'viewThread', $node->getId()));
                             $tpl->setVariable('COMMANDS_TXT', $lng->txt('delete'));
                             $this->ctrl->clearParameters($this);
                             $tpl->parseCurrentBlock();
                         }
                         if (!$this->objCurrentTopic->isClosed() && $this->is_moderator) {
                             // button: censor
                             $tpl->setCurrentBlock('commands');
                             $this->ctrl->setParameter($this, 'action', 'censor');
                             $this->ctrl->setParameter($this, 'pos_pk', $node->getId());
                             $this->ctrl->setParameter($this, 'thr_pk', $node->getThreadId());
                             $this->ctrl->setParameter($this, 'offset', $Start);
                             $this->ctrl->setParameter($this, 'orderby', $_GET['orderby']);
                             $tpl->setVariable('COMMANDS_COMMAND', $this->ctrl->getLinkTarget($this, 'viewThread', $node->getId()));
                             $tpl->setVariable('COMMANDS_TXT', $lng->txt('censorship'));
                             $this->ctrl->clearParameters($this);
                             $tpl->parseCurrentBlock();
                             // button: activation/deactivation
                             $tpl->setCurrentBlock('commands');
                             $this->ctrl->setParameter($this, 'pos_pk', $node->getId());
                             $this->ctrl->setParameter($this, 'thr_pk', $node->getThreadId());
                             $this->ctrl->setParameter($this, 'offset', $Start);
                             $this->ctrl->setParameter($this, 'orderby', $_GET['orderby']);
                             if (!$node->isActivated()) {
                                 $tpl->setVariable('COMMANDS_COMMAND', $this->ctrl->getLinkTarget($this, 'askForPostActivation', $node->getId()));
                                 $tpl->setVariable('COMMANDS_TXT', $lng->txt('activate_post'));
                             }
                             $this->ctrl->clearParameters($this);
                             $tpl->parseCurrentBlock();
                         }
                         // button: mark read
                         if ($ilUser->getId() != ANONYMOUS_USER_ID && !$node->isPostRead()) {
                             $tpl->setCurrentBlock('commands');
                             $this->ctrl->setParameter($this, 'pos_pk', $node->getId());
                             $this->ctrl->setParameter($this, 'thr_pk', $node->getThreadId());
                             $this->ctrl->setParameter($this, 'offset', $Start);
                             $this->ctrl->setParameter($this, 'orderby', $_GET['orderby']);
                             $this->ctrl->setParameter($this, 'viewmode', $_SESSION['viewmode']);
                             $tpl->setVariable('COMMANDS_COMMAND', $this->ctrl->getLinkTarget($this, 'markPostRead', $node->getId()));
                             $tpl->setVariable('COMMANDS_TXT', $lng->txt('is_read'));
                             $this->ctrl->clearParameters($this);
                             $tpl->parseCurrentBlock();
                         }
                         // button: mark unread
                         if ($ilUser->getId() != ANONYMOUS_USER_ID && $node->isPostRead()) {
                             $tpl->setCurrentBlock('commands');
                             $this->ctrl->setParameter($this, 'pos_pk', $node->getId());
                             $this->ctrl->setParameter($this, 'thr_pk', $node->getThreadId());
                             $this->ctrl->setParameter($this, 'offset', $Start);
                             $this->ctrl->setParameter($this, 'orderby', $_GET['orderby']);
                             $this->ctrl->setParameter($this, 'viewmode', $_SESSION['viewmode']);
                             $tpl->setVariable('COMMANDS_COMMAND', $this->ctrl->getLinkTarget($this, 'markPostUnread', $node->getId()));
                             $tpl->setVariable('COMMANDS_TXT', $lng->txt('unread'));
                             $this->ctrl->clearParameters($this);
                             $tpl->parseCurrentBlock();
                         }
                     }
                 }
                 // if ($this->objCurrentPost->getId() != $node->getId())
                 // download post attachments
                 $tmp_file_obj = new ilFileDataForum($forumObj->getId(), $node->getId());
                 if (count($tmp_file_obj->getFilesOfPost())) {
                     if ($node->getId() != $this->objCurrentPost->getId() || $_GET['action'] != 'showedit') {
                         foreach ($tmp_file_obj->getFilesOfPost() as $file) {
                             $tpl->setCurrentBlock('attachment_download_row');
                             $this->ctrl->setParameter($this, 'pos_pk', $node->getId());
                             $this->ctrl->setParameter($this, 'file', $file['md5']);
                             $tpl->setVariable('HREF_DOWNLOAD', $this->ctrl->getLinkTarget($this, 'viewThread'));
                             $tpl->setVariable('TXT_FILENAME', $file['name']);
                             $this->ctrl->clearParameters($this);
                             $tpl->parseCurrentBlock();
                         }
                         $tpl->setCurrentBlock('attachments');
                         $tpl->setVariable('TXT_ATTACHMENTS_DOWNLOAD', $lng->txt('forums_attachments'));
                         include_once "./Services/UIComponent/Glyph/classes/class.ilGlyphGUI.php";
                         $tpl->setVariable('DOWNLOAD_IMG', ilGlyphGUI::get(ilGlyphGUI::ATTACHMENT, $lng->txt('forums_download_attachment')));
                         $tpl->parseCurrentBlock();
                     }
                 }
                 $tpl->setCurrentBlock('posts_row');
                 // anker for every post
                 $tpl->setVariable('POST_ANKER', $node->getId());
                 //permanent link for every post
                 //	$tpl->setVariable('PERMA_LINK', ILIAS_HTTP_PATH."/goto.php?target="."frm"."_".$this->object->getRefId()."_".$node->getThreadId()."_".$node->getId()."&client_id=".CLIENT_ID);
                 $tpl->setVariable('TXT_PERMA_LINK', $lng->txt('perma_link'));
                 $tpl->setVariable('PERMA_TARGET', '_top');
                 if ($this->objProperties->getMarkModeratorPosts() == 1) {
                     if ($node->getIsAuthorModerator() === null && ($is_moderator = ilForum::_isModerator($_GET['ref_id'], $node->getPosAuthorId()))) {
                         $rowCol = 'ilModeratorPosting';
                     } elseif ($node->getIsAuthorModerator()) {
                         $rowCol = 'ilModeratorPosting';
                     } else {
                         $rowCol = ilUtil::switchColor($z, 'tblrow1', 'tblrow2');
                     }
                 } else {
                     $rowCol = ilUtil::switchColor($z, 'tblrow1', 'tblrow2');
                 }
                 if ($_GET['action'] != 'delete' && $_GET['action'] != 'censor' && !$this->displayConfirmPostActivation() || $this->objCurrentPost->getId() != $node->getId()) {
                     $tpl->setVariable('ROWCOL', ' ' . $rowCol);
                 } else {
                     // highlight censored posts
                     $rowCol = 'tblrowmarked';
                 }
                 // post is censored
                 if ($node->isCensored()) {
                     // display censorship advice
                     if ($_GET['action'] != 'censor') {
                         $tpl->setVariable('TXT_CENSORSHIP_ADVICE', $this->lng->txt('post_censored_comment_by_moderator'));
                     }
                     // highlight censored posts
                     $rowCol = 'tblrowmarked';
                 }
                 // set row color
                 $tpl->setVariable('ROWCOL', ' ' . $rowCol);
                 // if post is not activated display message for the owner
                 if (!$node->isActivated() && $node->isOwner($ilUser->getId())) {
                     $tpl->setVariable('POST_NOT_ACTIVATED_YET', $this->lng->txt('frm_post_not_activated_yet'));
                 }
                 // Author
                 $this->ctrl->setParameter($this, 'pos_pk', $node->getId());
                 $this->ctrl->setParameter($this, 'thr_pk', $node->getThreadId());
                 $backurl = urlencode($this->ctrl->getLinkTarget($this, 'viewThread', $node->getId()));
                 $this->ctrl->clearParameters($this);
                 $this->ctrl->setParameter($this, 'backurl', $backurl);
                 $this->ctrl->setParameter($this, 'thr_pk', $node->getThreadId());
                 $this->ctrl->setParameter($this, 'user', $node->getDisplayUserId());
                 require_once 'Modules/Forum/classes/class.ilForumAuthorInformation.php';
                 $authorinfo = new ilForumAuthorInformation($node->getPosAuthorId(), $node->getDisplayUserId(), $node->getUserAlias(), $node->getImportName(), array('href' => $this->ctrl->getLinkTarget($this, 'showUser')));
                 $this->ctrl->clearParameters($this);
                 if ($authorinfo->hasSuffix()) {
                     $tpl->setVariable('AUTHOR', $authorinfo->getSuffix());
                     $tpl->setVariable('USR_NAME', $node->getUserAlias());
                 } else {
                     $tpl->setVariable('AUTHOR', $authorinfo->getLinkedAuthorShortName());
                     if ($authorinfo->getAuthorName(true)) {
                         $tpl->setVariable('USR_NAME', $authorinfo->getAuthorName(true));
                     }
                 }
                 $tpl->setVariable('USR_IMAGE', $authorinfo->getProfilePicture());
                 if ($authorinfo->getAuthor()->getId() && ilForum::_isModerator((int) $_GET['ref_id'], $node->getPosAuthorId())) {
                     if ($authorinfo->getAuthor()->getGender() == 'f') {
                         $tpl->setVariable('ROLE', $this->lng->txt('frm_moderator_f'));
                     } else {
                         if ($authorinfo->getAuthor()->getGender() == 'm') {
                             $tpl->setVariable('ROLE', $this->lng->txt('frm_moderator_m'));
                         }
                     }
                 }
                 // get create- and update-dates
                 if ($node->getUpdateUserId() > 0) {
                     $spanClass = '';
                     // last update from moderator?
                     $posMod = $frm->getModeratorFromPost($node->getId());
                     if (is_array($posMod) && $posMod['top_mods'] > 0) {
                         $MODS = $rbacreview->assignedUsers($posMod['top_mods']);
                         if (is_array($MODS)) {
                             if (in_array($node->getUpdateUserId(), $MODS)) {
                                 $spanClass = 'moderator_small';
                             }
                         }
                     }
                     $node->setChangeDate($node->getChangeDate());
                     if ($spanClass == '') {
                         $spanClass = 'small';
                     }
                     $this->ctrl->setParameter($this, 'backurl', $backurl);
                     $this->ctrl->setParameter($this, 'thr_pk', $node->getThreadId());
                     $this->ctrl->setParameter($this, 'user', $node->getUpdateUserId());
                     require_once 'Modules/Forum/classes/class.ilForumAuthorInformation.php';
                     $authorinfo = new ilForumAuthorInformation($node->getPosAuthorId(), $node->getUpdateUserId(), '', '', array('href' => $this->ctrl->getLinkTarget($this, 'showUser')));
                     $this->ctrl->clearParameters($this);
                     $tpl->setVariable('POST_UPDATE_TXT', $lng->txt('edited_on') . ': ' . $frm->convertDate($node->getChangeDate()) . ' - ' . strtolower($lng->txt('by')));
                     $tpl->setVariable('UPDATE_AUTHOR', $authorinfo->getLinkedAuthorShortName());
                     if ($authorinfo->getAuthorName(true)) {
                         $tpl->setVariable('UPDATE_USR_NAME', $authorinfo->getAuthorName(true));
                     }
                 }
                 // if ($node->getUpdateUserId() > 0)*/
                 // Author end
                 // prepare post
                 $node->setMessage($frm->prepareText($node->getMessage()));
                 if ($ilUser->getId() == ANONYMOUS_USER_ID || $node->isPostRead()) {
                     $tpl->setVariable('SUBJECT', $node->getSubject());
                 } else {
                     $this->ctrl->setParameter($this, 'pos_pk', $node->getId());
                     $this->ctrl->setParameter($this, 'thr_pk', $node->getThreadId());
                     $this->ctrl->setParameter($this, 'offset', $Start);
                     $this->ctrl->setParameter($this, 'orderby', $_GET['orderby']);
                     $this->ctrl->setParameter($this, 'viewmode', $_SESSION['viewmode']);
                     $mark_post_target = $this->ctrl->getLinkTarget($this, 'markPostRead', $node->getId());
                     $tpl->setVariable('SUBJECT', "<a href=\"" . $mark_post_target . "\"><b>" . $node->getSubject() . "</b></a>");
                 }
                 $tpl->setVariable('POST_DATE', $frm->convertDate($node->getCreateDate()));
                 if (!$node->isCensored() || $this->objCurrentPost->getId() == $node->getId() && $_GET['action'] == 'censor') {
                     // post from moderator?
                     $modAuthor = $frm->getModeratorFromPost($node->getId());
                     $spanClass = "";
                     if (is_array($modAuthor) && $modAuthor['top_mods'] > 0) {
                         unset($MODS);
                         $MODS = $rbacreview->assignedUsers($modAuthor['top_mods']);
                         if (is_array($MODS)) {
                             if (in_array($node->getDisplayUserId(), $MODS)) {
                                 $spanClass = 'moderator';
                             }
                         }
                     }
                     // possible bugfix for mantis #8223
                     if ($node->getMessage() == strip_tags($node->getMessage())) {
                         // We can be sure, that there are not html tags
                         $node->setMessage(nl2br($node->getMessage()));
                     }
                     if ($spanClass != "") {
                         $tpl->setVariable('POST', "<span class=\"" . $spanClass . "\">" . ilRTE::_replaceMediaObjectImageSrc($node->getMessage(), 1) . "</span>");
                     } else {
                         $tpl->setVariable('POST', ilRTE::_replaceMediaObjectImageSrc($node->getMessage(), 1));
                     }
                 } else {
                     $tpl->setVariable('POST', "<span class=\"moderator\">" . nl2br($node->getCensorshipComment()) . "</span>");
                 }
                 $tpl->parseCurrentBlock();
             }
             $z++;
         }
     } else {
         $tpl->setCurrentBlock('posts_no');
         $tpl->setVariable('TXT_MSG_NO_POSTS_AVAILABLE', $lng->txt('forums_posts_not_available'));
         $tpl->parseCurrentBlock();
     }
     $oThreadToolbar = clone $ilToolbar;
     $oThreadToolbar->addSeparator();
     $oThreadToolbar->addButton($this->lng->txt('top_of_page'), '#frm_page_top');
     $tpl->setVariable('THREAD_TOOLBAR', $oThreadToolbar->getHTML());
     $tpl->setVariable('TPLPATH', $tpl->vars['TPLPATH']);
     // permanent link
     include_once 'Services/PermanentLink/classes/class.ilPermanentLinkGUI.php';
     $permalink = new ilPermanentLinkGUI('frm', $this->object->getRefId(), '_' . $this->objCurrentTopic->getId());
     $this->tpl->setVariable('PRMLINK', $permalink->getHTML());
     // Render tree
     if ($_SESSION['viewmode'] == 'answers' || $_SESSION['viewmode'] == ilForumProperties::VIEW_TREE) {
         $tpl->setLeftNavContent($this->getForumExplorer());
     }
     return true;
 }
    function start()
    {
        global $ilDB;
        ilUtil::makeDir($this->target_dir_absolute . "/objects");
        $query_frm = 'SELECT * FROM frm_settings fs ' . 'JOIN object_data od ON fs.obj_id = od.obj_id ' . 'JOIN frm_data ON top_frm_fk  = od.obj_id ' . 'WHERE fs.obj_id = ' . $ilDB->quote($this->forum_id, 'integer');
        $res = $ilDB->query($query_frm);
        while ($row = $res->fetchRow(DB_FETCHMODE_OBJECT)) {
            break;
        }
        $this->xmlStartTag("Forum", null);
        $this->xmlElement("Id", null, (int) $row->top_pk);
        $this->xmlElement("ObjId", null, (int) $row->obj_id);
        $this->xmlElement("Title", null, $row->title);
        $this->xmlElement("Description", null, $row->description);
        $this->xmlElement("DefaultView", null, (int) $row->default_view);
        $this->xmlElement("Pseudonyms", null, (int) $row->anonymized);
        $this->xmlElement("Statistics", null, (int) $row->statistics_enabled);
        $this->xmlElement("PostingActivation", null, (int) $row->post_activation);
        $this->xmlElement("PresetSubject", null, (int) $row->preset_subject);
        $this->xmlElement("PresetRe", null, (int) $row->add_re_subject);
        $this->xmlElement("NotificationType", null, $row->notification_type);
        $this->xmlElement("ForceNotification", null, (int) $row->admin_force_noti);
        $this->xmlElement("ToggleNotification", null, (int) $row->user_toggle_noti);
        $this->xmlElement("LastPost", null, $row->top_last_post);
        $this->xmlElement("Moderator", null, (int) $row->top_mods);
        $this->xmlElement("CreateDate", null, $row->top_date);
        $this->xmlElement("UpdateDate", null, $row->top_update);
        $this->xmlElement("UpdateUserId", null, $row->update_user);
        $this->xmlElement("UserId", null, (int) $row->top_usr_id);
        $query_thr = "SELECT frm_threads.* " . " FROM frm_threads " . " INNER JOIN frm_data ON top_pk = thr_top_fk " . 'WHERE top_frm_fk = ' . $ilDB->quote($this->forum_id, 'integer');
        $res = $ilDB->query($query_thr);
        while ($row = $ilDB->fetchObject($res)) {
            $this->xmlStartTag("Thread");
            $this->xmlElement("Id", null, (int) $row->thr_pk);
            $this->xmlElement("Subject", null, $row->thr_subject);
            $this->xmlElement("UserId", null, (int) $row->thr_usr_id);
            $this->xmlElement("Alias", null, $row->thr_usr_alias);
            $this->xmlElement("LastPost", null, $row->thr_last_post);
            $this->xmlElement("CreateDate", null, $row->thr_date);
            $this->xmlElement("UpdateDate", null, $row->thr_date);
            $this->xmlElement("ImportName", null, $row->import_name);
            $this->xmlElement("Sticky", null, (int) $row->is_sticky);
            $this->xmlElement("Closed", null, (int) $row->is_closed);
            $query = 'SELECT frm_posts.*, frm_posts_tree.*
						FROM frm_posts
							INNER JOIN frm_data
								ON top_pk = pos_top_fk
							INNER JOIN frm_posts_tree
								ON pos_fk = pos_pk
						WHERE pos_thr_fk = ' . $ilDB->quote($row->thr_pk, 'integer') . ' ';
            $query .= " ORDER BY frm_posts_tree.lft ASC";
            $resPosts = $ilDB->query($query);
            $lastDepth = null;
            while ($rowPost = $ilDB->fetchObject($resPosts)) {
                /*
                				// Used for nested postings
                				if( $rowPost->depth < $lastDepth )
                				{
                					for( $i = $rowPost->depth; $i <= $lastDepth; $i++ )
                					{
                						$this->xmlEndTag("Post");
                					}
                				}*/
                $this->xmlStartTag("Post");
                $this->xmlElement("Id", null, (int) $rowPost->pos_pk);
                $this->xmlElement("UserId", null, (int) $rowPost->pos_usr_id);
                $this->xmlElement("Alias", null, $rowPost->pos_usr_alias);
                $this->xmlElement("Subject", null, $rowPost->pos_subject);
                $this->xmlElement("CreateDate", null, $rowPost->pos_date);
                $this->xmlElement("UpdateDate", null, $rowPost->pos_update);
                $this->xmlElement("UpdateUserId", null, (int) $rowPost->update_user);
                $this->xmlElement("Censorship", null, (int) $rowPost->pos_cens);
                $this->xmlElement("CensorshipMessage", null, $rowPost->pos_cens_com);
                $this->xmlElement("Notification", null, $rowPost->notify);
                $this->xmlElement("ImportName", null, $rowPost->import_name);
                $this->xmlElement("Status", null, (int) $rowPost->pos_status);
                $this->xmlElement("Message", null, ilRTE::_replaceMediaObjectImageSrc($rowPost->pos_message, 0));
                $media_exists = false;
                $mobs = ilObjMediaObject::_getMobsOfObject('frm:html', $rowPost->pos_pk);
                foreach ($mobs as $mob) {
                    $moblabel = "il_" . IL_INST_ID . "_mob_" . $mob;
                    if (ilObjMediaObject::_exists($mob)) {
                        if (!$media_exists) {
                            $this->xmlStartTag("MessageMediaObjects");
                            $media_exists = true;
                        }
                        $mob_obj = new ilObjMediaObject($mob);
                        $imgattrs = array("label" => $moblabel, "uri" => $this->target_dir_relative . "/objects/" . "il_" . IL_INST_ID . "_mob_" . $mob . "/" . $mob_obj->getTitle());
                        $this->xmlElement("MediaObject", $imgattrs, NULL);
                        $mob_obj->exportFiles($this->target_dir_absolute);
                    }
                }
                if ($media_exists) {
                    $this->xmlEndTag("MessageMediaObjects");
                }
                $this->xmlElement("Lft", null, (int) $rowPost->lft);
                $this->xmlElement("Rgt", null, (int) $rowPost->rgt);
                $this->xmlElement("Depth", null, (int) $rowPost->depth);
                $this->xmlElement("ParentId", null, (int) $rowPost->parent_pos);
                $tmp_file_obj = new ilFileDataForum($this->forum_id, $rowPost->pos_pk);
                $set = array();
                if (count($tmp_file_obj->getFilesOfPost())) {
                    foreach ($tmp_file_obj->getFilesOfPost() as $file) {
                        $this->xmlStartTag("Attachment");
                        copy($file['path'], $this->target_dir_absolute . "/" . basename($file['path']));
                        $content = $this->target_dir_relative . "/" . basename($file['path']);
                        $this->xmlElement("Content", null, $content);
                        $this->xmlEndTag("Attachment");
                    }
                }
                //Used for nested postings
                //$lastDepth = $rowPost->depth;
                $this->xmlEndTag("Post");
            }
            /*
            			// Used for nested postings
            			if( $lastDepth )
            			{
            				for( $i = 1; $i <= $lastDepth ; $i++ )
            				{
            					$this->xmlEndTag("Post");
            				}
            
            				$lastDepth = null;
            			}*/
            $this->xmlEndTag("Thread");
        }
        $this->xmlEndTag("Forum");
        return true;
    }
 protected function sendMails($res)
 {
     global $ilAccess, $ilDB, $lng;
     static $cache = array();
     static $attachments_cache = array();
     include_once 'Modules/Forum/classes/class.ilObjForum.php';
     include_once 'Services/Mail/classes/class.ilMail.php';
     include_once 'Services/User/classes/class.ilObjUser.php';
     include_once 'Services/Language/classes/class.ilLanguage.php';
     $forumObj = new ilObjForum();
     $frm = $forumObj->Forum;
     $numRows = 0;
     $mail_obj = new ilMail(ANONYMOUS_USER_ID);
     $mail_obj->enableSOAP(false);
     while ($row = $ilDB->fetchAssoc($res)) {
         // don not send a notification to the post author
         if ($row['pos_display_user_id'] != $row['user_id']) {
             // GET AUTHOR OF NEW POST
             if ($row['pos_display_user_id']) {
                 $row['pos_usr_name'] = ilObjUser::_lookupLogin($row['pos_display_user_id']);
             } else {
                 if (strlen($row['pos_usr_alias'])) {
                     $row['pos_usr_name'] = $row['pos_usr_alias'] . ' (' . $lng->txt('frm_pseudonym') . ')';
                 }
             }
             if ($row['pos_usr_name'] == '') {
                 $row['pos_usr_name'] = $lng->txt('forums_anonymous');
             }
             // get all references of obj_id
             if (!isset($cache[$row['obj_id']])) {
                 $cache[$row['obj_id']] = ilObject::_getAllReferences($row['obj_id']);
             }
             // check for attachments
             $has_attachments = false;
             if (!isset($attachments_cache[$row['obj_id']][$row['pos_pk']])) {
                 $fileDataForum = new ilFileDataForum($row['obj_id'], $row['pos_pk']);
                 $filesOfPost = $fileDataForum->getFilesOfPost();
                 foreach ($filesOfPost as $attachment) {
                     $attachments_cache[$row['obj_id']][$row['pos_pk']][] = $attachment['name'];
                     $has_attachments = true;
                 }
             } else {
                 $has_attachments = true;
             }
             // do rbac check before sending notification
             $send_mail = false;
             foreach ((array) $cache[$row['obj_id']] as $ref_id) {
                 if ($ilAccess->checkAccessOfUser($row['user_id'], 'read', '', $ref_id)) {
                     $row['ref_id'] = $ref_id;
                     $send_mail = true;
                     break;
                 }
             }
             $attached_files = array();
             if ($has_attachments == true) {
                 $attached_files = $attachments_cache[$row['obj_id']][$row['pos_pk']];
             }
             if ($send_mail) {
                 $frm->setLanguage(ilForum::_getLanguageInstanceByUsrId($row['user_id']));
                 $mail_obj->sendMail(ilObjUser::_lookupLogin($row['user_id']), '', '', $frm->formatNotificationSubject($row), $frm->formatNotification($row, 1, $attached_files, $row['user_id']), array(), array('normal'));
                 $numRows++;
             }
         }
     }
     return $numRows;
 }
    function start()
    {
        global $ilDB;
        $query_frm = 'SELECT * FROM frm_settings fs ' . 'JOIN object_data od ON fs.obj_id = od.obj_id ' . 'JOIN frm_data ON top_frm_fk  = od.obj_id ' . 'WHERE fs.obj_id = ' . $ilDB->quote($this->forum_id, 'integer');
        $res = $ilDB->query($query_frm);
        while ($row = $res->fetchRow(DB_FETCHMODE_OBJECT)) {
            break;
        }
        $this->xmlStartTag("Forum", null);
        $this->xmlElement("Id", null, (int) $row->top_pk);
        $this->xmlElement("ObjId", null, (int) $row->obj_id);
        $this->xmlElement("Title", null, $row->title);
        $this->xmlElement("Description", null, $row->description);
        $this->xmlElement("DefaultView", null, (int) $row->default_view);
        $this->xmlElement("Pseudonyms", null, (int) $row->anonymized);
        $this->xmlElement("Statistics", null, (int) $row->statistics_enabled);
        $this->xmlElement("PostingActivation", null, (int) $row->post_activation);
        $this->xmlElement("PresetSubject", null, (int) $row->preset_subject);
        $this->xmlElement("PresetRe", null, (int) $row->add_re_subject);
        $this->xmlElement("NotificationType", null, $row->notification_type);
        $this->xmlElement("ForceNotification", null, (int) $row->admin_force_noti);
        $this->xmlElement("ToggleNotification", null, (int) $row->user_toggle_noti);
        $this->xmlElement("LastPost", null, $row->top_last_post);
        $this->xmlElement("Moderator", null, (int) $row->top_mods);
        $this->xmlElement("CreateDate", null, $row->top_date);
        $this->xmlElement("UpdateDate", null, $row->top_update);
        $this->xmlElement("UpdateUserId", null, $row->update_user);
        $this->xmlElement("UserId", null, (int) $row->top_usr_id);
        $query_thr = "SELECT frm_threads.* " . " FROM frm_threads " . " INNER JOIN frm_data ON top_pk = thr_top_fk " . 'WHERE top_frm_fk = ' . $ilDB->quote($this->forum_id, 'integer');
        $res = $ilDB->query($query_thr);
        while ($row = $ilDB->fetchObject($res)) {
            $this->xmlStartTag("Thread");
            $this->xmlElement("Id", null, (int) $row->thr_pk);
            $this->xmlElement("Subject", null, $row->thr_subject);
            $this->xmlElement("UserId", null, (int) $row->thr_usr_id);
            $this->xmlElement("Alias", null, $row->thr_usr_alias);
            $this->xmlElement("LastPost", null, $row->thr_last_post);
            $this->xmlElement("CreateDate", null, $row->thr_date);
            $this->xmlElement("UpdateDate", null, $row->thr_date);
            $this->xmlElement("ImportName", null, $row->import_name);
            $this->xmlElement("Sticky", null, (int) $row->is_sticky);
            $this->xmlElement("Closed", null, (int) $row->is_closed);
            $query = 'SELECT frm_posts.*, frm_posts_tree.*
						FROM frm_posts
							INNER JOIN frm_data
								ON top_pk = pos_top_fk
							INNER JOIN frm_posts_tree
								ON pos_fk = pos_pk
						WHERE pos_thr_fk = ' . $ilDB->quote($row->thr_pk, 'integer') . ' ';
            $query .= " ORDER BY frm_posts_tree.lft ASC";
            $resPosts = $ilDB->query($query);
            $lastDepth = null;
            while ($rowPost = $ilDB->fetchObject($resPosts)) {
                /*
                				// Used for nested postings
                				if( $rowPost->depth < $lastDepth )
                				{
                					for( $i = $rowPost->depth; $i <= $lastDepth; $i++ )
                					{
                						$this->xmlEndTag("Post");
                					}
                				}*/
                $this->xmlStartTag("Post");
                $this->xmlElement("Id", null, (int) $rowPost->pos_pk);
                $this->xmlElement("UserId", null, (int) $rowPost->pos_usr_id);
                $this->xmlElement("Alias", null, $rowPost->pos_usr_alias);
                $this->xmlElement("Subject", null, $rowPost->pos_subject);
                $this->xmlElement("CreateDate", null, $rowPost->pos_date);
                $this->xmlElement("UpdateDate", null, $rowPost->pos_update);
                $this->xmlElement("UpdateUserId", null, (int) $rowPost->update_user);
                $this->xmlElement("Censorship", null, (int) $rowPost->pos_cens);
                $this->xmlElement("CensorshipMessage", null, $rowPost->pos_cens_com);
                $this->xmlElement("Notification", null, $rowPost->notify);
                $this->xmlElement("ImportName", null, $rowPost->import_name);
                $this->xmlElement("Status", null, (int) $rowPost->pos_status);
                $this->xmlElement("Message", null, $rowPost->pos_message);
                $this->xmlElement("Lft", null, (int) $rowPost->lft);
                $this->xmlElement("Rgt", null, (int) $rowPost->rgt);
                $this->xmlElement("Depth", null, (int) $rowPost->depth);
                $this->xmlElement("ParentId", null, (int) $rowPost->parent_pos);
                $tmp_file_obj = new ilFileDataForum($this->forum_id, $rowPost->pos_pk);
                $set = array();
                if (count($tmp_file_obj->getFilesOfPost())) {
                    foreach ($tmp_file_obj->getFilesOfPost() as $file) {
                        $this->xmlStartTag("Attachment");
                        copy($file['path'], $this->target_dir_absolute . "/" . basename($file['path']));
                        $content = $this->target_dir_relative . "/" . basename($file['path']);
                        $this->xmlElement("Content", null, $content);
                        /*	$thumb = $tmp_file_obj->getThumbFilename($file);
                        			if($thumb)
                        			{
                        				copy($tmp_file_obj->getThumbPath().'/'.$thumb, $this->target_dir_absolute."/".$thumb);
                        				$contentThumb = $this->target_dir_relative."/".$thumb;
                        				$this->xmlElement("ContentThumbnail", null, $contentThumb);
                        			}*/
                        ++$i;
                        $this->xmlEndTag("Attachment");
                    }
                }
                //Used for nested postings
                //$lastDepth = $rowPost->depth;
                $this->xmlEndTag("Post");
            }
            /*
            			// Used for nested postings
            			if( $lastDepth )
            			{
            				for( $i = 1; $i <= $lastDepth ; $i++ )
            				{
            					$this->xmlEndTag("Post");
            				}
            
            				$lastDepth = null;
            			}*/
            $this->xmlEndTag("Thread");
        }
        $this->xmlEndTag("Forum");
        return true;
    }
Пример #6
0
    function sendForumNotifications($post_data)
    {
        global $ilDB, $ilAccess, $lng, $ilUser;
        include_once "Services/Mail/classes/class.ilMail.php";
        include_once './Services/User/classes/class.ilObjUser.php';
        // GET THREAD DATA
        $result = $ilDB->queryf('
			SELECT thr_subject FROM frm_threads 
			WHERE thr_pk = %s', array('integer'), array($post_data['pos_thr_fk']));
        while ($record = $ilDB->fetchAssoc($result)) {
            $post_data['thr_subject'] = $record['thr_subject'];
            break;
        }
        // determine obj_id of the forum
        $obj_id = self::_lookupObjIdForForumId($post_data['pos_top_fk']);
        // GET AUTHOR OF NEW POST
        if ($post_data['pos_usr_id']) {
            $post_data['pos_usr_name'] = ilObjUser::_lookupLogin($post_data['pos_usr_id']);
        } else {
            if (strlen($post_data['pos_usr_alias'])) {
                $post_data['pos_usr_name'] = $post_data['pos_usr_alias'] . ' (' . $lng->txt('frm_pseudonym') . ')';
            }
        }
        if ($post_data['pos_usr_name'] == '') {
            $post_data['pos_usr_name'] = $this->lng->txt('forums_anonymous');
        }
        // GET USERS WHO WANT TO BE INFORMED ABOUT NEW POSTS
        $res = $ilDB->queryf('
			SELECT frm_notification.user_id FROM frm_notification, frm_data 
			WHERE frm_data.top_pk = %s
			AND frm_notification.frm_id = frm_data.top_frm_fk 
			AND frm_notification.user_id <> %s
			GROUP BY frm_notification.user_id', array('integer', 'integer'), array($post_data['pos_top_fk'], $ilUser->getId()));
        // get all references of obj_id
        $frm_references = ilObject::_getAllReferences($obj_id);
        // save language of the current user
        global $lng;
        $userLanguage = $lng;
        // get attachments data
        $fileDataForum = new ilFileDataForum($obj_id, $post_data['pos_pk']);
        $filesOfPost = $fileDataForum->getFilesOfPost();
        $attachments = array();
        foreach ($filesOfPost as $attachment) {
            $attachments[] = $attachment['name'];
        }
        $mail_obj = new ilMail(ANONYMOUS_USER_ID);
        while ($row = $ilDB->fetchAssoc($res)) {
            // do rbac check before sending notification
            $send_mail = false;
            foreach ((array) $frm_references as $ref_id) {
                if ($ilAccess->checkAccessOfUser($row['user_id'], 'read', '', $ref_id)) {
                    $send_mail = true;
                    break;
                }
            }
            if ($send_mail) {
                $this->setLanguage(self::_getLanguageInstanceByUsrId($row['user_id']));
                $mail_obj->sendMail(ilObjUser::_lookupLogin($row["user_id"]), "", "", $this->formatNotificationSubject($post_data), $this->formatNotification($post_data, 0, $attachments, $row['user_id']), array(), array("system"));
            }
        }
        // reset language
        $this->setLanguage($userLanguage);
    }