From 04a69225e1d179a7a600d450df899ae49e291b2b Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Mon, 22 Apr 2013 18:15:15 +0200 Subject: [PATCH] Adding track_e_hotpotatoes.c_id, track_e_exercices.c_id, and track_e_attempt.c_id fields see #6090 --- main/admin/class_user_import.php | 25 +- main/admin/course_edit.php | 3 +- main/admin/user_move_stats.php | 499 +++++++++--------- main/exercice/admin.php | 2 +- main/exercice/exercice.php | 6 +- main/exercice/exercise.class.php | 21 +- main/exercice/exercise.lib.php | 164 ++++-- main/exercice/exercise_history.php | 10 +- main/exercice/exercise_report.php | 74 ++- main/exercice/exercise_result.class.php | 30 +- main/exercice/exercise_show.php | 45 +- main/exercice/exercise_submit.php | 5 +- .../hotpotatoes_exercise_result.class.php | 54 +- main/exercice/mark_free_answer.php | 16 +- main/exercice/overview.php | 2 +- main/exercice/savescores.php | 4 +- main/exercice/stats.php | 12 +- main/exercice/testcategory.class.php | 5 +- main/gradebook/gradebook_result.class.php | 46 +- main/gradebook/lib/be/exerciselink.class.php | 63 ++- main/inc/ajax/exercise.ajax.php | 4 +- main/inc/lib/course.lib.php | 8 +- main/inc/lib/events.lib.inc.php | 243 ++++++--- main/inc/lib/nanogong.lib.php | 62 ++- main/inc/lib/tracking.lib.php | 146 ++--- main/install/1.10.0/db_main.sql | 15 +- .../1.10.0/migrate-db-1.9.0-1.10.0-pre.sql | 6 +- main/mySpace/myStudents.php | 17 +- main/mySpace/myspace.lib.php | 147 +++--- main/mySpace/progression.php | 4 +- main/mySpace/reussite.php | 15 +- main/newscorm/learnpath.class.php | 4 +- main/newscorm/lp_stats.php | 14 +- main/reports/modules/quiz.php | 19 +- main/session/index.php | 52 +- main/social/home.php | 1 - main/tracking/course_session_report.php | 3 +- main/tracking/exams.php | 8 +- main/tracking/lp_results_by_user.php | 2 +- main/tracking/personnalLog.php | 2 +- main/tracking/question_course_report.php | 3 +- main/tracking/userLog.php | 4 +- main/tracking/userlogCSV.php | 3 +- 43 files changed, 1045 insertions(+), 823 deletions(-) diff --git a/main/admin/class_user_import.php b/main/admin/class_user_import.php index b31bc6553a..5864d2a018 100644 --- a/main/admin/class_user_import.php +++ b/main/admin/class_user_import.php @@ -16,7 +16,7 @@ function validate_data($user_classes) { global $purification_option_for_usernames; $errors = array (); $classcodes = array (); - + if (!isset($_POST['subscribe']) && !isset($_POST['subscribe'])) { $user_class['error'] = get_lang('SelectAnAction'); $errors[] = $user_class; @@ -26,20 +26,20 @@ function validate_data($user_classes) { $user_class['line'] = $index + 1; // 1. Check whether mandatory fields are set. $mandatory_fields = array ('UserName', 'ClassName'); - - foreach ($mandatory_fields as $key => $field) { - if (!isset ($user_class[$field]) || strlen($user_class[$field]) == 0) { + + foreach ($mandatory_fields as $key => $field) { + if (!isset ($user_class[$field]) || strlen($user_class[$field]) == 0) { $user_class['error'] = get_lang($field.'Mandatory'); $errors[] = $user_class; } } - + // 2. Check whether classcode exists. if (isset ($user_class['ClassName']) && strlen($user_class['ClassName']) != 0) { // 2.1 Check whether code has been allready used in this CVS-file. if (!isset ($classcodes[$user_class['ClassName']])) { // 2.1.1 Check whether code exists in DB. - $class_table = Database :: get_main_table(TABLE_MAIN_CLASS); + $class_table = Database :: get_main_table(TABLE_MAIN_CLASS); $sql = "SELECT * FROM $class_table WHERE name = '".Database::escape_string($user_class['ClassName'])."'"; $res = Database::query($sql); if (Database::num_rows($res) == 0) { @@ -57,7 +57,7 @@ function validate_data($user_classes) { $user_class['error'] = get_lang('UserNameTooLong').': '.$user_class['UserName']; $errors[] = $user_class; } - $username = UserManager::purify_username($user_class['UserName'], $purification_option_for_usernames); + $username = UserManager::purify_username($user_class['UserName'], $purification_option_for_usernames); // 3.2. Check whether username exists. if (UserManager::is_username_available($username)) { $user_class['error'] = get_lang('UnknownUser').': '.$username; @@ -83,7 +83,7 @@ function save_data($users_classes) { // Data parsing: purification + conversion (UserName, ClassName) --> (user_is, class_id) $csv_data = array (); foreach ($users_classes as $index => $user_class) { - + $sql1 = "SELECT user_id FROM $user_table WHERE username = '".Database::escape_string(UserManager::purify_username($user_class['UserName'], $purification_option_for_usernames))."'"; $res1 = Database::query($sql1); $obj1 = Database::fetch_object($res1); @@ -94,7 +94,7 @@ function save_data($users_classes) { $csv_data[$obj1->user_id][$obj2->id] = 1; } } - + // Logic for processing the request (data + UI options). $db_subscriptions = array(); foreach ($csv_data as $user_id => $csv_subscriptions) { @@ -105,7 +105,7 @@ function save_data($users_classes) { } $to_subscribe = array_diff(array_keys($csv_subscriptions), array_keys($db_subscriptions)); $to_unsubscribe = array_diff(array_keys($db_subscriptions), array_keys($csv_subscriptions)); - + // Subscriptions for new classes. if ($_POST['subscribe']) { foreach ($to_subscribe as $class_id) { @@ -140,7 +140,6 @@ $this_section = SECTION_PLATFORM_ADMIN; api_protect_admin_script(true); require_once api_get_path(LIBRARY_PATH).'import.lib.php'; -require_once api_get_path(LIBRARY_PATH).'classmanager.lib.php'; $tool_name = get_lang('AddUsersToAClass').' CSV'; @@ -160,9 +159,9 @@ $form->addElement('style_submit_button', 'submit', get_lang('Import'), 'class="s if ($form->validate()) { $users_classes = parse_csv_data($_FILES['import_file']['tmp_name']); - + $errors = validate_data($users_classes); - if (count($errors) == 0) { + if (count($errors) == 0) { save_data($users_classes); header('Location: class_list.php?action=show_message&message='.urlencode(get_lang('FileImported'))); exit(); diff --git a/main/admin/course_edit.php b/main/admin/course_edit.php index 640c6d18b2..c14520e81f 100644 --- a/main/admin/course_edit.php +++ b/main/admin/course_edit.php @@ -33,7 +33,8 @@ if (empty($course)) { // Get course teachers $table_course_user = Database :: get_main_table(TABLE_MAIN_COURSE_USER); $order_clause = api_sort_by_first_name() ? ' ORDER BY firstname, lastname' : ' ORDER BY lastname, firstname'; -$sql = "SELECT user.user_id,lastname,firstname FROM $table_user as user,$table_course_user as course_user WHERE course_user.status='1' AND course_user.user_id=user.user_id AND course_user.course_code='".$course_code."'".$order_clause; +$sql = "SELECT user.user_id,lastname,firstname FROM $table_user as user,$table_course_user as course_user +WHERE course_user.status='1' AND course_user.user_id=user.user_id AND course_user.course_code='".$course_code."'".$order_clause; $res = Database::query($sql); $course_teachers = array(); while ($obj = Database::fetch_object($res)) { diff --git a/main/admin/user_move_stats.php b/main/admin/user_move_stats.php index c0463b0d68..e0d9f50746 100644 --- a/main/admin/user_move_stats.php +++ b/main/admin/user_move_stats.php @@ -21,353 +21,353 @@ $debug = 0; function compare_data($result_message) { foreach ($result_message as $table=>$data) { - - $title = $table; + + $title = $table; if ($table == 'TRACK_E_EXERCISES') { $title = get_lang('Exercises'); } elseif ($table == 'TRACK_E_EXERCISES_IN_LP') { $title = get_lang('ExercisesInLp'); } elseif ($table == 'LP_VIEW') { $title = get_lang('LearningPaths'); - } + } echo '

'.get_lang($title).'


'; - - if (is_array($data)) { + + if (is_array($data)) { foreach ($data as $id => $item) { - + if ($table == 'TRACK_E_EXERCISES' || $table == 'TRACK_E_EXERCISES_IN_LP' ) { - echo "

".get_lang('Attempt')." #$id

"; + echo "

".get_lang('Attempt')." #$id

"; echo '

'; echo get_lang('Exercise').' #'.$item['exe_exo_id']; - echo '

'; + echo ''; if (!empty($item['orig_lp_id'])) { echo '

'; echo get_lang('LearningPath').' #'.$item['orig_lp_id']; echo '

'; - } + } //Process data $array = array('exe_date' =>get_lang('Date'), 'exe_result' =>get_lang('Score'),'exe_weighting'=>get_lang('Weighting')); foreach($item as $key=> $value) { if (in_array($key,array_keys($array))) { $key = $array[$key]; echo "$key = $value
"; - } + } } - } else { - echo "

".get_lang('Id')." #$id

"; + } else { + echo "

".get_lang('Id')." #$id

"; //process data foreach($item as $key=> $value) { - echo "$key = $value
"; + echo "$key = $value
"; } - } - } + } + } } else { echo get_lang('NoResults'); - } + } } } if (isset($_REQUEST['load_ajax'])) { //Checking the variable $_SESSION['combination'] that has all the information of the selected course (instead of using a lots of hidden variables ... ) if (isset($_SESSION['combination']) && !empty($_SESSION['combination'])) { - $combinations = $_SESSION['combination']; + $combinations = $_SESSION['combination']; $combination_result = $combinations[$_REQUEST['unique_id']]; if (empty($combination_result)) { echo get_lang('ThereWasAnError'); } else { - $origin_course_code = $combination_result['course_code']; - $origin_session_id = intval($combination_result['session_id']); + $course_info = api_get_course_info_by_id($combination_result['c_id']); + $origin_course_code = $course_info['code']; + $course_id = $course_info['real_id']; + $origin_session_id = intval($combination_result['session_id']); $new_session_id = intval($_REQUEST['session_id']); - + //if (!isset($_REQUEST['view_stat'])) { if ($origin_session_id == $new_session_id ) { echo get_lang('CantMoveToTheSameSession'); exit; } //} - $user_id = intval($_REQUEST['user_id']); - + $user_id = intval($_REQUEST['user_id']); + $new_course_list = SessionManager::get_course_list_by_session_id($new_session_id); - + $course_founded = false; - foreach ($new_course_list as $course_item) { + foreach ($new_course_list as $course_item) { if ($origin_course_code == $course_item['code']) { $course_founded = true; } } - - - $result_message = array(); + + $result_message = array(); $result_message_compare = array(); - + $update_database = true; - if (isset($_REQUEST['view_stat']) && $_REQUEST['view_stat'] == 1 ) { + if (isset($_REQUEST['view_stat']) && $_REQUEST['view_stat'] == 1 ) { $update_database = false; } - - //Check if the same course exist in the session destination + + //Check if the same course exist in the session destination if ($course_founded) { - - //Check if the user is registered in the session otherwise we will add it + + //Check if the user is registered in the session otherwise we will add it $result = SessionManager::get_users_by_session($new_session_id); if (empty($result) || !in_array($user_id, array_keys($result))) { - if ($debug) echo 'User added to the session'; + if ($debug) echo 'User added to the session'; //Registering user to the new session - SessionManager::suscribe_users_to_session($new_session_id, array($user_id), false); - } - + SessionManager::suscribe_users_to_session($new_session_id, array($user_id), false); + } + //Begin with the import process - $course_info = api_get_course_info($origin_course_code); - $course_id = $course_info['real_id']; - + $TABLETRACK_EXERCICES = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES); $TBL_TRACK_ATTEMPT = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT); $TBL_TRACK_E_COURSE_ACCESS = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_COURSE_ACCESS); $TBL_TRACK_E_LAST_ACCESS = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_LASTACCESS); - + $TBL_LP_VIEW = Database::get_course_table(TABLE_LP_VIEW); $TBL_NOTEBOOK = Database::get_course_table(TABLE_NOTEBOOK); $TBL_STUDENT_PUBLICATION = Database::get_course_table(TABLE_STUDENT_PUBLICATION); $TBL_STUDENT_PUBLICATION_ASSIGNMENT = Database::get_course_table(TABLE_STUDENT_PUBLICATION_ASSIGNMENT); $TBL_ITEM_PROPERTY = Database::get_course_table(TABLE_ITEM_PROPERTY); - + $TBL_DROPBOX_FILE = Database::get_course_table(TABLE_DROPBOX_FILE); $TBL_DROPBOX_POST = Database::get_course_table(TABLE_DROPBOX_POST); $TBL_AGENDA = Database::get_course_table(TABLE_AGENDA); - + $course_code = Database::escape_string($course_code); - + //1. track_e_exercises - + //ORIGINAL COURSE - - $sql = "SELECT * FROM $TABLETRACK_EXERCICES WHERE exe_cours_id = '$origin_course_code' AND session_id = $origin_session_id AND exe_user_id = $user_id "; + + $sql = "SELECT * FROM $TABLETRACK_EXERCICES WHERE c_id = '$course_id' AND session_id = $origin_session_id AND exe_user_id = $user_id "; $res = Database::query($sql); - $list = array(); + $list = array(); while($row = Database::fetch_array($res,'ASSOC')) { $list[$row['exe_id']]= $row; - } - + } + if (!empty($list)) foreach ($list as $exe_id =>$data) { if ($update_database) { $sql = "UPDATE $TABLETRACK_EXERCICES SET session_id = '$new_session_id' WHERE exe_id = $exe_id"; - $res = Database::query($sql); + $res = Database::query($sql); $result_message[$TABLETRACK_EXERCICES]++; } else { if(!empty($data['orig_lp_id']) && !empty($data['orig_lp_item_id'])) { $result_message['TRACK_E_EXERCISES'][$exe_id] = $data; - } else { + } else { $result_message['TRACK_E_EXERCISES_IN_LP'][$exe_id] = $data; } - } - } - + } + } + //DESTINY COURSE - + if (!$update_database) { - - $sql = "SELECT * FROM $TABLETRACK_EXERCICES WHERE exe_cours_id = '$origin_course_code' AND session_id = $new_session_id AND exe_user_id = $user_id "; + + $sql = "SELECT * FROM $TABLETRACK_EXERCICES WHERE c_id = '$course_id' AND session_id = $new_session_id AND exe_user_id = $user_id "; $res = Database::query($sql); - $list = array(); + $list = array(); while($row = Database::fetch_array($res,'ASSOC')) { $list[$row['exe_id']]= $row; - } - + } + if (!empty($list)) foreach ($list as $exe_id =>$data) { if ($update_database) { $sql = "UPDATE $TABLETRACK_EXERCICES SET session_id = '$new_session_id' WHERE exe_id = $exe_id"; - $res = Database::query($sql); + $res = Database::query($sql); $result_message[$TABLETRACK_EXERCICES]++; } else { if(!empty($data['orig_lp_id']) && !empty($data['orig_lp_item_id'])) { $result_message_compare['TRACK_E_EXERCISES'][$exe_id] = $data; - } else { + } else { $result_message_compare['TRACK_E_EXERCISES_IN_LP'][$exe_id] = $data; } - } - } + } + } } - - + + //2.track_e_attempt, track_e_attempt_recording, track_e_downloads //Nothing to do because there are not relationship with a session - - //3. track_e_course_access - - $sql = "SELECT * FROM $TBL_TRACK_E_COURSE_ACCESS WHERE course_code = '$origin_course_code' AND session_id = $origin_session_id AND user_id = $user_id "; + + //3. track_e_course_access + + $sql = "SELECT * FROM $TBL_TRACK_E_COURSE_ACCESS + WHERE course_code = '$origin_course_code' AND session_id = $origin_session_id AND user_id = $user_id "; $res = Database::query($sql); - $list = array(); + $list = array(); while($row = Database::fetch_array($res,'ASSOC')) { $list[$row['course_access_id']] = $row; - } - + } + if (!empty($list)) foreach ($list as $id => $data) { if ($update_database) { $sql = "UPDATE $TBL_TRACK_E_COURSE_ACCESS SET session_id = '$new_session_id' WHERE course_access_id = $id"; - if ($debug) echo $sql; - $res = Database::query($sql); - if ($debug) var_dump($res); + if ($debug) echo $sql; + $res = Database::query($sql); + if ($debug) var_dump($res); $result_message[$TBL_TRACK_E_COURSE_ACCESS]++; } else { //$result_message[$TBL_TRACK_E_COURSE_ACCESS][$id] = $data; - } + } } - + //4. track_e_lastaccess - - $sql = "SELECT access_id FROM $TBL_TRACK_E_LAST_ACCESS WHERE access_cours_code = '$origin_course_code' AND access_session_id = $origin_session_id AND access_user_id = $user_id "; + + $sql = "SELECT access_id FROM $TBL_TRACK_E_LAST_ACCESS WHERE access_cours_code = '$origin_course_code' AND access_session_id = $origin_session_id AND access_user_id = $user_id "; $res = Database::query($sql); - $list = array(); + $list = array(); while($row = Database::fetch_array($res,'ASSOC')) { $list[] = $row['access_id']; - } + } if (!empty($list)) foreach ($list as $id) { if ($update_database) { $sql = "UPDATE $TBL_TRACK_E_LAST_ACCESS SET access_session_id = '$new_session_id' WHERE access_id = $id"; - if ($debug) echo $sql; + if ($debug) echo $sql; $res = Database::query($sql); - if ($debug) var_dump($res); + if ($debug) var_dump($res); $result_message[$TBL_TRACK_E_LAST_ACCESS]++; - } - } - - //5. lp_item_view - + } + } + + //5. lp_item_view + //CHECK ORIGIN - + $sql = "SELECT * FROM $TBL_LP_VIEW WHERE user_id = $user_id AND session_id = $origin_session_id AND c_id = $course_id "; $res = Database::query($sql); - - //Getting the list of LPs in the new session + + //Getting the list of LPs in the new session $lp_list = new LearnpathList($user_id, $origin_course_code, $new_session_id); $flat_list = $lp_list->get_flat_list(); - - $list = array(); + + $list = array(); while($row = Database::fetch_array($res,'ASSOC')) { - //Checking if the LP exist in the new session - if (in_array($row['lp_id'], array_keys($flat_list))) { + //Checking if the LP exist in the new session + if (in_array($row['lp_id'], array_keys($flat_list))) { $list[$row['id']] = $row; - } + } } - + if (!empty($list)) foreach ($list as $id=>$data) { if ($update_database) { $sql = "UPDATE $TBL_LP_VIEW SET session_id = '$new_session_id' WHERE c_id = $course_id AND id = $id "; - if ($debug) var_dump($sql); - $res = Database::query($sql); - if ($debug) var_dump($res); + if ($debug) var_dump($sql); + $res = Database::query($sql); + if ($debug) var_dump($res); $result_message[$TBL_LP_VIEW]++; } else { //Getting all information of that lp_item_id $score = Tracking::get_avg_student_score($user_id, $origin_course_code, array($data['lp_id']),$origin_session_id); - $progress = Tracking::get_avg_student_progress($user_id, $origin_course_code, array($data['lp_id']),$origin_session_id); - $result_message['LP_VIEW'][$data['lp_id']] = array('score' => $score, 'progress' =>$progress); - } + $progress = Tracking::get_avg_student_progress($user_id, $origin_course_code, array($data['lp_id']),$origin_session_id); + $result_message['LP_VIEW'][$data['lp_id']] = array('score' => $score, 'progress' =>$progress); + } } - - + + //CHECk DESTINY if (!$update_database) { $sql = "SELECT * FROM $TBL_LP_VIEW WHERE user_id = $user_id AND session_id = $new_session_id AND c_id = $course_id"; $res = Database::query($sql); - - //Getting the list of LPs in the new session + + //Getting the list of LPs in the new session $lp_list = new LearnpathList($user_id, $origin_course_code, $new_session_id); $flat_list = $lp_list->get_flat_list(); - - $list = array(); + + $list = array(); while($row = Database::fetch_array($res,'ASSOC')) { - //Checking if the LP exist in the new session - if (in_array($row['lp_id'], array_keys($flat_list))) { + //Checking if the LP exist in the new session + if (in_array($row['lp_id'], array_keys($flat_list))) { $list[$row['id']] = $row; - } - } + } + } if (!empty($list)) - foreach ($list as $id=>$data) { + foreach ($list as $id=>$data) { //Getting all information of that lp_item_id $score = Tracking::get_avg_student_score($user_id, $origin_course_code, array($data['lp_id']), $new_session_id); - $progress = Tracking::get_avg_student_progress($user_id, $origin_course_code, array($data['lp_id']), $new_session_id); + $progress = Tracking::get_avg_student_progress($user_id, $origin_course_code, array($data['lp_id']), $new_session_id); $result_message_compare['LP_VIEW'][$data['lp_id']] = array('score' => $score, 'progress' =>$progress); } } - - + + //6. Agenda - + //calendar_event_attachment no problems no session_id $sql = "SELECT ref FROM $TBL_ITEM_PROPERTY WHERE tool = 'calendar_event' AND insert_user_id = $user_id AND c_id = $course_id "; $res = Database::query($sql); while($row = Database::fetch_array($res,'ASSOC')) { $id = $row['ref']; - if ($update_database) { + if ($update_database) { $sql = "UPDATE $TBL_AGENDA SET session_id = '$new_session_id' WHERE c_id = $course_id AND id = $id "; - if ($debug) var_dump($sql); + if ($debug) var_dump($sql); $res_update = Database::query($sql); - if ($debug) var_dump($res_update); + if ($debug) var_dump($res_update); $result_message['agenda']++; - } - } - + } + } + //7. Forum ?? So much problems when trying to import data - + //8. Student publication - Works - + //echo '

Student publication

