Subversion Repositories SmartDukaan

Rev

Rev 10592 | Rev 10602 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
10582 lgm 1
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
2
 
3
class Checkout extends MY_Controller {
4
 
5
public $layoutName ='';
6
 
7
	function __construct() {
8
 
9
		// Call the CI_controller constructor
10
		parent::__construct();
11
		$admin = $this->session->userdata('admin');
12
		if(!isset($admin) || empty($admin)) {
13
			redirect(base_url().'authorize');
14
		}
15
		$this->layout->setlayout('layout/layout_main');
16
		$this->load->model('checkout_model');
17
		$this->load->model('captcha_model');
18
		$this->layoutName= $this->layout->getLayout();
19
		$this->layoutName =substr($this->layoutName , 0, strrpos($this->layoutName , "/")).'/';
20
			//print_r($this->session->userdata);
21
 
22
 
23
	}
24
	public function index()
25
	{
26
		$authorized = $this->session->userdata('authorized');
27
		if(isset($authorized) and !empty($authorized['id']))
28
		{
29
			//if user logged-in
30
			redirect(base_url().strtolower(__CLASS__).'/shipping');
31
		}
32
 
33
		//standard array
34
		$data = array();
35
		$checkoutconfig = $this->config->item('checkout');
36
		if(!isset($_POST['submit'])){
37
		unset($checkoutconfig['response'][1]);	
38
		$data['response']=$this->checkout_model->getCheckoutDetails($this->input->get(),$this->input->post(),$checkoutconfig);
39
		$this->layout->view('checkout/checkout_view',$data);
40
		}
41
		if(isset($_POST['submit'])){
42
			$type = $this->input->post('type');
43
			if($type == "member"){
44
			unset($checkoutconfig['response'][0]);	
45
			$data['response']=$this->checkout_model->getCheckoutDetails($this->input->get(),$this->input->post(),$checkoutconfig);
46
			if(isset($data['response']['response']['login_submit']['authorized'])){
47
			$this->session->set_userdata('authorized',$data['response']['response']['login_submit']['authorized']);
48
			$this->session->set_flashdata(array('msg'=>$data['response']['response']['login_submit']['msg']));
49
			redirect(base_url().$data['response']['response']['login_submit']['redirect']);
50
			}
51
			else
52
			{
53
				$this->layout->view(strtolower(__CLASS__).'/checkout_view',$data);
54
			}
55
			}
56
			if($type == 'guest'){
57
				redirect(base_url().strtolower(__CLASS__).'/shipping');	
58
			}
59
			if($type == 'register'){
60
				redirect(base_url().'auth/signup');	
61
			}
62
		}
63
	}
64
	// public function billing()
65
	// {
66
	// 	//standard array
67
	// 	$data = array();
68
 
69
	// 	$data['response']=$this->checkout_model->getCheckoutDetails($this->input->get(),$this->input->post(),$this->config->item('billing'));
70
	// 	$this->layout->view('checkout/checkout_view',$data);
71
 
72
	// }
73
	public function __paginateList($data=array())
74
	{
75
			//$data['baseSubTotal']=$data['baseSubTotal'];
76
			$data['subTotal'] = $data['subTotal'];
77
			//$data['shippingCharges'] = $data['shippingCharges'];
78
			return $data;	
79
 
80
	}
81
 
82
	public function orderconfirmation()
83
	{
84
		$authorized = $this->session->userdata('authorized');
85
	    if(isset($authorized) && !empty($authorized)){
86
			$_GET['userId'] = $authorized['Id'];
87
			$_GET['Id'] = $authorized['cartId'];
88
			if($authorized['isLoggedIn'] == 1){
89
				$_GET['isLoggedIn'] = 'true';
90
			}
91
		elseif(isset($authorized['isLoggedIn']) && empty($authorized['isLoggedIn'])) {
92
				$_GET['isLoggedIn'] = 'false';
93
			}
94
		}
95
    	//die();
96
    	$this->lessphp->object()->ccompile('assets/css/shipping.less','assets/css/shipping.css');
97
        $data['stylesheet'] = 'shipping.css';
98
		$data['response']=$this->checkout_model->getCheckoutDetails($this->input->get(),$this->input->post(),$this->config->item('orderconfirmation'));
99
		// $this->session->unset_userdata('shipping');
100
		// $this->session->unset_userdata('billing');
101
		// $this->session->unset_userdata('shoppingId');
102
		$this->session->unset_userdata('hotspotId');
103
		$this->session->unset_userdata('addressId');
104
		$this->layout->view('checkout/checkout_view',$data);
105
	}
106
	public function payment()
107
	{
108
		//standard array
109
		//print_r($this->session->all_userdata())
110
		$authorized = $this->session->userdata('authorized');
111
		if(!isset($authorized) || empty($authorized)){
112
			redirect(base_url()."cart");
113
		}
114
 
115
		$data = array();
116
		$codCaptcha = $this->session->userdata('cod');
117
		if(isset($codCaptcha) && $codCaptcha == 1){
118
			$data['codCaptcha'] = 1;
119
			$this->session->unset_userdata('cod');
120
		}else{
121
			$data['codCaptcha'] = 0;
122
		}
123
		$paymentconfig = $this->config->item('payment');
124
		if(!isset($_POST['submit'])){
125
			$hotspot = $this->session->userdata('hotspotId');
126
			if(isset($hotspot) && !empty($hotspot)){
127
				$_GET['hotSpotAddressId'] = $hotspot;
128
				$_GET['deliveryLocation'] = 'hotSpot';
129
			}else{
130
				$_GET['deliveryLocation'] = 'myLocation';
131
			}
132
			unset($paymentconfig['response'][2]);
133
			if(isset($authorized) && !empty($authorized)){
134
				$_GET['userId'] = $authorized['Id'];
135
				$_GET['Id'] = $authorized['cartId'];
136
				if($authorized['isLoggedIn'] == 1){
137
					$_GET['isLoggedIn'] = 'true';
138
				}
139
				elseif(isset($authorized['isLoggedIn']) && empty($authorized['isLoggedIn'])) {
140
					$_GET['isLoggedIn'] = 'false';
141
				}
142
			}
143
			$addressId = $this->session->userdata('addressId');
144
			$_GET['addressid'] = $addressId;
145
			$this->lessphp->object()->ccompile('assets/css/shipping.less','assets/css/shipping.css');
146
      		$data['stylesheet'] = 'shipping.css';
147
			$data['response']=$this->checkout_model->getCheckoutDetails($this->input->get(),'',$paymentconfig);
148
			if(isset($data['response']['response']['payment_process'])){
149
				$result = json_decode($data['response']['response']['payment_process'][0]);
150
				$totalAmount = $result->results->totalAmount;
151
				if(isset($result->results->isTotalAmountZero)){
152
					$isTotalAmountZero = $result->results->isTotalAmountZero;
153
				}
154
				$totalAmount = number_format((float)$totalAmount,0,'.','');
155
				$captcha = $this->captcha_model->generateCaptcha();
10600 lgm 156
				echo 'captcha is'.'<br/>';
157
				print_r($captcha);
10582 lgm 158
				$this->session->set_userdata('captcha',$captcha['word']);
159
				$data['captcha'] = $captcha;
160
				// if($totalAmount == 0 && isset($isTotalAmountZero) && $isTotalAmountZero == 1){
161
				// 	$captcha = $this->captcha_model->generateCaptcha();
162
				// 	$this->session->set_userdata('captcha',$captcha['word']);
163
				// 	$this->session->set_userdata('captchaDisplay',$isTotalAmountZero);
164
				// 	$data['captcha'] = $captcha;
165
				// }
166
				$this->layout->view('checkout/checkout_view',$data);
167
			}
168
			else{
169
				redirect(base_url()."cart");
170
			}
171
		}
172
		elseif(isset($_POST['submit'])){
173
			if(isset($_POST['captcha_response_field']) && !empty($_POST['captcha_response_field'])){
174
				$captcha = $this->session->userdata('captcha');
175
				if(strcmp($captcha,$_POST['captcha_response_field']) != 0){
176
					if(isset($_POST['payoption']) && $_POST['payoption'] == 3000){
177
						$this->session->set_userdata('cod',1);
178
					}
179
        			redirect(base_url().'payment');
180
      			}
181
			}
182
			unset($paymentconfig['response'][0]);
183
			unset($paymentconfig['response'][1]);
184
			if(isset($authorized) && !empty($authorized)){
185
				$_POST['userId'] = $authorized['Id'];
186
				if($authorized['isLoggedIn'] == 1){
187
					$_POST['isLoggedIn'] = 'true';
188
				}
189
				elseif(isset($authorized['isLoggedIn']) && empty($authorized['isLoggedIn'])) {
190
					$_POST['isLoggedIn'] = 'false';
191
				}
192
			}
193
			$addressId = $this->session->userdata('addressId');
194
			$_POST['addressid'] = $addressId;
195
			$_POST['payment_option'] = $_POST['payoption'];
196
			$data['response']=$this->checkout_model->getCheckoutDetails($this->input->get(),$this->input->post(),$paymentconfig);
197
			if(isset($data['response']['response']['payment_submit'][0]) && !empty($data['response']['response']['payment_submit'][0])){
198
				$paymentSubmit = $data['response']['response']['payment_submit'][0];
199
				if(isset($paymentSubmit->response->isPaymentRedirect) && $paymentSubmit->response->isPaymentRedirect == 1){
200
					$image = base_url().'/images/loading.gif';
201
					$location = $paymentSubmit->response->redirectUrl;
202
					echo '<html><head><meta http-equiv="refresh" content="2;url='.$paymentSubmit->response->redirectUrl.'">
203
  					<title>Saholic Mobile Site: Redirecting to <'.$paymentSubmit->response->gatewayName.'> Payment Gateway</title>
204
 					</head>
205
 						<body>
206
     					<div style="text-align:center; margin-top:200px;">Please wait while we redirect you to the Payment Gateway.</div>
207
     					<div align="center" class="img">
208
      					<img title="loading" alt="loading" src="'.$image.'">
209
     					</div>
210
 						</body>
211
						</html>';
212
				}elseif(strpos($paymentSubmit->response->redirectUrl, 'ebs-pay') !== false){
213
					$url = $this->config->item('curl_base_url').$paymentSubmit->response->redirectUrl;
214
					//echo $url;
215
					$authorized = $this->session->userdata('authorized');
216
					if(isset($authorized) && !empty($authorized)){
217
						$params['userId'] = $authorized['Id'];
218
						if($authorized['isLoggedIn'] == 1){
219
							$params['isLoggedIn'] = 'true';
220
						}
221
						elseif(isset($authorized['isLoggedIn']) && empty($authorized['isLoggedIn'])) {
222
							$params['isLoggedIn'] = 'false';
223
						}
224
					}
225
					$this->mcurl->add_call('ebs','get',$url,$params);
226
         			$response = $this->mcurl->execute($url);
227
         			$data['response'] = $response['ebs']['response'];
228
         			$response = $this->magento_model->payment_submit($data);
229
         			if(isset($response) && !empty($response)){
230
         				$ebs = $response[0]->response;
231
         				echo '<html>
232
						<head>
233
						 <title>m.saholic.com: Redirecting to EBS Payment Page</title>
234
						</head>
235
						<body>
236
						    <div style="text-align:center; margin-top:200px;">Please wait while we redirect you to the Payment Gateway.</div>
237
						 <div align="center" class="img">
238
						  <img title="loading" alt="loading" src="'.base_url().'assets/images/loading.gif">
239
						 </div>
240
						 <div style="display:none">
241
						  <form  method="post" action="'.$ebs->postAction.'" name="frmTransaction" id="frmTransaction">  
242
				           <!-- Account Id -->
243
				           <input name="account_id" type="hidden" value="'.$ebs->account_id.'" />
244
				           <!-- Transaction Details -->
245
				           <input name="reference_no" type="hidden" value="'.$ebs->reference_no.'" />
246
				           <input name="amount" type="hidden" value="'.$ebs->amount.'" />
247
				           <input name="description" type="hidden" value="'.$ebs->description.'" />
248
				           <input name="payment_option" type="hidden" value="'.$ebs->payment_option.'"/>
249
				           <!-- Billing Address -->
250
				           <input name="name" type="hidden" value="'.$ebs->name.'" />
251
				           <input name="address" type="hidden" value="'.$ebs->address.'" />
252
				           <input name="city" type="hidden" value="'.$ebs->city.'" />
253
				           <input name="state" type="hidden" value="'.$ebs->state.'" />
254
				           <input name="postal_code" type="hidden" value="'.$ebs->postal_code.'" />
255
				           <input name="country" type="hidden" value="IND"/>
256
				           <input name="email" type="hidden" value="'.$ebs->email.'" />
257
				           <input name="phone" type="hidden" value="'.$ebs->phone.'" />
258
				           <!-- Delivery Address -->
259
				           <input name="ship_name" type="hidden" value="'.$ebs->ship_name.'" />
260
				           <input name="ship_address" type="hidden" value="'.$ebs->ship_address.'" />
261
				           <input name="ship_city" type="hidden" value="'.$ebs->ship_city.'" />
262
				           <input name="ship_state" type="hidden" value="'.$ebs->ship_state.'" />
263
				           <input name="ship_postal_code" type="hidden" value="'.$ebs->ship_postal_code.'" />
264
				           <input name="ship_country" type="hidden" value="IND"/> 
265
				           <input name="ship_phone" type="hidden" value="'.$ebs->ship_phone.'" />
266
				           <input name="return_url" type="hidden" value="'.$ebs->return_url.'" />
267
				           <input name="mode" value="'.$ebs->mode.'"/>
268
				           <input name="secure_hash" type="hidden" value="'.$ebs->secure_hash.'" />
269
				           <input name="channel" type="hidden" value="'.$ebs->channel.'" />
270
				           <input name="page_id" type="hidden" value="'.$ebs->page_id.'" />
271
				           <input name="submitted" value="Submit" type="submit" /> 
272
				           <input value="Reset" type="reset" />
273
						  </form>
274
						    </div>
275
						    <script type="text/javascript">
276
						     document.getElementById("frmTransaction").submit();
277
						    </script>
278
						  </body>
279
						</html>';
280
         			}else{
281
         				redirect(base_url().'payment');
282
         			}
283
				}
284
				else{
285
					redirect(base_url().$paymentSubmit->response->redirectUrl);
286
				}
287
			}
288
			else{
289
			redirect(base_url()."payment");	
290
			}
291
		}
292
 
293
	}
294
	public function ebsprocessing(){
295
		if(isset($_GET['DR']) && !empty($_GET['DR'])){
296
			$paymentconfig = $this->config->item('ebsProcessing');
297
			$authorized = $this->session->userdata('authorized');
298
			if(isset($authorized) && !empty($authorized)){
299
				$_GET['userId'] = $authorized['Id'];
300
				if($authorized['isLoggedIn'] == 1){
301
					$_GET['isLoggedIn'] = 'true';
302
				}
303
				elseif(isset($authorized['isLoggedIn']) && empty($authorized['isLoggedIn'])) {
304
					$_GET['isLoggedIn'] = 'false';
305
				}
306
			}
307
			$data['response']=$this->checkout_model->getCheckoutDetails($this->input->get(),$this->input->post(),$paymentconfig);
308
			if(isset($data['response']['response']['ebs_processing'][0]->response)){
309
				$redirectUrl = $data['response']['response']['ebs_processing'][0]->response->redirectUrl;
310
				$redirectUrl = explode('?', $redirectUrl);
311
				$redirectUrl = base_url().'ebs-pay-response/?'.$redirectUrl[1];
312
				echo '<html><head><meta http-equiv="refresh" content="2;url='.$redirectUrl.'">
313
  					<title>Saholic Mobile Site:</title>
314
 					</head>
315
 						<body>
316
     					<div style="text-align:center; margin-top:200px;">'.$data['response']['response']['ebs_processing'][0]->response->redirectMessage.'</div>
317
     					<div align="center" class="img">
318
      					<img title="loading" alt="loading" src="">
319
     					</div>
320
 						</body>
321
						</html>';
322
			}
323
		}
324
	}
325
	public function ebsresponse(){
326
		if(isset($_GET['DR']) && !empty($_GET['DR'])){
327
			$paymentconfig = $this->config->item('ebsResponse');
328
			$authorized = $this->session->userdata('authorized');
329
			if(isset($authorized) && !empty($authorized)){
330
				$_GET['userId'] = $authorized['Id'];
331
				if($authorized['isLoggedIn'] == 1){
332
					$_GET['isLoggedIn'] = 'true';
333
				}
334
				elseif(isset($authorized['isLoggedIn']) && empty($authorized['isLoggedIn'])) {
335
					$_GET['isLoggedIn'] = 'false';
336
				}
337
			}
338
			$data['response']=$this->checkout_model->getCheckoutDetails($this->input->get(),$this->input->post(),$paymentconfig);
339
			if(isset($data['response']['response']['ebs_response'][0]->response) && !empty($data['response']['response']['ebs_response'][0]->response)){
340
				$redirectUrl = $data['response']['response']['ebs_response'][0]->response->redirectUrl;
341
				redirect($redirectUrl);
342
			}
343
			else{
344
				redirect(base_url().'payment');
345
			}
346
		}
347
	}
348
	public function hdfcPayResponse(){
349
		if(isset($_POST)){
350
			$paymentconfig = $this->config->item('hdfcResponse');
351
			$authorized = $this->session->userdata('authorized');
352
			if(isset($authorized) && !empty($authorized)){
353
				$_POST['userId'] = $authorized['Id'];
354
				if($authorized['isLoggedIn'] == 1){
355
					$_POST['isLoggedIn'] = 'true';
356
				}
357
				elseif(isset($authorized['isLoggedIn']) && empty($authorized['isLoggedIn'])) {
358
					$_POST['isLoggedIn'] = 'false';
359
				}
360
			}
361
			$data['response']=$this->checkout_model->getCheckoutDetails($this->input->get(),$this->input->post(),$paymentconfig);
362
			if(isset($data['response']['response']['hdfc_response'][0]->response) && !empty($data['response']['response']['hdfc_response'][0]->response)){
363
				$redirectUrl = $data['response']['response']['hdfc_response'][0]->response->redirectUrl;
364
				redirect($redirectUrl);
365
			}
366
			else{
367
				redirect(base_url());
368
			}	
369
		}else{
370
			redirect(base_url());
371
		}
372
	}
373
	public function innovitiPayment(){
374
		$last = $this->uri->total_segments();
375
		$itemcode = $this->uri->segment($last);
376
		if(isset($itemcode) && !empty($itemcode)){
377
			$url = $this->config->item('curl_base_url').'innoviti-pay/'.$itemcode;
378
			$params = array();
379
			$authorized = $this->session->userdata('authorized');
380
			if(isset($authorized) && !empty($authorized)){
381
				$params['userId'] = $authorized['Id'];
382
				if($authorized['isLoggedIn'] == 1){
383
					$params['isLoggedIn'] = 'true';
384
				}
385
				elseif(isset($authorized['isLoggedIn']) && empty($authorized['isLoggedIn'])) {
386
					$params['isLoggedIn'] = 'false';
387
				}
388
			$this->mcurl->add_call('innoviti','get',$url,$params);
389
 			$response = $this->mcurl->execute($url);
390
 			$data['response'] = $response['innoviti']['response'];
391
         	$response = $this->magento_model->payment_submit($data);
392
         	if(isset($response) && !empty($response)){
393
         		$innoviti = $response[0]->response;
10592 lgm 394
         		echo '
395
         			<div style="text-align:center; margin-top:200px;">Please wait while we redirect you to the Payment Gateway.</div>
396
						 <div align="center" class="img">
397
						  <img title="loading" alt="loading" src="../assets/images/loading.gif">
398
						 </div>
399
         			<form  method="post" action="'.$innoviti->action.'" name="frmTransaction" id="frmTransaction">  
10582 lgm 400
           				<input name="merchantId" type="hidden" value="'.$innoviti->merchantId.'" />
401
     					<input name="subMerchantId" type="hidden" value="'.$innoviti->subMerchantId.'" />
402
           				<!-- Transaction Details -->
403
           				<input name="orderId" type="hidden" value="'.$innoviti->orderId.'" />
404
     					<input name="amt" type="hidden" value="'.$innoviti->amt.'" />   
405
     					<input name="cur" type="hidden" value="INR" />
406
     					<input name="processingCode" type="hidden" value="'.$innoviti->processingCode.'" />
407
     					<input name="proSku" type="hidden" value="'.$innoviti->proSku.'" />
408
           				<input name="Cname" type="hidden" value="'.$innoviti->Cname.'" /></td>
409
     					<input name="mobile" type="hidden" value="'.$innoviti->mobile.'" />
410
     					<input name="emailId" type="hidden" value="'.$innoviti->emailId.'" />     
411
   						<input name="redirUrl" type="hidden" value="'.$innoviti->redirUrl.'" />
412
     					<input name="chksum" type="hidden" value="'.$innoviti->chksum.'" />
413
     					<input name="isCtx" type="hidden" value="NO" />
414
           				<script type="text/javascript">
415
						    document.getElementById("frmTransaction").submit();
416
						</script>
417
      				  </form>';
418
         	}
419
			}else{
420
				redirect(base_url());
421
			}
422
 
423
		}else{
424
			redirect(base_url());
425
		}
426
	}
427
	public function innovitiResponse(){
428
		if(isset($_POST)){
429
			$paymentconfig = $this->config->item('innovitiResponse');
430
			$authorized = $this->session->userdata('authorized');
431
			if(isset($authorized) && !empty($authorized)){
432
				$_POST['userId'] = $authorized['Id'];
433
				if($authorized['isLoggedIn'] == 1){
434
					$_POST['isLoggedIn'] = 'true';
435
				}
436
				elseif(isset($authorized['isLoggedIn']) && empty($authorized['isLoggedIn'])) {
437
					$_POST['isLoggedIn'] = 'false';
438
				}
439
			}
440
			$data['response']=$this->checkout_model->getCheckoutDetails($this->input->get(),$this->input->post(),$paymentconfig);
441
			if(isset($data['response']['response']['innoviti_response'][0]->response) && !empty($data['response']['response']['innoviti_response'][0]->response)){
442
				$redirectUrl = $data['response']['response']['innoviti_response'][0]->response->redirectUrl;
443
				redirect($redirectUrl);
444
			}
445
			else{
446
				redirect(base_url());
447
			}	
448
		}else{
449
			redirect(base_url());
450
		}
451
	}
452
	public function paymenterror(){
453
			$authorized = $this->session->userdata('authorized');
454
			if(isset($authorized) && !empty($authorized)){
455
				$data = array();
456
				$paymentconfig = $this->config->item('paymenterror');
457
				$data['stylesheet'] = 'shipping.css';
458
				$data['response']=$this->checkout_model->getCheckoutDetails($this->input->get(),$this->input->post(),$paymentconfig);
459
				$this->layout->view('checkout/checkout_view',$data);
460
			}else{
461
				redirect(base_url());
462
			}
463
	}
464
	public function shipping()
465
	{
466
 
467
		$data = array();
468
		$authorized = $this->session->userdata('authorized');
469
		if($authorized['isLoggedIn'] != 1){
470
			$this->session->set_userdata('location','shipping');
471
			redirect(base_url()."login");
472
		}
473
		$shippingconfig = $this->config->item('shipping');
474
		if(!isset($_POST['submit']))
475
		{
476
			$authorized = $this->session->userdata('authorized');
477
				if(isset($authorized) && !empty($authorized)){
478
					$_GET['userId'] = $authorized['Id'];
479
					$_GET['Id'] = $authorized['cartId'];
480
					if($authorized['isLoggedIn'] == 1){
481
						$_GET['isLoggedIn'] = 'true';
482
					}
483
					elseif(isset($authorized['isLoggedIn']) && empty($authorized['isLoggedIn'])) {
484
						$_GET['isLoggedIn'] = 'false';
485
					}
486
				}
487
			$this->lessphp->object()->ccompile('assets/css/shipping.less','assets/css/shipping.css');
488
			$data['stylesheet'] = 'shipping.css';
489
			$cache = getFileCache('pickup');
490
			if(isset($cache) && !empty($cache)){
491
				unset($shippingconfig['response'][1]);
492
				$data['response']=$this->checkout_model->getCheckoutDetails($this->input->get(),$this->input->post(),$shippingconfig);
493
				$data['response']['response']['pickup'] = $cache;
494
			}else{
495
				$data['response']=$this->checkout_model->getCheckoutDetails($this->input->get(),$this->input->post(),$shippingconfig);
496
        		if(isset($data['response']['response']['pickup']) && !empty($data['response']['response']['pickup']))
497
        		setFileCache($data['response']['response']['pickup'], 'pickup',900);
498
			}
499
			$this->layout->view('checkout/checkout_view',$data);
500
		}
501
		if(isset($_POST['submit']))
502
		{
503
			unset($shippingconfig['response'][1]);	
504
			$data = $this->get_shipping_billing($_POST);
505
			$this->session->set_userdata($data);
506
			$authorized = $this->session->userdata('authorized');
507
			if(isset($authorized) && !empty($authorized)){
508
				$_POST['userId'] = $authorized['Id'];
509
				//$_POST['Id'] = $authorized['cartId'];
510
					if($authorized['isLoggedIn'] == 1){
511
						$_POST['isLoggedIn'] = 'true';
512
					}
513
					elseif(isset($authorized['isLoggedIn']) && empty($authorized['isLoggedIn'])) {
514
						$_POST['isLoggedIn'] = 'false';
515
					}
516
				}
517
			//$data['stylesheet'] = 'shipping.less';
518
			$data['response']=$this->checkout_model->getCheckoutDetails($this->input->get(),$this->input->post(),$shippingconfig);
519
			//$this->layout->view('checkout/checkout_view',$data);
520
			redirect(base_url()."shipping");
521
 
522
		}
523
 
524
	}
525
	public function shippingmode()
526
	{
527
		$data = array();
528
		$shippingconfig = $this->config->item('shippingmethod');
529
		if(!isset($_POST['submit']))
530
		{
531
			unset($shippingconfig['response'][1]);
532
			$data['response']['address']=$this->checkout_model->getCheckoutDetails($this->input->get(),$this->input->post(),$shippingconfig);
533
			$this->layout->view('checkout/checkout_view',$data);
534
		}
535
		if(isset($_POST['submit']))
536
		{
537
			unset($shippingconfig['response'][0]);
538
			$data['response']=$this->checkout_model->getCheckoutDetails($this->input->get(),$this->input->post(),$shippingconfig);
539
			if($data['response']['response']['shippingmethod_submit'][0] == 1){
540
			redirect(base_url().strtolower(__CLASS__)."/payment");
541
			}
542
			else{
543
			redirect(base_url().strtolower(__CLASS__)."/shippingmode");	
544
			}
545
 
546
		}
547
	}
548
	public function review()
549
	{
550
		//standard array
551
		$authorized = $this->session->userdata('authorized');
552
		if(isset($authorized) and !empty($authorized['id']))
553
		{
554
			//if user logged-in
555
			$_GET['customerId'] = $authorized['id'];
556
		}
557
		$data = array();
558
		$data['response']=$this->checkout_model->getCheckoutDetails($this->input->get(),$this->input->post(),$this->config->item('review'));
559
		if(isset($data['response']['response']['review_process']) && !empty($data['response']['response']['review_process'])){
560
		$this->layout->view('checkout/checkout_view',$data);
561
		}
562
		else{
563
			redirect(base_url().strtolower(__CLASS__)."/shipping");
564
		}
565
	}
566
 
567
	public function get_shipping_billing($data=array()){
568
		$billing =array();
569
		$shipping =array();
570
		if (isset($data) && !empty($data)) {
571
			$shipping=array('name'  => $data['name'],'line1' => $data['line1'],'line2' => $data['line2'], 'city' => $data['city'], 'pin' => $data['pin'], 'phonenumber' => $data['phone']);
572
			return array('shipping'=>$shipping,'billing'=>$billing);
573
		}
574
	}
575
 
576
	public function delete($addressId){
577
		$shippingconfig = $this->config->item('shipping_delete');
578
		$_GET['addressId'] = $addressId;
579
		$authorized = $this->session->userdata('authorized');
580
		if(isset($authorized) && !empty($authorized)){
581
			$_GET['userId'] = $authorized['Id'];
582
			$_GET['Id'] = $authorized['cartId'];
583
			if($authorized['isLoggedIn'] == 1){
584
				$_GET['isLoggedIn'] = 'true';
585
			}
586
			elseif(isset($authorized['isLoggedIn']) && empty($authorized['isLoggedIn'])) {
587
				$_GET['isLoggedIn'] = 'false';
588
				}
589
			}
590
			$data['response']=$this->checkout_model->getCheckoutDetails($this->input->get(),$this->input->post(),$shippingconfig);
591
			print_r($data['response']);
592
		}
593
 
594
	public function changeAddress($addressId,$type){
595
		if(isset($addressId) && isset($type)){
596
		$shippingconfig = $this->config->item('shipping_change');
597
		$_GET['addressId'] = $addressId;
598
		$_GET['addressType'] = $type;
599
		$authorized = $this->session->userdata('authorized');
600
		if(isset($authorized) && !empty($authorized)){
601
			$_GET['userId'] = $authorized['Id'];
602
			$_GET['Id'] = $authorized['cartId'];
603
			if($authorized['isLoggedIn'] == 1){
604
				$_GET['isLoggedIn'] = 'true';
605
			}
606
			elseif(isset($authorized['isLoggedIn']) && empty($authorized['isLoggedIn'])) {
607
				$_GET['isLoggedIn'] = 'false';
608
				}
609
			}
610
			$data['response']=$this->checkout_model->getCheckoutDetails($this->input->get(),$this->input->post(),$shippingconfig);
611
			$this->session->set_userdata('addressId',$addressId);
612
			print_r($data['response']['response']['changeAddress'][0]->message);
613
		}
614
	}
615
	public function changeCaptcha(){
616
		$captchaDisplay = $this->session->userdata('captchaDisplay');
617
		//if(isset($captchaDisplay) && $captchaDisplay == 1){
618
			$captcha = $this->captcha_model->generateCaptcha();
619
			$this->session->set_userdata('captcha',$captcha['word']);
620
			unset($captcha['word']);
621
			unset($captcha['time']);
622
			unset($captcha['name']);
623
			echo json_encode($captcha);
624
		//}
625
	}
626
	public function insuranceInfo($bday,$gname,$addressId){
627
	if((isset($bday) && !empty($bday)) && (isset($gname) && !empty($gname)) && (isset($addressId) && !empty($addressId))){
628
		if(isset($gname) && !empty($gname)){
629
			$gname = str_replace('-','',$gname);
630
			$gname = ltrim($gname);
631
			$gname = rtrim($gname);
632
			$_GET['guardianName'] = $gname;
633
		}
634
		if(isset($bday) && !empty($bday)){
635
			$dob = explode('-',$bday);
636
			$dob = array_reverse($dob);
637
			$temp1 = $dob[1];
638
			$temp2 = $dob[0];
639
			$dob[0] = $temp1;
640
			$dob[1] = $temp2;
641
			$dob = implode('/', $dob);
642
			$_GET['dob'] = $dob; 
643
		}
644
		$insuranceconfig = $this->config->item('insurance_info');
645
		$_GET['addressId'] = $addressId;
646
		$data['response']=$this->checkout_model->getCheckoutDetails($this->input->get(),$this->input->post(),$insuranceconfig);
647
		if(isset($data['response']['response']['insuranceInfo'][0]->response) && (!empty($data['response']['response']['insuranceInfo'][0]->response))) {
648
			echo json_encode($data['response']['response']['insuranceInfo'][0]);
649
		}
650
	}
651
  }
652
  public function pickupSpot($id){
653
  	if(isset($id) && !empty($id) && is_numeric($id)){
654
  		$this->session->set_userdata('hotspotId',$id);
655
  		$response['msg'] = 'sucess';
656
  		echo json_encode($response);
657
  	}
658
  }
659
 
660
}
661
 
662
 
663
/* End of file welcome.php */
664
/* Location: ./application/controllers/welcome.php */