/** * Destroy */ static function destroy() { $session = Container::getSession(); $session->invalidate(); }
/** * Returns a div html string with * @param string The message * @param string The message type (confirm,normal,warning,error) * @param bool Whether to XSS-filter or not * @return string Message wrapped into an HTML div */ public static function return_message($message, $type = 'normal', $filter = true) { if (empty($message)) { return ''; } if ($filter) { $message = api_htmlentities($message, ENT_QUOTES, api_is_xml_http_request() ? 'UTF-8' : api_get_system_encoding()); } Container::getSession()->getFlashBag()->add($type, $message); return ''; }
/** * Returns a div html string with * @param string The message * @param string The message type (confirm,normal,warning,error) * @param bool Whether to XSS-filter or not * @return string Message wrapped into an HTML div */ public static function return_message($message, $type = 'normal', $filter = true) { if ($filter) { $message = api_htmlentities($message, ENT_QUOTES, api_is_xml_http_request() ? 'UTF-8' : api_get_system_encoding()); } Container::getSession()->getFlashBag()->add($type, $message); return ''; /* $class = ""; switch($type) { case 'warning': $class .= 'alert alert-warning'; break; case 'error': $class .= 'alert alert-danger'; break; case 'confirmation': case 'confirm': case 'success': $class .= 'alert alert-success'; break; case 'normal': default: $class .= 'alert alert-info'; } return self::div($message, array('class'=> $class));*/ }
/** * Gets the tools of a certain category. Returns an array expected * by show_tools_category() * @param string $course_tool_category contains the category of tools to * display: "toolauthoring", "toolinteraction", "tooladmin", "tooladminplatform", "toolplugin" * @return array */ public static function get_tools_category($course_tool_category) { $course_tool_table = Database::get_course_table(TABLE_TOOL_LIST); $is_platform_admin = api_is_platform_admin(); $all_tools_list = array(); // Condition for the session $session_id = api_get_session_id(); $course_id = api_get_course_int_id(); $condition_session = api_get_session_condition($session_id, true, true); $studentView = Container::getSession()->get('studentview'); //var_dump($studentView); switch ($course_tool_category) { case TOOL_STUDENT_VIEW: $condition_display_tools = ' WHERE visibility = 1 AND (category = "authoring" OR category = "interaction" OR category = "plugin") '; if ((api_is_coach() || api_is_course_tutor()) && $studentView != 'studentview') { $condition_display_tools = ' WHERE (visibility = 1 AND (category = "authoring" OR category = "interaction" OR category = "plugin") OR (name = "' . TOOL_TRACKING . '") ) '; } $sql = "SELECT * FROM {$course_tool_table} {$condition_display_tools} AND c_id = {$course_id} {$condition_session} ORDER BY id"; $result = Database::query($sql); $col_link = "##003399"; break; case TOOL_AUTHORING: $sql = "SELECT * FROM {$course_tool_table}\n WHERE\n category = 'authoring' AND\n c_id = {$course_id}\n {$condition_session}\n ORDER BY id"; $result = Database::query($sql); $col_link = "##003399"; break; case TOOL_INTERACTION: $sql = "SELECT * FROM {$course_tool_table} WHERE category = 'interaction' AND c_id = {$course_id} {$condition_session} ORDER BY id"; $result = Database::query($sql); $col_link = "##003399"; break; case TOOL_ADMIN_VISIBLE: $sql = "SELECT * FROM {$course_tool_table} WHERE category = 'admin' AND visibility ='1' AND c_id = {$course_id} {$condition_session} ORDER BY id"; $result = Database::query($sql); $col_link = "##003399"; break; case TOOL_ADMIN_PLATFORM: $sql = "SELECT * FROM {$course_tool_table} WHERE category = 'admin' AND c_id = {$course_id} {$condition_session} ORDER BY id"; $result = Database::query($sql); $col_link = "##003399"; break; case TOOL_COURSE_PLUGIN: //Other queries recover id, name, link, image, visibility, admin, address, added_tool, target, category and session_id // but plugins are not present in the tool table, only globally and inside the course_settings table once configured $sql = "SELECT * FROM {$course_tool_table} WHERE category = 'plugin' AND c_id = {$course_id} {$condition_session} ORDER BY id"; $result = Database::query($sql); break; } //Get the list of hidden tools - this might imply performance slowdowns // if the course homepage is loaded many times, so the list of hidden // tools might benefit from a shared memory storage later on $list = api_get_settings('Tools', 'list', api_get_current_access_url_id()); $hide_list = array(); $check = false; foreach ($list as $line) { // Admin can see all tools even if the course_hide_tools configuration is set if ($is_platform_admin) { continue; } if ($line['variable'] == 'course_hide_tools' and $line['selected_value'] == 'true') { $hide_list[] = $line['subkey']; $check = true; } } while ($temp_row = Database::fetch_assoc($result)) { if ($check) { if (!in_array($temp_row['name'], $hide_list)) { $all_tools_list[$temp_row['name']] = $temp_row; } } else { $all_tools_list[$temp_row['name']] = $temp_row; } } // Grabbing all the links that have the property on_homepage set to 1 $course_link_table = Database::get_course_table(TABLE_LINK); $course_item_property_table = Database::get_course_table(TABLE_ITEM_PROPERTY); switch ($course_tool_category) { case TOOL_AUTHORING: $sql_links = "SELECT tl.*, tip.visibility, tl.id link_id\n FROM {$course_link_table} tl\n LEFT JOIN {$course_item_property_table} tip ON tip.tool='link' AND tip.ref=tl.id\n WHERE \ttl.c_id = {$course_id} AND\n tip.c_id = {$course_id} AND\n tl.on_homepage='1' {$condition_session}"; break; case TOOL_INTERACTION: $sql_links = null; /* $sql_links = "SELECT tl.*, tip.visibility FROM $course_link_table tl LEFT JOIN $course_item_property_table tip ON tip.tool='link' AND tip.ref=tl.id WHERE tl.on_homepage='1' "; */ break; case TOOL_STUDENT_VIEW: $sql_links = "SELECT tl.*, tip.visibility, tl.id link_id\n FROM {$course_link_table} tl\n LEFT JOIN {$course_item_property_table} tip ON tip.tool='link' AND tip.ref=tl.id\n WHERE \ttl.c_id \t\t= {$course_id} AND\n tip.c_id \t\t= {$course_id} AND\n tl.on_homepage\t='1' {$condition_session}"; break; case TOOL_ADMIN: $sql_links = "SELECT tl.*, tip.visibility, tl.id link_id\n FROM {$course_link_table} tl\n LEFT JOIN {$course_item_property_table} tip ON tip.tool='link' AND tip.ref=tl.id\n WHERE \ttl.c_id = {$course_id} AND\n tip.c_id = {$course_id} AND\n tl.on_homepage='1' {$condition_session}"; break; default: $sql_links = null; break; } // Edited by Kevin Van Den Haute (kevin@develop-it.be) for integrating Smartblogs if ($sql_links != null) { $result_links = Database::query($sql_links); if (Database::num_rows($result_links) > 0) { while ($links_row = Database::fetch_array($result_links, 'ASSOC')) { $properties = array(); $properties['name'] = $links_row['title']; $properties['session_id'] = $links_row['session_id']; $properties['link'] = $links_row['url']; $properties['visibility'] = $links_row['visibility']; $properties['image'] = $links_row['visibility'] == '0' ? 'file_html.gif' : 'file_html.gif'; $properties['adminlink'] = api_get_path(WEB_CODE_PATH) . 'link/link.php?action=editlink&id=' . $links_row['id']; $properties['target'] = $links_row['target']; $properties['link_id'] = !empty($links_row['link_id']) ? $links_row['link_id'] : null; $tmp_all_tools_list[] = $properties; } } } if (isset($tmp_all_tools_list)) { foreach ($tmp_all_tools_list as $tool) { if ($tool['image'] == 'blog.gif') { // Init $tbl_blogs_rel_user = Database::get_course_table(TABLE_BLOGS_REL_USER); // Get blog id $blog_id = substr($tool['link'], strrpos($tool['link'], '=') + 1, strlen($tool['link'])); // Get blog members if ($is_platform_admin) { $sql_blogs = "SELECT * FROM {$tbl_blogs_rel_user} blogs_rel_user WHERE blog_id =" . $blog_id; } else { $sql_blogs = "SELECT * FROM {$tbl_blogs_rel_user} blogs_rel_user WHERE blog_id =" . $blog_id . " AND user_id = " . api_get_user_id(); } $result_blogs = Database::query($sql_blogs); if (Database::num_rows($result_blogs) > 0) { $all_tools_list[] = $tool; } } else { $all_tools_list[] = $tool; } } } return $all_tools_list; }