'; - + $sql = "SELECT ref FROM $TBL_ITEM_PROPERTY WHERE tool = 'work' AND insert_user_id = $user_id AND c_id = $course_id"; if ($debug) echo $sql; $res = Database::query($sql); while($row = Database::fetch_array($res,'ASSOC')) { $id = $row['ref']; $sql = "SELECT * FROM $TBL_STUDENT_PUBLICATION WHERE id = $id AND session_id = $origin_session_id AND c_id = $course_id"; - if ($debug) var_dump($sql); + if ($debug) var_dump($sql); $sub_res = Database::query($sql); if (Database::num_rows($sub_res) > 0 ) { - $data = Database::fetch_array($sub_res,'ASSOC'); - if ($debug) var_dump($data); + $data = Database::fetch_array($sub_res,'ASSOC'); + if ($debug) var_dump($data); $parent_id = $data['parent_id']; if (isset($data['parent_id']) && !empty($data['parent_id'])) { $sql = "SELECT * FROM $TBL_STUDENT_PUBLICATION WHERE id = $parent_id AND c_id = $course_id"; $select_res = Database::query($sql); $parent_data = Database::fetch_array($select_res,'ASSOC'); if ($debug) var_dump($parent_data); - + $sys_course_path = api_get_path(SYS_COURSE_PATH); $course_dir = $sys_course_path . $course_info['path']; $base_work_dir = $course_dir . '/work'; - require_once api_get_path(SYS_CODE_PATH).'work/work.lib.php'; - - //Creating the parent folder in the session if does not exists already - + require_once api_get_path(SYS_CODE_PATH).'work/work.lib.php'; + + //Creating the parent folder in the session if does not exists already + //@todo ugly fix $search_this = "folder_moved_from_session_id_$origin_session_id"; $search_this2 = $parent_data['url']; - $sql = "SELECT * FROM $TBL_STUDENT_PUBLICATION - WHERE description like '%$search_this%' AND url LIKE '%$search_this2%' AND session_id = $new_session_id AND c_id = $course_id + $sql = "SELECT * FROM $TBL_STUDENT_PUBLICATION + WHERE description like '%$search_this%' AND url LIKE '%$search_this2%' AND session_id = $new_session_id AND c_id = $course_id ORDER BY id desc LIMIT 1"; if ($debug) echo $sql; $sub_res = Database::query($sql); $num_rows = Database::num_rows($sub_res); - - if ($num_rows > 0 ) { + + if ($num_rows > 0 ) { $new_result = Database::fetch_array($sub_res,'ASSOC'); $created_dir = $new_result['url']; - $new_parent_id = $new_result['id']; - } else { - + $new_parent_id = $new_result['id']; + } else { + if ($update_database) { - + $dir_name = substr($parent_data['url'], 1); $created_dir = create_unexisting_work_directory($base_work_dir, $dir_name); - $created_dir = '/'.$created_dir; + $created_dir = '/'.$created_dir; $now = api_get_utc_datetime(); - //Creating directory - $sql_add_publication = "INSERT INTO " . $TBL_STUDENT_PUBLICATION . " SET " . + //Creating directory + $sql_add_publication = "INSERT INTO " . $TBL_STUDENT_PUBLICATION . " SET " . "url = '".$created_dir."', c_id = '".$course_id."', title = '".$parent_data['title']."', @@ -375,25 +375,25 @@ if (isset($_REQUEST['load_ajax'])) { author = '', active = '0', accepted = '1', - filetype = 'folder', + filetype = 'folder', sent_date = '".$now."', qualification = '".$parent_data['qualification'] ."', parent_id = '', qualificator_id = '', date_of_qualification = '0000-00-00 00:00:00', - session_id = ".$new_session_id; + session_id = ".$new_session_id; $rest_insert = Database::query($sql_add_publication); if ($debug) echo ($sql_add_publication); // add the directory $id = Database::insert_id(); //Folder created - api_item_property_update($course_info, 'work', $id, 'DirectoryCreated', api_get_user_id()); + api_item_property_update($course_info, 'work', $id, 'DirectoryCreated', api_get_user_id()); if ($debug) var_dump($rest_insert); - $new_parent_id = $id; + $new_parent_id = $id; $result_message[$TBL_STUDENT_PUBLICATION.' - new folder created called: '.$created_dir]++; - } - } - + } + } + //Creating student_publication_assignment if exists $sql = "SELECT * FROM $TBL_STUDENT_PUBLICATION_ASSIGNMENT WHERE publication_id = $parent_id AND c_id = $course_id"; if ($debug) var_dump($sql); @@ -401,35 +401,35 @@ if (isset($_REQUEST['load_ajax'])) { if (Database::num_rows($rest_select) > 0 ) { if ($update_database) { $assignment_data = Database::fetch_array($rest_select,'ASSOC'); - $sql_add_publication = "INSERT INTO " . $TBL_STUDENT_PUBLICATION_ASSIGNMENT . " SET - c_id = '$course_id', + $sql_add_publication = "INSERT INTO " . $TBL_STUDENT_PUBLICATION_ASSIGNMENT . " SET + c_id = '$course_id', expires_on = '".$assignment_data['expires_on']."', ends_on = '".$assignment_data['ends_on']."', add_to_calendar = '".$assignment_data['add_to_calendar']."', enable_qualification = '".$assignment_data['enable_qualification']."', publication_id = '".$new_parent_id."'"; - if ($debug) echo $sql_add_publication; + if ($debug) echo $sql_add_publication; $rest_select = Database::query($sql_add_publication); $id = Database::insert_id(); - - $sql_update = "UPDATE " . $TBL_STUDENT_PUBLICATION . " SET " . + + $sql_update = "UPDATE " . $TBL_STUDENT_PUBLICATION . " SET " . "has_properties = '".$id."', view_properties = '1' WHERE id = ".$new_parent_id; - if ($debug) echo $sql_update; - $rest_update = Database::query($sql_update); - - + if ($debug) echo $sql_update; + $rest_update = Database::query($sql_update); + + if ($debug) var_dump($sql_update); - $result_message[$TBL_STUDENT_PUBLICATION_ASSIGNMENT]++; - } - } - + $result_message[$TBL_STUDENT_PUBLICATION_ASSIGNMENT]++; + } + } + $doc_url = $data['url']; - $new_url = str_replace($parent_data['url'], $created_dir, $doc_url); - - if ($update_database) { - //Creating a new work + $new_url = str_replace($parent_data['url'], $created_dir, $doc_url); + + if ($update_database) { + //Creating a new work $sql_add_publication = "INSERT INTO " . $TBL_STUDENT_PUBLICATION . " SET " . "url = '" . $new_url . "', c_id = '".$course_id."', @@ -442,89 +442,89 @@ if (isset($_REQUEST['load_ajax'])) { sent_date = '".$data['sent_date'] ."', parent_id = '".$new_parent_id ."' , session_id = ".$new_session_id; - - if ($debug) echo $sql_add_publication; - $rest_insert = Database::query($sql_add_publication); + + if ($debug) echo $sql_add_publication; + $rest_insert = Database::query($sql_add_publication); if ($debug) var_dump($rest_insert); $id = Database::insert_id(); api_item_property_update($course_info, 'work', $id, 'DocumentAdded', $user_id); - $result_message[$TBL_STUDENT_PUBLICATION]++; - - $full_file_name = $course_dir.'/'.$doc_url; + $result_message[$TBL_STUDENT_PUBLICATION]++; + + $full_file_name = $course_dir.'/'.$doc_url; $new_file = $course_dir.'/'.$new_url; - + if (file_exists($full_file_name)) { //deleting old assignment - $result = copy($full_file_name, $new_file); + $result = copy($full_file_name, $new_file); if ($result) { - unlink($full_file_name); + unlink($full_file_name); $sql = "DELETE FROM $TBL_STUDENT_PUBLICATION WHERE id= ".$data['id']; if ($debug) var_dump($sql); - $result_delete = Database::query($sql); + $result_delete = Database::query($sql); api_item_property_update($course_info, 'work', $data['id'], 'DocumentDeleted', api_get_user_id()); } } } } - - } - } - - //9. Survey Pending - + + } + } + + //9. Survey Pending + //10. Dropbox - not neccesary to move categories (no presence of session_id) - + $sql = "SELECT id FROM $TBL_DROPBOX_FILE WHERE uploader_id = $user_id AND session_id = $origin_session_id AND c_id = $course_id"; - if ($debug) var_dump($sql); + if ($debug) var_dump($sql); $res = Database::query($sql); while($row = Database::fetch_array($res,'ASSOC')) { $id = $row['id']; if ($update_database) { $sql = "UPDATE $TBL_DROPBOX_FILE SET session_id = '$new_session_id' WHERE c_id = $course_id AND id = $id"; - if ($debug) var_dump($sql); + if ($debug) var_dump($sql); $res = Database::query($sql); if ($debug) var_dump($res); - + $sql = "UPDATE $TBL_DROPBOX_POST SET session_id = '$new_session_id' WHERE file_id = $id"; - if ($debug) - var_dump($sql); + if ($debug) + var_dump($sql); $res = Database::query($sql); - if ($debug) - var_dump($res); + if ($debug) + var_dump($res); $result_message[$TBL_DROPBOX_FILE]++; - } - } - + } + } + //11. Notebook - - $sql = "SELECT notebook_id FROM $TBL_NOTEBOOK + + $sql = "SELECT notebook_id FROM $TBL_NOTEBOOK WHERE user_id = $user_id AND session_id = $origin_session_id AND course = '$origin_course_code' AND c_id = $course_id"; - if ($debug) var_dump($sql); + if ($debug) var_dump($sql); $res = Database::query($sql); while($row = Database::fetch_array($res,'ASSOC')) { - $id = $row['notebook_id']; - if ($update_database) { - $sql = "UPDATE $TBL_NOTEBOOK SET session_id = '$new_session_id' WHERE c_id = $course_id AND notebook_id = $id"; - if ($debug) var_dump($sql); + $id = $row['notebook_id']; + if ($update_database) { + $sql = "UPDATE $TBL_NOTEBOOK SET session_id = '$new_session_id' WHERE c_id = $course_id AND notebook_id = $id"; + if ($debug) var_dump($sql); $res = Database::query($sql); - if ($debug) var_dump($res); + if ($debug) var_dump($res); } } - + if ($update_database) { echo '

'.get_lang('StatsMoved').'

'; if (is_array($result_message)) foreach ($result_message as $table=>$times) { echo 'Table '.$table.' - '.$times.' records updated
'; - } + } } else { - echo '

'.get_lang('UserInformationOfThisCourse').'

'; - + echo '

'.get_lang('UserInformationOfThisCourse').'

'; + echo '
'; echo ''; echo ''; echo ''; echo ''; echo ''; echo '
'; - + if ($origin_session_id == 0 ) { echo '

'.get_lang('OriginCourse').'

'; } else { @@ -534,17 +534,17 @@ if (isset($_REQUEST['load_ajax'])) { echo '
'; if ($new_session_id == 0 ) { - echo '

'.get_lang('DestinyCourse').'

'; + echo '

'.get_lang('DestinyCourse').'

'; } else { echo '

'.get_lang('DestinySession').' #'.$new_session_id.'

'; - } + } compare_data($result_message_compare); echo '
'; } } else { - echo get_lang('CourseDoesNotExistInThisSession'); + echo get_lang('CourseDoesNotExistInThisSession'); } } } else { @@ -566,7 +566,7 @@ $htmlHeadXtra[] = ''; function get_courses_list_by_user_id_based_in_exercises($user_id) { $TABLETRACK_EXERCICES = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES); $user_id = intval($user_id); - //$sql = "SELECT DISTINCT exe_user_id, exe_cours_id as code, session_id as id_session FROM $TABLETRACK_EXERCICES WHERE exe_user_id = $user_id GROUP BY exe_user_id, exe_cours_id ORDER by exe_user_id, exe_cours_id ASC"; - $sql = "SELECT DISTINCT exe_user_id, exe_cours_id as code, session_id as id_session FROM $TABLETRACK_EXERCICES WHERE exe_user_id = $user_id ORDER by exe_user_id, exe_cours_id ASC"; - + $sql = "SELECT DISTINCT exe_user_id, c_id, session_id as id_session + FROM $TABLETRACK_EXERCICES WHERE exe_user_id = $user_id + ORDER by exe_user_id, c_id ASC"; + $res = Database::query($sql); $course_list = array(); while($row = Database::fetch_array($res,'ASSOC')) { - $course_list []= $row; + $course_list []= $row; } - return $course_list; + return $course_list; } @@ -632,7 +633,7 @@ $navigation .= ' '; $page ++; if ($page < $nro_pages) $navigation .= ''.get_lang('Next').''; -else +else $navigation .= get_lang('Next'); echo $navigation; @@ -649,12 +650,12 @@ $combinations = array(); if (!empty($user_list)) { foreach ($user_list as $user) { - + $user_id = $user['user_id']; //if ($user_id != 78 ) continue; $name = $user['firstname'].' '.$user['lastname']; $course_list_registered = CourseManager::get_courses_list_by_user_id($user_id, true, false); - + $new_course_list = array(); foreach ($course_list_registered as $course_reg) { if (empty($course_reg['id_session'])) { @@ -662,12 +663,12 @@ if (!empty($user_list)) { } $new_course_list[] = $course_reg['code'].'_'.$course_reg['id_session']; } - + $course_list = get_courses_list_by_user_id_based_in_exercises($user_id); - + if (is_array($course_list) && !empty($course_list)) { foreach ($course_list as $my_course) { - $key = $my_course['code'].'_'.$my_course['id_session']; + $key = $my_course['c_id'].'_'.$my_course['id_session']; if(!in_array($key,$new_course_list)) { $my_course['not_registered'] = 1; $course_list_registered[] = $my_course; @@ -676,35 +677,35 @@ if (!empty($user_list)) { } $course_list = $course_list_registered; - - echo '
'; + + echo '
'; echo ''; - echo ''; + echo ''; echo ''; - echo ''; - + echo ''; + echo ''; + if (!empty($course_list)) { - echo ''; - - foreach ($course_list as $course) { + echo ''; + + foreach ($course_list as $course) { echo ''; + echo ''; } echo ''; echo ''; - + foreach ($course_list as $course) { - $course_code = $course['code']; + $courseId = $course['c_id']; if (empty($course['id_session'])) { $session_id = 0; } else { @@ -713,15 +714,15 @@ if (!empty($user_list)) { echo ''; } echo ''; @@ -729,7 +730,7 @@ if (!empty($user_list)) { echo ''; - + } echo '
'; echo "

$name #$user_id

