Browse Source

Add delete_correction feature

jmontoyaa 8 years ago
parent
commit
c20c3a2669
2 changed files with 44 additions and 1 deletions
  1. 25 1
      main/work/view.php
  2. 19 0
      main/work/work.lib.php

+ 25 - 1
main/work/view.php

@@ -97,6 +97,19 @@ if ((user_is_author($id) || $isDrhOfCourse || (api_is_allowed_to_edit() || api_i
                 );
 
                 Display::addFlash(Display::return_message(get_lang('DocDeleted')));
+                header('Location: '.$url);
+                exit;
+                break;
+            case 'delete_correction':
+                if (isset($work['url_correction']) && !empty($work['url_correction'])) {
+                    if (api_is_allowed_to_edit()) {
+                        deleteCorrection($courseInfo, $work);
+                        Display::addFlash(
+                            Display::return_message(get_lang('Deleted'))
+                        );
+                    }
+                }
+
                 header('Location: '.$url);
                 exit;
                 break;
@@ -123,7 +136,7 @@ if ((user_is_author($id) || $isDrhOfCourse || (api_is_allowed_to_edit() || api_i
                     $work['download_url']
                 );
 
-                if (isset($work['url_correction'])) {
+                if (!empty($work['url_correction'])) {
                     $actions .= Display::url(
                         Display::return_icon(
                             'check-circle.png',
@@ -133,6 +146,17 @@ if ((user_is_author($id) || $isDrhOfCourse || (api_is_allowed_to_edit() || api_i
                         ),
                         $work['download_url'].'&correction=1'
                     );
+                    if (api_is_allowed_to_edit()) {
+                        $actions .= Display::url(
+                            Display::return_icon(
+                                'delete.png',
+                                get_lang('Delete').': '.get_lang('Correction'),
+                                null,
+                                ICON_SIZE_MEDIUM
+                            ),
+                            api_get_self().'?action=delete_correction&id='.$id.'&'.api_get_cidreq()
+                        );
+                    }
                 }
             }
         }

+ 19 - 0
main/work/work.lib.php

@@ -5129,3 +5129,22 @@ function protectWork($courseInfo, $workId)
         }
     }
 }
+
+function deleteCorrection($courseInfo, $work)
+{
+    if (isset($work['url_correction']) && !empty($work['url_correction']) && isset($work['iid'])) {
+        $id = $work['iid'];
+        $table = Database:: get_course_table(TABLE_STUDENT_PUBLICATION);
+        $sql = "UPDATE $table SET
+                    url_correction = '',
+                    title_correction = ''
+                WHERE iid = $id";
+        Database::query($sql);
+        $coursePath = api_get_path(SYS_COURSE_PATH).$courseInfo['path'].'/';
+        if (file_exists($coursePath.$work['url_correction'])) {
+            if (Security::check_abs_path($coursePath.$work['url_correction'], $coursePath)) {
+                unlink($coursePath.$work['url_correction']);
+            }
+        }
+    }
+}