Warning: chmod(): Operation not permitted in /var/www/hopeinstoughton_www/wp-content/plugins/simple-universal-google-analytics/main.php on line 8 [0] in function chmod in /var/www/hopeinstoughton_www/wp-content/plugins/simple-universal-google-analytics/main.php on line 8 [1] in function include_once in /var/www/hopeinstoughton_www/wp-settings.php on line 560 [2] in function require_once in /var/www/hopeinstoughton_www/wp-config.php on line 85 [3] in function require_once in /var/www/hopeinstoughton_www/wp-load.php on line 50 [4] in function require_once in /var/www/hopeinstoughton_www/wp-blog-header.php on line 13 [5] in function require in /var/www/hopeinstoughton_www/index.php on line 17
| Server IP : 94.177.8.99 / Your IP : 216.73.217.165 Web Server : Apache/2.4.58 (Ubuntu) System : Linux aries 6.8.0-134-generic #134-Ubuntu SMP PREEMPT_DYNAMIC Fri Jun 26 18:43:11 UTC 2026 x86_64 User : www-data ( 33) PHP Version : 8.1.34 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : OFF Directory : /var/www/hopeinstoughton_books/core/plugins/ |
Upload File : |
<?php
// Display and manage a html form
global $VARIABLE, $WEBFORMS;
if (!isset($VARIABLE['javascript'])) {
$VARIABLE['javascript'] = ''; // load at start
$VARIABLE['javascript_onload'] = ''; // execute when page has loaded
$VARIABLE['javascript_include'] = ''; // addditional <script></script>
}
$WEBFORMS = array();
$WEBFORMS_INIT = array(); // list of all components that have been initialized
if (!defined('PASSWORD_PRESENT')) {
define('PASSWORD_PRESENT', '********'); // the placeholder that is displayed instead of current password
}
define('TEXTTYPE_NORMAL', 0);
define('TEXTTYPE_ALLCAPS', 1); // not implemented
define('TEXTTYPE_PASSWORD', 2);
define('TEXTTYPE_NUMERIC', 3);
define('TEXTTYPE_CURRENCY', 4);
define('TEXTTYPE_PERCENT', 5);
//----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- -----
//----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- -----
class webform_field {
var $parent;
var $multiselect;
var $width;
var $height;
var $onDisplay; // not used - use OnLoad property instead
var $OnChange; // javascript function to be executed on field change
var $onSave;
var $onPost;
var $onSubmit; // javascript function to be executed on form submission
var $fieldtype;
var $groupnum;
var $flag_savefield;
function __construct($parent, $fieldtype, $fieldname, $fieldlabel, $required) {
$this->parent = $parent;
$this->multiselect = $this->displayonly = 0;
$this->width = 200;
$this->height = 1;
$this->fieldtype = $fieldtype;
$this->databasefield = $fieldtype;
$this->fieldname = $fieldname;
$this->fieldlabel = $fieldlabel;
$this->required = $required;
$this->extra = $this->hint = '';
$this->enabled = 1;
$this->callback = NULL;
$this->allowsgml = 0;
$this->flag_savefield = 1;
$this->ISPOST = $GLOBALS['config']->isPost();
}
public function SetHint($hint) {
$this->hint = $hint;
}
public function SetHeight($lines) { // set the height of the control, normally in "lines"
$this->height = $lines;
}
public function SetWidth($value) {
$this->width = $value;
}
public function SetEnabled($value) {
$this->enabled = $value;
}
public function SetExtLabel($text) { // text to appear on the right of the field, such as '%', or Min/Max values,
$this->extra = $text;
}
public function SetDatabaseField($databasefieldname) { // this field should be attached to a database field
$this->databasefield = $databasefieldname;
}
public function SetSaveField($value = 0) { // if 0 the data for field is not saved to the databse
$this->flag_savefield = $value;
}
function _addHint(&$html) {
if (!empty($this->hint)) {
$dhint = htmlspecialchars($this->hint);
$html = "<span title=\"$dhint\">$html</span>";
}
}
// used for displayonly fields - If true, will allow html in the data, otherwise '<' is replaced by <, etc
public function SetSGML($value = 1) {
$this->allowsgml = $value;
}
// called only once , use to load in any html needed to support this type of field.
public function Initialize_html() {
// nothing extra required for a generic field
}
public function Initialize_form() {
// nothing extra required for a generic field
}
// format the value suitable for a Display-only field
function _displayonly($value) {
if ($this->allowsgml) {
$input = $value;
} else {
$input = '<strong>' . htmlspecialchars($value) . '</strong>';
}
return $input;
}
public function asHTML() { // create the html for entire field, based on the field template defined in the parent
global $VARIABLE;
$label = $this-> _LabelAsHTML();
$fieldname = $this->fieldname;
$value = isset($VARIABLE[$fieldname]) ? $VARIABLE[$fieldname] : '';
$displayonly = empty($this->displayonly) ? 0 : $this->displayonly;
if ($this->callback !== NULL) { // this is a custom field
$temp = $this->callback;
if (is_array($temp)) {
$input = $temp[0]->$temp[1]($this, $value, $displayonly);
} else {
$input = $temp($this, $value, $displayonly);
}
} elseif ($this->fieldtype == 'comment') {
$input = '';
$label = $this->_LabelAsHTML(1);
} elseif (method_exists($this, '_ashtml') && !$displayonly) {
$input = $this->_ashtml();
} elseif ($this->fieldtype == 'textarea') {
$input = $this->_ashtml(); // <textarea> has it's own displayonly property - use it
} elseif ($this->fieldtype == 'hidden') {
$value = htmlspecialchars($value);
return '<input type="hidden" id="' . $fieldname . '" name="' . $fieldname . '" value="' . $value. '">';
} elseif ($this->fieldtype == 'display' || $displayonly) {
$input = $this->_displayonly($value);
} else {
$input = "[unknown: {$this->fieldtype}]";
}
self::_addhint($input);
$macros = array(
'LABEL' => $label,
'FIELD' => $input,
'EXTRA' => $this->extra);
return _cwfp_ReplaceMacro($this->parent->template_field, $macros);
}
// retrieve the value from posted data
public function ValueFromPost($default = '') {
$fieldname = $this->fieldname;
if ($this->onPost !== NULL) {
$temp = $this->onPost;
if (is_array($temp)) {
return $temp[0]->$temp[1]($this);
} else {
return $temp($this);
}
} elseif ($this->ISPOST) {
$current = isset($_POST[$fieldname]) ? $_POST[$fieldname] : '';
return trim($current);
} else {
$current = isset($_GET[$fieldname]) ? $_GET[$fieldname] : $default;
return trim($current);
}
}
// add the item to the data record
function SaveItem($current) {
$fieldname = $this->fieldname;
$this->parent->DATA[$fieldname] = $current;
}
function _LabelAsHTML($displayonly = 0) {
global $VARIABLE;
$fieldlabel = $this->fieldlabel;
$accesskey = quote_getAccessKey($fieldlabel);
$class = ($this->required) ? 'prompt1' : 'prompt0';
if (!($this->displayonly || $displayonly) && $fieldlabel != '') $fieldlabel .= ':';
if (isset($VARIABLE["{$this->fieldname}.ERR"])) {
$fieldlabel = "<font color=\"#cc0000\">$fieldlabel</font>";
}
return "<label id=\"l_{$this->fieldname}\" for=\"{$this->fieldname}\"$accesskey><span class=\"$class\">{$fieldlabel}</span></label>";
}
}
//----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- <INPUT TEXT/PASSWORD>
class webform_field_text extends webform_field {
// Options for Text field
function __construct($parent, $fieldtype, $fieldname, $fieldlabel, $required) {
$this->maxchars = $this->texttype = $this->confirm = 0;
$this->autocomplete = '';
parent::__construct($parent, $fieldtype, $fieldname, $fieldlabel, $required);
}
public function SetType($value) {
$this->texttype = $value;
}
public function SetConfirm($value = 1) { // is this a password Confirmation field,. Entered value must be the same as the other password field
if ($value) $this->texttype = TEXTTYPE_PASSWORD; // "passwords match" is displayed
$this->confirm = $value;
}
public function SetMaxCharacters($value = 11) {
$this->maxchars = $value;
}
public function SetAutoComplete($link = '') { // $link points to a script that will create suggestions based on what is already typed
$this->autocomplete = $link;
}
function _ashtml() { // just the <input> field as html
global $VARIABLE;
$param = '';
if (!empty($this->width)) $param .= " style=\"width:{$this->width}px\"";
if (!empty($this->maxchars)) $param .= " size=\"{$this->maxchars}\"";
if (!empty($this->OnChange)) $param .= " onchange=\"{$this->OnChange}\"";
if (!empty($this->OnBlur)) $param .= " onblur=\"{$this->OnBlur}\"";
if (!$this->enabled) $param .= ' disabled="disabled"';
$cssclass = empty($this->parent->cssclass) ? '' : ' ' . $this->parent->cssclass;
$fieldname = $this->fieldname;
$value = isset($VARIABLE[$fieldname]) ? $VARIABLE[$fieldname] : '';
$dvalue = htmlspecialchars($value);
if ($this->texttype == TEXTTYPE_PASSWORD) {
$type = 'password';
if (preg_match('~[0-9a-fA-F]{32}~', $value)) $dvalue = PASSWORD_PRESENT; // don't reveal any passwords
} else {
$type = 'text';
}
return "<input type=\"$type\" class=\"text$cssclass\" name=\"$fieldname\" id=\"$fieldname\" value=\"$dvalue\"$param>";
}
public function ValueFromPost($default = '') {
global $VARIABLE;
$current = parent::ValueFromPost($default);
if ($this->maxchars > 0) $current = substr($current, 0, $this->maxchars); // some data fields have a max length
if ($this->confirm) { // locate the other password field, and make sure the value is the same.
$fields = $this->parent->GetFieldsbyType('text');
foreach($fields as $item) {
if ($item->texttype == TEXTTYPE_PASSWORD && !$item->confirm) { // is this the matching password field?
$original = $item->ValueFromPost($default);
if ($current != $original) {
$fieldname = $this->fieldname;
$VARIABLE["$fieldname.ERR"] = 'The passwords do not match';
}
break;
}
}
}
return $current;
}
function SaveItem($current) {
$fieldname = $this->fieldname;
if ($this->texttype == TEXTTYPE_PASSWORD) {
if ($current == PASSWORD_PRESENT) $current = $this->parent->DATA[$fieldname]; // password is unchanged
} elseif ($this->texttype == TEXTTYPE_NUMERIC) {
$current = intval($current);
} elseif ($this->texttype == TEXTTYPE_CURRENCY) {
$current = intval(floatval($current) * 100 + 0.5) / 100;
} elseif ($this->texttype == TEXTTYPE_PERCENT) {
$current = intval(floatval($current) * 1000 + 0.5) / 1000;
}
$this->parent->DATA[$fieldname] = $current;
}
// Do we need to include the autoinclude script?
public function Initialize_html() {
global $VARIABLE;
$fields = $this->parent->GetFieldsbyType('text');
$hasHTML = array();
$autocomplete_fields = array();
foreach($fields as $item) {
$fieldname = $item->fieldname;
if ($item->autocomplete != '') {
$autocomplete_fields[$fieldname] = $item->autocomplete;
}
}
if (count($autocomplete_fields)) {
if (strpos($VARIABLE['javascript_include'], 'jquery-ui.js') === FALSE) {
$VARIABLE['javascript_include'] .= <<<BLOCK
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.18/jquery-ui.js" type="text/javascript"></script>
<link rel="stylesheet" href="/global/jq_calendar/datepicker.css" type="text/css" />
BLOCK;
}
$VARIABLE['javascript_include'] .= <<<BLOCK
<style type="text/css">
.ui-autocomplete {
font-size: medium !important;
}
</style>
BLOCK;
/* $VARIABLE['javascript_include'] .= <<<BLOCK
<script type="text/javascript" src="/global/inc/jquery.autocomplete.js"></script>
<link href="/global/inc/autocomplete/jquery.autocomplete.css" rel="stylesheet" type="text/css" />
BLOCK;
$VARIABLE['javascript_onload'] .= "\t\$('#$field').autocomplete({url:'$callback', maxItemsToShow: 30});\n";
*/
foreach($autocomplete_fields as $field => $callback) {
$VARIABLE['javascript_onload'] .= <<<BLOCK
$("#$field").autocomplete({
source: function(req, add){
$.getJSON("$callback?callback=?", req, function(data) {
var suggestions = [];
$.each(data, function(i, val) {
suggestions.push(unescape(val.name));
});
add(suggestions);
});
} } );
BLOCK;
}
}
}
}
//----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- <TEXTAREA / HTML>
class webform_field_textarea extends webform_field {
// Options for TextArea field
function __construct($parent, $fieldtype, $fieldname, $fieldlabel, $required) {
$this->formathtml = 0;
$this->wrap = '';
parent::__construct($parent, $fieldtype, $fieldname, $fieldlabel, $required);
$this->width = 400; // default textarea sizes
$this->height = 200;
}
public function SetIsHTML($value = 1) {
$this->formathtml = $value;
}
public function SetWrap($value = '') {
$this->wrap = $value;
}
function _ashtml() { // just the <textarea> field as html; all in html management, if needed
global $VARIABLE;
$fieldname = $this->fieldname;
$value = isset($VARIABLE[$fieldname]) ? $VARIABLE[$fieldname] : '';
$value = htmlspecialchars($value);
if ($this->formathtml) {
return <<<BLOCK
<tr><td><textarea name="$fieldname" id="$fieldname" rows="15" style="width:99%;">$value</textarea>
BLOCK;
}
$wd = $this->width;
$ht = $this->height;
$param = '';
if ($this->wrap != '') $param .= " wrap=\"{$this->wrap}\"";
if ($this->displayonly) $param .= ' readonly';
$cssclass = empty($this->parent->cssclass) ? '' : ' class="' . $this->parent->cssclass . '"';
return "<textarea name=\"$fieldname\" id=\"$fieldname\"$cssclass style=\"width:{$wd}px;height:{$ht}px;\"$param>$value</textarea>";
}
public function Initialize_html() {
global $VARIABLE;
// do we have any html text boxes?
$fields = $this->parent->GetFieldsbyType('textarea');
$hasHTML = array();
foreach($fields as $item) {
if ($item->formathtml) {
$hasHTML[] = $item->fieldname;
}
}
$first = '';
if (count($hasHTML)) { // Time to load in Xinha to handle the html editor
$list = '';
foreach($hasHTML as $item) {
if ($list != '') $list .= ',';
if ($first == '') $first = $item;
$list .= "'$item'";
}
$VARIABLE['javascript'] .= <<<BLOCK
var xinha_plugins = ['CharacterMap', 'ContextMenu', 'FullScreen', 'ListType', 'SpellChecker', 'Stylist', 'SuperClean', 'TableOperations'];
var xinha_editors = [{$list}];
function xinha_init() {
if(!HTMLArea.loadPlugins(xinha_plugins, xinha_init)) return;
var xinha_config = new HTMLArea.Config();
xinha_config.toolbar = [
["popupeditor","htmlmode"],
["separator","formatblock","fontname","fontsize","bold","italic","underline"],
["separator","forecolor","hilitecolor","textindicator"],
["separator","subscript","superscript"],
["linebreak","separator","justifyleft","justifycenter","justifyright","justifyfull"],
["separator","insertorderedlist","insertunorderedlist","outdent","indent"],
["separator","inserthorizontalrule","createlink","insertimage","inserttable"],
["linebreak","separator","undo","redo","print"], (HTMLArea.is_gecko ? [] : ["cut","copy","paste"]),
["separator","killword","clearfonts","toggleborders","splitblock","showhelp"],
];
xinha_editors = HTMLArea.makeEditors(xinha_editors, xinha_config, xinha_plugins);
xinha_editors.{$first}.config.height = '480px';
HTMLArea.startEditors(xinha_editors);
}
function _SaveAndExit(n) {
var editor = xinha_editors.{$first};
editor._textArea.value = editor.outwardHtml(editor.getHTML());
document.mainform.test.value=n;
document.mainform.submit();
return false;
}
BLOCK;
$VARIABLE['javascript_onload'] .= "\txinha_init();\n";
$VARIABLE['javascript_include'] .= <<<BLOCK
<link type="text/css" rel="stylesheet" title="xp-green" href="/xinha/skins/xp-green/skin.css">
<script type="text/javascript">
var _editor_url = '/xinha/';
var _editor_lang = "en";
</script>
<script type="text/javascript" src="/xinha/htmlarea.js"></script>
BLOCK;
}
}
}
//----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- CHECKBOX
class webform_field_checkbox extends webform_field {
public function asHTML() { // create the html for entire field, based on the field template defined in the parent
global $VARIABLE;
$label = $this-> _LabelAsHTML(1);
$fieldname = $this->fieldname;
$value = isset($VARIABLE[$fieldname]) ? $VARIABLE[$fieldname] : '';
$sel = (intval($value)) ? ' checked' : '';
$input = <<<BLOCK
<input type="checkbox" id="$fieldname" name="$fieldname" value="1"$sel>
BLOCK;
parent::_addhint($label);
parent::_addhint($input);
$macros = array(
'LABEL' => $label,
'FIELD' => $input,
'EXTRA' => $this->extra);
return _cwfp_ReplaceMacro($this->parent->template_checkbox, $macros);
}
public function ValueFromPost($default = '') { // checkbox is normally a 0 or a 1
$current = parent::ValueFromPost($default);
return intval($current);
}
}
//----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- FILE
class webform_field_file extends webform_field {
function __construct($parent, $fieldtype, $fieldname, $fieldlabel, $required) {
$this->original_filename = '';
parent::__construct($parent, $fieldtype, $fieldname, $fieldlabel, $required);
}
public function _asHTML() { // css styles do not work ; but older "size=' '" does work
$fieldname = $this->fieldname;
$param = '';
if (!empty($this->width)) {
$wd = intval($this->width / 6.25);
$param .= " size=\"{$wd}\"";
}
$maxsize = ini_get('upload_max_filesize');
return "<input type=\"file\" name=\"$fieldname\" id=\"$fieldname\"$param> (max: $maxsize)\n";
}
// Get the name of the file... raise an error if it is missing
// earlier version returned the contents of the file. This version returns the filename
public function ValueFromPost($default = '') {
global $VARIABLE;
$fieldname = $this->fieldname;
$filenames = _cwfp_GetFilename($fieldname);
if ($filenames == NULL && $this->ISPOST) {
if ($this->required) $VARIABLE["$fieldname.ERR"] = 'A local file from your computer is required for <b>' . _cwfp_WithoutAccess($this->fieldlabel) . '</b>';
$current = '';
} else {
list($current, $this->original_filename) = $filenames;
}
return $current;
}
}
//----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- <SELECT>
class webform_field_list extends webform_field {
// Options for Dropdown <selects>
function __construct($parent, $fieldtype, $fieldname, $fieldlabel, $required) {
$this->ismultiple = $this->usebitmask = 0;
$this->list = array();
parent::__construct($parent, $fieldtype, $fieldname, $fieldlabel, $required);
$this->width = 0;
$this->height = 0;
}
public function SetList($list) {
$this->list = $list;
}
// allow more than one item to be selected from the list
public function SetMultiSelect($multi = 1) {
$this->ismultiple = $multi;
}
// the final value for this field will be a bitmapped value - each bit represents a different item in the list
public function SetUseBitmask($value = 1) {
$this->usebitmask = $value;
}
function _ashtml() { // just the <select> field as html
global $VARIABLE;
$fieldname = $this->fieldname;
$value = isset($VARIABLE[$fieldname]) ? $VARIABLE[$fieldname] : '';
$wd = $this->width;
$ht = $this->height;
$opt = '';
$list = $this->list;
if ($this->ismultiple) $valuelist = explode("\t", $value);
$gray = isset($this->x_gray) ? $this->x_gray : 0;
foreach($list as $key => $desc) {
if (is_array($desc)) {
$visible = $desc[1];
$desc = $desc[0];
} else {
$visible = 1;
}
$desc = htmlspecialchars($desc);
if ($this->usebitmask) {
$sel = $key & $value ? ' selected' : '';
} elseif ($this->ismultiple) {
if (is_numeric($key)) {
$sel = in_array($key, $valuelist) ? ' selected' : '';
} else {
$sel = in_array($key, $valuelist, TRUE) ? ' selected' : '';
}
} elseif (is_numeric($value)) {
$sel = $key == $value ? ' selected' : '';
} else {
$sel = $key === $value ? ' selected' : '';
}
if (substr($desc, 0, 2) == '--') {
$opt .= "\n<option disabled=\"disabled\">$desc</option>";
} else {
$sel .= ($gray && !$visible) ? ' style="color:#aaa"' : '';
$opt .= "\n<option value=\"$key\"$sel>$desc</option>";
}
}
$param = '';
if (!empty($this->OnChange)) $param .= ' onchange="' . $this->OnChange . '"';
if (!empty($this->OnBlur)) $param .= ' onblur="' . $this->OnBlur . '"';
$fieldname2 = $fieldname;
if ($this->ismultiple) {
$param .= ' multiple';
$fieldname2 .= '[]';
}
if ($ht > 0) $param .= " size=\"$ht\"";
if ($wd) {
$wd .= 'px';
$param .= " style=\"width: $wd;\"";
}
// $cssclass = empty($this->parent->cssclass) ? '' : ' class="' . $this->parent->cssclass . '"';
return "<select name=\"$fieldname2\" class=\"customselectbox\" id=\"$fieldname\"$param>$opt</select>";
}
public function ValueFromPost($default = '') { // tab separated list of values
if (!$this->ismultiple) {
return parent::ValueFromPost($default);
}
$fieldname = $this->fieldname;
if ($this->usebitmask) {
$current = 0;
foreach($_POST[$fieldname] as $value) {
$current |= intval($value);
}
return $current;
}
$current = '';
if (isset($_POST[$fieldname]) && is_array($_POST[$fieldname])) {
foreach($_POST[$fieldname] as $value) {
if ($current != '') $current .= "\t";
$current .= $value;
}
return $current;
}
return $default;
}
// Do we need to include css styling?
public function Initialize_html() {
global $VARIABLE;
$class = $this->parent->cssclass;
if ($class == '') return; // no custom styles for fields - don't include our special magic
/*the list boxes can cause problems - Bill has received a few complaints
$fields = $this->parent->GetFieldsbyType('list');
if (count($fields)) {
$VARIABLE['javascript_include'] .= <<<BLOCK
<script type="text/javascript" src="/global/inc/jquery.customselect.js"></script>
BLOCK;
$VARIABLE['javascript_onload'] .= "\t\$('.customselectbox').customSelect('$class');\n";
}
*/
}
}
//----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- <SUBMIT>
class webform_field_submit extends webform_field {
public function asHTML() { // only the button, without any label
$param = '';
if (!$this->enabled) $param .= ' disabled="disabled"';
$input = "<input type=\"submit\" name=\"{$this->fieldname}\" id=\"s\" value=\" {$this->fieldlabel} \"$param/>";
self::_addhint($input);
$macros = array(
'BUTTON' => $input,
'EXTRA' => $this->extra);
return _cwfp_ReplaceMacro($this->parent->template_submit, $macros);
}
}
//----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- --- DATE
class webform_field_date extends webform_field {
function __construct($parent, $fieldtype, $fieldname, $fieldlabel, $required) {
$this->isexpiry = 0;
$this->includetime = 0;
parent::__construct($parent, $fieldtype, $fieldname, $fieldlabel, $required);
}
public function SetIsExpiry($value = 1) { // month and year, for example, a credit card expiry
$this->isexpiry = $value;
}
public function SetIncludeTime($value = 1) { // include time component of a date?
$this->includetime = $value;
}
function _ashtml() { // just the <input> field as html
global $VARIABLE, $DISPLAY_DATE_FORMAT, $SETTINGS;
$fieldname = $this->fieldname;
$value = isset($VARIABLE[$fieldname]) ? $VARIABLE[$fieldname] : '';
if ($this->isexpiry) {
$date = explode(',', $value);
if (count($date) == 2) {
list($month, $year) = $date;
} else {
$month = $year = NULL;
}
$CCMONTHS = array_combine(range(1,12), range(1,12)); // generate array of 1 through 12
$CCYEARS = array_combine(range(date('Y'), date('Y')+20), range(date('Y'), date('Y')+20)); // array of current-year through current-year + 20
$opt_m = $opt_y = '';
foreach($CCMONTHS as $key => $desc) {
$desc = htmlspecialchars($desc);
$sel = $key == $month ? ' selected' : '';
$opt_m .= "\n<option value=\"$key\"$sel>$desc</option>";
}
foreach($CCYEARS as $key => $desc) {
$desc = htmlspecialchars($desc);
$sel = $key == $year ? ' selected' : '';
$opt_y .= "\n<option value=\"$key\"$sel>$desc</option>";
}
return <<<BLOCK
Month: <select name="{$fieldname}" id="{$fieldname}">$opt_m</select>
Year: <select name="{$fieldname}_year" id="{$fieldname}_year">$opt_y</select>
BLOCK;
} else { // date must be in the form yyyy-mm-dd [hh:ii:ss]
$param = '';
if (!$this->enabled) $param .= ' disabled="disabled"';
$hint = str_replace('yy', 'yyyy', $DISPLAY_DATE_FORMAT);
$param .= " title=\"Date format: $hint. Enter '.' for today\"";
if (!empty($this->OnChange)) $param .= ' onchange="' . $this->OnChange . '"';
if (substr($value, 0, 10) == '0000-00-00' || $value == '' || substr($value, 0, 10) == '1969-12-31') {
$value = '';
} else {
$temp = trim(preg_replace('/\s{2,}/', ' ', $value));
list($item_date, $item_time) = explode(' ', $temp . ' ');
$USER_NUM = isset($_SESSION['sess_login']) ? $_SESSION['sess_login'] : 0;
list($yy, $mm, $dd) = explode('-', $item_date);
$fmt = isset($SETTINGS['datefmt']) ? $SETTINGS['datefmt'] : 'm/d/Y';
switch($fmt) {
case 'Y-m-d':
break;
case 'm/d/Y':
case 'M d, Y':
$value = "$mm/$dd/$yy";
break;
case 'd-m-Y':
$value = "$dd-$mm-$yy";
break;
}
if ($this->includetime && $item_time != '') {
$value .= ' ' . $item_time;
}
}
$cssclass = empty($this->parent->cssclass) ? '' : ' ' . $this->parent->cssclass;
return <<<BLOCK
<input type="text" name="{$fieldname}" id="{$fieldname}" class="date_toggled$cssclass" style="width: 90px;" value="$value"$param />
<input type="hidden" name="_x_{$fieldname}" id="_x_{$fieldname}" value="">
BLOCK;
}
}
function _displayonly($value) {
global $browserinfo;
// is our date library included? If so, use it
if (!class_exists('browserinfo')) return parent::_displayonly($value);
$year = intval(substr($value, 0, 4), 10);
if ($year < 2000) return '<strong>-</strong>';
$date = strtotime($value . 'Z');
return '<strong>' . cbi_insertdate($date) . '</strong>';
}
public function ValueFromPost($default = '') { // post is in format yyyymmdd -> but we use yyyy-mm-dd
$fieldname = $this->fieldname;
if ($this->ISPOST) {
$current = isset($_POST['_x_' . $fieldname]) ? $_POST['_x_' . $fieldname] : '';
} else {
$current = isset($_GET['_x_' . $fieldname]) ? $_GET['_x_' . $fieldname] : $default;
}
if ($current == '') $current = parent::ValueFromPost($default);
/*
$USER_NUM = isset($_SESSION['sess_login']) ? $_SESSION['sess_login'] : 0;
if ($USER_NUM == 1467388885) {
var_dump($current);
}
*/
if ($this->isexpiry) {
$fieldname = $this->fieldname;
$current .= ',' . $_POST[$fieldname . '_year'];
} elseif ($current != '') {
if ($current == '.' || $current == '-' || $current == '/') {
$current = date('Y-m-d'); // $dateformat
} else {
$c = substr_count($current, '-'); // already in YYY-mm-dd format
if ($c == 2) return $current;
$yy = substr($current, 0, 4); //
$mm = substr($current, 4, 2);
$dd = substr($current, 6, 2);
$current = "$yy-$mm-$dd";
}
}
return $current;
}
public function Initialize_html() {
global $VARIABLE, $DISPLAY_DATE_FORMAT;
if (strpos($VARIABLE['javascript_include'], 'jquery-ui.js') === FALSE) {
$VARIABLE['javascript_include'] .= <<<BLOCK
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.18/jquery-ui.js" type="text/javascript"></script>
<link rel="stylesheet" href="/global/jq_calendar/datepicker.css" type="text/css" />
BLOCK;
}
$fields = $this->parent->GetFieldsbyType('date');
$output = <<<BLOCK
$.datepicker.setDefaults( {
dateFormat: '$DISPLAY_DATE_FORMAT',
showOn: 'button',
buttonImage: '/global/jq_calendar/images/calendar.gif',
buttonImageOnly: true,
numberOfMonths: 2,
showButtonPanel: true,
changeYear: true
});
BLOCK;
foreach($fields as $item) {
$id = $item->fieldname;
$output .= "\t$('#$id').datepicker();\n";
}
$VARIABLE['javascript_onload'] .= $output;
}
public function Initialize_form() {
global $VARIABLE;
$formname = $this->parent->formname;
// on form submit, convert dates from the user's preferences, to our standard format: yyyymmdd
// In Locate Client, this is executed first
$VARIABLE['javascript_onload'] .= <<<BLOCK
$('form[name=$formname]').submit(function() {
$(this).find('input.hasDatepicker').each( function() {
var dp = $(this);
var id = dp.attr('id');
std = $('#_x_' + id);
std.val( $.datepicker.formatDate( 'yymmdd', dp.datepicker('getDate')) );
});
return true;
});
BLOCK;
}
// is this correct?
function SaveItem($current) { // Date should be in format "yyyy-mm-dd"
$fieldname = $this->fieldname;
if ($current != '') {
if (! preg_match('~(\d+)-(\d+)-(\d+)~', $current)) {
$current = _convertToStandard($current);
}
}
$this->parent->DATA[$fieldname] = $current;
}
}
//----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- -----
//----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- -----
class webform {
var $fielddefs;
var $identifier; // each form should have a different number - so that column settings can be saved
var $template_form;
var $template_field;
var $template_submit;
var $onSubmit;
var $formname; // the javascript name of the form
var $focus; // default to this field. Leave blank for no focus (unless error)
var $DB;
var $alternates;
var $groups;
var $active_group = -1;
var $DATA;
var $cssclass; // class to be added to all <input> and <submit> fields. Not suitable for FILE or CHECKBOX fields
function __construct($identifier, $formname = 'mainform') {
global $DATABASE, $WEBFORMS;
$this->fielddefs = array();
$this->DB = &$DATABASE;
$this->identifier = $identifier;
$this->formname = $formname;
$this->focus = '*'; // default to the first field
$this->alternates = array();
$this->groups = array();
$this->tabs = array();
$this->active_group = -1;
$this->active_tab = -1;
$this->tabheaderdisplayed = 0;
$WEBFORMS[$identifier] = $this;
$this->DATA = array(); // current record from the database
$this->cssclass = '';
$this->template_field = <<<BLOCK
<tr><td>%%LABEL</td></tr>
<tr><td>%%FIELD %%EXTRA</td></tr>
BLOCK;
$this->template_checkbox = '<tr><td>%%FIELD %%LABEL%%EXTRA</td></tr>';
$this->template_submit = '<tr><td align="right">%%EXTRA%%BUTTON</td></tr>';
$this->template_error = '<tr><td><p><font color="#cc0000">Please correct the following error(s):</font><ul>%%ERROR</ul></p></td></tr>';
$this->template_form = '%%FIELDS%%ERRORS%%SUBMIT'; // needs additions <table>....</table>
$this->ISPOST = $GLOBALS['config']->isPost();
}
function __destruct() {
global $WEBFORMS;
unset($WEBFORMS[$this->identifier]);
}
public function SetTitle($title) {
global $VARIABLE;
}
public function addsubmit($fieldname, $fieldlabel) {
$item = new webform_field_submit($this, 'submit', $fieldname, $fieldlabel, 0);
$item->SetDatabaseField(''); // not for database consumption
$item->groupnum = -1;
$this->fielddefs[] = &$item;
return $item;
}
// tabname => displayed on the tab
// icon => displayed to the left of the text on the tab,
// fieldlayout -> html defining positioning of fields within the tab %%fieldname is replaced by the field label and html input tag
public function addTab($tabname, $icon = '', $fieldlayout = '') {
$this->active_tab = count($this->tabs);
$this->tabs[] = array('n' => $tabname, 'i' => $icon, 'f' => $fieldlayout, 'h' => 0);
}
public function HighlightTab($tabname, $hilite = 1) { // highlight the current tab by marking it
foreach($this->tabs as $index => &$tab) {
if ($tab['n'] == $tabname) {
$tab['h'] = $hilite;
return 1;
}
}
return 0;
}
public function addComment($comment) {
$item = new webform_field_text($this, 'comment', '', $comment, 0);
$item->groupnum = $this->active_group;
$item->tabnum = $this->active_tab;
$this->displayonly = 1;
$this->fielddefs[] = &$item;
return $item;
}
public function addfield_text($fieldname, $fieldlabel, $required = 0) {
$item = new webform_field_text($this, 'text', $fieldname, $fieldlabel, $required);
$item->groupnum = $this->active_group;
$item->tabnum = $this->active_tab;
$this->fielddefs[] = &$item;
return $item;
}
public function addfield_textarea($fieldname, $fieldlabel, $required = 0) { // html or plain text
$item = new webform_field_textarea($this, 'textarea', $fieldname, $fieldlabel, $required);
$item->groupnum = $this->active_group;
$item->tabnum = $this->active_tab;
$this->fielddefs[] = &$item;
return $item;
}
public function addfield_checkbox($fieldname, $fieldlabel) {
$item = new webform_field_checkbox($this, 'checkbox', $fieldname, $fieldlabel, 0);
$item->groupnum = $this->active_group;
$item->tabnum = $this->active_tab;
$this->fielddefs[] = &$item;
return $item;
}
public function addfield_date($fieldname, $fieldlabel, $required = 0) {
$item = new webform_field_date($this, 'date', $fieldname, $fieldlabel, $required);
$item->groupnum = $this->active_group;
$item->tabnum = $this->active_tab;
$this->fielddefs[] = &$item;
return $item;
}
public function addfield_list($fieldname, $fieldlabel, $required = 0) {
$item = new webform_field_list($this, 'list', $fieldname, $fieldlabel, $required);
$item->groupnum = $this->active_group;
$item->tabnum = $this->active_tab;
$this->fielddefs[] = &$item;
return $item;
}
public function addfield_radio($fieldname, $fieldlabel, $required = 0) { // list of radio buttons
$item = new webform_field($this, 'radio', $fieldname, $fieldlabel, $required);
$item->groupnum = $this->active_group;
$item->tabnum = $this->active_tab;
$this->fielddefs[] = &$item;
return $item;
}
public function addfield_custom($fieldname, $fieldlabel, $callback, $required = 0) { // list of radio buttons
$item = new webform_field($this, 'custom', $fieldname, $fieldlabel, $required);
$item->callback = $callback; // name of the php function to generate the html code
$item->groupnum = $this->active_group;
$item->tabnum = $this->active_tab;
$this->fielddefs[] = &$item;
return $item;
}
public function addfield_file($fieldname, $fieldlabel, $required = 0) {
$item = new webform_field_file($this, 'file', $fieldname, $fieldlabel, $required);
$item->groupnum = $this->active_group;
$item->tabnum = $this->active_tab;
$this->fielddefs[] = &$item;
return $item;
}
public function addfield_hidden($fieldname) {
$item = new webform_field($this, 'hidden', $fieldname, '', 0);
$item->enabled = 0; // hidden fields are not enabled, and cannot be focused
$item->groupnum = -1;
$item->tabnum = -1;
$this->fielddefs[] = &$item;
return $item;
}
public function addfield_displayonly($fieldname, $fieldlabel) {
$item = new webform_field($this, 'display', $fieldname, $fieldlabel, 0);
$item->displayonly = 1;
$item->flag_savefield = 0; // display fields are not saved
$item->SetDatabaseField(''); // it won't change - so no need to save
$item->groupnum = $this->active_group;
$item->tabnum = $this->active_tab;
$this->fielddefs[] = &$item;
return $item;
}
public function setTemplate_form($templatetext) {
}
public function setTemplate_field($templatetext) {
}
public function GetFieldByFieldName($fieldname) {
foreach($this->fielddefs as $field) {
if ($field->fieldname == $fieldname) return $field;
}
return NULL;
}
// Return all the fields of the given type
public function GetFieldsbyType($type) {
$result = array();
foreach($this->fielddefs as $field) {
if ($field->fieldtype == $type) {
$result[] = $field;
}
}
return $result;
}
public function GetErrorCount() {
$count = 0;
foreach($this->fielddefs as $field) // don't include hidden or submit items
if (!empty($VARIABLE[$field->fieldname . '.ERR'])) $count++;
return $count;
}
// Generate the html required for this form
public function asHTML($autofocus = 1, $tablestart = '', $tableend = '') { // was ifp_GeneratePage
global $VARIABLE;
$this->initialize_html();
// fields & error messages
$firstfield = '';
$error = $submits = $errorfield = '';
$fields = self::TabHeader();
if ($this->tabheaderdisplayed) {
foreach($this->tabs as $tabindex => $tabdata) {
// generate tab html
$html = '';
if (!empty($tabdata['f'])) {
$html = self::_generatecustomLayout($tabdata['f']);
} elseif (count($this->groups) > 0) {
$html .= $this->_asHTML_fieldgroup($tabindex, -1);
foreach($this->groups as $idx => $caption) {
$group = $this->_asHTML_fieldgroup($tabindex, $idx);
$fields .= $this->formatFieldgroup($group, $caption);
}
$html .= $this->_asHTML_fieldgroup($tabindex, -2);
} else {
$html .= $this->_asHTML_fieldgroup($tabindex, -999);
}
$fields .= self::_asTab($tabindex, $html, $tablestart, $tableend);
}
$fields = '<div>' . $fields . '</div>';
$tablestart = $tableend = '';
} else {
if (count($this->groups) > 0) {
$fields .= $this->_asHTML_fieldgroup(-1, -1);
foreach($this->groups as $idx => $caption) {
$group = $this->_asHTML_fieldgroup(-1, $idx);
$fields .= $this->formatFieldgroup($group, $caption);
}
$fields .= $this->_asHTML_fieldgroup(-1, -2);
} else {
$fields .= $this->_asHTML_fieldgroup(-1, -999);
}
}
foreach($this->fielddefs as $field) { // don't include hidden or submit items
if ($field->fieldtype == 'submit' || $field->fieldtype == 'hidden') {
if ($submits != '') $submits .= ' ';
$submits .= $field->AsHTML();
}
if (!empty($VARIABLE[$field->fieldname . '.ERR'])) {
$data = $VARIABLE[$field->fieldname . '.ERR'];
if ($errorfield == '') $errorfield = $field->fieldname;
$error .= "\n<li>$data</li>";
}
// determine the name of the first field that is enabled, and not display-only
if ($firstfield == '') {
$displayonly = isset($field->displayonly) ? $field->displayonly : 0;
if ($field->enabled && !$displayonly) {
$firstfield = $field->fieldname;
}
}
}
if ($errorfield == '') {
$errorfield = $this->focus == '*' ? $firstfield : $this->focus;
}
if ($error != '') {
$macros = array('ERROR' => $error);
$error = _cwfp_ReplaceMacro($this->template_error, $macros);
}
if ($errorfield != '' && $autofocus) {
$VARIABLE['javascript_onload'] .= "\tdocument.{$this->formname}.$errorfield.focus();\n";
}
$macros = array('FIELDS' => $fields,
'ERRORS' => $error,
'SUBMIT' => $submits);
return $tablestart . _cwfp_ReplaceMacro($this->template_form, $macros) . $tableend;
}
private function _asTab($index, $html, $tablestart, $tableend) {
$visible = $index ? 'detail0' : 'detail1';
$important = empty($this->tabs[$index]['h']) ? 0 : 1;
$tabnum = $index + 1; if ($tabnum < 10) $tabnum = '0' . $tabnum;
$important = $important ? '<span id="hilite_' . $tabnum . '"></span>' : '';
return "<div id=\"detail_{$tabnum}\" class=\"$visible\">$important$tablestart$html$tableend</div>\n";
}
private function TabHeader() { // this should be outside of any table that may have been defined
global $VARIABLE;
if (!count($this->tabs)) return ''; // Tabs not used
$VARIABLE['javascript_include'] .= <<<BLOCK
<style type="text/css">
.tab2 {
cursor: pointer;
float: left;
height: 25px;
margin-right: 1px;
padding: 0 1px 0 0;
}
.tab {
cursor: pointer;
float: left;
font-weight: bold;
line-height: 25px;
outline: medium none;
padding: 0 6px 0 9px;
text-decoration: none;
}
a.tab img.tab_icon {
float: left;
height: 20px;
margin: 5px 0 0;
padding: 0;
width: 20px;
}
.tab2 a:hover {
text-decoration: none;
}
.detail0 {
display: none;
}
.detail1 {
margin: 0;
padding: 10px;
display: block;
width: 90%;
border: 1px solid #666;
border-radius: 5px;
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
-khtml-border-radius: 5px;
background-color: #eef;
box-shadow: 6px 6px 5px rgba(0,0,0,0.4);
-webkit-box-shadow: 6px 6px 5px rgba(0,0,0,0.4);
-moz-box-shadow: 6px 6px 5px rgba(0,0,0,0.4);
-khtml-box-shadow: 6px 6px 5px rgba(0,0,0,0.4);
}
span.selected {
z-index: 100;
}
span.deselect {
z-index: 100;
}
.tabheader {
display: block;
font-size: 11px;
width: 100%;
}
span.selected a.tab {
background: url(/img/tab0l.png) no-repeat scroll left top transparent;
margin-left: -9px;
}
span.selected {
background: url(/img/tab0r.png) no-repeat scroll 100% 0 transparent;
margin-left: 9px;
}
span.deselect a.tab {
background: url(/img/tab1l.png) no-repeat scroll 0 0 transparent;
margin-left: -9px;
}
span.deselect {
background: url(/img/tab1r.png) no-repeat scroll 100% 0 transparent;
margin-left: 9px;
}
span.alert a.tab {
background: url(/img/tab5l.png) no-repeat scroll 0 0 transparent;
margin-left: -9px;
}
span.alert {
background: url(/img/tab5r.png) no-repeat scroll 100% 0 transparent;
margin-left: 9px;
}
</style>
BLOCK;
$VARIABLE['javascript'] .= <<<BLOCK
current_id = '';
function res_click(spanid) {
var current_tab;
if (current_id != '') {
current_tab = $('#' + current_id);
var temp = $('#hilite' + current_id);
if (temp.length) {
current_tab.removeClass('selected').addClass('alert');
} else {
current_tab.removeClass('selected').addClass('deselect');
}
$('#detail' + current_id).removeClass('detail1').addClass('detail0');
}
current_tab = $('#' + spanid);
if (!current_tab.length) return false;
current_id = spanid;
current_tab.removeClass('deselect alert').addClass('selected');
$('#detail' + current_id).removeClass('detail0').addClass('detail1');
return false;
}
function res_init() {
var anchorvalue = '';
var strippedUrl = document.location.toString().split('#');
if (strippedUrl.length > 1) anchorvalue = strippedUrl[1];
if (anchorvalue != '') {
var newtab = $('#detail' + anchorvalue);
if (newtab.length) res_click(anchorvalue);
}
}
BLOCK;
$VARIABLE['javascript_onload'] .= "\tres_click('_01');\n\tres_init();\n";
$output = '';
$this->tabheaderdisplayed = 1;
foreach($this->tabs as $index => $tabdata) {
$important = empty($tabdata['h']) ? 'deselect' : 'alert';
$class = ($index) ? $important : 'selected';
$tabnum = $index + 1; if ($tabnum < 10) $tabnum = '0' . $tabnum;
$icon = empty($tabdata['i']) ? '' : "<img class=\"tab_icon\" src=\"{$tabdata['i']}\" />";
// accesskey="d"
$output .= <<<BLOCK
<span class="tab2 $class" id="_{$tabnum}" onclick="return res_click('_{$tabnum}');"><a href="#" class="tab">$icon<label class="tab" for="_{$tabnum}" >{$tabdata['n']}</label></a></span>
BLOCK;
}
return <<<BLOCK
<div class="tabheader">
$output
</div>
<div class="clearfix"></div>
BLOCK;
}
private function _generatecustomLayout($html) {
// sort fieldnames from longest to shortest
$fieldname = array();
foreach($this->fielddefs as $field) { // don't include hidden or submit items
if ($field->fieldtype != 'submit' && $field->fieldtype != 'hidden') {
$fieldname[] = array($field->fieldname, $field);
}
}
usort($fieldname, array($this, '__sort_by_length'));
$p = -1;
// now replace macros with field html
while (1) {
$p = strpos($html, '%%', $p + 1);
if ($p === FALSE) break;
foreach($fieldname as $item) {
$c = strlen($item[0]);
if (substr($html, $p + 2, $c) == $item[0]) {
$field = $item[1];
$field = $field->AsHTML();
$html = substr($html, 0, $p) . $field . substr($html, $p + 2 + $c);
$p += strlen($field) - 2 - $c;
break;
}
}
}
return $html;
}
private function __sort_by_length($a, $b) { // longest to shortest
$a = strlen($a[0]);
$b = strlen($b[0]);
if ($a == $b) return 0;
return ($a > $b) ? -1 : 1;
}
private function formatFieldgroup($group, $caption) {
return "<tr><td><fieldset><legend><b> $caption </b></legend><table border=\"0\">$group</table></fieldset></td></tr>";
}
private function _asHTML_fieldgroup($tabnum, $n) {
$fields = '';
foreach($this->fielddefs as $field) { // don't include hidden or submit items
if ($field->fieldtype != 'submit' && $field->fieldtype != 'hidden') {
if (($field->tabnum == $tabnum) && ($field->groupnum == $n || $n == -999)) {
$fields .= $field->AsHTML();
}
}
}
return $fields;
}
public function group($caption) { // the following non-button fields are to grouped as a fieldset
if ($caption == '') {
$this->active_group = -2; // group -1 is at the beginning, group -2 is at the end
} else {
$this->groups[] = $caption;
$this->active_group = count($this->groups) - 1;
}
return $this->active_group;
}
public function database_assign(&$database) {
$this->DB = &$database;
}
// load the current record from the database, based on the sql (if present)
// overwrite with any posted data
// if posted, check for errors - eg required fields blank
public function database_load($sql = '', $params = NULL, $table_name = '') { // was ifp_PrepareData
global $VARIABLE;
if ($sql != '') {
$this->DATA = $this->DB->Lookup($sql, $params, $table_name);
if (!empty($this->onLoad)) {
$temp = $this->onLoad;
if (is_array($temp)) {
$temp[0]->$temp[1]($this);
} else {
$temp($this);
}
}
}
foreach($this->fielddefs as $info) {
$fieldname = $info->fieldname;
// Get the value of the field from the database, if present
if (isset($this->DATA[$fieldname])) {
$current = $this->DATA[$fieldname];
} elseif (isset($VARIABLE[$fieldname])) {
$current = $VARIABLE[$fieldname]; // this is a non-database field (needs to be removed before saving it
} else {
$current = '';
}
/* $USER_NUM = isset($_SESSION['sess_login']) ? $_SESSION['sess_login'] : 0;
if ($USER_NUM == 1467388885) {
var_dump($current);
} */
if (!empty($info->OnLoad)) {
$temp = $info->OnLoad;
if (is_array($temp)) {
$current = $temp[0]->$temp[1]($info, $current);
} else {
$current = $temp($info, $current);
}
}
// Override it with any posted value
if ($this->ISPOST) {
$current = $info->ValueFromPost();
if ($current == '' && $info->required && empty($VARIABLE["$fieldname.ERR"])) { // don't generate another error if there is already an error
$VARIABLE["$fieldname.ERR"] = '<b>' . _cwfp_WithoutAccess($info->fieldlabel) . '</b> is a required field';
}
if (!empty($info->OnValidate)) { // was $info['callback']
$temp = $info->OnValidate;
if (is_array($temp)) {
$current = $temp[0]->$temp[1]($info, $current);
} else {
$current = $temp($info, $current);
}
}
} else { // pick up default values from query_string
$current = $info->ValueFromPost($current);
if (!empty($info->OnValidate)) { // was $info['callback']
$temp = $info->OnValidate;
if (is_array($temp)) {
$current = $temp[0]->$temp[1]($info, $current);
} else {
$current = $temp($info, $current);
}
}
}
if (method_exists($this, '_format')) {
$current = $this->_format($current);
}
$VARIABLE[$fieldname] = $current; // dates will be in a format yyyy-mm-dd,
if (!isset($this->DATA[$fieldname])) $this->DATA[$fieldname] = $current;
}
// now that we have collected all the data for all the fields, check for "at least 1 field from a list is required"
if (count($this->alternates) && $this->ISPOST) {
foreach($this->alternates as $alternative) {
$this->_checkalternative($alternative);
}
}
// _sys_ is a check field, used to determine if data has changed
$VARIABLE['_sys_'] = ($this->ISPOST && isset($_POST['_sys_'])) ? $_POST['_sys_'] : '';
$errcount = 0;
foreach($this->fielddefs as $info) {
$fieldname = $info->fieldname;
if (isset($VARIABLE["$fieldname.ERR"])) $errcount++;
}
return $errcount;
}
private function _checkalternative($fieldlist) {
global $VARIABLE;
$fieldlabels = array();
foreach($fieldlist as $fieldname) {
$value = isset($VARIABLE[$fieldname]) ? trim($VARIABLE[$fieldname]) : '';
if ($value != '') return; // we have at least one value - all is good
}
// if it is 0, then display the message, please enter <b>email address</b>, <b>field2</b> or <b>product key</b>
foreach($this->fielddefs as $info) {
$fieldname = $info->fieldname;
if (in_array($fieldname, $fieldlist)) {
$fieldlabels[$fieldname] = _cwfp_WithoutAccess($info->fieldlabel);
}
}
$c = count($fieldlist);
$message = '';
for($i = 0; $i < $c; $i++) {
$fieldname = $fieldlist[$i];
if ($i == $c - 1 && $i > 0) {
$message .= ' or ';
} elseif ($i > 0) {
$message .= ' , ';
} else {
$first = $fieldname;
}
$message .= '<b>' . $fieldlabels[$fieldname] . '</b>';
}
$VARIABLE["$first.ERR"] = 'Please enter ' . $message;
}
// save current record back into the database
public function database_save($autoinc_field = '') {
global $VARIABLE;
if ($VARIABLE['_sys_'] != '') {
// ifp_markchangedfields($fielddefs, $VARIABLE['_sys_']);
}
foreach($this->fielddefs as $info) {
$fieldname = $info->fieldname;
$current = isset($VARIABLE[$fieldname]) ? $VARIABLE[$fieldname] : '';
$displayonly = isset($item->displayonly) ? $item->displayonly : 0;
if (!empty($info->onSave)) {
$temp = $info->onSave;
if (is_array($temp)) {
$current = $temp[0]->$temp[1]($info, $current);
} else {
$current = $temp($info, $current);
}
} elseif (!$displayonly) { // || ($opts & OPT_UPDATE
$info->SaveItem($current);
}
if ($info->flag_savefield) {
$this->DATA[$fieldname] = $current;
} elseif (substr($fieldname, 0, 2) != '__') {
unset($this->DATA[$fieldname]);
}
}
if (!empty($this->onSave)) {
$temp = $this->onSave;
if (is_array($temp)) {
$temp[0]->$temp[1]($this);
} else {
$temp($this);
}
}
if (empty($this->DATA['__table'])) return 1; // no table requested - don't save
$existing = empty($this->DATA['__existing']) ? 0 : $this->DATA['__existing'];
if ($existing) {
$this->DB->SaveRecord($this->DATA);
} else {
$this->DB->SaveRecord($this->DATA, $autoinc_field);
}
// var_dump($DATABASE->lastsql);
return $this->DB->error == '';
}
public function addCheckField() { // add a special field. Use if only Changed fields require saving
}
// At least one of the specified field(s) must have a value
public function AlternativeFields($fieldlist) {
$this->alternates[] = $fieldlist;
}
private function initialize_html() { // initialize each type of component
global $VARIABLE, $WEBFORMS_INIT;
$form_init = array();
foreach($this->fielddefs as $field) {
if (!isset($WEBFORMS_INIT[$field->fieldtype])) { // once per page,
$field->Initialize_html();
$WEBFORMS_INIT[$field->fieldtype] = 1;
}
if (!isset($form_init[$field->fieldtype])) { // once per form
$field->Initialize_Form();
$form_init[$field->fieldtype] = 1;
}
}
}
}
//----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- -----
//----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- -----
function _cwfp_ReplaceMacro($source, $macros) {
//** sort longest to shortest
foreach($macros as $key => $value) {
$source = str_replace('%%' . $key, $value, $source);
}
return $source;
}
function _cwfp_WithoutAccess($prompt) {
if (($p = strpos($prompt, '&')) !== FALSE) {
$prompt = substr($prompt, 0, $p) . substr($prompt, $p + 1);
}
return $prompt;
}
function _cwfp_setDateFormat() {
global $SETTINGS, $DISPLAY_DATE_FORMAT, $DEFAULT_DATE_FORMAT;
// if (!isset($DEFAULT_DATE_FORMAT)) $DEFAULT_DATE_FORMAT = 0;
$fmt = isset($SETTINGS['datefmt']) ? $SETTINGS['datefmt'] : 'm/d/Y';
switch($fmt) {
case 'Y-m-d':
$DEFAULT_DATE_FORMAT = 0; // used for cbi_inserdate
$DISPLAY_DATE_FORMAT = 'yy.mm.dd';
break;
case 'm/d/Y':
case 'M d, Y':
$DEFAULT_DATE_FORMAT = 4;
$DISPLAY_DATE_FORMAT = 'mm/dd/yy';
break;
case 'd-m-Y':
$DEFAULT_DATE_FORMAT = 8;
$DISPLAY_DATE_FORMAT = 'dd-mm-yy';
break;
}
}
function _cwfp_GetFilename($fieldname) {
if (!isset($_FILES[$fieldname])) {
while (substr($fieldname, 0, 1) == '_') {
$fieldname = substr($fieldname, 1);
}
}
if (isset($_FILES[$fieldname]) && $_FILES[$fieldname]['size'] > 0) {
$name = $_FILES[$fieldname]['tmp_name'];
if (is_uploaded_file($name)) {
return array($name, $_FILES[$fieldname]['name']);
}
}
return NULL;
}
function cwfp_yyyymmdd_to_date($specificdate) {
if ($specificdate == '') return '';
return substr($specificdate, 0, 4) . '-' . substr($specificdate, 4, 2) . '-' . substr($specificdate, 6, 2);
}
// These are our two core date routines -
// * Default date,
// * "Get Midnight" (converts the local time entered in the form to UTC start/end times for reports
function cwfp_Midnight($datetime, $delta = 0) { // $datetime in format yyyy-mm-dd
global $browser;
$midnightgmt = strtotime($datetime . 'Z');
if (is_object($browser)) {
$k = isset($browser->data['tz']) ? $browser->data['tz'] : -5;
$midnightgmt -= ($k * 60);
}
// $midnightgmt is now the UTC time when midnight localtime occurs
if ($delta) { // we now have a midnight. Which day should it be for?
if ($delta > 0) $delta = '+' . $delta;
$midnightgmt = strtotime("$delta day", $midnightgmt);
}
return $midnightgmt; // this is in unixtime (number of seconds since 1/1/1900
}
function cwfp_LoadFile($filename) {
$fp = fopen($filename, 'rb');
$stat = fstat($fp);
if ($stat['size']) {
$data = fread($fp, $stat['size']);
} else {
$data = '';
}
fclose($fp);
return $data;
}
// Converts the dates stored in the database to Locate Dates so that we can group them by Locate Date, not by GMT Date
function AsBrowserLocalTime($time = 0, $fmt = 'Y-m-d H:i:s') {
global $browser;
if (!$time) $time = time();
if (is_object($browser)) {
$k = isset($browser->data['tz']) ? $browser->data['tz'] : -5;
$time += ($k * 60);
}
$localtime = gmdate($fmt, $time);
return $localtime;
}
global $action;
$action = quote_Param_AsString('s');
_cwfp_setDateFormat();
/*
$(document).ready(function(){
$('.mySelectBoxClass').customSelect();
});
http://www.adamcoulombe.info/lab/jquery/select-box/
(function($){
$.fn.extend({
customSelect : function(options) {
if(!$.browser.msie || $.browser.version>6){
return this.each(function() {
var currentSelected = $(this).find(':selected');
var html = currentSelected.html();
if(!html){ html=' '; }
$(this).after('<span class="customStyleSelectBox"><span class="customStyleSelectBoxInner">'+html+'</span></span>').css({position:'absolute', opacity:0,fontSize:$(this).next().css('font-size')});
var selectBoxSpan = $(this).next();
var selectBoxWidth = parseInt($(this).width()) - parseInt(selectBoxSpan.css('padding-left')) -parseInt(selectBoxSpan.css('padding-right'));
var selectBoxSpanInner = selectBoxSpan.find(':first-child');
selectBoxSpan.css({display:'inline-block'});
selectBoxSpanInner.css({width:selectBoxWidth, display:'inline-block'});
var selectBoxHeight = parseInt(selectBoxSpan.height()) + parseInt(selectBoxSpan.css('padding-top')) + parseInt(selectBoxSpan.css('padding-bottom'));
$(this).height(selectBoxHeight).change(function(){
// selectBoxSpanInner.text($(this).val()).parent().addClass('changed'); This was not ideal
selectBoxSpanInner.text($(this).find(':selected').text()).parent().addClass('changed');
// Thanks to Juarez Filho & PaddyMurphy
});
});
}
}
});
})(jQuery);
*/