2 /****************************************************************/
4 /****************************************************************/
5 /* Copyright (c) 2002-2008 by Greg Gay & Joel Kronenberg */
6 /* Adaptive Technology Resource Centre / University of Toronto */
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: filemanager_display_alternatives.inc.php 7208 2008-07-04 16:07:24Z silvia $
15 if (!defined('AT_INCLUDE_PATH')) { exit; }
17 define('AT_INCLUDE_PATH', '../../include/');
18 //require(AT_INCLUDE_PATH.'vitals.inc.php');
19 //require(AT_INCLUDE_PATH.'lib/filemanager.inc.php');
23 //from tools/filemanager/index.php
24 if ((isset($_REQUEST['popup']) && $_REQUEST['popup']) &&
25 (!isset($_REQUEST['framed']) || !$_REQUEST['framed'])) {
28 } else if (isset($_REQUEST['framed']) && $_REQUEST['framed'] &&
29 isset($_REQUEST['popup']) && $_REQUEST['popup']) {
36 // end tools/filemanager/index.php
39 function get_file_extension($file_name) {
40 $ext = pathinfo($file_name);
41 return $ext['extension'];
44 function get_file_type_icon($file_name) {
47 $ext = get_file_extension($file_name);
50 require(AT_INCLUDE_PATH .'lib/mime.inc.php');
53 if (isset($mime[$ext]) && $mime[$ext][1]) {
54 return $mime[$ext][1];
59 function get_relative_path($src, $dest) {
62 } else if (substr($dest, 0, strlen($src)) == $src) {
63 $path = substr($dest, strlen($src) + 1);
65 $path = '../' . $dest;
71 // get the course total in Bytes
72 $course_total = dirsize($current_path);
74 $framed = intval($_GET['framed']);
75 $popup = intval($_GET['popup']);
77 if (defined('AT_FORCE_GET_FILE') && AT_FORCE_GET_FILE) {
78 $get_file = 'get.php/';
80 $get_file = 'content/' . $_SESSION['course_id'] . '/';
83 echo '<p>'._AT('current_path').' ';
86 echo '<a href="'.$_SERVER['PHP_SELF'].'?cid='.$cid. SEP . 'popup=' . $popup . SEP . 'framed=' . $framed .SEP. 'tab='.$current_tab.'">'._AT('home').'</a> ';
93 $pathext = urlencode($_POST['pathext']);
97 $bits = explode('/', $pathext);
99 foreach ($bits as $bit) {
101 $bit_path .= $bit . '/';
104 if ($bit_path == $pathext) {
107 echo '<a href="'.$_SERVER['PHP_SELF'].'?pathext=' . urlencode($bit_path) . SEP . 'popup=' . $popup . SEP . 'framed=' . $framed . '">' . $bit . '</a>';
116 if ($popup == TRUE) {
123 if (TRUE || $framed != TRUE) {
125 if ($_GET['overwrite'] != '') {
126 // get file name, out of the full path
127 $path_parts = pathinfo($current_path.$_GET['overwrite']);
129 if (!file_exists($path_parts['dirname'].'/'.$pathext.$path_parts['basename'])
130 || !file_exists($path_parts['dirname'].'/'.$pathext.substr($path_parts['basename'], 5))) {
131 /* source and/or destination does not exist */
132 $msg->addErrors('CANNOT_OVERWRITE_FILE');
134 @unlink($path_parts['dirname'].'/'.$pathext.substr($path_parts['basename'], 5));
135 $result = @rename($path_parts['dirname'].'/'.$pathext.$path_parts['basename'], $path_parts['dirname'].'/'.$pathext.substr($path_parts['basename'], 5));
138 $msg->addFeedback('FILE_OVERWRITE');
140 $msg->addErrors('CANNOT_OVERWRITE_FILE');
145 echo '<fieldset><legend class="group_form">'._AT('add').'</legend>';
146 echo '<table cellspacing="1" cellpadding="0" border="0" summary="" align="center">';
147 echo '<tr><td colspan="2">';
151 if ($depth < $MaxDirDepth) {
152 echo '<input type="text" name="dirname" size="20" /> ';
153 echo '<input type="hidden" name="mkdir_value" value="true" /> ';
154 echo '<input type="submit" name="mkdir" value="'._AT('create_folder').'" class="button" />';
155 echo ' <small class="spacer">'._AT('keep_it_short').'</small>';
157 echo _AT('depth_reached');
160 echo '<input type="hidden" name="pathext" value="'.$pathext.'" />';
161 echo '<input type="hidden" name="current_tab" value="'.$current_tab.'" />';
165 $my_MaxCourseSize = $system_courses[$_SESSION['course_id']]['max_quota'];
168 if (($my_MaxCourseSize == AT_COURSESIZE_UNLIMITED)
169 || (($my_MaxCourseSize == AT_COURSESIZE_DEFAULT) && ($course_total < $MaxCourseSize))
170 || ($my_MaxCourseSize-$course_total > 0)) {
171 echo '<tr><td colspan="1">';
172 echo '<input type="hidden" name="MAX_FILE_SIZE" value="'.$my_MaxFileSize.'" />';
173 echo '<input type="file" name="uploadedfile" id="uploadedfile" class="formfield" size="20" />';
174 echo '<input type="submit" name="upload" value="'._AT('upload').'" class="button" />';
175 echo '<input type="hidden" name="pathext" value="'.$pathext.'" /> ';
176 echo '<input type="hidden" name="alter" value="TRUE" /> ';
178 if ($popup == TRUE) {
179 echo '<input type="hidden" name="popup" value="1" />';
181 echo '</td></tr></table></fieldset>';
186 $msg->printInfos('OVER_QUOTA');
190 // Directory and File listing
193 echo '<input type="hidden" name="pathext" value ="'.$pathext.'" />';
196 <table class="data static" summary="" border="0" rules="groups" style="width: 90%">
199 <!-- <th scope="col"><input type="checkbox" name="checkall" onclick="Checkall(checkform);" id="selectall" title="<?php echo _AT('select_all'); ?>" /></th>
203 <th scope="col"><?php echo _AT('name'); ?></th>
205 <!-- <th scope="col"><?php //echo _AT('date'); ?></th>
206 <th scope="col"><?php //echo _AT('size'); ?></th>-->
212 <td colspan="3" align="right">
213 <?php echo '<input type="submit" name="add" value="'._AT('add').'" class="button"/>';?>
223 <td colspan="3"><a href="<?php echo $_SERVER['PHP_SELF'].'?cid='.$cid. SEP .'back=1'.SEP.'pathext='.$pathext.SEP. 'popup=' . $popup .SEP. 'framed=' . $framed .SEP.'cp='.$_GET['cp'] . SEP. 'tab='.$current_tab; ?>"><img src="<?php echo$_base_href;?>images/arrowicon.gif" border="0" height="11" width="10" alt="" /> <?php echo _AT('back'); ?></a></td>
230 $dir=opendir($current_path);
232 // loop through folder to get files and directory listing
233 while (false !== ($file = readdir($dir)) ) {
235 // if the name is not a directory
236 if( ($file == '.') || ($file == '..') ) {
240 // get some info about the file
241 $filedata = stat($current_path.$pathext.$file);
242 $path_parts = pathinfo($file);
243 $ext = strtolower($path_parts['extension']);
247 // if it is a directory change the file name to a directory link
248 if(is_dir($current_path.$pathext.$file)) {
249 $size = dirsize($current_path.$pathext.$file.'/');
250 $totalBytes += $size;
251 $filename = '<a href="'.$_SERVER['PHP_SELF'].'?cid='.$cid.SEP.'pathext='.urlencode($pathext.$file.'/').SEP.'popup='.$popup.SEP.'framed='.$framed.SEP.'cp='.$_GET['cp'].SEP.'tab='.$current_tab.SEP.'alternatives='.$_POST['alternatives'].'">'.$file.'</a>';
252 $fileicon = ' ';
253 $fileicon .= '<img src="'.$_base_href.'images/folder.gif" alt="'._AT('folder').':'.$file.'" height="18" width="20" class="img-size-fm1" />'."\n";
254 $fileicon .= ' ';
260 } else if ($ext == 'zip') {
262 $totalBytes += $filedata[7];
264 $fileicon = ' <img src="'.$_base_href.'images/icon-zip.gif" alt="'._AT('zip_archive').':'.$file.'" height="16" width="16" border="0" class="img-size-fm2" /> '."\n";
267 $totalBytes += $filedata[7];
269 $fileicon = ' <img src="'.$_base_href.'images/file_types/'.get_file_type_icon($filename).'.gif" height="16" width="16" alt="" title="" class="img-size-fm2" /> '."\n";
271 $file1 = strtolower($file);
272 // create listing for dirctor or file
275 $dirs[$file1] .= '<tr><td> </td>'."\n";
276 $dirs[$file1] .= '<td>'.$fileicon.'</td>'."\n";
277 $dirs[$file1] .= ' ';
278 $dirs[$file1] .= '<td>'.$filename.'</td>'."\n";
279 $dirs[$file1] .= '</tr>'."\n";
284 // set content path $cp
285 $sql = "SELECT content_path FROM ".TABLE_PREFIX."content WHERE content_id=".$cid;
286 $result = mysql_query($sql, $db);
287 $row = mysql_fetch_assoc($result);
288 $cp = $row["content_path"];
291 $file_with_relative_path = get_relative_path($cp, $pathext.urlencode($file));
293 $files[$file1] .= '<tr> <td align="center">';
294 $files[$file1] .= '<input type="radio" id="'.$file_with_relative_path.'" value="'.$file_with_relative_path.'" name="radio_alt"/> </td>'."\n";
295 $files[$file1] .= '<td align="center">'.$fileicon.'</td>'."\n";
297 $files[$file1] .= '<td ><label for="'.$file.'"> ';
299 $files[$file1] .= '<a href="'.$file_with_relative_path.'">'.$file.'</a>';
301 $files[$file1] .= ' </label></td></tr>'."\n";
306 // sort listing and output directories
307 if (is_array($dirs)) {
308 ksort($dirs, SORT_STRING);
309 foreach($dirs as $x => $y) {
314 //sort listing and output files
315 if (is_array($files)) {
316 ksort($files, SORT_STRING);
317 foreach($files as $x => $y) {
322 echo '</table>'."\n";
327 <script type="text/javascript">
330 function openWindow(page) {
331 newWindow = window.open(page, "progWin", "width=400,height=200,toolbar=no,location=no");