Fix psalm issues: Double casting, add phpdoc, fix php warning

Update from 1.11.x
pull/3768/head
Julio Montoya 5 years ago
parent a8affdffce
commit 16bbf012b3
  1. 2
      public/main/course_info/download.php
  2. 9
      public/main/course_info/infocours.php
  3. 2
      public/main/forum/forumfunction.inc.php
  4. 28
      public/main/inc/ajax/course.ajax.php
  5. 683
      public/main/inc/ajax/exercise.ajax.php
  6. 1
      public/main/inc/ajax/extra_field.ajax.php
  7. 38
      public/main/inc/ajax/gradebook.ajax.php
  8. 3
      public/main/inc/ajax/myspace.ajax.php
  9. 1
      public/main/inc/ajax/record_audio_rtc.ajax.php
  10. 8
      public/main/inc/ajax/record_audio_wami.ajax.php
  11. 8
      public/main/inc/lib/pdf.lib.php
  12. 4
      public/main/social/group_topics.php
  13. 1
      public/main/social/home.php
  14. 6
      public/main/social/personal_data.php
  15. 3
      public/main/social/profile.php
  16. 12
      public/main/survey/ch_personality.php

@ -30,7 +30,7 @@ if (in_array($extension, ['xml', 'csv']) &&
(api_is_platform_admin(true) || api_is_drh()) (api_is_platform_admin(true) || api_is_drh())
) { ) {
$content_type = 'application/force-download'; $content_type = 'application/force-download';
} elseif ('zip' === $extension && $_cid && (api_is_platform_admin(true) || api_is_course_admin())) { } elseif ('zip' === $extension && api_get_course_id() && (api_is_platform_admin(true) || api_is_course_admin())) {
$content_type = 'application/force-download'; $content_type = 'application/force-download';
} }

