Subversion-Projekte lars-tiefland.ci

Revision

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