| // +----------------------------------------------------------------------+ // // $Id: abstraction.php,v 1.3 2007/01/08 09:41:11 ah Exp $ /** * HTML/XML Generator. * * @version 1 */ class xml_gen { /** * Generate XML for plain link. * * If $uri is false a grey text will be displayed instead. * * @param string uri URI to open * @param string text Text or HTML used for linking * @param string attr Additional HTML attributes, e.g. "target=main width='100%'". */ public static function a($uri, $text, $attr = false) { if (!$uri) { return "$text"; } // Replace & with & in uri $uri = str_replace('&', '&', $uri); return "$text"; } /** * Generate XML code for image. * * Automatically locates file- looks for it in any ../ (max 20 levels) * Can extract width and height automatically. * Border defaults to 0. Can be overridden with $attr * * @param string filename Relative filename of picture or uri. * @param string width Forced width of picture. * @param string height Forced height of picture. * @param string attr Additional HTML attributes, e.g. "target=main width='100%'". * @return string Generated XML. */ public static function img($filename, $attr = false, $width = false, $height = false) { // If filename is a local file, locate it somewhere in (../)* if (!strstr($filename, "http://") && !strstr($filename, "?")) { $name = preg_replace("/^\//", "", $filename); $i= 21; while (--$i && !file_exists($name)) { $name = '../'.$name; } if (!file_exists($name)) { return false; } $fn_size = $name; // Replace relative filename with correct path if (@$filename[0] != "/") { $filename = $name; } } // Get height and width if (!empty($fn_size) && (!$height || !$width)) { $sz = GetImageSize($fn_size); if (!$width) { $width= $sz[0]; } if (!$height) { $height= $sz[1]; } } // Add border code? $border= (stristr(" $attr", " border=")) ? '' : "border='0'"; // Add alt code? $alt= (stristr(" $attr", " alt=")) ? '' : 'alt=""'; // Replace & with & in filename $filename = str_replace('&', '&', $filename); // Output $result = "\n"; } /** * Generate XML for pictorial link with image swapping -or- Simple picture -depending- on $condition. * * @param bool condition Show Picture or xml_gen::a_img? * @param string selected Filename for image to display if $condition == true. - use m_over if set to null * @param string uri URI to open * @param string filename Filename for image to display if $condition == false. * @param string m_over Filename for image to display when mouse is over image. * @param string attr Additional HTML attributes, e.g. "target=main width='100%'". * Except for onmouse* $attr is only added to
Requires flash version '.$requied_flash_version.'
'; $flashObjectString .= ''; } else { $flashObjectString = ''; $flashObjectString .= ''; $flashObjectString .= ''; $flashObjectString .= ''; $flashObjectString .= ''; $flashObjectString .= ''; } return $flashObjectString; } /** * Generate XML for . */ public static function span($content, $attr = null) { return "$content"; } /** * Generate XML for
. */ public static function div($content, $attr = null) { return "
$content
"; } /** * Generate XML for bold text. */ public static function b($text) { return "$text"; } /** * Generate XML for italic text. */ public static function i($text) { return "$text"; } /** * Generate XML for pre formatted text. */ public static function pre($text, $attr = null) { return "
$text
\n"; } /** * Generate XML for paragraph. */ public static function p($text, $attr = null) { if (is_array($text)) { $text = implode("
", $text); } return "

$text

\n"; } /** * Generate XML for error paragraph. */ public static function p_err($text) { if (is_array($text)) { $text = implode("
", $text); } return xml_gen::p($text, "class='error'"); } /** * Generate XML for text as heading 1. */ public static function h1($text, $attr='') { return "

$text

"; } /** * Generate XML for text as heading 2. */ public static function h2($text, $attr='') { return "

$text

"; } /** * Generate XML for text as heading 3. */ public static function h3($text, $attr='') { return "

$text

"; } /** * Generate XML for text as heading 4. */ public static function h4($text, $attr='') { return "

$text

"; } /** * Generate XML for spaces. */ public static function space($n=1) { return str_repeat(" ", $n); } /** * Generate XML for linefeeds. */ public static function br($n = 1, $abs = null) { if ($abs) { $abs= " clear=all"; } return str_repeat("\n", $n); } /** * Generate XML for hr tag. */ public static function hr($attr = null) { return "
"; } /** * Generate XML for unordered list. */ public static function ul($elements, $attr = null) { return "
    $elements
\n"; } /** * Generate XML for list index. */ public static function li($text, $attr = null) { return "
  • $text\n"; } /** * Generate XML for iframe * * Defaults to no scrolling and no frameborder. * Automatic height and width possible for local uris only. * * @param string src Iframe source (src) * @param mixed width Iframe width - set to 'auto' to automatically adjust width. * @param mixed height Iframe height - set to 'auto' to automatically adjust height * @param string attr Additional HTML attributes, e.g. "target=main width='100%'". */ public static function iframe($src, $width=null, $height=null, $attr=null) { if (!strstr($attr, 'frameborder')) { $attr .= " frameborder='0'"; } if (!strstr($attr, 'scrolling')) { $attr .= " scrolling='no'"; } if ($width == 'auto' || $height == 'auto') { $on_load = ''; if ($width == 'auto') { $on_load .= 'this.width=this.contentWindow ? this.contentWindow.document.body.scrollWidth : this.document.body.scrollWidth;'; } if ($height == 'auto') { $on_load .= 'this.height=this.contentWindow ? this.contentWindow.document.body.scrollHeight : this.document.body.scrollHeight;'; } $attr .= "onLoad='$on_load'"; } $result = ""; } /** * Generate XML for invisible table with desired width and height. */ public static function spacer($width, $height) { return "
     
    "; } /** * Generate js onclick for confirmations for /** * Constructor - define table layout here. * * @param int colums Number of colums in table * @param string attr Additional HTML attributes. cellpadding, cellspacing and border all defaults to 0. * @param string classes classes (set on ) to alternate. "header;alternate" or ";alternate". * @param string aligns Alignments of columns. List seperated by ;. I.e. "left;right;center;left". * @param string widths widths of columns. List seperated by ;. I.e. "100;20%;20". * Alternate is ; seperated too, I.e. "header;odd;even". */ public function __construct($columns, $attr=false, $classes=false, $aligns=false, $widths=false) { echo "\n\n".''; $this->closed = true; // Table is closed $this->curr_col = -1; // We are at column -1 (before ) $this->curr_row = 0; // We are in row 0 $this->columns = $columns; $this->header = $classes && ($classes[0] != ';'); $this->aligns = explode(';', $aligns); $this->widths = explode(';', $widths); $this->classes = explode(';', $classes); $this->set_widths = 1; $this->rowspan = array(); } /** * Destructor - finalise table. */ public function done() { $this->end_row(); echo "\n\n"; } /** * Output data cell(s). * * @param mixed data String: Data to output. Can be blank... just output after function call. * Array: Each element will be output in a new cell. * @param string attr Additional HTML attributes. Set col/rowspan, override/set class, width, align... */ public function data($data = '', $attr = false) { if (is_array($data)) { foreach ($data as $element) { $this->data($element); } return; } // Before ? if ($this->curr_col == -1) { $this->new_row(); } // After last column? elseif ($this->curr_col + $this->rowspan[0] >= $this->columns) { $this->end_row(); $this->new_row(); } // After ? if ($this->curr_col > 0) { echo ''."\n"; $this->closed = true; } // Begin new cell echo 'closed= false; // Override width if (!stristr(" $attr", ' width=') && !stristr(" $attr", ' colspan=')) { if ($this->curr_row == $this->set_widths && sizeof($this->widths > $this->curr_col) && !empty($this->widths[$this->curr_col])) { echo " width='".$this->widths[$this->curr_col]."'"; } } // Override alignment if (!stristr(" $attr", ' align=')) { if (sizeof($this->aligns > $this->curr_col) && !empty($this->aligns[$this->curr_col])) { echo ' align="'.$this->aligns[$this->curr_col].'"'; } } // Output data echo ' '.$attr.'>'.$data; // Advance internal pointer $this->curr_col++; // Colspan? $colspan = 1; if (preg_match('# colspan=(["\'0-9]+) #i', ' '.$attr.' ', $regs)) { $colspan = str_replace("'", '', str_replace('"', '', $regs[1])); if ($colspan > 1) { $this->curr_col += $colspan - 1; } if ($this->curr_row == $this->set_widths) { $this->set_widths++; } } // rowspan? if (preg_match('# rowspan=(["\'0-9]+) #i', ' '.$attr.' ', $regs)) { $rowspan = str_replace("'", '', str_replace('"', '', $regs[1])); while ($rowspan > 1) { array_push($this->rowspan, 0); // add a elements to our array... we may not need it... who cares? @$this->rowspan[$rowspan - 1] += $colspan; $rowspan--; } } } /** * Set attributes on next . */ public function row_attr($attr) { $this->next_row_attr = ' '.$attr; } /** * Finalise current row. Fill with empty cells if needed. */ public function end_row() { if (($this->curr_col == -1) && $this->closed) { return; } // Before last column? if ($this->curr_col + @$this->rowspan[0] < $this->columns) { $colspan = $this->columns - $this->curr_col - @$this->rowspan[0] + 1; $this->data('', 'colspan="'.$colspan.'"'); } if (!$this->closed) { echo ''."\n"; } echo ''."\n"; $this->curr_col = -1; ksort($this->rowspan); array_shift($this->rowspan); } /** * Advance to new row. */ protected function new_row() { echo "\n".'next_row_attr, ' class=')) { echo $this->get_class(); } echo $this->next_row_attr; $this->next_row_attr = ''; echo '>'."\n"; $this->curr_row++; $this->curr_col = 0; array_push($this->rowspan, 0); } /** * Get class for current row. */ protected function get_class() { $sz = sizeof($this->classes); if (!$sz) { return; } $class = $this->classes[0]; if (($this->curr_row == 0) && $this->header && $class) { return ' class="'.$class.'"'; } $offset = 1; if ($this->header) { $offset--; } $offs = (($sz > 1) ? 1 + (($offset + $this->curr_row - 1) % ($sz - 1)) : 1); $class = isset($this->classes[$offs]) ? $this->classes[$offs] : null; if ($class) { return ' class="'.$class.'"'; } } } ////////////////////////////////////////////////////////////////////////////// // Forms ///////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////// /** * HTML Form Generator. * * @version 3 */ class form { protected $elements; // Array of elements: array ( array("fisk", "radio"), ... protected $last_date_type; // YMD order of last date field protected $focus_element = -1; // Element on which to focus with javascript. protected $check_code; // Javascript code for CheckFormX() protected $extra_code_pre; // Extra javascript when drawing form protected $extra_code_post; // Extra javascript before submit protected $values; // Object or array containing default values. public $name; // Name of form. public $class_fields = "field"; // Standard class for textfields, textareas public $class_fields_readonly = "field_readonly"; // Standard class for readonly fields public $class_fields_disabled = "field_disabled"; // Standard class for disabled fields public $class_selects = "select"; // Standard class for selectboxes public $class_selects_readonly = "select_readonly"; // Standard class for readonly selectboxes public $class_selects_disabled = "select_disabled"; // Standard class for disabled selectboxes public $class_buttons = "button"; // Standard class for buttons public $class_checkboxes = "checkbox"; // Standard class for checkboxes public $class_radiobuttons = "radiobutton"; // Standard class for radiobuttons public $class_labels = "label"; // Standard class for labels (checkboxes and radiobuttons) public $class_labels_readonly = "label_readonly"; // Standard class for "readonly" labels public $class_datefields = "datefield"; // Standard class for datefield combi - do not set width public $class_dual_select_marked = "marked"; // Standard class for dual select - marked option public $option_dhtml_options = false; // Add options to "; // Store element in elements array array_push($this->elements, array ($name, "hidden")); } /** * Output a radio button. * * Checked button comes from array or object defined with values. * Default from $_REQUEST[$name]. * * @param string name Name of radio group. * @param string value Value for this radio button. * @param string label Text label. * @param string attr Additional HTML attributes, e.g. "id=main" */ public function radio($name, $value, $label = null, $attr = false) { // Get value from name $val = $this->get($name); $check = $val == $value; // Convert $check to HTML $check = ($check) ? "checked" : ""; if ($label) { // Render label grey if attr contains "disabled". if (stristr(" $attr ", " disabled ")) { $label = "$label"; } elseif ($this->class_labels) { $label = "$label"; } } // Get box class $class = empty($this->class_radiobuttons) ? "" : "class='$this->class_radiobuttons'"; // Output radio button echo "\n$label"; // Store element in elements array array_push($this->elements, array ($name, "radio")); } /** * Output a checkbox * * Checked comes from array or object defined with values. * Default from $_REQUEST[$name]. * * @param string name Name of check box. * @param string label Text label. * @param string attr Additional HTML attributes, e.g. "id=main" */ public function checkbox($name, $label = null, $attr = false) { $value = $this->get($name); $value = !empty($value); // Convert $check and value to HTML $check = $value ? "checked" : ""; // Render label grey if attr contains "disabled". if ($label) { if (stristr(" $attr ", " disabled ")) { $label = "$label"; } elseif ($this->class_labels) { $label = "$label"; } } // Get box class $class = empty($this->class_checkboxes) ? "" : "class='$this->class_checkboxes'"; // Output checkbox echo "\n$label"; // Store element in elements array array_push($this->elements, array ($name, "checkbox")); } /** * Output a select box * * Selected element comes from array or object defined with values. * Default from $_REQUEST[$name]. * * @param string name Name of select box. * @param array items Associative array with items: $value => $label. * @param string attr Additional HTML attributes, e.g. "id=main" */ public function select($name, $items, $attr = false) { $select = $this->get($name); // convert select to array if (!is_array($select)) { $select = array (0 => $select); } // Use class_select_disabled if no class or style is specified in attr and field readonly. if ($this->class_selects_disabled && stristr(" $attr", " disabled") && !stristr(" $attr", " class=") && !stristr(" $attr", " style=")) { $attr .= " class='$this->class_selects_disabled'"; } // Use class_select_readonly if no class or style is specified in attr and field readonly. if ($this->class_selects_readonly && stristr(" $attr", " readonly") && !stristr(" $attr", " class=") && !stristr(" $attr", " style=")) { $attr .= " class='$this->class_selects_readonly'"; } // Use class_selects if no class or style is specified in attr. if ($this->class_selects && !stristr(" $attr", " class=") && !stristr(" $attr", " style=")) { $attr .= " class='$this->class_selects'"; } // Output select - the normal HTML way if (!$this->option_dhtml_options) { echo ""; } // Output box elements - the DHTML way else { echo "\n"; echo ""; } // Store element in elements array array_push($this->elements, array ($name, "select")); } /** * Output a submit button. * * @param string label Label on button. * @param string attr Additional HTML attributes, e.g. "id=main" * @param string $change_action Change action to this value before submit. */ public function submit($label, $attr = false, $change_action = false) { // Use class_buttons if no class or style is specified in attr. if ($this->class_buttons && !stristr(" $attr", " class=") && !stristr(" $attr", " style=")) { $attr .= " class='$this->class_buttons'"; } // Change form action if ($change_action) { $change_action = "onclick=\"$this->name.action='$change_action';\""; } // Output button echo ""; } /** * Output a reset button. * * @param string label Label on button. * @param string attr Additional HTML attributes, e.g. "id=main" */ public function reset($label, $attr = false) { // Use class_buttons if no class or style is specified in attr. if ($this->class_buttons && !stristr(" $attr", " class=") && !stristr(" $attr", " style=")) { $attr .= " class='$this->class_buttons'"; } // Output button echo ""; } /** * Output a button. * * @param string label Label on button. * @param string attr Additional HTML attributes, e.g. "id=main" */ public function button($label, $attr = false) { // Use class_buttons if no class or style is specified in attr. if ($this->class_buttons && !stristr(" $attr", " class=") && !stristr(" $attr", " style=")) { $attr .= " class='$this->class_buttons'"; } // Output button echo ""; } /** * Output an image submit button. * * @param string label Label on button. * @param string attr Additional HTML attributes, e.g. "id=main" * @param string $change_action Change action to this value before submit. */ public function image($image, $text, $attr = false, $change_action = false) { // Change form action if ($change_action) { $change_action = "onclick=\"$this->name.action='$change_action';\""; } // Output button echo ""; } /** * Output a text field. * * Value comes from array or object defined with values. * Default from $_REQUEST[$name]. * * @param string name Name of text field. * @param string attr Additional HTML attributes, e.g. "id=main" */ public function text($name, $attr = false) { $value = $this->get($name); // Convert " to HTML $value = str_replace('"', '"', $value); // Use class_fields_disabled if no class or style is specified in attr and field readonly. if ($this->class_fields_disabled && stristr(" $attr", " disabled") && !stristr(" $attr", " class=") && !stristr(" $attr", " style=")) { $attr .= " class='$this->class_fields_disabled'"; } // Use class_fields_readonly if no class or style is specified in attr and field readonly. if ($this->class_fields_readonly && stristr(" $attr", " readonly") && !stristr(" $attr", " class=") && !stristr(" $attr", " style=")) { $attr .= " class='$this->class_fields_readonly'"; } // Use class_fields if no class or style is specified in attr. if ($this->class_fields && !stristr(" $attr", " class=") && !stristr(" $attr", " style=")) { $attr .= " class='$this->class_fields'"; } // Output text field echo ""; // Store element in elements array array_push($this->elements, array ($name, "text")); } /** * Output a password field. * * Value comes from array or object defined with values. * Default from $_REQUEST[$name]. * * @param string name Name of password field. * @param string attr Additional HTML attributes, e.g. "id=main" */ public function password($name, $attr = false) { // Get value $value = $this->get($name); // Convert " to HTML $value = str_replace('"', '"', $value); // Use class_fields_disabled if no class or style is specified in attr and field readonly. if ($this->class_fields_disabled && stristr(" $attr", " disabled") && !stristr(" $attr", " class=") && !stristr(" $attr", " style=")) { $attr .= " class='$this->class_fields_disabled'"; } // Use class_fields_readonly if no class or style is specified in attr and field readonly. if ($this->class_fields_readonly && stristr(" $attr", " readonly") && !stristr(" $attr", " class=") && !stristr(" $attr", " style=")) { $attr .= " class='$this->class_fields_readonly'"; } // Use class_fields if no class or style is specified in attr. if ($this->class_fields && !stristr(" $attr", " class=") && !stristr(" $attr", " style=")) { $attr .= " class='".$this->class_fields."'"; } // Output text field echo ""; // Store element in elements array array_push($this->elements, array ($name, "password")); } /** * Output a text area. * * Value comes from array or object defined with values. * Default from $_REQUEST[$name]. * * @param string name Name of text area. * @param string attr Additional HTML attributes, e.g. "id=main" */ public function textarea($name, $attr = false) { // Get value $value = $this->get($name); // Convert " to HTML $value = str_replace('"', '"', $value); // Use class_fields_disabled if no class or style is specified in attr and field readonly. if ($this->class_fields_disabled && stristr(" $attr", " disabled") && !stristr(" $attr", " class=") && !stristr(" $attr", " style=")) { $attr .= " class='$this->class_fields_disabled'"; } // Use class_fields_readonly if no class or style is specified in attr and field readonly. if ($this->class_fields_readonly && stristr(" $attr", " readonly") && !stristr(" $attr", " class=") && !stristr(" $attr", " style=")) { $attr .= " class='$this->class_fields_readonly'"; } // Use class_fields if no class or style is specified in attr. if ($this->class_fields && !stristr(" $attr", " class=") && !stristr(" $attr", " style=")) { $attr .= " class='$this->class_fields'"; } // Add required rows attribute if not specified in attr if (!stristr(" $attr", " rows=")) { $attr .= " rows='3'"; } // Add required cols attribute if not specified in attr if (!stristr(" $attr", " cols=")) { $attr .= " cols='40'"; } // Output text field echo ""; // Store element in elements array array_push($this->elements, array ($name, "textarea")); } /** * Output a file upload field. * * @param string name Name of file upload field. * @param string attr Additional HTML attributes, e.g. "id=main" */ public function file_upload($name, $attr = false) { // Use class_fields_disabled if no class or style is specified in attr and field readonly. if ($this->class_fields_disabled && stristr(" $attr", " disabled") && !stristr(" $attr", " class=") && !stristr(" $attr", " style=")) { $attr .= " class='$this->class_fields_disabled'"; } // Use class_fields_readonly if no class or style is specified in attr and field readonly. if ($this->class_fields_readonly && stristr(" $attr", " readonly") && !stristr(" $attr", " class=") && !stristr(" $attr", " style=")) { $attr .= " class='$this->class_fields_readonly'"; } // Use class_fields if no class or style is specified in attr. if ($this->class_fields && !stristr(" $attr", " class=") && !stristr(" $attr", " style=")) { $attr .= " class='$this->class_fields'"; } // Output text field echo ""; // Store element in elements array array_push($this->elements, array ($name, "file")); } /** * Output a two field dual select box for multiple choices * * @param string name Name of hidden field receiving selected values. * @param array items Associative array with items: $value => $label. * @param string attr Additional HTML attributes for