123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288 |
- <?php
- require_once '../../exercice/exercise.class.php';
- require_once '../../exercice/question.class.php';
- require_once '../../exercice/answer.class.php';
- require_once '../global.inc.php';
- require_once '../../exercice/exercise.lib.php';
- api_protect_course_script(true);
- $action = $_REQUEST['a'];
- $course_id = api_get_course_int_id();
- switch ($action) {
- case 'get_live_stats':
- if (!api_is_allowed_to_edit(null, true)) {
- break;
- }
-
-
- $action = $_GET['a'];
- $exercise_id = intval($_GET['exercise_id']);
- $page = intval($_REQUEST['page']);
- $limit = intval($_REQUEST['rows']);
- $sidx = $_REQUEST['sidx'];
- $sord = $_REQUEST['sord'];
- if (!in_array($sord, array('asc','desc'))) {
- $sord = 'desc';
- }
-
-
- if (!$sidx) $sidx = 1;
-
- $track_exercise = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
- $user_table = Database::get_main_table(TABLE_MAIN_USER);
- $track_attempt = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
-
- $minutes = intval($_REQUEST['minutes']);
- $now = time() - 60*$minutes;
- $now = api_get_utc_datetime($now);
-
- $where_condition = " orig_lp_id = 0 AND exe_exo_id = $exercise_id AND start_date > '$now' ";
- $sql = "SELECT COUNT(DISTINCT exe_id) FROM $track_exercise WHERE $where_condition ";
- $result = Database::query($sql);
-
- $count = Database::fetch_row($result);
- $count = $count[0];
-
-
-
- $total_pages = 0;
- if ($count > 0) {
- if (!empty($limit)) {
- $total_pages = ceil($count/$limit);
- }
- }
- if ($page > $total_pages) {
- $page = $total_pages;
- }
-
- $start = $limit * $page - $limit;
- if ($start < 0 ) {
- $start = 0;
- }
-
- $sql = "SELECT count_questions, exe_user_id, firstname, lastname, aa.status, start_date, exe_result, exe_weighting, exe_result/exe_weighting as score, exe_duration, questions_to_check, orig_lp_id
- FROM $user_table u INNER JOIN (
- SELECT t.exe_user_id, count(question_id) as count_questions, status,
- start_date, exe_result, exe_weighting, exe_result/exe_weighting as score, exe_duration, questions_to_check, orig_lp_id
- FROM $track_exercise t LEFT JOIN $track_attempt a ON (a.exe_id = t.exe_id AND t.exe_user_id = a.user_id )
- WHERE t.status = 'incomplete' AND
- $where_condition
- GROUP BY exe_user_id
- ) as aa
- ON aa.exe_user_id = user_id
- ORDER BY $sidx $sord LIMIT $start, $limit";
-
- $result = Database::query($sql);
- $results = array();
-
- while ($row = Database::fetch_array($result,'ASSOC')){
- $results[] = $row;
- }
-
- $response = new stdClass();
- $response->page = $page;
- $response->total = $total_pages;
- $response->records = $count;
- $i=0;
-
- if (!empty($results)) {
- foreach($results as $row) {
-
-
- $response->rows[$i]['id'] = $row['exe_id'];
- $array = array( $row['firstname'],
- $row['lastname'],
- api_format_date($row['start_date'], DATE_TIME_FORMAT_LONG),
- $row['count_questions'],
- round($row['score']*100).'%'
- );
- $response->rows[$i]['cell'] = $array;
- $i++;
- }
- }
- echo json_encode($response);
- break;
- case 'update_question_order':
- if (api_is_allowed_to_edit(null, true)) {
- $new_question_list = $_POST['question_id_list'];
- $TBL_QUESTIONS = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION);
- $counter = 1;
- foreach ($new_question_list as $new_order_id) {
- Database::update($TBL_QUESTIONS, array('question_order'=>$counter), array('question_id = ? AND c_id = ? '=>array(intval($new_order_id), $course_id)));
- $counter++;
- }
- Display::display_confirmation_message(get_lang('Saved'));
- }
- break;
- case 'add_question_to_reminder':
- $objExercise = $_SESSION['objExercise'];
- if (empty($objExercise)) {
- echo 0;
- exit;
- } else {
- $objExercise->edit_question_to_remind($_REQUEST['exe_id'], $_REQUEST['question_id'], $_REQUEST['action']);
- }
- break;
- case 'save_exercise_by_now':
-
- if (api_is_allowed_to_session_edit()) {
-
-
- $type = $_REQUEST['type'];
-
-
- $choice = $_REQUEST['choice'];
-
-
- $hot_spot_coordinates = $_REQUEST['hotspot'];
-
-
-
- $remind_list = isset($_REQUEST['remind_list']) && !empty($_REQUEST['remind_list'])? array_keys($_REQUEST['remind_list']) : null;
-
- $exe_id = $_REQUEST['exe_id'];
-
-
- $question_id = intval($_REQUEST['question_id']);
- $question_list = $_SESSION['questionList'];
- $objExercise = $_SESSION['objExercise'];
-
- if (empty($question_list) || empty($objExercise)) {
- echo 0;
- exit;
- }
-
- $exercise_stat_info = $objExercise->get_stat_track_exercise_info_by_exe_id($exe_id);
-
- $attempt_list = array();
-
-
- if (empty($exercise_stat_info)) {
-
- } else {
-
- $exe_id = $exercise_stat_info['exe_id'];
- $total_score = $exercise_stat_info['exe_result'];
-
-
- $attempt_list = get_all_exercise_event_by_exe_id($exe_id);
- }
-
-
-
- if ($objExercise->type == ONE_PER_PAGE) {
- $bd_reminder_list = explode(',', $exercise_stat_info['questions_to_check']);
-
- if (empty($remind_list)) {
- $remind_list = $bd_reminder_list;
-
- $new_list = array();
- foreach($bd_reminder_list as $item) {
- if ($item != $question_id) {
- $new_list[] = $item;
- }
- }
- $remind_list = $new_list;
- } else {
- if (isset($remind_list[0])) {
- if (!in_array($remind_list[0], $bd_reminder_list)) {
- array_push($bd_reminder_list, $remind_list[0]);
- }
- $remind_list = $bd_reminder_list;
- }
- }
- }
-
-
-
- if (empty($exe_id)) {
-
- echo 'error';
- exit;
- } else {
- $_SESSION['exe_id'] = $exe_id;
- }
-
-
- $total_weight = 0;
- if ($type == 'simple') {
- foreach($question_list as $my_question_id) {
- $objQuestionTmp = Question :: read($my_question_id);
- $total_weight += $objQuestionTmp->selectWeighting();
- }
- }
-
- unset($objQuestionTmp);
-
-
-
- foreach($question_list as $my_question_id) {
- if ($type == 'simple' && $question_id != $my_question_id) {
- continue;
- }
-
- $my_choice = $choice[$my_question_id];
-
-
- $objQuestionTmp = Question::read($my_question_id);
-
-
- if ($objQuestionTmp->type == FREE_ANSWER && $type == 'all') {
- $my_choice = isset($_REQUEST['free_choice'][$my_question_id]) && !empty($_REQUEST['free_choice'][$my_question_id])? $_REQUEST['free_choice'][$my_question_id]: null;
- }
-
- if ($type == 'all') {
- $total_weight += $objQuestionTmp->selectWeighting();
- }
-
-
- $hotspot_delineation_result = $_SESSION['hotspot_delineation_result'][$objExercise->selectId()][$my_question_id];
-
-
- if (isset($attempt_list) && !empty($attempt_list[$my_question_id])) {
- delete_attempt($exe_id, api_get_user_id() , api_get_course_id(), api_get_session_id(), $my_question_id);
- if ($objQuestionTmp->type == HOT_SPOT) {
- delete_attempt_hotspot($exe_id, api_get_user_id() , api_get_course_id(), $my_question_id);
- }
- $total_score -= $attempt_list[$my_question_id]['marks'];
- }
-
-
- $result = $objExercise->manage_answer($exe_id, $my_question_id, $my_choice,'exercise_result', $hot_spot_coordinates, true, false, $show_results, $objExercise->selectPropagateNeg(), $hotspot_delineation_result, true);
-
- $total_score += $result['score'];
-
- update_event_exercice($exe_id, $objExercise->selectId(), $total_score, $total_weight, api_get_session_id(), $exercise_stat_info['orig_lp_id'], $exercise_stat_info['orig_lp_item_id'], $exercise_stat_info['orig_lp_item_view_id'], $exercise_stat_info['exe_duration'], $question_list, 'incomplete', $remind_list);
-
-
- unset($objQuestionTmp);
- }
- }
-
- if ($objExercise->type == ONE_PER_PAGE) {
- echo 'one_per_page';
- exit;
- }
- echo 'ok';
- break;
- default:
- echo '';
- }
- exit;
|