public static function fe_render_page() { global $wpdb; if (get_query_var('client-area')) { switch (get_query_var('client-area')) { case 'dashboard': self::logged_in(); $bookings = $wpdb->get_results($wpdb->prepare('SELECT * FROM `' . $wpdb->prefix . 'carrental_booking` WHERE `id_user` = %d ORDER BY `created` DESC', $_SESSION['user_id']), ARRAY_A); self::$title = CarRental::t('Client Area'); self::view('my-bookings', array('bookings' => $bookings), true); break; case 'sign-in': self::$title = CarRental::t('Sign up to client area'); self::view('sign-in', array(), true); break; case 'account-settings': self::logged_in(); self::$title = CarRental::t('Account settings'); self::view('account-settings', array(), true); break; case 'my-account': self::logged_in(); self::$title = CarRental::t('My account'); $user = $wpdb->get_row($wpdb->prepare('SELECT * FROM `' . $wpdb->prefix . 'carrental_users` WHERE `user_id` = %d', $_SESSION['user_id']), ARRAY_A); self::view('my-account', array('user' => $user), true); break; case 'logout': self::logged_in(); unset($_SESSION['user_id']); unset($_SESSION['user_email']); $_SESSION['carrental_flash_msg'] = array('status' => 'success', 'msg' => CarRental::t('Login successful.')); header('Location: ' . home_url() . '/' . self::$url . '/login'); exit; break; case 'lost-password': self::$title = CarRental::t('Lost password'); self::view('lost-password', array(), true); break; default: // login self::$title = CarRental::t('Log in to your account'); self::view('login', array(), true); break; } exit; } }
<div class="carrental-wrapper"> <?php include CARRENTAL_CLIENT_AREA__PLUGIN_DIR . 'views/header.php'; ?> <a href="<?php echo esc_url(CarRental_Client_Area::get_page_url()); ?> " class="btn btn-default">Back to all users</a> <div class="carrental-client-area-client-details"> <ul> <li><label>First name: </label><span><?php echo $user['first_name']; ?> </span></li> <li><label>Last name: </label><span><?php echo $user['last_name']; ?> </span></li> <li><label>Email: </label><span><?php echo $user['email']; ?> </span></li> <li><label>Phone: </label><span><?php echo $user['phone']; ?> </span></li> <li><label>Street: </label><span><?php echo $user['street']; ?> </span></li>
<span class="additional xxlarge"><?php echo CarRental::t('Not available'); ?> </span> <?php } ?> </p> </div> <!-- .row --> <?php $user = array(); if (defined('CARRENTAL_CLIENT_AREA_VERSION')) { $user = CarRental_Client_Area::get_current_user(); } $inputs = get_option('carrental_reservation_inputs'); $inputs = unserialize($inputs); ?> <hr class="separate"> <div class="h2 additional"><?php echo CarRental::t('Driver details'); ?> </div> <div class="form-size-100"> <div class="columns-2 control-group">
echo $d['email']; ?> </td><td><?php echo $d['first_name'] . ' ' . $d['last_name']; ?> </td><td><?php echo $d['orders_count']; ?> </td><td><?php echo date('Y-m-d H:i:s', strtotime($d['last_login'])); ?> </td><td><?php echo $d['last_login_ip']; ?> </td><td><a href="<?php echo esc_url(CarRental_Client_Area::get_page_url()) . '&user_id=' . $d['user_id']; ?> ">Show details</a></td></tr> <?php } ?> </tbody> </table> <?php } else { ?> <p>No users found.</p> <?php } ?> </div>
/** * Save booking to database */ function save_booking($data) { global $wpdb; try { $id_order = self::generate_unique_order_id(); // Get location details $enter_loc_id = $return_loc_id = (int) $data['el']; $enter_loc = $return_loc = self::get_location_name($enter_loc_id); if (!empty($data['rl']) && (int) $data['rl'] > 0 && $_GET['dl'] == 'on') { $return_loc_id = (int) $data['rl']; $return_loc = self::get_location_name((int) $data['rl']); } // Get vehicle details $vehicle = self::get_vehicle_parameters((int) $data['id_car']); $consumption_metric = get_option('carrental_consumption'); $currency = get_option('carrental_global_currency'); $distance_metric = get_option('carrental_distance_metric'); $date_from = Date('Y-m-d H:i:s', strtotime($data['fd'] . ' ' . $data['fh'])); $date_to = Date('Y-m-d H:i:s', strtotime($data['td'] . ' ' . $data['th'])); $date_diff = abs(strtotime($date_to) - strtotime($date_from)); $diff_days = intval($date_diff / 86400); $diff_hours = intval($date_diff % 86400 / 3600); $diff_minutes = intval($date_diff % 86400 / 60); if ($diff_days >= 1 && ($diff_hours > 0 || $diff_minutes > 0)) { ++$diff_days; // If you pass by 30 minutes and more, it 1 day more } // get vehicle price $main_price = self::get_prices('fleet', (int) $data['id_car'], $date_from, $date_to, $data['promo'], isset($data['el']) ? $data['el'] : false, isset($data['rl']) ? $data['rl'] : false, isset($data['dl']) ? true : false); /* * TSDweb integration (activated by another plugin) */ try { $tsd = unserialize(get_option('carrental_tsdweb')); if ($tsd && !empty($tsd) && is_array($tsd)) { if (defined('CARRENTAL_TSDWEB__PLUGIN_DIR') && CARRENTAL_TSDWEB__PLUGIN_DIR != '') { if (file_exists(CARRENTAL_TSDWEB__PLUGIN_DIR . DIRECTORY_SEPARATOR . 'class.carrental-tsdweb.php')) { require_once CARRENTAL_TSDWEB__PLUGIN_DIR . DIRECTORY_SEPARATOR . 'class.carrental-tsdweb.php'; $data['bid_enter'] = $data['bid_return'] = self::get_location_id((int) $data['el']); if (!empty($data['rl']) && (int) $data['rl'] > 0 && $_GET['dl'] == 'on') { $data['bid_return'] = self::get_location_id((int) $data['rl']); } $data['class_code'] = $vehicle->class_code; $data['rate_id'] = $main_price['rate_id']; // Get month price $tf = strtotime($date_from); $monthly_date_to = Date('Y-m-d H:i:s', mktime(Date('H', $tf), Date('i', $tf), Date('s', $tf), Date('m', $tf) + Date('t', $tf), Date('d', $tf), Date('Y', $tf))); // + 1 month $monthly = self::get_prices('fleet', (int) $data['id_car'], $date_from, $monthly_date_to, $data['promo'], isset($data['el']) ? $data['el'] : false, isset($data['rl']) ? $data['rl'] : false, isset($data['dl']) ? true : false); $data['monthly_rate'] = (double) $monthly['total_rental'] + (double) $monthly['tax_total_rental']; // Get week price $weekly_date_to = Date('Y-m-d H:i:s', mktime(Date('H', $tf), Date('i', $tf), Date('s', $tf), Date('m', $tf), Date('d', $tf) + 7, Date('Y', $tf))); // + 7 days $weekly = self::get_prices('fleet', (int) $data['id_car'], $date_from, $weekly_date_to, $data['promo'], isset($data['el']) ? $data['el'] : false, isset($data['rl']) ? $data['rl'] : false, isset($data['dl']) ? true : false); $data['weekly_rate'] = (double) $weekly['total_rental'] + (double) $weekly['tax_total_rental']; // Get day price $daily_date_to = Date('Y-m-d H:i:s', mktime(Date('H', $tf), Date('i', $tf), Date('s', $tf), Date('m', $tf), Date('d', $tf) + 1, Date('Y', $tf))); // + 1 day $daily = self::get_prices('fleet', (int) $data['id_car'], $date_from, $daily_date_to, $data['promo'], isset($data['el']) ? $data['el'] : false, isset($data['rl']) ? $data['rl'] : false, isset($data['dl']) ? true : false); $data['daily_rate'] = (double) $daily['total_rental'] + (double) $daily['tax_total_rental']; CarRental_Tsdweb::api_send_data($data); } } } } catch (Exception $e) { } /* * END OF TSD Web integration */ $status = 1; // confirmed if (((int) $_POST['paypal'] == 1 || $_POST['payment_option'] == 'eway' || $_POST['payment_option'] == 'mercadopago') && (double) $_POST['total_rental'] > 0) { $payments_others = unserialize(get_option('carrental_available_payments_others')); switch ($_POST['payment_option']) { case 'eway': if ($payments_others && !empty($payments_others) && isset($payments_others['eway']) && $payments_others['eway']['enabled'] == 'yes' && (double) $payments_others['eway']['security-deposit'] > 0) { $status = 2; // pending payment } break; case 'mercadopago': if ($payments_others && !empty($payments_others) && isset($payments_others['mercadopago']) && $payments_others['mercadopago']['enabled'] == 'yes' && (double) $payments_others['mercadopago']['security-deposit'] > 0) { $status = 2; // pending payment } break; default: $status = 2; break; } } $user_id = 0; if (defined('CARRENTAL_CLIENT_AREA_VERSION')) { $user_id = CarRental_Client_Area::return_or_register_user(); } $status = apply_filters('carrental_save_booking_status_filter', $status); $lng = 'en_GB'; if (isset($_SESSION['carrental_language']) && !empty($_SESSION['carrental_language'])) { $lng = $_SESSION['carrental_language']; } $arr = array('id_order' => $id_order, 'first_name' => $data['first_name'], 'last_name' => $data['last_name'], 'email' => $data['email'], 'phone' => $data['phone'], 'street' => $data['street'], 'city' => $data['city'], 'zip' => $data['zip'], 'country' => $data['country'], 'company' => $data['company'], 'vat' => $data['vat'], 'flight' => $data['flight'], 'license' => $data['license'], 'id_card' => $data['id_card'], 'terms' => $data['terms'], 'newsletter' => $data['newsletter'], 'enter_loc' => $enter_loc, 'enter_date' => $date_from, 'return_loc' => $return_loc, 'return_date' => $date_to, 'id_enter_branch' => $enter_loc_id, 'id_return_branch' => $return_loc_id, 'vehicle' => $vehicle->name, 'vehicle_id' => $vehicle->id_fleet, 'vehicle_ac' => $vehicle->ac, 'vehicle_luggage' => $vehicle->luggage, 'vehicle_seats' => $vehicle->seats, 'vehicle_fuel' => $vehicle->fuel, 'vehicle_picture' => $vehicle->picture, 'vehicle_consumption' => $vehicle->consumption, 'vehicle_consumption_metric' => $consumption_metric, 'vehicle_transmission' => $vehicle->transmission, 'vehicle_free_distance' => $vehicle->free_distance . ' ' . $distance_metric, 'vehicle_deposit' => $vehicle->deposit . ' ' . $currency, 'payment_option' => $data['payment_selected_option'], 'comment' => $data['comment'], 'partner_code' => $data['partner_code'], 'status' => $status, 'currency' => $currency, 'id_user' => $user_id, 'lng' => $lng); $wpdb->insert(CarRental::$db['booking'], $arr); $id_booking = $wpdb->insert_id; // Add prices/extras // Vehicle price (+ tax) $total_price = 0; $arr = array('id_booking' => $id_booking, 'name' => $vehicle->name . ', ' . $date_from . ' (' . $enter_loc . ') - ' . $date_to . ' (' . $return_loc . ')', 'price' => (double) $main_price['total_rental_clear'], 'currency' => $main_price['currency']); $wpdb->insert(CarRental::$db['booking_prices'], $arr); $total_price += (double) $main_price['total_rental_clear']; if (isset($main_price['summary']) && isset($main_price['summary']['branch_distance_price']) && (double) $main_price['summary']['branch_distance_price'] > 0) { $arr = array('id_booking' => $id_booking, 'name' => 'Fee for returning in different location.', 'price' => (double) $main_price['summary']['branch_distance_price'], 'currency' => $main_price['currency']); $wpdb->insert(CarRental::$db['booking_prices'], $arr); $total_price += (double) $main_price['summary']['branch_distance_price']; } if (isset($main_price['summary']) && isset($main_price['summary']['branch_pick_up_price']) && (double) $main_price['summary']['branch_pick_up_price'] > 0) { $arr = array('id_booking' => $id_booking, 'name' => 'Fee for pick-up on specific branch.', 'price' => (double) $main_price['summary']['branch_pick_up_price'], 'currency' => $main_price['currency']); $wpdb->insert(CarRental::$db['booking_prices'], $arr); $total_price += (double) $main_price['summary']['branch_pick_up_price']; } if (isset($main_price['summary']) && isset($main_price['summary']['branch_returning_price']) && (double) $main_price['summary']['branch_returning_price'] > 0) { $arr = array('id_booking' => $id_booking, 'name' => 'Fee for returning on specific branch.', 'price' => (double) $main_price['summary']['branch_returning_price'], 'currency' => $main_price['currency']); $wpdb->insert(CarRental::$db['booking_prices'], $arr); $total_price += (double) $main_price['summary']['branch_returning_price']; } if ((double) $main_price['tax_total_rental'] > 0) { $arr = array('id_booking' => $id_booking, 'name' => $main_price['vat'] . '% Value Added Tax', 'price' => (double) $main_price['tax_total_rental'], 'currency' => $main_price['currency']); $wpdb->insert(CarRental::$db['booking_prices'], $arr); $total_price += (double) $main_price['tax_total_rental']; } // Extras prices if (!isset($data['extras'])) { $data['extras'] = array(); } $extras = self::get_vehicle_extras((int) $data['id_car'], array()); foreach ($extras as $ex) { if ($ex->mandatory == 1) { if (!in_array($ex->id_extras, $data['extras'])) { $data['extras'][] = $ex->id_extras; } } } if (isset($data['extras']) && !empty($data['extras'])) { foreach ($data['extras'] as $key => $id_extras) { // @todo: More drivers. $extras_detail = self::get_extras_parameters((int) $id_extras); $extras_prices = self::get_prices('extras', (int) $id_extras, $date_from, $date_to, $data['promo']); if ($extras_detail->max_additional_drivers > 0 && (int) $data['drivers'] > 0) { $arr = array('id_booking' => $id_booking, 'name' => $data['drivers'] . 'x ' . $extras_detail->name, 'price' => (double) $extras_prices['total_rental'] * $data['drivers'], 'currency' => $extras_prices['currency']); $wpdb->insert(CarRental::$db['booking_prices'], $arr); $total_price += (double) $extras_prices['total_rental'] * $data['drivers']; if ((double) $extras_prices['tax_total_rental'] > 0) { $arr = array('id_booking' => $id_booking, 'name' => $data['drivers'] . 'x ' . $extras_detail->name . ' - ' . $extras_prices['vat'] . '% Value Added Tax', 'price' => (double) $extras_prices['tax_total_rental'] * $data['drivers'], 'currency' => $extras_prices['currency']); $wpdb->insert(CarRental::$db['booking_prices'], $arr); $total_price += (double) $extras_prices['tax_total_rental'] * $data['drivers']; } } else { $arr = array('id_booking' => $id_booking, 'name' => $extras_detail->name, 'price' => (double) $extras_prices['total_rental'], 'currency' => $extras_prices['currency']); $wpdb->insert(CarRental::$db['booking_prices'], $arr); $total_price += (double) $extras_prices['total_rental']; if ((double) $extras_prices['tax_total_rental'] > 0) { $arr = array('id_booking' => $id_booking, 'name' => $extras_detail->name . ' - ' . $extras_prices['vat'] . '% Value Added Tax', 'price' => (double) $extras_prices['tax_total_rental'], 'currency' => $extras_prices['currency']); $wpdb->insert(CarRental::$db['booking_prices'], $arr); $total_price += (double) $extras_prices['tax_total_rental']; } } } } // Car delivery price $delivery_price = self::get_delivery_price(); if ($enter_loc != $return_loc && (double) $delivery_price > 0) { $arr = array('id_booking' => $id_booking, 'name' => 'Car delivery to different location', 'price' => (double) $delivery_price, 'currency' => $main_price['currency']); $wpdb->insert(CarRental::$db['booking_prices'], $arr); $total_price += (double) $delivery_price; } // Add drivers if (isset($data['drv']) && !empty($data['drv'])) { foreach ($data['drv'] as $key => $val) { if (!empty($val['first_name']) && !empty($val['last_name']) && !empty($val['email']) && !empty($val['phone'])) { $arr = array('id_booking' => $id_booking, 'first_name' => $val['first_name'], 'last_name' => $val['last_name'], 'email' => $val['email'], 'phone' => $val['phone'], 'street' => $val['street'], 'city' => $val['city'], 'zip' => $val['zip'], 'country' => $val['country'], 'license' => $val['license'], 'id_card' => $val['id_card']); $wpdb->insert(CarRental::$db['booking_drivers'], $arr); } } } if ($status == 2) { // if online payment $available_payments = unserialize(get_option('carrental_available_payments')); if (isset($available_payments['carrental_online_payment_discount']) && $available_payments['carrental_online_payment_discount'] > 0) { $discount = -1 * (double) $total_price * ($available_payments['carrental_online_payment_discount'] / 100); $arr = array('id_booking' => $id_booking, 'name' => 'Online payment discount', 'price' => $discount, 'currency' => $main_price['currency']); $wpdb->insert(CarRental::$db['booking_prices'], $arr); $total_price += (double) $discount; } } $hash = self::generate_hash($id_order, $data['email']); if ($status != 2) { // Send e-mail if (isset($_SESSION['carrental_language']) && !empty($_SESSION['carrental_language'])) { $emailBody = get_option('carrental_reservation_email_' . $_SESSION['carrental_language']); $emailSubject = get_option('carrental_reservation_email_subject_' . $_SESSION['carrental_language']); if ($emailBody == '') { $emailBody = get_option('carrental_reservation_email_en_GB'); } if ($emailSubject == '') { $emailSubject = get_option('carrental_reservation_email_subject_en_GB'); } } else { $emailBody = get_option('carrental_reservation_email_en_GB'); $emailSubject = get_option('carrental_reservation_email_subject_en_GB'); } if (!empty($emailBody)) { $theme_options = unserialize(get_option('carrental_theme_options')); if (isset($theme_options['date_format'])) { // reformat dates $date_from = date(self::date_format_php($theme_options['date_format'], 'auto'), strtotime($date_from)); $date_to = date(self::date_format_php($theme_options['date_format'], 'auto'), strtotime($date_to)); } $emailBody = str_replace('[CustomerName]', $data['first_name'] . " " . $data['last_name'], $emailBody); $emailBody = str_replace('[ReservationDetails]', $vehicle->name . ', ' . $date_from . ' (' . $enter_loc . ') - ' . $date_to . ' (' . $return_loc . ')', $emailBody); $emailBody = str_replace('[Car]', $vehicle->name, $emailBody); $emailBody = str_replace('[pickupdate]', $date_from, $emailBody); $emailBody = str_replace('[dropoffdate]', $date_to, $emailBody); $emailBody = str_replace('[pickup_location]', $enter_loc, $emailBody); $emailBody = str_replace('[dropoff_location]', $return_loc, $emailBody); $emailBody = str_replace('[total_payment]', round($total_price, 2), $emailBody); $emailBody = str_replace('[rate]', round($total_price / $diff_days, 2), $emailBody); $emailBody = str_replace('[rental_days]', $diff_days, $emailBody); $emailBody = str_replace('[ReservationNumber]', $id_order, $emailBody); $emailBody = str_replace('[customer_comment]', $data['comment'], $emailBody); $emailBody = str_replace('[ReservationLink]', home_url() . '?page=carrental&summary=' . $hash, $emailBody); $emailBody = str_replace('[ReservationLinkStart]', '<a href="' . home_url() . '?page=carrental&summary=' . $hash . '">', $emailBody); $emailBody = str_replace('[ReservationLinkEnd]', '</a>', $emailBody); $emailBody = '<html><body>' . $emailBody . '</body></html>'; $emailBody = self::removeslashes(nl2br($emailBody)); $recipient = $data['email']; if ($emailSubject == '') { $subject = "Reservation confirmation #" . $id_order; } else { $subject = $emailSubject; $subject = str_replace('[CustomerName]', $data['first_name'] . " " . $data['last_name'], $subject); $subject = str_replace('[ReservationDetails]', $vehicle->name . ', ' . $date_from . ' (' . $enter_loc . ') - ' . $date_to . ' (' . $return_loc . ')', $subject); $subject = str_replace('[Car]', $vehicle->name, $subject); $subject = str_replace('[pickupdate]', $date_from, $subject); $subject = str_replace('[dropoffdate]', $date_to, $subject); $subject = str_replace('[pickup_location]', $enter_loc, $subject); $subject = str_replace('[dropoff_location]', $return_loc, $subject); $subject = str_replace('[total_payment]', round($total_price, 2), $subject); $subject = str_replace('[rate]', round($total_price / $diff_days, 2), $subject); $subject = str_replace('[rental_days]', $diff_days, $subject); $subject = str_replace('[ReservationNumber]', $id_order, $subject); $subject = str_replace('[ReservationLink]', home_url() . '?page=carrental&summary=' . $hash, $subject); $subject = str_replace('[ReservationLinkStart]', '<a href="' . home_url() . '?page=carrental&summary=' . $hash . '">', $subject); $subject = str_replace('[ReservationLinkEnd]', '</a>', $subject); } $company = unserialize(get_option('carrental_company_info')); $email = isset($company['email']) && !empty($company['email']) ? $company['email'] : 'admin@' . $_SERVER['SERVER_NAME']; $name = isset($company['name']) && !empty($company['name']) ? $company['name'] : 'Car Rental WP Plugin'; add_filter('wp_mail_content_type', create_function('', 'return "text/html"; ')); add_filter('wp_mail_from', create_function('', 'return "' . $email . '"; ')); add_filter('wp_mail_from_name', create_function('', 'return "' . $name . '"; ')); $book_send_email = get_option('carrental_book_send_email'); if (empty($book_send_email)) { $book_send_email = array('client' => 1, 'admin' => 1, 'other' => 1); } else { $book_send_email = unserialize($book_send_email); if (!is_array($book_send_email)) { $book_send_email = array(); } if (!isset($book_send_email['client'])) { $book_send_email['client'] = 1; } if (!isset($book_send_email['admin'])) { $book_send_email['admin'] = 1; } if (!isset($book_send_email['other'])) { $book_send_email['other'] = 0; } } $attachments = array(); $attachments = apply_filters('carrental_email_attachments', $attachments, $id_order); if ($book_send_email['client'] == 1) { $res = wp_mail($recipient, $subject, $emailBody, '', $attachments); } if ($book_send_email['other'] == 1 && isset($book_send_email['other_email']) && $book_send_email['other_email'] != '') { @wp_mail($book_send_email['other_email'], $subject, $emailBody, '', $attachments); } // Copy to admin if (isset($company['email']) && !empty($company['email']) && $book_send_email['admin'] == 1) { @wp_mail($company['email'], $subject, $emailBody, '', $attachments); } } } return $hash; } catch (Exception $e) { return $e->getMessage(); } }