Subversion-Projekte lars-tiefland.ci

Revision

Revision 2005 | Revision 2007 | Zur aktuellen Revision | 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 2006 2017-02-01 21:18:08Z 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
		}
690 lars 65
		$this->update_versand();
646 lars 66
		switch ($this->input->post('action'))
514 lars 67
		{
646 lars 68
			case "Persdata":
674 lars 69
				$req_error = true;
641 lars 70
				if ($this->input->post('Persdata'))
640 lars 71
				{
641 lars 72
					$userData = $this->input->post('Persdata');
73
					if ($this->input->post('Lieferadresse') === "false")
629 lars 74
					{
641 lars 75
						$userData['liefer_Anrede'] = $userData['Anrede'];
76
						$userData['liefer_Vorname'] = $userData['Vorname'];
77
						$userData['liefer_Nachname'] = $userData['Nachname'];
78
						$userData['liefer_Firma'] = $userData['Firma'];
79
						$userData['liefer_Strasse'] = $userData['Strasse'];
80
						$userData['liefer_Hausnummer'] = $userData['Hausnummer'];
81
						$userData['liefer_PLZ'] = $userData['PLZ'];
82
						$userData['liefer_Ort'] = $userData['Ort'];
83
						$userData['liefer_email'] = $userData['email'];
84
						$userData['liefer_Telefon'] = $userData['Telefon'];
85
					}
663 lars 86
					elseif ($this->input->post('Lieferadresse') === "true")
87
					{
664 lars 88
						if ($this->form_validation->run('liefer') === false)
663 lars 89
						{
90
							$errormsg_liefer["liefer_Vorname"] = form_error('Persdata[liefer_Vorname]');
91
							$errormsg_liefer["liefer_Nachname"] = form_error('Persdata[liefer_Nachname]');
92
							$errormsg_liefer["liefer_Strasse"] = form_error('Persdata[liefer_Strasse]');
93
							$errormsg_liefer["liefer_Hausnummer"] = form_error('Persdata[liefer_Hausnummer]');
94
							$errormsg_liefer["liefer_PLZ"] = form_error('Persdata[liefer_PLZ]');
95
							$errormsg_liefer["liefer_Ort"] = form_error('Persdata[liefer_Ort]');
96
							$this->smarty->assign('errormsg_liefer', $errormsg_liefer);
97
							unset($_GET['subStep']);
98
						}
99
					}
742 lars 100
					elseif ($this->input->post('Lieferadresse') == "packstation")
101
					{
102
						if ($this->form_validation->run('packstation') === false)
103
						{
745 lars 104
							$errormsg_liefer["liefer_Vorname_pst"] = form_error('Persdata[liefer_Vorname_pst]');
105
							$errormsg_liefer["liefer_Nachname_pst"] = form_error('Persdata[liefer_Nachname_pst]');
106
							$errormsg_liefer["liefer_Firma_pst"] = form_error('Persdata[liefer_Firma_pst]');
107
							$errormsg_liefer["liefer_Hausnummer_pst"] = form_error('Persdata[liefer_Hausnummer_pst]');
108
							$errormsg_liefer["liefer_PLZ_pst"] = form_error('Persdata[liefer_PLZ_pst]');
109
							$errormsg_liefer["liefer_Ort_pst"] = form_error('Persdata[liefer_Ort_pst]');
742 lars 110
							$this->smarty->assign('errormsg_liefer', $errormsg_liefer);
111
							unset($_GET['subStep']);
112
						}
113
					}
641 lars 114
					$_SESSION['SHOP']['buy']['Persdata'] = $userData;
735 lars 115
					$_SESSION['SHOP']['Lieferadresse'] = $this->input->post('Lieferadresse');
689 lars 116
					$this->update_versand();
666 lars 117
					$this->form_validation->reset_validation();
641 lars 118
					if ($this->form_validation->run('guest') === false)
119
					{
120
						$errormsg_rechnung["Vorname"] = form_error('Persdata[Vorname]');
121
						$errormsg_rechnung["Nachname"] = form_error('Persdata[Nachname]');
122
						$errormsg_rechnung["Strasse"] = form_error('Persdata[Strasse]');
123
						$errormsg_rechnung["Hausnummer"] = form_error('Persdata[Hausnummer]');
124
						$errormsg_rechnung["PLZ"] = form_error('Persdata[PLZ]');
125
						$errormsg_rechnung["Ort"] = form_error('Persdata[Ort]');
126
						$errormsg_rechnung["email"] = form_error('Persdata[email]');
127
						$errormsg_rechnung["Telefon"] = form_error('Persdata[Telefon]');
128
						$this->smarty->assign('errormsg_rechnung', $errormsg_rechnung);
129
						unset($_GET['subStep']);
130
					}
131
					else
132
					{
666 lars 133
						$this->form_validation->reset_validation();
641 lars 134
						if ($this->input->post('account') == 'new')
629 lars 135
						{
641 lars 136
							if ($this->form_validation('new') === false)
137
							{
674 lars 138
								$req_error = false;
641 lars 139
							}
629 lars 140
						}
674 lars 141
						else
142
						{
143
							$req_error = false;
144
						}
629 lars 145
					}
146
				}
674 lars 147
				if (!$req_error)
148
				{
149
					$_SESSION["SHOP"]['VERSAND'] = array();
150
 
1995 lars 151
					$vItem = $this->artikel->get_artikel($_POST["Versand"], true, true);
674 lars 152
					$VersandItem = array(
153
						"Menge" => 1,
154
						"ID" => $_POST['Versand'],
155
						"Versand" => true,
677 lars 156
						'preis' => $vItem['preis'],
701 lars 157
						'kurzbezeichnung' => $vItem['kurzbezeichnung'],
674 lars 158
						);
159
					$_SESSION['SHOP']['VERSAND'] = $VersandItem;
160
					$_SESSION["SHOP"]["buy"]["Versand"] = true;
161
					if ($GLOBALS["INI"]["PayPalPlus"]["aktiv"] == 1)
162
					{
163
						$customMethods = array(
164
							"vorkasse",
165
							"selbstabholung",
166
							"ratenzahlung",
167
							"nachnahme",
168
							"sofortueberweisung",
169
							);
680 lars 170
						$buy_link_base = 'https://ci.starfleethq.de/';
674 lars 171
						if ($GLOBALS["INI"]["ssl_buy"] == 1)
172
						{
173
							$buy_link_base = str_replace("http:", "https:", $buy_link_base);
174
						}
680 lars 175
						$url = $buy_link_base."/bestellen_seite_2.order";
676 lars 176
						$versandOptionen = get_versandkosten($_SESSION['SHOP']['buy']['Persdata']['liefer_Land']);
674 lars 177
						foreach ($versandOptionen as $o_id => $opt)
178
						{
179
							//admin_debug( $opt["rufname"] );
180
							$rufname = strtolower($opt["rufname"]);
181
							if ($GLOBALS["INI"]["dbConnect"]["db_is_utf8"] != 1)
182
							{
183
								$opt["kurz"] = utf8_encode($opt["kurz"]);
184
								$opt["beschr"] = utf8_encode($opt["beschr"]);
185
							}
186
							if (in_array($rufname, $customMethods))
187
							{
188
								$method = array(
189
									"redirectUrl" => $url,
190
									"methodName" => $opt["kurz"],
191
									"description" => $opt["beschr"],
192
									);
193
								$imgBase = "/images/webelemente/versand_";
194
								$imgName = $imgBase.$rufname.".jpg";
195
								$imgUrl = "https://".$_SERVER["SERVER_NAME"].$imgName;
196
								$imgNameFull = $_SERVER["DOCUMENT_ROOT"].$imgName;
197
								if ($GLOBALS["INI"]["ssl_buy"] == 1)
198
								{
199
									if (file_exists($imgNameFull))
200
									{
201
										$method["imageUrl"] = $imgUrl;
202
									}
203
								}
204
								$thirdPartyMethods[] = $method;
205
							}
206
							$payPal3rdParty = json_encode($thirdPartyMethods);
207
							require_once "module/creditcard/paypalPlus.php";
208
							$c = new paypalPlus();
209
							$apporvalUrl = $c->getCreditcardStatus(null);
679 lars 210
							$this->smarty->assign("paymentMethods", $payPal3rdParty);
211
							$this->smarty->assign("approvalUrl", $apporvalUrl);
674 lars 212
						}
213
					}
214
				}
514 lars 215
				break;
646 lars 216
			case "Versand":
1995 lars 217
				$vItem = $_SESSION['SHOP']['VERSAND'];
2002 lars 218
				if (strtolower($vItem["rufname"]) == "paypal" || strtolower($vItem["rufname"]) ==
1993 lars 219
					"ratenzahlung")
220
				{
221
					if ($GLOBALS["INI"]["paypal"]["usesApi"] == 1)
222
					{
223
						require_once "module/creditcard/paypal.php";
224
						$c = new paypal();
225
						$c->getCreditcardStatus(null);
226
						//
227
					}
228
				}
646 lars 229
				break;
230
			case "execute":
644 lars 231
				if ($this->form_validation->run('execute') === false)
232
				{
233
					$step = 2;
234
					$errormsg_kontrolle = validation_errors();
235
					$this->smarty->assign('errormsg_kontrolle', $errormsg_kontrolle);
236
				}
667 lars 237
				else
238
				{
239
					$this->save();
240
				}
644 lars 241
				break;
514 lars 242
		}
