Code

Applied fixes
[gosa.git] / plugins / admin / fai / class_faiManagement.inc
1 <?php
2 /*
3    This code is part of GOsa (https://gosa.gonicus.de)
4    Copyright (C) 2003  Cajus Pollmeier
6    This program is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 2 of the License, or
9    (at your option) any later version.
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
16    You should have received a copy of the GNU General Public License
17    along with this program; if not, write to the Free Software
18    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  */
21 require "tabsPartition.inc";
22 require "tabsVariable.inc";
23 require "tabsHook.inc";
24 require "tabsTemplate.inc";
25 require "tabsScript.inc";
26 require "tabsProfile.inc";
27 require "tabsPackage.inc";
29 class faiManagement extends plugin
30 {
31         /* Definitions */
32         var $plHeadline                 = "FAI";
33         var $plDescription              = "Fully Automatic Installation - management";
35         /* CLI vars */
36         var $cli_summary                = "Handling of FAI entries";
37         var $cli_description    = "This plugin represents a management tool\n
38                 which allows us to manage all needed attributes for fully automatic installations (FAI)";
39         var $cli_parameters             = array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
41         /* Headpage attributes */
42         var $departments= array();
43         var $deptabs= NULL;
44   var $lock_type    = "";    // should be branch/freeze
45   var $lock_name    = "";
46   var $lock_dn      = "";  
48         /* attribute list for save action */
49         var $attributes                 = array("lock_type","lock_name","lock_dn");     //      Attributes Managed by this plugin, none, 
50         //      because this is only an overview over all objects already defined in FAI.
51         var $objectclasses              = array();      //      ObjectClasses which the attributes are related to
52         var $dialog                             = array();      //      This object contains every dialog we have currently opened
54         var $objects                    = array();      //      This array contains all available objects shown in divlist
55         var $is_dialog          = false;
57   var $dispNewBranch= false;
58   var $dispNewFreeze= false;
60         /* construction/reconstruction 
61          * The Filter ($faifilter stored in $_SESSION['faifilter']) defines the last 
62          *  selected department and filter options
63          * If it is not defined already we create a new fresh faifilter.
64          */
65         function faiManagement ($config, $ui)
66         {
67                 $this->ui                       = $ui;  
69                 /* Set current dn to "", */
70                 $this->dn                       = "";
72                 /* Assign config */
73                 $this->config           = $config;
75                 /* Get global filter config */
76                 if (!is_global("faifilter")){
77                         $base   = get_base_from_people($ui->dn);
78                         $faifilter= array("base" => $base,
79                                         "regex" => "*","branch" => "main");
80                         $faifilter['ShowProfiles']      = true;
81                         $faifilter['ShowTemplates'] = true;
82                         $faifilter['ShowScripts']       = true;
83                         $faifilter['ShowHooks']         = true;
84                         $faifilter['ShowVariables']     = true;
85                         $faifilter['ShowPackages']      = true;
86                         $faifilter['ShowPartitions']=true;
87                         register_global("faifilter", $faifilter);
88                 }
89         }
91         function execute()
92         {
93     /* Call parent execute */
94     plugin::execute();
96     $_SESSION['LOCK_VARS_TO_USE'] = array("/^edit_entry$/","/^id$/","/^entry_edit_/","/^entry_delete_/");
98                 $display        = "";
99                 $smarty         = get_smarty();
100                 $smarty->assign("BranchName","");
101     $s_action   = "";
102                 $s_entry        = "";
103                 /* filter management 
104                  * Filter will be changed if POST['regex'] or $_GET['search'] isset
105                  * New Filter will be stored in session and is used to generate list contents
106                  */     
107                 $faifilter = $_SESSION['faifilter'];
108     
109     if((isset($_POST['select_branch']))&&(!empty($_POST['select_branch']))){
110       $faifilter['branch'] = $_POST['select_branch'];
111     }
113                 /* Filter is posted by apply button 
114                  * Check every single chkbox 
115                  */
116                 if(isset($_POST['regex'])){
117                         $faifilter['regex'] = $_POST['regex']."*";
118                         foreach(array("ShowPartitions","ShowProfiles","ShowTemplates","ShowScripts","ShowHooks","ShowVariables","ShowPackages") as $attrs){
119                                 if(isset($_POST[$attrs])){
120                                         $faifilter[$attrs] = true;
121                                 }else{
122                                         $faifilter[$attrs] = false;
123                                 }
124                         }
125                 }
128                 /* Check ImageButton posts
129                  * Create new tab ich new_xx is posted
130                  */
131                 foreach($_POST as $key => $val){
132       if(preg_match("/remove_branch/",$key)){
133         $s_action = "remove_branch";
134       }elseif(preg_match("/branch_branch/",$key)){
135         $s_action = "branch_branch";
136       }elseif(preg_match("/freeze_branch/",$key)){
137         $s_action = "freeze_branch";
138                         }elseif(preg_match("/create_partition/i",$key)){
139                                 $s_action = "new_partition";
140                         }elseif(preg_match("/create_script/i",$key)){
141                                 $s_action = "new_script";
142                         }elseif(preg_match("/create_hook/i",$key)){
143                                 $s_action = "new_hook";
144                         }elseif(preg_match("/create_variable/i",$key)){
145                                 $s_action = "new_variable";
146                         }elseif(preg_match("/create_template/i",$key)){
147                                 $s_action = "new_template";
148                         }elseif(preg_match("/create_package/i",$key)){
149                                 $s_action = "new_package";
150                         }elseif(preg_match("/create_profile/i",$key)){
151                                 $s_action = "new_profile";
152                         }elseif(preg_match("/edit_continue/",$key)){
153                                 $s_action = "select_class_name_finished";
154                         }elseif(preg_match("/^entry_edit_.*/",$key)){
155                                 $s_entry = preg_replace("/^entry_edit_/","",$key);
156                                 $s_entry = preg_replace("/_.*$/","",$s_entry);
157                                 $s_action = "edit";
158                         }elseif(preg_match("/^entry_delete_.*/",$key)){
159                                 $s_entry = preg_replace("/^entry_delete_/","",$key);
160                                 $s_entry = preg_replace("/_.*$/","",$s_entry);
161         $s_action = "delete";
162       }elseif(preg_match("/dep_back.*/i",$key)){
163         $faifilter['branch'] = "main";
164         $s_action="back";
165       }elseif(preg_match("/dep_home.*/i",$key)){
166         $faifilter['branch'] = "main";
167         $s_action="home";
168       }elseif(preg_match("/dep_root.*/i",$key)){
169         $faifilter['branch'] = "main";
170         $s_action="root";
171       }
173     }
175                 if($s_action=="root"){
176                         $faifilter['base']=($this->config->current['BASE']);
177                 }
179                 if($s_action=="home"){
180                         $faifilter['base']= get_base_from_people($this->ui->dn);
181                         //$faifilter['base']=(preg_replace("/^[^,]+,/","",$faifilter['base']));
182                 }
184                 if($s_action=="back"){
185                         $base_back          = preg_replace("/^[^,]+,/","",$faifilter['base']);
186                         $base_back          = convert_department_dn($base_back);
188                         if(isset($this->config->departments[trim($base_back)])){
189                                 $faifilter['base']= $this->config->departments[trim($base_back)];
190                         }else{
191                                 $faifilter['base']= $this->config->departments["/"];
192                         }
193                 }
195                 if(isset($_GET['act'])&&($_GET['act']=="dep_open")){
196             $s_action="open";
197             $s_entry = base64_decode($_GET['dep_id']);
198             $faifilter['base']= $this->config->departments[trim($s_entry)];
199         }
201                 if(isset($_GET['edit_entry'])){
202                         $s_entry = $_GET['edit_entry'];
203                         $s_action = "edit";
204                 }
206                 /* Confirm dialog 
207                  * Delte object 
208          */
209                 if ($s_action=="delete"){
211                         /* Get 'dn' from posted termlinst */
212                         $this->dn= $this->objects[$s_entry]['dn'];
214                         /* Load permissions for selected 'dn' and check if
215                            we're allowed to remove this 'dn' */
216                         $acl=           get_permissions ($this->dn, $this->ui->subtreeACL);
217                         $this->acl= get_module_permission($acl, "FAIclass", $this->dn);
218                         if (chkacl($this->acl, "delete") == ""){
220                                 /* Check locking, save current plugin in 'back_plugin', so the dialog knows where to return. */
221                                 if (($user= get_lock($this->dn)) != ""){
222                                         return(gen_locked_message ($user, $this->dn));
223                                 }
225                                 /* Lock the current entry, so nobody will edit it during deletion */
226                                 add_lock ($this->dn, $this->ui->dn);
227                                 $smarty->assign("warning", sprintf(_("You're about to delete all information about the FAI class at '%s'."), LDAP::fix($this->dn)));
228                                 return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
229                         } else {
231                                 /* Obviously the user isn't allowed to delete. Show message and
232                                    clean session. */
233                                 print_red (_("You are not allowed to delete this component!"));
234                         }
235                 }
237                 /* Delete canceled? */
238                 if (isset($_POST['delete_cancel'])){
239                         del_lock ($this->dn);
240                 }
243                 /* Deltetion was confirmed, so delete this entry
244                  */
245                 if (isset($_POST['delete_terminal_confirm'])){
247                         /* Some nice guy may send this as POST, so we've to check
248                            for the permissions again. */
249                         if (chkacl($this->acl, "delete") == ""){
251                                 /* Find out more about the object type */
252                                 $ldap   = $this->config->get_ldap_link();
253                                 $ldap->cat($this->dn);
254                                 $attrs  = $ldap->fetch();
256                                 $type   = $this->get_type($attrs);                      
258                                 $this->dialog= new $type[0]($this->config,      $this->config->data['TABS'][$type[2]], $this->dn);
259                                 $this->dialog->set_acl(array($this->acl));
261                                 $this->dialog->by_object[$type[1]]->remove_from_parent ();
262                                 unset ($this->dialog);
263                                 gosa_log ("FAI class '".$this->dn."' has been removed");
264                                 $this->dialog= NULL;
266                                 /* Terminal list has changed, reload it. */
267                         } else {
269                                 /* Normally this shouldn't be reached, send some extra
270                                    logs to notify the administrator */
271                                 print_red (_("You are not allowed to delete this component!"));
272                                 gosa_log ("Warning: '".$this->ui->uid."' tried to trick system ".
273                                                 "deletion.");
274                         }
276                         /* Remove lock file after successfull deletion */
277                         del_lock ($this->dn);
278                 }
280                 /* Edit Entry */
281                 //if($s_action == "edit"){
282                 if(($s_action == "edit") && (!isset($this->dialog->config))){
283                         $entry  = $this->objects[$s_entry];
285                         $a_setup = ($this->get_type($entry));
286                 
287                         $this->dn = $entry['dn'];
288                         /* Check locking, save current plugin in 'back_plugin', so the dialog knows where to return. */
289                         if (($user= get_lock($this->dn)) != ""){
290                                 return(gen_locked_message ($user, $this->dn));
291                         }
292                         add_lock ($this->dn, $this->ui->dn);
294                         $this->dialog= new $a_setup[0]($this->config,
295                                         $this->config->data['TABS'][$a_setup[2]],$this->dn);
296                         $this->is_dialog = true;
297       if($entry['FAIstate'] == "freeze"){
298         $this->dialog->set_acl(array("*none*"))  ;
299       }
300                         $_SESSION['objectinfo'] = $this->dn;
301                 }
303     /*  Branch handling 
304         09.01.2006
305     */
307     /* Abort creating new branch 
308      */
309     if(isset($_POST['CancelBranchName'])){
310       $this->dispNewBranch = false;
311       $this->dispNewFreeze = false;
312     }
313     
314     /* Remove branch 
315      */
316     if($s_action == "remove_branch"){
317       $base= $faifilter['branch'];
318       /* Load permissions for selected 'dn' and check if
319          we're allowed to remove this 'dn' */
320       $acl= get_permissions ($faifilter['base'], $this->ui->subtreeACL);
321       $this->acl= get_module_permission($acl, "FAIclass", $base);
322       if (chkacl($this->acl, "delete") == ""){
323         $smarty->assign("info", sprintf(_("You're about to delete a fai branch / freeze  '%s'."), $faifilter['branch']));
324         return($smarty->fetch(get_template_path('remove_branch.tpl',TRUE)));
325       } else {
326         print_red (_("You are not allowed to delete this release!"));
327       }
328     }
330     /* Delete this entry 
331      */
332     if(isset($_POST['delete_branch_confirm'])){
333       $bb =  $faifilter['branch'];
334       if(!isset($ldap)){
335         $ldap = $this->config->get_ldap_link();
336       }
338       $br = $this->getBranches();
340       if(isset($br[$bb])){
342         $name = $br[$bb];
344         $ldap->cd($bb);
345         $ldap->recursive_remove();
346         $ldap->cd(preg_replace('/,ou=fai,ou=configs,ou=systems,/', ',ou=apps,', $bb));
347         $ldap->recursive_remove();
348         $faifilter['branch'] = "main";
350         /* Post remove */
351         //  $this->lock_type is set from this->reload
352         $this->lock_name   = $name;
353         $this->lock_dn     = $bb;
355         $this->postremove();
356       }
357     }
359     /* Open dialog to insert new branch name 
360      */
362     if((isset($_POST['UseBranchName']))&&(($this->dispNewBranch)||($this->dispNewFreeze))){
363       $_SESSION['LASTPOST'] = $_POST;
365       if($this->dispNewBranch){
366         $type = "branch";
367       }else{
368         $type = "freeze";
369       }
371       /* Check branch name */
372       $name = $_POST['BranchName'];
373       $is_ok = true;
375       $smarty->assign("BranchName",$name);
377       $base= "ou=fai,ou=configs,ou=systems,".$faifilter['base'];
379       /* Check used characters */
380       if(preg_match("/[^0-9a-z \ö\ä\ü\.-_:,]/i",$name)){
381         if($type == "branch"){
382           print_red(_("Specified branch name is invalid."));
383         }else{
384           print_red(_("Specified freeze name is invalid."));
385         }
386         $is_ok = false;
387       }
389       /* Check if this name is already in use */
390       if(!$this->CheckNewBranchName($_POST['BranchName'],$faifilter['branch'])){
391         print_red(_("This name is already in use."));
392         $is_ok = false;
393       }
395       if($is_ok){
396         $_SESSION['LASTPOST']['base'] = $base;
397         $_SESSION['LASTPOST']['type'] = $type;
398         $smarty->assign("iframe", true);
399         $smarty->assign("plugID", $_GET['plug']);
400         $display        = $smarty->fetch(get_template_path('faiNewBranch.tpl', TRUE, dirname(__FILE__)));
401         return($display);
402       }
403     }
405     if(isset($_GET['PerformBranch'])){
406       /* Create it know */
407       $this->dispNewBranch = false;
408       $this->dispNewFreeze = false;
409       $base = $_SESSION['LASTPOST']['base'];
410       $_POST = $_SESSION['LASTPOST'];      
411       $name = $_POST['BranchName'];
413       $type = $_SESSION['LASTPOST']['type'];
415       $ldap = $this->config->get_ldap_link();
417       $baseToUse = $base;
418       if($_SESSION['faifilter']['branch']!="main"){
419         $baseToUse = $_SESSION['faifilter']['branch'];
420       }
422       $appsrc = preg_replace("/ou=fai,ou=configs,ou=systems,/","ou=apps,",$baseToUse); 
423       $appdst = preg_replace("/ou=fai,ou=configs,ou=systems,/","ou=apps,","ou=".$name.",".$baseToUse) ; 
425       /* Print header to have styles included */
426       echo "<!-- headers.tpl-->".$smarty->fetch(get_template_path('headers.tpl'));
427       echo "<body style='background-image:none;margin:3px;color:black'>";
429       /* Duplicate applications 
430        */
431       $ldap->cd ($appdst);
432       $ldap->recursive_remove();
433       $ldap->cd ($this->config->current['BASE']);
434       $ldap->copy_FAI_resource_recursive($appsrc,$appdst,$type,true);
436       /* Duplicate fai objects 
437        */
438       $ldap->cd ("ou=".$name.",".$baseToUse);
439       $ldap->recursive_remove();
440       $ldap->cd ($this->config->current['BASE']);
441       $ldap->copy_FAI_resource_recursive($baseToUse,"ou=".$name.",".$baseToUse,$type,true);
443       echo "<div style='width:100%;text-align:right;'><form name='form' method='post' action='?plug=".$_GET['plug']."' target='_parent'>
444               <br><input type='submit' name='back' value='"._("Continue")."'>
445             </form></div>";
447       /* Print footer to have valid html */
448       echo "</body></html>";
450       $this->dispNewFreeze = false; 
452       /* Postcreate */ 
454       /* Assign possible attributes */
455       $this->lock_type  = $type; 
456       $this->lock_name  = $name; 
457       $this->lock_dn    = $baseToUse;
458       $this->postcreate();
459       exit();
460     }
462     if(($s_action == "branch_branch")||($this->dispNewBranch)){
463       $this->dispNewBranch=true;
464       $smarty->assign("iframe",false);
465                   $display      .= $smarty->fetch(get_template_path('faiNewBranch.tpl', TRUE, dirname(__FILE__)));
466       return($display);
467     }
468     
469     if(($s_action == "freeze_branch")||($this->dispNewFreeze)){
470       $this->dispNewFreeze = true;
471       $smarty->assign("iframe",false);
472                   $display      .= $smarty->fetch(get_template_path('faiNewBranch.tpl', TRUE, dirname(__FILE__)));
473       return($display);
474     }
476     /* ENDE Branch handling 
477      */
479     /* Dialog handling */
480     if($s_action == "new_partition"){
481       $this->dialog = new askClassName($this->config,$this->dn,$this->ui,"FAIpartitionTable");
482     }
484     /* Dialog handling */
485     if($s_action == "new_script"){
486       $this->dialog = new askClassName($this->config,$this->dn,$this->ui,"FAIscript");
487     }
489     /* Dialog handling */
490     if($s_action == "new_hook"){
491       $this->dialog = new askClassName($this->config,$this->dn,$this->ui,"FAIhook");
492     }
494     /* Dialog handling */
495     if($s_action == "new_variable"){
496       $this->dialog = new askClassName($this->config,$this->dn,$this->ui,"FAIvariable");
497     }
499     /* Dialog handling */
500     if($s_action == "new_template"){
501       $this->dialog = new askClassName($this->config,$this->dn,$this->ui,"FAItemplate");
502     }
504     /* Dialog handling */
505     if($s_action == "new_package"){
506       $this->dialog = new askClassName($this->config,$this->dn,$this->ui,"FAIpackageList");
507     }
509     /* New Profile */
510     if($s_action == "new_profile"){
511       $this->dn = "new" ;
512       $a_setup= $this->get_type(array("objectClass"=>array("FAIprofile")));
514       $this->dialog = new $a_setup[0]($this->config,
515           $this->config->data['TABS'][$a_setup[2]],$this->dn);
516       $this->is_dialog = true;
518     }
520     if($s_action == "select_class_name_finished"){
521       $this->dialog->save_object();
522       if(count($this->dialog->check())!=0){
523         foreach($this->dialog->check() as $msg){
524           print_red($msg);
525         }               
526       }else{
527         $this->dn = "new" ;
528         $a_setup= $this->get_type(array("objectClass"=>array($this->dialog->objectClass)));
529         $name = $this->dialog->save();
531         $this->dialog = new $a_setup[0]($this->config,
532             $this->config->data['TABS'][$a_setup[2]],$this->dn,$name);
533         $this->dialog->by_object[$a_setup[1]]->cn = $name;
534         $this->is_dialog = true;
535       }         
536     }   
538     /* Search is set */
539     if(isset($_GET['search'])){
540       $faifilter['regex']=$_GET['search']."*";
541     }
543     /* Department select */
544     if((isset($_POST['base']))&&($s_action=="")){
545                         $faifilter['base']=$_POST['base'];
546                 }
548     $base= "ou=fai,ou=configs,ou=systems,".$faifilter['base'];
550     $br = $this->getBranches($base);
551     if(!isset($br[$faifilter['branch']])){
552       $faifilter['branch'] = "main";
553     }
554    
555     $smarty->assign("select_branch",$faifilter['branch']);
557                 /* remove double asterisks and save new filter */
558                 $faifilter['regex'] = preg_replace("/\*\*/","*",$faifilter['regex']);
559                 $_SESSION['faifilter']= $faifilter;
561                 /* Edit dialog was canceled 
562                  * Remove dialog an show management dialog
563                  */
564                 if(isset($_POST['edit_cancel'])){
565                         unset($this->dialog);
566                         $this->dialog=NULL;
567                         $this->is_dialog = false;
568                         unset($_SESSION['objectinfo']);
569                         del_lock ($this->dn);
570                 }
572                 /* This check if the given tab could be saved 
573                  * If it was possible to save it, remove dialog object. 
574                  * If it wasn't possible, show errors and keep dialog.
575                  */
576                 if((isset($_POST['edit_finish'])) && (isset($this->dialog->config))){
577                         $this->dialog->save_object();
578                         if(count($this->dialog->check())!=0){
579                                 foreach($this->dialog->check() as $msg){
580                                         print_red($msg);
581                                 }
582                         }else{
583                                 del_lock ($this->dn);
584                                 $this->dialog->save();
585                                 unset($this->dialog);
586                                 $this->dialog=NULL;
587                                 $this->is_dialog=false;
588                                 unset($_SESSION['objectinfo']);
589                         }
590                 }
592                 /* If dialog is set, but $this->is_dialog==false, then 
593                  *  only the "abort" button is shown, this are dialogs that must not be saved.  
594                  * If is_dialog == true, we are currently editing tab objects.
595                  *  Here we need both, save and cancel
596                  */ 
598                 if(($this->dialog != NULL) && (isset($this->dialog->config))){
599                         $display .= $this->dialog->execute();
600                         /* Don't show buttons if tab dialog requests this */
601                         if (((isset($this->dialog->current))&&($this->dialog->by_object[$this->dialog->current]->is_dialog))){
602                                 
603                         }elseif(((isset($this->dialog->current))&&(!$this->dialog->by_object[$this->dialog->current]->is_dialog))){
604                                 $display.= "<p style=\"text-align:right\">\n";
605                                 $display.= "<input type=\"submit\" name=\"edit_finish\" value=\""._("Finish")."\">\n";
606                                 $display.= "&nbsp;\n";
607                                 $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
608                                 $display.= "</p>";
609                         }elseif(!isset($this->dialog->current)){
610                                 $display.= "<p style=\"text-align:right\">\n";
611                                 $display.= "<input type=\"submit\" name=\"edit_continue\" value=\""._("Continue")."\">&nbsp;";
612                                 $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
613                                 $display.= "</p>";
614                         }
615                         return($display);
616                 }
618                 /* Show Management template
619                  * The following code will only be reached if no dialog (tabs or dialogs)
620                  *  are currently opened.
621                  * Assign all reguired vars to template engine
622                  */
624                 /* Prepare departments */
625                 $options= "";
626                 foreach ($this->config->idepartments as $key => $value){
627                         if ($faifilter['base'] == $key){
628                                 $options.= "<option selected='selected' value='$key'>$value</option>";
629                         } else {
630                                 $options.= "<option value='$key'>$value</option>";
631                         }
632                 }
634                 /* Create listhead, it will be shown on top of the divlist. 
635                  * It provides general navigation and object creation
636                  */
637                 $faihead = 
638                         "<div style='background:#F0F0F9;padding:5px;'>&nbsp;".
640                         "<input class='center' type='image' src='images/list_root.png' align='middle' 
641                         title='"._("Go to root department")."' name='dep_root' alt='".      _("Root")."'>&nbsp;".
643                         "<input class='center' type='image' src='images/list_up.png' align='middle' 
644                         title='"._("Go up one department")."' name='dep_back' alt='"._("Up"). "'>&nbsp;".
646                         "<input class='center' type='image' src='images/list_home.png' align='middle' 
647                         title='"._("Go to users home department")."' name='dep_home' alt='"._("Home")."'>&nbsp;".
649       " <input class='center' type='image' src='images/list_reload.png' align='middle' title='"._("Reload list")."' name='submit_department' alt='"._("Submit")."'>&nbsp;".
651                         "<img class='center' src=\"images/list_seperator.png\" alt=\"\" align=\"middle\" height=\"16\" width=\"1\">&nbsp;".
652                         
653                         " <input class='center' type='image' src='images/fai_new_profile.png' align='middle' 
654                         title='"._("New profile")."' name='Create_profile' alt='"._("P")."'>&nbsp;".
655                         
656                         "<img class='center' src=\"images/list_seperator.png\" alt=\"\" align=\"middle\" height=\"16\" width=\"1\">&nbsp;".
657                                 
658                         " <input class='center' type='image' src='images/fai_new_partitionTable.png' align='middle' 
659                         title='"._("New partition table")."' name='Create_partition' alt='"._("PT")."'>&nbsp;".
661                         " <input class='center' type='image' src='images/fai_new_script.png' align='middle' 
662                         title='"._("New scripts")."' name='Create_script' alt='"._("S")."'>&nbsp;".
664                         " <input class='center' type='image' src='images/fai_new_hook.png' align='middle' 
665                         title='"._("New hooks")."' name='Create_hook' alt='"._("H")."'>&nbsp;".
667                         " <input class='center' type='image' src='images/fai_new_variable.png' align='middle' 
668                         title='"._("New variables")."' name='Create_variable' alt='"._("V")."'>&nbsp;".
669                         
670                         " <input class='center' type='image' src='images/fai_new_template.png' align='middle' 
671                         title='"._("New templates")."' name='Create_template' alt='"._("T")."'>&nbsp;".
673                         " <input class='center' type='image' src='images/fai_new_packages.png' align='middle' 
674                         title='"._("New package list")."' name='Create_package' alt='"._("PK")."'>&nbsp;".
676                         " <img class='center' src='images/list_seperator.png' align='middle' alt='' height='16' width='1'>&nbsp;".
678                         _("Base")."&nbsp;<select name='base' onChange='mainform.submit()' class='center'>$options</select>".
679                         " <input class='center' type='image' src='images/list_submit.png' align='middle' title='"._("Submit department")."' name='submit_department' alt='"._("Submit")."'>&nbsp;".
680                         
681                         "</div>";
683                 $this->reload();
685                 /* Create list with objects */
686                 $divlist = new divlist("faiManagement"); 
687                 $divlist->SetEntriesPerPage(0);
688                 $divlist->SetSummary(_("This table displays all systems, in the selected tree."));
690                 $divlist->SetHeader(array(
691                                         array("string" => "&nbsp;", "attach" => "style='text-align:center;width:20px;'"),
692                                         array("string" => _("Name of FAI class"), "attach" => "style=''"),
693                                         array("string" => _("Class type"), "attach" => "style='width:200px;'"),
694                                         array("string" => _("Actions"), "attach" => "style='width:60px;border-right:0px;text-align:right;'")));
697                 $action  = "<input class='center' type='image' src='images/edit.png'    alt='"._("edit")."'   name='entry_edit_%KEY%' title='"._("Edit class")."'>";
698                 $action .= "<input class='center' type='image' src='images/edittrash.png' alt='"._("delete")."' name='entry_delete_%KEY%' title='"._("Delete class")."'>";
700                 $editlink ="<a href='?plug=".$_GET['plug']."&amp;edit_entry=%KEY%'>%NAME%</a>";                 
701                 $linkopen = "<a href='?plug=".$_GET['plug']."&amp;act=dep_open&amp;dep_id=%s'>%s</a>";
703                 foreach($this->departments as $key => $val) {
704                         if(!isset($this->config->departments[trim($key)])){
705                                 $this->config->departments[trim($key)]="";
706                         }
708                         $non_empty="";
709                         $keys= str_replace("/","\/",$key);
710                         foreach($this->config->departments as $keyd=>$vald ){
711                                 if(preg_match("/".$keys."\/.*/",$keyd)){
712                                         $non_empty="full";
713                                 }
714                         }
717                         $title = $this->config->departments[$key];
718                         $field0 = array("string" => "<img src='images/".$non_empty."folder.png' title='"._("department")."' alt='department'>", "attach" => "style='text-align:center;width:20px;'");
719                         $field1 = array("string" => sprintf($linkopen,base64_encode($key),$val), "attach" => "style='' title='".$title."'");
720                         $field2 = array("string" => "&nbsp;", "attach" => "style='width:200px;'");
721                         $field3 = array("string" => "&nbsp;", "attach" => "style='width:60px;border-right:0px;text-align:right;'");
723                         $divlist->AddEntry( array($field0,$field1,$field2,$field3));
725                 }
726     
727                 /* Attach objects */
728                 foreach($this->objects as $key => $value){
729                                 $info= "";
730                                 $img = "";
731                                 $type = $value['type'];
732                                 $abort=false;
734                                 switch($type) {
735                                         case "FAIpartitionTable"        : 
736                                                 if(!$faifilter['ShowPartitions']){ 
737                                                         $abort = true;
738                                                 }
739                                         $img="<img class='center' src='images/fai_partitionTable.png' title='"._("Partition table")."' alt='PT'>";
740                                         $info = _("Partition table");
741                                         break;
742                                         case "FAIpackageList"           : 
743                                                 if(!$faifilter['ShowPackages']){ 
744                                                         $abort = true;
745                                                 }
746                                         $img="<img class='center' src='images/fai_packages.png' title='"._("Package list")."' alt='PL'>";
747                                         $info = _("Package list");
748                                         break;
749                                         case "FAIscript"                        : 
750                                                 if(!$faifilter['ShowScripts']){ 
751                                                         $abort = true;
752                                                 }
753                                         $img="<img class='center' src='images/fai_script.png' title='"._("Scripts")."' alt='S'>";
754                                         $info = _("Scripts");
755                                         break;
756                                         case "FAIvariable"                      : 
757                                                 if(!$faifilter['ShowVariables']){ 
758                                                         $abort = true;
759                                                 }
760                                         $img="<img class='center' src='images/fai_variable.png' title='"._("Variables")."' alt='V'>";
761                                         $info = _("Variables");
762                                         break;
763                                         case "FAIhook"                          :
764                                                 if(!$faifilter['ShowHooks']){ 
765                                                         $abort = true;
766                                                 }
767                                         $img="<img class='center' src='images/fai_hook.png' title='"._("Hooks")."' alt='H'>";
768                                         $info = _("Hooks");
769                                         break;
770                                         case "FAIprofile"                       : 
771                                                 if(!$faifilter['ShowProfiles']){ 
772                                                         $abort = true;
773                                                 }
774                                         $img="<img class='center' src='images/fai_profile.png' title='"._("Profile")."' alt='P'>";
775                                         $info = _("Profile");
776                                         break;
777                                         case "FAItemplate"                      : 
778                                                 if(!$faifilter['ShowTemplates']){ 
779                                                         $abort = true;
780                                                 }
781                                         $img="<img class='center' src='images/fai_template.png' title='"._("Templates")."' alt='T'>";
782                                         $info = _("Templates");
783                                         break;
784                                         default                                         : 
785                                         $img="<img class='center' src='images/empty.png' alt=''>";$info = "";break;
787                                 }
788                                 
789                                 if(!$abort)     {
790                                         if((isset($value['description']))&&(!empty($value['description']))){
791                                                 $desc= " [".$value['description']."]";
792                                         }else{
793                                                 $desc= "";
794                                         }
796           if($value['FAIstate'] == "freeze"){
797             $action  = "<input class='center' type='image' src='images/edit.png'        alt='"._("edit")."'   
798               name='entry_edit_%KEY%' title='"._("Edit class")."'>";
799             $edi = $editlink;
800             $acti = $action;
801           }else{
802             $action  = "<input class='center' type='image' src='images/edit.png'        alt='"._("edit")."'   
803               name='entry_edit_%KEY%' title='"._("Edit class")."'>";
804             $action .= "<input class='center' type='image' src='images/edittrash.png' alt='"._("delete")."' 
805               name='entry_delete_%KEY%' title='"._("Delete class")."'>";
806             $acti = $action;
807             $edi = $editlink;
808           }
810                                         $field1 = array("string" => $img , "attach" => "style='text-align:center;width:20px;'");
811                                         $field2 = array("string" => preg_replace(array("/%KEY%/","/%NAME%/"),array($key,$value['cn'].$desc),$edi) , "attach" => "style=''");
812                                         $field3 = array("string" => $info, "attach" => "style='width:200px;'");
813                                         $field4 = array("string" => preg_replace("/%KEY%/",$key,$acti) , "attach" => "style='width:60px;border-right:0px;text-align:right;'");
814                                         $divlist->AddEntry(array($field1,$field2,$field3,$field4));
816                         }
817                 }
819                 foreach($faifilter as $attrs => $value){
820                         if($value){
821                                 $smarty->assign($attrs."CHK", " checked ");
822                         }else{
823                                 $smarty->assign($attrs."CHK", " ");
824                         }
825                 }
827                 /* Assign all reguired vars to template engine */
829     $branches = $this->getBranches();
830     asort($branches);
831     $smarty->assign("branchKeys",array_flip($branches));
832     $smarty->assign("branches",$branches);
833     
834                 $smarty->assign("faihead"               , $faihead);    
835                 $smarty->assign("failist"               , $divlist->DrawList());
836                 $smarty->assign("regex"                 , $faifilter['regex']); 
837                 $smarty->assign("infoimage"             , get_template_path('images/info.png'));
838                 $smarty->assign("branchimage"           , get_template_path('images/branch.png'));
839                 $smarty->assign("launchimage"   , get_template_path('images/launch.png'));
840                 $smarty->assign("alphabet"              , generate_alphabet());
841                 $smarty->assign("apply"                 , apply_filter());
842                 $smarty->assign("search_image"  , get_template_path('images/search.png'));
843                 $smarty->assign("hint", print_sizelimit_warning());
845                 $display        = $smarty->fetch(get_template_path('headpage.tpl', TRUE, dirname(__FILE__)));
846                 return ($display);
847         }
849   function getBranches($base = false,$prefix = "")
850   {
851     $ret = array("main"=>"/");
852     $ldap = $this->config->get_ldap_link();
853   
854     $ldap->cd($this->config->current['BASE']);
856     $faifilter = $_SESSION['faifilter'];
859     if(!$base){
860                 $base= "ou=fai,ou=configs,ou=systems,".$faifilter['base'];
861     }
862     $ldap->cd($base);
863     $ldap->ls("(objectClass=FAIbranch)",$base);
865     while($attrs = $ldap->fetch()){
866       
867       if((isset($attrs['ou']))&&($attrs['dn']!=$base)){
868         $ret[$attrs['dn']]= $prefix.$attrs['ou'][0];
869         $ret = array_merge($ret,$this->getBranches($attrs['dn'],"".$prefix.$attrs['ou'][0]."/"));
870       }
871     }
872     return($ret);
873   }
875         function reload()
876         {
877                 /* Create a new list of FAI object 
878                  * Object list depends on faifilter['regex']
879                  * Generate List of Partitions,Hooks,Scripts,Templates,Profiles ... 
880                  */
881                 $faifilter= get_global('faifilter');
882                 // Added for dirlist function...
884                 /* Set base for all searches */
885                 $base= "ou=fai,ou=configs,ou=systems,".$faifilter['base'];
887     if($faifilter['branch'] !="main"){
888       $base = $faifilter['branch'];
889     }
890    
891                 $regex = $faifilter['regex'];   
893                 /* Array to save objects */
894                 $objects = array();
895         
896                 $this->objects=array();
898                 /* NEW LIST MANAGMENT
899                  * We also need to search for the departments
900                  * So we are able to navigate like in konquerer
901                  */
902                 $base2 = $faifilter['base'];
904                 $res3 =  get_list2($this->ui->subtreeACL, "(&(|(ou=$regex)(description=$regex))(objectClass=gosaDepartment))",
905                                 TRUE, $base2, array("ou", "description"), TRUE);
907                 $this->departments= array();
908                 $tmp = array();
909                 foreach ($res3 as $value){
910                         $tmp[strtolower($value['dn']).$value['dn']]=$value;
911                 }
912                 ksort($tmp);
913                 foreach($tmp as $value){
914                         if(isset($value["description"][0])){
915                                 $this->departments[$value['dn']]=convert_department_dn2($value['dn'])." - [".$value["description"][0]."]";
916                         }else{
917                                 $this->departments[$value['dn']]=convert_department_dn2($value['dn']);//$value["description"][0];
918                         }
919                 }
921                 /* END NEW LIST MANAGMENT
922                  */
924         
925                 $res= get_list($this->ui->subtreeACL, "(objectClass=organizationalUnit)", 
926                                 FALSE, $base, array("cn","description","objectClass"),TRUE);
928     $str = "";
930                 foreach($res as $objecttypes){
931                         $res2 = get_list($this->ui->subtreeACL, "(&(objectClass=*)(cn=".$regex."))",
932                                         FALSE, $objecttypes['dn'], array("cn","description","objectClass","FAIclass","FAIstate"),TRUE);
933                         foreach($res2 as $object){
934                                 $type= "";      
935                                 unset($object['objectClass']['count']);
936                                 if(!isset($object['description'][0])){
937                                         $object['description'][0]="";
938                                 }
939                                 
940                                 /* Clean up object informations */
941                                 $obj['cn']                      = $object['cn'][0];
942                                 $obj['dn']                      = $object['dn'];
943                                 $obj['description'] = $object['description'][0];
944                                 $obj['objectClass'] = $object['objectClass'];
946         if(isset($object['FAIstate'])){
947           $obj['FAIstate'] = $object['FAIstate'][0];
949           /* Append type to this string, to be able to check if the selected 
950            * entry is of type 'freeze' or 'branch'
951            */
952           $str.="|".$obj['FAIstate'];
953         }else{
954           $obj['FAIstate'] ="";
955         }
957                                 if(in_array("FAIpartitionTable",$obj['objectClass'])){
958                                         $type = "FAIpartitionTable";
959                                 }elseif(in_array("FAIpackageList",$obj['objectClass'])){
960                                         $type = "FAIpackageList";
961                                 }elseif(in_array("FAIscript",$obj['objectClass'])){
962                                         $type = "FAIscript";
963                                 }elseif(in_array("FAIvariable",$obj['objectClass'])){
964                                         $type = "FAIvariable";
965                                 }elseif(in_array("FAIhook",$obj['objectClass'])){
966                                         $type = "FAIhook";
967                                 }elseif(in_array("FAIprofile",$obj['objectClass'])){
968                                         $obj['FAIclass']        = $object['FAIclass'][0];
969                                         $type = "FAIprofile";
970                                 }elseif(in_array("FAItemplate",$obj['objectClass'])){
971                                         $type = "FAItemplate";
972                                 }
973                                 $this->objects[strtolower($obj['cn']).$obj['cn'].$type] = $obj;
974                                 $this->objects[strtolower($obj['cn']).$obj['cn'].$type]['type']=$type;
975  
976                         }
977                 }
979     /* Tell class what we have currently opened 
980         'main' has type '' 
981      */
982     if(preg_match("/freeze/",$str)){
983       $this->lock_type = "freeze";
984     }elseif(preg_match("/branch/",$str)){
985       $this->lock_type = "branch";
986     }else{
987       $this->lock_type = "";
988     }
990                 ksort($this->objects);
991                 reset ($this->objects);
992         
993                 /* use numeric index, thats a bit more secure */        
994                 $tmp0 = array();
995                 foreach($this->objects as $obj){
996                         $tmp0[]= $obj;
997                 }
998                 $this->objects = array();
999                 $this->objects = $tmp0;
1001         }
1003         function remove_lock()
1004         {
1005                 if (isset($this->dn)){
1006                         del_lock ($this->dn);
1007                 }
1008         }
1010         function get_type($array){
1011                 if(in_array("FAIpartitionTable",$array['objectClass'])){
1012                         return(array("tabsPartition","faiPartitionTable","FAIPARTITIONTABS"));
1013                 }
1014                 if(in_array("FAIscript",$array['objectClass'])){
1015                         return(array("tabsScript","faiScript","FAISCRIPTTABS"));
1016                 }
1017                 if(in_array("FAItemplate",$array['objectClass'])){
1018                         return(array("tabsTemplate","faiTemplate","FAITEMPLATETABS"));
1019                 }
1020                 if(in_array("FAIhook",$array['objectClass'])){
1021                         return(array("tabsHook","faiHook","FAIHOOKTABS"));
1022                 }
1023                 if(in_array("FAIvariable",$array['objectClass'])){
1024                         return(array("tabsVariable","faiVariable","FAIVARIABLETABS"));
1025                 }
1026                 if(in_array("FAIprofile",$array['objectClass'])){
1027                         return(array("tabsProfile","faiProfile","FAIPROFILETABS"));
1028                 }
1029                 
1030                 if(in_array("FAIpackageList",$array['objectClass'])){
1031                         return(array("tabsPackage","faiPackage","FAIPACKAGETABS"));
1032                 }
1033         }
1035   function CheckNewBranchName($name,$base){
1036     $f = $_SESSION['faifilter']['branch'];
1038     if(empty($name)){
1039       return(false);
1040     }
1042     if($f == "main"){
1043       $f = $_SESSION['faifilter']['base'];
1044     } 
1045   
1046     if(in_array($name,$this->getBranches($f))) {
1047       return(false);
1048     }
1050     if(empty($name)){
1051       return(false);
1052     }
1053     
1054     if(in_array($name,array("fai","disk","packages","scripts","templates","hooks","variables","profiles"))){
1055       return(false);
1056     }
1057   
1058     return(true);
1059   }
1062 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1063 ?>