prefix) ===false) $tablename = $wpdb->prefix . $tablename ; $sql_check_table = " SELECT COUNT(*) AS count FROM information_schema.tables WHERE table_schema = '". DB_NAME ."' AND table_name = '" . $tablename . "'"; $res = $wpdb->get_results($sql_check_table); return $res[0]->count; } } // Show Ajax message at the top of page ////////////////////////////////////////////////////////////////////////////////////////////////////// if (!function_exists ('show_top_message_wpdev')) { function show_top_message_wpdev($mess, $show_time = 3000, $is_hide=false) { ?> prefix ."wpdev_crm_orders as ordr " ; //$sql .= "INNER JOIN ".$wpdb->prefix ."wpdev_crm_customers as custmr " ; //$sql .= "ON ordr.customer_id = custmr.customer_id " ; $sql .= " " . $where ." "; $sql .= " ORDER BY ordr.order_id "; //debuge($sql);die; $result_orders = $wpdb->get_results( $sql ); $exist_bookings_id = ''; foreach ($result_orders as $in_id) { $exist_bookings_id .= $in_id->internal_id .', '; } //debuge($exist_bookings_id); if ($exist_bookings_id != '') { $exist_bookings_id = substr($exist_bookings_id,0,-2); $exist_bookings_id = " WHERE bk.booking_id NOT IN (". $exist_bookings_id .")"; } //debuge($exist_bookings_id);die; //Set here order by some field $sql = "SELECT * FROM ".$wpdb->prefix ."booking as bk INNER JOIN ".$wpdb->prefix ."bookingdates as dt ON bk.booking_id = dt.booking_id " . $exist_bookings_id . " ORDER BY bk.booking_id ASC, dt.booking_date ASC "; $result = $wpdb->get_results( $sql ); if (! $is_hide) show_top_message_wpdev( __('Processing...','wpdev-crm') , 3000, false ); //adebug(count($result), $result); $final_structure = array(); $previos_id = ''; $previos_date = ''; $fsi = -1; // Loop all bookings for getting final strucutre with dates. foreach ($result as $single_booking) { if ($previos_id == $single_booking->booking_id ) { // if ID the same so we are getting only date $final_structure[$fsi]['booking_date'] .= ', ' .$single_booking->booking_date; $previos_date = $single_booking->booking_date; } else { if ( ($fsi!==-1) && ($previos_date!=='') ) { // Get end time from previos record $end_time = explode(' ', $previos_date); $end_time= explode(':', $end_time[1]); $final_structure[$fsi]['end_time'] = $end_time; } $previos_date = ''; // New booking $fsi++; $previos_id = $single_booking->booking_id; $final_structure[$fsi] = array(); $final_structure[$fsi]['booking_id'] = $single_booking->booking_id; $final_structure[$fsi]['form'] = $single_booking->form; $final_structure[$fsi]['booking_type'] = $single_booking->booking_type; $final_structure[$fsi]['remark'] = $single_booking->remark; if (isset($single_booking->pay_status)) $final_structure[$fsi]['pay_status'] = $single_booking->pay_status; else $final_structure[$fsi]['pay_status'] = ''; if (isset($single_booking->cost)) $final_structure[$fsi]['cost'] = $single_booking->cost; else $final_structure[$fsi]['cost'] = ''; $final_structure[$fsi]['booking_date'] = $single_booking->booking_date; $final_structure[$fsi]['approved'] = $single_booking->approved; $start_time = explode(' ', $single_booking->booking_date); $start_time= explode(':', $start_time[1]); $final_structure[$fsi]['start_time'] = $start_time; } } if ( ($fsi!==-1) && ($previos_date!=='') ) { // Get end time for the last booking $end_time = explode(' ', $previos_date); $end_time= explode(':', $end_time[1]); $final_structure[$fsi]['end_time'] = $end_time; } $togather_cont= count($final_structure); if (! $is_hide) show_top_message_wpdev( sprintf(__('Found %s new bookings...','wpdev-crm'), $togather_cont ) , 3000, true ); //adebug($final_structure); // Loop all bookings $my_cnt = 0; $alternative_color = ''; foreach ($final_structure as $single_booking) { $my_cnt++; if ( $alternative_color == '') {$alternative_color = ' class="alternative_color" ';} else { $alternative_color = '';} // Function for adding new orders from booking $booking_id = $single_booking['booking_id'] ; $booking_type = $single_booking['booking_type']; $booking_days = $single_booking['booking_date'] ; $times_array = array( $single_booking['start_time'], $single_booking['end_time'] ); $booking_form = $single_booking['form'] ; $booking_cost = $single_booking['cost'] ; $added_booking = add_booking_order_single( $booking_id, $booking_type, $booking_days, $times_array , $booking_form , $booking_cost ); //$added_booking['date_of_order'] = date('Y-m-d H:i:s', mktime(date('H'), date('i'), date('s'), date('m'), date('d'), '1970') );// set old date and not import date for not showing it, during import if (! $is_hide) show_top_message_wpdev( sprintf(__('Added %s bookings...','wpdev-crm'), $my_cnt . '/'. $togather_cont ) , 3000, true ); if (! $is_hide) if ($added_booking !== false) { ?>

