get_results("SHOW TABLES LIKE '".$wpdb->prefix.$this->table_messages."'"); if (!count($results)) { $sql = "CREATE TABLE ".$wpdb->prefix.$this->table_messages." ( id mediumint(9) NOT NULL AUTO_INCREMENT, formid INT NOT NULL, time datetime DEFAULT '0000-00-00 00:00:00' NOT NULL, ipaddr VARCHAR(250) DEFAULT '' NOT NULL, notifyto VARCHAR(250) DEFAULT '' NOT NULL, data mediumtext, posted_data mediumtext, UNIQUE KEY id (id) );"; $wpdb->query($sql); } $results = $wpdb->get_results("SHOW TABLES LIKE '".$wpdb->prefix.$this->table_items."'"); if (!count($results)) { $sql = "CREATE TABLE ".$wpdb->prefix.$this->table_items." ( id mediumint(9) NOT NULL AUTO_INCREMENT, form_name VARCHAR(250) DEFAULT '' NOT NULL, form_structure mediumtext, product_name VARCHAR(250) DEFAULT '' NOT NULL, pay_later_label VARCHAR(250) DEFAULT '' NOT NULL, fp_from_email VARCHAR(250) DEFAULT '' NOT NULL, fp_destination_emails text, fp_subject VARCHAR(250) DEFAULT '' NOT NULL, fp_inc_additional_info VARCHAR(10) DEFAULT '' NOT NULL, fp_return_page VARCHAR(250) DEFAULT '' NOT NULL, fp_message text, fp_emailformat VARCHAR(10) DEFAULT '' NOT NULL, fp_emailtomethod VARCHAR(10) DEFAULT '' NOT NULL, fp_destination_emails_field VARCHAR(200) DEFAULT '' NOT NULL, cu_enable_copy_to_user VARCHAR(10) DEFAULT '' NOT NULL, cu_user_email_field VARCHAR(250) DEFAULT '' NOT NULL, cu_subject VARCHAR(250) DEFAULT '' NOT NULL, cu_message text, cu_emailformat VARCHAR(10) DEFAULT '' NOT NULL, fp_emailfrommethod VARCHAR(10) DEFAULT '' NOT NULL, vs_text_is_required VARCHAR(250) DEFAULT '' NOT NULL, vs_text_is_email VARCHAR(250) DEFAULT '' NOT NULL, vs_text_datemmddyyyy VARCHAR(250) DEFAULT '' NOT NULL, vs_text_dateddmmyyyy VARCHAR(250) DEFAULT '' NOT NULL, vs_text_number VARCHAR(250) DEFAULT '' NOT NULL, vs_text_digits VARCHAR(250) DEFAULT '' NOT NULL, vs_text_max VARCHAR(250) DEFAULT '' NOT NULL, vs_text_min VARCHAR(250) DEFAULT '' NOT NULL, vs_text_pageof VARCHAR(250) DEFAULT '' NOT NULL, vs_text_submitbtn VARCHAR(250) DEFAULT '' NOT NULL, vs_text_previousbtn VARCHAR(250) DEFAULT '' NOT NULL, vs_text_nextbtn VARCHAR(250) DEFAULT '' NOT NULL, cp_user_access text, rep_enable VARCHAR(10) DEFAULT '' NOT NULL, rep_days VARCHAR(10) DEFAULT '' NOT NULL, rep_hour VARCHAR(10) DEFAULT '' NOT NULL, rep_emails text, rep_subject text, rep_emailformat VARCHAR(10) DEFAULT '' NOT NULL, rep_message text, cv_enable_captcha VARCHAR(20) DEFAULT '' NOT NULL, cv_width VARCHAR(20) DEFAULT '' NOT NULL, cv_height VARCHAR(20) DEFAULT '' NOT NULL, cv_chars VARCHAR(20) DEFAULT '' NOT NULL, cv_font VARCHAR(20) DEFAULT '' NOT NULL, cv_min_font_size VARCHAR(20) DEFAULT '' NOT NULL, cv_max_font_size VARCHAR(20) DEFAULT '' NOT NULL, cv_noise VARCHAR(20) DEFAULT '' NOT NULL, cv_noise_length VARCHAR(20) DEFAULT '' NOT NULL, cv_background VARCHAR(20) DEFAULT '' NOT NULL, cv_border VARCHAR(20) DEFAULT '' NOT NULL, cv_text_enter_valid_captcha VARCHAR(200) DEFAULT '' NOT NULL, UNIQUE KEY id (id) );"; $wpdb->query($sql); } // insert initial data $count = $wpdb->get_var( "SELECT COUNT(id) FROM ".$wpdb->prefix.$this->table_items ); if (!$count) { define('CP_APPBOOK_DEFAULT_fp_from_email', get_the_author_meta('user_email', get_current_user_id()) ); define('CP_APPBOOK_DEFAULT_fp_destination_emails', CP_APPBOOK_DEFAULT_fp_from_email); $wpdb->insert( $wpdb->prefix.$this->table_items, array( 'id' => 1, 'form_name' => 'Form 1', 'form_structure' => $this->get_option('form_structure', CP_APPBOOK_DEFAULT_form_structure), 'product_name' => $this->get_option('fp_from_email', 'Booking'), 'pay_later_label' => $this->get_option('fp_from_email', 'Pay later'), 'fp_from_email' => $this->get_option('fp_from_email', CP_APPBOOK_DEFAULT_fp_from_email), 'fp_destination_emails' => $this->get_option('fp_destination_emails', CP_APPBOOK_DEFAULT_fp_destination_emails), 'fp_subject' => $this->get_option('fp_subject', CP_APPBOOK_DEFAULT_fp_subject), 'fp_inc_additional_info' => $this->get_option('fp_inc_additional_info', CP_APPBOOK_DEFAULT_fp_inc_additional_info), 'fp_return_page' => $this->get_option('fp_return_page', CP_APPBOOK_DEFAULT_fp_return_page), 'fp_message' => $this->get_option('fp_message', CP_APPBOOK_DEFAULT_fp_message), 'fp_emailformat' => $this->get_option('fp_emailformat', CP_APPBOOK_DEFAULT_email_format), 'cu_enable_copy_to_user' => $this->get_option('cu_enable_copy_to_user', CP_APPBOOK_DEFAULT_cu_enable_copy_to_user), 'cu_user_email_field' => $this->get_option('cu_user_email_field', CP_APPBOOK_DEFAULT_cu_user_email_field), 'cu_subject' => $this->get_option('cu_subject', CP_APPBOOK_DEFAULT_cu_subject), 'cu_message' => $this->get_option('cu_message', CP_APPBOOK_DEFAULT_cu_message), 'cu_emailformat' => $this->get_option('cu_emailformat', CP_APPBOOK_DEFAULT_email_format), 'vs_text_is_required' => $this->get_option('vs_text_is_required', CP_APPBOOK_DEFAULT_vs_text_is_required), 'vs_text_is_email' => $this->get_option('vs_text_is_email', CP_APPBOOK_DEFAULT_vs_text_is_email), 'vs_text_datemmddyyyy' => $this->get_option('vs_text_datemmddyyyy', CP_APPBOOK_DEFAULT_vs_text_datemmddyyyy), 'vs_text_dateddmmyyyy' => $this->get_option('vs_text_dateddmmyyyy', CP_APPBOOK_DEFAULT_vs_text_dateddmmyyyy), 'vs_text_number' => $this->get_option('vs_text_number', CP_APPBOOK_DEFAULT_vs_text_number), 'vs_text_digits' => $this->get_option('vs_text_digits', CP_APPBOOK_DEFAULT_vs_text_digits), 'vs_text_max' => $this->get_option('vs_text_max', CP_APPBOOK_DEFAULT_vs_text_max), 'vs_text_min' => $this->get_option('vs_text_min', CP_APPBOOK_DEFAULT_vs_text_min), 'vs_text_pageof' => $this->get_option('vs_text_pageof', 'Page {0} of {0}'), 'vs_text_submitbtn' => $this->get_option('vs_text_submitbtn', 'Submit'), 'vs_text_previousbtn' => $this->get_option('vs_text_previousbtn', 'Previous'), 'vs_text_nextbtn' => $this->get_option('vs_text_nextbtn', 'Next'), 'rep_enable' => $this->get_option('rep_enable', 'no'), 'rep_days' => $this->get_option('rep_days', '1'), 'rep_hour' => $this->get_option('rep_hour', '0'), 'rep_emails' => $this->get_option('rep_emails', ''), 'rep_subject' => $this->get_option('rep_subject', 'Submissions report...'), 'rep_emailformat' => $this->get_option('rep_emailformat', 'text'), 'rep_message' => $this->get_option('rep_message', 'Attached you will find the data from the form submissions.'), 'cv_enable_captcha' => $this->get_option('cv_enable_captcha', CP_APPBOOK_DEFAULT_cv_enable_captcha), 'cv_width' => $this->get_option('cv_width', CP_APPBOOK_DEFAULT_cv_width), 'cv_height' => $this->get_option('cv_height', CP_APPBOOK_DEFAULT_cv_height), 'cv_chars' => $this->get_option('cv_chars', CP_APPBOOK_DEFAULT_cv_chars), 'cv_font' => $this->get_option('cv_font', CP_APPBOOK_DEFAULT_cv_font), 'cv_min_font_size' => $this->get_option('cv_min_font_size', CP_APPBOOK_DEFAULT_cv_min_font_size), 'cv_max_font_size' => $this->get_option('cv_max_font_size', CP_APPBOOK_DEFAULT_cv_max_font_size), 'cv_noise' => $this->get_option('cv_noise', CP_APPBOOK_DEFAULT_cv_noise), 'cv_noise_length' => $this->get_option('cv_noise_length', CP_APPBOOK_DEFAULT_cv_noise_length), 'cv_background' => $this->get_option('cv_background', CP_APPBOOK_DEFAULT_cv_background), 'cv_border' => $this->get_option('cv_border', CP_APPBOOK_DEFAULT_cv_border), 'cv_text_enter_valid_captcha' => $this->get_option('cv_text_enter_valid_captcha', CP_APPBOOK_DEFAULT_cv_text_enter_valid_captcha) ) ); } } /* Filter for placing the item into the contents */ public function filter_list($atts) { global $wpdb; extract( shortcode_atts( array( 'calendar' => '', 'fields' => 'DATE,TIME,email', 'from' => "today", 'to' => "today +30 days", 'paidonly' => "" ), $atts ) ); ob_start(); // calculate dates $from = date("Y-m-d",strtotime($from)); $to = date("Y-m-d",strtotime($to)); // pre-select time-slots $selection = array(); $rows = $wpdb->get_results( $wpdb->prepare("SELECT notifyto,posted_data,data FROM ".$wpdb->prefix.$this->table_messages." WHERE ".($calendar?'formid='.intval($calendar).' AND ':'')."time<=%s ORDER BY time DESC LIMIT 0,1000", $to) ); foreach($rows as $item) { $data = unserialize($item->posted_data); foreach($data["apps"] as $app) if ($app["date"] >= $from && $app["date"] <= $to) $selection[] = array($app["date"]." ".$app["slot"], $app["date"], $app["slot"], $data, $item->notifyto, $item->data); } // order time-slots function appbkfastsortfn($a, $b) { return ($a[0] > $b[0]); } usort($selection, "appbkfastsortfn" ); // clean fields IDs $fields = explode(",",trim($fields)); for($j=0; $j'; for($j=0; $j'; switch ($fields[$j]) { case 'date': echo $selection[$i][1]; break; case 'time': echo $selection[$i][2]; break; case 'email': echo $selection[$i][4]; break; case 'data': echo substr($selection[$i][5],strpos($selection[$i][5],"\n\n")+2); break; case 'paid': echo ($selection[$i][3][$fields[$j]]?__('Yes','cpappb'):' '); break; default: echo ($selection[$i][3][$fields[$j]]==''?' ':$selection[$i][3][$fields[$j]]); } echo ''; } echo ''; echo '
'; } $buffered_contents = ob_get_contents(); ob_end_clean(); return $buffered_contents; } /* Filter for placing the item into the contents */ public function filter_content($atts) { global $wpdb; extract( shortcode_atts( array( 'id' => '', ), $atts ) ); if ($id != '') $this->item = $id; /** * Filters applied before generate the form, * is passed as parameter an array with the forms attributes, and return the list of attributes */ $atts = apply_filters( 'cpappb_pre_form', $atts ); ob_start(); $this->insert_public_item(); $buffered_contents = ob_get_contents(); ob_end_clean(); /** * Filters applied after generate the form, * is passed as parameter the HTML code of the form with the corresponding and get_option('vs_text_submitbtn', 'Submit'); $button_label = ($button_label==''?'Submit':$button_label); // START:: code to load form settings $raw_form_str = str_replace("\r"," ",str_replace("\n"," ",$this->cleanJSON($this->translate_json($this->get_option('form_structure', CP_APPBOOK_DEFAULT_form_structure))))); $form_data = json_decode( $raw_form_str ); if( is_null( $form_data ) ){ $json = new JSON; $form_data = $json->unserialize( $raw_form_str ); } if( !is_null( $form_data ) ) { if( !empty( $form_data[ 0 ] ) ) { foreach( $form_data[ 0 ] as $key => $object ) { if ($object->ftype == 'fcheck' || $object->ftype == 'fradio' || $object->ftype == 'fdropdown') { for($ki=0; $kichoicesVal); $ki++) $object->choicesVal[$ki] = str_replace('@', CP_APPBOOK_REP_ARR, $object->choicesVal[$ki]); $form_data[ 0 ][ $key ] = $object; $raw_form_str = json_encode( $form_data ); } } } if( isset( $form_data[ 1 ] ) && isset( $form_data[ 1 ][ 0 ] ) && isset( $form_data[ 1 ][ 0 ]->formtemplate ) ) { $templatelist = $this->available_templates(); if( isset( $templatelist[ $form_data[ 1 ][ 0 ]->formtemplate ] ) ); print ''; } } $raw_form_str = str_replace('"','"',esc_attr($raw_form_str)); // END:: code to load form settings if (!defined('CP_AUTH_INCLUDE')) define('CP_AUTH_INCLUDE',true); @include dirname( __FILE__ ) . '/cp-public-int.inc.php'; if (!CP_APPBOOK_DEFER_SCRIPTS_LOADING) { $prefix_ui = ''; if (@file_exists(dirname( __FILE__ ).'/../../../wp-includes/js/jquery/ui/jquery.ui.core.min.js')) $prefix_ui = 'jquery.ui.'; // This code won't be used in most cases. This code is for preventing problems in wrong WP themes and conflicts with third party plugins. ?> print_counter++; } /* Code for the admin area */ public function plugin_page_links($links) { $customAdjustments_link = ''.__('Request custom changes').''; array_unshift($links, $customAdjustments_link); $settings_link = ''.__('Settings').''; array_unshift($links, $settings_link); $help_link = ''.__('Help').''; array_unshift($links, $help_link); return $links; } public function admin_menu() { add_options_page($this->plugin_name.' Options', $this->plugin_name, 'manage_options', $this->menu_parameter, array($this, 'settings_page') ); add_menu_page( $this->plugin_name.' Options', $this->plugin_name, 'read', $this->menu_parameter, array($this, 'settings_page') ); add_submenu_page( $this->menu_parameter, 'Upgrade', 'Upgrade', 'edit_pages', $this->menu_parameter."_upgrade", array($this, 'settings_page') ); } function insert_button() { global $wpdb; $options = ''; $calendars = $wpdb->get_results( 'SELECT * FROM '.$wpdb->prefix.$this->table_items); foreach($calendars as $item) $options .= ''; wp_enqueue_style('wp-jquery-ui-dialog'); wp_enqueue_script('jquery-ui-dialog'); ?> '.__('Insert  Appointment Hour Booking','cpappb').''; } public function settings_page() { global $wpdb; if ($this->get_param("cal") || $this->get_param("cal") == '0') { $this->item = $this->get_param("cal"); if ($this->get_param("schedule") == '1') @include_once dirname( __FILE__ ) . '/cp-admin-int-schedule.inc.php'; else if ($this->get_param("list") == '1') @include_once dirname( __FILE__ ) . '/cp-admin-int-message-list.inc.php'; else if ($this->get_param("report") == '1') @include_once dirname( __FILE__ ) . '/cp-admin-int-report.inc.php'; else @include_once dirname( __FILE__ ) . '/cp-admin-int.inc.php'; } else if ($this->get_param("page") == $this->menu_parameter.'_upgrade') { echo("Redirecting to upgrade page..."); exit; } else @include_once dirname( __FILE__ ) . '/cp-admin-int-list.inc.php'; } function insert_adminScripts($hook) { if ($this->get_param("page") == $this->menu_parameter) { wp_deregister_script('query-stringify'); wp_register_script('query-stringify', plugins_url('/js/jQuery.stringify.js', __FILE__)); wp_enqueue_script( $this->prefix.'_builder_script', $this->get_site_url( true ).'/?cp_cpappb_resources=admin',array("jquery","jquery-ui-core","jquery-ui-sortable","jquery-ui-tabs","jquery-ui-droppable","jquery-ui-button","query-stringify","jquery-ui-datepicker") ); wp_enqueue_style('jquery-style', 'https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.2/themes/smoothness/jquery-ui.css'); wp_enqueue_style('cpapp-style', plugins_url('/css/style.css', __FILE__)); } if( 'post.php' != $hook && 'post-new.php' != $hook ) return; // space to include some script in the post or page areas if needed } /* hook for checking posted data for the admin area */ function data_management() { global $wpdb; if(!empty($_POST['cp_app_action'])) { $formid = $_POST['formid']; $field = $_POST['formfield']; $myrows = $wpdb->get_results( $wpdb->prepare("SELECT posted_data FROM ".$wpdb->prefix.$this->table_messages." where formid=%d", $formid) ); $tmp = array(); for ($i=0; $i < count($myrows); $i++) { $data = unserialize($myrows[$i]->posted_data); if ($data[$field]) $tmp = array_merge($tmp,explode(";",$data[$field])); } $tmp2 = array(); for ($i=0;$isubstr($tmp[$i],0,10) ,"h1"=>intval(substr($tmp[$i],11,2)),"m1"=>intval(substr($tmp[$i],14,2)),"h2"=>intval(substr($tmp[$i],17,2)),"m2"=>intval(substr($tmp[$i],20,2))); } echo json_encode($tmp2); //{type:"all",d:"",h1:8,m1:0,h2:17,m2:0} exit; } if( isset( $_REQUEST[ 'cp_cpappb_resources' ] ) ) { if( $_REQUEST[ 'cp_cpappb_resources' ] == 'admin' ) { require_once dirname( __FILE__ ).'/js/fbuilder-loader-admin.php'; } else { require_once dirname( __FILE__ ).'/js/fbuilder-loader-public.php'; } exit; } $this->check_reports(); if ($this->get_param($this->prefix.'_encodingfix') == '1') { $wpdb->query('alter table '.$wpdb->prefix.$this->table_items.' convert to character set utf8 collate utf8_unicode_ci;'); $wpdb->query('alter table '.$wpdb->prefix.$this->table_messages.' convert to character set utf8 collate utf8_unicode_ci;'); echo 'Ok, encoding fixed.'; exit; } if ($this->get_param($this->prefix.'_captcha') == 'captcha' ) { @include_once dirname( __FILE__ ) . '/captcha/captcha.php'; exit; } if ($this->get_param($this->prefix.'_csv') && is_admin() ) { $this->export_csv(); return; } if ( $this->get_param($this->prefix.'_post_options') && is_admin() ) { $this->save_options(); return; } if ( 'POST' != $_SERVER['REQUEST_METHOD'] || ! isset( $_POST[$this->prefix.'_pform_process'] ) ) if ( 'GET' != $_SERVER['REQUEST_METHOD'] || !isset( $_GET['hdcaptcha_'.$this->prefix.'_post'] ) ) return; if ($this->get_param($this->prefix.'_id')) $this->item = $this->get_param($this->prefix.'_id'); @session_start(); if (isset($_GET["ps"])) $sequence = $_GET["ps"]; else if (isset($_POST["cp_pform_psequence"])) $sequence = $_POST["cp_pform_psequence"]; if ( !apply_filters( 'cpappb_valid_submission', true) || ( ($this->get_option('cv_enable_captcha', CP_APPBOOK_DEFAULT_cv_enable_captcha) != 'false') && ( (strtolower($this->get_param('hdcaptcha_'.$this->prefix.'_post')) != strtolower($_SESSION['rand_code'.$sequence])) || ($_SESSION['rand_code'.$sequence] == '') ) && ( (md5(strtolower($this->get_param('hdcaptcha_'.$this->prefix.'_post'))) != ($_COOKIE['rand_code'.$sequence])) || ($_COOKIE['rand_code'.$sequence] == '') ) ) ) { echo 'captchafailed'; exit; } // if this isn't the real post (it was the captcha verification) then echo ok and exit if ( 'POST' != $_SERVER['REQUEST_METHOD'] || ! isset( $_POST[$this->prefix.'_pform_process'] ) ) { echo 'ok'; exit; } foreach ($_POST as $item => $value) $_POST[$item] = (is_array($value)?$value:stripcslashes($value)); // get form info //--------------------------- require_once(ABSPATH . "wp-admin" . '/includes/file.php'); $form_data = json_decode($this->cleanJSON($this->get_option('form_structure', CP_APPBOOK_DEFAULT_form_structure))); $fields = array(); foreach ($form_data[0] as $item) if ($item->ftype != 'fapp') { $fields[$item->name] = $item->title; if ($item->ftype == 'fPhone') // join fields for phone fields { $_POST[$item->name.$sequence] = ''; for($i=0; $i<=substr_count($item->dformat," "); $i++) { $_POST[$item->name.$sequence] .= ($_POST[$item->name.$sequence."_".$i]!=''?($i==0?'':'-').$_POST[$item->name.$sequence."_".$i]:''); unset($_POST[$item->name.$sequence."_".$i]); } } } $apps = $this->extract_appointments($form_data[0], $_POST, $sequence); $price = $this->extract_total_price ($apps); $apptext = $this->get_appointments_text ($apps); // grab posted data //--------------------------- $buffer = __('Appointments','cpappb').":\n".$apptext."\n"; $params = array(); $params["final_price"] = $price; $params["apps"] = $apps; $params["formid"] = $this->item; $params["referrer"] = $_POST["refpage".$sequence]; foreach ($_POST as $item => $value) if (isset($fields[str_replace($sequence,'',$item)])) { if (is_array($value)) { for ($iv=0; $iv $value) { $item = str_replace( $sequence,'',$item ); if ( isset( $fields[ $item ] ) ) { $files_names_arr = array(); $files_links_arr = array(); $files_urls_arr = array(); for( $f = 0; $f < count( $value[ 'name' ] ); $f++ ) { if( !empty( $value[ 'name' ][ $f ] ) ) { $uploaded_file = array( 'name' => $value[ 'name' ][ $f ], 'type' => $value[ 'type' ][ $f ], 'tmp_name' => $value[ 'tmp_name' ][ $f ], 'error' => $value[ 'error' ][ $f ], 'size' => $value[ 'size' ][ $f ], ); $movefile = wp_handle_upload( $uploaded_file, array( 'test_form' => false ) ); if ( empty( $movefile[ 'error' ] ) ) { $files_links_arr[] = $params[ $item."_link" ][ $f ] = $movefile["file"]; $files_urls_arr[] = $params[ $item."_url" ][ $f ] = $movefile["url"]; $files_names_arr[] = $uploaded_file[ 'name' ]; /** * Action called when the file is uploaded, the file's data is passed as parameter */ do_action( 'cpappb_file_uploaded', $movefile ); } //else echo $movefile[ 'error' ]; } } $joinned_files_names = implode( ", ", $files_names_arr ); $buffer .= $fields[ $item ] . ": ". $joinned_files_names . "\n\n"; $params[ $item ] = $joinned_files_names; //$params[ $item."_links"] = implode( ",", $files_links_arr ); //$params[ $item."_urls"] = implode( ",", $files_urls_arr ); } } $buffer_A = $buffer; /** * Action called before insert the data into database. * To the function is passed an array with submitted data. */ do_action( 'cpappb_process_data_before_insert', $params ); // insert into database //--------------------------- $wpdb->query("ALTER TABLE ".$wpdb->prefix.$this->table_messages." CHANGE `ipaddr` `ipaddr` VARCHAR(250)"); $to = $this->get_option('cu_user_email_field', CP_APPBOOK_DEFAULT_cu_user_email_field); $rows_affected = $wpdb->insert( $wpdb->prefix.$this->table_messages, array( 'formid' => $this->item, 'time' => current_time('mysql'), 'ipaddr' => (CP_APPBOOK_DEFAULT_track_IP?$_SERVER['REMOTE_ADDR']:''), 'notifyto' => (@$_POST[$to.$sequence]?$_POST[$to.$sequence]:''), 'posted_data' => serialize($params), 'data' =>$buffer_A ) ); if (!$rows_affected) { echo 'Error saving data! Please try again.'; exit; } $myrows = $wpdb->get_results( "SELECT MAX(id) as max_id FROM ".$wpdb->prefix.$this->table_messages ); $item_number = $myrows[0]->max_id; // Call action for data processing //--------------------------------- $params[ 'itemnumber' ] = $item_number; /** * Action called after inserted the data into database. * To the function is passed an array with submitted data. */ do_action( 'cpappb_process_data', $params ); $this->ready_to_go_reservation($item_number, "", $params); $_SESSION[ 'cp_cff_form_data' ] = $item_number; /** * Filters applied to decide if the website should be redirected to the thank you page after submit the form, * pass a boolean as parameter and returns a boolean */ $redirect = true; $redirect = apply_filters( 'cpappb_redirect', $redirect ); if( $redirect ) { header("Location: ".$this->get_option('fp_return_page', CP_APPBOOK_DEFAULT_fp_return_page)); exit(); } } function extract_appointments($form,$data,$sequence) { $apps = array(); foreach($form as $field) if ($field->ftype == 'fapp' && @$data[$field->name.$sequence] != '') { $apps_text = explode(';',$data[$field->name.$sequence]); foreach($apps_text as $app_item_text) { $item_split = explode(' ',$app_item_text); $apps[] = array ( 'serviceindex' => $item_split[2], 'service' => $field->services[ $item_split[2] ]->name, 'duration' => $field->services[ $item_split[2] ]->duration, 'price' => $field->services[ $item_split[2] ]->price, 'date' => $item_split[0], 'slot' => $item_split[1] ); } } return $apps; } function extract_total_price($apps) { $price = 0; foreach($apps as $app) $price += $app["price"]; return number_format($price,2,'.',''); } function get_appointments_text($apps) { $text = ''; foreach($apps as $app) $text .= " - ".$app["date"]." ".$app["slot"]." (".$app["service"].")\n"; return $text; } function ready_to_go_reservation($itemnumber, $payer_email = "", $params = array()) { global $wpdb; $myrows = $wpdb->get_results( $wpdb->prepare("SELECT * FROM ".$wpdb->prefix.$this->table_messages." WHERE id=%d", $itemnumber) ); $mycalendarrows = $wpdb->get_results( $wpdb->prepare('SELECT * FROM '.$wpdb->prefix.$this->table_items.' WHERE `id`=%d', $myrows[0]->formid) ); $this->item = $myrows[0]->formid; $buffer_A = $myrows[0]->data; $buffer = $buffer_A; if ('true' == $this->get_option('fp_inc_additional_info', CP_APPBOOK_DEFAULT_fp_inc_additional_info)) { $buffer .="ADDITIONAL INFORMATION\n" ."*********************************\n"; $basic_data = "IP: ".$myrows[0]->ipaddr."\n" ."Server Time: ".date("Y-m-d H:i:s")."\n"; /** * Includes additional information to the email's message, * are passed two parameters: the basic information, and the IP address */ $basic_data = apply_filters( 'cpappb_additional_information', $basic_data, $myrows[0]->ipaddr ); $params["additional"] = $basic_data; $buffer .= $basic_data; } // 1- Send email //--------------------------- $attachments = array(); if ('html' == $this->get_option('fp_emailformat', CP_APPBOOK_DEFAULT_email_format)) $message = str_replace('<%INFO%>',str_replace("\n","
",str_replace('<','<',$buffer)),$this->get_option('fp_message', CP_APPBOOK_DEFAULT_fp_message)); else $message = str_replace('<%INFO%>',$buffer,$this->get_option('fp_message', CP_APPBOOK_DEFAULT_fp_message)); $subject = $this->get_option('fp_subject', CP_APPBOOK_DEFAULT_fp_subject); foreach ($params as $item => $value) { $message = str_replace('<%'.$item.'%>',(is_array($value)?(implode(", ",$value)):($value)),$message); $subject = str_replace('<%'.$item.'%>',(is_array($value)?(implode(", ",$value)):($value)),$subject); if (strpos($item,"_link")) { foreach ($value as $filevalue) $attachments[] = $filevalue; } } $message = str_replace('<%itemnumber%>',$itemnumber,$message); $subject = str_replace('<%itemnumber%>',$itemnumber,$subject); $from = $this->get_option('fp_from_email', @CP_APPBOOK_DEFAULT_fp_from_email); $to = explode(",",$this->get_option('fp_destination_emails', @CP_APPBOOK_DEFAULT_fp_destination_emails)); if ('html' == $this->get_option('fp_emailformat', CP_APPBOOK_DEFAULT_email_format)) $content_type = "Content-Type: text/html; charset=utf-8\n"; else $content_type = "Content-Type: text/plain; charset=utf-8\n"; $replyto = $myrows[0]->notifyto; if ($this->get_option('fp_emailfrommethod', "fixed") == "customer") $from_1 = $replyto; else $from_1 = $from; if ($this->get_option('fp_emailtomethod', "fixed") == 'customer') { $text_addr = $params[$this->get_option('fp_destination_emails_field', "fixed")]; if (is_array($text_addr)) $text_addr = implode(", ",$text_addr); $pattern = '/[a-zA-Z0-9_\.\+-]+@[A-Za-z0-9_-]+\.([A-Za-z0-9_-][A-Za-z0-9_]+)/'; //regex for pattern of e-mail address preg_match_all($pattern, $text_addr, $matches); if (count($matches[0]) > 0) $to = $matches[0]; } $to = array_unique ($to); for ($i=0;$i<500;$i++) { $subject = str_replace('<%fieldname'.$i.'%>',"",$subject); $message = str_replace('<%fieldname'.$i.'%>',"",$message); } foreach ($to as $item) if (trim($item) != '') { if (!strpos($from_1,">")) $from_1 = '"'.$from_1.'" <'.$from_1.'>'; wp_mail(trim($item), $subject, $message, "From: ".$from_1."\r\n". ($replyto!=''?"Reply-To: \"$replyto\" <".$replyto.">\r\n":''). $content_type. "X-Mailer: PHP/" . phpversion(), $attachments); } if ($mycalendarrows[0]->rep_days == 0 && $mycalendarrows[0]->rep_enable == 'yes') { $this->check_reports(true); } // 2- Send copy to user //--------------------------- $to = $this->get_option('cu_user_email_field', CP_APPBOOK_DEFAULT_cu_user_email_field); $_POST[$to] = $myrows[0]->notifyto; if ((trim($_POST[$to]) != '' || $payer_email != '') && 'true' == $this->get_option('cu_enable_copy_to_user', CP_APPBOOK_DEFAULT_cu_enable_copy_to_user)) { if ('html' == $this->get_option('cu_emailformat', CP_APPBOOK_DEFAULT_email_format)) $message = str_replace('<%INFO%>',str_replace("\n","
",str_replace('<','<',$buffer_A)).'',$this->get_option('cu_message', CP_APPBOOK_DEFAULT_cu_message)); else $message = str_replace('<%INFO%>',$buffer_A,$this->get_option('cu_message', CP_APPBOOK_DEFAULT_cu_message)); $subject = $this->get_option('cu_subject', CP_APPBOOK_DEFAULT_cu_subject); foreach ($params as $item => $value) { $message = str_replace('<%'.$item.'%>',(is_array($value)?(implode(", ",$value)):($value)),$message); $subject = str_replace('<%'.$item.'%>',(is_array($value)?(implode(", ",$value)):($value)),$subject); } $message = str_replace('<%itemnumber%>',$itemnumber,$message); $subject = str_replace('<%itemnumber%>',$itemnumber,$subject); for ($i=0;$i<500;$i++) { $subject = str_replace('<%fieldname'.$i.'%>',"",$subject); $message = str_replace('<%fieldname'.$i.'%>',"",$message); } if (!strpos($from,">")) $from = '"'.$from.'" <'.$from.'>'; if ('html' == $this->get_option('cu_emailformat', CP_APPBOOK_DEFAULT_email_format)) $content_type = "Content-Type: text/html; charset=utf-8\n"; else $content_type = "Content-Type: text/plain; charset=utf-8\n"; if ($_POST[$to] != '') wp_mail(trim($_POST[$to]), $subject, $message, "From: ".$from."\r\n". $content_type. "X-Mailer: PHP/" . phpversion()); if ($_POST[$to] != $payer_email && $payer_email != '') wp_mail(trim($payer_email), $subject, $message, "From: ".$from."\r\n". $content_type. "X-Mailer: PHP/" . phpversion()); } } function available_templates(){ if( empty( $this->CP_CFPP_global_templates ) ) { // Get available designs $tpls_dir = dir( plugin_dir_path( __FILE__ ).'templates' ); $this->CP_CFPP_global_templates = array(); while( false !== ( $entry = $tpls_dir->read() ) ) { if ( $entry != '.' && $entry != '..' && is_dir( $tpls_dir->path.'/'.$entry ) && file_exists( $tpls_dir->path.'/'.$entry.'/config.ini' ) ) { if( ( $ini_array = parse_ini_file( $tpls_dir->path.'/'.$entry.'/config.ini' ) ) !== false ) { if( !empty( $ini_array[ 'file' ] ) ) $ini_array[ 'file' ] = plugins_url( 'templates/'.$entry.'/'.$ini_array[ 'file' ], __FILE__ ); if( !empty( $ini_array[ 'thumbnail' ] ) ) $ini_array[ 'thumbnail' ] = plugins_url( 'templates/'.$entry.'/'.$ini_array[ 'thumbnail' ], __FILE__ ); $this->CP_CFPP_global_templates[ $ini_array[ 'prefix' ] ] = $ini_array; } } } } return $this->CP_CFPP_global_templates; } function save_options() { global $wpdb; $this->item = $_POST[$this->prefix."_id"]; $this->verify_nonce ($_POST["anonce"], 'cpappb_actions_admin'); //$this->add_field_verify($wpdb->prefix.$this->table_items, 'product_name'); //$this->add_field_verify($wpdb->prefix.$this->table_items, 'pay_later_label'); if (substr_count($_POST['form_structure'],"\\") > 30) foreach ($_POST as $item => $value) if (!is_array($value)) $_POST[$item] = stripcslashes($value); $data = array( 'form_structure' => $_POST['form_structure'], 'product_name' => $_POST['product_name'], 'pay_later_label' => $_POST['pay_later_label'], 'fp_from_email' => $_POST['fp_from_email'], 'fp_destination_emails' => $_POST['fp_destination_emails'], 'fp_subject' => $_POST['fp_subject'], 'fp_inc_additional_info' => $_POST['fp_inc_additional_info'], 'fp_return_page' => $_POST['fp_return_page'], 'fp_message' => $_POST['fp_message'], 'fp_emailformat' => $_POST['fp_emailformat'], 'fp_emailtomethod' => $_POST['fp_emailtomethod'], 'fp_destination_emails_field' => $_POST['fp_destination_emails_field'], 'cu_enable_copy_to_user' => $_POST['cu_enable_copy_to_user'], 'cu_user_email_field' => $_POST['cu_user_email_field'], 'cu_subject' => $_POST['cu_subject'], 'cu_message' => $_POST['cu_message'], 'cu_emailformat' => $_POST['cu_emailformat'], 'fp_emailfrommethod' => $_POST['fp_emailfrommethod'], 'vs_text_is_required' => $_POST['vs_text_is_required'], 'vs_text_is_email' => $_POST['vs_text_is_email'], 'vs_text_datemmddyyyy' => $_POST['vs_text_datemmddyyyy'], 'vs_text_dateddmmyyyy' => $_POST['vs_text_dateddmmyyyy'], 'vs_text_number' => $_POST['vs_text_number'], 'vs_text_digits' => $_POST['vs_text_digits'], 'vs_text_max' => $_POST['vs_text_max'], 'vs_text_min' => $_POST['vs_text_min'], 'vs_text_pageof' => $_POST['vs_text_pageof'], 'vs_text_submitbtn' => $_POST['vs_text_submitbtn'], 'vs_text_previousbtn' => $_POST['vs_text_previousbtn'], 'vs_text_nextbtn' => $_POST['vs_text_nextbtn'], 'cp_user_access' => serialize(@$_POST["cp_user_access"]), 'rep_enable' => $_POST['rep_enable'], 'rep_days' => $_POST['rep_days'], 'rep_hour' => $_POST['rep_hour'], 'rep_emails' => $_POST['rep_emails'], 'rep_subject' => $_POST['rep_subject'], 'rep_emailformat' => $_POST['rep_emailformat'], 'rep_message' => $_POST['rep_message'], 'cv_enable_captcha' => $_POST['cv_enable_captcha'], 'cv_width' => $_POST['cv_width'], 'cv_height' => $_POST['cv_height'], 'cv_chars' => $_POST['cv_chars'], 'cv_font' => $_POST['cv_font'], 'cv_min_font_size' => $_POST['cv_min_font_size'], 'cv_max_font_size' => $_POST['cv_max_font_size'], 'cv_noise' => $_POST['cv_noise'], 'cv_noise_length' => $_POST['cv_noise_length'], 'cv_background' => str_replace('#','',$_POST['cv_background']), 'cv_border' => str_replace('#','',$_POST['cv_border']), 'cv_text_enter_valid_captcha' => $_POST['cv_text_enter_valid_captcha'] ); $wpdb->update ( $wpdb->prefix.$this->table_items, $data, array( 'id' => $this->item )); } function get_form_field_label ($fieldid, $form) { foreach($form as $item) if ($item->name == $fieldid) { if (isset($item->shortlabel) && $item->shortlabel != '') return $item->shortlabel; else return $item->title; } return $fieldid; } function generateSafeFileName($filename) { $filename = strtolower(strip_tags($filename)); $filename = str_replace(";","_",$filename); $filename = str_replace("#","_",$filename); $filename = str_replace(" ","_",$filename); $filename = str_replace("'","",$filename); $filename = str_replace('"',"",$filename); $filename = str_replace("__","_",$filename); $filename = str_replace("&","and",$filename); $filename = str_replace("/","_",$filename); $filename = str_replace("\\","_",$filename); $filename = str_replace("?","",$filename); return $filename; } function export_csv () { if (!is_admin()) return; global $wpdb; $this->item = intval($this->get_param("cal")); if ($this->item) { $form = json_decode($this->cleanJSON($this->get_option('form_structure', CP_APPBOOK_DEFAULT_form_structure))); $form = $form[0]; } else $form = array(); $cond = ''; if ($this->get_param("search")) $cond .= " AND (data like '%".esc_sql($this->get_param("search"))."%' OR posted_data LIKE '%".esc_sql($this->get_param("search"))."%')"; if ($this->get_param("dfrom")) $cond .= " AND (`time` >= '".esc_sql($this->get_param("dfrom"))."')"; if ($this->get_param("dto")) $cond .= " AND (`time` <= '".esc_sql($this->get_param("dto"))." 23:59:59')"; if ($this->item != 0) $cond .= " AND formid=".$this->item; $events_query = "SELECT * FROM ".$wpdb->prefix.$this->table_messages." WHERE 1=1 ".$cond." ORDER BY `time` DESC"; /** * Allows modify the query of messages, passing the query as parameter * returns the new query */ $events_query = apply_filters( 'cpappb_csv_query', $events_query ); $events = $wpdb->get_results( $events_query ); if ($this->include_user_data_csv) $fields = array("ID", "Form ID", "Time", "IP Address", "email"); else $fields = array("ID", "Form", "Time", "email"); $values = array(); foreach ($events as $item) { if ($this->include_user_data_csv) $value = array($item->id,$this->get_option('form_name',''), $item->time, $item->ipaddr, $item->notifyto); else $value = array($item->id,$this->get_option('form_name',''), $item->time, $item->notifyto); if ($item->posted_data) $data = unserialize($item->posted_data); else $data = array(); $end = count($fields); for ($i=0; $i<$end; $i++) if (isset($data[$fields[$i]]) ){ $value[$i] = $data[$fields[$i]]; unset($data[$fields[$i]]); } if (is_array($data)) foreach ($data as $k => $d) { $fields[] = $k; $value[] = $d; } $values[] = $value; } $filename = $this->generateSafeFileName(strtolower($this->get_option('form_name','export'))).'_'.date("m_d_y"); header("Content-type: application/octet-stream"); header("Content-Disposition: attachment; filename=".$filename.".csv"); $end = count($fields); for ($i=0; $i<$end; $i++) echo '"'.str_replace('"','""', $this->get_form_field_label($fields[$i],$form)).'",'; echo "\n"; foreach ($values as $item) { for ($i=0; $i<$end; $i++) { if (!isset($item[$i])) $item[$i] = ''; if (is_array($item[$i])) $item[$i] = implode($item[$i],','); echo '"'.str_replace('"','""', $item[$i]).'",'; } echo "\n"; } exit; } public function setId($id) { $this->item = $id; } public function translate_json($str) { $form_data = json_decode($this->cleanJSON($str)); $form_data[1][0]->title = __($form_data[1][0]->title,'cpappb'); $form_data[1][0]->description = __($form_data[1][0]->description,'cpappb'); for ($i=0; $i < count($form_data[0]); $i++) { $form_data[0][$i]->title = __($form_data[0][$i]->title,'cpappb'); $form_data[0][$i]->userhelpTooltip = __($form_data[0][$i]->userhelpTooltip,'cpappb'); $form_data[0][$i]->userhelp = __($form_data[0][$i]->userhelp,'cpappb'); if ($form_data[0][$i]->ftype == 'fCommentArea') $form_data[0][$i]->userhelp = __($form_data[0][$i]->userhelp,'cpappb'); else if ($form_data[0][$i]->ftype == 'fradio' || $form_data[0][$i]->ftype == 'fcheck' || $form_data[0][$i]->ftype == 'fradio') { for ($j=0; $j < count($form_data[0][$i]->choices); $j++) $form_data[0][$i]->choices[$j] = __($form_data[0][$i]->choices[$j],'cpappb'); } } $str = json_encode($form_data); return $str; } private function get_records_csv($formid, $form_name = "") { global $wpdb; $saved_item = $this->item; $this->item = $formid; $last_sent_id = get_option('cp_cpappb_last_sent_id_'.$formid, '0'); $events = $wpdb->get_results( $wpdb->prepare("SELECT * FROM ".$wpdb->prefix.$this->table_messages." WHERE formid=%d AND id>%d ORDER BY id ASC",$formid,$last_sent_id) ); if ($wpdb->num_rows <= 0) // if no rows, return empty return ''; if ($this->item) { $form = json_decode($this->cleanJSON($this->get_option('form_structure', CP_APPBOOK_DEFAULT_form_structure))); $form = $form[0]; } else $form = array(); $buffer = ''; if ($this->include_user_data_csv) $fields = array("Submission ID", "Form", "Time", "IP Address", "email"); else $fields = array("Submission ID", "Form", "Time", "email"); $values = array(); foreach ($events as $item) { if ($this->include_user_data_csv) $value = array($item->id, $form_name, $item->time, $item->ipaddr, $item->notifyto); else $value = array($item->id, $form_name, $item->time, $item->notifyto); $last_sent_id = $item->id; if ($item->posted_data) $data = unserialize($item->posted_data); else $data = array(); $end = count($fields); for ($i=0; $i<$end; $i++) if (isset($data[$fields[$i]]) ){ $value[$i] = $data[$fields[$i]]; unset($data[$fields[$i]]); } if (is_array($data)) foreach ($data as $k => $d) { $fields[] = $k; $value[] = $d; } $values[] = $value; } update_option('cp_cpappb_last_sent_id_'.$formid, $last_sent_id); $end = count($fields); for ($i=0; $i<$end; $i++) $buffer .= '"'.str_replace('"','""', $this->get_form_field_label($fields[$i],$form)).'",'; $buffer .= "\n"; foreach ($values as $item) { for ($i=0; $i<$end; $i++) { if (!isset($item[$i])) $item[$i] = ''; if (is_array($item[$i])) $item[$i] = implode($item[$i],','); $buffer .= '"'.str_replace('"','""', $item[$i]).'",'; } $buffer .= "\n"; } $this->item = $saved_item; return $buffer; } private function check_reports($skip_verification = false) { global $wpdb; $last_verified = get_option('cp_cpappb_last_verified',''); if ( $skip_verification || $last_verified == '' || $last_verified < date("Y-m-d H:i:s", strtotime("-1 minutes")) ) // verification to don't check too fast to avoid overloading the site { update_option('cp_cpappb_last_verified',date("Y-m-d H:i:s")); // global reports for all forms if (get_option('cp_cpappb_rep_enable', 'no') == 'yes' && get_option('cp_cpappb_rep_days', '') != '' && get_option('cp_cpappb_rep_emails', '') != '' ) { $formid = 0; $verify_after = date("Y-m-d H:i:s", strtotime("-".get_option('cp_cpappb_rep_days', '')." days")); $last_sent = get_option('cp_cpappb_last_sent'.$formid, ''); if ($last_sent == '' || $last_sent < $verify_after) // check if this form needs to check for a new report { update_option('cp_cpappb_last_sent'.$formid, date("Y-m-d ".(get_option('cp_cpappb_rep_hour', '')<'10'?'0':'').get_option('cp_cpappb_rep_hour', '').":00:00")); $text = ''; $forms = $wpdb->get_results("SELECT id,fp_from_email,form_name,rep_days,rep_hour,rep_emails,rep_subject,rep_emailformat,rep_message,rep_enable FROM ".$wpdb->prefix.$this->table_items." WHERE rep_emails<>'' AND rep_enable='yes'"); $attachments = array(); foreach ($forms as $form) // for each form with the reports enabled { $csv = $this->get_records_csv($form->id, $form->form_name); if ($csv != '') { $text = "- ".substr_count($csv,",\n\"").' submissions from '.$form->form_name."\n"; $filename = $this->generateSafeFileName(strtolower($form->form_name)).'_'.date("m_d_y"); $filename = WP_CONTENT_DIR . '/uploads/'.$filename .'.csv'; $handle = fopen($filename, 'w'); fwrite($handle,$csv); fclose($handle); $attachments[] = $filename; } } if ('html' == get_option('cp_cpappb_rep_emailformat','')) $content_type = "Content-Type: text/html; charset=utf-8\n"; else $content_type = "Content-Type: text/plain; charset=utf-8\n"; if (count($attachments)) wp_mail( str_replace(" ","",str_replace(";",",",get_option('cp_cpappb_rep_emails',''))), get_option('cp_cpappb_rep_subject',''), get_option('cp_cpappb_rep_message','')."\n".$text, "From: \"".get_option('cp_cpappb_fp_from_email','')."\" <".get_option('cp_cpappb_fp_from_email','').">\r\n". $content_type. "X-Mailer: PHP/" . phpversion(), @$attachments); } } // reports for specific forms $forms = $wpdb->get_results("SELECT id,form_name,fp_from_email,rep_days,rep_hour,rep_emails,rep_subject,rep_emailformat,rep_message,rep_enable FROM ".$wpdb->prefix.$this->table_items." WHERE rep_emails<>'' AND rep_enable='yes'"); foreach ($forms as $form) // for each form with the reports enabled { $formid = $form->id; $verify_after = date("Y-m-d H:i:s", strtotime("-".$form->rep_days." days")); $last_sent = get_option('cp_cpappb_last_sent'.$formid, ''); if ($skip_verification || $last_sent == '' || $last_sent < $verify_after) // check if this form needs to check for a new report { update_option('cp_cpappb_last_sent'.$formid, date("Y-m-d ".($form->rep_hour<'10'?'0':'').$form->rep_hour.":00:00")); $csv = $this->get_records_csv($formid, $form->form_name); if ($csv != '') { $filename = $this->generateSafeFileName(strtolower($form->form_name)).'_'.date("m_d_y"); $filename = WP_CONTENT_DIR . '/uploads/'.$filename .'.csv'; $handle = fopen($filename, 'w'); fwrite($handle,$csv); fclose($handle); $attachments = array( $filename ); if ('html' == $form->rep_emailformat) $content_type = "Content-Type: text/html; charset=utf-8\n"; else $content_type = "Content-Type: text/plain; charset=utf-8\n"; wp_mail( str_replace(" ","",str_replace(";",",",$form->rep_emails)), $form->rep_subject, $form->rep_message, "From: \"".$form->fp_from_email."\" <".$form->fp_from_email.">\r\n". $content_type. "X-Mailer: PHP/" . phpversion(), $attachments); } } } // end foreach } // end if } // end check_reports function } // end class // WIDGET CODE BELOW require_once dirname( __FILE__ ).'/cp-widget.inc.php'; // Auxiliar functions // ****************************************************************** // Auxiliar functions // *********************************************************************** function cpappb_cleanJSON ($str) { $str = str_replace('&qquot;','"',$str); $str = str_replace(' ',' ',$str); $str = str_replace("\n",'\n',$str); $str = str_replace("\r",'',$str); return $str; } function cpappb_form_result( $atts, $content = "", $id = 0 ) { global $wpdb; if( $id == 0 && !empty( $_SESSION[ 'cp_cff_form_data' ] ) ) $id = $_SESSION[ 'cp_cff_form_data' ]; if( !empty( $id ) ) { $content = html_entity_decode( $content ); $result = $wpdb->get_row( $wpdb->prepare( "SELECT form_settings.form_structure AS form_structure, form_data.data AS data, form_data.data AS data, form_data.ipaddr as ipaddr FROM ".$wpdb->prefix."cpappbk_forms"." AS form_settings,".$wpdb->prefix."cpappbk_messages"." AS form_data WHERE form_data.id=%d AND form_data.formid=form_settings.id", $id ) ); if( !is_null( $result ) ) { $atts = shortcode_atts( array( 'fields' => '' ), $atts ); if( !empty( $atts[ 'fields' ] ) || !empty( $content ) ) { $raw_form_str = cpappb_cleanJSON( $result->form_structure ); $form_data = json_decode( $raw_form_str ); if( is_null( $form_data ) ) { $json = new JSON; $form_data = $json->unserialize( $raw_form_str ); } } if( empty( $form_data ) ) { return "

