src.dualinventive.com/mtinfo/dist/webroot/rc-4.05/include/form_elements.php

4135 lines
142 KiB
PHP

<?php
/** \file include\form_elements.php
* \brief DI webinterface form elements
* \author Rob Schalken, Core|Vision
* \version $Revision: 26471 $
* \date $Date: 2016-03-22 14:49:49 +0100 (Tue, 22 Mar 2016) $
*
* This file contains the form elements
*
* NB, future changes:
* - translations should be done at top-level, _not_ in this file
* - all forms should be rewritten to 'print_form_start()'/'print_form_end()'
* - all printable items should get an '$options' array to allow for future
* extensions
* - when all this is complete
* - remove the translations via gettext in this file, i.e. remove "_(...)"
* -> 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", "<br>", htmlspecialchars(strip_tags(str_replace("<br>", "\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 "<input id=\"input_info\" type=\"text\" name=\"" . $info_name . "\" value=\"" . _($info) . "\" readonly tabindex=\"-1\"";
if ($bold) {
echo " style=\"font-weight:bold;" . $extra_info_style . "\"";
}
else if ((!$bold) && (strlen($extra_info_style))) {
echo " style=\"" . $extra_info_style . "\"";
}
if( shorten_text(_($info), 20) != _($info) ) {
echo " onmouseover=\"Tip('" . strclean_tooltip(_($info)) . "',BGCOLOR,'" . $_PAGE_INFO['ini']['tooltip']['background'] . "',BORDERCOLOR, '" . $_PAGE_INFO['ini']['tooltip']['border'] . "');\"";
echo " onmouseout=\"UnTip();\"";
}
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 "<td class=\"action_button\" ";
if( $button['style'] ) echo " style=\"" . $button['style'] . "\"";
echo ">";
if( $button['href'] ) print_link_start($button['href']);
echo "<div";
if( $button['action'] ) echo " class=\"action_button\"";
else echo " class=\"no_button\"";
if( $button['id'] ) echo " id=\"" . $button['id'] . "\"";
if( $button['action'] ) $button['onclick'] .= $button['action'];
foreach( $button as $event => $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 "<img src=\"" . $button['icon'] . "\">";
else if( $button['text'] ) echo "<p>" . $button['text'] . "</p>";
echo "</div>";
if( $button['href'] ) print_link_end();
if( $in_table ) echo "</td>";
}
/**
* 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 = "<br>\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 "<tr>\n";
echo "<td id=\"col0\"></td>\n";
echo "<td id=\"col1\">";
if( $_title ) echo "<p>" . $_title . "</p>\n";
echo "</td>\n";
echo "<td id=\"col2\">";
}
else {
// in a paragraph? print a line break
if( isset($_PAGE_INFO['p']) && $_PAGE_INFO['p']['line']++ > 0 ) echo "<br>\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 "<div";
if( $title['css_class'] ) echo " class=\"" . $title['css_class'] . "\"";
if( $title['style'] ) echo " style=\"display: inline-block;" . $title['style'] . "\"";
echo ">";
echo $_title . $sep;
echo "</div>";
}
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 </td> when the option "join_with_next" is set;
// the <td> 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 "</td>";
echo "<td id=\"col3\"></td>";
echo "</tr>\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 <ol> or <ul>)
*
* 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 "<li>";
$_PAGE_INFO['list'] = TRUE;
}
if( $link ) {
echo "<a";
// show the link
echo " href=\"" . $link . "\"";
}
else echo "<span";
if( $options['css_class'] ) echo " class=\"" . $options['css_class'] . "\"";
else echo " class=\"href\"";
if( $options['style'] ) echo " class=\"" . $options['style'] . "\"";
// does this link have an id? mostly for CSS...
if( $options['id'] ) echo " id=\"" . $options['id'] . "\"";
if( $options['name'] ) echo " name=\"" . $options['name'] . "\"";
if( $options['title'] ) echo " title=\"" . $options['title'] . "\"";
// the link
if( $options['replace'] ) {
// replace the contents of the current window; session is _not_ saved
// and the current page may not appear in the browser history
$options['onclick'] .= "window.location.href='" . $link . "';";
}
else if( substr($link, 0, 11) == "javascript:" ) {
// javascript link
$options['onclick'] .= substr($link, 11);
}
else if( $options['target'] && strcasecmp($options['target'], '_self') ) {
// opening in a new window (no need to save the data as the originating
// window is still in tact)
$options['onclick'] .= "window.open('" . $link . "','" . $options['target'] . "');";
}
else if( $options['new_window'] ) {
// opening in a new window (no need to save the data as the originating
// window is still in tact)
$options['onclick'] .= "window.open('" . $link . "');";
}
else {
// make sure that the form data is saved in the session
// the function 'submitFormAndFollow()' is defined in "java.js"
$options['onclick'] .= "submitFormAndFollow('" . $link . "');";
}
// do _not_ follow the "a href"; instead, rely on the javascript
$options['onclick'] .= "return false;";
// context menu, by default with 'open in new window' and 'open in new tab'
if( !$options['oncontextmenu'] ) $options['oncontextmenu'] = "ShowPopup(this);";
// tooltip
if( $options['tip'] ) {
$options['onmouseover'] .= "Tip('" . strclean_tooltip($options['tip']) . "',BGCOLOR,'" . $_PAGE_INFO['ini']['tooltip']['background'] . "',BORDERCOLOR, '" . $_PAGE_INFO['ini']['tooltip']['border'] . "');";
$options['onmouseout'] .= "UnTip();";
}
// events
foreach( $options as $event => $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 "</a>";
else
echo "</span>";
unset($_PAGE_INFO['form']['link']);
}
else {
// caller must check
echo "</a>";
}
// part of an ordered or unordered list?
if( $_PAGE_INFO['list'] ) {
echo "</li>\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 "<form id=\"form\" name=\"" . $name . "\" action=\"" . $action . "\" method=\"POST\" autocomplete=\"off\" enctype=\"multipart/form-data\">\n";
// Add CSRF (cross-site request forgery) token
echo "<input type=\"hidden\" name=\"__csrf_token__\" value=\"" . csrf_create_token("form") . "\">\n";
echo "<table";
echo " class=\"" . $options['css_class'];
if( isset($_SESSION[$_PAGE_INFO['id']]['extended_menu']) ) echo " extended_menu";
echo "\"";
echo " align=\"center\"";
if( $options['id'] ) echo " id=\"" . $options['id'] . "\"";
echo ">\n";
$_PAGE_INFO['form']['active'] = array('name' => $name);
$_PAGE_INFO['form']['row'] = 0; // reference counter
}
function print_form_end()
{
global $_PAGE_INFO;
echo "</table>\n";
echo "</form>\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 "<center>\n";
if (strlen($header)) {
echo "<h1>" . $header . "</h1>";
}
echo "<table width=\"100%\">\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 "<tr>\n";
}
else {
echo "<tr align=\"center\">\n";
}
for ($j = 0; $j < $columns; $j++) {
if (($i*$columns + $j) < sizeof($menuitems)) {
echo "<td>\n";
echo "<div class=\"sub_menu_matrix\"";
if( $options['style'] ) echo " style=\"" . $options['style'] . "\"";
echo ">\n";
// Extra info?
if (is_array($options['extra_info'])) {
// Text?
if (strlen($options['extra_info'][$i*$columns + $j]['text'])) {
echo "<div";
echo " class=\"sub_menu_matrix_info\"";
if( $options['extra_info'][$i*$columns + $j]['tip'] ) {
echo " onmouseover=\"Tip('" . strclean_tooltip($options['extra_info'][$i*$columns + $j]['tip']) . "',BGCOLOR,'" . $_PAGE_INFO['ini']['tooltip']['background'] . "',BORDERCOLOR, '" . $_PAGE_INFO['ini']['tooltip']['border'] . "');\"";
echo " onmouseout=\"UnTip();\"";
}
echo ">";
echo "&#160;";
echo strip_tags($options['extra_info'][$i*$columns + $j]['text']);
echo "&#160;";
echo "</div>";
}
// Icon?
if (strlen($options['extra_info'][$i*$columns + $j]['icon'])) {
echo "<div class=\"sub_menu_matrix_icon\">";
echo "<!--[if lte IE 6]>";
echo "<span style=\"display:inline-block;filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" . IMAGE_DIR . $options['extra_info'][$i*$columns + $j]['icon'] . "');\">";
echo "<![endif]-->";
echo "<img id=\"menu_image\" src=\"" . IMAGE_DIR . $options['extra_info'][$i*$columns + $j]['icon'] . "\">\n";
echo "<!--[if lte IE 6]>";
echo "</span>";
echo "<![endif]-->";
echo "</div>";
}
}
// 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 "<div>";
$has_div = TRUE;
print_link_start($menulinks[$i*$columns + $j], $menuitem_options);
}
else if (strlen($menuitems[$i*$columns + $j])) {
echo "<div class=\"nolink\"";
foreach( $menuitem_options as $event => $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 "</div>\n"; // link
echo "</div>\n"; // button (sub_menu_matrix)
echo "</td>\n"; // table cell
}
}
echo "</tr>\n";
}
}
else {
// Single column
// Retrieve main items and check for the rights
for ($i = 0; $i < sizeof($menuitems); $i++) {
echo "<tr>\n";
if ($options['form']) {
echo "<td>\n";
}
else {
echo "<td align=\"center\">\n";
}
echo "<div class=\"sub_menu\"";
if( $options['style'] ) echo " style=\"" . $options['style'] . "\"";
echo ">\n";
// Extra info?
if (is_array($options['extra_info'])) {
if (strlen($options['extra_info'][$i]['text'])) {
echo "<div";
echo " class=\"sub_menu_matrix_info\"";
if( $options['extra_info'][$i]['tip'] ) {
echo " onmouseover=\"Tip('" . strclean_tooltip($options['extra_info'][$i]['tip']) . "',BGCOLOR,'" . $_PAGE_INFO['ini']['tooltip']['background'] . "',BORDERCOLOR, '" . $_PAGE_INFO['ini']['tooltip']['border'] . "');\"";
echo " onmouseout=\"UnTip();\"";
}
echo ">";
echo "&#160;";
echo strip_tags($options['extra_info'][$i]['text']);
echo "&#160;";
echo "</div>";
}
if (strlen($options['extra_info'][$i]['icon'])) {
echo "<div class=\"sub_menu_matrix_icon\">";
echo "<!--[if lte IE 6]>";
echo "<span style=\"display:inline-block;filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" . IMAGE_DIR . $options['extra_info'][$i]['icon'] . "');\">";
echo "<![endif]-->";
echo "<img id=\"menu_image\" src=\"" . IMAGE_DIR . $options['extra_info'][$i]['icon'] . "\">\n";
echo "<!--[if lte IE 6]>";
echo "</span>";
echo "<![endif]-->";
echo "</div>";
}
}
$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 "<div class=\"nolink\"";
foreach( $menuitem_options as $event => $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 "</div>\n"; // no link
echo "</div>\n"; // sub_menu
echo "</td>\n"; // table cell
echo "</tr>\n";
}
}
echo "</table>\n";
if( $form ) print_epilogue(TRUE);
else echo "</center>";
}
/**
* 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 "<tr>";
echo "<td id=\"col0\"></td>\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 "<td id=\"col1\"></td>\n";
$options['colspan'] = FALSE;
$options['style'] .= "text-align: left;";
}
echo "<td id=\"col2\"";
if( $options['colspan'] ) echo " colspan=\"" . ($options['colspan'] - 1) . "\"";
if( $options['css_class'] ) echo " class=\"" . $options['css_class'] . "\"";
if( $options['style'] ) echo " style=\"" . $options['style'] . "\"";
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 "<button";
echo " type=\"button\"";
// CSS class and style
if( $button['css_class'] ) echo " class=\"" . $button['css_class'] . "\"";
else echo " class=\"button\"";
if( $button['style'] ) echo " style=\"" . $button['style'] . "\"";
// disabled?
if( $button['ro'] && is_ro($button['ro']) ) echo " disabled";
// JavaScript evnets
foreach( $button as $event => $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 "<table><tr><td>";
echo "<img src=\"" . $button['icon'] . "\">";
echo "</td><td>";
}
// button text
echo nl2br(strip_tags($button['text']));
if( $button['icon'] ) {
// close table
echo "</td></tr></table>";
}
echo "</button>";
if( $button['href'] ) print_link_end();
echo "\n";
}
else {
echo "<button class=\"button\" type=\"button\"";
if( !is_numeric($action) ) echo " onclick=\"onSubmit('" . $action . "', '', 1);\"";
echo ">";
echo nl2br(strip_tags($button));
echo "</button>\n";
}
}
if( $options['form'] ) {
echo "</td>\n";
echo "</tr>\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 "<div class=\"" . ($options['class'] ? $options['class'] : "button_div") . "\"";
if( $options['id'] ) echo " id=\"" . $options['id'] . "\"";
if( $options['style'] ) echo " style=\"" . $options['style'] . "\"";
if( $options['action'] ) echo " onclick=\"" . $options['action'] . "\" style=\"cursor:pointer;\"";
echo ">";
}
if( $options['buttons'] ) {
echo "<table><tr><td class=\"text\">";
}
if ($options['center']) {
echo "<center>";
}
if( $options['href'] ) {
print_link_start($options['href'], $options['target']);
}
if( $options['anchor'] ) {
echo "<a id=\"" . $options['anchor'] . "\">";
}
if( $title ) {
echo "<h1";
if( shorten_text($title, 40) != $title ) {
echo " onmouseover=\"Tip('" . strclean_tooltip($title) . "',BGCOLOR,'" . $_PAGE_INFO['ini']['tooltip']['background'] . "',BORDERCOLOR, '" . $_PAGE_INFO['ini']['tooltip']['border'] . "');\"";
echo " onmouseout=\"UnTip();\"";
}
echo ">";
echo $title;
echo "</h1>";
}
if( $options['anchor'] ) echo "</a>";
if( $options['href'] ) print_link_end();
if( $options['center'] ) echo "</center>";
if( $options['buttons'] ) {
echo "</td>";
foreach( $options['buttons'] as $button ) print_inline_button($button, TRUE);
echo "</tr></table>";
}
if( $need_div ) echo "</div>";
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 "<tr>\n";
echo "<td id=\"col0\"></td>\n";
echo "<td id=\"col2\" colspan=\"2\">";
}
else $has_row = FALSE;
if( $need_div ) {
echo "<div class=\"" . ($options['class'] ? $options['class'] : "button_div") . "\"";
if( $options['id'] ) echo " id=\"" . $options['id'] . "\"";
if( $options['style'] ) echo " style=\"" . $options['style'] . "\"";
if( $options['action'] ) echo " onclick=\"" . $options['action'] . "\" style=\"cursor:pointer;\"";
echo ">";
}
if( $options['buttons'] ) {
echo "<table><tr><td class=\"text\">";
}
if ($options['center']) {
echo "<center>";
}
if( $options['href'] ) print_link_start($options['href'], $options['target']);
if( $options['anchor'] ) {
echo "<a id=\"" . $options['anchor'] . "\">";
}
if (strlen($subtitle)) {
echo "<h2>" . $subtitle . "</h2>";
}
if( $options['anchor'] ) echo "</a>";
if( $options['href'] ) print_link_end();
if ($options['center']) echo "</center>";
if( $options['buttons'] ) {
echo "</td>";
foreach( $options['buttons'] as $button ) print_inline_button($button, TRUE);
echo "</tr></table>";
}
if( $need_div ) echo "</div>";
// print_epilogue($options['form']);
if( $has_row ) echo "</td></tr>\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 "<tr>\n";
echo "<td id=\"col0\"></td>\n";
echo "<td id=\"col2\" colspan=\"2\">";
}
else $has_row = FALSE;
if( $need_div ) {
echo "<div class=\"" . ($options['class'] ? $options['class'] : "button_div") . "\"";
if( $options['id'] ) echo " id=\"" . $options['id'] . "\"";
if( $options['style'] ) echo " style=\"" . $options['style'] . "\"";
if( $options['action'] ) echo " onclick=\"" . $options['action'] . "\" style=\"cursor:pointer;\"";
echo ">";
}
if( $options['buttons'] ) {
echo "<table><tr><td class=\"text\">";
}
if ($options['center']) {
echo "<center>";
}
// anchor?
if( $options['href'] ) print_link_start($options['href'], $options['target']);
if( $options['anchor'] ) {
echo "<a id=\"" . $options['anchor'] . "\">";
}
if (strlen($subtitle)) {
echo "<h3>" . $subtitle . "</h3>";
}
if( $options['anchor'] ) echo "</a>";
if( $options['href'] ) print_link_end();
if( $options['center'] ) echo "</center>";
if( $options['buttons'] ) {
echo "</td>";
foreach( $options['buttons'] as $button ) print_inline_button($button, TRUE);
echo "</tr></table>";
}
if( $need_div ) echo "</div>";
// print_epilogue($options['form']);
if( $has_row ) echo "</td></tr>\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> 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 "<div class=\"" . ($options['css_class'] ? $options['css_class'] : "button_div") . "\"";
if( $options['id'] ) echo " id=\"" . $options['id'] . "\"";
if( $options['style'] ) echo " style=\"" . $options['style'] . "\"";
if( $options['action'] ) echo " onclick=\"" . $options['action'] . "\" style=\"cursor:pointer;\"";
echo ">";
}
if( $options['buttons'] ) {
echo "<table><tr>";
if( strlen($text) ) echo "<td class=\"text\">";
}
if( $options['p'] ) {
echo "<p";
if( $options['css_class'] ) echo " class=\"" . $options['css_class'] . "\"";
if( $style ) echo " style=\"" . implode(";", $style) . "\"";
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 "<a id=\"" . $options['anchor'] . "\">";
}
// print the text
if( strlen($text) ) echo $text;
// clean up
if( $options['anchor'] ) echo "</a>";
if( $options['href'] ) print_link_end();
if( $options['p'] ) echo "</p>";
if( $options['buttons'] ) {
if( strlen($text) ) echo "</td>";
foreach( $options['buttons'] as $button ) print_inline_button($button, TRUE);
echo "</tr></table>";
}
if( $need_div ) {
echo "</div>";
}
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 "<script type=\"text/javascript\">\n";
echo "var func_filter = function () {\n";
echo $onkeyup;
echo "}\n";
echo "</script>\n";
echo "<input type=\"text\" autofocus id=\"filter_element\" name=\"" . $name . "\" value=\"" . $value . "\" autocomplete=\"off\" onkeypress=\"return noenter(event,this)\" onkeyup=\"new_value('" . $name . "',func_filter);\" onfocus=\"current_value('" . $name . "');\">\n";
}
else {
echo "<input type=\"text\" autofocus name=\"" . $name . "\" value=\"" . $value . "\" autocomplete=\"off\" onkeypress=\"return noenter(event,this)\">\n";
echo "<input type=\"button\" id=\"searchbutton\" class=\"button\" value=\"" . _("Search") . "\" onClick=\"onSubmit('but_search', '', 1);\">\n";
}
echo "<input type=\"button\" id=\"resetbutton\" class=\"button\" value=\"" . _("Reset") . "\" onClick=\"onSubmit('but_reset', '', 1);\">\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 "<script type=\"text/javascript\">\n";
echo "var func_" . $name ." = function onkeyup () {\n";
echo $options['onkeyup'];
echo "}\n";
echo "</script>\n";
}
// Alignment
if( $options['center'] ) {
echo "<center>";
}
echo "<input";
echo " type=\"text\"";
echo " id=\"text_element\"";
if( is_ro($ro_actions) ) {
echo " disabled";
if( strlen($name) ) {
$array_pos = strpos($name, "[");
if( $array_pos ) {
$input_name = substr($name, 0, $array_pos) . "_display" . substr($name, $array_pos);
}
else $input_name = $name . "_display";
echo " name=\"" . $input_name . "\"";
}
// Add tooltip (only when read-only)
if( shorten_text($value, $options['text_length']) != $value ) {
$options['onmouseover'] .= "Tip('" . strclean_tooltip($value) . "',BGCOLOR,'" . $_PAGE_INFO['ini']['tooltip']['background'] . "',BORDERCOLOR, '" . $_PAGE_INFO['ini']['tooltip']['border'] . "');";
$options['onmouseout'] .= "UnTip();";
}
}
else if( strlen($name) ) {
echo " name=\"" . $name . "\"";
}
echo " value=\"" . strip_tags($value) . "\"";
foreach( $options as $event => $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 "</center>";
}
// 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 "<textarea rows=\"" . $height . "\"";
if( is_ro($ro_actions) ) {
echo " disabled";
}
else if( $name ) {
echo " name=\"" . $name . "\"";
}
foreach( $options as $event => $action )
if( strtolower(substr($event, 0, 2)) == "on" )
echo " " . $event . "=\"" . $action . "\"";
echo ">";
if( $options['html'] )
echo htmlspecialchars($value);
else
echo strip_tags($value);
echo "</textarea>\n";
// Display message?
if (strlen($info)) print_info($name, $info, $options['info_bold']);
// action?
if( $options['action'] ) {
echo "<div class=\"tiny_button\">";
echo "<button type=\"button\" class=\"tiny_button\" onclick=\"" . $options['action']['action'] . "\">";
echo $options['action']['button_text'];
echo "</button>\n";
echo "</div>";
}
// 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 "<div";
if( $options['id'] ) echo " id=\"" . $options['id'] . "\"";
echo " class=\"dropdown\"";
echo ">";
echo "<input type=\"text\"";
if( $options['type'] == "dropdownlist" ) {
echo " id=\"value_display\" readonly";
$display_value = $selections[$value];
if( is_array($display_value) ) $display_value = $display_value['text'];
echo " value=\"" . strip_tags($display_value) . "\"";
}
else {
$display_value = $value;
echo " id=\"value_edit\"";
echo " value=\"" . strip_tags($display_value) . "\"";
echo " onfocus=\"" . $name_js . ".HideDropDown();\"";
}
if( is_ro($ro_actions) ) {
echo " class=\"disabled\"";
if( $options['type'] != "dropdownlist" ) {
// otherwise already set
echo " readonly";
}
if( $options['width'] ) echo " style=\"width: " . ($options['width'] - 20) . "px;\"";
}
else {
echo " name=\"" . $name_input . "\"";
// handle clicks on an iPad via the touch events
if( $options['type'] == "dropdownlist" ) {
// expand the dropdown list when the editbox is clicked
echo " onclick=\"" . $name_js . ".OnClickEditBox();\"";
}
else {
// combobox: copy text to the hidden control
echo " onchange=\"" . $name_js . ".CopyValue();\"";
}
if( $options['width'] ) echo " style=\"width: ". ($options['width'] - 20) . "px\"";
}
// Add tooltip
if( shorten_text($display_value, $options['text_length']) != $display_value ) {
echo " onmouseover=\"Tip('" . strclean_tooltip($display_value) . "',BGCOLOR,'" . $_PAGE_INFO['ini']['tooltip']['background'] . "',BORDERCOLOR, '" . $_PAGE_INFO['ini']['tooltip']['border'] . "');\"";
echo " onmouseout=\"UnTip();\"";
}
echo ">";
if( !is_ro($ro_actions) ) {
echo "<img name=\"" . $name . ":button\" src=\"" . IMAGE_DIR . "foldbutton_blue_icon_collapsed.png\" ";
// toggle dropdown list on mouse click
echo " onclick=\"";
echo $name_js . ".OnClickDropDown();";
if( $options['type'] == "dropdown" ) {
// preselect list item when opening the list in a combobox
echo $name_js . ".SelectValue(getElement('" . $name_input . "').value);";
}
echo "\"";
echo ">\n";
}
else {
echo "<img name=\"" . $name . ":button\" class=\"disabled\" src=\"" . IMAGE_DIR . "foldbutton_gray_icon_collapsed.png\">\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 "<div";
echo " class=\"combobox_div\"";
echo " id=\"" . $name . ":dropdownlist\"";
if( $options['offset'] ) {
echo " style=\"margin-left: " . $options['offset'] . "px;\"";
}
else if( $options['width'] ) {
echo " style=\"width: " . $options['width'] . "px;\"";
}
echo ">";
}
echo "<div class=\"listbox_div\"";
echo " id=\"" . $name . ":ul-div\"";
echo ">";
echo "<ul";
echo " draggable=\"true\"";
if( is_ro($ro_actions) ) {
echo " class=\"disabled\"";
}
else {
// the select is the item of interest
echo " id=\"" . $name_select . "\"";
}
// translate options for the select element
if( $options['size'] ) {
$options['style'] .= "height: " . ($options['size'] * 2.5) . "ex";
}
// not supported: if( $options['multi'] ) echo " multiple";
// print the options
if( $options['css_class'] ) echo " class=\"" . $options['css_class'] . "\"";
if( $options['style'] ) echo " style=\"" . $options['style'] . "\"";
foreach( $options as $event => $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 "<li";
echo " id=\"" . $name . ":item:" . strip_tags($selection_value) . "\"";
echo " draggable=\"true\"";
$css_class = FALSE;
// select this item?
if(
(!is_ro($ro_actions) || $options['selection'] == "show") &&
!($options['selection'] == "hide") &&
(
($options['multi'] && is_array($value) && in_array($selection_value, $value)) ||
(!$options['multi'] && $selection_value == $value && strlen($value) == strlen($selection_value) /* blech */) ||
(is_array($selection) && $selection['selected'])
)
) {
$css_class = "selected";
}
// print the item
if( is_array($selection) ) {
$select_text = "";
// preprocess the options
foreach( $selection as $option => $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 "&nbsp;";
}
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 "&nbsp;";
}
echo "</li>";
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 "<li></li>\n";
echo "</ul>";
echo "</div>";
if( $use_div ) {
echo "</div>";
}
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 "<script type=\"text/javascript\">\n";
echo "var " . $name_js . " = new SelectionBox(";
echo "'" . $name . "',";
echo "'" . $options['type'] . "',";
echo "'" . IMAGE_DIR . "foldbutton_blue_icon_collapsed.png" . "',";
echo "'" . IMAGE_DIR . "foldbutton_blue_icon_expanded.png" . "'";
echo ");\n";
if( $options['multi'] ) echo $name_js . ".multiSelect=true;\n";
echo $name_js . ".Initialize();\n";
echo "</script>\n";
}
if( $has_editbox ) {
echo "</div>\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 "<script type=\"text/javascript\">\n";
echo "var _js_treeview_" . $name . " = new TreeView(";
echo "'" . $name . "',";
echo "'" . $options['icon']['closed'] . "',";
echo "'" . $options['icon']['open'] . "',";
echo "'" . $options['icon']['empty'] . "'";
echo ");\n";
echo "</script>\n";
print_prologue($title);
// print the top level, if set
if( is_array($items) ) {
echo "<ul";
if( $options['css_class'] ) echo " class=\"" . $options['css_class'] . "\"";
else echo " class=\"treeview\"";
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 "</ul>\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 "<li";
if( $options['tooltip'] || $item['tooltip'] ) {
if( $item['tooltip'] && is_bool($item['tooltip']) )
$tooltip = strip_tags($item['tooltip']);
else if( $options['tooltip'] && $item['tooltip'] !== FALSE )
$tooltip = strip_tags($item['value']);
$item['onmouseover'] = "Tip('" . strclean_tooltip($tooltip) . "',BGCOLOR,'" . $_PAGE_INFO['ini']['tooltip']['background'] . "',BORDERCOLOR, '" . $_PAGE_INFO['ini']['tooltip']['border'] . "');" . $item['onmouseover'];
$item['onmouseout'] = "UnTip();" . $item['onmouseout'] ;
}
if( $options['css_class'] ) echo " class=\"" . $options['css_class'] . "\"";
foreach( $item as $event => $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 "<img";
if( $item['items'] ) echo " class=\"button\"";
echo " src=\"" . $options['icon'][$icon] . "\"";
echo " id=\"" . $name . "[" . $list_tag . "][img]\"";
echo " onclick=\"_js_treeview_" . $name . ".OnClickExpand('" . $list_tag . "');\"";
echo ">";
// checkbox?
if( $item['checkbox'] ) {
echo "<input";
echo " type=\"checkbox\"";
echo " name=\"" . $item['checkbox']['name'] . "\"";
if( $item['checkbox']['checked'] ) echo " checked";
if( $item['checkbox']['readonly'] || is_ro($this_ro) ) echo " disabled";
foreach( $item['checkbox'] as $event => $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 "<span";
if( $item['href'] && $item['recall'] ) {
echo " class=\"link\"";
echo " onclick=\"var e = getElement('" . $item['recall'] . "'); if( e ) e.value = '" . $item['href'] . "'; onSubmit('" . $item['recall'] . "','',1);\"";
}
if( $str != $org_str ) {
// the text is shortened, so we need a "span" element to show the tool tip
echo " onmouseover=\"Tip('" . strclean_tooltip($org_str) . "',BGCOLOR,'" . $_PAGE_INFO['ini']['tooltip']['background'] . "',BORDERCOLOR, '" . $_PAGE_INFO['ini']['tooltip']['border'] . "');\"";
echo " onmouseout=\"UnTip();\" ";
}
echo ">";
echo $str;
echo "</span>";
}
// print the sub-items, when present
if( $item['items'] ) {
echo "<ul";
if( $expand_list ) echo " style=\"display: block\"";
else echo " style=\"display: none\"";
echo " id=\"" . $name . "[" . $list_tag . "][list]\"";
echo ">\n";
foreach( $item['items'] as $id => $item ) {
print_treeview_item($name, $list_tag . ":" . $id, $value, $item, $level + 1, $children_ro, $info, $options);
}
echo "</ul>\n";
}
echo "</li>\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<event> 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 "<button";
echo " type=\"" . ($options['submit'] ? "submit" : "button") . "\"";
echo " name=\"" . $name . "\"";
if( $options['tip'] ) {
$options['onmouseover'] .= "Tip('" . strclean_tooltip($options['tip']) . "',BGCOLOR,'" . $_PAGE_INFO['ini']['tooltip']['background'] . "',BORDERCOLOR, '" . $_PAGE_INFO['ini']['tooltip']['border'] . "');";
$options['onmouseout'] .= "UnTip();";
}
if( $options['css_class'] ) echo " class=\"" . $options['css_class'] . "\"";
if( $options['style'] ) echo " style=\"" . $options['style'] . "\"";
foreach( $options as $event => $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 "<img src=\"" . $options['icon'] . "\">";
echo nl2br(strip_tags($value));
echo "</button>";
// 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 <input type="file"> element, with input box for the file name and browse button
echo "<input type=\"file\" style=\"position:absolute; visibility:hidden;\" id=\"" . $name . "_file_element\" name=\"" . $name . $multiple_name . "\" " . $multiple_addon . " value=\"\" onChange=\"getElement('" . $name . "_filename').value=this.value; " . $onchange . "\" onsubmit='return false'>";
echo "<input type=\"text\" id=\"" . $name . "_filename\" name=\"" . $name . "_file_element_text_overrule\">";
echo "<input type=\"button\" id=\"filebutton\" name=\"" . $name . "_file_element_overrule\" value=\"" . $browse_caption . "\" class=\"button\" onClick=\"getElement('" . $name . "_file_element').click();\">";
if ($upload) {
echo "<input type=\"submit\" id=\"filebutton\" class=\"button\" value=\"" . $upload_caption . "\" onclick=\"" . $onuploadsumbit . "\">\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 "<input type=\"file\" style=\"position:absolute;visibility:hidden;height:0px;\" id=\"" . $name . "_file_element\" name=\"" . $name . $multiple_name . "\" " . $multiple_addon . " value=\"\" onchange=\"getElement('" . $name . "_filename').value=this.value; " . $onchange . "\" onsubmit='return false'>";
echo "<input type=\"text\" style=\"position:absolute;visibility:hidden;height:0px;\" id=\"" . $name . "_filename\" name=\"" . $name . "_file_element_text_overrule\">";
}
}
else {
// Old versions of IE; use the somewhat ugly <input type="file"> element
// IE won't change the text of the browse button...
if( $hidden_input ) echo $upload_caption;
else echo $browse_caption;
echo "<br>\n";
//
echo "<input type=\"file\" class=\"file_element" . ($upload ? " upload" : "") . "\" name=\"" . $name . $multiple_name . "\" " . $multiple_addon . "";
// NOT USED/IGNORED: echo " value=\"" . $upload_caption . "\"";
if (strlen($onchange)) {
echo " onchange=\"" . $onchange . "\"";
}
echo ">";
if ($upload) {
echo "<input type=\"submit\" class=\"file_element\" value=\"" . $upload_caption . "\" onclick=\"" . $onuploadsumbit . "\">\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 "<div class=\"";
if( $link ) echo "file_open_button";
else echo "inactive_button";
echo "\" id=\"" . $name . "\"";
if( $bold ) echo " style=\"font-weight:bold;\"";
echo ">";
echo "<table>";
echo "<tr>";
echo "<td class=\"button_text\">";
print_link_start($link, array_merge($options, array('id' => $name)));
echo "<div";
if( strlen($value) > 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 "</div>";
print_link_end();
echo "</td>";
if( is_array($options['buttons']) )
foreach( $options['buttons'] as $button )
print_inline_button($button, TRUE);
echo "</tr>";
echo "</table>";
echo "</div>";
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 "<div class=\"date\">";
echo "<input type=\"text\" id=\"date_element\" value=\"" . $value . "\" readonly onkeypress=\"return noenter(event,this)\"";
if (is_ro($ro_actions)) {
echo " disabled";
}
else {
echo " name=\"" . $name . "\"";
}
echo ">";
if (!is_ro($ro_actions)) {
echo "<img src=\"" . IMAGE_DIR . "calender.gif\" ";
echo "onclick=\"JACS.show(getElement('" . $name . "'),event, '" . $name . "_id');JACS.next('" . $name . "_id',onSubmit,'other', '', 1);\"";
echo ">\n";
}
// Display message?
if (strlen($info)) print_info($name, $info, $bold);
echo "</div>";
// 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 "<input type=\"text\" id=\"datetime_element\" value=\"" . $date_value . "\" readonly onkeypress=\"return noenter(event,this)\"";
if (is_ro($ro_actions)) {
echo " disabled>";
}
else {
echo " name=\"" . $date_name . "\">";
}
if (!is_ro($ro_actions)) {
echo "<img src=\"" . IMAGE_DIR . "calender.gif\"";
echo " onclick=\"JACS.show(getElement('" . $date_name . "'),event, '" . $date_name . "_id');JACS.next('" . $date_name . "_id',onSubmit,'other', '', 1);\"";
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 "<div class=\"time_interval\">";
//// 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 "</div>\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 "<center>";
}
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 "<input type=\"password\" id=\"password_element\" name=\"" . $name . "\" value=\"" . $value . "\"";
echo " autocomplete=\"off\"";
echo " onkeypress=\"return noenter(event,this)\"";
echo " onchange=\"document.form." . $name . "_changed.value = 1; return true;\"";
echo " onfocus=\"if( !document.form." . $name . "_changed.value && document.form." . $name . ".value=='" . addcslashes(PASSWD_DISPLAY_TEXT, "\"\'\n\r\f\t") . "' ) document.form." . $name . ".value = ''; return true;\"";
echo " onblur=\"if( !document.form." . $name . "_changed.value && document.form." . $name . ".value=='' ) document.form." . $name . ".value = '" . addcslashes(PASSWD_DISPLAY_TEXT, "\"\'\n\r\f\t") . "'; return true;\"";
echo ">";
echo "<input type=\"hidden\" name=\"" . $name . "_changed\" value=\"" . $_POST[$name . "_changed"] . "\">\n";
// Alignment
if (strlen($center)) {
echo "</center>";
}
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 "<div class=\"mouse_catcher\"";
echo " onmouseover=\"Tip('" . strclean_tooltip($options['tooltip']) . "',BGCOLOR,'" . $_PAGE_INFO['ini']['tooltip']['background'] . "',BORDERCOLOR, '" . $_PAGE_INFO['ini']['tooltip']['border'] . "');\"";
echo " onmouseout=\"UnTip();\"";
echo "></div>";
}
if( $options['href'] ) print_link_start($options['href']);
if( $need_div ) {
echo "<div class=\"" . ($options['class'] ? $options['class'] : "button_div") . "\"";
if( $options['id'] ) echo " id=\"" . $options['id'] . "\"";
if( $options['action'] ) echo " onclick=\"" . $options['action'] . "\" style=\"cursor:pointer;\"";
echo ">";
}
if( $options['center'] ) echo "<center>";
if( $options['buttons'] ) {
echo "<table ";
if( $options['table_style'] ) echo " style=\"" . $options['table_style'] . "\"";
echo "><tr><td class=\"text\">";
}
if( $options['label'] ) {
echo "<label";
if( $options['tooltip'] ) {
echo " onmouseover=\"Tip('" . strclean_tooltip($options['tooltip']) . "',BGCOLOR,'" . $_PAGE_INFO['ini']['tooltip']['background'] . "',BORDERCOLOR, '" . $_PAGE_INFO['ini']['tooltip']['border'] . "');\"";
echo " onmouseout=\"UnTip();\"";
}
echo ">";
}
echo "<input";
echo " type=\"checkbox\"";
if( $options['css_class'] ) echo " class=\"" . $options['css_class'] . "\"";
if( $options['id'] ) echo " id=\"" . $options['id'] . "\"";
echo " name=\"" . $name . "\"";
echo " value=\"" . $value_checked . "\"";
if (is_ro($ro_actions)) {
echo " disabled";
}
if( $options['tooltip'] ) {
$options['onmouseover'] .= "Tip('" . strclean_tooltip($options['tooltip']) . "',BGCOLOR,'" . $_PAGE_INFO['ini']['tooltip']['background'] . "',BORDERCOLOR, '" . $_PAGE_INFO['ini']['tooltip']['border'] . "');";
$options['onmouseout'] .= "UnTip();";
}
foreach( $options as $event => $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 "<span style=\"" . $options['style'] . "\">";
}
if( $options['label'] ) {
echo $options['label'];
}
else if( !$on_form ) {
echo $title;
}
if( $options['style'] ) {
echo "</span>";
}
if( $options['label'] ) {
echo "</label>\n";
}
if( $options['buttons'] ) {
echo "</td>";
foreach( $options['buttons'] as $button ) print_inline_button($button, TRUE);
echo "</tr></table>";
}
if( $options['info'] ) print_info($name, $options['info']);
if( $options['center'] ) echo "</center>";
if( $need_div ) {
echo "</div>";
}
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 "<div class=\"mouse_catcher\"";
echo " onmouseover=\"Tip('" . strclean_tooltip($options['tooltip']) . "',BGCOLOR,'" . $_PAGE_INFO['ini']['tooltip']['background'] . "',BORDERCOLOR, '" . $_PAGE_INFO['ini']['tooltip']['border'] . "');\"";
echo " onmouseout=\"UnTip();\"";
echo "></div>";
}
if( $options['center'] ) echo "<center>";
if( $options['label'] ) {
echo "<label";
if( $options['tooltip'] ) {
echo " onmouseover=\"Tip('" . strclean_tooltip($options['tooltip']) . "',BGCOLOR,'" . $_PAGE_INFO['ini']['tooltip']['background'] . "',BORDERCOLOR, '" . $_PAGE_INFO['ini']['tooltip']['border'] . "');\"";
echo " onmouseout=\"UnTip();\"";
}
echo ">";
}
echo "<input";
echo " type=\"radio\"";
if( $options['css_class'] ) echo " class=\"" . $options['css_class'] . "\"";
if( $options['id'] ) echo " id=\"" . $options['id'] . "\"";
echo " name=\"" . $name . "\"";
echo " value=\"" . $value_checked . "\"";
if (is_ro($ro_actions)) {
echo " disabled";
}
if( $options['tooltip'] ) {
$options['onmouseover'] .= "Tip('" . strclean_tooltip($options['tooltip']) . "',BGCOLOR,'" . $_PAGE_INFO['ini']['tooltip']['background'] . "',BORDERCOLOR, '" . $_PAGE_INFO['ini']['tooltip']['border'] . "');";
$options['onmouseout'] .= "Untip();";
}
foreach( $options as $event => $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 "<span style=\"" . $options['style'] . "\">";
}
if( $options['label'] ) {
echo $options['label'];
}
else if( !$on_form ) {
echo $title;
}
if( $options['style'] ) {
echo "</span>";
}
if( $options['label'] ) {
echo "</label>\n";
}
if( $options['info'] ) print_info($name, $options['info']);
if( $options['center'] ) echo "</center>";
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 "<div class=\"" . $options['css_class'] . "\"";
if( $options['id'] ) echo " id=\"" . $options['id'] . "\"";
if( $options['style'] || $options['align'] ) {
echo " style=\"";
if( $options['align'] ) echo "text-align:" . $options['align'] . ";";
if( $options['style'] ) echo $options['style'];
echo "\"";
}
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 "<a href=\"" . $button['href'] . "\"";
if( $button['target'] ) echo " target=\"" . $button['target'] . "\"";
echo ">";
}
echo "<button type=\"button\"";
if( $button['css_class'] ) echo " class=\"" . $button['css_class'] . "\"";
else echo " class=\"" . $options['css_class'] . "\"";
if( $button['id'] ) echo " id=\"" . $button['id'] . "\"";
if( $button['name'] ) echo " name=\"" . $button['name'] . "\"";
if( $button['style'] ) echo " style=\"" . $button['style'] . "\"";
foreach( $button as $event => $action )
if( strtolower(substr($event, 0, 2)) == "on" )
echo " " . $event . "=\"" . $action . "\"";
if( isset($button['ro']) ) $ro = $button['ro'];
else $ro = $ro_actions;
if( is_ro($ro) ) echo " disabled";
echo ">";
if( $button['icon'] ) echo "<img src=\"" . $button['icon'] . "\">";
echo $button['button_text'];
echo "</button>\n";
}
else while( $name ) {
$button = array(
'button_text' => array_shift($name),
'action' => array_shift($action)
);
echo "<button type=\"button\"";
if( $button['css_class'] ) echo " class=\"" . $button['css_class'] . "\"";
else echo " class=\"" . $options['css_class'] . "\"";
if( $button['id'] ) echo " id=\"" . $button['id'] . "\"";
if( $button['name'] ) echo " name=\"" . $button['name'] . "\"";
if( $button['style'] ) echo " style=\"" . $button['style'] . "\"";
if( $button['button_action'] ) echo " onclick=\"" . $button['button_action'] . "\"";
if( is_ro($ro_actions) ) echo " disabled";
echo ">";
echo $button['button_text'];
echo "</button>\n";
}
}
else {
// simple. single button
echo "<button type=\"button\"";
echo " class=\"" . $options['css_class'] . "\"";
if( $options['id'] ) echo " id=\"" . $options['id'] . "\"";
if( $options['name'] ) echo " name=\"" . $options['name'] . "\"";
if( $options['style'] ) echo " style=\"" . $button['style'] . "\"";
if( $action ) echo " onclick=\"" . $action . "\"";
if( is_ro($ro_actions) ) echo " disabled";
echo ">";
echo $name;
echo "</button>\n";
}
if( $options['container'] ) echo "</div>\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 "<input type=\"hidden\" name=\"" . $name . "\" value=\"" . strip_tags($value) . "\">";
}
/**
* 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 "<table class=\"checkbox_table\" width=\"100%\">\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 "<tr><td colspan=\"3\">";
echo "<h2";
if ($menu_item == "root") {
echo " style=\"color:#002F4C\"";
}
echo ">";
echo _("right:" . $menu_item);
echo "</h2>";
//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 "</tr>\n";
echo "<tr>";
}
echo "<td>";
// 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 "<input id=\"" . $name . ":" . $j . "\" type=\"checkbox\" name=\"" . $name ."[]\"";
// Disable items or root right for this menu?
if (is_array($rights_enabled)) {
if(
!in_array($right, $rights_enabled) ||
(in_array($menu_item . ":" . "root", $rights_checked) && db_ver_right_cust($_SESSION[$_PAGE_INFO['id']]['search']['customer']['id'], $menu_item . ":" . "root", $skip_rights_current)) ||
($include_rights[$right] && in_array($include_rights[$right], $rights_checked))
) {
echo " disabled";
}
}
// Checked items?
echo " value=\"" . $right . "\"";
if (is_array($rights_checked)) {
if(
in_array($right, $rights_checked) ||
(in_array($menu_item . ":" . "root", $rights_checked) && db_ver_right_cust($_SESSION[$_PAGE_INFO['id']]['search']['customer']['id'], $menu_item . ":" . "root", $skip_rights_current)) ||
($include_rights[$right] && in_array($include_rights[$right], $rights_checked))
) {
echo " checked";
}
}
// Onchange event (only for the admin)
echo " onClick=\"onSubmit('" . $right . "', '', 1);\"";
echo " onkeypress=\"return noenter(event,this)\"";
echo ">";
echo "<label for=\"" . $name . ":" . $j . "\"";
echo " style=\"";
if ($menu_item == "root") {
echo "color:#002F4C;";
}
// Line through when up the pyramid the rights are no longer there (exceptions are only user rights)
if ((is_valid_action("cust_info")) || ((is_valid_action("cust_change")) && ($_SESSION[$_PAGE_INFO['id']]['MTinfo_menu'] == "menu:klanten:wijzigen"))) {
if (is_array($rights_checked)) {
// Skip own right check?
$skip_rights_current = (is_valid_action("cust_change")) ? 1 : 0;
if ((in_array($right_menu, $rights_checked)) && (!db_ver_right_cust($_SESSION[$_PAGE_INFO['id']]['search']['customer']['id'], $right_menu, $skip_rights_current))) {
echo "text-decoration:line-through;";
}
}
}
else if (is_valid_action("user_info","user_change","cust_change")) {
// user rights? => Skip
if (is_array($rights_checked)) {
// Skip own right check?
$skip_rights_current = is_valid_action("user_change","cust_change");
if ((in_array($right, $rights_checked)) && (!db_ver_right_user($_SESSION[$_PAGE_INFO['id']]['search']['user']['id'], $right, 1, $skip_rights_current))) {
echo "text-decoration:line-through;";
}
}
}
echo "\"";
echo ">";
if( $sright == "toegang" ) {
echo _("right:" . $sright);
}
else {
echo _("right:" . $right);
}
echo "</label>\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 "</td>\n";
// Number 3 => end of row
if (($i % 3) == 2) {
echo "</tr>\n";
}
$i++;
$j++;
}
}
}
}
}
// JW20141003: needed for IE11 to print top and right borders
while( ($i++ % 3) ) echo "<td></td>";
echo "</tr>\n";
// End of row when less then 3 items
if (($i % 3) != 0) {
echo "</tr>\n";
}
}
}
}
echo "</table>\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 "<table width=\"100%\" class=\"user_control\" align=\"left\">\n";
echo "<tr>\n";
// Left lisbox
echo "<td>";
if( $labels ) echo "<label for=\"" . $name . "_left\" style=\"text-align:left\">" . $labels[0] . "<br>" . "</label>";
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 "</td>";
// Table for buttons
echo "<td>\n";
echo "<table class=\"leftright_button\">\n";
// filler
echo "<tr style=\"height:" . (($options['size']-1) * 5) . "px\">";
echo "</tr>";
echo "<tr>";
echo "<td>";
$icon = ($all) ? "<<" : "<";
echo "<input";
echo " type=\"button\"";
echo " name=\"" . $name .":rtl\"";
echo " value=\"" . $icon . "\"";
echo " onclick=\"_js_leftright_" . $name . ".OnClickRtl();\"";
echo ">";
echo "</td>";
echo "</tr>";
echo "<tr>";
echo "<td>";
$icon = ($all) ? ">>" : ">";
echo "<input";
echo " type=\"button\"";
echo " name=\"" . $name .":ltr\"";
echo " value=\"" . $icon . "\"";
echo " onclick=\"_js_leftright_" . $name . ".OnClickLtr();\"";
echo ">";
echo "</td>";
echo "</tr>";
echo "</table>\n";
echo "</td>\n";
// right listbox
echo "<td>";
echo "<div id=\"" . $name . "_right_list\" style=\"display: block;\">";
if( $labels ) echo "<label for=\"" . $name . "_right\" style=\"text-align:left\">" . $labels[1] . "<br>" . "</label>";
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 "<label for=\"" . $name . ":filter\" style=\"text-align:left\">" . _("Filter") . ":<br>" . "</label>";
// filter entry box
echo "<input";
echo " id=\"filter_input\"";
echo " type=\"text\"";
echo " name=\"" . $name . ":filter\"";
echo " value=\"" . $filter_value . "\"";
echo " autocomplete=\"off\"";
echo " onkeypress=\"return noenter(event,this)\"";
echo " onkeyup=\"if( typeof filter_timer != 'undefined' ) { clearInterval(filter_timer); }; filter_timer = setTimeout(function(){ _js_leftright_" . $name . ".UpdateFilter(); }, 300);\"";
echo ">";
// reset filter button
echo "<input";
echo " id=\"resetbutton\"";
echo " type=\"button\"";
echo " name=\"" . $name . ":filter:reset\"";
echo " class=\"button\"";
echo " value=\"" . _("Reset") . "\"";
echo " onclick=\"getElement('" . $name . ":filter').value='';_js_leftright_" . $name . ".UpdateFilter();\"";
echo ">\n";
}
echo "</div>";
echo "</td>\n";
echo "</tr>\n";
echo "</table>\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 "<script type=\"text/javascript\">\n";
echo "var _js_leftright_" . $name . " = new LeftRightBox(";
echo "'" . $name . "',";
echo "'" . ($all ? "all" : "") . "',";
echo "_js_select_" . $name . "_left,";
echo "_js_select_" . $name . "_right";
echo ");\n";
foreach( $options as $event => $action )
if( strtolower(substr($event, 0, 2)) == "on" )
echo "_js_leftright_" . $name . "." . $event . " = '" . addslashes($action) . "';\n";
echo "</script>\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 "<div class=\"scrollable_div\"";
$style = array();
if( $options['style'] ) $style[] = $options['style'];
if( $options['max-height'] ) {
$max_height = "max-height:";
$max_height .= $options['max-height'];
if( is_numeric($options['max-height']) ) $max_height .= "px";
$style[] = $max_height;
}
if( !empty($style) ) {
echo " style=\"";
echo implode(";", $style);
echo "\"";
}
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 "<table>";
if( isset($_PAGE_INFO['form']) ) $_PAGE_INFO['form']['scrollable_div'] = TRUE;
}
function print_scrollarea_end($options = FALSE /* not used */)
{
global $_PAGE_INFO;
echo "</div>";
echo "</table>";
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 "<tr>\n";
echo "<td id=\"col0\"></td>";
echo "<td colspan=\"3\"";
if( $options['id'] ) echo " id=\"" . $options['id'] . "\"";
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 "<div";
if( $options['div']['css_class'] ) echo " class=\"" . $options['div']['css_class'] . "\"";
else echo " class=\"" . $options['css_class'] . "\"";
if( $options['div']['style'] ) $div_style[] = $options['div']['style'];
if( $options['div']['width'] ) $div_style[] = "width:" . $options['div']['width'] . (is_numeric($options['div']['width']) ? "px" : "");
if( $options['div']['height'] ) $div_style[] = "max-height:" . $options['div']['height'] . (is_numeric($options['div']['height']) ? "px" : "");
if( $div_style ) echo " style=\"" . implode(";", $div_style) . ";\"";
echo ">";
$_PAGE_INFO['embedded_table']['div'] = TRUE;
}
// start the embedded table
echo "<table";
$style = array();
if( $options['css_class'] ) echo " class=\"" . $options['css_class'] . "\"";
if( $options['style'] ) $style[] = $options['style'];
if( $options['width'] ) $style[] = "width:" . $options['width'] . (is_numeric($options['width']) ? "px" : "");
if( $options['height'] ) $style[] = "height:" . $options['height'] . (is_numeric($options['height']) ? "px" : "");
if( $style ) echo " style=\"" . implode(";", $style) . ";\"";
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 "<tr";
if( $options['header_height'] ) echo " style=\"height:" . $options['header_height'] . (is_numeric($options['header_height']) ? "px;" : ";") . "\"";
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 "<th";
if( $header['css_class'] ) echo " class=\"" . $header['css_class'] . "\"";
if( $style ) echo " style=\"" . implode(";", $style) . "\"";
if( ($tip = $header['tip']) || ($tip = $header['tooltip']) ) {
echo " onmouseover=\"Tip('" . strclean_tooltip($tip) . "',BGCOLOR,'" . $_PAGE_INFO['ini']['tooltip']['background'] . "',BORDERCOLOR, '" . $_PAGE_INFO['ini']['tooltip']['border'] . "');\"";
echo " onmouseout=\"UnTip();\"";
}
if( $header['colspan'] ) echo " colspan=\"" . $header['colspan'] . "\"";
echo ">";
if( $header['div'] ) {
$div_style = array();
echo "<div";
if( $header['div']['css_class'] ) echo " class=\"" . $header['div']['css_class'] . "\"";
if( $header['div']['style'] ) $div_style[] = $header['div']['style'];
if( $header['div']['width'] ) $div_style[] = "width:" . $header['div']['width'] . (is_numeric($header['div']['width']) ? "px" : "");
if( $header['div']['height'] ) $div_style[] = "height:" . $header['div']['height'] . (is_numeric($header['div']['height']) ? "px" : "");
if( $div_style ) echo " style=\"" . implode(";", $div_style) . ";\"";
echo ">";
}
if( $header['icon'] ) {
echo "<img src=\"" . $header['icon'] . "\"> ";
}
if( $header['html'] )
echo $header_title;
else
echo nl2br(strip_tags($header_title));
if( $header['div'] ) {
echo "</div>";
}
echo "</th>\n";
}
echo "</tr>\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 "</div>";
if( $_PAGE_INFO['embedded_table']['col'] ) echo "</td>";
if( $_PAGE_INFO['embedded_table']['row'] ) echo "</tr>";
unset($_PAGE_INFO['embedded_table']);
// close the table
echo "</table>\n";
// close the enclosing DIV, when used
if( $_PAGE_INFO['embedded_table']['div'] ) echo "</div>";
if( $full_width ) {
echo "</td>\n";
echo "</tr>\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 "</div>";
if( $_PAGE_INFO['embedded_table']['col'] ) echo "</td>";
if( $_PAGE_INFO['embedded_table']['row'] ) echo "</tr>";
echo "<tr id=\"row" . ($row & 1) . "\"";
$style = array();
if( $options['css_class'] ) echo " class=\"" . $options['css_class'] . "\"";
if( $options['style'] ) $style[] = $options['style'];
if( $options['width'] ) $style[] = "width:" . $options['width'] . (is_numeric($options['width']) ? "px" : "");
if( $options['height'] ) $style[] = "height:" . $options['height'] . (is_numeric($options['height']) ? "px" : "");
if( $style ) echo " style=\"" . implode(";", $style) . ";\"";
foreach( $options as $event => $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 "</div>";
if( $_PAGE_INFO['embedded_table']['col'] ) echo "</td>";
echo "</tr>\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 "</div>";
if( $_PAGE_INFO['embedded_table']['col'] ) echo "</td>";
echo "<td";
if( $options['color'] ) $options['style'] .= "; color: " . $options['color'] . ";";
if( $options['rowspan'] ) echo " rowspan=\"" . $options['rowspan'] . "\"";
if( $options['colspan'] ) echo " colspan=\"" . $options['colspan'] . "\"";
if( $options['css_class'] ) echo " class=\"" . $options['css_class'] . "\"";
if( $options['style'] ) echo " style=\"" . $options['style'] . "\"";
if( $options['width'] ) echo " width=\"" . $options['width'] . "\"";
if( $options['height'] ) echo " height=\"" . $options['height'] . "\"";
foreach( $options as $event => $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 "<div";
if( $options['div']['css_class'] ) echo " class=\"" . $options['div']['css_class'] . "\"";
if( $options['div']['style'] ) $div_style[] = $options['div']['style'];
if( $options['div']['width'] ) $div_style[] = "width:" . $options['div']['width'] . (is_numeric($options['div']['width']) ? "px" : "");
if( $options['div']['height'] ) $div_style[] = "height:" . $options['div']['height'] . (is_numeric($options['div']['height']) ? "px" : "");
if( $div_style ) echo " style=\"" . implode(";", $div_style) . ";\"";
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 "</div>";
echo "</td>";
$_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 "<div";
if( $id ) echo " id=\"" . $id . "\"";
if( $options['css_class'] ) echo " class=\"" . $options['css_class'] . "\"";
if( $options['style'] ) echo " style=\"" . $options['style'] . "\"";
echo ">";
$_PAGE_INFO['div']['active'] = $id;
}
function print_div_end()
{
global $_PAGE_INFO;
unset($_PAGE_INFO['div']);
echo "</div>";
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 "<p";
if( $options['css_class'] ) echo " class=\"" . $options['css_class'] . "\"";
if( $options['style'] ) echo " style=\"" . $options['style'] . "\"";
echo ">";
$_PAGE_INFO['p']['line'] = 0;
}
function print_paragraph_end($options = NULL)
{
global $_PAGE_INFO;
unset($_PAGE_INFO['p']);
echo "</p>\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 "<img";
echo " src=\"" . $src . "\"";
if( $options['id'] ) echo " id=\"" . $options['id'] . "\"";
if( $options['css_class'] ) echo " class=\"" . $options['css_class'] . "\"";
if( $options['style'] ) echo " style=\"" . $options['style'] . "\"";
if( $options['tip'] ) {
echo " onmouseover=\"Tip('" . strclean_tooltip($options['tip']) . "',BGCOLOR,'" . $_PAGE_INFO['ini']['tooltip']['background'] . "',BORDERCOLOR, '" . $_PAGE_INFO['ini']['tooltip']['border'] . "');\"";
echo " onmouseout=\"UnTip();\"";
}
foreach( $options as $event => $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 <sizeof($data); $i++) {
if ($i) {
$result .= "//";
}
$result .= $data[$i]['id'];
}
}
else {
$result = "//No Result//";
}
// Hidden control
echo "<input type=\"hidden\" name=\"result\" value=\"" . $result . "\">";
return $result;
}
/**
* Recall stored result from session info
*
* Inputs:
* - session_key Place where data was stored
*/
function result_recall($session_key)
{
$result = "";
if ($session_key != "//No Result//") {
$result = split("//", $session_key);
}
return $result;
}
/**
* Function to insert some empty space
*/
function print_empty_space($height = 10)
{
echo "<tr height=\"" . $height . "px\">\n";
echo "</tr>\n";
}
/**
* Function to insert button padding
*/
function print_button_padding()
{
echo "<td id=\"col2\" style=\"padding-left:0px\">\n";
}
?>