[svn r10486] add a real progress bar fot the upload (if php > 5.2, else it displays the old faked progress bar)

skala
Eric Marguin 19 years ago
parent 7a33360788
commit fedbbd49f7
  1. 61
      main/inc/lib/formvalidator/FormValidator.class.php
  2. 19
      main/inc/lib/javascript/upload.js
  3. 34
      main/inc/lib/upload.xajax.php
  4. 38
      main/upload/upload_ppt.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','<script language="javascript" src="'.api_get_path(WEB_CODE_PATH).'inc/lib/javascript/upload.js" type="text/javascript"></script>');
$this->addElement('html','<script type="text/javascript">var myUpload = new upload('.(abs(intval($delay))*1000).');</script>');
}
/**
* 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','<input name="UPLOAD_IDENTIFIER" type="hidden" value="'.$upload_id.'" />');
// add the div where the progress bar will be displayed
$this->addElement('html','
<div id="dynamic_div_container" style="display:none">
<div id="dynamic_div_label"></div>
<div id="dynamic_div_frame" style="width:214px; height:12px; border:1px solid grey">
<div id="dynamic_div_filled" style="width:0%;height:100%;background-image:url('.api_get_path(REL_PATH).'main/img/real_upload_step.gif);background-repeat:repeat-x"></div>
</div>
</div>');
// 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','<script language="javascript" src="'.api_get_path(WEB_CODE_PATH).'inc/lib/javascript/upload.js" type="text/javascript"></script>');
$this->addElement('html','<script type="text/javascript">var myUpload = new upload('.(abs(intval($delay))*1000).');</script>');
// 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

@ -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';

@ -0,0 +1,34 @@
<?php
/**
* Xajax action to handle the real progress bar for an upload
* @author Eric Marguin
*/
include("../global.inc.php");
require_once api_get_path(LIBRARY_PATH).'xajax/xajax.inc.php';
$xajax_upload = new Xajax();
$xajax_upload -> 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;
}
?>

@ -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= '
<style>
.row {
width: 200px;
}
</style>';
$htmlHeadXtra[] = '<script language="javascript" src="../inc/lib/javascript/upload.js" type="text/javascript"></script>';
$htmlHeadXtra[] = '<script type="text/javascript">
var myUpload = new upload(0);
</script>';
$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 '<div style="'.$s_style_error.'"><div style="float:left; margin-right:10px;"><img src="'.api_get_path(WEB_IMG_PATH)."message_error.gif".'" alt="'.$alt_text.'" '.$attribute_list.' /></div><div style="margin-left: 43px">'.$errorMessage.'</div></div>';
}
echo '<div id="dynamic_div" style="display:block;margin-left:40%;margin-top:10px;height:50px;"></div>';
$form = new FormValidator('update_course');
$form -> add_real_progress_bar('ppt2lp',1);
// build the form
$form -> addElement ('html','<br /><br />');
$form -> addElement('file', 'user_file','<img src="../img/powerpoint_big.gif" />');
$form -> addGroup ($elements, null, null, '&nbsp;&nbsp;');
$form -> addElement ('hidden', 'ppt2lp', 'true');
$form -> addElement ('html','<br /><br />');
$form -> addElement ('submit', 'convert', get_lang('ConvertToLP'));
echo '<div id="upload_form_div" name="form_div" style="display:block;">';
// display the form
$form -> display();
echo '<form enctype="multipart/form-data" method="POST" action="'.$_SERVER['PHP_SELF'].'" onsubmit="myUpload.start(\'dynamic_div\',\'../img/progress_bar.gif\',\''.get_lang("Converting").'\',\'upload_form_div\');">';
echo '<img src="../img/powerpoint_big.gif" align="absbottom">
&nbsp;&nbsp;<input type="file" name="user_file">
<input type="hidden" name="ppt2lp" value="true" />
<br><br>
<input type="submit" name="convert" value="'.get_lang('ConvertToLP').'">
&nbsp;&nbsp;
<img src="../img/scormbuilder.gif" align="absmiddle">';
echo '</form>';
echo '</div>';
echo "<br><br><br><br>";

Loading…
Cancel
Save