".htmlentities(print_r($array, true)).""; } //htmlentities escape array static public function htmlentities_array($array) { if (!is_array($array)) { throw new Exception("\"{$array}\" is not an array"); } $arraynew = array(); foreach ($array as $name => $value) { if (is_array($value)) { $arraynew[$name] = self::htmlentities_array($value); } else { $arraynew[$name] = htmlentities($value); } } return $arraynew; } //Prepare empty formdata static public function prepare_formdata($fields) { $formdata = array(); foreach ($fields as $field) { $formdata[$field] = ''; } return $formdata; } //Create dropdown box options html static public function create_options($options, $selected=null, $extraoptions='') { $optionvalues = self::bitwiseopt_toarray($extraoptions); $selected_list = array(); if ($selected !== null) { if (is_array($selected)) { $selected_list = $selected; } else { $selected_list[] = $selected; } } if (in_array(self::CREATEOPT_PLEASESELECT, $optionvalues)) { $optionsnew = array('' => '-- Please Select --'); foreach ($options as $name => $value) { $optionsnew[$name] = $value; } $options = $optionsnew; } $options_html = ''; foreach ($options as $name => $value) { $name_h = htmlentities($name); $value_h = htmlentities($value); $selected_html = ''; foreach ($selected_list as $selecteditem) { if ( ($selecteditem !== null) && (strlen($selecteditem) == strlen($name)) && ($selecteditem == $name) ) { $selected_html = ' selected="selected"'; break; } } $options_html .= <<{$value_h}\n EOHTML; } return $options_html; } //Create radio buttons html static public function create_radio($grpname, $options, $checked=null, $disabled=null, $class='', $addinhtml='', $extraoptions='') { $optionvalues = self::bitwiseopt_toarray($extraoptions); $disabled_list = array(); if ($disabled !== null) { if (is_array($disabled)) { $disabled_list = $disabled; } else { $disabled_list[] = $disabled; } } $grpname_h = htmlentities($grpname); $radiooptions_html = ''; foreach ($options as $name => $value) { $name_h = htmlentities($name); $value_h = htmlentities($value); if ( ($checked !== null) && ($checked == $name) && (strlen($checked) == strlen($name)) ) { $checked_html = ' checked="checked"'; } else{ $checked_html = ''; } $disabled_html = ''; foreach ($disabled_list as $disableditem) { if ( ($disableditem !== null) && (strlen($disableditem) == strlen($name)) ) { $disabled_html = ' disabled="disabled"'; break; } } if (in_array(self::CREATERADIO_NEWLINE, $optionvalues)) { $spacer = '
'; } else { $spacer = '     '; } if ($class) { $class_html = " class=\"{$class}\""; } else { $class_html = ''; } $radiooptions_html .= <<  {$spacer}\n EOHTML; } return $radiooptions_html; } //Create random string static public function randstring($length, $options) { $optionvalues = self::bitwiseopt_toarray($options); $length = intval($length); $charsetoptions = array( self::RANDSTRING_AZ_LC => array('frm' => 97, 'to' => 122), self::RANDSTRING_AZ_UC => array('frm' => 65, 'to' => 90), self::RANDSTRING_09 => array('frm' => 48, 'to' => 57), ); //Check at least one charset is specified if (count($optionvalues) < 1) { throw new Exception('At least one charset must be specified'); } //Check string length is specified if ($length < 1) { throw new Exception('Length must be greater than zero'); } //Go through charsets specified $charset_picklist = array(); foreach ($optionvalues as $charset) { //Check specified charset is valid if (!isset($charsetoptions[$charset])) { throw new Exception("Specified charset \"{$charset}\" invalid"); } //Go though characters in the charset and add them on for ($i=$charsetoptions[$charset]['frm']; $i <= $charsetoptions[$charset]['to']; $i++) { $charset_picklist[] = chr($i); } } $charset_picklist_total = count($charset_picklist); $randstring = ''; for ($i=0; $i<$length; $i++) { $randchrindex = mt_rand(0, $charset_picklist_total-1); $randstring .= $charset_picklist[$randchrindex]; } return $randstring; } //Convert php array to hidden form fields static public function array_formfield($formfield, $prefix='') { $formfield_html = ''; foreach ($formfield as $name => $value) { if ($prefix) { $namewprefix = $prefix . '[' . $name . ']'; } else { $namewprefix = $name; } if (is_array($value)) { $formfield_html .= self::array_formfield($value, $namewprefix); } else { $value_h = htmlentities($value); if ($prefix) { $namewprefix_h = htmlentities($namewprefix); } else { $namewprefix_h = htmlentities($name); } $formfield_html .= <<\n EOHTML; } } return $formfield_html; } //Convert php array to js array static public function array_jsarray($grpname, $array, $level=0) { if ($level > 10) { throw new Exception('Too much recursion'); } $array_js = ''; foreach ($array as $name => $value) { $name_s = addslashes($name); if (is_array($value)) { $array_js_recur = self::array_jsarray('', $value, $level+1); $tabs = str_repeat("\t", $level+1); $array_js .= <<