move code up one directory
[atutor.git] / mods / _core / file_manager / move.php
1 <?php
2 /****************************************************************/
3 /* ATutor                                                                                                               */
4 /****************************************************************/
5 /* Copyright (c) 2002-2010                                      */
6 /* Inclusive Design Institute                                   */
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_once(AT_INCLUDE_PATH.'../mods/_core/file_manager/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'].SEP.'cp='.$_POST['cp'].SEP.'cid='.$_POST['cid'].SEP.'pid='.$_POST['pid'].SEP.'a_type='.$_POST['a_type']);
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'].SEP.'cp='.$_POST['cp'].SEP.'cid='.$_POST['cid'].SEP.'pid='.$_POST['pid'].SEP.'a_type='.$_POST['a_type']);
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.SEP.'cp='.$_POST['cp'].SEP.'cid='.$_POST['cid'].SEP.'pid='.$_POST['pid'].SEP.'a_type='.$_POST['a_type']);
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.SEP.'cp='.$_POST['cp'].SEP.'cid='.$_POST['cid'].SEP.'pid='.$_POST['pid'].SEP.'a_type='.$_POST['a_type']);
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.SEP.'cp='.$_POST['cp'].SEP.'cid='.$_POST['cid'].SEP.'pid='.$_POST['pid'].SEP.'a_type='.$_POST['a_type']);
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.SEP.'cp='.$_POST['cp'].SEP.'cid='.$_POST['cid'].SEP.'pid='.$_POST['pid'].SEP.'a_type='.$_POST['a_type']);
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.SEP.'cp='.$_POST['cp'].SEP.'cid='.$_POST['cid'].SEP.'pid='.$_POST['pid'].SEP.'a_type='.$_POST['a_type']);
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.SEP.'cp='.$_POST['cp'].SEP.'cid='.$_POST['cid'].SEP.'pid='.$_POST['pid'].SEP.'a_type='.$_POST['a_type']);
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'].SEP.'cp='.$_POST['cp'].SEP.'cid='.$_POST['cid'].SEP.'pid='.$_POST['pid'].SEP.'a_type='.$_POST['a_type']);
108         exit;
109 }
110
111 if (isset($_POST['dir_chosen'])) {
112         $hidden_vars['framed']  = $_REQUEST['framed'];
113         $hidden_vars['popup']   = $_REQUEST['popup'];
114         $hidden_vars['pathext'] = $_REQUEST['pathext'];
115         $hidden_vars['dest']    = $_REQUEST['dir_name'];
116         $hidden_vars['cp']  = $_REQUEST['cp'];
117         $hidden_vars['cid']   = $_REQUEST['cid'];
118         $hidden_vars['pid'] = $_REQUEST['pid'];
119         $hidden_vars['a_type']    = $_REQUEST['a_type'];
120         
121         if (isset($_POST['files'])) {
122                 $list_of_files = implode(' <br />', $_POST['files']);
123                 $hidden_vars['listoffiles'] = $list_of_files;
124                 $msg->addConfirm(array('FILE_MOVE', "<br />".$list_of_files."<br />", $_POST['dir_name']), $hidden_vars);
125         }
126         if (isset($_POST['dirs'])) {
127                 $list_of_dirs = implode(',', $_POST['dirs']);
128                 $hidden_vars['listoffiles'] = $list_of_dirs;
129                 $msg->addConfirm(array('DIR_MOVE', $list_of_dirs, $_POST['dir_name']), $hidden_vars);
130         }
131         require(AT_INCLUDE_PATH.'header.inc.php');
132         $msg->printConfirm();
133         require(AT_INCLUDE_PATH.'footer.inc.php');
134
135 else {
136         require(AT_INCLUDE_PATH.'header.inc.php');
137         
138         $tree = AT_CONTENT_DIR.$_SESSION['course_id'].'/';
139         $file    = $_GET['file'];
140         $pathext = $_GET['pathext']; 
141         $popup   = $_GET['popup'];
142         $framed  = $_GET['framed'];
143         $cp  = $_GET['cp'];
144         $cid  = $_GET['cid'];
145         $pid  = $_GET['pid'];
146         $a_type  = $_GET['a_type'];
147         
148         /* find the files and directories to be copied */
149         $total_list = explode(',', $_GET['list']);
150
151         $count = count($total_list);
152         $countd = 0;
153         $countf = 0;
154         for ($i=0; $i<$count; $i++) {
155                 if (is_dir($current_path.$pathext.$total_list[$i])) {
156                         $_dirs[$countd] = $total_list[$i];
157                         $hidden_dirs  .= '<input type="hidden" name="dirs['.$countd.']"   value="'.$_dirs[$countd].'" />';
158                         $countd++;
159                 } else {
160                         $_files[$countf] = $total_list[$i];
161                         $hidden_files .= '<input type="hidden" name="files['.$countf.']" value="'.$_files[$countf].'" />';
162                         $countf++;
163                 }
164         }
165 ?>
166
167 <form name="move_form" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
168 <div class="input-form">
169         <div class="row">
170                 <p><?php echo _AT('select_directory'); ?></p>
171         </div>
172         
173         <div class="row">
174                 <ul>
175                         <li class="folders"><label><input type="radio" name="dir_name" value="<?php echo _AT('home'); ?>"<?php
176                                 if ($pathext == '') {
177                                         echo ' checked="checked"';
178                                         $here = ' ' . _AT('current_location');
179                                 } 
180                                 echo '/>'._AT('home').' ' .$here.'</label>';
181                         
182                                 echo display_tree($current_path, '', $pathext);
183                         ?></li>
184                 </ul>
185         </div>
186
187         <div class="row buttons">
188                 <input type="submit" name="dir_chosen" value="<?php echo _AT('move'); ?>" accesskey="s" /> 
189                 <input type="submit" name="cancel" value="<?php echo _AT('cancel'); ?>" />
190         </div>
191 </div>
192
193 <input type="hidden" name="pathext" value="<?php echo $pathext; ?>" />
194 <input type="hidden" name="framed" value="<?php echo $framed; ?>" />
195 <input type="hidden" name="popup" value="<?php echo $popup; ?>" />
196 <input type="hidden" name="cp" value="<?php echo $cp; ?>" />
197 <input type="hidden" name="cid" value="<?php echo $cid; ?>" />
198 <input type="hidden" name="pid" value="<?php echo $pid; ?>" />
199 <input type="hidden" name="a_type" value="<?php echo $a_type; ?>" />
200                         <?php
201         echo $hidden_dirs;
202         echo $hidden_files;
203 ?>
204 </form>
205
206 <?php require(AT_INCLUDE_PATH.'footer.inc.php');
207 }
208 ?>