diff --git a/main/exercice/exercise.class.php b/main/exercice/exercise.class.php index 6204db91f8..076b9eb994 100644 --- a/main/exercice/exercise.class.php +++ b/main/exercice/exercise.class.php @@ -1482,11 +1482,13 @@ class Exercise { /** * Cleans the student's results only for the Exercise tool (Not from the LP) - * The LP results are NOT deleted + * The LP results are NOT deleted by default, otherwise put $clean_lp_tests = true * Works with exercises in sessions + * @param bool $clean_lp_tests + * @param int $clean_result_before_date * @return int quantity of user's exercises deleted */ - function clean_results($clean_lp_tests = false) { + function clean_results($clean_lp_tests = false, $clean_result_before_date = '0') { $table_track_e_exercises = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES); $table_track_e_attempt = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT); @@ -1494,10 +1496,17 @@ class Exercise { orig_lp_id = 0 AND orig_lp_item_id = 0'; + // if we want to delete results from LP too if ($clean_lp_tests) { $sql_where = ""; } + // if we want to delete attempts before date $clean_result_before_date + // $clean_result_before_date must be a valid UTC-0 date yyyy-mm-dd + if ($clean_result_before_date != '0') { + $sql_where .= " AND exe_date <= '$clean_result_before_date' "; + } + $sql_select = "SELECT exe_id FROM $table_track_e_exercises WHERE exe_cours_id = '".api_get_course_id()."' AND exe_exo_id = ".$this->id." AND @@ -1507,7 +1516,8 @@ class Exercise { $result = Database::query($sql_select); $exe_list = Database::store_result($result); - //deleting TRACK_E_ATTEMPT table + // deleting TRACK_E_ATTEMPT table + // check if exe in learning path or not $i = 0; if (is_array($exe_list) && count($exe_list) > 0) { foreach($exe_list as $item) { @@ -1517,13 +1527,12 @@ class Exercise { } } - //delete TRACK_E_EXERCICES table + // 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." $sql_where AND session_id = ".api_get_session_id().""; - Database::query($sql); return $i; diff --git a/main/exercice/exercise_report.php b/main/exercice/exercise_report.php index 5860f7553f..b37e94282b 100644 --- a/main/exercice/exercise_report.php +++ b/main/exercice/exercise_report.php @@ -23,6 +23,7 @@ require_once '../gradebook/lib/be.inc.php'; $this_section = SECTION_COURSES; $htmlHeadXtra[] = api_get_jqgrid_js(); +$htmlHeadXtra[] = api_get_datepicker_js(); // Access control api_protect_course_script(true, false, true); @@ -220,7 +221,20 @@ if ($is_allowedToEdit && $origin != 'learnpath') { $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).''; + Display::return_icon('save.png', get_lang('Export'), '', ICON_SIZE_MEDIUM).''; + // clean result before a selected date icon + $actions .= Display::url( + Display::return_icon('clean_before_date.png', get_lang('CleanStudentsResultsBeforeDate'), '', ICON_SIZE_MEDIUM), '', array('onclick' => "javascript:display_date_picker()", 'href' => '#') + ); + // clean result before a selected date datepicker popup + $actions .= Display::span( + Display::input('input', 'datepicker_start', get_lang('SelectADateOnTheCalendar'), + array('onmouseover'=>'datepicker_input_mouseover()', 'id'=>'datepicker_start', 'onchange'=>'datepicker_input_changed()', 'readonly'=>'readonly') + ). + Display::button('delete', get_lang('Delete'), + array('onclick'=>'submit_datepicker()')), + array('style'=>'display:none', 'id'=>'datepicker_span') + ); } } else { $actions .= ''.Display :: return_icon('back.png', get_lang('GoBackToQuestionList'), '', ICON_SIZE_MEDIUM).''; @@ -239,6 +253,7 @@ if (($is_allowedToEdit || $is_tutor || api_is_coach()) && $_GET['delete'] == 'de } } + if ($is_allowedToEdit || $is_tutor) { $nameTools = get_lang('StudentScore'); $interbreadcrumb[] = array("url" => "exercice.php?gradebook=$gradebook", "name" => get_lang('Exercices')); @@ -256,6 +271,27 @@ if ($is_allowedToEdit || $is_tutor) { Display :: display_header($nameTools); +// Clean all results for this test before the selected date +$datepicker_language = get_datepicker_langage_code(); +if (($is_allowedToEdit || $is_tutor || api_is_coach()) && isset($_GET['delete_before_date']) && $locked == false) { + // ask for the date + $check = Security::check_token('get'); + if ($check) { + // delete attempts before date $_GET['delete_before_date'] + $dateUTC = api_get_utc_datetime($_GET['delete_before_date']); + if (api_is_valid_date($_GET['delete_before_date'])) { + $objExerciseTmp = new Exercise(); + if ($objExerciseTmp->read($exercise_id)) { + $nb_del = $objExerciseTmp->clean_results(true, $_GET['delete_before_date']); + Display :: display_confirmation_message(sprintf(get_lang('XResultsCleaned'), $nb_del)); + } + } + } +} + +// Security token to protect deletion +$token = Security::get_token(); + $actions = Display::div($actions, array('class' => 'actions')); $extra = '
+ "); + * and message contains character " + * @param $in_text + */ +function convert_double_quote_to_single($in_text) { + return api_preg_replace('/"/', "''", $in_text); +} \ No newline at end of file