/**
  * Export to HTML.
  *
  */
 function exportHTML()
 {
     global $lng, $tpl, $ilUser, $ilAccess, $ilias;
     if (!$ilAccess->checkAccess('read,visible', '', $_GET['ref_id'])) {
         $ilias->raiseError($lng->txt('permission_denied'), $ilias->error_obj->MESSAGE);
     }
     $tplEx = new ilTemplate('tpl.forums_export_html.html', true, true, 'Modules/Forum');
     // threads
     //for ($j = 0; $j < count($_POST['forum_id']); $j++)
     for ($j = 0; $j < count($_POST['thread_ids']); $j++) {
         //$objCurrentTopic = new ilForumTopic(addslashes($_POST['forum_id'][$j]), $ilAccess->checkAccess('moderate_frm', '', $_GET['ref_id']));
         $objCurrentTopic = new ilForumTopic(addslashes($_POST['thread_ids'][$j]), $ilAccess->checkAccess('moderate_frm', '', $_GET['ref_id']));
         // get forum- and thread-data
         $this->frm->setMDB2WhereCondition('top_pk = %s ', array('integer'), array($objCurrentTopic->getForumId()));
         if (is_array($frmData = $this->frm->getOneTopic())) {
             $objFirstPostNode = $objCurrentTopic->getFirstPostNode();
             $objCurrentTopic->setOrderField('frm_posts_tree.rgt');
             $postTree = $objCurrentTopic->getPostTree($objFirstPostNode);
             $posNum = count($postTree);
             $z = 0;
             foreach ($postTree as $post) {
                 $tplEx->setCurrentBlock('posts_row');
                 $rowCol = ilUtil::switchColor($z++, 'tblrow2', 'tblrow1');
                 $tplEx->setVariable('ROWCOL', $rowCol);
                 $authorinfo = new ilForumAuthorInformation($post->getUserId(), $post->getUserAlias(), $post->getImportName());
                 $tplEx->setVariable('AUTHOR', $authorinfo->getAuthorName());
                 if ($post->getUserId()) {
                     // get create- and update-dates
                     if ($post->getUpdateUserId()) {
                         $authorinfo = new ilForumAuthorInformation($post->getUpdateUserId(), '', '');
                         $tplEx->setVariable('POST_UPDATE', "<br />[" . $lng->txt('edited_on') . ": " . $this->frm->convertDate($post->getChangeDate()) . " - " . strtolower($lng->txt('from')) . " " . $authorinfo->getAuthorName() . "]");
                     }
                     if ($authorinfo->getAuthor()->getPref('public_profile') != 'n') {
                         $tplEx->setVariable('TXT_REGISTERED', $lng->txt('registered_since'));
                         $tplEx->setVariable('REGISTERED_SINCE', $this->frm->convertDate($authorinfo->getAuthor()->getCreateDate()));
                     }
                     if ($ilAccess->checkAccess('moderate_frm', '', $_GET['ref_id'])) {
                         $numPosts = $this->frm->countUserArticles($post->getUserId());
                     } else {
                         $numPosts = $this->frm->countActiveUserArticles($post->getUserId());
                     }
                     $tplEx->setVariable('TXT_NUM_POSTS', $lng->txt('forums_posts'));
                     $tplEx->setVariable('NUM_POSTS', $numPosts);
                 }
                 $tplEx->setVariable('SUBJECT', $post->getSubject());
                 $tplEx->setVariable('TXT_CREATE_DATE', $lng->txt('forums_thread_create_date'));
                 $tplEx->setVariable('POST_DATE', $this->frm->convertDate($post->getCreateDate()));
                 $tplEx->setVariable('SPACER', "<hr noshade width=\"100%\" size=\"1\" align=\"center\" />");
                 if ($post->isCensored()) {
                     $tplEx->setVariable('POST', nl2br(stripslashes($post->getCensorshipComment())));
                 } else {
                     /** @todo mjansen: possible bugfix for mantis #8223 */
                     if ($post->getMessage() == strip_tags($post->getMessage())) {
                         // We can be sure, that there are not html tags
                         $post->setMessage(nl2br($post->getMessage()));
                     }
                     $tplEx->setVariable('POST', ilRTE::_replaceMediaObjectImageSrc($this->frm->prepareText($post->getMessage(), 0, '', 'export'), 1));
                 }
                 $tplEx->parseCurrentBlock('posts_row');
                 unset($author);
             }
             // foreach ($postTree as $post)
             $tplEx->setCurrentBlock('posttable');
             $tplEx->setVariable('TXT_AUTHOR', $lng->txt('author'));
             $tplEx->setVariable('TXT_POST', $lng->txt('forums_thread') . ': ' . $objCurrentTopic->getSubject());
             $tplEx->parseCurrentBlock('posttable');
             // Thread Headline
             $tplEx->setCurrentBlock('thread_headline');
             $tplEx->setVariable('T_TITLE', $objCurrentTopic->getSubject());
             if ($ilAccess->checkAccess('moderate_frm', '', $_GET['ref_id'])) {
                 $tplEx->setVariable('T_NUM_POSTS', $objCurrentTopic->countPosts());
             } else {
                 $tplEx->setVariable('T_NUM_POSTS', $objCurrentTopic->countActivePosts());
             }
             $tplEx->setVariable('T_NUM_VISITS', $objCurrentTopic->getVisits());
             $tplEx->setVariable('T_FORUM', $frmData['top_name']);
             $authorinfo = new ilForumAuthorInformation($objCurrentTopic->getUserId(), $objCurrentTopic->getUserAlias(), $objCurrentTopic->getImportName());
             $tplEx->setVariable('T_AUTHOR', $authorinfo->getAuthorName());
             $tplEx->setVariable('T_TXT_FORUM', $lng->txt('forum') . ': ');
             $tplEx->setVariable('T_TXT_TOPIC', $lng->txt('forums_thread') . ': ');
             $tplEx->setVariable('T_TXT_AUTHOR', $lng->txt('forums_thread_create_from') . ': ');
             $tplEx->setVariable('T_TXT_NUM_POSTS', $lng->txt('forums_articles') . ': ');
             $tplEx->setVariable('T_TXT_NUM_VISITS', $lng->txt('visits') . ': ');
             $tplEx->parseCurrentBlock('thread_headline');
             $tplEx->setCurrentBlock('thread_block');
             $tplEx->parseCurrentBlock('thread_block');
             $tplEx->setCurrentBlock('forum_block');
             $tplEx->parseCurrentBlock('forum_block');
         }
         // if (is_array($frmData = $this->frm->getOneTopic()))
     }
     // for ($j = 0; $j < count($_POST["forum_id"]); $j++)
     ilUtil::deliverData($tplEx->get(), 'forum_html_export_' . $_GET['ref_id'] . '.html');
     exit;
 }
    /**
     * Moves all chosen threads and their posts to a new forum
     * 
     * @param    array	chosen thread pks
     * @param    integer	object id of src forum
     * @param    integer	object id of dest forum
     * @access	public
     */
    public function moveThreads($thread_ids = array(), $src_ref_id = 0, $dest_top_frm_fk = 0)
    {
        global $ilDB;
        $src_top_frm_fk = ilObject::_lookupObjectId($src_ref_id);
        if (is_numeric($src_top_frm_fk) && $src_top_frm_fk > 0 && is_numeric($dest_top_frm_fk) && $dest_top_frm_fk > 0) {
            $this->setMDB2WhereCondition('top_frm_fk = %s ', array('integer'), array($src_top_frm_fk));
            $oldFrmData = $this->getOneTopic();
            $this->setMDB2WhereCondition('top_frm_fk = %s ', array('integer'), array($dest_top_frm_fk));
            $newFrmData = $this->getOneTopic();
            if ($oldFrmData['top_pk'] && $newFrmData['top_pk']) {
                $moved_posts = 0;
                $moved_threads = 0;
                $visits = 0;
                foreach ($thread_ids as $id) {
                    $objTmpThread = new ilForumTopic($id);
                    $numPosts = $objTmpThread->movePosts($src_top_frm_fk, $oldFrmData['top_pk'], $dest_top_frm_fk, $newFrmData['top_pk']);
                    if (($last_post_string = $objTmpThread->getLastPostString()) != '') {
                        $last_post_string = explode('#', $last_post_string);
                        $last_post_string[0] = $newFrmData['top_pk'];
                        $last_post_string = implode('#', $last_post_string);
                        $objTmpThread->setLastPostString($last_post_string);
                    }
                    $visits += $objTmpThread->getVisits();
                    $moved_posts += $numPosts;
                    ++$moved_threads;
                    $objTmpThread->setForumId($newFrmData['top_pk']);
                    $objTmpThread->update();
                    unset($objTmpThread);
                }
                // update frm_data source forum
                $ilDB->setLimit(1);
                $res = $ilDB->queryf('
					SELECT pos_thr_fk, pos_pk 
					FROM frm_posts						  
					WHERE pos_top_fk = %s
					ORDER BY pos_date DESC', array('integer'), array($oldFrmData['top_pk']));
                $row = $ilDB->fetchObject($res);
                $last_post_src = $oldFrmData['top_pk'] . '#' . $row->pos_thr_fk . '#' . $row->pos_pk;
                $statement = $ilDB->manipulateF('
					UPDATE frm_data
					SET top_num_posts = top_num_posts - %s,
						top_num_threads = top_num_threads - %s,
						visits = visits - %s,
						top_last_post = %s
					WHERE top_pk = %s', array('integer', 'integer', 'integer', 'text', 'integer'), array($moved_posts, $moved_threads, $visits, $last_post_src, $oldFrmData['top_pk']));
                // update frm_data destination forum
                $ilDB->setLimit(1);
                $res = $ilDB->queryf('
					SELECT pos_thr_fk, pos_pk 
				 	FROM frm_posts						  
					WHERE pos_top_fk = %s
					ORDER BY pos_date DESC', array('integer'), array($newFrmData['top_kp']));
                $row = $ilDB->fetchObject($res);
                $last_post_dest = $newFrmData['top_pk'] . '#' . $row->pos_thr_fk . '#' . $row->pos_pk;
                $statement = $ilDB->manipulateF('
					UPDATE frm_data
					SET top_num_posts = top_num_posts + %s,
						top_num_threads = top_num_threads + %s,
						visits = visits + %s,
						top_last_post = %s
						WHERE top_pk = %s', array('integer', 'integer', 'integer', 'text', 'integer'), array($moved_posts, $moved_threads, $visits, $last_post_dest, $newFrmData['top_pk']));
                /*
                // update news items
                include_once("./Services/News/classes/class.ilNewsItem.php");
                $objNewsItem = new ilNewsItem();
                $news_items = $objNewsItem->getNewsForRefId($src_ref_id);
                foreach ($news_items as $news_item)
                {
                	$tmpObjNewsItem = new ilNewsItem($news_item['id']);
                	if ($tmpObjNewsItem->getContextObjId() == $src_top_frm_fk)
                	{
                		$tmpObjNewsItem->setContextObjId($dest_top_frm_fk);
                		$tmpObjNewsItem->update();
                	}
                	unset($tmpObjNewsItem);
                }
                */
            }
        }
    }
 /**
  * @param ilForumTopic $thread
  */
 public function fillRow(ilForumTopic $thread)
 {
     /**
      * @var $ilUser ilObjUser
      */
     global $ilUser;
     $this->ctrl->setParameter($this->getParentObject(), 'thr_pk', $thread->getId());
     if ('mergeThreads' == $this->parent_cmd) {
         $checked = $this->max_count == 1 || isset($_POST['thread_ids']) && in_array($thread->getId(), $_POST['thread_ids']);
         $this->tpl->setVariable('VAL_CHECK', ilUtil::formRadioButton($checked, 'thread_ids[]', $thread->getId()));
     } else {
         if ('showThreads' == $this->parent_cmd) {
             $this->tpl->setVariable('VAL_CHECK', ilUtil::formCheckbox(isset($_POST['thread_ids']) && in_array($thread->getId(), $_POST['thread_ids']) ? true : false, 'thread_ids[]', $thread->getId()));
         } else {
             if ($thread->isSticky()) {
                 $this->tpl->setVariable('VAL_SORTING_NAME', 'thread_sorting[' . $thread->getId() . ']');
                 $this->tpl->setVariable('VAL_SORTING', (int) $this->position * 10);
             } else {
                 $this->tpl->setVariable('VAL_CHECK', '');
             }
             $this->position++;
         }
     }
     $subject = '';
     if ($thread->isSticky()) {
         $subject .= '<span class="light">[' . $this->lng->txt('sticky') . ']</span> ';
     }
     if ($thread->isClosed()) {
         $subject .= '<span class="light">[' . $this->lng->txt('topic_close') . ']</span> ';
     }
     if (!$ilUser->isAnonymous() && $this->ilias->getSetting('forum_notification') != 0 && $thread->getUserNotificationEnabled()) {
         $subject .= '<span class="light">[' . $this->lng->txt('forums_notification_enabled') . ']</span> ';
     }
     $num_posts = $thread->getNumPosts();
     $num_unread = $thread->getNumUnreadPosts();
     $num_new = $thread->getNumNewPosts();
     if ($num_posts > 0) {
         $subject = '<div><a href="' . $this->ctrl->getLinkTarget($this->getParentObject(), 'viewThread') . '">' . $thread->getSubject() . '</a></div>' . $subject;
     } else {
         $subject = $thread->getSubject() . $subject;
     }
     $this->tpl->setVariable('VAL_SUBJECT', $subject);
     // Author
     $this->ctrl->setParameter($this->getParentObject(), 'backurl', urlencode($this->ctrl->getLinkTargetByClass("ilrepositorygui", "")));
     $this->ctrl->setParameter($this->getParentObject(), 'user', $thread->getUserId());
     $authorinfo = new ilForumAuthorInformation($thread->getUserId(), $thread->getUserAlias(), $thread->getImportName(), array('class' => 'il_ItemProperty', 'href' => $this->ctrl->getLinkTarget($this->getParentObject(), 'showUser')));
     $this->tpl->setVariable('VAL_AUTHOR', $authorinfo->getLinkedAuthorName());
     $topicStats = $num_posts;
     if (!$ilUser->isAnonymous()) {
         if ($num_unread > 0) {
             $topicStats .= '<br /><span class="alert ilWhiteSpaceNowrap">' . $this->lng->txt('unread') . ': ' . $num_unread . '</span>';
         }
         if ($num_new > 0 && $this->getOverviewSetting() == 0) {
             $topicStats .= '<br /><span class="alert ilWhiteSpaceNowrap">' . $this->lng->txt('new') . ': ' . $num_new . '</span>';
         }
     }
     $this->tpl->setVariable('VAL_ARTICLE_STATS', $topicStats);
     $this->tpl->setVariable('VAL_NUM_VISIT', $thread->getVisits());
     // Last posting
     if ($num_posts > 0) {
         if ($this->getIsModerator()) {
             $objLastPost = $thread->getLastPost();
         } else {
             $objLastPost = $thread->getLastActivePost();
         }
         if (is_object($objLastPost)) {
             $authorinfo = new ilForumAuthorInformation($objLastPost->getUserId(), $objLastPost->getUserAlias(), $objLastPost->getImportName(), array('href' => $this->ctrl->getLinkTarget($this->getParentObject(), 'viewThread') . '#' . $objLastPost->getId()));
             $this->tpl->setVariable('VAL_LP_DATE', '<div class="ilWhiteSpaceNowrap">' . ilDatePresentation::formatDate(new ilDateTime($objLastPost->getCreateDate(), IL_CAL_DATETIME)) . '</div>' . '<div class="ilWhiteSpaceNowrap">' . $this->lng->txt('from') . ' ' . $authorinfo->getLinkedAuthorName() . '</div>');
         }
     }
     // Row style
     $css_row = $this->css_row;
     if ($thread->isSticky()) {
         $css_row = $css_row == 'tblrow1' ? 'tblstickyrow1' : 'tblstickyrow2';
     }
     $this->tpl->setVariable('CSS_ROW', $css_row);
     $this->ctrl->setParameter($this->getParentObject(), 'thr_pk', '');
     $this->ctrl->setParameter($this->getParentObject(), 'user', '');
     $this->ctrl->setParameter($this->getParentObject(), 'backurl', '');
 }
 /**
  * 
  */
 public function exportHTML()
 {
     /**
      * @var $tpl      ilTemplate
      * @var $lng      ilLanguage
      * @var $ilAccess ilAccessHandler
      * @var $ilias    ILIAS
      */
     global $lng, $tpl, $ilAccess, $ilias;
     if (!$ilAccess->checkAccess('read,visible', '', $_GET['ref_id'])) {
         $ilias->raiseError($lng->txt('permission_denied'), $ilias->error_obj->MESSAGE);
     }
     ilDatePresentation::setUseRelativeDates(false);
     $tpl = new ilTemplate('tpl.forums_export_html.html', true, true, 'Modules/Forum');
     $location_stylesheet = ilUtil::getStyleSheetLocation();
     $tpl->setVariable('LOCATION_STYLESHEET', $location_stylesheet);
     $tpl->setVariable('BASE', substr(ILIAS_HTTP_PATH, -1) == '/' ? ILIAS_HTTP_PATH : ILIAS_HTTP_PATH . '/');
     $num_threads = count((array) $_POST['thread_ids']);
     for ($j = 0; $j < $num_threads; $j++) {
         $topic = new ilForumTopic((int) $_POST['thread_ids'][$j], $this->is_moderator);
         $this->frm->setMDB2WhereCondition('top_pk = %s ', array('integer'), array($topic->getForumId()));
         if (is_array($thread_data = $this->frm->getOneTopic())) {
             if (0 == $j) {
                 $tpl->setVariable('TITLE', $thread_data['top_name']);
             }
             $first_post = $topic->getFirstPostNode();
             $topic->setOrderField('frm_posts_tree.rgt');
             $post_collection = $topic->getPostTree($first_post);
             $z = 0;
             foreach ($post_collection as $post) {
                 $this->renderPostHtml($tpl, $post, $z++, self::MODE_EXPORT_CLIENT);
             }
             $tpl->setCurrentBlock('thread_headline');
             $tpl->setVariable('T_TITLE', $topic->getSubject());
             if ($this->is_moderator) {
                 $tpl->setVariable('T_NUM_POSTS', $topic->countPosts());
             } else {
                 $tpl->setVariable('T_NUM_POSTS', $topic->countActivePosts());
             }
             $tpl->setVariable('T_NUM_VISITS', $topic->getVisits());
             $tpl->setVariable('T_FORUM', $thread_data['top_name']);
             $authorinfo = new ilForumAuthorInformation($topic->getThrAuthorId(), $topic->getDisplayUserId(), $topic->getUserAlias(), $topic->getImportName());
             $tpl->setVariable('T_AUTHOR', $authorinfo->getAuthorName());
             $tpl->setVariable('T_TXT_FORUM', $lng->txt('forum') . ': ');
             $tpl->setVariable('T_TXT_TOPIC', $lng->txt('forums_thread') . ': ');
             $tpl->setVariable('T_TXT_AUTHOR', $lng->txt('forums_thread_create_from') . ': ');
             $tpl->setVariable('T_TXT_NUM_POSTS', $lng->txt('forums_articles') . ': ');
             $tpl->setVariable('T_TXT_NUM_VISITS', $lng->txt('visits') . ': ');
             $tpl->parseCurrentBlock();
         }
         $tpl->setCurrentBlock('thread_block');
         $tpl->parseCurrentBlock();
     }
     ilUtil::deliverData($tpl->get('DEFAULT', false, false, false, true, false, false), 'forum_html_export_' . $_GET['ref_id'] . '.html');
 }