Examples TOCexamples

Custom String

$Date: 2005/07/25 10:25:30 $

 Table of contents

Introduction

This example requires :


This example will run a horizontal ProgressBar with custom string.

There are 10 cells with default values:

Percent text info is left aligned on a white background area of 350 pixels width.

[Top]

 Render options

Here are options to build this progress bar string (percent text info):
width = 350
align = left
HTML_Progress_UI::setStringAttributes()

[Top]

 Output

Screenshot

[Top]

 PHP source syntax highlight

  1. <?php
  2. /**
  3.  * Horizontal String ProgressBar example.
  4.  *
  5.  * @version    $Id: string.php,v 1.2 2005/07/25 10:25:30 farell Exp $
  6.  * @author     Laurent Laville <pear@laurent-laville.org>
  7.  * @package    HTML_Progress
  8.  * @subpackage Examples
  9.  */
  10.  
  11. require_once 'HTML/Progress.php';
  12.  
  13. $pkg = array('PEAR', 'Archive_Tar', 'Config',
  14.     'HTML_QuickForm', 'HTML_CSS', 'HTML_Page', 'HTML_Template_Sigma',
  15.     'Log', 'MDB', 'PHPUnit');
  16.  
  17. function myFunctionHandler($progressValue, &$obj)
  18. {
  19.     global $pkg;
  20.  
  21.     $obj->sleep();
  22.     $i = floor($progressValue / 10);
  23.     if ($progressValue == 100) {
  24.         $msg = '';
  25.     } else {
  26.         $msg = "&nbsp; installing package ($progressValue %) ... : ".$pkg[$i];
  27.     }
  28.     $obj->setString($msg);
  29. }
  30.  
  31. $bar = new HTML_Progress();
  32. $bar->setAnimSpeed(100);
  33. $bar->setIncrement(5);
  34. $bar->setStringPainted(true);          // get space for the string
  35. $bar->setString('');                   // but don't paint it
  36. $bar->setProgressHandler('myFunctionHandler');
  37.  
  38. $ui =& $bar->getUI();
  39. $ui->setTab('    ');
  40. $ui->setStringAttributes('width=350 align=left');
  41. ?>
  42. <html>
  43. <head>
  44. <title>Horizontal String ProgressBar example</title>
  45. <style type="text/css">
  46. <!--
  47. <?php echo $bar->getStyle(); ?>
  48.  
  49. body {
  50.     background-color: #FFFFFF;
  51.     color: #000000;
  52.     font-family: Verdana, Arial;
  53. }
  54.  
  55. a:visited, a:active, a:link {
  56.     color: navy;
  57. }
  58. // -->
  59. </style>
  60. <script type="text/javascript">
  61. <!--
  62. <?php echo $bar->getScript(); ?>
  63. //-->
  64. </script>
  65. </head>
  66. <body>
  67.  
  68. <?php
  69. echo $bar->toHtml();
  70. $bar->run();
  71. $bar->display();  // to display the last custom string (blank)
  72. ?>
  73.  
  74. </body>
  75. </html>

[Top]