function forumsearch() { checkPerm('view'); if (isset($_POST['search_arg'])) { $_SESSION['forum']['search_arg'] = $_POST['search_arg']; $search_arg = importVar('search_arg'); } else { $search_arg = $_SESSION['forum']['search_arg']; } $ord = importVar('ord'); $mod_perm = checkPerm('mod', true); require_once _base_ . '/lib/lib.table.php'; require_once _base_ . '/lib/lib.navbar.php'; require_once _base_ . '/lib/lib.form.php'; $lang =& DoceboLanguage::createInstance('forum'); $acl_man =& Docebo::user()->getAclManager(); if ($mod_perm) { $query_view_forum = "\r\n\t\tSELECT DISTINCT idForum\r\n\t\tFROM " . $GLOBALS['prefix_lms'] . "_forum\r\n\t\tWHERE idCourse = '" . (int) $_SESSION['idCourse'] . "'"; } else { $acl =& Docebo::user()->getAcl(); $all_user_idst = $acl->getSTGroupsST(getLogUserId()); $all_user_idst[] = getLogUserId(); $query_view_forum = "\r\n\t\tSELECT DISTINCT f.idForum\r\n\t\tFROM " . $GLOBALS['prefix_lms'] . "_forum AS f\r\n\t\t\tLEFT JOIN " . $GLOBALS['prefix_lms'] . "_forum_access AS fa ON ( f.idForum = fa.idForum )\r\n\t\tWHERE f.idCourse = '" . (int) $_SESSION['idCourse'] . "' AND\r\n\t\t\t( fa.idMember IS NULL OR fa.idMember IN (" . implode($all_user_idst, ',') . " ) ) "; } $forums = array(); $re_forum = sql_query($query_view_forum); while (list($id_f) = sql_fetch_row($re_forum)) { $forums[] = $id_f; } if (empty($forums)) { $page_title = array('index.php?modname=forum&op=forum' => $lang->def('_FORUM'), $lang->def('_SEARCH_RESULT_FOR') . ' : ' . $search_arg); $GLOBALS['page']->add(getTitleArea($page_title, 'forum') . '<div class="std_block">' . $lang->def('_NO_PLACEFORSEARCH') . '</div>', 'content'); } $query_num_thread = "\r\n\tSELECT COUNT(DISTINCT t.idThread)\r\n\tFROM " . $GLOBALS['prefix_lms'] . "_forumthread AS t JOIN\r\n\t\t\t" . $GLOBALS['prefix_lms'] . "_forummessage AS m\r\n\tWHERE t.idThread = m.idThread AND t.idForum IN ( " . implode($forums, ',') . " )\r\n\t\tAND ( m.title LIKE '%" . $search_arg . "%' OR m.textof LIKE '%" . $search_arg . "%' ) "; list($tot_thread) = sql_fetch_row(sql_query($query_num_thread)); $jump_url = 'index.php?modname=forum&op=search'; $nav_bar = new NavBar('ini', Get::sett('visuItem'), $tot_thread, 'link'); $nav_bar->setLink($jump_url . '&ord=' . $ord); $ini = $nav_bar->getSelectedElement(); $ini_page = $nav_bar->getSelectedPage(); $query_thread = "\r\n\tSELECT DISTINCT t.idThread, t.idForum, t.author AS thread_author, t.posted, t.title, t.num_post, t.num_view, t.locked, t.erased\r\n\tFROM " . $GLOBALS['prefix_lms'] . "_forumthread AS t JOIN\r\n\t\t\t" . $GLOBALS['prefix_lms'] . "_forummessage AS m\r\n\tWHERE t.idThread = m.idThread AND t.idForum IN ( " . implode($forums, ',') . " )\r\n\t\tAND ( m.title LIKE '%" . $search_arg . "%' OR m.textof LIKE '%" . $search_arg . "%' ) "; switch ($ord) { case "obji": $query_thread .= " ORDER BY t.title DESC "; break; case "obj": $query_thread .= " ORDER BY t.title "; break; case "authi": $query_thread .= " ORDER BY t.author DESC "; break; case "auth": $query_thread .= " ORDER BY t.author "; break; case "posti": $query_thread .= " ORDER BY m.posted "; break; case "post": default: $ord = 'post'; $query_thread .= " ORDER BY m.posted DESC "; break; } $query_thread .= " LIMIT {$ini}, " . Get::sett('visuItem'); $re_thread = sql_query($query_thread); $re_last_post = sql_query("\r\n\tSELECT m.idThread, t.author AS thread_author, m.posted, m.title, m.author AS mess_author, m.generator\r\n\tFROM " . $GLOBALS['prefix_lms'] . "_forumthread AS t LEFT JOIN\r\n\t\t" . $GLOBALS['prefix_lms'] . "_forummessage AS m ON ( t.last_post = m.idMessage )\r\n\tWHERE t.idForum IN ( " . implode($forums, ',') . " )"); while (list($idT_p, $id_ta, $posted, $title_p, $id_a, $is_gener) = sql_fetch_row($re_last_post)) { $last_authors[$id_ta] = $id_ta; if ($posted !== NULL) { $last_post[$idT_p]['info'] = Format::date($posted) . '<br />' . substr(strip_tags($title_p), 0, 15) . ' ...'; $last_post[$idT_p]['author'] = $id_a; $last_authors[$id_a] = $id_a; } } if (isset($last_authors)) { $authors_names =& $acl_man->getUsers($last_authors); } $page_title = array('index.php?modname=forum&op=forum' => $lang->def('_FORUM'), $lang->def('_SEARCH_RESULT_FOR') . ' : ' . $search_arg); $GLOBALS['page']->add(getTitleArea($page_title, 'forum') . '<div class="std_block">' . Form::openForm('search_forum', 'index.php?modname=forum&op=search') . '<div class="quick_search_form">' . '<label for="search_arg">' . $lang->def('_SEARCH_LABEL') . '</label> ' . Form::getInputTextfield('search_t', 'search_arg', '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'); $tb = new Table(Get::sett('visuItem'), $lang->def('_THREAD_CAPTION'), $lang->def('_THRAD_SUMMARY')); $img_up = '<img src="' . getPathImage() . 'standard/ord_asc.png" alt="' . $lang->def('_ORD_ASC') . '" />'; $img_down = '<img src="' . getPathImage() . 'standard/ord_desc.png" alt="' . $lang->def('_ORD_DESC') . '" />'; $cont_h = array('<img src="' . getPathImage() . 'standard/msg_read.png" title="' . $lang->def('_FREET') . '" alt="' . $lang->def('_FREE') . '" />', '<a href="' . $jump_url . '&ord=' . ($ord == 'obj' ? 'obji' : 'obj') . '" title="' . $lang->def('_ORDER_BY') . '">' . ($ord == 'obj' ? $img_up : ($ord == 'obji' ? $img_down : '')) . $lang->def('_THREAD') . '</a>', $lang->def('_NUMREPLY'), '<a href="' . $jump_url . '&ord=' . ($ord == 'auth' ? 'authi' : 'auth') . '" title="' . $lang->def('_ORDER_BY') . '">' . ($ord == 'auth' ? $img_up : ($ord == 'authi' ? $img_down : '')) . $lang->def('_AUTHOR') . '</a>', $lang->def('_NUMVIEW'), '<a href="' . $jump_url . '&ord=' . ($ord == 'post' ? 'posti' : 'post') . '" title="' . $lang->def('_ORDER_BY') . '">' . ($ord == 'post' ? $img_up : ($ord == 'posti' ? $img_down : '')) . $lang->def('_LASTPOST') . '</a>'); $type_h = array('image', '', 'align_center', 'align_center', 'image', 'align_center'); if ($mod_perm) { $cont_h[] = '<img src="' . getPathImage() . 'standard/edit.png" alt="' . $lang->def('_MOD') . '" title="' . $lang->def('_MOD') . '" />'; $type_h[] = 'image'; $cont_h[] = '<img src="' . getPathImage() . 'standard/delete.png" alt="' . $lang->def('_DEL') . '" title="' . $lang->def('_DEL') . '" />'; $type_h[] = 'image'; } $tb->setColsStyle($type_h); $tb->addHead($cont_h); while (list($idT, $id_forum, $t_author, $posted, $title, $num_post, $num_view, $locked, $erased) = sql_fetch_row($re_thread)) { $c_css = ''; // thread author $t_author = isset($authors_names[$t_author]) ? $authors_names[$t_author][ACL_INFO_LASTNAME] . $authors_names[$t_author][ACL_INFO_FIRSTNAME] == '' ? $acl_man->relativeId($authors_names[$t_author][ACL_INFO_USERID]) : $authors_names[$t_author][ACL_INFO_LASTNAME] . ' ' . $authors_names[$t_author][ACL_INFO_FIRSTNAME] : $lang->def('_UNKNOWN_AUTHOR'); // last post author if (isset($last_post[$idT])) { $author = $last_post[$idT]['author']; $last_mess_write = $last_post[$idT]['info'] . ' ( ' . $lang->def('_BY') . ': <span class="mess_author">' . (isset($authors_names[$author]) ? $authors_names[$author][ACL_INFO_LASTNAME] . $authors_names[$author][ACL_INFO_FIRSTNAME] == '' ? $acl_man->relativeId($authors_names[$author][ACL_INFO_USERID]) : $authors_names[$author][ACL_INFO_LASTNAME] . ' ' . $authors_names[$author][ACL_INFO_FIRSTNAME] : $lang->def('_UNKNOWN_AUTHOR')) . '</span> )'; } else { $last_mess_write = $lang->def('_NONE'); } // status of the thread if ($erased) { $status = '<img src="' . getPathImage() . 'standard/cancel.png" alt="' . $lang->def('_FREE') . '" />'; } elseif ($locked) { $status = '<img src="' . getPathImage() . 'standard/locked.png" alt="' . $lang->def('_LOCKED') . '" />'; } elseif (isset($_SESSION['unreaded_forum'][$_SESSION['idCourse']][$id_forum][$idT])) { $status = '<img src="' . getPathImage() . 'standard/msg_unread.png" alt="' . $lang->def('_UNREAD') . '" />'; $c_css = ' class="text_bold"'; } else { $status = '<img src="' . getPathImage() . 'standard/msg_read.png" alt="' . $lang->def('_FREE') . '" />'; } $content = array($status); $content[] = $erased && !$mod_perm ? '<div class="forumErased">' . $lang->def('_OPERATION_SUCCESSFUL') . '</div>' : '<a' . $c_css . ' href="index.php?modname=forum&op=searchmessage&idThread=' . $idT . '&ini_thread=' . $ini_page . '">' . ($search_arg !== '' ? eregi_replace($search_arg, '<span class="filter_evidence">' . $search_arg . '</span>', $title) : $title) . '</a>'; $content[] = $num_post . (isset($_SESSION['unreaded_forum'][$_SESSION['idCourse']][$id_forum][$idT]) && $_SESSION['unreaded_forum'][$_SESSION['idCourse']][$id_forum][$idT] != 'new_thread' ? '<br /><span class="forum_notread">(' . $_SESSION['unreaded_forum'][$_SESSION['idCourse']][$id_forum][$idT] . ' ' . $lang->def('_ADD') . ')</span>' : ''); $content[] = $t_author; $content[] = $num_view; //$content[] = Format::date($posted); $content[] = $last_mess_write; if ($mod_perm) { $content[] = '<a href="index.php?modname=forum&op=modthread&idThread=' . $idT . '&search=1&ini=' . $ini_page . '" ' . 'title="' . $lang->def('_MOD') . ' : ' . strip_tags($title) . '">' . '<img src="' . getPathImage() . 'standard/edit.png" alt="' . $lang->def('_MOD') . ' : ' . strip_tags($title) . '" /></a>'; $content[] = '<a href="index.php?modname=forum&op=delthread&idThread=' . $idT . '&search=1&ini=' . $ini_page . '" ' . 'title="' . $lang->def('_DEL') . ' : ' . strip_tags($title) . '">' . '<img src="' . getPathImage() . 'standard/delete.png" alt="' . $lang->def('_DEL') . ' : ' . strip_tags($title) . '" /></a>'; } $tb->addBody($content); } $GLOBALS['page']->add($tb->getTable(), 'content'); $GLOBALS['page']->add($nav_bar->getNavBar($ini) . '</div>', 'content'); }
function getSelectedElement($var_name = false, $kind_of = false) { $page = NavBar::getSelectedPage($var_name, $kind_of); return ($page - 1) * $this->element_per_page; }
function coursecatalogue($id_block, $title, $option = array()) { YuiLib::load(array('animation' => 'my_animation', 'container' => 'container-min', 'container' => 'container_core-min')); cout(Util::get_js(Get::rel_path('cms') . '/modules/catalog/catalog.js', true), 'page_head'); if (!isset($_SESSION['chart'])) { $_SESSION['chart'] = array(); } $id_course = Get::req('id_course', DOTY_INT, 0); $action = Get::req('action', DOTY_STRING, ''); if ($id_course !== 0 && $action === '') { $_SESSION['chart'][$id_course]['idCourse'] = $id_course; } else { require_once _lms_ . '/lib/lib.subscribe.php'; $man_subscribe = new CourseSubscribe_Management(); $man_subscribe->subscribeToCourse(getLogUserId(), $id_course); } require_once _cms_ . '/lib/lib.catalog.php'; require_once _base_ . '/lib/lib.navbar.php'; cout('<link href="./modules/catalog/catalog.css" type="text/css" rel="stylesheet"/>', 'page_head'); $css_path = Get::tmpl_path('base') . 'yui-skin'; cout(Util::get_css($css_path . '/tabview.css', true), 'page_head'); $lang =& DoceboLanguage::CreateInstance('catalogue', 'cms'); $man_cat = new Man_Catalog(); $array_id_block = explode('_', $id_block); $page = Get::req('page', DOTY_INT, 0); if ($page == 0) { $page = $this->getBlockPage($array_id_block[0]); } cout(getTitleArea($title) . '<div class="std_block">'); $catalogue = $man_cat->getCatalogueForBlock($array_id_block[0]); $all_course = false; if (array_search(0, $catalogue) !== false) { unset($catalogue[array_search(0, $catalogue)]); $all_course = true; } $id_catalogue = Get::req('id_catalogue', DOTY_INT, -2); if ($id_catalogue == -2) { if (count($catalogue)) { if (isset($catalogue[0])) { $id_catalogue = $catalogue[0]['id_catalogue']; } else { $id_catalogue = $catalogue[1]['id_catalogue']; } } else { $id_catalogue = 0; } } $id_category = Get::req('id_cat', DOTY_INT, 0); $number_courses = $man_cat->getCourseNumberForBlock($array_id_block[0], $id_catalogue, $id_category, $all_course); $nav_bar = new NavBar('ini', Get::sett('visuItem'), $number_courses); $nav_bar->setLink('index.php?pag=' . $page . '&id_catalogue=' . $id_catalogue . ($id_category != 0 ? '&id_cat=' . $id_category : '')); $ini = $nav_bar->getSelectedPage(); $limit = ($ini - 1) * Get::sett('visuItem'); cout($nav_bar->getNavBar() . '<div id="demo" class="yui-navset">' . '<ul class="yui-nav">'); foreach ($catalogue as $catalogue_info) { cout('<li ' . ($catalogue_info['id_catalogue'] == $id_catalogue ? ' class="selected"' : '') . '><a href="index.php?pag=' . $page . '&id_catalogue=' . $catalogue_info['id_catalogue'] . '"><em>' . $catalogue_info['name'] . '</em></a></li>'); } cout('<li ' . ($id_catalogue == 0 ? ' class="selected"' : '') . '><a href="index.php?pag=' . $page . '&id_catalogue=0"><em>' . $lang->def('_ALL_COURSES') . '</em></a></li>' . '<li ' . ($id_catalogue == -1 ? ' class="selected"' : '') . '><a href="index.php?pag=' . $page . '&id_catalogue=-1"><em>' . $lang->def('_CATEGORY') . '</em></a></li>'); reset($catalogue); cout('</ul>'); cout('<div class="yui-content">'); if ($number_courses == 0 && $id_catalogue != -1) { cout('<p>' . $lang->def('_NO_COURSE_FOR_CATALOG') . '</p>'); } elseif ($id_catalogue == -1) { //Category Visualization if ($id_category == 0) { $query = "SELECT ca.idCategory, ca.path, ca.lev, ca.iLeft, ca.iRight, COUNT(co.idCourse)" . " FROM " . $GLOBALS['prefix_lms'] . "_category AS ca" . " LEFT JOIN " . $GLOBALS['prefix_lms'] . "_course AS co ON co.idCategory = ca.idCategory" . " WHERE ca.lev = 1" . " GROUP BY ca.idCategory" . " ORDER BY ca.lev, ca.path"; } else { $query = "SELECT iLeft, iRight" . " FROM " . $GLOBALS['prefix_lms'] . "_category" . " WHERE idCategory = " . $id_category; list($ileft, $iright) = sql_fetch_row(sql_query($query)); $query = "SELECT ca.idCategory, ca.path, ca.lev, ca.iLeft, ca.iRight, COUNT(co.idCourse)" . " FROM " . $GLOBALS['prefix_lms'] . "_category AS ca" . " LEFT JOIN " . $GLOBALS['prefix_lms'] . "_course AS co ON co.idCategory = ca.idCategory" . " WHERE ca.iLeft >= " . $ileft . " AND ca.iRight <= " . $iright . " GROUP BY ca.idCategory" . " ORDER BY ca.lev, ca.path"; } $result = sql_query($query); $first = true; $num_folder = sql_num_rows($result); cout('<div class="cat_nav">'); while (list($id_cat, $path, $lev, $ileft, $iright, $courses) = sql_fetch_row($result)) { $cat_name = end(explode('/', $path)); if ($id_category == $id_cat) { cout('<div class="cat_position">' . '<a href="index.php?pag=' . $page . '&id_catalogue=-1">' . $lang->def('_CATEGORY') . '</a>'); if ($lev > 1) { $query_parent = "SELECT idCategory, path" . " FROM " . $GLOBALS['prefix_lms'] . "_category" . " WHERE iLeft < " . $ileft . " AND iRight > " . $iright . " ORDER BY lev ASC"; $result_parent = sql_query($query_parent); while (list($id_cat_pa, $path_pa) = sql_fetch_row($result_parent)) { $pa_name = end(explode('/', $path_pa)); cout(' - <a href="index.php?pag=' . $page . '&id_catalogue=-1&id_cat=' . $id_cat_pa . '">' . $pa_name . '</a>'); } } cout(' - ' . $cat_name . '</div>'); } if ($first && $num_folder > 0) { $first = false; cout('<ul class="cat_nav_list">'); } if ($id_category != $id_cat) { $sub_folder = ($iright - $ileft - 1) / 2; cout('<li>' . '<a href="index.php?pag=' . $page . '&id_catalogue=-1&id_cat=' . $id_cat . '">' . $cat_name . '<br />' . ($sub_folder > 0 ? '<span class="cat_item_info">' . $lang->def("_CATEGORIES") . ' (' . $sub_folder . ')<br />' : '') . ($courses > 0 ? '<span class="cat_item_info">' . $lang->def("_COURSES") . ' (' . $courses . ')' : '') . '</a>' . '</li>'); } } if ($num_folder > 0) { cout('</ul>'); } cout('</div>'); //Course visualization cout('<div class="course_list">'); if ($number_courses == 0) { cout('<p>' . $lang->def('_NO_COURSE_FOR_CATEGORY') . '</p>'); } else { $courses = $man_cat->getCourseForBlock($array_id_block[0], $limit, $id_catalogue, $id_category, $all_course); foreach ($courses as $course_info) { $action = $this->controlCourse($course_info, $page, $id_catalogue, $id_category, $ini); cout('<div class="course">' . '<div class="course_info">' . '<h3 class="course_title"><img src="' . getPathImage() . '/language/' . strtolower($course_info['lang_code']) . '.png" alt="" title="" /> ' . $course_info['name'] . '</h3>' . '<p class="course_description">' . $course_info['description'] . '</p>' . '</div>' . '<div class="course_action">' . $action . '</div>' . '</div>'); } } cout('</div>'); } else { //Course in catalogue visualization $courses = $man_cat->getCourseForBlock($array_id_block[0], $limit, $id_catalogue, $id_category, $all_course); foreach ($courses as $course_info) { $action = $this->controlCourse($course_info, $page, $id_catalogue, $id_category, $ini); cout('<div class="course">' . '<div class="course_info">' . '<h3 class="course_title"><img src="' . getPathImage() . '/language/' . strtolower($course_info['lang_code']) . '.png" alt="" title="" /> ' . $course_info['name'] . '</h3>' . '<p class="course_description">' . $course_info['description'] . '</p>' . '</div>' . '<div class="course_action">' . $action . '</div>' . '</div>'); } } cout('</div>' . '</div>' . $nav_bar->getNavBar() . '</div>'); }