Subversion-Projekte lars-tiefland.ci

Revision

Revision 2308 | Revision 2310 | 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: 2309 $
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
 
46
	public function save()
47
	{
48
	}
2283 lars 49
 
2280 lars 50
	public function export($id)
51
	{
2309 lars 52
		$aColumns = array("exported");
2286 lars 53
		$sQuery = "SELECT DISTINCT
54
                    exported
55
                FROM
56
                    artikel_to_Bestellung ab
57
                JOIN
58
                    bestellung_logistiker bl
59
                ON
60
                    bl.logistiker=$id
61
                AND
62
                    bl.bestellung = ab.Bestellung
63
                WHERE
64
                    exported
2283 lars 65
 
2286 lars 66
                $sWhere
67
                $sOrder
68
                $sLimit
69
            ";
70
 
2288 lars 71
		$rResult = $GLOBALS['order_db']->query($sQuery);
2286 lars 72
 
73
		/* Data set length after filtering */
74
		$sQuery = "
75
                        SELECT FOUND_ROWS() AS total
76
                ";
2288 lars 77
		$rResultFilterTotal = $GLOBALS['order_db']->query($sQuery);
2286 lars 78
		$aResultFilterTotal = $aResultFilterTotal->unbuffered_row('array');
79
		$iFilteredTotal = $aResultFilterTotal["total"];
80
 
81
		/* Total data set length */
82
		$sQuery = "
83
                        SELECT
84
                    COUNT(" . $sIndexColumn . ") AS total
85
                FROM
86
                    artikel_to_Bestellung ab
87
                JOIN
88
                    bestellung_logistiker bl
89
                ON
90
                    bl.logistiker=$id
91
                AND
92
                    bl.bestellung = ab.Bestellung
93
                WHERE
94
                    exported
95
                ";
2288 lars 96
		$rResultTotal = $GLOBALS['order_db']->query($sQuery);
2286 lars 97
		$aResultTotal = $aResultTotal->unbuffert_row('array');
98
		$iTotal = $aResultTotal["total"];
99
 
100
 
101
		/*
102
		* Output
103
		*/
104
		$output = array(
105
			"sEcho" => intval($echo['sEcho']),
106
			"iTotalRecords" => $iTotal,
107
			"iTotalDisplayRecords" => $iTotal,
108
			"aaData" => array());
109
 
110
		$sql = "SELECT
111
                    export_script
112
                FROM
113
                    logistiker
114
                WHERE
115
                    id = " . $id . "
116
            ";
2288 lars 117
		$res = $GLOBALS['order_db']->query($sql);
2286 lars 118
		$nrow = $res->unbuffered_row('array');
119
		if (strstr($nrow["export_script"], "=")) {
120
			$qs = explode(";", $nrow["export_script"]);
121
			foreach ($qs as $val) {
122
				list($key, $wert) = explode("=", $val);
123
				if ($key == "mode") {
124
					$qsArr[] = "mode=" . $wert;
125
				} elseif (is_null($wert)) {
126
					$script = $key;
127
				} elseif (!stristr($key, "status") && $wert) {
128
					$qsArr[] = "$key=" . $wert;
129
				}
130
			}
131
			$qs = implode("&", $qsArr);
132
		} else {
133
			list($script, $mode) = explode(";", $nrow["export_script"]);
134
			$qs = "mode=" . $mode;
135
		}
136
		while ($aRow = $rResult->unbuffered_row('array')) {
137
			$aRow['exported'] = '<a href="/Warenwirtschaft/' . $script . '?time=' . $aRow['exported'] .
138
				'&id=' . $id . '&' . $qs . '" target="_blank">' . date('d.m.Y H:i:s', strtotime
139
				($aRow['exported'])) . '</a>';
140
			$row = array();
141
			for ($i = 0; $i < count($aColumns); $i++) {
142
				if ($aColumns[$i] == "version") {
143
					/* Special output formatting for 'version' column */
144
					$row[] = ($aRow[$aColumns[$i]] == "0") ? '-' : $aRow[$aColumns[$i]];
145
				} else
146
					if ($aColumns[$i] != ' ') {
147
						/* General output */
148
						$row[] = $aRow[$aColumns[$i]];
149
					}
150
			}
151
			$output['aaData'][] = $row;
152
		}
153
 
154
		return json_encode($output);
2280 lars 155
	}
