From: hickert Date: Thu, 16 Aug 2007 13:32:26 +0000 (+0000) Subject: checked in first changes for gotomasses. X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=f31bf4a8f6d635d5905b96535762432cd5a6825a;p=gosa.git checked in first changes for gotomasses. Not yet finished git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@7065 594d385d-05f5-0310-b6e9-bd551577e9d8 --- diff --git a/plugins/addons/gotomasses/class_gotomasses.inc b/plugins/addons/gotomasses/class_gotomasses.inc index e88d43d0b..8588da5ce 100644 --- a/plugins/addons/gotomasses/class_gotomasses.inc +++ b/plugins/addons/gotomasses/class_gotomasses.inc @@ -13,16 +13,10 @@ class gotomasses extends plugin /* Source file that contains the csv data */ var $file_to_read = "Undefined"; #Set in constructor - /* Parsed csv content */ - var $contents = array(); + /* Queue tasks */ + var $tasks = array(); - /* Used to detect changes made on the csv content. - * js warnings will be - * shown if the content wasn't saved or discarded - */ - var $contents_backup = array(); - var $view_logged = FALSE; - var $contents_initially_loaded = FALSE; + var $dialog = NULL; function gotomasses($config, $dn= NULL) { @@ -34,236 +28,207 @@ class gotomasses extends plugin } - function get_object_groups() - { - $ret = array(); - $ldap = $this->config->get_ldap_link(); - $ldap->cd($this->config->current['BASE']); - $ldap->search("(&(objectClass=gosaGroupOfNames)(cn=*))",array("cn")); - while($attrs = $ldap->fetch()){ - $ret [$attrs['cn'][0]] = $attrs['cn'][0]; - } - return($ret); - } - function execute() { - /* Load contents */ - if(!$this->contents_initially_loaded){ - $this->load_csv_data(); - $this->contents_initially_loaded = TRUE; + /* Check posts */ + $s_entry = $s_action = ""; + $arr = array("/^edit_/"=>"edit","/^remove_/"=>"remove"); + foreach($arr as $regex => $action){ + foreach($_POST as $name => $value){ + if(preg_match($regex,$name)){ + $s_action = $action; + $s_entry = preg_replace($regex,"",$name); + $s_entry = preg_replace("/_(x|y)$/","",$s_entry); + } + } } - /* Log view */ - if(!$this->view_logged){ - $this->view_logged = TRUE; - new log("view","gotomasses/".get_class($this),$this->dn); + /* Remove entry from list */ + if($s_action == "remove" && isset($this->tasks[$s_entry])){ + unset($this->tasks[$s_entry]); } - if(isset($_POST['export_gotomass_csv']) && $this->acl_is_writeable("something")){ - $data = ""; - foreach($this->contents as $val){ - $data .= $val['MAC'].", ".$val['OG']."\n"; - } - header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); - header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT"); - header("Cache-Control: no-cache"); - header("Pragma: no-cache"); - header("Cache-Control: post-check=0, pre-check=0"); - header("Content-type: text/plain"); - if (preg_match('/MSIE 5.5/', $_SERVER['HTTP_USER_AGENT']) || - preg_match('/MSIE 6.0/', $_SERVER['HTTP_USER_AGENT'])){ - header('Content-Disposition: filename="gotomass.csv"'); - } else { - header('Content-Disposition: attachment; filename="gotomass.csv";'); - } - echo $data; - exit(); + /* Edit selected entry */ + if($s_action == "edit" && isset($this->tasks[$s_entry])){ + $entry = $this->tasks[$s_entry]; + $this->dialog = new goto_task($this->config,$entry); } - - /* Import given file */ - if(isset($_POST['import_gotomass_csv']) && isset($_FILES['mass_file'])){ - if(!$this->acl_is_writeable("something")){ - print_red(_("Your are not allowed to import csv data into this plugin.")); - }else{ - $str = @file_get_contents($_FILES['mass_file']['tmp_name']); - if(empty($str)){ - print_red(_("The uploaded file seams to be empty, import aborted.")); - }else{ - $this->load_csv_data($str); - } - } + + /* Close dialog */ + if(isset($_POST['close_goto_task'])){ + $this->dialog = NULL; } - /* Add a new empty entry to the list */ - if(isset($_POST['add_new_entry'])){ - $this->contents[] = array("MAC" => "", "OG" => "","VALID_MAC" => FALSE); + /* Close dialog */ + if(isset($_POST['close_goto_task'])){ + $this->dialog = NULL; } + + /* Display dialogs if currently opened */ + if(is_object($this->dialog)){ + $this->dialog->save_object(); + return($this->dialog->execute()); + } + + + $this->load_csv_data(); + $smarty = get_smarty(); + $plug = $_GET['plug']; + $divlist = new divlist("gotomasses"); + $divlist->SetWidth("100%"); + $divlist->SetHeader(array( array("string"=>""._("Target").""), + array("string"=>""._("Schedule")."", + "attach"=>"style='width:150px;'"), + array("string"=>""._("Type")."", + "attach"=>"style='width:50px;'"), + array("string"=>_("Action"), + "attach"=>"style='border-right:0px;width:50px;'"))); - /* Call parent execute */ - plugin::execute(); - $smarty= get_smarty(); - $smarty->assign("is_writeable",$this->acl_is_writeable("something")); - $smarty->assign("is_readable", $this->acl_is_readable("something")); - $smarty->assign("contents_modified",$this->contents_modified()); - $smarty->assign("ogs", $this->get_object_groups()); - $smarty->assign("contents", $this->contents); - $smarty->assign("launchimage","images/launch.png"); + + foreach($this->tasks as $key => $task){ + + $action = ""; + $action.= ""; + + $field1 = array("string" => $this->target_to_string($task)); + $field2 = array("string" => $this->time_to_string($task)); + $field3 = array("string" => $this->action_to_string($task)); + $field4 = array("string" => $action,"attach" => "style='border-right:0px;'"); + + + $divlist->AddEntry(array($field1,$field2,$field3,$field4)); + } + + $smarty->assign("divlist" , $divlist->DrawList()); + $smarty->assign("contents_modified" , TRUE ); return ($smarty->fetch (get_template_path('contents.tpl', TRUE))); } - /* Check if something is modified */ - function contents_modified($display = FALSE) + function target_to_string($data) { - $a = $this->contents; - $b = $this->contents_backup; - if(count($a) != count($b)){ - if($display){ - print_a(array_diff_assoc($a,$b)); - } - return(TRUE); - }else{ - foreach($a as $a_key => $a_val){ - if(count(array_diff($a_val, $b[$a_key]))){ - - if($display){ - print_a(array_diff($a_val, $b[$a_key])); - } - return(TRUE); - } - } - } - return(FALSE); + $ret = ""; + foreach($data['Target'] as $target){ + $ret .= preg_replace("/^[^:]+:/i","",$target).", "; + } + return(preg_replace("/, $/","",$ret)); } + + function time_to_string($data) + { + return($data['Minute']." ".$data['Hour']." ".$data['Day']." ".$data['Month']." ".$data['Weekday']); + } + + + function action_to_string($data) + { + switch($data['Action']){ - function load_csv_data($data = NULL) + case 'reinstall' : return("Reinstall");break; + case 'install' : return("Install");break; + case 'reboot' : return("Restart");break; + case 'update' : return("Update");break; + default : return("Unknown"); + } + } + + + function load_csv_data() { $ui = get_userinfo(); - if(!$this->acl_is_readable("something")){ - $this->contents =array(); + if(!$this->acl_is_readable("ACL missing")){ + $this->tasks =array(); print_red(_("Your are not allowed to view contents of this plugin.")); return(FALSE); } - if($data == NULL){ - if(!file_exists($this->file_to_read) || !is_readable($this->file_to_read)){ - print_red(sprintf(_("Can't locate or read csv storage file '%s'."),$this->file_to_read)); - return(FALSE); - } + if(!file_exists($this->file_to_read) || !is_readable($this->file_to_read)){ + print_red(sprintf(_("Can't locate or read csv storage file '%s'."),$this->file_to_read)); + return(FALSE); + } - $fp = @fopen($this->file_to_read,"r"); - if(!$fp){ - print_red(sprintf(_("Can't read csv storage file '%s'."),$this->file_to_read)); - return(FALSE); - } + $fp = @fopen($this->file_to_read,"r"); + if(!$fp){ + print_red(sprintf(_("Can't read csv storage file '%s'."),$this->file_to_read)); + return(FALSE); + } - $this->contents =array(); + /* Get file contents */ + $data =""; + while(!feof($fp)){ + $data.= fread($fp,512); + } - while(!feof($fp)){ - $str = trim(fgets($fp,512)); + /* Get lines from file */ + $this->tasks = array(); + $comment = ""; + $rows = split("\n",$data); - /* Get mac address */ - $og = trim(preg_replace("/^[^,;]*(,|;)/","",$str)); - $mac = preg_replace("/(,|;).*$/","",$str); + /* Walk trough rows and parse data */ + foreach($rows as $row){ - if(!empty($og) || !empty($mac)){ - $this->contents[] = array("MAC" => $mac , "OG" => $og,"VALID_MAC" => is_mac($mac)); - } + /* Skip empty lines */ + $row = trim($row); + if(empty($row)){ + continue; } - fclose($fp); - $this->contents_backup = $this->contents; - }else{ - $this->contents =array(); - $rows = split("\n",$data); - foreach($rows as $str){ - - /* Get mac address */ - $og = trim(preg_replace("/^[^,;]*(,|;)/","",$str)); - $mac = preg_replace("/(,|;).*$/","",$str); - - if(!empty($og) || !empty($mac)){ - $this->contents[] = array("MAC" => $mac , "OG" => $og, "VALID_MAC" => is_mac($mac)); - } + + /* Get comment, if available */ + if(preg_match("/^#/",$row)){ + $comment = preg_replace("/^#/","",$row); + continue; } - } + + /* Split row into minutes/ hours ...*/ + $row = preg_replace('/[\t ]/umi'," ",$row); + $row = preg_replace('/ */umi'," ",$row); + $parts = split(" ",$row); + + if(count($parts) != 7){ + print_red(_("Entry broken, skipped.")); + }else{ + + $entry = array(); + $entry['Minute'] = $parts[0]; + $entry['Hour'] = $parts[1]; + $entry['Day'] = $parts[2]; + $entry['Month'] = $parts[3]; + $entry['Weekday'] = $parts[4]; + $entry['Action'] = $parts[5]; + $entry['Target'] = split(",",$parts[6]); + $entry['Comment'] = $comment; + $this->tasks [] = $entry; + } + } } function save_csv_data() { - if(!$this->acl_is_writeable("something")){ - $this->contents =array(); - print_red(_("Your are not allowed to write the content of this plugin.")); - return(FALSE); - } - - if(!file_exists($this->file_to_read) || !is_writeable($this->file_to_read)){ - print_red(sprintf(_("Can't locate or write csv storage file '%s'."),$this->file_to_read)); - }else{ - $fp = @fopen($this->file_to_read,"w"); - if(!$fp){ - print_red(sprintf(_("Can't write csv storage file '%s'."),$this->file_to_read)); - }else{ - $data = ""; - foreach($this->contents as $val){ - $data .= $val['MAC'].", ".$val['OG']."\n"; - } - fwrite($fp,$data,strlen($data)); - fclose($fp); - } - } } function save_object() { if(isset($_POST['gotomasses'])){ + } + } - /* Check for input changes */ - $ogs = $this->get_object_groups(); - foreach($this->contents as $id => $data){ - if(isset($_POST['mac_'.$id])){ - $this->contents[$id]['MAC'] = $_POST['mac_'.$id]; - $this->contents[$id]['VALID_MAC'] = is_mac($_POST['mac_'.$id]); - } - if(isset($_POST['og_'.$id]) && in_array_ics($_POST['og_'.$id],$ogs)){ - $this->contents[$id]['OG'] = $_POST['og_'.$id]; - } - } - - /* check for remove requests */ - $once = TRUE; - foreach($_POST as $name => $value){ - if(preg_match("/^remove_[0-9]*_(x|y)$/",$name) && $once){ - $once = FALSE; - $id = preg_replace("/^remove_/","",$name); - $id = preg_replace("/_(x|y)$/","",$id); - - if(isset($this->contents[$id])){ - unset($this->contents[$id]); - } - } - } - - /* Write back all changes */ - if(isset($_POST['save_gotomass_changes'])){ - $this->save_csv_data(); - /* Call load again, so we will see if everything is fine. - * And load_csv_data causes the contents_backup to be updated - */ - $this->load_csv_data(); - } - - /* Reload data from csv file ? */ - if(isset($_POST['reload_gotomass_data'])){ - $this->load_csv_data(); - } + /* Return list of object groups */ + function get_object_groups() + { + $ret = array(); + $ldap = $this->config->get_ldap_link(); + $ldap->cd($this->config->current['BASE']); + $ldap->search("(&(objectClass=gosaGroupOfNames)(cn=*))",array("cn")); + while($attrs = $ldap->fetch()){ + $ret[$attrs['cn'][0]] = $attrs['cn'][0]; } + return($ret); } diff --git a/plugins/addons/gotomasses/contents.tpl b/plugins/addons/gotomasses/contents.tpl index d2a245061..97eeea1b5 100644 --- a/plugins/addons/gotomasses/contents.tpl +++ b/plugins/addons/gotomasses/contents.tpl @@ -1,119 +1,16 @@ -
-

[F] - {t}Options{/t}  -

-
-
+

+   + {t}List of scheduled tasts{/t} +

+ + + + +
+ {$divlist} +
- - - - - - -
- {t}Export{/t}  - {if $is_readable} - - {else} - - {/if} - - - {t}Import{/t}  - - {if $is_writeable} - - - {else} - - - {/if} -
-
- - - - - - - - - {foreach from=$contents item=val key=key} - {if ($key+2)%2 ==0 } - - {else} - - {/if} - - - {if !$contents.$key.VALID_MAC} - - - - - - - {/foreach} - {if $is_writeable} - - - - - - - - {/if} -
- {t}No.{/t} - - {t}Mac address{/t} -   - - {t}Assigned object group{/t} - - {t}Action{/t} -
- {$key+1} - - {else} - - {/if} - - - - - - {if $is_writeable} - - {else} -   - {/if} -
-  - - -  - - -  - - -  - - - -
-
-

- {if $is_writeable} - - {else} - - {/if} - -

-