';
}
public function settings_page() {
global $wpdb;
if ($this->get_param("cal") || $this->get_param("cal") == '0' || $this->get_param("pwizard") == '1')
{
$this->item = $this->get_param("cal");
if (isset($_GET["edit"]) && $_GET["edit"] == '1')
@include_once dirname( __FILE__ ) . '/cp_admin_int_edition.inc.php';
else 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 if ($this->get_param("addbk") == '1')
@include_once dirname( __FILE__ ) . '/cp-admin-int-add-booking.inc.php';
else if ($this->get_param("pwizard") == '1')
{
if ($this->get_param("cal"))
$this->item = $this->get_param("cal");
@include_once dirname( __FILE__ ) . '/cp-publish-wizzard.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 if ($this->get_param("page") == $this->menu_parameter.'_odemo')
{
echo("Redirecting to demo page...");
exit;
}
else if ($this->get_param("page") == $this->menu_parameter.'_support')
{
echo("Redirecting to support page...");
exit;
}
else if ($this->get_param("page") == $this->menu_parameter.'_settings')
{
@include_once dirname( __FILE__ ) . '/cp-settings.inc.php';
}
else if ($this->get_param("page") == $this->menu_parameter.'_addons')
{
@include_once dirname( __FILE__ ) . '/cp-addons.inc.php';
}
else
@include_once dirname( __FILE__ ) . '/cp-admin-int-list.inc.php';
}
function gutenberg_block() {
global $wpdb;
wp_enqueue_script( 'cpapphourbk_gutenberg_editor', plugins_url('/js/block.js', __FILE__));
wp_enqueue_style('cpapp-calendarstyle', plugins_url('css/cupertino/calendar.css', __FILE__));
wp_enqueue_style('cpapp-publicstyle', plugins_url('css/stylepublic.css', __FILE__));
wp_enqueue_style('cpapp-custompublicstyle', $this->get_site_url( false ).'?cp_cpappb_resources=css');
wp_deregister_script('query-stringify');
wp_register_script('query-stringify', plugins_url('/js/jQuery.stringify.js', __FILE__));
wp_deregister_script($this->prefix.'_validate_script');
wp_register_script($this->prefix.'_validate_script', plugins_url('/js/jquery.validate.js', __FILE__));
wp_enqueue_script( $this->prefix.'_builder_script',
$this->get_site_url( false ).'?cp_cpappb_resources=public',array("jquery","jquery-ui-core","jquery-ui-datepicker","jquery-ui-widget","jquery-ui-position","jquery-ui-tooltip","query-stringify",$this->prefix."_validate_script"), false, true );
$forms = array();
$rows = $wpdb->get_results("SELECT id,form_name FROM ".$wpdb->prefix.$this->table_items." ORDER BY form_name");
foreach ($rows as $item)
$forms[] = array (
'value' => $item->id,
'label' => $item->form_name,
);
wp_localize_script( 'cpapphourbk_gutenberg_editor', 'apphourbk_forms', array(
'forms' => $forms,
'siteUrl' => get_site_url()
) );
}
public function render_form_admin ($atts) {
$is_gutemberg_editor = defined( 'REST_REQUEST' ) && REST_REQUEST && ! empty( $_REQUEST['context'] ) && 'edit' === $_REQUEST['context'];
if (!$is_gutemberg_editor)
return $this->filter_content (array('id' => $atts["formId"]));
else if ($atts["formId"])
{
$this->setId($atts["formId"]);
return '';
}
else
return '';
}
function insert_adminScripts($hook) {
if ($this->get_param("page") == $this->menu_parameter && $this->get_param("addbk") != '1')
{
wp_deregister_script( 'bootstrap-datepicker-js' );
wp_register_script('bootstrap-datepicker-js', plugins_url('/js/nope.js', __FILE__));
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") );
if (isset($_GET["calendarview"]) && $_GET["calendarview"] == '1')
wp_enqueue_script( 'jquery-ui-dialog' );
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__));
wp_enqueue_style('cpapp-newadminstyle', plugins_url('/css/newadminlayout.css', __FILE__));
$calendar_language = $this->get_option('calendar_language','');
if ($calendar_language == '') $calendar_language = $this->autodetect_language();
if ($calendar_language != '')
wp_enqueue_script($this->prefix.'_language_file', plugins_url('js/languages/jquery.ui.datepicker-'.$calendar_language.'.js', __FILE__), array("jquery","jquery-ui-core","jquery-ui-sortable","jquery-ui-tabs","jquery-ui-droppable","jquery-ui-button","query-stringify","jquery-ui-datepicker"));
}
if( 'post.php' != $hook && 'post-new.php' != $hook )
return;
// space to include some script in the post or page areas if needed
}
function autodetect_language() {
$basename = '/js/languages/jquery.ui.datepicker-';
$options = array (get_bloginfo('language'),
strtolower(get_bloginfo('language')),
substr(strtolower(get_bloginfo('language')),0,2)."-".substr(strtoupper(get_bloginfo('language')),strlen(strtoupper(get_bloginfo('language')))-2,2),
substr(strtolower(get_bloginfo('language')),0,2),
substr(strtolower(get_bloginfo('language')),strlen(strtolower(get_bloginfo('language')))-2,2)
);
foreach ($options as $option)
{
if (file_exists(dirname( __FILE__ ).$basename.$option.'.js'))
return $option;
$option = str_replace ("-","_", $option);
if (file_exists(dirname( __FILE__ ).$basename.$option.'.js'))
return $option;
}
return '';
}
function data_management_loaded() {
global $wpdb;
$action = $this->get_param('cp_apphourbooking_do_action_loaded');
if (!$action) return; // go out if the call isn't for this one
if ($this->get_param('cpapphourbk_id')) $this->item = $this->get_param('cpapphourbk_id');
if ($action == "wizard")
{
$shortcode = '[CP_APP_HOUR_BOOKING id="'.$this->item .'"]';
$this->postURL = $this->publish_on(@$_POST["whereto"], @$_POST["publishpage"], @$_POST["publishpost"], $shortcode, @$_POST["posttitle"]);
return;
}
// ...
echo 'Some unexpected error happened. If you see this error contact the support service at https://apphourbooking.dwbooster.com/contact-us';
exit();
}
private function publish_on($whereto, $publishpage = '', $publishpost = '', $content = '', $posttitle = 'Booking Form')
{
global $wpdb;
$id = '';
if ($whereto == '0' || $whereto =='1') // new page
{
$my_post = array(
'post_title' => $posttitle,
'post_type' => ($whereto == '0'?'page':'post'),
'post_content' => 'This is a preview page, remember to publish it if needed. You can edit the full calendar and form settings into the admin settings page.';print_r($data);
function _js2PhpTime($jsdate){
if(preg_match('@(\d+)/(\d+)/(\d+)\s+(\d+):(\d+)((am|pm)*)@', $jsdate, $matches)==1){
if ($matches[6]=="pm")
if ($matches[4]<12)
$matches[4] += 12;
$ret = mktime($matches[4], $matches[5], 0, $matches[1], $matches[2], $matches[3]);
}else if(preg_match('@(\d+)/(\d+)/(\d+)@', $jsdate, $matches)==1){
$ret = mktime(0, 0, 0, $matches[1], $matches[2], $matches[3]);
}
return $ret;
}
function _php2MySqlTime($phpDate){
return date("Y-m-d H:i:s", $phpDate);
}
function _php2JsTime($phpDate){
return @date("m/d/Y H:i", $phpDate);
}
function _mySql2PhpTime($sqlDate){
$a1 = explode (" ",$sqlDate);
$a2 = explode ("-",$a1[0]);
$a3 = explode (":",$a1[1]);
$t = mktime(@$a3[0],@$a3[1],@$a3[2],@$a2[1],@$a2[2],@$a2[0]);
return $t;
}
usort($data, array($this, 'wptsbk_custom_sort') );
$ret = array();
$ret['events'] = array();
$ret["issort"] = true;
$ret['error'] = null;
$d1 = _js2PhpTime($_POST["startdate"]);
$d2 = _js2PhpTime($_POST["enddate"]);
$d1 = mktime(0, 0, 0, date("m", $d1), date("d", $d1), date("Y", $d1));
$d2 = mktime(0, 0, 0, date("m", $d2), date("d", $d2), date("Y", $d2))+24*60*60-1;
$ret["start"] = _php2JsTime($d1);
$ret["end"] = _php2JsTime($d2);
foreach ($data as $item)
{
$datetime = $item["d"]." ".$item["h1"].":".($item["m1"]<10?"0":"").$item["m1"];
$datetime2 = $item["d"]." ".$item["h2"].":".($item["m2"]<10?"0":"").$item["m2"];
$ev = array(
mt_rand(1,9999999), //$row["id"],
$item["e"],
_php2JsTime(_mySql2PhpTime($datetime)),
_php2JsTime(_mySql2PhpTime($datetime2)),
0, // is all day event?
0, // more than one day event
'',//Recurring event rule,
'#3CF',
0,//editable
'',
'',//$attends
$item["info"],
'',
1
);
$ret['events'][] = $ev;
}
echo json_encode($ret);
exit;
}
public function wptsbk_custom_sort($a,$b) {
return ($a['d']>$b['d']) ||
($a['d']==$b['d'] && $a['h1']>$b['h1']) ||
($a['d']==$b['d'] && $a['h1']==$b['h1'] && $a['m1']>$b['m1']);
}
function data_management() {
global $wpdb;
load_plugin_textdomain( 'appointment-hour-booking', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
$ao_options = get_option('autoptimize_js_exclude',"seal.js, js/jquery/jquery.js");
if (!strpos($ao_options,'stringify.js'))
update_option('autoptimize_js_exclude',"jQuery.stringify.js,jquery.validate.js,".$ao_options);
if(!empty($_REQUEST['cp_app_action']))
{
$formid = $_REQUEST['formid'];
$field = @$_REQUEST['formfield'];
$myrows = $wpdb->get_results( $wpdb->prepare("SELECT data,notifyto,posted_data FROM ".$wpdb->prefix.$this->table_messages." where formid=%d", $formid) );
$tmp2 = array();
for ($i=0; $i < count($myrows); $i++)
{
$data = unserialize($myrows[$i]->posted_data);
for($k=0; $k$data["apps"][$k]["date"] ,"h1"=>intval(substr($slot,0,2)),"m1"=>intval(substr($slot,3,2)),"h2"=>intval(substr($slot,6,2)),"m2"=>intval(substr($slot,9,2)),"serviceindex"=>intval(@$data["apps"][$k]["serviceindex"]),"quantity"=>$quantity);
if ($_REQUEST['cp_app_action'] == 'mv')
{
$tmp2[count($tmp2)-1]["info"] = $myrows[$i]->data;
$tmp2[count($tmp2)-1]["e"] = $myrows[$i]->notifyto;
}
}
}
if ($_REQUEST['cp_app_action'] == 'mv' && is_admin())
{
$this->print_multiview_format($tmp2);
}
else
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 if( $_REQUEST[ 'cp_cpappb_resources' ] == 'css' )
{
header("Content-type: text/css");
$custom_styles = base64_decode(get_option('CP_AHB_CSS', ''));
echo $custom_styles;
}
else if( $_REQUEST[ 'cp_cpappb_resources' ] == 'customjs' )
{
header("Content-type: application/javascript");
$custom_scripts = base64_decode(get_option('CP_AHB_JS', ''));
echo $custom_scripts;
}
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.'_csv2') && is_admin() )
{
$this->export_csv_schedule(array());
return;
}
if ( $this->get_param($this->prefix.'_post_options') && is_admin() )
{
$this->save_options();
return;
}
if ( 'POST' == $_SERVER['REQUEST_METHOD'] && isset( $_POST['CP_AHB_post_edition'] ) && is_admin() )
{
$this->save_edition();
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) ||
(
(!is_admin() && $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();
$apps = $this->extract_appointments($form_data[0], $_POST, $sequence);
$price = $this->extract_total_price ($apps);
$apptext = $this->get_appointments_text ($apps);
$excluded_items = 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]);
}
}
}
else
{
$fields[$item->name] = $item->title;
$_POST[$item->name.$sequence] = $apptext;
$excluded_items[] = $item->name;
}
// grab posted data
//---------------------------
$buffer = __('Appointments','appointment-hour-booking').":\n".$apptext."\n";
$params = array();
$params["final_price"] = $price;
$params["apps"] = $apps;
foreach ($apps as $appitem)
{
$params["app_service_".$appitem["id"]] = $appitem["service"];
$params["app_status_".$appitem["id"]] = $appitem["cancelled"];
$params["app_duration_".$appitem["id"]] = $appitem["duration"];
$params["app_price_".$appitem["id"]] = $appitem["price"];
$params["app_date_".$appitem["id"]] = $this->format_date($appitem["date"]);
$params["app_slot_".$appitem["id"]] = $appitem["slot"];
$slotpieces = explode("/",$appitem["slot"]);
$params["app_starttime_".$appitem["id"]] = $this->format12hours(trim(@$slotpieces[0]), @$appitem["military"] == 0);
$params["app_endtime_".$appitem["id"]] = $this->format12hours(trim(@$slotpieces[1]), @$appitem["military"] == 0);
$params["app_quantity_".$appitem["id"]] = $appitem["quant"];
}
$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
//---------------------------
$current_user = wp_get_current_user();
$this->add_field_verify($wpdb->prefix.$this->table_messages, "whoadded");
$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,
'whoadded' => "".$current_user->ID
) );
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_ref_array( 'cpappb_process_data', array(&$params) );
$wpdb->update( $wpdb->prefix.$this->table_messages,
array( 'posted_data' => serialize($params) ),
array ( 'id' => $item_number),
array( '%s' ),
array( '%d' )
);
$this->ready_to_go_reservation($item_number, "", $params);
$_SESSION[ 'cp_cff_form_data' ] = $item_number;
if (is_admin())
return;
/**
* 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->replace_tags($this->get_option('fp_return_page', CP_APPBOOK_DEFAULT_fp_return_page), $params, true));
exit();
}
}
public function replace_tags ($message, $params, $urlencode = false)
{
foreach ($params as $item => $value)
{
if ($urlencode)
$value = urlencode( (is_array($value)?'':$value) );
$message = @str_replace('<'.'%'.$item.'%'.'>',(is_array($value)?(implode(", ",$value)):($value)),$message);
$message = @str_replace('%'.$item.'%',(is_array($value)?(implode(", ",$value)):($value)),$message);
}
for ($i=0;$i<500;$i++)
{
$message = str_replace('<'.'%fieldname'.$i.'%'.'>',"",$message);
$message = str_replace('%fieldname'.$i.'%',"",$message);
}
return $message;
}
public function extract_appointments($form,$data,$sequence)
{
$apps = array();
$subid = 0;
foreach($form as $field)
if ($field->ftype == 'fapp' && @$data[$field->name.$sequence] != '')
{
$apps_text = explode(';',$data[$field->name.$sequence]);
$fieldtotalcost = 0;
$fieldpostedcost = floatval(@$data["tcost".$field->name.$sequence]);
foreach($apps_text as $app_item_text)
{
$item_split = explode(' ',$app_item_text);
$subid++;
$fieldtotalcost += $field->services[ $item_split[2] ]->price;
$apps[] = array (
'id' => $subid,
'cancelled' => $this->get_option('defaultstatus', ''),
'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],
'military' => @$field->militaryTime,
'field' => $field->name,
'quant' => $item_split[3]
);
}
if ($fieldtotalcost < $fieldpostedcost) // this is to support javascript price calculations
$apps[count($apps)-1]["price"] = $fieldpostedcost;
}
return $apps;
}
function extract_total_price($apps)
{
$price = 0;
foreach($apps as $app)
$price += floatval($app["price"]);
return number_format($price,2,'.','');
}
function get_appointments_text($apps)
{
$option = $this->get_option('display_emails_endtime', '');
$text = '';
foreach($apps as $app)
{
$slot = $app["slot"];
if ($option != '')
$slot = substr ($slot, 0, strpos($slot,"/"));
$slot = str_replace("/","-",$app["slot"]);
if (@$app["military"] == 0)
{
$times = explode("-",$slot);
$times[0] = explode(":",$times[0]);
$times[1] = explode(":",$times[1]);
$slot = ($times[0][0]>12?$times[0][0]-12:$times[0][0]).":".$times[0][1].' '.($times[0][0]>=12?'PM':'AM') ." - ".
($times[1][0]>12?$times[1][0]-12:$times[1][0]).":".$times[1][1].' '.($times[1][0]>=12?'PM':'AM');
}
$text .= " - ".$this->format_date($app["date"])." ".$slot.($app["quant"]>1?' ('.$app["quant"].')':'')." (".$app["service"].")\n";
}
return $text;
}
function format12hours($time, $is_non_military)
{
if ($is_non_military)
{
$times = explode(":",$time);
$time = ($times[0]>12?$times[0]-12:$times[0]).":".$times[1].' '.($times[0]>=12?'PM':'AM');
}
return $time;
}
function format_date($date)
{
$format = $this->get_option('date_format', 'mm/dd/yy');
if (!$format) $format = 'mm/dd/yy';
$format = str_replace('mm', 'm', $format);
$format = str_replace('dd', 'd', $format);
$format = str_replace('yy', 'Y', $format);
$format = str_replace('DD', 'l', $format);
$format = str_replace('MM', 'F', $format);
return date($format, strtotime($date));
}
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();
$message = str_replace('<'.'%', '%', $this->get_option('fp_message', CP_APPBOOK_DEFAULT_fp_message));
$message = str_replace('%'.'>', '%', $message);
$subject = str_replace('<'.'%', '%', $this->get_option('fp_subject', CP_APPBOOK_DEFAULT_fp_subject));
$subject = str_replace('%'.'>', '%', $subject);
if ('html' == $this->get_option('fp_emailformat', CP_APPBOOK_DEFAULT_email_format))
$message = str_replace('%INFO%',str_replace("\n","
",str_replace('<','<',$buffer)),$message);
else
$message = str_replace('%INFO%',$buffer,$message);
$subject = $this->get_option('fp_subject', CP_APPBOOK_DEFAULT_fp_subject);
/**
* Attach or modify attached files,
* Example for adding ical or PDF attachments
*/
$attachments = apply_filters( 'cpappb_email_attachments', $attachments, $params, $this->item);
$params["apps"] = $this->get_appointments_text($params["apps"]);
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);
}
// if is_admin and not required emails end function here
if (is_admin() && !isset($_POST["sendemails_admin"]))
return;
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))
{
$message = str_replace('<'.'%', '%', $this->get_option('cu_message', CP_APPBOOK_DEFAULT_cu_message));
$message = str_replace('%'.'>', '%', $message);
$subject = str_replace('<'.'%', '%', $this->get_option('cu_subject', CP_APPBOOK_DEFAULT_cu_subject));
$subject = str_replace('%'.'>', '%', $subject);
if ('html' == $this->get_option('cu_emailformat', CP_APPBOOK_DEFAULT_email_format))
$message = str_replace('%INFO%',str_replace("\n","
",str_replace('<','<',$buffer_A)).' ',$message);
else
$message = str_replace('%INFO%',$buffer_A,$message);
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(), $attachments);
if ($_POST[$to] != $payer_email && $payer_email != '')
wp_mail(trim($payer_email), $subject, $message,
"From: ".$from."\r\n".
$content_type.
"X-Mailer: PHP/" . phpversion(), $attachments);
}
}
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_edition()
{
global $wpdb;
foreach ($_POST as $item => $value)
if (!is_array($value))
$_POST[$item] = stripcslashes($value);
if (isset($_POST["gotab"]) && @$_POST["gotab"] == '')
{
update_option( 'cp_cpappb_rep_enable', $_POST["cp_cpappb_rep_enable"]);
update_option( 'cp_cpappb_rep_days', $_POST["cp_cpappb_rep_days"]);
update_option( 'cp_cpappb_rep_hour', $_POST["cp_cpappb_rep_hour"]);
update_option( 'cp_cpappb_rep_emails', $_POST["cp_cpappb_rep_emails"]);
update_option( 'cp_cpappb_fp_from_email', $_POST["cp_cpappb_fp_from_email"]);
update_option( 'cp_cpappb_rep_subject', $_POST["cp_cpappb_rep_subject"]);
update_option( 'cp_cpappb_rep_emailformat', $_POST["cp_cpappb_rep_emailformat"]);
update_option( 'cp_cpappb_rep_message', $_POST["cp_cpappb_rep_message"]);
}
else if (@$_POST["gotab"] == 'csvarea')
{
update_option( 'cp_cpappb_bocsvexclude', $_POST["bocsvexclude"]);
update_option( 'cp_cpappb_schcsvexclude', $_POST["schcsvexclude"]);
}
else if (@$_POST["gotab"] == 'fixarea')
{
update_option( 'CP_APPB_LOAD_SCRIPTS', ($_POST["ccscriptload"]=="1"?"0":"1") );
if ($_POST["cccharsets"] != '')
{
$target_charset = esc_sql($_POST["cccharsets"]);
$tables = array( $wpdb->prefix.$this->table_messages, $wpdb->prefix.$this->table_items );
foreach ($tables as $tab)
{
$myrows = $wpdb->get_results( "DESCRIBE {$tab}" );
foreach ($myrows as $item)
{
$name = $item->Field;
$type = $item->Type;
if (preg_match("/^varchar\((\d+)\)$/i", $type, $mat) || !strcasecmp($type, "CHAR") || !strcasecmp($type, "TEXT") || !strcasecmp($type, "MEDIUMTEXT"))
{
$wpdb->query("ALTER TABLE {$tab} CHANGE {$name} {$name} {$type} COLLATE {$target_charset}");
}
}
}
}
}
else
{
if (substr_count(@$_POST['editionarea'],"\\\""))
$_POST["editionarea"] = stripcslashes(@$_POST["editionarea"]);
if (@$_POST["cfwpp_edit"] == 'js')
update_option('CP_AHB_JS', base64_encode(@$_POST["editionarea"]));
else if (@$_POST["cfwpp_edit"] == 'css')
update_option('CP_AHB_CSS', base64_encode(@$_POST["editionarea"]));
}
}
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, 'calendar_language');
$this->add_field_verify($wpdb->prefix.$this->table_items, 'date_format');
$this->add_field_verify($wpdb->prefix.$this->table_items, 'vs_text_maxapp');
$this->add_field_verify($wpdb->prefix.$this->table_items, 'defaultstatus', "VARCHAR(250) DEFAULT '' NOT NULL");;
$this->add_field_verify($wpdb->prefix.$this->table_items, 'defaultpaidstatus', "VARCHAR(250) DEFAULT '' NOT NULL");
$this->add_field_verify($wpdb->prefix.$this->table_items, 'cp_user_access_settings', "VARCHAR(10) DEFAULT '' NOT NULL");
$this->add_field_verify($wpdb->prefix.$this->table_items, 'display_emails_endtime', "VARCHAR(10) DEFAULT '' NOT NULL");
while ((substr_count($_POST['form_structure'],"\\") > 30) || substr_count($_POST['form_structure'],"\\\"title\\\":"))
foreach ($_POST as $item => $value)
if (!is_array($value))
$_POST[$item] = stripcslashes($value);
$data = array(
'form_structure' => $_POST['form_structure'],
'vs_text_maxapp' => $_POST['vs_text_maxapp'],
'calendar_language' => $_POST['calendar_language'],
'date_format' => $_POST['date_format'],
'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'],
'defaultstatus' => $_POST['defaultstatus'],
'defaultpaidstatus' => $_POST['defaultpaidstatus'],
'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"]),
'cp_user_access_settings' => $_POST['cp_user_access_settings'],
'display_emails_endtime' => $_POST['display_emails_endtime'],
'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 ));
if (isset($_POST["savepublish"]))
{
echo '';
} else if (isset($_POST["savereturn"]))
{
echo '';
}
}
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");
$fields_exclude = explode(",",trim(get_option('cp_cpappb_bocsvexclude',"")));
for($j=0; $j" . preg_replace( "/\n+/", "
", $result->data ) . "
{$fields[ $field ]->title} {$result->data[ $field ]}
"; } elseif( in_array( $fields[ $field ]->ftype, array( 'fSectionBreak' ) ) ) { $str .= "".$fields[ $field ]->title."".(( !empty($fields[ $field ]->userhelp) ) ? "