From e1d02d4346ce9663d50e41578e09bb47c7a179be Mon Sep 17 00:00:00 2001 From: jmontoyaa Date: Tue, 4 Oct 2016 11:58:26 +0200 Subject: [PATCH 01/87] Fix null mysql error --- main/exercise/exercise_report.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main/exercise/exercise_report.php b/main/exercise/exercise_report.php index 1a07e4b2cb..19ff4d4304 100755 --- a/main/exercise/exercise_report.php +++ b/main/exercise/exercise_report.php @@ -175,7 +175,7 @@ if (isset($_REQUEST['comments']) && } for ($i = 0; $i < $loop_in_track; $i++) { - $my_marks = $_POST['marks_'.$array_content_id_exe[$i]]; + $my_marks = isset($_POST['marks_'.$array_content_id_exe[$i]]) ? $_POST['marks_'.$array_content_id_exe[$i]] : ''; $contain_comments = $_POST['comments_'.$array_content_id_exe[$i]]; if (isset($contain_comments)) { $my_comments = $_POST['comments_'.$array_content_id_exe[$i]]; From 5f1ccfa27ebe60d28cb7359c3497bd3bfb097e30 Mon Sep 17 00:00:00 2001 From: jmontoyaa Date: Tue, 4 Oct 2016 13:48:53 +0200 Subject: [PATCH 02/87] Rename variable name $showTotalScoreAndUserChoicesInLastAttempt --- main/exercise/exercise.class.php | 73 ++++++++++++++++++-------------- main/exercise/exercise_show.php | 35 ++++++--------- 2 files changed, 53 insertions(+), 55 deletions(-) diff --git a/main/exercise/exercise.class.php b/main/exercise/exercise.class.php index c8cd79b56b..a107a6b9d4 100755 --- a/main/exercise/exercise.class.php +++ b/main/exercise/exercise.class.php @@ -3095,7 +3095,7 @@ class Exercise * @param bool $show_result show results or not * @param int $propagate_neg * @param array $hotspot_delineation_result - * @param boolean $showTotalScoreAndUserChoices + * @param boolean $showTotalScoreAndUserChoicesInLastAttempt * @todo reduce parameters of this function * @return string html code */ @@ -3110,7 +3110,7 @@ class Exercise $show_result = true, $propagate_neg = 0, $hotspot_delineation_result = array(), - $showTotalScoreAndUserChoices = false + $showTotalScoreAndUserChoicesInLastAttempt = true ) { global $debug; //needed in order to use in the exercise_attempt() for the time @@ -3187,9 +3187,6 @@ class Exercise $totalWeighting = 0; $totalScore = 0; - // Destruction of the Question object - //unset($objQuestionTmp); - // Construction of the Answer object $objAnswerTmp = new Answer($questionId); $nbrAnswers = $objAnswerTmp->selectNbrAnswers(); @@ -3894,12 +3891,13 @@ class Exercise //no break case MATCHING: if ($from_database) { - $sql = 'SELECT id, answer, id_auto - FROM '.$table_ans.' + $sql = "SELECT id, answer, id_auto + FROM $table_ans WHERE - c_id = '.$course_id.' AND - question_id = "'.$questionId.'" AND - correct = 0'; + c_id = $course_id AND + question_id = $questionId AND + correct = 0 + "; $res_answer = Database::query($sql); // Getting the real answer $real_list = array(); @@ -3907,13 +3905,13 @@ class Exercise $real_list[$real_answer['id_auto']] = $real_answer['answer']; } - $sql = 'SELECT id, answer, correct, id_auto, ponderation - FROM '.$table_ans.' + $sql = "SELECT id, answer, correct, id_auto, ponderation + FROM $table_ans WHERE - c_id = '.$course_id.' AND - question_id="'.$questionId.'" AND + c_id = $course_id AND + question_id = $questionId AND correct <> 0 - ORDER BY id_auto'; + ORDER BY id_auto"; $res_answers = Database::query($sql); $questionScore = 0; @@ -3956,9 +3954,20 @@ class Exercise $questionScore += $i_answerWeighting; $totalScore += $i_answerWeighting; + // Try with id if (isset($real_list[$i_answer_id])) { $user_answer = Display::span($real_list[$i_answer_id]); } + + + // Try with $i_answer_id_auto + if (empty($user_answer)) { + if (isset($real_list[$i_answer_id_auto])) { + $user_answer = Display::span( + $real_list[$i_answer_id_auto] + ); + } + } } else { $user_answer = Display::span( $real_list[$s_user_answer], @@ -3971,7 +3980,7 @@ class Exercise } if ($show_result) { - if ($showTotalScoreAndUserChoices == true) { + if ($showTotalScoreAndUserChoicesInLastAttempt == false) { $user_answer = ''; } echo ''; @@ -3979,7 +3988,7 @@ class Exercise echo '' . $user_answer; if (in_array($answerType, [MATCHING, MATCHING_DRAGGABLE])) { - if (isset($real_list[$i_answer_correct_answer]) && $showTotalScoreAndUserChoices == false) { + if (isset($real_list[$i_answer_correct_answer]) && $showTotalScoreAndUserChoicesInLastAttempt == true) { echo Display::span( $real_list[$i_answer_correct_answer], ['style' => 'color: #008000; font-weight: bold;'] @@ -4209,7 +4218,7 @@ class Exercise 0, 0, $results_disabled, - $showTotalScoreAndUserChoices + $showTotalScoreAndUserChoicesInLastAttempt ); } elseif ($answerType == MULTIPLE_ANSWER_TRUE_FALSE) { ExerciseShowFunctions::display_multiple_answer_true_false( @@ -4223,7 +4232,7 @@ class Exercise $questionId, 0, $results_disabled, - $showTotalScoreAndUserChoices + $showTotalScoreAndUserChoicesInLastAttempt ); } elseif ($answerType == MULTIPLE_ANSWER_COMBINATION_TRUE_FALSE ) { ExerciseShowFunctions::display_multiple_answer_combination_true_false( @@ -4237,7 +4246,7 @@ class Exercise 0, 0, $results_disabled, - $showTotalScoreAndUserChoices + $showTotalScoreAndUserChoicesInLastAttempt ); } elseif ($answerType == FILL_IN_BLANKS) { ExerciseShowFunctions::display_fill_in_blanks_answer( @@ -4247,7 +4256,7 @@ class Exercise 0, $results_disabled, '', - $showTotalScoreAndUserChoices + $showTotalScoreAndUserChoicesInLastAttempt ); } elseif ($answerType == CALCULATED_ANSWER) { ExerciseShowFunctions::display_calculated_answer( @@ -4256,7 +4265,7 @@ class Exercise 0, 0, $results_disabled, - $showTotalScoreAndUserChoices + $showTotalScoreAndUserChoicesInLastAttempt ); } elseif ($answerType == FREE_ANSWER) { ExerciseShowFunctions::display_free_answer( @@ -4293,7 +4302,7 @@ class Exercise $answerComment, $results_disabled, $answerId, - $showTotalScoreAndUserChoices + $showTotalScoreAndUserChoicesInLastAttempt ); } elseif ($answerType == HOT_SPOT_ORDER) { ExerciseShowFunctions::display_hotspot_order_answer( @@ -4497,7 +4506,7 @@ class Exercise $questionId, $answerId, $results_disabled, - $showTotalScoreAndUserChoices + $showTotalScoreAndUserChoicesInLastAttempt ); } else { ExerciseShowFunctions::display_unique_or_multiple_answer( @@ -4511,7 +4520,7 @@ class Exercise $questionId, '', $results_disabled, - $showTotalScoreAndUserChoices + $showTotalScoreAndUserChoicesInLastAttempt ); } break; @@ -4528,7 +4537,7 @@ class Exercise $questionId, $answerId, $results_disabled, - $showTotalScoreAndUserChoices + $showTotalScoreAndUserChoicesInLastAttempt ); } else { ExerciseShowFunctions::display_multiple_answer_combination_true_false( @@ -4542,7 +4551,7 @@ class Exercise $questionId, '', $results_disabled, - $showTotalScoreAndUserChoices + $showTotalScoreAndUserChoicesInLastAttempt ); } break; @@ -4559,7 +4568,7 @@ class Exercise $questionId, $answerId, $results_disabled, - $showTotalScoreAndUserChoices + $showTotalScoreAndUserChoicesInLastAttempt ); } else { ExerciseShowFunctions::display_multiple_answer_true_false( @@ -4573,7 +4582,7 @@ class Exercise $questionId, '', $results_disabled, - $showTotalScoreAndUserChoices + $showTotalScoreAndUserChoicesInLastAttempt ); } break; @@ -4585,7 +4594,7 @@ class Exercise $questionId, $results_disabled, $str, - $showTotalScoreAndUserChoices + $showTotalScoreAndUserChoicesInLastAttempt ); break; case CALCULATED_ANSWER: @@ -4596,7 +4605,7 @@ class Exercise $questionId, $results_disabled, '', - $showTotalScoreAndUserChoices + $showTotalScoreAndUserChoicesInLastAttempt ); break; case FREE_ANSWER: @@ -4631,7 +4640,7 @@ class Exercise $answerComment, $results_disabled, $answerId, - $showTotalScoreAndUserChoices + $showTotalScoreAndUserChoicesInLastAttempt ); break; case HOT_SPOT_DELINEATION: diff --git a/main/exercise/exercise_show.php b/main/exercise/exercise_show.php index 87643f91a3..450a5d8796 100755 --- a/main/exercise/exercise_show.php +++ b/main/exercise/exercise_show.php @@ -196,7 +196,7 @@ if ($origin != 'learnpath') { - - '; - Display::display_warning_message( - get_lang('ThankYouForPassingTheTest') . '

' . (get_lang('BackToExercisesList')) . '', - false - ); - echo ' - - ';*/ - } } elseif ($result_disabled == RESULT_DISABLE_SHOW_SCORE_ONLY) { $show_results = false; $show_only_total_score = true; @@ -245,11 +232,13 @@ if (!empty($track_exercise_info)) { if ($numberAttempts >= $track_exercise_info['max_attempt']) { $show_results = true; $show_only_total_score = true; - $showTotalScoreAndUserChoices = false; + // Attempt reach max so show score/feedback now + $showTotalScoreAndUserChoicesInLastAttempt = true; } else { $show_results = true; $show_only_total_score = true; - $showTotalScoreAndUserChoices = true; + // Last attempt not reach don't show score/feedback + $showTotalScoreAndUserChoicesInLastAttempt = false; } } } @@ -266,7 +255,7 @@ if ($is_allowedToEdit && in_array($action, ['qualify', 'edit'])) { $show_results = true; } -if ($show_results || $show_only_total_score || $showTotalScoreAndUserChoices) { +if ($show_results || $show_only_total_score || $showTotalScoreAndUserChoicesInLastAttempt) { $user_info = api_get_user_info($student_id); //Shows exercise header echo $objExercise->show_exercise_result_header( @@ -411,13 +400,13 @@ foreach ($questionList as $questionId) { $show_results, $objExercise->selectPropagateNeg(), [], - $showTotalScoreAndUserChoices + $showTotalScoreAndUserChoicesInLastAttempt ); $questionScore = $question_result['score']; $totalScore += $question_result['score']; break; case HOT_SPOT: - if ($show_results || $showTotalScoreAndUserChoices) { + if ($show_results || $showTotalScoreAndUserChoicesInLastAttempt) { echo ''); + $defaults["counter[$i]"] = '-'; $defaults['answer[' . $i . ']'] = get_lang('DontKnow'); - $defaults['weighting[' . $i . ']'] = 0; + $defaults['weighting[' . $i . ']'] = '0'; $defaults['scenario'] = $temp_scenario; $renderer = & $form->defaultRenderer(); @@ -235,12 +236,13 @@ class UniqueAnswerNoOption extends Question 'weighting[' . $i . ']' ); - $answer_number = $form->addElement('text', 'counter[' . $i . ']', null, 'value="-"'); - $answer_number->freeze(); + $form + ->addElement('text', 'counter[' . $i . ']', null) + ->freeze(); $form->addElement('hidden', 'position[' . $i . ']', '666'); - $form->addElement('radio', 'correct', null, null, $i, 'class="checkbox" style="margin-left: 0em;"'); + $form->addElement('radio', 'correct', null, null, $i, ['class' => 'checkbox', 'disabled' => true]); $form->addElement('html_editor', 'answer[' . $i . ']', null, array(), $editor_config); $form->addRule('answer[' . $i . ']', get_lang('ThisFieldIsRequired'), 'required'); @@ -248,7 +250,9 @@ class UniqueAnswerNoOption extends Question //$form->addElement('select', 'destination'.$i, get_lang('SelectQuestion').' : ',$select_question,'multiple'); - $form->addText("weighting[$i]", null, false, ['style' => 'width: 60px;', 'value' => 0, 'readonly' => 'readonly']); + $form + ->addElement('text', "weighting[$i]", null) + ->freeze(); $form->addHTml(''); $form->addHtml('
'; @@ -433,7 +422,7 @@ foreach ($questionList as $questionId) { $show_results, $objExercise->selectPropagateNeg(), [], - $showTotalScoreAndUserChoices + $showTotalScoreAndUserChoicesInLastAttempt ); $questionScore = $question_result['score']; $totalScore += $question_result['score']; @@ -476,7 +465,7 @@ foreach ($questionList as $questionId) { $objExercise->selectPropagateNeg(), 'database', [], - $showTotalScoreAndUserChoices + $showTotalScoreAndUserChoicesInLastAttempt ); $questionScore = $question_result['score']; @@ -821,7 +810,7 @@ $total_score_text = null; //Total score if ($origin != 'learnpath' || ($origin == 'learnpath' && isset($_GET['fb_type']))) { - if ($show_results || $show_only_total_score || $showTotalScoreAndUserChoices) { + if ($show_results || $show_only_total_score || $showTotalScoreAndUserChoicesInLastAttempt) { $total_score_text .= '
'; $my_total_score_temp = $totalScore; if ($objExercise->selectPropagateNeg() == 0 && $my_total_score_temp < 0) { @@ -837,7 +826,7 @@ if ($origin != 'learnpath' || ($origin == 'learnpath' && isset($_GET['fb_type']) } } -if (!empty($category_list) && ($show_results || $show_only_total_score || $showTotalScoreAndUserChoices)) { +if (!empty($category_list) && ($show_results || $show_only_total_score || $showTotalScoreAndUserChoicesInLastAttempt)) { // Adding total $category_list['total'] = array( 'score' => $my_total_score_temp, From 495228c2689ea9a62f5f6aff34f827a01d1b2c10 Mon Sep 17 00:00:00 2001 From: jmontoyaa Date: Tue, 4 Oct 2016 13:52:28 +0200 Subject: [PATCH 03/87] Rename $showTotalScoreAndUserChoicesInLastAttempt --- main/inc/lib/exercise.lib.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/main/inc/lib/exercise.lib.php b/main/inc/lib/exercise.lib.php index 75cd9cad62..b52feb49e4 100644 --- a/main/inc/lib/exercise.lib.php +++ b/main/inc/lib/exercise.lib.php @@ -3527,7 +3527,7 @@ HOTSPOT; $show_only_score = false; } - $show_total_score_and_user_choices = false; + $showTotalScoreAndUserChoicesInLastAttempt = true; if ($objExercise->results_disabled == RESULT_DISABLE_SHOW_SCORE_ATTEMPT_SHOW_ANSWERS_LAST_ATTEMPT) { $show_only_score = true; @@ -3555,9 +3555,9 @@ HOTSPOT; if ($numberAttempts >= $objExercise->attempts) { $show_results = true; $show_only_score = false; - $show_total_score_and_user_choices = false; + $showTotalScoreAndUserChoicesInLastAttempt = true; } else { - $show_total_score_and_user_choices = true; + $showTotalScoreAndUserChoicesInLastAttempt = false; } } } @@ -3609,7 +3609,7 @@ HOTSPOT; $show_results, $objExercise->selectPropagateNeg(), [], - $show_total_score_and_user_choices + $showTotalScoreAndUserChoicesInLastAttempt ); if (empty($result)) { From 5787a9af1c37d52bd3b47c1185dac4490370f4c3 Mon Sep 17 00:00:00 2001 From: jmontoyaa Date: Tue, 4 Oct 2016 15:38:58 +0200 Subject: [PATCH 04/87] Add question preview when click "see as student" see BT#11764 --- main/exercise/admin.php | 50 ++++++++++++++++++++++---------- main/exercise/exercise.class.php | 1 - 2 files changed, 35 insertions(+), 16 deletions(-) diff --git a/main/exercise/admin.php b/main/exercise/admin.php index 1b04105bfe..3598a28b42 100755 --- a/main/exercise/admin.php +++ b/main/exercise/admin.php @@ -54,15 +54,16 @@ $this_section = SECTION_COURSES; // Access control api_protect_course_script(true); -$is_allowedToEdit = api_is_allowed_to_edit(null,true); +$is_allowedToEdit = api_is_allowed_to_edit(null, true, false, false); $sessionId = api_get_session_id(); +$studentViewActive = api_is_student_view_active(); if (!$is_allowedToEdit) { api_not_allowed(true); } /* stripslashes POST data */ -if($_SERVER['REQUEST_METHOD'] == 'POST') { +if ($_SERVER['REQUEST_METHOD'] == 'POST') { foreach($_POST as $key=>$val) { if(is_string($val)) { $_POST[$key]=stripslashes($val); @@ -78,15 +79,15 @@ if($_SERVER['REQUEST_METHOD'] == 'POST') { if (empty($exerciseId)) { $exerciseId = isset($_GET['exerciseId']) ? intval($_GET['exerciseId']):'0'; } -if (empty($newQuestion)) { - $newQuestion = isset($_GET['newQuestion']) ? $_GET['newQuestion'] : 0; -} + +$newQuestion = isset($_GET['newQuestion']) ? $_GET['newQuestion'] : 0; + if (empty($modifyAnswers)) { $modifyAnswers = isset($_GET['modifyAnswers']) ? $_GET['modifyAnswers'] : 0; } -if (empty($editQuestion)) { - $editQuestion = isset($_GET['editQuestion']) ? $_GET['editQuestion'] : 0; -} + +$editQuestion = isset($_GET['editQuestion']) ? $_GET['editQuestion'] : 0; + if (empty($modifyQuestion)) { $modifyQuestion = isset($_GET['modifyQuestion']) ? $_GET['modifyQuestion'] : 0; } @@ -188,8 +189,6 @@ if (!is_object($objExercise)) { // Exercise can be edited in their course. if ($objExercise->sessionId != $sessionId) { api_not_allowed(true); - /*header('Location: '.api_get_path(WEB_CODE_PATH).'exercise/exercise.php?'.api_get_cidreq()); - exit;*/ } // doesn't select the exercise ID if we come from the question pool @@ -205,7 +204,6 @@ $nbrQuestions = $objExercise->selectNbrQuestions(); // Question object creation. if ($editQuestion || $newQuestion || $modifyQuestion || $modifyAnswers) { if ($editQuestion || $newQuestion) { - // reads question data if ($editQuestion) { // question not found @@ -246,7 +244,7 @@ if ($cancelQuestion) { exit(); } else { // goes back to the question viewing - $editQuestion=$modifyQuestion; + $editQuestion = $modifyQuestion; unset($newQuestion,$modifyQuestion); } } @@ -274,7 +272,7 @@ if (!empty($clone_question) && !empty($objExercise->id)) { // if cancelling answer creation/modification if ($cancelAnswers) { // goes back to the question viewing - $editQuestion=$modifyAnswers; + $editQuestion = $modifyAnswers; unset($modifyAnswers); } $nameTools = null; @@ -421,11 +419,33 @@ if ($newQuestion || $editQuestion) { $type = isset($_REQUEST['answerType']) ? Security::remove_XSS($_REQUEST['answerType']) : null; echo ''; - if ($newQuestion == 'yes') { + if ($newQuestion === 'yes') { $objExercise->edit_exercise_in_lp = true; + require 'question_admin.inc.php'; } - require 'question_admin.inc.php'; + if ($editQuestion) { + // Question preview if teacher clicked the "switch to student" + if ($studentViewActive && $is_allowedToEdit) { + echo '
'; + echo Display::div($objQuestion->selectTitle(), array('class' => 'question_title')); + ExerciseLib::showQuestion( + $editQuestion, + false, + null, + null, + false, + true, + false, + true, + $objExercise->feedback_type, + true + ); + echo '
'; + } else { + require 'question_admin.inc.php'; + } + } } if (isset($_GET['hotspotadmin'])) { diff --git a/main/exercise/exercise.class.php b/main/exercise/exercise.class.php index a107a6b9d4..4be98ece8b 100755 --- a/main/exercise/exercise.class.php +++ b/main/exercise/exercise.class.php @@ -3959,7 +3959,6 @@ class Exercise $user_answer = Display::span($real_list[$i_answer_id]); } - // Try with $i_answer_id_auto if (empty($user_answer)) { if (isset($real_list[$i_answer_id_auto])) { From 93aa582f4614a8c467797ef6cb2fbbfef30de781 Mon Sep 17 00:00:00 2001 From: jmontoyaa Date: Tue, 4 Oct 2016 16:36:05 +0200 Subject: [PATCH 05/87] Minor - format code --- main/work/add_document.php | 4 ---- main/work/downloadfolder.inc.php | 2 +- main/work/edit.php | 1 - main/work/work.lib.php | 4 ++-- 4 files changed, 3 insertions(+), 8 deletions(-) diff --git a/main/work/add_document.php b/main/work/add_document.php index 40fd0107d4..482ae4b595 100755 --- a/main/work/add_document.php +++ b/main/work/add_document.php @@ -1,8 +1,6 @@
'; } else { - $documentInfo = DocumentManager::get_document_data_by_id($docId, $courseInfo['code']); $url = api_get_path(WEB_CODE_PATH).'work/add_document.php?id='.$workId.'&document_id='.$docId.'&'.api_get_cidreq(); $form = new FormValidator('add_doc', 'post', $url); diff --git a/main/work/downloadfolder.inc.php b/main/work/downloadfolder.inc.php index eea74152b9..33d58e8c16 100755 --- a/main/work/downloadfolder.inc.php +++ b/main/work/downloadfolder.inc.php @@ -68,7 +68,7 @@ if ($groupId) { if (api_is_allowed_to_edit() || api_is_coach()) { //Search for all files that are not deleted => visibility != 2 - $sql = "SELECT DISTINCT + $sql = "SELECT DISTINCT url, title, description, diff --git a/main/work/edit.php b/main/work/edit.php index 7a8e687edb..acca4af5f2 100755 --- a/main/work/edit.php +++ b/main/work/edit.php @@ -306,7 +306,6 @@ if (!empty($work_id)) { if (api_resource_is_locked_by_gradebook($work_id, LINK_STUDENTPUBLICATION)) { echo Display::display_warning_message(get_lang('ResourceLockedByGradebook')); } else { - $comments = getWorkComments($work_item); $template = $tpl->get_template('work/comments.tpl'); diff --git a/main/work/work.lib.php b/main/work/work.lib.php index fdbd32c50a..d8c1606c9d 100755 --- a/main/work/work.lib.php +++ b/main/work/work.lib.php @@ -3897,14 +3897,14 @@ function updatePublicationAssignment($workId, $params, $courseInfo, $groupId) $table = Database::get_course_table(TABLE_STUDENT_PUBLICATION_ASSIGNMENT); $workTable = Database::get_course_table(TABLE_STUDENT_PUBLICATION); $workId = intval($workId); - $time = api_get_utc_datetime(); + $now = api_get_utc_datetime(); $course_id = $courseInfo['real_id']; // Insert into agenda $agendaId = 0; if (isset($params['add_to_calendar']) && $params['add_to_calendar'] == 1) { // Setting today date - $date = $end_date = $time; + $date = $end_date = $now; if (isset($params['enableExpiryDate'])) { $end_date = $params['expires_on']; From 5ca982bfa4898f5b56a7e5495804c245b53b2ff4 Mon Sep 17 00:00:00 2001 From: jmontoyaa Date: Tue, 4 Oct 2016 17:03:00 +0200 Subject: [PATCH 06/87] If event doenst exist invalidate agenda.id --- main/work/work.lib.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/main/work/work.lib.php b/main/work/work.lib.php index d8c1606c9d..6c6ca21253 100755 --- a/main/work/work.lib.php +++ b/main/work/work.lib.php @@ -3923,6 +3923,14 @@ function updatePublicationAssignment($workId, $params, $courseInfo, $groupId) $agenda->set_course($courseInfo); $agenda->type = 'course'; + if (!empty($agendaId)) { + // add_to_calendar is set but it doesnt exists then invalidate + $eventInfo = $agenda->get_event($agendaId); + if (empty($eventInfo)) { + $agendaId = 0; + } + } + if (empty($agendaId)) { $agendaId = $agenda->addEvent( $date, From 915cfc95e62ceac12f064a3d4767cf88db64c31a Mon Sep 17 00:00:00 2001 From: jmontoyaa Date: Tue, 4 Oct 2016 17:11:58 +0200 Subject: [PATCH 07/87] add_to_calendar is an int not boolean --- app/Migrations/Schema/V111/Version111.php | 1 + .../CourseBundle/Entity/CStudentPublicationAssignment.php | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/app/Migrations/Schema/V111/Version111.php b/app/Migrations/Schema/V111/Version111.php index 4bef423f58..190920d226 100644 --- a/app/Migrations/Schema/V111/Version111.php +++ b/app/Migrations/Schema/V111/Version111.php @@ -314,6 +314,7 @@ class Version111 extends AbstractMigrationChamilo $this->addSql('DELETE FROM settings_current WHERE variable = "course_create_active_tools" AND subkey = "online_conference"'); $this->addSql('DELETE FROM settings_options WHERE variable = "visio_use_rtmpt"'); $this->addSql('DELETE FROM course_module WHERE name = "conference"'); + $this->addSql('ALTER TABLE c_student_publication_assignment CHANGE add_to_calendar add_to_calendar INT NOT NULL;'); } /** diff --git a/src/Chamilo/CourseBundle/Entity/CStudentPublicationAssignment.php b/src/Chamilo/CourseBundle/Entity/CStudentPublicationAssignment.php index 64a5cbdc93..0ef2fb21d7 100644 --- a/src/Chamilo/CourseBundle/Entity/CStudentPublicationAssignment.php +++ b/src/Chamilo/CourseBundle/Entity/CStudentPublicationAssignment.php @@ -58,7 +58,7 @@ class CStudentPublicationAssignment /** * @var boolean * - * @ORM\Column(name="add_to_calendar", type="boolean", nullable=false) + * @ORM\Column(name="add_to_calendar", type="integer", nullable=false) */ private $addToCalendar; From 260ea62dec0d6dcfa6d807c3c9626f14c15a0f5b Mon Sep 17 00:00:00 2001 From: Angel Fernando Quiroz Campos Date: Tue, 4 Oct 2016 13:12:31 -0500 Subject: [PATCH 08/87] Show questions on list for teacher by AJAX - refs BT#11562 --- main/exercise/question_list_admin.inc.php | 53 +++++++++++++++-------- main/inc/ajax/exercise.ajax.php | 29 +++++++++++++ main/inc/lib/display.lib.php | 2 +- main/inc/lib/exercise.lib.php | 4 +- 4 files changed, 67 insertions(+), 21 deletions(-) diff --git a/main/exercise/question_list_admin.inc.php b/main/exercise/question_list_admin.inc.php index 990033f33a..f269076d67 100755 --- a/main/exercise/question_list_admin.inc.php +++ b/main/exercise/question_list_admin.inc.php @@ -105,7 +105,37 @@ $ajax_url = api_get_path(WEB_AJAX_PATH)."exercise.ajax.php?".api_get_cidreq()."& heightStyle: "content", active: false, // all items closed by default collapsible: true, - header: ".header_operations" + header: ".header_operations", + beforeActivate: function (e, ui) { + var data = ui.newHeader.data(); + + if (typeof data === 'undefined') { + return; + } + + var exerciseId = data.exercise || 0, + questionId = data.question || 0; + + if (!questionId || !exerciseId) { + return; + } + + var $pnlQuestion = $('#pnl-question-' + questionId); + + if ($pnlQuestion.html().trim().length) { + return; + } + + $pnlQuestion.html(''); + + $.get('exercise.ajax.php', { + a: 'show_question', + exercise: exerciseId, + question: questionId + }, function (response) { + $pnlQuestion.html(response) + }); + } }) .sortable({ cursor: "move", // works? @@ -154,8 +184,6 @@ if (!$inATest) { echo ""; echo "
"; echo ""; - echo "
 
"; - echo '
'; if ($nbrQuestions) { //Always getting list from DB @@ -259,7 +287,7 @@ if (!$inATest) { $questionScore = Display::tag('div', $objQuestionTmp->selectWeighting(), array('style'=>$styleScore)); echo '
'; - echo '
'; + echo '
'; echo $questionName; echo $questionType; echo $questionCategory; @@ -267,23 +295,12 @@ if (!$inATest) { echo $questionScore; echo $actions; echo '
'; - echo '
'; - echo '

' . get_lang($question_class) . '

'; - //echo get_lang('Level').': '.$objQuestionTmp->selectLevel(); - ExerciseLib::showQuestion( - $id, - false, - null, + echo Display::tag( + 'div', null, - false, - true, - false, - true, - $objExercise->feedback_type, - true + ['class' => 'question-list-description-block', 'id' => "pnl-question-$id"] ); echo '
'; - echo '
'; unset($objQuestionTmp); } } diff --git a/main/inc/ajax/exercise.ajax.php b/main/inc/ajax/exercise.ajax.php index ad33780de9..79518dd649 100755 --- a/main/inc/ajax/exercise.ajax.php +++ b/main/inc/ajax/exercise.ajax.php @@ -504,6 +504,35 @@ switch ($action) { } echo 'ok'; break; + case 'show_question': + $questionId = isset($_GET['question']) ? intval($_GET['question']) : 0; + $exerciseId = isset($_REQUEST['exercise']) ? intval($_REQUEST['exercise']) : 0; + + if (!$questionId || !$exerciseId) { + break; + } + + $objExercise = new Exercise(); + $objExercise->read($exerciseId); + + $objQuestion = Question::read($questionId); + $objQuestion->get_question_type_name(); + + echo '

' . $objQuestion->get_question_type_name() . '

'; + //echo get_lang('Level').': '.$objQuestionTmp->selectLevel(); + ExerciseLib::showQuestion( + $questionId, + false, + null, + null, + false, + true, + false, + true, + $objExercise->feedback_type, + true + ); + break; default: echo ''; } diff --git a/main/inc/lib/display.lib.php b/main/inc/lib/display.lib.php index 099717be0a..67d1dcee96 100755 --- a/main/inc/lib/display.lib.php +++ b/main/inc/lib/display.lib.php @@ -884,7 +884,7 @@ class Display if (in_array($tag, array('img','input','br'))) { $return_value = '<'.$tag.' '.$attribute_list.' />'; } else { - $return_value = '<'.$tag.' '.$attribute_list.' > '.$content.''; + $return_value = '<'.$tag.' '.$attribute_list.' >'.$content.''; } return $return_value; } diff --git a/main/inc/lib/exercise.lib.php b/main/inc/lib/exercise.lib.php index b52feb49e4..0d6052a3e1 100644 --- a/main/inc/lib/exercise.lib.php +++ b/main/inc/lib/exercise.lib.php @@ -1140,7 +1140,7 @@ HTML; $relPath = api_get_path(WEB_CODE_PATH); echo "
"; From cbb5dffc26fef42f8aee1b32f68157af34e91b5a Mon Sep 17 00:00:00 2001 From: Angel Fernando Quiroz Campos Date: Tue, 4 Oct 2016 13:22:51 -0500 Subject: [PATCH 09/87] Validate access to teachers when show question - refs BT#11562 --- main/inc/ajax/exercise.ajax.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/main/inc/ajax/exercise.ajax.php b/main/inc/ajax/exercise.ajax.php index 79518dd649..3174c5a445 100755 --- a/main/inc/ajax/exercise.ajax.php +++ b/main/inc/ajax/exercise.ajax.php @@ -505,6 +505,13 @@ switch ($action) { echo 'ok'; break; case 'show_question': + $isAllowedToEdit = api_is_allowed_to_edit(null, true, false, false); + + if (!$isAllowedToEdit) { + api_not_allowed(true); + exit; + } + $questionId = isset($_GET['question']) ? intval($_GET['question']) : 0; $exerciseId = isset($_REQUEST['exercise']) ? intval($_REQUEST['exercise']) : 0; From 299b3387b408fa0a7a9efe6211e2d5899720d68d Mon Sep 17 00:00:00 2001 From: Angel Fernando Quiroz Campos Date: Tue, 4 Oct 2016 16:04:29 -0500 Subject: [PATCH 10/87] Disable radio button to avoid select Don't Know question option on question type 10 - refs #8408 --- main/exercise/unique_answer_no_option.class.php | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/main/exercise/unique_answer_no_option.class.php b/main/exercise/unique_answer_no_option.class.php index 520abf145e..36e0ef2fd6 100755 --- a/main/exercise/unique_answer_no_option.class.php +++ b/main/exercise/unique_answer_no_option.class.php @@ -209,8 +209,9 @@ class UniqueAnswerNoOption extends Question $i = 666; $form->addHtml('
'); From 90dd379f4143df22f633916e319995381463f9f1 Mon Sep 17 00:00:00 2001 From: Angel Fernando Quiroz Campos Date: Tue, 4 Oct 2016 16:56:46 -0500 Subject: [PATCH 11/87] Keep the current directory after upload a document - refs #8446 --- main/document/upload.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/main/document/upload.php b/main/document/upload.php index 31671a7a0a..ed7870b992 100755 --- a/main/document/upload.php +++ b/main/document/upload.php @@ -198,7 +198,16 @@ if (!empty($_FILES)) { $index, true ); - header('Location: '.api_get_self().'?'.api_get_cidreq().'#tabs-2'); + + $redirectUrl = api_get_self() . '?' . api_get_cidreq(); + + if ($document_data) { + $redirectUrl .= '&' . http_build_query([ + 'id' => $document_data['iid'] + ]); + } + + header("Location: $redirectUrl"); exit; } From 6fcee52fcda150720640f254101079f545ef0bfc Mon Sep 17 00:00:00 2001 From: cvargas Date: Wed, 5 Oct 2016 00:06:59 -0500 Subject: [PATCH 12/87] Fix suggested Apache rewrite rule --- documentation/installation_guide.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/documentation/installation_guide.html b/documentation/installation_guide.html index c21429a42c..367f1570a1 100755 --- a/documentation/installation_guide.html +++ b/documentation/installation_guide.html @@ -678,7 +678,7 @@ If you have issues with files taking a long time to download, make sure you reco RewriteCond %{QUERY_STRING} ^id=(.*)$ RewriteRule ^([^/.]+)/?$ user.php?$1 [L] RewriteRule ^certificates/$ certificates/index.php?id=%1 [L] - RewriteRule ^courses/([^/]+)/$ app/course_home/course_home.php?cDir=$1 [QSA,L] + RewriteRule ^courses/([^/]+)/$ main/course_home/course_home.php?cDir=$1 [QSA,L] RewriteRule ^courses/([^/]+)/index.php$ main/course_home/course_home.php?cDir=$1 [QSA,L] RewriteRule ^courses/([^/]+)/document/(.*)$ main/document/download.php?doc_url=/$2&cDir=$1 [QSA,L] RewriteRule ^courses/([^/]+)/work/(.*)$ main/work/download.php?file=work/$2&cDir=$1 [QSA,L] From 6aeb40ccc95bbf079f17b016ab7650de33ddf47b Mon Sep 17 00:00:00 2001 From: Carlos Vargas Date: Wed, 5 Oct 2016 00:06:59 -0500 Subject: [PATCH 13/87] Fix suggested Apache rewrite rule --- documentation/installation_guide.html | 2 +- documentation/installation_guide_es_ES.html | 2 +- documentation/installation_guide_fr_FR.html | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/documentation/installation_guide.html b/documentation/installation_guide.html index c21429a42c..367f1570a1 100755 --- a/documentation/installation_guide.html +++ b/documentation/installation_guide.html @@ -678,7 +678,7 @@ If you have issues with files taking a long time to download, make sure you reco RewriteCond %{QUERY_STRING} ^id=(.*)$ RewriteRule ^([^/.]+)/?$ user.php?$1 [L] RewriteRule ^certificates/$ certificates/index.php?id=%1 [L] - RewriteRule ^courses/([^/]+)/$ app/course_home/course_home.php?cDir=$1 [QSA,L] + RewriteRule ^courses/([^/]+)/$ main/course_home/course_home.php?cDir=$1 [QSA,L] RewriteRule ^courses/([^/]+)/index.php$ main/course_home/course_home.php?cDir=$1 [QSA,L] RewriteRule ^courses/([^/]+)/document/(.*)$ main/document/download.php?doc_url=/$2&cDir=$1 [QSA,L] RewriteRule ^courses/([^/]+)/work/(.*)$ main/work/download.php?file=work/$2&cDir=$1 [QSA,L] diff --git a/documentation/installation_guide_es_ES.html b/documentation/installation_guide_es_ES.html index 8a6fbcb331..3323ad6316 100755 --- a/documentation/installation_guide_es_ES.html +++ b/documentation/installation_guide_es_ES.html @@ -771,7 +771,7 @@ Apache2: La configuración para nuestro sitio de ejemplo my.chamilo10.net sería RewriteCond %{QUERY_STRING} ^id=(.*)$ RewriteRule ^([^/.]+)/?$ user.php?$1 [L] RewriteRule ^certificates/$ certificates/index.php?id=%1 [L] - RewriteRule ^courses/([^/]+)/$ app/course_home/course_home.php?cDir=$1 [QSA,L] + RewriteRule ^courses/([^/]+)/$ main/course_home/course_home.php?cDir=$1 [QSA,L] RewriteRule ^courses/([^/]+)/index.php$ main/course_home/course_home.php?cDir=$1 [QSA,L] RewriteRule ^courses/([^/]+)/document/(.*)$ main/document/download.php?doc_url=/$2&cDir=$1 [QSA,L] RewriteRule ^courses/([^/]+)/work/(.*)$ main/work/download.php?file=work/$2&cDir=$1 [QSA,L] diff --git a/documentation/installation_guide_fr_FR.html b/documentation/installation_guide_fr_FR.html index 1cdd7d458c..9855d31fb4 100644 --- a/documentation/installation_guide_fr_FR.html +++ b/documentation/installation_guide_fr_FR.html @@ -732,7 +732,7 @@ ou, si vous travaillez avec Apache 2.4, la syntaxe est légèrement différente RewriteCond %{QUERY_STRING} ^id=(.*)$ RewriteRule ^([^/.]+)/?$ user.php?$1 [L] RewriteRule ^certificates/$ certificates/index.php?id=%1 [L] - RewriteRule ^courses/([^/]+)/$ app/course_home/course_home.php?cDir=$1 [QSA,L] + RewriteRule ^courses/([^/]+)/$ main/course_home/course_home.php?cDir=$1 [QSA,L] RewriteRule ^courses/([^/]+)/index.php$ main/course_home/course_home.php?cDir=$1 [QSA,L] RewriteRule ^courses/([^/]+)/document/(.*)$ main/document/download.php?doc_url=/$2&cDir=$1 [QSA,L] RewriteRule ^courses/([^/]+)/work/(.*)$ main/work/download.php?file=work/$2&cDir=$1 [QSA,L] From 6fb26d53eb3cd5fabafe1b7bb00af252dedb4acb Mon Sep 17 00:00:00 2001 From: Yannick Warnier Date: Wed, 5 Oct 2016 00:59:33 -0500 Subject: [PATCH 14/87] Update language terms --- main/lang/french/trad4all.inc.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/main/lang/french/trad4all.inc.php b/main/lang/french/trad4all.inc.php index 5ef7302e00..3f53a4adb2 100644 --- a/main/lang/french/trad4all.inc.php +++ b/main/lang/french/trad4all.inc.php @@ -6130,7 +6130,10 @@ $SSOServerUnAuthURIComment = "L'adresse de la page qui se charge de la déconnex $SSOServerProtocolTitle = "Protocole du serveur Single Sign On"; $SSOServerProtocolComment = "Le protocole à préfixer au domaine du serveur Single Sign On (nous recommandons l'usage de https:// si votre serveur le permet, car tout protocole non sécurisé engendre des risques au niveau du mécanisme d'authentification)."; $EnabledWirisTitle = "Editeur mathématique WIRIS"; -$EnabledWirisComment = "Activer l'éditeur mathématique WIRIS"; +$EnabledWirisComment = "Activer l'éditeur mathématique WIRIS. +En installant ce plugin, vous obtenez l'éditeur WIRIS et WIRIS CAS. +Cette activation n'est totalement réalisé que si le plugin PHP pour CKeditor WIRIS a été préalablement téléchargé et décompressé dans le répertoire de Chamilo main/inc/lib/javascript/ckeditor/plugins/ +Cela est nécessaire car Wiris est un logiciel propriétaire et ses services sont de nature commerciale. Pour faire des ajustements pour le plug-in, éditer le fichier configuration.ini ou remplacer son contenu par le fichier de chamilo configuration.ini.default"; $FileSavedAs = "Le fichier a été enregistré sous"; $FileExportAs = "Le fichier a été exporté sous"; $AllowSpellCheckTitle = "Correcteur orthographique"; From 82ae9c3cf171067a334acbd245385d96344f6f1e Mon Sep 17 00:00:00 2001 From: jmontoyaa Date: Wed, 5 Oct 2016 11:36:30 +0200 Subject: [PATCH 15/87] WIP: Fix query that makes matching update wrong see BT#11761 Need to be tested. --- app/Migrations/Schema/V110/Version20151221150100.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Migrations/Schema/V110/Version20151221150100.php b/app/Migrations/Schema/V110/Version20151221150100.php index 8d4b7ba81a..dc09abd18b 100644 --- a/app/Migrations/Schema/V110/Version20151221150100.php +++ b/app/Migrations/Schema/V110/Version20151221150100.php @@ -42,9 +42,9 @@ class Version20151221150100 extends AbstractMigrationChamilo $this->addSql(" UPDATE c_quiz_answer a INNER JOIN c_quiz_answer b - ON a.question_id = b.question_id + ON (a.question_id = b.question_id AND b.c_id = a.c_id) INNER JOIN c_quiz_question q - ON b.question_id = q.id + ON (b.question_id = q.id AND b.c_id = q.c_id) SET a.correct = b.id_auto WHERE a.correct = b.id AND From 64bde06f4b98cbba653ccdd8b1ab388a1db1b031 Mon Sep 17 00:00:00 2001 From: jmontoyaa Date: Wed, 5 Oct 2016 12:42:57 +0200 Subject: [PATCH 16/87] Minor - format code, remove unused functions --- main/announcements/announcements.php | 7 +- main/inc/lib/AnnouncementEmail.php | 10 +- main/inc/lib/AnnouncementManager.php | 241 +----------------- main/inc/lib/agenda.lib.php | 70 +---- .../announcements/announcements.inc.test.php | 37 --- 5 files changed, 25 insertions(+), 340 deletions(-) diff --git a/main/announcements/announcements.php b/main/announcements/announcements.php index 849ffd4efe..88a7bea32f 100755 --- a/main/announcements/announcements.php +++ b/main/announcements/announcements.php @@ -40,7 +40,6 @@ if (!empty($sessionId) && $drhHasAccessToSessionContent) { $allowToEdit = $allowToEdit || api_is_drh(); } - /* ACCESS RIGHTS */ api_protect_course_script(true); @@ -214,17 +213,15 @@ switch ($action) { 'width' => '150', 'align' => 'left', //'formatter' => 'action_formatter', - 'sortable' => 'false', - ), + 'sortable' => 'false' + ) ); // Autowidth $extra_params['autowidth'] = 'true'; // height auto $extra_params['height'] = 'auto'; - $editOptions = ''; - if (api_is_allowed_to_edit()) { $extra_params['multiselect'] = true; $editOptions = ' diff --git a/main/inc/lib/AnnouncementEmail.php b/main/inc/lib/AnnouncementEmail.php index 5d75ae123a..3c91e9633c 100644 --- a/main/inc/lib/AnnouncementEmail.php +++ b/main/inc/lib/AnnouncementEmail.php @@ -238,9 +238,8 @@ class AnnouncementEmail ); $user_email = $this->sender('mail'); - //$course_param = api_get_cidreq(); // Build the link by hand because api_get_cidreq() doesn't accept course params - $course_param = 'cidReq='.api_get_course_id().'&id_session='.$session_id.'&gidReq='.api_get_group_id(); + $course_param = 'cidReq='.api_get_course_id().'&id_session='.$session_id.'&gidReq='.api_get_group_id(); $course_name = $this->course('title'); $result = "
$content
"; @@ -250,9 +249,10 @@ class AnnouncementEmail if (!empty($attachment)) { $result .= '
'; $result .= Display::url( - $attachment['filename'], - api_get_path(WEB_CODE_PATH).'announcements/download.php?file='.basename($attachment['path']).'&'.$course_param - ).'
'; + $attachment['filename'], + api_get_path(WEB_CODE_PATH).'announcements/download.php?file='.basename($attachment['path']).'&'.$course_param + ); + $result .= '
'; } $result .= '
'; diff --git a/main/inc/lib/AnnouncementManager.php b/main/inc/lib/AnnouncementManager.php index c612ea6932..241b49249f 100755 --- a/main/inc/lib/AnnouncementManager.php +++ b/main/inc/lib/AnnouncementManager.php @@ -17,7 +17,6 @@ class AnnouncementManager */ public function __construct() { - } /** @@ -659,10 +658,8 @@ class AnnouncementManager } // store in item_property (first the groups, then the users - if (!is_null($to)) { // !is_null($to): when no user is selected we send it to everyone - $send_to = CourseManager::separateUsersGroups($to); // storing the selected groups @@ -817,206 +814,6 @@ class AnnouncementManager return false; } - /** - * This function shows the form for sending a message to a specific group or user. - * @param $to_already_selected - */ - public static function show_to_form($to_already_selected) - { - $userList = self::get_course_users(); - $groupList = self::get_course_groups(); - - if ($to_already_selected == '' || $to_already_selected == 'everyone') { - $to_already_selected = array(); - } - - echo ""; - echo ''; - echo '"; - echo ''; - echo ''; - - - // the form containing all the groups and all the users of the course - echo '"; - - // the buttons for adding or removing groups/users - echo '"; - - echo ""; - echo ""; - echo "
'; - echo '"; - echo "
'; - echo "" . get_lang('Users') . "
"; - - self::construct_not_selected_select_form($groupList, $userList, $to_already_selected); - echo "
'; - echo ''; - echo '

'; - echo ''; - echo "
"; - - // the form containing the selected groups and users - echo "" . get_lang('DestinationUsers') . "
"; - self::construct_selected_select_form($groupList, $userList, $to_already_selected); - echo "
"; - } - - /** - * this function shows the form for sending a message to a specific group or user. - */ - public static function show_to_form_group($group_id) - { - echo ""; - echo ""; - echo ""; - - // the buttons for adding or removing groups/users - echo ""; - echo ""; - echo ""; - echo "
"; - echo "'; - echo ""; - echo ''; - echo '

'; - echo ''; - echo "
"; - - echo "'; - - echo "
"; - } - - /** - * Shows the form for sending a message to a specific group or user. - * @param array $groupList - * @param array $userList - * @param array $to_already_selected - */ - public static function construct_not_selected_select_form( - $groupList = array(), - $userList = array(), - $to_already_selected = array() - ) { - echo '"; - } - - /** - * this function shows the form for sending a message to a specific group or user. - */ - /** - * @param null $groupList - * @param null $userList - * @param $to_already_selected - */ - public static function construct_selected_select_form($groupList = null, $userList = null, $to_already_selected = array()) - { - // we load all the groups and all the users into a reference array that we use to search the name of the group / user - $ref_array_groups = self::get_course_groups(); - $ref_array_users = self::get_course_users(); - - // we construct the form of the already selected groups / users - echo '"; - } - /** * Returns announcement info from its id * @@ -1133,23 +930,6 @@ class AnnouncementManager return $to; } - /** - * returns the javascript for setting a filter - * this goes into the $htmlHeadXtra[] array - */ - public static function user_group_filter_javascript() - { - return ""; - } - /** * constructs the form to display all the groups and users the message has been sent to * input: $sent_to_array is a 2 dimensional array containing the groups and the users @@ -1223,8 +1003,6 @@ class AnnouncementManager } } - - /** * Returns all the users and all the groups a specific announcement item * has been sent to @@ -1275,19 +1053,19 @@ class AnnouncementManager /** * Show a list with all the attachments according to the post's id - * @param int announcement id + * @param int $announcementId * @return array with the post info * @author Arthur Portugal * @version November 2009, dokeos 1.8.6.2 */ - public static function get_attachment($announcement_id) + public static function get_attachment($announcementId) { $tbl_announcement_attachment = Database::get_course_table(TABLE_ANNOUNCEMENT_ATTACHMENT); - $announcement_id = intval($announcement_id); + $announcementId = intval($announcementId); $course_id = api_get_course_int_id(); $row = array(); $sql = 'SELECT id, path, filename, comment FROM ' . $tbl_announcement_attachment . ' - WHERE c_id = ' . $course_id . ' AND announcement_id = ' . $announcement_id . ''; + WHERE c_id = ' . $course_id . ' AND announcement_id = ' . $announcementId; $result = Database::query($sql); if (Database::num_rows($result) != 0) { $row = Database::fetch_array($result, 'ASSOC'); @@ -1684,8 +1462,6 @@ class AnnouncementManager $iterator = 1; $bottomAnnouncement = $announcement_number; - $origin = null; - $displayed = []; $results = []; $actionUrl = api_get_path(WEB_CODE_PATH).'announcements/announcements.php?'.api_get_cidreq(); @@ -1784,7 +1560,7 @@ class AnnouncementManager public static function getNumberAnnouncements() { // Maximum title messages to display - $maximum = '12'; + $maximum = '12'; // Database Table Definitions $tbl_announcement = Database::get_course_table(TABLE_ANNOUNCEMENT); $tbl_item_property = Database::get_course_table(TABLE_ITEM_PROPERTY); @@ -1800,7 +1576,7 @@ class AnnouncementManager if (empty($_GET['origin']) or $_GET['origin'] !== 'learnpath') { if (api_get_group_id() == 0) { - $group_condition = ""; + $group_condition = ''; } else { $group_condition = " AND (ip.to_group_id='".api_get_group_id()."' OR ip.to_group_id = 0 OR ip.to_group_id IS NULL)"; } @@ -1816,7 +1592,7 @@ class AnnouncementManager $condition_session GROUP BY ip.ref ORDER BY display_order DESC - LIMIT 0,$maximum"; + LIMIT 0, $maximum"; } } else { // students only get to see the visible announcements @@ -1857,7 +1633,8 @@ class AnnouncementManager } } - // the user is member of several groups => display personal announcements AND his group announcements AND the general announcements + // the user is member of several groups => display personal announcements AND + // his group announcements AND the general announcements if (is_array($group_memberships) && count($group_memberships)>0) { $sql = "SELECT announcement.*, ip.visibility, ip.to_group_id, ip.insert_user_id FROM $tbl_announcement announcement, $tbl_item_property ip diff --git a/main/inc/lib/agenda.lib.php b/main/inc/lib/agenda.lib.php index 3287cc93c4..d66cdba802 100644 --- a/main/inc/lib/agenda.lib.php +++ b/main/inc/lib/agenda.lib.php @@ -146,7 +146,7 @@ class Agenda ) { $start = api_get_utc_datetime($start); $end = api_get_utc_datetime($end); - $allDay = isset($allDay) && $allDay == 'true' ? 1 : 0; + $allDay = isset($allDay) && $allDay === 'true' ? 1 : 0; $id = null; switch ($this->type) { @@ -1116,8 +1116,8 @@ class Agenda return $this->events; break; } - } + return ''; } @@ -1854,54 +1854,6 @@ class Agenda return $eventDate->format(DateTime::ISO8601); } - /** - * this function shows the form with the user that were not selected - * @author: Patrick Cool , Ghent University - * @return string code - */ - public static function construct_not_selected_select_form($group_list = null, $user_list = null, $to_already_selected = array()) - { - $html = '"; - } - - return $html; - } - /** * @param FormValidator $form * @param array $groupList @@ -1913,10 +1865,10 @@ class Agenda */ public function setSendToSelect( $form, - $groupList = null, - $userList = null, - $sendTo = array(), - $attributes = array(), + $groupList = [], + $userList = [], + $sendTo = [], + $attributes = [], $addOnlyItemsInSendTo = false, $required = false ) { @@ -2051,7 +2003,7 @@ class Agenda * @param array $params * @return FormValidator */ - public function getForm($params = array()) + public function getForm($params = []) { $action = isset($params['action']) ? Security::remove_XSS($params['action']) : null; $id = isset($params['id']) ? intval($params['id']) : null; @@ -2351,7 +2303,6 @@ class Agenda return $list; } - /** * Show a list with all the attachments according to the post's id * @param int $attachmentId @@ -2386,7 +2337,7 @@ class Agenda * Add an attachment file into agenda * @param int $eventId * @param array $fileUserUpload ($_FILES['user_upload']) - * @param string comment about file + * @param string $comment about file * @param array $courseInfo * @return string */ @@ -2797,7 +2748,6 @@ class Agenda /** @var Sabre\VObject\Property\ICalendar\Recur $repeat */ $repeat = $event->RRULE; if ($id && !empty($repeat)) { - $repeat = $repeat->getParts(); $freq = $trans[$repeat['FREQ']]; @@ -3466,10 +3416,9 @@ class Agenda return $items; } - /** * This function retrieves one personal agenda item returns it. - * @param int The agenda item ID + * @param int $id The agenda item ID * @return array The results of the database query, or null if not found */ public static function get_personal_agenda_item($id) @@ -3488,7 +3437,6 @@ class Agenda return $item; } - /** * This function calculates the startdate of the week (monday) * and the enddate of the week (sunday) diff --git a/tests/main/announcements/announcements.inc.test.php b/tests/main/announcements/announcements.inc.test.php index 8b317bda1d..6893c5e323 100755 --- a/tests/main/announcements/announcements.inc.test.php +++ b/tests/main/announcements/announcements.inc.test.php @@ -7,43 +7,6 @@ class TestAnnouncements extends UnitTestCase { $this->UnitTestCase('Displays one specific announcement test'); } - public function Testconstruct_not_selected_select_form(){ - $courseSysCode= '123'; - $course_code = $courseSysCode; - ob_start(); - $to_already_selected=""; - $_SESSION['_cid'] = 'CURSO1'; - $user_list = array( 0=>array( - 0 => '1','user_id' => '1', - 1 =>'Doe','lastname' =>'Doe', - 2 =>'John','firstname' =>'John', - 3 => 'admin','username' =>'admin' - )); - - $res = construct_not_selected_select_form($group_list=null, $user_list,$to_already_selected); - ob_end_clean(); - $this->assertTrue(is_null($res)); - //var_dump($res); - } - - public function Testconstruct_selected_select_form(){ - $to_already_selected=""; - ob_start(); - $res = construct_selected_select_form($group_list=null, $user_list=null,$to_already_selected); - ob_end_clean(); - $this->assertTrue(is_null($res)); - //var_dump($res); - } - - public function Testshow_to_form_group(){ - ob_start(); - $group_id=1; - $group_users=GroupManager::get_subscribed_users($group_id); - $res = show_to_form_group($group_id); - ob_end_clean(); - $this->assertTrue(is_null($res)); - //var_dump($res); - } public function Testget_course_users(){ $_SESSION['id_session'] = 'CURSO1'; From 7c3e3bed7131b178faccb7084f279a482c4ae548 Mon Sep 17 00:00:00 2001 From: jmontoyaa Date: Wed, 5 Oct 2016 13:38:42 +0200 Subject: [PATCH 17/87] Fix error when user has set his language but HTML is not set See BT#10668 --- main/inc/lib/internationalization.lib.php | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/main/inc/lib/internationalization.lib.php b/main/inc/lib/internationalization.lib.php index 7043669358..8ab11fcf05 100755 --- a/main/inc/lib/internationalization.lib.php +++ b/main/inc/lib/internationalization.lib.php @@ -158,10 +158,14 @@ function get_lang($variable, $reserved = null, $language = null) { * Gets the current interface language. * @param bool $purified (optional) When it is true, a purified (refined) * language value will be returned, for example 'french' instead of 'french_unicode'. + * @param bool $setParentLanguageName * @return string The current language of the interface. */ -function api_get_interface_language($purified = false, $check_sub_language = false) -{ +function api_get_interface_language( + $purified = false, + $check_sub_language = false, + $setParentLanguageName = true +) { global $language_interface; if (empty($language_interface)) { @@ -183,7 +187,9 @@ function api_get_interface_language($purified = false, $check_sub_language = fal ) { if (!empty($language_info['parent_id'])) { $language_info = api_get_language_info($language_info['parent_id']); - $parent_language_name = $language_info['english_name']; + if ($setParentLanguageName) { + $parent_language_name = $language_info['english_name']; + } if (!empty($parent_language_name)) { return $parent_language_name; @@ -781,7 +787,9 @@ function api_get_person_name( //We check if the language is supported, otherwise we check the interface language of the parent language of sublanguage if (empty($language)) { - $language = api_get_interface_language(false, true); + // Do not set $setParentLanguageName because this function is called before + // the main language is loaded in global.inc.php + $language = api_get_interface_language(false, true, false); } if (!isset($valid[$format][$language])) { From e61f5fe7b184dd0309a97d3da0a5f473c36c9229 Mon Sep 17 00:00:00 2001 From: jmontoyaa Date: Wed, 5 Oct 2016 15:17:36 +0200 Subject: [PATCH 18/87] Add title --- main/exercise/exercise.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/main/exercise/exercise.php b/main/exercise/exercise.php index d2aa14d0e0..e67b6132f0 100644 --- a/main/exercise/exercise.php +++ b/main/exercise/exercise.php @@ -285,7 +285,8 @@ if ($is_allowedToEdit) { //clean student results if ($exercise_action_locked == false) { $quantity_results_deleted = $objExerciseTmp->clean_results(true); - Display :: display_confirmation_message(sprintf(get_lang('XResultsCleaned'), $quantity_results_deleted)); + $title = $objExerciseTmp->selectTitle(); + Display :: display_confirmation_message($title.': '.sprintf(get_lang('XResultsCleaned'), $quantity_results_deleted)); } break; case 'copy_exercise': //copy an exercise From e56398e404803c6f2525df5d173bb34161633600 Mon Sep 17 00:00:00 2001 From: jmontoyaa Date: Wed, 5 Oct 2016 15:18:00 +0200 Subject: [PATCH 19/87] Add logs when deleting work folder and files --- main/inc/lib/api.lib.php | 4 ++++ main/inc/lib/events.lib.php | 5 +++++ main/inc/lib/statistics.lib.php | 3 +-- main/work/work.lib.php | 29 +++++++++++++++++++++++++++++ 4 files changed, 39 insertions(+), 2 deletions(-) diff --git a/main/inc/lib/api.lib.php b/main/inc/lib/api.lib.php index 4f1b980b5d..453a4247fa 100644 --- a/main/inc/lib/api.lib.php +++ b/main/inc/lib/api.lib.php @@ -248,6 +248,10 @@ define('LOG_EXERCISE_AND_USER_ID', 'exercise_and_user_id'); define('LOG_LP_ID', 'lp_id'); define('LOG_EXERCISE_ATTEMPT_QUESTION_ID', 'exercise_a_q_id'); +define('LOG_WORK_DIR_DELETE', 'work_dir_delete'); +define('LOG_WORK_FILE_DELETE', 'work_file_delete'); +define('LOG_WORK_DATA', 'work_data_array'); + define('LOG_MY_FOLDER_PATH', 'path'); define('LOG_MY_FOLDER_NEW_PATH', 'new_path'); diff --git a/main/inc/lib/events.lib.php b/main/inc/lib/events.lib.php index 44792fb15c..0a6cdf6967 100644 --- a/main/inc/lib/events.lib.php +++ b/main/inc/lib/events.lib.php @@ -701,6 +701,11 @@ class Event $event_value = serialize($event_value); } } + // If event is an array then the $event_value_type should finish with + // the suffix _array for example LOG_WORK_DATA = work_data_array + if (is_array($event_value)) { + $event_value = serialize($event_value); + } $event_value = Database::escape_string($event_value); $sessionId = empty($sessionId) ? api_get_session_id() : intval($sessionId); diff --git a/main/inc/lib/statistics.lib.php b/main/inc/lib/statistics.lib.php index 95c51804c4..88c8eaafda 100644 --- a/main/inc/lib/statistics.lib.php +++ b/main/inc/lib/statistics.lib.php @@ -249,7 +249,7 @@ class Statistics WHERE track_default.default_user_id = user.user_id AND url.user_id = user.user_id AND - access_url_id='".$current_url_id."'"; + access_url_id= $current_url_id "; } else { $sql = "SELECT default_event_type as col0, @@ -282,7 +282,6 @@ class Statistics $res = Database::query($sql); $activities = array (); while ($row = Database::fetch_row($res)) { - if (strpos($row[1], '_object') === false && strpos($row[1], '_array') === false) { $row[2] = $row[2]; } else { diff --git a/main/work/work.lib.php b/main/work/work.lib.php index 6c6ca21253..e2d4640292 100755 --- a/main/work/work.lib.php +++ b/main/work/work.lib.php @@ -802,6 +802,20 @@ function deleteDirWork($id) WHERE c_id = $course_id AND publication_id = $id"; Database::query($sql); + Event::addEvent( + LOG_WORK_DIR_DELETE, + LOG_WORK_DATA, + [ + 'id' => $work_data['id'], + 'url' => $work_data['url'], + 'title' => $work_data['title'] + ], + null, + api_get_user_id(), + api_get_course_int_id(), + api_get_session_id() + ); + $link_info = GradebookUtils::isResourceInCourseGradebook( api_get_course_id(), 3, @@ -4123,6 +4137,21 @@ function deleteWorkItem($item_id, $courseInfo) 'DocumentDeleted', api_get_user_id() ); + + Event::addEvent( + LOG_WORK_FILE_DELETE, + LOG_WORK_DATA, + [ + 'id' => $work_data['id'], + 'url' => $work_data['url'], + 'title' => $work_data['title'] + ], + null, + api_get_user_id(), + api_get_course_int_id(), + api_get_session_id() + ); + $work = $row['url']; if ($row['contains_file'] == 1) { From 5b0bc80cce94093b6397edbda9877b2404bec8b1 Mon Sep 17 00:00:00 2001 From: jmontoyaa Date: Wed, 5 Oct 2016 15:38:25 +0200 Subject: [PATCH 20/87] Use api_get_user_info() --- main/template/default/work/comments.tpl | 52 ++++++++++++------------- main/work/view.php | 2 +- main/work/work.lib.php | 11 ++++-- 3 files changed, 34 insertions(+), 31 deletions(-) diff --git a/main/template/default/work/comments.tpl b/main/template/default/work/comments.tpl index 78ba9036c8..09350eb7dc 100755 --- a/main/template/default/work/comments.tpl +++ b/main/template/default/work/comments.tpl @@ -6,35 +6,35 @@
    - {% for comment in comments %} -
  • - +{% for comment in comments %} +
  • + +

    + {% if comment.comment is not empty %} + {{ comment.comment }} + {% else %} + {{ 'HereIsYourFeedback' | get_lang }} + {% endif %} +

    + {% if comment.file_url is not empty %}

    - {% if comment.comment is not empty %} - {{ comment.comment }} - {% else %} - {{ 'HereIsYourFeedback' | get_lang }} + + + {{ comment.file_name_to_show }} + + {% if is_allowed_to_edit %} + + + {% endif %}

    - {% if comment.file_url is not empty %} -

    - - - {{ comment.file_name_to_show }} - - {% if is_allowed_to_edit %} - - - - {% endif %} -

    - {% endif %} -
  • - {% endfor %} + {% endif %} + +{% endfor %}


diff --git a/main/work/view.php b/main/work/view.php index 397fba1368..0eea05417e 100755 --- a/main/work/view.php +++ b/main/work/view.php @@ -144,7 +144,7 @@ if ((user_is_author($id) || $isDrhOfCourse || (api_is_allowed_to_edit() || api_i $tpl->assign('is_allowed_to_edit', api_is_allowed_to_edit()); $template = $tpl->get_template('work/view.tpl'); - $content = $tpl->fetch($template); + $content = $tpl->fetch($template); $tpl->assign('content', $content); $tpl->display_one_col_template(); } else { diff --git a/main/work/work.lib.php b/main/work/work.lib.php index e2d4640292..cecee86c90 100755 --- a/main/work/work.lib.php +++ b/main/work/work.lib.php @@ -2876,9 +2876,11 @@ function getWorkComments($work) } $sql = "SELECT - c.id, c.user_id, u.firstname, u.lastname, u.username, u.picture_uri + c.id, + c.user_id FROM $commentTable c - INNER JOIN $userTable u ON (u.user_id = c.user_id) + INNER JOIN $userTable u + ON (u.id = c.user_id) WHERE c_id = $courseId AND work_id = $workId ORDER BY sent_at "; @@ -2886,9 +2888,10 @@ function getWorkComments($work) $comments = Database::store_result($result, 'ASSOC'); if (!empty($comments)) { foreach ($comments as &$comment) { - $comment['picture'] = UserManager::getUserPicture($comment['user_id']); + $userInfo = api_get_user_info($comment['user_id']); + $comment['picture'] = $userInfo['avatar']; + $comment['complete_name'] = $userInfo['complete_name_with_username']; $commentInfo = getWorkComment($comment['id']); - if (!empty($commentInfo)) { $comment = array_merge($comment, $commentInfo); } From eb9f5c407b2b5730c753b87bb7c189c2dc7dae84 Mon Sep 17 00:00:00 2001 From: jmontoyaa Date: Wed, 5 Oct 2016 15:41:35 +0200 Subject: [PATCH 21/87] Fix PHP fatal error BT#11792 --- main/inc/lib/pear/excelreader/reader.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main/inc/lib/pear/excelreader/reader.php b/main/inc/lib/pear/excelreader/reader.php index 79465570db..7731795e2e 100755 --- a/main/inc/lib/pear/excelreader/reader.php +++ b/main/inc/lib/pear/excelreader/reader.php @@ -251,9 +251,9 @@ class Spreadsheet_Excel_Reader * * Some basic initialisation */ - function Spreadsheet_Excel_Reader() + public function __construct() { - $this->_ole =& new OLERead(); + $this->_ole = new OLERead(); $this->setUTFEncoder('iconv'); } From b0e46fde2be25a0a27e8ddf6995e373c02c7bca4 Mon Sep 17 00:00:00 2001 From: jmontoyaa Date: Wed, 5 Oct 2016 16:00:14 +0200 Subject: [PATCH 22/87] Minor - Improve code --- main/work/work.lib.php | 45 +++++++++++++++++++++++------------------- 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/main/work/work.lib.php b/main/work/work.lib.php index cecee86c90..c886ef8244 100755 --- a/main/work/work.lib.php +++ b/main/work/work.lib.php @@ -3083,7 +3083,7 @@ function getLastWorkStudentFromParentByUser( $sessionCondition = api_get_session_condition($sessionId); $sql = "SELECT * - FROM $work + FROM $work WHERE user_id = $userId $sessionCondition AND @@ -3231,9 +3231,9 @@ function addWorkComment($courseInfo, $userId, $parentWork, $work, $data) $content = sprintf(get_lang('ThereIsANewWorkFeedbackInWorkXHere'), $work['title'], $url); if (!empty($userIdListToSend)) { - foreach ($userIdListToSend as $userId) { + foreach ($userIdListToSend as $userIdToSend) { MessageManager::send_message_simple( - $userId, + $userIdToSend, $subject, $content ); @@ -3297,7 +3297,6 @@ function getWorkDateValidationStatus($homework) $has_ended = false; if (!empty($homework)) { - if (!empty($homework['expires_on']) || !empty($homework['ends_on'])) { $time_now = time(); @@ -4201,9 +4200,9 @@ function getFormWork($form, $defaults = array()) $form->addButtonAdvancedSettings('advanced_params', get_lang('AdvancedParameters')); if (!empty($defaults) && (isset($defaults['enableEndDate']) || isset($defaults['enableExpiryDate']))) { - $form->addElement('html', '
'); + $form->addHtml('
'); } else { - $form->addElement('html', '