Subversion-Projekte lars-tiefland.ci

Revision

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

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