Subversion-Projekte lars-tiefland.ci

Revision

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