';
if ($objExercise->selectPropagateNeg() == 0 && $myTotalScoreTemp < 0) {
diff --git a/main/exercise/question_list_admin.inc.php b/main/exercise/question_list_admin.inc.php
index 8e48d46f8c..44d3014ded 100755
--- a/main/exercise/question_list_admin.inc.php
+++ b/main/exercise/question_list_admin.inc.php
@@ -216,13 +216,17 @@ if (!$inATest) {
if (is_array($questionList)) {
foreach ($questionList as $id) {
- //To avoid warning messages
+ // To avoid warning messages.
if (!is_numeric($id)) {
continue;
}
/** @var Question $objQuestionTmp */
$objQuestionTmp = Question::read($id);
+ if (empty($objQuestionTmp)) {
+ continue;
+ }
+
$clone_link = Display::url(
Display::return_icon(
'cd.png',
@@ -233,7 +237,8 @@ if (!$inATest) {
api_get_self().'?'.api_get_cidreq().'&clone_question='.$id.'&page='.$page,
['class' => 'btn btn-default btn-sm']
);
- $edit_link = $objQuestionTmp->type == CALCULATED_ANSWER && $objQuestionTmp->isAnswered()
+
+ $edit_link = $objQuestionTmp->selectType() == CALCULATED_ANSWER && $objQuestionTmp->isAnswered()
? Display::span(
Display::return_icon(
'edit_na.png',
@@ -311,11 +316,11 @@ if (!$inATest) {
TestCategory::getCategoryNameForQuestion($objQuestionTmp->id)
);
if (empty($txtQuestionCat)) {
- $txtQuestionCat = "-";
+ $txtQuestionCat = '-';
}
// Question level
- $txtQuestionLevel = $objQuestionTmp->level;
+ $txtQuestionLevel = $objQuestionTmp->getLevel();
if (empty($objQuestionTmp->level)) {
$txtQuestionLevel = '-';
}
diff --git a/main/exercise/stats.php b/main/exercise/stats.php
index cdd75fc7a1..86084cd749 100755
--- a/main/exercise/stats.php
+++ b/main/exercise/stats.php
@@ -235,7 +235,7 @@ if (!empty($question_list)) {
$answer_id,
$question_id,
$exerciseId,
- api_get_course_int_id(),
+ $courseCode,
$sessionId
);
$percentage = 0;
diff --git a/main/forum/forumfunction.inc.php b/main/forum/forumfunction.inc.php
index 8a10ba8eee..5457d937a6 100755
--- a/main/forum/forumfunction.inc.php
+++ b/main/forum/forumfunction.inc.php
@@ -100,7 +100,7 @@ function handle_forum_and_forumcategories($lp_id = null)
$get_content = isset($_GET['content']) ? $_GET['content'] : '';
$post_submit_cat = isset($_POST['SubmitForumCategory']) ? true : false;
$post_submit_forum = isset($_POST['SubmitForum']) ? true : false;
- $get_id = isset($_GET['id']) ? intval($_GET['id']) : '';
+ $get_id = isset($_GET['id']) ? (int) $_GET['id'] : 0;
$forum_categories_list = get_forum_categories();
// Verify if forum category exists
@@ -111,23 +111,23 @@ function handle_forum_and_forumcategories($lp_id = null)
$content = '';
// Adding a forum category
- if (($action_forum_cat == 'add' && $get_content == 'forumcategory') || $post_submit_cat) {
+ if (($action_forum_cat === 'add' && $get_content === 'forumcategory') || $post_submit_cat) {
$content = show_add_forumcategory_form([], $lp_id); //$lp_id when is called from learning path
}
// Adding a forum
- if ((($action_forum_cat == 'add' || $action_forum_cat == 'edit') && $get_content == 'forum') ||
+ if ((($action_forum_cat === 'add' || $action_forum_cat === 'edit') && $get_content === 'forum') ||
$post_submit_forum
) {
$inputvalues = [];
- if ($action_forum_cat == 'edit' && $get_id || $post_submit_forum) {
+ if ($action_forum_cat === 'edit' && $get_id || $post_submit_forum) {
$inputvalues = get_forums($get_id);
}
$content = show_add_forum_form($inputvalues, $lp_id);
}
// Edit a forum category
- if (($action_forum_cat == 'edit' && $get_content == 'forumcategory') ||
+ if (($action_forum_cat === 'edit' && $get_content === 'forumcategory') ||
(isset($_POST['SubmitEditForumCategory'])) ? true : false
) {
$forum_category = get_forum_categories($get_id);
@@ -135,10 +135,8 @@ function handle_forum_and_forumcategories($lp_id = null)
}
// Delete a forum category
- if ($action_forum_cat == 'delete') {
- $id_forum = intval($get_id);
- $list_threads = get_threads($id_forum);
-
+ if ($action_forum_cat === 'delete') {
+ $list_threads = get_threads($get_id);
for ($i = 0; $i < count($list_threads); $i++) {
deleteForumCategoryThread('thread', $list_threads[$i]['thread_id']);
$link_info = GradebookUtils::isResourceInCourseGradebook(
@@ -155,21 +153,21 @@ function handle_forum_and_forumcategories($lp_id = null)
}
// Change visibility of a forum or a forum category.
- if ($action_forum_cat == 'invisible' || $action_forum_cat == 'visible') {
+ if ($action_forum_cat === 'invisible' || $action_forum_cat === 'visible') {
$return_message = change_visibility($get_content, $get_id, $action_forum_cat);
Display::addFlash(
Display::return_message($return_message, 'confirmation', false)
);
}
// Change lock status of a forum or a forum category.
- if ($action_forum_cat == 'lock' || $action_forum_cat == 'unlock') {
+ if ($action_forum_cat === 'lock' || $action_forum_cat === 'unlock') {
$return_message = change_lock_status($get_content, $get_id, $action_forum_cat);
Display::addFlash(
Display::return_message($return_message, 'confirmation', false)
);
}
// Move a forum or a forum category.
- if ($action_forum_cat == 'move' && isset($_GET['direction'])) {
+ if ($action_forum_cat === 'move' && isset($_GET['direction'])) {
$return_message = move_up_down($get_content, $_GET['direction'], $get_id);
Display::addFlash(
Display::return_message($return_message, 'confirmation', false)
@@ -268,14 +266,14 @@ function show_add_forum_form($inputvalues = [], $lp_id)
$form_title = get_lang('EditForum');
}
- $form->addElement('header', $form_title);
+ $form->addHeader($form_title);
// We have a hidden field if we are editing.
if (!empty($inputvalues) && is_array($inputvalues)) {
$my_forum_id = isset($inputvalues['forum_id']) ? $inputvalues['forum_id'] : null;
$form->addElement('hidden', 'forum_id', $my_forum_id);
}
- $lp_id = intval($lp_id);
+ $lp_id = (int) $lp_id;
// hidden field if from learning path
$form->addElement('hidden', 'lp_id', $lp_id);
@@ -893,7 +891,6 @@ function store_forum($values, $courseInfo = [], $returnId = false)
$logInfo = [
'tool' => TOOL_FORUM,
'tool_id' => $values['forum_id'],
- 'tool_id_detail' => 0,
'action' => 'update-forum',
'action_details' => 'forum',
'info' => $values['forum_title'],
@@ -922,7 +919,7 @@ function store_forum($values, $courseInfo = [], $returnId = false)
'end_time' => !empty($values['end_time']) ? api_get_utc_datetime($values['end_time']) : null,
'forum_order' => isset($new_max) ? $new_max : null,
'session_id' => $session_id,
- 'lp_id' => isset($values['lp_id']) ? intval($values['lp_id']) : 0,
+ 'lp_id' => isset($values['lp_id']) ? (int) $values['lp_id'] : 0,
'locked' => 0,
'forum_id' => 0,
];
@@ -931,6 +928,25 @@ function store_forum($values, $courseInfo = [], $returnId = false)
if ($forumId > 0) {
$sql = "UPDATE $table_forums SET forum_id = iid WHERE iid = $forumId";
Database::query($sql);
+ $courseCode = $courseInfo['code'];
+ $subscribe = (int) api_get_course_setting('subscribe_users_to_forum_notifications', $courseCode);
+
+ $status = STUDENT;
+ if (!empty($session_id)) {
+ $status = 0;
+ }
+ if ($subscribe === 1) {
+ $userList = CourseManager::get_user_list_from_course_code(
+ $courseCode,
+ $session_id,
+ null,
+ null,
+ $status
+ );
+ foreach ($userList as $userInfo) {
+ set_notification('forum', $forumId, false, $userInfo, $courseInfo);
+ }
+ }
api_item_property_update(
$courseInfo,
@@ -951,7 +967,6 @@ function store_forum($values, $courseInfo = [], $returnId = false)
$logInfo = [
'tool' => TOOL_FORUM,
'tool_id' => $forumId,
- 'tool_id_detail' => 0,
'action' => 'new-forum',
'action_details' => 'forum',
'info' => $values['forum_title'],
@@ -1000,7 +1015,7 @@ function deleteForumCategoryThread($content, $id)
$groupId = api_get_group_id();
$groupInfo = GroupManager::get_group_properties($groupId);
$userId = api_get_user_id();
- $id = intval($id);
+ $id = (int) $id;
// Delete all attachment file about this tread id.
$sql = "SELECT post_id FROM $table_forums_post
@@ -1012,7 +1027,7 @@ function deleteForumCategoryThread($content, $id)
$tool_constant = null;
$return_message = '';
- if ($content == 'forumcategory') {
+ if ($content === 'forumcategory') {
$tool_constant = TOOL_FORUM_CATEGORY;
$return_message = get_lang('ForumCategoryDeleted');
@@ -1034,7 +1049,7 @@ function deleteForumCategoryThread($content, $id)
}
}
- if ($content == 'forum') {
+ if ($content === 'forum') {
$tool_constant = TOOL_FORUM;
$return_message = get_lang('ForumDeleted');
@@ -1056,7 +1071,7 @@ function deleteForumCategoryThread($content, $id)
}
}
- if ($content == 'thread') {
+ if ($content === 'thread') {
$tool_constant = TOOL_FORUM_THREAD;
$return_message = get_lang('ThreadDeleted');
Skill::deleteSkillsFromItem($id, ITEM_TYPE_FORUM_THREAD);
@@ -5624,58 +5639,68 @@ function get_forums_of_group($groupInfo)
/**
* This function stores which users have to be notified of which forums or threads.
*
- * @param string $content does the user want to be notified about a forum or about a thread
- * @param int $id the id of the forum or thread
+ * @param string $content does the user want to be notified about a forum or about a thread
+ * @param int $id the id of the forum or thread
+ * @param bool $addOnly
+ * @param array $userInfo
+ * @param array $courseInfo
*
* @return string language variable
*
- * @author Patrick Cool
, Ghent University, Belgium
- *
- * @version May 2008, dokeos 1.8.5
+ * @author Patrick Cool , Ghent University, Belgium
+ * @author Julio Montoya
*
- * @since May 2008, dokeos 1.8.5
+ * @since May 2008 v1.8.5
*/
-function set_notification($content, $id, $add_only = false)
+function set_notification($content, $id, $addOnly = false, $userInfo = [], $courseInfo = [])
{
- $_user = api_get_user_info();
+ $userInfo = empty($userInfo) ? api_get_user_info() : $userInfo;
+ $courseInfo = empty($courseInfo) ? api_get_course_info() : $courseInfo;
+ $id = (int) $id;
+
+ if (empty($userInfo) || empty($courseInfo) || empty($id) || empty($content)) {
+ return false;
+ }
+
// Database table definition
$table_notification = Database::get_course_table(TABLE_FORUM_NOTIFICATION);
- $course_id = api_get_course_int_id();
+ $course_id = $courseInfo['real_id'];
// Which database field do we have to store the id in?
- if ($content == 'forum') {
- $database_field = 'forum_id';
- } else {
- $database_field = 'thread_id';
+ $field = 'thread_id';
+ if ($content === 'forum') {
+ $field = 'forum_id';
}
+ $userId = $userInfo['user_id'];
+
// First we check if the notification is already set for this.
$sql = "SELECT * FROM $table_notification
WHERE
c_id = $course_id AND
- $database_field = '".Database::escape_string($id)."' AND
- user_id = '".intval($_user['user_id'])."'";
+ $field = $id AND
+ user_id = $userId ";
$result = Database::query($sql);
$total = Database::num_rows($result);
// If the user did not indicate that (s)he wanted to be notified already
// then we store the notification request (to prevent double notification requests).
if ($total <= 0) {
- $sql = "INSERT INTO $table_notification (c_id, $database_field, user_id)
- VALUES (".$course_id.", '".Database::escape_string($id)."','".intval($_user['user_id'])."')";
+ $sql = "INSERT INTO $table_notification (c_id, $field, user_id)
+ VALUES ($course_id, '$id','$userId')";
Database::query($sql);
Session::erase('forum_notification');
getNotificationsPerUser(0, true);
return get_lang('YouWillBeNotifiedOfNewPosts');
} else {
- if (!$add_only) {
+ if (!$addOnly) {
$sql = "DELETE FROM $table_notification
WHERE
c_id = $course_id AND
- $database_field = '".Database::escape_string($id)."' AND
- user_id = '".intval($_user['user_id'])."'";
+ $field = $id AND
+ user_id = $userId ";
Database::query($sql);
Session::erase('forum_notification');
getNotificationsPerUser(0, true);
@@ -5695,6 +5720,7 @@ function set_notification($content, $id, $add_only = false)
* @return array returns
*
* @author Patrick Cool , Ghent University, Belgium
+ * @author Julio Montoya
*
* @version May 2008, dokeos 1.8.5
*
@@ -5708,18 +5734,19 @@ function get_notifications($content, $id)
$course_id = api_get_course_int_id();
// Which database field contains the notification?
- if ($content == 'forum') {
- $database_field = 'forum_id';
- } else {
- $database_field = 'thread_id';
+ $field = 'thread_id';
+ if ($content === 'forum') {
+ $field = 'forum_id';
}
+ $id = (int) $id;
+
$sql = "SELECT user.user_id, user.firstname, user.lastname, user.email, user.user_id user
FROM $table_users user, $table_notification notification
WHERE
notification.c_id = $course_id AND user.active = 1 AND
user.user_id = notification.user_id AND
- notification.$database_field= '".Database::escape_string($id)."'";
+ notification.$field = $id ";
$result = Database::query($sql);
$return = [];
@@ -5749,20 +5776,7 @@ function get_notifications($content, $id)
*/
function send_notifications($forum_id = 0, $thread_id = 0, $post_id = 0)
{
- //$_course = api_get_course_info();
-
- /*$forumCourseId = api_get_configuration_value('global_forums_course_id');
- if (!empty($forumCourseId)) {
- if ($_course['real_id'] == $forumCourseId) {
- return false;
- }
- }*/
-
$forum_id = (int) $forum_id;
-
- // The content of the mail
- //$thread_link = api_get_path(WEB_CODE_PATH).'forum/viewthread.php?'.api_get_cidreq().'&forum='.$forum_id.'&thread='.$thread_id;
-
// Users who subscribed to the forum
if ($forum_id != 0) {
$users_to_be_notified_by_forum = get_notifications('forum', $forum_id);
@@ -5771,8 +5785,6 @@ function send_notifications($forum_id = 0, $thread_id = 0, $post_id = 0)
}
$current_thread = get_thread_information($forum_id, $thread_id);
- //$current_forum = get_forum_information($current_thread['forum_id']);
- //$subject = get_lang('NewForumPost').' - '.$_course['official_code'].' - '.$current_forum['forum_title'].' - '.$current_thread['thread_title'];
// User who subscribed to the thread
if ($thread_id != 0) {
@@ -6228,8 +6240,8 @@ function editAttachedFile($array, $id, $courseId = null)
{
// Init variables
$setString = '';
- $id = intval($id);
- $courseId = intval($courseId);
+ $id = (int) $id;
+ $courseId = (int) $courseId;
if (empty($courseId)) {
// $courseId can be null, use api method
$courseId = api_get_course_int_id();
@@ -6277,8 +6289,7 @@ function editAttachedFile($array, $id, $courseId = null)
*/
function getAttachmentsAjaxTable($postId = 0)
{
- // Init variables
- $postId = intval($postId);
+ $postId = (int) $postId;
$courseId = api_get_course_int_id();
$attachIds = getAttachmentIdsByPostId($postId, $courseId);
$fileDataContent = '';
@@ -6357,10 +6368,10 @@ function getAttachedFiles(
$attachId = 0,
$courseId = 0
) {
- $forumId = intval($forumId);
- $courseId = intval($courseId);
- $attachId = intval($attachId);
- $postId = intval($postId);
+ $forumId = (int) $forumId;
+ $courseId = (int) $courseId;
+ $attachId = (int) $attachId;
+ $postId = (int) $postId;
$threadId = !empty($threadId) ? intval($threadId) : isset($_REQUEST['thread']) ? intval($_REQUEST['thread']) : '';
if (empty($courseId)) {
// $courseId can be null, use api method
@@ -6368,7 +6379,7 @@ function getAttachedFiles(
}
if (empty($forumId)) {
if (!empty($_REQUEST['forum'])) {
- $forumId = intval($_REQUEST['forum']);
+ $forumId = (int) $_REQUEST['forum'];
} else {
// if forum ID is empty, cannot generate delete url
@@ -6438,11 +6449,11 @@ function getAttachedFiles(
*
* @return array
*/
-function clearAttachedFiles($postId = null, $courseId = null)
+function clearAttachedFiles($postId = 0, $courseId = 0)
{
// Init variables
- $courseId = intval($courseId);
- $postId = intval($postId);
+ $courseId = (int) $courseId;
+ $postId = (int) $postId;
$array = [];
if (empty($courseId)) {
// $courseId can be null, use api method
@@ -6488,8 +6499,8 @@ function clearAttachedFiles($postId = null, $courseId = null)
function getAttachmentIdsByPostId($postId, $courseId = 0)
{
$array = [];
- $courseId = intval($courseId);
- $postId = intval($postId);
+ $courseId = (int) $courseId;
+ $postId = (int) $postId;
if (empty($courseId)) {
// $courseId can be null, use api method
$courseId = api_get_course_int_id();
@@ -6520,7 +6531,8 @@ function getAttachmentIdsByPostId($postId, $courseId = 0)
*/
function getForumCategoryByTitle($title, $courseId, $sessionId = 0)
{
- $sessionId = intval($sessionId);
+ $sessionId = (int) $sessionId;
+ $courseId = (int) $courseId;
$forumCategoryTable = Database::get_course_table(TABLE_FORUM_CATEGORY);
$itemProperty = Database::get_course_table(TABLE_ITEM_PROPERTY);
@@ -6550,7 +6562,7 @@ function getForumCategoryByTitle($title, $courseId, $sessionId = 0)
'ip.tool = ? AND ' => TOOL_FORUM_CATEGORY,
'fc.session_id = ? AND ' => $sessionId,
'fc.cat_title = ? AND ' => $title,
- 'fc.c_id = ?' => intval($courseId),
+ 'fc.c_id = ?' => $courseId,
],
],
'first'
diff --git a/main/forum/index.php b/main/forum/index.php
index 5e58b30017..3a9fcb2353 100755
--- a/main/forum/index.php
+++ b/main/forum/index.php
@@ -62,9 +62,9 @@ if (api_is_in_gradebook()) {
$search_forum = isset($_GET['search']) ? Security::remove_XSS($_GET['search']) : '';
/* ACTIONS */
-$actions = isset($_GET['action']) ? $_GET['action'] : '';
+$action = isset($_GET['action']) ? $_GET['action'] : '';
-if ($actions === 'add') {
+if ($action === 'add') {
switch ($_GET['content']) {
case 'forum':
$interbreadcrumb[] = [
@@ -102,12 +102,12 @@ $form_count = 0;
$formContent = '';
if (api_is_allowed_to_edit(false, true)) {
//if is called from a learning path lp_id
- $lp_id = isset($_REQUEST['lp_id']) ? intval($_REQUEST['lp_id']) : null;
+ $lp_id = isset($_REQUEST['lp_id']) ? (int) $_REQUEST['lp_id'] : null;
$formContent = handle_forum_and_forumcategories($lp_id);
}
// Notification
-if ($actions == 'notify' && isset($_GET['content']) && isset($_GET['id'])) {
+if ($action == 'notify' && isset($_GET['content']) && isset($_GET['id'])) {
if (api_get_session_id() != 0 &&
api_is_allowed_to_session_edit(false, true) == false
) {
@@ -120,14 +120,11 @@ if ($actions == 'notify' && isset($_GET['content']) && isset($_GET['id'])) {
get_whats_new();
$whatsnew_post_info = Session::read('whatsnew_post_info');
-/* TRACKING */
Event::event_access_tool(TOOL_FORUM);
$logInfo = [
'tool' => TOOL_FORUM,
- 'tool_id' => 0,
- 'tool_id_detail' => 0,
- 'action' => !empty($actions) ? $actions : 'list-category',
+ 'action' => !empty($action) ? $action : 'list-category',
'action_details' => isset($_GET['content']) ? $_GET['content'] : '',
];
Event::registerLog($logInfo);
@@ -557,7 +554,7 @@ if (is_array($forumCategories)) {
}
}
- if (!api_is_anonymous() && api_is_allowed_to_session_edit(false, true) && $hideNotifications == false) {
+ if ($hideNotifications == false && !api_is_anonymous() && api_is_allowed_to_session_edit(false, true)) {
$toolActions .= ''
.Display::return_icon($iconnotify, get_lang('NotifyMe'), null, ICON_SIZE_SMALL)
diff --git a/main/gradebook/gradebook_edit_cat.php b/main/gradebook/gradebook_edit_cat.php
index a753852f79..36f118676e 100755
--- a/main/gradebook/gradebook_edit_cat.php
+++ b/main/gradebook/gradebook_edit_cat.php
@@ -2,8 +2,6 @@
/* For licensing terms, see /license.txt */
/**
- * Script.
- *
* @package chamilo.gradebook
*/
require_once __DIR__.'/../inc/global.inc.php';
diff --git a/main/gradebook/index.php b/main/gradebook/index.php
index bfafe4407a..33390a73e4 100755
--- a/main/gradebook/index.php
+++ b/main/gradebook/index.php
@@ -178,8 +178,6 @@ $my_actions = implode(';', $list_actions);
$my_actions_values = implode(';', $list_values);
$logInfo = [
'tool' => TOOL_GRADEBOOK,
- 'tool_id' => 0,
- 'tool_id_detail' => 0,
'action' => $my_actions,
'action_details' => $my_actions_values,
];
@@ -260,19 +258,19 @@ if (isset($_GET['visiblelog'])) {
//move a category
if (isset($_GET['movecat'])) {
GradebookUtils::block_students();
- $cats = Category::load($_GET['movecat']);
+ $moveCategoryId = isset($_GET['movecat']) ? (int) $_GET['movecat'] : 0;
+ $cats = Category::load($moveCategoryId);
if (!isset($_GET['targetcat'])) {
$move_form = new CatForm(
CatForm::TYPE_MOVE,
$cats[0],
'move_cat_form',
null,
- api_get_self().'?movecat='.intval($_GET['movecat']).'&selectcat='.$selectCat
+ api_get_self().'?movecat='.$moveCategoryId.'&selectcat='.$selectCat
);
if ($move_form->validate()) {
header('Location: '.api_get_self().'?selectcat='.$selectCat
- .'&movecat='.intval($_GET['movecat'])
- .'&targetcat='.$move_form->exportValue('move_cat'));
+ .'&movecat='.$moveCategoryId.'&targetcat='.$move_form->exportValue('move_cat'));
exit;
}
} else {
@@ -370,7 +368,7 @@ if (isset($_GET['deletecat'])) {
GradebookUtils::block_students();
$cats = Category::load($_GET['deletecat']);
if (isset($cats[0])) {
- //delete all categories,subcategories and results
+ // Delete all categories,subcategories and results
if ($cats[0] != null) {
if ($cats[0]->get_id() != 0) {
// better don't try to delete the root...
@@ -406,12 +404,11 @@ if (isset($_GET['visibleeval'])) {
if (isset($_GET['lockedeval'])) {
GradebookUtils::block_students();
$locked = (int) $_GET['lockedeval'];
+ $type_locked = 1;
+ $confirmation_message = get_lang('EvaluationHasBeenLocked');
if (isset($_GET['typelocked']) && api_is_platform_admin()) {
$type_locked = 0;
$confirmation_message = get_lang('EvaluationHasBeenUnLocked');
- } else {
- $type_locked = 1;
- $confirmation_message = get_lang('EvaluationHasBeenLocked');
}
$eval = Evaluation::load($locked);
if ($eval[0] != null) {
@@ -493,7 +490,7 @@ if (!empty($course_to_crsind) && !isset($_GET['confirm'])) {
die('Error: movecat or moveeval not defined');
}
$button = '';
diff --git a/main/gradebook/lib/GradebookUtils.php b/main/gradebook/lib/GradebookUtils.php
index f4b7460fea..b5927b7ac6 100644
--- a/main/gradebook/lib/GradebookUtils.php
+++ b/main/gradebook/lib/GradebookUtils.php
@@ -713,9 +713,12 @@ class GradebookUtils
$date_certificate
) {
$table = Database::get_main_table(TABLE_MAIN_GRADEBOOK_CERTIFICATE);
- $sql = 'SELECT COUNT(id) as count
- FROM '.$table.' gc
- WHERE gc.cat_id="'.intval($cat_id).'" AND user_id="'.intval($user_id).'" ';
+ $cat_id = (int) $cat_id;
+ $user_id = (int) $user_id;
+
+ $sql = "SELECT COUNT(id) as count
+ FROM $table gc
+ WHERE gc.cat_id = $cat_id AND user_id = $user_id ";
$rs_exist = Database::query($sql);
$row = Database::fetch_array($rs_exist);
if ($row['count'] == 0) {
@@ -740,8 +743,11 @@ class GradebookUtils
public static function get_certificate_by_user_id($cat_id, $user_id)
{
$table = Database::get_main_table(TABLE_MAIN_GRADEBOOK_CERTIFICATE);
- $sql = 'SELECT * FROM '.$table.'
- WHERE cat_id="'.intval($cat_id).'" AND user_id="'.intval($user_id).'"';
+ $cat_id = (int) $cat_id;
+ $user_id = (int) $user_id;
+
+ $sql = "SELECT * FROM $table
+ WHERE cat_id = $cat_id AND user_id = $user_id ";
$result = Database::query($sql);
$row = Database::fetch_array($result, 'ASSOC');
@@ -796,27 +802,28 @@ class GradebookUtils
$user_id,
$cat_id = null
) {
+ $user_id = (int) $user_id;
$table_certificate = Database::get_main_table(TABLE_MAIN_GRADEBOOK_CERTIFICATE);
- $sql = 'SELECT
- gc.score_certificate,
- gc.created_at,
- gc.path_certificate,
- gc.cat_id,
- gc.user_id,
+ $sql = 'SELECT
+ gc.score_certificate,
+ gc.created_at,
+ gc.path_certificate,
+ gc.cat_id,
+ gc.user_id,
gc.id
FROM '.$table_certificate.' gc
- WHERE gc.user_id="'.intval($user_id).'" ';
+ WHERE gc.user_id = "'.$user_id.'" ';
if (!is_null($cat_id) && $cat_id > 0) {
$sql .= ' AND cat_id='.intval($cat_id);
}
$rs = Database::query($sql);
- $list_certificate = [];
+ $list = [];
while ($row = Database::fetch_array($rs)) {
- $list_certificate[] = $row;
+ $list[] = $row;
}
- return $list_certificate;
+ return $list;
}
/**
@@ -854,9 +861,9 @@ class GradebookUtils
//add print header
if (!$hide_print_button) {
- $print = '