Browse Source

Fix certificate upload see BT#10006

Julio Montoya 9 years ago
parent
commit
74898e0264
3 changed files with 26 additions and 7 deletions
  1. 2 5
      main/document/document.php
  2. 1 0
      main/document/upload.php
  3. 23 2
      main/inc/lib/document.lib.php

+ 2 - 5
main/document/document.php

@@ -587,15 +587,12 @@ if (isset($document_id) && empty($action)) {
     // If the path is not found (no document id), set the path to /
     $document_id = DocumentManager::get_document_id($courseInfo, $curdirpath);
 
-    if (!$document_id) {
-        $document_id = DocumentManager::get_document_id($courseInfo, $curdirpath);
-    }
-
     $document_data = DocumentManager::get_document_data_by_id(
         $document_id,
         api_get_course_id(),
         true
     );
+
     $parent_id = $document_data['parent_id'];
 }
 
@@ -1622,7 +1619,7 @@ if ($is_allowed_to_edit ||
     if ($is_certificate_mode) {
         $actions .= Display::url(
             Display::return_icon('upload_certificate.png', get_lang('UploadCertificate'), '', ICON_SIZE_MEDIUM),
-            api_get_path(WEB_CODE_PATH).'document/upload.php?'.api_get_cidreq().'&id='.$current_folder_id
+            api_get_path(WEB_CODE_PATH).'document/upload.php?'.api_get_cidreq().'&id='.$current_folder_id.'&certificate=true'
         );
     } else {
         $actions .= Display::url(

+ 1 - 0
main/document/upload.php

@@ -163,6 +163,7 @@ if ($groupId != 0) {
 }
 if (isset($_REQUEST['certificate'])) {
     $nameTools = get_lang('UploadCertificate').$add_group_to_title;
+    $is_certificate_mode = true;
 } else {
     $nameTools = get_lang('UplUploadDocument').$add_group_to_title;
 }

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

@@ -1943,7 +1943,10 @@ class DocumentManager
             $post_dir_name = get_lang('CertificatesFiles');
             $visibility_command = 'invisible';
 
-            if (!is_dir($base_work_dir_test)) {
+            $id = self::get_document_id_of_directory_certificate();
+
+            if (empty($id)) {
+
                 create_unexisting_directory(
                     $courseInfo,
                     api_get_user_id(),
@@ -1952,10 +1955,28 @@ class DocumentManager
                     $to_user_id,
                     $base_work_dir,
                     $dir_name,
-                    $post_dir_name
+                    $post_dir_name,
+                    null,
+                    false
                 );
+
                 $id = self::get_document_id_of_directory_certificate();
 
+                if (empty($id)) {
+
+                    $id = add_document(
+                        $courseInfo,
+                        $dir_name,
+                        'folder',
+                        0,
+                        $post_dir_name,
+                        null,
+                        0,
+                        true,
+                        $to_group_id
+                    );
+                }
+
                 if (!empty($id)) {
                     api_item_property_update(
                         $courseInfo,