From 08946b372888996130ff9e06394fa0e1dfc61ca8 Mon Sep 17 00:00:00 2001 From: Harris Wong Date: Mon, 3 Oct 2011 20:21:15 +0000 Subject: [PATCH] 4854: Infusion uploader integrated into file manager File Manager within AContent now uses infusion multi file uploader. --- docs/file_manager/filemanager_display.inc.php | 288 ++++++++++++------ docs/file_manager/index.php | 43 +-- docs/file_manager/upload.php | 15 +- docs/include/classes/FileUtility.class.php | 17 ++ docs/include/vitals.inc.php | 2 +- docs/themes/default/include/header.tmpl.php | 2 + 6 files changed, 227 insertions(+), 140 deletions(-) diff --git a/docs/file_manager/filemanager_display.inc.php b/docs/file_manager/filemanager_display.inc.php index 453298f..0fd396d 100644 --- a/docs/file_manager/filemanager_display.inc.php +++ b/docs/file_manager/filemanager_display.inc.php @@ -120,6 +120,7 @@ $labelcol = 3; if (TRUE || $framed != TRUE) { + if ($_GET['overwrite'] != '') { // get file name, out of the full path $path_parts = pathinfo($current_path.$_GET['overwrite']); @@ -144,15 +145,13 @@ if (TRUE || $framed != TRUE) { // make new directory echo '
'._AT('add_file_folder').''."\n"; echo '
'."\n"; - echo '
'."\n"; + echo ' '."\n"; if( $MakeDirOn ) { if ($depth < $MaxDirDepth) { echo '
'."\n"; echo '  '._AT('keep_it_short').'
'."\n"; echo ' '."\n"; echo ' '."\n"; - echo ' '."\n"; - if ($cid > 0) echo ' '."\n"; echo ' '."\n"; } else { echo _AT('depth_reached')."\n"; @@ -164,98 +163,200 @@ if (TRUE || $framed != TRUE) { echo '

'."\n"; - - // If flash is available, provide the option of using Fluid's uploader or the basic uploader + // If flash is available, provide the option of using Fluid's uploader or the basic uploader if (isset($_SESSION['flash']) && $_SESSION['flash'] == "yes") { echo '
'."\n"; if (isset($_COOKIE["fluid_on"]) && $_COOKIE["fluid_on"]=="yes") $fluid_on = 'checked="checked"'; - echo '( '."\n"; + echo '( '."\n"; echo ')'."\n"; echo '
'."\n"; } - - // Create a new file echo '
'."\n"; - $course_row = $coursesDAO->get($_course_id); - if ($course_row['max_quota'] == '' || is_null($course_row['max_quota'])) - $my_MaxCourseSize = $MaxCourseSize; + $course_row = $coursesDAO->get($_course_id); + if ($course_row['max_quota'] == '' || is_null($course_row['max_quota'])) + $my_MaxCourseSize = $MaxCourseSize; // upload file if ($course_row['max_quota'] == TR_COURSESIZE_UNLIMITED || $my_MaxCourseSize-$course_total > 0) { echo '
'._AT('OR').'
'."\n".'
'."\n"; if (isset($_SESSION['flash']) && $_SESSION['flash'] == "yes") { ?> -
> - - '."\n".'
'; - } else { echo ' '."\n"; $msg->printInfos('OVER_QUOTA'); } } + // Directory and File listing echo '
'; echo ''; @@ -572,6 +674,19 @@ function setURLAlternative() { } +// set a cookie +function setCheckboxCookie(obj, value1, value2, date) +{ + var today = new Date(); + var the_date = new Date(date); + var the_cookie_date = the_date.toGMTString(); + if (obj.checked==true) + var the_cookie = value1 + ";expires=" + the_cookie_date; + else + var the_cookie = value2 + ";expires=" + the_cookie_date; + document.cookie = the_cookie; +} + // toggle the view between div object and button function toggleform(id, link) { var obj = document.getElementById(id); @@ -591,19 +706,6 @@ function toggleform(id, link) { btn.style.display = ''; } } - -// set a cookie -function setCheckboxCookie(obj, value1, value2, date) -{ - var today = new Date(); - var the_date = new Date(date); - var the_cookie_date = the_date.toGMTString(); - if (obj.checked==true) - var the_cookie = value1 + ";expires=" + the_cookie_date; - else - var the_cookie = value2 + ";expires=" + the_cookie_date; - document.cookie = the_cookie; -} - - - '; } global $msg; diff --git a/docs/file_manager/upload.php b/docs/file_manager/upload.php index 64b169d..5643ac8 100644 --- a/docs/file_manager/upload.php +++ b/docs/file_manager/upload.php @@ -49,20 +49,21 @@ $my_MaxFileSize = FileUtility::megabytes_to_bytes(substr(ini_get('upload_max_fil $path = TR_CONTENT_DIR . $_course_id.'/'.$_POST['pathext']; if (isset($_POST['submit'])) { - + if($_FILES['file']) { + $_FILES['uploadedfile'] = $_FILES['file']; + } if($_FILES['uploadedfile']['name']) { - $_FILES['uploadedfile']['name'] = trim($_FILES['uploadedfile']['name']); $_FILES['uploadedfile']['name'] = str_replace(' ', '_', $_FILES['uploadedfile']['name']); $path_parts = pathinfo($_FILES['uploadedfile']['name']); $ext = $path_parts['extension']; - /* check if this file extension is allowed: */ /* $IllegalExtentions is defined in ./include/config.inc.php */ if (in_array($ext, $IllegalExtentions)) { $errors = array('FILE_ILLEGAL', $ext); $msg->addError($errors); + FileUtility::handleAjaxUpload(500); 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); exit; } @@ -78,7 +79,6 @@ if (isset($_POST['submit'])) { /* anything else should be okay, since we're on *nix.. hopefully */ $_FILES['uploadedfile']['name'] = str_replace(array(' ', '/', '\\', ':', '*', '?', '"', '<', '>', '|', '\''), '', $_FILES['uploadedfile']['name']); - /* if the file size is within allowed limits */ if( ($_FILES['uploadedfile']['size'] > 0) && ($_FILES['uploadedfile']['size'] <= $my_MaxFileSize) ) { @@ -118,6 +118,7 @@ if (isset($_POST['submit'])) { $_course_id, SEP); $msg->addFeedback($f); + FileUtility::handleAjaxUpload(200); if ($alter) 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); else @@ -131,7 +132,8 @@ if (isset($_POST['submit'])) { } else { $msg->addFeedback('FILE_UPLOADED'); - + FileUtility::handleAjaxUpload(200); + if ($alter) 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); else @@ -141,6 +143,7 @@ if (isset($_POST['submit'])) { } } else { $msg->addError(array('MAX_STORAGE_EXCEEDED', get_human_size($my_MaxCourseSize))); + FileUtility::handleAjaxUpload(500); if ($alter) 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); else @@ -150,6 +153,7 @@ if (isset($_POST['submit'])) { } } else { $msg->addError(array('FILE_TOO_BIG', get_human_size($my_MaxFileSize))); + FileUtility::handleAjaxUpload(500); if ($alter) 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); else @@ -159,6 +163,7 @@ if (isset($_POST['submit'])) { } } else { $msg->addError('FILE_NOT_SELECTED'); + FileUtility::handleAjaxUpload(500); if ($alter) 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); else diff --git a/docs/include/classes/FileUtility.class.php b/docs/include/classes/FileUtility.class.php index 04213c1..b2e0df4 100644 --- a/docs/include/classes/FileUtility.class.php +++ b/docs/include/classes/FileUtility.class.php @@ -407,5 +407,22 @@ class FileUtility { readfile($filename); } } + + /** + * This function handles ajax request and return an array of errors encoded in JSON + * @param int HTTP Status code, so far, handle 200 and 500. + */ + public static function handleAjaxUpload($statusCode) { + if ($_POST['type'] === 'ajax') { + if ($statusCode === 500) { + // $msg->printErrors(); + header("HTTP/1.1 500 Internal Server Error", TRUE, 500); + } elseif ($statusCode === 200) { + // $msg->printFeedbacks(); + header("HTTP/1.1 200 Ok", TRUE, 200); + } + exit; + } + } } ?> \ No newline at end of file diff --git a/docs/include/vitals.inc.php b/docs/include/vitals.inc.php index f7a7dd7..ab4ed7e 100644 --- a/docs/include/vitals.inc.php +++ b/docs/include/vitals.inc.php @@ -270,7 +270,7 @@ if(isset($_COOKIE["flash"])){ $_SESSION['flash'] = $_COOKIE["flash"]; //delete the cookie - ATutor.setcookie("flash",'',time()-3600); + AContent.setcookie("flash",'',time()-3600); } if (!isset($_SESSION["flash"])) { diff --git a/docs/themes/default/include/header.tmpl.php b/docs/themes/default/include/header.tmpl.php index 7a201bc..dde10d6 100644 --- a/docs/themes/default/include/header.tmpl.php +++ b/docs/themes/default/include/header.tmpl.php @@ -75,6 +75,7 @@ $starttime = $mtime; + rtl_css; ?> + -- 2.17.1