Code

Fixed application freezing
[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         {
94         /* Call parent execute */
95         plugin::execute();
97     $_SESSION['LOCK_VARS_TO_USE'] = array("/^edit_entry$/","/^id$/","/^entry_edit_/","/^entry_delete_/");
99                 $display        = "";
100                 $smarty         = get_smarty();
101                 $smarty->assign("BranchName","");
102     $s_action   = "";
103                 $s_entry        = "";
104                 /* filter management 
105                  * Filter will be changed if POST['regex'] or $_GET['search'] isset
106                  * New Filter will be stored in session and is used to generate list contents
107                  */     
108                 $faifilter = $_SESSION['faifilter'];
109     
110     if((isset($_POST['select_branch']))&&(!empty($_POST['select_branch']))){
111       $faifilter['branch'] = $_POST['select_branch'];
112     }
114                 /* Filter is posted by apply button 
115                  * Check every single chkbox 
116                  */
117                 if(isset($_POST['regex'])){
118                         $faifilter['regex'] = $_POST['regex']."*";
119                         foreach(array("ShowPartitions","ShowProfiles","ShowTemplates","ShowScripts","ShowHooks","ShowVariables","ShowPackages") as $attrs){
120                                 if(isset($_POST[$attrs])){
121                                         $faifilter[$attrs] = true;
122                                 }else{
123                                         $faifilter[$attrs] = false;
124                                 }
125                         }
126                 }
129                 /* Check ImageButton posts
130                  * Create new tab ich new_xx is posted
131                  */
132                 foreach($_POST as $key => $val){
133       if(preg_match("/remove_branch/",$key)){
134         $s_action = "remove_branch";
135       }elseif(preg_match("/branch_branch/",$key)){
136         $s_action = "branch_branch";
137       }elseif(preg_match("/freeze_branch/",$key)){
138         $s_action = "freeze_branch";
139                         }elseif(preg_match("/create_partition/i",$key)){
140                                 $s_action = "new_partition";
141                         }elseif(preg_match("/create_script/i",$key)){
142                                 $s_action = "new_script";
143                         }elseif(preg_match("/create_hook/i",$key)){
144                                 $s_action = "new_hook";
145                         }elseif(preg_match("/create_variable/i",$key)){
146                                 $s_action = "new_variable";
147                         }elseif(preg_match("/create_template/i",$key)){
148                                 $s_action = "new_template";
149                         }elseif(preg_match("/create_package/i",$key)){
150                                 $s_action = "new_package";
151                         }elseif(preg_match("/create_profile/i",$key)){
152                                 $s_action = "new_profile";
153                         }elseif(preg_match("/edit_continue/",$key)){
154                                 $s_action = "select_class_name_finished";
155                         }elseif(preg_match("/^entry_edit_.*/",$key)){
156                                 $s_entry = preg_replace("/^entry_edit_/","",$key);
157                                 $s_entry = preg_replace("/_.*$/","",$s_entry);
158                                 $s_action = "edit";
159                         }elseif(preg_match("/^entry_delete_.*/",$key)){
160                                 $s_entry = preg_replace("/^entry_delete_/","",$key);
161                                 $s_entry = preg_replace("/_.*$/","",$s_entry);
162         $s_action = "delete";
163       }elseif(preg_match("/dep_back.*/i",$key)){
164         $faifilter['branch'] = "main";
165         $s_action="back";
166       }elseif(preg_match("/dep_home.*/i",$key)){
167         $faifilter['branch'] = "main";
168         $s_action="home";
169       }elseif(preg_match("/dep_root.*/i",$key)){
170         $faifilter['branch'] = "main";
171         $s_action="root";
172       }
174     }
176                 if($s_action=="root"){
177                         $faifilter['base']=($this->config->current['BASE']);
178                 }
180                 if($s_action=="home"){
181                         $faifilter['base']= get_base_from_people($this->ui->dn);
182                         //$faifilter['base']=(preg_replace("/^[^,]+,/","",$faifilter['base']));
183                 }
185                 if($s_action=="back"){
186                         $base_back          = preg_replace("/^[^,]+,/","",$faifilter['base']);
187                         $base_back          = convert_department_dn($base_back);
189                         if(isset($this->config->departments[trim($base_back)])){
190                                 $faifilter['base']= $this->config->departments[trim($base_back)];
191                         }else{
192                                 $faifilter['base']= $this->config->departments["/"];
193                         }
194                 }
196                 if(isset($_GET['act'])&&($_GET['act']=="dep_open")){
197             $s_action="open";
198             $s_entry = base64_decode($_GET['dep_id']);
199             $faifilter['base']= $this->config->departments[trim($s_entry)];
200         }
202                 if(isset($_GET['edit_entry'])){
203                         $s_entry = $_GET['edit_entry'];
204                         $s_action = "edit";
205                 }
207                 /* Confirm dialog 
208                  * Delte object 
209          */
210                 if ($s_action=="delete"){
212                         /* Get 'dn' from posted termlinst */
213                         $this->dn= $this->objects[$s_entry]['dn'];
215                         /* Load permissions for selected 'dn' and check if
216                            we're allowed to remove this 'dn' */
217                         $acl=           get_permissions ($this->dn, $this->ui->subtreeACL);
218                         $this->acl= get_module_permission($acl, "FAIclass", $this->dn);
219                         if (chkacl($this->acl, "delete") == ""){
221                                 /* Check locking, save current plugin in 'back_plugin', so the dialog knows where to return. */
222                                 if (($user= get_lock($this->dn)) != ""){
223                                         return(gen_locked_message ($user, $this->dn));
224                                 }
226                                 /* Lock the current entry, so nobody will edit it during deletion */
227                                 add_lock ($this->dn, $this->ui->dn);
228                                 $smarty->assign("warning", sprintf(_("You're about to delete all information about the FAI class at '%s'."), LDAP::fix($this->dn)));
229                                 return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
230                         } else {
232                                 /* Obviously the user isn't allowed to delete. Show message and
233                                    clean session. */
234                                 print_red (_("You are not allowed to delete this component!"));
235                         }
236                 }
238                 /* Delete canceled? */
239                 if (isset($_POST['delete_cancel'])){
240                         del_lock ($this->dn);
241                 }
244                 /* Deltetion was confirmed, so delete this entry
245                  */
246                 if (isset($_POST['delete_terminal_confirm'])){
248                         /* Some nice guy may send this as POST, so we've to check
249                            for the permissions again. */
250                         if (chkacl($this->acl, "delete") == ""){
252                                 /* Find out more about the object type */
253                                 $ldap   = $this->config->get_ldap_link();
254                                 $ldap->cat($this->dn);
255                                 $attrs  = $ldap->fetch();
257                                 $type   = $this->get_type($attrs);                      
259                                 $this->dialog= new $type[0]($this->config,      $this->config->data['TABS'][$type[2]], $this->dn);
260                                 $this->dialog->set_acl(array($this->acl));
262                                 $this->dialog->by_object[$type[1]]->remove_from_parent ();
263                                 unset ($this->dialog);
264                                 gosa_log ("FAI class '".$this->dn."' has been removed");
265                                 $this->dialog= NULL;
267                                 /* Terminal list has changed, reload it. */
268                         } else {
270                                 /* Normally this shouldn't be reached, send some extra
271                                    logs to notify the administrator */
272                                 print_red (_("You are not allowed to delete this component!"));
273                                 gosa_log ("Warning: '".$this->ui->uid."' tried to trick system ".
274                                                 "deletion.");
275                         }
277                         /* Remove lock file after successfull deletion */
278                         del_lock ($this->dn);
279                 }
281                 /* Edit Entry */
282                 //if($s_action == "edit"){
283                 if(($s_action == "edit") && (!isset($this->dialog->config))){
284                         $entry  = $this->objects[$s_entry];
286                         $a_setup = ($this->get_type($entry));
287                 
288                         $this->dn = $entry['dn'];
289                         /* Check locking, save current plugin in 'back_plugin', so the dialog knows where to return. */
290                         if (($user= get_lock($this->dn)) != ""){
291                                 return(gen_locked_message ($user, $this->dn));
292                         }
293                         add_lock ($this->dn, $this->ui->dn);
295                         $this->dialog= new $a_setup[0]($this->config,
296                                         $this->config->data['TABS'][$a_setup[2]],$this->dn);
297                         $this->is_dialog = true;
298       if($entry['FAIstate'] == "freeze"){
299         $this->dialog->set_acl(array("*none*"))  ;
300       }
301                         $_SESSION['objectinfo'] = $this->dn;
302                 }
304     /*  Branch handling 
305         09.01.2006
306     */
308     /* Abort creating new branch 
309      */
310     if(isset($_POST['CancelBranchName'])){
311       $this->dispNewBranch = false;
312       $this->dispNewFreeze = false;
313     }
314     
315     /* Remove branch 
316      */
317     if($s_action == "remove_branch"){
318       $base= $faifilter['branch'];
319       /* Load permissions for selected 'dn' and check if
320          we're allowed to remove this 'dn' */
321       $acl= get_permissions ($faifilter['base'], $this->ui->subtreeACL);
322       $this->acl= get_module_permission($acl, "FAIclass", $base);
323       if (chkacl($this->acl, "delete") == ""){
324         $smarty->assign("info", sprintf(_("You're about to delete a fai branch / freeze  '%s'."), $faifilter['branch']));
325         return($smarty->fetch(get_template_path('remove_branch.tpl',TRUE)));
326       } else {
327         print_red (_("You are not allowed to delete this release!"));
328       }
329     }
331     /* Delete this entry 
332      */
333     if(isset($_POST['delete_branch_confirm'])){
334       $bb =  $faifilter['branch'];
335       if(!isset($ldap)){
336         $ldap = $this->config->get_ldap_link();
337       }
339       $br = $this->getBranches();
341       if(isset($br[$bb])){
343         $name = $br[$bb];
345         $ldap->cd($bb);
346         $ldap->recursive_remove();
347         $faifilter['branch'] = "main";
349         /* Post remove */
350                 
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       }
423       $appsrc = preg_replace("/ou=fai,ou=configs,ou=systems,/","ou=apps,",$baseToUse); 
424       $appdst = preg_replace("/ou=fai,ou=configs,ou=systems,/","ou=apps,","ou=".$name.",".$baseToUse) ; 
426       /* Duplicate applications 
427        */
428       $ldap->cd ($appdst);
429       $ldap->recursive_remove();
430       $ldap->cd ($this->config->current['BASE']);
431       $ldap->copy_FAI_resource_recursive($appsrc,$appdst,$type,true);
433       /* Duplicate fai objects 
434        */
435       $ldap->cd ("ou=".$name.",".$baseToUse);
436       $ldap->recursive_remove();
437       $ldap->cd ($this->config->current['BASE']);
438       $ldap->copy_FAI_resource_recursive($baseToUse,"ou=".$name.",".$baseToUse,$type,true);
440       echo "<div style='width:100%;text-align:right;'><form name='form' method='post' action='?plug=".$_GET['plug']."' target='_parent'>
441               <input type='submit' name='back' value='"._("Back")."'>
442             </form></div>";
444       $this->dispNewFreeze = false; 
446       /* Postcreate */ 
448       /* Assign possible attributes */
449       $this->lock_type  = $type; 
450       $this->lock_name  = $name; 
451       $this->lock_dn    = $baseToUse;
452       $this->postcreate();
453       exit();
454     }
456     if(($s_action == "branch_branch")||($this->dispNewBranch)){
457       $this->dispNewBranch=true;
458       $smarty->assign("iframe",false);
459                   $display      .= $smarty->fetch(get_template_path('faiNewBranch.tpl', TRUE, dirname(__FILE__)));
460       return($display);
461     }
462     
463     if(($s_action == "freeze_branch")||($this->dispNewFreeze)){
464       $this->dispNewFreeze = true;
465       $smarty->assign("iframe",false);
466                   $display      .= $smarty->fetch(get_template_path('faiNewBranch.tpl', TRUE, dirname(__FILE__)));
467       return($display);
468     }
470     /* ENDE Branch handling 
471      */
473     /* Dialog handling */
474     if($s_action == "new_partition"){
475       $this->dialog = new askClassName($this->config,$this->dn,$this->ui,"FAIpartitionTable");
476     }
478     /* Dialog handling */
479     if($s_action == "new_script"){
480       $this->dialog = new askClassName($this->config,$this->dn,$this->ui,"FAIscript");
481     }
483     /* Dialog handling */
484     if($s_action == "new_hook"){
485       $this->dialog = new askClassName($this->config,$this->dn,$this->ui,"FAIhook");
486     }
488     /* Dialog handling */
489     if($s_action == "new_variable"){
490       $this->dialog = new askClassName($this->config,$this->dn,$this->ui,"FAIvariable");
491     }
493     /* Dialog handling */
494     if($s_action == "new_template"){
495       $this->dialog = new askClassName($this->config,$this->dn,$this->ui,"FAItemplate");
496     }
498     /* Dialog handling */
499     if($s_action == "new_package"){
500       $this->dialog = new askClassName($this->config,$this->dn,$this->ui,"FAIpackageList");
501     }
503     /* New Profile */
504     if($s_action == "new_profile"){
505       $this->dn = "new" ;
506       $a_setup= $this->get_type(array("objectClass"=>array("FAIprofile")));
508       $this->dialog = new $a_setup[0]($this->config,
509           $this->config->data['TABS'][$a_setup[2]],$this->dn);
510       $this->is_dialog = true;
512     }
514     if($s_action == "select_class_name_finished"){
515       $this->dialog->save_object();
516       if(count($this->dialog->check())!=0){
517         foreach($this->dialog->check() as $msg){
518           print_red($msg);
519         }               
520       }else{
521         $this->dn = "new" ;
522         $a_setup= $this->get_type(array("objectClass"=>array($this->dialog->objectClass)));
523         $name = $this->dialog->save();
525         $this->dialog = new $a_setup[0]($this->config,
526             $this->config->data['TABS'][$a_setup[2]],$this->dn,$name);
527         $this->dialog->by_object[$a_setup[1]]->cn = $name;
528         $this->is_dialog = true;
529       }         
530     }   
532     /* Search is set */
533     if(isset($_GET['search'])){
534       $faifilter['regex']=$_GET['search']."*";
535     }
537     /* Department select */
538     if((isset($_POST['base']))&&($s_action=="")){
539                         $faifilter['base']=$_POST['base'];
540                 }
542     $base= "ou=fai,ou=configs,ou=systems,".$faifilter['base'];
544     $br = $this->getBranches($base);
545     if(!isset($br[$faifilter['branch']])){
546       $faifilter['branch'] = "main";
547     }
548    
549     $smarty->assign("select_branch",$faifilter['branch']);
551                 /* remove double asterisks and save new filter */
552                 $faifilter['regex'] = preg_replace("/\*\*/","*",$faifilter['regex']);
553                 $_SESSION['faifilter']= $faifilter;
555                 /* Edit dialog was canceled 
556                  * Remove dialog an show management dialog
557                  */
558                 if(isset($_POST['edit_cancel'])){
559                         unset($this->dialog);
560                         $this->dialog=NULL;
561                         $this->is_dialog = false;
562                         unset($_SESSION['objectinfo']);
563                         del_lock ($this->dn);
564                 }
566                 /* This check if the given tab could be saved 
567                  * If it was possible to save it, remove dialog object. 
568                  * If it wasn't possible, show errors and keep dialog.
569                  */
570                 if((isset($_POST['edit_finish'])) && (isset($this->dialog->config))){
571                         $this->dialog->save_object();
572                         if(count($this->dialog->check())!=0){
573                                 foreach($this->dialog->check() as $msg){
574                                         print_red($msg);
575                                 }
576                         }else{
577                                 del_lock ($this->dn);
578                                 $this->dialog->save();
579                                 unset($this->dialog);
580                                 $this->dialog=NULL;
581                                 $this->is_dialog=false;
582                                 unset($_SESSION['objectinfo']);
583                         }
584                 }
586                 /* If dialog is set, but $this->is_dialog==false, then 
587                  *  only the "abort" button is shown, this are dialogs that must not be saved.  
588                  * If is_dialog == true, we are currently editing tab objects.
589                  *  Here we need both, save and cancel
590                  */ 
592                 if(($this->dialog != NULL) && (isset($this->dialog->config))){
593                         $display .= $this->dialog->execute();
594                         /* Don't show buttons if tab dialog requests this */
595                         if (((isset($this->dialog->current))&&($this->dialog->by_object[$this->dialog->current]->is_dialog))){
596                                 
597                         }elseif(((isset($this->dialog->current))&&(!$this->dialog->by_object[$this->dialog->current]->is_dialog))){
598                                 $display.= "<p style=\"text-align:right\">\n";
599                                 $display.= "<input type=\"submit\" name=\"edit_finish\" value=\""._("Finish")."\">\n";
600                                 $display.= "&nbsp;\n";
601                                 $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
602                                 $display.= "</p>";
603                         }elseif(!isset($this->dialog->current)){
604                                 $display.= "<p style=\"text-align:right\">\n";
605                                 $display.= "<input type=\"submit\" name=\"edit_continue\" value=\""._("Continue")."\">&nbsp;";
606                                 $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
607                                 $display.= "</p>";
608                         }
609                         return($display);
610                 }
612                 /* Show Management template
613                  * The following code will only be reached if no dialog (tabs or dialogs)
614                  *  are currently opened.
615                  * Assign all reguired vars to template engine
616                  */
618                 /* Prepare departments */
619                 $options= "";
620                 foreach ($this->config->idepartments as $key => $value){
621                         if ($faifilter['base'] == $key){
622                                 $options.= "<option selected='selected' value='$key'>$value</option>";
623                         } else {
624                                 $options.= "<option value='$key'>$value</option>";
625                         }
626                 }
628                 /* Create listhead, it will be shown on top of the divlist. 
629                  * It provides general navigation and object creation
630                  */
631                 $faihead = 
632                         "<div style='background:#F0F0F9;padding:5px;'>&nbsp;".
634                         "<input class='center' type='image' src='images/list_up.png' align='middle' 
635                         title='"._("Go up one department")."' name='dep_back' alt='"._("Up"). "'>&nbsp;".
637                         "<input class='center' type='image' src='images/list_root.png' align='middle' 
638                         title='"._("Go to root department")."' name='dep_root' alt='".      _("Root")."'>&nbsp;".
640                         "<input class='center' type='image' src='images/list_home.png' align='middle' 
641                         title='"._("Go to users home department")."' name='dep_home' alt='"._("Home")."'>&nbsp;".
643                         "<img class='center' src=\"images/list_seperator.png\" alt=\"\" align=\"middle\" height=\"16\" width=\"1\">&nbsp;".
644                         
645                         " <input class='center' type='image' src='images/fai_new_profile.png' align='middle' 
646                         title='"._("New profile")."' name='Create_profile' alt='"._("P")."'>&nbsp;".
647                         
648                         "<img class='center' src=\"images/list_seperator.png\" alt=\"\" align=\"middle\" height=\"16\" width=\"1\">&nbsp;".
649                                 
650                         " <input class='center' type='image' src='images/fai_new_partitionTable.png' align='middle' 
651                         title='"._("New partition table")."' name='Create_partition' alt='"._("PT")."'>&nbsp;".
653                         " <input class='center' type='image' src='images/fai_new_script.png' align='middle' 
654                         title='"._("New scripts")."' name='Create_script' alt='"._("S")."'>&nbsp;".
656                         " <input class='center' type='image' src='images/fai_new_hook.png' align='middle' 
657                         title='"._("New hooks")."' name='Create_hook' alt='"._("H")."'>&nbsp;".
659                         " <input class='center' type='image' src='images/fai_new_variable.png' align='middle' 
660                         title='"._("New variables")."' name='Create_variable' alt='"._("V")."'>&nbsp;".
661                         
662                         " <input class='center' type='image' src='images/fai_new_template.png' align='middle' 
663                         title='"._("New templates")."' name='Create_template' alt='"._("T")."'>&nbsp;".
665                         " <input class='center' type='image' src='images/fai_new_packages.png' align='middle' 
666                         title='"._("New package list")."' name='Create_package' alt='"._("PK")."'>&nbsp;".
668                         " <img class='center' src='images/list_seperator.png' align='middle' alt='' height='16' width='1'>&nbsp;".
670                         _("Base")."&nbsp;<select name='base' onChange='mainform.submit()' class='center'>$options</select>".
671                         " <input class='center' type='image' src='images/list_submit.png' align='middle' title='"._("Submit department")."' name='submit_department' alt='"._("Submit")."'>&nbsp;".
672                         
673                         "</div>";
675                 $this->reload();
677                 /* Create list with objects */
678                 $divlist = new divlist("faiManagement"); 
679                 $divlist->SetEntriesPerPage(0);
680                 $divlist->SetSummary(_("This table displays all systems, in the selected tree."));
682                 $divlist->SetHeader(array(
683                                         array("string" => "&nbsp;", "attach" => "style='text-align:center;width:20px;'"),
684                                         array("string" => _("Name of FAI class"), "attach" => "style=''"),
685                                         array("string" => _("Class type"), "attach" => "style='width:200px;'"),
686                                         array("string" => _("Actions"), "attach" => "style='width:60px;border-right:0px;text-align:right;'")));
689                 $action  = "<input class='center' type='image' src='images/edit.png'    alt='"._("edit")."'   name='entry_edit_%KEY%' title='"._("Edit class")."'>";
690                 $action .= "<input class='center' type='image' src='images/edittrash.png' alt='"._("delete")."' name='entry_delete_%KEY%' title='"._("Delete class")."'>";
692                 $editlink ="<a href='?plug=".$_GET['plug']."&amp;edit_entry=%KEY%'>%NAME%</a>";                 
693                 $linkopen = "<a href='?plug=".$_GET['plug']."&amp;act=dep_open&amp;dep_id=%s'>%s</a>";
695                 foreach($this->departments as $key => $val) {
696                         if(!isset($this->config->departments[trim($key)])){
697                                 $this->config->departments[trim($key)]="";
698                         }
700                         $non_empty="";
701                         $keys= str_replace("/","\/",$key);
702                         foreach($this->config->departments as $keyd=>$vald ){
703                                 if(preg_match("/".$keys."\/.*/",$keyd)){
704                                         $non_empty="full";
705                                 }
706                         }
709                         $title = $this->config->departments[$key];
710                         $field0 = array("string" => "<img src='images/".$non_empty."folder.png' title='"._("department")."' alt='department'>", "attach" => "style='text-align:center;width:20px;'");
711                         $field1 = array("string" => sprintf($linkopen,base64_encode($key),$val), "attach" => "style='' title='".$title."'");
712                         $field2 = array("string" => "&nbsp;", "attach" => "style='width:200px;'");
713                         $field3 = array("string" => "&nbsp;", "attach" => "style='width:60px;border-right:0px;text-align:right;'");
715                         $divlist->AddEntry( array($field0,$field1,$field2,$field3));
717                 }
718     
719                 /* Attach objects */
720                 foreach($this->objects as $key => $value){
721                                 $info= "";
722                                 $img = "";
723                                 $type = $value['type'];
724                                 $abort=false;
726                                 switch($type) {
727                                         case "FAIpartitionTable"        : 
728                                                 if(!$faifilter['ShowPartitions']){ 
729                                                         $abort = true;
730                                                 }
731                                         $img="<img class='center' src='images/fai_partitionTable.png' title='"._("Partition table")."' alt='PT'>";
732                                         $info = _("Partition table");
733                                         break;
734                                         case "FAIpackageList"           : 
735                                                 if(!$faifilter['ShowPackages']){ 
736                                                         $abort = true;
737                                                 }
738                                         $img="<img class='center' src='images/fai_packages.png' title='"._("Package list")."' alt='PL'>";
739                                         $info = _("Package list");
740                                         break;
741                                         case "FAIscript"                        : 
742                                                 if(!$faifilter['ShowScripts']){ 
743                                                         $abort = true;
744                                                 }
745                                         $img="<img class='center' src='images/fai_script.png' title='"._("Scripts")."' alt='S'>";
746                                         $info = _("Scripts");
747                                         break;
748                                         case "FAIvariable"                      : 
749                                                 if(!$faifilter['ShowVariables']){ 
750                                                         $abort = true;
751                                                 }
752                                         $img="<img class='center' src='images/fai_variable.png' title='"._("Variables")."' alt='V'>";
753                                         $info = _("Variables");
754                                         break;
755                                         case "FAIhook"                          :
756                                                 if(!$faifilter['ShowHooks']){ 
757                                                         $abort = true;
758                                                 }
759                                         $img="<img class='center' src='images/fai_hook.png' title='"._("Hooks")."' alt='H'>";
760                                         $info = _("Hooks");
761                                         break;
762                                         case "FAIprofile"                       : 
763                                                 if(!$faifilter['ShowProfiles']){ 
764                                                         $abort = true;
765                                                 }
766                                         $img="<img class='center' src='images/fai_profile.png' title='"._("Profile")."' alt='P'>";
767                                         $info = _("Profile");
768                                         break;
769                                         case "FAItemplate"                      : 
770                                                 if(!$faifilter['ShowTemplates']){ 
771                                                         $abort = true;
772                                                 }
773                                         $img="<img class='center' src='images/fai_template.png' title='"._("Templates")."' alt='T'>";
774                                         $info = _("Templates");
775                                         break;
776                                         default                                         : 
777                                         $img="<img class='center' src='images/empty.png' alt=''>";$info = "";break;
779                                 }
780                                 
781                                 if(!$abort)     {
782                                         if((isset($value['description']))&&(!empty($value['description']))){
783                                                 $desc= " [".$value['description']."]";
784                                         }else{
785                                                 $desc= "";
786                                         }
788           if($value['FAIstate'] == "freeze"){
789             $action  = "<input class='center' type='image' src='images/edit.png'        alt='"._("edit")."'   
790               name='entry_edit_%KEY%' title='"._("Edit class")."'>";
791             $edi = $editlink;
792             $acti = $action;
793           }else{
794             $action  = "<input class='center' type='image' src='images/edit.png'        alt='"._("edit")."'   
795               name='entry_edit_%KEY%' title='"._("Edit class")."'>";
796             $action .= "<input class='center' type='image' src='images/edittrash.png' alt='"._("delete")."' 
797               name='entry_delete_%KEY%' title='"._("Delete class")."'>";
798             $acti = $action;
799             $edi = $editlink;
800           }
802                                         $field1 = array("string" => $img , "attach" => "style='text-align:center;width:20px;'");
803                                         $field2 = array("string" => preg_replace(array("/%KEY%/","/%NAME%/"),array($key,$value['cn'].$desc),$edi) , "attach" => "style=''");
804                                         $field3 = array("string" => $info, "attach" => "style='width:200px;'");
805                                         $field4 = array("string" => preg_replace("/%KEY%/",$key,$acti) , "attach" => "style='width:60px;border-right:0px;text-align:right;'");
806                                         $divlist->AddEntry(array($field1,$field2,$field3,$field4));
808                         }
809                 }
811                 foreach($faifilter as $attrs => $value){
812                         if($value){
813                                 $smarty->assign($attrs."CHK", " checked ");
814                         }else{
815                                 $smarty->assign($attrs."CHK", " ");
816                         }
817                 }
819                 /* Assign all reguired vars to template engine */
821     $branches = $this->getBranches();
822     asort($branches);
823     $smarty->assign("branchKeys",array_flip($branches));
824     $smarty->assign("branches",$branches);
825     
826                 $smarty->assign("faihead"               , $faihead);    
827                 $smarty->assign("failist"               , $divlist->DrawList());
828                 $smarty->assign("regex"                 , $faifilter['regex']); 
829                 $smarty->assign("infoimage"             , get_template_path('images/info.png'));
830                 $smarty->assign("branchimage"           , get_template_path('images/branch.png'));
831                 $smarty->assign("launchimage"   , get_template_path('images/launch.png'));
832                 $smarty->assign("alphabet"              , generate_alphabet());
833                 $smarty->assign("apply"                 , apply_filter());
834                 $smarty->assign("search_image"  , get_template_path('images/search.png'));
835                 $smarty->assign("hint", print_sizelimit_warning());
837                 $display        = $smarty->fetch(get_template_path('headpage.tpl', TRUE, dirname(__FILE__)));
838                 return ($display);
839         }
841   function getBranches($base = false,$prefix = "")
842   {
843     $ret = array("main"=>"/");
844     $ldap = $this->config->get_ldap_link();
845   
846     $ldap->cd($this->config->current['BASE']);
848     $faifilter = $_SESSION['faifilter'];
851     if(!$base){
852                 $base= "ou=fai,ou=configs,ou=systems,".$faifilter['base'];
853     }
854     $ldap->cd($base);
855     $ldap->ls("(objectClass=FAIbranch)",$base);
857     while($attrs = $ldap->fetch()){
858       
859       if((isset($attrs['ou']))&&($attrs['dn']!=$base)){
860         $ret[$attrs['dn']]= $prefix.$attrs['ou'][0];
861         $ret = array_merge($ret,$this->getBranches($attrs['dn'],"".$prefix.$attrs['ou'][0]."/"));
862       }
863     }
864     return($ret);
865   }
867         function reload()
868         {
869                 /* Create a new list of FAI object 
870                  * Object list depends on faifilter['regex']
871                  * Generate List of Partitions,Hooks,Scripts,Templates,Profiles ... 
872                  */
873                 $faifilter= get_global('faifilter');
874                 // Added for dirlist function...
876                 /* Set base for all searches */
877                 $base= "ou=fai,ou=configs,ou=systems,".$faifilter['base'];
879     if($faifilter['branch'] !="main"){
880       $base = $faifilter['branch'];
881     }
882    
883                 $regex = $faifilter['regex'];   
885                 /* Array to save objects */
886                 $objects = array();
887         
888                 $this->objects=array();
890                 /* NEW LIST MANAGMENT
891                  * We also need to search for the departments
892                  * So we are able to navigate like in konquerer
893                  */
894                 $base2 = $faifilter['base'];
896                 $res3 =  get_list2($this->ui->subtreeACL, "(&(|(ou=$regex)(description=$regex))(objectClass=gosaDepartment))",
897                                 TRUE, $base2, array("ou", "description"), TRUE);
899                 $this->departments= array();
900                 $tmp = array();
901                 foreach ($res3 as $value){
902                         $tmp[strtolower($value['dn']).$value['dn']]=$value;
903                 }
904                 ksort($tmp);
905                 foreach($tmp as $value){
906                         if(isset($value["description"][0])){
907                                 $this->departments[$value['dn']]=convert_department_dn2($value['dn'])." - [".$value["description"][0]."]";
908                         }else{
909                                 $this->departments[$value['dn']]=convert_department_dn2($value['dn']);//$value["description"][0];
910                         }
911                 }
913                 /* END NEW LIST MANAGMENT
914                  */
916         
917                 $res= get_list($this->ui->subtreeACL, "(objectClass=organizationalUnit)", 
918                                 FALSE, $base, array("cn","description","objectClass"),TRUE);
920     $str = "";
922                 foreach($res as $objecttypes){
923                         $res2 = get_list($this->ui->subtreeACL, "(&(objectClass=*)(cn=".$regex."))",
924                                         FALSE, $objecttypes['dn'], array("cn","description","objectClass","FAIclass","FAIstate"),TRUE);
925                         foreach($res2 as $object){
926                                 $type= "";      
927                                 unset($object['objectClass']['count']);
928                                 if(!isset($object['description'][0])){
929                                         $object['description'][0]="";
930                                 }
931                                 
932                                 /* Clean up object informations */
933                                 $obj['cn']                      = $object['cn'][0];
934                                 $obj['dn']                      = $object['dn'];
935                                 $obj['description'] = $object['description'][0];
936                                 $obj['objectClass'] = $object['objectClass'];
938         if(isset($object['FAIstate'])){
939           $obj['FAIstate'] = $object['FAIstate'][0];
941           /* Append type to this string, to be able to check if the selected 
942            * entry is of type 'freeze' or 'branch'
943            */
944           $str.="|".$obj['FAIstate'];
945         }else{
946           $obj['FAIstate'] ="";
947         }
949                                 if(in_array("FAIpartitionTable",$obj['objectClass'])){
950                                         $type = "FAIpartitionTable";
951                                 }elseif(in_array("FAIpackageList",$obj['objectClass'])){
952                                         $type = "FAIpackageList";
953                                 }elseif(in_array("FAIscript",$obj['objectClass'])){
954                                         $type = "FAIscript";
955                                 }elseif(in_array("FAIvariable",$obj['objectClass'])){
956                                         $type = "FAIvariable";
957                                 }elseif(in_array("FAIhook",$obj['objectClass'])){
958                                         $type = "FAIhook";
959                                 }elseif(in_array("FAIprofile",$obj['objectClass'])){
960                                         $obj['FAIclass']        = $object['FAIclass'][0];
961                                         $type = "FAIprofile";
962                                 }elseif(in_array("FAItemplate",$obj['objectClass'])){
963                                         $type = "FAItemplate";
964                                 }
965                                 $this->objects[strtolower($obj['cn']).$obj['cn'].$type] = $obj;
966                                 $this->objects[strtolower($obj['cn']).$obj['cn'].$type]['type']=$type;
967  
968                         }
969                 }
971     /* Tell class what we have currently opened 
972         'main' has type '' 
973      */
974     if(preg_match("/freeze/",$str)){
975       $this->lock_type = "freeze";
976     }elseif(preg_match("/branch/",$str)){
977       $this->lock_type = "branch";
978     }else{
979       $this->lock_type = "";
980     }
982                 ksort($this->objects);
983                 reset ($this->objects);
984         
985                 /* use numeric index, thats a bit more secure */        
986                 $tmp0 = array();
987                 foreach($this->objects as $obj){
988                         $tmp0[]= $obj;
989                 }
990                 $this->objects = array();
991                 $this->objects = $tmp0;
993         }
995         function remove_lock()
996         {
997                 if (isset($this->dn)){
998                         del_lock ($this->dn);
999                 }
1000         }
1002         function get_type($array){
1003                 if(in_array("FAIpartitionTable",$array['objectClass'])){
1004                         return(array("tabsPartition","faiPartitionTable","FAIPARTITIONTABS"));
1005                 }
1006                 if(in_array("FAIscript",$array['objectClass'])){
1007                         return(array("tabsScript","faiScript","FAISCRIPTTABS"));
1008                 }
1009                 if(in_array("FAItemplate",$array['objectClass'])){
1010                         return(array("tabsTemplate","faiTemplate","FAITEMPLATETABS"));
1011                 }
1012                 if(in_array("FAIhook",$array['objectClass'])){
1013                         return(array("tabsHook","faiHook","FAIHOOKTABS"));
1014                 }
1015                 if(in_array("FAIvariable",$array['objectClass'])){
1016                         return(array("tabsVariable","faiVariable","FAIVARIABLETABS"));
1017                 }
1018                 if(in_array("FAIprofile",$array['objectClass'])){
1019                         return(array("tabsProfile","faiProfile","FAIPROFILETABS"));
1020                 }
1021                 
1022                 if(in_array("FAIpackageList",$array['objectClass'])){
1023                         return(array("tabsPackage","faiPackage","FAIPACKAGETABS"));
1024                 }
1025         }
1027   function CheckNewBranchName($name,$base){
1028     $f = $_SESSION['faifilter']['branch'];
1030     if(empty($name)){
1031       return(false);
1032     }
1034     if($f == "main"){
1035       $f = $_SESSION['faifilter']['base'];
1036     } 
1037   
1038     if(in_array($name,$this->getBranches($f))) {
1039       return(false);
1040     }
1042     if(empty($name)){
1043       return(false);
1044     }
1045     
1046     if(in_array($name,array("fai","disk","packages","scripts","templates","hooks","variables","profiles"))){
1047       return(false);
1048     }
1049   
1050     return(true);
1051   }
1054 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1055 ?>