Highway to PSR2
[openemr.git] / interface / main / calendar / includes / pnHTML.php
blob9cd4d9a5c4e42888c0ccc12fbfd68ae1d4500f16
1 <?php // File: $Id$
2 // ----------------------------------------------------------------------
3 // POST-NUKE Content Management System
4 // Copyright (C) 2001 by the Post-Nuke Development Team.
5 // http://www.postnuke.com/
6 // ----------------------------------------------------------------------
7 // Based on:
8 // PHP-NUKE Web Portal System - http://phpnuke.org/
9 // Thatware - http://thatware.org/
10 // ----------------------------------------------------------------------
11 // LICENSE
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 // ----------------------------------------------------------------------
29 /**
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);
40 /**
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);
51 /**
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);
58 /**
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);
65 /**
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.
73 * <B>Example</B>
74 * <pre>
75 * // Information array
76 * $colors = array(array('id' => 1,
77 * 'name' => 'Red',
78 * 'encoding' => 'ff0000'),
79 * array('id' => 2,
80 * 'name' => 'Blue',
81 * 'encoding' => '00ff00'),
82 * array('id' => 3,
83 * 'name' => 'Green',
84 * 'encoding' => '0000ff'));
86 * // Create the HTML object and start it
87 * $myhtml = new pnHTML();
88 * $myhtml->Start();
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);
95 * }
96 * $myhtml->TableEnd();
98 * // Add form to select a color
99 * $myhtml->Text('&lt;P&gt;&lt;P&gt;');
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
108 * $myhtml->End();
109 * $myhtml->PrintPage();
110 * </pre>
112 * @package PostNuke
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
120 class pnHTML
122 /*==============================================================================*
123 | Properties |
124 *==============================================================================*/
127 * Specific headers which must be printed prior to the main body of HTML
129 * @access private
130 * @var string $header
132 var $header;
135 * The pending HTML output
137 * @access private
138 * @var string $output
140 var $output;
143 * Return output?
145 * @access private
146 * @var integer $return
148 var $return;
151 * Parse text for output?
153 * @access private
154 * @var integer $parse
156 var $parse;
159 * Current tab index value
161 * @access private
162 * @var integer $tabindex
164 var $tabindex;
167 * File upload mode
169 * @access private
170 * @since 1.13 - 2002/01/23
171 * @var integer $fileupload
173 var $fileupload;
175 /*==============================================================================*
176 | Methods: Base |
177 *==============================================================================*/
180 * Constructor
182 * @access public
183 * @return boolean Always returns true
185 function pnHTML()
187 $this->header = array ();
188 $this->output = '';
189 $this->return = _PNH_KEEPOUTPUT;
190 $this->parse = _PNH_PARSEINPUT;
191 $this->tabindex = 0;
192 $this->fileupload = 0;
193 return true;
197 * Return the current state of the output stream
199 * @access public
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
213 * @access public
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();
222 switch ($st) {
223 default:
224 case _PNH_KEEPOUTPUT:
225 // The ONLY time this should be accessed directly
226 $this->return = _PNH_KEEPOUTPUT;
227 break;
228 case _PNH_RETURNOUTPUT:
229 // The ONLY time this should be accessed directly
230 $this->return = _PNH_RETURNOUTPUT;
231 break;
234 return $pre;
238 * Retrive the current input state
240 * @access public
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
248 return $this->parse;
252 * Set state of the input stream
254 * @access public
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();
263 switch ($st) {
264 case _PNH_VERBATIMINPUT:
265 // The ONLY time this should be accessed directly
266 $this->parse = _PNH_VERBATIMINPUT;
267 break;
268 default:
269 case _PNH_PARSEINPUT:
270 // The ONLY time this should be accessed directly
271 $this->parse = _PNH_PARSEINPUT;
272 break;
275 return $pre;
279 * Set the form to allow file uploads to take place
281 * @access public
282 * @since 1.13 - 2002/01/23
283 * @return boolean Always returns true
284 * @see FormStart(), FormFile()
286 function UploadMode()
288 $this->fileupload = 1;
289 return true;
292 /*==============================================================================*
293 | Methods: Output |
294 *==============================================================================*/
297 * Return the HTML output from the buffer.
299 * Note that this function does not clear out the object's buffer.
301 * @access public
302 * @since 1.15 - 2002/01/30
303 * @return string An HTML string
305 function GetOutput()
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.
315 * @access public
317 function PrintPage()
319 // Headers set by the system
320 foreach ($this->header as $headerline) {
321 header($headerline);
324 // Other headers
325 // Removed as per patch #264 bvdbos
326 // header('Content-length: ' . strlen($this->output));
328 print $this->output;
331 /*==============================================================================*
332 | Methods: Misc |
333 *==============================================================================*/
336 * Put the appropriate HTML tags in place to create a valid start to HTML output.
338 * @access public
339 * @return string An HTML string if <code>ReturnHTML()</code> has been called,
340 * otherwise null
341 * @see EndPage()
343 function StartPage()
345 ob_start();
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();
353 @ob_end_clean();
355 if ($this->GetOutputMode() == _PNH_RETURNOUTPUT) {
356 return $output;
357 } else {
358 $this->output .= $output;
363 * Put the appropriate HTML tags in place to create a valid end to HTML output.
365 * @access public
366 * @return string An HTML string if <code>ReturnHTML()</code> has been called,
367 * otherwise null
368 * @see StartPage()
370 function EndPage()
372 global $index;
373 if (pnVarCleanFromInput('module')) {
374 $index = 0;
375 } else {
376 $index = 1;
379 ob_start();
380 print '</td></tr></table>';
381 include 'footer.php';
382 $output = ob_get_contents();
383 @ob_end_clean();
385 if ($this->GetOutputMode() == _PNH_RETURNOUTPUT) {
386 return $output;
387 } else {
388 $this->output .= $output;
394 * @access public
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) {
406 return;
409 $compoutput = new pnHTML();
411 if (empty($startnum)) {
412 $startnum = 1;
415 if (empty($perpage)) {
416 $perpage = 10;
419 // Make << and >> do paging properly
420 // Display subset of pages if large number
422 // Check that we are needed
423 if ($total <= $perpage) {
424 return;
427 // Show startnum link
428 if ($startnum != 1) {
429 $url = preg_replace('/%%/', 1, $urltemplate);
430 $compoutput->URL($url, '<<');
431 } else {
432 $compoutput->Text('<<');
435 $compoutput->Text(' ');
437 // Show following items
438 $pagenum = 1;
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(' ');
446 } else {
447 // On this page - show text
448 $compoutput->Text($pagenum.' ');
451 $pagenum++;
454 if (($curnum >= $perpage+1) && ($startnum < $curnum-$perpage)) {
455 $url = preg_replace('/%%/', $curnum-$perpage, $urltemplate);
456 $compoutput->URL($url, '>>');
457 } else {
458 $compoutput->Text('>>');
461 if ($this->GetOutputMode() == _PNH_RETURNOUTPUT) {
462 $compoutput->SetOutputMode(_PNH_RETURNOUTPUT);
463 return $compoutput->PrintPage();
464 } else {
465 $this->output .= $compoutput->GetOutput();
470 * Redirect the user to another page
472 * This function is broken, do not use it!
474 * @access public
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,
478 * otherwise null
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'];
491 if (empty($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
502 if (empty($path)) {
503 $output = "Location: http://$server/$url";
504 } else {
505 $output = "Location: http://$server/$path/$url";
508 if ($this->GetOutputMode() == _PNH_RETURNOUTPUT) {
509 return $output;
510 } else {
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
524 * @access public
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);
533 $arg['confirm'] = 1;
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();
544 } else {
545 $compoutput->SetOutputMode(_PNH_RETURNOUTPUT);
546 $this->output .= $compoutput->GetOutput();
550 /*==============================================================================*
551 | Methods: Text |
552 *==============================================================================*/
555 * Add free-form text to the object's buffer
557 * @access public
558 * @param string $text The text string to add
559 * @return string An HTML string if <code>ReturnHTML()</code> has been called,
560 * otherwise null
562 function Text($text)
564 if ($this->GetInputMode() == _PNH_PARSEINPUT) {
565 $text = pnVarPrepForDisplay($text);
568 if ($this->GetOutputMode() == _PNH_RETURNOUTPUT) {
569 return $text;
570 } else {
571 $this->output .= $text;
576 * Add free-form text to the object's buffer as a title
578 * @access public
579 * @param string $text the text string to add
580 * @return string An HTML string if <code>ReturnHTML()</code> has been called,
581 * otherwise null
583 function Title($text)
585 $output = '<center><font class="pn-title">';
587 if ($this->GetInputMode() == _PNH_PARSEINPUT) {
588 $output .= pnVarPrepForDisplay($text);
589 } else {
590 $output .= $text;
593 $output .= '</font></center><br />';
595 if ($this->GetOutputMode() == _PNH_RETURNOUTPUT) {
596 return $output;
597 } else {
598 $this->output .= $output;
603 * add bold text to the object's buffer
605 * @access public
606 * @param string $text the text string to add
607 * @return string An HTML string if <code>ReturnHTML()</code> has been called,
608 * otherwise null
610 function BoldText($text)
612 if ($this->GetOutputMode() == _PNH_RETURNOUTPUT) {
613 return '<b>'.pnVarPrepForDisplay($text).'</b>';
614 } else {
615 $this->output .= '<b>'.pnVarPrepForDisplay($text).'</b>';
620 * Add line break
622 * @access public
623 * @param integer $numbreaks number of linebreaks to add
624 * @return string An HTML string if <code>ReturnHTML()</code> has been called,
625 * otherwise null
627 function Linebreak($numbreaks = 1)
629 $out = '';
630 for ($i=0; $i<$numbreaks; $i++) {
631 $out .= '<br />';
634 if ($this->GetOutputMode() == _PNH_RETURNOUTPUT) {
635 return $out;
636 } else {
637 $this->output .= $out;
642 * Add HTML tags for a hotlink.
644 * @access public
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,
649 * otherwise null
651 function URL($url, $text)
653 if (empty($url)) {
654 return;
657 $output = '<a href="'.$url.'">';
658 if (!empty($text)) {
659 if ($this->GetInputMode() == _PNH_PARSEINPUT) {
660 $text = pnVarPrepForDisplay($text);
663 $output .= $text;
666 $output .= '</a>';
668 if ($this->GetOutputMode() == _PNH_RETURNOUTPUT) {
669 return $output;
670 } else {
671 $this->output .= $output;
675 /*==============================================================================*
676 | Methods: Tables |
677 *==============================================================================*/
680 * Add HTML tags for the start of a table.
682 * @access public
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
687 * to be specified
688 * @return string An HTML string if <code>ReturnHTML()</code> has been called,
689 * otherwise null
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)) {
714 $output .= '<tr>';
715 foreach ($headers as $head) {
716 if (empty($head)) {
717 $head = '&nbsp;';
720 if ($this->GetInputMode() == _PNH_PARSEINPUT) {
721 $head = pnVarPrepForDisplay($head);
724 $output .= '<th>' . $head . '</th>';
727 $output .= '</tr>';
730 if ($this->GetOutputMode() == _PNH_RETURNOUTPUT) {
731 return $output;
732 } else {
733 $this->output .= $output;
738 * Add HTML tags for the start of a table row.
740 * @access public
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,
744 * otherwise null
746 function TableRowStart($align = 'center', $valign = 'middle')
748 $output = '<tr align="'.$align.'" valign="'.$valign.'">';
749 if ($this->GetOutputMode() == _PNH_RETURNOUTPUT) {
750 return $output;
751 } else {
752 $this->output .= $output;
757 * Add HTML tags for the start of a table column.
759 * @access public
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,
765 * otherwise null
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) {
771 return $output;
772 } else {
773 $this->output .= $output;
778 * Add HTML tags for the end of a table column.
780 * @access public
781 * @return string An HTML string if <code>ReturnHTML()</code> has been called,
782 * otherwise null
784 function TableColEnd()
786 $output = '</td>';
787 if ($this->GetOutputMode() == _PNH_RETURNOUTPUT) {
788 return $output;
789 } else {
790 $this->output .= $output;
795 * Add HTML tags for the end of a table row.
797 * @access public
798 * @return string An HTML string if <code>ReturnHTML()</code> has been called,
799 * otherwise null
801 function TableRowEnd()
803 $output = '</tr>';
804 if ($this->GetOutputMode() == _PNH_RETURNOUTPUT) {
805 return $output;
806 } else {
807 $this->output .= $output;
812 * Add HTML tags for the end of a table.
814 * @access public
815 * @return string An HTML string if <code>ReturnHTML()</code> has been called,
816 * otherwise null
818 function TableEnd()
820 $output = '</table></td></tr></table>';
821 if ($this->GetOutputMode() == _PNH_RETURNOUTPUT) {
822 return $output;
823 } else {
824 $this->output .= $output;
829 * Add HTML tags for a row of a table.
831 * @access public
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,
836 * otherwise null
838 function TableAddRow($row, $align = 'center', $valign = 'middle')
840 if (empty($row)) {
841 return;
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])) {
847 // new style
848 foreach ($row as $rowitem) {
849 if (!isset($rowitem['content'])) {
850 $rowitem['content'] = '&nbsp;';
853 if ($this->GetInputMode()) {
854 $rowitem['content'] = pnVarPrepForDisplay($rowitem['content']);
857 $output .= '<td'
858 .((empty($rowitem['align'])) ? '' : ' align="'.$rowitem['align'].'"')
859 .((empty($rowitem['valign'])) ? '' : ' valign="'.$rowitem['valign'].'"')
860 .'>'.$rowitem['content'].'</td>'
863 } else {
864 // old style
865 foreach ($row as $rowitem) {
866 if (!isset($rowitem)) {
867 $rowitem = '&nbsp;';
870 if ($this->GetInputMode() == _PNH_PARSEINPUT) {
871 $rowitem = pnVarPrepForDisplay($rowitem);
874 $output .= '<td>' . $rowitem . '</td>';
878 $output .= '</tr>';
879 if ($this->GetOutputMode() == _PNH_RETURNOUTPUT) {
880 return $output;
881 } else {
882 $this->output .= $output;
886 /*==============================================================================*
887 | Methods: Forms |
888 *==============================================================================*/
891 * Add HTML tags to start a form.
893 * @access public
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,
896 * otherwise null
898 function FormStart($action)
900 $output = '<form'
901 .' action="'.pnVarPrepForDisplay($action).'"'
902 .' method="post"'
903 .' enctype="'.((empty($this->fileupload)) ? 'application/x-www-form-urlencoded' : 'multipart/form-data').'"'
904 .'>'
906 if ($this->GetOutputMode() == _PNH_RETURNOUTPUT) {
907 return $output;
908 } else {
909 $this->output .= $output;
914 * Add HTML tags to end a form.
916 * @access public
917 * @return string An HTML string if <code>ReturnHTML()</code> has been called,
918 * otherwise null
920 function FormEnd()
922 $output = '</form>';
924 if ($this->GetOutputMode() == _PNH_RETURNOUTPUT) {
925 return $output;
926 } else {
927 $this->output .= $output;
932 * Add HTML tags for a submission button as part of a form.
934 * @access public
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,
939 * otherwise null
941 function FormSubmit($label = 'Submit', $accesskey = '')
943 $this->tabindex++;
944 $output = '<input'
945 .' type="submit"'
946 .' value="'.pnVarPrepForDisplay($label).'"'
947 .' align="middle"'
948 .((empty($accesskey)) ? '' : ' accesskey="'.pnVarPrepForDisplay($accesskey).'"')
949 .' tabindex="'.$this->tabindex.'"'
950 .' />'
952 if ($this->GetOutputMode() == _PNH_RETURNOUTPUT) {
953 return $output;
954 } else {
955 $this->output .= $output;
960 * Add HTML tags for a text field as part of a form.
962 * @access public
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,
972 * otherwise null
974 function FormText($fieldname, $contents = '', $size = 16, $maxlength = 64, $password = false, $accesskey = '')
976 if (empty($fieldname)) {
977 return;
980 $this->tabindex++;
981 $output = '<input'
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.'"'
990 .' />'
992 if ($this->GetOutputMode() == _PNH_RETURNOUTPUT) {
993 return $output;
994 } else {
995 $this->output .= $output;
1000 * Add HTML tags for a text area as part of a form
1002 * @access public
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
1006 | should cover
1007 * @param integer $cols the number of columns that the text area
1008 | should cover
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,
1012 * otherwise null
1014 function FormTextArea($fieldname, $contents = '', $rows = 6, $cols = 40, $wrap = 'soft', $accesskey = '')
1016 if (empty($fieldname)) {
1017 return;
1020 $this->tabindex++;
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.'"'
1029 .'>'
1030 .pnVarPrepForDisplay($contents)
1031 .'</textarea>'
1033 if ($this->GetOutputMode() == _PNH_RETURNOUTPUT) {
1034 return $output;
1035 } else {
1036 $this->output .= $output;
1041 * Add HTML tags for a hidden field as part of a form.
1043 * @access public
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,
1047 * otherwise null
1049 function FormHidden($fieldname, $value = '')
1051 if (empty($fieldname)) {
1052 return;
1055 if (is_array($fieldname)) {
1056 $output = '';
1057 foreach ($fieldname as $n => $v) {
1058 $output .= '<input'
1059 .' type="hidden"'
1060 .' name="'.pnVarPrepForDisplay($n).'"'
1061 .' id="'.pnVarPrepForDisplay($n).'"'
1062 .' value="'.pnVarPrepForDisplay($v).'"'
1063 .'/>'
1066 } else {
1067 $output = '<input'
1068 .' type="hidden"'
1069 .' name="'.pnVarPrepForDisplay($fieldname).'"'
1070 .' id="'.pnVarPrepForDisplay($fieldname).'"'
1071 .' value="'.pnVarPrepForDisplay($value).'"'
1072 .' />'
1076 if ($this->GetOutputMode() == _PNH_RETURNOUTPUT) {
1077 return $output;
1078 } else {
1079 $this->output .= $output;
1084 * Add HTML tags for a select field as part of a form.
1086 * @access public
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,
1103 * otherwise null
1105 function FormSelectMultiple($fieldname, $data, $multiple = 0, $size = 1, $selected = '', $accesskey = '', $disable = false, $readonly = false)
1107 if (empty($fieldname)) {
1108 return;
1111 $disable_text = "";
1112 if ($disable) {
1113 $disable_text = " disabled ";
1116 if ($readonly) {
1117 $disable_text = " disabled ";
1120 $this->tabindex++;
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;
1131 $c = count($data);
1132 if ($c < $size) {
1133 $size = $c;
1136 $output = '<select'
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
1144 .'>'
1146 foreach ($data as $datum) {
1147 $output .= '<option'
1148 .' value="'.pnVarPrepForDisplay($datum['id']).'"'
1149 .((empty($datum['selected'])) ? '' : ' selected="selected"')
1150 .'>'
1151 .pnVarPrepForDisplay($datum['name'])
1152 .'</option>'
1156 $output .= '</select>';
1157 if ($this->GetOutputMode() == _PNH_RETURNOUTPUT) {
1158 return $output;
1159 } else {
1160 $this->output .= $output;
1165 * Add HTML tags for a checkbox or radio button field as part of a form.
1167 * @access public
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,
1176 * otherwise null
1178 function FormCheckbox($fieldname, $checked = false, $value = '1', $type = 'checkbox', $accesskey = '')
1180 if (empty($fieldname)) {
1181 return;
1184 $this->tabindex++;
1185 $output = '<input'
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.'"'
1193 .' />'
1195 if ($this->GetOutputMode() == _PNH_RETURNOUTPUT) {
1196 return $output;
1197 } else {
1198 $this->output .= $output;
1203 * Add HTML tags for a file upload field as part of a form.
1205 * @access public
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
1209 * of characters
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,
1213 * otherwise null
1215 function FormFile($fieldname, $size = 32, $maxsize = 1000000, $accesskey = '')
1217 if (empty($fieldname)) {
1218 return;
1221 $this->tabindex++;
1222 $output = '<input type="hidden" name="MAX_FILE_SIZE" value="'.pnVarPrepForDisplay($maxsize).'" />';
1223 $output .= '<input'
1224 .' type="file"'
1225 .' name="'.pnVarPrepForDisplay($fieldname).'"'
1226 .' id="'.pnVarPrepForDisplay($fieldname).'"'
1227 .' size="'.pnVarPrepForDisplay($size).'"'
1228 .((empty($accesskey)) ? '' : ' accesskey="'.pnVarPrepForDisplay($accesskey).'"')
1229 .' tabindex="'.$this->tabindex.'"'
1230 .' />'
1232 if ($this->GetOutputMode() == _PNH_RETURNOUTPUT) {
1233 return $output;
1234 } else {
1235 $this->output .= $output;