"notebookteacher" '; if ((api_is_coach() || api_is_course_tutor() || api_is_platform_admin()) && !$studentView) { $conditions = ' WHERE ( visibility = 1 AND ( category = "authoring" OR category = "interaction" OR category = "plugin" ) OR (t.name = "'.TOOL_TRACKING.'") )'; } // Add order if there are LPs $sql = "SELECT t.* FROM $course_tool_table t LEFT JOIN $lpTable l ON (t.c_id = l.c_id AND link LIKE concat('%/lp_controller.php?action=view&lp_id=', l.id, '&%')) LEFT JOIN $tblLpCategory lc ON (t.c_id = lc.c_id AND l.category_id = lc.iid) $conditions AND t.c_id = $course_id $condition_session ORDER BY CASE WHEN l.category_id IS NULL THEN 0 ELSE 1 END, CASE WHEN l.display_order IS NULL THEN 0 ELSE 1 END, lc.position, l.display_order, t.id"; $orderBy = ''; break; case TOOL_AUTHORING: $sql = "SELECT t.* FROM $course_tool_table t LEFT JOIN $lpTable l ON (t.c_id = l.c_id AND link LIKE concat('%/lp_controller.php?action=view&lp_id=', l.id, '&%')) LEFT JOIN $tblLpCategory lc ON (t.c_id = lc.c_id AND l.category_id = lc.iid) WHERE category = 'authoring' AND t.c_id = $course_id $condition_session ORDER BY CASE WHEN l.category_id IS NULL THEN 0 ELSE 1 END, CASE WHEN l.display_order IS NULL THEN 0 ELSE 1 END, lc.position, l.display_order, t.id"; $orderBy = ''; break; case TOOL_INTERACTION: $sql = "SELECT * FROM $course_tool_table t WHERE category = 'interaction' AND c_id = $course_id $condition_session "; break; case TOOL_ADMIN_VISIBLE: $sql = "SELECT * FROM $course_tool_table t WHERE category = 'admin' AND visibility ='1' AND c_id = $course_id $condition_session "; break; case TOOL_ADMIN_PLATFORM: $sql = "SELECT * FROM $course_tool_table t WHERE category = 'admin' AND c_id = $course_id $condition_session "; break; case TOOL_DRH: $sql = "SELECT * FROM $course_tool_table t WHERE t.name IN ('tracking') AND c_id = $course_id $condition_session "; 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 t WHERE category = 'plugin' AND name <> 'courseblock' AND c_id = $course_id $condition_session "; break; } $sql .= $orderBy; $result = Database::query($sql); $tools = []; while ($row = Database::fetch_assoc($result)) { $tools[] = $row; } // 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 = []; $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' && $line['selected_value'] == 'true') { $hide_list[] = $line['subkey']; $check = true; } } $allowEditionInSession = api_get_configuration_value('allow_edit_tool_visibility_in_session'); // If exists same tool (by name) from session in base course then avoid it. Allow them pass in other cases $tools = array_filter($tools, function (array $toolToFilter) use ($sessionId, $tools) { if (!empty($toolToFilter['session_id'])) { foreach ($tools as $originalTool) { if ($toolToFilter['name'] == $originalTool['name'] && empty($originalTool['session_id'])) { return false; } } } return true; }); foreach ($tools as $temp_row) { $add = false; if ($check) { if (!in_array($temp_row['name'], $hide_list)) { $add = true; } } else { $add = true; } if ($allowEditionInSession && !empty($sessionId)) { // Checking if exist row in session $criteria = [ 'course' => $course_id, 'name' => $temp_row['name'], 'sessionId' => $sessionId, ]; /** @var CTool $toolObj */ $toolObj = Database::getManager()->getRepository('ChamiloCourseBundle:CTool')->findOneBy($criteria); if ($toolObj) { if (api_is_allowed_to_edit() == false && $toolObj->getVisibility() == false) { continue; } } } switch ($temp_row['image']) { case 'scormbuilder.gif': $lpId = self::getPublishedLpIdFromLink($temp_row['link']); $lp = new learnpath( api_get_course_id(), $lpId, $userId ); $path = $lp->get_preview_image_path(ICON_SIZE_BIG); if (api_is_allowed_to_edit(null, true)) { $add = true; } else { $add = learnpath::is_lp_visible_for_student( $lpId, $userId, $courseInfo, $sessionId ); } if ($path) { $temp_row['custom_image'] = $path; } break; case 'lp_category.gif': $lpCategory = self::getPublishedLpCategoryFromLink( $temp_row['link'] ); $add = learnpath::categoryIsVisibleForStudent( $lpCategory, $user ); break; } if ($add) { $all_tools_list[] = $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); $condition_session = api_get_session_condition( $sessionId, true, true, 'tip.session_id' ); switch ($course_tool_category) { case TOOL_AUTHORING: $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.c_id = $course_id AND tip.c_id = $course_id AND 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 FROM $course_link_table tl LEFT JOIN $course_item_property_table tip ON tip.tool='link' AND tip.ref=tl.id WHERE tl.c_id = $course_id AND tip.c_id = $course_id AND tl.on_homepage ='1' $condition_session"; break; case TOOL_ADMIN: $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.c_id = $course_id AND tip.c_id = $course_id AND 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 = []; $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.png' : 'file_html.png'; $properties['adminlink'] = api_get_path(WEB_CODE_PATH).'link/link.php?action=editlink&id='.$links_row['id']; $properties['target'] = $links_row['target']; $tmp_all_tools_list[] = $properties; } } } if (isset($tmp_all_tools_list)) { $tbl_blogs_rel_user = Database::get_course_table(TABLE_BLOGS_REL_USER); foreach ($tmp_all_tools_list as $tool) { if ($tool['image'] == 'blog.gif') { // Get blog id $blog_id = substr($tool['link'], strrpos($tool['link'], '=') + 1, strlen($tool['link'])); // Get blog members if ($is_platform_admin) { $sql = "SELECT * FROM $tbl_blogs_rel_user blogs_rel_user WHERE blog_id = ".$blog_id; } else { $sql = "SELECT * FROM $tbl_blogs_rel_user blogs_rel_user WHERE blog_id = ".$blog_id." AND user_id = ".$userId; } $result = Database::query($sql); if (Database::num_rows($result) > 0) { $all_tools_list[] = $tool; } } else { $all_tools_list[] = $tool; } } } $list = self::filterPluginTools($all_tools_list, $course_tool_category); return $list; } /** * Displays the tools of a certain category. * * @param array $all_tools_list List of tools as returned by get_tools_category() * * @return array */ public static function show_tools_category($all_tools_list) { $_user = api_get_user_info(); $theme = api_get_setting('homepage_view'); if ($theme === 'vertical_activity') { //ordering by get_lang name $order_tool_list = []; if (is_array($all_tools_list) && count($all_tools_list) > 0) { foreach ($all_tools_list as $key => $new_tool) { $tool_name = self::translate_tool_name($new_tool); $order_tool_list[$key] = $tool_name; } natsort($order_tool_list); $my_temp_tool_array = []; foreach ($order_tool_list as $key => $new_tool) { $my_temp_tool_array[] = $all_tools_list[$key]; } $all_tools_list = $my_temp_tool_array; } else { $all_tools_list = []; } } $web_code_path = api_get_path(WEB_CODE_PATH); $session_id = api_get_session_id(); $is_platform_admin = api_is_platform_admin(); $allowEditionInSession = api_get_configuration_value('allow_edit_tool_visibility_in_session'); if ($session_id == 0) { $is_allowed_to_edit = api_is_allowed_to_edit(null, true) && api_is_course_admin(); } else { $is_allowed_to_edit = api_is_allowed_to_edit(null, true) && !api_is_coach(); if ($allowEditionInSession) { $is_allowed_to_edit = api_is_allowed_to_edit(null, true) && api_is_coach($session_id, api_get_course_int_id()); } } $items = []; $app_plugin = new AppPlugin(); if (isset($all_tools_list)) { $lnk = ''; foreach ($all_tools_list as &$tool) { $item = []; $studentview = false; $tool['original_link'] = $tool['link']; if ($tool['image'] === 'scormbuilder.gif') { // Check if the published learnpath is visible for student $lpId = self::getPublishedLpIdFromLink($tool['link']); if (api_is_allowed_to_edit(null, true)) { $studentview = true; } if (!api_is_allowed_to_edit(null, true) && !learnpath::is_lp_visible_for_student( $lpId, api_get_user_id(), api_get_course_info(), api_get_session_id() ) ) { continue; } } if ($session_id != 0 && in_array($tool['name'], ['course_setting'])) { continue; } // This part displays the links to hide or remove a tool. // These links are only visible by the course manager. unset($lnk); $item['extra'] = null; $toolAdmin = isset($tool['admin']) ? $tool['admin'] : ''; if ($is_allowed_to_edit) { if (empty($session_id)) { if (isset($tool['id'])) { if ($tool['visibility'] == '1' && $toolAdmin != '1') { $link['name'] = Display::return_icon( 'visible.png', get_lang('Deactivate'), ['id' => 'linktool_'.$tool['iid']], ICON_SIZE_SMALL, false ); $link['cmd'] = 'hide=yes'; $lnk[] = $link; } if ($tool['visibility'] == '0' && $toolAdmin != '1') { $link['name'] = Display::return_icon( 'invisible.png', get_lang('Activate'), ['id' => 'linktool_'.$tool['iid']], ICON_SIZE_SMALL, false ); $link['cmd'] = 'restore=yes'; $lnk[] = $link; } } } elseif ($allowEditionInSession) { $criteria = [ 'course' => api_get_course_int_id(), 'name' => $tool['name'], 'sessionId' => $session_id, ]; /** @var CTool $tool */ $toolObj = Database::getManager()->getRepository('ChamiloCourseBundle:CTool')->findOneBy($criteria); if ($toolObj) { $visibility = (int) $toolObj->getVisibility(); switch ($visibility) { case '0': $info = pathinfo($tool['image']); $basename = basename($tool['image'], '.'.$info['extension']); $tool['image'] = $basename.'_na.'.$info['extension']; $link['name'] = Display::return_icon( 'invisible.png', get_lang('Activate'), ['id' => 'linktool_'.$tool['iid']], ICON_SIZE_SMALL, false ); $link['cmd'] = 'restore=yes'; $lnk[] = $link; break; case '1': $link['name'] = Display::return_icon( 'visible.png', get_lang('Deactivate'), ['id' => 'linktool_'.$tool['iid']], ICON_SIZE_SMALL, false ); $link['cmd'] = 'hide=yes'; $lnk[] = $link; break; } } else { $link['name'] = Display::return_icon( 'visible.png', get_lang('Deactivate'), ['id' => 'linktool_'.$tool['iid']], ICON_SIZE_SMALL, false ); $link['cmd'] = 'hide=yes'; $lnk[] = $link; } } if (!empty($tool['adminlink'])) { $item['extra'] = ''. Display::return_icon('edit.gif', get_lang('Edit')). ''; } } // Both checks are necessary as is_platform_admin doesn't take student view into account if ($is_platform_admin && $is_allowed_to_edit) { if ($toolAdmin != '1') { $link['cmd'] = 'hide=yes'; } } $item['visibility'] = ''; if (isset($lnk) && is_array($lnk)) { foreach ($lnk as $this_link) { if (empty($tool['adminlink'])) { $item['visibility'] .= ''. $this_link['name'].''; } } } // NOTE : Table contains only the image file name, not full path if (stripos($tool['link'], 'http://') === false && stripos($tool['link'], 'https://') === false && stripos($tool['link'], 'ftp://') === false ) { $tool['link'] = $web_code_path.$tool['link']; } $class = ''; if ($tool['visibility'] == '0' && $toolAdmin != '1') { $class = 'text-muted'; $info = pathinfo($tool['image']); $basename = basename($tool['image'], '.'.$info['extension']); $tool['image'] = $basename.'_na.'.$info['extension']; } $qm_or_amp = strpos($tool['link'], '?') === false ? '?' : '&'; // If it's a link, we don't add the cidReq if ($tool['image'] === 'file_html.png' || $tool['image'] === 'file_html_na.png') { $tool['link'] = $tool['link']; } else { $tool['link'] = $tool['link'].$qm_or_amp.api_get_cidreq(); } $toolIid = isset($tool['iid']) ? $tool['iid'] : null; //@todo this visio stuff should be removed if (strpos($tool['name'], 'visio_') !== false) { $tool_link_params = [ 'id' => 'tooldesc_'.$toolIid, 'href' => '"javascript: void(0);"', 'class' => $class, 'onclick' => 'javascript: window.open(\''.$tool['link'].'\',\'window_visio'.api_get_course_id().'\',config=\'height=\'+730+\', width=\'+1020+\', left=2, top=2, toolbar=no, menubar=no, scrollbars=yes, resizable=yes, location=no, directories=no, status=no\')', 'target' => $tool['target'], ]; } elseif (strpos($tool['name'], 'chat') !== false && api_get_course_setting('allow_open_chat_window') ) { $tool_link_params = [ 'id' => 'tooldesc_'.$toolIid, 'class' => $class, 'href' => 'javascript: void(0);', 'onclick' => 'javascript: window.open(\''.$tool['link'].'\',\'window_chat'.api_get_course_id().'\',config=\'height=\'+600+\', width=\'+825+\', left=2, top=2, toolbar=no, menubar=no, scrollbars=yes, resizable=yes, location=no, directories=no, status=no\')', //Chat Open Windows 'target' => $tool['target'], ]; } else { $tool_link_params = [ 'id' => 'tooldesc_'.$toolIid, 'href' => $tool['link'], 'class' => $class, 'target' => $tool['target'], ]; } $tool_name = self::translate_tool_name($tool); // Including Courses Plugins // Creating title and the link if (isset($tool['category']) && $tool['category'] == 'plugin') { $plugin_info = $app_plugin->getPluginInfo($tool['name']); if (isset($plugin_info) && isset($plugin_info['title'])) { $tool_name = $plugin_info['title']; } if (!file_exists(api_get_path(SYS_CODE_PATH).'img/'.$tool['image']) && !file_exists(api_get_path(SYS_CODE_PATH).'img/icons/64/'.$tool['image'])) { $tool['image'] = 'plugins.png'; } $tool_link_params['href'] = api_get_path(WEB_PLUGIN_PATH) .$tool['original_link'].$qm_or_amp.api_get_cidreq(); } // Use in the course home $icon = Display::return_icon( $tool['image'], $tool_name, ['class' => 'tool-icon', 'id' => 'toolimage_'.$toolIid], ICON_SIZE_BIG, false ); // Used in the top bar $iconMedium = Display::return_icon( $tool['image'], $tool_name, ['class' => 'tool-icon', 'id' => 'toolimage_'.$toolIid], ICON_SIZE_MEDIUM, false ); // Used for vertical navigation $iconSmall = Display::return_icon( $tool['image'], $tool_name, ['class' => 'tool-img', 'id' => 'toolimage_'.$toolIid], ICON_SIZE_SMALL, false ); /*if (!empty($tool['custom_icon'])) { $image = self::getCustomWebIconPath().$tool['custom_icon']; $icon = Display::img( $image, $tool['description'], array( 'class' => 'tool-icon', 'id' => 'toolimage_'.$tool['id'] ) ); }*/ // Validation when belongs to a session $session_img = api_get_session_image( $tool['session_id'], !empty($_user['status']) ? $_user['status'] : '' ); if ($studentview) { $tool_link_params['href'] .= '&isStudentView=true'; } $item['url_params'] = $tool_link_params; $item['icon'] = Display::url($icon, $tool_link_params['href'], $tool_link_params); $item['only_icon'] = $icon; $item['only_icon_medium'] = $iconMedium; $item['only_icon_small'] = $iconSmall; $item['only_href'] = $tool_link_params['href']; $item['tool'] = $tool; $item['name'] = $tool_name; $tool_link_params['id'] = 'is'.$tool_link_params['id']; $item['link'] = Display::url( $tool_name.$session_img, $tool_link_params['href'], $tool_link_params ); $items[] = $item; } } foreach ($items as &$item) { $originalImage = self::getToolIcon($item, ICON_SIZE_BIG); $item['tool']['only_icon_medium'] = self::getToolIcon($item, ICON_SIZE_MEDIUM, false); $item['tool']['only_icon_small'] = self::getToolIcon($item, ICON_SIZE_SMALL, false); if ($theme === 'activity_big') { $item['tool']['image'] = Display::url( $originalImage, $item['url_params']['href'], $item['url_params'] ); } } return $items; } /** * Shows the general data for a particular meeting. * * @param int $id_session * * @return string session data */ public static function show_session_data($id_session) { $sessionInfo = api_get_session_info($id_session); if (empty($sessionInfo)) { return ''; } $table = Database::get_main_table(TABLE_MAIN_SESSION_CATEGORY); $sql = 'SELECT name FROM '.$table.' WHERE id = "'.intval($sessionInfo['session_category_id']).'"'; $rs_category = Database::query($sql); $session_category = ''; if (Database::num_rows($rs_category) > 0) { $rows_session_category = Database::store_result($rs_category); $rows_session_category = $rows_session_category[0]; $session_category = $rows_session_category['name']; } $coachInfo = api_get_user_info($sessionInfo['id_coach']); $output = ''; if (!empty($session_category)) { $output .= '