From 43190f4b11183a301f8babfebf95b437e6a1af9b Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Thu, 18 Dec 2014 10:10:23 +0100 Subject: [PATCH] Minor - format code. --- main/course_home/activity.php | 72 ++++----- main/exercice/savescores.php | 19 +-- main/inc/lib/course_home.lib.php | 212 +++++++++++++++++++------- main/inc/lib/sessionmanager.lib.php | 7 +- main/inc/lib/system/session.class.php | 22 +-- main/newscorm/learnpath.class.php | 4 +- main/newscorm/learnpathItem.class.php | 183 +++++++++++----------- main/newscorm/lp_ajax_save_item.php | 2 + main/newscorm/lp_view.php | 2 - 9 files changed, 316 insertions(+), 207 deletions(-) diff --git a/main/course_home/activity.php b/main/course_home/activity.php index f7dd8c3c8e..76aa7064b7 100755 --- a/main/course_home/activity.php +++ b/main/course_home/activity.php @@ -20,37 +20,37 @@ $session_id = api_get_session_id(); // MAIN CODE if (api_is_allowed_to_edit(null, true)) { - // HIDE - if (!empty($_GET['hide'])) { - $sql = "UPDATE $tool_table SET visibility=0 WHERE c_id = $course_id AND id=".$id; - Database::query($sql); - $show_message = Display::return_message(get_lang('ToolIsNowHidden'), 'confirmation'); - } elseif (!empty($_GET['restore'])) { - // visibility 0,2 -> 1 - // REACTIVATE - $sql = "UPDATE $tool_table SET visibility=1 WHERE c_id = $course_id AND id=".$id; - Database::query($sql); - //$show_message = Display::return_message(get_lang('ToolIsNowVisible'),'confirmation'); - } + // HIDE + if (!empty($_GET['hide'])) { + $sql = "UPDATE $tool_table SET visibility=0 WHERE c_id = $course_id AND id=".$id; + Database::query($sql); + $show_message = Display::return_message(get_lang('ToolIsNowHidden'), 'confirmation'); + } elseif (!empty($_GET['restore'])) { + // visibility 0,2 -> 1 + // REACTIVATE + $sql = "UPDATE $tool_table SET visibility=1 WHERE c_id = $course_id AND id=".$id; + Database::query($sql); + //$show_message = Display::return_message(get_lang('ToolIsNowVisible'),'confirmation'); + } } // Work with data post askable by admin of course if (api_is_platform_admin()) { - // Show message to confirm that a tool it to be hidden from available tools - // visibility 0,1->2 - if (!empty($_GET['askDelete'])) { + // Show message to confirm that a tool it to be hidden from available tools + // visibility 0,1->2 + if (!empty($_GET['askDelete'])) { $content .='
'.get_lang('DelLk').'
    '.get_lang('No').' |  '.get_lang('Yes').'
