X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=plugins%2Faddons%2Fgotomasses%2Fclass_gotomasses.inc;h=113cbcd738283b3b486c34191d725566a1ec43bd;hb=8d8ff16c22df33fcd6336137c87c63b5b4c7f249;hp=cc5527e6c72b9a88e59241d0ff0c651253ac3599;hpb=2e7ff47d680a51400866e3a48e4eb7d191ddb599;p=gosa.git diff --git a/plugins/addons/gotomasses/class_gotomasses.inc b/plugins/addons/gotomasses/class_gotomasses.inc index cc5527e6c..113cbcd73 100644 --- a/plugins/addons/gotomasses/class_gotomasses.inc +++ b/plugins/addons/gotomasses/class_gotomasses.inc @@ -3,7 +3,7 @@ class gotomasses extends plugin { /* Definitions */ - var $plHeadline = "Mass machine"; + var $plHeadline = "System mass deployment"; var $plDescription = "This does something"; /* attribute list for save action */ @@ -14,8 +14,15 @@ class gotomasses extends plugin var $file_to_read = "Undefined"; #Set in constructor /* Parsed csv content */ - var $contents = array(); + var $contents = array(); + /* Used to detect changes made on the csv content. + * Buttons will be disabled and js warnings will be + * shown if the content wasn't saved or discarded + */ + var $contents_backup = array(); + + var $contents_initially_loaded = FALSE; function gotomasses($config, $dn= NULL) { @@ -24,8 +31,6 @@ class gotomasses extends plugin /* Include config object */ $this->config= $config; - - $this->load_csv_data(); } @@ -44,6 +49,12 @@ class gotomasses extends plugin function execute() { + /* Load contents */ + if(!$this->contents_initially_loaded){ + $this->load_csv_data(); + $this->contents_initially_loaded = TRUE; + } + if(isset($_POST['export_gotomass_csv'])){ $data = ""; foreach($this->contents as $val){ @@ -67,40 +78,80 @@ class gotomasses extends plugin /* Import given file */ if(isset($_POST['import_gotomass_csv']) && isset($_FILES['mass_file'])){ - $str = @file_get_contents($_FILES['mass_file']['tmp_name']); - if(empty($str)){ - print_red(_("The uploaded file seams to be empty, import aborted.")); + if(!$this->acl_is_writeable("something")){ + print_red(_("Your are not allowed to import csv data into this plugin.")); }else{ - $this->load_csv_data($str); + $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); + } } } /* Add a new empty entry to the list */ if(isset($_POST['add_new_entry'])){ - $this->contents[] = array("MAC" => "", "OG" => ""); + $this->contents[] = array("MAC" => "", "OG" => "","VALID_MAC" => FALSE); } /* 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"); return ($smarty->fetch (get_template_path('contents.tpl', TRUE))); } + + /* Check if something is modified */ + function contents_modified($display = FALSE) + { + $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); + } + function load_csv_data($data = NULL) { + $ui = get_userinfo(); + + if(!$this->acl_is_readable("something")){ + $this->contents =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 goto masses csv storage file '%s'."),$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 goto masses csv storage file '%s'."),$this->file_to_read)); + print_red(sprintf(_("Can't read csv storage file '%s'."),$this->file_to_read)); return(FALSE); } @@ -114,10 +165,11 @@ class gotomasses extends plugin $mac = preg_replace("/(,|;).*$/","",$str); if(!empty($og) || !empty($mac)){ - $this->contents[] = array("MAC" => $mac , "OG" => $og); + $this->contents[] = array("MAC" => $mac , "OG" => $og,"VALID_MAC" => is_mac($mac)); } } fclose($fp); + $this->contents_backup = $this->contents; }else{ $this->contents =array(); $rows = split("\n",$data); @@ -128,7 +180,7 @@ class gotomasses extends plugin $mac = preg_replace("/(,|;).*$/","",$str); if(!empty($og) || !empty($mac)){ - $this->contents[] = array("MAC" => $mac , "OG" => $og); + $this->contents[] = array("MAC" => $mac , "OG" => $og, "VALID_MAC" => is_mac($mac)); } } } @@ -137,14 +189,18 @@ class gotomasses extends plugin 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 goto masses csv storage file '%s'."),$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 goto masses csv storage file '%s'."),$this->file_to_read)); + print_red(sprintf(_("Can't write csv storage file '%s'."),$this->file_to_read)); }else{ $data = ""; foreach($this->contents as $val){ @@ -165,7 +221,8 @@ class gotomasses extends plugin $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]['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]; @@ -189,6 +246,11 @@ class gotomasses extends plugin /* 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 ? */ @@ -202,13 +264,13 @@ class gotomasses extends plugin function plInfo() { return (array( - "plShortName" => _("Mass machine deployment"), - "plDescription" => _("Mass machine deployment addon"), + "plShortName" => _("System mass deployment"), + "plDescription" => _("Provide a mechanism to automatically activate a set of systems"), "plSelfModify" => FALSE, "plDepends" => array(), "plPriority" => 0, "plSection" => array("addon"), - "plCategory" => array("gotomasses" => array("objectClass" => "none", "description" => _("Mass machine deployment"))), + "plCategory" => array("gotomasses" => array("objectClass" => "none", "description" => _("System mass deployment"))), "plProvidedAcls" => array() )); }