diff --git a/main/exercice/exercise.lib.php b/main/exercice/exercise.lib.php index 852eea2d71..91a61d0fde 100755 --- a/main/exercice/exercise.lib.php +++ b/main/exercice/exercise.lib.php @@ -1504,7 +1504,9 @@ function convert_score($score, $weight) { } /** - * Getting all active exercises from a course from a session (if a session_id is provided we will show all the exercises in the course + all exercises in the session) + * Getting all active exercises from a course from a session + * (if a session_id is provided we will show all the exercises in the course + + * all exercises in the session) * @param array course data * @param int session id * @param boolean Check publications dates @@ -1516,7 +1518,14 @@ function convert_score($score, $weight) { * 3 = active <> -1 * @return array array with exercise data */ -function get_all_exercises($course_info = null, $session_id = 0, $check_publication_dates = false, $search_exercise = '', $search_all_sessions = false, $active = 2) { +function get_all_exercises( + $course_info = null, + $session_id = 0, + $check_publication_dates = false, + $search_exercise = '', + $search_all_sessions = false, + $active = 2 +) { $TBL_EXERCICES = Database :: get_course_table(TABLE_QUIZ_TEST); $course_id = api_get_course_int_id(); @@ -1550,12 +1559,21 @@ function get_all_exercises($course_info = null, $session_id = 0, $check_publicat } if ($search_all_sessions == true) { - $conditions = array('where'=>array($active_sql . ' c_id = ? '. $needle_where . $time_conditions => array($course_id, $needle)), 'order'=>'title'); + $conditions = array( + 'where' => array($active_sql . ' c_id = ? '. $needle_where . $time_conditions => array($course_id, $needle)), + 'order' => 'title' + ); } else { if ($session_id == 0) { - $conditions = array('where'=>array($active_sql . ' session_id = ? AND c_id = ? '. $needle_where . $time_conditions => array($session_id, $course_id, $needle)), 'order'=>'title'); + $conditions = array( + 'where' => array($active_sql . ' session_id = ? AND c_id = ? '. $needle_where . $time_conditions => array($session_id, $course_id, $needle)), + 'order' =>'title' + ); } else { - $conditions = array('where'=>array($active_sql . ' (session_id = 0 OR session_id = ? ) AND c_id = ? ' . $needle_where . $time_conditions => array($session_id, $course_id, $needle)), 'order'=>'title'); + $conditions = array( + 'where' => array($active_sql . ' (session_id = 0 OR session_id = ? ) AND c_id = ? ' . $needle_where . $time_conditions => array($session_id, $course_id, $needle)), + 'order' => 'title' + ); } } diff --git a/main/inc/ajax/course_home.ajax.php b/main/inc/ajax/course_home.ajax.php index 04b23d7dd0..526fbb31d9 100755 --- a/main/inc/ajax/course_home.ajax.php +++ b/main/inc/ajax/course_home.ajax.php @@ -5,7 +5,6 @@ * Responses to AJAX calls */ $action = $_GET['a']; -$now = time(); switch ($action) { case 'set_visibility': @@ -108,10 +107,11 @@ switch ($action) { require_once '../global.inc.php'; require_once api_get_path(SYS_CODE_PATH).'newscorm/learnpathList.class.php'; - + $now = time(); $page = intval($_REQUEST['page']); //page $limit = intval($_REQUEST['rows']); // quantity of rows - $sidx = $_REQUEST['sidx']; //index to filter + //index to filter + $sidx = isset($_REQUEST['sidx']) && !empty($_REQUEST['sidx']) ? $_REQUEST['sidx'] : 'id'; $sord = $_REQUEST['sord']; //asc or desc if (!in_array($sord, array('asc','desc'))) { $sord = 'desc'; @@ -119,6 +119,7 @@ switch ($action) { $session_id = intval($_REQUEST['session_id']); $course_id = intval($_REQUEST['course_id']); + //Filter users that does not belong to the session if (!api_is_platform_admin()) { $new_session_list = UserManager::get_personal_session_course_list(api_get_user_id()); @@ -132,25 +133,28 @@ switch ($action) { } } - if (!$sidx) { - $sidx = 1; - } - $start = $limit*$page - $limit; - $course_list = SessionManager::get_course_list_by_session_id($session_id); + $course_list = SessionManager::get_course_list_by_session_id($session_id); $count = 0; - + $temp = array(); foreach ($course_list as $item) { - $list = new LearnpathList(api_get_user_id(), $item['code'], $session_id); + $list = new LearnpathList(api_get_user_id(), $item['code'], $session_id); $flat_list = $list->get_flat_list(); $lps[$item['code']] = $flat_list; $course_url = api_get_path(WEB_COURSE_PATH).$item['directory'].'/?id_session='.$session_id; - $item['title'] = Display::url($item['title'], $course_url, array('target'=>SESSION_LINK_TARGET)); + $item['title'] = Display::url($item['title'], $course_url, array('target' => SESSION_LINK_TARGET)); - foreach($flat_list as $lp_id => $lp_item) { + foreach ($flat_list as $lp_id => $lp_item) { $temp[$count]['id']= $lp_id; $lp_url = api_get_path(WEB_CODE_PATH).'newscorm/lp_controller.php?cidReq='.$item['code'].'&id_session='.$session_id.'&lp_id='.$lp_id.'&action=view'; - $last_date = Tracking::get_last_connection_date_on_the_course(api_get_user_id(),$item['code'], $session_id, false); + + $last_date = Tracking::get_last_connection_date_on_the_course( + api_get_user_id(), + $item['code'], + $session_id, + false + ); + if ($lp_item['modified_on'] == '0000-00-00 00:00:00' || empty($lp_item['modified_on'])) { $lp_date = api_get_local_time($lp_item['created_on']); $image = 'new.gif'; @@ -160,6 +164,7 @@ switch ($action) { $image = 'moderator_star.png'; $label = get_lang('LearnpathUpdated'); } + if (strtotime($last_date) < strtotime($lp_date)) { $icons = Display::return_icon($image, get_lang('TitleNotification').': '.$label.' - '.$lp_date); } @@ -170,7 +175,7 @@ switch ($action) { $date = '-'; } - //Checking LP publicated and expired_on dates + // Checking LP publicated and expired_on dates if (!empty($lp_item['publicated_on']) && $lp_item['publicated_on'] != '0000-00-00 00:00:00') { if ($now < api_strtotime($lp_item['publicated_on'], 'UTC')) { continue; @@ -183,7 +188,11 @@ switch ($action) { } } - $temp[$count]['cell']=array($date, $item['title'], Display::url($icons.' '.$lp_item['lp_name'], $lp_url, array('target'=>SESSION_LINK_TARGET))); + $temp[$count]['cell'] = array( + $date, + $item['title'], + Display::url($icons.' '.$lp_item['lp_name'], $lp_url, array('target'=>SESSION_LINK_TARGET)) + ); $temp[$count]['course'] = strip_tags($item['title']); $temp[$count]['lp'] = $lp_item['lp_name']; $temp[$count]['date'] = $lp_item['publicated_on']; @@ -220,16 +229,16 @@ switch ($action) { $response->records = $count; echo json_encode($response); break; - case 'session_courses_lp_by_week': - require_once '../global.inc.php'; require_once api_get_path(SYS_CODE_PATH).'newscorm/learnpathList.class.php'; + $now = time(); $page = intval($_REQUEST['page']); //page $limit = intval($_REQUEST['rows']); // quantity of rows - $sidx = $_REQUEST['sidx']; //index to filter - if (empty($sidx)) $sidx = 'course'; + $sidx = isset($_REQUEST['sidx']) && !empty($_REQUEST['sidx']) ? $_REQUEST['sidx'] : 'course'; + $sidx = str_replace(array('week desc,', ' '), '', $sidx); + $sord = $_REQUEST['sord']; //asc or desc if (!in_array($sord, array('asc','desc'))) { $sord = 'desc'; @@ -268,7 +277,7 @@ switch ($action) { $lps[$item['code']] = $flat_list; $item['title'] = Display::url($item['title'],api_get_path(WEB_COURSE_PATH).$item['directory'].'/?id_session='.$session_id,array('target'=>SESSION_LINK_TARGET)); - foreach($flat_list as $lp_id => $lp_item) { + foreach ($flat_list as $lp_id => $lp_item) { $temp[$count]['id']= $lp_id; $lp_url = api_get_path(WEB_CODE_PATH).'newscorm/lp_controller.php?cidReq='.$item['code'].'&id_session='.$session_id.'&lp_id='.$lp_id.'&action=view'; @@ -315,8 +324,9 @@ switch ($action) { $count++; } } - - $temp = msort($temp, $sidx, $sord); + if (!empty($sidx)) { + $temp = msort($temp, $sidx, $sord); + } $response = new stdClass(); $i =0; @@ -348,10 +358,12 @@ switch ($action) { case 'session_courses_lp_by_course': require_once '../global.inc.php'; require_once api_get_path(SYS_CODE_PATH).'newscorm/learnpathList.class.php'; - + $now = time(); $page = intval($_REQUEST['page']); //page $limit = intval($_REQUEST['rows']); // quantity of rows - $sidx = $_REQUEST['sidx']; //index to filter + $sidx = isset($_REQUEST['sidx']) && !empty($_REQUEST['sidx']) ? $_REQUEST['sidx'] : 'id'; + $sidx = str_replace(array('course asc,', ' '), '', $sidx); + $sord = $_REQUEST['sord']; //asc or desc if (!in_array($sord, array('asc','desc'))) { $sord = 'desc'; @@ -372,13 +384,8 @@ switch ($action) { } } - if (!$sidx) { - $sidx = 1; - } - $start = $limit*$page - $limit; $course_list = SessionManager::get_course_list_by_session_id($session_id); - $count = 0; foreach ($course_list as $item) { @@ -445,12 +452,12 @@ switch ($action) { $response = new stdClass(); $i =0; - foreach($temp as $key=>$row) { + foreach ($temp as $key=>$row) { $row = $row['cell']; if (!empty($row)) { if ($key >= $start && $key < ($start + $limit)) { $response->rows[$i]['id']= $key; - $response->rows[$i]['cell']=array($row[0], $row[1], $row[2],$row[3]); + $response->rows[$i]['cell']=array($row[0], $row[1], $row[2]); $i++; } } diff --git a/main/inc/lib/array.lib.php b/main/inc/lib/array.lib.php index 77230ac549..c7bc36de07 100755 --- a/main/inc/lib/array.lib.php +++ b/main/inc/lib/array.lib.php @@ -13,7 +13,7 @@ * * @param array a dimensional array * @return array an array with unique values - * + * */ function array_unique_dimensional($array) { if(!is_array($array)) @@ -32,9 +32,9 @@ function array_unique_dimensional($array) { } /** - * + * * Sort multidimensional arrays - * + * * @param array unsorted multidimensional array * @param string key to be sorted * @return array result array @@ -84,16 +84,16 @@ function array_walk_recursive_limited(&$array, $function, $apply_to_keys_also = unset($array[$key]); } } - } + } $recursive_counter--; } function utf8_sort($array) { - $old_locale = setlocale(LC_ALL, null); + $old_locale = setlocale(LC_ALL, null); $code = api_get_language_isocode(); $locale_list = array($code.'.utf8', 'en.utf8','en_US.utf8','en_GB.utf8'); $try_sort = false; - + foreach($locale_list as $locale) { $my_local = setlocale(LC_COLLATE, $locale); if ($my_local) { @@ -101,11 +101,11 @@ function utf8_sort($array) { break; } } - + if ($try_sort) { uasort($array, 'strcoll'); } - setlocale(LC_COLLATE, $old_locale); + setlocale(LC_COLLATE, $old_locale); return $array; } @@ -114,4 +114,4 @@ function array_to_string($array, $separator = ',') { return ''; } return implode($separator.' ', $array); -} \ No newline at end of file +} diff --git a/main/inc/lib/main_api.lib.php b/main/inc/lib/main_api.lib.php index 161dc36b4f..843f4c2b1d 100755 --- a/main/inc/lib/main_api.lib.php +++ b/main/inc/lib/main_api.lib.php @@ -69,6 +69,8 @@ define('SESSION_VISIBLE', 2); define('SESSION_INVISIBLE', 3); // not available define('SESSION_AVAILABLE', 4); +define('SESSION_LINK_TARGET','_self'); + define('SUBSCRIBE_ALLOWED', 1); define('SUBSCRIBE_NOT_ALLOWED', 0); define('UNSUBSCRIBE_ALLOWED', 1); diff --git a/main/inc/lib/model.lib.php b/main/inc/lib/model.lib.php index 1d92b31374..b3d86b0ca7 100755 --- a/main/inc/lib/model.lib.php +++ b/main/inc/lib/model.lib.php @@ -170,12 +170,14 @@ class Model return $id; } } + return false; } /** * Updates the obj in the database. The $params['id'] must exist in order to update a record * @param array $values + * * @return bool * */ diff --git a/main/inc/lib/tracking.lib.php b/main/inc/lib/tracking.lib.php index c631019ff3..bfe2a1d9cc 100755 --- a/main/inc/lib/tracking.lib.php +++ b/main/inc/lib/tracking.lib.php @@ -7,10 +7,6 @@ * @package chamilo.library * @author Julio Montoya (Score average fixes) */ -/** - * Code - */ -define('SESSION_LINK_TARGET','_self'); require_once api_get_path(SYS_CODE_PATH).'exercice/exercise.lib.php'; require_once api_get_path(SYS_CODE_PATH).'newscorm/learnpathList.class.php'; @@ -3019,8 +3015,14 @@ class Tracking $exercise_graph_list = array(); foreach ($course_list as $course_data) { - - $exercise_list = get_all_exercises($course_data, $my_session_id); + $exercise_list = get_all_exercises( + $course_data, + $my_session_id, + false, + null, + false, + 1 + ); foreach ($exercise_list as $exercise_data) { $exercise_obj = new Exercise($course_data['id']); $exercise_obj->read($exercise_data['id']); @@ -3352,7 +3354,14 @@ class Tracking //$exercise_list = get_all_exercises($course_info, $session_id, true); // Show exercise results of invisible exercises? see BT#4091 - $exercise_list = get_all_exercises($course_info, $session_id, false); + $exercise_list = get_all_exercises( + $course_info, + $session_id, + false, + null, + false, + 1 + ); $to_graph_exercise_result = array(); diff --git a/main/mySpace/lp_tracking.php b/main/mySpace/lp_tracking.php index fbbc173fbb..be080f4e8f 100755 --- a/main/mySpace/lp_tracking.php +++ b/main/mySpace/lp_tracking.php @@ -41,12 +41,12 @@ if (isset($_GET['course'])) { $user_infos = UserManager :: get_user_info_by_id($user_id); $name = api_get_person_name($user_infos['firstname'], $user_infos['lastname']); -if (!api_is_platform_admin(true) && !CourseManager :: is_course_teacher(api_get_user_id(), $cidReq) && !Tracking :: is_allowed_to_coach_student(api_get_user_id(), $_GET['student_id']) && !api_is_drh() && !api_is_course_tutor()) { - api_not_allowed(); +if (!api_is_platform_admin(true) && !CourseManager :: is_course_teacher(api_get_user_id(), $cidReq) && !Tracking :: is_allowed_to_coach_student(api_get_user_id(), $_GET['student_id']) && !api_is_drh() && !api_is_course_tutor()) { + api_not_allowed(); } $course_exits = CourseManager::course_exists($cidReq); -if (!empty($course_exits)) { +if (!empty($course_exits)) { $course_info = api_get_course_info($cidReq); } else { api_not_allowed(); @@ -96,7 +96,6 @@ $list = learnpath :: get_flat_ordered_items_list($lp_id, 0, $course_info['real_i $origin = 'tracking'; if ($export_csv) { require_once api_get_path(SYS_CODE_PATH).'newscorm/lp_stats.php'; - //Export :: export_table_csv($csv_content, 'reporting_student'); } else { ob_start(); require_once api_get_path(SYS_CODE_PATH).'newscorm/lp_stats.php'; diff --git a/main/newscorm/learnpathList.class.php b/main/newscorm/learnpathList.class.php index 8cbc76d6ca..5efd130f34 100755 --- a/main/newscorm/learnpathList.class.php +++ b/main/newscorm/learnpathList.class.php @@ -31,7 +31,7 @@ class learnpathList * @param int Optional session id (otherwise we use api_get_session_id()) * @return void */ - function __construct($user_id, $course_code = '', $session_id = null, $order_by = null, $check_publication_dates = false) + public function __construct($user_id, $course_code = '', $session_id = null, $order_by = null, $check_publication_dates = false) { $course_info = api_get_course_info($course_code); $lp_table = Database::get_course_table(TABLE_LP_MAIN); @@ -65,10 +65,10 @@ class learnpathList if ($check_publication_dates) { $time_conditions = " AND ( - (publicated_on <> '0000-00-00 00:00:00' AND publicated_on < '$now' AND expired_on <> '0000-00-00 00:00:00' AND expired_on > '$now' ) OR - (publicated_on <> '0000-00-00 00:00:00' AND publicated_on < '$now' AND expired_on = '0000-00-00 00:00:00') OR - (publicated_on = '0000-00-00 00:00:00' AND expired_on <> '0000-00-00 00:00:00' AND expired_on > '$now') OR - (publicated_on = '0000-00-00 00:00:00' AND expired_on = '0000-00-00 00:00:00' )) + (publicated_on <> '0000-00-00 00:00:00' AND publicated_on < '$now' AND expired_on <> '0000-00-00 00:00:00' AND expired_on > '$now' ) OR + (publicated_on <> '0000-00-00 00:00:00' AND publicated_on < '$now' AND expired_on = '0000-00-00 00:00:00') OR + (publicated_on = '0000-00-00 00:00:00' AND expired_on <> '0000-00-00 00:00:00' AND expired_on > '$now') OR + (publicated_on = '0000-00-00 00:00:00' AND expired_on = '0000-00-00 00:00:00' )) "; } diff --git a/main/session/index.php b/main/session/index.php index b371ae0b6d..81fcf53576 100755 --- a/main/session/index.php +++ b/main/session/index.php @@ -68,8 +68,15 @@ if (!empty($new_session_list)) { $course_info = api_get_course_info($my_course['code']); - //Getting all exercises from the current course - $exercise_list = get_all_exercises($course_info, $my_session_id, true); + // Getting all visible exercises from the current course + $exercise_list = get_all_exercises( + $course_info, + $my_session_id, + true, + null, + false, + 1 + ); $course['name'] = $course_info['name']; $course['id'] = $course_info['real_id']; @@ -117,7 +124,6 @@ if (!empty($course_list)) { 'publicated_on ASC', true ); - $lp_list = $list->get_flat_list(); $lp_count = 0; @@ -131,7 +137,16 @@ if (!empty($course_list)) { } $course_info = api_get_course_info($course_data['code']); - $exercise_count = count(get_all_exercises($course_info, $session_id, true)); + $exercise_count = count( + get_all_exercises( + $course_info, + $session_id, + true, + null, + false, + 1 + ) + ); $max_mutation_date = ''; $last_date = Tracking::get_last_connection_date_on_the_course(