@ -984,11 +984,8 @@ if ($form->validate() && $isEditable) {
$illustrationRepo->deleteIllustration($courseEntity); $illustrationRepo->deleteIllustration($courseEntity);
} }
global $_configuration; $limitCourses = api_get_configuration_value('hosting_limit_active_courses');
if (isset($_configuration[$urlId]) && if ($limitCourses > 0) {
isset($_configuration[$urlId]['hosting_limit_active_courses']) &&
$_configuration[$urlId]['hosting_limit_active_courses'] > 0
) {
$courseInfo = api_get_course_info_by_id($courseId); $courseInfo = api_get_course_info_by_id($courseId);
// Check if // Check if
@ -996,7 +993,7 @@ if ($form->validate() && $isEditable) {
$visibility != $courseInfo['visibility'] $visibility != $courseInfo['visibility']
) { ) {
$num = CourseManager::countActiveCourses($urlId); $num = CourseManager::countActiveCourses($urlId);
if ($num >= $_configuration[$urlId]['hosting_limit_active_courses']) { if ($num >= $limitCourses) {
api_warn_hosting_contact('hosting_limit_active_courses'); api_warn_hosting_contact('hosting_limit_active_courses');
Display::addFlash( Display::addFlash(

@ -765,7 +765,7 @@ function store_forum($values, $courseInfo = [], $returnId = false)
//'forum_image' => $new_file_name, //'forum_image' => $new_file_name,
$forum $forum
->setForumTitle($values['forum_title']) ->setForumTitle($values['forum_title'])
->setForumComment($values['forum_comment'] ?? null) ->setForumComment($values['forum_comment'] ?? '')
->setForumCategory($forumCategory) ->setForumCategory($forumCategory)
->setAllowAnonymous($values['allow_anonymous_group']['allow_anonymous'] ?? null) ->setAllowAnonymous($values['allow_anonymous_group']['allow_anonymous'] ?? null)
->setAllowEdit($values['students_can_edit_group']['students_can_edit'] ?? null) ->setAllowEdit($values['students_can_edit_group']['students_can_edit'] ?? null)

@ -153,14 +153,14 @@ switch ($action) {
//TODO change this function to search not only courses STARTING with $_GET['q'] //TODO change this function to search not only courses STARTING with $_GET['q']
if (api_is_platform_admin()) { if (api_is_platform_admin()) {
$courseList = CourseManager::get_courses_list( $courseList = CourseManager::get_courses_list(
0, //offset 0,
0, //howMany 0,
1, //$orderby = 1 1,
'ASC', 'ASC',
-1, //visibility -1,
$_GET['q'], $_GET['q'],
null, //$urlId null,
true //AlsoSearchCode true
); );
} elseif (api_is_teacher()) { } elseif (api_is_teacher()) {
$courseList = CourseManager::get_course_list_of_user_as_course_admin(api_get_user_id(), $_GET['q']); $courseList = CourseManager::get_course_list_of_user_as_course_admin(api_get_user_id(), $_GET['q']);
@ -257,12 +257,18 @@ switch ($action) {
} }
break; break;
case 'search_user_by_course': case 'search_user_by_course':
if (api_is_platform_admin()) { $sessionId = $_GET['session_id'];
$user = Database::get_main_table(TABLE_MAIN_USER); $course = api_get_course_info_by_id($_GET['course_id']);
$session_course_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
$sessionId = $_GET['session_id']; $isPlatformAdmin = api_is_platform_admin();
$course = api_get_course_info_by_id($_GET['course_id']); $userIsSubscribedInCourse = CourseManager::is_user_subscribed_in_course(
api_get_user_id(),
$course['code'],
!empty($sessionId),
$sessionId
);
if ($isPlatformAdmin || $userIsSubscribedInCourse) {
$json = [ $json = [
'items' => [], 'items' => [],
]; ];

@ -160,7 +160,6 @@ switch ($action) {
} }
// 1. Setting variables needed by jqgrid // 1. Setting variables needed by jqgrid
$action = $_GET['a'];
$exercise_id = (int) $_GET['exercise_id']; $exercise_id = (int) $_GET['exercise_id'];
$page = (int) $_REQUEST['page']; //page $page = (int) $_REQUEST['page']; //page
$limit = (int) $_REQUEST['rows']; //quantity of rows $limit = (int) $_REQUEST['rows']; //quantity of rows
@ -391,409 +390,431 @@ switch ($action) {
echo 1; echo 1;
exit; exit;
break; break;
case 'check_answers':
if (false === api_is_allowed_to_session_edit()) {
echo 'error';
exit;
}
/** @var Exercise $objExercise */
$objExercise = Session::read('objExercise');
$questionList = Session::read('questionList');
$exeId = Session::read('exe_id');
// If exercise or question is not set then exit.
if (empty($questionList) || empty($objExercise)) {
echo 'error';
exit;
}
$statInfo = $objExercise->get_stat_track_exercise_info_by_exe_id($exeId);
echo Display::page_subheader(get_lang('QuestionsToReview'));
echo $objExercise->getReminderTable($questionList, $statInfo, true);
break;
case 'save_exercise_by_now': case 'save_exercise_by_now':
$course_info = api_get_course_info_by_id($course_id); $course_info = api_get_course_info_by_id($course_id);
$course_id = $course_info['real_id']; $course_id = $course_info['real_id'];
// Use have permissions? // Use have permissions to edit exercises results now?
if (api_is_allowed_to_session_edit()) { if (false === api_is_allowed_to_session_edit()) {
// "all" or "simple" strings means that there's one or all questions exercise type echo 'error';
$type = isset($_REQUEST['type']) ? $_REQUEST['type'] : null; if ($debug) {
error_log(
'Exercises attempt '.$exeId.': Failed saving question(s) in course/session '.
$course_id.'/'.$session_id.
': The user ('.api_get_user_id().') does not have the permission to access this session now'
);
}
exit;
}
// "all" or "simple" strings means that there's one or all questions exercise type
$type = isset($_REQUEST['type']) ? $_REQUEST['type'] : null;
// Questions choices. // Questions choices.
$choice = isset($_REQUEST['choice']) ? $_REQUEST['choice'] : []; $choice = isset($_REQUEST['choice']) ? $_REQUEST['choice'] : [];
// certainty degree choice // certainty degree choice
$choiceDegreeCertainty = $_REQUEST['choiceDegreeCertainty'] ?? []; $choiceDegreeCertainty = $_REQUEST['choiceDegreeCertainty'] ?? [];
// Hot spot coordinates from all questions. // Hot spot coordinates from all questions.
$hot_spot_coordinates = isset($_REQUEST['hotspot']) ? $_REQUEST['hotspot'] : []; $hot_spot_coordinates = isset($_REQUEST['hotspot']) ? $_REQUEST['hotspot'] : [];
// There is a reminder? // There is a reminder?
$remind_list = isset($_REQUEST['remind_list']) && !empty($_REQUEST['remind_list']) $remind_list = isset($_REQUEST['remind_list']) && !empty($_REQUEST['remind_list'])
? array_keys($_REQUEST['remind_list']) : []; ? array_keys($_REQUEST['remind_list']) : [];
// Needed in manage_answer. // Needed in manage_answer.
$learnpath_id = isset($_REQUEST['learnpath_id']) ? (int) $_REQUEST['learnpath_id'] : 0; $learnpath_id = isset($_REQUEST['learnpath_id']) ? (int) $_REQUEST['learnpath_id'] : 0;
$learnpath_item_id = isset($_REQUEST['learnpath_item_id']) ? (int) $_REQUEST['learnpath_item_id'] : 0; $learnpath_item_id = isset($_REQUEST['learnpath_item_id']) ? (int) $_REQUEST['learnpath_item_id'] : 0;
// Attempt id. // Attempt id.
if ($debug) { if ($debug) {
error_log("exe_id = $exeId"); error_log("exe_id = $exeId");
error_log("type = $type"); error_log("type = $type");
error_log('choice = '.print_r($choice, 1).' '); error_log('choice = '.print_r($choice, 1).' ');
error_log('hot_spot_coordinates = '.print_r($hot_spot_coordinates, 1)); error_log('hot_spot_coordinates = '.print_r($hot_spot_coordinates, 1));
error_log('remind_list = '.print_r($remind_list, 1)); error_log('remind_list = '.print_r($remind_list, 1));
error_log('--------------------------------'); error_log('--------------------------------');
} }
// Exercise information. // Exercise information.
/** @var Exercise $objExercise */ /** @var Exercise $objExercise */
$objExercise = Session::read('objExercise'); $objExercise = Session::read('objExercise');
// Question info. // Question info.
$question_id = isset($_REQUEST['question_id']) ? (int) $_REQUEST['question_id'] : null; $question_id = isset($_REQUEST['question_id']) ? (int) $_REQUEST['question_id'] : null;
$question_list = Session::read('questionList'); $question_list = Session::read('questionList');
// If exercise or question is not set then exit. // If exercise or question is not set then exit.
if (empty($question_list) || empty($objExercise)) { if (empty($question_list) || empty($objExercise)) {
echo 'error'; echo 'error';
if ($debug) { if ($debug) {
if (empty($question_list)) { if (empty($question_list)) {
error_log('question_list is empty'); error_log('question_list is empty');
}
if (empty($objExercise)) {
error_log('objExercise is empty');
}
} }
exit; if (empty($objExercise)) {
} error_log('objExercise is empty');
if (WhispeakAuthPlugin::questionRequireAuthentify($question_id)) {
if (ONE_PER_PAGE == $objExercise->type) {
echo 'one_per_page';
break;
} }
}
exit;
}
echo 'ok'; if (WhispeakAuthPlugin::questionRequireAuthentify($question_id)) {
if (ONE_PER_PAGE == $objExercise->type) {
echo 'one_per_page';
break; break;
} else {
ChamiloSession::erase(WhispeakAuthPlugin::SESSION_QUIZ_QUESTION);
} }
// Getting information of the current exercise. echo 'ok';
$exercise_stat_info = $objExercise->get_stat_track_exercise_info_by_exe_id($exeId); break;
$exercise_id = $exercise_stat_info['exe_exo_id']; } else {
$attemptList = []; ChamiloSession::erase(WhispeakAuthPlugin::SESSION_QUIZ_QUESTION);
}
// Getting information of the current exercise.
$exercise_stat_info = $objExercise->get_stat_track_exercise_info_by_exe_id($exeId);
$exercise_id = $exercise_stat_info['exe_exo_id'];
$attemptList = [];
// First time here we create an attempt (getting the exe_id). // First time here we create an attempt (getting the exe_id).
if (!empty($exercise_stat_info)) { if (!empty($exercise_stat_info)) {
// We know the user we get the exe_id. // We know the user we get the exe_id.
$exeId = $exercise_stat_info['exe_id']; $exeId = $exercise_stat_info['exe_id'];
$total_score = $exercise_stat_info['score']; $total_score = $exercise_stat_info['score'];
// Getting the list of attempts // Getting the list of attempts
$attemptList = Event::getAllExerciseEventByExeId($exeId); $attemptList = Event::getAllExerciseEventByExeId($exeId);
} }
// Updating Reminder algorithm. // No exe id? Can't save answer.
if (empty($exeId)) { if (empty($exeId)) {
// Fires an error. // Fires an error.
echo 'error'; echo 'error';
if ($debug) { if ($debug) {
error_log('exe_id is empty'); error_log('exe_id is empty');
}
exit;
} }
exit;
}
Session::write('exe_id', $exeId); Session::write('exe_id', $exeId);
// Updating Reminder algorithm. // Updating Reminder algorithm.
if (ONE_PER_PAGE == $objExercise->type) { if (ONE_PER_PAGE == $objExercise->type) {
$bd_reminder_list = explode(',', $exercise_stat_info['questions_to_check']); $bd_reminder_list = explode(',', $exercise_stat_info['questions_to_check']);
if (empty($remind_list)) { if (empty($remind_list)) {
$remind_list = $bd_reminder_list; $remind_list = $bd_reminder_list;
$new_list = []; $new_list = [];
foreach ($bd_reminder_list as $item) { foreach ($bd_reminder_list as $item) {
if ($item != $question_id) { if ($item != $question_id) {
$new_list[] = $item; $new_list[] = $item;
}
} }
$remind_list = $new_list; }
} else { $remind_list = $new_list;
if (isset($remind_list[0])) { } else {
if (!in_array($remind_list[0], $bd_reminder_list)) { if (isset($remind_list[0])) {
array_push($bd_reminder_list, $remind_list[0]); if (!in_array($remind_list[0], $bd_reminder_list)) {
} array_push($bd_reminder_list, $remind_list[0]);
$remind_list = $bd_reminder_list;
} }
$remind_list = $bd_reminder_list;
} }
} }
}
// No exe id? Can't save answer. // Getting the total weight if the request is simple.
$total_weight = 0; $total_weight = 0;
if ('simple' === $type) { if ('simple' === $type) {
foreach ($question_list as $my_question_id) { foreach ($question_list as $my_question_id) {
$objQuestionTmp = Question::read($my_question_id, $objExercise->course); $objQuestionTmp = Question::read($my_question_id, $objExercise->course);
$total_weight += $objQuestionTmp->selectWeighting(); $total_weight += $objQuestionTmp->selectWeighting();
}
}
unset($objQuestionTmp);
// Fires an error.
if ($debug) {
error_log('Starting questions loop in save_exercise_by_now');
} }
}
unset($objQuestionTmp);
if ($debug) {
error_log('Starting questions loop in save_exercise_by_now');
}
// Getting the total weight if the request is simple // Check we have at least one non-empty answer in the array
if ('all' === $type) { // provided by the user's click on the "Finish test" button.
$atLeastOneAnswer = false; if ('all' === $type) {
foreach ($question_list as $my_question_id) { $atLeastOneAnswer = false;
if (!empty($choice[$my_question_id])) { foreach ($question_list as $my_question_id) {
$atLeastOneAnswer = true; if (!empty($choice[$my_question_id])) {
break; $atLeastOneAnswer = true;
} break;
}
if (!$atLeastOneAnswer) {
error_log(
'In '.__FILE__.'::action save_exercise_by_now,'.
' from user '.api_get_user_id().
' for track_e_exercises.exe_id = '.$exeId.
', we received an empty set of answers.'.
'Preventing submission to avoid overwriting w/ null.');
echo 'error';
exit;
} }
} }
if (!$atLeastOneAnswer) {
error_log(
'In '.__FILE__.'::action save_exercise_by_now,'.
' from user '.api_get_user_id().
' for track_e_exercises.exe_id = '.$exeId.
', we received an empty set of answers.'.
'Preventing submission to avoid overwriting w/ null.');
echo 'error';
exit;
}
}
// Looping the question list // Looping the question list from database (not from the user answer)
foreach ($question_list as $my_question_id) { foreach ($question_list as $my_question_id) {
if ('simple' === $type && $question_id != $my_question_id) { if ('simple' === $type && $question_id != $my_question_id) {
if ($debug) { if ($debug) {
error_log('Skipping question '.$my_question_id.' in single-question save action'); error_log('Skipping question '.$my_question_id.' in single-question save action');
}
continue;
} }
continue;
}
$my_choice = isset($choice[$my_question_id]) ? $choice[$my_question_id] : null; $my_choice = isset($choice[$my_question_id]) ? $choice[$my_question_id] : null;
// Creates a temporary Question object
$objQuestionTmp = Question::read($my_question_id, $objExercise->course);
$myChoiceDegreeCertainty = null; $objQuestionTmp = Question::read($my_question_id, $objExercise->course);
if (MULTIPLE_ANSWER_TRUE_FALSE_DEGREE_CERTAINTY === $objQuestionTmp->type) {
if (isset($choiceDegreeCertainty[$my_question_id])) {
$myChoiceDegreeCertainty = $choiceDegreeCertainty[$my_question_id];
}
}
// Getting free choice data. $myChoiceDegreeCertainty = null;
if (in_array($objQuestionTmp->type, [FREE_ANSWER, ORAL_EXPRESSION]) && 'all' == $type) { if (MULTIPLE_ANSWER_TRUE_FALSE_DEGREE_CERTAINTY === $objQuestionTmp->type) {
$my_choice = isset($_REQUEST['free_choice'][$my_question_id]) && !empty($_REQUEST['free_choice'][$my_question_id]) if (isset($choiceDegreeCertainty[$my_question_id])) {
? $_REQUEST['free_choice'][$my_question_id] $myChoiceDegreeCertainty = $choiceDegreeCertainty[$my_question_id];
: null;
} }
}
if ('all' === $type) { // Getting free choice data.
// If saving the whole exercise (not only one question), if (in_array($objQuestionTmp->type, [FREE_ANSWER, ORAL_EXPRESSION]) && 'all' == $type) {
// record the sum of individual max scores (called $my_choice = isset($_REQUEST['free_choice'][$my_question_id]) && !empty($_REQUEST['free_choice'][$my_question_id])
// "exe_weighting" in track_e_exercises) ? $_REQUEST['free_choice'][$my_question_id]
$total_weight += $objQuestionTmp->selectWeighting(); : null;
} }
// This variable came from exercise_submit_modal.php. if ('all' === $type) {
$hotspot_delineation_result = null; // If saving the whole exercise (not only one question),
if (isset($_SESSION['hotspot_delineation_result']) && // record the sum of individual max scores (called
isset($_SESSION['hotspot_delineation_result'][$objExercise->getId()]) // "exe_weighting" in track_e_exercises)
) { $total_weight += $objQuestionTmp->selectWeighting();
$hotspot_delineation_result = $_SESSION['hotspot_delineation_result'][$objExercise->getId()][$my_question_id]; }
}
if ('simple' === $type) { // This variable came from exercise_submit_modal.php.
// Getting old attempt in order to decrees the total score. $hotspot_delineation_result = null;
$old_result = $objExercise->manage_answer( if (isset($_SESSION['hotspot_delineation_result']) &&
$exeId, isset($_SESSION['hotspot_delineation_result'][$objExercise->getId()])
$my_question_id, ) {
null, $hotspot_delineation_result = $_SESSION['hotspot_delineation_result'][$objExercise->getId()][$my_question_id];
'exercise_show', }
[],
false,
true,
false,
$objExercise->selectPropagateNeg()
);
// Removing old score.
$total_score = $total_score - $old_result['score'];
}
$questionDuration = 0; if ('simple' === $type) {
if (api_get_configuration_value('allow_time_per_question')) { // Getting old attempt in order to decrease the total score.
$extraFieldValue = new ExtraFieldValue('question'); $old_result = $objExercise->manage_answer(
$value = $extraFieldValue->get_values_by_handler_and_field_variable($objQuestionTmp->iid, 'time'); $exeId,
if (!empty($value) && isset($value['value']) && !empty($value['value'])) { $my_question_id,
$questionDuration = Event::getAttemptQuestionDuration($exeId, $objQuestionTmp->iid); null,
if (empty($questionDuration)) { 'exercise_show',
echo 'error'; [],
if ($debug) { false,
error_log("Question duration = 0, in exeId: $exeId, question_id: $my_question_id"); true,
} false,
exit; $objExercise->selectPropagateNeg()
);
// Removing old score.
$total_score = $total_score - $old_result['score'];
}
$questionDuration = 0;
if (api_get_configuration_value('allow_time_per_question')) {
$extraFieldValue = new ExtraFieldValue('question');
$value = $extraFieldValue->get_values_by_handler_and_field_variable($objQuestionTmp->iid, 'time');
if (!empty($value) && isset($value['value']) && !empty($value['value'])) {
$questionDuration = Event::getAttemptQuestionDuration($exeId, $objQuestionTmp->iid);
if (empty($questionDuration)) {
echo 'error';
if ($debug) {
error_log("Question duration = 0, in exeId: $exeId, question_id: $my_question_id");
} }
exit;
} }
} }
// Deleting old attempt }
if (isset($attemptList) && !empty($attemptList[$my_question_id])) { // Deleting old attempt.
if ($debug) { if (isset($attemptList) && !empty($attemptList[$my_question_id])) {
error_log("delete_attempt exe_id : $exeId, my_question_id: $my_question_id"); if ($debug) {
} error_log("delete_attempt exe_id : $exeId, my_question_id: $my_question_id");
Event::delete_attempt( }
Event::delete_attempt(
$exeId,
api_get_user_id(),
$course_id,
$session_id,
$my_question_id
);
if (HOT_SPOT === $objQuestionTmp->type) {
Event::delete_attempt_hotspot(
$exeId, $exeId,
api_get_user_id(), api_get_user_id(),
$course_id, $course_id,
$session_id, $session_id,
$my_question_id $my_question_id
); );
if (HOT_SPOT === $objQuestionTmp->type) {
Event::delete_attempt_hotspot(
$exeId,
api_get_user_id(),
$course_id,
$session_id,
$my_question_id
);
}
if (isset($attemptList[$my_question_id]) &&
isset($attemptList[$my_question_id]['marks'])
) {
$total_score -= $attemptList[$my_question_id]['marks'];
}
} }
// We're inside *one* question. Go through each possible answer for this question if (isset($attemptList[$my_question_id]) &&
if (MULTIPLE_ANSWER_TRUE_FALSE_DEGREE_CERTAINTY === $objQuestionTmp->type) { isset($attemptList[$my_question_id]['marks'])
$myChoiceTmp = []; ) {
$myChoiceTmp['choice'] = $my_choice; $total_score -= $attemptList[$my_question_id]['marks'];
$myChoiceTmp['choiceDegreeCertainty'] = $myChoiceDegreeCertainty;
$result = $objExercise->manage_answer(
$exeId,
$my_question_id,
$myChoiceTmp,
'exercise_result',
$hot_spot_coordinates,
true,
false,
false,
$objExercise->selectPropagateNeg(),
$hotspot_delineation_result,
true,
false,
false,
$questionDuration
);
} else {
$result = $objExercise->manage_answer(
$exeId,
$my_question_id,
$my_choice,
'exercise_result',
$hot_spot_coordinates,
true,
false,
false,
$objExercise->selectPropagateNeg(),
$hotspot_delineation_result,
true,
false,
false,
$questionDuration
);
} }
}
// Adding the new score. // We're inside *one* question. Go through each possible answer for this question
$total_score += $result['score']; if (MULTIPLE_ANSWER_TRUE_FALSE_DEGREE_CERTAINTY === $objQuestionTmp->type) {
$myChoiceTmp = [];
$myChoiceTmp['choice'] = $my_choice;
$myChoiceTmp['choiceDegreeCertainty'] = $myChoiceDegreeCertainty;
$result = $objExercise->manage_answer(
$exeId,
$my_question_id,
$myChoiceTmp,
'exercise_result',
$hot_spot_coordinates,
true,
false,
false,
$objExercise->selectPropagateNeg(),
$hotspot_delineation_result,
true,
false,
false,
$questionDuration
);
} else {
$result = $objExercise->manage_answer(
$exeId,
$my_question_id,
$my_choice,
'exercise_result',
$hot_spot_coordinates,
true,
false,
false,
$objExercise->selectPropagateNeg(),
$hotspot_delineation_result,
true,
false,
false,
$questionDuration
);
}
if ($debug) { // Adding the new score.
error_log("total_score: $total_score "); $total_score += $result['score'];
error_log("total_weight: $total_weight ");
}
$duration = 0; if ($debug) {
$now = time(); error_log("total_score: $total_score ");
if ('all' == $type) { error_log("total_weight: $total_weight ");
$exercise_stat_info = $objExercise->get_stat_track_exercise_info_by_exe_id($exeId); }
}
$key = ExerciseLib::get_time_control_key( $duration = 0;
$exercise_id, $now = time();
$exercise_stat_info['orig_lp_id'], if ('all' == $type) {
$exercise_stat_info['orig_lp_item_id'] $exercise_stat_info = $objExercise->get_stat_track_exercise_info_by_exe_id($exeId);
); }
$durationTime = Session::read('duration_time'); $key = ExerciseLib::get_time_control_key(
if (isset($durationTime[$key]) && !empty($durationTime[$key])) { $exercise_id,
if ($debug) { $exercise_stat_info['orig_lp_id'],
error_log('Session time :'.$durationTime[$key]); $exercise_stat_info['orig_lp_item_id']
} );
$duration = $now - $durationTime[$key];
if (!empty($exercise_stat_info['exe_duration'])) {
$duration += $exercise_stat_info['exe_duration'];
}
$duration = (int) $duration;
} else {
if (!empty($exercise_stat_info['exe_duration'])) {
$duration = $exercise_stat_info['exe_duration'];
}
}
$durationTime = Session::read('duration_time');
if (isset($durationTime[$key]) && !empty($durationTime[$key])) {
if ($debug) { if ($debug) {
error_log('duration to save in DB:'.$duration); error_log('Session time :'.$durationTime[$key]);
}
$duration = $now - $durationTime[$key];
if (!empty($exercise_stat_info['exe_duration'])) {
$duration += $exercise_stat_info['exe_duration'];
}
$duration = (int) $duration;
} else {
if (!empty($exercise_stat_info['exe_duration'])) {
$duration = $exercise_stat_info['exe_duration'];
} }
}
Session::write('duration_time', [$key => $now]); if ($debug) {
Event::updateEventExercise( error_log('duration to save in DB:'.$duration);
$exeId, }
$objExercise->getId(),
$total_score, Session::write('duration_time', [$key => $now]);
$total_weight, Event::updateEventExercise(
$session_id, $exeId,
$exercise_stat_info['orig_lp_id'], $objExercise->getId(),
$exercise_stat_info['orig_lp_item_id'], $total_score,
$exercise_stat_info['orig_lp_item_view_id'], $total_weight,
$duration, $session_id,
$question_list, $exercise_stat_info['orig_lp_id'],
'incomplete', $exercise_stat_info['orig_lp_item_id'],
$remind_list $exercise_stat_info['orig_lp_item_view_id'],
); $duration,
$question_list,
'incomplete',
$remind_list
);
if (api_get_configuration_value('allow_time_per_question')) { if (api_get_configuration_value('allow_time_per_question')) {
$questionStart = Session::read('question_start', []); $questionStart = Session::read('question_start', []);
if (!empty($questionStart)) { if (!empty($questionStart)) {
if (isset($questionStart[$my_question_id])) { if (isset($questionStart[$my_question_id])) {
unset($questionStart[$my_question_id]); unset($questionStart[$my_question_id]);
}
array_filter($questionStart);
Session::write('question_start', $questionStart);
} }
} array_filter($questionStart);
Session::write('question_start', $questionStart);
/*HookQuizQuestionAnswered::create()
->setEventData(
[
'exe_id' => (int) $exeId,
'quiz' => [
'id' => (int) $objExercise->id,
'title' => $objExercise->selectTitle(true),
],
'question' => [
'id' => (int) $my_question_id,
'weight' => (float) $result['weight'],
],
]
)
->notifyQuizQuestionAnswered();*/
// Destruction of the Question object
unset($objQuestionTmp);
if ($debug) {
error_log('---------- end question ------------');
} }
} }
/*HookQuizQuestionAnswered::create()
->setEventData(
[
'exe_id' => (int) $exeId,
'quiz' => [
'id' => (int) $objExercise->id,
'title' => $objExercise->selectTitle(true),
],
'question' => [
'id' => (int) $my_question_id,
'weight' => (float) $result['weight'],
],
]
)
->notifyQuizQuestionAnswered();*/
// Destruction of the Question object
unset($objQuestionTmp);
if ($debug) { if ($debug) {
error_log('Finished questions loop in save_exercise_by_now'); error_log('---------- end question ------------');
} }
} else { }
if ($debug) {
error_log('Finished questions loop in save_exercise_by_now');
}
if ($type === 'all') {
if ($debug) { if ($debug) {
error_log( error_log("result: ok - all");
'Exercises attempt '.$exeId.': Failed saving question(s) in course/session '. error_log(" ------ end ajax call ------- ");
$course_id.'/'.$session_id.
': The user ('.
api_get_user_id().
') does not have the permission to access this session now');
} }
echo 'error';
exit;
}
if ('all' == $type) {
echo 'ok'; echo 'ok';
exit; exit;
} }

@ -151,7 +151,6 @@ switch ($action) {
dataType: "json", dataType: "json",
data: "values="+save, data: "values="+save,
success: function(data) { success: function(data) {
console.log(data);
} }
}); });

@ -53,6 +53,44 @@ switch ($action) {
$form->display(); $form->display();
} }
break;*/ break;*/
case 'export_all_certificates':
$categoryId = (int) $_GET['cat_id'];
$filterOfficialCodeGet = isset($_GET['filter']) ? Security::remove_XSS($_GET['filter']) : null;
if (api_is_student_boss()) {
$userGroup = new UserGroup();
$userList = $userGroup->getGroupUsersByUser(api_get_user_id());
} else {
$userList = [];
if (!empty($filterOfficialCodeGet)) {
$userList = UserManager::getUsersByOfficialCode($filterOfficialCodeGet);
}
}
$courseCode = api_get_course_id();
$sessionId = api_get_session_id();
$commandScript = api_get_path(SYS_CODE_PATH).'gradebook/cli/export_all_certificates.php';
$userList = implode(',', $userList);
shell_exec("php $commandScript $courseCode $sessionId $categoryId $userList > /dev/null &");
break;
case 'verify_export_all_certificates':
$categoryId = (int) $_GET['cat_id'];
$courseCode = isset($_GET['cidReq']) ? Security::remove_XSS($_GET['cidReq']) : api_get_course_id();
$sessionId = isset($_GET['id_session']) ? (int) $_GET['id_session'] : api_get_session_id();
$date = api_get_utc_datetime(null, false, true);
$pdfName = 'certs_'.$courseCode.'_'.$sessionId.'_'.$categoryId.'_'.$date->format('Y-m-d');
$sysFinalFile = api_get_path(SYS_ARCHIVE_PATH)."$pdfName.pdf";
$webFinalFile = api_get_path(WEB_ARCHIVE_PATH)."$pdfName.pdf";
if (file_exists($sysFinalFile)) {
echo $webFinalFile;
}
break;
default: default:
echo ''; echo '';
break; break;

@ -23,7 +23,6 @@ switch ($action) {
if (empty($userId)) { if (empty($userId)) {
exit; exit;
} }
// At this date : 23/02/2017, a minor review can't determine where is used this case 'access_detail'
$cacheAvailable = api_get_configuration_value('apc'); $cacheAvailable = api_get_configuration_value('apc');
$table = null; $table = null;
$variable = 'lp_global_report_'.$userId; $variable = 'lp_global_report_'.$userId;
@ -41,7 +40,7 @@ switch ($action) {
$sessionCategoryList = UserManager::get_sessions_by_category($userId, false); $sessionCategoryList = UserManager::get_sessions_by_category($userId, false);
$total = 0; $total = 0;
$totalAverage = 0; $totalAverage = 0;
$table = new HTML_Table(['class' => 'data_table']); $table = new HTML_Table(['class' => 'table table-hover table-striped data_table']);
$row = 0; $row = 0;
$col = 0; $col = 0;
foreach ($sessionCategoryList as $category) { foreach ($sessionCategoryList as $category) {

@ -5,7 +5,6 @@ use ChamiloSession as Session;
require_once __DIR__.'/../global.inc.php'; require_once __DIR__.'/../global.inc.php';
// Add security from Chamilo
api_block_anonymous_users(); api_block_anonymous_users();
$courseInfo = api_get_course_info(); $courseInfo = api_get_course_info();

@ -19,12 +19,12 @@ if (isset($params['waminame']) && isset($params['wamidir']) && isset($params['wa
$wamiuserid = $params['wamiuserid']; $wamiuserid = $params['wamiuserid'];
} else { } else {
api_not_allowed(); api_not_allowed();
die(); exit();
} }
if (empty($wamiuserid)) { if (empty($wamiuserid)) {
api_not_allowed(); api_not_allowed();
die(); exit();
} }
$type = isset($_REQUEST['type']) ? $_REQUEST['type'] : 'document'; // can be document or message $type = isset($_REQUEST['type']) ? $_REQUEST['type'] : 'document'; // can be document or message
@ -49,7 +49,7 @@ $ext = explode('.', $waminame);
$ext = strtolower($ext[sizeof($ext) - 1]); $ext = strtolower($ext[sizeof($ext) - 1]);
if ('wav' != $ext) { if ('wav' != $ext) {
die(); exit();
} }
switch ($type) { switch ($type) {
@ -67,7 +67,7 @@ switch ($type) {
$documentPath = $saveDir.'/'.$waminame_to_save; $documentPath = $saveDir.'/'.$waminame_to_save;
// Add to disk // Add to disk
$fh = fopen($documentPath, 'w') or die("can't open file"); $fh = fopen($documentPath, 'w') or exit("can't open file");
fwrite($fh, $content); fwrite($fh, $content);
fclose($fh); fclose($fh);

@ -559,10 +559,10 @@ class PDF
* *
* @return bool * @return bool
*/ */
public function delete_watermark($courseCode = null) public static function delete_watermark($courseCode = null)
{ {
$urlId = api_get_current_access_url_id(); $urlId = api_get_current_access_url_id();
if (!empty($courseCode) && 'true' == api_get_setting('pdf_export_watermark_by_course')) { if (!empty($courseCode) && 'true' === api_get_setting('pdf_export_watermark_by_course')) {
$course_info = api_get_course_info($courseCode); $course_info = api_get_course_info($courseCode);
// course path // course path
$store_path = api_get_path(SYS_COURSE_PATH).$course_info['path'].'/'.$urlId.'_pdf_watermark.png'; $store_path = api_get_path(SYS_COURSE_PATH).$course_info['path'].'/'.$urlId.'_pdf_watermark.png';
@ -588,10 +588,10 @@ class PDF
* *
* @return mixed web path of the file if sucess, false otherwise * @return mixed web path of the file if sucess, false otherwise
*/ */
public function upload_watermark($filename, $source_file, $courseCode = null) public static function upload_watermark($filename, $source_file, $courseCode = null)
{ {
$urlId = api_get_current_access_url_id(); $urlId = api_get_current_access_url_id();
if (!empty($courseCode) && 'true' == api_get_setting('pdf_export_watermark_by_course')) { if (!empty($courseCode) && 'true' === api_get_setting('pdf_export_watermark_by_course')) {
$course_info = api_get_course_info($courseCode); $course_info = api_get_course_info($courseCode);
$store_path = api_get_path(SYS_COURSE_PATH).$course_info['path']; // course path $store_path = api_get_path(SYS_COURSE_PATH).$course_info['path']; // course path
$web_path = api_get_path(WEB_COURSE_PATH).$course_info['path'].'/pdf_watermark.png'; $web_path = api_get_path(WEB_COURSE_PATH).$course_info['path'].'/pdf_watermark.png';

@ -51,9 +51,7 @@ if (isset($_REQUEST['action']) && 'delete' == $_REQUEST['action']) {
} }
// My friends // My friends
$friend_html = SocialManager::listMyFriendsBlock( $friend_html = SocialManager::listMyFriendsBlock(api_get_user_id());
$user_id
);
$content = null; $content = null;
$social_right_content = ''; $social_right_content = '';

@ -39,6 +39,7 @@ if (!empty($threadList)) {
$posts = SocialManager::getMyWallMessages($user_id, 0, 10, $threadIdList); $posts = SocialManager::getMyWallMessages($user_id, 0, 10, $threadIdList);
$countPost = $posts['count']; $countPost = $posts['count'];
$posts = $posts['posts']; $posts = $posts['posts'];
$htmlHeadXtra = [];
SocialManager::getScrollJs($countPost, $htmlHeadXtra); SocialManager::getScrollJs($countPost, $htmlHeadXtra);
// Block Menu // Block Menu

@ -88,14 +88,14 @@ switch ($action) {
$contentEmail = sprintf( $contentEmail = sprintf(
get_lang('User %s signed the agreement.TheDateY'), get_lang('User %s signed the agreement.TheDateY'),
$currentUserInfo['complete_name'], $currentUserInfo['complete_name'],
api_get_local_time($time) api_get_local_time()
); );
MessageManager::send_message_simple( MessageManager::send_message_simple(
$bossId, $bossId,
$subjectEmail, $subjectEmail,
$contentEmail, $contentEmail,
$user_id api_get_user_id()
); );
} }
} }
@ -400,7 +400,7 @@ $personalData['data'] = $personalDataContent;
$em = Database::getManager(); $em = Database::getManager();
/** @var LegalRepository $legalTermsRepo */ /** @var LegalRepository $legalTermsRepo */
$legalTermsRepo = $em->getRepository('ChamiloCoreBundle:Legal'); $legalTermsRepo = $em->getRepository(\Chamilo\CoreBundle\Entity\Legal::class);
// Get data about the treatment of data // Get data about the treatment of data
$treatmentTypes = LegalManager::getTreatmentTypeList(); $treatmentTypes = LegalManager::getTreatmentTypeList();

@ -106,6 +106,7 @@ if (isset($_GET['u'])) {
api_block_anonymous_users(); api_block_anonymous_users();
$countPost = SocialManager::getCountWallMessagesByUser($friendId); $countPost = SocialManager::getCountWallMessagesByUser($friendId);
$htmlHeadXtra = [];
SocialManager::getScrollJs($countPost, $htmlHeadXtra); SocialManager::getScrollJs($countPost, $htmlHeadXtra);
$link_shared = ''; $link_shared = '';
if (isset($_GET['shared'])) { if (isset($_GET['shared'])) {
@ -237,7 +238,7 @@ if ($show_full_profile) {
if (!empty($user_info['competences']) || !empty($user_info['diplomas']) if (!empty($user_info['competences']) || !empty($user_info['diplomas'])
|| !empty($user_info['openarea']) || !empty($user_info['teach'])) { || !empty($user_info['openarea']) || !empty($user_info['teach'])) {
$more_info .= '<div><h3>'.get_lang('More information').'</h3></div>'; $more_info = '<div><h3>'.get_lang('More information').'</h3></div>';
if (!empty($user_info['competences'])) { if (!empty($user_info['competences'])) {
$more_info .= '<br />'; $more_info .= '<br />';
$more_info .= '<div class="social-actions-message"><strong>'.get_lang('My competences').'</strong></div>'; $more_info .= '<div class="social-actions-message"><strong>'.get_lang('My competences').'</strong></div>';

@ -53,6 +53,7 @@ class ch_personality extends survey_question
// Values of question options // Values of question options
if (is_array($formData['values'])) { // Check if data is correct if (is_array($formData['values'])) { // Check if data is correct
foreach ($formData['values'] as $key => &$value) { foreach ($formData['values'] as $key => &$value) {
$value = Security::remove_XSS($value);
$question_values[] = '<input size="3" type="text" id="values['.$key.']" name="values['.$key.']" value="'.$value.'" />'; $question_values[] = '<input size="3" type="text" id="values['.$key.']" name="values['.$key.']" value="'.$value.'" />';
} }
} }
@ -62,14 +63,9 @@ class ch_personality extends survey_question
$this->html .= '<tr>'; $this->html .= '<tr>';
$this->html .= '<td align="right"><label for="answers['.$key.']">'.($key + 1).'</label></td>'; $this->html .= '<td align="right"><label for="answers['.$key.']">'.($key + 1).'</label></td>';
$this->html .= '<td width="550">'; $this->html .= '<td width="550">';
$this->html .= api_return_html_area( $dataValue = api_html_entity_decode(stripslashes($formData['answers'][$key]));
'answers['.$key.']', $dataValue = Security::remove_XSS($dataValue);
api_html_entity_decode(stripslashes($formData['answers'][$key])), $this->html .= '<textarea name="answers['.$key.']" >'.$dataValue.'</textarea>';
'',
'',
null,
['ToolbarSet' => 'Survey', 'Width' => '100%', 'Height' => '120']
);
$this->html .= '</td>'; $this->html .= '</td>';
$this->html .= '<td>'; $this->html .= '<td>';

Loading…
Cancel
Save