tagging as ATutor 1.5.4-release
[atutor.git] / tools / filemanager / move.php
1 <?php
2 /****************************************************************/
3 /* ATutor                                                                                                               */
4 /****************************************************************/
5 /* Copyright (c) 2002-2006 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 // $Id$
14
15 define('AT_INCLUDE_PATH', '../../include/');
16 require(AT_INCLUDE_PATH.'vitals.inc.php');
17 require(AT_INCLUDE_PATH.'lib/filemanager.inc.php');
18
19 if (!authenticate(AT_PRIV_FILES,AT_PRIV_RETURN)) {
20         authenticate(AT_PRIV_CONTENT);
21 }
22
23
24 $current_path = AT_CONTENT_DIR.$_SESSION['course_id'].'/';
25
26 $popup = $_REQUEST['popup'];
27 $framed = $_REQUEST['framed'];
28
29 if (isset($_POST['submit_no'])) {
30         $msg->addFeedback('CANCELLED');
31         header('Location: index.php?pathext='.$_POST['pathext'].SEP.'framed='.$_POST['framed'].SEP.'popup='.$_POST['popup']);
32         exit;
33 }
34
35 if (isset($_POST['cancel'])) {
36         $msg->addFeedback('CANCELLED');
37         header('Location: index.php?pathext='.$_POST['pathext'].SEP.'framed='.$_REQUEST['framed'].SEP.'popup='.$_REQUEST['popup']);
38         exit;
39 }
40
41 if (isset($_POST['submit_yes'])) {
42         $dest = $_POST['dest'] .'/';
43         $pathext = $_POST['pathext'];
44
45         if (isset($_POST['listofdirs'])) {
46
47                 $_dirs = explode(',',$_POST['listofdirs']);
48                 $count = count($_dirs);
49                 
50                 for ($i = 0; $i < $count; $i++) {
51                         $source = $_dirs[$i];
52                         
53                         if (course_realpath($current_path . $pathext . $source) == FALSE) {
54                                 // error: File does not exist
55                                 $msg->addError('DIR_NOT_EXIST');
56                                 header('Location: index.php?pathext='.$pathext.SEP.'framed='.$framed.SEP.'popup='.$popup);
57                                 exit;
58                         }
59                         else if (course_realpath($current_path . $dest) == FALSE) {
60                                 // error: File does not exist
61                                 $msg->addError('UNKNOWN');
62                                 header('Location: index.php?pathext='.$pathext.SEP.'framed='.$framed.SEP.'popup='.$popup);
63                                 exit;
64                         }
65                         else if (strpos($source, '..') !== false) {
66                                 $msg->addError('UNKNOWN');
67                                 header('Location: index.php?pathext='.$pathext.SEP.'framed='.$framed.SEP.'popup='.$popup);
68                                 exit;
69                         }       
70                         else {
71                                 @rename($current_path.$pathext.$source, $current_path.$dest.$source);
72                         }
73                 }
74                 $msg->addFeedback('DIRS_MOVED');
75         }
76         if (isset($_POST['listoffiles'])) {
77
78                 $_files = explode(',',$_POST['listoffiles']);
79                 $count = count($_files);
80
81                 for ($i = 0; $i < $count; $i++) {
82                         $source = $_files[$i];
83                         
84                         if (course_realpath($current_path . $pathext . $source) == FALSE) {
85                                 // error: File does not exist
86                                 $msg->addError('FILE_NOT_EXIST');
87                                 header('Location: index.php?pathext='.$pathext.SEP.'framed='.$framed.SEP.'popup='.$popup);
88                                 exit;
89                         }
90                         else if (course_realpath($current_path . $dest) == FALSE) {
91                                 // error: File does not exist
92                                 $msg->addError('UNKNOWN');
93                                 header('Location: index.php?pathext='.$pathext.SEP.'framed='.$framed.SEP.'popup='.$popup);
94                                 exit;
95                         }
96                         else if (strpos($source, '..') !== false) {
97                                 $msg->addError('UNKNOWN');
98                                 header('Location: index.php?pathext='.$pathext.SEP.'framed='.$framed.SEP.'popup='.$popup);
99                                 exit;
100                         }       
101                         else {
102                                 @rename($current_path.$pathext.$source, $current_path.$dest.$source);
103                         }
104                 }
105                 $msg->addFeedback('MOVED_FILES');
106         }
107         header('Location: index.php?pathext='.$_POST['pathext'].SEP.'framed='.$_POST['framed'].SEP.'popup='.$_POST['popup']);
108         exit;
109 }
110
111 if (isset($_POST['dir_chosen'])) {
112         $hidden_vars['framed']  = $_POST['framed'];
113         $hidden_vars['popup']   = $_POST['popup'];
114         $hidden_vars['pathext'] = $_POST['pathext'];
115         $hidden_vars['dest']    = $_POST['dir_name'];
116
117         if (isset($_POST['files'])) {
118                 $list_of_files = implode(',', $_POST['files']);
119                 $hidden_vars['listoffiles'] = $list_of_files;
120                 $msg->addConfirm(array('FILE_MOVE', $list_of_files, $_POST['dir_name']), $hidden_vars);
121         }
122         if (isset($_POST['dirs'])) {
123                 $list_of_dirs = implode(',', $_POST['dirs']);
124                 $hidden_vars['listoffiles'] = $list_of_dirs;
125                 $msg->addConfirm(array('DIR_MOVE', $list_of_dirs, $_POST['dir_name']), $hidden_vars);
126         }
127         require(AT_INCLUDE_PATH.'header.inc.php');
128         $msg->printConfirm();
129         require(AT_INCLUDE_PATH.'footer.inc.php');
130
131 else {
132         require(AT_INCLUDE_PATH.'header.inc.php');
133         
134         $tree = AT_CONTENT_DIR.$_SESSION['course_id'].'/';
135         $file    = $_GET['file'];
136         $pathext = $_GET['pathext']; 
137         $popup   = $_GET['popup'];
138         $framed  = $_GET['framed'];
139
140         /* find the files and directories to be copied */
141         $total_list = explode(',', $_GET['list']);
142
143         $count = count($total_list);
144         $countd = 0;
145         $countf = 0;
146         for ($i=0; $i<$count; $i++) {
147                 if (is_dir($current_path.$pathext.$total_list[$i])) {
148                         $_dirs[$countd] = $total_list[$i];
149                         $hidden_dirs  .= '<input type="hidden" name="dirs['.$countd.']"   value="'.$_dirs[$countd].'" />';
150                         $countd++;
151                 } else {
152                         $_files[$countf] = $total_list[$i];
153                         $hidden_files .= '<input type="hidden" name="files['.$countf.']" value="'.$_files[$countf].'" />';
154                         $countf++;
155                 }
156         }
157 ?>
158
159 <form name="move_form" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
160 <div class="input-form">
161         <div class="row">
162                 <p><?php echo _AT('select_directory'); ?></p>
163         </div>
164         
165         <div class="row">
166                 <ul>
167                         <li class="folders"><label><input type="radio" name="dir_name" value=""<?php
168                                 if ($pathext == '') {
169                                         echo ' checked="checked"';
170                                         $here = ' ' . _AT('current_location');
171                                 } 
172                                 echo '/>Home ' .$here.'</label>';
173                         
174                                 echo display_tree($current_path, '', $pathext);
175                         ?></li>
176                 </ul>
177         </div>
178
179         <div class="row buttons">
180                 <input type="submit" name="dir_chosen" value="<?php echo _AT('move'); ?>" accesskey="s" /> 
181                 <input type="submit" name="cancel" value="<?php echo _AT('cancel'); ?>" />
182         </div>
183 </div>
184
185 <input type="hidden" name="pathext" value="<?php echo $pathext; ?>" />
186 <input type="hidden" name="framed" value="<?php echo $framed; ?>" />
187 <input type="hidden" name="popup" value="<?php echo $popup; ?>" />
188 <?php
189         echo $hidden_dirs;
190         echo $hidden_files;
191 ?>
192 </form>
193
194 <?php require(AT_INCLUDE_PATH.'footer.inc.php');
195 }
196 ?>