Subversion-Projekte lars-tiefland.ci

Revision

Revision 2349 | Revision 2364 | Zur aktuellen Revision | Details | Vergleich mit vorheriger | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
2243 lars 1
<?php
2
 
3
/**
4
 *
5
 * @package WebanOS CI
6
 * @author Lars Tiefland <ltiefland@gmail.com>
7
 * @copyright 2016
8
 * @version $Rev: 2363 $
9
 */
10
 
11
class Logistiker_model extends CI_Model
12
{
13
	public function __construct()
14
	{
15
		parent::__construct();
16
	}
17
 
18
	public function get_list($start = 0)
19
	{
2244 lars 20
		$sql = "SELECT
21
				*
22
			FROM
23
				logistiker
24
		";
2247 lars 25
		$res = $this->db->query($sql);
2244 lars 26
		while ($row = $res->unbuffered_row('array')) {
27
			$logistiker[] = $row;
28
		}
29
		return $logistiker;
2243 lars 30
	}
31
 
32
	public function get($id)
33
	{
2244 lars 34
		$sql = "SELECT
35
				*
36
			FROM
37
				logistiker
38
			WHERE
39
				id=" . $id . "
40
		";
2247 lars 41
		$res = $this->db->query($sql);
2244 lars 42
		$logistiker = $res->unbuffered_row('array');
43
		return $logistiker;
2243 lars 44
	}
45
 
2327 lars 46
	public function save($daten)
2243 lars 47
	{
2330 lars 48
		if (!$this->input->post('id'))
2321 lars 49
		{
50
			$sql = "
51
				INSERT INTO
52
					logistiker
53
				SET
54
			";
55
			foreach ($daten as $key => $value)
56
			{
57
				$felder[] = $key."=".$GLOBALS["order_db"]->escape($value);
58
			}
59
			$sql .= implode(",", $felder);
60
			$res = $this->db->query($sql);
61
			$id = $this->db->insert_id();
62
		}
63
		else
64
		{
65
			$sql = "UPDATE
66
					logistiker
67
				SET
68
			";
69
			foreach ($daten as $key => $value)
70
			{
71
				$felder[] = $key."=".$GLOBALS["order_db"]->escape($value);
72
			}
73
			$sql .= implode(",", $felder);
74
			$sql .= "
75
				WHERE
2330 lars 76
					id=".$this->input->post('id')."
2321 lars 77
			";
78
			$res = $this->db->query($sql);
79
		}
80
		if ($res)
81
		{
2333 lars 82
			echo "Daten wurden erfolgreich geändert!";
2321 lars 83
		}
84
		else
85
		{
2333 lars 86
			echo "Leider ist ein Fehler aufgetreten. Bitte versuchen Sie es später noch einmal!";
2321 lars 87
		}
2243 lars 88
	}
2348 lars 89
 
90
	public function del($id)
91
	{
92
		$sql = "DELETE FROM
93
				logistiker
94
			WHERE
95
				id=".$id."
96
		";
97
		$res = $this->db->query($sql);
98
		if ($res)
99
		{
2349 lars 100
			echo "Logistiker wurde erfolgreich gelöscht!";
2348 lars 101
		}
102
		else
103
		{
104
			echo "Leider ist ein Fehler aufgetreten. Bitte versuchen Sie es später noch einmal!";
105
		}
106
	}
2283 lars 107
 
2280 lars 108
	public function export($id)
109
	{
2309 lars 110
		$aColumns = array("exported");
2314 lars 111
		$sIndexColumn = "exported";
2313 lars 112
		$sLimit = $this->input->get('iDisplayStart') . "," . $this->input->get('iDisplayLength');
2317 lars 113
		if (isset($_GET['iSortCol_0'])) {
114
			$sOrder = "ORDER BY  ";
115
			for ($i = 0; $i < intval($this->input->get('iSortingCols')); $i++) {
116
				if ($this->input->get('bSortable_' . intval($this->input->get('iSortCol_' . $i))) ==
117
					"true") {
118
					$sOrder .= $aColumns[intval($this->input->get('iSortCol_' . $i))] . "
119
                                    " . $this->input->get('sSortDir_' . $i) .
120
						", ";
121
				}
122
			}
123
 
124
			$sOrder = substr_replace($sOrder, "", -2);
125
			if ($sOrder == "ORDER BY") {
126
				$sOrder = "";
127
			}
128
		}
2286 lars 129
		$sQuery = "SELECT DISTINCT
130
                    exported
131
                FROM
132
                    artikel_to_Bestellung ab
133
                JOIN
134
                    bestellung_logistiker bl
135
                ON
136
                    bl.logistiker=$id
137
                AND
138
                    bl.bestellung = ab.Bestellung
139
                WHERE
140
                    exported
2283 lars 141
 
2314 lars 142
                " . $sOrder . "
143
                LIMIT " . $sLimit . "
2286 lars 144
            ";
2310 lars 145
		trigger_error($sQuery);
2288 lars 146
		$rResult = $GLOBALS['order_db']->query($sQuery);
2286 lars 147
 
148
		/* Data set length after filtering */
149
		$sQuery = "
150
                        SELECT FOUND_ROWS() AS total
151
                ";
2288 lars 152
		$rResultFilterTotal = $GLOBALS['order_db']->query($sQuery);
2312 lars 153
		$aResultFilterTotal = $rResultFilterTotal->unbuffered_row('array');
2286 lars 154
		$iFilteredTotal = $aResultFilterTotal["total"];
155
 
156
		/* Total data set length */
157
		$sQuery = "
158
                        SELECT
159
                    COUNT(" . $sIndexColumn . ") AS total
160
                FROM
161
                    artikel_to_Bestellung ab
162
                JOIN
163
                    bestellung_logistiker bl
164
                ON
165
                    bl.logistiker=$id
166
                AND
167
                    bl.bestellung = ab.Bestellung
168
                WHERE
169
                    exported
170
                ";
2288 lars 171
		$rResultTotal = $GLOBALS['order_db']->query($sQuery);
2315 lars 172
		$aResultTotal = $rResultTotal->unbuffered_row('array');
2286 lars 173
		$iTotal = $aResultTotal["total"];
174
 
175
 
176
		/*
177
		* Output
178
		*/
179
		$output = array(
2316 lars 180
			"sEcho" => intval($this->input->get('sEcho')),
2286 lars 181
			"iTotalRecords" => $iTotal,
182
			"iTotalDisplayRecords" => $iTotal,
183
			"aaData" => array());
184
 
185
		$sql = "SELECT
186
                    export_script
187
                FROM
188
                    logistiker
189
                WHERE
190
                    id = " . $id . "
191
            ";
2288 lars 192
		$res = $GLOBALS['order_db']->query($sql);
2286 lars 193
		$nrow = $res->unbuffered_row('array');
194
		if (strstr($nrow["export_script"], "=")) {
195
			$qs = explode(";", $nrow["export_script"]);
196
			foreach ($qs as $val) {
197
				list($key, $wert) = explode("=", $val);
198
				if ($key == "mode") {
199
					$qsArr[] = "mode=" . $wert;
200
				} elseif (is_null($wert)) {
201
					$script = $key;
202
				} elseif (!stristr($key, "status") && $wert) {
203
					$qsArr[] = "$key=" . $wert;
204
				}
205
			}
206
			$qs = implode("&", $qsArr);
207
		} else {
208
			list($script, $mode) = explode(";", $nrow["export_script"]);
209
			$qs = "mode=" . $mode;
210
		}
211
		while ($aRow = $rResult->unbuffered_row('array')) {
212
			$aRow['exported'] = '<a href="/Warenwirtschaft/' . $script . '?time=' . $aRow['exported'] .
213
				'&id=' . $id . '&' . $qs . '" target="_blank">' . date('d.m.Y H:i:s', strtotime
214
				($aRow['exported'])) . '</a>';
215
			$row = array();
216
			for ($i = 0; $i < count($aColumns); $i++) {
217
				if ($aColumns[$i] == "version") {
218
					/* Special output formatting for 'version' column */
219
					$row[] = ($aRow[$aColumns[$i]] == "0") ? '-' : $aRow[$aColumns[$i]];
220
				} else
221
					if ($aColumns[$i] != ' ') {
222
						/* General output */
223
						$row[] = $aRow[$aColumns[$i]];
224
					}
225
			}
226
			$output['aaData'][] = $row;
227
		}
228
 
229
		return json_encode($output);
2280 lars 230
	}
2283 lars 231
 
2280 lars 232
	public function tracking($id)
233
	{
2303 lars 234
		$aColumns = array(
235
			'paketnummer',
236
			'datum',
237
			'bestellung',
238
			);
2305 lars 239
		if (isset($_GET['iSortCol_0'])) {
240
			$sOrder = "ORDER BY  ";
241
			for ($i = 0; $i < intval($this->input->get('iSortingCols')); $i++) {
242
				if ($this->input->get('bSortable_' . intval($this->input->get('iSortCol_' . $i))) ==
243
					"true") {
244
					$sOrder .= $aColumns[intval($this->input->get('iSortCol_' . $i))] . "
2306 lars 245
                                    " . $this->input->get('sSortDir_' . $i) .
246
						", ";
2305 lars 247
				}
248
			}
249
 
250
			$sOrder = substr_replace($sOrder, "", -2);
251
			if ($sOrder == "ORDER BY") {
252
				$sOrder = "";
253
			}
254
		}
2285 lars 255
		$sWhere = "";
2287 lars 256
		if ($this->input->get('sSearch') != "") {
2285 lars 257
			$sWhere = "WHERE (";
258
			for ($i = 0; $i < count($aColumns); $i++) {
259
				if ($aColumns[$i] == "datum") {
260
					$a = " from_unixtime(datum) ";
2288 lars 261
					$sWhere .= $a . " LIKE '%" . $GLOBALS['order_db']->escape($this->input->get('sSearch')) .
2285 lars 262
						"%' OR ";
263
				} else {
2295 lars 264
					$sWhere .= $aColumns[$i] . " LIKE '%" . $GLOBALS['order_db']->escape($this->
265
						input->get('sSearch')) . "%' OR ";
2285 lars 266
				}
267
 
268
			}
269
			$sWhere = substr_replace($sWhere, "", -3);
270
			$sWhere .= ')';
2280 lars 271
		}
2285 lars 272
 
273
		/* Individual column filtering */
274
		for ($i = 0; $i < count($aColumns); $i++) {
2287 lars 275
			if ($this->input->get('bSearchable_' . $i) == "true" && $this->input->get('sSearch_' .
276
				$i) != '') {
2285 lars 277
				if ($sWhere == "") {
278
					$sWhere = "WHERE ";
279
				} else {
280
					$sWhere .= " AND ";
281
				}
282
				if ($aColumns[$i] == "datum") {
283
					$r = " from_unixtime(datum) ";
2288 lars 284
					$sWhere .= $r . " LIKE '%" . $GLOBALS['order_db']->escape($this->input->get('sSearch_' .
2287 lars 285
						$i)) . "%' ";
2285 lars 286
				} else {
2288 lars 287
					$sWhere .= $r . " LIKE '%" . $GLOBALS['order_db']->escape($this->input->get('sSearch_' .
2287 lars 288
						$i)) . "%' ";
2285 lars 289
				}
290
 
291
			}
292
		}
293
 
294
		if (empty($sWhere)) {
295
			$sWhere = " where bp.logistiker=l.id AND l.id = $id ";
296
		} else {
297
			$sWhere = " $sWhere and bp.logistiker=l.id AND l.id = $id ";
298
		}
2297 lars 299
		$sLimit = $this->input->get('iDisplayStart') . "," . $this->input->get('iDisplayLength');
2285 lars 300
		$sQuery = "SELECT
301
                    SQL_CALC_FOUND_ROWS
302
                    bp.*,
303
                    l.kname,
304
                    l.trackinglink
305
                FROM
306
                    logistiker l,
307
                    bestellung_paketnummern bp
2297 lars 308
                    " . $sWhere . "
309
                    " . $sOrder . "
2298 lars 310
					LIMIT " . $sLimit . "
2285 lars 311
                ";
312
		//echo $sQuery;
2288 lars 313
		$rResult = $GLOBALS['order_db']->query($sQuery);
2285 lars 314
 
315
		/* Data set length after filtering */
316
		$sQuery = "
317
                        SELECT FOUND_ROWS() AS total
318
                ";
2288 lars 319
		$rResultFilterTotal = $GLOBALS['order_db']->query($sQuery);
2289 lars 320
		$aResultFilterTotal = $rResultFilterTotal->unbuffered_row('array');
2285 lars 321
		$iFilteredTotal = $aResultFilterTotal["total"];
322
 
323
		/* Total data set length */
324
		$sQuery = "
325
                        SELECT
2292 lars 326
                    COUNT(bp.id) AS total
2285 lars 327
                FROM
328
                    logistiker l,
329
                    bestellung_paketnummern bp
330
                WHERE
331
                    bp.logistiker=l.id
332
                AND
333
                    l.id = $id
334
                ";
335
 
336
 
2288 lars 337
		$rResultTotal = $GLOBALS['order_db']->query($sQuery);
2294 lars 338
		$aResultTotal = $rResultTotal->unbuffered_row('array');
2285 lars 339
		$iTotal = $aResultTotal["total"];
340
 
341
 
342
		/*
343
		* Output
344
		*/
345
		$output = array(
2286 lars 346
			"sEcho" => intval($this->input->get('sEcho')),
2285 lars 347
			"iTotalRecords" => $iTotal,
348
			"iTotalDisplayRecords" => $iFilteredTotal,
349
			"aaData" => array());
350
 
351
		while ($aRow = $rResult->unbuffered_row('array')) {
352
			//$aRow['datum'] = strtotime($aRow['datum']);
353
			$aRow['datum'] = date('d.m.Y', $aRow['datum']);
2308 lars 354
			$aRow['bestellung'] = ' <a target="_blank" href="/backend/order/edit/' . $aRow['bestellung'] .
2307 lars 355
				'">zum Vorgang</a>';
2285 lars 356
 
357
			$url = $aRow["trackinglink"];
358
			if (stristr($url, "%")) {
359
				$tag = date("d", $row_p["datum"]);
360
				$monat = date("m", $row_p["datum"]);
361
				$jahr = date("Y", $row_p["datum"]);
362
				$url = str_replace("%tag%", $tag, $url);
363
				$url = str_replace("%monat%", $monat, $url);
364
				$url = str_replace("%jahr%", $jahr, $url);
365
				$url = str_replace("%trackingnr%", $aRow["paketnummer"], $url);
366
			} else {
367
				$url .= $aRow["paketnummer"];
368
			}
369
 
370
 
371
			$aRow["paketnummer"] = $aRow["kname"] . ': <a href=' . $url . ' target=_blank>' .
372
				$aRow["paketnummer"] . '</a>';
373
			$row = array();
374
			for ($i = 0; $i < count($aColumns); $i++)
375
				if ($aColumns[$i] == "version") {
376
					/* Special output formatting for 'version' column */
377
					$row[] = ($aRow[$aColumns[$i]] == "0") ? '-' : $aRow[$aColumns[$i]];
378
				} else
379
					if ($aColumns[$i] != ' ') {
380
						/* General output */
381
						$row[] = $aRow[$aColumns[$i]];
382
					}
2304 lars 383
			$output['aaData'][] = $row;
2285 lars 384
		}
385
 
386
		return json_encode($output);
2280 lars 387
	}
2285 lars 388
 
2243 lars 389
}
390
 
391
?>