Browse Source

Fixing comment file manage see BT#6418

Julio Montoya 11 years ago
parent
commit
7aa9644c98

+ 1 - 1
main/template/default/work/view.tpl

@@ -28,7 +28,7 @@
                 <p>
                     <a href="{{ comment.file_url }}">
                         <img src="{{ "attachment.gif"|icon(32) }}">
-                        {{ 'Download' | get_lang }}
+                        {{ comment.file_name_to_show }}
                     </a>
                     {% if is_allowed_to_edit %}
                         <a href="{{ comment.delete_file_url }}">

+ 1 - 2
main/work/download_comment_file.php

@@ -23,7 +23,6 @@ $workData = getWorkComment($commentId);
 $courseInfo = api_get_course_info();
 
 if (!empty($workData)) {
-
     if (
         empty($workData['file_path']) ||
         (isset($workData['file_path']) && !file_exists($workData['file_path']))
@@ -36,7 +35,7 @@ if (!empty($workData)) {
 
     if (user_is_author($workData['work_id']) || $courseInfo['show_score'] == 0 && $work['active'] == 1 && $work['accepted'] == 1) {
         if (Security::check_abs_path($workData['file_path'], api_get_path(SYS_COURSE_PATH).api_get_course_path().'/')) {
-            DocumentManager::file_send_for_download($workData['file_path'], true);
+            DocumentManager::file_send_for_download($workData['file_path'], true, $workData['file_name_to_show']);
         }
     } else {
         api_not_allowed(true);

+ 2 - 2
main/work/view.php

@@ -28,8 +28,8 @@ if (user_is_author($id) || $course_info['show_score'] == 0 && $work['active'] ==
     } else {
         $url_dir = 'work_list.php?id='.$my_folder_data['id'];
     }
-    $interbreadcrumb[] = array('url' => $url_dir, 'name' =>  $my_folder_data['title']);
-    $interbreadcrumb[] = array('url' => '#','name' =>  $work['title']);
+    $interbreadcrumb[] = array('url' => $url_dir, 'name' => $my_folder_data['title']);
+    $interbreadcrumb[] = array('url' => '#','name' => $work['title']);
 
     if (($course_info['show_score'] == 0 && $work['active'] == 1 && $work['accepted'] == 1) ||
         api_is_allowed_to_edit() || user_is_author($id)

+ 25 - 22
main/work/work.lib.php

@@ -2785,29 +2785,28 @@ function getWorkComments($work)
     $courseId = intval($work['c_id']);
     $workId = intval($work['id']);
 
-    $sql = "SELECT c.*, u.firstname, u.lastname, u.username, u.picture_uri
+    $sql = "SELECT c.id, c.user_id, u.firstname, u.lastname, u.username, u.picture_uri
             FROM $commentTable c INNER JOIN $userTable u ON(u.user_id = c.user_id)
             WHERE c_id = $courseId AND work_id = $workId
             ORDER BY sent_at
             ";
     $result = Database::query($sql);
     $comments = Database::store_result($result, 'ASSOC');
-    $urlPath = api_get_path(WEB_CODE_PATH).'work/download_comment_file.php?'.api_get_cidreq();
-    $deleteUrl = api_get_path(WEB_CODE_PATH).'work/view.php?'.api_get_cidreq().'&id='.$workId.'&action=delete_attachment';
-    foreach ($comments as &$comment) {
-        $pictureInfo = UserManager::get_picture_user(
-            $comment['user_id'],
-            $comment['picture_uri'],
-            24,
-            USER_IMAGE_SIZE_SMALL
-        );
+    if (!empty($comments)) {
+        foreach ($comments as &$comment) {
+            $pictureInfo = UserManager::get_picture_user(
+                $comment['user_id'],
+                $comment['picture_uri'],
+                24,
+                USER_IMAGE_SIZE_SMALL
+            );
+            $comment['picture'] = $pictureInfo['file'];
+            $commentInfo = getWorkComment($comment['id']);
 
-        if (!empty($comment['file'])) {
-            $comment['file_url'] = $urlPath.'&comment_id='.$comment['id'];
-            $comment['delete_file_url'] = $deleteUrl.'&comment_id='.$comment['id'];
+            if (!empty($commentInfo)) {
+                $comment = array_merge($comment, $commentInfo);
+            }
         }
-
-        $comment['picture'] = $pictureInfo['file'];
     }
     return $comments;
 }
@@ -2842,14 +2841,21 @@ function getWorkComment($id, $courseInfo = array())
         $comment = Database::fetch_array($result, 'ASSOC');
         $filePath = null;
         $fileUrl = null;
+        $deleteUrl = null;
+        $fileName = null;
         if (!empty($comment['file'])) {
             $work = get_work_data_by_id($comment['work_id']);
             $workParent = get_work_data_by_id($work['parent_id']);
             $filePath = api_get_path(SYS_COURSE_PATH).$courseInfo['path'].'/work/'.$workParent['url'].'/'.$comment['file'];
-            $fileUrl = api_get_path(WEB_CODE_PATH).'work/download_comment_file.php?comment_id='.$id;
+            $fileUrl = api_get_path(WEB_CODE_PATH).'work/download_comment_file.php?comment_id='.$id.'&'.api_get_cidreq();
+            $deleteUrl = api_get_path(WEB_CODE_PATH).'work/view.php?'.api_get_cidreq().'&id='.$comment['work_id'].'&action=delete_attachment&comment_id='.$id;
+            $fileParts = explode('_', $comment['file']);
+            $fileName = str_replace($fileParts[0].'_'.$fileParts[1].'_', '', $comment['file']);
         }
+        $comment['delete_file_url'] = $deleteUrl;
         $comment['file_path'] = $filePath;
         $comment['file_url'] = $fileUrl;
+        $comment['file_name_to_show'] = $fileName;
     }
     return $comment;
 }
@@ -2893,10 +2899,6 @@ function addWorkComment($courseInfo, $userId, $work, $data)
 
     $commentTable = Database::get_course_table(TABLE_STUDENT_PUBLICATION_ASSIGNMENT_COMMENT);
 
-    if (empty($data['comment'])) {
-        return null;
-    }
-
     $params = array(
         'work_id' => $work['id'],
         'c_id' => $work['c_id'],
@@ -2942,9 +2944,10 @@ function getWorkCommentForm($work)
         'post',
         api_get_path(WEB_CODE_PATH).'work/view.php?id='.$work['id'].'&action=send_comment&'.api_get_cidreq()
     );
-    $form->addElement('textarea', 'comment', get_lang('Comment'), array('class' => 'span5', 'rows' => '8'));
+
     $form->addElement('file', 'file', get_lang('Attachment'));
-    $form->addRule('comment', get_lang('ThisFieldIsRequired'), 'required');
+    $form->addElement('textarea', 'comment', get_lang('Comment'), array('class' => 'span5', 'rows' => '8'));
+    //$form->addRule('comment', get_lang('ThisFieldIsRequired'), 'required');
     $form->addElement('hidden', 'id', $work['id']);
     $form->addElement('button', 'button', get_lang('Send'));
     return $form->return_form();