Browse Source

Minor - Fix double casting

Julio Montoya 6 years ago
parent
commit
bc8aad5923
2 changed files with 9 additions and 4 deletions
  1. 2 2
      main/announcements/announcements.php
  2. 7 2
      main/inc/lib/api.lib.php

+ 2 - 2
main/announcements/announcements.php

@@ -371,11 +371,11 @@ switch ($action) {
                 }
 
                 if (!api_is_session_general_coach() ||
-                    api_is_element_in_the_session(TOOL_ANNOUNCEMENT, (int) $_GET['id'])
+                    api_is_element_in_the_session(TOOL_ANNOUNCEMENT, $_GET['id'])
                 ) {
                     AnnouncementManager::change_visibility_announcement(
                         $_course,
-                        (int) $_GET['id']
+                        $_GET['id']
                     );
                     Display::addFlash(Display::return_message(get_lang('VisibilityChanged')));
                     header('Location: '.$homeUrl);

+ 7 - 2
main/inc/lib/api.lib.php

@@ -6204,7 +6204,6 @@ function api_is_course_visible_for_user($userid = null, $cid = null)
  * @param string the tool of the element
  * @param int the element id in database
  * @param int the session_id to compare with element session id
- * @param string $tool
  *
  * @return bool true if the element is in the session, false else
  */
@@ -6214,6 +6213,12 @@ function api_is_element_in_the_session($tool, $element_id, $session_id = null)
         $session_id = api_get_session_id();
     }
 
+    $element_id = (int) $element_id;
+
+    if (empty($element_id)) {
+        return false;
+    }
+
     // Get information to build query depending of the tool.
     switch ($tool) {
         case TOOL_SURVEY:
@@ -6238,7 +6243,7 @@ function api_is_element_in_the_session($tool, $element_id, $session_id = null)
     $course_id = api_get_course_int_id();
 
     $sql = "SELECT session_id FROM $table_tool 
-            WHERE c_id = $course_id AND $key_field =  ".intval($element_id);
+            WHERE c_id = $course_id AND $key_field =  ".$element_id;
     $rs = Database::query($sql);
     if ($element_session_id = Database::result($rs, 0, 0)) {
         if ($element_session_id == intval($session_id)) {