public function index()
 {
     // global $wp_rewrite;
     // $wp_rewrite->flush_rules();
     $payments_model = $this->load->model('payments_model');
     $payments_model->check_valid_hash('asdas');
     $car_id = AT_Session::get_instance()->userdata('paidEntityID');
     $car_model = $this->load->model('car_model');
     if (AT_Common::validate_id($car_id) && $car_model->check_user_cars($car_id, AT_Common::get_logged_user_id(), 'publish') > 0) {
         $this->view->use_layout('header_content_footer')->add_block('content', 'payments/prepare', array('cars' => $car_model->get_car_info($car_id), 'methods' => array('paypal' => array('state' => $this->core->get_option('paypal_state', 0), 'name' => 'PayPal', 'logo' => 'https://www.paypalobjects.com/webstatic/mktg/Logo/AM_mc_vs_ms_ae_UK.png')), 'plans' => $this->core->get_option('merchant_plan', false), 'paid' => array('featured' => $this->core->get_option('merchant_module_featured', false), 'top' => $this->core->get_option('merchant_module_promote', false))));
     } else {
         $this->view->use_layout('header_content_footer')->add_block('content', 'payments/denied', array());
     }
 }
 public function __construct()
 {
     $this->core = AT_Core::get_instance();
     // if ( !$this->core->get_option( 'theme_is_activated', false ) && is_user_logged_in() ) {
     // 	AT_Notices::set_frontend_notice(
     // 		'<h3>'.__( 'New to AutoDealer?' , AT_TEXTDOMAIN ) . '</h3>' .
     // 		__( 'You almost ready to use full theme features. Please complete two last steps before move your website to production mode.' , AT_TEXTDOMAIN ) .
     // 		'<br />' .
     // 		sprintf(__( '<a href="%1$s">Click here to continue &rarr;</a>' , AT_TEXTDOMAIN ), get_admin_url() . 'admin.php?page=at_site_options_general'),
     // 		$class = 'notice'
     // 	);
     // 	Header('Location: ' . get_admin_url() . 'admin.php?page=at_site_options_general');
     // 	die();
     // 	// exit( __( 'Theme is not activated' , AT_TEXTDOMAIN ) );
     // }
     // SSL and ajax tricks
     // if ( ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] != rtrim( home_url(), '/' ) ) {
     // 	AT_Common::redirect( AT_Router::get_instance()->server('REQUEST_URI'), '301' );
     // }
     $this->uri = AT_Router::get_instance();
     if ($this->uri->get_method() != 'show_underconstruction' && $this->core->get_option('status_site', 'production') == 'underconstruction') {
         AT_Core::show_underconstruction();
     }
     $this->view = $this->core->view;
     $this->load = AT_Loader::get_instance();
     $this->session = AT_Session::get_instance();
     $this->registry = AT_Registry::get_instance();
     $this->load->library('breadcrumbs');
     $this->breadcrumbs = AT_Breadcrumbs::get_instance();
     $validation_rules = $this->load->helper('validation_rules', true);
     $this->validation = $this->load->library('form_validation', true, $validation_rules->rules);
     //$this->validation->set_rules();
     if (AT_Common::is_user_logged() && $this->core->get_option('theme_is_activated', false)) {
         $user_model = $this->load->model('user_model');
         $user_info = $user_model->get_user_by_id(AT_Common::get_logged_user_id());
         $this->registry->set('user_info', $user_info);
         if ($this->core->get_option('confirm_email_enable', true) && !in_array($this->uri->segments(1), array('confirm_email', 'unlogged')) && (is_null($user_info['date_active']) || empty($user_info['date_active']))) {
             AT_Common::redirect('auth/confirm_email');
         }
     }
 }
 public function query()
 {
     $this->validation();
     if (AT_Session::get_instance()->userdata('paymentMethod') === 'paypal') {
         //Mainly we need 4 variables from product page Item Name, Item Price, Item Number and Item Quantity.
         $planID = AT_Session::get_instance()->userdata('paymentPlanID');
         $plan = $this->core->get_option('merchant_plan', array());
         $plan = $plan[$planID];
         $ItemName = $plan['name'];
         $ItemPrice = number_format($plan['rate'], 2);
         $ItemNumber = AT_Session::get_instance()->userdata('paidEntityID');
         //Item Number
         $ItemDesc = $plan['name'] . __('for ', AT_TEXTDOMAIN) . '#' . AT_Session::get_instance()->userdata('paidEntityID');
         $ItemQty = 1;
         // Item Quantity
         $ItemTotalPrice = $ItemPrice * $ItemQty;
         //(Item Price x Quantity = Total) Get total amount of product;
         //Other important variables like tax, shipping cost
         $TotalTaxAmount = 0.0;
         $HandalingCost = 0.0;
         $InsuranceCost = 0.0;
         $ShippinDiscount = 0.0;
         $ShippinCost = 0.0;
         $GrandTotal = $ItemTotalPrice + $TotalTaxAmount + $HandalingCost + $InsuranceCost + $ShippinCost + $ShippinDiscount;
         //Parameters for SetExpressCheckout, which will be sent to PayPal
         $this->nvp = '&METHOD=SetExpressCheckout' . '&RETURNURL=' . urlencode($this->urlReturn) . '&CANCELURL=' . urlencode($this->urlCancel) . '&PAYMENTREQUEST_0_PAYMENTACTION=' . urlencode("SALE") . '&L_PAYMENTREQUEST_0_NAME0=' . urlencode($ItemName) . '&L_PAYMENTREQUEST_0_NUMBER0=' . urlencode($ItemNumber) . '&L_PAYMENTREQUEST_0_DESC0=' . urlencode($ItemDesc) . '&L_PAYMENTREQUEST_0_AMT0=' . urlencode($ItemPrice) . '&L_PAYMENTREQUEST_0_QTY0=' . urlencode($ItemQty) . '&NOSHIPPING=1' . '&PAYMENTREQUEST_0_ITEMAMT=' . urlencode($ItemTotalPrice) . '&PAYMENTREQUEST_0_TAXAMT=' . urlencode($TotalTaxAmount) . '&PAYMENTREQUEST_0_SHIPPINGAMT=' . urlencode($ShippinCost) . '&PAYMENTREQUEST_0_HANDLINGAMT=' . urlencode($HandalingCost) . '&PAYMENTREQUEST_0_SHIPDISCAMT=' . urlencode($ShippinDiscount) . '&PAYMENTREQUEST_0_INSURANCEAMT=' . urlencode($InsuranceCost) . '&PAYMENTREQUEST_0_AMT=' . urlencode($GrandTotal) . '&PAYMENTREQUEST_0_CURRENCYCODE=' . urlencode($this->core->get_option('paypal_currency_code', 'USD')) . '&LOCALECODE=' . $this->lang . '&LOGOIMG=' . $this->core->get_option('header_logo_src') . '&CARTBORDERCOLOR=FFFFFF' . '&ALLOWNOTE=1';
         //We need to execute the "SetExpressCheckOut" method to obtain paypal token
         $response = $this->connect();
         $data = array('uid' => AT_Common::get_logged_user_id(), 'tid' => '', 'sid' => 0, 'amount' => number_format($GrandTotal, 0, '.', ''), 'ack' => $response["ACK"], 'msg' => $response["L_SHORTMESSAGE0"], 'entity' => AT_Session::get_instance()->userdata('paidEntity'), 'entity_id' => AT_Session::get_instance()->userdata('paidEntityID'), 'created_at' => date('Y-m-d H:s:i'));
         $payments_model = $this->load->model('payments_model');
         $transaction_id = $payments_model->insert_transaction($data);
         // Register session
         AT_Session::get_instance()->set_userdata('recent_transaction_id', $transaction_id);
         // AT_Session::get_instance()->userdata('recent_transaction_id'),
         //Respond according to message we receive from Paypal
         if ("SUCCESS" == strtoupper($response["ACK"]) || "SUCCESSWITHWARNING" == strtoupper($response["ACK"])) {
             // `id` int(11) NOT NULL AUTO_INCREMENT,
             // `uid` int(11) NOT NULL,
             // `tid` varchar(128) NOT NULL,
             // `sid` tinyint(1) DEFAULT '0',
             // `amount` varchar(50) NOT NULL,
             // `ack` varchar(50) NULL,
             // `msg` varchar(255) NOT NULL,
             // `token` varchar(128) NULL,
             // `created_at` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
             // `completed_at` datetime DEFAULT NULL,
             // `timestamp` datetime DEFAULT NULL,
             $data = array('uid' => AT_Common::get_logged_user_id(), 'tid' => '', 'sid' => 0, 'amount' => number_format($GrandTotal, 0, '.', ''), 'ack' => $response["ACK"], 'msg' => $response["L_SHORTMESSAGE0"], 'token' => $response["TOKEN"], 'created_at' => date('Y-m-d H:s:i'), 'timestamp' => $response["TIMESTAMP"]);
             $payments_model->update_transaction($transaction_id, $data);
             //Redirect user to PayPal store with Token received.
             $paypalurl = 'https://www.' . ($this->mode == 'sandbox' ? 'sandbox' : '') . '.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=' . $response["TOKEN"];
             echo $paypalurl;
             header('Location: ' . $paypalurl);
             // echo $paypalurl;
         } else {
             //Show error message
             // $this->destroy();
             $data = array('sid' => 3, 'ack' => $httpParsedResponseAr["ACK"], 'msg' => $httpParsedResponseAr["L_SHORTMESSAGE0"]);
             $payments_model->update_transaction($transaction_id, $data);
             $this->view->use_layout('header_content_footer')->add_block('content', 'payments/paypal/error', array('response' => $response, 'msg' => $response["L_LONGMESSAGE0"]));
         }
     } else {
         $this->view->use_layout('header_content_footer')->add_block('content', 'payments/denied', array());
     }
 }
 public function transactions()
 {
     if ($this->uri->is_ajax_request() && !empty($_POST)) {
         try {
             if (!$this->validation->run('affiliate')) {
                 throw new Exception(serialize($this->validation->get_errors()));
             }
             $user_model = $this->load->model('user_model');
             $reference_model = $this->load->model('reference_model');
             $data = array('dealer_id' => AT_Common::get_logged_user_id(), 'name' => $_POST['name'], 'email' => $_POST['email'], 'adress' => isset($_POST['adress']) ? $_POST['adress'] : '', 'phone' => isset($_POST['phone_1']) ? $_POST['phone_1'] : '', 'phone_2' => isset($_POST['phone_2']) ? $_POST['phone_2'] : '', 'region_id' => isset($_POST['region_id']) ? $_POST['region_id'] : '', 'schedule' => isset($_POST['schedule']) ? serialize($_POST['schedule']) : serialize(array('monday' => '', 'tuesday' => '', 'wednesday' => '', 'thursday' => '', 'friday' => '', 'saturday' => '', 'sunday' => '')));
             $_POST['affiliate_id'] = (int) $_POST['affiliate_id'];
             if ($_POST['affiliate_id'] == 0) {
                 $_POST['affiliate_id'] = $user_model->insert_dealer_affiliate($data);
             } else {
                 $user_model->update_dealer_affiliate($_POST['affiliate_id'], $data);
             }
             $view = new AT_View();
             $view->use_layout('content')->add_block('content', 'settings/dealer_affiliate_item', array('affiliate' => $user_model->get_dealer_affiliate_by_id($_POST['affiliate_id']), 'regions' => $reference_model->get_regions()));
             $content = $view->render()->display(TRUE);
             unset($view);
             $response = array('status' => 'OK', 'content' => $content, 'message' => __('The changes was saved.', AT_TEXTDOMAIN));
         } catch (Exception $e) {
             $response = array('status' => 'ERROR', 'message' => unserialize($e->getMessage()));
         }
         $this->view->add_json($response)->display();
         exit;
     }
     $user_model = $this->load->model('user_model');
     $reference_model = $this->load->model('reference_model');
     $this->view->use_layout('profile');
     $this->view->add_block('content', 'settings/transactions', array('transactions' => $user_model->get_user_transactions_by_id(AT_Common::get_logged_user_id())));
     $this->breadcrumbs->add_item(__('Account', AT_TEXTDOMAIN), 'profile/');
     $this->breadcrumbs->add_item(__('Transactions', AT_TEXTDOMAIN), 'profile/settings/transactions');
     $menu_model = $this->load->model('menu_model');
     $this->view->add_block('left_side', 'general/navigation', $menu_model->get_menu('main', 'transactions'));
 }
						            map: map, 
						            title: dealer_address
						        }); 
						      }
						    }
						  });
						}

					}
					google.maps.event.addDomListener(window, 'load', dealer_map_init);
			</script>
			<?php 
    }
    ?>
			<?php 
    if (AT_Common::is_user_logged() && AT_Common::get_logged_user_id() == $car_info['options']['_owner_id']) {
        ?>
			<a href="<?php 
        echo AT_Common::site_url('profile/vehicles/edit/' . $car_info['ID'] . '/');
        ?>
" class="btn2"><?php 
        echo __('Edit vehicle', AT_TEXTDOMAIN);
        ?>
</a>
			<?php 
    }
    ?>
			<div class="clear"></div>
		</div>
		<?php 
}
 private function _get_limit_publish()
 {
     if ($this->_publish_limit > 0) {
         $car_model = $this->load->model('car_model');
         $count_cars = $car_model->get_cars_count_by_user_id(AT_Common::get_logged_user_id(), 'publish');
         $limit = $this->_publish_limit - $count_cars;
         if ($limit < 0) {
             $limit = 0;
         }
     } else {
         $limit = 999999;
     }
     return $limit;
 }