4854: Infusion uploader integrated into file manager
authorHarris Wong <hwong@ocad.ca>
Mon, 3 Oct 2011 20:21:15 +0000 (20:21 -0000)
committerHarris Wong <hwong@ocad.ca>
Mon, 3 Oct 2011 20:21:15 +0000 (20:21 -0000)
File Manager within AContent now uses infusion multi file uploader.

docs/file_manager/filemanager_display.inc.php
docs/file_manager/index.php
docs/file_manager/upload.php
docs/include/classes/FileUtility.class.php
docs/include/vitals.inc.php
docs/themes/default/include/header.tmpl.php

index 453298f..0fd396d 100644 (file)
@@ -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 '<div class="input-form"><fieldset class="group_form"><legend class="group_form">'._AT('add_file_folder').'</legend>'."\n";
        echo '  <div class="row">'."\n";
-       echo '          <form name="form1" method="post" action="'.$_SERVER['PHP_SELF'].'?'.(($pathext != '') ? 'pathext='.urlencode($pathext).SEP : ''). 'popup='.$popup.SEP.'cp='.SEP.$_GET['cp'].SEP.'pid='.$_GET['pid'].SEP.'_cid='.$cid.SEP.'a_type='.$a_type.SEP.'_course_id='.$_course_id.'">'."\n";
+       echo '          <form name="form1" method="post" action="'.$_SERVER['PHP_SELF'].'?'.(($pathext != '') ? 'pathext='.urlencode($pathext).SEP : ''). 'popup='.$popup.SEP.'cp='.SEP.$_GET['cp'].SEP.'pid='.$_GET['pid'].SEP.'cid='.$cid.SEP.'a_type='.$a_type.'">'."\n";
        if( $MakeDirOn ) {
                if ($depth < $MaxDirDepth) {
                        echo '          <label for="dirname">'._AT('create_folder_here').'</label><br />'."\n";
                        echo '          &nbsp;<small class="spacer">'._AT('keep_it_short').'</small><br />'."\n";
                        echo '          <input type="text" name="dirname" id="dirname" size="20" /> '."\n";
                        echo '          <input type="hidden" name="mkdir_value" value="true" /> '."\n";
-                       echo '          <input type="hidden" name="_course_id" value="'.$_course_id.'" /> '."\n";
-                       if ($cid > 0) echo '            <input type="hidden" name="_cid" value="'.$cid.'" /> '."\n";
                        echo '          <input type="submit" name="mkdir" value="'._AT('create_folder').'" class="button" />'."\n";
                } else {
                        echo _AT('depth_reached')."\n";
@@ -164,98 +163,200 @@ if (TRUE || $framed != TRUE) {
 
        echo '  <div class="row"><hr /></div>'."\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 '<div class="row">'."\n";
                if (isset($_COOKIE["fluid_on"]) && $_COOKIE["fluid_on"]=="yes")
                        $fluid_on = 'checked="checked"';
-               echo '(<input type="checkbox" id="fluid_on" name="fluid_on" onclick="toggleform(\'simple-container\', \'fluid-container\'); setCheckboxCookie(this, \'fluid_on=yes\', \'fluid_on=no\',\'December 31, 2099\');" value="yes" '.$fluid_on.' /> '."\n";
+               echo '(<input type="checkbox" id="fluid_on" name="fluid_on" value="yes" '.$fluid_on.' /> '."\n";
                echo '<label for="fluid_on" >'._AT('enable_uploader').'</label>)'."\n";
                echo '</div>'."\n";
        }
-
-
        // Create a new file
        echo '  <div class="row" style="float: left;"><input type="button" class="button" name="new_file" value="' . _AT('file_manager_new') . '" onclick="window.location.href=\''.TR_BASE_HREF.'file_manager/new.php?pathext=' . urlencode($pathext) . SEP . 'framed=' . $framed . SEP . 'popup=' . $popup . SEP.'_course_id='.$_course_id. '\'"/></div>'."\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 '  <div class="row" style="float: left;">'._AT('OR').'</div>'."\n".'       <div class="row" style="float: left;">'."\n";
                if (isset($_SESSION['flash']) && $_SESSION['flash'] == "yes") {
                ?>
-                       <div id="fluid-container" <?php echo (isset($_COOKIE["fluid_on"]) && $_COOKIE["fluid_on"]=="yes") ? '' : 'style="display:none;"'; ?>>
-                               <input type="button" id="uploader_link" class="button" name="upload_file" value="<?php echo _AT('upload_files'); ?>" onclick="toggleform('uploader', 'uploader_link');" />
-                               <div id="uploader" style="display: none;">
-                                       <form id="flc-uploader" class="flc-uploader fl-uploader fl-progEnhance-enhanced" method="get" enctype="multipart/form-data" action="" style="margin: 0px; padding: 0px;">
-                                               <div class="start">
-                                                       <div class="fl-uploader-queue-wrapper">
-                                                               <div class="fl-uploader-queue-header">
-                                                                       <table cellspacing="0" cellpadding="0">
-                                                                                       <tr>
-                                                                                               <th scope="col" class="fileName"><?php echo _AT('file_name'); ?></th>
-                                                                                               <th scope="col" class="fileSize"><?php echo _AT('size'); ?>&nbsp;&nbsp;</th>
-                                                                                               <th scope="col" class="fileRemove">&nbsp;</th>
-                                                                                       </tr>
-                                                                       </table>
-                                                               </div>
-
-                                      <div class="flc-scroller fl-scroller">
-                                               <div class="fl-scroller-inner">
-                                                   <table cellspacing="0" class="flc-uploader-queue fl-uploader-queue" summary="Queue of files to upload.">
-                                                       <tbody>
-                                                           <!-- Rows will be rendered in here. -->
-                                                           
-                                                           <!-- Template markup for the file queue rows -->
-                                                           <tr class="flc-uploader-file-tmplt flc-uploader-file fl-uploader-hidden-templates">
-                                                               <th class="flc-uploader-file-name fl-uploader-file-name" scope="row"><?php echo _AT('file_placeholder'); ?></th>
-                                                               <td class="flc-uploader-file-size fl-uploader-file-size">0 <?php echo _AT('kb'); ?></td>
-                                                               <td class="fl-uploader-file-actions">
-                                                                   <button type="button" class="flc-uploader-file-action fl-uploader-file-action" title="<?php echo _AT('remove_queued_file'); ?>" tabindex="-1">
-                                                                       <span class="fl-uploader-button-text fl-uploader-hidden"><?php echo _AT('remove_queued_file'); ?></span>
-                                                                   </button>
-                                                               </td>
-                                                           </tr>
-                                                           
-                                                           <!-- Template for the file error info rows -->
-                                                           <tr class="flc-uploader-file-error-tmplt fl-uploader-file-error fl-uploader-hidden-templates">
-                                                               <td colspan="3" class="flc-uploader-file-error"></td>
-                                                           </tr>
-                                                       </tbody>
-                                                   </table>
-                                                   <div class="flc-uploader-file-progressor-tmplt fl-uploader-file-progress"><span class="fl-uploader-file-progress-text fl-uploader-hidden">76%</span></div>
-                                               </div>
-                                           </div>
-
-                                                               <div class="flc-uploader-browse-instructions fl-uploader-browse-instructions"> <?php echo _AT('click_browse_files'); ?> </div>
-
-                                                               <div class="flc-uploader-queue-footer fl-uploader-queue-footer">
-                                                                       <table cellspacing="0" cellpadding="0">
-                                                                                       <tr>
-                                                                                               <td class="flc-uploader-total-progress-text"><?php echo _AT('total'); ?>: <span class="fluid-uploader-totalFiles">0</span> <?php echo _AT('files'); ?> (<span class="fluid-uploader-totalBytes">0 <?php echo _AT('kb'); ?></span>)</td>
-                                                                                               <td class="fl-uploader-footer-buttons" align="right" ><a class="flc-uploader-button-browse fl-uploader-browse" tabindex="0" ><?php echo _AT('browse_files'); ?></a></td>
-                                                                                       </tr>
-                                                                       </table>
-                                                                       <div class="flc-uploader-total-progress fl-uploader-total-progress-okay">&nbsp;</div>
-                                                               </div>
-                                                       </div>
-                                                       
-                                                       <div class="fl-uploader-btns">
-                                                               <button type="button" class="flc-uploader-button-pause fl-uploader-pause fl-uploader-hidden" onclick="toggleform('uploader', 'uploader_link');"><?php echo _AT('cancel'); ?></button>
-                                                               <button type="button" class="flc-uploader-button-upload fl-uploader-upload fl-uploader-button-default fl-uploader-dim" ><?php echo _AT('upload'); ?></button>
-                                                       </div>
-                                                       
-                                               </div>
-                                       </form>
-
+               <div id="uploader-error-container"></div>
+                       <div id="fluid-container">
+                               <div id="uploader">
+                               <!-- Basic upload controls, used when JavaScript is unavailable -->
+        <form method="post" enctype="multipart/form-data" class="fl-progEnhance-basic">
+            <p>Use the Browse button to add a file, and the Save button to upload it.</p>
+            <input name="fileData" type="file" />
+            <input type="hidden" name="_course_id" value ="<?php echo $_course_id; ?>" />
+            <input class="fl-uploader-basic-save" type="submit" value="Save"/>
+        </form>
+        
+        <!-- Uploader container -->
+        <form class="flc-uploader fl-uploader fl-progEnhance-enhanced" method="get" enctype="multipart/form-data">
+            
+            <!-- File Queue, which is split up into two separate tables: one for the header and body -->
+            <table class="fl-uploader-header">
+                       <tr>
+                                       <th class="fl-uploader-file-name">File Name</th>
+                                       <th class="fl-uploader-file-size">Size</th>
+                                       <th class="fl-uploader-file-actions"></th>
+                               </tr>u
+            </table>
+            
+            <!-- File Queue body, which is the default container for the FileQueueView component -->
+            <table summary="The list of files" class="flc-uploader-queue fl-uploader-queue">
+                               <caption>File Upload Queue:</caption>
+                               <tbody>
+                                       <!-- Template for file row -->
+                                       <tr class="flc-uploader-file-tmplt flc-uploader-file">
+                                               <td class="flc-uploader-file-name fl-uploader-file-name">File Name Placeholder</td>
+                                               <td class="flc-uploader-file-size fl-uploader-file-size">0 KB</td>
+                                               <td class="fl-uploader-file-actions">
+                                                       <button type="button" class="flc-uploader-file-action" tabindex="-1"></button>
+                                               </td>
+                                       </tr>
+                                       
+                                       <!-- Template for error info row -->
+                                       <tr class="flc-uploader-file-error-tmplt fl-uploader-file-error">
+                                               <td colspan="3" class="flc-uploader-file-error"></td>
+                                       </tr>
+                               </tbody>
+                       </table>
+            
+            <!-- File progress bar template, used to generate progress bars for each file in the queue -->
+            <div class="flc-uploader-file-progressor-tmplt fl-uploader-file-progress"></div>            
+
+            <!-- Initial instructions -->
+            <div class="flc-uploader-browse-instructions fl-uploader-browse-instructions">
+                Choose <em>Browse files</em> to add files to the queue. 
+            </div>            
+
+            <!-- Status footer -->
+            <div class="flc-uploader-queue-footer fl-uploader-queue-footer fl-fix">
+                <div class="flc-uploader-total-progress-text fl-uploader-total-progress-text fl-force-left">
+                    Total: 0 files (0 KB)
+                </div>
+                <div class="fl-text-align-right fl-force-right">
+                    <span class="flc-uploader-button-browse fl-uploader-browse">
+                        <span class="flc-uploader-button-browse-text">Browse files</span>
+                    </span>
+                </div>
+                <!-- Total progress bar -->
+                <div class="flc-uploader-total-progress fl-uploader-total-progress-okay"></div>
+                <div class="flc-uploader-errorsPanel fl-uploader-errorsPanel">
+                     <div class="fl-uploader-errorsPanel-header"><span class="flc-uploader-errorPanel-header">Warnings:</span></div>
+    
+                     <!-- The markup for each error section will be rendered into these containers. -->
+                     <div class="flc-uploader-errorPanel-section-fileSize"></div>
+                     <div class="flc-uploader-errorPanel-section-numFiles"></div>
+                     
+                     <!-- Error section template.-->
+                     <div class="flc-uploader-errorPanel-section-tmplt fl-uploader-hidden-templates">
+                         <div class="flc-uploader-errorPanel-section-title fl-uploader-errorPanel-section-title">
+                             x files were too y and were not added to the queue.
+                         </div>
+                         
+                         <div class="flc-uploader-errorPanel-section-details fl-uploader-errorPanel-section-details">
+                             <p>The following files were not added:</p>
+                             <p class="flc-uploader-errorPanel-section-files">file_1, file_2, file_3, file_4, file_5 </p>
+                         </div>
+                         
+                         <button type="button" class="flc-uploader-errorPanel-section-toggleDetails fl-uploader-errorPanel-section-toggleDetails">Hide this list</button>
+                         <button type="button" class="flc-uploader-errorPanel-section-removeButton fl-uploader-errorPanel-section-removeButton">
+                             <span class="flc-uploader-erroredButton-text fl-uploader-hidden">Remove error</span>
+                         </button>
+                     </div>
+                 </div>                
+            </div>
+            
+            <!-- Upload buttons -->
+            <div class="fl-uploader-buttons">
+                <button type="button" class="flc-uploader-button-pause fl-uploader-button-stop fl-uploader-hidden">Stop Upload</button>
+                <button type="button" class="flc-uploader-button-upload fl-uploader-button-upload fl-uploader-dim">Upload</button>
+            </div>
+            
+            <div class="flc-uploader-status-region fl-offScreen-hidden"></div>
+        </form>        
+            
+        <script type="text/javascript">
+            var myUploader = fluid.uploader(".flc-uploader", {
+                queueSettings: {
+                    uploadURL: '<?php echo TR_BASE_HREF; ?>file_manager/upload.php',
+                    fileUploadLimit: 5,
+                    fileQueueLimit: 2,
+                    postParams: {pathext: '<?php echo $pathext; ?>', type: 'ajax', submit: 'submit', _course_id: '<?php echo $_course_id; ?>'},
+                    fileSizeLimit: <?php echo $my_MaxCourseSize/1024; ?>
+                },
+                events: {
+                    onSuccess: {
+                        event: "onFileSuccess",
+                        args: [
+                            {
+                                fileName: "{arguments}.0.name",
+                                responseText: "{arguments}.1"
+                            }
+                        ]
+                    },
+                    onError: {
+                        event: "onFileError",
+                        args: [
+                            {
+                                fileName: "{arguments}.0.name",
+                                statusCode: "{arguments}.2",
+                                responseText: "{arguments}.3.responseText"
+                            }
+                        ]
+                    }
+                },
+                listeners: {
+                       onSuccess: function (response){
+                               // example assumes that the server code passes the new image URL in the serverData
+                               console.log("Success triggered", response);
+                               jQuery('#uploader-error-container').html(response.responseText);
+                       }, 
+                       onError: function(response) {
+                        console.log("Error triggered", response);
+                        jQuery('#uploader-error-container').html(response.responseText);
+                    },
+                    onUploadStart: function() {
+                        jQuery('#uploader-error-container').html("");
+                    },
+                    afterUploadComplete: function () {
+                        window.location = "<?php echo TR_BASE_HREF; ?>file_manager/index.php?pathext=<?php echo $pathext . SEP . '_course_id=' . $_course_id; ?>";
+                    }
+                   },
+                   components: {
+                    strategy: {
+                        options: {
+                            flashMovieSettings: {
+                                flashURL: "<?php echo TR_BASE_HREF; ?>include/jscripts/infusion/lib/swfupload/flash/swfupload.swf",
+                                flashButtonImageURL: "<?php echo TR_BASE_HREF; ?>include/jscripts/infusion/components/uploader/images/browse.png"
+                            }
+                        }
+                    }
+                }
+            });
+            
+            //bind fluid checkbox
+            jQuery('#fluid_on').bind("click", function() {
+                toggleform('simple-container', 'fluid-container'); 
+                setCheckboxCookie(this, 'fluid_on=yes', 'fluid_on=no','December 31, 2099');
+                console.log('hey');
+            });
+            
+            //hide multifile uploader if it's not checked 
+            if (!jQuery('#fluid_on').attr('checked')) {
+                jQuery('#fluid-container').hide();
+            }
+        </script>
                                </div>
                        </div>
                <?php
-                       if (isset($_COOKIE["fluid_on"]) && $_COOKIE["fluid_on"]=="yes")
+               if (isset($_COOKIE["fluid_on"]) && $_COOKIE["fluid_on"]=="yes")
                                echo '<div id="simple-container" style="display: none;">';
                        else
                                echo '<div id="simple-container">';
@@ -265,11 +366,13 @@ if (TRUE || $framed != TRUE) {
                }
 
                // Simple single file uploader
-               echo '<form onsubmit="openWindow(\''.TR_BASE_HREF.'home/prog.php\');" class="fl-ProgEnhance-basic" name="form1" method="post" action="file_manager/upload.php?popup='.$popup.SEP. 'framed='.$framed.SEP.'cp='.$_GET['cp'].SEP.'pid='.$_GET['pid'].SEP.'_cid='.$cid.SEP.'a_type='.$a_type.SEP.'_course_id='.$_course_id.'" enctype="multipart/form-data">';
+               echo '<form onsubmit="openWindow(\''.TR_BASE_HREF.'home/prog.php\');" name="form1" method="post" action="file_manager/upload.php?popup='.$popup.SEP. 'framed='.$framed.SEP.'cp='.$_GET['cp'].SEP.'pid='.$_GET['pid'].SEP.'cid='.$cid.SEP.'a_type='.$a_type.'" enctype="multipart/form-data">';
                echo '<input type="hidden" name="MAX_FILE_SIZE" value="'.$my_MaxFileSize.'" />';
-               echo '<label for="uploadedfile">'._AT('upload_files').'</label>'."\n";
+               
+               echo '<label for="uploadedfile">'._AT('upload_files').'</label><br />'."\n";
                echo '<input type="file" name="uploadedfile" id="uploadedfile" class="formfield" size="20" /> ';
                echo '<input type="submit" name="submit" value="'._AT('upload').'" class="button" />';
+               echo '<input type="hidden" name="_course_id" value ="'.$_course_id.'" />';
                echo '<input type="hidden" name="pathext" value="'.$pathext.'" />  ';
 
                if ($popup == TRUE) {
@@ -277,15 +380,14 @@ if (TRUE || $framed != TRUE) {
                }
                echo '</form>';
                echo '</div>';
-
                echo '          </div>'."\n".'  </fieldset></div>';
-
        } else {
                echo '  </fieldset></div>'."\n";
                $msg->printInfos('OVER_QUOTA');
        }
 }
 
+
 // Directory and File listing 
 echo '<form name="checkform" action="'.$_SERVER['PHP_SELF'].'?'.(($pathext!='') ? 'pathext='.urlencode($pathext).SEP : '').'popup='.$popup .SEP. 'framed='.$framed.SEP.'cp='.$_GET['cp'].SEP.'pid='.$_GET['pid'].SEP.'_cid='.$cid.SEP.'a_type='.$a_type.'" method="post">';
 echo '<input type="hidden" name="pathext" value ="'.$pathext.'" />';
@@ -572,6 +674,19 @@ function setURLAlternative() {
 }
 
 <?php  if (isset($_SESSION['flash']) && $_SESSION['flash'] == "yes") { ?>
+// 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;
-}
 <?php } ?>
 
 <?php 
index 75dc8cf..29ece72 100644 (file)
@@ -13,6 +13,7 @@
 define('TR_INCLUDE_PATH', '../include/');
 require(TR_INCLUDE_PATH.'vitals.inc.php');
 require_once(TR_INCLUDE_PATH.'classes/FileUtility.class.php');
+$_custom_css = $_base_href.'include/jscripts/infusion/components/uploader/css/Uploader.css';
 
 if ((isset($_REQUEST['popup']) && $_REQUEST['popup']) && 
        (!isset($_REQUEST['framed']) || !$_REQUEST['framed'])) {
@@ -33,7 +34,7 @@ if (isset($_SESSION['flash']) && $_SESSION['flash'] == "yes") {
     if (!isset($_COOKIE["fluid_on"]))
         trans.utility.setcookie("fluid_on", "yes", time()+1200); 
 
-    $fluid_dir = 'jscripts/infusion/';
+    $fluid_dir = 'include/jscripts/infusion/';
     $framed = intval($_GET['framed']);
     $popup = intval($_GET['popup']);
     $current_path = TR_CONTENT_DIR.$_course_id.'/';
@@ -54,46 +55,6 @@ if (isset($_SESSION['flash']) && $_SESSION['flash'] == "yes") {
         }
 
     }
-
-    $_custom_head .= '
-        <link href="'.$fluid_dir.'components/uploader/css/Uploader.css" rel="stylesheet" type="text/css" />
-        <script src="'.$fluid_dir.'InfusionAll.js" type="text/javascript"></script>
-        <script language="JavaScript" type="text/javascript">
-
-            var myUpload; // mostly used for testing
-
-            jQuery(document).ready(function () {
-                   myUpload = fluid.progressiveEnhanceableUploader(".flc-uploader", ".fl-ProgEnhance-basic", {
-                       uploadManager: {
-                                   type: "fluid.swfUploadManager",
-               
-                                   options: {
-                                      // Set the uploadURL to the URL for posting files to your server.
-                                      uploadURL: "'.$_base_href.'include/lib/upload.php?path='.urlencode($current_path.$pathext).'",
-               
-                                      // This option points to the location of the SWFUpload Flash object that ships with Fluid Infusion.
-                                      flashURL: "jscripts/infusion/lib/swfupload/flash/swfupload.swf"
-                                       }
-                               },
-               
-                       listeners: {
-                       onFileSuccess: function (file, serverData){
-                               // example assumes that the server code passes the new image URL in the serverData
-                               window.location="'.$_SERVER['PHP_SELF'].'?pathext=' . urlencode($pathext) . SEP . 'popup=' . $popup . SEP . 'framed=' . $framed . SEP . 'msg=FILEUPLOAD_DONE'.SEP.'_course_id='.$_course_id.'";
-                       }
-                   },
-               
-                 decorators: [{
-                    type: "fluid.swfUploadSetupDecorator",
-                    options: {
-                         // This option points to the location of the Browse Files button used with Flash 10 clients.
-                         flashButtonImageURL: "'.TR_BASE_HREF.'jscripts/infusion/components/uploader/images/browse.png"
-                                       }
-                 }]
-                    });
-               });
-        </script>
-    ';
 }
 
 global $msg;
index 64b169d..5643ac8 100644 (file)
@@ -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
index 04213c1..b2e0df4 100644 (file)
@@ -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
index f7a7dd7..ab4ed7e 100644 (file)
@@ -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"])) {
index 7a201bc..dde10d6 100644 (file)
@@ -75,6 +75,7 @@ $starttime = $mtime;
 
        <!-- <link href='http://fonts.googleapis.com/css?family=Droid+Sans:regular,bold' rel='stylesheet' type='text/css' /> -->
        <link rel="icon" href="<?php echo $this->base_path; ?>favicon.ico" type="image/x-icon" /> 
+       <link rel="stylesheet" href="<?php echo $this->base_path.'include/jscripts/infusion/framework/fss/css/fss-layout.css'; ?>" type="text/css" />
        <link rel="stylesheet" href="<?php echo $this->base_path.'themes/'.$this->theme; ?>/forms.css" type="text/css" />
        <link rel="stylesheet" href="<?php echo $this->base_path.'themes/'.$this->theme; ?>/styles.css" type="text/css" />
        <!--[if IE]>
@@ -82,6 +83,7 @@ $starttime = $mtime;
        <![endif]-->
 <?php echo $this->rtl_css; ?>
        <script src="<?php echo $this->base_path; ?>include/jscripts/infusion/InfusionAll.js" type="text/javascript"></script>
+       <script src="<?php echo $this->base_href; ?>include/jscripts/infusion/framework/enhancement/js/ProgressiveEnhancement.js" type="text/javascript"></script>
        <script src="<?php echo $this->base_path; ?>include/jscripts/infusion/jquery.autoHeight.js" type="text/javascript"></script>
        <script src="<?php echo $this->base_path; ?>include/jscripts/flowplayer/flowplayer-3.2.4.min.js" type="text/javascript"></script>
        <script src="<?php echo $this->base_path; ?>include/jscripts/handleAjaxResponse.js" type="text/javascript"></script>