" . preg_replace( "/\n+/", "
", $result->data ) . "

"; } else { $fields = array(); foreach($form_data[0] as $item) { $fields[$item->name] = $item; } $fields[ 'ipaddr' ] = $result->ipaddr; $result->data = unserialize( $result->data ); $str = ''; $atts[ 'fields' ] = explode( ",", str_replace( " ", "", $atts[ 'fields' ] ) ); foreach( $atts[ 'fields' ] as $field ) { if( isset( $fields[ $field ] ) ) { if( isset( $result->data[ $field ] ) ) { if( is_array( $result->data[ $field ] ) ) $result->data[ $field ] = implode( ',', $result->data[ $field ] ); $str .= "

{$fields[ $field ]->title} {$result->data[ $field ]}

"; } elseif( in_array( $fields[ $field ]->ftype, array( 'fSectionBreak' ) ) ) { $str .= "

".$fields[ $field ]->title."".(( !empty($fields[ $field ]->userhelp) ) ? "
".$fields[ $field ]->userhelp."" : '' )."

"; } } } if( $content != '' ) { $replaced_values = _cpappb_replace_vars( $fields, $result->data, $content, $result->data, 'html', $id ); $str .= $replaced_values[ 'message' ]; } return $str; } } } return ''; } function _cpappb_extract_tags( $message ) { $tags_arr = array(); if( preg_match_all( "/<%(info|fieldname\d+|fieldname\d+_label|fieldname\d+_shortlabel|fieldname\d+_value|fieldname\d+_url|fieldname\d+_urls|coupon|itemnumber|final_price|payment_option|ipaddress|currentdate_mmddyyyy|currentdate_ddmmyyyy)\b(?:(?!%>).)*%>/i", $message, $matches ) ) { $tag = array(); foreach( $matches[ 0 ] as $index => $value ) { $tag[ 'node' ] = $value; $tag[ 'tag' ] = strtolower( $matches[ 1 ][ $index ] ); $tag[ 'if_not_empty' ] = preg_match( "/if_not_empty/i", $value ); $tag[ 'before' ] = ( preg_match( "/before\s*=\s*\{\{((?:(?!\}\}).)*)\}\}/i", $value, $match ) ) ? $match[ 1 ] : ''; $tag[ 'after' ] = ( preg_match( "/after\s*=\s*\{\{((?:(?!\}\}).)*)\}\}/i", $value, $match ) ) ? $match[ 1 ] : ''; $tag[ 'separator' ] = ( preg_match( "/separator\s*=\s*\{\{((?:(?!\}\}).)*)\}\}/i", $value, $match ) ) ? $match[ 1 ] : ''; $baseTag = ( preg_match( "/(fieldname\d+)_(label|value|shortlabel)/i", $tag[ 'tag' ], $match ) ) ? $match[ 1 ] : $tag[ 'tag' ]; if( empty( $tags_arr[ $baseTag ] ) ) $tags_arr[ $baseTag ] = array(); $tags_arr[ $baseTag ][] = $tag; } } return $tags_arr; } function _cpappb_replace_vars( $fields, $params, $message, $buffer = '', $contentType = 'html', $itemnumber = '' ) { // Lambda functions $arrayReplacementFunction = create_function('&$tags, $tagName, $replacement, &$message', 'if(isset($tags[ $tagName ])){foreach( $tags[ $tagName ] as $tagData ){ $message = str_replace( $tagData[ "node" ], $tagData[ "before" ].$replacement.$tagData[ "after" ], $message );}unset( $tags[ $tagName ] );}'); $singleReplacementFunction = create_function('$tagData, $value, &$message', '$message = str_replace( $tagData[ "node" ], $tagData[ "before" ].$value.$tagData[ "after" ],$message );'); $message = str_replace( '< %', '<%', $message ); $attachments = array(); // Remove empty blocks while( preg_match( "/<%\s*fieldname(\d+)_block\s*%>/", $message, $matches ) ) { if( empty( $params[ 'fieldname'.$matches[ 1 ] ] ) ) { $from = strpos( $message, $matches[ 0 ] ); if( preg_match( "/<%\s*fieldname(".$matches[ 1 ].")_endblock\s*%>/", $message, $matches_end ) ) { $lenght = strpos( $message, $matches_end[ 0 ] ) + strlen( $matches_end[ 0 ] ) - $from; } else { $lenght = strlen( $matches[ 0 ] ); } $message = substr_replace( $message, '', $from, $lenght ); } else { $message = preg_replace( array( "/<%\s*fieldname".$matches[ 1 ]."_block\s*%>/", "/<%\s*fieldname".$matches[ 1 ]."_endblock\s*%>/"), "", $message ); } } $tags = _cpappb_extract_tags( $message ); if ( 'html' == $contentType ) { $message = str_replace( "\n", "", $message ); $buffer = str_replace( array('<', '>', '\"', "\'"), array('<', '>', '"', "'" ), $buffer ); } // Replace the INFO tags if( !empty( $tags[ 'info' ] ) ) { $buffer1 = $buffer; do{ $tmp = $buffer1; $buffer1 = preg_replace( array( "/^[^\n:]*:{1,2}\s*\n/", "/\n[^\n:]*:{1,2}\s*\n/", "/\n[^\n:]*:{1,2}\s*$/" ), array( "", "\n", "" ), $buffer1 ); }while( $buffer1 <> $tmp ); foreach( $tags[ 'info' ] as $tagData ) { $singleReplacementFunction( $tagData, ( ( $tagData[ 'if_not_empty' ] ) ? $buffer1 : $buffer ), $message ); } unset( $tags[ 'info' ] ); } foreach ($params as $item => $value) { $value_bk = $value; if( isset( $tags[ $item ] ) ) { $label = ( isset( $fields[ $item ] ) && property_exists( $fields[ $item ], 'title' ) ) ? $fields[ $item ]->title : ''; $shortlabel = ( isset( $fields[ $item ] ) && property_exists( $fields[ $item ], 'shortlabel' ) ) ? $fields[ $item ]->shortlabel : ''; $value = ( !empty( $value ) || is_numeric( $value ) && $value == 0 ) ? ( ( is_array( $value ) ) ? implode( ", ", $value ) : $value ) : ''; if ( 'html' == $contentType ) { $label = str_replace( array('<', '>', '\"', "\'"), array('<', '>', '"', "'" ), $label ); $shortlabel = str_replace( array('<', '>', '\"', "\'"), array('<', '>', '"', "'" ), $shortlabel ); $value = str_replace( array('<', '>', '\"', "\'"), array('<', '>', '"', "'" ), $value ); } foreach( $tags[ $item ] as $tagData ) { if( $tagData[ 'if_not_empty' ] == 0 || $value !== '' ) { switch( $tagData[ 'tag' ] ) { case $item: $singleReplacementFunction( $tagData, $label.$tagData[ 'separator' ].$value, $message ); break; case $item.'_label': $singleReplacementFunction( $tagData, $label, $message ); break; case $item.'_value': $singleReplacementFunction( $tagData, $value, $message ); break; case $item.'_shortlabel': $singleReplacementFunction( $tagData, $shortlabel, $message ); break; } } else { $message = str_replace( $tagData[ 'node' ], '', $message ); } } unset( $tags[ $item ] ); } if( preg_match( "/_link\b/i", $item ) ) { $attachments = array_merge( $attachments, $value_bk ); } } $arrayReplacementFunction( $tags, 'itemnumber', $itemnumber, $message ); $arrayReplacementFunction( $tags, 'currentdate_mmddyyyy', date("m/d/Y H:i:s"), $message ); $arrayReplacementFunction( $tags, 'currentdate_ddmmyyyy', date("d/m/Y H:i:s"), $message ); $arrayReplacementFunction( $tags, 'ipaddress', $fields[ 'ipaddr' ], $message ); // Replace coupons code if( isset( $_REQUEST[ 'couponcode' ] ) && isset( $tags[ 'couponcode' ] ) ) { $arrayReplacementFunction( $tags, 'couponcode', $_REQUEST[ 'couponcode' ], $message ); } foreach( $tags as $tagArr ) { foreach( $tagArr as $tagData ) { $message = str_replace( $tagData[ 'node' ], '', $message ); } } if ( 'html' == $contentType ) { $message = str_replace( "\n", "
", $message ); } $message = str_replace( '\\', '', stripslashes( stripcslashes( $message ) ) ); return array( 'message' => $message, 'attachments' => $attachments ); } ?>