| 1 |
<?php |
| 2 |
|
| 3 |
if (!class_exists('wpdev_booking_module_for_orders')) { |
| 4 |
class wpdev_booking_module_for_orders { |
| 5 |
|
| 6 |
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
| 7 |
// Constructor //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
| 8 |
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
| 9 |
function wpdev_booking_module_for_orders() { |
| 10 |
add_action('wpdev_new_booking', array(&$this, 'add_booking_order'),1,5); // Save order from booking |
| 11 |
} |
| 12 |
|
| 13 |
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
| 14 |
// A C T I O N S |
| 15 |
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
| 16 |
// Add order only for B O O K I N G s // Original params: $booking_id, $bktype, str_replace('|',',',$dates), array($start_time, $end_time ) ,$sdform ); |
| 17 |
function add_booking_order( $booking_id, $booking_type, $booking_days, $times_array , $booking_form ){ |
| 18 |
add_booking_order_single( $booking_id, $booking_type, $booking_days, $times_array , $booking_form ); |
| 19 |
} |
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
| 24 |
// F U N C T I O N S |
| 25 |
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
| 26 |
function get_booking_short_days( $long_days ) { |
| 27 |
|
| 28 |
$last_day = ''; |
| 29 |
$last_show_day = ''; |
| 30 |
$short_days = array(); |
| 31 |
|
| 32 |
foreach ($long_days as $dte) { |
| 33 |
|
| 34 |
if (empty($last_day)) { // First date |
| 35 |
$short_days[]= $dte; |
| 36 |
$last_show_day = $dte; |
| 37 |
} else { // All other days |
| 38 |
if ( apply_filters('wpdev_bk_is_next_day', $dte ,$last_day) ){ |
| 39 |
if ($last_show_day != '-') $short_days[]= '-'; |
| 40 |
$last_show_day = '-'; |
| 41 |
} else { |
| 42 |
if ($last_show_day !=$last_day) $short_days[]= $last_day; |
| 43 |
$short_days[]= ','; |
| 44 |
$short_days[]= $dte; |
| 45 |
$last_show_day = $dte; |
| 46 |
} |
| 47 |
} |
| 48 |
$last_day = $dte; |
| 49 |
} |
| 50 |
if($last_show_day != $dte) $short_days[]= $dte; |
| 51 |
|
| 52 |
$short_days_string = ''; |
| 53 |
foreach ($short_days as $day_string) { $short_days_string .= $day_string . ' '; } |
| 54 |
|
| 55 |
return array($short_days, $short_days_string); |
| 56 |
} |
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
} |
| 61 |
} |
| 62 |
|
| 63 |
|
| 64 |
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
| 65 |
// Support functions |
| 66 |
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
| 67 |
|
| 68 |
// Check if table exist ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
| 69 |
if (!function_exists ('is_wpdev_table_exists')) { |
| 70 |
function is_wpdev_table_exists( $tablename ) { |
| 71 |
global $wpdb; |
| 72 |
if (strpos($tablename, $wpdb->prefix) ===false) $tablename = $wpdb->prefix . $tablename ; |
| 73 |
$sql_check_table = " |
| 74 |
SELECT COUNT(*) AS count |
| 75 |
FROM information_schema.tables |
| 76 |
WHERE table_schema = '". DB_NAME ."' |
| 77 |
AND table_name = '" . $tablename . "'"; |
| 78 |
|
| 79 |
$res = $wpdb->get_results($sql_check_table); |
| 80 |
return $res[0]->count; |
| 81 |
|
| 82 |
} |
| 83 |
} |
| 84 |
|
| 85 |
// Show Ajax message at the top of page ////////////////////////////////////////////////////////////////////////////////////////////////////// |
| 86 |
if (!function_exists ('show_top_message_wpdev')) { |
| 87 |
function show_top_message_wpdev($mess, $show_time = 3000, $is_hide=false) { |
| 88 |
?> <script type="text/javascript"> |
| 89 |
document.getElementById('ajax_working').innerHTML = '<div class="info_message ajax_message" id="ajax_message">\n\ |
| 90 |
<div style="text-align:center;">'+'<?php echo $mess; ?>'+'</div> \n\ |
| 91 |
<div style="float:left;width:80px;margin-top:-3px;">\n\ |
| 92 |
</div>\n\ |
| 93 |
</div>'; |
| 94 |
jWPDev('.info_message').animate({opacity: 1},<?php echo $show_time; ?>); |
| 95 |
<?php if($is_hide) { ?> jWPDev('.info_message').fadeOut(2000); <?php } ?> |
| 96 |
|
| 97 |
</script> <?php |
| 98 |
} |
| 99 |
} |
| 100 |
|
| 101 |
|
| 102 |
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
| 103 |
// AJAX |
| 104 |
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
| 105 |
|
| 106 |
// Import all exist bookings |
| 107 |
function wpdev_import_booking_crm_ajax( $is_hide = false ){ global $wpdb; |
| 108 |
if (! $is_hide) { |
| 109 |
?> <script type="text/javascript"> |
| 110 |
jQuery('.this_td_empty').fadeOut(500); |
| 111 |
var $my_row = ''; |
| 112 |
</script> |
| 113 |
<?php |
| 114 |
} |
| 115 |
|
| 116 |
$fin_message = __('Done','wpdev-crm'); |
| 117 |
// Import here |
| 118 |
if ( is_wpdev_table_exists('booking')) { |
| 119 |
|
| 120 |
$where = ''; |
| 121 |
$sql = "SELECT ordr.customer_id, ordr.internal_id |
| 122 |
FROM ".$wpdb->prefix ."wpdev_crm_orders as ordr " ; |
| 123 |
//$sql .= "INNER JOIN ".$wpdb->prefix ."wpdev_crm_customers as custmr " ; |
| 124 |
//$sql .= "ON ordr.customer_id = custmr.customer_id " ; |
| 125 |
$sql .= " " . $where ." "; |
| 126 |
$sql .= " ORDER BY ordr.order_id "; |
| 127 |
//debuge($sql);die; |
| 128 |
$result_orders = $wpdb->get_results( $sql ); |
| 129 |
|
| 130 |
$exist_bookings_id = ''; |
| 131 |
foreach ($result_orders as $in_id) { |
| 132 |
$exist_bookings_id .= $in_id->internal_id .', '; |
| 133 |
} |
| 134 |
//debuge($exist_bookings_id); |
| 135 |
if ($exist_bookings_id != '') { |
| 136 |
$exist_bookings_id = substr($exist_bookings_id,0,-2); |
| 137 |
$exist_bookings_id = " WHERE bk.booking_id NOT IN (". $exist_bookings_id .")"; |
| 138 |
} |
| 139 |
//debuge($exist_bookings_id);die; |
| 140 |
//Set here order by some field |
| 141 |
$sql = "SELECT * |
| 142 |
FROM ".$wpdb->prefix ."booking as bk |
| 143 |
INNER JOIN ".$wpdb->prefix ."bookingdates as dt |
| 144 |
ON bk.booking_id = dt.booking_id " . |
| 145 |
$exist_bookings_id . |
| 146 |
" ORDER BY bk.booking_id ASC, dt.booking_date ASC |
| 147 |
"; |
| 148 |
$result = $wpdb->get_results( $sql ); |
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
if (! $is_hide) show_top_message_wpdev( __('Processing...','wpdev-crm') , 3000, false ); |
| 153 |
|
| 154 |
//adebug(count($result), $result); |
| 155 |
|
| 156 |
$final_structure = array(); |
| 157 |
$previos_id = ''; $previos_date = ''; |
| 158 |
$fsi = -1; |
| 159 |
// Loop all bookings for getting final strucutre with dates. |
| 160 |
foreach ($result as $single_booking) { |
| 161 |
if ($previos_id == $single_booking->booking_id ) { // if ID the same so we are getting only date |
| 162 |
$final_structure[$fsi]['booking_date'] .= ', ' .$single_booking->booking_date; |
| 163 |
$previos_date = $single_booking->booking_date; |
| 164 |
} else { |
| 165 |
if ( ($fsi!==-1) && ($previos_date!=='') ) { // Get end time from previos record |
| 166 |
$end_time = explode(' ', $previos_date); |
| 167 |
$end_time= explode(':', $end_time[1]); |
| 168 |
$final_structure[$fsi]['end_time'] = $end_time; |
| 169 |
} |
| 170 |
$previos_date = ''; // New booking |
| 171 |
$fsi++; |
| 172 |
$previos_id = $single_booking->booking_id; |
| 173 |
$final_structure[$fsi] = array(); |
| 174 |
$final_structure[$fsi]['booking_id'] = $single_booking->booking_id; |
| 175 |
$final_structure[$fsi]['form'] = $single_booking->form; |
| 176 |
$final_structure[$fsi]['booking_type'] = $single_booking->booking_type; |
| 177 |
$final_structure[$fsi]['remark'] = $single_booking->remark; |
| 178 |
if (isset($single_booking->pay_status)) $final_structure[$fsi]['pay_status'] = $single_booking->pay_status; else $final_structure[$fsi]['pay_status'] = ''; |
| 179 |
if (isset($single_booking->cost)) $final_structure[$fsi]['cost'] = $single_booking->cost; else $final_structure[$fsi]['cost'] = ''; |
| 180 |
$final_structure[$fsi]['booking_date'] = $single_booking->booking_date; |
| 181 |
$final_structure[$fsi]['approved'] = $single_booking->approved; |
| 182 |
$start_time = explode(' ', $single_booking->booking_date); |
| 183 |
$start_time= explode(':', $start_time[1]); |
| 184 |
$final_structure[$fsi]['start_time'] = $start_time; |
| 185 |
} |
| 186 |
} |
| 187 |
if ( ($fsi!==-1) && ($previos_date!=='') ) { // Get end time for the last booking |
| 188 |
$end_time = explode(' ', $previos_date); |
| 189 |
$end_time= explode(':', $end_time[1]); |
| 190 |
$final_structure[$fsi]['end_time'] = $end_time; |
| 191 |
} |
| 192 |
$togather_cont= count($final_structure); |
| 193 |
if (! $is_hide) show_top_message_wpdev( sprintf(__('Found %s new bookings...','wpdev-crm'), $togather_cont ) , 3000, true ); |
| 194 |
//adebug($final_structure); |
| 195 |
|
| 196 |
// Loop all bookings |
| 197 |
$my_cnt = 0; |
| 198 |
$alternative_color = ''; |
| 199 |
foreach ($final_structure as $single_booking) { $my_cnt++; |
| 200 |
if ( $alternative_color == '') {$alternative_color = ' class="alternative_color" ';} else { $alternative_color = '';} |
| 201 |
|
| 202 |
// Function for adding new orders from booking |
| 203 |
|
| 204 |
$booking_id = $single_booking['booking_id'] ; |
| 205 |
$booking_type = $single_booking['booking_type']; |
| 206 |
$booking_days = $single_booking['booking_date'] ; |
| 207 |
$times_array = array( $single_booking['start_time'], $single_booking['end_time'] ); |
| 208 |
$booking_form = $single_booking['form'] ; |
| 209 |
$booking_cost = $single_booking['cost'] ; |
| 210 |
|
| 211 |
$added_booking = add_booking_order_single( $booking_id, $booking_type, $booking_days, $times_array , $booking_form , $booking_cost ); |
| 212 |
|
| 213 |
|
| 214 |
//$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 |
| 215 |
|
| 216 |
if (! $is_hide) show_top_message_wpdev( sprintf(__('Added %s bookings...','wpdev-crm'), $my_cnt . '/'. $togather_cont ) , 3000, true ); |
| 217 |
if (! $is_hide) |
| 218 |
if ($added_booking !== false) { |
| 219 |
?> |
| 220 |
<script type="text/javascript"> |
| 221 |
$my_row = '<tr>'; |
| 222 |
//$my_row += '<td colspan="6" <?php echo $alternative_color ?> style="text-align:left;" > <?php echo __('Record','wpdev-crm'), ' #',$added_booking['id'] , ' ', __('imported successfully','wpdev-crm'); ?> </td>'; |
| 223 |
$my_row += '<td <?php echo $alternative_color ?> style="text-align:left;" > <?php echo $added_booking['id'] ; ?> </td>'; |
| 224 |
$my_row += '<td <?php echo $alternative_color ?> style="font-size:11px;"> <?php echo $added_booking['info']; ?> </td>'; |
| 225 |
$my_row += '<td <?php echo $alternative_color ?> ><a class="bktypetitle" style="line-height: 25px; background-color:#888;text-shadow:0 -1px 0 #CCCCCC;color:#fff; padding: 2px 5px; font-size: 10px; white-space: nowrap;" href="javascript:;"><?php echo $added_booking['customer'] ?></a></td>'; |
| 226 |
$my_row += '<td <?php echo $alternative_color ?> ><a class="bktypetitle" style="line-height: 25px; background-color:#fff; padding: 2px 5px; font-size: 10px; white-space: nowrap;" href="javascript:;" ><?php echo $added_booking['type'] ?></a></td>'; |
| 227 |
|
| 228 |
|
| 229 |
$my_row += '<td <?php echo $alternative_color ?> >'; |
| 230 |
//$my_row += '<span><a href="javascript:;" class="booking_overmause1" ><?php |
| 231 |
echo apply_filters('wpdev_bk_get_showing_date_format', mysql2date('U', $added_booking['date_of_order'] )); |
| 232 |
?></a></span>'; |
| 233 |
$my_row += '</td>'; |
| 234 |
$my_row += '<th <?php echo $alternative_color ?> > <?php echo $added_booking['cost'] ?> </th>'; |
| 235 |
$my_row += '</tr>'; |
| 236 |
|
| 237 |
jQuery('#wpdev_order_table tr:first').after($my_row) |
| 238 |
</script> |
| 239 |
<?php } |
| 240 |
} |
| 241 |
if (! $is_hide) |
| 242 |
if ( $my_cnt != 0) { |
| 243 |
?> <center><h3><a href="javascript:;" onclick="javascript:location.reload(true);"><?php _e('Reload page','wpdev-crm'); ?></a></h3></center> <?php |
| 244 |
} |
| 245 |
} else { $fin_message = __('Can not find installed Booking Calendar plugin inside of system','wpdev-crm'); } |
| 246 |
// show_top_message_wpdev( $fin_message , 2000, true ); |
| 247 |
if (! $is_hide) { die(); } |
| 248 |
} |
| 249 |
|
| 250 |
|
| 251 |
// Adding / import one new bookings |
| 252 |
function add_booking_order_single( $booking_id, $booking_type, $booking_days, $times_array , $booking_form , $booking_cost =0 ){ |
| 253 |
// debuge($booking_cost); |
| 254 |
global $wpdb; |
| 255 |
if ($booking_cost != 0 ) $summ = $booking_cost; |
| 256 |
else { |
| 257 |
if ($booking_cost === '0.00') $summ = 0; |
| 258 |
else { |
| 259 |
$summ = 0; |
| 260 |
if ( class_exists('wpdev_bk_premium')) // Get COST if possible. |
| 261 |
$summ = apply_filters('wpdev_get_booking_cost', $booking_type, $booking_days, $times_array, $booking_form ); |
| 262 |
} |
| 263 |
} |
| 264 |
//$now_time = gmdate( 'Y-m-d H:i:s' ); |
| 265 |
$now_time = date_i18n("Y-m-d H:i:s", mktime()) ; |
| 266 |
|
| 267 |
// Get dates with Time ///////////////////////////////////////////////////////////// |
| 268 |
$start_time = $times_array[0]; |
| 269 |
$end_time = $times_array[1]; |
| 270 |
$my_dates = explode(',', $booking_days); |
| 271 |
|
| 272 |
$my_dates4DB = ''; |
| 273 |
if ( count($my_dates) == 1 ) { |
| 274 |
if ( ( $start_time != array('00', '00', '00') ) && ( $end_time != array('00', '00', '00') ) ) { |
| 275 |
$my_dates[]=$my_dates[0]; |
| 276 |
} |
| 277 |
} |
| 278 |
for ($i = 0; $i < count($my_dates); $i++) { $my_dates[$i] = trim($my_dates[$i]); } // Trim dates |
| 279 |
sort($my_dates); |
| 280 |
|
| 281 |
//debuge($my_dates); |
| 282 |
$my_date = trim($my_dates[0]); |
| 283 |
$my_date = explode(' ', $my_date); $my_date = $my_date[0]; |
| 284 |
if ( strpos($my_date,'-') !== false ) { |
| 285 |
$my_date = explode('-',$my_date); |
| 286 |
$date = sprintf( "%04d-%02d-%02d %02d:%02d:%02d", $my_date[0], $my_date[1], $my_date[2], $start_time[0], $start_time[1], $start_time[2] ); |
| 287 |
} else { |
| 288 |
$my_date = explode('.',$my_date); |
| 289 |
$date = sprintf( "%04d-%02d-%02d %02d:%02d:%02d", $my_date[2], $my_date[1], $my_date[0], $start_time[0], $start_time[1], $start_time[2] ); |
| 290 |
} |
| 291 |
$start_single_date = $date; |
| 292 |
|
| 293 |
$my_date = trim($my_dates[ (count($my_dates) - 1 )]); |
| 294 |
$my_date = explode(' ', $my_date); $my_date = $my_date[0]; |
| 295 |
if ( strpos($my_date,'-') !== false ) { |
| 296 |
$my_date = explode('-',$my_date); |
| 297 |
$date = sprintf( "%04d-%02d-%02d %02d:%02d:%02d", $my_date[0], $my_date[1], $my_date[2], $end_time[0], $end_time[1], $end_time[2] ); |
| 298 |
} else { |
| 299 |
$my_date = explode('.',$my_date); |
| 300 |
$date = sprintf( "%04d-%02d-%02d %02d:%02d:%02d", $my_date[2], $my_date[1], $my_date[0], $end_time[0], $end_time[1], $end_time[2] ); |
| 301 |
} |
| 302 |
$fin_single_date = $date; |
| 303 |
|
| 304 |
|
| 305 |
|
| 306 |
$i=0; |
| 307 |
foreach ($my_dates as $my_date) { |
| 308 |
$my_date = trim($my_date); |
| 309 |
$my_date = explode(' ', $my_date); $my_date = $my_date[0]; |
| 310 |
$i++; |
| 311 |
if ( strpos($my_date,'-') !== false ) { |
| 312 |
$my_dates4DB .= $my_date . ','; |
| 313 |
} else { |
| 314 |
// Loop through all dates |
| 315 |
if (strpos($my_date,'.')!==false) { |
| 316 |
$my_date = explode('.',$my_date); |
| 317 |
if ($i == 1) { $date = sprintf( "%04d-%02d-%02d %02d:%02d:%02d", $my_date[2], $my_date[1], $my_date[0], $start_time[0], $start_time[1], $start_time[2] ); |
| 318 |
} elseif ($i == count($my_dates)) { $date = sprintf( "%04d-%02d-%02d %02d:%02d:%02d", $my_date[2], $my_date[1], $my_date[0], $end_time[0], $end_time[1], $end_time[2] ); |
| 319 |
} else { $date = sprintf( "%04d-%02d-%02d %02d:%02d:%02d", $my_date[2], $my_date[1], $my_date[0], '00', '00', '00' ); } |
| 320 |
$my_dates4DB .= $date . ','; |
| 321 |
} |
| 322 |
} |
| 323 |
} |
| 324 |
if (strpos($my_dates4DB,',')!==false) $my_dates4DB = substr($my_dates4DB,0,-1); |
| 325 |
/////////////////////////////////////////////////////////////////////////////////// |
| 326 |
|
| 327 |
$form_content_array = ''; |
| 328 |
if ( function_exists ('get_form_content')) { $form_content_array = get_form_content($booking_form, $booking_type) ; } // TODO: check in Free version |
| 329 |
|
| 330 |
if ($form_content_array != '') { |
| 331 |
|
| 332 |
if ( ! isset($form_content_array['_all_']['email' . $booking_type ]) ) return; // Email must be set if not set so return from here |
| 333 |
|
| 334 |
$booking_form .= "~wpdev_booking_dates^booking_dates^" . $my_dates4DB ; // Add dates of reservation in correct format |
| 335 |
|
| 336 |
// ADD or SELECT C u s t o m e r ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
| 337 |
$my_sql = "SELECT customer_id as id FROM ".$wpdb->prefix . "wpdev_crm_customers WHERE email = '".$form_content_array['_all_']['email' . $booking_type ]."'"; |
| 338 |
$my_result = $wpdb->get_results( $my_sql ); |
| 339 |
if (count($my_result)>0) { //Check if this customer already exist using EMAIL as uniq field |
| 340 |
$customer_id = (int) $my_result[0]->id; // Customer is exist here is ID |
| 341 |
} else { // Not Exist |
| 342 |
// Insert customer |
| 343 |
$customer_details_info = array(); // Get customer fields if they exist |
| 344 |
|
| 345 |
if ( isset($form_content_array['_all_']['name' . $booking_type ]) ) $customer_details_info[] = $form_content_array['_all_']['name' . $booking_type ]; |
| 346 |
else $customer_details_info[] = ''; |
| 347 |
if ( isset($form_content_array['_all_']['secondname' . $booking_type ]) ) $customer_details_info[] = $form_content_array['_all_']['secondname' . $booking_type ]; |
| 348 |
else $customer_details_info[] = ''; |
| 349 |
if ( isset($form_content_array['_all_']['email' . $booking_type ]) ) $customer_details_info[] = $form_content_array['_all_']['email' . $booking_type ]; |
| 350 |
else $customer_details_info[] = ''; |
| 351 |
if ( isset($form_content_array['_all_']['phone' . $booking_type ]) ) $customer_details_info[] = $form_content_array['_all_']['phone' . $booking_type ]; |
| 352 |
else $customer_details_info[] = ''; |
| 353 |
if ( isset($form_content_array['_all_']['address' . $booking_type ]) ) $customer_details_info[] = $form_content_array['_all_']['address' . $booking_type ]; |
| 354 |
else $customer_details_info[] = ''; |
| 355 |
if ( isset($form_content_array['_all_']['city' . $booking_type ]) ) $customer_details_info[] = $form_content_array['_all_']['city' . $booking_type ]; |
| 356 |
else $customer_details_info[] = ''; |
| 357 |
if ( isset($form_content_array['_all_']['country' . $booking_type ]) ) $customer_details_info[] = $form_content_array['_all_']['country' . $booking_type ]; |
| 358 |
else $customer_details_info[] = ''; |
| 359 |
|
| 360 |
$customer_details_info[0] = str_replace("'", '', $customer_details_info[0]); |
| 361 |
$customer_details_info[1] = str_replace("'", '', $customer_details_info[1]); |
| 362 |
$customer_details_info[2] = str_replace("'", '', $customer_details_info[2]); |
| 363 |
$customer_details_info[3] = str_replace("'", '', $customer_details_info[3]); |
| 364 |
$customer_details_info[4] = str_replace("'", '', $customer_details_info[4]); |
| 365 |
$customer_details_info[5] = str_replace("'", '', $customer_details_info[5]); |
| 366 |
$customer_details_info[6] = str_replace("'", '', $customer_details_info[6]); |
| 367 |
$booking_form = str_replace("'", '', $booking_form ); |
| 368 |
|
| 369 |
$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]."', |
| 370 |
'".$booking_form."', |
| 371 |
NOW() |
| 372 |
)"; |
| 373 |
if(1) |
| 374 |
if ( !empty($insert) ) |
| 375 |
if ( false === $wpdb->query("INSERT INTO ".$wpdb->prefix . |
| 376 |
"wpdev_crm_customers (name, second_name, email, phone, adress, city, country, info, customer_date) VALUES " . $insert) ) { |
| 377 |
?> <script type="text/javascript"> document.getElementById('ajax_working').innerHTML = '<div style="height:20px;width:100%;text-align:center;margin:15px auto;"><?php echo __('Error during inserting into BD', 'wpdev-crm'), ' wpdev_crm_customers'; ?></div>'; </script> <?php |
| 378 |
//adebug($insert); |
| 379 |
die(); |
| 380 |
} |
| 381 |
$customer_id = (int) $wpdb->insert_id; //Get ID of reservation |
| 382 |
} |
| 383 |
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
| 384 |
|
| 385 |
|
| 386 |
// Insert O R D E R /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
| 387 |
//$my_order_date = 'NOW()'; |
| 388 |
if ( $_POST['ajax_action_crm'] == 'IMPORT_BOOKINGS' ) { // Its mean import, so we set old YEAR |
| 389 |
$my_order_date = date('Y-m-d H:i:s', mktime(date('H'), date('i'), date('s'), date('m'), date('d'), '1970') ); |
| 390 |
} else { |
| 391 |
$my_order_date = date('Y-m-d H:i:s', mktime(date('H'), date('i'), date('s'), date('m'), date('d'), date('Y')) ); |
| 392 |
} |
| 393 |
|
| 394 |
|
| 395 |
$booking_form = str_replace("'", '', $booking_form ); |
| 396 |
|
| 397 |
$insert = "('". $booking_form ."', |
| 398 |
'". $customer_id ."', |
| 399 |
'". serialize( array( 'booking'=>$booking_type ) ) ."', |
| 400 |
'". $summ ."', |
| 401 |
'".$my_order_date."', |
| 402 |
'". $booking_id ."', |
| 403 |
'".$my_dates4DB."', |
| 404 |
'".$booking_type."', |
| 405 |
'".$start_single_date."', |
| 406 |
'".$fin_single_date."' |
| 407 |
)"; |
| 408 |
if(1) |
| 409 |
if ( !empty($insert) ) |
| 410 |
if ( false === $wpdb->query("INSERT INTO ".$wpdb->prefix . |
| 411 |
"wpdev_crm_orders (order_info, customer_id, type, cost, order_date, internal_id, internal_filters, internal_filters1, internal_filters2, internal_filters3) VALUES " . $insert) ) { |
| 412 |
?> <script type="text/javascript"> document.getElementById('ajax_working').innerHTML = '<div style="height:20px;width:100%;text-align:center;margin:15px auto;"><?php echo __('Error during inserting into BD', 'wpdev-crm'), ' wpdev_crm_orders '; ?></div>'; </script> <?php |
| 413 |
die(); |
| 414 |
} |
| 415 |
$order_id = (int) $wpdb->insert_id; |
| 416 |
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
| 417 |
//return; |
| 418 |
if ( function_exists ('get_form_content')) { |
| 419 |
|
| 420 |
$content_fomr_show = get_form_content($booking_form, $booking_type); |
| 421 |
/* $content_fomr_show = str_replace('<br/>', '', $content_fomr_show['content']); |
| 422 |
$content_fomr_show = str_replace('<br />', '', $content_fomr_show); |
| 423 |
$content_fomr_show = str_replace('"', '', $content_fomr_show); |
| 424 |
$content_fomr_show = str_replace("'", '', $content_fomr_show); |
| 425 |
$content_fomr_show = str_replace('/', '', $content_fomr_show); |
| 426 |
$content_fomr_show = str_replace('/n/', '', $content_fomr_show);/**/ |
| 427 |
// Remove all shortcodes, which is not replaced early. |
| 428 |
$content_fomr_show = $content_fomr_show['content']; |
| 429 |
$content_fomr_show = preg_replace ('/[\s]{0,}\[[a-zA-Z0-9.,-_]{0,}\][\s]{0,}/', '', $content_fomr_show); |
| 430 |
//$content_fomr_show = preg_replace ('/[\s]*<[\s]*br[\s]*[\/]*[\s]*>[\s]*/', '', $content_fomr_show); |
| 431 |
$content_fomr_show = preg_replace ('/<br[\s]*[\/]*[\s]*>/', '', $content_fomr_show); |
| 432 |
$content_fomr_show = preg_replace ('/[\s]*\n[\s]*/', ' ', $content_fomr_show); // Remove all hided line breaks \n |
| 433 |
//debuge( htmlentities($content_fomr_show) ); |
| 434 |
if ( function_exists ('get_booking_title')) $title = get_booking_title( $booking_type ); |
| 435 |
else $title = 'Standard'; |
| 436 |
return (array( |
| 437 |
'id'=> $order_id, |
| 438 |
'info' => $content_fomr_show, |
| 439 |
'customer' => $customer_details_info[0]." " .$customer_details_info[1], |
| 440 |
'type' => $title , |
| 441 |
'date_of_order' => date('Y-m-d H:i:s'), |
| 442 |
'cost' => $summ |
| 443 |
) ); |
| 444 |
} else { |
| 445 |
return false; |
| 446 |
} |
| 447 |
} |
| 448 |
|
| 449 |
} |
| 450 |
|
| 451 |
|
| 452 |
|
| 453 |
?> |
| 454 |
|