'; - } elseif (isset($_GET['delete']) && $_GET['delete']) { + } elseif (isset($_GET['delete']) && $_GET['delete']) { /* * Process hiding a tools from available tools. */ - //where $id is set? - $id = intval($id); - Database::query("DELETE FROM $tool_table WHERE c_id = $course_id AND id='$id' AND added_tool=1"); - } + //where $id is set? + $id = intval($id); + Database::query("DELETE FROM $tool_table WHERE c_id = $course_id AND id='$id' AND added_tool=1"); + } } // Course legal @@ -67,25 +67,25 @@ if ($enabled == 'true') { // Start of tools for CourseAdmins (teachers/tutors) if ($session_id == 0 && api_is_course_admin() && api_is_allowed_to_edit(null, true)) { - $content .= '
+ $content .= '
+ $content .= '  '; + $content .= get_lang('PleaseStandBy'); + $content .= '
'; $content .= $pluginExtra; - if (api_get_setting('show_session_data') == 'true' && $session_id > 0) { + if (api_get_setting('show_session_data') == 'true' && $session_id > 0) { $content .= '
'.get_lang('SessionData').' '.CourseHome::show_session_data($session_id).'
'; - } + } $my_list = CourseHome::get_tools_category(TOOL_AUTHORING); - $items = CourseHome::show_tools_category($my_list); + $items = CourseHome::show_tools_category($my_list); $content .= return_block(get_lang('Authoring'), $items, 'course-tools-author'); $my_list = CourseHome::get_tools_category(TOOL_INTERACTION); @@ -101,13 +101,13 @@ if ($session_id == 0 && api_is_course_admin() && api_is_allowed_to_edit(null, tr } elseif (api_is_coach()) { $content .= $pluginExtra; - if (api_get_setting('show_session_data') == 'true' && $session_id > 0) { - $content .= '
+ if (api_get_setting('show_session_data') == 'true' && $session_id > 0) { + $content .= '
'.get_lang('SessionData').' '; - $content .= CourseHome::show_session_data($session_id); - $content .= '
'; - } + $content .= CourseHome::show_session_data($session_id); + $content .= '
'; + } $content .= '
'; $my_list = CourseHome::get_tools_category(TOOL_STUDENT_VIEW); @@ -127,18 +127,18 @@ if ($session_id == 0 && api_is_course_admin() && api_is_allowed_to_edit(null, tr $onlyMaintenanceList[] = $item; } } - + $items = CourseHome::show_tools_category($onlyMaintenanceList); $content .= return_block(get_lang('Administration'), $items); } } } else { - $my_list = CourseHome::get_tools_category(TOOL_STUDENT_VIEW); - if (count($my_list) > 0) { + $my_list = CourseHome::get_tools_category(TOOL_STUDENT_VIEW); + if (count($my_list) > 0) { $content .= '
'; $content .= CourseHome::show_tools_category($my_list); $content .= '
'; - } + } } function return_block($title, $content, $class) { diff --git a/main/exercice/savescores.php b/main/exercice/savescores.php index f86960f4dc..836ac1651f 100755 --- a/main/exercice/savescores.php +++ b/main/exercice/savescores.php @@ -6,9 +6,7 @@ * @author * @version $Id: savescores.php 15602 2008-06-18 08:52:24Z pcool $ */ -/** - * Code - */ + // name of the language file that needs to be included $language_file = 'learnpath'; @@ -22,9 +20,12 @@ if (isset($_GET['origin']) && $_GET['origin'] == 'learnpath') { } require_once '../inc/global.inc.php'; +$courseInfo = api_get_course_info(); +$_user = api_get_user_info(); + $this_section = SECTION_COURSES; require_once api_get_path(LIBRARY_PATH).'fileManage.lib.php'; -$documentPath = api_get_path(SYS_COURSE_PATH).$_course['path']."/document"; +$documentPath = api_get_path(SYS_COURSE_PATH).$courseInfo['path']."/document"; $test = $_REQUEST['test']; $full_file_path = $documentPath.$test; @@ -39,8 +40,7 @@ $_cid = api_get_course_id(); $score = $_REQUEST['score']; $origin = $_REQUEST['origin']; $learnpath_item_id = intval($_REQUEST['learnpath_item_id']); -$course_info = api_get_course_info(); -$course_id = $course_info['real_id']; +$course_id = $courseInfo['real_id']; $jscript2run = ''; /** @@ -103,9 +103,10 @@ if ($origin != 'learnpath') { } else { $htmlHeadXtra[] = $jscript2run; Display::display_reduced_header(); - $update_sql = "UPDATE $TABLE_LP_ITEM_VIEW SET status = 'completed' - WHERE c_id = $course_id AND lp_item_id= $learnpath_item_id"; - Database::query($update_sql); + $sql = "UPDATE $TABLE_LP_ITEM_VIEW SET + status = 'completed' + WHERE c_id = $course_id AND lp_item_id= $learnpath_item_id"; + Database::query($sql); Display::display_confirmation_message(get_lang('HotPotatoesFinished')); Display::display_footer(); } diff --git a/main/inc/lib/course_home.lib.php b/main/inc/lib/course_home.lib.php index 12b9fbf7d5..ffa0bcc139 100755 --- a/main/inc/lib/course_home.lib.php +++ b/main/inc/lib/course_home.lib.php @@ -4,12 +4,16 @@ define('SHORTCUTS_HORIZONTAL', 0); define('SHORTCUTS_VERTICAL', 1); +/** + * Class CourseHome + */ class CourseHome { /** * Gets the html content to show in the 3 column view */ - public static function show_tool_3column($cat) { + public static function show_tool_3column($cat) + { global $_user; $TBL_ACCUEIL = Database :: get_course_table(TABLE_TOOL_LIST); $TABLE_TOOLS = Database :: get_main_table(TABLE_MAIN_COURSE_MODULE); @@ -60,7 +64,6 @@ class CourseHome $course_id = api_get_course_int_id(); - // Grabbing all the links that have the property on_homepage set to 1 if ($cat == 'External') { $tbl_link = Database :: get_course_table(TABLE_LINK); @@ -107,7 +110,13 @@ class CourseHome // check if the published learnpath is visible for student $published_lp_id = self::get_published_lp_id_from_link($tool['link']); if (!api_is_allowed_to_edit(null, true) && - !learnpath::is_lp_visible_for_student($published_lp_id, api_get_user_id(), api_get_course_id(), api_get_session_id())) { + !learnpath::is_lp_visible_for_student( + $published_lp_id, + api_get_user_id(), + api_get_course_id(), + api_get_session_id() + ) + ) { continue; } } @@ -170,7 +179,11 @@ class CourseHome } $lnk = array(); - if (api_is_allowed_to_edit(null, true) && $cat != "courseAdmin" && !strpos($tool['link'], 'learnpath_handler.php?learnpath_id') && !api_is_coach()) { + if (api_is_allowed_to_edit(null, true) && + $cat != "courseAdmin" && + !strpos($tool['link'], 'learnpath_handler.php?learnpath_id') && + !api_is_coach() + ) { if ($tool['visibility']) { $link['name'] = Display::return_icon('remove.gif', get_lang('Deactivate'), array('style' => 'vertical-align: middle;')); $link['cmd'] = "hide=yes"; @@ -183,7 +196,8 @@ class CourseHome if (is_array($lnk)) { foreach ($lnk as & $this_lnk) { if ($tool['adminlink']) { - $cell_content .= ''.Display::return_icon('edit.gif', get_lang('Edit')).''; + $cell_content .= ''. + Display::return_icon('edit.gif', get_lang('Edit')).''; } else { $cell_content .= ''.$this_lnk['name'].''; } @@ -194,6 +208,7 @@ class CourseHome $table->updateCellAttributes($cell_number / $numcols, ($cell_number) % $numcols, 'width="32%" height="42"'); $cell_number++; } + return $table->toHtml(); } @@ -204,7 +219,8 @@ class CourseHome * @param string $course_tool_category contains the category of tools to display: * "Public", "PublicButHide", "courseAdmin", "claroAdmin" */ - public static function show_tool_2column($course_tool_category) { + public static function show_tool_2column($course_tool_category) + { $html = ''; $web_code_path = api_get_path(WEB_CODE_PATH); $course_tool_table = Database::get_course_table(TABLE_TOOL_LIST); @@ -290,12 +306,20 @@ class CourseHome $published_lp_id = self::get_published_lp_id_from_link($tool['link']); if (!api_is_allowed_to_edit(null, true) && - !learnpath::is_lp_visible_for_student($published_lp_id, api_get_user_id(), api_get_course_id(), api_get_session_id())) { + !learnpath::is_lp_visible_for_student( + $published_lp_id, + api_get_user_id(), + api_get_course_id(), + api_get_session_id() + ) + ) { continue; } } - if (api_get_session_id() != 0 && in_array($tool['name'], array('course_maintenance', 'course_setting'))) { + if (api_get_session_id() != 0 && + in_array($tool['name'], array('course_maintenance', 'course_setting')) + ) { continue; } @@ -304,7 +328,10 @@ class CourseHome } // 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) { + if (stripos($tool['link'], 'http://') === false && + stripos($tool['link'], 'https://') === false && + stripos($tool['link'], 'ftp://') === false + ) { $tool['link'] = $web_code_path.$tool['link']; } if ($course_tool_category == TOOL_PUBLIC_BUT_HIDDEN) { @@ -324,13 +351,18 @@ class CourseHome } $tool_name = self::translate_tool_name($tool); - $html .= Display::return_icon($tool['image'], $tool_name, array(), null, ICON_SIZE_MEDIUM).' '.$tool_name.''; + $html .= Display::return_icon( + $tool['image'], + $tool_name, + array(), + null, + ICON_SIZE_MEDIUM + ) . ' ' . $tool_name . ''; // This part displays the links to hide or remove a tool. // These links are only visible by the course manager. unset($lnk); if (api_is_allowed_to_edit(null, true) && !api_is_coach()) { - if ($tool['visibility'] == '1' || $tool['name'] == TOOL_TRACKING) { $link['name'] = Display::return_icon('remove.gif', get_lang('Deactivate')); $link['cmd'] = 'hide=yes'; @@ -391,6 +423,7 @@ class CourseHome if ($i % 2) { $html .= " "; } + return $html; } @@ -422,29 +455,38 @@ class CourseHome $col_link = "##003399"; break; case TOOL_AUTHORING: - $sql = "SELECT * FROM $course_tool_table WHERE category = 'authoring' AND c_id = $course_id $condition_session ORDER BY id"; + $sql = "SELECT * FROM $course_tool_table + WHERE category = 'authoring' AND c_id = $course_id $condition_session + 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"; + $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"; + $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"; + $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"; + $sql = "SELECT * FROM $course_tool_table + WHERE category = 'plugin' AND c_id = $course_id $condition_session + ORDER BY id"; $result = Database::query($sql); break; } @@ -479,8 +521,12 @@ class CourseHome if ($temp_row['image'] == 'scormbuilder.gif') { $lp_id = self::get_published_lp_id_from_link($temp_row['link']); - $lp = new learnpath(api_get_course_id(), $lp_id, api_get_user_id()); - $path = $lp->get_preview_image_path(64); + $lp = new learnpath( + api_get_course_id(), + $lp_id, + api_get_user_id() + ); + $path = $lp->get_preview_image_path(ICON_SIZE_BIG); $add = $lp->is_lp_visible_for_student( $lp_id, api_get_user_id(), @@ -505,10 +551,12 @@ class CourseHome 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"; + 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; @@ -523,17 +571,19 @@ class CourseHome $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"; + 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"; + WHERE + tl.c_id = $course_id AND + tip.c_id = $course_id AND + tl.on_homepage='1' $condition_session"; break; default: $sql_links = null; @@ -570,9 +620,11 @@ class CourseHome // Get blog members if ($is_platform_admin) { - $sql_blogs = "SELECT * FROM $tbl_blogs_rel_user blogs_rel_user WHERE blog_id =".$blog_id; + $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(); + $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); @@ -584,16 +636,19 @@ class CourseHome } } } + return $all_tools_list; } /** * Displays the tools of a certain category. - * @param array List of tools as returned by get_tools_category() - * @param int rows + * @param array $all_tools_list List of tools as returned by get_tools_category() + * @param bool $rows + * * @return void */ - public static function show_tools_category($all_tools_list, $rows = false) { + public static function show_tools_category($all_tools_list, $rows = false) + { global $_user; $theme = api_get_setting('homepage_view'); if ($theme == 'vertical_activity') { @@ -643,7 +698,13 @@ class CourseHome $studentview = true; } if (!api_is_allowed_to_edit(null, true) && - !learnpath::is_lp_visible_for_student($published_lp_id, api_get_user_id(), api_get_course_id(), api_get_session_id())) { + !learnpath::is_lp_visible_for_student( + $published_lp_id, + api_get_user_id(), + api_get_course_id(), + api_get_session_id() + ) + ) { continue; } } @@ -697,7 +758,10 @@ class CourseHome } // 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) { + if (stripos($tool['link'], 'http://') === false && + stripos($tool['link'], 'https://') === false && + stripos($tool['link'], 'ftp://') === false + ) { $tool['link'] = $web_code_path.$tool['link']; } if ($tool['visibility'] == '0' && $tool['admin'] != '1') { @@ -840,6 +904,7 @@ class CourseHome $i++; } } + return $html; } @@ -849,7 +914,8 @@ class CourseHome * @param id session id * @return string session data */ - public static function show_session_data($id_session) { + public static function show_session_data($id_session) + { $session_table = Database::get_main_table(TABLE_MAIN_SESSION); $user_table = Database::get_main_table(TABLE_MAIN_USER); $session_category_table = Database::get_main_table(TABLE_MAIN_SESSION_CATEGORY); @@ -860,17 +926,32 @@ class CourseHome $id_session = intval($id_session); } - $sql = 'SELECT name, nbr_courses, nbr_users, nbr_classes, DATE_FORMAT(date_start,"%d-%m-%Y") as date_start, DATE_FORMAT(date_end,"%d-%m-%Y") as date_end, lastname, firstname, username, session_admin_id, nb_days_access_before_beginning, nb_days_access_after_end, session_category_id, visibility - FROM '.$session_table.' + $sql = 'SELECT + name, + nbr_courses, + nbr_users, + nbr_classes, + DATE_FORMAT(date_start,"%d-%m-%Y") as date_start, + DATE_FORMAT(date_end,"%d-%m-%Y") as date_end, + lastname, + firstname, + username, + session_admin_id, + nb_days_access_before_beginning, + nb_days_access_after_end, + session_category_id, + visibility + FROM '.$session_table.' LEFT JOIN '.$user_table.' - ON id_coach = user_id + ON id_coach = user_id WHERE '.$session_table.'.id='.$id_session; $rs = Database::query($sql); $session = Database::store_result($rs); $session = $session[0]; - $sql_category = 'SELECT name FROM '.$session_category_table.' WHERE id = "'.intval($session['session_category_id']).'"'; + $sql_category = 'SELECT name FROM '.$session_category_table.' + WHERE id = "'.intval($session['session_category_id']).'"'; $rs_category = Database::query($sql_category); $session_category = ''; if (Database::num_rows($rs_category) > 0) { @@ -890,7 +971,8 @@ class CourseHome $output .= ''.get_lang('SessionCategory').': '.''.$session_category.''; } $output .= ''.get_lang('SessionName').': '.''.$session['name'].''.get_lang('GeneralCoach').': '.''.$session['lastname'].' '.$session['firstname'].' ('.$session['username'].')'.''; - $output .= ''.get_lang('SessionIdentifier').': '.Display::return_icon('star.png', ' ', array('align' => 'absmiddle')).''.get_lang('Date').': '.''.$msg_date.''; + $output .= ''.get_lang('SessionIdentifier').': '. + Display::return_icon('star.png', ' ', array('align' => 'absmiddle')).''.get_lang('Date').': '.''.$msg_date.''; return $output; } @@ -900,16 +982,17 @@ class CourseHome * @param array $tool The input record. * @return string Returns the name of the corresponding tool. */ - public static function translate_tool_name(& $tool) { + public static function translate_tool_name(& $tool) + { static $already_translated_icons = array( - 'file_html.gif', - 'file_html_na.gif', - 'scormbuilder.gif', - 'scormbuilder_na.gif', - 'blog.gif', - 'blog_na.gif', - 'external.gif', - 'external_na.gif' + 'file_html.gif', + 'file_html_na.gif', + 'scormbuilder.gif', + 'scormbuilder_na.gif', + 'blog.gif', + 'blog_na.gif', + 'external.gif', + 'external_na.gif' ); if (in_array($tool['image'], $already_translated_icons)) { @@ -939,7 +1022,8 @@ class CourseHome * @param string Link to published lp * @return int Learning path id */ - public static function get_published_lp_id_from_link($published_lp_link) { + public static function get_published_lp_id_from_link($published_lp_link) + { $lp_id = 0; $param_lp_id = strstr($published_lp_link, 'lp_id='); if (!empty($param_lp_id)) { @@ -951,7 +1035,12 @@ class CourseHome return $lp_id; } - static function get_navigation_items($include_admin_tools = false) { + /** + * @param bool $include_admin_tools + * @return array + */ + static function get_navigation_items($include_admin_tools = false) + { $navigation_items = array(); $course_id = api_get_course_int_id(); @@ -965,7 +1054,9 @@ class CourseHome $navigation_items['home']['link'] = api_get_path(REL_COURSE_PATH).Security::remove_XSS($_SESSION['_course']['path']).'/index.php'; $navigation_items['home']['name'] = get_lang('CourseHomepageLink'); - $sql_menu_query = "SELECT * FROM $course_tools_table WHERE c_id = $course_id AND visibility='1' and admin='0' ORDER BY id ASC"; + $sql_menu_query = "SELECT * FROM $course_tools_table + WHERE c_id = $course_id AND visibility='1' and admin='0' + ORDER BY id ASC"; $sql_result = Database::query($sql_menu_query); while ($row = Database::fetch_array($sql_result)) { $navigation_items[$row['id']] = $row; @@ -1012,7 +1103,8 @@ class CourseHome /** * Show a navigation menu */ - static function show_navigation_menu() { + public static function show_navigation_menu() + { $navigation_items = self::get_navigation_items(true); $course_id = api_get_course_id(); @@ -1031,7 +1123,9 @@ class CourseHome $url_item = parse_url($navigation_item['link']); $url_current = parse_url($_SERVER['REQUEST_URI']); - if (strpos($navigation_item['link'], 'chat') !== false && api_get_course_setting('allow_open_chat_window', $course_id)) { + if (strpos($navigation_item['link'], 'chat') !== false && + api_get_course_setting('allow_open_chat_window', $course_id) + ) { $html .= ''; foreach ($navigation_items as $key => $navigation_item) { - if (strpos($navigation_item['link'], 'chat') !== false && api_get_course_setting('allow_open_chat_window')) { + if (strpos($navigation_item['link'], 'chat') !== false && + api_get_course_setting('allow_open_chat_window') + ) { $html .= 'lp_id." AND parent_item_id = $id"; + WHERE + c_id = $course_id AND + lp_id = ".$this->lp_id." AND + parent_item_id = $id"; $res = Database::query($sql); if (Database::num_rows($res) < 1) { // Nothing to do (no children) @@ -311,12 +315,12 @@ class learnpathItem $course_id = api_get_course_int_id(); - $sql_del_view = "DELETE FROM $lp_item_view - WHERE c_id = $course_id AND lp_item_id = " . $this->db_id; + $sql = "DELETE FROM $lp_item_view + WHERE c_id = $course_id AND lp_item_id = " . $this->db_id; if (self::debug > 0) { - error_log('Deleting from lp_item_view: ' . $sql_del_view, 0); + error_log('Deleting from lp_item_view: ' . $sql, 0); } - Database::query($sql_del_view); + Database::query($sql); $sql = "SELECT * FROM $lp_item WHERE c_id = $course_id AND id = " . $this->db_id; @@ -329,7 +333,7 @@ class learnpathItem WHERE c_id = $course_id AND id = " . $this->db_id; Database::query($sql); if (self::debug > 0) { - error_log('Deleting from lp_item: ' . $sql_del_view); + error_log('Deleting from lp_item: ' . $sql); } if (api_get_setting('search_enabled') == 'true') { @@ -344,7 +348,7 @@ class learnpathItem /** * Drops a child from the children array - * @param string index of child item to drop + * @param string $item index of child item to drop * @return void */ public function drop_child($item) @@ -520,9 +524,10 @@ class learnpathItem case TOOL_DOCUMENT: $table_doc = Database::get_course_table(TABLE_DOCUMENT); $sql = 'SELECT path - FROM ' . $table_doc . ' - WHERE c_id = ' . $course_id . ' - AND id = ' . $path; + FROM ' . $table_doc . ' + WHERE + c_id = ' . $course_id . ' AND + id = ' . $path; $res = Database::query($sql); $row = Database::fetch_array($res); $real_path = 'document' . $row['path']; @@ -545,7 +550,7 @@ class learnpathItem /** * Gets the DB ID - * @return integer Database ID for the current item + * @return integer Database ID for the current item */ public function get_id() { @@ -570,10 +575,12 @@ class learnpathItem $this->interactions = array(); $course_id = api_get_course_int_id(); $tbl = Database::get_course_table(TABLE_LP_ITEM_VIEW); - $sql = "SELECT id FROM $tbl " . - "WHERE c_id = $course_id AND lp_item_id = " . $this->db_id . " " . - "AND lp_view_id = " . $this->view_id . " " . - "AND view_count = " . $this->attempt_id; + $sql = "SELECT id FROM $tbl + WHERE + c_id = $course_id AND + lp_item_id = " . $this->db_id . " AND + lp_view_id = " . $this->view_id . " AND + view_count = " . $this->attempt_id; $res = Database::query($sql); if (Database::num_rows($res) > 0) { $row = Database::fetch_array($res); @@ -950,7 +957,7 @@ class learnpathItem $sql = "SELECT seriousgame_mode FROM $table WHERE c_id = $course_id AND id = " . $this->lp_id; - $res = @Database::query($sql); + $res = Database::query($sql); if (Database::num_rows($res) < 1) { $this->error = "Could not find parent learnpath in learnpath table"; if (self::debug > 2) { @@ -1014,8 +1021,7 @@ class learnpathItem } if (!isset($abs_path)) { $path = $this->get_file_path(); - $abs_path = api_get_path(SYS_COURSE_PATH) . api_get_course_path( - ) . '/' . $path; + $abs_path = api_get_path(SYS_COURSE_PATH) . api_get_course_path() . '/' . $path; //echo "Abs path coming from item : ".$abs_path."
\n"; } /* @@ -1032,12 +1038,10 @@ class learnpathItem case TOOL_QUIZ: case 'sco': // Get the document and, if HTML, open it. - if (is_file($abs_path)) { // for now, read the whole file in one go (that's gonna be // a problem when the file is too big). $info = pathinfo($abs_path); - $ext = $info['extension']; switch (strtolower($ext)) { @@ -1641,8 +1645,7 @@ class learnpathItem default: // Ignore. break; } - //error_log(str_repeat(' ', $recursivity), 'found files '.print_r($files_list, true), 0); - //return $files_list; + $checked_files_list = array(); $checked_array_list = array(); foreach ($files_list as $idx => $file) { @@ -1680,9 +1683,9 @@ class learnpathItem /** * Gets the item status - * @param boolean $check_db Do or don't check into the database for the latest value. Optional. Default is true - * @param boolean $update_local Do or don't update the local attribute value with what's been found in DB - * @return string Current status or 'Not attempted' if no status set yet + * @param boolean $check_db Do or don't check into the database for the latest value. Optional. Default is true + * @param boolean $update_local Do or don't update the local attribute value with what's been found in DB + * @return string Current status or 'Not attempted' if no status set yet */ public function get_status($check_db = true, $update_local = false) { @@ -1812,8 +1815,9 @@ class learnpathItem } if ($query_db === true) { $table = Database::get_course_table(TABLE_LP_ITEM_VIEW); - $sql = "SELECT start_time, total_time FROM $table - WHERE + $sql = "SELECT start_time, total_time + FROM $table + WHERE c_id = $course_id AND id = '" . $this->db_item_view_id . "' AND view_count = '" . $this->get_attempt_id() . "'"; @@ -1879,8 +1883,10 @@ class learnpathItem { $lp_item = Database::get_course_table(TABLE_LP_ITEM); $course_id = api_get_course_int_id(); - $sql = "SELECT * FROM $lp_item WHERE c_id = $course_id - AND id='" . Database::escape_string($this->db_id) . "'"; + $sql = "SELECT * FROM $lp_item + WHERE + c_id = $course_id AND + id='" . Database::escape_string($this->db_id) . "'"; $res = Database::query($sql); $row = Database::fetch_array($res); return $row['terms']; @@ -2029,7 +2035,7 @@ class learnpathItem /** * Tells if a restart is allowed (take it from $this->prevent_reinit and $this->status) - * @return integer -1 if retaking the sco another time for credit is not allowed, + * @return integer -1 if retaking the sco another time for credit is not allowed, * 0 if it is not allowed but the item has to be finished * 1 if it is allowed. Defaults to 1 */ @@ -2104,7 +2110,7 @@ class learnpathItem * Outputs the item contents * @return string HTML file (displayable in an