2283 lars 156
 
2280 lars 157
	public function tracking($id)
158
	{
2303 lars 159
		$aColumns = array(
160
			'paketnummer',
161
			'datum',
162
			'bestellung',
163
			);
2305 lars 164
		if (isset($_GET['iSortCol_0'])) {
165
			$sOrder = "ORDER BY  ";
166
			for ($i = 0; $i < intval($this->input->get('iSortingCols')); $i++) {
167
				if ($this->input->get('bSortable_' . intval($this->input->get('iSortCol_' . $i))) ==
168
					"true") {
169
					$sOrder .= $aColumns[intval($this->input->get('iSortCol_' . $i))] . "
2306 lars 170
                                    " . $this->input->get('sSortDir_' . $i) .
171
						", ";
2305 lars 172
				}
173
			}
174
 
175
			$sOrder = substr_replace($sOrder, "", -2);
176
			if ($sOrder == "ORDER BY") {
177
				$sOrder = "";
178
			}
179
		}
2285 lars 180
		$sWhere = "";
2287 lars 181
		if ($this->input->get('sSearch') != "") {
2285 lars 182
			$sWhere = "WHERE (";
183
			for ($i = 0; $i < count($aColumns); $i++) {
184
				if ($aColumns[$i] == "datum") {
185
					$a = " from_unixtime(datum) ";
2288 lars 186
					$sWhere .= $a . " LIKE '%" . $GLOBALS['order_db']->escape($this->input->get('sSearch')) .
2285 lars 187
						"%' OR ";
188
				} else {
2295 lars 189
					$sWhere .= $aColumns[$i] . " LIKE '%" . $GLOBALS['order_db']->escape($this->
190
						input->get('sSearch')) . "%' OR ";
2285 lars 191
				}
192
 
193
			}
194
			$sWhere = substr_replace($sWhere, "", -3);
195
			$sWhere .= ')';
2280 lars 196
		}
2285 lars 197
 
198
		/* Individual column filtering */
199
		for ($i = 0; $i < count($aColumns); $i++) {
2287 lars 200
			if ($this->input->get('bSearchable_' . $i) == "true" && $this->input->get('sSearch_' .
201
				$i) != '') {
2285 lars 202
				if ($sWhere == "") {
203
					$sWhere = "WHERE ";
204
				} else {
205
					$sWhere .= " AND ";
206
				}
207
				if ($aColumns[$i] == "datum") {
208
					$r = " from_unixtime(datum) ";
2288 lars 209
					$sWhere .= $r . " LIKE '%" . $GLOBALS['order_db']->escape($this->input->get('sSearch_' .
2287 lars 210
						$i)) . "%' ";
2285 lars 211
				} else {
2288 lars 212
					$sWhere .= $r . " LIKE '%" . $GLOBALS['order_db']->escape($this->input->get('sSearch_' .
2287 lars 213
						$i)) . "%' ";
2285 lars 214
				}
215
 
216
			}
217
		}
218
 
219
		if (empty($sWhere)) {
220
			$sWhere = " where bp.logistiker=l.id AND l.id = $id ";
221
		} else {
222
			$sWhere = " $sWhere and bp.logistiker=l.id AND l.id = $id ";
223
		}
2297 lars 224
		$sLimit = $this->input->get('iDisplayStart') . "," . $this->input->get('iDisplayLength');
2285 lars 225
		$sQuery = "SELECT
226
                    SQL_CALC_FOUND_ROWS
227
                    bp.*,
228
                    l.kname,
229
                    l.trackinglink
230
                FROM
231
                    logistiker l,
232
                    bestellung_paketnummern bp
2297 lars 233
                    " . $sWhere . "
234
                    " . $sOrder . "
2298 lars 235
					LIMIT " . $sLimit . "
2285 lars 236
                ";
237
		//echo $sQuery;
2299 lars 238
		trigger_error($sQuery);
2288 lars 239
		$rResult = $GLOBALS['order_db']->query($sQuery);
2285 lars 240
 
241
		/* Data set length after filtering */
242
		$sQuery = "
243
                        SELECT FOUND_ROWS() AS total
244
                ";
2288 lars 245
		$rResultFilterTotal = $GLOBALS['order_db']->query($sQuery);
2289 lars 246
		$aResultFilterTotal = $rResultFilterTotal->unbuffered_row('array');
2285 lars 247
		$iFilteredTotal = $aResultFilterTotal["total"];
248
 
249
		/* Total data set length */
250
		$sQuery = "
251
                        SELECT
2292 lars 252
                    COUNT(bp.id) AS total
2285 lars 253
                FROM
254
                    logistiker l,
255
                    bestellung_paketnummern bp
256
                WHERE
257
                    bp.logistiker=l.id
258
                AND
259
                    l.id = $id
260
                ";
261
 
262
 
2288 lars 263
		$rResultTotal = $GLOBALS['order_db']->query($sQuery);
2294 lars 264
		$aResultTotal = $rResultTotal->unbuffered_row('array');
2285 lars 265
		$iTotal = $aResultTotal["total"];
266
 
267
 
268
		/*
269
		* Output
270
		*/
271
		$output = array(
2286 lars 272
			"sEcho" => intval($this->input->get('sEcho')),
2285 lars 273
			"iTotalRecords" => $iTotal,
274
			"iTotalDisplayRecords" => $iFilteredTotal,
275
			"aaData" => array());
276
 
277
		while ($aRow = $rResult->unbuffered_row('array')) {
278
			//$aRow['datum'] = strtotime($aRow['datum']);
279
			$aRow['datum'] = date('d.m.Y', $aRow['datum']);
2308 lars 280
			$aRow['bestellung'] = ' <a target="_blank" href="/backend/order/edit/' . $aRow['bestellung'] .
2307 lars 281
				'">zum Vorgang</a>';
2285 lars 282
 
283
			$url = $aRow["trackinglink"];
284
			if (stristr($url, "%")) {
285
				$tag = date("d", $row_p["datum"]);
286
				$monat = date("m", $row_p["datum"]);
287
				$jahr = date("Y", $row_p["datum"]);
288
				$url = str_replace("%tag%", $tag, $url);
289
				$url = str_replace("%monat%", $monat, $url);
290
				$url = str_replace("%jahr%", $jahr, $url);
291
				$url = str_replace("%trackingnr%", $aRow["paketnummer"], $url);
292
			} else {
293
				$url .= $aRow["paketnummer"];
294
			}
295
 
296
 
297
			$aRow["paketnummer"] = $aRow["kname"] . ': <a href=' . $url . ' target=_blank>' .
298
				$aRow["paketnummer"] . '</a>';
299
			$row = array();
300
			for ($i = 0; $i < count($aColumns); $i++)
301
				if ($aColumns[$i] == "version") {
302
					/* Special output formatting for 'version' column */
303
					$row[] = ($aRow[$aColumns[$i]] == "0") ? '-' : $aRow[$aColumns[$i]];
304
				} else
305
					if ($aColumns[$i] != ' ') {
306
						/* General output */
307
						$row[] = $aRow[$aColumns[$i]];
308
					}
2304 lars 309
			$output['aaData'][] = $row;
2285 lars 310
		}
311
 
312
		return json_encode($output);
2280 lars 313
	}
2285 lars 314
 
2243 lars 315
}
316
 
317
?>