Code

Added sorting for branch freeze list
[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;
45         /* attribute list for save action */
46         var $attributes                 = array();      //      Attributes Managed by this plugin, none, 
47         //      because this is only an overview over all objects already defined in FAI.
48         var $objectclasses              = array();      //      ObjectClasses which the attributes are related to
49         var $dialog                             = array();      //      This object contains every dialog we have currently opened
51         var $objects                    = array();      //      This array contains all available objects shown in divlist
52         var $is_dialog          = false;
54   var $dispNewBranch= false;
55   var $dispNewFreeze= false;
57         /* construction/reconstruction 
58          * The Filter ($faifilter stored in $_SESSION['faifilter']) defines the last 
59          *  selected department and filter options
60          * If it is not defined already we create a new fresh faifilter.
61          */
62         function faiManagement ($config, $ui)
63         {
64                 $this->ui                       = $ui;  
66                 /* Set current dn to "", */
67                 $this->dn                       = "";
69                 /* Assign config */
70                 $this->config           = $config;
72                 /* Get global filter config */
73                 if (!is_global("faifilter")){
74                         $base   = get_base_from_people($ui->dn);
75                         $faifilter= array("base" => $base,
76                                         "regex" => "*","branch" => "main");
77                         $faifilter['ShowProfiles']      = true;
78                         $faifilter['ShowTemplates'] = true;
79                         $faifilter['ShowScripts']       = true;
80                         $faifilter['ShowHooks']         = true;
81                         $faifilter['ShowVariables']     = true;
82                         $faifilter['ShowPackages']      = true;
83                         $faifilter['ShowPartitions']=true;
84                         register_global("faifilter", $faifilter);
85                 }
86         }
88         function execute()
89         {
91         /* Call parent execute */
92         plugin::execute();
94                 $display        = "";
95                 $smarty         = get_smarty();
96                 $smarty->assign("BranchName","");
97     $s_action   = "";
98                 $s_entry        = "";
99                 /* filter management 
100                  * Filter will be changed if POST['regex'] or $_GET['search'] isset
101                  * New Filter will be stored in session and is used to generate list contents
102                  */     
103                 $faifilter = $_SESSION['faifilter'];
104     
105     if((isset($_POST['select_branch']))&&(!empty($_POST['select_branch']))){
106       $faifilter['branch'] = $_POST['select_branch'];
107     }
109                 /* Filter is posted by apply button 
110                  * Check every single chkbox 
111                  */
112                 if(isset($_POST['regex'])){
113                         $faifilter['regex'] = $_POST['regex']."*";
114                         foreach(array("ShowPartitions","ShowProfiles","ShowTemplates","ShowScripts","ShowHooks","ShowVariables","ShowPackages") as $attrs){
115                                 if(isset($_POST[$attrs])){
116                                         $faifilter[$attrs] = true;
117                                 }else{
118                                         $faifilter[$attrs] = false;
119                                 }
120                         }
121                 }
124                 /* Check ImageButton posts
125                  * Create new tab ich new_xx is posted
126                  */
127                 foreach($_POST as $key => $val){
128       if(preg_match("/remove_branch/",$key)){
129         $s_action = "remove_branch";
130       }elseif(preg_match("/branch_branch/",$key)){
131         $s_action = "branch_branch";
132       }elseif(preg_match("/freeze_branch/",$key)){
133         $s_action = "freeze_branch";
134                         }elseif(preg_match("/create_partition/i",$key)){
135                                 $s_action = "new_partition";
136                         }elseif(preg_match("/create_script/i",$key)){
137                                 $s_action = "new_script";
138                         }elseif(preg_match("/create_hook/i",$key)){
139                                 $s_action = "new_hook";
140                         }elseif(preg_match("/create_variable/i",$key)){
141                                 $s_action = "new_variable";
142                         }elseif(preg_match("/create_template/i",$key)){
143                                 $s_action = "new_template";
144                         }elseif(preg_match("/create_package/i",$key)){
145                                 $s_action = "new_package";
146                         }elseif(preg_match("/create_profile/i",$key)){
147                                 $s_action = "new_profile";
148                         }elseif(preg_match("/edit_continue/",$key)){
149                                 $s_action = "select_class_name_finished";
150                         }elseif(preg_match("/^entry_edit_.*/",$key)){
151                                 $s_entry = preg_replace("/^entry_edit_/","",$key);
152                                 $s_entry = preg_replace("/_.*$/","",$s_entry);
153                                 $s_action = "edit";
154                         }elseif(preg_match("/^entry_delete_.*/",$key)){
155                                 $s_entry = preg_replace("/^entry_delete_/","",$key);
156                                 $s_entry = preg_replace("/_.*$/","",$s_entry);
157         $s_action = "delete";
158       }elseif(preg_match("/dep_back.*/i",$key)){
159         $faifilter['branch'] = "main";
160         $s_action="back";
161       }elseif(preg_match("/dep_home.*/i",$key)){
162         $faifilter['branch'] = "main";
163         $s_action="home";
164       }elseif(preg_match("/dep_root.*/i",$key)){
165         $faifilter['branch'] = "main";
166         $s_action="root";
167       }
169     }
171                 if($s_action=="root"){
172                         $faifilter['base']=($this->config->current['BASE']);
173                 }
175                 if($s_action=="home"){
176                         $faifilter['base']=(preg_replace("/^[^,]+,/","",$this->ui->dn));
177                         $faifilter['base']=(preg_replace("/^[^,]+,/","",$faifilter['base']));
178                 }
180                 if($s_action=="back"){
181                         $base_back          = preg_replace("/^[^,]+,/","",$faifilter['base']);
182                         $base_back          = convert_department_dn($base_back);
184                         if(isset($this->config->departments[trim($base_back)])){
185                                 $faifilter['base']= $this->config->departments[trim($base_back)];
186                         }else{
187                                 $faifilter['base']= $this->config->departments["/"];
188                         }
189                 }
191                 if(isset($_GET['act'])&&($_GET['act']=="dep_open")){
192             $s_action="open";
193             $s_entry = base64_decode($_GET['dep_id']);
194             $faifilter['base']= $this->config->departments[trim($s_entry)];
195         }
197                 if(isset($_GET['edit_entry'])){
198                         $s_entry = $_GET['edit_entry'];
199                         $s_action = "edit";
200                 }
202                 /* Confirm dialog 
203                  * Delte object 
204          */
205                 if ($s_action=="delete"){
207                         /* Get 'dn' from posted termlinst */
208                         $this->dn= $this->objects[$s_entry]['dn'];
210                         /* Load permissions for selected 'dn' and check if
211                            we're allowed to remove this 'dn' */
212                         $acl=           get_permissions ($this->dn, $this->ui->subtreeACL);
213                         $this->acl= get_module_permission($acl, "FAIclass", $this->dn);
214                         if (chkacl($this->acl, "delete") == ""){
216                                 /* Check locking, save current plugin in 'back_plugin', so the dialog knows where to return. */
217                                 if (($user= get_lock($this->dn)) != ""){
218                                         return(gen_locked_message ($user, $this->dn));
219                                 }
221                                 /* Lock the current entry, so nobody will edit it during deletion */
222                                 add_lock ($this->dn, $this->ui->dn);
223                                 $smarty->assign("warning", sprintf(_("You're about to delete all information about the FAI class at '%s'."), $this->dn));
224                                 return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
225                         } else {
227                                 /* Obviously the user isn't allowed to delete. Show message and
228                                    clean session. */
229                                 print_red (_("You are not allowed to delete this component!"));
230                         }
231                 }
233                 /* Delete canceled? */
234                 if (isset($_POST['delete_cancel'])){
235                         del_lock ($this->dn);
236                 }
239                 /* Deltetion was confirmed, so delete this entry
240                  */
241                 if (isset($_POST['delete_terminal_confirm'])){
243                         /* Some nice guy may send this as POST, so we've to check
244                            for the permissions again. */
245                         if (chkacl($this->acl, "delete") == ""){
247                                 /* Find out more about the object type */
248                                 $ldap   = $this->config->get_ldap_link();
249                                 $ldap->cat($this->dn);
250                                 $attrs  = $ldap->fetch();
252                                 $type   = $this->get_type($attrs);                      
254                                 $this->dialog= new $type[0]($this->config,      $this->config->data['TABS'][$type[2]], $this->dn);
255                                 $this->dialog->set_acl(array($this->acl));
257                                 $this->dialog->by_object[$type[1]]->remove_from_parent ();
258                                 unset ($this->dialog);
259                                 gosa_log ("FAI class '".$this->dn."' has been removed");
260                                 $this->dialog= NULL;
262                                 /* Terminal list has changed, reload it. */
263                                 $this->reload ();
264                         } else {
266                                 /* Normally this shouldn't be reached, send some extra
267                                    logs to notify the administrator */
268                                 print_red (_("You are not allowed to delete this component!"));
269                                 gosa_log ("Warning: '".$this->ui->uid."' tried to trick system ".
270                                                 "deletion.");
271                         }
273                         /* Remove lock file after successfull deletion */
274                         del_lock ($this->dn);
275                 }
277                 /* Edit Entry */
278                 if($s_action == "edit"){
279                         $entry  = $this->objects[$s_entry];
281                         $a_setup = ($this->get_type($entry));
282                 
283                         $this->dn = $entry['dn'];
284                         /* Check locking, save current plugin in 'back_plugin', so the dialog knows where to return. */
285                         if (($user= get_lock($this->dn)) != ""){
286                                 return(gen_locked_message ($user, $this->dn));
287                         }
288                         add_lock ($this->dn, $this->ui->dn);
290                         $this->dialog= new $a_setup[0]($this->config,
291                                         $this->config->data['TABS'][$a_setup[2]],$this->dn);
292                         $this->is_dialog = true;
293                         $_SESSION['objectinfo'] = $this->dn;
294                 }
297     /*  Branch handling 
298         09.01.2006
299     */
301     /* Create new branch */
302     if((isset($_POST['UseBranchName']))&&($this->dispNewBranch)){
303      
304       /* Check branch name */
305       $name = $_POST['BranchName'];
306       $is_ok = true;
308       $smarty->assign("BranchName",$name);
309                   $base= "ou=fai,ou=configs,ou=systems,".$faifilter['base'];
310       
311       /* Check used characters */
312       if(preg_match("/[^0-9a-z \ö\ä\ü\.-_:,]/i",$name)){
313         print_red(_("Specified branch name is invalid."));
314         $is_ok = false;
315       }
316    
317       /* Check if this name is already in use */
318       if(!$this->CheckNewBranchName($_POST['BranchName'],$faifilter['branch'])){
319         print_red(_("This name is already in use."));
320         $is_ok = false;
321       }
322      
323       if($is_ok){
324         /* Create it know */
325         $ldap = $this->config->get_ldap_link();
327         $baseToUse = $base;
328         if($_SESSION['faifilter']['branch']!="main"){
329           $baseToUse = $_SESSION['faifilter']['branch'];
330         }
332         $ldap->cd ("ou=".$name.",".$baseToUse);
333         $ldap->recursive_remove();
334         
335         $ldap->cd ($this->config->current['BASE']);
336         $ldap->copy_FAI_resource_recursive($baseToUse,"ou=".$name.",".$baseToUse,"branch",true);
337         
338         $this->dispNewBranch = false; 
339       }
340     }
342     /* Abort creating new branch */
343     if(isset($_POST['CancelBranchName'])){
344       $this->dispNewBranch = false;
345       $this->dispNewFreeze = false;
346     }
348     /* Open dialog to insert new branch name */
349     if(($s_action == "branch_branch")||($this->dispNewBranch)){
350       $this->dispNewBranch=true;
351                   $base= "ou=fai,ou=configs,ou=systems,".$faifilter['base'];
352                   $display      .= $smarty->fetch(get_template_path('faiNewBranch.tpl', TRUE, dirname(__FILE__)));
353       return($display);
354     }
356     /* Remove branch */
357     if($s_action == "remove_branch"){
358       $base= $faifilter['branch'];
359       /* Load permissions for selected 'dn' and check if
360          we're allowed to remove this 'dn' */
361       $acl= get_permissions ($faifilter['base'], $this->ui->subtreeACL);
362       $this->acl= get_module_permission($acl, "fai", $base);
363       if (chkacl($this->acl, "delete") == ""){
364         $smarty->assign("info", sprintf(_("You're about to delete a fai branch / freeze  '%s'."), $faifilter['branch']));
365         return($smarty->fetch(get_template_path('remove_branch.tpl',TRUE)));
366       } else {
367         print_red (_("You are not allowed to delete this user!"));
368       }
369     }
371     /* Delete this entry */
372     if(isset($_POST['delete_branch_confirm'])){
373       $bb =  $faifilter['branch'];
374       if(!isset($ldap)){
375         $ldap = $this->config->get_ldap_link();
376       }
378       $br = $this->getBranches();
380       if(isset($br[$bb])){
381         $ldap->cd($bb);
382         $ldap->recursive_remove();
383         $faifilter['branch'] = "main";
384       }
385     }
388     if((isset($_POST['UseBranchName']))&&($this->dispNewFreeze)){
389       /* Check branch name */
390       $name = $_POST['BranchName'];
391       $is_ok = true;
393       $smarty->assign("BranchName",$name);
395                   $base= "ou=fai,ou=configs,ou=systems,".$faifilter['base'];
396       
397       /* Check used characters */
398       if(preg_match("/[^0-9a-z \ö\ä\ü\.-_:,]/i",$name)){
399         print_red(_("Specified branch name is invalid."));
400         $is_ok = false;
401       }
402    
403       /* Check if this name is already in use */
404       if(!$this->CheckNewBranchName($_POST['BranchName'],$faifilter['branch'])){
405         print_red(_("This name is already in use."));
406         $is_ok = false;
407       }
408      
409       if($is_ok){
410         /* Create it know */
411         $ldap = $this->config->get_ldap_link();
413         $baseToUse = $base;
414         if($_SESSION['faifilter']['branch']!="main"){
415           $baseToUse = $_SESSION['faifilter']['branch'];
416         }
417         
418         $ldap->cd ("ou=".$name.",".$baseToUse);
419         $ldap->recursive_remove();
420         
421         $ldap->cd ($this->config->current['BASE']);
422         $ldap->copy_FAI_resource_recursive($baseToUse,"ou=".$name.",".$baseToUse,"freeze",true);
423         
424         $this->dispNewFreeze = false; 
425       }
426     }
427     
428     if(($s_action == "freeze_branch")||($this->dispNewFreeze)){
429       $this->dispNewFreeze = true;
430                   $display      .= $smarty->fetch(get_template_path('faiNewBranch.tpl', TRUE, dirname(__FILE__)));
431       return($display);
432     }
434     /* ENDE Branch handling 
435      */
437     /* Dialog handling */
438                 if($s_action == "new_partition"){
439                         $this->dialog = new askClassName($this->config,$this->dn,$this->ui,"FAIpartitionTable");
440                 }
442                 /* Dialog handling */
443                 if($s_action == "new_script"){
444                         $this->dialog = new askClassName($this->config,$this->dn,$this->ui,"FAIscript");
445                 }
447                 /* Dialog handling */
448                 if($s_action == "new_hook"){
449                         $this->dialog = new askClassName($this->config,$this->dn,$this->ui,"FAIhook");
450                 }
452                 /* Dialog handling */
453                 if($s_action == "new_variable"){
454                         $this->dialog = new askClassName($this->config,$this->dn,$this->ui,"FAIvariable");
455                 }
457                 /* Dialog handling */
458                 if($s_action == "new_template"){
459                         $this->dialog = new askClassName($this->config,$this->dn,$this->ui,"FAItemplate");
460                 }
462                 /* Dialog handling */
463                 if($s_action == "new_package"){
464                         $this->dialog = new askClassName($this->config,$this->dn,$this->ui,"FAIpackageList");
465                 }
467                 /* New Profile */
468                 if($s_action == "new_profile"){
469                         $this->dn = "new" ;
470                         $a_setup= $this->get_type(array("objectClass"=>array("FAIprofile")));
472                         $this->dialog = new $a_setup[0]($this->config,
473                                         $this->config->data['TABS'][$a_setup[2]],$this->dn);
474                         $this->is_dialog = true;
476                 }
478                 if($s_action == "select_class_name_finished"){
479                         $this->dialog->save_object();
480                         if(count($this->dialog->check())!=0){
481                                 foreach($this->dialog->check() as $msg){
482                                         print_red($msg);
483                                 }               
484                         }else{
485                                 $this->dn = "new" ;
486                                 $a_setup= $this->get_type(array("objectClass"=>array($this->dialog->objectClass)));
487                                 $name = $this->dialog->save();
489                                 $this->dialog = new $a_setup[0]($this->config,
490                                                 $this->config->data['TABS'][$a_setup[2]],$this->dn,$name);
491                                 $this->dialog->by_object[$a_setup[1]]->cn = $name;
492                                 $this->is_dialog = true;
493                         }               
494                 }       
496                 /* Search is set */
497                 if(isset($_GET['search'])){
498                         $faifilter['regex']=$_GET['search']."*";
499                 }
501                 /* Department select */
502                 if((isset($_POST['base']))&&($s_action=="")){
503                         $faifilter['base']=$_POST['base'];
504                 }
505   
507     $br = $this->getBranches();
508     if(!isset($br[$faifilter['branch']])){
509       $faifilter['branch'] = "main";
510     }
511    
512     $smarty->assign("select_branch",$faifilter['branch']);
514                 /* remove double asterisks and save new filter */
515                 $faifilter['regex'] = preg_replace("/\*\*/","*",$faifilter['regex']);
516                 $_SESSION['faifilter']= $faifilter;
518                 /* Edit dialog was canceled 
519                  * Remove dialog an show management dialog
520                  */
521                 if(isset($_POST['edit_cancel'])){
522                         unset($this->dialog);
523                         $this->dialog=NULL;
524                         $this->is_dialog = false;
525                         unset($_SESSION['objectinfo']);
526                         del_lock ($this->dn);
527                 }
529                 /* This check if the given tab could be saved 
530                  * If it was possible to save it, remove dialog object. 
531                  * If it wasn't possible, show errors and keep dialog.
532                  */
533                 if(isset($_POST['edit_finish'])){
534                         $this->dialog->save_object();
535                         if(count($this->dialog->check())!=0){
536                                 foreach($this->dialog->check() as $msg){
537                                         print_red($msg);
538                                 }
539                         }else{
540                                 del_lock ($this->dn);
541                                 $this->dialog->save();
542                                 unset($this->dialog);
543                                 $this->dialog=NULL;
544                                 $this->is_dialog=false;
545                                 unset($_SESSION['objectinfo']);
546                         }
547                 }
549                 /* If dialog is set, but $this->is_dialog==false, then 
550                  *  only the "abort" button is shown, this are dialogs that must not be saved.  
551                  * If is_dialog == true, we are currently editing tab objects.
552                  *  Here we need both, save and cancel
553                  */ 
555                 if($this->dialog != NULL){
556                         $display .= $this->dialog->execute();
557                         /* Don't show buttons if tab dialog requests this */
558                         if (((isset($this->dialog->current))&&($this->dialog->by_object[$this->dialog->current]->is_dialog))){
559                                 
560                         }elseif(((isset($this->dialog->current))&&(!$this->dialog->by_object[$this->dialog->current]->is_dialog))){
561                                 $display.= "<p style=\"text-align:right\">\n";
562                                 $display.= "<input type=\"submit\" name=\"edit_finish\" value=\""._("Finish")."\">\n";
563                                 $display.= "&nbsp;\n";
564                                 $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
565                                 $display.= "</p>";
566                         }elseif(!isset($this->dialog->current)){
567                                 $display.= "<p style=\"text-align:right\">\n";
568                                 $display.= "<input type=\"submit\" name=\"edit_continue\" value=\""._("Continue")."\">&nbsp;";
569                                 $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
570                                 $display.= "</p>";
571                         }
572                         return($display);
573                 }
575                 /* Show Management template
576                  * The following code will only be reached if no dialog (tabs or dialogs)
577                  *  are currently opened.
578                  * Assign all reguired vars to template engine
579                  */
581                 /* Prepare departments */
582                 $options= "";
583                 foreach ($this->config->idepartments as $key => $value){
584                         if ($faifilter['base'] == $key){
585                                 $options.= "<option selected='selected' value='$key'>$value</option>";
586                         } else {
587                                 $options.= "<option value='$key'>$value</option>";
588                         }
589                 }
591                 /* Create listhead, it will be shown on top of the divlist. 
592                  * It provides general navigation and object creation
593                  */
594                 $faihead = 
595                         "<div style='background:#F0F0F9;padding:5px;'>&nbsp;".
597                         "<input class='center' type='image' src='images/list_up.png' align='middle' 
598                         title='"._("Go up one department")."' name='dep_back' alt='"._("Up"). "'>&nbsp;".
600                         "<input class='center' type='image' src='images/list_root.png' align='middle' 
601                         title='"._("Go to root department")."' name='dep_root' alt='".      _("Root")."'>&nbsp;".
603                         "<input class='center' type='image' src='images/list_home.png' align='middle' 
604                         title='"._("Go to users home department")."' name='dep_home' alt='"._("Home")."'>&nbsp;".
606                         "<img class='center' src=\"images/list_seperator.png\" alt=\"\" align=\"middle\" height=\"16\" width=\"1\">&nbsp;".
607                         
608                         " <input class='center' type='image' src='images/fai_new_profile.png' align='middle' 
609                         title='"._("New profile")."' name='Create_profile' alt='"._("P")."'>&nbsp;".
610                         
611                         "<img class='center' src=\"images/list_seperator.png\" alt=\"\" align=\"middle\" height=\"16\" width=\"1\">&nbsp;".
612                                 
613                         " <input class='center' type='image' src='images/fai_new_partitionTable.png' align='middle' 
614                         title='"._("New partition table")."' name='Create_partition' alt='"._("PT")."'>&nbsp;".
616                         " <input class='center' type='image' src='images/fai_new_script.png' align='middle' 
617                         title='"._("New scripts")."' name='Create_script' alt='"._("S")."'>&nbsp;".
619                         " <input class='center' type='image' src='images/fai_new_hook.png' align='middle' 
620                         title='"._("New hooks")."' name='Create_hook' alt='"._("H")."'>&nbsp;".
622                         " <input class='center' type='image' src='images/fai_new_variable.png' align='middle' 
623                         title='"._("New variables")."' name='Create_variable' alt='"._("V")."'>&nbsp;".
624                         
625                         " <input class='center' type='image' src='images/fai_new_template.png' align='middle' 
626                         title='"._("New templates")."' name='Create_template' alt='"._("T")."'>&nbsp;".
628                         " <input class='center' type='image' src='images/fai_new_packages.png' align='middle' 
629                         title='"._("New package list")."' name='Create_package' alt='"._("PK")."'>&nbsp;".
631                         " <img class='center' src='images/list_seperator.png' align='middle' alt='' height='16' width='1'>&nbsp;".
633                         _("Current base")."&nbsp;<select name='base' onChange='mainform.submit()' class='center'>$options</select>".
634                         " <input class='center' type='image' src='images/list_submit.png' align='middle' title='"._("Submit department")."' name='submit_department' alt='"._("Submit")."'>&nbsp;".
635                         
636                         "</div>";
638                 $this->reload();
640                 /* Create list with objects */
641                 $divlist = new divlist("faiManagement"); 
642                 $divlist->SetEntriesPerPage(0);
643                 $divlist->SetSummary(_("This table displays all systems, in the selected tree."));
645                 $divlist->SetHeader(array(
646                                         array("string" => "&nbsp;", "attach" => "style='text-align:center;width:20px;'"),
647                                         array("string" => _("Name of FAI class"), "attach" => "style=''"),
648                                         array("string" => _("Class type"), "attach" => "style='width:200px;'"),
649                                         array("string" => _("Actions"), "attach" => "style='width:60px;border-right:0px;text-align:right;'")));
652                 $action  = "<input class='center' type='image' src='images/edit.png'    alt='"._("edit")."'   name='entry_edit_%KEY%' title='"._("Edit class")."'>";
653                 $action .= "<input class='center' type='image' src='images/edittrash.png' alt='"._("delete")."' name='entry_delete_%KEY%' title='"._("Delete class")."'>";
655                 $editlink ="<a href='?plug=".$_GET['plug']."&amp;edit_entry=%KEY%'>%NAME%</a>";                 
656                 $linkopen = "<a href='?plug=".$_GET['plug']."&amp;act=dep_open&amp;dep_id=%s'>%s</a>";
658                 foreach($this->departments as $key => $val) {
659                         if(!isset($this->config->departments[trim($key)])){
660                                 $this->config->departments[trim($key)]="";
661                         }
663                         $non_empty="";
664                         $keys= str_replace("/","\/",$key);
665                         foreach($this->config->departments as $keyd=>$vald ){
666                                 if(preg_match("/".$keys."\/.*/",$keyd)){
667                                         $non_empty="full";
668                                 }
669                         }
672                         $title = $this->config->departments[$key];
673                         $field0 = array("string" => "<img src='images/".$non_empty."folder.png' title='"._("department")."' alt='department'>", "attach" => "style='text-align:center;width:20px;'");
674                         $field1 = array("string" => sprintf($linkopen,base64_encode($key),$val), "attach" => "style='' title='".$title."'");
675                         $field2 = array("string" => "&nbsp;", "attach" => "style='width:200px;'");
676                         $field3 = array("string" => "&nbsp;", "attach" => "style='width:60px;border-right:0px;text-align:right;'");
678                         $divlist->AddEntry( array($field0,$field1,$field2,$field3));
680                 }
681     
682                 /* Attach objects */
683                 foreach($this->objects as $key => $value){
684                                 $info= "";
685                                 $img = "";
686                                 $type = $value['type'];
687                                 $abort=false;
689                                 switch($type) {
690                                         case "FAIpartitionTable"        : 
691                                                 if(!$faifilter['ShowPartitions']){ 
692                                                         $abort = true;
693                                                 }
694                                         $img="<img class='center' src='images/fai_partitionTable.png' title='"._("Partition table")."' alt='PT'>";
695                                         $info = _("Partition table");
696                                         break;
697                                         case "FAIpackageList"           : 
698                                                 if(!$faifilter['ShowPackages']){ 
699                                                         $abort = true;
700                                                 }
701                                         $img="<img class='center' src='images/fai_packages.png' title='"._("Package list")."' alt='PL'>";
702                                         $info = _("Package list");
703                                         break;
704                                         case "FAIscript"                        : 
705                                                 if(!$faifilter['ShowScripts']){ 
706                                                         $abort = true;
707                                                 }
708                                         $img="<img class='center' src='images/fai_script.png' title='"._("Scripts")."' alt='S'>";
709                                         $info = _("Scripts");
710                                         break;
711                                         case "FAIvariable"                      : 
712                                                 if(!$faifilter['ShowVariables']){ 
713                                                         $abort = true;
714                                                 }
715                                         $img="<img class='center' src='images/fai_variable.png' title='"._("Variables")."' alt='V'>";
716                                         $info = _("Variables");
717                                         break;
718                                         case "FAIhook"                          :
719                                                 if(!$faifilter['ShowHooks']){ 
720                                                         $abort = true;
721                                                 }
722                                         $img="<img class='center' src='images/fai_hook.png' title='"._("Hooks")."' alt='H'>";
723                                         $info = _("Hooks");
724                                         break;
725                                         case "FAIprofile"                       : 
726                                                 if(!$faifilter['ShowProfiles']){ 
727                                                         $abort = true;
728                                                 }
729                                         $img="<img class='center' src='images/fai_profile.png' title='"._("Profile")."' alt='P'>";
730                                         $info = _("Profile");
731                                         break;
732                                         case "FAItemplate"                      : 
733                                                 if(!$faifilter['ShowTemplates']){ 
734                                                         $abort = true;
735                                                 }
736                                         $img="<img class='center' src='images/fai_template.png' title='"._("Templates")."' alt='T'>";
737                                         $info = _("Templates");
738                                         break;
739                                         default                                         : 
740                                         $img="<img class='center' src='images/empty.png' alt=''>";$info = "";break;
742                                 }
743                                 
744                                 if(!$abort)     {
745                                         if((isset($value['description']))&&(!empty($value['description']))){
746                                                 $desc= " [".$value['description']."]";
747                                         }else{
748                                                 $desc= "";
749                                         }
751           if($value['FAIstate'] == "freeze"){
752             $acti = "";
753             $edi  = "%NAME%";
754           }else{
755             $acti = $action;
756             $edi = $editlink;
757           }
759                                         $field1 = array("string" => $img , "attach" => "style='text-align:center;width:20px;'");
760                                         $field2 = array("string" => preg_replace(array("/%KEY%/","/%NAME%/"),array($key,$value['cn'].$desc),$edi) , "attach" => "style=''");
761                                         $field3 = array("string" => $info, "attach" => "style='width:200px;'");
762                                         $field4 = array("string" => preg_replace("/%KEY%/",$key,$acti) , "attach" => "style='width:60px;border-right:0px;text-align:right;'");
763                                         $divlist->AddEntry(array($field1,$field2,$field3,$field4));
765                         }
766                 }
768                 foreach($faifilter as $attrs => $value){
769                         if($value){
770                                 $smarty->assign($attrs."CHK", " checked ");
771                         }else{
772                                 $smarty->assign($attrs."CHK", " ");
773                         }
774                 }
776                 /* Assign all reguired vars to template engine */
778     $branches = $this->getBranches();
779     asort($branches);
780     $smarty->assign("branchKeys",array_flip($branches));
781     $smarty->assign("branches",$branches);
782     
783                 $smarty->assign("faihead"               , $faihead);    
784                 $smarty->assign("failist"               , $divlist->DrawList());
785                 $smarty->assign("regex"                 , $faifilter['regex']); 
786                 $smarty->assign("infoimage"             , get_template_path('images/info.png'));
787                 $smarty->assign("branchimage"           , get_template_path('images/action.png'));
788                 $smarty->assign("launchimage"   , get_template_path('images/launch.png'));
789                 $smarty->assign("alphabet"              , generate_alphabet());
790                 $smarty->assign("apply"                 , apply_filter());
791                 $smarty->assign("search_image"  , get_template_path('images/search.png'));
792                 $smarty->assign("hint", print_sizelimit_warning());
794                 $display        = $smarty->fetch(get_template_path('headpage.tpl', TRUE, dirname(__FILE__)));
795                 return ($display);
796         }
798   function getBranches($base = false,$prefix = "")
799   {
800     $ret = array("main"=>_("main"));
801     $ldap = $this->config->get_ldap_link();
802   
803     $ldap->cd($this->config->current['BASE']);
805     $faifilter = $_SESSION['faifilter'];
808     if(!$base){
809                 $base= "ou=fai,ou=configs,ou=systems,".$faifilter['base'];
810     }
811     $ldap->cd($base);
812     $ldap->ls("(objectClass=FAIbranch)",$base);
814     while($attrs = $ldap->fetch()){
815       
816       if((isset($attrs['ou']))&&($attrs['dn']!=$base)){
817         $ret[$attrs['dn']]= $prefix.$attrs['ou'][0];
818         $ret = array_merge($ret,$this->getBranches($attrs['dn'],$prefix.$attrs['ou'][0]."/"));
819       }
820     }
821     return($ret);
822   }
824         function reload()
825         {
826                 /* Create a new list of FAI object 
827                  * Object list depends on faifilter['regex']
828                  * Generate List of Partitions,Hooks,Scripts,Templates,Profiles ... 
829                  */
830                 $faifilter= get_global('faifilter');
831                 // Added for dirlist function...
833                 /* Set base for all searches */
834                 $base= "ou=fai,ou=configs,ou=systems,".$faifilter['base'];
836     if($faifilter['branch'] !="main"){
837       $base = $faifilter['branch'];
838     }
839    
840                 $regex = $faifilter['regex'];   
842                 /* Array to save objects */
843                 $objects = array();
844         
845                 $this->objects=array();
847                 /* NEW LIST MANAGMENT
848                  * We also need to search for the departments
849                  * So we are able to navigate like in konquerer
850                  */
851                 $base2 = $faifilter['base'];
853                 $res3 =  get_list2($this->ui->subtreeACL, "(&(|(ou=$regex)(description=$regex))(objectClass=gosaDepartment))",
854                                 TRUE, $base2, array("ou", "description"), TRUE);
856                 $this->departments= array();
857                 $tmp = array();
858                 foreach ($res3 as $value){
859                         $tmp[strtolower($value['dn']).$value['dn']]=$value;
860                 }
861                 ksort($tmp);
862                 foreach($tmp as $value){
863                         if(isset($value["description"][0])){
864                                 $this->departments[$value['dn']]=convert_department_dn2($value['dn'])." - [".$value["description"][0]."]";
865                         }else{
866                                 $this->departments[$value['dn']]=convert_department_dn2($value['dn']);//$value["description"][0];
867                         }
868                 }
870                 /* END NEW LIST MANAGMENT
871                  */
873         
874                 $res= get_list($this->ui->subtreeACL, "(objectClass=organizationalUnit)", 
875                                 FALSE, $base, array("cn","description","objectClass"),TRUE);
877                 foreach($res as $objecttypes){
878                         $res2 = get_list($this->ui->subtreeACL, "(&(objectClass=*)(cn=".$regex."))",
879                                         FALSE, $objecttypes['dn'], array("cn","description","objectClass","FAIclass","FAIstate"),TRUE);
880                         foreach($res2 as $object){
881                                 $type= "";      
882                                 unset($object['objectClass']['count']);
883                                 if(!isset($object['description'][0])){
884                                         $object['description'][0]="";
885                                 }
886                                 
887                                 /* Clean up object informations */
888                                 $obj['cn']                      = $object['cn'][0];
889                                 $obj['dn']                      = $object['dn'];
890                                 $obj['description'] = $object['description'][0];
891                                 $obj['objectClass'] = $object['objectClass'];
893         if(isset($object['FAIstate'])){
894           $obj['FAIstate'] = $object['FAIstate'][0];
895         }else{
896           $obj['FAIstate'] ="";
897         }
899                                 if(in_array("FAIpartitionTable",$obj['objectClass'])){
900                                         $type = "FAIpartitionTable";
901                                 }elseif(in_array("FAIpackageList",$obj['objectClass'])){
902                                         $type = "FAIpackageList";
903                                 }elseif(in_array("FAIscript",$obj['objectClass'])){
904                                         $type = "FAIscript";
905                                 }elseif(in_array("FAIvariable",$obj['objectClass'])){
906                                         $type = "FAIvariable";
907                                 }elseif(in_array("FAIhook",$obj['objectClass'])){
908                                         $type = "FAIhook";
909                                 }elseif(in_array("FAIprofile",$obj['objectClass'])){
910                                         $obj['FAIclass']        = $object['FAIclass'][0];
911                                         $type = "FAIprofile";
912                                 }elseif(in_array("FAItemplate",$obj['objectClass'])){
913                                         $type = "FAItemplate";
914                                 }
915                                 $this->objects[strtolower($obj['cn']).$obj['cn'].$type] = $obj;
916                                 $this->objects[strtolower($obj['cn']).$obj['cn'].$type]['type']=$type;
917  
918                         }
919                 }
920                 ksort($this->objects);
921                 reset ($this->objects);
922         
923                 /* use numeric index, thats a bit more secure */        
924                 $tmp0 = array();
925                 foreach($this->objects as $obj){
926                         $tmp0[]= $obj;
927                 }
928                 $this->objects = array();
929                 $this->objects = $tmp0;
931         }
933         function remove_lock()
934         {
935                 if (isset($this->dn)){
936                         del_lock ($this->dn);
937                 }
938         }
940         function get_type($array){
941                 if(in_array("FAIpartitionTable",$array['objectClass'])){
942                         return(array("tabsPartition","faiPartitionTable","FAIPARTITIONTABS"));
943                 }
944                 if(in_array("FAIscript",$array['objectClass'])){
945                         return(array("tabsScript","faiScript","FAISCRIPTTABS"));
946                 }
947                 if(in_array("FAItemplate",$array['objectClass'])){
948                         return(array("tabsTemplate","faiTemplate","FAITEMPLATETABS"));
949                 }
950                 if(in_array("FAIhook",$array['objectClass'])){
951                         return(array("tabsHook","faiHook","FAIHOOKTABS"));
952                 }
953                 if(in_array("FAIvariable",$array['objectClass'])){
954                         return(array("tabsVariable","faiVariable","FAIVARIABLETABS"));
955                 }
956                 if(in_array("FAIprofile",$array['objectClass'])){
957                         return(array("tabsProfile","faiProfile","FAIPROFILETABS"));
958                 }
959                 
960                 if(in_array("FAIpackageList",$array['objectClass'])){
961                         return(array("tabsPackage","faiPackage","FAIPACKAGETABS"));
962                 }
963         }
965   function CheckNewBranchName($name,$base){
966     $f = $_SESSION['faifilter']['branch'];
968     if($f == "main"){
969       $f = $_SESSION['faifilter']['base'];
970     } 
971     
972     if(in_array($name,$this->getBranches($f))) {
973       return(false);
974     }
976     if(empty($name)){
977       return(false);
978     }
979     return(true);
980   }
983 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
984 ?>