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 define('TR_INCLUDE_PATH', '../include/');
14 require_once(TR_INCLUDE_PATH.'vitals.inc.php');
15 require_once(TR_INCLUDE_PATH.'classes/DAO/CoursesDAO.class.php');
16 require_once(TR_INCLUDE_PATH.'classes/FileUtility.class.php');
19 Utility::authenticate(TR_PRIV_ISAUTHOR_OF_CURRENT_COURSE);
20 $coursesDAO = new CoursesDAO();
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 $row = $coursesDAO->get($_course_id);
34 $my_MaxCourseSize = $row['max_quota'];
35 $my_MaxFileSize = $row['max_file_size'];
37 if ($my_MaxCourseSize != TR_COURSESIZE_UNLIMITED) $my_MaxCourseSize = $MaxCourseSize;
38 $my_MaxFileSize = FileUtility::megabytes_to_bytes(substr(ini_get('upload_max_filesize'), 0, -1));
40 // if ($my_MaxCourseSize == TR_COURSESIZE_DEFAULT) {
41 // $my_MaxCourseSize = $MaxCourseSize;
43 // if ($my_MaxFileSize == TR_FILESIZE_DEFAULT) {
44 // $my_MaxFileSize = $MaxFileSize;
45 // } else if ($my_MaxFileSize == TR_FILESIZE_SYSTEM_MAX) {
46 // $my_MaxFileSize = megabytes_to_bytes(substr(ini_get('upload_max_filesize'), 0, -1));
49 $path = TR_CONTENT_DIR . $_course_id.'/'.$_POST['pathext'];
51 if (isset($_POST['submit'])) {
53 $_FILES['uploadedfile'] = $_FILES['file'];
55 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'];
61 /* check if this file extension is allowed: */
62 /* $IllegalExtentions is defined in ./include/config.inc.php */
63 if (in_array($ext, $IllegalExtentions)) {
64 $errors = array('FILE_ILLEGAL', $ext);
65 $msg->addError($errors);
66 FileUtility::handleAjaxUpload(500);
67 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'].SEP.'_course_id='.$_course_id);
71 /* also have to handle the 'application/x-zip-compressed' case */
72 if ( ($_FILES['uploadedfile']['type'] == 'application/x-zip-compressed')
73 || ($_FILES['uploadedfile']['type'] == 'application/zip')
74 || ($_FILES['uploadedfile']['type'] == 'application/x-zip')){
79 /* anything else should be okay, since we're on *nix.. hopefully */
80 $_FILES['uploadedfile']['name'] = str_replace(array(' ', '/', '\\', ':', '*', '?', '"', '<', '>', '|', '\''), '', $_FILES['uploadedfile']['name']);
82 /* if the file size is within allowed limits */
83 if( ($_FILES['uploadedfile']['size'] > 0) && ($_FILES['uploadedfile']['size'] <= $my_MaxFileSize) ) {
85 /* if adding the file will not exceed the maximum allowed total */
86 $course_total = FileUtility::dirsize($path);
88 if ((($course_total + $_FILES['uploadedfile']['size']) <= $my_MaxCourseSize) || ($my_MaxCourseSize == TR_COURSESIZE_UNLIMITED)) {
90 /* check if this file exists first */
91 if (file_exists($path.$_FILES['uploadedfile']['name'])) {
92 /* this file already exists, so we want to prompt for override */
94 /* save it somewhere else, temporarily first */
95 /* file_name.time ? */
96 $_FILES['uploadedfile']['name'] = substr(time(), -4).'.'.$_FILES['uploadedfile']['name'];
98 $f = array('FILE_EXISTS',
99 substr($_FILES['uploadedfile']['name'], 5));
100 $msg->addFeedback($f);
103 /* copy the file in the directory */
104 $result = move_uploaded_file( $_FILES['uploadedfile']['tmp_name'], $path.$_FILES['uploadedfile']['name'] );
107 require(TR_INCLUDE_PATH.'header.inc.php');
108 $msg->printErrors('FILE_NOT_SAVED');
109 echo '<a href="../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'].SEP.'_course_id='.$_course_id.'">' . _AT('back') . '</a>';
110 require(TR_INCLUDE_PATH.'footer.inc.php');
114 $f = array('FILE_UPLOADED_ZIP',
115 urlencode($_POST['pathext']),
116 urlencode($_FILES['uploadedfile']['name']),
120 $msg->addFeedback($f);
121 FileUtility::handleAjaxUpload(200);
123 header('Location: '.$_base_href.'editor/edit_content.php?cid='.$_REQUEST['cid'].SEP . 'pathext='.$_POST['pathext'].SEP. 'popup='.$_GET['popup'].SEP. 'tab='.$_REQUEST['tab'].SEP.'_course_id='.$_course_id);
125 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.'_course_id='.$_course_id);
129 // uploading an alternative content object
130 if ($_GET['a_type'] > 0) {
131 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']).SEP.'_course_id='.$_course_id);
134 $msg->addFeedback('FILE_UPLOADED');
135 FileUtility::handleAjaxUpload(200);
138 header('Location: '.$_base_href.'editor/edit_content.php?cid='.$_REQUEST['cid'].SEP . 'pathext='.$_POST['pathext'].SEP. 'popup='.$_GET['popup'].SEP. 'tab='.$_REQUEST['tab'].SEP.'_course_id='.$_course_id);
140 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.'_course_id='.$_course_id);
145 $msg->addError(array('MAX_STORAGE_EXCEEDED', get_human_size($my_MaxCourseSize)));
146 FileUtility::handleAjaxUpload(500);
148 header('Location: '.$_base_href.'editor/edit_content.php?cid='.$_REQUEST['cid'].SEP . 'pathext='.$_POST['pathext'].SEP. 'popup='.$_GET['popup'].SEP. 'tab='.$_REQUEST['tab'].SEP.'_course_id='.$_course_id);
150 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.'_course_id='.$_course_id);
155 $msg->addError(array('FILE_TOO_BIG', get_human_size($my_MaxFileSize)));
156 FileUtility::handleAjaxUpload(500);
158 header('Location: '.$_base_href.'editor/edit_content.php?cid='.$_REQUEST['cid'].SEP . 'pathext='.$_POST['pathext'].SEP. 'popup='.$_GET['popup'].SEP. 'tab='.$_REQUEST['tab'].SEP.'_course_id='.$_course_id);
160 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.'_course_id='.$_course_id);
165 $msg->addError('FILE_NOT_SELECTED');
166 FileUtility::handleAjaxUpload(500);
168 header('Location: '.$_base_href.'editor/edit_content.php?cid='.$_REQUEST['cid'].SEP . 'pathext='.$_POST['pathext'].SEP. 'popup='.$_GET['popup'].SEP. 'tab='.$_REQUEST['tab'].SEP.'_course_id='.$_course_id);
170 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.'_course_id='.$_course_id);