Code

9fb3c9769c231ed37b2611600d5462f7f88ca088
[gosa.git] / plugins / addons / gotomasses / class_gotomasses.inc
1 <?php
3 class gotomasses extends plugin
4 {
5   /* Definitions */
6   var $plHeadline     = "System deployment";
7   var $plDescription  = "This does something";
9   /* attribute list for save action */
10   var $attributes= array();
11   var $objectclasses= array();
13   /* Queue tasks */
14   var $current =false;
15   var $dialog = FALSE;
16   var $ids_to_remove = array();
17   var $divlist = NULL;
19   function gotomasses(&$config, $dn= NULL)
20   {
21     /* Include config object */
22     $this->config= &$config;
23     $this->divlist = new divListMasses($this->config,$this);
24     $this->o_queue = new hostActionQueue(&$config);
25   }
28   function execute()
29   {
30     $smarty = get_smarty();
31     /************
32      * Handle posts 
33      ************/
35     $s_entry = $s_action = "";
36     $arr = array( "/^edit_task_/"=>"edit","/^remove_task_/"=>"remove",
37                   "/^new_task_/"=>"new_task","/^remove_multiple_task_/" => "remove_multiple");
38     foreach($arr as $regex => $action){
39       foreach($_POST as $name => $value){
40         if(preg_match($regex,$name)){
41           $s_action = $action;
42           $s_entry  = preg_replace($regex,"",$name);
43           $s_entry  = preg_replace("/_(x|y)$/","",$s_entry);
44         }
45       }
46     }
48     /* Edit posted from list link */
49     if(isset($_GET['act']) && $_GET['act'] == "edit" && isset($_GET['id']) && isset($this->tasks[$_GET['id']])){
50       $s_action = "edit";
51       $s_entry = $_GET['id'];
52     }
54     /************
55      * REMOVE 
56      ************/
58     /* Remove multiple */
59     if($s_action == "remove_multiple"){
60       if(!$this->acl_is_removeable()){
61         print_red(_("You are not allowed to remove a task."));
62       }else{
63         $this->ids_to_remove = $this->list_get_selected_items();
64         $tmp = "";
65         foreach($this->ids_to_remove as $key => $id){
66           if(isset($this->tasks[$id])){
67             $task = $this->tasks[$id];
68             $tmp.= "\n".$this->target_to_string($task);
69           }else{
70             unset($this->ids_to_remove[$key]);
71           }
72         }
73         $smarty->assign("multiple", TRUE); 
74         $smarty->assign("info",sprintf(_("Your are about to delete the following tasks: %s"),"<pre>".$tmp."</pre>"));
75         $this->current = $s_entry;
76         return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
77       }
78     }
80     /* Remove specified tasks */
81     if(count($this->ids_to_remove) && isset($_POST['delete_multiple_confirm'])){
82       foreach($this->ids_to_remove as $id){
83         $this->o_queue->remove($id);    
84       }
85       $this->save();
86     }
88     /* Remove aborted */
89     if(isset($_POST['delete_cancel'])){
90       $this->ids_to_remove = array();;
91     }
94     /************
95      * EDIT 
96      ************/
98     /* Edit selected entry */
99     if($s_action == "edit" && isset($this->tasks[$s_entry])){
100       $entry = $this->tasks[$s_entry];
101       $this->dialog = new goto_task($this->config,$this,$entry);
102       $this->current = $s_entry;
103     }
105     /* New entry */
106     if($s_action== "new_task" && $this->acl_is_createable()){
107       $this->dialog = new goto_task($this->config,$this);
108       $this->current = -1;
109     }
110   
111     /* Close dialog */
112     if(isset($_POST['close_goto_task'])){
113       $this->dialog = FALSE;
114       $this->current = -1;
115     }
117     /* Close dialog */
118     if((isset($_POST['save_goto_task']) || isset($_POST['apply_goto_task'])) && is_object($this->dialog) ){
119       $this->dialog->save_object();
120       $msgs = $this->dialog->check();
121       if(count($msgs)){
122         foreach($msgs as $msg){
123           print_red($msg);  
124         }
125       }else{
126         if(isset($this->tasks[$this->current]) && $this->current != -1){
127           $this->tasks[$this->current] = $this->dialog->save();
128         }else{
129           $tmp = $this->dialog->save();
131           $targets =$tmp['Target'];
132           foreach($targets as $target){
133             $tmp['Target'] = array($target);
134             if(!$this->o_queue->add($tmp)){
135               print_red($this->o_queue->get_error());
136             }
137           }
138         }
139         if(!isset($_POST['apply_goto_task'])){
140           $this->dialog = FALSE;
141           $this->current = -1;
142         }
143         $this->save();
144       }
145     }
147     /* Display dialogs if currently opened */
148     if(is_object($this->dialog)){
149       $this->dialog->save_object();
150       return($this->dialog->execute());
151     }
154     /************
155      * Handle Divlist 
156      ************/
158     $this->divlist->execute();
159     $this->divlist->SetEntries($this->get_queue_entries()); 
160     return($this->divlist->Draw());
161   }
163     
164   function get_queue_entries()
165   {
166    if(!$this->o_queue->load()){
167      print_red("ERROR:".$this->o_queue->get_error());
168      return(FALSE);
169    }
170     $ret = array();
171     while($entry = $this->o_queue->fetch()){
172       $ret[] = $entry;
173     }
174     return($ret);
175   }
176  
186  
187   function target_to_string($data)
188   {
189     $ret = "";
190     if($data['Action'] == "initial_install"){
191       foreach($data['Initial_Target'] as $target){
192         $ret .= $target['MAC'].", ";
193       } 
194     }else{
195       foreach($data['Target'] as $target){
196         $ret .= $target.", ";
197       } 
198     }
199     return(preg_replace("/, $/","",$ret));
200   }
202   
203   function time_to_string($data)
204   {
205     return($data['Minute']." ".$data['Hour']." ".$data['Day']." ".$data['Month']." ".$data['Weekday']);
206   }
208   
209   function action_to_string($data)
210   {
211     $tmp = $this->get_actions();
212     if(isset($tmp[$data['Action']])){
213       return($tmp[$data['Action']]);
214     }else{
215       return(_("Unknown"));
216     }
217   }
219   
220   function save_object()
221   {
222     $this->divlist->save_object();
223   }
226   /* Return list of object groups */
227   function get_object_groups()
228   {
229     $ret = array();
230     $ldap = $this->config->get_ldap_link();
231     $ldap->cd($this->config->current['BASE']);
232     $ldap->search("(&(objectClass=gosaGroupOfNames)(cn=*))",array("cn"));
233     while($attrs = $ldap->fetch()){
234       $ret[$attrs['cn'][0]] = $attrs['cn'][0];
235     }
236     return($ret); 
237   }
239   
240   function save()
241   {
242   }
245   function list_get_selected_items()
246   {
247     $ids = array();
248     foreach($_POST as $name => $value){
249       if(preg_match("/^item_selected_[0-9]*$/",$name)){
250         $id   = preg_replace("/^item_selected_/","",$name);
251         $ids[$id] = $id;
252       }
253     }
254     return($ids);
255   }
258   function get_actions()
259   {
260     /* Prepare list of available actions */
261     $actions = array(       "reboot"          => _("Reboot"),
262                             "localboot"       => _("Localboot"),
263                             "halt"            => _("Halt system"),
264                             "initial_install" => _("Initial installation"),
265                             "update"          => _("Update"),
266                             "reinstall"       => _("(Re)Install"),
267                             "rescan"          => _("Rescan"),
268                             "wake"            => _("Wake"),
269                             "memcheck"        => _("Memory check"));
270     return($actions);
271   }
274   function plInfo()
275   {
276     return (array(
277         "plShortName"   => _("System mass deployment"),
278         "plDescription" => _("Provide a mechanism to automatically activate a set of systems"),
279         "plSelfModify"  => FALSE,
280         "plDepends"     => array(),
281         "plPriority"    => 0,
282         "plSection"     => array("addon"),
283         "plCategory"    => array("gotomasses" => array("objectClass" => "none", "description" => _("System mass deployment"))),
284         "plProvidedAcls" => array("Comment"   => _("Description"), 
285                                   "Action"    => _("Action"),
286                                   "Day"       => _("Day"),
287                                   "Minute"    => _("Minute"),
288                                   "Hour"      => _("Hour"),
289                                   "Month"     => _("Month"),
290                                   "Weekday"   => _("Week day"),
291                                   "Target"    => _("Target"))
292         ));
293   }
295 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
296 ?>