Example #1
0
function message()
{
    checkPerm('view');
    require_once _base_ . '/lib/lib.table.php';
    require_once _base_ . '/lib/lib.form.php';
    require_once _base_ . '/lib/lib.user_profile.php';
    require_once $GLOBALS['where_framework'] . '/lib/lib.tags.php';
    $tags = new Tags('lms_forum');
    $tags->setupJs('a[id^=handler-tags-]', 'a[id^=private-handler-tags-]');
    require_once _base_ . '/lib/lib.dialog.php';
    setupHrefDialogBox('a[href*=delmessage]');
    $lang =& DoceboLanguage::createInstance('forum', 'lms');
    $id_thread = importVar('idThread', true, 0);
    $sema_perm = checkPerm('sema', true);
    $moderate = checkPerm('moderate', true);
    $mod_perm = checkPerm('mod', true);
    $write_perm = checkPerm('write', true);
    $acl_man =& Docebo::user()->getAclManager();
    $profile_man = new UserProfile(0);
    $profile_man->init('profile', 'framework', 'index.php?modname=forum&op=forum');
    $tb = new Table(Get::sett('visuItem'), $lang->def('_CAPTION_FORUM_MESSAGE'), $lang->def('_CAPTION_FORUM_MESSAGE'));
    $tb->initNavBar('ini', 'link');
    $tb->setLink('index.php?modname=forum&op=message&idThread=' . $id_thread);
    $ini = $tb->getSelectedElement();
    $ini_page = $tb->getSelectedPage();
    $first_unread_message = importVar('firstunread', true, 0);
    $ini_first_unread_message = importVar('ini', true, 0);
    $set_important = importVar('important', true, 0);
    if ($set_important == 1) {
        $query_set_important = "UPDATE " . $GLOBALS['prefix_lms'] . "_forumthread" . " SET rilevantForum = 1" . " WHERE idThread = '" . $id_thread . "'";
        $result_set_important = sql_query($query_set_important);
    }
    if ($set_important == 2) {
        $query_set_important = "UPDATE " . $GLOBALS['prefix_lms'] . "_forumthread" . " SET rilevantForum = 0" . " WHERE idThread = '" . $id_thread . "'";
        $result_set_important = sql_query($query_set_important);
    }
    // Some info about forum and thread
    $thread_query = "\r\n\tSELECT idForum, title, num_post, locked, erased, rilevantForum\r\n\tFROM " . $GLOBALS['prefix_lms'] . "_forumthread\r\n\tWHERE idThread = '" . $id_thread . "'";
    list($id_forum, $thread_title, $tot_message, $locked_t, $erased_t, $is_important) = sql_fetch_row(sql_query($thread_query));
    $forum_query = "\r\n\tSELECT title, locked\r\n\tFROM " . $GLOBALS['prefix_lms'] . "_forum\r\n\tWHERE idForum = '" . $id_forum . "'";
    list($forum_title, $locked_f) = sql_fetch_row(sql_query($forum_query));
    ++$tot_message;
    //set as readed if needed
    if (isset($_SESSION['unreaded_forum'][$_SESSION['idCourse']][$id_forum][$id_thread])) {
        unset($_SESSION['unreaded_forum'][$_SESSION['idCourse']][$id_forum][$id_thread]);
    }
    if ($ini == 0 && !isset($_GET['result'])) {
        sql_query("\r\n\t\tUPDATE " . $GLOBALS['prefix_lms'] . "_forumthread\r\n\t\tSET num_view = num_view + 1\r\n\t\tWHERE idThread = '" . $id_thread . "'");
    }
    $page_title = array('index.php?modname=forum&op=forum' => $lang->def('_FORUM'), 'index.php?modname=forum&op=thread&idForum=' . $id_forum => $forum_title, $thread_title);
    if ($erased_t && !$mod_perm && !$moderate) {
        $GLOBALS['page']->add(getTitleArea($page_title, 'forum') . '<div class="std_block">' . $lang->def('_CANNOTENTER') . '</div>', 'content');
        return;
    }
    // Who have semantic evaluation
    $re_sema = sql_query("\r\n\tSELECT DISTINCT idmsg\r\n\tFROM " . $GLOBALS['prefix_lms'] . "_forum_sema");
    while (list($msg_sema) = sql_fetch_row($re_sema)) {
        $forum_sema[$msg_sema] = 1;
    }
    // Find post
    $messages = array();
    $authors = array();
    $authors_names = array();
    $authors_info = array();
    $re_message = sql_query("\r\n\tSELECT idMessage, posted, title, textof, attach, locked, author, modified_by, modified_by_on\r\n\tFROM " . $GLOBALS['prefix_lms'] . "_forummessage\r\n\tWHERE idThread = '" . $id_thread . "'\r\n\tORDER BY posted\r\n\tLIMIT {$ini}, " . Get::sett('visuItem'));
    while ($record = mysql_fetch_assoc($re_message)) {
        $messages[$record['idMessage']] = $record;
        $authors[$record['author']] = $record['author'];
        if ($record['modified_by'] != 0) {
            $authors[$record['modified_by']] = $record['modified_by'];
        }
        $tag_resource_list[] = $record['idMessage'];
    }
    $authors_names =& $acl_man->getUsers($authors);
    $level_name = CourseLevel::getLevels();
    //tags
    $tags->loadResourcesTags($tag_resource_list);
    // Retriving level and number of post of the authors
    if (!empty($authors)) {
        $re_num_post = sql_query("\r\n\t\tSELECT u.idUser, u.level, COUNT(*)\r\n\t\tFROM " . $GLOBALS['prefix_lms'] . "_forummessage AS m, " . $GLOBALS['prefix_lms'] . "_courseuser AS u\r\n\t\tWHERE u.idCourse = '" . (int) $_SESSION['idCourse'] . "' AND m.author = u.idUser AND m.author IN ( " . implode($authors, ',') . " )\r\n\t\tGROUP BY u.idUser, u.level");
        while (list($id_u, $level_u, $num_post_a) = sql_fetch_row($re_num_post)) {
            $authors_info[$id_u] = array('num_post' => $num_post_a, 'level' => $level_name[$level_u]);
        }
        $profile_man->setCahceForUsers($authors);
    }
    $type_h = array('forum_sender', 'forum_text');
    $cont_h = array($lang->def('_AUTHOR'), $lang->def('_TEXTOF'));
    $tb->setColsStyle($type_h);
    $tb->addHead($cont_h);
    // Compose messagges display
    $path = $GLOBALS['where_files_relative'] . '/appCore/' . Get::sett('pathphoto');
    $counter = 0;
    while (list($id_message, $message_info) = each($messages)) {
        $counter++;
        // sender info
        $m_author = $message_info['author'];
        //if(isset($authors_names[$m_author]) && $authors_names[$m_author][ACL_INFO_AVATAR] != '') $img_size = @getimagesize($path.$authors_names[$m_author][ACL_INFO_AVATAR]);
        $profile_man->setIdUser($m_author);
        $author = $profile_man->getUserPanelData(false, 'normal');
        $sender = '';
        $sender = '<div class="forum_author">';
        $sender .= $author['actions'] . $author['display_name'] . (isset($authors_info[$m_author]) ? '<div class="forum_level">' . $authors_info[$m_author]['level'] . '</div>' : '') . '<br/>' . $author['avatar'] . '<div class="forum_numpost">' . $lang->def('_NUMPOST') . ' : ' . (isset($authors_info[$m_author]['num_post']) ? $authors_info[$m_author]['num_post'] : 0) . '</div>' . '<a class="ico-wt-sprite subs_user" href="index.php?modname=forum&amp;op=viewprofile&amp;idMessage=' . $id_message . '&amp;ini=' . $ini_page . '&amp;idThread=' . $id_thread . '">' . '<span>' . $lang->def('_VIEW_PROFILE') . '</span></a>';
        /*.( isset($authors_names[$m_author]) && $authors_names[$m_author][ACL_INFO_AVATAR] != ''
        		? '<img class="forum_avatar'.( $img_size[0] > 150 || $img_size[1] > 150 ? ' image_limit' : '' ).'" src="'.$path.$authors_names[$m_author][ACL_INFO_AVATAR].'" alt="'.$lang->def('_AVATAR').'" />'
        		: '' )*/
        /*
        .( isset($authors_names[$m_author])
        	?( $authors_names[$m_author][ACL_INFO_LASTNAME].$authors_names[$m_author][ACL_INFO_FIRSTNAME] == '' ?
        		$acl_man->relativeId($authors_names[$m_author][ACL_INFO_USERID]) :
        		$authors_names[$m_author][ACL_INFO_LASTNAME].' '.$authors_names[$m_author][ACL_INFO_FIRSTNAME] )
        	: $lang->def('_UNKNOWN_AUTHOR') )
        */
        /*.'<img src="'.getPathImage().'standard/identity.png" alt="&gt;" />&nbsp;'
        			.'<a href="index.php?modname=forum&amp;op=viewprofile&amp;idMessage='.$id_message.'&amp;ini='.$ini_page.'">'.$lang->def('_VIEW_PROFILE').'</a>';
        		*/
        // msg info
        $msgtext = '';
        if ($counter == $first_unread_message) {
            $msgtext .= '<a name="firstunread"></a><div class="forum_post_posted">';
        } else {
            $msgtext .= '<div class="forum_post_posted">';
        }
        $msgtext .= '<a id="' . $id_message . '" name="' . $id_message . '"></a>';
        $msgtext .= $lang->def('_DATE') . ' : ' . Format::date($message_info['posted']) . ' ( ' . loadDistance($message_info['posted']) . ' )' . '</div>';
        if ($message_info['locked']) {
            $msgtext .= '<div class="forum_post_locked">' . $lang->def('_LOCKEDMESS') . '</div>';
        } else {
            if ($message_info['attach'] != '') {
                $msgtext .= '<div class="forum_post_attach">' . '<a href="index.php?modname=forum&amp;op=download&amp;id=' . $id_message . '">' . $lang->def('_ATTACHMENT') . ' : ' . '<img src="' . getPathImage() . mimeDetect($message_info['attach']) . '" alt="' . $lang->def('_ATTACHMENT') . '" /></a>' . '</div>';
            }
            $msgtext .= '<div class="forum_post_title">' . $lang->def('_SUBJECT') . ' : ' . $message_info['title'] . '</div>';
            $msgtext .= '<div class="forum_post_text">' . str_replace('[quote]', '<blockquote class="forum_quote">', str_replace('[/quote]', '</blockquote>', $message_info['textof'])) . '</div>';
            if ($message_info['modified_by'] != 0) {
                $modify_by = $message_info['modified_by'];
                $msgtext .= '<div class="forum_post_modified_by">' . $lang->def('_MODIFY_BY') . ' : ' . (isset($authors_names[$m_author]) ? $authors_names[$modify_by][ACL_INFO_LASTNAME] . $authors_names[$modify_by][ACL_INFO_FIRSTNAME] == '' ? $acl_man->relativeId($authors_names[$modify_by][ACL_INFO_USERID]) : $authors_names[$modify_by][ACL_INFO_LASTNAME] . ' ' . $authors_names[$modify_by][ACL_INFO_FIRSTNAME] : $lang->def('_UNKNOWN_AUTHOR')) . ' ' . $lang->def('_ON') . ' : ' . Format::date($message_info['modified_by_on']) . '</div>';
            }
            if (isset($authors_names[$m_author]) && $authors_names[$m_author][ACL_INFO_SIGNATURE] != '') {
                $msgtext .= '<div class="forum_post_sign_separator"></div>' . '<div class="forum_post_sign">' . $authors_names[$m_author][ACL_INFO_SIGNATURE] . '</div>';
            }
            $strip_text = strip_tags($message_info['textof']);
            $msgtext .= '<div class="tags align-right">' . $tags->showTags($id_message, 'tags-', $message_info['title'], substr($strip_text, 0, 200) . (strlen($strip_text) > 200 ? '...' : ''), 'index.php?modname=forum&op=message&idThread=' . $id_thread . '&ini=' . $ini_page . '#' . $id_message) . '</div>';
        }
        $content = array($sender, $msgtext);
        $tb->addBody($content);
        // some action that you can do with this message
        $action = '';
        /*if($sema_perm) {
        			if(isset($forum_sema[$id_message])) $img_sema = 'sema_check';
        			else $img_sema = 'sema';
        			$action .= '<a href="index.php?modname=forum&amp;op=editsema&amp;idMessage='.$id_message.'&amp;ini='.$ini_page.'" '
        					.'title="'.$lang->def('_MOD').' : '.strip_tags($message_info['title']).'">'
        				.'<img src="'.getPathImage().'forum/'.$img_sema.'.gif" alt="'.$lang->def('_MOD').' : '.strip_tags($message_info['title']).'" /> '
        				.$lang->def('_SEMATAG').'</a> ';
        		}*/
        if ($moderate || $mod_perm) {
            if ($message_info['locked']) {
                $action .= '<a href="index.php?modname=forum&amp;op=moderatemessage&amp;idMessage=' . $id_message . '&amp;ini=' . $ini_page . '" ' . 'title="' . $lang->def('_DEMODERATE') . ' : ' . strip_tags($message_info['title']) . '">' . '<img src="' . getPathImage() . 'standard/demoderate.png" alt="' . $lang->def('_DEMODERATE') . ' : ' . strip_tags($message_info['title']) . '" /> ' . $lang->def('_DEMODERATE') . '</a> ';
            } else {
                $action .= '<a href="index.php?modname=forum&amp;op=moderatemessage&amp;idMessage=' . $id_message . '&amp;ini=' . $ini_page . '" ' . 'title="' . $lang->def('_MODERATE') . ' : ' . strip_tags($message_info['title']) . '">' . '<img src="' . getPathImage() . 'standard/moderate.png" alt="' . $lang->def('_MODERATE') . ' : ' . strip_tags($message_info['title']) . '" /> ' . $lang->def('_MODERATE') . '</a> ';
            }
        }
        if (!$locked_t && !$locked_f && !$message_info['locked'] && $write_perm) {
            $action .= '<a href="index.php?modname=forum&amp;op=addmessage&amp;idThread=' . $id_thread . '&amp;idMessage=' . $id_message . '&amp;ini=' . $ini_page . '" ' . 'title="' . $lang->def('_REPLY') . ' : ' . strip_tags($message_info['title']) . '">' . '<img src="' . getPathImage() . 'standard/reply.png" alt="' . $lang->def('_REPLY') . ' : ' . strip_tags($message_info['title']) . '" /> ' . $lang->def('_QUOTE') . '</a>';
        }
        if ($moderate || $mod_perm || $m_author == getLogUserId()) {
            $action .= '<a href="index.php?modname=forum&amp;op=modmessage&amp;idMessage=' . $id_message . '&amp;ini=' . $ini_page . '" ' . 'title="' . $lang->def('_MOD_MESSAGE') . ' : ' . strip_tags($message_info['title']) . '">' . '<img src="' . getPathImage() . 'standard/edit.png" alt="' . $lang->def('_MOD') . ' : ' . strip_tags($message_info['title']) . '" /> ' . $lang->def('_MOD') . '</a>' . '<a href="index.php?modname=forum&amp;op=delmessage&amp;idMessage=' . $id_message . '&amp;ini=' . $ini_page . '" ' . 'title="' . $lang->def('_DEL') . ' : ' . strip_tags($message_info['title']) . '">' . '<img src="' . getPathImage() . 'standard/delete.png" alt="' . $lang->def('_DEL') . ' : ' . strip_tags($message_info['title']) . '" /> ' . $lang->def('_DEL') . '</a> ';
        }
        $tb->addBodyExpanded($action, 'forum_action');
    }
    $GLOBALS['page']->add(getTitleArea($page_title, 'forum') . '<div class="std_block">' . Form::openForm('search_forum', 'index.php?modname=forum&amp;op=search&amp;idThread=' . $id_thread) . '<div class="quick_search_form">' . '<label for="search_arg">' . $lang->def('_SEARCH_LABEL') . '</label> ' . Form::getInputTextfield('search_t', 'search_arg', 'search_arg', '', $lang->def('_SEARCH'), 255, '') . '<input class="search_b" type="submit" id="search_button" name="search_button" value="' . $lang->def('_SEARCH') . '" />' . '</div>' . Form::closeForm(), 'content');
    // NOTE: If notify request register it
    require_once $GLOBALS['where_framework'] . '/lib/lib.usernotifier.php';
    $can_notify = usernotifier_getUserEventStatus(getLogUserId(), 'ForumNewResponse');
    if (isset($_GET['notify']) && $can_notify) {
        if (issetNotify('thread', $id_thread, getLogUserId())) {
            $re = unsetNotify('thread', $id_thread, getLogUserId());
            $is_notify = !$re;
        } else {
            $re = setNotify('thread', $id_thread, getLogUserId());
            $is_notify = $re;
        }
        if ($re) {
            $GLOBALS['page']->add(getResultUi($lang->def('_NOTIFY_CHANGE_STATUS_CORRECT')), 'content');
        } else {
            $GLOBALS['page']->add(getErrorUi($lang->def('_NOTIFY_CHANGE_STATUS_FAILED')), 'content');
        }
    } elseif ($can_notify) {
        $is_notify = issetNotify('thread', $id_thread, getLogUserId());
    }
    $text_inner = '';
    if (!$locked_t && !$locked_f && $write_perm) {
        $text_inner .= '<a href="index.php?modname=forum&amp;op=addmessage&amp;idThread=' . $id_thread . '&amp;ini=' . $ini_page . '" title="' . $lang->def('_REPLY') . '" class="ico-wt-sprite subs_add">' . '<span>' . $lang->def('_REPLY') . '</span></a>';
    }
    if ($can_notify) {
        $text_inner .= '<a href="index.php?modname=forum&amp;op=message&amp;notify=1&amp;idThread=' . $id_thread . '&amp;ini=' . $ini_page . '" ' . (!$is_notify ? 'class="ico-wt-sprite fd_notice"><span>' . $lang->def('_NOTIFY_ME_FORUM') . '</span></a> ' : 'class="ico-wt-sprite fd_error"><span>' . $lang->def('_UNNOTIFY_ME_FORUM') . '</span></a> ') . '';
    }
    if ($moderate) {
        $text_inner .= ' <a href="index.php?modname=forum&amp;op=modstatusthread&amp;idThread=' . $id_thread . '&amp;ini=' . $ini_page . '">' . ($locked_t ? '<img src="' . getPathImage() . 'standard/msg_read.png" alt="' . $lang->def('_FREE') . '" /> ' . $lang->def('_FREETHREAD') : '<img src="' . getPathImage() . 'standard/locked.png" alt="' . $lang->def('_LOCKTHREAD') . '" /> ' . $lang->def('_LOCKTHREAD')) . '</a>';
    }
    if ($mod_perm) {
        $text_inner .= ' <a href="index.php?modname=forum&amp;op=changeerased&amp;idThread=' . $id_thread . '&amp;ini=' . $ini_page . '">' . ($erased_t ? '<img src="' . getPathImage() . 'standard/msg_read.png" alt="' . $lang->def('_UNERASE') . '" /> ' . $lang->def('_UNERASE') : '<img src="' . getPathImage() . 'standard/moderate.png" alt="' . $lang->def('_MODERATE') . '" /> ' . $lang->def('_MODERATE')) . '</a>';
    }
    if (checkPerm('moderate', true) || checkPerm('mod', true)) {
        if ($is_important) {
            $text_inner .= ' <a href="index.php?modname=forum&op=message&amp;idThread=' . $id_thread . '&amp;ini=' . $ini_page . '&amp;important=2"><img src="' . getPathImage() . 'standard/notimportant.png" alt="' . $lang->def('_SET_NOT_IMPORTANT_THREAD') . '" /> ' . $lang->def('_SET_NOT_IMPORTANT_THREAD') . '</a>';
        } else {
            $text_inner .= ' <a href="index.php?modname=forum&op=message&amp;idThread=' . $id_thread . '&amp;ini=' . $ini_page . '&amp;important=1"><img src="' . getPathImage() . 'standard/important.png" alt="' . $lang->def('_MARK_AS_IMPORTANT') . '" /> ' . $lang->def('_MARK_AS_IMPORTANT') . '</a>';
        }
    }
    if ($text_inner != '') {
        $tb->addActionAdd($text_inner);
    }
    $GLOBALS['page']->add($tb->getNavBar($ini, $tot_message), 'content');
    $GLOBALS['page']->add($tb->getTable(), 'content');
    $GLOBALS['page']->add($tb->getNavBar($ini, $tot_message) . '</div>', 'content');
}