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 /****************************************************************/
14 define('AT_INCLUDE_PATH', '../../../include/');
15 require(AT_INCLUDE_PATH.'vitals.inc.php');
16 require_once(AT_INCLUDE_PATH.'../mods/_core/file_manager/filemanager.inc.php');
18 if (!authenticate(AT_PRIV_FILES,AT_PRIV_RETURN)) {
19 authenticate(AT_PRIV_CONTENT);
22 $_SESSION['done'] = 1;
23 $popup = $_REQUEST['popup'];
24 $framed = $_REQUEST['framed'];
25 $alter = $_REQUEST['alter'];
27 //echo $_REQUEST['cid'];
28 //echo $_REQUEST['tab'];
32 /* get this courses MaxQuota and MaxFileSize: */
33 $sql = "SELECT max_quota, max_file_size FROM ".TABLE_PREFIX."courses WHERE course_id=$_SESSION[course_id]";
34 $result = mysql_query($sql, $db);
35 $row = mysql_fetch_array($result);
36 $my_MaxCourseSize = $row['max_quota'];
37 $my_MaxFileSize = $row['max_file_size'];
39 if ($my_MaxCourseSize == AT_COURSESIZE_DEFAULT) {
40 $my_MaxCourseSize = $MaxCourseSize;
42 if ($my_MaxFileSize == AT_FILESIZE_DEFAULT) {
43 $my_MaxFileSize = $MaxFileSize;
44 } else if ($my_MaxFileSize == AT_FILESIZE_SYSTEM_MAX) {
45 $my_MaxFileSize = megabytes_to_bytes(substr(ini_get('upload_max_filesize'), 0, -1));
48 $path = AT_CONTENT_DIR . $_SESSION['course_id'].'/'.$_POST['pathext'];
50 if (isset($_POST['submit'])) {
52 $_FILES['uploadedfile'] = $_FILES['file'];
54 if($_FILES['uploadedfile']['name']) {
56 $_FILES['uploadedfile']['name'] = trim($_FILES['uploadedfile']['name']);
57 $_FILES['uploadedfile']['name'] = str_replace(' ', '_', $_FILES['uploadedfile']['name']);
59 $path_parts = pathinfo($_FILES['uploadedfile']['name']);
60 $ext = $path_parts['extension'];
62 /* check if this file extension is allowed: */
63 /* $IllegalExtentions is defined in ./include/config.inc.php */
64 if (in_array($ext, $IllegalExtentions)) {
65 $errors = array('FILE_ILLEGAL', $ext);
66 $msg->addError($errors);
67 handleAjaxUpload(500);
68 header('Location: index.php?pathext='.$_POST['pathext'].SEP. 'framed='.$framed.SEP.'cp='.$_GET['cp'].SEP.'pid='.$_GET['pid'].SEP.'cid='.$_GET['cid'].SEP.'a_type='.$_GET['a_type']);
72 /* also have to handle the 'application/x-zip-compressed' case */
73 if ( ($_FILES['uploadedfile']['type'] == 'application/x-zip-compressed')
74 || ($_FILES['uploadedfile']['type'] == 'application/zip')
75 || ($_FILES['uploadedfile']['type'] == 'application/x-zip')){
80 /* anything else should be okay, since we're on *nix.. hopefully */
81 $_FILES['uploadedfile']['name'] = str_replace(array(' ', ',', '/', '\\', ':', ';', '*', '?', '"', '<', '>', '|', '\''), '', $_FILES['uploadedfile']['name']);
83 /* if the file size is within allowed limits */
84 if( ($_FILES['uploadedfile']['size'] > 0) && ($_FILES['uploadedfile']['size'] <= $my_MaxFileSize) ) {
86 /* if adding the file will not exceed the maximum allowed total */
87 $course_total = dirsize($path);
89 if ((($course_total + $_FILES['uploadedfile']['size']) <= ($my_MaxCourseSize + $MaxCourseFloat)) || ($my_MaxCourseSize == AT_COURSESIZE_UNLIMITED)) {
91 /* check if this file exists first */
92 if (file_exists($path.$_FILES['uploadedfile']['name'])) {
93 /* this file already exists, so we want to prompt for override */
95 /* save it somewhere else, temporarily first */
96 /* file_name.time ? */
97 $_FILES['uploadedfile']['name'] = substr(time(), -4).'.'.$_FILES['uploadedfile']['name'];
99 $f = array('FILE_EXISTS',
100 substr($_FILES['uploadedfile']['name'], 5),
101 $_FILES['uploadedfile']['name'],
105 $msg->addFeedback($f);
108 /* copy the file in the directory */
109 $result = move_uploaded_file( $_FILES['uploadedfile']['tmp_name'], $path.$_FILES['uploadedfile']['name'] );
112 require(AT_INCLUDE_PATH.'header.inc.php');
113 $msg->printErrors('FILE_NOT_SAVED');
114 echo '<a href="../mods/_core/file_manager/index.php?pathext=' . $_POST['pathext'] . SEP . 'popup=' . $_GET['popup'] . SEP. 'framed='.$framed.SEP.'cp='.$_GET['cp'].SEP.'pid='.$_GET['pid'].SEP.'cid='.$_GET['cid'].SEP.'a_type='.$_GET['a_type'].'">' . _AT('back') . '</a>';
115 require(AT_INCLUDE_PATH.'footer.inc.php');
119 $f = array('FILE_UPLOADED_ZIP',
120 urlencode($_POST['pathext']),
121 urlencode($_FILES['uploadedfile']['name']),
124 $msg->addFeedback($f);
125 handleAjaxUpload(200);
127 header('Location: '.$_base_href.'editor/edit_content.php?cid='.$_REQUEST['cid'].SEP . 'pathext='.$_POST['pathext'].SEP. 'popup='.$_GET['popup'].SEP. 'tab='.$_REQUEST['tab']);
129 header('Location: index.php?pathext=' . $_POST['pathext'] . SEP . 'popup=' . $_GET['popup'].SEP. 'framed='.$framed.SEP.'cp='.$_GET['cp'].SEP.'pid='.$_GET['pid'].SEP.'cid='.$_GET['cid'].SEP.'a_type='.$_GET['a_type']);
133 // uploading an alternative content object
134 if ($_GET['a_type'] > 0) {
135 header('Location: index.php?pathext=' . $_POST['pathext'] . SEP . 'popup=' . $_GET['popup'].SEP. 'framed='.$framed.SEP.'cp='.$_GET['cp'].SEP.'pid='.$_GET['pid'].SEP.'cid='.$_GET['cid'].SEP.'a_type='.$_GET['a_type'].SEP.'uploadfile='.urlencode($_FILES['uploadedfile']['name']));
138 $msg->addFeedback('FILE_UPLOADED');
139 handleAjaxUpload(200);
142 header('Location: '.$_base_href.'editor/edit_content.php?cid='.$_REQUEST['cid'].SEP . 'pathext='.$_POST['pathext'].SEP. 'popup='.$_GET['popup'].SEP. 'tab='.$_REQUEST['tab']);
144 header('Location: index.php?pathext=' . $_POST['pathext'] . SEP . 'popup=' . $_GET['popup'].SEP. 'framed='.$framed.SEP.'cp='.$_GET['cp'].SEP.'pid='.$_GET['pid'].SEP.'cid='.$_GET['cid'].SEP.'a_type='.$_GET['a_type']);
149 $msg->addError(array('MAX_STORAGE_EXCEEDED', get_human_size($my_MaxCourseSize)));
150 handleAjaxUpload(500);
152 header('Location: '.$_base_href.'editor/edit_content.php?cid='.$_REQUEST['cid'].SEP . 'pathext='.$_POST['pathext'].SEP. 'popup='.$_GET['popup'].SEP. 'tab='.$_REQUEST['tab']);
154 header('Location: index.php?pathext=' . $_POST['pathext'] . SEP . 'popup=' . $_GET['popup'].SEP. 'framed='.$framed.SEP.'cp='.$_GET['cp'].SEP.'pid='.$_GET['pid'].SEP.'cid='.$_GET['cid'].SEP.'a_type='.$_GET['a_type']);
159 $msg->addError(array('FILE_TOO_BIG', get_human_size($my_MaxFileSize)));
160 handleAjaxUpload(500);
162 header('Location: '.$_base_href.'editor/edit_content.php?cid='.$_REQUEST['cid'].SEP . 'pathext='.$_POST['pathext'].SEP. 'popup='.$_GET['popup'].SEP. 'tab='.$_REQUEST['tab']);
164 header('Location: index.php?pathext=' . $_POST['pathext'] . SEP . 'popup=' . $_GET['popup'].SEP. 'framed='.$framed.SEP.'cp='.$_GET['cp'].SEP.'pid='.$_GET['pid'].SEP.'cid='.$_GET['cid'].SEP.'a_type='.$_GET['a_type']);
169 $msg->addError('FILE_NOT_SELECTED');
170 handleAjaxUpload(500);
172 header('Location: '.$_base_href.'editor/edit_content.php?cid='.$_REQUEST['cid'].SEP . 'pathext='.$_POST['pathext'].SEP. 'popup='.$_GET['popup'].SEP. 'tab='.$_REQUEST['tab']);
174 header('Location: index.php?pathext=' . $_POST['pathext'] . SEP . 'popup=' . $_GET['popup'].SEP. 'framed='.$framed.SEP.'cp='.$_GET['cp'].SEP.'pid='.$_GET['pid'].SEP.'cid='.$_GET['cid'].SEP.'a_type='.$_GET['a_type']);