X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=plugins%2Faddons%2Fgotomasses%2Fclass_gotomasses.inc;h=4a58ca9c8db74179e8499b15c506f28239f3e579;hb=c90e32c493a5d7bd5496418b19a0f2b796dd8c06;hp=88a3e1b267762c9eb51f6cce5e1e85adb0854ab4;hpb=2dd0610553775a07cd552ccdcbbf650a18794a8c;p=gosa.git
diff --git a/plugins/addons/gotomasses/class_gotomasses.inc b/plugins/addons/gotomasses/class_gotomasses.inc
index 88a3e1b26..4a58ca9c8 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 = "System mass deployment";
+ var $plHeadline = "System deployment";
var $plDescription = "This does something";
/* attribute list for save action */
@@ -17,20 +17,24 @@ class gotomasses extends plugin
var $tasks = array();
var $current =false;
var $dialog = FALSE;
+ var $ids_to_remove = array();
+ var $divlist = NULL;
- function gotomasses($config, $dn= NULL)
+ function gotomasses(&$config, $dn= NULL)
{
- /* Define source file */
- $this->data_file = CONFIG_DIR."/gotomasses_machines";
-
/* Include config object */
- $this->config= $config;
+ $this->config= &$config;
+ /* Define source file */
+ $this->data_file = CONFIG_DIR."/gotomasses_machines";
+ $file = $this->config->search("gotomasses", "STORAGE_FILE",array('menu'));
+ if(!empty($file)){
+ $this->data_file = $file;
+ }
$this->load_gotomasses_data();
}
-
function execute()
{
$smarty = get_smarty();
@@ -39,7 +43,8 @@ class gotomasses extends plugin
************/
$s_entry = $s_action = "";
- $arr = array("/^edit_task_/"=>"edit","/^remove_task_/"=>"remove","/^new_task_/"=>"new_task");
+ $arr = array( "/^edit_task_/"=>"edit","/^remove_task_/"=>"remove",
+ "/^new_task_/"=>"new_task","/^remove_multiple_task_/" => "remove_multiple");
foreach($arr as $regex => $action){
foreach($_POST as $name => $value){
if(preg_match($regex,$name)){
@@ -50,17 +55,58 @@ class gotomasses extends plugin
}
}
+ /* Edit posted from list link */
+ if(isset($_GET['act']) && $_GET['act'] == "edit" && isset($_GET['id']) && isset($this->tasks[$_GET['id']])){
+ $s_action = "edit";
+ $s_entry = $_GET['id'];
+ }
+
/************
* List posts
************/
+ /* Remove multiple */
+ if($s_action == "remove_multiple"){
+ if(!$this->acl_is_removeable()){
+ print_red(_("You are not allowed to remove a task."));
+ }else{
+ $this->ids_to_remove = $this->list_get_selected_items();
+ $tmp = "";
+ foreach($this->ids_to_remove as $key => $id){
+ if(isset($this->tasks[$id])){
+ $task = $this->tasks[$id];
+ $tmp.= "\n".$this->target_to_string($task);
+ }else{
+ unset($this->ids_to_remove[$key]);
+ }
+ }
+ $smarty->assign("multiple", TRUE);
+ $smarty->assign("info",sprintf(_("Your are about to delete the following tasks: %s"),"
".$tmp."
"));
+ $this->current = $s_entry;
+ return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
+ }
+ }
+
+ /* Remove specified tasks */
+ if(count($this->ids_to_remove) && isset($_POST['delete_multiple_confirm'])){
+ foreach($this->ids_to_remove as $id){
+ if(isset($this->tasks[$id])){
+ unset($this->tasks[$id]);
+ }
+ }
+ $this->save();
+ }
+
/* Remove entry from list */
if($s_action == "remove" && isset($this->tasks[$s_entry])){
if(!$this->acl_is_removeable()){
print_red(_("You are not allowed to remove a task."));
}else{
- $smarty->assign("info",_("Your are about to delete a gotomasses task."));
+ $entry = $this->tasks[$s_entry];
$this->current = $s_entry;
+ $smarty->assign("info",sprintf(_("Your are about to delete the following tasks: %s"),
+ "".$this->target_to_string($entry)."
"));
+ $smarty->assign("multiple", FALSE);
return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
}
}
@@ -72,6 +118,11 @@ class gotomasses extends plugin
$this->save();
}
+ /* Remove aborted */
+ if(isset($_POST['delete_cancel'])){
+ $this->ids_to_remove = array();;
+ }
+
/* Edit selected entry */
if($s_action == "edit" && isset($this->tasks[$s_entry])){
$entry = $this->tasks[$s_entry];
@@ -124,64 +175,24 @@ class gotomasses extends plugin
* Handle Divlist
************/
- $plug = $_GET['plug'];
- $divlist = new MultiSelectWindow($this->config,"GotoMasses","gotomassses");
- $divlist->SetSummary(_("Gotomasses tasks"));
- $divlist->SetHeadpageMode();
- $divlist->EnableCloseButton(FALSE);
- $divlist->EnableSaveButton(FALSE);
- $divlist->SetInformation(_("This menu allows you to add, remove and change the properties of gotomasses tasks."));
-
- /* Display add button if allowed */
- if($this->acl_is_createable()){
- $header = "
-
-
";
- }else{
- $header = "";
- }
-
- /* Get Permissions */
- $ui = get_userinfo();
- $acls = $this->getacl("");
- foreach($ui->get_module_departments("gotomasses") as $dep){
- $acls .= $ui->get_category_permissions($dep,"gotomasses");
- }
-
- /* Create divlist */
- $divlist->SetListHeader($header);
- $divlist->AddHeader(array("string"=>""._("Target").""));
- $divlist->AddHeader(array("string"=>""._("Schedule")."",
- "attach"=>"style='width:100px;'"));
- $divlist->AddHeader(array("string"=>""._("Type")."",
- "attach"=>"style='width:60px;'"));
- $divlist->AddHeader(array("string"=>_("Action"),
- "attach"=>"style='border-right:0px;width:40px;'"));
-
- if(!empty($acls)){
- foreach($this->tasks as $key => $task){
- $action = "";
- if($this->acl_is_removeable()){
- $action.= "";
- }
- $field1 = array("string" => "".$this->target_to_string($task)."
");
- $field2 = array("string" => $this->time_to_string($task),"attach" => "style='width:100px;'");
- $field3 = array("string" => $this->action_to_string($task),"attach" => "style='width:60px;'");
- $field4 = array("string" => $action,"attach" => "style='text-align:right;width:40px;border-right:0px;'");
- $divlist->AddElement(array($field1,$field2,$field3,$field4));
- }
- }
-
- return($divlist->Draw());
+ $list = new divListMasses($this->config,$this);
+ $list->SetEntries($this->tasks);
+ return($list->Draw());
}
function target_to_string($data)
{
$ret = "";
- foreach($data['Target'] as $target){
- $ret .= $target.", ";
- }
+ if($data['Action'] == "initial_install"){
+ foreach($data['Initial_Target'] as $target){
+ $ret .= $target['MAC'].", ";
+ }
+ }else{
+ foreach($data['Target'] as $target){
+ $ret .= $target.", ";
+ }
+ }
return(preg_replace("/, $/","",$ret));
}
@@ -194,13 +205,11 @@ class gotomasses extends plugin
function action_to_string($data)
{
- switch($data['Action']){
-
- case 'reinstall' : return("Reinstall");break;
- case 'install' : return("Install");break;
- case 'reboot' : return("Restart");break;
- case 'update' : return("Update");break;
- default : return("Unknown");
+ $tmp = $this->get_actions();
+ if(isset($tmp[$data['Action']])){
+ return($tmp[$data['Action']]);
+ }else{
+ return(_("Unknown"));
}
}
@@ -253,7 +262,7 @@ class gotomasses extends plugin
$row = preg_replace('/ */umi'," ",$row);
$parts = split(" ",$row);
- if(count($parts) != 8){
+ if(count($parts) != 10){
print_red(_("Entry broken, skipped."));
}else{
@@ -265,7 +274,22 @@ class gotomasses extends plugin
$entry['Weekday'] = $parts[4];
$entry['Action'] = $parts[5];
$entry['OGroup'] = $parts[6];
- $entry['Target'] = split(",",$parts[7]);
+ $entry['Zone'] = $parts[7];
+ $entry['Section'] = $parts[8];
+ if($entry['Action'] == "initial_install"){
+ $tmp2 = split(";",$parts[9]);
+ foreach($tmp2 as $target){
+ $tmp = split(",",$target);
+ $entry['Initial_Target'][] = array(
+ "MAC" => $tmp[0],
+ "IP" => $tmp[1],
+ "NAME" => $tmp[2]);
+ }
+ $entry['Target'] = array();
+ }else{
+ $entry['Initial_Target'] = array();
+ $entry['Target'] = split(";",$parts[7]);
+ }
$entry['Comment'] = $comment;
$this->tasks [] = $entry;
}
@@ -279,17 +303,29 @@ class gotomasses extends plugin
foreach($this->tasks as $task){
$str .= "\n#".trim($task['Comment']);
$str .= "\n";
- $str .= str_pad($task['Minute'] ,5," ")." ";
- $str .= str_pad($task['Hour'] ,5," ")." ";
- $str .= str_pad($task['Day'] ,5," ")." ";
- $str .= str_pad($task['Month'] ,5," ")." ";
- $str .= str_pad($task['Weekday'],5," ")." ";
+ if($task['Action'] == "initial_install"){
+ $str .= "* * * * * ";
+ }else{
+ $str .= str_pad($task['Minute'] ,5," ")." ";
+ $str .= str_pad($task['Hour'] ,5," ")." ";
+ $str .= str_pad($task['Day'] ,5," ")." ";
+ $str .= str_pad($task['Month'] ,5," ")." ";
+ $str .= str_pad($task['Weekday'],5," ")." ";
+ }
$str .= str_pad($task['Action'] ,5," ")." ";
$str .= str_pad($task['OGroup'] ,5," ")." ";
- foreach($task['Target'] as $target){
- $str .= $target.",";
+ $str .= str_pad($task['Zone'] ,5," ")." ";
+ $str .= str_pad($task['Section'],5," ")." ";
+ if($task['Action'] == "initial_install"){
+ foreach($task['Initial_Target'] as $target){
+ $str .= trim($target['MAC']).",".trim($target['IP']).",".trim($target['NAME']).";";
+ }
+ }else{
+ foreach($task['Target'] as $target){
+ $str .= $target.";";
+ }
}
- $str = preg_replace("/,$/","",$str);
+ $str = preg_replace("/;$/","",$str);
}
/* check file existence*/
@@ -338,15 +374,30 @@ class gotomasses extends plugin
}
+ function list_get_selected_items()
+ {
+ $ids = array();
+ foreach($_POST as $name => $value){
+ if(preg_match("/^item_selected_[0-9]*$/",$name)){
+ $id = preg_replace("/^item_selected_/","",$name);
+ $ids[$id] = $id;
+ }
+ }
+ return($ids);
+ }
+
+
function get_actions()
{
/* Prepare list of available actions */
- $actions = array( "reboot" => _("Reboot"),
+ $actions = array( "reboot" => _("Reboot"),
"localboot" => _("Localboot"),
"halt" => _("Halt system"),
+ "initial_install" => _("Initial installation"),
"update" => _("Update"),
"reinstall" => _("(Re)Install"),
"rescan" => _("Rescan"),
+ "wake" => _("Wake"),
"memcheck" => _("Memory check"));
return($actions);
}