Source for file jsquickwalk.php

Documentation is available at jsquickwalk.php

  1. <?php
  2. /**
  3. * Create a pair of forward/back javascript links to allow the user to move forward and back through a sequence of date periods
  4. *
  5. @author    Stuart Prescott
  6. @copyright  Copyright Stuart Prescott
  7. @license    http://opensource.org/licenses/gpl-license.php GNU Public License
  8. @version    $Id$
  9. @package    Bumblebee
  10. @subpackage Misc
  11. */
  12.  
  13. /** Load ancillary functions */
  14. require_once 'inc/typeinfo.php';
  15.  
  16. /** date manipulation routines */
  17. require_once 'inc/date.php';
  18.  
  19. /**
  20. * Create a pair of forward/back javascript links to allow the user to move forward and back through a sequence of date periods
  21. *
  22. @package    Bumblebee
  23. @subpackage Misc
  24. */
  25. class JSQuickWalk {
  26.   /**
  27.   * unqiue name in the javascript namespace for these functions (prepended to everything)
  28.   * @var string 
  29.   */
  30.   var $namebase;
  31.   /**
  32.   * name for the "back" link
  33.   * @var string 
  34.   */
  35.   var $back;
  36.   /**
  37.   * name for the "forward" link
  38.   * @var string 
  39.   */
  40.   var $fwd;
  41.   /**
  42.   * html text-input id's for the two date elements
  43.   * @var array 
  44.   */
  45.   var $keys;
  46.   /**
  47.   * dates to use in the sequence
  48.   * @var array 
  49.   */
  50.   var $values;
  51.   /**
  52.   * initial position in sequence
  53.   * @var integer 
  54.   */
  55.   var $counter;
  56.  
  57.   /**
  58.   * Constructor
  59.   * @param string $namebase added to javascript namespace for uniqueness
  60.   * @param string $back     label for 'previous' button
  61.   * @param string $fwd      label for 'next' button
  62.   * @param array  $keys     list of js id tags for the text boxes to alter
  63.   * @param array  $values   list of dates to use in the sequence
  64.   * @param integer $counter  initial position in sequence
  65.   */
  66.   function JSQuickWalk($namebase$back$fwd$keys$values$counter{
  67.     $this->namebase = $namebase;
  68.     $this->back = $back;
  69.     $this->fwd  = $fwd;
  70.     $this->keys = $keys;
  71.     $this->values = $values;
  72.     $this->counter = $counter;
  73.   }
  74.   
  75.   /**
  76.   * generate the javascript for the +/- links
  77.   * @return string javascript embedded in html for necessary functions and data
  78.   */
  79.   function displayJS({
  80.     $eol="\n";
  81.     $t '<script type="text/javascript">'.$eol
  82.         .'<!--'.$eol;
  83.     $t .= $this->namebase.'walkarray = new Array();'.$eol;
  84.     for ($i=0$i<count($this->values)$i++{
  85.       $t .= $this->namebase.'walkarray['.$i.']= new Array();'.$eol;
  86.       foreach ($this->keys as $k{
  87.         $t .= $this->namebase.'walkarray['.$i.']["'.$k.'"]="'
  88.                                     .$this->values[$i][$k]->dateString().'";'.$eol;
  89.       }
  90.     }
  91.     $c $this->namebase.'walkcounter';
  92.     $t .= 'var '.$c.'='.$this->counter.';'.$eol;
  93.     $t .= 'function '.$this->namebase.'walkfwd() {'.$eol
  94.          .'  rightForm = "bumblebeeform";'
  95.          //.'  alert("FOO"+'.$c.')'.$eol
  96.          .'  ('.$c.' < '.(count($this->values)-1).' && '.$c.'++);'.$eol;
  97.     foreach ($this->keys as $k{
  98.       $t .= '  document.forms[rightForm].'.$this->namebase.$k.'.value='
  99.                               .$this->namebase.'walkarray['.$c.']["'.$k.'"];'.$eol;
  100.     }
  101.     
  102. //         .'  alert('.$c.'['..'])'.$eol
  103.          //.'  return false;'
  104.     $t .= '}'.$eol;
  105.  
  106.     $t .= 'function '.$this->namebase.'walkback() {'.$eol
  107.          .'  rightForm = "bumblebeeform";'
  108.          .'  ('.$c.' > 0 && '.$c.'--);'.$eol;
  109.     foreach ($this->keys as $k{
  110.       $t .= '  document.forms[rightForm].'.$this->namebase.$k.'.value='
  111.                               .$this->namebase.'walkarray['.$c.']["'.$k.'"];'.$eol;
  112.     }
  113.     $t .= '}'.$eol;
  114.     $t .= '-->'.$eol
  115.          .'</script>'.$eol;
  116.     return $t;
  117.   }
  118.   
  119.   /**
  120.   * generate the forward link
  121.   * @return string html link to fire the forwards event
  122.   */
  123.   function displayFwd({
  124.     return '<a href="javascript:'.$this->namebase.'walkfwd()">'
  125.             .$this->fwd.'</a>';
  126.   }
  127.   
  128.   /**
  129.   * generate the back link
  130.   * @return string html link to fire the previous event
  131.   */
  132.   function displayBack({
  133.     return '<a href="javascript:'.$this->namebase.'walkback()">'
  134.             .$this->back.'</a>';
  135.   }
  136.  
  137. }

Documentation generated on Tue, 06 Mar 2007 10:01:44 +0000 by phpDocumentor 1.3.0