tagging as ATutor 1.5.4-release
[atutor.git] / file_storage / index.php
1 <?php
2 /****************************************************************/
3 /* ATutor                                                                                                               */
4 /****************************************************************/
5 /* Copyright (c) 2002-2006 by Greg Gay & Joel Kronenberg        */
6 /* Adaptive Technology Resource Centre / University of Toronto  */
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(AT_INCLUDE_PATH.'lib/filemanager.inc.php'); // for get_human_size()
18 require(AT_INCLUDE_PATH.'lib/file_storage.inc.php');
19
20 if (isset($_GET['submit_workspace'])) {
21         unset($_GET['folder']);
22
23         $owner_type = abs($_GET['ot']);
24
25         if ($owner_type == WORKSPACE_GROUP) {
26
27                 $parts = explode('_', $_GET['ot'], 2);
28                 if (isset($parts[1]) && $parts[1] && isset($_SESSION['groups'][$parts[1]])) {
29                         $owner_id = $parts[1];
30                 } else {
31                         $owner_type = WORKSPACE_COURSE;
32                         unset($owner_id);
33                 }
34         } else if ($owner_type == WORKSPACE_ASSIGNMENT) {
35                 $parts = explode('_', $_GET['ot'], 2);
36                 if (isset($parts[1]) && $parts[1]) {
37                         $owner_id = $parts[1];
38                 } else {
39                         $owner_type = WORKSPACE_ASSIGNMENT;
40                         unset($owner_id);
41                 }
42         } else {
43                 unset($owner_id);
44         }
45         $_REQUEST['folder'] = 0;
46 } else if (isset($_REQUEST['ot'], $_REQUEST['oid'])) {
47         $owner_type = abs($_REQUEST['ot']);
48         $owner_id   = abs($_REQUEST['oid']);
49 } else if (isset($_SESSION['fs_owner_type'], $_SESSION['fs_owner_id'], $_SESSION['fs_folder_id'])) {
50         $owner_type = abs($_SESSION['fs_owner_type']);
51         $owner_id   = abs($_SESSION['fs_owner_id']);
52 } else {
53         $owner_type = WORKSPACE_COURSE;
54 }
55
56 if (isset($_REQUEST['folder'])) {
57         $folder_id = abs($_REQUEST['folder']);
58 } else if (isset($_SESSION['fs_folder_id'])) {
59         $folder_id = abs($_SESSION['fs_folder_id']);
60 } else {
61         $folder_id = 0;
62 }
63
64 // init the owner_id if not currently set
65 if (!isset($owner_id)) {
66         if ($owner_type == WORKSPACE_COURSE) {
67                 $owner_id = $_SESSION['course_id'];
68         } else if ($owner_type == WORKSPACE_PERSONAL) {
69                 $owner_id = $_SESSION['member_id'];
70         } else if ($owner_type == WORKSPACE_GROUP) {
71                 $owner_id = $group_id;
72         }
73 }
74
75 $owner_arg_prefix = '?ot='.$owner_type.SEP.'oid='.$owner_id. SEP;
76 if (!($owner_status = fs_authenticate($owner_type, $owner_id))) {
77         $msg->addError('ACCESS_DENIED');
78         header('Location: index.php');
79         exit;
80 }
81 $_SESSION['fs_owner_type'] = $owner_type;
82 $_SESSION['fs_owner_id']   = $owner_id;
83 $_SESSION['fs_folder_id']  = $folder_id;
84
85 if (isset($_GET['submit_workspace'])) {
86         header('Location: index.php'.$owner_arg_prefix);
87         exit;
88 }
89
90 // action - Submit Assignment
91 if (isset($_GET['assignment']) && (isset($_GET['files']) || isset($_GET['folders']))) {
92         if (isset($_GET['folders'])) {
93                 $msg->addError('HAND_IN_FOLDER');
94         } else if (!isset($_GET['files'])) {
95                 $msg->addError('NO_ITEM_SELECTED');
96         } else {
97                 header('Location: assignment.php?'.$_SERVER['QUERY_STRING']);
98                 exit;
99         }
100 }
101 // action - View Revisions
102 else if (isset($_GET['revisions'], $_GET['files'])) {
103         if (is_array($_GET['files']) && (count($_GET['files']) == 1) && empty($_GET['folders'])) {
104                 $file_id = intval(current($_GET['files']));
105                 header('Location: revisions.php'.$owner_arg_prefix.'id='.$file_id);
106                 exit;
107         }
108 }
109 // action - View Comments
110 else if (isset($_GET['comments'], $_GET['files'])) {
111         if (is_array($_GET['files']) && (count($_GET['files']) == 1) && empty($_GET['folders'])) {
112                 $file_id = intval(current($_GET['files']));
113                 header('Location: comments.php'.$owner_arg_prefix.'id='.$file_id);
114                 exit;
115         }
116 }
117 // action - Edit File/Folder
118 else if (query_bit($owner_status, WORKSPACE_AUTH_WRITE) && isset($_GET['edit']) && (isset($_GET['folders']) || isset($_GET['files']))) {
119         if (is_array($_GET['files']) && (count($_GET['files']) == 1) && empty($_GET['folders'])) {
120                 $file_id = abs(current($_GET['files']));
121                 header('Location: edit.php'.$owner_arg_prefix.'id='.$file_id);
122                 exit;
123         } else if (is_array($_GET['folders']) && (count($_GET['folders']) == 1) && empty($_GET['files'])) {
124                 $folder_id = abs(current($_GET['folders']));
125                 header('Location: edit_folder.php'.$owner_arg_prefix.'id='.$folder_id);
126                 exit;
127         }
128 }
129 // action - Move Files/Folders
130 else if (query_bit($owner_status, WORKSPACE_AUTH_WRITE) && isset($_GET['move']) && (isset($_GET['folders']) || isset($_GET['files']))) {
131         header('Location: move.php'.$owner_arg_prefix.$_SERVER['QUERY_STRING']);
132         exit;
133 }
134 // action - Download Files/Folders
135 else if (isset($_GET['download']) && (isset($_GET['folders']) || isset($_GET['files']))) {
136         if (is_array($_GET['files']) && (count($_GET['files']) == 1) && empty($_GET['folders'])) {
137                 $file_id = abs(current($_GET['files']));
138                 $sql = "SELECT file_name, file_size FROM ".TABLE_PREFIX."files WHERE file_id=$file_id AND owner_type=$owner_type AND owner_id=$owner_id";
139                 $result = mysql_query($sql, $db);
140                 if ($row = mysql_fetch_assoc($result)) {
141                         $ext = fs_get_file_extension($row['file_name']);
142
143                         if (isset($mime[$ext]) && $mime[$ext][0]) {
144                                 $file_mime = $mime[$ext][0];
145                         } else {
146                                 $file_mime = 'application/octet-stream';
147                         }
148                         $file_path = fs_get_file_path($file_id) . $file_id;
149
150                         ob_end_clean();
151                         header("Content-Encoding: none");
152                         header('Content-Type: ' . $file_mime);
153                         header('Content-transfer-encoding: binary'); 
154                         header('Content-Disposition: attachment; filename="'.htmlspecialchars($row['file_name']).'"');
155                         header('Expires: 0');
156                         header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
157                         header('Pragma: public');
158                         header('Content-Length: '.$row['file_size']);
159
160                         // see the note in get.php about the use of x-Sendfile
161                         header('x-Sendfile: '.$file_path);
162                         header('x-Sendfile: ', TRUE); // if we get here then it didn't work
163
164                         @readfile($file_path);
165                         exit;
166                 }
167         } else {
168                 // zip multiple files and folders
169                 require(AT_INCLUDE_PATH . 'classes/zipfile.class.php');
170                 $zipfile =& new zipfile();
171
172                 $zip_file_name = fs_get_workspace($owner_type, $owner_id); // want the name of the workspace
173                 $zip_file_name = str_replace(" ","_",$zip_file_name );
174
175                 if (is_array($_GET['files'])) {
176                         foreach ($_GET['files'] as $file_id) {
177                                 $file_path = fs_get_file_path($file_id) . $file_id;
178                                 
179
180                                 $sql = "SELECT file_name, UNIX_TIMESTAMP(date) AS date FROM ".TABLE_PREFIX."files WHERE file_id=$file_id AND owner_type=$owner_type AND owner_id=$owner_id";
181                                 $result = mysql_query($sql, $db);
182                                 if (($row = mysql_fetch_assoc($result)) && file_exists($file_path)) {
183                                         $zipfile->add_file(file_get_contents($file_path), $row['file_name'], $row['date']);
184                                 }
185                         }
186                 }
187                 if (is_array($_GET['folders'])) {
188                         foreach($_GET['folders'] as $folder_id) {
189                                 fs_download_folder($folder_id, $zipfile, $owner_type, $owner_id);
190                                 $row['title'] = str_replace(" ","_",$row['title']  );
191                                 $zipfile->create_dir($row['title']);
192                         }
193
194                         if (count($_GET['folders']) == 1) {
195                                 // zip just one folder, use that folder's title as the zip file name
196                                 $row = fs_get_folder_by_id($_GET['folders'][0], $owner_type, $owner_id);
197                                 if ($row) {
198                                         $zip_file_name = $row['title'];
199                                         $zip_file_name = str_replace(" ","_",$zip_file_name );
200                                 }
201                         }
202                 }
203                 $zipfile->close();
204                 $zipfile->send_file($zip_file_name);
205         }
206         exit;
207
208 }
209 // action - Delete Files/Folders (pre-confirmation)
210 else if (query_bit($owner_status, WORKSPACE_AUTH_WRITE) && isset($_GET['delete']) && (isset($_GET['folders']) || isset($_GET['files']))) {
211         $hidden_vars = array();
212         $hidden_vars['folder'] = $folder_id;
213         $hidden_vars['ot']     = $owner_type;
214         $hidden_vars['oid']     = $owner_id;
215         if (isset($_GET['files'])) {
216                 $file_list_to_print = '';
217                 $files = implode(',', $_GET['files']);
218                 $hidden_vars['files'] = $files;
219                 $sql = "SELECT file_name FROM ".TABLE_PREFIX."files WHERE file_id IN ($files) AND owner_type=$owner_type AND owner_id=$owner_id ORDER BY file_name";
220                 $result = mysql_query($sql, $db);
221                 while ($row = mysql_fetch_assoc($result)) {
222                         $file_list_to_print .= '<li style="list-style: none; margin: 0px; padding: 0px 10px;"><img src="images/file_types/'.fs_get_file_type_icon($row['file_name']).'.gif" height="16" width="16" alt="" title="" /> '.htmlspecialchars($row['file_name']).'</li>';
223                 }
224                 $msg->addConfirm(array('FILE_DELETE', $file_list_to_print), $hidden_vars);
225         }
226                 
227         if (isset($_GET['folders'])) {
228                 $dir_list_to_print = '';
229                 $folders = implode(',', $_GET['folders']);
230                 $hidden_vars['folders'] = $folders;
231                 $rows = fs_get_folder_by_id($_GET['folders'], $owner_type, $owner_id);
232                 foreach ($rows as $row) {
233                         $dir_list_to_print .= '<li style="list-style: none; margin: 0px; padding: 0px 10px;"><img src="images/folder.gif" height="18" width="20" alt="" title="" /> '.htmlspecialchars($row['title']).'</li>';
234                 }
235                 $msg->addConfirm(array('DIR_DELETE', $dir_list_to_print), $hidden_vars);
236         }
237
238         require(AT_INCLUDE_PATH.'header.inc.php');
239         $msg->printConfirm();
240         require(AT_INCLUDE_PATH.'footer.inc.php');
241         exit;
242
243 }
244 // action - Confirm Delete Files/Folders
245 else if (query_bit($owner_status, WORKSPACE_AUTH_WRITE) && isset($_POST['submit_yes'])) {
246
247         // handle the delete
248         if (isset($_POST['files'])) {
249                 $files = explode(',', $_POST['files']);
250         }
251         if (isset($_POST['folders'])) {
252                 $folders = explode(',', $_POST['folders']);
253         }
254         if (isset($files)) {
255                 foreach ($files as $file) {
256                         fs_delete_file($file, $owner_type, $owner_id);
257                 }
258                 $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
259         }
260
261         if (isset($folders)) {
262                 foreach ($folders as $folder) {
263                         fs_delete_folder($folder, $owner_type, $owner_id);
264                 }
265                 $msg->addFeedback('DIR_DELETED');
266         }
267
268         header('Location: index.php'.$owner_arg_prefix.'folder='.abs($_POST['folder']));
269         exit;
270 }
271 // action - Cancel Delete
272 else if (query_bit($owner_status, WORKSPACE_AUTH_WRITE) && isset($_POST['submit_no'])) {
273         $msg->addFeedback('CANCELLED');
274         header('Location: index.php'.$owner_arg_prefix.'folder='.abs($_POST['folder']));
275         exit;
276
277 // action - Create Folder
278 } else if (query_bit($owner_status, WORKSPACE_AUTH_WRITE) && isset($_POST['create_folder'])) {
279         // create a new folder
280         $_POST['new_folder_name'] = trim($_POST['new_folder_name']);
281
282         if (!$_POST['new_folder_name']) {
283                 $msg->addError(array('EMPTY_FIELDS', _AT('name')));
284         }
285
286         if (!$msg->containsErrors()) {
287                 $_POST['new_folder_name'] = $addslashes($_POST['new_folder_name']);
288
289                 $parent_folder_id = abs($_POST['folder']);
290
291                 $sql = "INSERT INTO ".TABLE_PREFIX."folders VALUES (NULL, $parent_folder_id, $owner_type, $owner_id, '$_POST[new_folder_name]')";
292                 $result = mysql_query($sql, $db);
293                 $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
294                 header('Location: index.php'.$owner_arg_prefix.'folder='.$parent_folder_id);
295                 exit;
296         }
297 }
298 // action - Upload
299 else if (query_bit($owner_status, WORKSPACE_AUTH_WRITE) && isset($_POST['upload'])) {
300         // handle the file upload
301         $_POST['comments'] = trim($_POST['comments']);
302
303         $parent_folder_id = abs($_POST['folder']);
304
305         if ($_FILES['file']['error'] == UPLOAD_ERR_INI_SIZE) {
306                 $msg->addError(array('FILE_TOO_BIG', get_human_size(megabytes_to_bytes(substr(ini_get('upload_max_filesize'), 0, -1)))));
307
308         } else if (!isset($_FILES['file']['name']) || ($_FILES['file']['error'] == UPLOAD_ERR_NO_FILE) || ($_FILES['file']['size'] == 0)) {
309                 $msg->addError('FILE_NOT_SELECTED');
310
311         } else if ($_FILES['file']['error'] || !is_uploaded_file($_FILES['file']['tmp_name'])) {
312                 $msg->addError('FILE_NOT_SAVED');
313         }
314
315         // check that we own this folder
316         if ($parent_folder_id) {
317                 $sql = "SELECT folder_id FROM ".TABLE_PREFIX."folders WHERE folder_id=$parent_folder_id AND owner_type=$owner_type AND owner_id=$owner_id";
318                 $result = mysql_query($sql, $db);
319                 if (!$row = mysql_fetch_assoc($result)) {
320                         $msg->addError('ACCESS_DENIED');
321                         header('Location: index.php');
322                         exit;
323                 }
324         }
325
326         if (!$msg->containsErrors()) {
327                 $_POST['description'] = $addslashes(trim($_POST['description']));
328                 $_FILES['file']['name'] = addslashes($_FILES['file']['name']);
329
330                 if ($_POST['comments']) {
331                         $num_comments = 1;
332                 } else {
333                         $num_comments = 0;
334                 }
335
336                 $sql = "INSERT INTO ".TABLE_PREFIX."files VALUES (NULL, $owner_type, $owner_id, $_SESSION[member_id], $parent_folder_id, 0, NOW(), $num_comments, 0, '{$_FILES['file']['name']}', {$_FILES['file']['size']}, '$_POST[description]')";
337                 $result = mysql_query($sql, $db);
338
339                 if ($result && ($file_id = mysql_insert_id($db))) {
340                         $path = fs_get_file_path($file_id);
341                         move_uploaded_file($_FILES['file']['tmp_name'], $path . $file_id);
342
343                         // check if this file name already exists
344                         $sql = "SELECT file_id, num_revisions FROM ".TABLE_PREFIX."files WHERE owner_type=$owner_type AND owner_id=$owner_id AND folder_id=$parent_folder_id AND file_id<>$file_id AND file_name='{$_FILES['file']['name']}' AND parent_file_id=0 ORDER BY file_id DESC LIMIT 1";
345                         $result = mysql_query($sql, $db);
346                         if ($row = mysql_fetch_assoc($result)) {
347                                 if ($_config['fs_versioning']) {
348                                         $sql = "UPDATE ".TABLE_PREFIX."files SET parent_file_id=$file_id, date=date WHERE file_id=$row[file_id]";
349                                         $result = mysql_query($sql, $db);
350
351                                         $sql = "UPDATE ".TABLE_PREFIX."files SET num_revisions=$row[num_revisions]+1, date=date WHERE file_id=$file_id";
352                                         $result = mysql_query($sql, $db);
353                                 } else {
354                                         fs_delete_file($row['file_id'], $owner_type, $owner_id);
355                                 }
356                         }
357
358                         $msg->addFeedback('FILE_UPLOADED');
359                 } else {
360                         $msg->addError('FILE_NOT_SAVED');
361                 }
362         }
363         header('Location: index.php'.$owner_arg_prefix.'folder='.$parent_folder_id);
364         exit;
365 } else if ((isset($_GET['delete']) || isset($_GET['download']) || isset($_GET['move']) || isset($_GET['edit']) || isset($_GET['assignment'])) && !isset($_GET['files']) && !isset($_GET['folders'])) {
366         $msg->addError('NO_ITEM_SELECTED');
367 }
368
369 if (query_bit($owner_status, WORKSPACE_AUTH_WRITE)) {
370         $onload = 'hideform(\'upload\'); hideform(\'c_folder\');';
371 }
372
373 require(AT_INCLUDE_PATH.'header.inc.php');
374
375 $orders = array('asc' => 'desc', 'desc' => 'asc');
376 $cols   = array('file_name' => 1, 'file_size' => 1, 'date' => 1);
377
378 if (isset($_GET['asc'])) {
379         $order = 'asc';
380         $col   = isset($cols[$_GET['asc']]) ? $_GET['asc'] : 'file_name';
381 } else if (isset($_GET['desc'])) {
382         $order = 'desc';
383         $col   = isset($cols[$_GET['desc']]) ? $_GET['desc'] : 'file_name';
384 } else {
385         // no order set
386         $order = 'asc';
387         $col   = 'file_name';
388 }
389
390 $folder_path = fs_get_folder_path($folder_id, $owner_type, $owner_id);
391
392 $folders = fs_get_folder_by_pid($folder_id, $owner_type, $owner_id);
393
394 $files = array();
395 $sql = "SELECT * FROM ".TABLE_PREFIX."files WHERE folder_id=$folder_id AND owner_type=$owner_type AND owner_id=$owner_id AND parent_file_id=0 ORDER BY $col $order";
396 $result = mysql_query($sql, $db);
397
398 while ($row = mysql_fetch_assoc($result)) {
399         $files[] = $row;
400 }
401
402 ?>
403
404 <?php if (query_bit($owner_status, WORKSPACE_AUTH_WRITE)): ?>
405         <form method="post" action="<?php echo $_SERVER['PHP_SELF'].$owner_arg_prefix; ?>" enctype="multipart/form-data" name="form0">
406         <input type="hidden" name="folder" value="<?php echo $folder_id; ?>" />
407         <div style="margin: 0px auto; width: 70%">
408                 <div class="input-form" style="width: 48%; float: right">
409                         <div class="row">
410                                 <h3><a href="file_storage/index.php" onclick="javascript:toggleform('c_folder'); return false;" style="font-family: Helevetica, Arial, sans-serif;" onmouseover="this.style.cursor='pointer'"><?php echo _AT('create_folder'); ?></a></h3>
411                         </div>
412                         <div  id="c_folder">
413                                 <div class="row">
414                                         <div class="required" title="<?php echo _AT('required_field'); ?>">*</div><label for="fname"><?php echo _AT('name'); ?></label><br />
415                                         <input type="text" id="fname" name="new_folder_name" size="20" />
416                                 </div>
417                                 <div class="row buttons">
418                                         <input type="submit" name="create_folder" value="<?php echo _AT('create'); ?>" />
419                                 </div>
420                         </div>
421                 </div>
422                 <div class="input-form" style="float: left; width: 48%">
423                         <div class="row">
424                                 <h3><a href="file_storage/index.php" onclick="javascript:toggleform('upload'); return false;" style="font-family: Helevetica, Arial, sans-serif;" onmouseover="this.style.cursor='pointer'"><?php echo _AT('new_file'); ?></a></h3>
425                         </div>
426                         <div id="upload">
427                                 <div class="row">
428                                         <div class="required" title="<?php echo _AT('required_field'); ?>">*</div><label for="file"><?php echo _AT('upload_file'); ?></label><br />
429                                         <input type="file" name="file" id="file" />
430                                         <br /><?php echo _AT('or'); ?> <a href="file_storage/new.php<?php echo $owner_arg_prefix; ?>folder=<?php echo $folder_id; ?>"><?php echo _AT('file_manager_new'); ?></a>
431                                 </div>
432                                 <div class="row">
433                                         <label for="description"><?php echo _AT('description'); ?></label><br />
434                                         <textarea name="description" id="description" rows="1" cols="20"></textarea>
435                                 </div>
436                                 <div class="row buttons">
437                                         <input type="submit" name="upload" value="<?php echo _AT('upload'); ?>" />
438                                 </div>
439                         </div>
440                 </div>
441         </div>
442         </form>
443
444         <div style="clear: both;"></div>
445 <?php endif; ?>
446
447 <?php
448 if ($_SESSION['groups']) {
449         $file_storage_groups = array();
450         $groups_list = implode(',',$_SESSION['groups']);
451         $sql = "SELECT G.type_id, G.title, G.group_id FROM ".TABLE_PREFIX."file_storage_groups FS INNER JOIN ".TABLE_PREFIX."groups G USING (group_id) WHERE FS.group_id IN ($groups_list) ORDER BY G.type_id, G.title";
452         $result = mysql_query($sql, $db);
453         while ($row = mysql_fetch_assoc($result)) {
454                 $file_storage_groups[] = $row;
455         }
456 }
457
458 if (authenticate(AT_PRIV_ASSIGNMENTS, AT_PRIV_RETURN)) {
459         $file_storage_assignments = array();
460         $sql = "SELECT * FROM ".TABLE_PREFIX."assignments WHERE course_id=$_SESSION[course_id] ORDER BY title";
461         $result = mysql_query($sql, $db);
462         while ($row = mysql_fetch_assoc($result)) {
463                 $file_storage_assignments[] = $row;
464         }
465 }
466 ?>
467
468 <form method="get" action="<?php echo $_SERVER['PHP_SELF']; ?>" name="form">
469 <input type="hidden" name="folder" value="<?php echo $folder_id; ?>" />
470 <input type="hidden" name="oid" value="<?php echo $owner_id; ?>" />
471 <table class="data">
472 <colgroup>
473         <?php if ($col == 'file_name'): ?>
474                 <col />
475                 <col class="sort" />
476                 <col span="5" />
477         <?php elseif($col == 'file_size'): ?>
478                 <col span="5" />
479                 <col class="sort" />
480                 <col />
481         <?php elseif($col == 'date'): ?>
482                 <col span="6" />
483                 <col class="sort" />
484         <?php endif; ?>
485 </colgroup>
486 <thead>
487 <tr>
488         <td colspan="7">
489                 <?php echo _AT('workspace'); ?> 
490                 <select name="ot" id="ot">
491                         <option value="1" <?php if ($owner_type == WORKSPACE_COURSE) { echo 'selected="selected"'; } ?>><?php echo _AT('course_files'); ?></option>
492                         <?php if ($_SESSION['member_id']): ?>
493                                 <option value="2" <?php if ($owner_type == WORKSPACE_PERSONAL) { echo 'selected="selected"'; } ?>><?php echo _AT('my_files'); ?></option>
494                         <?php endif; ?>
495                         <?php if ($file_storage_groups): ?>
496                                 <optgroup label="<?php echo _AT('groups'); ?>">
497                                         <?php foreach ($file_storage_groups as $group): ?>
498                                                 <option value="<?php echo WORKSPACE_GROUP; ?>_<?php echo $group['group_id']; ?>" <?php if ($owner_type == WORKSPACE_GROUP && $owner_id == $group['group_id']) { echo 'selected="selected"'; } ?>><?php echo $group['title']; ?></option>
499                                         <?php endforeach; ?>
500                                 </optgroup>
501                         <?php endif; ?>
502                         <?php if (authenticate(AT_PRIV_ASSIGNMENTS, AT_PRIV_RETURN) && count($file_storage_assignments) != 0) : ?>
503                                 <optgroup label="<?php echo _AT('assignments'); ?>">
504                                         <?php foreach ($file_storage_assignments as $assignment): ?>
505                                                 <option value="<?php echo WORKSPACE_ASSIGNMENT; ?>_<?php echo $assignment['assignment_id']; ?>" <?php if ($owner_type == WORKSPACE_ASSIGNMENT && $owner_id == $assignment['assignment_id']) { echo 'selected="selected"'; } ?>><?php echo $assignment['title']; ?></option>
506                                         <?php endforeach; ?>
507                                 </optgroup>
508                         <?php endif; ?>
509                 </select>
510                 <input type="submit" name="submit_workspace" value="<?php echo _AT('go'); ?>" class="button" />
511
512                 <br />
513                 <?php echo _AT('current_path'); ?>
514                         <a href="<?php echo $_SERVER['PHP_SELF'].$owner_arg_prefix; ?>folder=0"><?php echo _AT('home'); ?></a>
515                 <?php foreach ($folder_path as $folder_info): ?>
516                         <?php if ($folder_info['folder_id'] == $folder_id): ?>
517                                 » <?php echo htmlspecialchars($folder_info['title']); ?>
518                                 <?php $parent_folder_id = $folder_info['parent_folder_id']; ?>
519                         <?php else: ?>
520                                 » <a href="<?php echo $_SERVER['PHP_SELF'].$owner_arg_prefix; ?>folder=<?php echo $folder_info['folder_id']; ?>"><?php echo htmlspecialchars($folder_info['title']); ?></a>
521                         <?php endif; ?>
522                 <?php endforeach; ?>
523         </td>
524 </tr>
525 <tr>
526
527         <th align="left" width="10"><input type="checkbox" value="<?php echo _AT('select_all'); ?>" id="all" title="<?php echo _AT('select_all'); ?>" name="selectall" onclick="CheckAll();" /></th>
528         <th scope="col"><a href="<?php echo $_SERVER['PHP_SELF'] . $owner_arg_prefix . 'folder='.$folder_id.SEP.$orders[$order]; ?>=file_name"><?php echo _AT('file');      ?></a></th>
529         <th scope="col"><?php echo _AT('author');    ?></th>
530         <th scope="col"><?php if ($_config['fs_versioning']): ?><?php echo _AT('revisions'); ?><?php endif; ?></th>
531         <th scope="col"><?php echo _AT('comments');  ?></th>
532         <th scope="col"><a href="<?php echo $_SERVER['PHP_SELF'] . $owner_arg_prefix . 'folder='.$folder_id.SEP.$orders[$order]; ?>=file_size"><?php echo _AT('size'); ?></a></th>
533         <th scope="col"><a href="<?php echo $_SERVER['PHP_SELF'] . $owner_arg_prefix . 'folder='.$folder_id.SEP.$orders[$order]; ?>=date"><?php echo _AT('date'); ?></a></th>
534 </tr>
535
536 </thead>
537 <tfoot>
538 <tr>
539         <td colspan="7">
540                 <input type="submit" name="download" value="<?php echo _AT('download'); ?>" />
541                 <?php if (query_bit($owner_status, WORKSPACE_AUTH_WRITE)): ?>
542                         <?php if (($owner_type != WORKSPACE_COURSE) && !(($owner_type == WORKSPACE_PERSONAL) && ($_SESSION['is_admin'] || authenticate(AT_PRIV_GROUPS,true))) ): ?>
543                                 <input type="submit" name="assignment" value="<?php echo _AT('hand_in'); ?>" />
544                         <?php endif; ?>
545                         <input type="submit" name="edit" value="<?php echo _AT('edit'); ?>" />
546                         <input type="submit" name="move" value="<?php echo _AT('move'); ?>" />
547                         <input type="submit" name="delete" value="<?php echo _AT('delete'); ?>" />
548                 <?php endif; ?>
549         </td>
550 </tr>
551 </tfoot>
552 <tbody>
553 <?php if ($folder_id): ?>
554         <tr>
555                 <td colspan="7"><a href="<?php echo $_SERVER['PHP_SELF'].$owner_arg_prefix.'folder='.intval($folder_path[count($folder_path)-1]['parent_folder_id']); ?>"><img src="images/arrowicon.gif" border="0" height="" width="" alt="" /> <?php echo _AT('back'); ?></a></td>
556         </tr>
557 <?php endif; ?>
558 <?php if ($folders || $files): ?>
559         <?php foreach ($folders as $folder_info): ?>
560                 <tr onmousedown="document.form['f<?php echo $folder_info['folder_id']; ?>'].checked = !document.form['f<?php echo $folder_info['folder_id']; ?>'].checked; rowselectbox(this, document.form['f<?php echo $folder_info['folder_id']; ?>'].checked, 'checkbuttons(false)');" id="r_<?php echo $folder_info['folder_id']; ?>_1">
561                         <td width="10"><input type="checkbox" name="folders[]" value="<?php echo $folder_info['folder_id']; ?>" id="f<?php echo $folder_info['folder_id']; ?>" onmouseup="this.checked=!this.checked" /></td>
562                         <td><img src="images/folder.gif" height="18" width="20" alt="" /> <a href="<?php echo $_SERVER['PHP_SELF'].$owner_arg_prefix; ?>folder=<?php echo $folder_info['folder_id']; ?>"><?php echo htmlspecialchars($folder_info['title']); ?></a></td>
563                         <td>&nbsp;</td>
564                         <td>&nbsp;</td>
565                         <td>&nbsp;</td>
566                         <td>&nbsp;</td>
567                         <td>&nbsp;</td>
568                 </tr>
569         <?php endforeach; ?>
570         <?php foreach ($files as $file_info): ?>
571                 <tr onmousedown="document.form['r<?php echo $file_info['file_id']; ?>'].checked = !document.form['r<?php echo $file_info['file_id']; ?>'].checked; rowselectbox(this, document.form['r<?php echo $file_info['file_id']; ?>'].checked, 'checkbuttons(false)');" id="r_<?php echo $file_info['file_id']; ?>_0">
572                         <td valign="top" width="10"><input type="checkbox" name="files[]" value="<?php echo $file_info['file_id']; ?>" id="r<?php echo $file_info['file_id']; ?>" onmouseup="this.checked=!this.checked" /></td>
573                         <td valign="top">
574                                 <img src="images/file_types/<?php echo fs_get_file_type_icon($file_info['file_name']); ?>.gif" height="16" width="16" alt="" title="" /> <?php echo htmlspecialchars($file_info['file_name']); ?>
575                                 <?php if ($file_info['description']): ?>
576                                         <p class="fm-desc"><?php echo htmlspecialchars($file_info['description']); ?></p>
577                                 <?php endif; ?>
578                         </td>
579                         <td valign="top"><?php echo get_display_name($file_info['member_id']); ?></td>
580                         <td valign="top">
581                                 <?php if ($_config['fs_versioning']): ?>
582                                         <?php if ($file_info['num_revisions']): 
583                                                 if ($file_info['num_revisions'] == 1) {
584                                                         $lang_var = 'fs_revision';
585                                                 } else {
586                                                         $lang_var = 'fs_revisions';
587                                                 }
588                                                 ?>
589                                                 
590                                                 <a href="<?php echo 'file_storage/revisions.php'.$owner_arg_prefix.'id='.$file_info['file_id']; ?>"><?php echo _AT($lang_var, $file_info['num_revisions']); ?></a>
591                                         <?php else: ?>
592                                                 -
593                                         <?php endif; ?>
594                                 <?php endif; ?>
595                         </td>
596                         <td valign="top">
597                         <?php 
598                         if ($file_info['num_comments'] == 1) {
599                                 $lang_var = 'fs_comment';
600                         } else {
601                                 $lang_var = 'fs_comments';
602                         }
603                         ?>
604                         <a href="<?php echo 'file_storage/comments.php'.$owner_arg_prefix.'id='.$file_info['file_id']; ?>"><?php echo _AT($lang_var, $file_info['num_comments']); ?></a></td>
605                         <td align="right" valign="top"><?php echo get_human_size($file_info['file_size']); ?></td>
606                         <td align="right" valign="top"><?php echo AT_date(_AT('filemanager_date_format'), $file_info['date'], AT_DATE_MYSQL_DATETIME); ?></td>
607                 </tr>
608         <?php endforeach; ?>
609 <?php else: ?>
610         <tr>
611                 <td colspan="7"><?php echo _AT('none_found'); ?></td>
612         </tr>
613 <?php endif; ?>
614 </tbody>
615 </table>
616 </form>
617
618 <script type="text/javascript">
619 // <!--
620 function checkbuttons(state) {
621         document.form.selectall.checked = state;
622
623         var num_files_checked = 0;
624         var num_folders_checked = 0;
625         for (var i=0;i<document.form.elements.length;i++) {
626                 var e = document.form.elements[i];
627                 if ((e.name == 'folders[]') && (e.type=='checkbox') && e.checked) {
628                         num_folders_checked++;
629                 } else if ((e.name == 'files[]') && (e.type=='checkbox') && e.checked) {
630                         num_files_checked++;
631                 }
632         }
633         if (num_files_checked + num_folders_checked > 1) {
634                 if (document.form.edit)
635                         document.form.edit.disabled = true;
636         } else {
637                 if (document.form.edit)
638                         document.form.edit.disabled = false;
639         }
640 }
641 function CheckAll() {
642         var state = document.form.selectall.checked;
643         for (var i=0;i<document.form.elements.length;i++)       {
644                 var e = document.form.elements[i];
645                 if ((e.name == 'folders[]') && (e.type=='checkbox')) {
646                         e.checked = state;
647                         rowselectbox(document.getElementById('r_' + e.value + '_1'), state, 'checkbuttons(' + state + ')');
648                 } else if ((e.name == 'files[]') && (e.type=='checkbox')) {
649                         e.checked = state;
650                         rowselectbox(document.getElementById('r_' + e.value + '_0'), state, 'checkbuttons(' + state + ')');
651                 }
652         }
653 }
654
655 function hideform(id) {
656         document.getElementById(id).style.display='none';
657 }
658
659 function toggleform(id) {
660         if (document.getElementById(id).style.display == "none") {
661                 //show
662                 document.getElementById(id).style.display='';   
663
664                 if (id == "c_folder") {
665                         document.form0.new_folder_name.focus();
666                 } else if (id == "upload") {
667                         document.form0.file.focus();
668                 }
669
670         } else {
671                 //hide
672                 document.getElementById(id).style.display='none';
673         }
674 }
675
676 // -->
677 </script>
678
679 <?php require(AT_INCLUDE_PATH.'footer.inc.php'); ?>