Revision 943 | Revision 2109 | Zur aktuellen Revision | Blame | Vergleich mit vorheriger | Letzte Änderung | Log anzeigen | RSS feed
<?phpclass Scheduler extends CI_Controller{public function __construct(){parent::__construct();}public function index(){$tasks = array();$sql = "SELECTid,name,art,skript,parameter,intervall,userFROMschnittstellenWHEREnutzungsart IN ('dual','automatisch')ANDuser!=''ORDER BYuser";$res = $this->db->query($sql);while ($row = $res->unbuffered_row('array')){$tasks[] = $row;}$this->smarty->assign("tasks", $tasks);$this->smarty->view('scheduler.tpl');}public function del($id = null){if ($id){$task = $this->get_task($id);$this->smarty->assign("task", $task);$this->smarty->view('scheduler_del.tpl');}else{$sql="DELETE FROMschnittstellenWHEREID = ".$this->input->post('id')."";$res = $this->db->query($sql);if ($res){$msg = "Cronjob wurde erfolgreich gelöscht!";}else{$msg = "Leider ist ein Fehler aufgetreten.<br>";$msg .= "Bitte versuchen Sie es später noch einmal!<br>";//$msg .= mysql_error();}echo $msg;}}public function edit($id = null){if ($id){$task = $this->get_task($id);}else{$domain = explode(".", $_SERVER["HTTP_HOST"]);$dom = array_shift($domain);$site_full = implode(".", $domain);if ($domain[count($domain) - 1] == "local"){unset($domain[count($domain) - 1]);}$site = implode(".", $domain);unset($out);if ($site != $site_full){$out = substr($site, 0, 16);}elseif ($site_full == "weban.de"){$out = "www-data";}else{$cmd = "cat /etc/passwd | grep ".__SHOP__." | cut -d \":\" -f1";exec($cmd, $out);$out = $out[0];}$task["user"] = $out;}$rep_hours[0] = "exakt";$rep_hours[1] = "jede Stunde";$hours[0] = 0;$hours[1] = 1;for ($i = 2; $i <= 23; $i++){$hours[$i] = $i;$rep_hours[$i] = "Alle ".$i." Stunden";}$rep_min[0] = "exakt";$rep_min[1] = "jede Minute";for ($i = 2; $i <= 30; $i++){$rep_min[$i] = "Alle ".$i." Minuten";}for ($i = 0; $i <= 59; $i++){$minutes[$i] = $i;}$nutzungsarten = array("" => "","dual" => "dual","automatisch" => "automatisch",);$tage = array("Sonntag","Montag","Dienstag","Mittwoch","Donnerstag","Freitag","Samstag",);for ($i = 1; $i <= 12; $i++){$mon = sprintf("%02d", $i);$datum = "01.".$mon.".".date("Y");$monate[$i] = strftime("%B", strtotime($datum));}$dom = array();for ($i = 1; $i <= 31; $i++){$day = sprintf("%02d", $i);$dom[$i] = $i;}$this->smarty->assign("task", $task);$this->smarty->assign("monate", $monate);$this->smarty->assign("tage", $tage);$this->smarty->assign("dom", $dom);$this->smarty->assign("nutzungsarten", $nutzungsarten);$this->smarty->assign("minutes", $minutes);$this->smarty->assign("rep_min", $rep_min);$this->smarty->assign("rep_hours", $rep_hours);$this->smarty->assign("hours", $hours);$this->smarty->view('scheduler_edit.tpl');}public function save(){$intervall = $this->create_intervall();if (!column_exists("schnittstellen", "aktiv", $GLOBALS["webs"]["datenbank"], $this->db)){$sql = "ALTER TABLEschnittstellenADDaktiv BOOL NOT NULL DEFAULT '1' AFTER user";$this->db->query($sql);}if (column_exists("schnittstellen", "email", $GLOBALS["webs"]["datenbank"], $this->db)){$extra = "email='".$this->input->post('email')."',";}if ($this->input->post('id')){$sql = "UPDATEschnittstellenSET".$extra."name='".$this->input->post("name")."',art='".$this->input->post('art')."',user='".$this->input->post('user')."',skript='".$this->input->post('skript')."',parameter='".$this->input->post('parameter')."',nutzungsart='".$this->input->post('nutzungsart')."',aktiv = ".$this->input->post('aktiv').",intervall='".$intervall."',letzte_aenderung_von='".$_SERVER["PHP_AUTH_USER"]."'WHEREid='".$this->input->post('id')."'";$res = $this->db->query($sql);if ($res){$msg = "Cronjob erfolgreich aktualisiert!";}else{$msg = "Leider ist ein Fehler aufgetreten.<br>";$msg .= "Bitte versuchen Sie es später noch einmal!<br>";//$msg .= mysql_error();}}else{$sql = "INSERT INTOschnittstellenSET".$extra."name='".$this->input->post('name')."',art='".$this->input->post('art')."',user='".$this->input->post('user')."',skript='".$this->input->post('skript')."',parameter='".$this->input->post('parameter')."',nutzungsart='".$this->input->post('nutzungsart')."',aktiv = ".$this->input->post('aktiv').",intervall='".$intervall."',erstellt_am=NOW(),erstellt_von='".$_SERVER["PHP_AUTH_USER"]."',letzte_aenderung_von='".$_SERVER["PHP_AUTH_USER"]."'";$res = $this->db->query($sql);if ($res){$msg = "neuen Cronjob erfolgreich angelegt!";}else{$msg = "Leider ist ein Fehler aufgetreten.<br>";$msg .= "Bitte versuchen Sie es später noch einmal!<br>";//$msg .= mysql_error();}}echo $msg;}private function get_task($id){$sql = "SELECT*FROMschnittstellenWHEREid=".$id."";$res = $this->db->query($sql);$task = $res->row_array();$intervall = $this->parse_intervall($task["intervall"]);$task["intervallParsed"] = $intervall;return $task;}private function parse_intervall($intervall){list($minute, $hour, $dom, $mon, $dow) = explode(" ", $intervall);$pos = strpos($minute, "/");if ($pos !== false){$intervallArr["min"] = null;$intervallArr["rep_min"] = substr($minute, $pos + 1);}elseif ($minute == "*"){$intervallArr["min"] = null;$intervallArr["rep_min"] = 1;}else{$intervallArr["min"] = $minute;$intervallArr["rep_min"] = 0;}$pos = strpos($hour, "/");if ($pos !== false){$intervallArr["hour"] = null;$intervallArr["rep_hour"] = substr($hour, $pos + 1);}elseif ($hour == "*"){$intervallArr["hour"] = null;$intervallArr["rep_hour"] = 1;}else{$intervallArr["hour"] = explode(",", $hour);$intervallArr["rep_hour"] = 0;}if ($mon == "*"){$intervallArr["mon"] = array(1,2,3,4,5,6,7,8,9,10,11,12,);}else{$intervallArr["mon"] = explode(",", $mon);}if ($dow == "*"){$intervallArr["dow"] = array(0,1,2,3,4,5,6,);}else{$intervallArr["dow"] = explode(",", $dow);}if ($dom == "*"){for ($i = 1; $i <= 31; $i++){$intervallArr["dom"][] = $i;}}else{$intervallArr["dom"] = explode(",", $dom);}return $intervallArr;}function create_intervall(){if ($this->input->post('rep_hour') != 0){$hour = "*";if ($this->input->post('rep_hour') != 1){$hour .= "/".$this->input->post('rep_hour');}}elseif (count($this->input->post('Time_Hour')) == 24){$hour = "*";}else{$hour = implode(",", $this->input->post('Time_Hour'));}if ($this->input->post('rep_min') != 0){$min = "*";if ($this->input->post('rep_min') != 1){$min .= "/".$this->input->post('rep_min');}}elseif (count($this->input->post('Time_Minute')) == 60){$min = "*";}else{$min = implode(",", $this->input->post('Time_Minute'));}if (count($this->input->post('dow')) == 7){$dow = "*";}else{$dow = implode(",", $this->input->post('dow'));}if (count($this->input->post('dom')) == 31){$dom = "*";}else{$dom = implode(",", $this->input->post('dom'));}if (count($this->input->post('mon')) == 12){$mon = "*";}else{$mon = implode(",", $this->input->post('mon'));}$intervall = $min." ".$hour." ".$dom." ".$mon." ".$dow;$intervall = trim($intervall, "#");return $intervall;}}