cvs: pear /HTML_Progress2/examples/ajax default2.php default2task.php download.gif

From: Date: Tue, 16 Jan 2007 15:23:15 +0000
Subject: cvs: pear /HTML_Progress2/examples/ajax default2.php default2task.php download.gif
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-44251@lists.php.net to get a copy of this message
farell Tue Jan 16 15:23:15 2007 UTC Added files: /pear/HTML_Progress2/examples/ajax default2.php default2task.php download.gif Log: BackgroundImages standard example transform to AJAX pattern, using two scripts 1. default2.php to build the progress bar 2. default2task.php to handle user-task (server side) http://cvs.php.net/viewvc.cgi/pear/HTML_Progress2/examples/ajax/default2.php?view=markup&rev=1.1 Index: pear/HTML_Progress2/examples/ajax/default2.php +++ pear/HTML_Progress2/examples/ajax/default2.php <?php /** * Reverse horizontal AJAX ProgressBar with red skin, using default Ajax driver. * This example show how to use two separate scripts to build progress bar, * and handle server side task operations. * * @version $Id: default2.php,v 1.1 2007/01/16 15:23:15 farell Exp $ * @author Laurent Laville <pear@laurent-laville.org> * @package HTML_Progress2 * @subpackage Examples * @access public * @example examples/ajax/default2.php * AJAX bgimages source code * @link http://www.laurent-laville.org/img/progress/screenshot/bgimages.png * screenshot (Image PNG, 310x40 pixels) 501 bytes */ require_once 'HTML/Progress2.php'; $pb = new HTML_Progress2(); $pb->setIdent('PB1'); $pb->setIncrement(10); $pb->setCellAttributes(array( 'active-color' => '#000084', 'inactive-color' => '#3A6EA5', 'width' => 25, 'spacing' => 0, 'background-image' => 'download.gif' )); $pb->setBorderPainted(true); $pb->setBorderAttributes('width=1 style=inset color=white'); $pb->setLabelAttributes('pct1', array( 'width' => 60, 'font-size' => 10, 'align' => 'center', 'valign' => 'left' )); $ae = $pb->registerAjax(); $ae->setRequestUri('default2task.php'); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3c.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> <head> <title>BgImages Ajax Progress2 example</title> <style type="text/css"> <!-- <?php echo $pb->getStyle(); ?> body {background-color: #C3C6C3; } --> </style> <?php echo $pb->getScript(false); ?> <script type="text/javascript" src="Poly9UrlParser.js"></script> <script type="text/javascript"> //<![CDATA[ <?php echo $ae->getScript(true); ?> function complete() { hideProgress(progressId); } //]]> </script> </head> <body> <?php $pb->display(); ?> <script type="text/javascript"> //<![CDATA[ <?php $m = $ae->getRequestMethod(); if ($m != 'GET') { echo "reqMethod = '$m';\n"; } $t = $ae->getRequestTimeout(); if ($t != 2000) { echo "timeout = '$t';\n"; } echo "url1 = '". $ae->getRequestUri(1) ."';\n"; echo "url2 = '". $ae->getRequestUri(2) ."';\n"; ?> startTask(); //]]> </script> </body> </html> http://cvs.php.net/viewvc.cgi/pear/HTML_Progress2/examples/ajax/default2task.php?view=markup&rev=1.1 Index: pear/HTML_Progress2/examples/ajax/default2task.php +++ pear/HTML_Progress2/examples/ajax/default2task.php <?php /** * Reverse horizontal AJAX ProgressBar with red skin, using default Ajax driver. * This is the task handler part of default2.php example. * * @version $Id: default2task.php,v 1.1 2007/01/16 15:23:15 farell Exp $ * @author Laurent Laville <pear@laurent-laville.org> * @package HTML_Progress2 * @subpackage Examples * @access public * @example examples/ajax/default2task.php * AJAX bgimages task handler source code */ /** * Simulate a user-task that will take many cycles to complete */ function processTask() { $newVal = $_SESSION['progressPercentage'] + mt_rand(1, 25); $_SESSION['progressPercentage'] = min(100, $newVal); return $_SESSION['progressPercentage']; } session_start(); if (isset($_REQUEST['registerTask'])) { // Negociate a new task identifier $_SESSION['taskId'] = mt_rand(); $_SESSION['progressId'] = $_REQUEST['registerTask']; $_SESSION['progressPercentage'] = 0; header("Content-Type: text/xml"); echo "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>"; ?> <progress id="<?php echo $_SESSION['progressId']; ?>" taskId="<?php echo $_SESSION['taskId']; ?>" /> <?php exit; } elseif (isset($_REQUEST['TaskId'])) { // Proceed user-task on each polling loop if ($_REQUEST['TaskId'] != $_SESSION['taskId']) { die('wrong task id'); } header("Content-Type: text/xml"); echo "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>"; } ?> <progress id="<?php echo $_SESSION['progressId']; ?>" taskId="<?php echo $_SESSION['taskId']; ?>"> <percentage><?php echo processTask(); ?></percentage> </progress>

« previous php.pear.cvs (#44251) next »