]> git.mjollnir.org Git - moodle.git/commitdiff
FIx notices and logic when deleting files and checking resources. bug 5156
authormoodler <moodler>
Wed, 12 Apr 2006 08:53:24 +0000 (08:53 +0000)
committermoodler <moodler>
Wed, 12 Apr 2006 08:53:24 +0000 (08:53 +0000)
files/index.php

index 7e36b89f7fa4f0882c842e3d874637759e531fce..1eebf667044a5edf050fee0ca31a23f5d317f837 100644 (file)
         case "delete":
             if (!empty($confirm) and confirm_sesskey()) {
                 html_header($course, $wdir);
-                foreach ($USER->filelist as $file) {
-                    $fullfile = $basedir.$file;
-                    if (! fulldelete($fullfile)) {
-                        echo "<br />Error: Could not delete: $fullfile";
+                if (!empty($USER->filelist)) {
+                    foreach ($USER->filelist as $file) {
+                        $fullfile = $basedir.$file;
+                        if (! fulldelete($fullfile)) {
+                            echo "<br />Error: Could not delete: $fullfile";
+                        }
                     }
                 }
                 clearfilelist();
             } else {
                 html_header($course, $wdir);
 
-                echo '<p align=\"center\">'.get_string('deletecheckwarning').':</p>';
-
-                print_simple_box_start("center");
-                printfilelist($USER->filelist);
-                print_simple_box_end();
-                echo "<br />";
-                print_simple_box_start("center");
-
                 if (setfilelist($_POST)) {
+                    notify(get_string('deletecheckwarning').':');
+                    print_simple_box_start("center");
+                    printfilelist($USER->filelist);
+                    print_simple_box_end();
+                    echo "<br />";
+
+                    $resourcelist = false;
                     foreach ($USER->filelist as $file) {
-                        //if file is part of resource then update resource table as well
+                        // If file is specified in a resource, then delete that too.
                         $clean_name = substr($file, 1);
                         if (record_exists('resource', 'reference', $clean_name)) {
+                            if (!$resourcelist) {
+                                print_simple_box_start("center");
+                                $resourcelist = true;
+                            }
                             $resource_id = files_get_cm_from_resource_name($clean_name);
-                            echo '<p align=\"center\"><b>'.get_string('warningdeleteresource', '', $file)."</align><a href='$CFG->wwwroot/course/mod.php?update=$resource_id&sesskey=$USER->sesskey'> Update</a></b>";
+                            echo '<p>'.get_string('warningdeleteresource', '', $file)." <a href='$CFG->wwwroot/course/mod.php?update=$resource_id&sesskey=$USER->sesskey'>".get_string('update')."</a></p>";
                         }
                     }
-
-                    print_simple_box_end();
-                    echo "<br />";
+                    if ($resourcelist) {
+                        print_simple_box_end();
+                        echo "<br />";
+                    }
 
                     notice_yesno (get_string("deletecheckfiles"), 
                                 "index.php?id=$id&amp;wdir=$wdir&amp;action=delete&amp;confirm=1&amp;sesskey=$USER->sesskey&amp;choose=$choose",