2 /****************************************************************/
4 /****************************************************************/
5 /* Copyright (c) 2002-2010 */
6 /* Inclusive Design Institute */
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 /****************************************************************/
15 $page = 'file_manager';
17 define('AT_INCLUDE_PATH', '../../../include/');
18 require(AT_INCLUDE_PATH.'vitals.inc.php');
19 require(AT_INCLUDE_PATH.'classes/pclzip.lib.php');
20 require_once(AT_INCLUDE_PATH.'../mods/_core/file_manager/filemanager.inc.php');
22 if (!authenticate(AT_PRIV_FILES,AT_PRIV_RETURN)) {
23 authenticate(AT_PRIV_CONTENT);
27 $popup = $_REQUEST['popup'];
28 $framed = $_REQUEST['framed'];
30 if (isset($_POST['cancel'])) {
31 $msg->addFeedback('CANCELLED');
32 header('Location: index.php?pathext='.$_POST['pathext'].SEP.'popup='.$_POST['popup'].SEP.'framed='.$_POST['framed']);
36 $path = AT_CONTENT_DIR . $_SESSION['course_id'].'/';
38 if ($_REQUEST['pathext'] != '') {
39 $pathext = $_REQUEST['pathext'];
41 if ($_REQUEST['file'] != '') {
42 $file = $_REQUEST['file'];
45 if (strpos($file, '..') !== false) {
46 require(AT_INCLUDE_PATH.'header.inc.php');
47 $msg->printErrors('UNKNOWN');
48 require(AT_INCLUDE_PATH.'footer.inc.php');
52 $path_parts = pathinfo($pathext.$file);
54 $temp_name = substr($file, 0, -strlen('.'.$path_parts['extension']));
56 $zip = new PclZip($path.$pathext.$file);
58 if (($list = $zip->listContent()) == 0) {
59 die("Error : ".$zip->errorInfo(true));
62 /*****************************************************************/
64 $translated_file_names = array();
66 for ($i=0; $i<sizeof($list); $i++) {
67 $path_parts = pathinfo($list[$i]['stored_filename']);
68 if ($path_parts['dirname'] == '.') {
69 $path_parts['dirname'] = '';
71 $path_parts['dirname'] .= '/';
73 $ext = $path_parts['extension'];
76 if($list[$i]['folder']) {
78 $filename = $list[$i]['stored_filename'];
79 $fileicon = '<img src="images/folder.gif" alt="'._AT('folder').'" />';
83 } else if ($ext == 'zip') {
85 $totalBytes += $list[$i]['size'];
86 $filename = $list[$i]['stored_filename'];
87 $fileicon = '<img src="images/icon-zip.gif" alt="'._AT('zip_archive').'" height="16" width="16" border="0" />';
90 $totalBytes += $list[$i]['size'];
91 $filename = $list[$i]['stored_filename'];
92 $fileicon = '<img src="images/icon_minipost.gif" alt="'._AT('file').'" height="11" width="16" />';
96 $dirs[strtolower($filename)] .= '<tr>
97 <td>'.$filename.'</td>';
99 $dirs[strtolower($filename)] .= '<td class="row1" align="right">'.get_human_size($list[$i]['size']).' </td>';
100 $dirs[strtolower($filename)] .= '<td class="row1"> ';
102 $dirs[strtolower($filename)] .= AT_date(_AT('filemanager_date_format'), $filedata[10], AT_DATE_UNIX_TIMESTAMP);
104 $dirs[strtolower($filename)] .= ' </td>';
106 $dirs[strtolower($filename)] .= '</tr>';
109 $files[strtolower($filename)] .= '<tr>
112 if (in_array($ext, $IllegalExtentions)) {
113 $files[strtolower($filename)] .= '<span style="text-decoration: line-through;" title="'._AT('illegal_file').'">'.$filename.'</span>';
115 $files[strtolower($filename)] .= $filename;
117 $trans_name = str_replace(' ', '_', $path_parts['basename']);
118 $trans_name = preg_replace("/[^A-Za-z0-9._\-]/", '', $trans_name);
120 if (in_array($path_parts['dirname'].$trans_name, $translated_file_names)) {
122 while (in_array($trans_name, $translated_file_names)) {
123 $part = substr($trans_name, 0, -strlen($ext)- 1 - (2*($trans_count-2)));
124 $trans_name = $part.'_'.$trans_count.'.'.$ext;
126 if ($trans_count>15){
127 exit; // INF loop safety thing..
132 $translated_file_names[$list[$i]['index']] = $path_parts['dirname'].$trans_name;
134 if ($path_parts['dirname'].$trans_name != $filename) {
135 $files[strtolower($filename)] .= ' => '.$trans_name;
140 $files[strtolower($filename)] .= '</td>';
142 $files[strtolower($filename)] .= '<td align="right">'.get_human_size($list[$i]['size']).' </td>';
143 $files[strtolower($filename)] .= '<td> ';
145 $files[strtolower($filename)] .= AT_date(_AT('filemanager_date_format'), $list[$i]['mtime'], AT_DATE_UNIX_TIMESTAMP);
147 $files[strtolower($filename)] .= '</td>';
149 $files[strtolower($filename)] .= '</tr>';
153 $sql = "SELECT max_quota, max_file_size FROM ".TABLE_PREFIX."courses WHERE course_id=$_SESSION[course_id]";
154 $result = mysql_query($sql, $db);
155 $row = mysql_fetch_assoc($result);
156 $my_MaxCourseSize = $row['max_quota'];
157 $my_MaxFileSize = $row['max_file_size'];
159 $course_total = dirsize($path);
160 if ($my_MaxCourseSize == AT_COURSESIZE_UNLIMITED) {
162 } else if ($my_MaxCourseSize == AT_COURSESIZE_DEFAULT) {
163 $my_MaxCourseSize = $MaxCourseSize;
164 $total_after = get_human_size($my_MaxCourseSize-$course_total-$totalBytes);
166 $total_after = get_human_size($my_MaxCourseSize - $course_total - $totalBytes);
169 // if $total_after < 0: redirect with error msg
171 if (isset($_POST['submit']) && ($total_after > 0)) {
172 $_POST['custom_path'] = trim($_POST['custom_path']);
173 $_POST['custom_path'] = str_replace(' ', '_', $_POST['custom_path']);
175 /* anything else should be okay, since we're on *nix.. hopefully */
176 $_POST['custom_path'] = preg_replace('/[^a-zA-Z0-9._\/]/', '', $_POST['custom_path']);
178 if (strpos($_POST['pathext'].$_POST['custom_path'], '..') !== false) {
179 $msg->addError('UNKNOWN');
180 header('Location: index.php?pathext='.$_POST['pathext'].SEP.'framed='.$_POST['framed'].SEP.'popup='.$_POST['popup']);
182 } else if ($zip->extract( PCLZIP_OPT_PATH, $path. $_POST['pathext'] . $_POST['custom_path'],
183 PCLZIP_CB_PRE_EXTRACT, 'preExtractCallBack') == 0) {
185 echo ("Error : ".$zip->errorInfo(true));
187 $msg->addFeedback('ARCHIVE_EXTRACTED');
188 header('Location: index.php?pathext='.$_POST['pathext'].SEP.'popup='.$_POST['popup'].SEP.'framed='.$_POST['framed']);
192 header('Location: index.php');
196 require(AT_INCLUDE_PATH.'header.inc.php');
198 if (($my_MaxCourseSize != AT_COURSESIZE_UNLIMITED) && ($total_after + $MaxCourseFloat <= 0)) {
199 $msg->printErrors('NO_SPACE_LEFT');
202 <form method="post" action="mods/_core/file_manager/zip.php">
203 <input type="hidden" name="pathext" value="<?php echo $_GET['pathext']; ?>" />
204 <input type="hidden" name="file" value="<?php echo $_GET['file']; ?>" />
205 <input type="hidden" name="popup" value="<?php echo $_GET['popup']; ?>" />
206 <input type="hidden" name="framed" value="<?php echo $_GET['framed']; ?>" />
207 <div class="input-form">
209 <p><?php echo _AT('zip_illegal_contents'); ?></p>
210 <p><?php echo _AT('extract_tip'); ?></p>
214 <span class="required" title="<?php echo _AT('required_field'); ?>">*</span><?php echo _AT('directory_name'); ?><br />
215 <input type="text" name="custom_path" value="<?php echo $temp_name; ?>" />
218 <div class="row buttons">
219 <input type="submit" name="submit" value="<?php echo _AT('extract'); ?>" />
220 <input type="submit" name="cancel" value="<?php echo _AT('cancel'); ?>" />
228 <table class="data static" summary="" rules="groups">
231 <th><?php echo _AT('name'); ?></th>
232 <th><?php echo _AT('size'); ?></th>
233 <th><?php echo _AT('date'); ?></th>
238 if (is_array($dirs)) {
239 foreach($dirs as $x => $y) {
244 if (is_array($files)) {
245 foreach($files as $x => $y) {
253 <td align="right"><?php echo _AT('archive_total'); ?>:</td>
254 <td align="right"><?php echo get_human_size($totalBytes); ?></td>
258 <td align="right"><?php echo _AT('course_total_zip'); ?>:</td>
259 <td align="right"><?php echo get_human_size($course_total); ?></td>
263 <td align="right"><?php echo _AT('course_available_zip1'); ?>:</td>
264 <td align="right"><?php
265 if ($my_MaxCourseSize == AT_COURSESIZE_UNLIMITED) {
266 echo _AT('unlimited');
268 echo get_human_size($my_MaxCourseSize-$course_total);
273 <td align="right"><?php echo _AT('course_available_zip2'); ?>:</td>
274 <td align="right"><?php
275 if ($my_MaxCourseSize == AT_COURSESIZE_UNLIMITED) {
276 echo _AT('unlimited');
278 if ($total_after <= 0) {
279 echo '<span style="color: red;">';
291 <?php require(AT_INCLUDE_PATH.'footer.inc.php'); ?>