REMOVED JW20160307 * - all printable items should call 'print_prologue()' and 'print_epilogue()' * - the fact that in item is on a form can be determined automatically */ /* * Required pages */ require_once("definitions.php"); require_once("utilities.php"); /** * Format tooltip text; retain new lines */ function strclean_tooltip($text) { return str_replace("\n", "
", htmlspecialchars(strip_tags(str_replace("
", "\n", $text)))); } /** * Print info * (private function) * * Inputs: * - name name + _info * - info info message * - bold Bold text */ function print_info($name, $info = "", $bold = 1, $extra_info_style = "") { global $_PAGE_INFO; // Display message? if (strlen($info)) { $array_pos = strpos($name, "["); if( $array_pos ) { $info_name = substr($name, 0, $array_pos) . "_info" . substr($name, $array_pos); } else $info_name = $name . "_info"; echo ""; echo "\n"; } } /** * Merge default options, by key, into option array * (private function) * * Inputs: * - options Options (arguments for the calling function) * by reference * - defaults Default options * * Returns: * - options Modified option array */ function print_merge_default_options(&$options, $defaults) { if( $defaults && is_array($defaults) ) foreach( $defaults as $key => $default_option ) { if( !isset($options[$key]) ) $options[$key] = $default_option; } return $options; } /** * Print (tiny) inline button * (private function; use 'print_tiny_button()' to add a stand-alone button to a form) * * Inputs: * - button Array with * - icon Icon to show, mutex with 'text' * - text Text to display * - href URL (href) * - action Code for the "onclick" event handler * - in_table Place the button in a table cell (CSS class "action_button") */ function print_inline_button($button, $in_table = FALSE) { global $_PAGE_INFO; if( $in_table ) echo ""; if( $button['href'] ) print_link_start($button['href']); echo " $action ) if( strtolower(substr($event, 0, 2)) == "on" ) echo " " . $event . "=\"" . $action . "\""; if( $button['tip'] ) { echo " onmouseover=\"Tip('" . strclean_tooltip(_($button['tip'])) . "',BGCOLOR,'" . $_PAGE_INFO['ini']['tooltip']['background'] . "',BORDERCOLOR, '" . $_PAGE_INFO['ini']['tooltip']['border'] . "');\""; echo " onmouseout=\"UnTip();\""; } echo ">"; if( $button['icon'] ) echo ""; else if( $button['text'] ) echo "

" . $button['text'] . "

"; echo ""; if( $button['href'] ) print_link_end(); if( $in_table ) echo ""; } /** * Test to check if printing to a form */ function must_start_form_row() { global $_PAGE_INFO; return ( isset($_PAGE_INFO['form']) && $_PAGE_INFO['form']['active'] && ( isset($_PAGE_INFO['form']['scrollable_div']) || $_PAGE_INFO['form']['row'] == 0 ) ) && !isset($_PAGE_INFO['embedded_table']) && !isset($_PAGE_INFO['div']); } /** * Print prologue and epilogue to a printable item * Checks if the item is on a form * (private function) * * Inputs * - title * - form Stricly old style (for pages that do not yet use * 'print_form_start()') */ function print_prologue($title = NULL) { global $_PAGE_INFO; if( !isset($_PAGE_INFO['form']) && func_num_args() > 1 ) { $args = func_get_args(); $form = $args[1]; } else { $form = must_start_form_row(); } // sort out the title $form_only = FALSE; $sep = "
\n"; if( is_array($title) ) { if( isset($title['form']) ) { $_title = $title['form']['title']; $form_only = TRUE; } else $_title = $title['title']; if( $title['sep'] ) $sep = $title['sep']; } else { $_title = $title; $title = array(); // basically, unset... } // print the title and start a table row on a form if( isset($_SESSION[$_PAGE_INFO['id']]['extended_menu']) ) { if( $title && !$form_only ) print_text($_title); } if( $form ) { echo "\n"; echo "\n"; echo ""; if( $_title ) echo "

" . $_title . "

\n"; echo "\n"; echo ""; } else { // in a paragraph? print a line break if( isset($_PAGE_INFO['p']) && $_PAGE_INFO['p']['line']++ > 0 ) echo "
\n"; // print the title, unless this is disabled (i.e. the title // in that case will only be printed if there is a "col2" column if( $_title && !$form_only ) { if( $title['css_class'] || $title['style'] ) { echo ""; echo $_title . $sep; echo ""; } else echo $_title . $sep; } } // each pair of 'print_prologue()' and 'print_epilogue()' must be matched if( isset($_PAGE_INFO['form']) ) $_PAGE_INFO['form']['row']++; return $form; } function print_epilogue() { // @todo unimplemented option: skip when the option "join_with_next" is set; // the in the prologue for the next item must be skipped as well global $_PAGE_INFO; if( !isset($_PAGE_INFO['form']) && func_num_args() > 0 ) { $args = func_get_args(); $form = $args[0]; } else { $form = $_PAGE_INFO['form']['active'] && ($_PAGE_INFO['form']['row'] > 0); } if( !isset($_PAGE_INFO['form']) || ($form && --$_PAGE_INFO['form']['row'] == 0) ) { echo ""; echo ""; echo "\n"; } } /** * Links */ /** * Open an "A HREF=..." element (well, a replacement for it) * * Inputs: * - link link (URL) * - options additional options (array, or boolean to open link in a new window) * - id * - name * - replace (replaces the content of the current window) * - target (e.g. '_blank', '_self', etc) * - new_window (same as "target = 'blank'") * - on.... (event handlers) * - list (item is a list item, i.e. part of an
    or
      ) * * Note: * This function prints a replacement for the "A HREF=..." element, so a calling * script can save its form data in a session when a link is clicked (in turn to * make sure that the changes the user made are still there when the user returns * to the page). * Also prints set default context menu with options to open the link in a new * tab or a new window. */ function print_link_start($link, $options = FALSE) { global $_PAGE_INFO; if( !is_array($options) ) $options = array('new_window' => $options); // yuk! fix for an old yukkiness where the name of the project is put in the URL //if( strpos($link, "page_project") >= 0 ) { $link = htmlentities($link); } // part of an ordered or unordered list? if( $options['list'] ) { echo "
    • "; $_PAGE_INFO['list'] = TRUE; } if( $link ) { echo " $action ) if( strtolower(substr($event, 0, 2)) == "on" ) echo " " . $event . "=\"" . $action . "\""; echo ">"; if( isset($_PAGE_INFO['form']) ) $_PAGE_INFO['form']['link'] = $link; } /** * Close an A element */ function print_link_end() { global $_PAGE_INFO; if( isset($_PAGE_INFO['form']) ) { if( $_PAGE_INFO['form']['link'] ) echo ""; else echo ""; unset($_PAGE_INFO['form']['link']); } else { // caller must check echo ""; } // part of an ordered or unordered list? if( $_PAGE_INFO['list'] ) { echo "
    • \n"; unset($_PAGE_INFO['list']); } } /** * Print an "A HREF=..." element (replacement) * * Inputs: * - link link (URL) * - text link text. HTML is allowed to add extra functionality * - options additional options; see 'print_link_start()' */ function print_link($link, $text, $options) { // automatic tip? if( $options['tip'] && is_array($options['tip']) ) { // automatically show tip when the length of the text is greater // than the value $options['tip']['auto'] if( $options['tip']['auto'] && shorten_text($text, $options['tip']['auto']) != $text ) { // option to override default tooltip text if( $options['tip']['text'] ) $tip = $options['tip']['text']; else $tip = $text; } // replace the tooltip array (which 'print_link_start()' doesn't understand) // with the final text $options['tip'] = $tip; } print_link_start($link, $options); echo $text; print_link_end(); } /** * Form */ function print_form_start($name, $action, $options = NULL) { global $_PAGE_INFO; if( !$options ) { $options = array('css_class' => "form_table"); } echo "
      \n"; // Add CSRF (cross-site request forgery) token echo "\n"; echo "\n"; $_PAGE_INFO['form']['active'] = array('name' => $name); $_PAGE_INFO['form']['row'] = 0; // reference counter } function print_form_end() { global $_PAGE_INFO; echo "\n"; echo "\n"; $_PAGE_INFO['form']['active'] = FALSE; } /** * Save page (form) state over recalls */ function print_save_state($name) { global $_PAGE_INFO; print_hidden_input($name, urlencode(serialize($_PAGE_INFO['form']))); } function print_restore_state($state) { global $_PAGE_INFO; $_PAGE_INFO['form'] = unserialize(urldecode($state)); } /** * Create menu (matrix or list) * * Inputs: * - header: Menu header * - menuitems: Button text * - menulinks: Button links * - menurights: Button rights (1=enabled, 0=disabled) * - matrix: Use matrix when more then 4 items? * - form: form? add row * - extra_info Add extra icon/info * - options Maximum text length, or options (associative array) * - text_width * - style - extra CSS style for the 'sub_menu' or 'sub_menu_matrix' div * - matrix * - form * - extra_info */ function print_menu($header, $menuitems, $menulinks, $menurights, $options = NULL, $form = FALSE, $extra_info = NULL, $text_length = 25) { global $_PAGE_INFO; // old and new style parameters if( !is_array($options) ) { // old style $matrix = $options; $options = array('text_length' => $text_length, 'form' => $form, 'extra_info' => $extra_info); if( is_numeric($matrix) ) { if( $matrix == 0 ) $options['matrix'] = FALSE; else if( $matrix == 1 ) $options['matrix'] = TRUE; } } print_merge_default_options($options, array('form' => FALSE, 'extra_info' => $extra_info, 'text_length' => $text_length)); $form = print_prologue(NULL, $options['form']); if( !$form ) echo "
      \n"; if (strlen($header)) { echo "

      " . $header . "

      "; } echo "\n"; // Display matrix or row // NB: old code uses '1' for TRUE :-( if( $_SESSION[$_PAGE_INFO['id']]['extended_menu'] ) $columns = 1; else if( $options['matrix'] === FALSE ) $columns = 1; else if( $options['matrix'] === TRUE ) $columns = 3; else if( is_numeric($options['matrix']) ) $columns = $options['matrix']; else if( count($menuitems) > 6 ) $columns = 3; else $columns = 1; if( $columns > 1 ) { // 3x? matrix for ($i = 0; $i < (sizeof($menuitems)/$columns); $i++) { if ($options['form']) { echo "\n"; } else { echo "\n"; } for ($j = 0; $j < $columns; $j++) { if (($i*$columns + $j) < sizeof($menuitems)) { echo "\n"; // table cell } } echo "\n"; } } else { // Single column // Retrieve main items and check for the rights for ($i = 0; $i < sizeof($menuitems); $i++) { echo "\n"; if ($options['form']) { echo "\n"; // table cell echo "\n"; } } echo "
      \n"; echo "
      \n"; // Extra info? if (is_array($options['extra_info'])) { // Text? if (strlen($options['extra_info'][$i*$columns + $j]['text'])) { echo ""; echo " "; echo strip_tags($options['extra_info'][$i*$columns + $j]['text']); echo " "; echo "
      "; } // Icon? if (strlen($options['extra_info'][$i*$columns + $j]['icon'])) { echo "
      "; echo ""; echo "\n"; echo ""; echo "
      "; } } // Clip the name of an item in the menu structure (minding nearower letters) $adapted_menuitems = $menuitems[$i*$columns + $j]; $menuitem_options = array('target' => "_self"); // HACK: no form data to save, so avoid calling 'onsubmit()' $has_div = FALSE; // Tooltip? => When value was too long if( shorten_text($adapted_menuitems, $options['text_length']) != $adapted_menuitems ) { $menuitem_options['onmouseover'] = "Tip('" . strclean_tooltip($menuitems[$i*$columns + $j]) . "',BGCOLOR,'" . $_PAGE_INFO['ini']['tooltip']['background'] . "',BORDERCOLOR, '" . $_PAGE_INFO['ini']['tooltip']['border'] . "');"; $menuitem_options['onmouseout'] = "UnTip();"; } // Rights? if ($menurights[$i*$columns + $j]) { echo "
      "; $has_div = TRUE; print_link_start($menulinks[$i*$columns + $j], $menuitem_options); } else if (strlen($menuitems[$i*$columns + $j])) { echo "
      $action ) if( strtolower(substr($event, 0, 2)) == "on" ) echo " " . $event . "=\"" . $action . "\""; echo ">"; $has_div = TRUE; } echo strip_tags($adapted_menuitems); // Rights? if ($menurights[$i*$columns + $j]) { print_link_end(); } if( $has_div ) echo "
      \n"; // link echo "
      \n"; // button (sub_menu_matrix) echo "
      \n"; } else { echo "\n"; } echo "
      \n"; // Extra info? if (is_array($options['extra_info'])) { if (strlen($options['extra_info'][$i]['text'])) { echo ""; echo " "; echo strip_tags($options['extra_info'][$i]['text']); echo " "; echo "
      "; } if (strlen($options['extra_info'][$i]['icon'])) { echo "
      "; echo ""; echo "\n"; echo ""; echo "
      "; } } $adapted_menuitems = $menuitems[$i]; $menuitem_options = array('target' => "_self"); // HACK: no form data to save, so avoid calling 'onsubmit()' $has_div = FALSE; // Tooltip? => When value was too long if ((shorten_text($menuitems[$i], $options['text_length'], SHORTEN_ALL) != $menuitems[$i]) || (stristr($adapted_menuitems, "..") !== FALSE)) { $menuitem_options['onmouseover'] = "Tip('" . strclean_tooltip($menuitems[$i]) . "',BGCOLOR,'" . $_PAGE_INFO['ini']['tooltip']['background'] . "',BORDERCOLOR, '" . $_PAGE_INFO['ini']['tooltip']['border'] . "');"; $menuitem_options['onmouseout'] = "UnTip();"; } // Rights? if ($menurights[$i]) { print_link_start($menulinks[$i], $menuitem_options); } else if (strlen($menuitems[$i])) { echo "
      $action ) if( strtolower(substr($event, 0, 2)) == "on" ) echo " " . $event . "=\"" . $action . "\""; echo ">"; $has_div = TRUE; } echo strip_tags($adapted_menuitems); // Rights? if( $menurights[$i] ) print_link_end(); // link if( $has_div ) echo "
      \n"; // no link echo "\n"; // sub_menu echo "
      \n"; if( $form ) print_epilogue(TRUE); else echo "
      "; } /** * Print save and cancel buttons */ function print_save_buttons($buttons, $options = FALSE) { if( !is_array($options) ) $options = array(); print_merge_default_options($options, array('colspan' => 3, 'css_class' => "save_buttons", 'form' => must_start_form_row())); if( $options['form'] ) { echo ""; echo "\n"; // left-aligned and padded to column 'col2' looks best when there // are one or two buttons; center-align (via CSS) under all columns // when there are three or more buttons if( count($buttons) < 3 ) { echo "\n"; $options['colspan'] = FALSE; $options['style'] .= "text-align: left;"; } echo "\n"; // like print_prologue() $_PAGE_INFO['form']['row']++; } foreach( $buttons as $action => $button ) { if( is_array($button) ) { // 'button' is an array with options: // - text Button text // - action Recall action (set from array key if not set); // used only when no 'onclick' event is specified // - ro Button is read-only // - icon Icon to display in the button (left of the text) // - css_class // - style // - on... JavaScript events // set default 'onclick' action when an action is indeed set as the key // but not when the caller supplied an 'onclick' (user knows best :-) if( $button['href'] ) print_link_start($button['href'], $button['target']); if( !is_numeric($action) && !$button['action'] ) $button['action'] = $action; if( $button['action'] && !$button['onclick'] ) { $button['onclick'] = "onSubmit('" . $button['action'] . "',''," . (isset($button['xml']) ? $button['xml'] : "1") . ($button['show_busy'] ? ",'busy'" : "") . ");"; } echo " $action ) if( strtolower(substr($event, 0, 2)) == "on" ) echo " " . $event . "=\"" . $action . "\""; echo ">"; if( $button['icon'] ) { // needs table to separate the icon and the text echo "
      "; echo ""; echo ""; } // button text echo nl2br(strip_tags($button['text'])); if( $button['icon'] ) { // close table echo "
      "; } echo ""; if( $button['href'] ) print_link_end(); echo "\n"; } else { echo "\n"; } } if( $options['form'] ) { echo "\n"; echo "\n"; $_PAGE_INFO['form']['row']--; } else echo "\n"; } /** * Print title */ function print_title($title, $options = 0, $form = 1 /* strictly old style */) { global $_PAGE_INFO; if( is_array($options) ) { print_merge_default_options($options, array('center' => FALSE, 'form' => TRUE)); } else { // old style parameters $options = array('center' => $options, 'form' => $form); } $need_div = $options['buttons'] || $options['style'] || $options['action']; print_prologue(NULL, $options['form']); if( $need_div ) { echo "
      "; } if( $options['buttons'] ) { echo ""; foreach( $options['buttons'] as $button ) print_inline_button($button, TRUE); echo "
      "; } if ($options['center']) { echo "
      "; } if( $options['href'] ) { print_link_start($options['href'], $options['target']); } if( $options['anchor'] ) { echo ""; } if( $title ) { echo ""; echo $title; echo ""; } if( $options['anchor'] ) echo ""; if( $options['href'] ) print_link_end(); if( $options['center'] ) echo "
      "; if( $options['buttons'] ) { echo "
      "; } if( $need_div ) echo "
      "; echo "\n"; print_epilogue($options['form']); } /** * Print subtitle */ function print_subtitle($subtitle, $options = 0, $form = 1 /* strictly old style */) { global $_PAGE_INFO; if( is_array($options) ) { print_merge_default_options($options, array('center' => FALSE, 'form' => TRUE)); } else { // old style parameters $options = array('center' => $options, 'form' => $form); } $need_div = $options['buttons'] || $options['style'] || $options['action']; // print_prologue(NULL, $options['form']); if( $options['form'] || must_start_form_row() ) { $has_row = TRUE; // NB: col0 needed for the horizontal spacing, col2 for the vertical spacing; // col1 is discardable echo "\n"; echo "\n"; echo ""; } else $has_row = FALSE; if( $need_div ) { echo "
      "; } if( $options['buttons'] ) { echo ""; foreach( $options['buttons'] as $button ) print_inline_button($button, TRUE); echo "
      "; } if ($options['center']) { echo "
      "; } if( $options['href'] ) print_link_start($options['href'], $options['target']); if( $options['anchor'] ) { echo ""; } if (strlen($subtitle)) { echo "

      " . $subtitle . "

      "; } if( $options['anchor'] ) echo "
      "; if( $options['href'] ) print_link_end(); if ($options['center']) echo "
      "; if( $options['buttons'] ) { echo "
      "; } if( $need_div ) echo "
      "; // print_epilogue($options['form']); if( $has_row ) echo "\n"; else echo "\n"; } function print_subsubtitle($subtitle, $options = 0, $form = 1 /* strictly old style */) { if( is_array($options) ) { print_merge_default_options($options, array('center' => FALSE, 'form' => TRUE)); } else { // old style parameters $options = array('center' => $options, 'form' => $form); } $need_div = $options['buttons'] || $options['style'] || $options['action']; // print_prologue(NULL, $options['form']); if( $options['form'] || must_start_form_row() ) { $has_row = TRUE; // NB: col0 needed for the horizontal spacing, col2 for the vertical spacing; // col1 is discardable echo "\n"; echo "\n"; echo ""; } else $has_row = FALSE; if( $need_div ) { echo "
      "; } if( $options['buttons'] ) { echo ""; foreach( $options['buttons'] as $button ) print_inline_button($button, TRUE); echo "
      "; } if ($options['center']) { echo "
      "; } // anchor? if( $options['href'] ) print_link_start($options['href'], $options['target']); if( $options['anchor'] ) { echo ""; } if (strlen($subtitle)) { echo "

      " . $subtitle . "

      "; } if( $options['anchor'] ) echo "
      "; if( $options['href'] ) print_link_end(); if( $options['center'] ) echo "
      "; if( $options['buttons'] ) { echo "
      "; } if( $need_div ) echo "
      "; // print_epilogue($options['form']); if( $has_row ) echo "\n"; else echo "\n"; } /** * Print text * * Inputs: * - text Text to print * - options * - form Print on a form (superceeded by 'print_prologue') * - p Print as a paragraph (default TRUE when not in an embedded table) * - id Optional ID (for CSS or JavaScript) * - icon Text is preceeded by an image/icon; URL or array: * - src URL for the image to print * - Other options; see 'print_image' * - bold Use bold font * - css_class CSS class for the paragraph * - style CSS style * - href Text is a clickable link * - action JavaScript "onClick" action * - buttons Array with action buttons; will be placed in a table; see 'print_inline_button' */ function print_text($text, $options = 0, $form = 1 /* strictly old style */) { global $_PAGE_INFO; if( is_array($options) ) { print_merge_default_options($options, array('css_class' => NULL, 'p' => !isset($_PAGE_INFO['embedded_table']), 'form' => !isset($_SESSION[$_PAGE_INFO['id']]['extended_menu']))); } else { // old style parameters $options = array('css_class' => $options, 'form' => $form); } if( $options['class'] ) $options['css_class'] = $options['class']; $need_div = $options['buttons'] || $options['style'] || $options['action']; $style = array(); if( $options['bold'] ) $style[] = "font-weight:bold"; if( $options['style'] ) $style[] = $options['style']; print_prologue($options['title'], $options['form']); // buttons? if( $need_div ) { echo "
      "; } if( $options['buttons'] ) { echo ""; if( strlen($text) ) echo ""; foreach( $options['buttons'] as $button ) print_inline_button($button, TRUE); echo "
      "; } if( $options['p'] ) { echo ""; } // icon? if( $options['icon'] ) { if( is_array($options['icon']) ) { $icon_src = $options['icon']['src']; $icon_options = $options['icon']; } else { $icon_src = $options['icon']; $icon_options = array(); } $icon_options['skip_prologue'] = TRUE; if( !isset($icon_options['css_class']) ) $icon_options['css_class'] = "icon_left"; print_image(NULL, $icon_src, $icon_options); } // clickable link? if( $options['href'] ) print_link_start($options['href'], $options['target']); // anchor? if( $options['anchor'] ) { echo ""; } // print the text if( strlen($text) ) echo $text; // clean up if( $options['anchor'] ) echo ""; if( $options['href'] ) print_link_end(); if( $options['p'] ) echo "

      "; if( $options['buttons'] ) { if( strlen($text) ) echo "
      "; } if( $need_div ) { echo "
      "; } echo "\n"; print_epilogue($options['form']); } /** * Print Filter & search button */ function print_filter_search($title, $name, $value, $onkeyup = "") { print_prologue($title, TRUE); if (strlen($onkeyup)) { echo "\n"; echo "\n"; } else { echo "\n"; echo "\n"; } echo "\n"; print_epilogue(TRUE); } /** * Print input * * Inputs: * - Title Title * - name name * - value session value * - ro_action Read only actions (array) * - info info message * - onkeyup onkey up event * - extra_info_style extra info style options * - center center control */ function print_input($title, $name, $value, $ro_actions, $info = "", $options = TRUE, $onkeyup = "", $extra_info_style = "", $center = "") { global $_PAGE_INFO; if( !is_array($options) ) { // old style parameters $options = array( 'info_bold' => $options, // $bold is replace by $options 'form' => TRUE, 'onkeyup' => $onkeyup, 'info_style' => $extra_info_style, 'center' => $center ); } print_merge_default_options($options, array( 'form' => TRUE, 'info_bold' => TRUE, 'text_length' => 30 // used to check if a tooltip must be shown ) ); $options['onkeypress'] .= "return noenter(event,this);"; if( $options['onkeyup'] ) { $options['onkeyup'] .= "new_value('" . $name . "',func_" . $name . ");"; $options['onfocus'] .= "current_value('" . $name . "');"; } $title_options = print_merge_default_options($options['title'], array('title' => $title)); print_prologue( $title_options, // NB: translation TRUE ); if (strlen($options['onkeyup'])) { echo "\n"; } // Alignment if( $options['center'] ) { echo "
      "; } echo " $action ) if( strtolower(substr($event, 0, 2)) == "on" ) echo " " . $event . "=\"" . $action . "\""; if( $options['css_class'] ) echo " class=\"" . $options['css_class'] . "\""; if( $options['style'] ) echo " style=\"" . $options['style'] . "\""; echo ">\n"; // Alignment if( $options['center'] ) { echo "
      "; } // Display message? if( $info ) print_info($name, $info, $options['info_bold'], $options['_info_style']); // Disabled control => create hidden control if (is_ro($ro_actions)) { print_hidden_input($name, htmlspecialchars($value)); } print_epilogue(TRUE); } /** * Print textarea * * Inputs: * - Title Title * - name name * - value session value * - height text area height * - ro_action Read only actions (array) * - action Add action button (array with 'button_text' and 'action') * - bold Display bold info text * - strip_tags Strip html tags from textarea */ function print_textarea($title, $name, $value, $height, $ro_actions, $info = "", $options = NULL, $bold = 1, $strip_tags = TRUE) { global $_PAGE_INFO; if( is_array($options) ) { print_merge_default_options($options, array('form' => TRUE, 'info_bold' => $bold, 'html' => !$strip_tags)); } else { // old style parameters $options = array( 'info_bold' => $bold, 'form' => TRUE, 'html' => !$strip_tags ); } print_prologue($title, $options['form']); // NB: translation echo "\n"; // Display message? if (strlen($info)) print_info($name, $info, $options['info_bold']); // action? if( $options['action'] ) { echo "
      "; echo "\n"; echo "
      "; } // Disabled control => create hidden control if( is_ro($ro_actions) ) { print_hidden_input($name, htmlspecialchars($value)); } print_epilogue(TRUE); } /** * Print drop-down or list selection * * Inputs: * - title Title * - name Name in the form * - value Value of the current selection * - selections Options to choose from (array 'value' => 'option' or * array 'value' => array('text' => ..., 'tooltip' => ..., on...event => ...) * - ro_actions Read-only actions (array) * - info Additional information * - options Formatting options * - type "dropdown", "dropdownlist" or a "listbox" by default * - id CSS identifier * - css_class CSS class * - style CSS style * - form Print on a three column form * - sort Sort the "selections" (minding special values) * - on...event JavaScript for the event * - size Number of items to show * - multi Allow multiple selections * - tooltip Show default tooltips (the option's text) * - selection Always show the selected items or hide them (by default, * hide them when the control is read-only); string "show", * "hide" or something else ("normal", "default", but this is not checked) * * NB: the selected "value" must match the key in the "selections" array, * if an item is to be selected */ function print_selection($title, $name, $value, $selections, $ro_actions = NULL, $info = "", $options = NULL, $bold = TRUE) { global $_PAGE_INFO; // set default options if( !is_array($options) ) $options = array(); print_merge_default_options($options, array( 'id' => FALSE, 'css_class' => FALSE, 'style' => FALSE, 'sort' => FALSE, 'multi' => FALSE, 'tooltips' => FALSE, 'select_default' => ($options['type'] == "dropdownlist"), // only used when 'value' is not a valid selection 'text_length' => 30 // used to check if a tooltip must be shown ) ); // extra options for the selectable options $li_options = array('onclick' => ""); // emulate a "select" element with "size=1" (which is in fact a "dropdownlist") if( !isset($options['type']) && ($options['size'] == 1) ) { $options['type'] = "dropdownlist"; unset($options['size']); } // sort the selections and determine the default value if( is_array($selections) ) { // sort the options? mind the special options (identified by an empty key) if( $options['sort'] ) { // find "special" options and also check that the options are simple text $special_selections = array(); $sort_keys = array(); foreach( $selections as $selection_value => $option ) { if( strlen($selection_value) == 0 || $selection_value < 0 ) { $special_selections[$selection_value] = $option; } else if( is_array($option) ) { $sort_keys[$selection_value] = $option['text']; } } if( $sort_keys ) { // selections are arrays with multiple options; special selections have // already been removed asort($sort_keys, SORT_LOCALE_STRING | SORT_FLAG_CASE); $sorted_selections = array(); foreach( $sort_keys as $key => $string ) $sorted_selections[$key] = $selections[$key]; $selections = $sorted_selections; } else { // simple array // remove the selection options from the array and sort the remaining (normal) options $selections = array_diff_key($selections, $special_selections); asort($selections, SORT_LOCALE_STRING | SORT_FLAG_CASE); } // re-insert the special selection(s) at the beginning of the array $selections = $special_selections + $selections; } // selection available? if not, select the default if( $options['select_default'] && !$options['multi'] && !isset($selections[$value]) ) { $values = array_keys($selections); $value = array_shift($values); } } // which control gets what name? $name_select = $name . ":select"; $name_input = $name . ":editbox"; // name of the JavaScript $name_js = "_js_select_" . preg_replace("/[^a-z0-9_]/i", "_", $name); // set appearance/controls depending on the type of box $use_div = FALSE; $has_editbox = FALSE; switch( $options['type'] ) { case "dropdown": case "dropdownlist": $has_editbox = TRUE; $use_div = TRUE; // a dropdown list is never a multi-select $options['multi'] = FALSE; break; } // is the size set? we won't allow zero size either... if( !$options['size'] ) { $options['size'] = count($selections); // limit the size to 16 entries max and 3 entries min when the control has an // editbox with a dropdown list if( $has_editbox ) { if( $options['size'] > 16 ) $options['size'] = 16; else if( $options['size'] < 1 ) $options['size'] = 3; } else if( !$options['size'] ) { // an empty list looks very awkward $options['size'] = 1; } } // width if( $options['width'] == "auto" ) { $editbox_width = 0; foreach( $selections as $selection ) { if( is_array($selection) ) $selection = $selection['text']; $editbox_width = max(strlen(strip_tags($selection)), $editbox_width); } $editbox_width *= 8; // average char width: 8px $options['width'] = $editbox_width + 20; // width including list button } // set default selection? only when the 'value' is not a valid selection if( isset($options['default']) && !isset($selections[$value]) ) { $value = $options['default']; } print_prologue($title); // display the input element, in a class "dropdown" div to align the image if( $has_editbox ) { // determing auto-width echo ""; echo ""; if( !is_ro($ro_actions) ) { echo "\n"; } else { echo "\n"; } // Display message? if (strlen($info)) print_info($name, $info, $bold, $options['info_style']); } else if( $options['multi'] ) { // multi-select listbox: expand the selected values if( !is_array($value) ) { if( $value ) $value = explode(",", $value); else $value = array(); } } // select element, when needed in a div if( $use_div ) { echo ""; } echo "
      "; echo " $action ) { if( $event == 'onclick' || $event == 'onchange' ) { $li_options['onclick'] .= $action; } else if( strtolower(substr($event, 0, 2)) == "on" ) { echo " " . $event . "=\"" . $action . "\""; } } echo ">\n"; // print the options for the select element if( is_array($selections) ) { $index = 0; foreach( $selections as $selection_value => $selection ) { if( is_array($selection) && $selection['href'] && !$selection['ro'] ) { print_link_start($selection['href'], $selection['new_window']); } echo " $option_value ) { switch( $option ) { case 'tooltip': $selection['onmouseover'] .= "Tip('" . strclean_tooltip($option_value) . "',BGCOLOR,'" . $_PAGE_INFO['ini']['tooltip']['background'] . "',BORDERCOLOR, '" . $_PAGE_INFO['ini']['tooltip']['border'] . "');"; $selection['onmouseout'] .= "UnTip();"; break; case 'color': if( $option_value ) { global $_COLORS; $color = $_COLORS[$option_value]; if( !$color ) $color = $option_value; $selection['style'] .= "color: " . $color . ";"; } break; case 'hide': if( $option_value ) $selection['style'] .= "display: none;"; break; case 'text': $selection_text = strip_tags($option_value); break; case 'ro': if( $option_value ) $css_class = "disabled"; break; } } // add default tooltips when no other tooltips set if( !$selection['tooltip'] && shorten_text($selection_text, $options['text_length']) != $selection_text) { $selection['onmouseover'] .= "Tip('" . strclean_tooltip($selection_text) . "',BGCOLOR,'" . $_PAGE_INFO['ini']['tooltip']['background'] . "',BORDERCOLOR, '" . $_PAGE_INFO['ini']['tooltip']['border'] . "');"; $selection['onmouseout'] .= "UnTip();"; } // add listbox click behaviour if( !is_ro($ro_actions) && !$selection['ro'] && !$selection['href'] ) { $selection['onclick'] .= $name_js . ".Select(" . $index . ");"; if( !$selection['href'] ) $selection['onclick'] .= $li_options['onclick']; } else if( $has_editbox ) { $selection['onclick'] .= $name_js . ".HideDropDown();"; if( !$selection['href'] ) $selection['onclick'] .= $li_options['onclick']; } // print the options foreach( $selection as $option_type => $option_value ) { if( strtolower(substr($option_type, 0, 2)) == "on" ) { // javascript events echo " " . $option_type . "=\"" . $option_value . "\""; } else switch( $option_type ) { // copy those styles into the output: case 'style': echo " " . $option_type . "=\"" . $option_value . "\""; break; } } if( $css_class ) echo " class=\"" . $css_class . "\""; echo ">"; if( strlen($selection_text) > 0 ) echo $selection_text; else echo " "; } else { $selection_text = strip_tags($selection); if( $options['tooltips'] || shorten_text($selection_text, $options['text_length']) != $selection_text) { echo " onmouseover=\"Tip('" . strclean_tooltip($selection_text) . "',BGCOLOR,'" . $_PAGE_INFO['ini']['tooltip']['background'] . "',BORDERCOLOR, '" . $_PAGE_INFO['ini']['tooltip']['border'] . "');\""; echo " onmouseout=\"UnTip();\""; } if( !is_ro($ro_actions) ) { echo " onclick=\"" . $name_js . ".Select(" . $index . ");" . $li_options['onclick'] . "\""; } if( $css_class ) echo " class=\"" . $css_class . "\""; echo ">"; if( strlen($selection_text) > 0 ) echo $selection_text; else echo " "; } echo ""; if( is_array($selection) && $selection['href'] && !$selection['ro'] ) { print_link_end(); } echo "\n"; $index++; } } // pad the list with dummy entries $n = is_array($selections) ? count($selections) : 0; for( $i = $n; $i < $options['size']; $i++ ) echo "
    • \n"; echo "
    "; echo ""; if( $use_div ) { echo ""; } echo "\n"; // Display message? if( !$has_editbox && strlen($info) ) print_info($name, $info, $bold, $options['info_style']); // The hidden control contains the value actually used if( $options['multi'] ) $initial_value = implode(",", $value); else $initial_value = $value; print_hidden_input($name, $initial_value); // create JavaScript object to handle the events // and show the selected item (i.e. "ensure visible" as it is often called) if( !is_ro($ro_actions) ) { echo "\n"; } if( $has_editbox ) { echo "\n"; } print_epilogue(); } /** * Print combobox (drowdown element) * Wrapper to "print_selection" */ function print_combobox($title, $name, $value, $selections, $ro_actions = NULL, $info = "", $options = NULL, $bold = TRUE) { if( !is_array($options) ) $options = array(); $options["type"] = "dropdown"; print_selection($title, $name, $value, $selections, $ro_actions, $info, $options, $bold); } /** * Print dropdown list, a replacement for a select element with size=1 * Wrapper to "print_selection" */ function print_dropdownlist($title, $name, $value, $selections, $ro_actions = NULL, $info = "", $options = NULL, $bold = TRUE) { if( !is_array($options) ) $options = array(); $options["type"] = "dropdownlist"; print_selection($title, $name, $value, $selections, $ro_actions, $info, $options, $bold); } /** * Print a list box * Wrapper to "print_selection" */ function print_listbox($title, $name, $value, $selections, $size, $ro_actions = NULL, $info = "", $options = NULL, $bold = TRUE) { if( !is_array($options) ) $options = array(); $options["type"] = "listbox"; $options['size'] = $size; print_selection($title, $name, $value, $selections, $ro_actions, $info, $options, $bold); } /** * Print tree view * * Inputs: * - title Title in the leftmost column * - name Name of this tree view (mostly for the JavaScript) * - value Current settings (POST array of the hidden inputs) * - items Item array * - Item is an object (well, array) with the following members: * - value Item text * - href Item is a clickable link * - target Target for the HREF * - on...event JavaScript for the event * - tooltip Tooltip text * - icon array with icons: * - open * - closed * - empty * - items Subitem array * - ro_actions (currently not used) * - info (currently not used) * - options Option array * - expand Expand subitems (only show top level items if FALSE) * - bold Item text in bold font */ function print_treeview($title, $name, $value, $items, $ro_actions = NULL, $info = NULL, $options = NULL) { global $_PAGE_INFO; // set default options if( !is_array($options) ) $options = array(); print_merge_default_options($options, array( 'css_class' => FALSE, 'style' => FALSE, 'expand' => TRUE, 'bold' => FALSE, 'form' => isset($_PAGE_INFO['form']), 'icon' => array( 'open' => IMAGE_DIR . "foldbutton_orange_icon_medium_expanded.png", 'closed' => IMAGE_DIR . "foldbutton_orange_icon_medium_collapsed.png", 'empty' => IMAGE_DIR . "foldbutton_orange_icon_medium_empty.png" ) ) ); if( !isset($options['text_length']) ) { if( isset($_SESSION[$_PAGE_INFO['id']]['extended_menu']) ) $options['text_length'] = 40; // TBD else if( $options['form'] ) $options['text_length'] = 44; } // create JavaScript object to handle the events echo "\n"; print_prologue($title); // print the top level, if set if( is_array($items) ) { echo "\n"; // print the top level items and recurse into the sub-items foreach( $items as $id => $item ) { print_treeview_item($name, $id, $value, $item, 1, $ro_actions, $info, $options); } echo "\n"; } print_epilogue(); } /** * Print a treeview item (private function) */ function print_treeview_item($name, $id, $value, $item, $level, $ro_actions, $info, $options) { global $_PAGE_INFO; // determine the state of the sub-item list $list_tag = $id; $expand_list = (!isset($value[$list_tag]) && $options['expand']) || $value[$list_tag]; $this_ro = $children_ro = $ro_actions; // print top level item, with the appropriate icon echo " $javascript ) if( substr($event, 0, 2) == "on" ) echo " " . $event . "=\"" . $javascript . "\""; echo ">"; // state to save over recalls print_hidden_input($name . "[" . $list_tag . "]", $expand_list); // sort out the item's name $str = strip_tags($item['value']); $org_str = $str; // bullet/image/button if( $item['items'] ) { if( $expand_list ) $icon = "open"; else $icon = "closed"; } else $icon = "empty"; echo ""; // checkbox? if( $item['checkbox'] ) { echo " $action ) if( strtolower(substr($event, 0, 2)) == "on" ) echo " " . $event . "=\"" . $action . "\""; echo ">\n"; // print hidden input when disabled if( is_ro($this_ro) ) print_hidden_input($checkbox['name'], $item['checkbox']['checked']); // set the child items as read-only when this item is not selected if( !$item['checkbox']['checked'] ) $children_ro = TRUE; } // print item value if( $item['href'] && !$item['recall'] ) { // clickable link $item_options = array(); if( $item['target'] ) $item_options['new_window'] = $item['target']; if( shorten_text($str, $options['text_length'] - ($level * 2), SHORTEN_NARROW) != $str ) { $item_options['onmouseover'] = "\"Tip('" . strclean_tooltip($org_str) . "',BGCOLOR,'" . $_PAGE_INFO['ini']['tooltip']['background'] . "',BORDERCOLOR, '" . $_PAGE_INFO['ini']['tooltip']['border'] . "');\""; $item_options['onmouseout'] = "\"UnTip();\""; } print_link_start($item['href'], $item_options); echo $str; print_link_end(); } else { echo ""; echo $str; echo ""; } // print the sub-items, when present if( $item['items'] ) { echo "\n"; foreach( $item['items'] as $id => $item ) { print_treeview_item($name, $list_tag . ":" . $id, $value, $item, $level + 1, $children_ro, $info, $options); } echo "\n"; } echo "\n"; } /** * Print table * * Inputs: * - Title Title * - Name Name * - value Array filled with data * - id Select id * - per Percentage of listbox * - align Alignment ("L" left ,"C" center) * - ro_actions Read only actions (array) * - on_change on change event * - size listbox sizeof * - sel_val selected value * - skip_table_end do not print last column * - width width of listbox (default 303px) */ function print_table($title, $name, $value, $opt, $id, $per = "", $align = "", $ro_actions, $on_change = "", $size = "", $sel_val = "", $skip_table_end = 0, $table_large = 0, $truetype = TRUE) { global $_PAGE_INFO; global $_COLORS; // The first items of the "values" is the table header (euch!) $n_columns = 0; $table_options = array('css_class' => "print_table"); $print_headers = strlen($value[0][0]); if( $print_headers ) { $table_headers = array(); for( $i = 0; $i < count($value[0]); $i++ ) { $table_header = array('text' => $value[0][$i]); $style = ""; if (is_array($align)) { switch( $align[$i] ) { case "C": $style .= "text-align: center;"; break; case "R": $style .= "text-align: right;"; break; case "L": $style .= "text-align: left;"; break; case "J": $style .= "text-align: justify;"; break; } } if( is_array($per) ) { $style .= "width: " . $per[$i] . "%;"; } if( $style ) $table_header['style'] = $style; $table_headers[] = $table_header; } } else $table_headers = FALSE; if( $size ) { $table_options['div'] = array('height' => $size . "em"); } print_embedded_table_start($title, $table_headers, $table_options); print_hidden_input($name, ""); // print the data rows $row = 0; for ($k = 1; $k < sizeof($value); $k++) { print_embedded_table_row_start($row++); if( $opt[$k] ) { // header print_embedded_table_cell($value[$k][0], array('colspan' => sizeof($value[0]), 'css_class' => "group_header")); } else for($i = 0; $i < sizeof($value[0]); $i++) { $cell_options = array(); $style = ""; if (is_array($align)) { switch( $align[$i] ) { case "C": $style .= "text-align: center;"; break; case "R": $style .= "text-align: right;"; break; case "L": $style .= "text-align: left;"; break; case "J": $style .= "text-align: justify;"; break; } } if( $on_change ) { $cell_options['onclick'] = "getElement('" . $name . "').value='" . $id[$k] . "';" . $on_change; $style .= "cursor: pointer;"; } if( $value[$k]['color'] ) $style .= "color: " . $_COLORS[$value[$k]['color']] . ";"; if( $value[$k]['bold'] ) $style .= "font-weight: bold;"; // the width is determined by the header if( is_array($per) && !$print_headers ) { $style .= "width: " . $per[$i] . "%;"; } if( $style ) $cell_options['style'] = $style; print_embedded_table_cell($value[$k][$i], $cell_options); } } print_embedded_table_end(); } /** * Print full size button * * Inputs: * - title Text in 'col0' * - name Name of the button for the form * - value Button text * - recall_action Recall action for the form handler * - ro_action Button is read-only * - info Extra information * - options Aditional options: * - submit Button is a submit button * - form Button is part of a form (default TRUE, superceeded by 'print_prologue') * - bold Print the extra info in bold font (default TRUE) * - css_class * - style * - tip Tooltip * - icon * - on JavaScript event handlers */ function print_button($title, $name, $value, $recall_action, $ro_actions = NULL, $info = "", $options = NULL) { global $_PAGE_INFO; // set default options if( !is_array($options) ) $options = array(); print_merge_default_options($options, array( 'submit' => FALSE, 'form' => TRUE, 'bold' => TRUE, 'css_class' => "footer_button" ) ); print_prologue($title, $options['form']); echo " $action ) if( strtolower(substr($event, 0, 2)) == "on" ) echo " " . $event . "=\"" . $action . "\""; if( $recall_action ) echo " onClick=\"onSubmit('" . $recall_action . "',''," . (isset($options['xml']) ? $options['xml'] : "1") . ");\""; if( is_ro($ro_actions) ) echo " disabled"; echo ">"; if( $options['icon'] ) echo ""; echo nl2br(strip_tags($value)); echo ""; // Display message? if( strlen($info) ) print_info($name, $info, $options['bold'], $options['info_style']); print_epilogue($options['form']); } /** * Print file upload (etc) control * * Inputs: * - Title Title * - name name * - Upload Upload button? * - onuploadsumbit Upload button submit event * - onchange Browse change event * - info Info message */ function print_input_file($title, $name, $upload = 0, $onuploadsumbit = "", $onchange = "", $info = "", $bold = 1, $hidden_input = FALSE, $multiple_files = FALSE /* $browse_caption , $upload_caption */) { global $_PAGE_INFO; print_prologue($title, TRUE); $args = func_get_args(); if( func_num_args() < 9 ) $browse_caption = _("Browse..."); else $browse_caption = $args[9]; if( func_num_args() < 11 ) $upload_caption = _("Upload..."); else $upload_caption = $args[10]; // Multiple files supported? $multiple_addon = ""; $multiple_name = ""; if ($multiple_files) { $multiple_addon = "multiple=\"multiple\""; $multiple_name = "[]"; } if( browser() != "IE" || browser_version() >= 9.0 ) { if( !$hidden_input ) { // MTinfo equivalent of the element, with input box for the file name and browse button echo ""; echo ""; echo ""; if ($upload) { echo "\n"; } } else { // Upload button (without file name input box) print_button(NULL, $name . "_file_element_overrule", $upload_caption, NULL, NULL, $info, array('onclick' => "getElement('" . $name . "_file_element').click();", 'form' => FALSE)); echo ""; echo ""; } } else { // Old versions of IE; use the somewhat ugly element // IE won't change the text of the browse button... if( $hidden_input ) echo $upload_caption; else echo $browse_caption; echo "
    \n"; // echo ""; if ($upload) { echo "\n"; } // Display message? if (strlen($info)) print_info($name, $info, $bold); } print_epilogue(TRUE); } /** * Print file open button * * Inputs: * - title Title (colum to the left of the control) * - name Identifier for the control * - value Text to print in the control's content * - link URL to call when the control is clicked * - options Options: * - buttons: Array with buttons (with an 'icon' and 'href' or 'action') * - new_window (boolean), default TRUE * - bold Print text in bold font */ function print_file_open($title, $name, $value, $ro_actions, $link, $options = NULL, $bold = 1) { global $_PAGE_INFO; if( !is_array($options) ) $options = array(); if( is_array($options[0]) && isset($options[0]['icon']) ) { // old style (buttons) $options['buttons'] = $options; } print_merge_default_options($options, array('new_window' => TRUE, 'form' => TRUE, 'text_length' => 40)); // // NB: button sizes and text lengths are best guesses and the are not necessarily perfect // // width of the button (override CSS) $button_width = 300; // compensate text width for the embedded buttons if( isset($options['button_width']) ) { $embedded_buttons_width = $options['button_width']; $options['text_length'] -= $embedded_buttons_width / 8; // wild guess: characters are on average 8px wide } else if( is_array($options['buttons']) ) { $embedded_buttons_width = count($options['buttons']) * 20; $options['text_length'] -= count($options['buttons']) * 2; } else $embedded_buttons_width = 0; // disable the link when this button is read-only if( is_ro($ro_actions) ) $link = FALSE; print_prologue($title, TRUE); echo "
    "; echo ""; echo ""; echo ""; if( is_array($options['buttons']) ) foreach( $options['buttons'] as $button ) print_inline_button($button, TRUE); echo ""; echo "
    "; print_link_start($link, array_merge($options, array('id' => $name))); echo " 0 /* TBD? */ ) { echo " onmouseover=\"Tip('" . strclean_tooltip($value) . "',BGCOLOR,'" . $_PAGE_INFO['ini']['tooltip']['background'] . "',BORDERCOLOR, '" . $_PAGE_INFO['ini']['tooltip']['border'] . "');\""; echo " onmouseout=\"UnTip();\""; } $style = ""; if( $options['style'] ) $style .= $options['style']; echo " style=\"" . $style . ";max-width:" . ($button_width - 6 - $embedded_buttons_width) . "px;\""; echo ">"; $button_text = strip_tags($value); $button_text = shorten_text($button_text, $options['text_length'], SHORTEN_NARROW); echo $button_text; echo ""; print_link_end(); echo "
    "; echo "
    "; print_epilogue(TRUE); } /** * Print date control * * Inputs: * - Title Title * - name name * - value session value * - ro_action Read only actions (array) */ function print_date($title, $name, $value, $ro_actions = FALSE, $info = "", $bold = 1) { global $_PAGE_INFO; print_prologue($title, TRUE); echo "
    "; echo ""; if (!is_ro($ro_actions)) { echo "\n"; } // Display message? if (strlen($info)) print_info($name, $info, $bold); echo "
    "; // Disabled control => create hidden control if (is_ro($ro_actions)) { print_hidden_input($name, $value); } print_epilogue(TRUE); } /** * Print time control * * Inputs: * - Title Title * - time_name time name * - time_value time value * - ro_action Read only actions (array) * - info info which must be displayed * - bold info bold */ function print_time($title, $time_name, $time_value, $ro_actions = FALSE, $info = "", $bold = 1) { global $_PAGE_INFO; // Time control $time_options = array(); for ($i = 0; $i < 24; $i++) { for ($j = 0; $j < 4; $j++) { $value = ($i < 10) ? "0" . $i : $i; $value .= ":"; $value .= (!$j) ? "00" : $j*15; $time_options[$value] = $value; } } print_dropdownlist($title, $time_name, $time_value, $time_options, $ro_actions, $info, array('onchange' => "onSubmit('other', '', 1);")); } /** * Print date time control * * Inputs: * - Title Title * - date_name date name * - date_value date value * - time_name time name * - time_value time value * - ro_action Read only actions (array) * - info info which must be displayed * - bold info bold * - extra_info_style extra info style options */ function print_datetime($title, $date_name, $date_value, $time_name, $time_value, $ro_actions = FALSE, $info = "", $bold = 1, $extra_info_style = "") { global $_PAGE_INFO; $options = array(); print_merge_default_options($options, array('css_class' => NULL)); print_prologue($title, TRUE); print_div_start(FALSE, array('css_class' => "datetime")); echo ""; } else { echo " name=\"" . $date_name . "\">"; } if (!is_ro($ro_actions)) { echo "\n"; } // Time control $time_options = array(); for ($i = 0; $i < 24; $i++) { for ($j = 0; $j < 4; $j++) { $value = ($i < 10) ? "0" . $i : $i; $value .= ":"; $value .= (!$j) ? "00" : $j*15; $time_options[$value] = $value; } } print_dropdownlist(NULL, $time_name, $time_value, $time_options, is_ro($ro_actions) || !strlen($date_value), $info, array('onchange' => "onSubmit('other', '', 1);")); print_div_end(); // Disabled control => create hidden control if (is_ro($ro_actions)) { print_hidden_input($date_name, $date_value); } print_epilogue(TRUE); } /** * Print day time control * * Inputs: * - Title Title * - name name * - value session value * - ro_action Read only actions (array) */ function print_daytime($title, $day_name, $day_value, $time_name, $time_value, $ro_actions, $info = "", $bold = 1, $skip_table_end = 0) { global $_PAGE_INFO; if( !is_array($options) ) { // old style parameters $options = array('label' => $options, 'onchange' => $on_change, 'skip_table_end' => $skip_table_end); } print_merge_default_options($options, array('css_class' => NULL)); print_prologue($title, TRUE); print_div_start(FALSE, array('css_class' => "daytime")); // day control $days = array("", ucfirst(_("Monday")), ucfirst(_("Tuesday")), ucfirst(_("Wednesday")), ucfirst(_("Thursday")), ucfirst(_("Friday")), ucfirst(_("Saturday")), ucfirst(_("Sunday"))); print_dropdownlist(NULL, $day_name, $day_value, $days, $ro_actions, NULL, array('id' => "day", 'onchange' => "onSubmit('other', '', 1);")); // Time control $time_options = array(); for ($i = 0; $i < 24; $i++) { for ($j = 0; $j < 4; $j++) { $value = ($i < 10) ? "0" . $i : $i; $value .= ":"; $value .= (!$j) ? "00" : $j*15; $time_options[$value] = $value; } } print_dropdownlist(NULL, $time_name, $time_value, $time_options, is_ro($ro_actions) || !$day_value, $info, array('id' => "time", 'onchange' => "onSubmit('other', '', 1);")); if( !$options['skip_table_end'] ) { print_div_end(); print_epilogue(TRUE); } } /** * Print interval control * * Inputs: * - Title Title * - count_name name for the count input * - unit_name name for the unit selection * - value session value * - ro_action Read only actions (array) */ function print_time_interval($title, $name, $interval_name, $ro_actions, $info = "", $bold = 1, $skip_table_end = 0) { global $_PAGE_INFO; if( !is_array($options) ) { // old style parameters $options = array('label' => $options, 'onchange' => $on_change, 'skip_table_end' => $skip_table_end); } print_merge_default_options($options, array('css_class' => NULL)); print_prologue($title, TRUE); echo "
    "; //// TO DO // Display message? if (strlen($info)) print_info($name, $info, $bold); // Disabled control => create hidden control if (is_ro($ro_actions)) { print_hidden_input($day_name, $day_value); } if( !$options['skip_table_end'] ) { echo "
    \n"; print_epilogue(TRUE); } } /** * Print password * * Inputs: * - Title Title * - name name * - value session value * - info info message * - extra_info_style extra info style options * - center center control */ function print_password($title, $name, $value, $info = "", $bold = 1, $extra_info_style = "", $center = "") { print_prologue($title, TRUE); // Alignment if (strlen($center)) { echo "
    "; } if( !isset($value) || strlen($value) == 0 ) { // show some dummy characters $value = addcslashes(PASSWD_DISPLAY_TEXT, "\"\'\n\r\f\t"); } else $value = strip_tags($value); echo ""; echo "\n"; // Alignment if (strlen($center)) { echo "
    "; } if (strlen($info)) print_info($name, $info, $bold, $extra_info_style); print_epilogue(TRUE); } /** * Print checkbox * * Inputs: * - Title Title * - name name * - value session value * - value_checked value checked * - ro_action Read only actions (array) * - info info message" * - label Add label */ function print_checkbox($title, $name, $value, $value_checked, $ro_actions, $options = NULL, $on_change = NULL) { global $_PAGE_INFO; if( !is_array($options) ) { // old style parameters $options = array('label' => $options, 'onchange' => $on_change); } print_merge_default_options($options, array('css_class' => 'checkbox_element', 'form' => !isset($_SESSION[$_PAGE_INFO['id']]['extended_menu']))); $on_form = print_prologue( array('form' => array('title' => $title)), $options['form'] ); $need_div = $options['buttons'] || $options['action']; if( is_ro($ro_actions) && $options['tooltip'] ) { echo "
    "; } if( $options['href'] ) print_link_start($options['href']); if( $need_div ) { echo "
    "; } if( $options['center'] ) echo "
    "; if( $options['buttons'] ) { echo ""; foreach( $options['buttons'] as $button ) print_inline_button($button, TRUE); echo "
    "; } if( $options['label'] ) { echo ""; } echo " $action ) if( strtolower(substr($event, 0, 2)) == "on" ) echo " " . $event . "=\"" . $action . "\""; if ($value == $value_checked) { echo " checked"; } echo " onkeypress=\"return noenter(event,this);\""; echo ">\n"; if( $options['style'] ) { echo ""; } if( $options['label'] ) { echo $options['label']; } else if( !$on_form ) { echo $title; } if( $options['style'] ) { echo ""; } if( $options['label'] ) { echo "\n"; } if( $options['buttons'] ) { echo "
    "; } if( $options['info'] ) print_info($name, $options['info']); if( $options['center'] ) echo "
    "; if( $need_div ) { echo "
    "; } if( $options['href'] ) print_link_end(); if( is_ro($ro_actions) && $value == $value_checked ) { print_hidden_input($name, $value); } if( !$options['skip_epilogue'] ) print_epilogue($options['form']); } /** * Print radiobutton * * Inputs: * - Title Title * - name name * - value session value * - value_checked value checked * - ro_action Read only actions (array) * - info info message" * - label Add label * - skip_table_end Skip table end */ function print_radiobutton($title, $name, $value, $value_checked, $ro_actions, $options = NULL, $on_change = NULL, $skip_table_end = FALSE) { global $_PAGE_INFO; if( !is_array($options) ) { // old style parameters $options = array('label' => $options, 'onchange' => $on_change, 'skip_table_end' => $skip_table_end); } print_merge_default_options($options, array('css_class' => "radio_element", 'form' => !isset($_SESSION[$_PAGE_INFO['id']]['extended_menu']))); $on_form = print_prologue( array('form' => array('title' => $title)), $options['form'] ); if( is_ro($ro_actions) && $options['tooltip'] ) { echo "
    "; } if( $options['center'] ) echo "
    "; if( $options['label'] ) { echo ""; } echo " $action ) if( strtolower(substr($event, 0, 2)) == "on" ) echo " " . $event . "=\"" . $action . "\""; if ($value == $value_checked) { echo " checked"; } echo " onkeypress=\"return noenter(event,this)\""; echo ">\n"; if( $options['style'] ) { echo ""; } if( $options['label'] ) { echo $options['label']; } else if( !$on_form ) { echo $title; } if( $options['style'] ) { echo ""; } if( $options['label'] ) { echo "\n"; } if( $options['info'] ) print_info($name, $options['info']); if( $options['center'] ) echo "
    "; if( is_ro($ro_actions) && $value == $value_checked ) { print_hidden_input($name, $value); } if( !$options['skip_table_end'] && !$options['skip_epilogue'] ) print_epilogue($options['form']); } /** * Print tel/fax/mob input * * Inputs: * - Title Title * - name name * - value session value * - ro_actions Read only actions (array) * - rc_actions Recall actions on which this input must react (array) * - actions Valid actions (array) * - old_info Old info value * - required 0 (nothing)/1 (required)/2 (checking) */ function print_tel_input($title, $name, $value, $ro_actions, $rc_actions, $actions, $old_info = "", $req = 0) { // Check for correct action if (($req == 1) && (!is_ro($ro_actions))) { $info = "*"; } else { $info = ""; } // Check recall action; always okay when none set $result = 0; if (is_array($rc_actions)) { foreach ($rc_actions as $rc) { if (is_valid_recall($rc)) { $result = 1; } } } if ($result) { // Check for correct action if (is_array($actions)) { $result = 0; foreach ($actions as $action) { if (is_valid_action($action)) { $result = 1; } } } if ($result) { // Check if this value is required if ($req == 1) { if (!strlen($value)) { $info = "Required field!"; $result = 0; } else { $info = "*"; } } } if (($result) || ($req == 2)) { // Check number if (!valid_fax_tel($value)) { $info = _("Invalid phone number!"); } } } else if (is_valid_recall()) { // Different recall => restore old value $info = $old_info; } print_input($title, $name, $value, $ro_actions, $info); } /** * Print email input * * Inputs: * - Title Title * - name name * - value session value * - ro_actions Read only actions (array) * - rc_actions Recall actions (array) * - actions Valid actions (array) * - old_info Old info value * - required 0 (nothing)/1 (required)/2 (checking) */ function print_email_input($title, $name, $value, $ro_actions, $rc_actions, $actions, $old_info = "", $req = 0) { // Check for correct action if (($req == 1) && (!is_ro($ro_actions))) { $info = "*"; } else { $info = ""; } // Check recall action $result = 0; if (is_array($rc_actions)) { foreach ($rc_actions as $rc) { if (is_valid_recall($rc)) { $result = 1; } } } if ($result) { // Check for correct action $result = 0; if (is_array($actions)) { foreach ($actions as $action) { if (is_valid_action($action)) { $result = 1; } } } if ($result) { // Check if this value is required if ($req == 1) { if (!strlen($value)) { $info = "Required field!"; $result = 0; } else { $info = "*"; } } } if (($result) || ($req == 2)) { // Check email if (!valid_email($value)) { $info = "Invalid email!"; } } } else if (is_valid_recall()) { // Different recall => restore old value $info = $old_info; } print_input($title, $name, $value, $ro_actions, $info); } /** * Print geo input * * Inputs: * - Title Title * - name name * - value session value * - ro_actions Read only actions (array) * - rc_actions Recall actions (array) * - actions Valid actions (array) * - old_info Old info value * - required 0 (nothing)/1 (required)/2 (checking) */ function print_geo_input($title, $name, $value, $ro_actions, $rc_actions, $actions, $old_info = "", $req = 0) { // Check for correct action if (($req == 1) && (!is_ro($ro_actions))) { $info = "*"; } else { $info = ""; } // Check recall action $result = 0; if (is_array($rc_actions)) { foreach ($rc_actions as $rc) { if (is_valid_recall($rc)) { $result = 1; } } } if ($result) { // Check for correct action $result = 0; if (is_array($actions)) { foreach ($actions as $action) { if (is_valid_action($action)) { $result = 1; } } } if ($result) { // Check if this value is required if ($req == 1) { if (!strlen($value)) { $info = "Required field!"; $result = 0; } else { $info = "*"; } } } if (($result) || ($req == 2)) { // Check geo if (!valid_geo($value)) { $info = "Invalid geo-value!"; } } } else if (is_valid_recall()) { // Different recall => restore old value $info = $old_info; } print_input($title, $name, $value, $ro_actions, $info); } /** * Print tiny button * * Inputs: * - title Title in the left column of a form * - name Button text or array with button texts or array with button info, in * which case 'action' must _not_ be set. * The button info array in the latter case must contain the keys * 'button_text', 'action' and 'ro' for read-only buttons. * NB: this is the only way to set the ro-options for each button individually * - action JavaScript code for the 'onclick' event(s), when not set in the array 'name' * - ro_actions Read-only options * - info Info field * - options Additional options */ function print_tiny_button($title, $name, $action, $ro_actions = NULL, $info = NULL, $options = NULL, $bold = TRUE) { global $_PAGE_INFO; // set the default options if( !is_array($options) ) $options = array(); print_merge_default_options($options, array('css_class' => "tiny_button", 'container' => TRUE, 'form' => !isset($_SESSION[$_PAGE_INFO['id']]['extended_menu']))); if( $options['css_extra'] ) { $options['css_class'] .= " " . $options['css_extra']; } if( is_mobile_browser() ) { $options['css_class'] .= " mobile"; } $on_form = print_prologue( array('form' => array('title' => $title)), $options['form'] ); // container if( $options['container'] ) { echo "
    "; if( !$on_form ) echo $title; } if( is_array($name) ) { // multiple buttons (extended functionality) if( !$action ) foreach( $name /* duh */ as $button ) { if( $button['tip'] ) { $button['onmouseover'] .= "Tip('" . strclean_tooltip($button['tip']) . "',BGCOLOR,'" . $_PAGE_INFO['ini']['tooltip']['background'] . "',BORDERCOLOR, '" . $_PAGE_INFO['ini']['tooltip']['border'] . "');"; $button['onmouseout'] .= "UnTip();"; } if( $button['action'] ) $button['onclick'] .= $button['action']; if( $button['href'] ) { echo ""; } echo "\n"; } else while( $name ) { $button = array( 'button_text' => array_shift($name), 'action' => array_shift($action) ); echo "\n"; } } else { // simple. single button echo "\n"; } if( $options['container'] ) echo "
    \n"; // Display message? if( strlen($info) ) print_info($name, $info, $bold, $options['info_style']); print_epilogue($options['form']); } /** * Print hidden input * * Inputs: * - name name * - value session value */ function print_hidden_input($name, $value) { echo ""; } /** * Print hidden state (like 'print_hidden_input()', but the value can be an array) */ function print_hidden_state($name, $value) { if( isset($value) ) { if( is_array($value) ) { foreach( $value as $key => $item ) { print_hidden_state($name . "[" . $key . "]", $item); } } else { print_hidden_input($name, $value); } } } /** * Print user rights entry table * * Inputs: * - title Title * - name Name for the checkboxes (will put an array in the form data) * - rights All available rights * - rights_enabled All enabled rights * - rights_checked All checked rights */ function print_rights_overview($title, $name, $rights, $rights_enabled, $rights_checked) { global $_PAGE_INFO; global $user_right_translation; // Skip these rights $skip_rights = array( "menu:lansen:wijzigen", "menu:projecten:wijzigen", "menu:projecten:verwijderen", "menu:service:magazijnbeheer", "zkl 3000 rc", "google_maps", "trillingssensor", "schakelen", "productie", "administratie", "magazijnbeheer", // replaced by menu:service rights; will be removed "menu:faq" // TO DO: will be removed from the database once the 'rechten' field is up-to-date ); // The LHS rights below are automatically checked when the user has the RHS right $include_rights = array( "menu:service:wijzigen" => "menu:service:manager" ); print_prologue($title, TRUE); echo "\n"; // Determine all menu items (menu:sub_menu:menu_item or menu:menu_item or General when no ':') $menu_items = array(); if (is_array($rights)) { foreach($rights as $right) { if (!in_array($right, $skip_rights)) { // Check user right translations if( isset($user_right_translation[$right]) ) $right = $user_right_translation[$right]; // Find ":" char in string $pos1 = strpos($right, ":"); if ($pos1 !== false) { // Find next ":" char in string $pos2 = strpos($right, ":", ($pos1 + strlen(":"))); if ($pos2 !== false) { // Add administrator menu if (substr($right, $pos2 + strlen(":")) == "root") { $menu = "root"; } else { $menu = substr($right, 0, $pos2); } } else { $menu = $right; } // Put menu item in array when not empty if (strlen($menu)) { array_push($menu_items, $menu); } } else { array_push($menu_items, "general"); } } } } // Add psuedo-menus $menu_items[] = "menu:app"; // Remove duplicated array values $menu_items = array_unique($menu_items); // Move general items to the top of the menu; the root menu items will be place on top of this below $value = array_search("general", $menu_items); if ($value !== FALSE) { unset($menu_items[$value]); array_unshift($menu_items, "general"); } // Move administrator to the top of the menu $value = array_search("root", $menu_items); if ($value !== FALSE) { unset($menu_items[$value]); array_unshift($menu_items, "root"); } // Display checkbox table with header if (is_array($menu_items)) { foreach ($menu_items as $menu_item) { if (!empty($menu_item)) { // Reset counter $i = 0; // Find ":" char in menu item $pos1 = strpos($menu_item, ":"); echo "\n"; echo ""; } echo "\n"; // Number 3 => end of row if (($i % 3) == 2) { echo "\n"; } $i++; $j++; } } } } } // JW20141003: needed for IE11 to print top and right borders while( ($i++ % 3) ) echo ""; echo "\n"; // End of row when less then 3 items if (($i % 3) != 0) { echo "\n"; } } } } echo "
    "; echo ""; echo _("right:" . $menu_item); echo ""; //Display checkboxes if (is_array($rights)) { foreach ($rights as $right) { if (!in_array($right, $skip_rights)) { $right_menu = $right; // Translate the user right in order to put it in the right menu if( isset($user_right_translation[$right_menu]) ) $right_menu = $user_right_translation[$right_menu]; $pos1 = strpos($right_menu, $menu_item); // Check if this menu item is a part of the right => this right must be put in this menu // Exception: when the menu item is General and no ':' available in the right if ((($pos1 !== false) || ((strpos($right_menu, ":") === false) && ($menu_item == "general")))) { // Double check if this is realy the correct menu_item and if this is an admin right if ((((strlen($right_menu) == strlen($menu_item)) || ($right_menu[($pos1 + strlen($menu_item))] == ":") || ($pos1 === false)) && (strpos($right_menu, "root") === false)) || ((strpos($right_menu, "root") !== false) && ($menu_item == "root"))) { // Number 1 => start of new row if (($i % 3) == 0) { if( $i != 0 ) echo "
    "; // Strip menu:,status:,etc: of user right $pos1 = strpos($right_menu, ":"); $pos2 = strpos($right_menu, ":", $pos1 + strlen(":")); if (($pos1 !== false) && ($pos2 !== false)) { if (substr($right_menu, $pos2 + strlen(":")) == "root") { // 2 x ":" available and admin right => remove menu and right part (menu:menu_item:right) $sright = substr($right_menu, ($pos1 + strlen(":")), $pos2 - ($pos1 + strlen(":"))); } else { // 2 x ":" available => remove two parts for example (menu:menu_item:right) $sright = substr($right_menu, ($pos2 + strlen(":"))); } } else if ($pos1 !== false) { // 1 x ":" available => right for accessing menu $sright = "toegang"; } else { // 0 x ":" available => General item $sright = $right_menu; } // Skip "current" customer when editing customer $skip_rights_current = (is_valid_action("cust_change","cust_new")); // Verify rights => check/unchecked and enable/disable checkbox echo ""; echo "\n"; // Save all values which are checked but now are disabled if ((is_array($rights_checked)) && (is_array($rights_enabled))) { if ((!in_array($right_menu, $rights_enabled)) && (in_array($right_menu, $rights_checked))) { // Store hidden input print_hidden_input($right_menu,$right_menu); } } echo "
    \n"; print_epilogue(TRUE); } /** * Print left right control * * Inputs: * - title control title * - name name * - object page object (project_info for example) * - labels labels for above the listboxes * - all_items array containing (id, value, color) * - initial_left_items array containing (id, value, color) => also used for ro actions * - ro_actions Read only actions (array) * - height Number of entries * - all Handle all items at once? */ function print_left_right_control($title, $name, $object, $labels, $all_items, $initial_left_items, $ro_actions, $options = NULL, $all = FALSE) { global $_PAGE_INFO; // old and new style parameters if( !is_array($options) ) { // old style $options = array('size' => $options, 'all' => $all); } print_merge_default_options($options, array('form' => FALSE, 'size' => 10, 'ro_size' => 0, 'all' => FALSE, 'sort' => TRUE)); // Define layout print_prologue($title, TRUE); // Assess labels; no colon at the end probably means old style (and not translated) // NB: translation if( $labels ) foreach( $labels as &$label ) { if( $label && substr($label, -1) != ":" ) { $label = $label . ":"; } } // PHP bug unset($label); // the data is the session can have a single of double (array) index if( is_array($object) ) $_SESSION_REF = &$_SESSION[$_PAGE_INFO['id']][$object[0]][$object[1]]; else $_SESSION_REF = &$_SESSION[$_PAGE_INFO['id']][$object]; // set initial right items $right_items = array(); if( is_array($all_items) ) foreach( $all_items as $item ) $right_items[$item['id']] = array('text' => $item['value'], 'color' => $item['color']); // set initial left items $has_left_items = FALSE; // copy the array and rely on the 'hide' option in 'print_selection()' $left_items = $right_items; // initially hide all items in the left box foreach( $left_items as &$item ) $item['hide'] = TRUE; unset($item); // avoid PHP bug // show the items from the session (recall or previous settings) or from the // initial settings (for special cases?) if( isset($_SESSION_REF[$name . "_left_ids"]) && $right_items ) { if( strlen($_SESSION_REF[$name . "_left_ids"]) ) { $ids = explode(",", $_SESSION_REF[$name . "_left_ids"]); if( is_array($ids) ) { foreach( $ids as $id ) if( isset($left_items[$id]) ) { $left_items[$id]['hide'] = FALSE; $has_left_items = TRUE; } } } } else if( is_array($initial_left_items) ) { // NB: it is allowed not to have an "all" array if( !$right_items ) { $left_items = array(); foreach( $initial_left_items as $item ) { // add the item to the leftside ("selected") box $left_items[$item['id']] = array('text' => $item['value'], 'color' => $item['color'], 'hide' => FALSE); $has_left_items = TRUE; // also add to the rightside box, but hidden $right_items[$item['id']] = $left_items[$item['id']]; $right_items[$item['id']]['hide'] = TRUE; } } else foreach( $initial_left_items as $item ) { $left_items[$item['id']]['hide'] = FALSE; $has_left_items = TRUE; // the selected items _must_ be in the array with all items if( !$right_items[$item['id']] ) trigger_error("Item " . $item['id'] . " (" . $item['value'] . ") is not set"); } } // Read only? if( is_ro($ro_actions) ) { $ro_items = array(); foreach( $left_items as $id => $item ) if( !$item['hide'] ) $ro_items[$id] = $item; print_listbox(NULL, $name . "_left", NULL, $ro_items, $options['ro_size'], TRUE); } else { // Filter value $filter_value = $_SESSION_REF[$name . ":filter"]; // apply filter and hide selected items for the right box foreach( $right_items as $id => $item ) if( ($left_items && !$left_items[$id]['hide']) || ($filter_value && stripos($item['text'], $filter_value) === FALSE) ) $right_items[$id]['hide'] = TRUE; echo "\n"; echo "\n"; // Left lisbox echo ""; // Table for buttons echo "\n"; // right listbox echo "\n"; echo "\n"; echo "
    "; if( $labels ) echo ""; print_listbox(NULL, $name . "_left", NULL, $left_items, $options['size'], FALSE, NULL, array('id' => "left_right_select", 'sort' => $options['sort'], 'multi' => TRUE, 'ondblclick' => "_js_leftright_" . $name . ".OnClickLtr();")); if( $options['empty'] ) { print_checkbox(NULL, FALSE, !$has_left_items, TRUE, TRUE, array('label' => $options['empty'])); } echo "\n"; echo "\n"; // filler echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo "
    "; $icon = ($all) ? "<<" : "<"; echo ""; echo "
    "; $icon = ($all) ? ">>" : ">"; echo ""; echo "
    \n"; echo "
    "; echo "
    "; if( $labels ) echo ""; print_listbox(NULL, $name . "_right", NULL, $right_items, $options['size'], FALSE, NULL, array('id' => "left_right_select", 'sort' => $options['sort'], 'multi' => TRUE, 'ondblclick' => "_js_leftright_" . $name . ".OnClickRtl();")); // add filter buttons if( !$all ) { echo ""; // filter entry box echo ""; // reset filter button echo "\n"; } echo "
    "; echo "
    \n"; } // Store left ids $left_ids = array(); foreach( $left_items as $id => $item ) if( !$item['hide'] ) $left_ids[] = $id; print_hidden_input($name . "_left_ids", implode(",", $left_ids)); // Store right ids $right_ids = array(); foreach( $right_items as $id => $item ) if( !$item['hide'] ) $right_ids[] = $id; print_hidden_input($name . "_right_ids", implode(",", $right_ids)); // Update/store session variables $_SESSION_REF[$name . "_left_ids"] = implode(",", $left_ids); // create JavaScript object to handle the events if( !is_ro($ro_actions) ) { echo "\n"; } print_epilogue(TRUE); // PHP bug - unset $_SESSION_REF as a reference; doesn't do anything with the object referenced unset($_SESSION_REF); } /** * Start and end a scroll area (scrollable div) * * Inputs: * - options Options array with (all optional) * - 'max-height' Override default height from CSS * - 'style' Other styles */ function print_scrollarea_start($title = FALSE, $options = FALSE) { global $_PAGE_INFO; // old style of calling w/o title if( is_array($title) ) $options = $title; // check if there are options if( is_array($options) ) { print_merge_default_options($options, array('form' => !isset($_SESSION[$_PAGE_INFO['id']]['extended_menu']))); } else { // old style parameters $options = array('form' => TRUE); } print_prologue($title, $options['form']); // NB: translation echo "
    "; // start (dummy) table; this way the other 'print_xxx' functions think // it is a normal form (BUT col0 and col1 are zero-width!) echo ""; if( isset($_PAGE_INFO['form']) ) $_PAGE_INFO['form']['scrollable_div'] = TRUE; } function print_scrollarea_end($options = FALSE /* not used */) { global $_PAGE_INFO; echo ""; echo "
    "; if( isset($_PAGE_INFO['form']) ) unset($_PAGE_INFO['form']['scrollable_div']); print_epilogue(TRUE); } /** * Embedded table * * Inputs: * - title Title * - headers Column headers (array of translated strings) * - options Option array * - form Set to FALSE to break out of the form (the * table will span all three columns of the * default MTinfo form) */ function print_embedded_table_start($title, $headers = FALSE, $options = NULL) { global $_PAGE_INFO; if( !is_array($options) ) $options = array(); print_merge_default_options($options, array('form' => TRUE, 'css_class' => "embedded_table")); // NB: $full_width = $options['full_width'] || (must_start_form_row() && !$options['form']); if( $full_width ) { if( $_PAGE_INFO['form'] ) { echo "\n"; echo ""; echo "\n"; // not calling the prologue, so increment "inside row" counter here $_PAGE_INFO['form']['row']++; } else { // TO DO: intended for recalls/xml_data calls } } else print_prologue($title); if( $options['div'] ) { $div_style = array(); echo ""; $_PAGE_INFO['embedded_table']['div'] = TRUE; } // start the embedded table echo "\n"; // and store this fact in the global state for this page $_PAGE_INFO['embedded_table'] = array('full_width' => $full_width, 'row' => FALSE, 'col' => FALSE); // print header row, when specified if( $headers ) { echo ""; foreach( $headers as $header ) { if( is_array($header) ) { $style = array(); if( $header['style'] ) $style[] = $header['style']; if( $header['width'] ) $style[] = "width:" . $header['width'] . (is_numeric($header['width']) ? "px;" : ";"); if( $header['height'] ) $style[] = "height:" . $header['height'] . (is_numeric($header['height']) ? "px;" : ";"); $header_title = $header['text']; } else { $header_title = $header; // something weird happens with the indices below... $header = array(); } echo ""; if( $header['div'] ) { $div_style = array(); echo ""; } if( $header['icon'] ) { echo " "; } if( $header['html'] ) echo $header_title; else echo nl2br(strip_tags($header_title)); if( $header['div'] ) { echo "
    "; } echo "\n"; } echo "\n"; } } function print_embedded_table_end() { global $_PAGE_INFO; // clean up $full_width = $_PAGE_INFO['embedded_table']['full_width']; if( $_PAGE_INFO['p'] ) print_paragraph_end(); if( $_PAGE_INFO['embedded_table']['div'] ) echo ""; if( $_PAGE_INFO['embedded_table']['col'] ) echo ""; if( $_PAGE_INFO['embedded_table']['row'] ) echo ""; unset($_PAGE_INFO['embedded_table']); // close the table echo "\n"; // close the enclosing DIV, when used if( $_PAGE_INFO['embedded_table']['div'] ) echo ""; if( $full_width ) { echo "\n"; echo "\n"; $_PAGE_INFO['form']['row']--; } else print_epilogue(); } function print_embedded_table_row_start($row = 0, $options = NULL) { global $_PAGE_INFO; // option: call with only 'options' if( is_array($row) && is_null($options) ) { $options = $row; unset($row); } if( !is_array($options) ) $options = array(); // clean up if( $_PAGE_INFO['p'] ) print_paragraph_end(); if( $_PAGE_INFO['embedded_table']['div'] ) echo ""; if( $_PAGE_INFO['embedded_table']['col'] ) echo ""; if( $_PAGE_INFO['embedded_table']['row'] ) echo ""; echo " $action ) if( strtolower(substr($event, 0, 2)) == "on" ) echo " " . $event . "=\"" . $action . "\""; echo ">"; $_PAGE_INFO['embedded_table']['col'] = FALSE; $_PAGE_INFO['embedded_table']['row'] = TRUE; } function print_embedded_table_row_end($row = 0) { global $_PAGE_INFO; if( $_PAGE_INFO['p'] ) print_paragraph_end(); if( $_PAGE_INFO['embedded_table']['div'] ) echo ""; if( $_PAGE_INFO['embedded_table']['col'] ) echo ""; echo "\n"; $_PAGE_INFO['embedded_table']['col'] = FALSE; $_PAGE_INFO['embedded_table']['row'] = FALSE; } function print_embedded_table_row($row, $data, $options = NULL) { if( !is_array($options) ) $options = array(); if( !isset($options['colspan']) ) $options['colspan'] = "*"; print_embedded_table_row_start($row, $options); if( !is_array($data) ) { print_embedded_table_cell($data, $options); } else if( isset($options['columns']) ) { // use the order specified foreach( $options['columns'] as $column ) { if( is_array($data[$column]) ) { // 'data' may have embedded options... if( isset($data[$column]['text']) ) $text = $data[$column]['text']; else $text = $data[$column]['value']; print_embedded_table_cell($text, $data[$column]); } else { print_embedded_table_cell($data[$column], $options); } } } else { // print the items in 'data' in order foreach( $data as $data_item ) { if( is_array($data_item) ) { // 'data' may have embedded options... if( isset($data_item['text']) ) $text = $data_item['text']; else $text = $data_item['value']; print_embedded_table_cell($text, $data_item); } else { print_embedded_table_cell($data_item, $options); } } } print_embedded_table_row_end($row); } function print_embedded_table_cell_start($options = NULL) { global $_PAGE_INFO; if( !is_array($options) ) $options = array(); // close preceeding cell if( $_PAGE_INFO['embedded_table']['div'] ) echo ""; if( $_PAGE_INFO['embedded_table']['col'] ) echo ""; echo " $action ) if( strtolower(substr($event, 0, 2)) == "on" ) echo " " . $event . "=\"" . $action . "\""; if( ($tooltip = $options['tip']) || ($tooltip = $options['tooltip']) ) { echo " onmouseover=\"Tip('" . strclean_tooltip($tooltip) . "',BGCOLOR,'" . $_PAGE_INFO['ini']['tooltip']['background'] . "',BORDERCOLOR, '" . $_PAGE_INFO['ini']['tooltip']['border'] . "');\""; echo " onmouseout=\"UnTip();\""; } echo ">"; $_PAGE_INFO['embedded_table']['col'] = TRUE; if( $options['div'] ) { $div_style = array(); echo ""; $_PAGE_INFO['embedded_table']['div'] = TRUE; } } function print_embedded_table_cell_end() { global $_PAGE_INFO; if( $_PAGE_INFO['p'] ) print_paragraph_end(); if( $_PAGE_INFO['embedded_table']['div'] ) echo ""; echo ""; $_PAGE_INFO['embedded_table']['col'] = FALSE; } function print_embedded_table_cell($text, $options = NULL) { print_embedded_table_cell_start($options); $text_options = array(); if( $options['href'] ) $text_options['href'] = $options['href']; if( $options['anchor'] ) $text_options['anchor'] = $options['anchor']; if( $options['icon'] ) $text_options['icon'] = $options['icon']; if( $options['buttons'] ) $text_options['buttons'] = $options['buttons']; print_text($text, $text_options); print_embedded_table_cell_end(); } /** * A 'div' on a form */ function print_div_start($id, $options = NULL) { global $_PAGE_INFO; print_prologue(); echo ""; $_PAGE_INFO['div']['active'] = $id; } function print_div_end() { global $_PAGE_INFO; unset($_PAGE_INFO['div']); echo ""; print_epilogue(); } /** * A'p' element on a form */ function print_paragraph_start($options = NULL) { global $_PAGE_INFO; if( isset($_PAGE_INFO['p']) ) print_paragraph_end(); print_prologue(); echo ""; $_PAGE_INFO['p']['line'] = 0; } function print_paragraph_end($options = NULL) { global $_PAGE_INFO; unset($_PAGE_INFO['p']); echo "

    \n"; print_epilogue(); } /** * Print image * * Inputs: * - title Title to print in "col1" * - src Image source * - options Options: * - css_class, style * - tip - show a tooltip * - alt - alternative text when the image is not found */ function print_image($title = "", $src, $options = NULL) { global $_PAGE_INFO; if( !$options ) $options = array(); if( !$options['skip_prologue'] ) print_prologue($title, TRUE); if( $options['href'] ) print_link_start($options['href'], $options); echo " $action ) if( strtolower(substr($event, 0, 2)) == "on" ) echo " " . $event . "=\"" . $action . "\""; if( $options['alt'] ) { echo " alt=\"" . $options['alt'] . "\""; } else { echo " alt=\"\""; } echo ">"; if( $options['href'] ) print_link_end(); if( !$options['skip_prologue'] ) print_epilogue(); } /** * Store result in session info * * Inputs: * - data Data which must be stored */ function result_store($data) { if (!empty($data)) { $result = ""; for ($i = 0; $i