diff --git a/main/admin/settings.lib.php b/main/admin/settings.lib.php index eaa6bc4df8..cd69b4a7e5 100644 --- a/main/admin/settings.lib.php +++ b/main/admin/settings.lib.php @@ -143,7 +143,6 @@ function handle_plugins() { } else { echo ''; } - //echo ''; echo ''; //Checkbox if (in_array($plugin, $installed_plugins)) { @@ -197,20 +196,21 @@ function handle_stylesheets() { $url_info = api_get_access_url($_configuration['access_url']); if ($style_info[0]['access_url_changeable'] == 1 && $url_info['active'] == 1) { $is_style_changeable = true; - echo '';*/ } } else { $is_style_changeable = true; - echo '';*/ } - $form = new FormValidator('stylesheet_upload', 'post', 'settings.php?category=Stylesheets&showuploadform=true'); + $form = new FormValidator('stylesheet_upload', 'post', 'settings.php?category=Stylesheets#tabs-2'); + //$form->addElement('header', get_lang('UploadNewStylesheet')); $form->addElement('text', 'name_stylesheet', get_lang('NameStylesheet'), array('size' => '40', 'maxlength' => '40')); $form->addRule('name_stylesheet', get_lang('ThisFieldIsRequired'), 'required'); $form->addElement('file', 'new_stylesheet', get_lang('UploadNewStylesheet')); @@ -218,8 +218,27 @@ function handle_stylesheets() { $form->addRule('new_stylesheet', get_lang('InvalidExtension').' ('.implode(',', $allowed_file_types).')', 'filetype', $allowed_file_types); $form->addRule('new_stylesheet', get_lang('ThisFieldIsRequired'), 'required'); - $form->addElement('style_submit_button', 'stylesheet_upload', get_lang('Ok'), array('class'=>'save')); - if ($form->validate() && is_writable(api_get_path(SYS_CODE_PATH).'css/')) { + $form->addElement('style_submit_button', 'stylesheet_upload', get_lang('Upload'), array('class'=>'save')); + + $show_upload_form = false; + + if (!is_writable(api_get_path(SYS_CODE_PATH).'css/')) { + Display::display_error_message(api_get_path(SYS_CODE_PATH).'css/'.get_lang('IsNotWritable')); + } else { + // Uploading a new stylesheet. + if ($_configuration['access_url'] == 1) { + //$form->display(); + $show_upload_form = true; + } else { + if ($is_style_changeable) { + //$form->display(); + $show_upload_form = true; + } + } + } + + if (isset($_POST['stylesheet_upload'])) { + if ($form->validate()) { $values = $form->exportValues(); $picture_element = $form->getElement('new_stylesheet'); $picture = $picture_element->getValue(); @@ -233,39 +252,15 @@ function handle_stylesheets() { if ($result) { Display::display_confirmation_message(get_lang('StylesheetAdded')); } - } else { - if (!is_writable(api_get_path(SYS_CODE_PATH).'css/')) { - Display::display_error_message(api_get_path(SYS_CODE_PATH).'css/'.get_lang('IsNotWritable')); - } else { - if (!empty($_GET['showuploadform']) && $_GET['showuploadform'] == 'true') { - echo '
'; - } else { - echo ''; } } -?> - -'; - echo '
"; //echo ''.$show_name.''; } else { - echo ''.$show_name.''; + //echo ''.$show_name.''; } - echo '
'; $counter++; } } @@ -306,14 +300,38 @@ function handle_stylesheets() { //Sort styles in alphabetical order asort($list_of_names); + $select_list = array(); foreach($list_of_names as $style_dir=>$item) { - echo $list_of_styles[$style_dir]; + $select_list[$style_dir] = strip_tags($list_of_styles[$style_dir]); } - //echo '
'; - echo '  '; + $form_change->addElement('select', 'style', get_lang('NameStylesheet'), $select_list); + $form_change->setDefaults('style', $selected); + + if ($form_change->validate()) { + // Submit stylesheets. + if (isset($_POST['save'])) { + store_stylesheets(); + echo Display::display_normal_message(get_lang('Saved')); + } + } if ($is_style_changeable){ - echo ''; + $group[] = $form_change->createElement('button', 'save', get_lang('SaveSettings'), array('class' => 'btn btn-primary')); + $group[] = $form_change->createElement('button', 'preview', get_lang('Preview'), array('class' => 'btn')); + $form_change->addGroup($group); + + if ($show_upload_form) { + echo ''; + echo Display::tabs(array(get_lang('Update'), get_lang('UploadNewStylesheet')), array($form_change->return_form(), $form->return_form())); + } else { + $form_change->display(); + } + } else { + $form_change->freeze(); } } diff --git a/main/admin/settings.php b/main/admin/settings.php index bdeeac7719..72afd19fd4 100644 --- a/main/admin/settings.php +++ b/main/admin/settings.php @@ -46,13 +46,6 @@ $settings_to_avoid = array( $convert_byte_to_mega_list = array('dropbox_max_filesize', 'message_max_upload_filesize', 'default_document_quotum', 'default_group_quotum'); -// Submit stylesheets. -if (isset($_POST['submit_stylesheets'])) { - $message = store_stylesheets(); - header("Location: ".api_get_self()."?category=Stylesheets"); - exit; -} - if (isset($_POST['style'])) { Display::$preview_style = $_POST['style']; } diff --git a/main/css/base.css b/main/css/base.css index 2118ae120c..2c702b4b4f 100644 --- a/main/css/base.css +++ b/main/css/base.css @@ -415,10 +415,16 @@ footer .container .row { vertical-align:middle; } .actions a { - display:inline-block; + display: block; + float: left; margin-right: 10px; vertical-align:middle; } + +.actions .btn-toolbar { + margin : 0px; +} + .actions span { margin-right: 10px; vertical-align:middle; diff --git a/main/exercice/exercise.class.php b/main/exercice/exercise.class.php index 59bead8e6e..4465eb1748 100644 --- a/main/exercice/exercise.class.php +++ b/main/exercice/exercise.class.php @@ -2270,7 +2270,7 @@ class Exercise { $str = str_replace('\r\n', '', $str); $choice = $arr[1]; - $tmp = api_strrpos($choice[$j],' / '); + $tmp = api_strrpos($choice[$j],' / '); $choice[$j] = api_substr($choice[$j],0,$tmp); $choice[$j] = trim($choice[$j]); @@ -2359,6 +2359,9 @@ class Exercise { } else { $totalScore+= $questionScore; } + if ($questionScore == '') { + $questionScore = 0; + } $arrques = $questionName; $arrans = $choice; } else { @@ -2735,7 +2738,7 @@ class Exercise { } else { if ($debug) error_log('Showing questions $from '.$from); - switch($answerType) { + switch ($answerType) { case UNIQUE_ANSWER : case UNIQUE_ANSWER_NO_OPTION: case MULTIPLE_ANSWER : @@ -3433,6 +3436,7 @@ class Exercise { public function is_visible($lp_id = 0, $lp_item_id = 0 , $lp_item_view_id = 0, $filter_by_admin = true) { //1. By default the exercise is visible $is_visible = true; + $message = null; //1.1 Admins and teachers can access to the exercise if ($filter_by_admin) { diff --git a/main/exercice/exercise.lib.php b/main/exercice/exercise.lib.php index 30ee039b6e..7fd991256e 100644 --- a/main/exercice/exercise.lib.php +++ b/main/exercice/exercise.lib.php @@ -203,6 +203,7 @@ function showQuestion($questionId, $only_questions = false, $origin = false, $cu $numAnswer = $objAnswerTmp->selectAutoId($answerId); $comment = $objAnswerTmp->selectComment($answerId); + $attributes = array(); // Unique answer if ($answerType == UNIQUE_ANSWER || $answerType == UNIQUE_ANSWER_NO_OPTION) { $input_id = 'choice-'.$questionId.'-'.$answerId; @@ -2073,6 +2074,7 @@ function display_question_list_by_attempt($objExercise, $exe_id, $save_user_resu //Getting attempt info $exercise_stat_info = $objExercise->get_stat_track_exercise_info_by_exe_id($exe_id); + //Getting question list $question_list = array(); if (!empty($exercise_stat_info['data_tracking'])) { $question_list = explode(',', $exercise_stat_info['data_tracking']); @@ -2135,7 +2137,7 @@ function display_question_list_by_attempt($objExercise, $exe_id, $save_user_resu ob_start(); // We're inside *one* question. Go through each possible answer for this question - $result = $objExercise->manage_answer($exercise_stat_info['exe_id'], $questionId, null ,'exercise_result', array(), false, true, $show_results, $objExercise->selectPropagateNeg(), $hotspot_delineation_result); + $result = $objExercise->manage_answer($exercise_stat_info['exe_id'], $questionId, null , 'exercise_result', array(), $save_user_result, true, $show_results, $objExercise->selectPropagateNeg(), $hotspot_delineation_result); $total_score += $result['score']; $total_weight += $result['weight']; diff --git a/main/exercice/exercise_reminder.php b/main/exercice/exercise_reminder.php index 853d79efd1..2b7ee98471 100644 --- a/main/exercice/exercise_reminder.php +++ b/main/exercice/exercise_reminder.php @@ -1,7 +1,7 @@ show_time_control_js($time_left); + $htmlHeadXtra[] = $objExercise->show_time_control_js($time_left); } @@ -106,48 +106,48 @@ if (api_is_course_admin() && $origin != 'learnpath') { echo Display::page_header(get_lang('QuestionsToReview')); if ($time_control) { - echo $objExercise->return_time_left_div(); + echo $objExercise->return_time_left_div(); } echo Display::div('', array('id'=>'message')); -echo ''; @@ -161,10 +161,10 @@ $exercise_result = array(); foreach ($attempt_list as $question_id => $options) { //echo $question_id.'
'; foreach($options as $item) { - + $question_obj = Question::read($item['question_id']); - - switch($question_obj->type) { + + switch($question_obj->type) { case FILL_IN_BLANKS: $item['answer'] = $objExercise->fill_in_blank_answer_to_string($item['answer']); break; @@ -172,12 +172,12 @@ foreach ($attempt_list as $question_id => $options) { //var_dump($item['answer']); break; } - - if ($item['answer'] != '0' && !empty($item['answer'])) { + + if ($item['answer'] != '0' && !empty($item['answer'])) { $exercise_result[] = $question_id; break; } - } + } } echo Display::label(get_lang('QuestionWithNoAnswer'), 'warning'); echo '

'; @@ -189,26 +189,26 @@ $counter = 0; foreach ($question_list as $questionId) { // destruction of the Question object unset($objQuestionTmp); - + // creates a temporary Question object $objQuestionTmp = Question :: read($questionId); // initialize question information - + $quesId = $objQuestionTmp->selectId(); $check_id = 'remind_list['.$questionId.']'; - $attributes = array('id'=>$check_id, 'onclick'=>"save_remind_item(this, '$questionId');"); - + $attributes = array('id'=>$check_id, 'onclick'=>"save_remind_item(this, '$questionId');"); + if (in_array($questionId, $remind_list)) { $attributes['checked'] = 1; } $label_attributes = array(); $label_attributes['class'] = 'checkbox'; - $label_attributes['for'] = $check_id; + $label_attributes['for'] = $check_id; $label_attributes['class'] = "checkbox"; - + $checkbox = Display::input('checkbox', 'remind_list['.$questionId.']', '', $attributes); $url = 'exercise_submit.php?exerciseId='.$objExercise->id.'&num='.$counter.'&reminder=1'; - + $counter++; if ($objExercise->type == ONE_PER_PAGE) { $question_title = Display::url($counter.'. '.cut($objQuestionTmp->selectTitle(), 40), $url); @@ -220,14 +220,14 @@ foreach ($question_list as $questionId) { if (!in_array($questionId, $exercise_result)) { $question_title = Display::label($question_title, 'warning'); } - $question_title = Display::tag('label', $checkbox.$question_title, $label_attributes); - $table .= Display::div($question_title, array('class'=>'exercise_reminder_item')); + $question_title = Display::tag('label', $checkbox.$question_title, $label_attributes); + $table .= Display::div($question_title, array('class'=>'exercise_reminder_item')); } // end foreach() block that loops over all questions echo Display::div($table, array('class'=>'span10')); -$exercise_actions = Display::url(get_lang('EndTest'), 'javascript://', array('onclick'=>'final_submit();', 'class'=>'btn btn-success')); -$exercise_actions .= ' '.Display::url(get_lang('ReviewQuestions'), 'javascript://', array('onclick'=>'review_questions();','class'=>'btn')); +$exercise_actions = Display::url(get_lang('EndTest'), 'javascript://', array('onclick'=>'final_submit();', 'class'=>'btn btn-warning')); +$exercise_actions .= ' '.Display::url(get_lang('ReviewQuestions'), 'javascript://', array('onclick'=>'review_questions();','class'=>'btn btn-success')); echo Display::div('', array('class'=>'clear')); echo Display::div($exercise_actions, array('class'=>'form-actions')); diff --git a/main/exercice/exercise_report.php b/main/exercice/exercise_report.php index 50d5e7062b..2c4b7663c9 100644 --- a/main/exercice/exercise_report.php +++ b/main/exercice/exercise_report.php @@ -78,7 +78,7 @@ if (!empty($_REQUEST['export_report']) && $_REQUEST['export_report'] == '1') { if (isset($_REQUEST['extra_data']) && $_REQUEST['extra_data'] == 1) { $load_extra_data = true; } - + require_once 'exercise_result.class.php'; switch ($_GET['export_format']) { case 'xls' : @@ -99,8 +99,8 @@ 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(intval($_GET['exeid']))) { - $id = intval($_GET['exeid']); //filtered by post-condition +if ($_REQUEST['comments'] == 'update' && ($is_allowedToEdit || $is_tutor) && $_GET['exeid'] == strval(intval($_GET['exeid']))) { + $id = intval($_GET['exeid']); //filtered by post-condition $track_exercise_info = get_exercise_track_exercise_info($id); if (empty($track_exercise_info)) { api_not_allowed(); @@ -111,14 +111,13 @@ if ($_REQUEST['comments'] == 'update' && ($is_allowedToEdit || $is_tutor) && $_G $lp_id = $track_exercise_info['orig_lp_id']; //$lp_item_id = $track_exercise_info['orig_lp_item_id']; $lp_item_view_id = $track_exercise_info['orig_lp_item_view_id']; - + $course_info = api_get_course_info(); // Teacher data - $teacher_info = api_get_user_info(api_get_user_id()); + $teacher_info = api_get_user_info(api_get_user_id()); $from_name = api_get_person_name($teacher_info['firstname'], $teacher_info['lastname'], null, PERSON_NAME_EMAIL_ADDRESS); - - $url = api_get_path(WEB_CODE_PATH) . 'exercice/exercise_report.php?' . api_get_cidreq() . '&id_session='.$session_id.'&exerciseId='.$exercise_id; + $url = api_get_path(WEB_CODE_PATH) . 'exercice/result.php?id='.$track_exercise_info['exe_id'].'&'.api_get_cidreq().'&show_headers=1&id_session='.$session_id; $my_post_info = array(); $post_content_id = array(); @@ -132,16 +131,17 @@ if ($_REQUEST['comments'] == 'update' && ($is_allowedToEdit || $is_tutor) && $_G } } - $loop_in_track=($comments_exist===true) ? (count($_POST)/2) : count($_POST); + $loop_in_track = ($comments_exist===true) ? (count($_POST)/2) : count($_POST); - $array_content_id_exe=array(); - if ($comments_exist===true) { - $array_content_id_exe = array_slice($post_content_id,$loop_in_track); + $array_content_id_exe = array(); + + if ($comments_exist === true) { + $array_content_id_exe = array_slice($post_content_id, $loop_in_track); } else { $array_content_id_exe = $post_content_id; } - for ($i=0;$i<$loop_in_track;$i++) { + for ($i=0; $i < $loop_in_track; $i++) { $my_marks = Database::escape_string($_POST['marks_'.$array_content_id_exe[$i]]); $contain_comments = Database::escape_string($_POST['comments_'.$array_content_id_exe[$i]]); if (isset($contain_comments)) { @@ -151,6 +151,7 @@ if ($_REQUEST['comments'] == 'update' && ($is_allowedToEdit || $is_tutor) && $_G } $my_questionid = intval($array_content_id_exe[$i]); $sql = "SELECT question from $TBL_QUESTIONS WHERE c_id = $course_id AND id = '$my_questionid'"; + $result =Database::query($sql); Database::result($result,0,"question"); @@ -172,7 +173,7 @@ if ($_REQUEST['comments'] == 'update' && ($is_allowedToEdit || $is_tutor) && $_G $totquery = "UPDATE $TBL_TRACK_EXERCICES SET exe_result = '".floatval($tot)."' WHERE exe_id = ".$id; Database::query($totquery); - + if (isset($_POST['send_notification'])) { //@todo move this somewhere else $subject = get_lang('ExamSheetVCC'); @@ -192,7 +193,6 @@ if ($_REQUEST['comments'] == 'update' && ($is_allowedToEdit || $is_tutor) && $_G $message = str_replace("#url#", $url, $message); MessageManager::send_message_simple($student_id, $subject, $message, api_get_user_id()); } - //Updating LP score here if (in_array($origin, array ('tracking_course','user_course','correct_exercise_in_lp'))) { @@ -322,16 +322,16 @@ if (!empty($group_parameters)) { if ($is_allowedToEdit || $is_tutor) { //The order is important you need to check the the $column variable in the model.ajax.php file - $columns = array(get_lang('FirstName'), - get_lang('LastName'), + $columns = array(get_lang('FirstName'), + get_lang('LastName'), get_lang('LoginName'), - get_lang('Group'), - get_lang('Duration').' ('.get_lang('MinMinute').')', - get_lang('StartDate'), - get_lang('EndDate'), - get_lang('Score'), - get_lang('Status'), - get_lang('ToolLearnpath'), + get_lang('Group'), + get_lang('Duration').' ('.get_lang('MinMinute').')', + get_lang('StartDate'), + get_lang('EndDate'), + get_lang('Score'), + get_lang('Status'), + get_lang('ToolLearnpath'), get_lang('Actions') ); diff --git a/main/exercice/exercise_show.php b/main/exercice/exercise_show.php index cbe61d7069..0689bfe2d1 100644 --- a/main/exercice/exercise_show.php +++ b/main/exercice/exercise_show.php @@ -95,12 +95,6 @@ if (empty($objExercise)) { } $feedback_type = $objExercise->feedback_type; -//If is not valid -$session_control_key = get_session_time_control_key($exercise_id, $learnpath_id, $learnpath_item_id); -if (isset($session_control_key) && !exercise_time_control_is_valid($exercise_id, $learnpath_id, $learnpath_item_id) && !in_array($action, array('qualify','edit'))) { - $sql_fraud = "UPDATE $TBL_TRACK_ATTEMPT SET answer = 0, marks=0, position = 0 WHERE exe_id = $id "; - Database::query($sql_fraud); -} //Only users can see their own results if (!$is_allowedToEdit) { @@ -109,8 +103,6 @@ if (!$is_allowedToEdit) { } } -//Unset session for clock time -exercise_time_control_delete($exercise_id, $learnpath_id, $learnpath_item_id); if (isset($_SESSION['gradebook'])) { $gradebook= Security::remove_XSS($_SESSION['gradebook']); @@ -237,7 +229,6 @@ $query = "SELECT attempts.question_id, answer FROM ".$TBL_TRACK_ATTEMPT." as att 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"; - //GROUP BY questions.position, attempts.question_id"; $result = Database::query($query); $question_list_from_database = array(); @@ -260,9 +251,6 @@ if (!empty($track_exercise_info['data_tracking'])) { if (empty($questionList)) { $questionList = $question_list_from_database; } - /*if (is_array($temp_question_list) && count($temp_question_list) == count($question_list_from_database)) { - $questionList = $tempquestionList; - }*/ } else { $questionList = $question_list_from_database; } diff --git a/main/exercice/exercise_submit.php b/main/exercice/exercise_submit.php index 2480716586..673fcca30a 100644 --- a/main/exercice/exercise_submit.php +++ b/main/exercice/exercise_submit.php @@ -347,7 +347,6 @@ if ($time_control) { //Sends the exercice form when the expired time is finished // if the user has submitted the form $exercise_title = $objExercise->selectTitle(); -$exercise_description = $objExercise->selectDescription(); $exercise_sound = $objExercise->selectSound(); //Media questions @@ -665,8 +664,20 @@ if ($time_control) { echo ''; } + if (!empty($objExercise->description)) { - echo Display::generate_accordion(array( array('title' => get_lang('ExerciseDescriptionLabel'), 'content' => $objExercise->description))); + echo ""; + echo Display::generate_accordion(array(array('title' => get_lang('ExerciseDescriptionLabel'), 'content' => null)), 'jquery', 'description_content'); } if ($origin != 'learnpath') { diff --git a/main/exercice/question.class.php b/main/exercice/question.class.php index 42fa6e8481..f2962df1af 100644 --- a/main/exercice/question.class.php +++ b/main/exercice/question.class.php @@ -1458,7 +1458,7 @@ abstract class Question // display question category, if any $header = Testcategory::returnCategoryAndTitle($this->id); - + $show_media = null; if ($show_media) { $header .= $this->show_media_content(); } diff --git a/main/exercice/result.php b/main/exercice/result.php index f3f96691e6..1f64b6f79b 100644 --- a/main/exercice/result.php +++ b/main/exercice/result.php @@ -1,10 +1,10 @@ read($exercise_id); } -//Only users can see their own results +//Only users can see their own results if (!$is_allowedToEdit) { if ($student_id != $current_user_id) { api_not_allowed(); @@ -70,12 +70,11 @@ if (!$is_allowedToEdit) { if ($show_headers) { $interbreadcrumb[] = array("url" => "exercice.php","name" => get_lang('Exercices')); $interbreadcrumb[] = array("url" => "#","name" => get_lang('Result')); - $this_section = SECTION_COURSES; + $this_section = SECTION_COURSES; Display::display_header(); } else { Display::display_reduced_header(); -} - +} display_question_list_by_attempt($objExercise, $id, false); if ($show_headers) { diff --git a/main/inc/lib/display.lib.php b/main/inc/lib/display.lib.php index ec99e409db..faa381a1ab 100644 --- a/main/inc/lib/display.lib.php +++ b/main/inc/lib/display.lib.php @@ -1453,12 +1453,17 @@ class Display { return self::span($text, array('class' => 'boot-tooltip', 'title' => strip_tags($tip))); } - public static function generate_accordion($items) { + public static function generate_accordion($items, $type = 'jquery', $id = null) { $html = null; if (!empty($items)) { + if (empty($id)) { $id = api_get_unique_id(); - //$html = '
'; //using bootstrap + } + if ($type == 'jquery') { $html = '
'; //using jquery + } else { + $html = '
'; //using bootstrap + } $count = 1; foreach ($items as $item) { @@ -1482,4 +1487,19 @@ class Display { } return $html; } + /** + * @todo use twig + */ + static function group_button($title, $elements) { + $html = '
+
+ + +
'; + return $html; + } } //end class Display \ No newline at end of file diff --git a/main/inc/lib/events.lib.inc.php b/main/inc/lib/events.lib.inc.php index f5539768d1..68c9db57ab 100644 --- a/main/inc/lib/events.lib.inc.php +++ b/main/inc/lib/events.lib.inc.php @@ -484,24 +484,34 @@ function exercise_attempt($score, $answer, $question_id, $exe_id, $position, $ex $file = Database::escape_string(basename($nano->load_filename_if_exists(false))); } - $sql = "INSERT INTO $TBL_TRACK_ATTEMPT (exe_id, user_id, question_id, answer, marks, course_code, session_id, position, tms, filename) - VALUES ( - ".$exe_id.", - ".$user_id.", - '".$question_id."', - '".$answer."', - '".$score."', - '".api_get_course_id()."', - '".api_get_session_id()."', - '".$position."', - '".$now."', - '".$file."' - )"; - - if ($debug) error_log("Saving question attempt: "); - if ($debug) error_log($sql); if (!empty($question_id) && !empty($exe_id) && !empty($user_id)) { + + //Check if attempt exists + $sql = "SELECT exe_id FROM $TBL_TRACK_ATTEMPT WHERE exe_id = $exe_id AND user_id = $user_id AND question_id = $question_id"; + $result = Database::query($sql); + if (Database::num_rows($result)) { + if ($debug) error_log("Attempt already exist: exe_id: $exe_id - user_id:$user_id - question_id:$question_id"); + //The attempt already exist do not update use update_event_exercice() instead + return false; + } + $sql = "INSERT INTO $TBL_TRACK_ATTEMPT (exe_id, user_id, question_id, answer, marks, course_code, session_id, position, tms, filename) + VALUES ( + ".$exe_id.", + ".$user_id.", + '".$question_id."', + '".$answer."', + '".$score."', + '".api_get_course_id()."', + '".api_get_session_id()."', + '".$position."', + '".$now."', + '".$file."' + )"; + + 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); diff --git a/main/inc/lib/mail.lib.inc.php b/main/inc/lib/mail.lib.inc.php index cebb07e044..375a01f479 100644 --- a/main/inc/lib/mail.lib.inc.php +++ b/main/inc/lib/mail.lib.inc.php @@ -80,6 +80,10 @@ function api_mail_html($recipient_name, $recipient_email, $subject, $message, $s $mail->AddReplyTo($sender_email, $sender_name); } + if (isset($extra_headers['reply_to'])) { + $mail->AddReplyTo($extra_headers['reply_to']['mail'], $extra_headers['reply_to']['name']); + } + // Attachments // $mail->AddAttachment($path); // $mail->AddAttachment($path, $filename); diff --git a/main/inc/lib/tracking.lib.php b/main/inc/lib/tracking.lib.php index 1defb02510..fa0c376393 100644 --- a/main/inc/lib/tracking.lib.php +++ b/main/inc/lib/tracking.lib.php @@ -2657,8 +2657,7 @@ class Tracking { $weighting = $exercise_stat['exe_weighting']; $exe_id = $exercise_stat['exe_id']; - //$latest_attempt_url .= ' '.Display::return_icon('quiz.gif', get_lang('Quiz')).' '; - $latest_attempt_url .= '../exercice/exercise_show.php?origin=myprogress&id='.$exe_id.'&cidReq='.$course_info['code'].'&id_session='.$session_id; + $latest_attempt_url .= api_get_path(WEB_CODE_PATH).'exercice/result.php?id='.$exe_id.'&cidReq='.$course_info['code'].'&show_headers=1&id_session='.$session_id; $percentage_score_result = Display::url(show_score($score, $weighting), $latest_attempt_url); $my_score = 0; if (!empty($weighting) && intval($weighting) != 0) { diff --git a/main/inc/lib/usermanager.lib.php b/main/inc/lib/usermanager.lib.php index c554908594..e639dfe8e4 100644 --- a/main/inc/lib/usermanager.lib.php +++ b/main/inc/lib/usermanager.lib.php @@ -366,12 +366,15 @@ class UserManager { } /** - * Can user be deleted? - * This functions checks if there's a course in which the given user is the + * Can user be deleted? This function checks whether there's a course + * in which the given user is the * only course administrator. If that is the case, the user can't be * deleted because the course would remain without a course admin. * @param int $user_id The user id * @return boolean true if user can be deleted + * @assert (null) === false + * @assert (-1) === false + * @assert ('abc') === false */ public static function can_delete_user($user_id) { global $_configuration; @@ -394,9 +397,14 @@ class UserManager { } /** - * Delete a user from the platform - * @param int $user_id The user id + * Delete a user from the platform, and all its belongings. This is a + * very dangerous function that should only be accessible by + * super-admins. Other roles should only be able to disable a user, + * which removes access to the platform but doesn't delete anything. + * @param int The ID of th user to be deleted * @return boolean true if user is succesfully deleted, false otherwise + * @assert (null) === false + * @assert ('abc') === false */ public static function delete_user($user_id) { @@ -513,14 +521,16 @@ class UserManager { } /** - * Deactivate users. Can be called either as: - * - * - UserManager :: delete_users(1, 2, 3); + * Deletes users completely. Can be called either as: + * - UserManager :: delete_users(1, 2, 3); or * - UserManager :: delete_users(array(1, 2, 3)); - * * @param array|int $ids * @return boolean True if at least one user was successfuly deleted. False otherwise. * @author Laurent Opprecht + * @uses UserManager::delete_user() to actually delete each user + * @assert (null) === false + * @assert (-1) === false + * @assert (array(-1)) === false */ static function delete_users($ids = array()) { $result = false; @@ -534,14 +544,14 @@ class UserManager { } /** - * Deactivate users. Can be called either as: - * + * Disable users. Can be called either as: * - UserManager :: deactivate_users(1, 2, 3); * - UserManager :: deactivate_users(array(1, 2, 3)); - * * @param array|int $ids * @return boolean * @author Laurent Opprecht + * @assert (null) === false + * @assert (array(-1)) === false */ static function deactivate_users($ids = array()) { if (empty($ids)) { @@ -557,14 +567,14 @@ class UserManager { } /** - * Activate users. Can be called either as: - * + * Enable users. Can be called either as: * - UserManager :: activate_users(1, 2, 3); * - UserManager :: activate_users(array(1, 2, 3)); - * - * @param array|int $ids + * @param array|int IDs of the users to enable * @return boolean * @author Laurent Opprecht + * @assert (null) === false + * @assert (array(-1)) === false */ static function activate_users($ids = array()) { if (empty($ids)) { @@ -583,6 +593,8 @@ class UserManager { * @param int $user_id * @param string $openid * @return boolean true if the user information was updated + * @assert (false,'') === false + * @assert (-1,'') === false */ public static function update_openid($user_id, $openid) { $table_user = Database :: get_main_table(TABLE_MAIN_USER); @@ -594,22 +606,23 @@ class UserManager { } /** - * Update user information - * @param int $user_id - * @param string $firstname - * @param string $lastname - * @param string $username - * @param string $password - * @param string $auth_source - * @param string $email - * @param int $status - * @param string $official_code - * @param string $phone - * @param string $picture_uri + * Update user information with all the parameters passed to this function + * @param int The ID of the user to be updated + * @param string The user's firstname + * @param string The user's lastname + * @param string The user's username (login) + * @param string The user's password + * @param string The authentication source (default: "platform") + * @param string The user's e-mail address + * @param int The user's status + * @param string The user's official code (usually just an internal institutional code) + * @param string The user's phone number + * @param string The user's picture URL (internal to the Chamilo directory) * @param int The user ID of the person who registered this user (optional, defaults to null) * @param int The department of HR in which the user is registered (optional, defaults to 0) * @param array A series of additional fields to add to this user as extra fields (optional, defaults to null) * @return boolean true if the user information was updated + * @assert (false) === false */ public static function update_user($user_id, $firstname, $lastname, $username, $password = null, $auth_source = null, $email, $status, $official_code, $phone, $picture_uri, $expiration_date, $active, $creator_id = null, $hr_dept_id = 0, $extra = null, $language = 'english', $encrypt_method = '', $send_email = false, $reset_password = 0) { global $_configuration; @@ -721,6 +734,9 @@ class UserManager { * * @param int user_id * @param int Enable or disable + * @return void + * @assert (-1,0) === false + * @assert (1,1) === true */ public static function change_active_state($user_id, $active, $send_email_if_activated = false) { $user_id = intval($user_id); @@ -760,6 +776,8 @@ class UserManager { * Disables a user * * @param int User id + * @uses UserManager::change_active_state() to actually disable the user + * @assert (0) === false */ public static function disable($user_id) { self::change_active_state($user_id, 0); @@ -769,17 +787,21 @@ class UserManager { * Enable a user * * @param int User id + * @uses UserManager::change_active_state() to actually disable the user + * @assert (0) === false */ public static function enable($user_id) { self::change_active_state($user_id, 1); } /** - * Returns the user's id based on the original id and field name in the extra fields. Returns 0 if no user was found - * + * Returns the user's id based on the original id and field name in + * the extra fields. Returns 0 if no user was found. This function is + * mostly useful in the context of a web services-based sinchronization * @param string Original user id * @param string Original field name * @return int User id + * @assert ('0','---') === 0 */ public static function get_user_id_from_original_id($original_user_id_value, $original_user_id_name) { $t_uf = Database::get_main_table(TABLE_MAIN_USER_FIELD); @@ -798,8 +820,11 @@ class UserManager { * Check if a username is available * @param string the wanted username * @return boolean true if the wanted username is available + * @assert ('') === false + * @assert ('xyzxyzxyz') === true */ public static function is_username_available($username) { + if (empty($username)) { return false; } $table_user = Database :: get_main_table(TABLE_MAIN_USER); $sql = "SELECT username FROM $table_user WHERE username = '".Database::escape_string($username)."'"; $res = Database::query($sql); @@ -815,6 +840,8 @@ class UserManager { * @return string Suggests a username that contains only ASCII-letters and digits, without check for uniqueness within the system. * @author Julio Montoya Armas * @author Ivan Tcholakov, 2009 - rework about internationalization. + * @assert ('','') === false + * @assert ('a','b') === 'ab' */ public static function create_username($firstname, $lastname, $language = null, $encoding = null) { if (is_null($encoding)) { diff --git a/main/lang/english/admin.inc.php b/main/lang/english/admin.inc.php index 6d9ecafb5b..e29cf6fb53 100644 --- a/main/lang/english/admin.inc.php +++ b/main/lang/english/admin.inc.php @@ -1257,6 +1257,8 @@ $SessionStartDate = "Access start date"; $SessionDisplayEndDate = "End date to display"; $SessionDisplayStartDate = "Start date to display"; $UserHasNoCourse = "This user is not subscribed to any course"; +$SessionPageEnabledComment = "When this option is enabled, the session title is a link to a special session page. When disabled, it is only a text title, without link. The session page linked to might be confusing for some users, which is why you might want to disable it."; +$SessionPageEnabledTitle = "Enable session link in courses list"; $ThisValueIsUsedInTheCourseURL = "This value is used in the course URL"; $ThereAreUsersUsingThisLanguageYouWantToDisableThisLanguageAndSetUsersWithTheDefaultPortalLanguage = "There are users using this language. Do you want to disable this language and set all this users with the default portal language?"; $SessionTutorsCanSeeExpiredSessionsResultsComment = "Can session tutors see the reports for their session after it has expired?"; diff --git a/main/lang/english/learnpath.inc.php b/main/lang/english/learnpath.inc.php index a41afd05e3..cbd5f5c5b1 100644 --- a/main/lang/english/learnpath.inc.php +++ b/main/lang/english/learnpath.inc.php @@ -247,6 +247,9 @@ $ModifyHotPotatoes = "Modify hotpotatoes"; $SaveHotpotatoes = "Save hotpotatoes"; $ReturnToLPList = "Return to list"; $LpPrerequisiteDescription = "Selecting another learning path as a prerequisite will hide the current prerequisite until the one in prerequisite is fully completed (100%)"; +$PrerequisitesOptions = "Prerequisites options"; +$ClearAllPrerequisites = "Clear all prerequisites"; +$SetPrerequisiteForEachItem = "Set previous step as prerequisite for each step"; $ClickOnTheLearnerViewToSeeYourLearningPath = "Click on the [Learner view] button to see your learning path"; $ExerciseCantBeEditedAfterAddingToTheLP = "Exercise can't be edited after being added to the Learning Path"; $EnableTimeLimits = "Enable availability limits"; diff --git a/main/lang/english/tracking.inc.php b/main/lang/english/tracking.inc.php index d239616bfc..0a1c78bac8 100644 --- a/main/lang/english/tracking.inc.php +++ b/main/lang/english/tracking.inc.php @@ -269,6 +269,9 @@ $LinkInvisible = "Link made invisible"; $LinkAdded = "Link added"; $Minutes = "Minutes"; $BackupCreated = "Backup created"; +$TrainingHoursAccumulated = "Training hours accumulated"; +$ManHours = "Man hours"; +$NotesObtained = "Notes obtained"; $DisplayCourseOverview = "Courses overview"; $DisplaySessionOverview = "Sessions overview"; $TotalNumberOfMessages = "Total number of messages"; diff --git a/main/lang/english/trad4all.inc.php b/main/lang/english/trad4all.inc.php index a6b77c7504..ddea0c5b38 100644 --- a/main/lang/english/trad4all.inc.php +++ b/main/lang/english/trad4all.inc.php @@ -950,6 +950,7 @@ $SkillXWithCourseX = "%s with %s"; $ToGetToLearnXYouWillNeedToTakeOneOfTheFollowingCourses = "To get to learn %s you will need to take one of the following courses:"; $YourSkillRankingX = "Your skill ranking: %s"; $ManageSkills = "Manage skills"; +$StartDateMustBeBeforeTheEndDate = "Start date must be before the end date"; $SkillRoot = "Root"; $SkillInfo = "Skill info"; $GetNewSkills = "Get new skills"; @@ -976,6 +977,7 @@ $NumberOfCoursesPrivate = "Number of private courses"; $NumberOfCoursesClosed = "Number of closed courses"; $NumberOfCoursesTotal = "Total number of courses"; $NumberOfUsersActive = "Number of active users"; +$Approved = "Approved"; $EditSettings = "Edit settings"; $ThisValueCantBeChanged = "This value can't be changed."; $TotalAvailableUsers = "Total available users"; diff --git a/main/newscorm/learnpath.class.php b/main/newscorm/learnpath.class.php index d95723b3e3..8186f94a5b 100644 --- a/main/newscorm/learnpath.class.php +++ b/main/newscorm/learnpath.class.php @@ -113,6 +113,8 @@ class learnpath { } } + $this->set_course_int_id($course_id); + // Check learnpath ID. if (empty($lp_id)) { $this->error = 'Learnpath ID is empty'; @@ -3608,7 +3610,6 @@ class learnpath { $prereq_string = $this->items[$item]->get_prereq_string(); } - if (empty($prereq_string)) { return true; } @@ -4043,7 +4044,6 @@ class learnpath { } else { return false; } - } /** @@ -4234,7 +4234,7 @@ class learnpath { if ($this->debug > 2) { error_log('New LP - lp updated with new preview requisite : ' . $this->requisite, 0); } - $res = Database::query($sql); + Database::query($sql); return true; } @@ -4368,7 +4368,7 @@ class learnpath { if ($this->debug > 2) { error_log('New LP - lp updated with new expired_on : ' . $this->modified_on, 0); } - $res = Database::query($sql); + Database::query($sql); return true; } @@ -5308,6 +5308,18 @@ class learnpath { $return .= '' . Display :: return_icon('upload_audio.png', get_lang('UpdateAllAudioFragments'),'',ICON_SIZE_MEDIUM).''; $return .= '' . Display :: return_icon('settings.png', get_lang('CourseSettings'),'',ICON_SIZE_MEDIUM).''; + + $buttons = array( + array( + 'title' => get_lang('SetPrerequisiteForEachItem'), + 'href' => 'lp_controller.php?'.api_get_cidreq().'&action=set_previous_step_as_prerequisite&lp_id=' . $_SESSION['oLP']->lp_id, + ), + array( + 'title' => get_lang('ClearAllPrerequisites'), + 'href' => 'lp_controller.php?'.api_get_cidreq().'&action=clear_prerequisites&lp_id=' . $_SESSION['oLP']->lp_id, + ), + ); + $return .= Display::group_button(get_lang('PrerequisitesOptions'), $buttons); $return .= '
'; echo $return; } @@ -7786,10 +7798,9 @@ class learnpath { $return .= get_lang('AddEditPrerequisites'); $return .= ''; - $return .= '
'; $return .= '
'; - $return .= ''; + $return .= '
'; $return .= ''; $return .= ''; $return .= ''; @@ -7837,6 +7848,9 @@ class learnpath { break; $return .= ''; $return .= ''; + //$return .= '
' . get_lang('LearnpathPrerequisites') . '' . get_lang('Minimum') . '
'; + + $return .= ''; $return .= ''; if ($arrLP[$i]['item_type'] == TOOL_QUIZ) { @@ -7874,10 +7889,8 @@ class learnpath { $return .= '
'; $return .= '
'; $return .= ''; - $return .= '
'; - $return .= '
'; - // $return .= '
'; + $return .= ''; return $return; } @@ -9220,6 +9233,50 @@ EOD; return false; } } + + function clear_prerequisites() { + $course_id = $this->get_course_int_id(); + if ($this->debug > 0) { + error_log('New LP - In learnpath::clear_prerequisites()', 0); + } + $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM); + $lp_id = $this->get_id(); + //Cleaning prerequisites + $sql = "UPDATE $tbl_lp_item SET prerequisite = '' + WHERE c_id = ".$course_id." AND lp_id = '$lp_id'"; + Database::query($sql); + + //Cleaning mastery score for exercises + $sql = "UPDATE $tbl_lp_item SET mastery_score = '' + WHERE c_id = ".$course_id." AND lp_id = '$lp_id' AND item_type = 'quiz'"; + Database::query($sql); + } + + function set_previous_step_as_prerequisite_for_all_items() { + $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM); + $course_id = $this->get_course_int_id(); + $lp_id = $this->get_id(); + + if (!empty($this->items)) { + $old_id = null; + $old_max = 0; + $old_type = null; + foreach ($this->items as $item) { + if (!empty($old_id)) { + $current_item_id = $item->get_id(); + if ($old_type == 'quiz') { + $sql = "UPDATE $tbl_lp_item SET mastery_score = '$old_max' WHERE c_id = ".$course_id." AND lp_id = '$lp_id' AND id = '$old_id'"; + Database::query($sql); + } + $sql = "UPDATE $tbl_lp_item SET prerequisite = '$old_id' WHERE c_id = ".$course_id." AND lp_id = '$lp_id' AND id = '$current_item_id'"; + Database::query($sql); + } + $old_id = $item->get_id(); + $old_max = $item->get_max(); + $old_type = $item->get_type(); + } + } + } } if (!function_exists('trim_value')) { diff --git a/main/newscorm/lp_add_item.php b/main/newscorm/lp_add_item.php index 32f6715947..e4420bf366 100644 --- a/main/newscorm/lp_add_item.php +++ b/main/newscorm/lp_add_item.php @@ -248,10 +248,14 @@ echo '
'; echo $_SESSION['oLP']->return_new_tree(null, true); +$message = isset($_REQUEST['message']) ? $_REQUEST['message'] : null; + // Show the template list. if ($type == 'document' && !isset($_GET['file'])) { // Show the template list. - echo '
';} + echo '
'; +} + echo '
'; //hide bar div @@ -261,6 +265,11 @@ if ($action == 'add_item' && $type == 'document' && !isset($_GET['file'])) { echo '
'; +//@todo use session flash messages +if (in_array($message, array('ItemUpdated'))) { + echo Display::return_message(get_lang($message)); +} + if (isset($new_item_id) && is_numeric($new_item_id)) { switch ($type) { case 'chapter': diff --git a/main/newscorm/lp_controller.php b/main/newscorm/lp_controller.php index 7d72ed93dc..daacdd41fe 100644 --- a/main/newscorm/lp_controller.php +++ b/main/newscorm/lp_controller.php @@ -100,6 +100,7 @@ $lpfound = false; $myrefresh = 0; $myrefresh_id = 0; + if (!empty($_SESSION['refresh']) && $_SESSION['refresh'] == 1) { // Check if we should do a refresh of the oLP object (for example after editing the LP). // If refresh is set, we regenerate the oLP object from the database (kind of flush). @@ -135,7 +136,6 @@ if (isset($_SESSION['lpobject'])) { } } - $course_id = api_get_course_int_id(); if ($debug>0) error_log('New LP - Passed data remains check', 0); @@ -224,8 +224,6 @@ if (isset($_GET['isStudentView']) && $_GET['isStudentView'] == 'true') { } } - - $action = (!empty($_REQUEST['action']) ? $_REQUEST['action'] : ''); switch ($action) { @@ -966,15 +964,24 @@ switch ($action) { require 'lp_list.php'; } else { if ($debug > 0) {error_log('New LP - Trying to impress this LP item to ' . $_REQUEST['item_id'], 0); } - if ( !empty($_REQUEST['item_id']) ) { + if (!empty($_REQUEST['item_id']) ) { $_SESSION['oLP']->set_current_item($_REQUEST['item_id']); } require 'lp_impress.php'; } break; + case 'set_previous_step_as_prerequisite': + $_SESSION['oLP']->set_previous_step_as_prerequisite_for_all_items(); + $url = api_get_self().'?action=add_item&type=step&lp_id='.intval($_SESSION['oLP']->lp_id)."&message=ItemUpdated"; + header('Location: '.$url); + break; + case 'clear_prerequisites': + $_SESSION['oLP']->clear_prerequisites(); + $url = api_get_self().'?action=add_item&type=step&lp_id='.intval($_SESSION['oLP']->lp_id)."&message=ItemUpdated"; + header('Location: '.$url); + break; default: if ($debug > 0) error_log('New LP - default action triggered', 0); - //$_SESSION['refresh'] = 1; require 'lp_list.php'; break; } diff --git a/main/survey/survey.lib.php b/main/survey/survey.lib.php index 7c1d51681f..ae27ca8155 100644 --- a/main/survey/survey.lib.php +++ b/main/survey/survey.lib.php @@ -3816,14 +3816,15 @@ class SurveyUtil { } $new_user = false; // User not already invited // Store the invitation if user_id not in $already_invited['course_users'] OR email is not in $already_invited['additional_users'] - $addit_users_array = explode(';', $already_invited['additional_users']); + $addit_users_array = isset($already_invited['additional_users']) && !empty($already_invited['additional_users']) ? explode(';', $already_invited['additional_users']) : array(); + $my_alredy_invited = ($already_invited['course_users'] == null) ? array() : $already_invited['course_users']; if ((is_numeric($value) && !in_array($value, $my_alredy_invited)) || (!is_numeric($value) && !in_array($value, $addit_users_array))) { $new_user = true; if (!array_key_exists($value, $survey_invitations)) { $sql = "INSERT INTO $table_survey_invitation (c_id, user, survey_code, invitation_code, invitation_date) VALUES ($course_id, '".Database::escape_string($value)."','".Database::escape_string($survey_data['code'])."','".Database::escape_string($invitation_code)."','".Database::escape_string(date('Y-m-d H:i:s'))."')"; - $result = Database::query($sql); + Database::query($sql); } } // Send the email if checkboxed @@ -3927,7 +3928,7 @@ class SurveyUtil { // Updating the field in the survey table $sql = "UPDATE $table_survey SET invited = '".Database::escape_string($total_invited)."' WHERE c_id = $course_id AND code = '".Database::escape_string($survey_code)."'"; - $result = Database::query($sql); + Database::query($sql); } /** @@ -3940,9 +3941,10 @@ class SurveyUtil { * @todo consider making $defaults['additional_users'] also an array * * @author Patrick Cool , Ghent University + * @author Julio Montoya, adding c_id fixes - Dec 2012 * @version January 2007 */ - static function get_invited_users($survey_code, $course_code = '') { + static function get_invited_users($survey_code, $course_code = '', $session_id = 0) { if (!empty($course_code)) { $course_info = api_get_course_info($course_code); $course_id = $course_info['real_id']; @@ -3950,32 +3952,53 @@ class SurveyUtil { $course_id = api_get_course_int_id(); } + if (empty($session_id)) { + $session_id = api_get_session_id(); + } + $table_survey_invitation = Database :: get_course_table(TABLE_SURVEY_INVITATION); - $table_user = Database :: get_main_table(TABLE_MAIN_USER); + $table_user = Database :: get_main_table(TABLE_MAIN_USER); // Selecting all the invitations of this survey AND the additional emailaddresses (the left join) $order_clause = api_sort_by_first_name() ? ' ORDER BY firstname, lastname' : ' ORDER BY lastname, firstname'; $sql = "SELECT user FROM $table_survey_invitation as table_invitation - LEFT JOIN $table_user as table_user - ON table_invitation.user = table_user.user_id AND table_invitation.c_id = $course_id - WHERE survey_code='".Database::escape_string($survey_code)."'".$order_clause; + WHERE table_invitation.c_id = $course_id AND + survey_code='".Database::escape_string($survey_code)."' AND + session_id = $session_id + + "; $defaults = array(); $defaults['course_users'] = array(); - $defaults['additional_users'] = ''; + $defaults['additional_users'] = array(); + $result = Database::query($sql); while ($row = Database::fetch_array($result)) { if (is_numeric($row['user'])) { $defaults['course_users'][] = $row['user']; } else { - if (empty($defaults['additional_users'])) { - $defaults['additional_users'] = $row['user']; - } else { - $defaults['additional_users'] .= ';'.$row['user']; - } + if (!empty($row['user'])) { + $defaults['additional_users'][] = $row['user']; + } } } + + if (!empty($defaults['course_users'])) { + $user_ids = implode("','", $defaults['course_users']); + $sql = "SELECT user_id FROM $table_user WHERE user_id IN ('$user_ids') $order_clause"; + $result = Database::query($sql); + $fixed_users = array(); + while ($row = Database::fetch_array($result)) { + $fixed_users[] = $row['user_id']; + } + $defaults['course_users'] = $fixed_users; + } + + if (!empty($defaults['additional_users'])) { + $defaults['additional_users'] = implode(';', $defaults['additional_users']); + } + //error_log(print_r($defaults, 1)); return $defaults; } @@ -4299,9 +4322,9 @@ class SurveyUtil { survey.survey_id AS col9, survey.session_id AS session_id FROM $table_survey survey - LEFT JOIN $table_survey_question survey_question ON survey.survey_id = survey_question.survey_id + LEFT JOIN $table_survey_question survey_question ON (survey.survey_id = survey_question.survey_id AND survey_question.c_id = $course_id) INNER JOIN $table_user user ON (survey.author = user.user_id) - WHERE survey.c_id = $course_id AND survey_question.c_id = $course_id + WHERE survey.c_id = $course_id $search_restriction $condition_session "; $sql .= " GROUP BY survey.survey_id"; diff --git a/main/survey/survey_invite.php b/main/survey/survey_invite.php index f36084a633..acdcea255c 100644 --- a/main/survey/survey_invite.php +++ b/main/survey/survey_invite.php @@ -94,14 +94,14 @@ if ($survey_data['invited'] > 0 && !isset($_POST['submit'])) { } // Building the form for publishing the survey -$form = new FormValidator('publish_form', 'post', api_get_self().'?survey_id='.$survey_id); +$form = new FormValidator('publish_form', 'post', api_get_self().'?survey_id='.$survey_id.'&'.api_get_cidReq()); $form->addElement('header', '', $tool_name); // Course users -$complete_user_list = CourseManager :: get_user_list_from_course_code($_course['id'], $_SESSION['id_session'], '', api_sort_by_first_name() ? 'ORDER BY firstname' : 'ORDER BY lastname'); +$complete_user_list = CourseManager::get_user_list_from_course_code(api_get_course_id(), api_get_session_id(), '', api_sort_by_first_name() ? 'ORDER BY firstname' : 'ORDER BY lastname'); $possible_users = array(); -foreach ($complete_user_list as $index => & $user) { +foreach ($complete_user_list as & $user) { $possible_users[$user['user_id']] = api_get_person_name($user['firstname'], $user['lastname']); } $users = $form->addElement('advmultiselect', 'course_users', get_lang('CourseUsers'), $possible_users, 'style="width: 250px; height: 200px;"'); @@ -119,15 +119,16 @@ $users->setElementTemplate(' '); $users->setButtonAttributes('add', array('class' => 'btn arrowr')); $users->setButtonAttributes('remove', array('class' => 'btn arrowl')); + // Additional users -$form->addElement('textarea', 'additional_users', array(get_lang('AdditonalUsers'), get_lang('AdditonalUsersComment')), array('class' => 'span6', 'rows' => 2)); +$form->addElement('textarea', 'additional_users', array(get_lang('AdditonalUsers'), get_lang('AdditonalUsersComment')), array('class' => 'span6', 'rows' => 5)); -//$form->addElement('html', '

'.Display::return_icon('course.png', Security::remove_XSS(get_lang('SendMail')),'',ICON_SIZE_SMALL).' '.Security::remove_XSS(get_lang('SendMail')).'

'); $form->addElement('html', '
'); $form->addElement('checkbox', 'send_mail','', get_lang('SendMail')); $form->addElement('html', '
'); $form->addElement('html', '
'); + // The title of the mail $form->addElement('text', 'mail_title', get_lang('MailTitle'), array('class' => 'span6')); // The text of the mail @@ -169,6 +170,7 @@ if ($form->validate()) { Display :: display_error_message(get_lang('FormHasErrorsPleaseComplete')); // Getting the invited users $defaults = SurveyUtil::get_invited_users($survey_data['code']); + // Getting the survey mail text if (!empty($survey_data['reminder_mail'])) { $defaults['mail_text'] = $survey_data['reminder_mail']; @@ -211,11 +213,12 @@ if ($form->validate()) { $message .= ''.$total_invited.' '; $message .= get_lang('WereInvited'); Display::display_normal_message($message, false); - Display :: display_confirmation_message($total_count.' '.get_lang('InvitationsSend')); + Display::display_confirmation_message($total_count.' '.get_lang('InvitationsSend')); } } else { // Getting the invited users $defaults = SurveyUtil::get_invited_users($survey_data['code']); + // Getting the survey mail text if (!empty($survey_data['reminder_mail'])) { $defaults['mail_text'] = $survey_data['reminder_mail']; @@ -224,6 +227,7 @@ if ($form->validate()) { } $defaults['mail_title'] = $survey_data['mail_subject']; $defaults['send_mail'] = 1; + $form->setDefaults($defaults); $form->display(); } diff --git a/main/tracking/exams.php b/main/tracking/exams.php index f79645937d..1aafe061b2 100644 --- a/main/tracking/exams.php +++ b/main/tracking/exams.php @@ -16,7 +16,7 @@ $this_section = SECTION_TRACKING; $is_allowedToTrack = $is_courseAdmin || $is_platformAdmin || $is_courseCoach || $is_sessionAdmin; -if(!$is_allowedToTrack) { +if(!$is_allowedToTrack) { api_not_allowed(); } @@ -27,25 +27,25 @@ if (isset($_GET['export'])) { $tbl_stats_exercices = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES); -if (api_is_platform_admin() ) { +if (api_is_platform_admin() ) { $global = true; } else { $global = false; } if ($global) { - $temp_course_list = CourseManager :: get_courses_list(); + $temp_course_list = CourseManager :: get_courses_list(); foreach($temp_course_list as $temp_course_item) { - $course_item = CourseManager ::get_course_information($temp_course_item['code']); + $course_item = CourseManager ::get_course_information($temp_course_item['code']); $course_list[]= array( 'db_name' => $course_item['db_name'], 'code' => $course_item['code'], 'real_id' => $course_item['real_id'], - 'title' => $course_item['title']); + 'title' => $course_item['title']); } -} else { +} else { $current_course['db_name'] = $_course['dbName']; $current_course['real_id'] = $_course['real_id']; - $current_course['code'] = $_course['id']; + $current_course['code'] = $_course['id']; $course_list = array($current_course); } @@ -58,15 +58,15 @@ if ($global) { $t_quiz = Database::get_course_table(TABLE_QUIZ_TEST); $course_id = api_get_course_int_id(); $sqlExercices = " SELECT quiz.title,id FROM ".$t_quiz." AS quiz WHERE c_id = $course_id AND active='1' ORDER BY quiz.title ASC"; - $resultExercices = Database::query($sqlExercices); + $resultExercices = Database::query($sqlExercices); $exercise_list[0] = get_lang('All'); while($a_exercices = Database::fetch_array($resultExercices)) { $exercise_list[$a_exercices['id']] = $a_exercices['title']; - } - + } + $form->addElement('select', 'exercise_id', get_lang('Exercise'), $exercise_list); } - + //$form->addElement('submit','submit',get_lang('Filter')); $form->addElement('style_submit_button','submit', get_lang('Filter'),'class="search"' ); @@ -80,16 +80,16 @@ if (!$export_to_xls) { Display :: display_header(get_lang('Reporting')); echo '
'; if ($global) { - + echo ''. Display::return_icon('stats.png', get_lang('MyStats'),'',ICON_SIZE_MEDIUM); echo ''; - + echo ''; echo ''.Display::return_icon('export_excel.png',get_lang('ExportAsXLS'),'',ICON_SIZE_MEDIUM).''; - echo ''.Display::return_icon('printer.png',get_lang('Print'),'',ICON_SIZE_MEDIUM).''; + echo ''.Display::return_icon('printer.png',get_lang('Print'),'',ICON_SIZE_MEDIUM).''; echo ''; - + $menu_items[] = Display::url(Display::return_icon('teacher.png', get_lang('TeacherInterface'), array(), 32), api_get_path(WEB_CODE_PATH).'mySpace/?view=teacher'); if (api_is_platform_admin()) { $menu_items[] = Display::url(Display::return_icon('star.png', get_lang('AdminInterface'), array(), 32), api_get_path(WEB_CODE_PATH).'mySpace/?view=admin'); @@ -97,24 +97,24 @@ if (!$export_to_xls) { $menu_items[] = Display::url(Display::return_icon('star.png', get_lang('CoachInterface'), array(), 32), api_get_path(WEB_CODE_PATH).'mySpace/?view=coach'); } $menu_items[] = Display::return_icon('quiz_na.png', get_lang('ExamTracking'), array(), 32); - + $nb_menu_items = count($menu_items); if($nb_menu_items>1) { foreach($menu_items as $key=> $item) { - echo $item; + echo $item; } } } else { - echo ''.get_lang('StudentsTracking').' | + echo ''.get_lang('StudentsTracking').' | '.get_lang('CourseTracking').' | '; echo ''.get_lang('ResourcesTracking').''; echo ' | '.get_lang('ExamTracking').''; - echo ' '.get_lang('ExportAsXLS').''; - - } + echo ' '.get_lang('ExportAsXLS').''; + + } echo '
'; - - $form->display(); + + $form->display(); echo '

'.sprintf(get_lang('FilteringWithScoreX'), $filter_score).'%

'; } @@ -128,10 +128,10 @@ if ($global) { $html_result .= ''.get_lang('ExamFail').''; $html_result .= ''.get_lang('TotalStudents').''; $html_result .= ''; -} else { - $html_result .= ''; +} else { + $html_result .= '
'; $html_result .= ''; - $html_result .= ''; + $html_result .= ''; //$html_result .= ''; $html_result .= ''; $html_result .= ''; @@ -146,14 +146,14 @@ if(!empty($course_list) && is_array($course_list)) foreach ($course_list as $current_course) { $global_row = $row_not_global = array(); $course_id = $current_course['real_id']; - - $a_students = CourseManager :: get_student_list_from_course_code($current_course['code'], false); + + $a_students = CourseManager :: get_student_list_from_course_code($current_course['code'], false); $total_students = count($a_students); - + $sqlExercices = "SELECT count(id) as count FROM ".$t_quiz." AS quiz WHERE active='1' AND c_id = $course_id "; $resultExercices = Database::query($sqlExercices); $data_exercises = Database::store_result($resultExercices); - $exercise_count = $data_exercises[0]['count']; + $exercise_count = $data_exercises[0]['count']; if ($global) { if ($exercise_count == 0) { $exercise_count = 2; @@ -161,25 +161,25 @@ foreach ($course_list as $current_course) { $html_result .= ""; + $html_result .= ""; } - + $sql = "SELECT visibility FROM $table WHERE c_id = $course_id AND name='quiz'"; $resultVisibilityQuizz = Database::query($sql); - - if (Database::result($resultVisibilityQuizz, 0 ,'visibility') == 1) { - $sqlExercices = " SELECT quiz.title,id FROM ".$t_quiz." AS quiz WHERE c_id = $course_id AND active='1' ORDER BY quiz.title ASC"; + + if (Database::result($resultVisibilityQuizz, 0 ,'visibility') == 1) { + $sqlExercices = " SELECT quiz.title,id FROM ".$t_quiz." AS quiz WHERE c_id = $course_id AND active='1' ORDER BY quiz.title ASC"; //Getting the exam list if (!$global) { if (!empty($exercise_id)) { - $sqlExercices = " SELECT quiz.title,id FROM ".$t_quiz." AS quiz WHERE c_id = $course_id AND active='1' AND id = $exercise_id ORDER BY quiz.title ASC"; + $sqlExercices = " SELECT quiz.title,id FROM ".$t_quiz." AS quiz WHERE c_id = $course_id AND active='1' AND id = $exercise_id ORDER BY quiz.title ASC"; } - } + } $resultExercices = Database::query($sqlExercices); $i = 0; - if (Database::num_rows($resultExercices) > 0) { + if (Database::num_rows($resultExercices) > 0) { while($a_exercices = Database::fetch_array($resultExercices)) { - $global_row[]= $current_course['title']; + $global_row[]= $current_course['title']; if (!$global) { $html_result .= ""; } @@ -187,36 +187,36 @@ foreach ($course_list as $current_course) { $html_result .= ''; - + } + + $html_result .= $a_exercices['title']; + $html_result .= ''; + $global_row[]=$a_exercices['title']; $row_not_global['exercise']= $a_exercices['title']; - + $taken = 0; $total_with_parameter = 0; $fail = 0; $not_taken = 0; - + $total_with_parameter_score = 0; $total_with_parameter_porcentage = 0; - - $student_result = array(); - - foreach ($a_students as $student ) { + + $student_result = array(); + + foreach ($a_students as $student ) { $current_student_id = $student['user_id']; $sqlEssais = " SELECT COUNT(ex.exe_id) as essais FROM $tbl_stats_exercices AS ex WHERE ex.exe_cours_id = '".$current_course['code']."' AND ex.exe_exo_id = ".$a_exercices['id']." AND exe_user_id='".$current_student_id."'"; - - - $resultEssais = Database::query($sqlEssais); - $a_essais = Database::fetch_array($resultEssais); - + + + $resultEssais = Database::query($sqlEssais); + $a_essais = Database::fetch_array($resultEssais); + $sqlScore = "SELECT exe_id, exe_result,exe_weighting FROM $tbl_stats_exercices WHERE exe_user_id = ".$current_student_id." @@ -224,42 +224,42 @@ foreach ($course_list as $current_course) { AND exe_exo_id = ".$a_exercices['id']." ORDER BY exe_result DESC LIMIT 1"; // we take the higher value //ORDER BY exe_date DESC LIMIT 1"; - + $resultScore = Database::query($sqlScore); $score = 0; - + while($a_score = Database::fetch_array($resultScore)) { $score = $score + $a_score['exe_result']; $weighting = $weighting + $a_score['exe_weighting']; $exe_id = $a_score['exe_id']; } - + $pourcentageScore = 0; if ($weighting!=0) { $pourcentageScore = round(($score*100)/$weighting); } - - $weighting = 0; - + + $weighting = 0; + if($i%2==0){ $s_css_class="row_odd"; } else { $s_css_class="row_even"; - } + } $i++; - + /*echo " "; */ - + //var_dump($pourcentageScore); /* echo " "; - + echo "'; - $user_info = $user_info['firstName'].' '.$user_info['lastName']; - - //Best result + $user_info = $user_info['firstName'].' '.$user_info['lastName']; + + //Best result if (!empty($a_essais['essais'])) { $user_row .= ''; - + if ($pourcentageScore >= $filter_score ) { $user_row .= ''; @@ -317,34 +305,34 @@ foreach ($course_list as $current_course) { $user_row .= get_lang('ExamFail').''; $temp_array [] = get_lang('ExamFail'); } - - $user_row .= ''; + $user_row .= ''; } else { $score = '-'; $user_row .= ''; - - $user_row .= ''; - $user_row .= ''; - } + } $user_row .= ''; - $student_result[$current_student_id] = array('html'=>$user_row,'score'=>$score,'array'=>$temp_array,'user'=>$user_info); + $student_result[$current_student_id] = array('html'=>$user_row,'score'=>$score,'array'=>$temp_array,'user'=>$user_info); $temp_array = array(); } } - - if (!$global) { + + if (!$global) { if (!empty($student_result)) { $student_result_empty = $student_result_content = array(); foreach($student_result as $row) { @@ -357,11 +345,11 @@ foreach ($course_list as $current_course) { //Sort only users with content usort($student_result_content, 'sort_user'); $student_result = array_merge($student_result_content, $student_result_empty ); - + foreach($student_result as $row) { $html_result .=$row['html']; $row_not_global['results'][]= $row['array']; - $row_not_global['users'][] = $row['user']; + $row_not_global['users'][] = $row['user']; } $export_array[] = $row_not_global; $row_not_global = array(); @@ -369,69 +357,69 @@ foreach ($course_list as $current_course) { } if ($global) { //Exam taken - $html_result .= ''; - - //Exam NOT taken - $html_result .= ''; - + //Examn pass if (!empty($total_with_parameter_score)) { $html_result .= ''; - - //Exam fail + + //Exam fail $html_result .= ''; - + $html_result .= ''; - $html_result .= ''; + $html_result .= ''; + $html_result .= ''; $export_array_global[] = $global_row; - $global_row = array(); + $global_row = array(); } } } else { - $html_result .= " + $html_result .= " "; - } + } } else { - $html_result .= " + $html_result .= " "; - } + } } $html_result .= '
'.get_lang('Quiz').''.get_lang('User').''.get_lang('User').''.sprintf(get_lang('ExamPassX'), $filter_score).''.get_lang('Percentage').' %'.get_lang('Status').'
"; $html_result .= $current_course['title']; - $html_result .= "
'; } else { $html_result .= ''; - } - - $html_result .= $a_exercices['title']; - $html_result .= ' "; echo $current_student_id.' '; echo " "; echo $pourcentageScore.' %'; echo " "; /* @@ -267,47 +267,35 @@ foreach ($course_list as $current_course) { echo " ";*/ - + if ($a_essais['essais'] > 0 ) { - $taken++; + $taken++; } - + if ($pourcentageScore >= $parameter_porcentage) { $total_with_parameter_porcentage++; } if ($pourcentageScore >= $filter_score) { - $total_with_parameter_score++; - } - - /* - $sql_last_attempt='SELECT exe_id FROM '.$tbl_stats_exercices.' WHERE exe_exo_id="'.$a_exercices['id'].'" AND exe_user_id="'.$current_student_id.'" AND exe_cours_id="'.$current_course['code'].'" ORDER BY exe_date DESC LIMIT 1'; - $resultLastAttempt = Database::query($sql_last_attempt); - if(Database::num_rows($resultLastAttempt)>0) { - $id_last_attempt=Database::result($resultLastAttempt,0,0); - if($a_essais['essais']>0) { - /// echo ' '; - } - } - */ - - + $total_with_parameter_score++; + } + if (!$global) { - $user_info = api_get_user_info($current_student_id); - + $user_info = api_get_user_info($current_student_id); + //User - $user_row = ''; + $user_row = ''; $user_row .= $user_info['firstName'].' '.$user_info['lastName']; $user_row .= ''; - $user_row .= $pourcentageScore; - $temp_array [] = $pourcentageScore; + $user_row .= $pourcentageScore; + $temp_array [] = $pourcentageScore; $user_row .= ''; $user_row .= get_lang('PassExam').''; + + $user_row .= ''; $user_row .= $a_essais['essais']; $temp_array [] = $a_essais['essais']; - $user_row .= ''; $user_row .= '-'; $temp_array [] = '-'; $user_row .= ''; + + $user_row .= ''; $user_row .= get_lang('NoAttempt'); $temp_array [] = get_lang('NoAttempt'); $user_row .= ''; + $user_row .= ''; $user_row .= 0; $temp_array [] = 0; $user_row .= '
'; + $html_result .= ''; $html_result .= $taken; $global_row[]= $taken; //echo $total.' / '.$total_students; $html_result .= ''; + + //Exam NOT taken + $html_result .= ''; $html_result .= $not_taken = $total_students - $taken; $global_row[]= $not_taken; $html_result .= ''; } else { $html_result .= ''; } - + $html_result .= $total_with_parameter_score; $global_row[]= $total_with_parameter_score; $html_result .= ''; $html_result .= $fail = $taken - $total_with_parameter_score; $global_row[]= $fail; $html_result .= ''; $html_result .= $total_students; $global_row[]= $total_students; - + $global_counter++; - $html_result .= '
".get_lang('NoExercise')."
".get_lang('NoExercise')."
'; if (!$export_to_xls) { - echo $html_result; + echo $html_result; } $filename = 'exam-reporting-'.date('Y-m-d-h:i:s').'.xls'; if ($export_to_xls) { @@ -451,10 +439,10 @@ function sort_user($a, $b) { } return 0; } - return 1; + return 1; } -function export_complete_report_xls($filename, $array) { +function export_complete_report_xls($filename, $array) { global $charset, $global, $filter_score; $workbook = new Spreadsheet_Excel_Writer(); $workbook ->setTempDir(api_get_path(SYS_ARCHIVE_PATH)); @@ -462,18 +450,18 @@ function export_complete_report_xls($filename, $array) { $workbook->setVersion(8); // BIFF8 $worksheet =& $workbook->addWorksheet('Report'); //$worksheet->setInputEncoding(api_get_system_encoding()); - $worksheet->setInputEncoding($charset); - + $worksheet->setInputEncoding($charset); + $line = 0; $column = 0; //skip the first column (row titles) - + if ($global) { $worksheet->write($line,$column,get_lang('Courses')); $column++; $worksheet->write($line,$column,get_lang('Exercises')); $column++; $worksheet->write($line,$column,get_lang('ExamTaken')); - $column++; + $column++; $worksheet->write($line,$column,get_lang('ExamNotTaken')); $column++; $worksheet->write($line,$column,sprintf(get_lang('ExamPassX'), $filter_score).'%'); @@ -481,45 +469,45 @@ function export_complete_report_xls($filename, $array) { $worksheet->write($line,$column,get_lang('ExamFail')); $column++; $worksheet->write($line,$column,get_lang('TotalStudents')); - $column++; - $line++; + $column++; + $line++; foreach ($array as $row) { $column = 0; - foreach ($row as $item) { + foreach ($row as $item) { $worksheet->write($line,$column,html_entity_decode(strip_tags($item))); $column++; } $line++; - } - $line++; + } + $line++; } else { $worksheet->write($line,$column,get_lang('Exercises')); $column++; $worksheet->write($line,$column,get_lang('User')); $column++; $worksheet->write($line,$column,get_lang('Percentage')); - $column++; + $column++; $worksheet->write($line,$column,get_lang('Status')); $column++; $worksheet->write($line,$column,get_lang('Attempts')); - $column++; - $line++; - foreach ($array as $row) { + $column++; + $line++; + foreach ($array as $row) { $column = 0; $worksheet->write($line,$column,html_entity_decode(strip_tags($row['exercise']))); $column++; foreach ($row['users'] as $key=>$user) { - $column = 1; + $column = 1; $worksheet->write($line,$column,html_entity_decode(strip_tags($user))); - $column++; + $column++; foreach ($row['results'][$key] as $result_item) { $worksheet->write($line,$column,html_entity_decode(strip_tags($result_item))); - $column++; + $column++; } - $line++; - } - } - $line++; + $line++; + } + } + $line++; } $workbook->close(); exit;