<?php
class ControllerCommonFooter extends Controller {
	public function index() {
		$this->load->language('common/footer');

		$this->load->model('catalog/information');

		$data['informations'] = array();

		foreach ($this->model_catalog_information->getInformations() as $result) {
			if ($result['bottom']) {
				$data['informations'][] = array(
					'title' => $result['title'],
					'href'  => $this->url->link('information/information', 'information_id=' . $result['information_id'])
				);
			}
		}

		// test
		if ( $this->customer->getId() == 246 ) {

			// total based shipping
			// $subtotal = $this->cart->getSubTotal();
			// $totaltotal = $this->cart->getTotal();
			// print_r($subtotal);
			// print_r('<br/>');
			// print_r($totaltotal);


// 			$this->load->model('account/order');
// 			$order_info = $this->model_account_order->getOrderGuest(4030);
// 			echo '<pre>';
// 			print_r($order_info);

// 			if( (int)$order_info['order_status_id'] != (int)$this->config->get('payment_skrill_order_status_id') ) {
// echo 1111;
// 			} else {
// echo 2222;
// 			}

			// $this->load->model('account/customer');
			// $customer_info = $this->model_account_customer->getCustomer(246);
			// $customer_id = $customer_info['customer_id'];
			// print_r($customer_id);


			$this->load->model('checkout/order');
			$this->load->model('account/customer');
			$this->load->model('account/address');

			$orderDetails =  $this->model_checkout_order->getOrderCustomerID(3940);

			$order_customer_id = $orderDetails[0]['customer_id'];
			$customer_infos = $this->model_account_customer->getCustomer($order_customer_id);

			if(!empty($customer_infos)) {
				$default_addressid = $customer_infos['address_id'];
			} else {
				$default_addressid = 0;
			}

			$address_info = $this->model_account_address->getAddress($default_addressid);

			if(!empty($address_info)) {
				//$this->model_account_address->editOrderDefaultAddress2(3940, $address_info, $order_customer_id);
			}
			// echo '<pre>';
			// print_r($address_info);
			// echo '</pre>';


			// echo $this->config->get('session_name');
			// echo '<br/>';
			// echo $this->session->getId();

			//$this->load->model('checkout/order');
			//echo $this->model_checkout_order->getOrderStatus(3857);
			// $this->load->model('account/customer');
			// $this->load->model('account/address');

			// $customer_info = $this->model_account_customer->getCustomer($this->customer->getId());

			// if(!empty($customer_info)) {
			// 	$default_addressid = $customer_info['address_id'];
			// } else {
			// 	$default_addressid = 0;
			// }

			// $address_info = $this->model_account_address->getAddress($default_addressid);

			// print_r($address_info);
			// if(!empty($address_info)) {
			// 	echo $this->model_account_address->editOrderDefaultAddress($address_info);
			// }

		}
		// end test

		$data['contact'] = $this->url->link('information/contact');
		$data['return'] = $this->url->link('account/return/add', '', true);
		$data['sitemap'] = $this->url->link('information/sitemap');
		$data['tracking'] = $this->url->link('information/tracking');
		$data['manufacturer'] = $this->url->link('product/manufacturer');
		$data['voucher'] = $this->url->link('account/voucher', '', true);
		$data['affiliate'] = $this->url->link('affiliate/login', '', true);
		$data['special'] = $this->url->link('product/special');
		$data['account'] = $this->url->link('account/account', '', true);
		$data['order'] = $this->url->link('account/order', '', true);
		$data['wishlist'] = $this->url->link('account/wishlist', '', true);
		$data['newsletter'] = $this->url->link('account/newsletter', '', true);

		$data['powered'] = sprintf($this->language->get('text_powered'), $this->config->get('config_name'), date('Y', time()));

		$data['custom_footer'] = sprintf($this->language->get('text_footer'), date('Y', time()));
		$data['date_year'] = sprintf(date('Y', time()));

		$data['language'] = $this->load->controller('common/language');

		// Whos Online
		if ($this->config->get('config_customer_online')) {
			$this->load->model('tool/online');

			if (isset($this->request->server['REMOTE_ADDR'])) {
				$ip = $this->request->server['REMOTE_ADDR'];
			} else {
				$ip = '';
			}

			if (isset($this->request->server['HTTP_HOST']) && isset($this->request->server['REQUEST_URI'])) {
				$url = ($this->request->server['HTTPS'] ? 'https://' : 'http://') . $this->request->server['HTTP_HOST'] . $this->request->server['REQUEST_URI'];
			} else {
				$url = '';
			}

			if (isset($this->request->server['HTTP_REFERER'])) {
				$referer = $this->request->server['HTTP_REFERER'];
			} else {
				$referer = '';
			}

			$this->model_tool_online->addOnline($ip, $this->customer->getId(), $url, $referer);
		}

		$data['scripts'] = $this->document->getScripts('footer');


		$this->load->model('extension/d_quickcheckout/address');
		$addresses = $this->model_extension_d_quickcheckout_address->getAddresses();
		// chris modification
		$custaddresses = $this->model_extension_d_quickcheckout_address->getCustAddresses();
		$data['default_address_id'] = $custaddresses['address_id'];

		return $this->load->view('common/footer', $data);
	}
}
