diff --git a/main/inc/lib/formvalidator/FormValidator.class.php b/main/inc/lib/formvalidator/FormValidator.class.php index 8265d8b444..598e26c8cd 100644 --- a/main/inc/lib/formvalidator/FormValidator.class.php +++ b/main/inc/lib/formvalidator/FormValidator.class.php @@ -23,6 +23,8 @@ require_once ('HTML/QuickForm.php'); require_once ('HTML/QuickForm/advmultiselect.php'); + + /** * Filter */ @@ -204,13 +206,67 @@ EOT; * @param int $delay The number of seconds between the moment the user * submits the form and the start of the progress bar. */ - function add_progress_bar($delay = 2) + function add_progress_bar($delay = 2, $label='') { + if(empty($label)) + { + $label = get_lang('PleaseStandBy'); + } $this->with_progress_bar = true; - $this->updateAttributes("onsubmit=\"myUpload.start('dynamic_div','".api_get_path(WEB_CODE_PATH)."img/progress_bar.gif','".get_lang('PleaseStandBy')."','".$this->getAttribute('id')."')\""); + $this->updateAttributes("onsubmit=\"myUpload.start('dynamic_div','".api_get_path(WEB_CODE_PATH)."img/progress_bar.gif','".$label."','".$this->getAttribute('id')."')\""); + $this->addElement('html',''); + $this->addElement('html',''); + } + + + /** + * Use the new functions (php 5.2) allowing to display a real upload progress. + * @param upload_id the value of the field UPLOAD_IDENTIFIER + * @param delay the frequency of the xajax call + */ + function add_real_progress_bar($upload_id, $delay=2) + { + if(phpversion()<'5.2') + { + $this -> add_progress_bar($delay); + return; + } + + if(!class_exists('xajax')) { + require_once api_get_path(LIBRARY_PATH).'xajax/xajax.inc.php'; + } + + $xajax_upload = new xajax(api_get_path(WEB_CODE_PATH).'inc/lib/upload.xajax.php'); + + $xajax_upload -> registerFunction ('updateProgress'); + + + // IMPORTANT : must be the first element of the form (that's why we don't use addElement(hidden...) + $this->addElement('html',''); + + // add the div where the progress bar will be displayed + $this->addElement('html',' +
'); + + // get the xajax code + $this->addElement('html',$xajax_upload -> getJavascript(api_get_path(WEB_CODE_PATH).'inc/lib/xajax')); + + // get the upload code $this->addElement('html',''); $this->addElement('html',''); + + + // add the upload event + $this->updateAttributes("onsubmit=\"myUpload.startRealUpload('dynamic_div','".$upload_id."','".$label."','".$this->getAttribute('id')."')\""); + + } + /** * Display the form. * If an element in the form didn't validate, an error message is showed @@ -255,6 +311,7 @@ EOT; } } + /** * Clean HTML * @param string HTML to clean diff --git a/main/inc/lib/javascript/upload.js b/main/inc/lib/javascript/upload.js index 0aba27769b..b18e1bae35 100644 --- a/main/inc/lib/javascript/upload.js +++ b/main/inc/lib/javascript/upload.js @@ -21,6 +21,24 @@ function upload(latency){ __progress_bar_interval = setTimeout(__display_progress_bar,latency); __upload_form_domid = formid; } + + /** + * Starts the timer of the real upload progress + */ + function startRealUpload(domid, upload_id){ + __progress_bar_domid = domid; + __progress_bar_uploadid = upload_id; + __progress_bar_interval = setInterval(__refreshUpload,latency); + document.getElementById(domid+'_container').style.display = 'block'; + } + + /** + * Function called by a timer to update every x seconds the progress bar + */ + function __refreshUpload(){ + xajax_updateProgress(__progress_bar_domid, __progress_bar_uploadid); + } + /** * Displays the progress bar in the given DOM element */ @@ -32,6 +50,7 @@ function upload(latency){ } } this.start = start; + this.startRealUpload = startRealUpload; var __progress_bar_domid = ''; var __progress_bar_img = '../img/progress_bar.gif'; var __progress_bar_text = 'Uploading... Please wait'; diff --git a/main/inc/lib/upload.xajax.php b/main/inc/lib/upload.xajax.php new file mode 100644 index 0000000000..8f47360a84 --- /dev/null +++ b/main/inc/lib/upload.xajax.php @@ -0,0 +1,34 @@ + registerFunction ('updateProgress'); +$xajax_upload -> processRequests(); + +/** + * This function updates the progress bar + * @param div_id where the progress bar is displayed + * @param upload_id the identifier given in the field UPLOAD_IDENTIFIER + */ +function updateProgress($div_id, $upload_id){ + + $objResponse = new XajaxResponse(); + $ul_info = uploadprogress_get_info($upload_id); + $percent = intval($ul_info['bytes_uploaded']*100/$ul_info['bytes_total']); + $objResponse -> addAssign($div_id.'_label' , 'innerHTML', get_lang('Uploading').' : '.$percent.' %'); + $objResponse -> addAssign($div_id.'_filled' , 'style.width', $percent.'%'); + + + return $objResponse; + +} + + + + +?> diff --git a/main/upload/upload_ppt.php b/main/upload/upload_ppt.php index d5afe32601..19f1851f48 100644 --- a/main/upload/upload_ppt.php +++ b/main/upload/upload_ppt.php @@ -18,11 +18,23 @@ include("../inc/global.inc.php"); require_once(api_get_path(LIBRARY_PATH) . 'fileUpload.lib.php'); require_once(api_get_path(LIBRARY_PATH) . 'events.lib.inc.php'); require_once(api_get_path(LIBRARY_PATH) . 'document.lib.php'); +require_once (api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php'); + + +//$xajax_upload -> debugOn(); + +$form_style= ' +'; $htmlHeadXtra[] = ''; $htmlHeadXtra[] = ''; +$htmlHeadXtra[] = $form_style; if(isset($_POST['convert'])){ $cwdir = getcwd(); @@ -38,7 +50,6 @@ if(isset($_POST['convert'])){ event_access_tool(TOOL_UPLOAD); - $interbreadcrumb[]= array ("url"=>"../newscorm/lp_controller.php?action=list", "name"=> get_lang(TOOL_LEARNPATH)); $nameTools = get_lang("OogieConversionPowerPoint"); Display :: display_header($nameTools); @@ -97,21 +108,22 @@ if(!empty($errorMessage)){ echo '