2 /************************************************************************/
4 /************************************************************************/
5 /* Copyright (c) 2010 */
6 /* Inclusive Design Institute */
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 /************************************************************************/
13 $page = 'file_manager';
15 define('TR_INCLUDE_PATH', '../include/');
16 require_once(TR_INCLUDE_PATH.'vitals.inc.php');
17 require_once(TR_INCLUDE_PATH.'lib/pclzip.lib.php');
18 require_once(TR_INCLUDE_PATH.'lib/pclzip_callback.lib.php');
19 require_once(TR_INCLUDE_PATH.'classes/FileUtility.class.php');
20 require_once(TR_INCLUDE_PATH.'classes/DAO/CoursesDAO.class.php');
23 Utility::authenticate(TR_PRIV_ISAUTHOR_OF_CURRENT_COURSE);
24 $coursesDAO = new CoursesDAO();
26 $popup = $_REQUEST['popup'];
27 $framed = $_REQUEST['framed'];
29 if (isset($_POST['cancel'])) {
30 $msg->addFeedback('CANCELLED');
31 header('Location: index.php?pathext='.$_POST['pathext'].SEP.'popup='.$_POST['popup'].SEP.'framed='.$_POST['framed'].SEP.'_course_id='.$_course_id);
35 $path = TR_CONTENT_DIR . $_course_id.'/';
37 if ($_REQUEST['pathext'] != '') {
38 $pathext = $_REQUEST['pathext'];
40 if ($_REQUEST['file'] != '') {
41 $file = $_REQUEST['file'];
44 if (strpos($file, '..') !== false) {
45 require(TR_INCLUDE_PATH.'header.inc.php');
46 $msg->printErrors('UNKNOWN');
47 require(TR_INCLUDE_PATH.'footer.inc.php');
51 $path_parts = pathinfo($pathext.$file);
53 $temp_name = substr($file, 0, -strlen('.'.$path_parts['extension']));
55 $zip = new PclZip($path.$pathext.$file);
57 if (($list = $zip->listContent()) == 0) {
58 die("Error : ".$zip->errorInfo(true));
61 /*****************************************************************/
63 $translated_file_names = array();
65 for ($i=0; $i<sizeof($list); $i++) {
66 $path_parts = pathinfo($list[$i]['stored_filename']);
67 if ($path_parts['dirname'] == '.') {
68 $path_parts['dirname'] = '';
70 $path_parts['dirname'] .= '/';
72 $ext = $path_parts['extension'];
75 if($list[$i]['folder']) {
77 $filename = $list[$i]['stored_filename'];
78 $fileicon = '<img src="images/folder.gif" alt="'._AT('folder').'" />';
82 } else if ($ext == 'zip') {
84 $totalBytes += $list[$i]['size'];
85 $filename = $list[$i]['stored_filename'];
86 $fileicon = '<img src="images/icon-zip.gif" alt="'._AT('zip_archive').'" height="16" width="16" border="0" />';
89 $totalBytes += $list[$i]['size'];
90 $filename = $list[$i]['stored_filename'];
91 $fileicon = '<img src="images/icon_minipost.gif" alt="'._AT('file').'" height="11" width="16" />';
95 $dirs[strtolower($filename)] .= '<tr>
96 <td>'.$filename.'</td>';
98 $dirs[strtolower($filename)] .= '<td class="row1" align="right">'.FileUtility::get_human_size($list[$i]['size']).' </td>';
99 $dirs[strtolower($filename)] .= '<td class="row1"> ';
101 $dirs[strtolower($filename)] .= AT_date(_AT('filemanager_date_format'), $filedata[10], TR_DATE_UNIX_TIMESTAMP);
103 $dirs[strtolower($filename)] .= ' </td>';
105 $dirs[strtolower($filename)] .= '</tr>';
108 $files[strtolower($filename)] .= '<tr>
111 if (in_array($ext, $IllegalExtentions)) {
112 $files[strtolower($filename)] .= '<span style="text-decoration: line-through;" title="'._AT('illegal_file').'">'.$filename.'</span>';
114 $files[strtolower($filename)] .= $filename;
116 $trans_name = str_replace(' ', '_', $path_parts['basename']);
117 $trans_name = preg_replace("/[^A-Za-z0-9._\-]/", '', $trans_name);
119 if (in_array($path_parts['dirname'].$trans_name, $translated_file_names)) {
121 while (in_array($trans_name, $translated_file_names)) {
122 $part = substr($trans_name, 0, -strlen($ext)- 1 - (2*($trans_count-2)));
123 $trans_name = $part.'_'.$trans_count.'.'.$ext;
125 if ($trans_count>15){
126 exit; // INF loop safety thing..
131 $translated_file_names[$list[$i]['index']] = $path_parts['dirname'].$trans_name;
133 if ($path_parts['dirname'].$trans_name != $filename) {
134 $files[strtolower($filename)] .= ' => '.$trans_name;
139 $files[strtolower($filename)] .= '</td>';
141 $files[strtolower($filename)] .= '<td align="right">'.FileUtility::get_human_size($list[$i]['size']).' </td>';
142 $files[strtolower($filename)] .= '<td> ';
144 $files[strtolower($filename)] .= AT_date(_AT('filemanager_date_format'), $list[$i]['mtime'], TR_DATE_UNIX_TIMESTAMP);
146 $files[strtolower($filename)] .= '</td>';
148 $files[strtolower($filename)] .= '</tr>';
152 $row = $coursesDAO->get($_course_id);
153 $my_MaxCourseSize = $row['max_quota'];
154 $my_MaxFileSize = $row['max_file_size'];
156 $course_total = FileUtility::dirsize($path);
157 if ($my_MaxCourseSize == TR_COURSESIZE_UNLIMITED) {
160 $my_MaxCourseSize = $MaxCourseSize;
161 $total_after = FileUtility::get_human_size($my_MaxCourseSize-$course_total-$totalBytes);
164 // $total_after = get_human_size($my_MaxCourseSize - $course_total - $totalBytes);
167 // if $total_after < 0: redirect with error msg
169 if (isset($_POST['submit']) && ($total_after > 0)) {
170 $_POST['custom_path'] = trim($_POST['custom_path']);
171 $_POST['custom_path'] = str_replace(' ', '_', $_POST['custom_path']);
173 /* anything else should be okay, since we're on *nix.. hopefully */
174 $_POST['custom_path'] = preg_replace('/[^a-zA-Z0-9._\/]/', '', $_POST['custom_path']);
176 if (strpos($_POST['pathext'].$_POST['custom_path'], '..') !== false) {
177 $msg->addError('UNKNOWN');
178 header('Location: index.php?pathext='.$_POST['pathext'].SEP.'framed='.$_POST['framed'].SEP.'popup='.$_POST['popup'].SEP.'_course_id='.$_course_id);
180 } else if ($zip->extract( PCLZIP_OPT_PATH, $path. $_POST['pathext'] . $_POST['custom_path'],
181 PCLZIP_CB_PRE_EXTRACT, 'preExtractCallBack') == 0) {
183 echo ("Error : ".$zip->errorInfo(true));
185 $msg->addFeedback('ARCHIVE_EXTRACTED');
186 header('Location: index.php?pathext='.$_POST['pathext'].SEP.'popup='.$_POST['popup'].SEP.'framed='.$_POST['framed'].SEP.'_course_id='.$_course_id);
190 header('Location: index.php'.SEP.'_course_id='.$_course_id);
194 require(TR_INCLUDE_PATH.'header.inc.php');
196 if ($total_after <= 0) {
197 $msg->printErrors('NO_SPACE_LEFT');
200 <form method="post" action="file_manager/zip.php">
201 <input type="hidden" name="pathext" value="<?php echo AT_print($_GET['pathext'], 'input.hidden'); ?>" />
202 <input type="hidden" name="file" value="<?php echo AT_print($_GET['file'], 'input.hidden'); ?>" />
203 <input type="hidden" name="popup" value="<?php echo AT_print($_GET['popup'], 'input.hidden'); ?>" />
204 <input type="hidden" name="framed" value="<?php echo AT_print($_GET['framed'], 'input.hidden'); ?>" />
205 <input type="hidden" name="_course_id" value="<?php echo $_course_id; ?>" />
206 <div class="input-form">
208 <p><?php echo _AT('zip_illegal_contents'); ?></p>
209 <p><?php echo _AT('extract_tip'); ?></p>
213 <span class="required" title="<?php echo _AT('required_field'); ?>">*</span><?php echo _AT('directory_name'); ?><br />
214 <input type="text" name="custom_path" value="<?php echo AT_print($temp_name, 'input.text'); ?>" />
217 <div class="row buttons">
218 <input type="submit" name="submit" value="<?php echo _AT('extract'); ?>" />
219 <input type="submit" name="cancel" value="<?php echo _AT('cancel'); ?>" />
227 <table class="data static" summary="" rules="groups">
230 <th><?php echo _AT('name'); ?></th>
231 <th><?php echo _AT('size'); ?></th>
232 <th><?php echo _AT('date'); ?></th>
237 if (is_array($dirs)) {
238 foreach($dirs as $x => $y) {
243 if (is_array($files)) {
244 foreach($files as $x => $y) {
252 <td align="right"><?php echo _AT('archive_total'); ?>:</td>
253 <td align="right"><?php echo FileUtility::get_human_size($totalBytes); ?></td>
257 <td align="right"><?php echo _AT('course_total_zip'); ?>:</td>
258 <td align="right"><?php echo FileUtility::get_human_size($course_total); ?></td>
262 <td align="right"><?php echo _AT('course_available_zip1'); ?>:</td>
263 <td align="right"><?php
264 if ($my_MaxCourseSize == TR_COURSESIZE_UNLIMITED) {
265 echo _AT('unlimited');
267 echo FileUtility::get_human_size($my_MaxCourseSize-$course_total);
272 <td align="right"><?php echo _AT('course_available_zip2'); ?>:</td>
273 <td align="right"><?php
274 if ($my_MaxCourseSize == TR_COURSESIZE_UNLIMITED) {
275 echo _AT('unlimited');
277 if ($total_after <= 0) {
278 echo '<span style="color: red;">';
290 <?php require(TR_INCLUDE_PATH.'footer.inc.php'); ?>