Zikula_Core
[ class tree: Zikula_Core ] [ index: Zikula_Core ] [ all elements ]

Source for file pnHTML.php

Documentation is available at pnHTML.php

  1. <?php
  2. /**
  3.  * Zikula Application Framework
  4.  *
  5.  * @copyright (c) 2001, Zikula Development Team
  6.  * @link http://www.zikula.org
  7.  * @version $Id: pnHTML.php 24342 2008-06-06 12:03:14Z markwest $
  8.  * @license GNU/GPL - http://www.gnu.org/copyleft/gpl.html
  9.  * @package Zikula_Core
  10.  */
  11.  
  12. /**
  13.  * Set object to keep generated HTML.
  14.  *
  15.  * After calling SetOutputMode() with this value, all future calls to
  16.  * pnHTML methods will store their HTML in the objecr rather than
  17.  * returning it to the calling process.
  18.  *
  19.  * $const _PNH_KEEPOUTPUT Keep the output from method calls
  20.  */
  21. define('_PNH_KEEPOUTPUT'0);
  22.  
  23. /**
  24.  * Set object to return generated HTML to caller.
  25.  *
  26.  * After calling SetOutputMode() with this value, all future calls to
  27.  * pnHTML methods will return their HTML directly to the calling process
  28.  * rather than storing it within the object.
  29.  *
  30.  * $const _PNH_RETURNOUTPUT Return the output from method calls
  31.  */
  32. define('_PNH_RETURNOUTPUT'1);
  33.  
  34. /**
  35.  * Set incoming text to be copied verbatim to the output buffer
  36.  *
  37.  * $const _PNH_VERBATIMINPUT Do not parse incoming text
  38.  */
  39. define('_PNH_VERBATIMINPUT'0);
  40.  
  41. /**
  42.  * Set incoming text to be parsed for display before putting in the output buffer
  43.  *
  44.  * $const _PNH_PARSEINPUT Parse incoming text
  45.  */
  46. define('_PNH_PARSEINPUT'1);
  47.  
  48. /**
  49.  * HTML creation and display functions
  50.  *
  51.  * This class is designed to make generating HTML output in Zikula
  52.  * very simple, and also allows for much greater control of output by
  53.  * the site administrator.
  54.  *
  55.  *
  56.  * <strong>Example</strong>
  57.  * <pre>
  58.  * // Information array
  59.  * $colors = array(array('id' => 1,
  60.  *                       'name' => 'Red',
  61.  *                       'encoding' => 'ff0000'),
  62.  *                 array('id' => 2,
  63.  *                       'name' => 'Blue',
  64.  *                       'encoding' => '00ff00'),
  65.  *                 array('id' => 3,
  66.  *                       'name' => 'Green',
  67.  *                       'encoding' => '0000ff'));
  68.  *
  69.  * // Create the HTML object and start it
  70.  * $myhtml = new pnHTML();
  71.  * $myhtml->Start();
  72.  *
  73.  * // Add table showing encoding information
  74.  * $myhtml->TableStart('Colors and Their Encodings', array('Color', 'Encoding'));
  75.  * foreach ($colors as $color) {
  76.  *     $info = array($color['name'], $color['encoding']);
  77.  *     $myhtml->TableAddRow($info);
  78.  * }
  79.  * $myhtml->TableEnd();
  80.  *
  81.  * // Add form to select a color
  82.  * $myhtml->Text('&lt;P&gt;&lt;P&gt;');
  83.  * $myhtml->FormStart('colorchosen.php');
  84.  * $myhtml->Text('Select a color: ');
  85.  * $myhtml->FormList('chosen', $colorinfo);
  86.  * $myhtml->FormSubmit('That\'s the color I want');
  87.  * $myhtml->FormEnd();
  88.  *
  89.  *
  90.  * // End the HTML object and print it
  91.  * $myhtml->End();
  92.  * $myhtml->PrintPage();
  93.  * </pre>
  94.  *
  95.  * @package Zikula_Core
  96.  * @subpackage pnHTML
  97.  * @author Jim McDonald
  98.  * @author Patrick Kellum
  99.  */
  100. class pnHTML {
  101.     /**
  102.      * ==============================================================================*
  103.      * |                               Properties                                     |
  104.      * ==============================================================================
  105.      */
  106.  
  107.     /**
  108.      * Specific headers which must be printed prior to the main body of HTML
  109.      *
  110.      * @access private
  111.      * @var string $header 
  112.      */
  113.     var $header;
  114.  
  115.     /**
  116.      * The pending HTML output
  117.      *
  118.      * @access private
  119.      * @var string $output 
  120.      */
  121.     var $output;
  122.  
  123.     /**
  124.      * Return output?
  125.      *
  126.      * @access private
  127.      * @var integer $return 
  128.      */
  129.     var $return;
  130.  
  131.     /**
  132.      * Parse text for output?
  133.      *
  134.      * @access private
  135.      * @var integer $parse 
  136.      */
  137.     var $parse;
  138.  
  139.     /**
  140.      * Current tab index value
  141.      *
  142.      * @access private
  143.      * @var integer $tabindex 
  144.      */
  145.     var $tabindex;
  146.  
  147.     /**
  148.      * File upload mode
  149.      *
  150.      * @access private
  151.      * @since 1.13 - 2002/01/23
  152.      * @var integer $fileupload 
  153.      */
  154.     var $fileupload;
  155.  
  156.     /**
  157.      * ==============================================================================*
  158.      * |                             Methods: Base                                    |
  159.      * ==============================================================================
  160.      */
  161.  
  162.     /**
  163.      * Constructor
  164.      *
  165.      * @access public
  166.      * @return boolean Always returns true
  167.      */
  168.     function pnHTML()
  169.     {
  170.         $this->header array ();
  171.         $this->output '';
  172.         $this->return _PNH_KEEPOUTPUT;
  173.         $this->parse _PNH_PARSEINPUT;
  174.         $this->tabindex 0;
  175.         $this->fileupload 0;
  176.         return true;
  177.     }
  178.  
  179.     /**
  180.      * Return the current state of the output stream
  181.      *
  182.      * @access public
  183.      * @since 1.13 - 2002/01/23
  184.      * @return integer Current output state
  185.      * @see SetOutputMode()
  186.      */
  187.     function GetOutputMode()
  188.     {
  189.         // The ONLY time this should be accessed directly
  190.         return $this->return;
  191.     }
  192.  
  193.     /**
  194.      * Set state of the output stream
  195.      *
  196.      * @access public
  197.      * @since 1.14 - 2002/01/29
  198.      * @param int $st Output state to set to
  199.      * @return integer Previous state
  200.      * @see GetOutputMode()
  201.      */
  202.     function SetOutputMode($st)
  203.     {
  204.         $pre $this->GetOutputMode();
  205.         switch ($st{
  206.             default:
  207.             case _PNH_KEEPOUTPUT{
  208.                 // The ONLY time this should be accessed directly
  209.                 $this->return _PNH_KEEPOUTPUT;
  210.                 break;
  211.             }
  212.             case _PNH_RETURNOUTPUT{
  213.                 // The ONLY time this should be accessed directly
  214.                 $this->return _PNH_RETURNOUTPUT;
  215.                 break;
  216.             }
  217.         }
  218.         return $pre;
  219.     }
  220.  
  221.     /**
  222.      * Retrive the current input state
  223.      *
  224.      * @access public
  225.      * @since 1.13 - 2002/01/23
  226.      * @return integer Current input state
  227.      * @see SetInputMode()
  228.      */
  229.     function GetInputMode()
  230.     {
  231.         // The ONLY time this should be accessed directly
  232.         return $this->parse;
  233.     }
  234.  
  235.     /**
  236.      * Set state of the input stream
  237.      *
  238.      * @access public
  239.      * @since 1.14 - 2002/01/29
  240.      * @param int $st Input state to set to
  241.      * @return integer Previous state
  242.      * @see GetInputMode()
  243.      */
  244.     function SetInputMode($st)
  245.     {
  246.         $pre $this->GetInputMode();
  247.         switch ($st{
  248.             case _PNH_VERBATIMINPUT{
  249.                 // The ONLY time this should be accessed directly
  250.                 $this->parse _PNH_VERBATIMINPUT;
  251.                 break;
  252.             }
  253.             default:
  254.             case _PNH_PARSEINPUT{
  255.                 // The ONLY time this should be accessed directly
  256.                 $this->parse _PNH_PARSEINPUT;
  257.                 break;
  258.             }
  259.         }
  260.         return $pre;
  261.     }
  262.  
  263.     /**
  264.      * Set the form to allow file uploads to take place
  265.      *
  266.      * @access public
  267.      * @since 1.13 - 2002/01/23
  268.      * @return boolean Always returns true
  269.      * @see FormStart(), FormFile()
  270.      */
  271.     function UploadMode()
  272.     {
  273.         $this->fileupload 1;
  274.         return true;
  275.     }
  276.  
  277.     /**
  278.      * ==============================================================================*
  279.      * |                            Methods: Output                                   |
  280.      * ==============================================================================
  281.      */
  282.  
  283.     /**
  284.      * Return the HTML output from the buffer.
  285.      *
  286.      * Note that this function does not clear out the object's buffer.
  287.      *
  288.      * @access public
  289.      * @since 1.15 - 2002/01/30
  290.      * @return string An HTML string
  291.      */
  292.     function GetOutput()
  293.     {
  294.         return implode($this->header"\n""\n" $this->output;
  295.     }
  296.  
  297.     /**
  298.      * Print the HTML currently held in the object.
  299.      *
  300.      * Note that this function does not clear out the object's buffer.
  301.      *
  302.      * @access public
  303.      */
  304.     function PrintPage()
  305.     {
  306.         // Headers set by the system
  307.         foreach ($this->header as $headerline{
  308.             header($headerline);
  309.         }
  310.  
  311.         // Other headers
  312.         // Removed as per patch #264 bvdbos
  313.         // header('Content-length: ' . strlen($this->output));
  314.         print $this->output;
  315.     }
  316.  
  317.     /**
  318.      * ==============================================================================*
  319.      * |                             Methods: Misc                                    |
  320.      * ==============================================================================
  321.      */
  322.  
  323.     /**
  324.      * Put the appropriate HTML tags in place to create a valid start to HTML output.
  325.      *
  326.      * @access public
  327.      * @return string An HTML string if <code>ReturnHTML()</code> has been called,
  328.      *  otherwise null
  329.      * @see EndPage()
  330.      */
  331.     function StartPage()
  332.     {
  333.         ob_start();
  334.         include 'header.php';
  335.         //        print '<table width="100%" border="0" cellpadding="0" cellspacing="0">';
  336.         // Fixes bug 16 Neo submitted by keops 14/09/2002
  337.         // Remove extra table on output for XTE for .726
  338.         // print '<table width="100%" border="0" cellpadding="0" cellspacing="0"><tr><td align="left" valign="top">';
  339.  
  340.         $output ob_get_contents();
  341.         @ob_end_clean();
  342.  
  343.         if ($this->GetOutputMode(== _PNH_RETURNOUTPUT)
  344.         {
  345.             return $output;
  346.         else {
  347.             $this->output .= $output;
  348.         }
  349.     }
  350.  
  351.     /**
  352.      * Put the appropriate HTML tags in place to create a valid end to HTML output.
  353.      *
  354.      * @access public
  355.      * @return string An HTML string if <code>ReturnHTML()</code> has been called,
  356.      *  otherwise null
  357.      * @see StartPage()
  358.      */
  359.     function EndPage()
  360.     {
  361.         global $index;
  362.         if (FormUtil::getPassedValue('module'false'GETPOST')) {
  363.             $index 0;
  364.         else {
  365.             $index 1;
  366.         }
  367.         ob_start();
  368.         //if (!class_exists('Xanthia')) {
  369.             // Do we really need an extra table here? - markwest
  370.             // Not just with Xanthia themes but rendered modules
  371.             // This prevents this like RSS theme overrrides etc.
  372.             //print '</td></tr></table><!-- testing tables footer -->';
  373.         //}
  374.         include 'footer.php';
  375.         $output ob_get_contents();
  376.         @ob_end_clean();
  377.  
  378.         if ($this->GetOutputMode(== _PNH_RETURNOUTPUT{
  379.             return $output;
  380.         else {
  381.             $this->output .= $output;
  382.         }
  383.     }
  384.  
  385.     /**
  386.      *
  387.      * @access public
  388.      * @author Greg 'Adam Baum'
  389.      * @since 1.13 - 2002/01/23
  390.      * @param integer $startnum start iteam
  391.      * @param integer $total total number of items present
  392.      * @param string $urltemplate template for url, will replace '%%' with item number
  393.      * @param integer $perpage number of links to display (default=10)
  394.      */
  395.     function Pager($startnum$total$urltemplate$perpage 10)
  396.     {
  397.         // Quick check to ensure that we have work to do
  398.         if ($total <= $perpage{
  399.             return;
  400.         }
  401.         $compoutput new pnHTML();
  402.  
  403.         if (empty($startnum)) {
  404.             $startnum 1;
  405.         }
  406.  
  407.         if (empty($perpage)) {
  408.             $perpage 10;
  409.         }
  410.         // Make << and >> do paging properly
  411.         // Display subset of pages if large number
  412.  
  413.         // Check that we are needed
  414.         if ($total <= $perpage{
  415.             return;
  416.         }
  417.  
  418.         // Show Introtext for WCAG
  419.         $compoutput->Text(_PAGE.' ');
  420.  
  421.         // Show startnum link
  422.         if ($startnum != 1{
  423.             $url preg_replace('/%%/'1$urltemplate);
  424.             $compoutput->URL($url'<<');
  425.         else {
  426.             $compoutput->Text('<<');
  427.         }
  428.         $compoutput->Text(' ');
  429.  
  430.         // Show following items
  431.         $pagenum 1;
  432.  
  433.         $compoutput->Text(' | ');
  434.         for ($curnum 1$curnum <= $total$curnum += $perpage{
  435.             if (($startnum $curnum|| ($startnum ($curnum $perpage 1))) {
  436.                 //mod by marsu - use sliding window for pagelinks
  437.                 if ((($pagenum%10)==0// link if page is multiple of 10
  438.                         || ($pagenum==1// link first page
  439.                         || (($curnum >($startnum-4*$perpage)) //link -3 and +3 pages
  440.                         &&($curnum <($startnum+4*$perpage)))
  441.                 {
  442.                 // Not on this page - show link
  443.                 $url preg_replace('/%%/'$curnum$urltemplate);
  444.                 $compoutput->URL($url$pagenum);
  445.                 $compoutput->Text(' | ');
  446.                 }
  447.                 //end mod by marsu
  448.             else {
  449.                 // On this page - show text
  450.                 $compoutput->Text($pagenum.' ');
  451.                 $compoutput->Text(' | ');
  452.             }
  453.             $pagenum++;
  454.         }
  455.         if (($curnum >= $perpage 1&& ($startnum $curnum $perpage)) {
  456.             $url preg_replace('/%%/'$curnum $perpage$urltemplate);
  457.             $compoutput->URL($url'>>');
  458.         else {
  459.             $compoutput->Text('>>');
  460.         }
  461.  
  462.         if ($this->GetOutputMode(== _PNH_RETURNOUTPUT{
  463.             $compoutput->SetOutputMode(_PNH_RETURNOUTPUT);
  464.             return $compoutput->PrintPage();
  465.         else {
  466.             $this->output .= $compoutput->GetOutput();
  467.         }
  468.     }
  469.  
  470.     /**
  471.      * Redirect the user to another page
  472.      *
  473.      * This function is broken, do not use it!
  474.      *
  475.      * @access public
  476.      * @param string $url URL to redirect to
  477.      * @param integer $waittime Seconds to wait before redirecting
  478.      * @return string An HTML string if <code>ReturnHTML()</code> has been called,
  479.      *  otherwise null
  480.      * @todo This function is broken, do not use it!
  481.      */
  482.     function Redirect($url$waittime 3)
  483.     {
  484.         $server pnServerGetVar('HTTP_HOST');
  485.         $self pnServerGetVar('PHP_SELF');
  486.  
  487.         // Removing leading slashes from path
  488.         $path preg_replace('!^/*!'''dirname($self));
  489.  
  490.         // Removing leading slashes from redirect url
  491.         $url preg_replace('!^/*!'''$url);
  492.  
  493.         // Make redirect line
  494.         if (empty ($path)) {
  495.             $output "Location: http://$server/$url";
  496.         else {
  497.             $output "Location: http://$server/$path/$url";
  498.         }
  499.  
  500.         if ($this->GetOutputMode(== _PNH_RETURNOUTPUT{
  501.             return $output;
  502.         else {
  503.             $this->header[$output;
  504.         }
  505.     }
  506.  
  507.     /**
  508.      * composite function for generic confirmation of action
  509.      *
  510.      * @param string $confirm_text Confirmation message to display
  511.      * @param string $confirm_url URL to go to if confirm button is clicked
  512.      * @param string $cancel_text Link text cor the cancel message
  513.      * @param string $cancel_url URL to go to is action is canceled
  514.      * @param array $arg An array of args to create hidden fields for
  515.      *
  516.      * @access public
  517.      */
  518.     function ConfirmAction($confirm_text$confirm_url$cancel_text$cancel_url$arg array ())
  519.     {
  520.         $compoutput new pnHTML();
  521.         $compoutput->FormStart($confirm_url);
  522.  
  523.         $compoutput->Text($confirm_text);
  524.         $compoutput->Linebreak(2);
  525.         $arg['confirm'1;
  526.         $arg['authid'pnSecGenAuthKey();
  527.         $arg['confirmation'1;
  528.         $compoutput->FormHidden($arg);
  529.         $compoutput->FormSubmit(_CONFIRM);
  530.         $compoutput->Linebreak(2);
  531.         $compoutput->URL($cancel_url$cancel_text);
  532.         $compoutput->FormEnd();
  533.         if ($this->GetOutputMode(== _PNH_RETURNOUTPUT{
  534.             $compoutput->SetOutputMode(_PNH_RETURNOUTPUT);
  535.             return $compoutput->PrintPage();
  536.         else {
  537.             $compoutput->SetOutputMode(_PNH_RETURNOUTPUT);
  538.             $this->output .= $compoutput->GetOutput();
  539.         }
  540.     }
  541.  
  542.     /**
  543.      * ==============================================================================*
  544.      * |                             Methods: Text                                    |
  545.      * ==============================================================================
  546.      */
  547.  
  548.     /**
  549.      * Add free-form text to the object's buffer
  550.      *
  551.      * @access public
  552.      * @param string $text The text string to add
  553.      * @return string An HTML string if <code>ReturnHTML()</code> has been called,
  554.      *  otherwise null
  555.      */
  556.     function Text($text)
  557.     {
  558.         if ($this->GetInputMode(== _PNH_PARSEINPUT{
  559.             $text DataUtil::formatForDisplay($text);
  560.         }
  561.  
  562.         if ($this->GetOutputMode(== _PNH_RETURNOUTPUT{
  563.             return $text;
  564.         else {
  565.             $this->output .= $text;
  566.         }
  567.     }
  568.  
  569.     /**
  570.      * Add free-form text to the object's buffer as a title
  571.      *
  572.      * @access public
  573.      * @param string $text the text string to add
  574.      * @return string An HTML string if <code>ReturnHTML()</code> has been called,
  575.      *  otherwise null
  576.      */
  577.     function PageTitle($text)
  578.     {
  579.         $output '<h1>';
  580.  
  581.         if ($this->GetInputMode(== _PNH_PARSEINPUT{
  582.             $output .= DataUtil::formatForDisplay($text);
  583.         else {
  584.             $output .= $text;
  585.         }
  586.         $output .= '</h1>';
  587.  
  588.         if ($this->GetOutputMode(== _PNH_RETURNOUTPUT{
  589.             return $output;
  590.         else {
  591.             $this->output .= $output;
  592.         }
  593.     }
  594.  
  595.     /**
  596.      * Add free-form text to the object's buffer as a title
  597.      *
  598.      * @access public
  599.      * @param string $text the text string to add
  600.      * @return string An HTML string if <code>ReturnHTML()</code> has been called,
  601.      *  otherwise null
  602.      */
  603.     function Title($text)
  604.     {
  605.         $output '<h2>';
  606.  
  607.         if ($this->GetInputMode(== _PNH_PARSEINPUT{
  608.             $output .= DataUtil::formatForDisplay($text);
  609.         else {
  610.             $output .= $text;
  611.         }
  612.         $output .= '</h2>';
  613.  
  614.         if ($this->GetOutputMode(== _PNH_RETURNOUTPUT{
  615.             return $output;
  616.         else {
  617.             $this->output .= $output;
  618.         }
  619.     }
  620.  
  621.     /**
  622.      * add bold text to the object's buffer
  623.      *
  624.      * @access public
  625.      * @param string $text the text string to add
  626.      * @return string An HTML string if <code>ReturnHTML()</code> has been called,
  627.      *  otherwise null
  628.      */
  629.     function BoldText($text)
  630.     {
  631.         if ($this->GetOutputMode(== _PNH_RETURNOUTPUT{
  632.             return '<strong>' DataUtil::formatForDisplay($text'</strong>';
  633.         else {
  634.             $this->output .= '<strong>' DataUtil::formatForDisplay($text'</strong>';
  635.         }
  636.     }
  637.  
  638.     /**
  639.      * Add line break
  640.      *
  641.      * @access public
  642.      * @param integer $numbreaks number of linebreaks to add
  643.      * @return string An HTML string if <code>ReturnHTML()</code> has been called,
  644.      *  otherwise null
  645.      */
  646.     function Linebreak($numbreaks 1)
  647.     {
  648.         $out '';
  649.         for ($i 0$i $numbreaks$i++{
  650.             $out .= '<br />';
  651.         }
  652.         if ($this->GetOutputMode(== _PNH_RETURNOUTPUT{
  653.             return $out;
  654.         else {
  655.             $this->output .= $out;
  656.         }
  657.     }
  658.  
  659.     /**
  660.      * Add HTML tags for a hotlink.
  661.      *
  662.      * @access public
  663.      * @since 1.13 - 2002/01/23
  664.      * @param string $url the URL of the link
  665.      * @param string $text the text that the URL is anchored to
  666.      * @return string An HTML string if <code>ReturnHTML()</code> has been called,
  667.      *  otherwise null
  668.      */
  669.     function URL($url=''$text='')
  670.     {
  671.         if (empty ($url)) {
  672.             return;
  673.         }
  674.  
  675.         $output '<a href="' $url '" ';
  676.         if (!empty($text)) {
  677.             if ($this->GetInputMode(== _PNH_PARSEINPUT{
  678.                 $text DataUtil::formatForDisplay($text);
  679.             }
  680.             $title strip_tags($text);
  681.             if (empty($title)) {
  682.                 $output .= '>'.$text;
  683.             else {
  684.                 $output .= 'title="' $title '">'.$text;
  685.             }
  686.         else {
  687.             $output .= '>' $url;
  688.         }
  689.         $output .= '</a>';
  690.  
  691.         if ($this->GetOutputMode(== _PNH_RETURNOUTPUT{
  692.             return $output;
  693.         else {
  694.             $this->output .= $output;
  695.         }
  696.     }
  697.  
  698.     /**
  699.      * ==============================================================================*
  700.      * |                           Methods: Tables                                    |
  701.      * ==============================================================================
  702.      */
  703.  
  704.     /**
  705.      * Add HTML tags for the start of a table.
  706.      *
  707.      * @access public
  708.      * @param string $title the title of the table
  709.      * @param array $headers an array of column headings
  710.      * @param integer $border size of table borders
  711.      * @param string $width the width of the table.  can be null if no width needs
  712.      *  to be specified
  713.      * @return string An HTML string if <code>ReturnHTML()</code> has been called,
  714.      *  otherwise null
  715.      */
  716.     function TableStart($title ''$headers array()$border 0$width '100%'$cellpadding 0$cellspacing 0)
  717.     {
  718.         // Wrap the user table in our own invisible table to make the title sit properly
  719.         $output '<table border="' $border '"' ((empty ($width)) '' ' width="' $width '"'' cellpadding="' $cellpadding '" cellspacing="' $cellspacing "\">\n";
  720.         if (!empty ($title)) {
  721.             if ($this->GetInputMode(== _PNH_PARSEINPUT{
  722.                 $title DataUtil::formatForDisplay($title);
  723.             }
  724.             $output .= '<tr><th align="center">' $title '</th></tr>' "\n";
  725.         }
  726.         $output .= "<tr><td>\n";
  727.  
  728.         if ($this->GetInputMode(== _PNH_PARSEINPUT{
  729.             $border DataUtil::formatForDisplay($border);
  730.         }
  731.         $output .= '<table border="' $border '" width="100%">';
  732.         // Add column headers
  733.         if (!empty ($headers)) {
  734.             $output .= '<tr>';
  735.             foreach ($headers as $head{
  736.                 if (empty ($head)) {
  737.                     $head '&nbsp;';
  738.                 }
  739.                 if ($this->GetInputMode(== _PNH_PARSEINPUT{
  740.                     $head DataUtil::formatForDisplay($head);
  741.                 }
  742.                 $output .= '<th>' $head '</th>';
  743.             }
  744.             $output .= '</tr>';
  745.         }
  746.         if ($this->GetOutputMode(== _PNH_RETURNOUTPUT{
  747.             return $output;
  748.         else {
  749.             $this->output .= $output;
  750.         }
  751.     }
  752.  
  753.     /**
  754.      * Add HTML tags for the start of a table row.
  755.      *
  756.      * @access public
  757.      * @param string $align Default horizantal alignment for all columns on this row
  758.      * @param string $valign Default vertical alignment for all columns on this row
  759.      * @return string An HTML string if <code>ReturnHTML()</code> has been called,
  760.      *  otherwise null
  761.      */
  762.     function TableRowStart($align 'center'$valign 'middle')
  763.     {
  764.         $output '<tr align="' $align '" valign="' $valign '">';
  765.         if ($this->GetOutputMode(== _PNH_RETURNOUTPUT{
  766.             return $output;
  767.         else {
  768.             $this->output .= $output;
  769.         }
  770.     }
  771.  
  772.     /**
  773.      * Add HTML tags for the start of a table column.
  774.      *
  775.      * @access public
  776.      * @param integer $colspan number of columns that this column spans
  777.      * @param string $align Horizantal alignment of the column
  778.      * @param string $valign Vertical alignment of this column
  779.      * @param integer $rowspan Total rows this column uses
  780.      * @return string An HTML string if <code>ReturnHTML()</code> has been called,
  781.      *  otherwise null
  782.      */
  783.     function TableColStart($colspan 1$align 'center'$valign 'middle'$rowspan 1)
  784.     {
  785.         $output '<td colspan="' $colspan '" rowspan="' $rowspan '" align="' $align '" valign="' $valign '">';
  786.         if ($this->GetOutputMode(== _PNH_RETURNOUTPUT{
  787.             return $output;
  788.         else {
  789.             $this->output .= $output;
  790.         }
  791.     }
  792.  
  793.     /**
  794.      * Add HTML tags for the end of a table column.
  795.      *
  796.      * @access public
  797.      * @return string An HTML string if <code>ReturnHTML()</code> has been called,
  798.      *  otherwise null
  799.      */
  800.     function TableColEnd()
  801.     {
  802.         $output '</td>';
  803.         if ($this->GetOutputMode(== _PNH_RETURNOUTPUT{
  804.             return $output;
  805.         else {
  806.             $this->output .= $output;
  807.         }
  808.     }
  809.  
  810.     /**
  811.      * Add HTML tags for the end of a table row.
  812.      *
  813.      * @access public
  814.      * @return string An HTML string if <code>ReturnHTML()</code> has been called,
  815.      *  otherwise null
  816.      */
  817.     function TableRowEnd()
  818.     {
  819.         $output '</tr>';
  820.         if ($this->GetOutputMode(== _PNH_RETURNOUTPUT{
  821.             return $output;
  822.         else {
  823.             $this->output .= $output;
  824.         }
  825.     }
  826.  
  827.     /**
  828.      * Add HTML tags for the end of a table.
  829.      *
  830.      * @access public
  831.      * @return string An HTML string if <code>ReturnHTML()</code> has been called,
  832.      *  otherwise null
  833.      */
  834.     function TableEnd()
  835.     {
  836.         $output '</table></td></tr></table>';
  837.         if ($this->GetOutputMode(== _PNH_RETURNOUTPUT{
  838.             return $output;
  839.         else {
  840.             $this->output .= $output;
  841.         }
  842.     }
  843.  
  844.     /**
  845.      * Add HTML tags for a row of a table.
  846.      *
  847.      * @access public
  848.      * @param array $row an array of row entries
  849.      * @param string $align (optional) the alignment of the row, which can be
  850.      *  one of <code>'left'</code>, <code>'center'</code> or <code>'right'</code>
  851.      * @return string An HTML string if <code>ReturnHTML()</code> has been called,
  852.      *  otherwise null
  853.      */
  854.     function TableAddRow($row$align 'center'$valign 'middle')
  855.     {
  856.         if (empty ($row)) {
  857.             return;
  858.         }
  859.         $output '<tr align="' $align '" valign="' $valign.'">';
  860.         // test to see if we are using the latest array style
  861.         if (is_array($row[0])) {
  862.             // new style
  863.             foreach ($row as $rowitem{
  864.                 if (!isset($rowitem['content'])) {
  865.                     $rowitem['content''&nbsp;';
  866.                 }
  867.                 if ($this->GetInputMode()) {
  868.                     $rowitem['content'DataUtil::formatForDisplay($rowitem['content']);
  869.                 }
  870.                 $output .= '<td'
  871.                     .((empty ($rowitem['align'])) '' ' align="'.$rowitem['align'].'"')
  872.                     .((empty ($rowitem['valign'])) '' ' valign="'.$rowitem['valign'].'"')
  873.                     .((empty ($rowitem['color'])) '' ' bgcolor="'.$rowitem['color'].'"')
  874.                     .'>'
  875.                     .((empty ($rowitem['class'])) $rowitem['content'$rowitem['content'])
  876.                     .'</td>';
  877.             }
  878.         else {
  879.             // old style
  880.             foreach ($row as $rowitem{
  881.                 if (!isset($rowitem)) {
  882.                     $rowitem '&nbsp;';
  883.                 }
  884.                 if ($this->GetInputMode(== _PNH_PARSEINPUT{
  885.                     $rowitem DataUtil::formatForDisplay($rowitem);
  886.                 }
  887.                 $output .= '<td>' $rowitem '</td>';
  888.             }
  889.         }
  890.         $output .= '</tr>';
  891.         if ($this->GetOutputMode(== _PNH_RETURNOUTPUT{
  892.             return $output;
  893.         else {
  894.             $this->output .= $output;
  895.         }
  896.     }
  897.  
  898.     /**
  899.      * ==============================================================================*
  900.      * |                             Methods: Forms                                   |
  901.      * ==============================================================================
  902.      */
  903.  
  904.     /**
  905.      * Add HTML tags to start a form.
  906.      *
  907.      * @access public
  908.      * @param string $action the URL that this form should go to on submission
  909.      * @param string $id OPTIONAL - the unique ID of this form
  910.      * @return string An HTML string if <code>ReturnHTML()</code> has been called,
  911.      *  otherwise null
  912.      */
  913.     function FormStart($action$id='')
  914.     {
  915.         $output '<form'
  916.             .' action="'.DataUtil::formatForDisplay($action).'"'
  917.             .' method="post"'
  918.             .' enctype="'.((empty ($this->fileupload)) 'application/x-www-form-urlencoded' 'multipart/form-data').'"';
  919.         if ($id != ''{
  920.           $output .= ' id="'.DataUtil::formatForDisplay($id).'"';
  921.         }
  922.         $output .= '><div>';
  923.  
  924.         if ($this->GetOutputMode(== _PNH_RETURNOUTPUT{
  925.             return $output;
  926.         else {
  927.             $this->output .= $output;
  928.         }
  929.     }
  930.  
  931.     /**
  932.      * Add HTML tags to end a form.
  933.      *
  934.      * @access public
  935.      * @return string An HTML string if <code>ReturnHTML()</code> has been called,
  936.      *  otherwise null
  937.      */
  938.     function FormEnd()
  939.     {
  940.         $output '</div></form>';
  941.  
  942.         if ($this->GetOutputMode(== _PNH_RETURNOUTPUT{
  943.             return $output;
  944.         else {
  945.             $this->output .= $output;
  946.         }
  947.     }
  948.  
  949.     /**
  950.      * Add HTML tags for a submission button as part of a form.
  951.      *
  952.      * @access public
  953.      * @param string $label (optional) the name of the submission button.  This
  954.      *  defaults to <code>'Submit'</code>
  955.      * @param string $accesskey (optional) accesskey to active this button
  956.      * @param string $name (optional) name for this button
  957.      * @return string An HTML string if <code>ReturnHTML()</code> has been called,
  958.      *  otherwise null
  959.      */
  960.     function FormSubmit($label 'Submit'$accesskey ''$name '')
  961.     {
  962.         $this->tabindex++;
  963.         $output '<input'
  964.             .' type="submit"'
  965.             .' value="'.DataUtil::formatForDisplay($label).'"'
  966.             .((empty ($name)) '' ' name="'.DataUtil::formatForDisplay($name).'"')
  967.             //.' align="middle"'
  968.             .((empty ($accesskey)) '' ' accesskey="'.DataUtil::formatForDisplay($accesskey).'"')
  969.             .' tabindex="'.$this->tabindex.'"'
  970.             .' />'
  971.         ;
  972.         if ($this->GetOutputMode(== _PNH_RETURNOUTPUT)
  973.         {
  974.             return $output;
  975.         else {
  976.             $this->output .= $output;
  977.         }
  978.     }
  979.  
  980.     /**
  981.      * Add HTML tags for a text field as part of a form.
  982.      *
  983.      * @access public
  984.      * @param string $fieldname the name of the text field
  985.      * @param string $contents (optional) the inital value of the text field
  986.      * @param integer $size (optional) the size of the text field on the page
  987.      *  in number of characters
  988.      * @param integer $maxlength (optional) the maximum number of characters the
  989.      *  text field can hold
  990.      * @param boolean $password (optional) field acts as a password field
  991.      * @param string $accesskey (optional) accesskey to active this item
  992.      * @return string An HTML string if <code>ReturnHTML()</code> has been called,
  993.      *  otherwise null
  994.      */
  995.     function FormText($fieldname$contents ''$size 16$maxlength 64$password false$accesskey '')
  996.     {
  997.         if (empty ($fieldname)) {
  998.             return;
  999.         }
  1000.         $this->tabindex++;
  1001.         $output '<input'
  1002.             .' type="'.(($password'password' 'text').'"'
  1003.             .' name="'.DataUtil::formatForDisplay($fieldname).'"'
  1004.             .' id="'.DataUtil::formatForDisplay($fieldname).'"'
  1005.             .' value="'.DataUtil::formatForDisplay($contents).'"'
  1006.             .' size="'.DataUtil::formatForDisplay($size).'"'
  1007.             .' maxlength="'.DataUtil::formatForDisplay($maxlength).'"'
  1008.             .((empty ($accesskey)) '' ' accesskey="'.DataUtil::formatForDisplay($accesskey).'"')
  1009.             .' tabindex="'.$this->tabindex.'"'
  1010.             .' />'
  1011.         ;
  1012.         if ($this->GetOutputMode(== _PNH_RETURNOUTPUT{
  1013.             return $output;
  1014.         else {
  1015.             $this->output .= $output;
  1016.         }
  1017.     }
  1018.  
  1019.     /**
  1020.      * Add HTML tags for a text area as part of a form
  1021.      *
  1022.      * @access public
  1023.      * @param string $fieldname the name of the text area filed
  1024.      * @param string $contents the initial value of the text area field
  1025.      * @param integer $rows the number of rows that the text area
  1026.      *  |        should cover
  1027.      * @param integer $cols the number of columns that the text area
  1028.      *  |        should cover
  1029.      * @param string $wrap (optional) wordwrap mode to use, either <code>'soft'</code> or <code>'hard'</code>
  1030.      * @param string $accesskey (optional) accesskey to active this item
  1031.      * @return string An HTML string if <code>ReturnHTML()</code> has been called,
  1032.      *  otherwise null
  1033.      */
  1034.     function FormTextArea($fieldname$contents ''$rows 6$cols 40$wrap 'soft'$accesskey '')
  1035.     {
  1036.         if (empty ($fieldname)) {
  1037.             return;
  1038.         }
  1039.         $this->tabindex++;
  1040.         $output '<textarea'
  1041.             .' name="'.DataUtil::formatForDisplay($fieldname).'"'
  1042.             .' id="'.DataUtil::formatForDisplay($fieldname).'"'
  1043.             //.' wrap="'.(($wrap = 'soft') ? 'soft' : 'hard').'"' // not proper HTML, but too useful to abandon yet
  1044.             .' rows="'.DataUtil::formatForDisplay($rows).'"'
  1045.             .' cols="'.DataUtil::formatForDisplay($cols).'"'
  1046.             .((empty ($accesskey)) '' ' accesskey="'.DataUtil::formatForDisplay($accesskey).'"')
  1047.             .' tabindex="'.$this->tabindex.'"'
  1048.             .'>'
  1049.             .DataUtil::formatForDisplay($contents)
  1050.             .'</textarea>';
  1051.         if ($this->GetOutputMode(== _PNH_RETURNOUTPUT)  {
  1052.             return $output;
  1053.         else {
  1054.             $this->output .= $output;
  1055.         }
  1056.     }
  1057.  
  1058.     /**
  1059.      * Add HTML tags for a hidden field as part of a form.
  1060.      *
  1061.      * @access public
  1062.      * @param mixed $fieldname the name of the hidden field.  can also be an array.
  1063.      * @param string $value the value of the hidden field
  1064.      * @return string An HTML string if <code>ReturnHTML()</code> has been called,
  1065.      *  otherwise null
  1066.      */
  1067.     function FormHidden($fieldname$value '')
  1068.     {
  1069.         if (empty ($fieldname)) {
  1070.             return;
  1071.         }
  1072.         if (is_array($fieldname)) {
  1073.             $output '';
  1074.             foreach ($fieldname as $n=>$v{
  1075.                 $output .= '<input'
  1076.                     .' type="hidden"'
  1077.                     .' name="'.DataUtil::formatForDisplay($n).'"'
  1078.                     //.' id="'.DataUtil::formatForDisplay($n).'"'
  1079.                     .' value="'.DataUtil::formatForDisplay($v).'"'
  1080.                     .'/>';
  1081.             }
  1082.         else {
  1083.             $output '<input'
  1084.                 .' type="hidden"'
  1085.                 .' name="'.DataUtil::formatForDisplay($fieldname).'"'
  1086.                 //.' id="'.DataUtil::formatForDisplay($fieldname).'"'
  1087.                 .' value="'.DataUtil::formatForDisplay($value).'"'
  1088.                 .' />';
  1089.         }
  1090.         if ($this->GetOutputMode(== _PNH_RETURNOUTPUT{
  1091.             return $output;
  1092.         else {
  1093.             $this->output .= $output;
  1094.         }
  1095.     }
  1096.  
  1097.     /**
  1098.      * Add HTML tags for a select field as part of a form.
  1099.      *
  1100.      * @access public
  1101.      * @since 1.13 - 2002/01/23
  1102.      * @param string $fieldname the name of the select field
  1103.      * @param array $data an array containing the data for the list.  Each array
  1104.      *  entry is itself an array, containing the values for <code>'id'</code>
  1105.      *  (the value returned if the entry is selected), <code>'name'</code>
  1106.      *  (the string displayed for this entry) and <code>'selected'</code>
  1107.      *  (optional, <code>1</code> if this option is selected)
  1108.      * @param integer $multiple (optional) <code>1</code> if the user is allowed to
  1109.      *  make multiple selections
  1110.      * @param integer $size (optional) the number of entries that are visible in the
  1111.      *  select at any one time.  Note that if the number
  1112.      *  of actual items is less than this value then the select box will
  1113.      *  shrink automatically to the correct size
  1114.      * @param string $selected (optional) selected value of <code>id</code>
  1115.      * @param string $accesskey (optional) accesskey to active this item
  1116.      * @param string $events: javascript events
  1117.      * @return string An HTML string if <code>ReturnHTML()</code> has been called,
  1118.      *  otherwise null
  1119.      */
  1120.     function FormSelectMultiple($fieldname$data$multiple=0$size=1$selected ''$accesskey=''$events='')
  1121.     {
  1122.         if (empty ($fieldname)) {
  1123.             return;
  1124.         }
  1125.         $this->tabindex++;
  1126.  
  1127.         // Set up selected if required
  1128.         if (!empty($selected)) {
  1129.             for ($i=0!empty($data[$i])$i++{
  1130.                 if ($data[$i]['id'== $selected{
  1131.                     $data[$i]['selected'1;
  1132.                 }
  1133.             }
  1134.         }
  1135.  
  1136.         $c count($data);
  1137.         if ($c $size{
  1138.             $size $c;
  1139.         }
  1140.         $output '<select'
  1141.             .' name="'.DataUtil::formatForDisplay($fieldname).'"'
  1142.             .' id="'.DataUtil::formatForDisplay($fieldname).'"'
  1143.             .' size="'.DataUtil::formatForDisplay($size).'"'
  1144.             .(($multiple == 1' multiple="multiple"' '')
  1145.             .((empty ($accesskey)) '' ' accesskey="'.DataUtil::formatForDisplay($accesskey).'"')
  1146.             .' tabindex="'.$this->tabindex.'"';
  1147.  
  1148.         if ($events != ''{
  1149.             $output .= ' '.$events;
  1150.         }
  1151.  
  1152.         $output .= '>';
  1153.  
  1154.         foreach ($data as $datum{
  1155.             $output .= '<option'
  1156.                 .' value="'.DataUtil::formatForDisplay($datum['id']).'"'
  1157.                 .((empty ($datum['selected'])) '' ' selected="selected"')
  1158.                 .'>'
  1159.                 .DataUtil::formatForDisplay($datum['name'])
  1160.                 .'</option>';
  1161.         }
  1162.         $output .= '</select>';
  1163.         if ($this->GetOutputMode(== _PNH_RETURNOUTPUT{
  1164.             return $output;
  1165.         else {
  1166.             $this->output .= $output;
  1167.         }
  1168.     }
  1169.  
  1170.     /**
  1171.      * Add HTML tags for a checkbox or radio button field as part of a form.
  1172.      *
  1173.      * @access public
  1174.      * @since 1.13 - 2002/01/23
  1175.      * @param string $fieldname the name of the checkbox field
  1176.      * @param string $value (optional) the value of the checkbox field
  1177.      * @param boolean $checked (optional) the field is checked
  1178.      * @param string $type (optional) the type of field this is, either
  1179.      *  <code>'checkbox'</code> or <code>'radio'</code>
  1180.      * @param string $accesskey (optional) accesskey to active this item
  1181.      * @return string An HTML string if <code>ReturnHTML()</code> has been called,
  1182.      *  otherwise null
  1183.      */
  1184.     function FormCheckbox($fieldname$checked false$value '1'$type 'checkbox'$accesskey '')
  1185.     {
  1186.         if (empty ($fieldname)) {
  1187.             return;
  1188.         }
  1189.         $this->tabindex++;
  1190.         $output '<input'
  1191.             .' type="'.(($type == 'checkbox''checkbox' 'radio').'"'
  1192.             .' name="'.DataUtil::formatForDisplay($fieldname).'"'
  1193.             .' id="'.DataUtil::formatForDisplay($fieldname).'"'
  1194.             .' value="'.DataUtil::formatForDisplay($value).'"'
  1195.             .(($checked' checked="checked"' '')
  1196.             .((empty ($accesskey)) '' ' accesskey="'.DataUtil::formatForDisplay($accesskey).'"')
  1197.             .' tabindex="'.$this->tabindex.'"'
  1198.             .' />'
  1199.         ;
  1200.         if ($this->GetOutputMode(== _PNH_RETURNOUTPUT{
  1201.             return $output;
  1202.         else {
  1203.             $this->output .= $output;
  1204.         }
  1205.     }
  1206.  
  1207.     /**
  1208.      * Add HTML tags for a file upload field as part of a form.
  1209.      *
  1210.      * @access public
  1211.      * @since 1.13 - 2002/01/23
  1212.      * @param string $fieldname the name of the field
  1213.      * @param integer $size (optional) the size of the field on the page in number
  1214.      *  of characters
  1215.      * @param integer $maxsize (optional) the maximum file size allowed (in bytes)
  1216.      * @param string $accesskey (optional) accesskey to active this item
  1217.      * @return string An HTML string if <code>ReturnHTML()</code> has been called,
  1218.      *  otherwise null
  1219.      */
  1220.     function FormFile($fieldname$size 32$maxsize 1000000$accesskey '')
  1221.     {
  1222.         if (empty ($fieldname)) {
  1223.             return;
  1224.         }
  1225.         $this->tabindex++;
  1226.         $output '<input type="hidden" name="MAX_FILE_SIZE" value="'.DataUtil::formatForDisplay($maxsize).'" />';
  1227.         $output .= '<input'
  1228.             .' type="file"'
  1229.             .' name="'.DataUtil::formatForDisplay($fieldname).'"'
  1230.             .' id="'.DataUtil::formatForDisplay($fieldname).'"'
  1231.             .' size="'.DataUtil::formatForDisplay($size).'"'
  1232.             .((empty ($accesskey)) '' ' accesskey="'.DataUtil::formatForDisplay($accesskey).'"')
  1233.             .' tabindex="'.$this->tabindex.'"'
  1234.             .' />'
  1235.         ;
  1236.         if ($this->GetOutputMode(== _PNH_RETURNOUTPUT{
  1237.             return $output;
  1238.         else {
  1239.             $this->output .= $output;
  1240.         }
  1241.     }
  1242. }

Documentation generated on Fri, 18 Jul 2008 21:53:04 +0200 by phpDocumentor 1.4.1