2 // ----------------------------------------------------------------------
3 // POST-NUKE Content Management System
4 // Copyright (C) 2001 by the Post-Nuke Development Team.
5 // http://www.postnuke.com/
6 // ----------------------------------------------------------------------
8 // PHP-NUKE Web Portal System - http://phpnuke.org/
9 // Thatware - http://thatware.org/
10 // ----------------------------------------------------------------------
13 // This program is free software; you can redistribute it and/or
14 // modify it under the terms of the GNU General Public License (GPL)
15 // as published by the Free Software Foundation; either version 2
16 // of the License, or (at your option) any later version.
18 // This program is distributed in the hope that it will be useful,
19 // but WITHOUT ANY WARRANTY; without even the implied warranty of
20 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 // GNU General Public License for more details.
23 // To read the license please visit http://www.gnu.org/copyleft/gpl.html
24 // ----------------------------------------------------------------------
25 // Original Author of file: Jim McDonald
26 // Purpose of file: HTML helpers
27 // ----------------------------------------------------------------------
30 * Set object to keep generated HTML.
32 * After calling SetOutputMode() with this value, all future calls to
33 * pnHTML methods will store their HTML in the objecr rather than
34 * returning it to the calling process.
36 * $const _PNH_KEEPOUTPUT Keep the output from method calls
38 define('_PNH_KEEPOUTPUT', 0);
41 * Set object to return generated HTML to caller.
43 * After calling SetOutputMode() with this value, all future calls to
44 * pnHTML methods will return their HTML directly to the calling process
45 * rather than storing it within the object.
47 * $const _PNH_RETURNOUTPUT Return the output from method calls
49 define('_PNH_RETURNOUTPUT', 1);
52 * Set incoming text to be copied verbatim to the output buffer
54 * $const _PNH_VERBATIMINPUT Do not parse incoming text
56 define('_PNH_VERBATIMINPUT', 0);
59 * Set incoming text to be parsed for display before putting in the output buffer
61 * $const _PNH_PARSEINPUT Parse incoming text
63 define('_PNH_PARSEINPUT', 1);
66 * HTML creation and display functions
68 * This class is designed to make generating HTML output in PostNuke
69 * very simple, and also allows for much greater control of output by
70 * the site administrator.
75 * // Information array
76 * $colors = array(array('id' => 1,
78 * 'encoding' => 'ff0000'),
81 * 'encoding' => '00ff00'),
84 * 'encoding' => '0000ff'));
86 * // Create the HTML object and start it
87 * $myhtml = new pnHTML();
90 * // Add table showing encoding information
91 * $myhtml->TableStart('Colors and Their Encodings', array('Color', 'Encoding'));
92 * foreach ($colors as $color) {
93 * $info = array($color['name'], $color['encoding']);
94 * $myhtml->TableAddRow($info);
96 * $myhtml->TableEnd();
98 * // Add form to select a color
99 * $myhtml->Text('<P><P>');
100 * $myhtml->FormStart('colorchosen.php');
101 * $myhtml->Text('Select a color: ');
102 * $myhtml->FormList('chosen', $colorinfo);
103 * $myhtml->FormSubmit('That\'s the color I want');
104 * $myhtml->FormEnd();
107 * // End the HTML object and print it
109 * $myhtml->PrintPage();
113 * @author Jim McDonald
114 * @author Patrick Kellum
115 * @link http://www.postnuke.com/ The Official PostNuke website
116 * @copyright (C) 2001, 2002 by the Post-Nuke Development Team
117 * @version $Revision$
118 * @todo need to add text sanitizer
122 /*==============================================================================*
124 *==============================================================================*/
127 * Specific headers which must be printed prior to the main body of HTML
130 * @var string $header
135 * The pending HTML output
138 * @var string $output
146 * @var integer $return
151 * Parse text for output?
154 * @var integer $parse
159 * Current tab index value
162 * @var integer $tabindex
170 * @since 1.13 - 2002/01/23
171 * @var integer $fileupload
175 /*==============================================================================*
177 *==============================================================================*/
183 * @return boolean Always returns true
187 $this->header
= array ();
189 $this->return = _PNH_KEEPOUTPUT
;
190 $this->parse
= _PNH_PARSEINPUT
;
192 $this->fileupload
= 0;
197 * Return the current state of the output stream
200 * @since 1.13 - 2002/01/23
201 * @return integer Current output state
202 * @see SetOutputMode()
204 function GetOutputMode()
206 // The ONLY time this should be accessed directly
207 return $this->return;
211 * Set state of the output stream
214 * @since 1.14 - 2002/01/29
215 * @param int $st Output state to set to
216 * @return integer Previous state
217 * @see GetOutputMode()
219 function SetOutputMode($st)
221 $pre = $this->GetOutputMode();
224 case _PNH_KEEPOUTPUT
:
225 // The ONLY time this should be accessed directly
226 $this->return = _PNH_KEEPOUTPUT
;
228 case _PNH_RETURNOUTPUT
:
229 // The ONLY time this should be accessed directly
230 $this->return = _PNH_RETURNOUTPUT
;
238 * Retrive the current input state
241 * @since 1.13 - 2002/01/23
242 * @return integer Current input state
243 * @see SetInputMode()
245 function GetInputMode()
247 // The ONLY time this should be accessed directly
252 * Set state of the input stream
255 * @since 1.14 - 2002/01/29
256 * @param int $st Input state to set to
257 * @return integer Previous state
258 * @see GetInputMode()
260 function SetInputMode($st)
262 $pre = $this->GetInputMode();
264 case _PNH_VERBATIMINPUT
:
265 // The ONLY time this should be accessed directly
266 $this->parse
= _PNH_VERBATIMINPUT
;
269 case _PNH_PARSEINPUT
:
270 // The ONLY time this should be accessed directly
271 $this->parse
= _PNH_PARSEINPUT
;
279 * Set the form to allow file uploads to take place
282 * @since 1.13 - 2002/01/23
283 * @return boolean Always returns true
284 * @see FormStart(), FormFile()
286 function UploadMode()
288 $this->fileupload
= 1;
292 /*==============================================================================*
294 *==============================================================================*/
297 * Return the HTML output from the buffer.
299 * Note that this function does not clear out the object's buffer.
302 * @since 1.15 - 2002/01/30
303 * @return string An HTML string
307 return implode($this->header
, "\n")."\n".$this->output
;
311 * Print the HTML currently held in the object.
313 * Note that this function does not clear out the object's buffer.
319 // Headers set by the system
320 foreach ($this->header
as $headerline) {
325 // Removed as per patch #264 bvdbos
326 // header('Content-length: ' . strlen($this->output));
331 /*==============================================================================*
333 *==============================================================================*/
336 * Put the appropriate HTML tags in place to create a valid start to HTML output.
339 * @return string An HTML string if <code>ReturnHTML()</code> has been called,
346 include 'header.php';
347 // print '<table width="100%" border="0" cellpadding="0" cellspacing="0">';
348 /* Fixes bug 16 Neo submitted by keops 14/09/2002
350 print '<table width="100%" border="0" cellpadding="0" cellspacing="0"><tr><td align="left" valign="top">';
352 $output = ob_get_contents();
355 if ($this->GetOutputMode() == _PNH_RETURNOUTPUT
) {
358 $this->output
.= $output;
363 * Put the appropriate HTML tags in place to create a valid end to HTML output.
366 * @return string An HTML string if <code>ReturnHTML()</code> has been called,
373 if (pnVarCleanFromInput('module')) {
380 print '</td></tr></table>';
381 include 'footer.php';
382 $output = ob_get_contents();
385 if ($this->GetOutputMode() == _PNH_RETURNOUTPUT
) {
388 $this->output
.= $output;
395 * @author Greg 'Adam Baum'
396 * @since 1.13 - 2002/01/23
397 * @param integer $startnum start iteam
398 * @param integer $total total number of items present
399 * @param string $urltemplate template for url, will replace '%%' with item number
400 * @param integer $perpage number of links to display (default=10)
402 function Pager($startnum, $total, $urltemplate, $perpage = 10)
404 // Quick check to ensure that we have work to do
405 if ($total <= $perpage) {
409 $compoutput = new pnHTML();
411 if (empty($startnum)) {
415 if (empty($perpage)) {
419 // Make << and >> do paging properly
420 // Display subset of pages if large number
422 // Check that we are needed
423 if ($total <= $perpage) {
427 // Show startnum link
428 if ($startnum != 1) {
429 $url = preg_replace('/%%/', 1, $urltemplate);
430 $compoutput->URL($url, '<<');
432 $compoutput->Text('<<');
435 $compoutput->Text(' ');
437 // Show following items
440 for ($curnum = 1; $curnum <= $total; $curnum +
= $perpage) {
441 if (($startnum < $curnum) ||
($startnum > ($curnum +
$perpage - 1))) {
442 // Not on this page - show link
443 $url = preg_replace('/%%/', $curnum, $urltemplate);
444 $compoutput->URL($url, $pagenum);
445 $compoutput->Text(' ');
447 // On this page - show text
448 $compoutput->Text($pagenum.' ');
454 if (($curnum >= $perpage+
1) && ($startnum < $curnum-$perpage)) {
455 $url = preg_replace('/%%/', $curnum-$perpage, $urltemplate);
456 $compoutput->URL($url, '>>');
458 $compoutput->Text('>>');
461 if ($this->GetOutputMode() == _PNH_RETURNOUTPUT
) {
462 $compoutput->SetOutputMode(_PNH_RETURNOUTPUT
);
463 return $compoutput->PrintPage();
465 $this->output
.= $compoutput->GetOutput();
470 * Redirect the user to another page
472 * This function is broken, do not use it!
475 * @param string $url URL to redirect to
476 * @param integer $waittime Seconds to wait before redirecting
477 * @return string An HTML string if <code>ReturnHTML()</code> has been called,
479 * @todo This function is broken, do not use it!
481 function Redirect($url, $waittime = 3)
483 global $HTTP_SERVER_VARS;
485 $server = $HTTP_SERVER_VARS['HTTP_HOST'];
486 if (empty($server)) {
487 $server = getenv('HTTP_HOST');
490 $self = $HTTP_SERVER_VARS['PHP_SELF'];
492 $self = getenv('PHP_SELF');
495 // Removing leading slashes from path
496 $path = preg_replace('!^/*!', '', dirname($self));
498 // Removing leading slashes from redirect url
499 $url = preg_replace('!^/*!', '', $url);
501 // Make redirect line
503 $output = "Location: http://$server/$url";
505 $output = "Location: http://$server/$path/$url";
508 if ($this->GetOutputMode() == _PNH_RETURNOUTPUT
) {
511 $this->header
[] = $output;
516 * composite function for generic confirmation of action
518 * @param string $confirm_text Confirmation message to display
519 * @param string $confirm_url URL to go to if confirm button is clicked
520 * @param string $cancel_text Link text cor the cancel message
521 * @param string $cancel_url URL to go to is action is canceled
522 * @param array $arg An array of args to create hidden fields for
526 function ConfirmAction($confirm_text, $confirm_url, $cancel_text, $cancel_url, $arg = array ())
528 $compoutput = new pnHTML();
529 $compoutput->FormStart($confirm_url);
531 $compoutput->Text($confirm_text);
532 $compoutput->Linebreak(2);
534 $arg['authid'] = pnSecGenAuthKey();
535 $arg['confirmation'] = 1;
536 $compoutput->FormHidden($arg);
537 $compoutput->FormSubmit(_CONFIRM
);
538 $compoutput->Linebreak(2);
539 $compoutput->URL($cancel_url, $cancel_text);
540 $compoutput->FormEnd();
541 if ($this->GetOutputMode() == _PNH_RETURNOUTPUT
) {
542 $compoutput->SetOutputMode(_PNH_RETURNOUTPUT
);
543 return $compoutput->PrintPage();
545 $compoutput->SetOutputMode(_PNH_RETURNOUTPUT
);
546 $this->output
.= $compoutput->GetOutput();
550 /*==============================================================================*
552 *==============================================================================*/
555 * Add free-form text to the object's buffer
558 * @param string $text The text string to add
559 * @return string An HTML string if <code>ReturnHTML()</code> has been called,
564 if ($this->GetInputMode() == _PNH_PARSEINPUT
) {
565 $text = pnVarPrepForDisplay($text);
568 if ($this->GetOutputMode() == _PNH_RETURNOUTPUT
) {
571 $this->output
.= $text;
576 * Add free-form text to the object's buffer as a title
579 * @param string $text the text string to add
580 * @return string An HTML string if <code>ReturnHTML()</code> has been called,
583 function Title($text)
585 $output = '<center><font class="pn-title">';
587 if ($this->GetInputMode() == _PNH_PARSEINPUT
) {
588 $output .= pnVarPrepForDisplay($text);
593 $output .= '</font></center><br />';
595 if ($this->GetOutputMode() == _PNH_RETURNOUTPUT
) {
598 $this->output
.= $output;
603 * add bold text to the object's buffer
606 * @param string $text the text string to add
607 * @return string An HTML string if <code>ReturnHTML()</code> has been called,
610 function BoldText($text)
612 if ($this->GetOutputMode() == _PNH_RETURNOUTPUT
) {
613 return '<b>'.pnVarPrepForDisplay($text).'</b>';
615 $this->output
.= '<b>'.pnVarPrepForDisplay($text).'</b>';
623 * @param integer $numbreaks number of linebreaks to add
624 * @return string An HTML string if <code>ReturnHTML()</code> has been called,
627 function Linebreak($numbreaks = 1)
630 for ($i=0; $i<$numbreaks; $i++
) {
634 if ($this->GetOutputMode() == _PNH_RETURNOUTPUT
) {
637 $this->output
.= $out;
642 * Add HTML tags for a hotlink.
645 * @since 1.13 - 2002/01/23
646 * @param string $url the URL of the link
647 * @param string $text the text that the URL is anchored to
648 * @return string An HTML string if <code>ReturnHTML()</code> has been called,
651 function URL($url, $text)
657 $output = '<a href="'.$url.'">';
659 if ($this->GetInputMode() == _PNH_PARSEINPUT
) {
660 $text = pnVarPrepForDisplay($text);
668 if ($this->GetOutputMode() == _PNH_RETURNOUTPUT
) {
671 $this->output
.= $output;
675 /*==============================================================================*
677 *==============================================================================*/
680 * Add HTML tags for the start of a table.
683 * @param string $title the title of the table
684 * @param array $headers an array of column headings
685 * @param integer $border size of table borders
686 * @param string $width the width of the table. can be null if no width needs
688 * @return string An HTML string if <code>ReturnHTML()</code> has been called,
691 function TableStart($title = '', $headers = array(), $border = 0, $width = '100%', $cellpadding = 0, $cellspacing = 0)
694 // Wrap the user table in our own invisible table to make the title sit properly
695 $output = '<table border="'.$border.'"'.((empty($width)) ?
'' : ' width="'.$width.'"').' cellpadding="'.$cellpadding.'" cellspacing="'.$cellspacing."\">\n";
696 if (!empty($title)) {
697 if ($this->GetInputMode() == _PNH_PARSEINPUT
) {
698 $title = pnVarPrepForDisplay($title);
701 $output .= '<tr><th align="center">'. $title .'</th></tr>' . "\n";
704 $output .= "<tr><td>\n";
706 if ($this->GetInputMode() == _PNH_PARSEINPUT
) {
707 $border = pnVarPrepForDisplay($border);
710 $output .= '<table border="' . $border . '" width="100%">';
712 // Add column headers
713 if (!empty($headers)) {
715 foreach ($headers as $head) {
720 if ($this->GetInputMode() == _PNH_PARSEINPUT
) {
721 $head = pnVarPrepForDisplay($head);
724 $output .= '<th>' . $head . '</th>';
730 if ($this->GetOutputMode() == _PNH_RETURNOUTPUT
) {
733 $this->output
.= $output;
738 * Add HTML tags for the start of a table row.
741 * @param string $align Default horizantal alignment for all columns on this row
742 * @param string $valign Default vertical alignment for all columns on this row
743 * @return string An HTML string if <code>ReturnHTML()</code> has been called,
746 function TableRowStart($align = 'center', $valign = 'middle')
748 $output = '<tr align="'.$align.'" valign="'.$valign.'">';
749 if ($this->GetOutputMode() == _PNH_RETURNOUTPUT
) {
752 $this->output
.= $output;
757 * Add HTML tags for the start of a table column.
760 * @param integer $colspan number of columns that this column spans
761 * @param string $align Horizantal alignment of the column
762 * @param string $valign Vertical alignment of this column
763 * @param integer $rowspan Total rows this column uses
764 * @return string An HTML string if <code>ReturnHTML()</code> has been called,
767 function TableColStart($colspan = 1, $align = 'center', $valign = 'middle', $rowspan = 1)
769 $output = '<td colspan="'.$colspan.'" rowspan="'.$rowspan.'" align="'.$align.'" valign="'.$valign.'">';
770 if ($this->GetOutputMode() == _PNH_RETURNOUTPUT
) {
773 $this->output
.= $output;
778 * Add HTML tags for the end of a table column.
781 * @return string An HTML string if <code>ReturnHTML()</code> has been called,
784 function TableColEnd()
787 if ($this->GetOutputMode() == _PNH_RETURNOUTPUT
) {
790 $this->output
.= $output;
795 * Add HTML tags for the end of a table row.
798 * @return string An HTML string if <code>ReturnHTML()</code> has been called,
801 function TableRowEnd()
804 if ($this->GetOutputMode() == _PNH_RETURNOUTPUT
) {
807 $this->output
.= $output;
812 * Add HTML tags for the end of a table.
815 * @return string An HTML string if <code>ReturnHTML()</code> has been called,
820 $output = '</table></td></tr></table>';
821 if ($this->GetOutputMode() == _PNH_RETURNOUTPUT
) {
824 $this->output
.= $output;
829 * Add HTML tags for a row of a table.
832 * @param array $row an array of row entries
833 * @param string $align (optional) the alignment of the row, which can be
834 * one of <code>'left'</code>, <code>'center'</code> or <code>'right'</code>
835 * @return string An HTML string if <code>ReturnHTML()</code> has been called,
838 function TableAddRow($row, $align = 'center', $valign = 'middle')
844 $output = '<tr align="'.$align.'" valign="'.$valign.'">';
845 // test to see if we are using the latest array style
846 if (is_array($row[0])) {
848 foreach ($row as $rowitem) {
849 if (!isset($rowitem['content'])) {
850 $rowitem['content'] = ' ';
853 if ($this->GetInputMode()) {
854 $rowitem['content'] = pnVarPrepForDisplay($rowitem['content']);
858 .((empty($rowitem['align'])) ?
'' : ' align="'.$rowitem['align'].'"')
859 .((empty($rowitem['valign'])) ?
'' : ' valign="'.$rowitem['valign'].'"')
860 .'>'.$rowitem['content'].'</td>'
865 foreach ($row as $rowitem) {
866 if (!isset($rowitem)) {
870 if ($this->GetInputMode() == _PNH_PARSEINPUT
) {
871 $rowitem = pnVarPrepForDisplay($rowitem);
874 $output .= '<td>' . $rowitem . '</td>';
879 if ($this->GetOutputMode() == _PNH_RETURNOUTPUT
) {
882 $this->output
.= $output;
886 /*==============================================================================*
888 *==============================================================================*/
891 * Add HTML tags to start a form.
894 * @param string $action the URL that this form should go to on submission
895 * @return string An HTML string if <code>ReturnHTML()</code> has been called,
898 function FormStart($action)
901 .' action="'.pnVarPrepForDisplay($action).'"'
903 .' enctype="'.((empty($this->fileupload
)) ?
'application/x-www-form-urlencoded' : 'multipart/form-data').'"'
906 if ($this->GetOutputMode() == _PNH_RETURNOUTPUT
) {
909 $this->output
.= $output;
914 * Add HTML tags to end a form.
917 * @return string An HTML string if <code>ReturnHTML()</code> has been called,
924 if ($this->GetOutputMode() == _PNH_RETURNOUTPUT
) {
927 $this->output
.= $output;
932 * Add HTML tags for a submission button as part of a form.
935 * @param string $label (optional) the name of the submission button. This
936 * defaults to <code>'Submit'</code>
937 * @param string $accesskey (optional) accesskey to active this button
938 * @return string An HTML string if <code>ReturnHTML()</code> has been called,
941 function FormSubmit($label = 'Submit', $accesskey = '')
946 .' value="'.pnVarPrepForDisplay($label).'"'
948 .((empty($accesskey)) ?
'' : ' accesskey="'.pnVarPrepForDisplay($accesskey).'"')
949 .' tabindex="'.$this->tabindex
.'"'
952 if ($this->GetOutputMode() == _PNH_RETURNOUTPUT
) {
955 $this->output
.= $output;
960 * Add HTML tags for a text field as part of a form.
963 * @param string $fieldname the name of the text field
964 * @param string $contents (optional) the inital value of the text field
965 * @param integer $size (optional) the size of the text field on the page
966 * in number of characters
967 * @param integer $maxlength (optional) the maximum number of characters the
968 * text field can hold
969 * @param boolean $password (optional) field acts as a password field
970 * @param string $accesskey (optional) accesskey to active this item
971 * @return string An HTML string if <code>ReturnHTML()</code> has been called,
974 function FormText($fieldname, $contents = '', $size = 16, $maxlength = 64, $password = false, $accesskey = '')
976 if (empty($fieldname)) {
982 .' type="'.(($password) ?
'password' : 'text').'"'
983 .' name="'.pnVarPrepForDisplay($fieldname).'"'
984 .' id="'.pnVarPrepForDisplay($fieldname).'"'
985 .' value="'.pnVarPrepForDisplay($contents).'"'
986 .' size="'.pnVarPrepForDisplay($size).'"'
987 .' maxlength="'.pnVarPrepForDisplay($maxlength).'"'
988 .((empty($accesskey)) ?
'' : ' accesskey="'.pnVarPrepForDisplay($accesskey).'"')
989 .' tabindex="'.$this->tabindex
.'"'
992 if ($this->GetOutputMode() == _PNH_RETURNOUTPUT
) {
995 $this->output
.= $output;
1000 * Add HTML tags for a text area as part of a form
1003 * @param string $fieldname the name of the text area filed
1004 * @param string $contents the initial value of the text area field
1005 * @param integer $rows the number of rows that the text area
1007 * @param integer $cols the number of columns that the text area
1009 * @param string $wrap (optional) wordwrap mode to use, either <code>'soft'</code> or <code>'hard'</code>
1010 * @param string $accesskey (optional) accesskey to active this item
1011 * @return string An HTML string if <code>ReturnHTML()</code> has been called,
1014 function FormTextArea($fieldname, $contents = '', $rows = 6, $cols = 40, $wrap = 'soft', $accesskey = '')
1016 if (empty($fieldname)) {
1021 $output = '<textarea'
1022 .' name="'.pnVarPrepForDisplay($fieldname).'"'
1023 .' id="'.pnVarPrepForDisplay($fieldname).'"'
1024 .' wrap="'.(($wrap = 'soft') ?
'soft' : 'hard').'"' // not proper HTML, but too useful to abandon yet
1025 .' rows="'.pnVarPrepForDisplay($rows).'"'
1026 .' cols="'.pnVarPrepForDisplay($cols).'"'
1027 .((empty($accesskey)) ?
'' : ' accesskey="'.pnVarPrepForDisplay($accesskey).'"')
1028 .' tabindex="'.$this->tabindex
.'"'
1030 .pnVarPrepForDisplay($contents)
1033 if ($this->GetOutputMode() == _PNH_RETURNOUTPUT
) {
1036 $this->output
.= $output;
1041 * Add HTML tags for a hidden field as part of a form.
1044 * @param mixed $fieldname the name of the hidden field. can also be an array.
1045 * @param string $value the value of the hidden field
1046 * @return string An HTML string if <code>ReturnHTML()</code> has been called,
1049 function FormHidden($fieldname, $value = '')
1051 if (empty($fieldname)) {
1055 if (is_array($fieldname)) {
1057 foreach ($fieldname as $n => $v) {
1060 .' name="'.pnVarPrepForDisplay($n).'"'
1061 .' id="'.pnVarPrepForDisplay($n).'"'
1062 .' value="'.pnVarPrepForDisplay($v).'"'
1069 .' name="'.pnVarPrepForDisplay($fieldname).'"'
1070 .' id="'.pnVarPrepForDisplay($fieldname).'"'
1071 .' value="'.pnVarPrepForDisplay($value).'"'
1076 if ($this->GetOutputMode() == _PNH_RETURNOUTPUT
) {
1079 $this->output
.= $output;
1084 * Add HTML tags for a select field as part of a form.
1087 * @since 1.13 - 2002/01/23
1088 * @param string $fieldname the name of the select field
1089 * @param array $data an array containing the data for the list. Each array
1090 * entry is itself an array, containing the values for <code>'id'</code>
1091 * (the value returned if the entry is selected), <code>'name'</code>
1092 * (the string displayed for this entry) and <code>'selected'</code>
1093 * (optional, <code>1</code> if this option is selected)
1094 * @param integer $multiple (optional) <code>1</code> if the user is allowed to
1095 * make multiple selections
1096 * @param integer $size (optional) the number of entries that are visible in the
1097 * select at any one time. Note that if the number
1098 * of actual items is less than this value then the select box will
1099 * shrink automatically to the correct size
1100 * @param string $selected (optional) selected value of <code>id</code>
1101 * @param string $accesskey (optional) accesskey to active this item
1102 * @return string An HTML string if <code>ReturnHTML()</code> has been called,
1105 function FormSelectMultiple($fieldname, $data, $multiple = 0, $size = 1, $selected = '', $accesskey = '', $disable = false, $readonly = false)
1107 if (empty($fieldname)) {
1113 $disable_text = " disabled ";
1117 $disable_text = " disabled ";
1122 // Set up selected if required
1123 if (!empty($selected)) {
1124 for ($i=0; !empty($data[$i]); $i++
) {
1125 if ($data[$i]['id'] == $selected) {
1126 $data[$i]['selected'] = 1;
1137 .' name="'.pnVarPrepForDisplay($fieldname).'"'
1138 .' id="'.pnVarPrepForDisplay($fieldname).'"'
1139 .' size="'.pnVarPrepForDisplay($size).'"'
1140 .(($multiple == 1) ?
' multiple="multiple"' : '')
1141 .((empty($accesskey)) ?
'' : ' accesskey="'.pnVarPrepForDisplay($accesskey).'"')
1142 .' tabindex="'.$this->tabindex
.'"'
1143 .' ' . $disable_text
1146 foreach ($data as $datum) {
1147 $output .= '<option'
1148 .' value="'.pnVarPrepForDisplay($datum['id']).'"'
1149 .((empty($datum['selected'])) ?
'' : ' selected="selected"')
1151 .pnVarPrepForDisplay($datum['name'])
1156 $output .= '</select>';
1157 if ($this->GetOutputMode() == _PNH_RETURNOUTPUT
) {
1160 $this->output
.= $output;
1165 * Add HTML tags for a checkbox or radio button field as part of a form.
1168 * @since 1.13 - 2002/01/23
1169 * @param string $fieldname the name of the checkbox field
1170 * @param string $value (optional) the value of the checkbox field
1171 * @param boolean $checked (optional) the field is checked
1172 * @param string $type (optional) the type of field this is, either
1173 * <code>'checkbox'</code> or <code>'radio'</code>
1174 * @param string $accesskey (optional) accesskey to active this item
1175 * @return string An HTML string if <code>ReturnHTML()</code> has been called,
1178 function FormCheckbox($fieldname, $checked = false, $value = '1', $type = 'checkbox', $accesskey = '')
1180 if (empty($fieldname)) {
1186 .' type="'.(($type == 'checkbox') ?
'checkbox' : 'radio').'"'
1187 .' name="'.pnVarPrepForDisplay($fieldname).'"'
1188 .' id="'.pnVarPrepForDisplay($fieldname).'"'
1189 .' value="'.pnVarPrepForDisplay($value).'"'
1190 .(($checked) ?
' checked="checked"' : '')
1191 .((empty($accesskey)) ?
'' : ' accesskey="'.pnVarPrepForDisplay($accesskey).'"')
1192 .' tabindex="'.$this->tabindex
.'"'
1195 if ($this->GetOutputMode() == _PNH_RETURNOUTPUT
) {
1198 $this->output
.= $output;
1203 * Add HTML tags for a file upload field as part of a form.
1206 * @since 1.13 - 2002/01/23
1207 * @param string $fieldname the name of the field
1208 * @param integer $size (optional) the size of the field on the page in number
1210 * @param integer $maxsize (optional) the maximum file size allowed (in bytes)
1211 * @param string $accesskey (optional) accesskey to active this item
1212 * @return string An HTML string if <code>ReturnHTML()</code> has been called,
1215 function FormFile($fieldname, $size = 32, $maxsize = 1000000, $accesskey = '')
1217 if (empty($fieldname)) {
1222 $output = '<input type="hidden" name="MAX_FILE_SIZE" value="'.pnVarPrepForDisplay($maxsize).'" />';
1225 .' name="'.pnVarPrepForDisplay($fieldname).'"'
1226 .' id="'.pnVarPrepForDisplay($fieldname).'"'
1227 .' size="'.pnVarPrepForDisplay($size).'"'
1228 .((empty($accesskey)) ?
'' : ' accesskey="'.pnVarPrepForDisplay($accesskey).'"')
1229 .' tabindex="'.$this->tabindex
.'"'
1232 if ($this->GetOutputMode() == _PNH_RETURNOUTPUT
) {
1235 $this->output
.= $output;