tagging as ATutor 1.5.4-release
[atutor.git] / tools / filemanager / delete.php
1 <?php
2 /****************************************************************/
3 /* ATutor                                                                                                               */
4 /****************************************************************/
5 /* Copyright (c) 2002-2004 by Greg Gay & Joel Kronenberg        */
6 /* Adaptive Technology Resource Centre / University of Toronto  */
7 /* http://atutor.ca                                                                                             */
8 /*                                                              */
9 /* This program is free software. You can redistribute it and/or*/
10 /* modify it under the terms of the GNU General Public License  */
11 /* as published by the Free Software Foundation.                                */
12 /****************************************************************/
13
14 define('AT_INCLUDE_PATH', '../../include/');
15 require(AT_INCLUDE_PATH.'vitals.inc.php');
16 require(AT_INCLUDE_PATH.'lib/filemanager.inc.php');
17
18 if (!authenticate(AT_PRIV_FILES,AT_PRIV_RETURN)) {
19         authenticate(AT_PRIV_CONTENT);
20 }
21
22 $current_path = AT_CONTENT_DIR.$_SESSION['course_id'].'/';
23
24 $popup = $_REQUEST['popup'];
25 $framed = $_REQUEST['framed'];
26
27 if (isset($_POST['submit_no'])) {
28         $msg->addFeedback('CANCELLED');
29         header('Location: index.php?pathext='.$_POST['pathext'].SEP.'framed='.$_POST['framed'].SEP.'popup='.$_POST['popup']);
30         exit;
31 }
32
33 if (isset($_POST['submit_yes'])) {
34         /* delete files and directories */
35         /* delete the file  */
36         $pathext = $_POST['pathext'];
37         if (isset($_POST['listoffiles']))  {
38                 $checkbox = explode(',',$_POST['listoffiles']);
39                 $count = count($checkbox);
40                 $result=true;
41                 for ($i=0; $i<$count; $i++) {
42                         $filename=$checkbox[$i];
43
44                         if (course_realpath($current_path . $pathext . $filename) == FALSE) {
45                                 $msg->addError('FILE_NOT_DELETED');
46                                 $result=false;
47                                 break;
48                         } else if (!(@unlink($current_path.$pathext.$filename))) {
49                                 $msg->addError('FILE_NOT_DELETED');
50                                 $result=false;
51                                 break;
52                         }                       
53                 }
54                 if ($result) 
55                         $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
56         }
57         /* delete directory */
58         if (isset($_POST['listofdirs'])) {
59                                 
60                 $checkbox = explode(',',$_POST['listofdirs']);
61                 $count = count($checkbox);
62                 $result=true;
63                 for ($i=0; $i<$count; $i++) {
64                         $filename=$checkbox[$i];
65                                 
66                         if (strpos($filename, '..') !== false) {
67                                 $msg->addError('UNKNOWN');
68                                 $result=false;
69                                 header('Location: index.php?pathext='.$_POST['pathext'].SEP.'framed='.$_POST['framed'].SEP.'popup='.$_POST['popup']);
70                                 exit;
71                         } else if (!is_dir($current_path.$pathext.$filename)) {
72                                 $msg->addError(array('DIR_NOT_DELETED',$filename));
73                                 $result=false;
74                                 header('Location: index.php?pathext='.$_POST['pathext'].SEP.'framed='.$_POST['framed'].SEP.'popup='.$_POST['popup']);
75                                 exit;
76                         } else if (!($result = clr_dir($current_path.$pathext.$filename))) { 
77                                 $msg->addError('DIR_NO_PERMISSION');
78                                 $result=false;
79                                 header('Location: index.php?pathext='.$_POST['pathext'].SEP.'framed='.$_POST['framed'].SEP.'popup='.$_POST['popup']);
80                                 exit;
81                         } 
82                 }
83                 if ($result)
84                         $msg->addFeedback('DIR_DELETED');
85         }
86         
87         header('Location: index.php?pathext='.$_POST['pathext'].SEP.'framed='.$_POST['framed'].SEP.'popup='.$_POST['popup']);
88         exit;
89 }
90
91         require(AT_INCLUDE_PATH.'header.inc.php');
92         // find the files and directories to be deleted 
93         $total_list = explode(',', $_GET['list']);
94         $pathext = $_GET['pathext']; 
95         $popup   = $_GET['popup'];
96         $framed  = $_GET['framed'];
97
98         $count = count($total_list);
99         $countd = 0;
100         $countf = 0;
101         
102         foreach ($total_list as $list_item) {
103                 if (is_dir($current_path.$pathext.$list_item)) {
104                         $_dirs[$countd]  = $list_item;
105                         $countd++;
106                 } else {
107                         $_files[$countf] = $list_item;
108                         $countf++;
109                 }
110         }
111                                 
112         $hidden_vars['pathext'] = $pathext;
113         $hidden_vars['popup']   = $popup;
114         $hidden_vars['framed']  = $framed;
115
116         if (isset($_files)) {
117                 $list_of_files = implode(',', $_files);
118                 $hidden_vars['listoffiles'] = $list_of_files;
119
120                 foreach ($_files as $file) {
121                         $file_list_to_print .= '<li>'.$file.'</li>';
122                 }
123                 $msg->addConfirm(array('FILE_DELETE', $file_list_to_print), $hidden_vars);
124         }
125                 
126         if (isset($_dirs)) {
127                 $list_of_dirs = implode(',', $_dirs);
128                 $hidden_vars['listofdirs'] = $list_of_dirs;
129
130                 foreach ($_dirs as $dir) {
131                         $dir_list_to_print .= '<li>'.$dir.'</li>';
132                 }
133
134                 $msg->addConfirm(array('DIR_DELETE',$dir_list_to_print), $hidden_vars);
135         }
136
137         $msg->printConfirm();
138         
139         require(AT_INCLUDE_PATH.'footer.inc.php');
140 ?>