243
		$_SESSION['SHOP']['buy']['step'] = $step;
244
		$this->smarty->view('buy.tpl');
245
	}
246
 
520 lars 247
	/**
248
	 * Order::save()
249
	 *
250
	 * @return
251
	 */
514 lars 252
	public function save()
253
	{
254
		$this->order->create();
255
	}
668 lars 256
 
257
	public function update_versand()
258
	{
705 lars 259
		$land = 47;
704 lars 260
		if (isset($_SESSION['SHOP']['buy']['Persdata']['liefer_Land']))
261
		{
262
			$land = $_SESSION['SHOP']['buy']['Persdata']['liefer_Land'];
263
		}
690 lars 264
		$versandOptinen = get_versandkosten($land);
669 lars 265
		if ($GLOBALS['INI']['PayPalPlus']['aktiv'] == 1)
668 lars 266
		{
267
			foreach ($versandOptinen as $opt)
268
			{
672 lars 269
				if ($opt['rufname'] == 'PayPalPlus')
668 lars 270
				{
271
					$pppVersand = $opt['ID'];
272
					break;
273
				}
274
			}
674 lars 275
			if ($this->input->get('Land') || $this->input->get('liefer'))
276
			{
277
				echo $pppVersand;
278
			}
279
			else
280
			{
281
				$this->smarty->assign("ppplusVersand", $pppVersand);
282
			}
668 lars 283
		}
284
		else
285
		{
286
			foreach ($versandOptinen as $opt)
287
			{
288
				if ($opt["rufname"] == "amazon" || $opt["rufname"] == "PayPalExpress")
289
				{
290
					continue;
291
				}
292
				elseif ($_GET["packstation"] == 1 && !stristr($opt["kurz"], "DHL"))
293
				{
294
					continue;
295
				}
296
				if ($_GET["kurier"] == 1 && $opt["express"] != 1)
297
				{
298
					continue;
299
				}
300
				if ($GLOBALS['INI']['charset'] == "utf-8" && $GLOBALS['INI']['dbConnect']['db_is_utf8'] !=
301
					1)
302
				{
303
					$opt["kurz"] = utf8_encode($opt["kurz"]);
304
					$opt['beschr'] = utf8_encode($opt['beschr']);
305
				}
306
				$opt['beschr'] = str_replace("\r\n", "<br>", $opt['beschr']);
307
 
308
				if (($_SESSION["SHOP"]["buy"]["Versand_selected"] == $opt["ID"]) || (!$_SESSION["SHOP"]["buy"]["Versand_selected"] &&
309
					$o_id == 0))
310
				{
311
					$opt["checked"] = 'checked="checked"';
312
				}
313
				$v_opt[] = $opt;
314
			}
315
			$this->smarty->assign("versandOptionen", $v_opt);
316
		}
317
	}
514 lars 318
}
319
 
233 lars 320
?>