Subversion-Projekte lars-tiefland.ci

Revision

Revision 2108 | Zur aktuellen Revision | Ganze Datei anzeigen | Leerzeichen ignorieren | Details | Blame | Letzte Änderung | Log anzeigen | RSS feed

Revision 2108 Revision 2109
Zeile 1... Zeile 1...
1
<?php
1
<?php
Zeile 2... Zeile 2...
2
 
2
 
3
class Scheduler extends CI_Controller
3
class Scheduler extends CI_Controller
4
{
4
{
5
    public function __construct()
5
	public function __construct()
6
    {
6
	{
7
        parent::__construct();
7
		parent::__construct();
8
    }
8
	}
9
    public function index()
9
	public function index()
10
    {
10
	{
11
        $tasks = array();
11
		$tasks = array();
12
        $sql = "SELECT
12
		$sql = "SELECT
13
				id,
13
				id,
14
				name,
14
				name,
15
				art,
15
				art,
16
				skript,
16
				skript,
Zeile 24... Zeile 24...
24
			AND
24
			AND
25
				user!=''
25
				user!=''
26
			ORDER BY
26
			ORDER BY
27
				user
27
				user
28
		";
28
		";
29
        $res = $this->db->query($sql);
29
		$res = $this->db->query($sql);
30
        while ($row = $res->unbuffered_row('array')) {
30
		while ($row = $res->unbuffered_row('array'))
-
 
31
		{
31
            $tasks[] = $row;
32
			$tasks[] = $row;
32
        }
33
		}
33
        $this->smarty->assign("tasks", $tasks);
34
		$this->smarty->assign("tasks", $tasks);
34
        $this->smarty->view('scheduler.tpl');
35
		$this->smarty->view('scheduler.tpl');
35
    }
36
	}
Zeile 36... Zeile 37...
36
 
37
 
37
    public function del($id = null)
38
	public function del($id = null)
38
    {
39
	{
-
 
40
		if ($id)
39
        if ($id) {
41
		{
40
            $task = $this->get_task($id);
42
			$task = $this->get_task($id);
41
            $this->smarty->assign("task", $task);
43
			$this->smarty->assign("task", $task);
42
            $this->smarty->view('scheduler_del.tpl');
44
			$this->smarty->view('scheduler_del.tpl');
-
 
45
		} else
43
        } else {
46
		{
44
            $sql = "
47
			$sql = "
45
				DELETE FROM
48
				DELETE FROM
46
					schnittstellen
49
					schnittstellen
47
				WHERE
50
				WHERE
48
					ID = " . $this->input->post('id') . "
51
					ID = " . $this->input->post('id') . "
49
			";
52
			";
50
            $res = $this->db->query($sql);
53
			$res = $this->db->query($sql);
-
 
54
			if ($res)
51
            if ($res) {
55
			{
52
                $msg = "Cronjob wurde erfolgreich gelöscht!";
56
				$msg = "Cronjob wurde erfolgreich gelöscht!";
-
 
57
			} else
53
            } else {
58
			{
54
                $msg = "Leider ist ein Fehler aufgetreten.<br>";
59
				$msg = "Leider ist ein Fehler aufgetreten.<br>";
55
                $msg .= "Bitte versuchen Sie es sp&auml;ter noch einmal!<br>";
60
				$msg .= "Bitte versuchen Sie es sp&auml;ter noch einmal!<br>";
56
                //$msg .= mysql_error();
61
				//$msg .= mysql_error();
57
            }
62
			}
58
            echo $msg;
63
			echo $msg;
59
        }
64
		}
60
    }
65
	}
61
    public function edit($id = null)
66
	public function edit($id = null)
62
    {
67
	{
-
 
68
		if ($id)
63
        if ($id) {
69
		{
64
            $task = $this->get_task($id);
70
			$task = $this->get_task($id);
-
 
71
		} else
65
        } else {
72
		{
66
            $domain = explode(".", $_SERVER["HTTP_HOST"]);
73
			$domain = explode(".", $_SERVER["HTTP_HOST"]);
67
            $dom = array_shift($domain);
74
			$dom = array_shift($domain);
68
            $site_full = implode(".", $domain);
75
			$site_full = implode(".", $domain);
-
 
76
			if ($domain[count($domain) - 1] == "local")
69
            if ($domain[count($domain) - 1] == "local") {
77
			{
70
                unset($domain[count($domain) - 1]);
78
				unset($domain[count($domain) - 1]);
71
            }
79
			}
72
            $site = implode(".", $domain);
80
			$site = implode(".", $domain);
73
            unset($out);
81
			unset($out);
-
 
82
			if ($site != $site_full)
74
            if ($site != $site_full) {
83
			{
75
                $out = substr($site, 0, 16);
84
				$out = substr($site, 0, 16);
-
 
85
			} elseif ($site_full == "weban.de")
76
            } elseif ($site_full == "weban.de") {
86
			{
77
                $out = "www-data";
87
				$out = "www-data";
-
 
88
			} else
78
            } else {
89
			{
79
                $cmd = "cat /etc/passwd | grep " . __SHOP__ . " | cut -d \":\" -f1";
90
				$cmd = "cat /etc/passwd | grep " . __SHOP__ . " | cut -d \":\" -f1";
80
                exec($cmd, $out);
91
				exec($cmd, $out);
81
                $out = $out[0];
92
				$out = $out[0];
82
            }
93
			}
83
            $task["user"] = $out;
94
			$task["user"] = $out;
84
        }
95
		}
85
        $rep_hours[0] = "exakt";
96
		$rep_hours[0] = "exakt";
86
        $rep_hours[1] = "jede Stunde";
97
		$rep_hours[1] = "jede Stunde";
87
        $hours[0] = 0;
98
		$hours[0] = 0;
88
        $hours[1] = 1;
99
		$hours[1] = 1;
-
 
100
		for ($i = 2; $i <= 23; $i++)
89
        for ($i = 2; $i <= 23; $i++) {
101
		{
90
            $hours[$i] = $i;
102
			$hours[$i] = $i;
91
            $rep_hours[$i] = "Alle " . $i . " Stunden";
103
			$rep_hours[$i] = "Alle " . $i . " Stunden";
92
        }
104
		}
93
        $rep_min[0] = "exakt";
105
		$rep_min[0] = "exakt";
94
        $rep_min[1] = "jede Minute";
106
		$rep_min[1] = "jede Minute";
-
 
107
		for ($i = 2; $i <= 30; $i++)
95
        for ($i = 2; $i <= 30; $i++) {
108
		{
96
            $rep_min[$i] = "Alle " . $i . " Minuten";
109
			$rep_min[$i] = "Alle " . $i . " Minuten";
97
        }
110
		}
-
 
111
		for ($i = 0; $i <= 59; $i++)
98
        for ($i = 0; $i <= 59; $i++) {
112
		{
99
            $minutes[$i] = $i;
113
			$minutes[$i] = $i;
100
        }
114
		}
101
        $nutzungsarten = array(
115
		$nutzungsarten = array(
102
            "" => "",
116
			"" => "",
103
            "dual" => "dual",
117
			"dual" => "dual",
104
            "automatisch" => "automatisch",
118
			"automatisch" => "automatisch",
105
            );
119
			);
106
        $tage = array(
120
		$tage = array(
107
            "Sonntag",
121
			"Sonntag",
108
            "Montag",
122
			"Montag",
109
            "Dienstag",
123
			"Dienstag",
110
            "Mittwoch",
124
			"Mittwoch",
111
            "Donnerstag",
125
			"Donnerstag",
112
            "Freitag",
126
			"Freitag",
113
            "Samstag",
127
			"Samstag",
114
            );
128
			);
-
 
129
		for ($i = 1; $i <= 12; $i++)
115
        for ($i = 1; $i <= 12; $i++) {
130
		{
116
            $mon = sprintf("%02d", $i);
131
			$mon = sprintf("%02d", $i);
117
            $datum = "01." . $mon . "." . date("Y");
132
			$datum = "01." . $mon . "." . date("Y");
118
            $monate[$i] = strftime("%B", strtotime($datum));
133
			$monate[$i] = strftime("%B", strtotime($datum));
119
        }
134
		}
120
        $dom = array();
135
		$dom = array();
-
 
136
		for ($i = 1; $i <= 31; $i++)
121
        for ($i = 1; $i <= 31; $i++) {
137
		{
122
            $day = sprintf("%02d", $i);
138
			$day = sprintf("%02d", $i);
123
            $dom[$i] = $i;
139
			$dom[$i] = $i;
124
        }
140
		}
125
        $this->smarty->assign("task", $task);
141
		$this->smarty->assign("task", $task);
126
        $this->smarty->assign("monate", $monate);
142
		$this->smarty->assign("monate", $monate);
127
        $this->smarty->assign("tage", $tage);
143
		$this->smarty->assign("tage", $tage);
128
        $this->smarty->assign("dom", $dom);
144
		$this->smarty->assign("dom", $dom);
129
        $this->smarty->assign("nutzungsarten", $nutzungsarten);
145
		$this->smarty->assign("nutzungsarten", $nutzungsarten);
130
        $this->smarty->assign("minutes", $minutes);
146
		$this->smarty->assign("minutes", $minutes);
131
        $this->smarty->assign("rep_min", $rep_min);
147
		$this->smarty->assign("rep_min", $rep_min);
132
        $this->smarty->assign("rep_hours", $rep_hours);
148
		$this->smarty->assign("rep_hours", $rep_hours);
133
        $this->smarty->assign("hours", $hours);
149
		$this->smarty->assign("hours", $hours);
134
        $this->smarty->view('scheduler_edit.tpl');
150
		$this->smarty->view('scheduler_edit.tpl');
Zeile 135... Zeile 151...
135
    }
151
	}
136
 
152
 
137
    public function save()
153
	public function save()
138
    {
154
	{
139
        $intervall = $this->create_intervall();
155
		$intervall = $this->create_intervall();
-
 
156
		if (!column_exists("schnittstellen", "aktiv", $GLOBALS["webs"]["datenbank"], $this->
140
        if (!column_exists("schnittstellen", "aktiv", $GLOBALS["webs"]["datenbank"], $this->
157
			db))
141
            db)) {
158
		{
142
            $sql = "
159
			$sql = "
143
                ALTER TABLE
160
                ALTER TABLE
144
                    schnittstellen
161
                    schnittstellen
145
                ADD
162
                ADD
146
                    aktiv BOOL NOT NULL DEFAULT '1' AFTER user
163
                    aktiv BOOL NOT NULL DEFAULT '1' AFTER user
147
            ";
164
            ";
148
            $this->db->query($sql);
165
			$this->db->query($sql);
149
        }
166
		}
-
 
167
		if (column_exists("schnittstellen", "email", $GLOBALS["webs"]["datenbank"], $this->
150
        if (column_exists("schnittstellen", "email", $GLOBALS["webs"]["datenbank"], $this->
168
			db))
151
            db)) {
169
		{
152
            $extra = "email='" . $this->input->post('email') . "',";
170
			$extra = "email='" . $this->input->post('email') . "',";
-
 
171
		}
153
        }
172
		if ($this->input->post('id'))
154
        if ($this->input->post('id')) {
173
		{
155
            $sql = "
174
			$sql = "
156
                UPDATE
175
                UPDATE
157
                    schnittstellen
176
                    schnittstellen
158
                SET
177
                SET
Zeile 167... Zeile 186...
167
                    intervall='" . $intervall . "',
186
                    intervall='" . $intervall . "',
168
                    letzte_aenderung_von='" . $_SERVER["PHP_AUTH_USER"] . "'
187
                    letzte_aenderung_von='" . $_SERVER["PHP_AUTH_USER"] . "'
169
                WHERE
188
                WHERE
170
                    id='" . $this->input->post('id') . "'
189
                    id='" . $this->input->post('id') . "'
171
            ";
190
            ";
172
            $res = $this->db->query($sql);
191
			$res = $this->db->query($sql);
173
            if ($res) {
192
			if ($res)
-
 
193
			{
174
                $msg = "Cronjob erfolgreich aktualisiert!";
194
				$msg = "Cronjob erfolgreich aktualisiert!";
175
            } else {
195
			} else
-
 
196
			{
176
                $msg = "Leider ist ein Fehler aufgetreten.<br>";
197
				$msg = "Leider ist ein Fehler aufgetreten.<br>";
177
                $msg .= "Bitte versuchen Sie es sp&auml;ter noch einmal!<br>";
198
				$msg .= "Bitte versuchen Sie es sp&auml;ter noch einmal!<br>";
178
                //$msg .= mysql_error();
199
				//$msg .= mysql_error();
179
            }
200
			}
180
        } else {
201
		} else
-
 
202
		{
181
            $sql = "
203
			$sql = "
182
                INSERT INTO
204
                INSERT INTO
183
                    schnittstellen
205
                    schnittstellen
184
                SET
206
                SET
185
                    " . $extra . "
207
                    " . $extra . "
186
                    name='" . $this->input->post('name') . "',
208
                    name='" . $this->input->post('name') . "',
Zeile 194... Zeile 216...
194
                    erstellt_am=NOW(),
216
                    erstellt_am=NOW(),
195
                    erstellt_von='" . $_SERVER["PHP_AUTH_USER"] . "',
217
                    erstellt_von='" . $_SERVER["PHP_AUTH_USER"] . "',
196
                    letzte_aenderung_von='" . $_SERVER["PHP_AUTH_USER"] . "'
218
                    letzte_aenderung_von='" . $_SERVER["PHP_AUTH_USER"] . "'
Zeile 197... Zeile 219...
197
 
219
 
198
            ";
220
            ";
199
            $res = $this->db->query($sql);
221
			$res = $this->db->query($sql);
-
 
222
			if ($res)
200
            if ($res) {
223
			{
201
                $msg = "neuen Cronjob erfolgreich angelegt!";
224
				$msg = "neuen Cronjob erfolgreich angelegt!";
-
 
225
			} else
202
            } else {
226
			{
203
                $msg = "Leider ist ein Fehler aufgetreten.<br>";
227
				$msg = "Leider ist ein Fehler aufgetreten.<br>";
204
                $msg .= "Bitte versuchen Sie es sp&auml;ter noch einmal!<br>";
228
				$msg .= "Bitte versuchen Sie es sp&auml;ter noch einmal!<br>";
205
                //$msg .= mysql_error();
229
				//$msg .= mysql_error();
206
            }
230
			}
207
        }
231
		}
208
        echo $msg;
232
		echo $msg;
Zeile 209... Zeile 233...
209
    }
233
	}
210
 
234
 
211
    private function get_task($id)
235
	private function get_task($id)
212
    {
236
	{
213
        $sql = "SELECT
237
		$sql = "SELECT
214
				*
238
				*
215
			FROM
239
			FROM
216
				schnittstellen
240
				schnittstellen
217
			WHERE
241
			WHERE
218
				id=" . $id . "
242
				id=" . $id . "
219
		";
243
		";
220
        $res = $this->db->query($sql);
244
		$res = $this->db->query($sql);
221
        $task = $res->row_array();
245
		$task = $res->row_array();
222
        $intervall = $this->parse_intervall($task["intervall"]);
246
		$intervall = $this->parse_intervall($task["intervall"]);
223
        $task["intervallParsed"] = $intervall;
247
		$task["intervallParsed"] = $intervall;
Zeile 224... Zeile 248...
224
        return $task;
248
		return $task;
225
    }
249
	}
226
 
250
 
227
    private function parse_intervall($intervall)
251
	private function parse_intervall($intervall)
228
    {
252
	{
-
 
253
		list($minute, $hour, $dom, $mon, $dow) = explode(" ", $intervall);
229
        list($minute, $hour, $dom, $mon, $dow) = explode(" ", $intervall);
254
		$pos = strpos($minute, "/");
230
        $pos = strpos($minute, "/");
255
		if ($pos !== false)
231
        if ($pos !== false) {
256
		{
-
 
257
			$intervallArr["min"] = null;
232
            $intervallArr["min"] = null;
258
			$intervallArr["rep_min"] = substr($minute, $pos + 1);
233
            $intervallArr["rep_min"] = substr($minute, $pos + 1);
259
		} elseif ($minute == "*")
234
        } elseif ($minute == "*") {
260
		{
-
 
261
			$intervallArr["min"] = null;
235
            $intervallArr["min"] = null;
262
			$intervallArr["rep_min"] = 1;
236
            $intervallArr["rep_min"] = 1;
263
		} else
237
        } else {
264
		{
238
            $intervallArr["min"] = $minute;
265
			$intervallArr["min"] = $minute;
239
            $intervallArr["rep_min"] = 0;
266
			$intervallArr["rep_min"] = 0;
-
 
267
		}
240
        }
268
		$pos = strpos($hour, "/");
241
        $pos = strpos($hour, "/");
269
		if ($pos !== false)
242
        if ($pos !== false) {
270
		{
-
 
271
			$intervallArr["hour"] = null;
243
            $intervallArr["hour"] = null;
272
			$intervallArr["rep_hour"] = substr($hour, $pos + 1);
244
            $intervallArr["rep_hour"] = substr($hour, $pos + 1);
273
		} elseif ($hour == "*")
245
        } elseif ($hour == "*") {
274
		{
-
 
275
			$intervallArr["hour"] = null;
246
            $intervallArr["hour"] = null;
276
			$intervallArr["rep_hour"] = 1;
247
            $intervallArr["rep_hour"] = 1;
277
		} else
248
        } else {
278
		{
249
            $intervallArr["hour"] = explode(",", $hour);
279
			$intervallArr["hour"] = explode(",", $hour);
-
 
280
			$intervallArr["rep_hour"] = 0;
250
            $intervallArr["rep_hour"] = 0;
281
		}
251
        }
282
		if ($mon == "*")
252
        if ($mon == "*") {
283
		{
253
            $intervallArr["mon"] = array(
284
			$intervallArr["mon"] = array(
254
                1,
285
				1,
255
                2,
286
				2,
256
                3,
287
				3,
257
                4,
288
				4,
258
                5,
289
				5,
259
                6,
290
				6,
260
                7,
291
				7,
261
                8,
292
				8,
262
                9,
293
				9,
263
                10,
294
				10,
264
                11,
295
				11,
-
 
296
				12,
265
                12,
297
				);
266
                );
298
		} else
267
        } else {
299
		{
-
 
300
			$intervallArr["mon"] = explode(",", $mon);
268
            $intervallArr["mon"] = explode(",", $mon);
301
		}
269
        }
302
		if ($dow == "*")
270
        if ($dow == "*") {
303
		{
271
            $intervallArr["dow"] = array(
304
			$intervallArr["dow"] = array(
272
                0,
305
				0,
273
                1,
306
				1,
274
                2,
307
				2,
275
                3,
308
				3,
276
                4,
309
				4,
277
                5,
310
				5,
-
 
311
				6,
278
                6,
312
				);
279
                );
313
		} else
280
        } else {
314
		{
-
 
315
			$intervallArr["dow"] = explode(",", $dow);
281
            $intervallArr["dow"] = explode(",", $dow);
316
		}
-
 
317
		if ($dom == "*")
282
        }
318
		{
283
        if ($dom == "*") {
319
			for ($i = 1; $i <= 31; $i++)
284
            for ($i = 1; $i <= 31; $i++) {
320
			{
-
 
321
				$intervallArr["dom"][] = $i;
285
                $intervallArr["dom"][] = $i;
322
			}
286
            }
323
		} else
287
        } else {
324
		{
288
            $intervallArr["dom"] = explode(",", $dom);
325
			$intervallArr["dom"] = explode(",", $dom);
Zeile 289... Zeile 326...
289
        }
326
		}
290
        return $intervallArr;
327
		return $intervallArr;
291
    }
328
	}
-
 
329
 
292
 
330
	function create_intervall()
293
    function create_intervall()
331
	{
-
 
332
		if ($this->input->post('rep_hour') != 0)
294
    {
333
		{
295
        if ($this->input->post('rep_hour') != 0) {
334
			$hour = "*";
296
            $hour = "*";
335
			if ($this->input->post('rep_hour') != 1)
-
 
336
			{
297
            if ($this->input->post('rep_hour') != 1) {
337
				$hour .= "/" . $this->input->post('rep_hour');
298
                $hour .= "/" . $this->input->post('rep_hour');
338
			}
-
 
339
		} elseif (count($this->input->post('Time_Hour')) == 24)
299
            }
340
		{
300
        } elseif (count($this->input->post('Time_Hour')) == 24) {
341
			$hour = "*";
301
            $hour = "*";
342
		} else
-
 
343
		{
302
        } else {
344
			$hour = implode(",", $this->input->post('Time_Hour'));
303
            $hour = implode(",", $this->input->post('Time_Hour'));
345
		}
-
 
346
		if ($this->input->post('rep_min') != 0)
304
        }
347
		{
305
        if ($this->input->post('rep_min') != 0) {
348
			$min = "*";
306
            $min = "*";
349
			if ($this->input->post('rep_min') != 1)
-
 
350
			{
307
            if ($this->input->post('rep_min') != 1) {
351
				$min .= "/" . $this->input->post('rep_min');
308
                $min .= "/" . $this->input->post('rep_min');
352
			}
-
 
353
		} elseif (count($this->input->post('Time_Minute')) == 60)
309
            }
354
		{
310
        } elseif (count($this->input->post('Time_Minute')) == 60) {
355
			$min = "*";
311
            $min = "*";
356
		} else
-
 
357
		{
312
        } else {
358
			$min = implode(",", $this->input->post('Time_Minute'));
313
            $min = implode(",", $this->input->post('Time_Minute'));
359
		}
-
 
360
		if (count($this->input->post('dow')) == 7)
314
        }
361
		{
315
        if (count($this->input->post('dow')) == 7) {
362
			$dow = "*";
Zeile 316... Zeile 363...
316
            $dow = "*";
363
		} else
-
 
364
		{
317
        } else {
365
			$dow = implode(",", $this->input->post('dow'));
318
            $dow = implode(",", $this->input->post('dow'));
366
		}
-
 
367
 
319
        }
368
		if (count($this->input->post('dom')) == 31)
320
 
369
		{
Zeile 321... Zeile 370...
321
        if (count($this->input->post('dom')) == 31) {
370
			$dom = "*";
-
 
371
		} else
322
            $dom = "*";
372
		{
323
        } else {
373
			$dom = implode(",", $this->input->post('dom'));
-
 
374
		}
324
            $dom = implode(",", $this->input->post('dom'));
375
 
325
        }
376
		if (count($this->input->post('mon')) == 12)
Zeile 326... Zeile 377...
326
 
377
		{
327
        if (count($this->input->post('mon')) == 12) {
378
			$mon = "*";
328
            $mon = "*";
379
		} else
329
        } else {
380
		{
330
            $mon = implode(",", $this->input->post('mon'));
381
			$mon = implode(",", $this->input->post('mon'));