prefix . "wpdev_crm_customers WHERE email = '".$form_content_array['_all_']['email' . $booking_type ]."'"; $my_result = $wpdb->get_results( $my_sql ); if (count($my_result)>0) { //Check if this customer already exist using EMAIL as uniq field $customer_id = (int) $my_result[0]->id; // Customer is exist here is ID } else { // Not Exist // Insert customer $customer_details_info = array(); // Get customer fields if they exist if ( isset($form_content_array['_all_']['name' . $booking_type ]) ) $customer_details_info[] = $form_content_array['_all_']['name' . $booking_type ]; else $customer_details_info[] = ''; if ( isset($form_content_array['_all_']['secondname' . $booking_type ]) ) $customer_details_info[] = $form_content_array['_all_']['secondname' . $booking_type ]; else $customer_details_info[] = ''; if ( isset($form_content_array['_all_']['email' . $booking_type ]) ) $customer_details_info[] = $form_content_array['_all_']['email' . $booking_type ]; else $customer_details_info[] = ''; if ( isset($form_content_array['_all_']['phone' . $booking_type ]) ) $customer_details_info[] = $form_content_array['_all_']['phone' . $booking_type ]; else $customer_details_info[] = ''; if ( isset($form_content_array['_all_']['address' . $booking_type ]) ) $customer_details_info[] = $form_content_array['_all_']['address' . $booking_type ]; else $customer_details_info[] = ''; if ( isset($form_content_array['_all_']['city' . $booking_type ]) ) $customer_details_info[] = $form_content_array['_all_']['city' . $booking_type ]; else $customer_details_info[] = ''; if ( isset($form_content_array['_all_']['country' . $booking_type ]) ) $customer_details_info[] = $form_content_array['_all_']['country' . $booking_type ]; else $customer_details_info[] = ''; $customer_details_info[0] = str_replace("'", '', $customer_details_info[0]); $customer_details_info[1] = str_replace("'", '', $customer_details_info[1]); $customer_details_info[2] = str_replace("'", '', $customer_details_info[2]); $customer_details_info[3] = str_replace("'", '', $customer_details_info[3]); $customer_details_info[4] = str_replace("'", '', $customer_details_info[4]); $customer_details_info[5] = str_replace("'", '', $customer_details_info[5]); $customer_details_info[6] = str_replace("'", '', $customer_details_info[6]); $booking_form = str_replace("'", '', $booking_form ); $insert = "('".$customer_details_info[0]."', '".$customer_details_info[1]."', '".$customer_details_info[2]."', '".$customer_details_info[3]."', '".$customer_details_info[4]."', '".$customer_details_info[5]."', '".$customer_details_info[6]."', '".$booking_form."', NOW() )"; if(1) if ( !empty($insert) ) if ( false === $wpdb->query("INSERT INTO ".$wpdb->prefix . "wpdev_crm_customers (name, second_name, email, phone, adress, city, country, info, customer_date) VALUES " . $insert) ) { ?> insert_id; //Get ID of reservation } ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Insert O R D E R /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //$my_order_date = 'NOW()'; if ( $_POST['ajax_action_crm'] == 'IMPORT_BOOKINGS' ) { // Its mean import, so we set old YEAR $my_order_date = date('Y-m-d H:i:s', mktime(date('H'), date('i'), date('s'), date('m'), date('d'), '1970') ); } else { $my_order_date = date('Y-m-d H:i:s', mktime(date('H'), date('i'), date('s'), date('m'), date('d'), date('Y')) ); } $booking_form = str_replace("'", '', $booking_form ); $insert = "('". $booking_form ."', '". $customer_id ."', '". serialize( array( 'booking'=>$booking_type ) ) ."', '". $summ ."', '".$my_order_date."', '". $booking_id ."', '".$my_dates4DB."', '".$booking_type."', '".$start_single_date."', '".$fin_single_date."' )"; if(1) if ( !empty($insert) ) if ( false === $wpdb->query("INSERT INTO ".$wpdb->prefix . "wpdev_crm_orders (order_info, customer_id, type, cost, order_date, internal_id, internal_filters, internal_filters1, internal_filters2, internal_filters3) VALUES " . $insert) ) { ?> insert_id; ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //return; if ( function_exists ('get_form_content')) { $content_fomr_show = get_form_content($booking_form, $booking_type); /* $content_fomr_show = str_replace('
', '', $content_fomr_show['content']); $content_fomr_show = str_replace('
', '', $content_fomr_show); $content_fomr_show = str_replace('"', '', $content_fomr_show); $content_fomr_show = str_replace("'", '', $content_fomr_show); $content_fomr_show = str_replace('/', '', $content_fomr_show); $content_fomr_show = str_replace('/n/', '', $content_fomr_show);/**/ // Remove all shortcodes, which is not replaced early. $content_fomr_show = $content_fomr_show['content']; $content_fomr_show = preg_replace ('/[\s]{0,}\[[a-zA-Z0-9.,-_]{0,}\][\s]{0,}/', '', $content_fomr_show); //$content_fomr_show = preg_replace ('/[\s]*<[\s]*br[\s]*[\/]*[\s]*>[\s]*/', '', $content_fomr_show); $content_fomr_show = preg_replace ('//', '', $content_fomr_show); $content_fomr_show = preg_replace ('/[\s]*\n[\s]*/', ' ', $content_fomr_show); // Remove all hided line breaks \n //debuge( htmlentities($content_fomr_show) ); if ( function_exists ('get_booking_title')) $title = get_booking_title( $booking_type ); else $title = 'Standard'; return (array( 'id'=> $order_id, 'info' => $content_fomr_show, 'customer' => $customer_details_info[0]." " .$customer_details_info[1], 'type' => $title , 'date_of_order' => date('Y-m-d H:i:s'), 'cost' => $summ ) ); } else { return false; } } } ?>