"; - echo '
'; if (isset($course['id_session']) && !empty($course['id_session'])) { echo ''.get_lang('SessionName').' '.$my_session_list[$course['id_session']].'
'; } echo $course['title']; - echo ' ('.$course['code'].') '; + echo ' ('.$course['c_id'].') '; if (isset($course['not_registered']) && !empty($course['not_registered'])) { echo ' '.get_lang('UserNotRegistered').''; } - echo '
'; echo get_lang('MoveTo'); echo '
'; $unique_id = uniqid(); - $combinations[$unique_id] = array('course_code' =>$course_code, 'session_id'=>$session_id); - + $combinations[$unique_id] = array('course_code' => $courseId, 'session_id'=>$session_id); + echo ''; - echo '
'; - echo ''; - echo ''; - echo '
'; + echo '
'; + echo ''; + echo ''; + echo '
'; echo '
'; echo get_lang('NoCoursesForThisUser'); echo '
'; echo '
'; diff --git a/main/exercice/admin.php b/main/exercice/admin.php index 2e9ceea42a..ad1fcc3fa5 100644 --- a/main/exercice/admin.php +++ b/main/exercice/admin.php @@ -116,7 +116,7 @@ if (empty($modifyExercise)) { //Cleaning all incomplete attempts of the admin/teacher to avoid weird problems when changing the exercise settings, number of questions, etc -delete_all_incomplete_attempts(api_get_user_id(), $exerciseId, api_get_course_id(), api_get_session_id()); +delete_all_incomplete_attempts(api_get_user_id(), $exerciseId, api_get_course_int_id(), api_get_session_id()); // get from session $objExercise = isset($_SESSION['objExercise'])?$_SESSION['objExercise']:0; diff --git a/main/exercice/exercice.php b/main/exercice/exercice.php index ce307c2956..53b55469b3 100644 --- a/main/exercice/exercice.php +++ b/main/exercice/exercice.php @@ -343,6 +343,7 @@ HotPotGCt($documentPath, 1, api_get_user_id()); //condition for the session $course_code = api_get_course_id(); +$courseId = api_get_course_int_id(); $session_id = api_get_session_id(); $condition_session = api_get_session_condition($session_id, true, true); @@ -599,7 +600,6 @@ if (!empty($exercise_list)) { ); } - $visibility = api_get_item_visibility($course_info, TOOL_QUIZ, $my_exercise_id); if ($row['active'] == 0 || $visibility == 0) { @@ -609,7 +609,7 @@ if (!empty($exercise_list)) { } $count_exercise_not_validated = intval( - count_exercise_result_not_validated($my_exercise_id, $course_code, $session_id) + count_exercise_result_not_validated($my_exercise_id, $courseId, $session_id) ); $move = Display::return_icon( @@ -857,7 +857,7 @@ if (!empty($exercise_list)) { $qry = "SELECT * FROM $TBL_TRACK_EXERCICES WHERE exe_exo_id = ".$row['id']." AND exe_user_id = ".api_get_user_id()." AND - exe_cours_id = '".api_get_course_id()."' AND + c_id = '".api_get_course_int_id()."' AND status <> 'incomplete' AND orig_lp_id = 0 AND orig_lp_item_id = 0 AND diff --git a/main/exercice/exercise.class.php b/main/exercice/exercise.class.php index 8fe57d28ab..d7f7c80104 100644 --- a/main/exercice/exercise.class.php +++ b/main/exercice/exercise.class.php @@ -1849,7 +1849,7 @@ class Exercise $table_track_e_attempt = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT); $sql_select = "SELECT exe_id FROM $table_track_e_exercises - WHERE exe_cours_id = '".api_get_course_id()."' AND + WHERE c_id = '".api_get_course_int_id()."' AND exe_exo_id = ".$this->id." AND orig_lp_id = 0 AND orig_lp_item_id = 0 AND @@ -1870,9 +1870,11 @@ class Exercise //delete TRACK_E_EXERCICES table $sql = "DELETE FROM $table_track_e_exercises - WHERE exe_cours_id = '".api_get_course_id( - )."' AND exe_exo_id = ".$this->id." AND orig_lp_id = 0 AND orig_lp_item_id = 0 AND session_id = ".api_get_session_id( - ).""; + WHERE c_id = '".api_get_course_int_id()."' AND + exe_exo_id = ".$this->id." AND + orig_lp_id = 0 AND + orig_lp_item_id = 0 AND + session_id = ".api_get_session_id(); Database::query($sql); return $i; @@ -2074,7 +2076,7 @@ class Exercise } $condition = ' WHERE exe_exo_id = '."'".$this->id."'".' AND exe_user_id = '."'".api_get_user_id()."'".' AND - exe_cours_id = '."'".api_get_course_id()."'".' AND + c_id = '."'".api_get_course_int_id()."'".' AND status = '."'".Database::escape_string($status)."'".' AND orig_lp_id = '."'".$lp_id."'".' AND orig_lp_item_id = '."'".$lp_item_id."'".' AND @@ -2132,9 +2134,8 @@ class Exercise } $questionList = array_map('intval', $questionList); $weight = Database::escape_string($weight); - $sql = "INSERT INTO $track_exercises ($sql_fields exe_exo_id, exe_user_id, exe_cours_id, status, session_id, data_tracking, start_date, orig_lp_id, orig_lp_item_id, exe_weighting) - VALUES($sql_fields_values '".$this->id."','".api_get_user_id()."','".api_get_course_id( - )."', 'incomplete','".api_get_session_id()."','".implode(',', $questionList)."', '".api_get_utc_datetime( + $sql = "INSERT INTO $track_exercises ($sql_fields exe_exo_id, exe_user_id, c_id, status, session_id, data_tracking, start_date, orig_lp_id, orig_lp_item_id, exe_weighting) + VALUES($sql_fields_values '".$this->id."','".api_get_user_id()."','".api_get_course_int_id()."', 'incomplete','".api_get_session_id()."','".implode(',', $questionList)."', '".api_get_utc_datetime( )."', '$safe_lp_id', '$safe_lp_item_id', '$weight')"; Database::query($sql); @@ -2601,7 +2602,7 @@ class Exercise case UNIQUE_ANSWER_IMAGE : case UNIQUE_ANSWER_NO_OPTION : if ($from_database) { - $queryans = "SELECT answer FROM ".$TBL_TRACK_ATTEMPT." WHERE exe_id = '".$exeId."' and question_id= '".$questionId."'"; + $queryans = "SELECT answer FROM ".$TBL_TRACK_ATTEMPT." WHERE exe_id = '".$exeId."' AND question_id= '".$questionId."'"; $resultans = Database::query($queryans); $choice = Database::result($resultans, 0, "answer"); @@ -2622,7 +2623,7 @@ class Exercise case MULTIPLE_ANSWER_TRUE_FALSE : if ($from_database) { $choice = array(); - $queryans = "SELECT answer FROM ".$TBL_TRACK_ATTEMPT." where exe_id = ".$exeId." and question_id = ".$questionId; + $queryans = "SELECT answer FROM ".$TBL_TRACK_ATTEMPT." WHERE exe_id = ".$exeId." AND question_id = ".$questionId; $resultans = Database::query($queryans); while ($row = Database::fetch_array($resultans)) { $ind = $row['answer']; diff --git a/main/exercice/exercise.lib.php b/main/exercice/exercise.lib.php index 7325d380be..a629b86b91 100644 --- a/main/exercice/exercise.lib.php +++ b/main/exercice/exercise.lib.php @@ -876,8 +876,8 @@ function get_exercise_track_exercise_info($exe_id) INNER JOIN $TBL_TRACK_EXERCICES as tee ON q.id=tee.exe_exo_id INNER JOIN $TBL_COURSE c - ON c.code = tee.exe_cours_id - WHERE tee.exe_id=$exe_id + ON c.id = tee.c_id + WHERE tee.exe_id = $exe_id AND q.c_id=c.id"; $res_fb_type = Database::query($sql_fb_type); @@ -969,7 +969,8 @@ function get_count_exam_hotpotatoes_results($in_hotpot_path) function get_exam_results_hotpotatoes_data($in_from, $in_number_of_items, $in_column, $in_direction, $in_hotpot_path, $in_get_count = false, $where_condition = null) { $tab_res = array(); - $course_code = api_get_course_id(); + $courseId = api_get_course_int_id(); + // by default in_column = 1 If parameters given, it is the name of the column witch is the bdd field name if ($in_column == 1) { $in_column = 'firstname'; @@ -980,7 +981,10 @@ function get_exam_results_hotpotatoes_data($in_from, $in_number_of_items, $in_co $TBL_GROUP = Database :: get_course_table(TABLE_GROUP); $TBL_USER = Database :: get_main_table(TABLE_MAIN_USER); - $sql .= "SELECT * FROM $TBL_TRACK_HOTPOTATOES thp JOIN $TBL_USER u ON thp.exe_user_id = u.user_id WHERE thp.exe_cours_id = '$course_code' AND exe_name LIKE '$in_hotpot_path%'"; + $sql = "SELECT * FROM $TBL_TRACK_HOTPOTATOES thp + JOIN $TBL_USER u ON thp.exe_user_id = u.user_id + WHERE thp.c_id = '$courseId' AND + exe_name LIKE '$in_hotpot_path%'"; // just count how many answers if ($in_get_count) { @@ -1050,13 +1054,13 @@ function get_exam_results_data($from, $number_of_items, $column, $direction, $ex // sql for chamilo-type tests for teacher / tutor view $sql_inner_join_tbl_track_exercices = " ( - SELECT DISTINCT ttte.*, if(tr.exe_id,1, 0) as revised - FROM $TBL_TRACK_EXERCICES ttte LEFT JOIN $TBL_TRACK_ATTEMPT_RECORDING tr - ON (ttte.exe_id = tr.exe_id) - WHERE exe_cours_id = '$course_code' AND - exe_exo_id = $exercise_id AND - ttte.session_id = ".api_get_session_id()." - )"; + SELECT DISTINCT ttte.*, if(tr.exe_id,1, 0) as revised + FROM $TBL_TRACK_EXERCICES ttte LEFT JOIN $TBL_TRACK_ATTEMPT_RECORDING tr + ON (ttte.exe_id = tr.exe_id) + WHERE ttte.c_id = '$course_id' AND + exe_exo_id = $exercise_id AND + ttte.session_id = ".api_get_session_id()." + )"; if ($is_allowedToEdit) { //Teacher view if (isset($_GET['gradebook']) && $_GET['gradebook'] == 'view') { @@ -1153,9 +1157,9 @@ function get_exam_results_data($from, $number_of_items, $column, $direction, $ex INNER JOIN $sql_inner_join_tbl_user AS user ON (user.user_id = exe_user_id) WHERE $extra_where_conditions AND te.status != 'incomplete' - AND te.exe_cours_id='".api_get_course_id()."' $session_id_and + AND te.c_id='".$course_id."' $session_id_and AND ce.active <>-1 - AND ce.c_id=".api_get_course_int_id()." + AND ce.c_id=".$course_id." $exercise_where "; // sql for hotpotatoes tests for teacher / tutor view @@ -1171,7 +1175,7 @@ function get_exam_results_data($from, $number_of_items, $column, $direction, $ex tth.exe_weighting, tth.exe_date"; } - + // AND $where_condition seems not to be used $hpsql = " $hpsql_select FROM $TBL_TRACK_HOTPOTATOES tth, @@ -1179,12 +1183,12 @@ function get_exam_results_data($from, $number_of_items, $column, $direction, $ex $sqlFromOption WHERE user.user_id=tth.exe_user_id - AND tth.exe_cours_id = '".api_get_course_id()."' + AND tth.c_id = '".$course_id."' $hotpotatoe_where $sqlWhereOption - AND $where_condition + ORDER BY - tth.exe_cours_id ASC, + tth.c_id ASC, tth.exe_date DESC"; } @@ -1234,7 +1238,7 @@ function get_exam_results_data($from, $number_of_items, $column, $direction, $ex if (is_array($results)) { $users_array_id = array(); - if ($_GET['gradebook'] == 'view') { + if (isset($_GET['gradebook']) && $_GET['gradebook'] == 'view') { $from_gradebook = true; } $sizeof = count($results); @@ -1247,7 +1251,7 @@ function get_exam_results_data($from, $number_of_items, $column, $direction, $ex for ($i = 0; $i < $sizeof; $i++) { $revised = $results[$i]['revised']; - if ($from_gradebook && ($is_allowedToEdit)) { + if (isset($from_gradebook) && $from_gradebook && $is_allowedToEdit) { if (in_array($results[$i]['username'].$results[$i]['firstname'].$results[$i]['lastname'], $users_array_id)) { continue; } @@ -1588,7 +1592,7 @@ function get_all_exercises_for_course_id($course_info = null, $session_id = 0, $ * @param int session id * @return int the position of the user between his friends in a course (or course within a session) */ -function get_exercise_result_ranking($my_score, $my_exe_id, $exercise_id, $course_code, $session_id = 0, $user_list = array(), $return_string = true) +function get_exercise_result_ranking($my_score, $my_exe_id, $exercise_id, $course_id, $session_id = 0, $user_list = array(), $return_string = true) { //No score given we return if (is_null($my_score)) { @@ -1601,7 +1605,7 @@ function get_exercise_result_ranking($my_score, $my_exe_id, $exercise_id, $cours $best_attempts = array(); foreach ($user_list as $user_data) { $user_id = $user_data['user_id']; - $best_attempts[$user_id] = get_best_attempt_by_user($user_id, $exercise_id, $course_code, $session_id); + $best_attempts[$user_id] = get_best_attempt_by_user($user_id, $exercise_id, $course_id, $session_id); } if (empty($best_attempts)) { @@ -1653,11 +1657,11 @@ function get_exercise_result_ranking($my_score, $my_exe_id, $exercise_id, $cours * @param float user score to be compared attention => score/weight * @param int exe id of the exercise (this is necesary because if 2 students have the same score the one with the minor exe_id will have a best position, just to be fair and FIFO) * @param int exercise id - * @param string course code + * @param int course id * @param int session id * @return int the position of the user between his friends in a course (or course within a session) */ -function get_exercise_result_ranking_by_attempt($my_score, $my_exe_id, $exercise_id, $course_code, $session_id = 0, $return_string = true) +function get_exercise_result_ranking_by_attempt($my_score, $my_exe_id, $exercise_id, $courseId, $session_id = 0, $return_string = true) { if (empty($session_id)) { $session_id = 0; @@ -1665,7 +1669,7 @@ function get_exercise_result_ranking_by_attempt($my_score, $my_exe_id, $exercise if (is_null($my_score)) { return '-'; } - $user_results = get_all_exercise_results($exercise_id, $course_code, $session_id, false); + $user_results = get_all_exercise_results($exercise_id, $courseId, $session_id, false); $position_data = array(); if (empty($user_results)) { return 1; @@ -1709,9 +1713,9 @@ function get_exercise_result_ranking_by_attempt($my_score, $my_exe_id, $exercise * Get the best attempt in a exercise (NO Exercises in LPs ) */ -function get_best_attempt_in_course($exercise_id, $course_code, $session_id) +function get_best_attempt_in_course($exercise_id, $courseId, $session_id) { - $user_results = get_all_exercise_results($exercise_id, $course_code, $session_id, false); + $user_results = get_all_exercise_results($exercise_id, $courseId, $session_id, false); $best_score_data = array(); $best_score = 0; if (!empty($user_results)) { @@ -1727,13 +1731,18 @@ function get_best_attempt_in_course($exercise_id, $course_code, $session_id) } return $best_score_data; } -/* - * Get the best score in a exercise (NO Exercises in LPs ) - */ -function get_best_attempt_by_user($user_id, $exercise_id, $course_code, $session_id) +/** + * Get the best score in a exercise (NO Exercises in LPs ) + * @param $user_id + * @param $exercise_id + * @param $courseId + * @param $session_id + * @return array + */ +function get_best_attempt_by_user($user_id, $exercise_id, $courseId, $session_id) { - $user_results = get_all_exercise_results($exercise_id, $course_code, $session_id, false, $user_id); + $user_results = get_all_exercise_results($exercise_id, $courseId, $session_id, false, $user_id); $best_score_data = array(); $best_score = 0; if (!empty($user_results)) { @@ -1753,13 +1762,13 @@ function get_best_attempt_by_user($user_id, $exercise_id, $course_code, $session /** * Get average score (NO Exercises in LPs ) * @param int exercise id - * @param string course code + * @param int course id * @param int session id * @return float Average score */ -function get_average_score($exercise_id, $course_code, $session_id) +function get_average_score($exercise_id, $courseId, $session_id) { - $user_results = get_all_exercise_results($exercise_id, $course_code, $session_id); + $user_results = get_all_exercise_results($exercise_id, $courseId, $session_id); $avg_score = 0; if (!empty($user_results)) { foreach ($user_results as $result) { @@ -1776,14 +1785,13 @@ function get_average_score($exercise_id, $course_code, $session_id) /** * Get average score by score (NO Exercises in LPs ) * @param int exercise id - * @param string course code + * @param int course id * @param int session id * @return float Average score */ -function get_average_score_by_course($course_code, $session_id) +function get_average_score_by_course($courseId, $session_id) { - $user_results = get_all_exercise_results_by_course($course_code, $session_id, false); - //echo $course_code.' - '.$session_id.'
'; + $user_results = get_all_exercise_results_by_course($courseId, $session_id, false); $avg_score = 0; if (!empty($user_results)) { foreach ($user_results as $result) { @@ -1799,9 +1807,17 @@ function get_average_score_by_course($course_code, $session_id) return $avg_score; } -function get_average_score_by_course_by_user($user_id, $course_code, $session_id) +/** + * + * @param $user_id + * @param $courseId + * @param $session_id + * + * @return float|int + */ +function get_average_score_by_course_by_user($user_id, $courseId, $session_id) { - $user_results = get_all_exercise_results_by_user($user_id, $course_code, $session_id); + $user_results = get_all_exercise_results_by_user($user_id, $courseId, $session_id); $avg_score = 0; if (!empty($user_results)) { foreach ($user_results as $result) { @@ -1820,8 +1836,9 @@ function get_average_score_by_course_by_user($user_id, $course_code, $session_id /** * Get average score by score (NO Exercises in LPs ) * @param int exercise id - * @param string course code + * @param int course id * @param int session id + * * @return float Best average score */ function get_best_average_score_by_exercise($exercise_id, $course_code, $session_id, $user_count) @@ -1847,6 +1864,11 @@ function get_best_average_score_by_exercise($exercise_id, $course_code, $session return $avg_score; } +/** + * @param $course_code + * @param $session_id + * @return array + */ function get_exercises_to_be_taken($course_code, $session_id) { $course_info = api_get_course_info($course_code); @@ -1863,26 +1885,28 @@ function get_exercises_to_be_taken($course_code, $session_id) /** * Get student results (only in completed exercises) stats by question + * * @param int question id * @param int exercise id - * @param string course code + * @param int course id * @param int session id * * */ -function get_student_stats_by_question($question_id, $exercise_id, $course_code, $session_id) +function get_student_stats_by_question($question_id, $exercise_id, $courseId, $session_id) { $track_exercises = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES); $track_attempt = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT); $question_id = intval($question_id); $exercise_id = intval($exercise_id); - $course_code = Database::escape_string($course_code); + $courseId = intval($courseId); $session_id = intval($session_id); $sql = "SELECT MAX(marks) as max , MIN(marks) as min, AVG(marks) as average FROM $track_exercises e INNER JOIN $track_attempt a ON (a.exe_id = e.exe_id) WHERE exe_exo_id = $exercise_id AND - course_code = '$course_code' AND + e.c_id = $courseId AND + a.c_id = $courseId e.session_id = $session_id AND question_id = $question_id AND status = '' LIMIT 1"; $result = Database::query($sql); @@ -1893,7 +1917,14 @@ function get_student_stats_by_question($question_id, $exercise_id, $course_code, return $return; } -function get_number_students_question_with_answer_count($question_id, $exercise_id, $course_code, $session_id) +/** + * @param int $question_id + * @param int $exercise_id + * @param int $courseId + * @param int $session_id + * @return int + */ +function get_number_students_question_with_answer_count($question_id, $exercise_id, $courseId, $session_id) { $track_exercises = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES); $track_attempt = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT); @@ -1901,15 +1932,15 @@ function get_number_students_question_with_answer_count($question_id, $exercise_ $question_id = intval($question_id); $exercise_id = intval($exercise_id); - $course_code = Database::escape_string($course_code); + $courseId = intval($courseId); $session_id = intval($session_id); $sql = "SELECT DISTINCT exe_user_id FROM $track_exercises e INNER JOIN $track_attempt a ON (a.exe_id = e.exe_id) INNER JOIN $course_user cu - ON cu.course_code = a.course_code AND cu.user_id = exe_user_id + ON cu.c_id = a.c_id AND cu.user_id = exe_user_id WHERE exe_exo_id = $exercise_id AND - a.course_code = '$course_code' AND + a.c_id = $courseId AND e.session_id = $session_id AND question_id = $question_id AND answer <> '0' AND @@ -1957,7 +1988,19 @@ function get_number_students_answer_hotspot_count($answer_id, $question_id, $exe return $return; } -function get_number_students_answer_count($answer_id, $question_id, $exercise_id, $course_code, $session_id, $question_type = null, $correct_answer = null, $current_answer = null) +/** + * + * @param int $answer_id + * @param int $question_id + * @param int $exercise_id + * @param int $courseId + * @param int $session_id + * @param string $question_type + * @param null $correct_answer + * @param null $current_answer + * @return int + */ +function get_number_students_answer_count($answer_id, $question_id, $exercise_id, $courseId, $session_id, $question_type = null, $correct_answer = null, $current_answer = null) { $track_exercises = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES); $track_attempt = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT); @@ -1966,7 +2009,7 @@ function get_number_students_answer_count($answer_id, $question_id, $exercise_id $question_id = intval($question_id); $answer_id = intval($answer_id); $exercise_id = intval($exercise_id); - $course_code = Database::escape_string($course_code); + $courseId = intval($courseId); $session_id = intval($session_id); switch ($question_type) { @@ -1982,9 +2025,9 @@ function get_number_students_answer_count($answer_id, $question_id, $exercise_id $sql = "SELECT $select_condition FROM $track_exercises e INNER JOIN $track_attempt a ON (a.exe_id = e.exe_id) INNER JOIN $course_user cu - ON cu.course_code = a.course_code AND cu.user_id = exe_user_id + ON cu.c_id = a.c_id AND cu.user_id = exe_user_id WHERE exe_exo_id = $exercise_id AND - a.course_code = '$course_code' AND + a.c_id = $courseId AND e.session_id = $session_id AND $answer_condition question_id = $question_id AND @@ -2127,19 +2170,28 @@ function check_fill_in_blanks($answer, $user_answer) return $good_answer; } -function get_number_students_finish_exercise($exercise_id, $course_code, $session_id) +/** + * + * @param int $exercise_id + * @param int $courseId + * @param int $session_id + * @depracted seems not to be used + * @return int + */ +function get_number_students_finish_exercise($exercise_id, $courseId, $session_id) { $track_exercises = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES); $track_attempt = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT); $exercise_id = intval($exercise_id); - $course_code = Database::escape_string($course_code); + $courseId = intval($courseId); $session_id = intval($session_id); $sql = "SELECT DISTINCT exe_user_id FROM $track_exercises e INNER JOIN $track_attempt a ON (a.exe_id = e.exe_id) WHERE exe_exo_id = $exercise_id AND - course_code = '$course_code' AND + a.c_id = $courseId AND + e.c_id = $courseId AND e.session_id = $session_id AND status = ''"; $result = Database::query($sql); diff --git a/main/exercice/exercise_history.php b/main/exercice/exercise_history.php index ec490bb57e..be30977791 100644 --- a/main/exercice/exercise_history.php +++ b/main/exercice/exercise_history.php @@ -62,14 +62,18 @@ echo '
'; - + jqgrid integration * Modified by hubert.borderiou (question category) @@ -113,7 +113,7 @@ if (!empty($_REQUEST['export_report']) && $_REQUEST['export_report'] == '1') { } //Send student email @todo move this code in a class, library -if ($_REQUEST['comments'] == 'update' && ($is_allowedToEdit || $is_tutor) && $_GET['exeid'] == strval( +if (isset($_REQUEST['comments']) && $_REQUEST['comments'] == 'update' && ($is_allowedToEdit || $is_tutor) && $_GET['exeid'] == strval( intval($_GET['exeid']) ) ) { @@ -238,46 +238,47 @@ if ($_REQUEST['comments'] == 'update' && ($is_allowedToEdit || $is_tutor) && $_G } } - -if ($is_allowedToEdit && $origin != 'learnpath') { - // the form - if (api_is_platform_admin() || api_is_course_admin() || api_is_course_tutor() || api_is_course_coach()) { - $actions .= ''.Display :: return_icon( - 'back.png', - get_lang('GoBackToQuestionList'), - '', - ICON_SIZE_MEDIUM - ).''; - $actions .= ''.Display :: return_icon( - 'activity_monitor.png', - get_lang('LiveResults'), - '', - ICON_SIZE_MEDIUM - ).''; - $actions .= ''.Display :: return_icon( - 'statistics.png', - get_lang('ReportByQuestion'), - '', - ICON_SIZE_MEDIUM - ).''; - $actions .= ''. - Display::return_icon('save.png', get_lang('Export'), '', ICON_SIZE_MEDIUM).''; - } -} else { +$actions = null; +if (isset($origin) && $origin == 'learnpath') { $actions .= ''.Display :: return_icon( 'back.png', get_lang('GoBackToQuestionList'), '', ICON_SIZE_MEDIUM ).''; +} else { + if ($is_allowedToEdit) { + // the form + if (api_is_platform_admin() || api_is_course_admin() || api_is_course_tutor() || api_is_course_coach()) { + $actions .= ''.Display :: return_icon( + 'back.png', + get_lang('GoBackToQuestionList'), + '', + ICON_SIZE_MEDIUM + ).''; + $actions .= ''.Display :: return_icon( + 'activity_monitor.png', + get_lang('LiveResults'), + '', + ICON_SIZE_MEDIUM + ).''; + $actions .= ''.Display :: return_icon( + 'statistics.png', + get_lang('ReportByQuestion'), + '', + ICON_SIZE_MEDIUM + ).''; + $actions .= ''. + Display::return_icon('save.png', get_lang('Export'), '', ICON_SIZE_MEDIUM).''; + } + } } //Deleting an attempt -if (($is_allowedToEdit || $is_tutor || api_is_coach( -)) && $_GET['delete'] == 'delete' && !empty ($_GET['did']) && $locked == false +if (($is_allowedToEdit || $is_tutor || api_is_coach()) && $_GET['delete'] == 'delete' && !empty ($_GET['did']) && $locked == false ) { $exe_id = intval($_GET['did']); if (!empty($exe_id)) { @@ -380,9 +381,7 @@ if ($is_allowedToEdit) { echo $actions; -$url = api_get_path( - WEB_AJAX_PATH -).'model.ajax.php?a=get_exercise_results&exerciseId='.$exercise_id.'&filter_by_user='.$filter_user; +$url = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_exercise_results&exerciseId='.$exercise_id.'&filter_by_user='.$filter_user; $action_links = ''; @@ -544,7 +543,6 @@ $extra_params['height'] = 'auto'; if ($is_allowedToEdit || $is_tutor) { ?> - //setSearchSelect("status"); // //view:true, del:false, add:false, edit:false, excel:true} @@ -596,4 +594,4 @@ jQuery("#results").jqGrid('navButtonAdd','#results_pager',{ -1 AND orig_lp_id = 0 AND orig_lp_item_id = 0"; @@ -131,9 +132,9 @@ class ExerciseResult tth.exe_date FROM $TBL_TRACK_HOTPOTATOES tth, $TBL_USER tu WHERE tu.user_id=tth.exe_user_id AND - tth.exe_cours_id = '" . Database :: escape_string($cid) . "' AND + tth.c_id = '" . $course_id . "' AND tth.exe_name = '$hotpotato_name' - ORDER BY tth.exe_cours_id ASC, tth.exe_date DESC"; + ORDER BY tth.c_id ASC, tth.exe_date DESC"; } else { $user_id_and = ' AND te.exe_user_id = ' . api_get_user_id() . ' '; @@ -150,21 +151,22 @@ class ExerciseResult exe_user_id as excruid, te.exe_duration as duration, ce.results_disabled as exdisabled - FROM $TBL_EXERCISES AS ce INNER JOIN $TBL_TRACK_EXERCISES AS te ON (te.exe_exo_id = ce.id) INNER JOIN $TBL_USER AS user ON (user.user_id = exe_user_id) + FROM $TBL_EXERCISES AS ce INNER JOIN $TBL_TRACK_EXERCISES AS te ON (te.exe_exo_id = ce.id) + INNER JOIN $TBL_USER AS user ON (user.user_id = exe_user_id) WHERE ce.c_id = $course_id AND te.status != 'incomplete' AND - te.exe_cours_id='" . Database :: escape_string($cid) . "' $user_id_and $session_id_and AND + te.c_id ='" . $course_id . "' $user_id_and $session_id_and AND ce.active <>-1 AND orig_lp_id = 0 AND orig_lp_item_id = 0 - ORDER BY userpart2, te.exe_cours_id ASC, ce.title ASC, te.exe_date DESC"; + ORDER BY userpart2, te.c_id ASC, ce.title ASC, te.exe_date DESC"; $hpsql = "SELECT '', exe_name, exe_result , exe_weighting, exe_date - FROM $TBL_TRACK_HOTPOTATOES - WHERE exe_user_id = '" . $user_id . "' AND - exe_cours_id = '" . Database :: escape_string($cid) . "' AND - tth.exe_name = '$hotpotato_name' - ORDER BY exe_cours_id ASC, exe_date DESC"; + FROM $TBL_TRACK_HOTPOTATOES + WHERE exe_user_id = '" . $user_id . "' AND + c_id = '" . $course_id . "' AND + tth.exe_name = '$hotpotato_name' + ORDER BY c_id ASC, exe_date DESC"; } $results = array(); @@ -407,7 +409,7 @@ class ExerciseResult } $worksheet->write($line,$column,get_lang('Groups')); $column++; - + if ($export_user_fields) { //show user fields section with a big th colspan that spans over all fields $extra_user_fields = UserManager::get_extra_fields(0,1000,5,'ASC',false, 1); @@ -455,7 +457,7 @@ class ExerciseResult $worksheet->write($line,$column,api_html_entity_decode(strip_tags(implode(", ", GroupManager :: get_user_group_name($row['user_id']))), ENT_QUOTES, $charset)); $column++; - + if ($export_user_fields) { //show user fields data, if any, for this user $user_fields_values = UserManager::get_extra_user_data($row['user_id'],false,false, false, true); diff --git a/main/exercice/exercise_show.php b/main/exercice/exercise_show.php index fc1e6ab93a..bc55c1f15a 100644 --- a/main/exercice/exercise_show.php +++ b/main/exercice/exercise_show.php @@ -27,7 +27,7 @@ require_once '../inc/global.inc.php'; require_once 'exercise.lib.php'; if (empty($origin) ) { - $origin = $_REQUEST['origin']; + $origin = isset($_REQUEST['origin']) ? $_REQUEST['origin'] : null; } if ($origin == 'learnpath') { @@ -46,16 +46,16 @@ $TBL_TRACK_ATTEMPT = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTE // General parameters passed via POST/GET if ($debug) { error_log('Entered exercise_result.php: '.print_r($_POST,1)); } -if ( empty ( $formSent ) ) { $formSent = $_REQUEST['formSent']; } -if ( empty ( $exerciseResult ) ) { $exerciseResult = $_SESSION['exerciseResult'];} -if ( empty ( $questionId ) ) { $questionId = $_REQUEST['questionId'];} -if ( empty ( $choice ) ) { $choice = $_REQUEST['choice'];} -if ( empty ( $questionNum ) ) { $questionNum = $_REQUEST['num'];} -if ( empty ( $nbrQuestions ) ) { $nbrQuestions = $_REQUEST['nbrQuestions'];} -if ( empty ( $questionList ) ) { $questionList = $_SESSION['questionList'];} -if ( empty ( $objExercise ) ) { $objExercise = $_SESSION['objExercise'];} -if ( empty ( $exeId ) ) { $exeId = $_REQUEST['id'];} -if ( empty ( $action ) ) { $action = $_REQUEST['action']; } +if ( empty ( $formSent ) ) { $formSent = isset($_REQUEST['formSent']) ? $_REQUEST['formSent'] : null; } +if ( empty ( $exerciseResult ) ) { $exerciseResult = isset($_SESSION['exerciseResult']) ? $_SESSION['exerciseResult'] : null; } +if ( empty ( $questionId ) ) { $questionId = isset($_REQUEST['questionId']) ? $_REQUEST['questionId'] : null;} +if ( empty ( $choice ) ) { $choice = isset($_REQUEST['choice']) ? $_REQUEST['choice'] : null;} +if ( empty ( $questionNum ) ) { $questionNum = isset($_REQUEST['num']) ? $_REQUEST['num'] : null;} +if ( empty ( $nbrQuestions ) ) { $nbrQuestions = isset($_REQUEST['nbrQuestions']) ? $_REQUEST['nbrQuestions'] : null;} +if ( empty ( $questionList ) ) { $questionList = isset($_SESSION['questionList']) ? $_SESSION['questionList'] : null;} +if ( empty ( $objExercise ) ) { $objExercise = isset($_SESSION['objExercise']) ? $_SESSION['objExercise'] : null;} +if ( empty ( $exeId ) ) { $exeId = isset($_REQUEST['id']) ? $_REQUEST['id'] : null;} +if ( empty ( $action ) ) { $action = isset($_REQUEST['action']) ? $_REQUEST['action'] : null;} $id = intval($_REQUEST['id']); //exe id @@ -105,7 +105,9 @@ if (!$is_allowedToEdit) { if (isset($_SESSION['gradebook'])) { - $gradebook= Security::remove_XSS($_SESSION['gradebook']); + $gradebook = Security::remove_XSS($_SESSION['gradebook']); +} else { + $gradebook = null; } if (!empty($gradebook) && $gradebook=='view') { @@ -218,15 +220,16 @@ $arrques = array(); $arrans = array(); $user_restriction = $is_allowedToEdit ? '' : "AND user_id=".intval($student_id)." "; -$query = "SELECT attempts.question_id, answer FROM ".$TBL_TRACK_ATTEMPT." as attempts - INNER JOIN ".$TBL_TRACK_EXERCICES." AS stats_exercices ON stats_exercices.exe_id=attempts.exe_id - INNER JOIN ".$TBL_EXERCICE_QUESTION." AS quizz_rel_questions - ON quizz_rel_questions.exercice_id=stats_exercices.exe_exo_id - AND quizz_rel_questions.question_id = attempts.question_id - AND quizz_rel_questions.c_id=".api_get_course_int_id()." - INNER JOIN ".$TBL_QUESTIONS." AS questions - ON questions.id=quizz_rel_questions.question_id - AND questions.c_id = ".api_get_course_int_id()." +$query = "SELECT attempts.question_id, answer + FROM ".$TBL_TRACK_ATTEMPT." as attempts + INNER JOIN ".$TBL_TRACK_EXERCICES." AS stats_exercices ON stats_exercices.exe_id=attempts.exe_id + INNER JOIN ".$TBL_EXERCICE_QUESTION." AS quizz_rel_questions + ON quizz_rel_questions.exercice_id=stats_exercices.exe_exo_id AND + quizz_rel_questions.question_id = attempts.question_id AND + quizz_rel_questions.c_id=".api_get_course_int_id()." + INNER JOIN ".$TBL_QUESTIONS." AS questions + ON questions.id=quizz_rel_questions.question_id AND + questions.c_id = ".api_get_course_int_id()." WHERE attempts.exe_id='".Database::escape_string($id)."' $user_restriction GROUP BY quizz_rel_questions.question_order, attempts.question_id"; diff --git a/main/exercice/exercise_submit.php b/main/exercice/exercise_submit.php index 77fd355455..6ed0a20087 100644 --- a/main/exercice/exercise_submit.php +++ b/main/exercice/exercise_submit.php @@ -487,7 +487,7 @@ if ($objExercise->selectAttempts() > 0) { if ($objExercise->results_disabled == 0 && $origin != 'learnpath') { //Showing latest attempt according with task BT#1628 - $exercise_stat_info = get_exercise_results_by_user($user_id, $exerciseId, api_get_course_id(), api_get_session_id()); + $exercise_stat_info = get_exercise_results_by_user($user_id, $exerciseId, api_get_course_int_id(), api_get_session_id()); if (!empty($exercise_stat_info)) { $max_exe_id = max(array_keys($exercise_stat_info)); @@ -634,7 +634,8 @@ if ($time_control) { // First we update the attempt to today // How the expired time is changed into "track_e_exercices" table,then the last attempt for this student should be changed too,so - $sql_track_e_exe = "UPDATE $exercice_attemp_table SET tms = '".api_get_utc_datetime()."' WHERE exe_id = '".$exercise_stat_info['exe_id']."' AND tms = '".$last_attempt_date."' "; + $sql_track_e_exe = "UPDATE $exercice_attemp_table SET tms = '".api_get_utc_datetime()."' + WHERE exe_id = '".$exercise_stat_info['exe_id']."' AND tms = '".$last_attempt_date."' "; if ($debug) {error_log('7.10. $sql_track_e_exe2: '.$sql_track_e_exe); } Database::query($sql_track_e_exe); diff --git a/main/exercice/hotpotatoes_exercise_result.class.php b/main/exercice/hotpotatoes_exercise_result.class.php index 09c50270b6..e41b0001f1 100644 --- a/main/exercice/hotpotatoes_exercise_result.class.php +++ b/main/exercice/hotpotatoes_exercise_result.class.php @@ -5,7 +5,7 @@ * of type HotpotatoesExerciseResult * which allows you to export exercises results in multiple presentation forms * @package chamilo.exercise - * @author + * @author * @version $Id: $ */ /** @@ -69,41 +69,41 @@ class HotpotatoesExerciseResult $TBL_USER = Database::get_main_table(TABLE_MAIN_USER); $TBL_TRACK_EXERCISES = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES); $TBL_TRACK_HOTPOTATOES = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_HOTPOTATOES); - $TBL_TRACK_ATTEMPT_RECORDING= Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT_RECORDING); - + $TBL_TRACK_ATTEMPT_RECORDING = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT_RECORDING); + $cid = api_get_course_id(); $course_id = api_get_course_int_id(); $user_id = intval($user_id); $session_id_and = ' AND te.session_id = ' . api_get_session_id() . ' '; $hotpotato_name = Database::escape_string($hotpotato_name); - - + + if (!empty($exercise_id)) { $session_id_and .= " AND exe_exo_id = $exercise_id "; } - if (empty($user_id)) { - $sql="SELECT firstname as userpart1, lastname as userpart2 , - email, - tth.exe_name, - tth.exe_result, - tth.exe_weighting, - tth.exe_date - FROM $TBL_TRACK_HOTPOTATOES tth, $TBL_USER tu - WHERE tu.user_id=tth.exe_user_id AND - tth.exe_cours_id = '" . Database :: escape_string($cid) . "' AND - tth.exe_name = '$hotpotato_name' - ORDER BY tth.exe_cours_id ASC, tth.exe_date ASC"; - } else { - $user_id_and = ' AND te.exe_user_id = ' . api_get_user_id() . ' '; - // get only this user's results - - $sql = "SELECT '', exe_name, exe_result , exe_weighting, exe_date - FROM $TBL_TRACK_HOTPOTATOES - WHERE exe_user_id = '" . $user_id . "' AND - exe_cours_id = '" . Database :: escape_string($cid) . "' AND - tth.exe_name = '$hotpotato_name' - ORDER BY exe_cours_id ASC, exe_date ASC"; + if (empty($user_id)) { + $sql="SELECT firstname as userpart1, lastname as userpart2 , + email, + tth.exe_name, + tth.exe_result, + tth.exe_weighting, + tth.exe_date + FROM $TBL_TRACK_HOTPOTATOES tth, $TBL_USER tu + WHERE tu.user_id=tth.exe_user_id AND + tth.c_id = '" . $course_id. "' AND + tth.exe_name = '$hotpotato_name' + ORDER BY tth.c_id ASC, tth.exe_date ASC"; + } else { + $user_id_and = ' AND te.exe_user_id = ' . api_get_user_id() . ' '; + // get only this user's results + + $sql = "SELECT '', exe_name, exe_result , exe_weighting, exe_date + FROM $TBL_TRACK_HOTPOTATOES + WHERE exe_user_id = '" . $user_id . "' AND + c_id = '" . $course_id . "' AND + tth.exe_name = '$hotpotato_name' + ORDER BY c_id ASC, exe_date ASC"; } $results = array(); diff --git a/main/exercice/mark_free_answer.php b/main/exercice/mark_free_answer.php index 2041589e19..56d54151b0 100644 --- a/main/exercice/mark_free_answer.php +++ b/main/exercice/mark_free_answer.php @@ -83,7 +83,7 @@ $nameTools=get_lang('Exercice'); $interbreadcrumb[]=array("url" => "exercice.php","name" => get_lang('Exercices')); $my_msg = 'No change.'; - +$courseId = api_get_course_int_id(); if ($action == 'mark') { if (!empty($_POST['score']) AND $_POST['score'] < $obj_question->selectWeighting() AND $_POST['score'] >= 0) { //mark the user mark into the database using something similar to the following function: @@ -91,7 +91,9 @@ if ($action == 'mark') { $exercise_table = Database::get_statistic_table('track_e_exercices'); #global $origin, $tbl_learnpath_user, $learnpath_id, $learnpath_item_id; $sql = "SELECT * FROM $exercise_table - WHERE exe_user_id = '".Database::escape_string($my_usr)."' AND exe_cours_id = '".Database::escape_string($my_cid)."' AND exe_exo_id = '".Database::escape_string($my_exe)."' + WHERE exe_user_id = '".Database::escape_string($my_usr)."' AND + c_id = '".$courseId."' AND + exe_exo_id = '".Database::escape_string($my_exe)."' ORDER BY exe_date DESC"; #echo $sql; $res = Database::query($sql); @@ -107,21 +109,21 @@ if ($action == 'mark') { $my_msg = get_lang('MarkIsUpdated'); } else { $my_score = $_POST['score']; - $reallyNow = time(); + $reallyNow = api_get_utc_datetime(); $sql = "INSERT INTO $exercise_table ( exe_user_id, - exe_cours_id, + c_id, exe_exo_id, exe_result, exe_weighting, exe_date ) VALUES ( '".Database::escape_string($my_usr)."', - '".Database::escape_string($my_cid)."', + '".$courseId."', '".Database::escape_string($my_exe)."', '".Database::escape_string($my_score)."', '".Database::escape_string($obj_question->selectWeighting())."', - FROM_UNIXTIME(".$reallyNow.") + ".$reallyNow." )"; #if ($origin == 'learnpath') #{ @@ -136,7 +138,7 @@ if ($action == 'mark') { $my_msg = get_lang('MarkInserted'); } //Database::query($sql); - //return 0; + //return 0; } else { $my_msg .= get_lang('TotalScoreTooBig'); } diff --git a/main/exercice/overview.php b/main/exercice/overview.php index 1bcc79ccd6..362561abbd 100644 --- a/main/exercice/overview.php +++ b/main/exercice/overview.php @@ -125,7 +125,7 @@ if ($visible_return['value'] == false) { } } -$attempts = get_exercise_results_by_user(api_get_user_id(), $objExercise->id, api_get_course_id(), api_get_session_id(), $learnpath_id, $learnpath_item_id, 'desc'); +$attempts = get_exercise_results_by_user(api_get_user_id(), $objExercise->id, api_get_course_int_id(), api_get_session_id(), $learnpath_id, $learnpath_item_id, 'desc'); $counter = count($attempts); $my_attempt_array = array(); diff --git a/main/exercice/savescores.php b/main/exercice/savescores.php index d4a152b26a..a1a9f2b4e3 100644 --- a/main/exercice/savescores.php +++ b/main/exercice/savescores.php @@ -61,11 +61,11 @@ function save_scores($file, $score) // anonymous $user_id = "NULL"; } - $sql = "INSERT INTO $TABLETRACK_HOTPOTATOES (exe_name, exe_user_id, exe_date, exe_cours_id, exe_result, exe_weighting) VALUES ( + $sql = "INSERT INTO $TABLETRACK_HOTPOTATOES (exe_name, exe_user_id, exe_date, c_id, exe_result, exe_weighting) VALUES ( '".Database::escape_string($file)."', '".Database::escape_string($user_id)."', '".Database::escape_string($date)."', - '".Database::escape_string(api_get_course_id())."', + '".api_get_course_int_id()."', '".Database::escape_string($score)."', '".Database::escape_string($weighting)."')"; diff --git a/main/exercice/stats.php b/main/exercice/stats.php index f136d9c6a7..6a82232bc9 100644 --- a/main/exercice/stats.php +++ b/main/exercice/stats.php @@ -45,8 +45,8 @@ $headers = array( if (!empty($question_list)) { foreach ($question_list as $question_id) { $question_obj = Question::read($question_id); - $exercise_stats = get_student_stats_by_question($question_id, $exercise_id, api_get_course_id(), api_get_session_id()); - $count_users = get_number_students_question_with_answer_count($question_id, $exercise_id, api_get_course_id(), api_get_session_id()); + $exercise_stats = get_student_stats_by_question($question_id, $exercise_id, api_get_course_int_id(), api_get_session_id()); + $count_users = get_number_students_question_with_answer_count($question_id, $exercise_id, api_get_course_int_id(), api_get_session_id()); $data[$question_id]['name'] = Text::cut($question_obj->question, 100); $data[$question_id]['type'] = $question_obj->get_question_type_name(); @@ -101,7 +101,7 @@ if (!empty($question_list)) { $id = 0; foreach ($question_list as $question_id) { $question_obj = Question::read($question_id); - $exercise_stats = get_student_stats_by_question($question_id, $exercise_id, api_get_course_id(), api_get_session_id()); + $exercise_stats = get_student_stats_by_question($question_id, $exercise_id, api_get_course_int_id(), api_get_session_id()); $answer = new Answer($question_id); $answer_count = $answer->selectNbrAnswers(); @@ -134,7 +134,7 @@ if (!empty($question_list)) { $data[$id]['correct'] = '-'; - $count = get_number_students_answer_count($real_answer_id, $question_id, $exercise_id, api_get_course_id(), api_get_session_id(), FILL_IN_BLANKS, $answer_info_db, $answer_item); + $count = get_number_students_answer_count($real_answer_id, $question_id, $exercise_id, api_get_course_int_id(), api_get_session_id(), FILL_IN_BLANKS, $answer_info_db, $answer_item); $percentange = 0; if (!empty($count_students)) { @@ -165,7 +165,7 @@ if (!empty($question_list)) { $data[$id]['answer'] = $correct; $data[$id]['correct'] = $answer_info; - $count = get_number_students_answer_count($answer_id, $question_id, $exercise_id, api_get_course_id(), api_get_session_id(), MATCHING); + $count = get_number_students_answer_count($answer_id, $question_id, $exercise_id, api_get_course_int_id(), api_get_session_id(), MATCHING); $percentange = 0; if (!empty($count_students)) { $percentange = $count/$count_students*100; @@ -198,7 +198,7 @@ if (!empty($question_list)) { $data[$id]['answer'] = $answer_info; $data[$id]['correct'] = $correct_answer; - $count = get_number_students_answer_count($real_answer_id, $question_id, $exercise_id, api_get_course_id(), api_get_session_id()); + $count = get_number_students_answer_count($real_answer_id, $question_id, $exercise_id, api_get_course_int_id(), api_get_session_id()); $percentange = 0; if (!empty($count_students)) { $percentange = $count/$count_students*100; diff --git a/main/exercice/testcategory.class.php b/main/exercice/testcategory.class.php index 570fe9af93..2665d99092 100644 --- a/main/exercice/testcategory.class.php +++ b/main/exercice/testcategory.class.php @@ -445,8 +445,9 @@ class Testcategory { $in_exe_id = intval($in_exe_id); $in_user_id = intval($in_user_id); - $query = "SELECT DISTINCT marks, exe_id, user_id, ta.question_id, category_id FROM $tbl_track_attempt ta , $tbl_question_rel_category qrc - WHERE ta.question_id=qrc.question_id AND qrc.category_id=$in_cat_id AND exe_id=$in_exe_id AND user_id=$in_user_id"; + $query = "SELECT DISTINCT marks, exe_id, user_id, ta.question_id, category_id + FROM $tbl_track_attempt ta , $tbl_question_rel_category qrc + WHERE ta.question_id = qrc.question_id AND qrc.category_id=$in_cat_id AND exe_id = $in_exe_id AND user_id = $in_user_id"; $res = Database::query($query); $totalcatscore = ""; while ($data = Database::fetch_array($res)) { diff --git a/main/gradebook/gradebook_result.class.php b/main/gradebook/gradebook_result.class.php index a8735a9622..bb30f6d2a2 100644 --- a/main/gradebook/gradebook_result.class.php +++ b/main/gradebook/gradebook_result.class.php @@ -72,8 +72,8 @@ class GradeBookResult $sql="SELECT q.id, q.question, q.ponderation, q.position, q.type, q.picture " . " FROM $TBL_EXERCISE_QUESTION eq, $TBL_QUESTIONS q " . " WHERE eq.c_di = $course_id AND - q.c_di = $course_id AND - eq.question_id=q.id AND + q.c_di = $course_id AND + eq.question_id=q.id AND eq.exercice_id='$e_id' " . " ORDER BY q.position"; $result = Database::query($sql); @@ -93,10 +93,10 @@ class GradeBookResult function _getGradeBookReporting($document_path,$user_id=null) { $return = array(); $TBL_EXERCISES = Database::get_course_table(TABLE_QUIZ_TEST); - $TBL_USER = Database::get_main_table(TABLE_MAIN_USER); + $TBL_USER = Database::get_main_table(TABLE_MAIN_USER); $TBL_TRACK_EXERCISES = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES); $TBL_TRACK_HOTPOTATOES = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_HOTPOTATOES); - + $cid = api_get_course_id(); $course_id = api_get_course_int_id(); if (empty($user_id)) { @@ -106,29 +106,29 @@ class GradeBookResult te.exe_weighting, te.exe_date,te.exe_id, user.email, user.user_id FROM $TBL_EXERCISES ce , $TBL_TRACK_EXERCISES te, $TBL_USER user WHERE ce.c_id = $course_id AND - te.exe_exo_id = ce.id AND - user_id=te.exe_user_id AND te.exe_cours_id='$cid' - ORDER BY te.exe_cours_id ASC, ce.title ASC, te.exe_date ASC"; + te.exe_exo_id = ce.id AND + user_id=te.exe_user_id AND te.c_id = '$course_id' + ORDER BY te.c_id ASC, ce.title ASC, te.exe_date ASC"; $hpsql="SELECT ".(api_is_western_name_order() ? "CONCAT(tu.firstname,' ',tu.lastname)" : "CONCAT(tu.lastname,' ',tu.firstname)").", tth.exe_name, tth.exe_result , tth.exe_weighting, tth.exe_date, tu.email, tu.user_id FROM $TBL_TRACK_HOTPOTATOES tth, $TBL_USER tu - WHERE tu.user_id=tth.exe_user_id AND tth.exe_cours_id = '".$cid."' - ORDER BY tth.exe_cours_id ASC, tth.exe_date ASC"; + WHERE tu.user_id=tth.exe_user_id AND tth.c_id = '".$course_id."' + ORDER BY tth.c_id ASC, tth.exe_date ASC"; } else { // get only this user's results $sql = "SELECT '',ce.title, te.exe_result , te.exe_weighting, te.exe_date,te.exe_id FROM $TBL_EXERCISES ce , $TBL_TRACK_EXERCISES te WHERE ce.c_id = $course_id AND - te.exe_exo_id = ce.id AND - te.exe_user_id = '".$user_id."' AND - te.exe_cours_id = '$cid' - ORDER BY te.exe_cours_id ASC, ce.title ASC, te.exe_date ASC"; + te.exe_exo_id = ce.id AND + te.exe_user_id = '".$user_id."' AND + te.c_id = '$course_id' + ORDER BY te.c_id ASC, ce.title ASC, te.exe_date ASC"; $hpsql="SELECT '',exe_name, exe_result , exe_weighting, exe_date FROM $TBL_TRACK_HOTPOTATOES - WHERE exe_user_id = '".$user_id."' AND exe_cours_id = '".$cid."' - ORDER BY exe_cours_id ASC, exe_date ASC"; + WHERE exe_user_id = '".$user_id."' AND c_id = '".$course_id."' + ORDER BY c_id ASC, exe_date ASC"; } $results=getManyResultsXCol($sql,8); @@ -239,29 +239,29 @@ class GradeBookResult * Exports the complete report as an XLS file * @return boolean False on error */ - public function exportCompleteReportXLS($data) { + public function exportCompleteReportXLS($data) { $filename = 'gradebook-results-'.date('Y-m-d-h:i:s').'.xls'; - include api_get_path(LIBRARY_PATH).'pear/Spreadsheet_Excel_Writer/Writer.php'; + include api_get_path(LIBRARY_PATH).'pear/Spreadsheet_Excel_Writer/Writer.php'; $workbook = new Spreadsheet_Excel_Writer(); $workbook->setVersion(8); // BIFF8 $workbook->setTempDir(api_get_path(SYS_ARCHIVE_PATH)); $workbook->send($filename); - + $worksheet =& $workbook->addWorksheet('Report'); $worksheet->setInputEncoding(api_get_system_encoding()); - + $line = 0; $column = 0; //skip the first column (row titles) //headers - foreach ($data[0] as $header_col) { + foreach ($data[0] as $header_col) { $worksheet->write($line, $column, $header_col); $column++; } - $line++; + $line++; $cant_students = count($data[1]); - + for ($i=0;$i<$cant_students;$i++) { $column = 0; foreach ($data[1][$i] as $col_name) { @@ -272,7 +272,7 @@ class GradeBookResult } $workbook->close(); exit; - + } /** * Exports the complete report as a DOCX file diff --git a/main/gradebook/lib/be/exerciselink.class.php b/main/gradebook/lib/be/exerciselink.class.php index 52f99e07b5..ee9c7f3c0d 100644 --- a/main/gradebook/lib/be/exerciselink.class.php +++ b/main/gradebook/lib/be/exerciselink.class.php @@ -21,7 +21,7 @@ class ExerciseLink extends AbstractLink parent::__construct(); $this->set_type(LINK_EXERCISE); } - + // FUNCTIONS IMPLEMENTING ABSTRACTLINK /** @@ -35,12 +35,12 @@ class ExerciseLink extends AbstractLink } $tbl_grade_links = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_LINK); - $sql = 'SELECT id, title from '.$this->get_exercise_table().' exe + $sql = 'SELECT id, title from '.$this->get_exercise_table().' exe WHERE id NOT IN ( - SELECT ref_id FROM '.$tbl_grade_links.' - WHERE type = '.LINK_EXERCISE." AND + SELECT ref_id FROM '.$tbl_grade_links.' + WHERE type = '.LINK_EXERCISE." AND course_code = '".$this->get_course_code()."' - ) AND + ) AND exe.c_id = ".$this->course_id; $result = Database::query($sql); @@ -50,7 +50,7 @@ class ExerciseLink extends AbstractLink } return $cats; } - + /** * Generate an array of all exercises available. * @return array 2-dimensional array - every element contains 2 subelements (id, name) @@ -58,21 +58,21 @@ class ExerciseLink extends AbstractLink public function get_all_links() { if (empty($this->course_code)) { die('Error in get_not_created_links() : course code not set'); - } + } $session_id = api_get_session_id(); if (empty($session_id)) { $session_condition = api_get_session_condition(0, true); } else { $session_condition = api_get_session_condition($session_id, true, true); - } - - $sql = 'SELECT id,title from '.$this->get_exercise_table().' - WHERE c_id = '.$this->course_id.' AND active=1 '.$session_condition; - - - /* $sql = 'SELECT id,title from '.$this->get_exercise_table().' + } + + $sql = 'SELECT id,title from '.$this->get_exercise_table().' + WHERE c_id = '.$this->course_id.' AND active=1 '.$session_condition; + + + /* $sql = 'SELECT id,title from '.$this->get_exercise_table().' WHERE c_id = '.$this->course_id.' AND active=1 AND session_id='.api_get_session_id().''; - */ + */ $result = Database::query($sql); $cats = array(); while ($data=Database::fetch_array($result)) { @@ -87,10 +87,10 @@ class ExerciseLink extends AbstractLink public function has_results() { $tbl_stats = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES); $session_id = api_get_session_id(); - $sql = 'SELECT count(exe_id) AS number FROM '.$tbl_stats." - WHERE session_id = $session_id AND - exe_cours_id = '".$this->get_course_code()."'".' AND - exe_exo_id = '.(int)$this->get_ref_id(); + $sql = 'SELECT count(exe_id) AS number FROM '.$tbl_stats." + WHERE session_id = $session_id AND + c_id = '".$this->course_id."'".' AND + exe_exo_id = '.(int)$this->get_ref_id(); $result = Database::query($sql); $number=Database::fetch_row($result); return ($number[0] != 0); @@ -109,21 +109,20 @@ class ExerciseLink extends AbstractLink //the following query should be similar (in conditions) to the one used in exercice/exercice.php, look for note-query-exe-results marker $session_id = api_get_session_id(); $sql = "SELECT * FROM $tbl_stats - WHERE exe_exo_id = ".intval($this->get_ref_id())." AND - orig_lp_id = 0 AND - orig_lp_item_id = 0 AND + WHERE exe_exo_id = ".intval($this->get_ref_id())." AND + orig_lp_id = 0 AND + orig_lp_item_id = 0 AND status <> 'incomplete' AND - session_id = $session_id + session_id = $session_id "; if (isset($stud_id)) { - $course_code_exe = $this->get_course_code(); - $sql .= " AND exe_cours_id = '$course_code_exe' AND + $sql .= " AND c_id = '{$this->course_id}' AND exe_user_id = '$stud_id' "; } $sql .= ' ORDER BY exe_id DESC'; $scores = Database::query($sql); - + if (isset($stud_id)) { // for 1 student if ($data = Database::fetch_array($scores)) { @@ -143,11 +142,11 @@ class ExerciseLink extends AbstractLink if (!in_array($data['exe_user_id'], $students)) { if ($data['exe_weighting'] != 0) { $students[] = $data['exe_user_id']; - $student_count++; + $student_count++; $sum += $data['exe_result'] / $data['exe_weighting']; } } - } + } if ($student_count == 0) { return null; @@ -179,7 +178,7 @@ class ExerciseLink extends AbstractLink * Get name to display: same as exercise title */ public function get_name() { - $data = $this->get_exercise_data(); + $data = $this->get_exercise_data(); return $data['title']; } @@ -230,7 +229,7 @@ class ExerciseLink extends AbstractLink */ private function get_exercise_table() { $this->exercise_table = Database :: get_course_table(TABLE_QUIZ_TEST); - return $this->exercise_table; + return $this->exercise_table; } /** @@ -241,9 +240,9 @@ class ExerciseLink extends AbstractLink if ($tbl_exercise=='') { return false; } elseif (!isset($this->exercise_data)) { - $sql = 'SELECT * FROM '.$this->get_exercise_table().' + $sql = 'SELECT * FROM '.$this->get_exercise_table().' WHERE c_id = '.$this->course_id.' AND id = '.(int)$this->get_ref_id().' '; - + $result = Database::query($sql); $this->exercise_data=Database::fetch_array($result); } diff --git a/main/inc/ajax/exercise.ajax.php b/main/inc/ajax/exercise.ajax.php index 244402368a..44d9947296 100644 --- a/main/inc/ajax/exercise.ajax.php +++ b/main/inc/ajax/exercise.ajax.php @@ -337,9 +337,9 @@ switch ($action) { // Deleting old attempt if (isset($attempt_list) && !empty($attempt_list[$my_question_id])) { if ($debug) error_log("delete_attempt exe_id : $exe_id, my_question_id: $my_question_id"); - delete_attempt($exe_id, api_get_user_id() , $course_code, $session_id, $my_question_id); + delete_attempt($exe_id, api_get_user_id(), $course_id, $session_id, $my_question_id); if ($objQuestionTmp->type == HOT_SPOT) { - delete_attempt_hotspot($exe_id, api_get_user_id() , $course_code, $my_question_id); + delete_attempt_hotspot($exe_id, api_get_user_id(), $course_id, $my_question_id); } if (isset($attempt_list[$my_question_id]) && isset($attempt_list[$my_question_id]['marks'])) { $total_score -= $attempt_list[$my_question_id]['marks']; diff --git a/main/inc/lib/course.lib.php b/main/inc/lib/course.lib.php index cb07125ff7..9651fda8de 100644 --- a/main/inc/lib/course.lib.php +++ b/main/inc/lib/course.lib.php @@ -1567,6 +1567,8 @@ class CourseManager { $table_stats_links = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_LINKS); $table_stats_uploads = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_UPLOADS); + $courseInfo = api_get_course_info($code); + $code = Database::escape_string($code); // Unsubscribe all classes from the course @@ -1595,11 +1597,11 @@ class CourseManager { // Delete the course from the stats tables - $sql = "DELETE FROM $table_stats_hotpots WHERE exe_cours_id = '".$code."'"; + $sql = "DELETE FROM $table_stats_hotpots WHERE c_id = '".$courseInfo['real_id']."'"; Database::query($sql); - $sql = "DELETE FROM $table_stats_attempt WHERE course_code = '".$code."'"; + $sql = "DELETE FROM $table_stats_attempt WHERE c_id = '".$courseInfo['real_id']."'"; Database::query($sql); - $sql = "DELETE FROM $table_stats_exercises WHERE exe_cours_id = '".$code."'"; + $sql = "DELETE FROM $table_stats_exercises WHERE c_id = '".$courseInfo['real_id']."'"; Database::query($sql); $sql = "DELETE FROM $table_stats_access WHERE access_cours_code = '".$code."'"; Database::query($sql); diff --git a/main/inc/lib/events.lib.inc.php b/main/inc/lib/events.lib.inc.php index c42c83542d..382830d342 100644 --- a/main/inc/lib/events.lib.inc.php +++ b/main/inc/lib/events.lib.inc.php @@ -422,9 +422,9 @@ function create_event_exercice($exo_id) $row_exe_id = Database::fetch_row($res_exe_id); $exercise_id = intval($row_exe_id[0]); // Second, check if the record exists in the database (looking for incomplete records) - $sql = "SELECT exe_id FROM $tbl_track_exe WHERE exe_exo_id = $exo_id AND ". - "exe_user_id = $uid AND ". - "exe_cours_id = '".api_get_course_id()."' AND ". + $sql = "SELECT exe_id FROM $tbl_track_exe + WHERE exe_exo_id = $exo_id AND + exe_user_id = $uid AND c_id = '".$course_id."' AND ". "status = 'incomplete' AND ". "session_id = ".api_get_session_id(); $res = Database::query($sql); @@ -445,8 +445,8 @@ function create_event_exercice($exo_id) } else { $expired_date = '0000-00-00 00:00:00'; } - $sql = "INSERT INTO $tbl_track_exe ( exe_user_id, exe_cours_id, expired_time_control, exe_exo_id, session_id) - VALUES ( $uid, '".api_get_course_id()."' ,'$expired_date','$exo_id','".api_get_session_id()."')"; + $sql = "INSERT INTO $tbl_track_exe (exe_user_id, c_id, expired_time_control, exe_exo_id, session_id) + VALUES ($uid, '".$course_id."' ,'$expired_date','$exo_id','".api_get_session_id()."')"; $res = Database::query($sql); $id = Database::insert_id(); return $id; @@ -507,7 +507,7 @@ function exercise_attempt($score, $answer, $question_id, $exe_id, $position, $ex $file = Database::escape_string(basename($nano->load_filename_if_exists(false))); } - $course_code = api_get_course_id(); + $courseId = api_get_course_int_id(); $session_id = api_get_session_id(); if (!empty($question_id) && !empty($exe_id) && !empty($user_id)) { @@ -515,7 +515,12 @@ function exercise_attempt($score, $answer, $question_id, $exe_id, $position, $ex //Check if attempt exists $sql = "SELECT exe_id FROM $TBL_TRACK_ATTEMPT - WHERE course_code = '$course_code' AND session_id = $session_id AND exe_id = $exe_id AND user_id = $user_id AND question_id = $question_id AND position = $position"; + WHERE c_id = $courseId AND + session_id = $session_id AND + exe_id = $exe_id AND + user_id = $user_id AND + question_id = $question_id AND + position = $position"; $result = Database::query($sql); if (Database::num_rows($result)) { if ($debug) @@ -524,30 +529,31 @@ function exercise_attempt($score, $answer, $question_id, $exe_id, $position, $ex return false; } - $sql = "INSERT INTO $TBL_TRACK_ATTEMPT (exe_id, user_id, question_id, answer, marks, course_code, session_id, position, tms, filename) + $sql = "INSERT INTO $TBL_TRACK_ATTEMPT (exe_id, user_id, question_id, answer, marks, c_id, session_id, position, tms, filename) VALUES ( ".$exe_id.", ".$user_id.", '".$question_id."', '".$answer."', '".$score."', - '".$course_code."', + '".$courseId."', '".$session_id."', '".$position."', '".$now."', '".$file."' )"; - if ($debug) + if ($debug) { error_log("Saving question attempt: "); - if ($debug) error_log($sql); + } $res = Database::query($sql); if (defined('ENABLED_LIVE_EXERCISE_TRACKING')) { $recording_table = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT_RECORDING); - if ($debug) + if ($debug) { error_log("Saving e attempt recording "); + } $recording_changes = "INSERT INTO $recording_table (exe_id, question_id, marks, insert_date, author, session_id) VALUES ('$exe_id','$question_id','$score','".api_get_utc_datetime()."','', '".api_get_session_id()."') "; Database::query($recording_changes); } @@ -843,14 +849,14 @@ function eventType_mod($etId, $users, $message, $subject) /** * Gets the last attempt of an exercise based in the exe_id + * @param int $exe_id + * @return mixed */ function get_last_attempt_date_of_exercise($exe_id) { $exe_id = intval($exe_id); $track_attempts = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT); - $sql_track_attempt = 'SELECT max(tms) as last_attempt_date FROM '.$track_attempts.' WHERE exe_id='.$exe_id; - $rs_last_attempt = Database::query($sql_track_attempt); $row_last_attempt = Database::fetch_array($rs_last_attempt); $last_attempt_date = $row_last_attempt['last_attempt_date']; //Get the date of last attempt @@ -881,7 +887,7 @@ function get_attempt_count($user_id, $exerciseId, $lp_id, $lp_item_id, $lp_item_ orig_lp_id = $lp_id AND orig_lp_item_id = $lp_item_id AND orig_lp_item_view_id = $lp_item_view_id AND - exe_cours_id = '".api_get_course_id()."' AND + c_id = '".api_get_course_int_id()."' AND session_id = '".api_get_session_id()."'"; $query = Database::query($sql); @@ -908,7 +914,7 @@ function get_attempt_count_not_finished($user_id, $exerciseId, $lp_id, $lp_item_ status != 'incomplete' AND orig_lp_id = $lp_id AND orig_lp_item_id = $lp_item_id AND - exe_cours_id = '".api_get_course_id()."' AND + c_id = '".api_get_course_int_id()."' AND session_id = '".api_get_session_id()."'"; $query = Database::query($sql); @@ -920,6 +926,12 @@ function get_attempt_count_not_finished($user_id, $exerciseId, $lp_id, $lp_item_ } } +/** + * @param int $user_id + * @param int $lp_id + * @param array $course + * @param int $session_id + */ function delete_student_lp_events($user_id, $lp_id, $course, $session_id) { @@ -954,7 +966,11 @@ function delete_student_lp_events($user_id, $lp_id, $course, $session_id) $sql = "DELETE FROM $lp_view_table WHERE c_id = $course_id AND user_id = $user_id AND lp_id= $lp_id AND session_id = $session_id "; Database::query($sql); - $sql = "SELECT exe_id FROM $track_e_exercises WHERE exe_user_id = $user_id AND session_id = $session_id AND exe_cours_id = '{$course['code']}' AND orig_lp_id = $lp_id"; + $sql = "SELECT exe_id FROM $track_e_exercises + WHERE exe_user_id = $user_id AND + session_id = $session_id AND + c_id = $course_id AND + orig_lp_id = $lp_id"; $result = Database::query($sql); $exe_list = array(); while ($row = Database::fetch_array($result, 'ASSOC')) { @@ -981,15 +997,20 @@ function delete_student_lp_events($user_id, $lp_id, $course, $session_id) * @param string course code * @param int session id */ -function delete_all_incomplete_attempts($user_id, $exercise_id, $course_code, $session_id = 0) +function delete_all_incomplete_attempts($user_id, $exercise_id, $course_id, $session_id = 0) { $track_e_exercises = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES); $user_id = intval($user_id); $exercise_id = intval($exercise_id); - $course_code = Database::escape_string($course_code); + $course_id = intval($course_id); $session_id = intval($session_id); if (!empty($user_id) && !empty($exercise_id) && !empty($course_code)) { - $sql = "DELETE FROM $track_e_exercises WHERE exe_user_id = $user_id AND exe_exo_id = $exercise_id AND exe_cours_id = '$course_code' AND session_id = $session_id AND status = 'incomplete' "; + $sql = "DELETE FROM $track_e_exercises + WHERE exe_user_id = $user_id AND + exe_exo_id = $exercise_id AND + c_id = '$course_id' AND + session_id = $session_id AND + status = 'incomplete' "; Database::query($sql); } } @@ -1002,11 +1023,11 @@ function delete_all_incomplete_attempts($user_id, $exercise_id, $course_code, $s * @return array with the results * */ -function get_all_exercise_results($exercise_id, $course_code, $session_id = 0, $load_question_list = true, $user_id = null) +function get_all_exercise_results($exercise_id, $courseId, $session_id = 0, $load_question_list = true, $user_id = null) { $TABLETRACK_EXERCICES = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES); $TBL_TRACK_ATTEMPT = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT); - $course_code = Database::escape_string($course_code); + $courseId = intval($courseId); $exercise_id = intval($exercise_id); $session_id = intval($session_id); @@ -1017,7 +1038,7 @@ function get_all_exercise_results($exercise_id, $course_code, $session_id = 0, $ } $sql = "SELECT * FROM $TABLETRACK_EXERCICES WHERE status = '' AND - exe_cours_id = '$course_code' AND + c_id = '$courseId' AND exe_exo_id = '$exercise_id' AND session_id = $session_id AND orig_lp_id =0 AND @@ -1046,18 +1067,24 @@ function get_all_exercise_results($exercise_id, $course_code, $session_id = 0, $ * @return array with the results * */ -function get_all_exercise_results_by_course($course_code, $session_id = 0, $get_count = true) +function get_all_exercise_results_by_course($courseId, $session_id = 0, $get_count = true) { $table_track_exercises = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES); $table_track_attempt = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT); - $course_code = Database::escape_string($course_code); - + $courseId = intval($courseId); $session_id = intval($session_id); + $select = '*'; if ($get_count) { $select = 'count(*) as count'; } - $sql = "SELECT $select FROM $table_track_exercises WHERE status = '' AND exe_cours_id = '$course_code' AND session_id = $session_id AND orig_lp_id = 0 AND orig_lp_item_id = 0 ORDER BY exe_id"; + $sql = "SELECT $select FROM $table_track_exercises + WHERE status = '' AND + c_id = '$courseId' AND + session_id = $session_id AND + orig_lp_id = 0 AND + orig_lp_item_id = 0 + ORDER BY exe_id"; $res = Database::query($sql); if ($get_count) { $row = Database::fetch_array($res, 'ASSOC'); @@ -1084,16 +1111,22 @@ function get_all_exercise_results_by_course($course_code, $session_id = 0, $get_ * @return array with the results * */ -function get_all_exercise_results_by_user($user_id, $course_code, $session_id = 0) +function get_all_exercise_results_by_user($user_id, $courseId, $session_id = 0) { $table_track_exercises = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES); $table_track_attempt = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT); - $course_code = Database::escape_string($course_code); - $exercise_id = intval($exercise_id); + $courseId = intval($courseId); $session_id = intval($session_id); $user_id = intval($user_id); - $sql = "SELECT * FROM $table_track_exercises WHERE status = '' AND exe_user_id = $user_id AND exe_cours_id = '$course_code' AND session_id = $session_id AND orig_lp_id = 0 AND orig_lp_item_id = 0 ORDER by exe_id"; + $sql = "SELECT * FROM $table_track_exercises + WHERE status = '' AND + exe_user_id = $user_id AND + c_id = '$courseId' AND + session_id = $session_id AND + orig_lp_id = 0 AND + orig_lp_item_id = 0 + ORDER by exe_id"; $res = Database::query($sql); $list = array(); @@ -1145,7 +1178,6 @@ function get_exercise_results_by_attempt($exe_id) $list[$exe_id]['question_list'][$row_q['question_id']] = $row_q; } } - // echo '
'; print_r($list); echo "
"; return $list; } @@ -1161,12 +1193,12 @@ function get_exercise_results_by_attempt($exe_id) * @return array with the results * */ -function get_exercise_results_by_user($user_id, $exercise_id, $course_code, $session_id = 0, $lp_id = 0, $lp_item_id = 0, $order = null) +function get_exercise_results_by_user($user_id, $exercise_id, $courseId, $session_id = 0, $lp_id = 0, $lp_item_id = 0, $order = null) { $table_track_exercises = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES); $table_track_attempt = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT); $table_track_attempt_recording = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT_RECORDING); - $course_code = Database::escape_string($course_code); + $courseId = intval($courseId); $exercise_id = intval($exercise_id); $session_id = intval($session_id); $user_id = intval($user_id); @@ -1180,12 +1212,12 @@ function get_exercise_results_by_user($user_id, $exercise_id, $course_code, $ses $sql = "SELECT * FROM $table_track_exercises WHERE status = '' AND exe_user_id = $user_id AND - exe_cours_id = '$course_code' AND + c_id = $courseId AND exe_exo_id = $exercise_id AND session_id = $session_id AND orig_lp_id = $lp_id AND orig_lp_item_id = $lp_item_id - ORDER by exe_id $order "; + ORDER by exe_id $order "; $res = Database::query($sql); $list = array(); @@ -1210,21 +1242,28 @@ function get_exercise_results_by_user($user_id, $exercise_id, $course_code, $ses /** * Count exercise attempts (NO Exercises in LPs ) from a given exercise id, course, session * @param int exercise id - * @param string course code + * @param int course id * @param int session id * @return array with the results * */ -function count_exercise_attempts_by_user($user_id, $exercise_id, $course_code, $session_id = 0) +function count_exercise_attempts_by_user($user_id, $exercise_id, $courseId, $session_id = 0) { $TABLETRACK_EXERCICES = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES); - $course_code = Database::escape_string($course_code); + $courseId = intval($courseId); $exercise_id = intval($exercise_id); $session_id = intval($session_id); $user_id = intval($user_id); $sql = "SELECT count(*) as count FROM $TABLETRACK_EXERCICES - WHERE status = '' AND exe_user_id = '$user_id' AND exe_cours_id = '$course_code' AND exe_exo_id = '$exercise_id' AND session_id = $session_id AND orig_lp_id =0 AND orig_lp_item_id = 0 ORDER BY exe_id"; + WHERE status = '' AND + exe_user_id = '$user_id' AND + c_id = '$courseId' AND + exe_exo_id = '$exercise_id' AND + session_id = $session_id AND + orig_lp_id =0 AND + orig_lp_item_id = 0 + ORDER BY exe_id"; $res = Database::query($sql); $result = 0; if (Database::num_rows($res) > 0) { @@ -1237,21 +1276,28 @@ function count_exercise_attempts_by_user($user_id, $exercise_id, $course_code, $ /** * Gets all exercise BEST results attempts (NO Exercises in LPs ) from a given exercise id, course, session per user * @param int exercise id - * @param string course code + * @param int course id * @param int session id * @return array with the results * @todo rename this function * */ -function get_best_exercise_results_by_user($exercise_id, $course_code, $session_id = 0) +function get_best_exercise_results_by_user($exercise_id, $courseId, $session_id = 0) { $table_track_exercises = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES); $table_track_attempt = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT); - $course_code = Database::escape_string($course_code); + $courseId = intval($courseId); $exercise_id = intval($exercise_id); $session_id = intval($session_id); - $sql = "SELECT * FROM $table_track_exercises WHERE status = '' AND exe_cours_id = '$course_code' AND exe_exo_id = '$exercise_id' AND session_id = $session_id AND orig_lp_id =0 AND orig_lp_item_id = 0 ORDER BY exe_id"; + $sql = "SELECT * FROM $table_track_exercises + WHERE status = '' AND + c_id = $courseId AND + exe_exo_id = '$exercise_id' AND + session_id = $session_id AND + orig_lp_id = 0 AND + orig_lp_item_id = 0 + ORDER BY exe_id"; $res = Database::query($sql); $list = array(); @@ -1269,7 +1315,6 @@ function get_best_exercise_results_by_user($exercise_id, $course_code, $session_ foreach ($list as $student_result) { $user_id = $student_result['exe_user_id']; $current_best_score[$user_id] = $student_result['exe_result']; - //echo $current_best_score[$user_id].' - '.$best_score_return[$user_id]['exe_result'].'
'; if ($current_best_score[$user_id] > $best_score_return[$user_id]['exe_result']) { $best_score_return[$user_id] = $student_result; } @@ -1277,18 +1322,24 @@ function get_best_exercise_results_by_user($exercise_id, $course_code, $session_ return $best_score_return; } -function get_best_attempt_exercise_results_per_user($user_id, $exercise_id, $course_code, $session_id = 0) +/** + * @param int $user_id + * @param int $exercise_id + * @param int $courseId + * @param int $session_id + * @return array + */ +function get_best_attempt_exercise_results_per_user($user_id, $exercise_id, $courseId, $session_id = 0) { $table_track_exercises = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES); - //$table_track_attempt = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT); - $course_code = Database::escape_string($course_code); + $courseId = intval($courseId); $exercise_id = intval($exercise_id); $session_id = intval($session_id); $user_id = intval($user_id); $sql = "SELECT * FROM $table_track_exercises WHERE status = '' AND - exe_cours_id = '$course_code' AND + c_id = '$courseId' AND exe_exo_id = '$exercise_id' AND session_id = $session_id AND exe_user_id = $user_id AND @@ -1322,17 +1373,24 @@ function get_best_attempt_exercise_results_per_user($user_id, $exercise_id, $cou return $best_score_return; } -function count_exercise_result_not_validated($exercise_id, $course_code, $session_id = 0) +/** + * @param int $exercise_id + * @param int $courseId + * @param int $session_id + * @return mixed + */ +function count_exercise_result_not_validated($exercise_id, $courseId, $session_id = 0) { $table_track_exercises = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES); $table_track_attempt = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT_RECORDING); - $course_code = Database::escape_string($course_code); + $courseId = intval($courseId); $session_id = intval($session_id); $exercise_id = intval($exercise_id); - $sql = "SELECT count(e.exe_id) as count FROM $table_track_exercises e LEFT JOIN $table_track_attempt a ON e.exe_id = a.exe_id + $sql = "SELECT count(e.exe_id) as count + FROM $table_track_exercises e LEFT JOIN $table_track_attempt a ON e.exe_id = a.exe_id WHERE exe_exo_id = $exercise_id AND - exe_cours_id = '$course_code' AND + c_id = '$courseId' AND e.session_id = $session_id AND orig_lp_id = 0 AND marks IS NULL AND @@ -1347,19 +1405,25 @@ function count_exercise_result_not_validated($exercise_id, $course_code, $sessio /** * Gets all exercise BEST results attempts (NO Exercises in LPs ) from a given exercise id, course, session per user * @param int exercise id - * @param string course code + * @param int course id * @param int session id * @return array with the results * */ -function get_count_exercises_attempted_by_course($course_code, $session_id = 0) +function get_count_exercises_attempted_by_course($courseId, $session_id = 0) { $table_track_exercises = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES); - $table_track_attempt = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT); - $course_code = Database::escape_string($course_code); + $courseId = intval($courseId); $session_id = intval($session_id); - $sql = "SELECT DISTINCT exe_exo_id, exe_user_id FROM $table_track_exercises WHERE status = '' AND exe_cours_id = '$course_code' AND session_id = $session_id AND orig_lp_id =0 AND orig_lp_item_id = 0 ORDER BY exe_id"; + $sql = "SELECT DISTINCT exe_exo_id, exe_user_id + FROM $table_track_exercises + WHERE status = '' AND + c_id = '$courseId' AND + session_id = $session_id AND + orig_lp_id =0 AND + orig_lp_item_id = 0 + ORDER BY exe_id"; $res = Database::query($sql); $count = 0; if (Database::num_rows($res) > 0) { @@ -1375,15 +1439,21 @@ function get_count_exercises_attempted_by_course($course_code, $session_id = 0) * @param int session id * @return array */ -function get_all_exercise_event_from_lp($exercise_id, $course_code, $session_id = 0) +function get_all_exercise_event_from_lp($exercise_id, $courseId, $session_id = 0) { $table_track_exercises = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES); $table_track_attempt = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT); - $course_code = Database::escape_string($course_code); + $courseId = intval($courseId); $exercise_id = intval($exercise_id); $session_id = intval($session_id); - $sql = "SELECT * FROM $table_track_exercises WHERE status = '' AND exe_cours_id = '$course_code' AND exe_exo_id = '$exercise_id' AND session_id = $session_id AND orig_lp_id !=0 AND orig_lp_item_id != 0"; + $sql = "SELECT * FROM $table_track_exercises + WHERE status = '' AND + c_id = $courseId AND + exe_exo_id = '$exercise_id' AND + session_id = $session_id AND + orig_lp_id !=0 AND + orig_lp_item_id != 0"; $res = Database::query($sql); $list = array(); @@ -1419,18 +1489,23 @@ function get_all_exercises_from_lp($lp_id, $course_id) * * @param int $id * @param int $question_id - * @return str the comment + * @return string the comment */ function get_comments($exe_id, $question_id) { $table_track_attempt = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT); $sql = "SELECT teacher_comment FROM ".$table_track_attempt." - WHERE exe_id='".Database::escape_string($exe_id)."' AND question_id = '".Database::escape_string($question_id)."' ORDER by question_id"; + WHERE exe_id='".Database::escape_string($exe_id)."' AND question_id = '".Database::escape_string($question_id)."' + ORDER by question_id"; $sqlres = Database::query($sql); $comm = Database::result($sqlres, 0, "teacher_comment"); return $comm; } +/** + * @param int $exe_id + * @return array + */ function get_all_exercise_event_by_exe_id($exe_id) { $table_track_attempt = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT); @@ -1446,42 +1521,65 @@ function get_all_exercise_event_by_exe_id($exe_id) return $list; } -function delete_attempt($exe_id, $user_id, $course_code, $session_id, $question_id) +/** + * + * @param int $exe_id + * @param int $user_id + * @param int $courseId + * @param int $session_id + * @param int $question_id + */ +function delete_attempt($exe_id, $user_id, $courseId, $session_id, $question_id) { $table_track_attempt = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT); $exe_id = intval($exe_id); $user_id = intval($user_id); - $course_code = Database::escape_string($course_code); + $courseId = intval($courseId); $session_id = intval($session_id); $question_id = intval($question_id); - $sql = "DELETE FROM $table_track_attempt WHERE exe_id = $exe_id AND user_id = $user_id AND course_code = '$course_code' AND session_id = $session_id AND question_id = $question_id "; + $sql = "DELETE FROM $table_track_attempt + WHERE exe_id = $exe_id AND + user_id = $user_id AND + c_id = $courseId AND + session_id = $session_id AND + question_id = $question_id "; Database::query($sql); } -function delete_attempt_hotspot($exe_id, $user_id, $course_code, $question_id) +/** + * @param $exe_id + * @param $user_id + * @param int $courseId + * @param $question_id + */ +function delete_attempt_hotspot($exe_id, $user_id, $courseId, $question_id) { $table_track_attempt = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_HOTSPOT); $exe_id = intval($exe_id); $user_id = intval($user_id); - $course_code = Database::escape_string($course_code); - //$session_id = intval($session_id); + $courseId = intval($courseId); $question_id = intval($question_id); - $sql = "DELETE FROM $table_track_attempt WHERE hotspot_exe_id = $exe_id AND hotspot_user_id = $user_id AND hotspot_course_code = '$course_code' AND hotspot_question_id = $question_id "; + $sql = "DELETE FROM $table_track_attempt + WHERE hotspot_exe_id = $exe_id AND + hotspot_user_id = $user_id AND + hotspot_course_code = $courseId AND + hotspot_question_id = $question_id "; Database::query($sql); } /** * User logs in for the first time to a course + * @param $course_code + * @param $user_id + * @param $session_id */ function event_course_login($course_code, $user_id, $session_id) { global $course_tracking_table; - - //@todo use api_get_utc_datetime $time = api_get_datetime(); $course_code = Database::escape_string($course_code); @@ -1492,7 +1590,6 @@ function event_course_login($course_code, $user_id, $session_id) VALUES('".$course_code."', '".$user_id."', '$time', '$time', '1', '".$session_id."')"; Database::query($sql); - //Course catalog stats modifications see #4191 CourseManager::update_course_ranking(null, null, null, null, true, false); } diff --git a/main/inc/lib/nanogong.lib.php b/main/inc/lib/nanogong.lib.php index 2a676c3db9..9ddbffadeb 100644 --- a/main/inc/lib/nanogong.lib.php +++ b/main/inc/lib/nanogong.lib.php @@ -15,15 +15,14 @@ */ class Nanogong { - - var $filename; - var $store_filename; - var $store_path; - var $params; - var $can_edit = false; + public $filename; + public $store_filename; + public $store_path; + public $params; + public $can_edit = false; /* Files allowed to upload */ - var $available_extensions = array('mp3', 'wav', 'ogg'); + public $available_extensions = array('mp3', 'wav', 'ogg'); public function __construct($params = array()) { @@ -169,7 +168,7 @@ class Nanogong /** * Delete audio file - * @return number + * @return int */ function delete_files() { @@ -193,7 +192,7 @@ class Nanogong /** * * Tricky stuff to deal with the feedback = 0 in exercises (all question per page) - * @param unknown_type $exe_id + * @param int $exe_id */ function replace_with_real_exe($exe_id) { @@ -215,6 +214,10 @@ class Nanogong } } + /** + * @param bool $load_from_database + * @return null|string + */ function load_filename_if_exists($load_from_database = false) { $filename = null; @@ -233,11 +236,11 @@ class Nanogong if (isset($this->params['exe_id']) && isset($this->params['user_id']) && isset($this->params['question_id']) && isset($this->params['session_id']) && isset($this->params['course_id'])) { $attempt_table = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT); $sql = "SELECT filename FROM $attempt_table - WHERE exe_id = ".$this->params['exe_id']." AND - user_id = ".$this->params['user_id']." AND - question_id = ".$this->params['question_id']." AND - session_id = ".$this->params['session_id']." AND - course_code = '".$this->course_info['code']."' LIMIT 1"; + WHERE exe_id = ".$this->params['exe_id']." AND + user_id = ".$this->params['user_id']." AND + question_id = ".$this->params['question_id']." AND + session_id = ".$this->params['session_id']." AND + c_id = '".$this->course_info['real_id']."' LIMIT 1"; $result = Database::query($sql); $result = Database::fetch_row($result, 'ASSOC'); @@ -258,6 +261,7 @@ class Nanogong * * Get the URL of the file * path courses/XXX/exercises/(session_id)/(exercise_id)/(question_id)/(user_id)/ + * @param int $force_download * * @return string */ @@ -267,14 +271,13 @@ class Nanogong $url = api_get_path(WEB_AJAX_PATH).'nanogong.ajax.php?a=get_file&download='.$force_download.'&'.$params; $params = $this->get_params(); $filename = basename($this->load_filename_if_exists()); - $url = api_get_path(WEB_COURSE_PATH).$this->course_info['path'].'/exercises/'. - $params['session_id'].'/'.$params['exercise_id'].'/'.$params['question_id'].'/'.$params['user_id'].'/'.$filename; - + $url = api_get_path(WEB_COURSE_PATH).$this->course_info['path'].'/exercises/'.$params['session_id'].'/'.$params['exercise_id'].'/'.$params['question_id'].'/'.$params['user_id'].'/'.$filename; return $url; } /** * Uploads the nanogong wav file + * @param bool */ public function upload_file($is_nano = false) { @@ -321,7 +324,7 @@ class Nanogong /** * Show the audio file + a button to download - * + * @param bool */ public function show_audio_file($show_delete_button = false) { @@ -571,6 +574,7 @@ class Nanogong /** * Returns the HTML form to upload a nano file or upload a file + * @param string */ function return_form($message = null) { @@ -588,8 +592,7 @@ class Nanogong array('id' => 'preview', 'style' => 'text-align:center; padding-left: 25px;') ); - $html .= '
'; - + $html = '
'; //Use normal upload file $html .= Display::return_icon('microphone.png', get_lang('PressRecordButton'), '', ICON_SIZE_BIG); $html .= '
'; @@ -636,21 +639,18 @@ class Nanogong $html .= ''.get_lang('UploadFile').''; $html .= ''; $html .= ''; - - $html .= '
'; - - $html .= ''; - $html .= '
'.$message.'
'; - $html .= $preview_file; - return $html; } + /** + * @param bool $return_as_query + * @return bool|string + */ function get_params($return_as_query = false) { if (empty($this->params)) { @@ -663,6 +663,10 @@ class Nanogong return $this->params; } + /** + * @param $attribute + * @return mixed + */ function get_param_value($attribute) { if (isset($this->params[$attribute])) { @@ -677,7 +681,7 @@ class Nanogong function show_button() { $params_string = $this->get_params(true); - $html .= '
'.Display::url( + $html = '
'.Display::url( get_lang('RecordAnswer'), api_get_path( WEB_AJAX_PATH @@ -688,4 +692,4 @@ class Nanogong return $html; } -} +} \ No newline at end of file diff --git a/main/inc/lib/tracking.lib.php b/main/inc/lib/tracking.lib.php index 703c99f4c8..541f8dcfc8 100644 --- a/main/inc/lib/tracking.lib.php +++ b/main/inc/lib/tracking.lib.php @@ -188,7 +188,7 @@ class Tracking $sql = "SELECT SUM(UNIX_TIMESTAMP(logout_course_date) - UNIX_TIMESTAMP(login_course_date)) as nb_seconds FROM $tbl_track_course - WHERE UNIX_TIMESTAMP(logout_course_date) > UNIX_TIMESTAMP(login_course_date) AND course_code='$course_code' AND session_id = '$session_id' $condition_user"; + WHERE UNIX_TIMESTAMP(logout_course_date) > UNIX_TIMESTAMP(login_course_date) AND course_code = '$course_code' AND session_id = '$session_id' $condition_user"; $rs = Database::query($sql); $row = Database::fetch_array($rs); @@ -477,11 +477,11 @@ class Tracking $sql = "SELECT SUM(exe_result/exe_weighting*100) as avg_score, COUNT(*) as num_attempts FROM $tbl_stats_exercise WHERE exe_exo_id IN ('".$exercise_id."') - $condition_user AND - orig_lp_id = 0 AND - status = '' AND - exe_cours_id = '$course_code' AND - orig_lp_item_id = 0 $condition_session + $condition_user AND + orig_lp_id = 0 AND + status = '' AND + c_id = '{$course_info['real_id']}' AND + orig_lp_item_id = 0 $condition_session ORDER BY exe_date DESC"; $res = Database::query($sql); @@ -507,15 +507,15 @@ class Tracking /** * Get count student's exercise COMPLETED attempts * @param int Student id - * @param string Course code + * @param int course id * @param int Exercise id * @param int Learning path id (optional), for showing attempts inside a learning path $lp_id and $lp_item_id params are required. * @param int Learning path item id (optional), for showing attempts inside a learning path $lp_id and $lp_item_id params are required. * @return int count of attempts */ - public static function count_student_exercise_attempts($student_id, $course_code, $exercise_id, $lp_id = 0, $lp_item_id = 0, $session_id = 0) + public static function count_student_exercise_attempts($student_id, $courseId, $exercise_id, $lp_id = 0, $lp_item_id = 0, $session_id = 0) { - $course_code = Database::escape_string($course_code); + $courseId = intval($courseId); $student_id = intval($student_id); $exercise_id = intval($exercise_id); $session_id = intval($session_id); @@ -526,17 +526,16 @@ class Tracking if (!empty($lp_item_id)) $lp_id = intval($lp_item_id); - $tbl_stats_exercices = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES); $sql = "SELECT COUNT(ex.exe_id) as essais FROM $tbl_stats_exercices AS ex - WHERE ex.exe_cours_id = '$course_code' - AND ex.exe_exo_id = $exercise_id - AND status = '' - AND orig_lp_id = $lp_id - AND orig_lp_item_id = $lp_item_id - AND exe_user_id= $student_id - AND session_id = $session_id "; + WHERE ex.c_id = '$courseId' AND + ex.exe_exo_id = $exercise_id AND + status = '' AND + orig_lp_id = $lp_id AND + orig_lp_item_id = $lp_item_id AND + exe_user_id= $student_id AND + session_id = $session_id "; $rs = Database::query($sql); $row = Database::fetch_row($rs); @@ -547,13 +546,14 @@ class Tracking /** * Get count student's exercise progress + * * @param int user id - * @param string course code + * @param int course id * @param int session id */ - static function get_exercise_student_progress($exercise_list, $user_id, $course_code, $session_id) + static function get_exercise_student_progress($exercise_list, $user_id, $courseId, $session_id) { - $course_code = Database::escape_string($course_code); + $courseId = intval($courseId); $user_id = intval($user_id); $session_id = intval($session_id); @@ -567,9 +567,10 @@ class Tracking $exercise_list_imploded = implode("' ,'", $exercise_list); $sql = "SELECT COUNT(DISTINCT ex.exe_exo_id) FROM $tbl_stats_exercices AS ex - WHERE ex.exe_cours_id = '$course_code' AND + WHERE ex.c_id = '$courseId' AND ex.session_id = $session_id AND - ex.exe_user_id = $user_id AND ex.exe_exo_id IN ('$exercise_list_imploded') "; + ex.exe_user_id = $user_id AND + ex.exe_exo_id IN ('$exercise_list_imploded') "; $rs = Database::query($sql); $count = 0; @@ -581,13 +582,21 @@ class Tracking return $count; } - static function get_exercise_student_average_best_attempt($exercise_list, $user_id, $course_code, $session_id) + /** + * + * @param $exercise_list + * @param $user_id + * @param $courseId + * @param $session_id + * @return string + */ + static function get_exercise_student_average_best_attempt($exercise_list, $user_id, $courseId, $session_id) { $result = 0; if (!empty($exercise_list)) { foreach ($exercise_list as $exercise_data) { $exercise_id = $exercise_data['id']; - $best_attempt = get_best_attempt_exercise_results_per_user($user_id, $exercise_id, $course_code, $session_id); + $best_attempt = get_best_attempt_exercise_results_per_user($user_id, $exercise_id, $courseId, $session_id); if (!empty($best_attempt)) { $result += $best_attempt['exe_result'] / $best_attempt['exe_weighting']; @@ -912,7 +921,7 @@ class Tracking exe_user_id = $user_id AND orig_lp_item_id = $item_id AND orig_lp_item_view_id = $lp_item_view_id AND - exe_cours_id = '$course_code' AND + c_id = '$course_id' AND session_id = $session_id ORDER BY exe_date DESC LIMIT 1"; if ($debug) @@ -2434,7 +2443,7 @@ class Tracking $exercise_graph_list[] = $best_average; $all_exercise_graph_list[] = $best_average; - $user_result_data = get_best_attempt_by_user(api_get_user_id(), $exercise_data['id'], $course_data['code'], $my_session_id); + $user_result_data = get_best_attempt_by_user(api_get_user_id(), $exercise_data['id'], $course_data['real_id'], $my_session_id); $score = 0; if (!empty($user_result_data['exe_weighting']) && intval($user_result_data['exe_weighting']) != 0) { $score = intval($user_result_data['exe_result'] / $user_result_data['exe_weighting'] * 100); @@ -2519,14 +2528,16 @@ class Tracking $count_exercises = count($exercises); } + $courseId = $course_data['real_id']; + //Count of user results - //$done_exercises = get_count_exercises_attempted_by_course($course_data['code'], $my_session_id); + //$done_exercises = get_count_exercises_attempted_by_course($course_data['real_id'], $my_session_id); $done_exercises = null; $answered_exercises = 0; if (!empty($exercises)) { foreach ($exercises as $exercise_item) { - $attempts = count_exercise_attempts_by_user(api_get_user_id(), $exercise_item['id'], $course_data['code'], $my_session_id); + $attempts = count_exercise_attempts_by_user(api_get_user_id(), $exercise_item['id'], $courseId, $my_session_id); if ($attempts > 1) { $answered_exercises++; } @@ -2534,7 +2545,7 @@ class Tracking } //Average - $average = get_average_score_by_course($course_data['code'], $my_session_id); + $average = get_average_score_by_course($course_data['real_id'], $my_session_id); $all_exercises += $count_exercises; @@ -2599,6 +2610,7 @@ class Tracking foreach ($course_list as $course_data) { $course_code = $course_data['code']; + $courseId = $course_data['real_id']; $course_title = $course_data['title']; //All exercises in the course @todo change for a real count @@ -2610,10 +2622,10 @@ class Tracking //Count of user results //$done_exercises = get_best_exercise_results_by_course($course_code, $session_id_from_get); //From course exercises NOT from LP exercises!!! - //$done_exercises = get_count_exercises_attempted_by_course($course_code, $session_id_from_get); + //$done_exercises = get_count_exercises_attempted_by_course($courseId, $session_id_from_get); $answered_exercises = 0; foreach ($exercises as $exercise_item) { - $attempts = count_exercise_attempts_by_user(api_get_user_id(), $exercise_item['id'], $course_code, $session_id_from_get); + $attempts = count_exercise_attempts_by_user(api_get_user_id(), $exercise_item['id'], $courseId, $session_id_from_get); if ($attempts > 1) { $answered_exercises++; } @@ -2622,14 +2634,16 @@ class Tracking $unanswered_exercises = $count_exercises - $answered_exercises; //Average - $average = get_average_score_by_course($course_code, $session_id_from_get); - $my_average = get_average_score_by_course_by_user(api_get_user_id(), $course_code, $session_id_from_get); + $average = get_average_score_by_course($courseId, $session_id_from_get); + $my_average = get_average_score_by_course_by_user(api_get_user_id(), $courseId, $session_id_from_get); - $stats_array[$course_code] = array('exercises' => $count_exercises, + $stats_array[$course_code] = array( + 'exercises' => $count_exercises, 'unanswered_exercises_by_user' => $unanswered_exercises, 'done_exercises' => $done_exercises, 'average' => $average, - 'my_average' => $my_average); + 'my_average' => $my_average + ); $weighting = 0; $last_connection = Tracking :: get_last_connection_date_on_the_course($user_id, $course_code, $session_id_from_get); @@ -2751,7 +2765,7 @@ class Tracking $score = $weighting = $attempts = 0; //Getting count of attempts by user - $attempts = count_exercise_attempts_by_user(api_get_user_id(), $exercices['id'], $course_info['code'], $session_id); + $attempts = count_exercise_attempts_by_user(api_get_user_id(), $exercices['id'], $course_info['real_id'], $session_id); $html .= ''; $url = api_get_path(WEB_CODE_PATH)."exercice/overview.php?cidReq={$course_info['code']}&id_session=$session_id&exerciseId={$exercices['id']}"; @@ -2765,7 +2779,7 @@ class Tracking //Exercise configuration show results or show only score if ($exercices['results_disabled'] == 0 || $exercices['results_disabled'] == 2) { //For graphics - $best_exercise_stats = get_best_exercise_results_by_user($exercices['id'], $course_info['code'], $session_id); + $best_exercise_stats = get_best_exercise_results_by_user($exercices['id'], $course_info['real_id'], $session_id); $to_graph_exercise_result[$exercices['id']] = array('title' => $exercices['title'], 'data' => $best_exercise_stats); $latest_attempt_url = ''; @@ -2773,11 +2787,11 @@ class Tracking $graph = $normal_graph = null; //Getting best results - $best_score_data = get_best_attempt_in_course($exercices['id'], $course_info['code'], $session_id); + $best_score_data = get_best_attempt_in_course($exercices['id'], $course_info['real_id'], $session_id); $best_score = show_score($best_score_data['exe_result'], $best_score_data['exe_weighting']); if ($attempts > 0) { - $exercise_stat = get_best_attempt_by_user(api_get_user_id(), $exercices['id'], $course_info['code'], $session_id); + $exercise_stat = get_best_attempt_by_user(api_get_user_id(), $exercices['id'], $course_info['real_id'], $session_id); if (!empty($exercise_stat)) { //Always getting the BEST attempt @@ -2792,7 +2806,7 @@ class Tracking $my_score = $score / $weighting; } //@todo this function slows the page - $position = get_exercise_result_ranking($my_score, $exe_id, $exercices['id'], $course_info['code'], $session_id, $user_list); + $position = get_exercise_result_ranking($my_score, $exe_id, $exercices['id'], $course_info['real_id'], $session_id, $user_list); $graph = self::generate_exercise_result_thumbnail_graph($to_graph_exercise_result[$exercices['id']]); $normal_graph = self::generate_exercise_result_graph($to_graph_exercise_result[$exercices['id']]); @@ -2927,15 +2941,15 @@ class Tracking $graph->drawFilledRoundedRectangle(7, 7, $main_width - 7, $main_height - 7, 5, 240, 240, 240); $graph->drawRoundedRectangle(5, 5, $main_width - 5, $main_height - 5, 5, 230, 230, 230); - $graph->drawGraphArea(255, 255, 255, TRUE); + $graph->drawGraphArea(255, 255, 255, true); //SCALE_NORMAL, SCALE_START0, SCALE_ADDALLSTART0, SCALE_ADDALL - $graph->drawScale($data_set->GetData(), $data_set->GetDataDescription(), SCALE_NORMAL, 150, 150, 150, TRUE, $y_label_angle, 1, TRUE); - $graph->drawGrid(4, TRUE, 230, 230, 230, 70); + $graph->drawScale($data_set->GetData(), $data_set->GetDataDescription(), SCALE_NORMAL, 150, 150, 150, true, $y_label_angle, 1, true); + $graph->drawGrid(4, true, 230, 230, 230, 70); // Draw the 0 line $graph->setFontProperties(api_get_path(LIBRARY_PATH).'pchart/fonts/tahoma.ttf', 6); - $graph->drawTreshold(0, 143, 55, 72, TRUE, TRUE); + $graph->drawTreshold(0, 143, 55, 72, true, true); // Draw the cubic curve graph $graph->drawLineGraph($data_set->GetData(), $data_set->GetDataDescription()); @@ -3071,7 +3085,7 @@ class Tracking $thumbnail_graph->drawGraphArea(255, 255, 255); //SCALE_NORMAL, SCALE_START0, SCALE_ADDALLSTART0 - $thumbnail_graph->drawScale($data_set->GetData(), $data_set->GetDataDescription(), SCALE_ADDALLSTART0, 150, 150, 150, FALSE, 0, 1, TRUE); + $thumbnail_graph->drawScale($data_set->GetData(), $data_set->GetDataDescription(), SCALE_ADDALLSTART0, 150, 150, 150, false, 0, 1, true); $thumbnail_graph->drawOverlayBarGraph($data_set->GetData(), $data_set->GetDataDescription(), 100); @@ -3199,12 +3213,12 @@ class Tracking $main_graph->drawFilledRoundedRectangle(10, 10, $main_width - 10, $main_height - 10, 5, 240, 240, 240); $main_graph->drawRoundedRectangle(7, 7, $main_width - 7, $main_height - 7, 5, 230, 230, 230); - $main_graph->drawGraphArea(255, 255, 255, TRUE); + $main_graph->drawGraphArea(255, 255, 255, true); //SCALE_NORMAL, SCALE_START0, SCALE_ADDALLSTART0 - $main_graph->drawScale($data_set->GetData(), $data_set->GetDataDescription(), SCALE_ADDALLSTART0, 150, 150, 150, TRUE, 0, 1, TRUE); + $main_graph->drawScale($data_set->GetData(), $data_set->GetDataDescription(), SCALE_ADDALLSTART0, 150, 150, 150, true, 0, 1, true); - $main_graph->drawGrid(4, TRUE, 230, 230, 230, 50); + $main_graph->drawGrid(4, true, 230, 230, 230, 50); // Draw the 0 line $main_graph->setFontProperties(api_get_path(LIBRARY_PATH).'pchart/fonts/tahoma.ttf', 6); @@ -3792,10 +3806,10 @@ class TrackingCourseLog } $user['average_progress'] = $avg_student_progress.'%'; - $total_user_exercise = Tracking::get_exercise_student_progress($total_exercises, $user['user_id'], $course_code, $session_id); + $total_user_exercise = Tracking::get_exercise_student_progress($total_exercises, $user['user_id'], $course_info['real_id'], $session_id); $user['exercise_progress'] = $total_user_exercise; - $total_user_exercise = Tracking::get_exercise_student_average_best_attempt($total_exercises, $user['user_id'], $course_code, $session_id); + $total_user_exercise = Tracking::get_exercise_student_average_best_attempt($total_exercises, $user['user_id'], $course_info['real_id'], $session_id); $user['exercise_average_best_attempt'] = $total_user_exercise; @@ -3971,11 +3985,16 @@ class TrackingUserLog /** * Displays the exercise results for a specific user in a specific course. - * @todo remove globals + * @param $view + * @param $user_id + * @param $course_id */ function display_exercise_tracking_info($view, $user_id, $course_id) { - global $TABLECOURSE_EXERCICES, $TABLETRACK_EXERCICES, $dateTimeFormatLong; + $TABLECOURSE_EXERCICES = Database::get_main_table(TABLE_QUIZ_TEST); + $TABLETRACK_EXERCICES = Database::get_main_table(TABLE_STATISTIC_TRACK_E_EXERCICES); + $TBL_TRACK_HOTPOTATOES = Database::get_main_table(TABLE_STATISTIC_TRACK_E_HOTPOTATOES); + if (substr($view, 1, 1) == '1') { $new_view = substr_replace($view, '0', 1, 1); echo " @@ -3987,15 +4006,15 @@ class TrackingUserLog $sql = "SELECT ce.title, te.exe_result , te.exe_weighting, UNIX_TIMESTAMP(te.exe_date) FROM $TABLECOURSE_EXERCICES AS ce , $TABLETRACK_EXERCICES AS te - WHERE te.exe_cours_id = '".Database::escape_string($course_id)."' + WHERE te.c_id = '".Database::escape_string($course_id)."' AND te.exe_user_id = '".Database::escape_string($user_id)."' AND te.exe_exo_id = ce.id ORDER BY ce.title ASC, te.exe_date ASC"; $hpsql = "SELECT te.exe_name, te.exe_result , te.exe_weighting, UNIX_TIMESTAMP(te.exe_date) FROM $TBL_TRACK_HOTPOTATOES AS te - WHERE te.exe_user_id = '".Database::escape_string($user_id)."' AND te.exe_cours_id = '".Database::escape_string($course_id)."' - ORDER BY te.exe_cours_id ASC, te.exe_date ASC"; + WHERE te.exe_user_id = '".Database::escape_string($user_id)."' AND te.c_id = '".Database::escape_string($course_id)."' + ORDER BY te.c_id ASC, te.exe_date ASC"; $hpresults = getManyResultsXCol($hpsql, 4); @@ -4347,11 +4366,18 @@ class TrackingUserLogCSV /** * Displays the exercise results for a specific user in a specific course. - * @todo remove globals + * @param $view + * @param $user_id + * @param $course_id + * @return array */ function display_exercise_tracking_info($view, $user_id, $course_id) { - global $TABLECOURSE_EXERCICES, $TABLETRACK_EXERCICES, $TABLETRACK_HOTPOTATOES, $dateTimeFormatLong; + $TABLECOURSE_EXERCICES = Database::get_main_table(TABLE_QUIZ_TEST); + $TABLETRACK_HOTPOTATOES = Database::get_main_table(TABLE_STATISTIC_TRACK_E_HOTPOTATOES); + $TABLETRACK_EXERCICES = Database::get_main_table(TABLE_STATISTIC_TRACK_E_EXERCICES); + + if (substr($view, 1, 1) == '1') { $new_view = substr_replace($view, '0', 1, 1); @@ -4360,15 +4386,15 @@ class TrackingUserLogCSV $sql = "SELECT ce.title, te.exe_result , te.exe_weighting, UNIX_TIMESTAMP(te.exe_date) FROM $TABLECOURSE_EXERCICES AS ce , $TABLETRACK_EXERCICES AS te - WHERE te.exe_cours_id = '$course_id' + WHERE te.c_id = '$course_id' AND te.exe_user_id = '$user_id' AND te.exe_exo_id = ce.id ORDER BY ce.title ASC, te.exe_date ASC"; $hpsql = "SELECT te.exe_name, te.exe_result , te.exe_weighting, UNIX_TIMESTAMP(te.exe_date) FROM $TABLETRACK_HOTPOTATOES AS te - WHERE te.exe_user_id = '$user_id' AND te.exe_cours_id = '$course_id' - ORDER BY te.exe_cours_id ASC, te.exe_date ASC"; + WHERE te.exe_user_id = '$user_id' AND te.c_id = '$course_id' + ORDER BY te.c_id ASC, te.exe_date ASC"; $hpresults = getManyResultsXCol($hpsql, 4); diff --git a/main/install/1.10.0/db_main.sql b/main/install/1.10.0/db_main.sql index db61f224c8..c43cba4c92 100644 --- a/main/install/1.10.0/db_main.sql +++ b/main/install/1.10.0/db_main.sql @@ -3188,13 +3188,11 @@ CREATE TABLE track_e_exercices ( exe_id int NOT NULL auto_increment, exe_user_id int unsigned default NULL, exe_date datetime NOT NULL default '0000-00-00 00:00:00', - exe_cours_id varchar(40) NOT NULL default '', exe_exo_id int unsigned NOT NULL default 0, exe_result float(6,2) NOT NULL default 0, exe_weighting float(6,2) NOT NULL default 0, - PRIMARY KEY (exe_id), - KEY exe_user_id (exe_user_id), - KEY exe_cours_id (exe_cours_id) + c_id INT unsigned NOT NULL default 0, + PRIMARY KEY (exe_id) ); ALTER TABLE track_e_exercices ADD status varchar(20) NOT NULL default ''; @@ -3219,12 +3217,13 @@ CREATE TABLE track_e_attempt ( answer text NOT NULL, teacher_comment text NOT NULL, marks float(6,2) NOT NULL default 0, - course_code varchar(40) NOT NULL default '', position int default 0, tms datetime NOT NULL default '0000-00-00 00:00:00', session_id INT NOT NULL DEFAULT 0, + c_id INT unsigned NOT NULL default 0, filename VARCHAR(255) DEFAULT NULL ); + ALTER TABLE track_e_attempt ADD INDEX (exe_id); ALTER TABLE track_e_attempt ADD INDEX (user_id); ALTER TABLE track_e_attempt ADD INDEX (question_id); @@ -3251,11 +3250,9 @@ CREATE TABLE track_e_hotpotatoes ( exe_name VARCHAR( 255 ) NOT NULL , exe_user_id int unsigned DEFAULT NULL , exe_date DATETIME DEFAULT '0000-00-00 00:00:00' NOT NULL , - exe_cours_id varchar(40) NOT NULL , + c_id INT unsigned NOT NULL default 0, exe_result smallint default 0 NOT NULL , - exe_weighting smallint default 0 NOT NULL, - KEY exe_user_id (exe_user_id), - KEY exe_cours_id (exe_cours_id) + exe_weighting smallint default 0 NOT NULL ); DROP TABLE IF EXISTS track_e_links; diff --git a/main/install/1.10.0/migrate-db-1.9.0-1.10.0-pre.sql b/main/install/1.10.0/migrate-db-1.9.0-1.10.0-pre.sql index d1e1120975..74deda44b6 100755 --- a/main/install/1.10.0/migrate-db-1.9.0-1.10.0-pre.sql +++ b/main/install/1.10.0/migrate-db-1.9.0-1.10.0-pre.sql @@ -104,10 +104,8 @@ INSERT INTO branch_transaction_status VALUES (1, 'To be executed'), (2, 'Execute CREATE TABLE branch_transaction (id bigint unsigned not null AUTO_INCREMENT, transaction_id bigint unsigned, branch_id int unsigned not null default 0, action char(20), item_id char(36), orig_id char(36), dest_id char(36), info char(20), status_id tinyint not null default 0, time_insert datetime NOT NULL DEFAULT '0000-00-00 00:00:00', time_update datetime NOT NULL DEFAULT '0000-00-00 00:00:00', message VARCHAR(255) default '' , PRIMARY KEY (id, transaction_id, branch_id)); - ALTER TABLE settings_current ADD INDEX idx_settings_current_au_cat (access_url, category(5)); - INSERT INTO settings_current (variable, subkey, type, category, selected_value, title, comment, scope, subkeytext, access_url_changeable) VALUES ('session_page_enabled', NULL, 'radio', 'Session', 'true', 'SessionPageEnabledTitle', 'SessionPageEnabledComment', NULL, NULL, 1); INSERT INTO settings_options (variable, value, display_text) VALUES ('session_page_enabled', 'true', 'Yes'); INSERT INTO settings_options (variable, value, display_text) VALUES ('session_page_enabled', 'false', 'No'); @@ -193,5 +191,9 @@ ALTER TABLE usergroup_rel_usergroup ADD INDEX ( relation_type ); ALTER TABLE announcement_rel_group DROP PRIMARY KEY; ALTER TABLE announcement_rel_group ADD COLUMN id INT unsigned NOT NULL auto_increment PRIMARY KEY; +ALTER TABLE track_e_hotpotatoes ADD COLUMN c_id int unsigned NOT NULL default 0; +ALTER TABLE track_e_exercices ADD COLUMN c_id int unsigned NOT NULL default 0; +ALTER TABLE track_e_attempt ADD COLUMN c_id int unsigned NOT NULL default 0; + -- Do not move this UPDATE settings_current SET selected_value = '1.10.0.862202a' WHERE variable = 'chamilo_database_version'; \ No newline at end of file diff --git a/main/mySpace/myStudents.php b/main/mySpace/myStudents.php index 3e977d9be9..25b5575a18 100644 --- a/main/mySpace/myStudents.php +++ b/main/mySpace/myStudents.php @@ -39,7 +39,7 @@ function show_image(image,width,height) { } '; -$export_csv = isset ($_GET['export']) && $_GET['export'] == 'csv' ? true : false; +$export_csv = isset($_GET['export']) && $_GET['export'] == 'csv' ? true : false; if ($export_csv) { ob_start(); @@ -74,9 +74,6 @@ if (isset($_GET['details'])) { } else if (!empty ($_GET['origin']) && $_GET['origin'] == 'tracking_course') { $course_info = CourseManager :: get_course_information($get_course_code); - if (empty ($cidReq)) { - //$interbreadcrumb[] = array ("url" => api_get_path(WEB_COURSE_PATH).$course_info['directory'], 'name' => $course_info['title']); - } $interbreadcrumb[] = array ( "url" => "../tracking/courseLog.php?cidReq=".$get_course_code.'&id_session=' . (empty ($_SESSION['id_session']) ? '' : $_SESSION['id_session']), "name" => get_lang("Tracking") @@ -554,7 +551,6 @@ if (!empty($info_course['title'])) { $table_title .= ($info_course ? Display::return_icon('course.png', get_lang('Course'), array(), ICON_SIZE_SMALL).' '.$info_course['title'].' ':''); } - echo Display::page_subheader($table_title); if (empty($_GET['details'])) { @@ -854,7 +850,7 @@ if (empty($_GET['details'])) { WHERE quiz.c_id = ".$info_course['real_id']." AND active='1' AND (quiz.session_id = $session_id OR quiz.session_id = 0) - ORDER BY quiz.title ASC "; + ORDER BY quiz.title ASC "; $result_exercices = Database::query($sql_exercices); $i = 0; @@ -862,7 +858,7 @@ if (empty($_GET['details'])) { while ($exercices = Database :: fetch_array($result_exercices)) { $exercise_id = intval($exercices['id']); - $count_attempts = Tracking::count_student_exercise_attempts($student_id, $course_code, $exercise_id, 0, 0, $session_id); + $count_attempts = Tracking::count_student_exercise_attempts($student_id, $info_course['real_id'], $exercise_id, 0, 0, $session_id); $score_percentage = Tracking::get_avg_student_exercise_score($student_id, $course_code, $exercise_id, $session_id); $csv_content[] = array ( @@ -877,7 +873,6 @@ if (empty($_GET['details'])) { $css_class = 'row_even'; echo ''.$exercices['title'].''; - echo ''; if ($count_attempts > 0) { @@ -894,7 +889,7 @@ if (empty($_GET['details'])) { $sql_last_attempt = 'SELECT exe_id FROM ' . $tbl_stats_exercices . ' WHERE exe_exo_id ="'.$exercise_id.'" AND exe_user_id ="'.$student_id.'" AND - exe_cours_id ="'.$course_code.'" AND + c_id ="'.$info_course['real_id'].'" AND session_id ="'.$session_id.'" AND status = "" AND orig_lp_id = 0 AND @@ -908,7 +903,6 @@ if (empty($_GET['details'])) { echo ' '; } else { echo Display::return_icon('quiz_na.png', get_lang('Exercise')); - //echo ' '; } } } @@ -1051,5 +1045,4 @@ if ($export_csv) { Export :: export_table_csv($csv_content, 'reporting_student'); exit; } -/* FOOTER */ -Display :: display_footer(); +Display :: display_footer(); \ No newline at end of file diff --git a/main/mySpace/myspace.lib.php b/main/mySpace/myspace.lib.php index eb957d74aa..1956e8e52a 100644 --- a/main/mySpace/myspace.lib.php +++ b/main/mySpace/myspace.lib.php @@ -161,7 +161,7 @@ class MySpace { */ function course_info_tracking_filter($user_id, $url_params, $row) { // the table header - $return .= ''; + $return = '
'; /*$return .= ' '; $return .= ' '; $return .= ' '; @@ -181,19 +181,25 @@ class MySpace { // database table definition $tbl_course_user = Database :: get_main_table(TABLE_MAIN_COURSE_USER); - // getting all the courses of the user - $sql = "SELECT * FROM $tbl_course_user WHERE user_id = '".Database::escape_string($user_id)."' AND relation_type<>".COURSE_RELATION_TYPE_RRHH." "; + // Getting all the courses of the user + $sql = "SELECT c_id FROM $tbl_course_user + WHERE user_id = '".Database::escape_string($user_id)."' AND relation_type<>".COURSE_RELATION_TYPE_RRHH." "; $result = Database::query($sql); - while ($row = Database::fetch_row($result)) { + while ($row = Database::fetch_array($result, 'ASSOC')) { + $courseInfo = api_get_course_info_by_id($row['c_id']); + + $courseCode = $courseInfo['code']; + $courseId = $courseInfo['real_id']; + $return .= ''; // course code - $return .= ' '; + $return .= ' '; // time spent in the course - $return .= ' '; + $return .= ' '; // student progress in course - $return .= ' '; + $return .= ' '; // student score - $avg_score = Tracking :: get_avg_student_score($user_id, $row[0]); + $avg_score = Tracking :: get_avg_student_score($user_id, $courseCode); if (is_numeric($avg_score)) { $avg_score = round($avg_score,2); } else { @@ -202,21 +208,21 @@ class MySpace { $return .= ' '; // student tes score - //$return .= ' '; + //$return .= ' '; // student messages - $return .= ' '; + $return .= ' '; // student assignments - $return .= ' '; + $return .= ' '; // student exercises results (obtained score, maximum score, number of exercises answered, score percentage) - $exercises_results = MySpace::exercises_results($user_id, $row[0]); + $exercises_results = MySpace::exercises_results($user_id, $courseId); $return .= ' '; //$return .= ' '; $return .= ' '; //$return .= ' '; // first connection - //$return .= ' '; + //$return .= ' '; // last connection - $return .= ' '; + $return .= ' '; $return .= ''; } $return .= '
'.get_lang('Course').''.get_lang('AvgTimeSpentInTheCourse').'
'.Text::cut($row[0], 20, true).''.Text::cut($courseInfo['code'], 20, true).'
'.api_time_to_hms(Tracking :: get_time_spent_on_the_course($user_id, $row[0])).'
'.api_time_to_hms(Tracking :: get_time_spent_on_the_course($user_id, $courseCode)).'
'.round(Tracking :: get_avg_student_progress($user_id, $row[0]), 2).'
'.round(Tracking :: get_avg_student_progress($user_id, $courseCode), 2).'
'.$avg_score.'
'.round(Tracking :: get_avg_student_exercise_score ($user_id, $row[0]),2).'%
'.round(Tracking :: get_avg_student_exercise_score ($user_id, $courseCode),2).'%
'.Tracking :: count_student_messages($user_id, $row[0]).'
'.Tracking :: count_student_messages($user_id, $courseCode).'
'.Tracking :: count_student_assignments($user_id, $row[0]).'
'.Tracking :: count_student_assignments($user_id, $courseCode).'
'.(is_null($exercises_results['percentage']) ? '' : $exercises_results['score_obtained'].'/'.$exercises_results['score_possible'].' ( '.$exercises_results['percentage'].'% )').'
'.$exercises_results['score_possible'].'
'.$exercises_results['questions_answered'].'
'.$exercises_results['percentage'].'%
'.Tracking :: get_first_connection_date_on_the_course ($user_id, $row[0]).''.Tracking :: get_first_connection_date_on_the_course ($user_id, $courseCode).'
'.Tracking :: get_last_connection_date_on_the_course ($user_id, $row[0]).'
'.Tracking :: get_last_connection_date_on_the_course ($user_id, $courseCode).'
'; @@ -232,7 +238,7 @@ class MySpace { function display_tracking_user_overview() { MySpace::display_user_overview_export_options(); - $t_head .= ' '; + $t_head = '
'; //$t_head .= ' '; $t_head .= ''; $t_head .= ' '; @@ -433,17 +439,19 @@ class MySpace { * @return string html code */ function course_tracking_filter($course_code, $url_params, $row) { - $course_code = $row[0]; + $course_code = $row['code']; + $courseId = $row['real_id']; // the table header - $return .= '
'.get_lang('CourseInformation').'
'.get_lang('Course').'
'; + $return = '
'; // database table definition $tbl_course_rel_user = Database :: get_main_table(TABLE_MAIN_COURSE_USER); - $tbl_course = Database :: get_main_table(TABLE_MAIN_COURSE); $tbl_user = Database :: get_main_table(TABLE_MAIN_USER); // getting all the courses of the user - $sql = "SELECT * FROM $tbl_user AS u INNER JOIN $tbl_course_rel_user AS cu ON cu.user_id = u.user_id WHERE cu.course_code = '".$course_code."' AND ISNULL(cu.role);"; + $sql = "SELECT * FROM $tbl_user AS u + INNER JOIN $tbl_course_rel_user AS cu ON cu.user_id = u.user_id + WHERE cu.course_code = '".$course_code."' AND ISNULL(cu.role);"; $result = Database::query($sql); $time_spent = 0; $progress = 0; @@ -480,7 +488,7 @@ class MySpace { } } - $exercise_results_tmp = MySpace::exercises_results($row->user_id, $course_code); + $exercise_results_tmp = MySpace::exercises_results($row->user_id, $row->c_id); $total_score_obtained += $exercise_results_tmp['score_obtained']; $total_score_possible += $exercise_results_tmp['score_possible']; $total_questions_answered += $exercise_results_tmp['questions_answered']; @@ -587,7 +595,8 @@ class MySpace { $csv_row[] = $course_title; // getting all the courses of the session - $sql = "SELECT * FROM $tbl_user AS u INNER JOIN $tbl_course_rel_user AS cu ON cu.user_id = u.user_id WHERE cu.course_code = '".$course_code."' AND ISNULL(cu.role);"; + $sql = "SELECT * FROM $tbl_user AS u INNER JOIN $tbl_course_rel_user AS cu ON cu.user_id = u.user_id + WHERE cu.course_code = '".$course_code."' AND ISNULL(cu.role);"; $result = Database::query($sql); $time_spent = 0; $progress = 0; @@ -624,7 +633,7 @@ class MySpace { } } - $exercise_results_tmp = MySpace::exercises_results($row->user_id, $course_code); + $exercise_results_tmp = MySpace::exercises_results($row->user_id, $row->c_id); $total_score_obtained += $exercise_results_tmp['score_obtained']; $total_score_possible += $exercise_results_tmp['score_possible']; $total_questions_answered += $exercise_results_tmp['questions_answered']; @@ -766,9 +775,9 @@ class MySpace { * @return string html code */ function session_tracking_filter($session_id, $url_params, $row) { - $session_id = $row[0]; + $session_id = $row['code']; // the table header - $return .= '
'; + $return = '
'; /*$return .= ' '; $return .= ' '; $return .= ' '; @@ -785,21 +794,23 @@ class MySpace { $return .= ' '; $return .= ' ';*/ - // database table definition + // Database table definition $tbl_session_rel_course = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE); $tbl_course = Database :: get_main_table(TABLE_MAIN_COURSE); $tbl_session_rel_course_rel_user = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE_USER); $tbl_user = Database :: get_main_table(TABLE_MAIN_USER); // getting all the courses of the user - $sql = "SELECT * FROM $tbl_course AS c INNER JOIN $tbl_session_rel_course AS sc ON sc.course_code = c.code WHERE sc.id_session = '".$session_id."';"; + $sql = "SELECT c.title, c.code, c.id FROM $tbl_course AS c INNER JOIN $tbl_session_rel_course AS sc ON sc.course_code = c.code + WHERE sc.id_session = '".$session_id."';"; $result = Database::query($sql); while ($row = Database::fetch_object($result)) { $return .= ''; // course code - $return .= ' '; + $return .= ''; // get the users in the course - $sql = "SELECT user_id FROM $tbl_user AS u INNER JOIN $tbl_session_rel_course_rel_user AS scu ON u.user_id = scu.id_user WHERE scu.id_session = '".$session_id."' AND scu.course_code = '".$row->code."';"; + $sql = "SELECT user_id FROM $tbl_user AS u INNER JOIN $tbl_session_rel_course_rel_user AS scu ON u.user_id = scu.id_user + WHERE scu.id_session = '".$session_id."' AND scu.course_code = '".$row->code."';"; $result_users = Database::query($sql); $time_spent = 0; $progress = 0; @@ -812,14 +823,14 @@ class MySpace { $total_score_obtained = 0; $total_score_possible = 0; $total_questions_answered = 0; - while($row_user = Database::fetch_object($result_users)) { + while ($row_user = Database::fetch_object($result_users)) { // get time spent in the course and session $time_spent += Tracking::get_time_spent_on_the_course($row_user->user_id, $row->code, $session_id); $progress_tmp = Tracking::get_avg_student_progress($row_user->user_id, $row->code, array(), $session_id, true); $progress += $progress_tmp[0]; $nb_progress_lp += $progress_tmp[1]; $score_tmp = Tracking :: get_avg_student_score($row_user->user_id, $row->code, array(), $session_id, true); - if(is_array($score_tmp)) { + if (is_array($score_tmp)) { $score += $score_tmp[0]; $nb_score_lp += $score_tmp[1]; } @@ -827,45 +838,51 @@ class MySpace { $nb_assignments += Tracking::count_student_assignments($row_user->user_id, $row->code, $session_id); $last_login_date_tmp = Tracking :: get_last_connection_date_on_the_course ($row_user->user_id, $row->code, $session_id, false); - if($last_login_date_tmp != false && $last_login_date == false) { // TODO: To be cleaned. + if ($last_login_date_tmp != false && $last_login_date == false) { // TODO: To be cleaned. $last_login_date = $last_login_date_tmp; } else if($last_login_date_tmp != false && $last_login_date != false) { // TODO: Repeated previous condition! To be cleaned. // Find the max and assign it to first_login_date - if(strtotime($last_login_date_tmp) > strtotime($last_login_date)) { + if (strtotime($last_login_date_tmp) > strtotime($last_login_date)) { $last_login_date = $last_login_date_tmp; } } - $exercise_results_tmp = MySpace::exercises_results($row_user->user_id, $row->code, $session_id); + $exercise_results_tmp = MySpace::exercises_results($row_user->user_id, $row->id, $session_id); $total_score_obtained += $exercise_results_tmp['score_obtained']; $total_score_possible += $exercise_results_tmp['score_possible']; $total_questions_answered += $exercise_results_tmp['questions_answered']; } - if($nb_progress_lp > 0) { + + if ($nb_progress_lp > 0) { $avg_progress = round($progress / $nb_progress_lp, 2); } else { $avg_progress = 0; } + if($nb_score_lp > 0) { $avg_score = round($score / $nb_score_lp, 2); } else { - $avg_score = '-'; + $avg_score = '-'; } + if($last_login_date) { $last_login_date = api_convert_and_format_date($last_login_date, DATE_FORMAT_SHORT, date_default_timezone_get()); } else { $last_login_date = '-'; } + if($total_score_possible > 0) { $total_score_percentage = round($total_score_obtained / $total_score_possible * 100, 2); } else { $total_score_percentage = 0; } + if($total_score_percentage > 0) { $total_score = $total_score_obtained.'/'.$total_score_possible.' ('.$total_score_percentage.' %)'; } else { $total_score = '-'; } + // time spent in the course $return .= ' '; // student progress in course @@ -942,14 +959,16 @@ class MySpace { $session_title = $session[1]; // getting all the courses of the session - $sql = "SELECT * FROM $tbl_course AS c INNER JOIN $tbl_session_rel_course AS sc ON sc.course_code = c.code WHERE sc.id_session = '".$session_id."';"; + $sql = "SELECT c.title, c.code, c.idFROM $tbl_course AS c INNER JOIN $tbl_session_rel_course AS sc ON sc.course_code = c.code + WHERE sc.id_session = '".$session_id."';"; $result = Database::query($sql); while ($row = Database::fetch_object($result)) { $csv_row = array(); $csv_row[] = $session_title; $csv_row[] = $row->title; // get the users in the course - $sql = "SELECT user_id FROM $tbl_user AS u INNER JOIN $tbl_session_rel_course_rel_user AS scu ON u.user_id = scu.id_user WHERE scu.id_session = '".$session_id."' AND scu.course_code = '".$row->code."';"; + $sql = "SELECT user_id FROM $tbl_user AS u INNER JOIN $tbl_session_rel_course_rel_user AS scu ON u.user_id = scu.id_user + WHERE scu.id_session = '".$session_id."' AND scu.course_code = '".$row->code."';"; $result_users = Database::query($sql); $time_spent = 0; $progress = 0; @@ -962,7 +981,7 @@ class MySpace { $total_score_obtained = 0; $total_score_possible = 0; $total_questions_answered = 0; - while($row_user = Database::fetch_object($result_users)) { + while ($row_user = Database::fetch_object($result_users)) { // get time spent in the course and session $time_spent += Tracking::get_time_spent_on_the_course($row_user->user_id, $row->code, $session_id); $progress_tmp = Tracking::get_avg_student_progress($row_user->user_id, $row->code, array(), $session_id, true); @@ -977,7 +996,7 @@ class MySpace { $nb_assignments += Tracking::count_student_assignments($row_user->user_id, $row->code, $session_id); $last_login_date_tmp = Tracking :: get_last_connection_date_on_the_course ($row_user->user_id, $row->code, $session_id, false); - if($last_login_date_tmp != false && $last_login_date == false) { // TODO: To be cleaned. + if ($last_login_date_tmp != false && $last_login_date == false) { // TODO: To be cleaned. $last_login_date = $last_login_date_tmp; } else if($last_login_date_tmp != false && $last_login_date == false) { // TODO: Repeated previous condition. To be cleaned. // Find the max and assign it to first_login_date @@ -986,36 +1005,42 @@ class MySpace { } } - $exercise_results_tmp = MySpace::exercises_results($row_user->user_id, $row->code, $session_id); + $exercise_results_tmp = MySpace::exercises_results($row_user->user_id, $row->id, $session_id); $total_score_obtained += $exercise_results_tmp['score_obtained']; $total_score_possible += $exercise_results_tmp['score_possible']; $total_questions_answered += $exercise_results_tmp['questions_answered']; } + if($nb_progress_lp > 0) { $avg_progress = round($progress / $nb_progress_lp, 2); } else { $avg_progress = 0; } + if($nb_score_lp > 0) { $avg_score = round($score / $nb_score_lp, 2); } else { $avg_score = '-'; } + if($last_login_date) { $last_login_date = api_convert_and_format_date($last_login_date, DATE_FORMAT_SHORT, date_default_timezone_get()); } else { $last_login_date = '-'; } + if($total_score_possible > 0) { $total_score_percentage = round($total_score_obtained / $total_score_possible * 100, 2); } else { $total_score_percentage = 0; } + if($total_score_percentage > 0) { $total_score = $total_score_obtained.'/'.$total_score_possible.' ('.$total_score_percentage.' %)'; } else { $total_score = '-'; } + // time spent in the course $csv_row[] = api_time_to_hms($time_spent); // student progress in course @@ -1054,15 +1079,15 @@ class MySpace { * @version Dokeos 1.8.6 * @since November 2008 */ - function exercises_results($user_id, $course_code, $session_id = false) { - $questions_answered = 0; + function exercises_results($user_id, $courseId, $session_id = false) { $sql = 'SELECT exe_result , exe_weighting FROM '.Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES)." - WHERE exe_cours_id = '".Database::escape_string($course_code)."' + WHERE c_id = '".Database::escape_string($courseId)."' AND exe_user_id = '".Database::escape_string($user_id)."'"; - if($session_id !== false) { + if ($session_id !== false) { $sql .= " AND session_id = '".$session_id."' "; } + $result = Database::query($sql); $score_obtained = 0; $score_possible = 0; @@ -1079,7 +1104,12 @@ class MySpace { $percentage = null; } - return array('score_obtained' => $score_obtained, 'score_possible' => $score_possible, 'questions_answered' => $questions_answered, 'percentage' => $percentage); + return array( + 'score_obtained' => $score_obtained, + 'score_possible' => $score_possible, + 'questions_answered' => $questions_answered, + 'percentage' => $percentage + ); } /** @@ -1160,9 +1190,9 @@ class MySpace { // the other lines (the data) foreach ($user_data as $key => $user) { // getting all the courses of the user - $sql = "SELECT * FROM $tbl_course_user WHERE user_id = '".Database::escape_string($user[4])."' AND relation_type<>".COURSE_RELATION_TYPE_RRHH." "; + $sql = "SELECT code, id FROM $tbl_course_user WHERE user_id = '".Database::escape_string($user[4])."' AND relation_type<>".COURSE_RELATION_TYPE_RRHH." "; $result = Database::query($sql); - while ($row = Database::fetch_row($result)) { + while ($row = Database::fetch_array($result, 'ASSOC')) { $csv_row = array(); // user official code $csv_row[] = $user[0]; @@ -1173,7 +1203,7 @@ class MySpace { // user login name $csv_row[] = $user[3]; // course code - $csv_row[] = $row[0]; + $csv_row[] = $row['code']; // the additional defined user fields $extra_fields = MySpace::get_user_overview_export_extra_fields($user[4]); @@ -1183,27 +1213,27 @@ class MySpace { } } // time spent in the course - $csv_row[] = api_time_to_hms(Tracking :: get_time_spent_on_the_course ($user[4], $row[0])); + $csv_row[] = api_time_to_hms(Tracking :: get_time_spent_on_the_course ($user[4], $row['code'])); // student progress in course - $csv_row[] = round(Tracking :: get_avg_student_progress ($user[4], $row[0]), 2); + $csv_row[] = round(Tracking :: get_avg_student_progress ($user[4], $row['code']), 2); // student score - $csv_row[] = round(Tracking :: get_avg_student_score ($user[4], $row[0]), 2); + $csv_row[] = round(Tracking :: get_avg_student_score ($user[4], $row['code']), 2); // student tes score - $csv_row[] = round(Tracking :: get_avg_student_exercise_score ($user[4], $row[0]), 2); + $csv_row[] = round(Tracking :: get_avg_student_exercise_score ($user[4], $row['code']), 2); // student messages - $csv_row[] = Tracking :: count_student_messages ($user[4], $row[0]); + $csv_row[] = Tracking :: count_student_messages ($user[4], $row['code']); // student assignments - $csv_row[] = Tracking :: count_student_assignments ($user[4], $row[0]); + $csv_row[] = Tracking :: count_student_assignments ($user[4], $row['code']); // student exercises results - $exercises_results = MySpace::exercises_results($user[4], $row[0]); + $exercises_results = MySpace::exercises_results($user[4], $row['id']); $csv_row[] = $exercises_results['score_obtained']; $csv_row[] = $exercises_results['score_possible']; $csv_row[] = $exercises_results['questions_answered']; $csv_row[] = $exercises_results['percentage']; // first connection - $csv_row[] = Tracking :: get_first_connection_date_on_the_course ($user[4], $row[0]); + $csv_row[] = Tracking :: get_first_connection_date_on_the_course ($user[4], $row['code']); // last connection - $csv_row[] = strip_tags(Tracking :: get_last_connection_date_on_the_course ($user[4], $row[0])); + $csv_row[] = strip_tags(Tracking :: get_last_connection_date_on_the_course ($user[4], $row['code'])); $csv_content[] = $csv_row; } @@ -1385,11 +1415,10 @@ class MySpace { * @since November 2008 */ function get_user_overview_export_extra_fields($user_id) { - // include the user manager - $extra_data = UserManager::get_extra_user_data($user_id, true); return $extra_data; } + /** * Checks if a username exist in the DB otherwise it create a "double" * i.e. if we look into for jmontoya but the user's name already exist we create the user jmontoya2 diff --git a/main/mySpace/progression.php b/main/mySpace/progression.php index 140b48751c..e1bdceff05 100644 --- a/main/mySpace/progression.php +++ b/main/mySpace/progression.php @@ -35,7 +35,7 @@ $tbl_track_exercice = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_EX /* MAIN CODE */ -$sql_course = "SELECT title,code FROM $tbl_course as course ORDER BY title ASC"; +$sql_course = "SELECT title, code, id FROM $tbl_course as course ORDER BY title ASC"; $result_course = Database::query($sql_course); if (Database::num_rows($result_course) > 0) { @@ -49,7 +49,7 @@ if (Database::num_rows($result_course) > 0) { // TODO: This query is to be checked, there are no HotPotatoes tests results. $sql_moy_test = "SELECT exe_result,exe_weighting FROM $tbl_track_exercice - WHERE exe_cours_id = '".$a_course['code']."'"; + WHERE c_id = '".$a_course['id']."'"; $result_moy_test = Database::query($sql_moy_test); $result = 0; $weighting = 0; diff --git a/main/mySpace/reussite.php b/main/mySpace/reussite.php index a479d75801..5265f6edbd 100644 --- a/main/mySpace/reussite.php +++ b/main/mySpace/reussite.php @@ -46,7 +46,7 @@ if (!empty($_GET['session'])) { if (Database::num_rows($result_session) > 0) { echo '
'.get_lang('Course').''.get_lang('AvgTimeSpentInTheCourse').''.get_lang('LatestLogin').'
'.$row->title.''.$row->title.'
'.api_time_to_hms($time_spent).'
'; while ($session = Database::fetch_array($result_session)) { - $sql_course = "SELECT title,code + $sql_course = "SELECT title, code, course.id FROM $tbl_course as course INNER JOIN $tbl_session_course AS rel_course ON course.code = rel_course.course_code @@ -57,9 +57,8 @@ if (!empty($_GET['session'])) { $total_result = 0; $total_weighting = 0; while ($course = Database::fetch_array($result_course)) { - $sql_moy_test = "SELECT exe_result,exe_weighting - FROM $tbl_track_exercice - WHERE exe_cours_id = '".$course['code']."'"; + $sql_moy_test = "SELECT exe_result,exe_weighting FROM $tbl_track_exercice + WHERE c_id = '".$course['id']."'"; $result_moy_test = Database::query($sql_moy_test); $result = 0; $weighting = 0; @@ -83,12 +82,8 @@ if (!empty($_GET['session'])) { echo get_lang('NoSession'); } } else { - $sql_course = "SELECT title,code - FROM $tbl_course as course - ORDER BY title ASC"; - + $sql_course = "SELECT title, code, id FROM $tbl_course as course ORDER BY title ASC"; $result_course = Database::query($sql_course); - echo "".get_lang('MoySession').""; echo "

"; if (Database::num_rows($result_course) > 0) { @@ -96,7 +91,7 @@ if (!empty($_GET['session'])) { while ($course= Database::fetch_array($result_course)) { $sql_moy_test = "SELECT exe_result,exe_weighting FROM $tbl_track_exercice - WHERE exe_cours_id = '".$course['code']."'"; + WHERE c_id = '".$course['id']."'"; $result_moy_test = Database::query($sql_moy_test); $result = 0; $weighting = 0; diff --git a/main/newscorm/learnpath.class.php b/main/newscorm/learnpath.class.php index 8a5020875c..b208ae4021 100644 --- a/main/newscorm/learnpath.class.php +++ b/main/newscorm/learnpath.class.php @@ -3236,10 +3236,10 @@ class learnpath $user_id = api_get_user_id(); $sql = "SELECT path FROM $tbl_track_e_exercises, $tbl_lp_item - WHERE c_id = $course_id AND + WHERE c_id = $courseId AND path = '" . $item['path'] . "' AND exe_user_id = '$user_id' AND - exe_cours_id = '$course_code' AND + c_id = '$course_code' AND path = exe_exo_id AND status <> 'incomplete'"; $result = Database::query($sql); diff --git a/main/newscorm/lp_stats.php b/main/newscorm/lp_stats.php index 93839237e5..65b29a46d5 100644 --- a/main/newscorm/lp_stats.php +++ b/main/newscorm/lp_stats.php @@ -154,7 +154,7 @@ if (isset($_GET['lp_id']) && isset($_GET['lp_item_id'])) { exe_user_id="' . api_get_user_id() . '" AND orig_lp_id = "' . (int) $clean_lp_id . '" AND orig_lp_item_id = "' . (int) $clean_lp_item_id . '" AND - exe_cours_id="' . $clean_course_code . '" AND + c_id="' . $course_id . '" AND session_id = ' . $session_id . ' ORDER BY exe_date'; } else { @@ -164,7 +164,7 @@ if (isset($_GET['lp_id']) && isset($_GET['lp_item_id'])) { exe_user_id="' . $student_id . '" AND orig_lp_id = "' . (int) $clean_lp_id . '" AND orig_lp_item_id = "' . (int) $clean_lp_item_id . '" AND - exe_cours_id="' . $clean_course_code . '" AND + c_id = "' . $course_id . '" AND session_id = ' . $session_id . ' ORDER BY exe_date'; } @@ -516,7 +516,7 @@ if (is_array($list) && count($list) > 0) { exe_user_id="' . api_get_user_id() . '" AND orig_lp_id = "' . $lp_id . '" AND orig_lp_item_id = "' . $row['myid'] . '" AND - exe_cours_id="' . $course_code . '" AND + c_id ="' . $course_id . '" AND status <> "incomplete" AND session_id = ' . $session_id . ' ORDER BY exe_date DESC limit 1'; @@ -526,7 +526,7 @@ if (is_array($list) && count($list) > 0) { exe_user_id="' . $student_id . '" AND orig_lp_id = "' . $lp_id . '" AND orig_lp_item_id = "' . $row['myid'] . '" AND - exe_cours_id="' . $course_code . '" AND + c_id ="' . $course_id . '" AND status <> "incomplete" AND session_id = ' . $session_id . ' ORDER BY exe_date DESC limit 1'; @@ -613,18 +613,20 @@ if (is_array($list) && count($list) > 0) { exe_user_id="' . api_get_user_id() . '" AND orig_lp_id = "' . $lp_id . '" AND orig_lp_item_id = "' . $row['myid'] . '" AND - exe_cours_id="' . $course_code . '" AND + c_id = "' . $course_id . '" AND status <> "incomplete" AND session_id = ' . $session_id . ' ORDER BY exe_date DESC '; } else { + $courseInfo = api_get_course_info($_GET['course']); + $my_url_suffix = '&course=' . Security::remove_XSS($_GET['course']) . '&student_id=' . $student_id . '&lp_id=' . Security::remove_XSS($row['mylpid']) . '&origin=' . Security::remove_XSS($_GET['origin'] . $from_link); $sql_last_attempt = 'SELECT * FROM ' . $tbl_stats_exercices . ' WHERE exe_exo_id="' . $row['path'] . '" AND exe_user_id="' . $student_id . '" AND orig_lp_id = "' . $lp_id . '" AND orig_lp_item_id = "' . $row['myid'] . '" AND - exe_cours_id="' . Database :: escape_string($_GET['course']) . '" AND + c_id = "' . $courseInfo['real_id'] . '" AND status <> "incomplete" AND session_id = ' . $session_id . ' ORDER BY exe_date DESC '; diff --git a/main/reports/modules/quiz.php b/main/reports/modules/quiz.php index ec4347d4ea..1140f01a51 100644 --- a/main/reports/modules/quiz.php +++ b/main/reports/modules/quiz.php @@ -1,4 +1,4 @@ - + array_push($reports_modules['quiz'], + array('keys_query' => 'select '.$course_id.' as course_id, '. $reports_modules_quiz_toolid.' as tool_id, '. 'q.id as child_id, q.title as child_name, '. "'".$course_code."'".' as course_code from '.Database::get_course_table(TABLE_QUIZ_TEST).' q ', - 'values_query_function' => 'reports_modules_quiz_quizVal')); + 'values_query_function' => 'reports_modules_quiz_quizVal')); } +/** + * @todo fix the exe_cours_id field + * @param $quiz + * @param $key_id + * @return array + */ + function reports_modules_quiz_quizVal($quiz, $key_id) { - return array('type'=> 'sql', 'sql' => + return array('type'=> 'sql', 'sql' => 'select '.$key_id.', exe_user_id as uid, '. 'session_id, -1 as attempt, exe_result as score, '. REPORTS_PROGRESS_COMPLETED.' as progress, '. diff --git a/main/session/index.php b/main/session/index.php index f2bf7d6531..2f30eb0273 100644 --- a/main/session/index.php +++ b/main/session/index.php @@ -76,7 +76,7 @@ if (!empty($new_session_list)) { $course['name'] = $course_info['name']; $course['id'] = $course_info['real_id']; if (!empty($exercise_list)) { - foreach($exercise_list as $exercise_item) { + foreach ($exercise_list as $exercise_item) { //Loading the exercise $exercise = new Exercise($course_info['real_id']); $exercise->read($exercise_item['id']); @@ -84,7 +84,7 @@ if (!empty($new_session_list)) { if ($visible_return['value'] != false) { //$exercise_course_list[$exercise_item['id']] = $exercise; //Reading all Exercise results by user, exercise_id, code, and session - $user_results = get_exercise_results_by_user(api_get_user_id(), $exercise_item['id'], $my_course['code'], $my_session_id); + $user_results = get_exercise_results_by_user(api_get_user_id(), $exercise_item['id'], $my_course['real_id'], $my_session_id); $course['exercises'][$exercise_item['id']]['data']['exercise_data'] = $exercise; $course['exercises'][$exercise_item['id']]['data']['results'] = $user_results; } @@ -195,7 +195,7 @@ $now = time(); foreach($final_array as $session_data) { $my_course_list = isset($session_data['data']) ? $session_data['data']: array(); if (!empty($my_course_list)) - foreach ($my_course_list as $my_course_code=>$course_data) { + foreach ($my_course_list as $my_course_code => $course_data) { if (isset($course_id) && !empty($course_id)) { if ($course_id != $course_data['id']) { continue; @@ -205,7 +205,7 @@ foreach($final_array as $session_data) { if (!empty($course_data['exercises'])) { //Exercises foreach ($course_data['exercises'] as $my_exercise_id => $exercise_data) { - $best_score_data = get_best_attempt_in_course($my_exercise_id, $my_course_code, $session_id); + $best_score_data = get_best_attempt_in_course($my_exercise_id, $course_data['id'], $session_id); $best_score = ''; if (!empty($best_score_data)) { @@ -229,20 +229,21 @@ foreach($final_array as $session_data) { if(!empty($exercise_result['exe_weighting']) && intval($exercise_result['exe_weighting']) != 0) { $my_score = $exercise_result['exe_result']/$exercise_result['exe_weighting']; } - $position = get_exercise_result_ranking($my_score, $exercise_result['exe_id'], $my_exercise_id, $my_course_code, $session_id, $user_list); + $position = get_exercise_result_ranking($my_score, $exercise_result['exe_id'], $my_exercise_id, $course_data['id'], $session_id, $user_list); //$exercise_info->exercise = Display::url($exercise_info->exercise, api_get_path(WEB_CODE_PATH)."exercice/exercice.php?cidReq=$my_course_code&exerciseId={$exercise_info->id}&id_session=$session_id&show=result", array('target'=>SESSION_LINK_TARGET,'class'=>'exercise-result-link')); $exercise_info->exercise = Display::url($exercise_info->exercise, api_get_path(WEB_CODE_PATH)."exercice/result.php?cidReq=$my_course_code&id={$exercise_result['exe_id']}&id_session=$session_id&show_headers=1", array('target'=>SESSION_LINK_TARGET,'class'=>'exercise-result-link')); - $my_real_array[]= array( //'date' => api_get_local_time($exercise_result['exe_date']), - 'status' => Display::return_icon('quiz.gif', get_lang('Attempted'),'', ICON_SIZE_SMALL), - 'date' => $start_date, - 'course' => $course_data['name'], - 'exercise' => $exercise_info->exercise, - 'attempt' => $counter, - 'result' => $platform_score, - 'best_result' => $best_score, - 'position' => $position - ); + $my_real_array[]= array( + //'date' => api_get_local_time($exercise_result['exe_date']), + 'status' => Display::return_icon('quiz.gif', get_lang('Attempted'),'', ICON_SIZE_SMALL), + 'date' => $start_date, + 'course' => $course_data['name'], + 'exercise' => $exercise_info->exercise, + 'attempt' => $counter, + 'result' => $platform_score, + 'best_result' => $best_score, + 'position' => $position + ); $counter++; } } else { @@ -254,16 +255,17 @@ foreach($final_array as $session_data) { } } $exercise_info->exercise = Display::url($exercise_info->exercise, api_get_path(WEB_CODE_PATH)."exercice/overview.php?cidReq=$my_course_code&exerciseId={$exercise_info->id}&id_session=$session_id", array('target'=>SESSION_LINK_TARGET)); - $new_exercises[]= array( //'date' => api_get_local_time($exercise_result['exe_date']), - 'status' => Display::return_icon('star.png', get_lang('New'), array('width'=>ICON_SIZE_SMALL)), - 'date' => $start_date, - 'course' => $course_data['name'], - 'exercise' => $exercise_info->exercise, - 'attempt' => '-', - 'result' => '-', - 'best_result' => '-', - 'position' => '-' - ); + $new_exercises[]= array( + //'date' => api_get_local_time($exercise_result['exe_date']), + 'status' => Display::return_icon('star.png', get_lang('New'), array('width'=>ICON_SIZE_SMALL)), + 'date' => $start_date, + 'course' => $course_data['name'], + 'exercise' => $exercise_info->exercise, + 'attempt' => '-', + 'result' => '-', + 'best_result' => '-', + 'position' => '-' + ); } } } diff --git a/main/social/home.php b/main/social/home.php index 3bf1c43c54..e5dde788fa 100644 --- a/main/social/home.php +++ b/main/social/home.php @@ -70,7 +70,6 @@ $list = array( $usergroup = new UserGroup(); // Current user information ->>>>>>> Minor - code style $social_right_content .= '
'.Display::description($list).'
'; $social_right_content .= '
diff --git a/main/tracking/course_session_report.php b/main/tracking/course_session_report.php index 239cf40e40..6a950fb583 100644 --- a/main/tracking/course_session_report.php +++ b/main/tracking/course_session_report.php @@ -1,4 +1,5 @@ $stats['exe_result'],'exe_weighting' =>$stats['exe_weighting']); diff --git a/main/tracking/personnalLog.php b/main/tracking/personnalLog.php index 587d3edd18..2787e49a7b 100755 --- a/main/tracking/personnalLog.php +++ b/main/tracking/personnalLog.php @@ -216,7 +216,7 @@ api_display_tool_title($nameTools); FROM $TABLECOURSE_EXERCICES AS ce , $TABLETRACK_EXERCICES AS te WHERE te.exe_user_id = '".$_user['user_id']."' AND te.exe_exo_id = ce.id - ORDER BY te.exe_cours_id ASC, ce.title ASC, te.exe_date ASC"; + ORDER BY te.c_id ASC, ce.title ASC, te.exe_date ASC"; echo "
'.get_lang('Session').''.get_lang('MoyenneTest').''.get_lang('MoyenneExamen').'
"; $results = getManyResultsXCol($sql,4); diff --git a/main/tracking/question_course_report.php b/main/tracking/question_course_report.php index 26e1c76adb..67fa8d659c 100644 --- a/main/tracking/question_course_report.php +++ b/main/tracking/question_course_report.php @@ -1,4 +1,5 @@ read($exercise['path']); $question_list = $my_exercise->selectQuestionList(); - $exercise_stats = get_all_exercise_event_from_lp($exercise['path'],$course_info['id'], $session_id); + $exercise_stats = get_all_exercise_event_from_lp($exercise['path'],$course_info['real_id'], $session_id); foreach ($question_list as $question_id) { $question_data = Question::read($question_id); diff --git a/main/tracking/userLog.php b/main/tracking/userLog.php index aeb8ec2cb2..7dcfd1f990 100644 --- a/main/tracking/userLog.php +++ b/main/tracking/userLog.php @@ -30,6 +30,7 @@ $this_section = "session_my_space"; // variables $user_id = api_get_user_id(); $course_id = api_get_course_id(); +$courseId = api_get_course_int_id(); //YW Hack security to quick fix RolesRights bug $is_allowed = true; @@ -76,7 +77,6 @@ $is_course_member = CourseManager::is_user_subscribed_in_real_or_linked_course($ // Database Table Definitions $TABLECOURSUSER = Database::get_main_table(TABLE_MAIN_COURSE_USER); $TABLEUSER = Database::get_main_table(TABLE_MAIN_USER); - $TABLECOURSE_GROUPSUSER = Database::get_course_table(TABLE_GROUP_USER); $tbl_learnpath_main = Database::get_course_table(TABLE_LP_MAIN); @@ -251,7 +251,7 @@ if( ( $is_allowedToTrack || $is_allowedToTrackEverybodyInCourse )) { TrackingUserLog::display_login_tracking_info($view, $uInfo, $_cid); //Exercise results - TrackingUserLog::display_exercise_tracking_info($view, $uInfo, $_cid); + TrackingUserLog::display_exercise_tracking_info($view, $uInfo, $courseId); //Student publications uploaded TrackingUserLog::display_student_publications_tracking_info($view, $uInfo, $_cid); diff --git a/main/tracking/userlogCSV.php b/main/tracking/userlogCSV.php index 5b89a08d2e..ceb0c54b76 100644 --- a/main/tracking/userlogCSV.php +++ b/main/tracking/userlogCSV.php @@ -23,6 +23,7 @@ require_once '../inc/global.inc.php'; // Roles and rights system $user_id = api_get_user_id(); $course_id = api_get_course_id(); +$courseId = api_get_course_int_id(); /* $role_id = RolesRights::get_local_user_role_id($user_id, $course_id); @@ -215,7 +216,7 @@ if( ( $is_allowedToTrack || $is_allowedToTrackEverybodyInCourse)) list($title_line1, $line1) = TrackingUserLogCSV::display_login_tracking_info($view, $uInfo, $_cid); //Exercise results - list($title_line2, $line2) = TrackingUserLogCSV::display_exercise_tracking_info($view, $uInfo, $_cid); + list($title_line2, $line2) = TrackingUserLogCSV::display_exercise_tracking_info($view, $uInfo, $courseId); //Student publications uploaded list($title_line3, $line3) = TrackingUserLogCSV::display_student_publications_tracking_info($view, $uInfo, $_cid);