Subversion-Projekte lars-tiefland.ci

Revision

Revision 2007 | Details | Vergleich mit vorheriger | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
514 lars 1
<?php
2
 
3
/**
4
 * @author Lars Tiefland
5
 * @copyright 2016
6
 */
7
 
520 lars 8
/**
9
 * Order
10
 *
11
 * Abwicklung des Bestellvorgangs
12
 * Prüfung der einzelnen Formularfelder
13
 *
525 lars 14
 * @package WebanOS CI
15
 * @author Lars Tiefland
16
 * @copyright 2016
17
 * @version $Id: Order.php 2009 2017-02-02 19:24:35Z lars $
520 lars 18
 * @access public
19
 */
514 lars 20
class Order extends CI_Controller
21
{
520 lars 22
	/**
23
	 * Order::__construct()
24
	 *
25
	 * @return
26
	 */
514 lars 27
	public function __construct()
28
	{
29
		parent::__construct();
688 lars 30
		if (!isset($_SESSION['SHOP']['buy']['Persdata']))
31
		{
32
			$_SESSION['SHOP']['buy']['Persdata'] = array();
33
		}
34
		if (!isset($_SESSION['SHOP']['BASKET']))
35
		{
36
			$_SESSION['SHOP']['BASKET'] = array();
37
		}
38
 
514 lars 39
		$GLOBALS['order_db'] = $this->load->database('order_db', TRUE);
40
		$GLOBALS['db_red'] = $this->load->database('db_red', TRUE);
575 lars 41
		$anreden = array(
576 lars 42
			$GLOBALS['langstrings']['buy']['mr'] => $GLOBALS['langstrings']['buy']['mr'],
43
			$GLOBALS['langstrings']['buy']['mrs'] => $GLOBALS['langstrings']['buy']['mrs'],
575 lars 44
			);
45
		$this->smarty->assign('anreden', $anreden);
514 lars 46
		$this->load->model('Order_model', 'order');
675 lars 47
		$this->load->model('artikel_model', 'artikel');
514 lars 48
		$versand_laender = getVersandLaender();
49
		$this->smarty->assign('Laender', $versand_laender);
50
	}
51
 
520 lars 52
	/**
53
	 * Order::index()
54
	 *
55
	 * @return
56
	 */
684 lars 57
	public function index($bStep = 1)
514 lars 58
	{
712 lars 59
		$thirdPartyMethods = array();
514 lars 60
		$step = $this->input->post('step');
61
		if (!$step)
62
		{
684 lars 63
			$step = $bStep;
514 lars 64
		}
2007 lars 65
		if (@$_GET["account"])
66
		{
67
			$_SESSION["account"] = $_GET["account"];
68
		}
690 lars 69
		$this->update_versand();
646 lars 70
		switch ($this->input->post('action'))
514 lars 71
		{
646 lars 72
			case "Persdata":
674 lars 73
				$req_error = true;
641 lars 74
				if ($this->input->post('Persdata'))
640 lars 75
				{
641 lars 76
					$userData = $this->input->post('Persdata');
77
					if ($this->input->post('Lieferadresse') === "false")
629 lars 78
					{
641 lars 79
						$userData['liefer_Anrede'] = $userData['Anrede'];
80
						$userData['liefer_Vorname'] = $userData['Vorname'];
81
						$userData['liefer_Nachname'] = $userData['Nachname'];
82
						$userData['liefer_Firma'] = $userData['Firma'];
83
						$userData['liefer_Strasse'] = $userData['Strasse'];
84
						$userData['liefer_Hausnummer'] = $userData['Hausnummer'];
85
						$userData['liefer_PLZ'] = $userData['PLZ'];
86
						$userData['liefer_Ort'] = $userData['Ort'];
87
						$userData['liefer_email'] = $userData['email'];
88
						$userData['liefer_Telefon'] = $userData['Telefon'];
89
					}
663 lars 90
					elseif ($this->input->post('Lieferadresse') === "true")
91
					{
664 lars 92
						if ($this->form_validation->run('liefer') === false)
663 lars 93
						{
94
							$errormsg_liefer["liefer_Vorname"] = form_error('Persdata[liefer_Vorname]');
95
							$errormsg_liefer["liefer_Nachname"] = form_error('Persdata[liefer_Nachname]');
96
							$errormsg_liefer["liefer_Strasse"] = form_error('Persdata[liefer_Strasse]');
97
							$errormsg_liefer["liefer_Hausnummer"] = form_error('Persdata[liefer_Hausnummer]');
98
							$errormsg_liefer["liefer_PLZ"] = form_error('Persdata[liefer_PLZ]');
99
							$errormsg_liefer["liefer_Ort"] = form_error('Persdata[liefer_Ort]');
100
							$this->smarty->assign('errormsg_liefer', $errormsg_liefer);
101
							unset($_GET['subStep']);
102
						}
103
					}
742 lars 104
					elseif ($this->input->post('Lieferadresse') == "packstation")
105
					{
106
						if ($this->form_validation->run('packstation') === false)
107
						{
745 lars 108
							$errormsg_liefer["liefer_Vorname_pst"] = form_error('Persdata[liefer_Vorname_pst]');
109
							$errormsg_liefer["liefer_Nachname_pst"] = form_error('Persdata[liefer_Nachname_pst]');
110
							$errormsg_liefer["liefer_Firma_pst"] = form_error('Persdata[liefer_Firma_pst]');
111
							$errormsg_liefer["liefer_Hausnummer_pst"] = form_error('Persdata[liefer_Hausnummer_pst]');
112
							$errormsg_liefer["liefer_PLZ_pst"] = form_error('Persdata[liefer_PLZ_pst]');
113
							$errormsg_liefer["liefer_Ort_pst"] = form_error('Persdata[liefer_Ort_pst]');
742 lars 114
							$this->smarty->assign('errormsg_liefer', $errormsg_liefer);
115
							unset($_GET['subStep']);
116
						}
117
					}
641 lars 118
					$_SESSION['SHOP']['buy']['Persdata'] = $userData;
735 lars 119
					$_SESSION['SHOP']['Lieferadresse'] = $this->input->post('Lieferadresse');
689 lars 120
					$this->update_versand();
666 lars 121
					$this->form_validation->reset_validation();
641 lars 122
					if ($this->form_validation->run('guest') === false)
123
					{
124
						$errormsg_rechnung["Vorname"] = form_error('Persdata[Vorname]');
125
						$errormsg_rechnung["Nachname"] = form_error('Persdata[Nachname]');
126
						$errormsg_rechnung["Strasse"] = form_error('Persdata[Strasse]');
127
						$errormsg_rechnung["Hausnummer"] = form_error('Persdata[Hausnummer]');
128
						$errormsg_rechnung["PLZ"] = form_error('Persdata[PLZ]');
129
						$errormsg_rechnung["Ort"] = form_error('Persdata[Ort]');
130
						$errormsg_rechnung["email"] = form_error('Persdata[email]');
131
						$errormsg_rechnung["Telefon"] = form_error('Persdata[Telefon]');
132
						$this->smarty->assign('errormsg_rechnung', $errormsg_rechnung);
133
						unset($_GET['subStep']);
134
					}
135
					else
136
					{
666 lars 137
						$this->form_validation->reset_validation();
641 lars 138
						if ($this->input->post('account') == 'new')
629 lars 139
						{
641 lars 140
							if ($this->form_validation('new') === false)
141
							{
674 lars 142
								$req_error = false;
641 lars 143
							}
629 lars 144
						}
674 lars 145
						else
146
						{
147
							$req_error = false;
148
						}
629 lars 149
					}
150
				}
674 lars 151
				if (!$req_error)
152
				{
153
					$_SESSION["SHOP"]['VERSAND'] = array();
154
 
1995 lars 155
					$vItem = $this->artikel->get_artikel($_POST["Versand"], true, true);
674 lars 156
					$VersandItem = array(
157
						"Menge" => 1,
158
						"ID" => $_POST['Versand'],
159
						"Versand" => true,
2009 lars 160
						'preis' => $vItem['preis1'],
701 lars 161
						'kurzbezeichnung' => $vItem['kurzbezeichnung'],
674 lars 162
						);
163
					$_SESSION['SHOP']['VERSAND'] = $VersandItem;
164
					$_SESSION["SHOP"]["buy"]["Versand"] = true;
165
					if ($GLOBALS["INI"]["PayPalPlus"]["aktiv"] == 1)
166
					{
167
						$customMethods = array(
168
							"vorkasse",
169
							"selbstabholung",
170
							"ratenzahlung",
171
							"nachnahme",
172
							"sofortueberweisung",
173
							);
680 lars 174
						$buy_link_base = 'https://ci.starfleethq.de/';
674 lars 175
						if ($GLOBALS["INI"]["ssl_buy"] == 1)
176
						{
177
							$buy_link_base = str_replace("http:", "https:", $buy_link_base);
178
						}
680 lars 179
						$url = $buy_link_base."/bestellen_seite_2.order";
676 lars 180
						$versandOptionen = get_versandkosten($_SESSION['SHOP']['buy']['Persdata']['liefer_Land']);
674 lars 181
						foreach ($versandOptionen as $o_id => $opt)
182
						{
183
							//admin_debug( $opt["rufname"] );
184
							$rufname = strtolower($opt["rufname"]);
185
							if ($GLOBALS["INI"]["dbConnect"]["db_is_utf8"] != 1)
186
							{
187
								$opt["kurz"] = utf8_encode($opt["kurz"]);
188
								$opt["beschr"] = utf8_encode($opt["beschr"]);
189
							}
190
							if (in_array($rufname, $customMethods))
191
							{
192
								$method = array(
193
									"redirectUrl" => $url,
194
									"methodName" => $opt["kurz"],
195
									"description" => $opt["beschr"],
196
									);
197
								$imgBase = "/images/webelemente/versand_";
198
								$imgName = $imgBase.$rufname.".jpg";
199
								$imgUrl = "https://".$_SERVER["SERVER_NAME"].$imgName;
200
								$imgNameFull = $_SERVER["DOCUMENT_ROOT"].$imgName;
201
								if ($GLOBALS["INI"]["ssl_buy"] == 1)
202
								{
203
									if (file_exists($imgNameFull))
204
									{
205
										$method["imageUrl"] = $imgUrl;
206
									}
207
								}
208
								$thirdPartyMethods[] = $method;
209
							}
210
							$payPal3rdParty = json_encode($thirdPartyMethods);
211
							require_once "module/creditcard/paypalPlus.php";
212
							$c = new paypalPlus();
213
							$apporvalUrl = $c->getCreditcardStatus(null);
679 lars 214
							$this->smarty->assign("paymentMethods", $payPal3rdParty);
215
							$this->smarty->assign("approvalUrl", $apporvalUrl);
674 lars 216
						}
217
					}
218
				}
514 lars 219
				break;
646 lars 220
			case "Versand":
1995 lars 221
				$vItem = $_SESSION['SHOP']['VERSAND'];
2002 lars 222
				if (strtolower($vItem["rufname"]) == "paypal" || strtolower($vItem["rufname"]) ==
1993 lars 223
					"ratenzahlung")
224
				{
225
					if ($GLOBALS["INI"]["paypal"]["usesApi"] == 1)
226
					{
227
						require_once "module/creditcard/paypal.php";
228
						$c = new paypal();
229
						$c->getCreditcardStatus(null);
230
						//
231
					}
232
				}
646 lars 233
				break;
234
			case "execute":
644 lars 235
				if ($this->form_validation->run('execute') === false)
236
				{
237
					$step = 2;
238
					$errormsg_kontrolle = validation_errors();
239
					$this->smarty->assign('errormsg_kontrolle', $errormsg_kontrolle);
240
				}
667 lars 241
				else
242
				{
243
					$this->save();
244
				}
644 lars 245
				break;
514 lars 246
		}
247
		$_SESSION['SHOP']['buy']['step'] = $step;
248
		$this->smarty->view('buy.tpl');
249
	}
250
 
520 lars 251
	/**
252
	 * Order::save()
253
	 *
254
	 * @return
255
	 */
514 lars 256
	public function save()
257
	{
258
		$this->order->create();
259
	}
668 lars 260
 
261
	public function update_versand()
262
	{
705 lars 263
		$land = 47;
704 lars 264
		if (isset($_SESSION['SHOP']['buy']['Persdata']['liefer_Land']))
265
		{
266
			$land = $_SESSION['SHOP']['buy']['Persdata']['liefer_Land'];
267
		}
690 lars 268
		$versandOptinen = get_versandkosten($land);
669 lars 269
		if ($GLOBALS['INI']['PayPalPlus']['aktiv'] == 1)
668 lars 270
		{
271
			foreach ($versandOptinen as $opt)
272
			{
672 lars 273
				if ($opt['rufname'] == 'PayPalPlus')
668 lars 274
				{
275
					$pppVersand = $opt['ID'];
276
					break;
277
				}
278
			}
674 lars 279
			if ($this->input->get('Land') || $this->input->get('liefer'))
280
			{
281
				echo $pppVersand;
282
			}
283
			else
284
			{
285
				$this->smarty->assign("ppplusVersand", $pppVersand);
286
			}
668 lars 287
		}
288
		else
289
		{
290
			foreach ($versandOptinen as $opt)
291
			{
292
				if ($opt["rufname"] == "amazon" || $opt["rufname"] == "PayPalExpress")
293
				{
294
					continue;
295
				}
296
				elseif ($_GET["packstation"] == 1 && !stristr($opt["kurz"], "DHL"))
297
				{
298
					continue;
299
				}
300
				if ($_GET["kurier"] == 1 && $opt["express"] != 1)
301
				{
302
					continue;
303
				}
304
				if ($GLOBALS['INI']['charset'] == "utf-8" && $GLOBALS['INI']['dbConnect']['db_is_utf8'] !=
305
					1)
306
				{
307
					$opt["kurz"] = utf8_encode($opt["kurz"]);
308
					$opt['beschr'] = utf8_encode($opt['beschr']);
309
				}
310
				$opt['beschr'] = str_replace("\r\n", "<br>", $opt['beschr']);
311
 
312
				if (($_SESSION["SHOP"]["buy"]["Versand_selected"] == $opt["ID"]) || (!$_SESSION["SHOP"]["buy"]["Versand_selected"] &&
313
					$o_id == 0))
314
				{
315
					$opt["checked"] = 'checked="checked"';
316
				}
317
				$v_opt[] = $opt;
318
			}
319
			$this->smarty->assign("versandOptionen", $v_opt);
320
		}
321
	}
514 lars 322
}
323
 
233 lars 324
?>