moved code up one level to eliminate the docs subdirectory
[acontent.git] / file_manager / move.php
1 <?php
2 /************************************************************************/
3 /* AContent                                                             */
4 /************************************************************************/
5 /* Copyright (c) 2010                                                   */
6 /* Inclusive Design Institute                                           */
7 /*                                                                      */
8 /* This program is free software. You can redistribute it and/or        */
9 /* modify it under the terms of the GNU General Public License          */
10 /* as published by the Free Software Foundation.                        */
11 /************************************************************************/
12
13 define('TR_INCLUDE_PATH', '../include/');
14 require(TR_INCLUDE_PATH.'vitals.inc.php');
15 require(TR_INCLUDE_PATH.'classes/FileUtility.class.php');
16
17 global $_course_id;
18 Utility::authenticate(TR_PRIV_ISAUTHOR_OF_CURRENT_COURSE);
19
20 $current_path = TR_CONTENT_DIR.$_course_id.'/';
21
22 $popup = $_REQUEST['popup'];
23 $framed = $_REQUEST['framed'];
24
25 if (isset($_POST['submit_no'])) {
26         $msg->addFeedback('CANCELLED');
27         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'].SEP.'_course_id='.$_course_id);
28         exit;
29 }
30
31 if (isset($_POST['cancel'])) {
32         $msg->addFeedback('CANCELLED');
33         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'].SEP.'_course_id='.$_course_id);
34         exit;
35 }
36
37 if (isset($_POST['submit_yes'])) {
38         $dest = $_POST['dest'] .'/';
39         $pathext = $_POST['pathext'];
40
41         if (isset($_POST['listofdirs'])) {
42
43                 $_dirs = explode(',',$_POST['listofdirs']);
44                 $count = count($_dirs);
45                 
46                 for ($i = 0; $i < $count; $i++) {
47                         $source = $_dirs[$i];
48                         
49                         if (FileUtility::course_realpath($current_path . $pathext . $source) == FALSE) {
50                                 // error: File does not exist
51                                 $msg->addError('DIR_NOT_EXIST');
52                                 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'].SEP.'_course_id='.$_course_id);
53                                 exit;
54                         }
55                         else if (FileUtility::course_realpath($current_path . $dest) == FALSE) {
56                                 // error: File does not exist
57                                 $msg->addError('UNKNOWN');
58                                 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'].SEP.'_course_id='.$_course_id);
59                                 exit;
60                         }
61                         else if (strpos($source, '..') !== false) {
62                                 $msg->addError('UNKNOWN');
63                                 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'].SEP.'_course_id='.$_course_id);
64                                 exit;
65                         }       
66                         else {
67                                 @rename($current_path.$pathext.$source, $current_path.$dest.$source);
68                         }
69                 }
70                 $msg->addFeedback('DIRS_MOVED');
71         }
72         if (isset($_POST['listoffiles'])) {
73
74                 $_files = explode(',',$_POST['listoffiles']);
75                 $count = count($_files);
76
77                 for ($i = 0; $i < $count; $i++) {
78                         $source = $_files[$i];
79                         
80                         if (FileUtility::course_realpath($current_path . $pathext . $source) == FALSE) {
81                                 // error: File does not exist
82                                 $msg->addError('FILE_NOT_EXIST');
83                                 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'].SEP.'_course_id='.$_course_id);
84                                 exit;
85                         }
86                         else if (FileUtility::course_realpath($current_path . $dest) == FALSE) {
87                                 // error: File does not exist
88                                 $msg->addError('UNKNOWN');
89                                 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'].SEP.'_course_id='.$_course_id);
90                                 exit;
91                         }
92                         else if (strpos($source, '..') !== false) {
93                                 $msg->addError('UNKNOWN');
94                                 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'].SEP.'_course_id='.$_course_id);
95                                 exit;
96                         }       
97                         else {
98                                 @rename($current_path.$pathext.$source, $current_path.$dest.$source);
99                         }
100                 }
101                 $msg->addFeedback('MOVED_FILES');
102         }
103         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'].SEP.'_course_id='.$_course_id);
104         exit;
105 }
106
107 if (isset($_POST['dir_chosen'])) {
108         $hidden_vars['framed'] = $_REQUEST['framed'];
109         $hidden_vars['popup'] = $_REQUEST['popup'];
110         $hidden_vars['pathext'] = $_REQUEST['pathext'];
111         $hidden_vars['dest'] = $_REQUEST['dir_name'];
112         $hidden_vars['cp'] = $_REQUEST['cp'];
113         $hidden_vars['cid'] = $_REQUEST['cid'];
114         $hidden_vars['pid'] = $_REQUEST['pid'];
115         $hidden_vars['a_type'] = $_REQUEST['a_type'];
116         $hidden_vars['_course_id'] = $_course_id;
117         
118         if (isset($_POST['files'])) {
119                 $list_of_files = implode(',', $_POST['files']);
120                 $hidden_vars['listoffiles'] = $list_of_files;
121                 $msg->addConfirm(array('FILE_MOVE', $list_of_files, $_POST['dir_name']), $hidden_vars);
122         }
123         if (isset($_POST['dirs'])) {
124                 $list_of_dirs = implode(',', $_POST['dirs']);
125                 $hidden_vars['listoffiles'] = $list_of_dirs;
126                 $msg->addConfirm(array('DIR_MOVE', $list_of_dirs, $_POST['dir_name']), $hidden_vars);
127         }
128         require(TR_INCLUDE_PATH.'header.inc.php');
129         $msg->printConfirm();
130         require(TR_INCLUDE_PATH.'footer.inc.php');
131
132 else {
133         require(TR_INCLUDE_PATH.'header.inc.php');
134         
135         $tree = TR_CONTENT_DIR.$_course_id.'/';
136         $file    = $_GET['file'];
137         $pathext = $_GET['pathext']; 
138         $popup   = $_GET['popup'];
139         $framed  = $_GET['framed'];
140         $cp  = $_GET['cp'];
141         $cid  = $_GET['cid'];
142         $pid  = $_GET['pid'];
143         $a_type  = $_GET['a_type'];
144         
145         /* find the files and directories to be copied */
146         $total_list = explode(',', $_GET['list']);
147
148         $count = count($total_list);
149         $countd = 0;
150         $countf = 0;
151         for ($i=0; $i<$count; $i++) {
152                 if (is_dir($current_path.$pathext.$total_list[$i])) {
153                         $_dirs[$countd] = $total_list[$i];
154                         $hidden_dirs  .= '<input type="hidden" name="dirs['.$countd.']"   value="'.$_dirs[$countd].'" />';
155                         $countd++;
156                 } else {
157                         $_files[$countf] = $total_list[$i];
158                         $hidden_files .= '<input type="hidden" name="files['.$countf.']" value="'.$_files[$countf].'" />';
159                         $countf++;
160                 }
161         }
162 ?>
163
164 <form name="move_form" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
165 <div class="input-form">
166         <div class="row">
167                 <p><?php echo _AT('select_directory'); ?></p>
168         </div>
169         
170         <div class="row">
171                 <ul>
172                         <li class="folders"><label><input type="radio" name="dir_name" value=""<?php
173                                 if ($pathext == '') {
174                                         echo ' checked="checked"';
175                                         $here = ' ' . _AT('current_location');
176                                 } 
177                                 echo '/>Home ' .$here.'</label>';
178                         
179                                 echo FileUtility::display_tree($current_path, '', $pathext);
180                         ?></li>
181                 </ul>
182         </div>
183
184         <div class="row buttons">
185                 <input type="submit" name="dir_chosen" value="<?php echo _AT('move'); ?>" accesskey="s" /> 
186                 <input type="submit" name="cancel" value="<?php echo _AT('cancel'); ?>" />
187         </div>
188 </div>
189
190 <input type="hidden" name="pathext" value="<?php echo AT_print($pathext, 'input.hidden'); ?>" />
191 <input type="hidden" name="framed" value="<?php echo AT_print($framed, 'input.hidden'); ?>" />
192 <input type="hidden" name="popup" value="<?php echo AT_print($popup, 'input.hidden'); ?>" />
193 <input type="hidden" name="cp" value="<?php echo AT_print($cp, 'input.hidden'); ?>" />
194 <input type="hidden" name="cid" value="<?php echo AT_print($cid, 'input.hidden'); ?>" />
195 <input type="hidden" name="pid" value="<?php echo AT_print($pid, 'input.hidden'); ?>" />
196 <input type="hidden" name="a_type" value="<?php echo AT_print($a_type, 'input.hidden'); ?>" />
197 <input type="hidden" name="_course_id" value="<?php echo AT_print($_course_id, 'input.hidden'); ?>" />
198 <?php
199         echo $hidden_dirs;
200         echo $hidden_files;
201 ?>
202 </form>
203
204 <?php require(TR_INCLUDE_PATH.'footer.inc.php');
205 }
206 ?>