Browse Source

Add response code "404 if file not found for scorm package see BT#13818

Julio 7 years ago
parent
commit
6b50f0ffaf

+ 1 - 1
main/document/download_scorm.php

@@ -58,7 +58,7 @@ if (Security::check_abs_path($sys_course_path.$doc_url, $sys_course_path.'/')) {
     $fixLinks = api_get_configuration_value('lp_replace_http_to_https');
     $result = DocumentManager::file_send_for_download($full_file_name, false, '', $fixLinks);
     if ($result === false) {
-        api_not_allowed(true);
+        api_not_allowed(true, '', 404);
     }
 }
 exit;

+ 4 - 1
main/inc/lib/api.lib.php

@@ -3357,10 +3357,12 @@ function api_is_anonymous($user_id = null, $db_check = false)
  * Displays message "You are not allowed here..." and exits the entire script.
  * @param bool   $print_headers    Whether or not to print headers (default = false -> does not print them)
  * @param string $message
+ * @param int $responseCode
  */
 function api_not_allowed(
     $print_headers = false,
-    $message = null
+    $message = null,
+    $responseCode = 0
 ) {
     if (api_get_setting('sso_authentication') === 'true') {
         global $osso;
@@ -3407,6 +3409,7 @@ function api_not_allowed(
     }
 
     $tpl = new Template(null, $show_headers, $show_headers, false, true, false);
+    $tpl->setResponseCode($responseCode);
     $tpl->assign('hide_login_link', 1);
     $tpl->assign('content', $msg);
 

+ 0 - 2
main/inc/lib/document.lib.php

@@ -298,7 +298,6 @@ class DocumentManager
         $len = filesize($full_file_name);
         // Fixing error when file name contains a ","
         $filename = str_replace(',', '', $filename);
-
         $sendFileHeaders = api_get_configuration_value('enable_x_sendfile_headers');
 
         if ($forced) {
@@ -334,7 +333,6 @@ class DocumentManager
             return true;
         } else {
             //no forced download, just let the browser decide what to do according to the mimetype
-
             $content_type = self::file_get_mime_type($filename);
             $lpFixedEncoding = api_get_configuration_value('lp_fixed_encoding');
 

+ 26 - 0
main/inc/lib/template.lib.php

@@ -46,6 +46,7 @@ class Template
     public $load_plugins = false;
     public $params = [];
     public $force_plugin_load = false;
+    public $responseCode = '';
 
     /**
      * @param string $title
@@ -1114,6 +1115,15 @@ class Template
                 'X-Powered-By: '.$_configuration['software_name'].' '.substr($_configuration['system_version'], 0, 1)
             );
             self::addHTTPSecurityHeaders();
+
+            $responseCode = $this->getResponseCode();
+            if (!empty($responseCode)) {
+                switch ($responseCode) {
+                    case '404':
+                        header("HTTP/1.0 404 Not Found");
+                        break;
+                }
+            }
         }
 
         $socialMeta = '';
@@ -1695,4 +1705,20 @@ class Template
 
         return implode(CourseManager::USER_SEPARATOR, $names);
     }
+
+    /**
+     * @param int $code
+     */
+    public function setResponseCode($code)
+    {
+        $this->responseCode = $code;
+    }
+
+    /**
+     * @param string $code
+     */
+    public function getResponseCode()
+    {
+        return $this->responseCode;
+    }
 }