Code

FAI release management reworked, only touched faiscript.
[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";
30 class faiManagement extends plugin
31 {
32         /* Definitions */
33         var $plHeadline                 = "FAI";
34         var $plDescription              = "Fully Automatic Installation - management";
36         /* CLI vars */
37         var $cli_summary                  = "Handling of FAI entries";
38         var $cli_description    = "This plugin represents a management tool\n
39                 which allows us to manage all needed attributes for fully automatic installations (FAI)";
40         var $cli_parameters             = array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
42         /* Headpage attributes */
43   var $lock_type    = "";    // should be branch/freeze
44   var $lock_name    = "";
45   var $lock_dn      = "";  
47         /* attribute list for save action */
48         var $attributes         = array("lock_type","lock_name","lock_dn");     //      Attributes Managed by this plugin 
49         var $objectclasses= array();    //      ObjectClasses which the attributes are related to
50         var $dialog                             = array();      //      This object contains every dialog we have currently opened
52         var $objects                    = array();      //      This array contains all available objects shown in divlist
53         var $is_dialog          = false;
55   var $dispNewBranch= false;
56   var $dispNewFreeze= false;
58   var $DivListFai;
60         /* construction/reconstruction 
61          */
62         function faiManagement ($config, $ui)
63         {
64                 /* Set defaults */
65                 $this->dn                       = "";
66                 $this->config   = $config;
67                 $this->ui                       = $ui;  
68     
69     /* Creat dialog object */
70     $this->DivListFai = new divListFai($this->config,$this);
71         }
73         function execute()
74         {
75     /* Call parent execute */
76     plugin::execute();
78     /* Initialise vars and smarty */
79                 $smarty         = get_smarty();
80                 $smarty->assign("BranchName","");
81     
82                 $display        = "";
83     $s_action   = "";
84                 $s_entry        = "";
85     
86     /* If an entry was locked, these vars will be stored in a session to allow direct edit */
87     $_SESSION['LOCK_VARS_TO_USE'] = array("/^edit_entry$/","/^id$/","/^entry_edit_/","/^entry_delete_/");
90     /****************
91       Handle posts 
92      ****************/
94                 /* Check ImageButton posts
95                  * Create new tab ich new_xx is posted
96                  */
97     $posts = array( "/remove_branch/"=>"remove_branch",    "/branch_branch/"=>"branch_branch",
98                     "/freeze_branch/"=>"freeze_branch",    "/create_partition/i"=>"new_partition",
99                     "/create_script/i"=>"new_script",      "/create_hook/i"=>"new_hook",
100                     "/create_variable/i"=>"new_variable",  "/create_template/i"=>"new_template",
101                     "/create_package/i"=>"new_package",    "/create_profile/i"=>"new_profile",
102                     "/edit_continue/"=>"select_class_name_finished");
104                 foreach($_POST as $name => $value){
105       foreach($posts as $reg => $act ){
106         if(preg_match($reg,$name)){
107           $s_action = $act;
108         }
109       }
110                         if(preg_match("/^entry_edit_.*/",$name)){
111                                 $s_entry = preg_replace("/^entry_edit_/","",$name);
112                                 $s_entry = preg_replace("/_.*$/","",$s_entry);
113                                 $s_action = "edit";
114                         }elseif(preg_match("/^entry_delete_.*/",$name)){
115                                 $s_entry = preg_replace("/^entry_delete_/","",$name);
116                                 $s_entry = preg_replace("/_.*$/","",$s_entry);
117         $s_action = "delete";
118       }
119     }
121                 if(isset($_GET['edit_entry'])){
122                         $s_entry = $_GET['edit_entry'];
123                         $s_action = "edit";
124                 }
125     
126     if((isset($_POST['CancelBranchName'])) || (isset($_POST['CloseIFrame']))){
127       $this->dispNewBranch = false;
128       $this->dispNewFreeze = false;
129     }
132     /****************
133       Delete confirme dialog 
134      ****************/
136                 if ($s_action=="delete"){
138                         /* Get 'dn' from posted termlinst */
139                         $this->dn= $this->objects[$s_entry]['dn'];
141                         /* Load permissions for selected 'dn' and check if
142                            we're allowed to remove this 'dn' */
143                         $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
144                         $this->acl= get_module_permission($acl, "FAIclass", $this->dn);
145                         if (chkacl($this->acl, "delete") == ""){
147                                 /* Check locking, save current plugin in 'back_plugin', so the dialog knows where to return. */
148                                 if (($user= get_lock($this->dn)) != ""){
149                                         return(gen_locked_message ($user, $this->dn));
150                                 }
152                                 /* Lock the current entry, so nobody will edit it during deletion */
153                                 add_lock ($this->dn, $this->ui->dn);
154                                 $smarty->assign("warning", sprintf(_("You're about to delete all information about the FAI class at '%s'."), @LDAP::fix($this->dn)));
155                                 return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
156                         } else {
158                                 /* Obviously the user isn't allowed to delete. Show message and
159                                    clean session. */
160                                 print_red (_("You are not allowed to delete this component!"));
161                         }
162                 }
165     /****************
166       Delete aborted  
167      ****************/
169                 /* Delete canceled? */
170                 if (isset($_POST['delete_cancel'])){
171                         del_lock ($this->dn);
172                 }
175     /****************
176       Delete confirmed 
177      ****************/
179                 /* Deltetion was confirmed, so delete this entry
180                  */
181                 if (isset($_POST['delete_terminal_confirm'])){
183                         /* Some nice guy may send this as POST, so we've to check
184                            for the permissions again. */
185                         if (chkacl($this->acl, "delete") == ""){
187                                 /* Find out more about the object type */
188                                 $ldap     = $this->config->get_ldap_link();
189                                 $ldap->cat($this->dn, array('objectClass'));
190                                 $attrs  = $ldap->fetch();
191                                 $type     = $this->get_type($attrs);                    
192                                 $this->dialog = new $type[0]($this->config,     $this->config->data['TABS'][$type[2]], $this->dn);
193                                 $this->dialog->set_acl(array($this->acl));
195                                 $this->dialog->by_object[$type[1]]->remove_from_parent ();
196                                 unset ($this->dialog);
197                                 gosa_log ("FAI class '".$this->dn."' has been removed");
198                                 $this->dialog= NULL;
199                         } else {
201                                 /* Normally this shouldn't be reached, send some extra
202                                    logs to notify the administrator */
203                                 print_red (_("You are not allowed to delete this component!"));
204                                 gosa_log ("Warning: '".$this->ui->uid."' tried to trick system ".
205                                                 "deletion.");
206                         }
208                         /* Remove lock file after successfull deletion */
209                         del_lock ($this->dn);
210                 }
213     /****************
214       Edit entry 
215      ****************/
217                 if(($s_action == "edit") && (!isset($this->dialog->config))){
218                         $entry    = $this->objects[$s_entry];
219                         $a_setup  = $this->get_type($entry);
220                         $this->dn = $entry['dn'];
222                         /* Check locking, save current plugin in 'back_plugin', so the dialog knows where to return. */
223                         if (($user= get_lock($this->dn)) != ""){
224                                 return(gen_locked_message ($user, $this->dn));
225                         }
226                         add_lock ($this->dn, $this->ui->dn);
228                         $this->dialog     = new $a_setup[0]($this->config,$this->config->data['TABS'][$a_setup[2]],$this->dn);
229                         $this->is_dialog  = true;
231       if($entry['FAIstate'] == "freeze"){
232         $this->dialog->set_acl(array("*none*"))  ;
233       }
234                         $_SESSION['objectinfo'] = $this->dn;
235                 }
238     /*  Branch handling 
239         09.01.2006
240     */
242     /****************
243       Remove branch
244      ****************/
246     /* Remove branch 
247      */
248     if($s_action == "remove_branch"){
249       $base= $this->DivListFai->selectedBranch;
251       /* Load permissions for selected 'dn' and check if
252          we're allowed to remove this 'dn' */
253       $acl= get_permissions ($this->DivListFai->selectedBase, $this->ui->subtreeACL);
254       $this->acl= get_module_permission($acl, "FAIclass", $base);
255       if (chkacl($this->acl, "delete") == ""){
256         $smarty->assign("info", sprintf(_("You're about to delete a fai branch / freeze  '%s'."), $this->DivListFai->selectedBranch));
257         return($smarty->fetch(get_template_path('remove_branch.tpl',TRUE)));
258       } else {
259         print_red (_("You are not allowed to delete this release!"));
260       }
261     }
263     
264     /****************
265       Remove branch confirmed
266      ****************/
268     if(isset($_POST['delete_branch_confirm'])){
269       $bb =  $this->DivListFai->selectedBranch;
270       if(!isset($ldap)){
271         $ldap = $this->config->get_ldap_link();
272       }
274       $br = $this->getBranches();
276       if(isset($br[$bb])){
277         $name = $br[$bb];
278         $ldap->cd($bb);
279         $ldap->recursive_remove();
280         $ldap->cd(preg_replace('/,ou=fai,ou=configs,ou=systems,/', ',ou=apps,', $bb));
281         $ldap->recursive_remove();
282         $this->DivListFai->selectedBranch = "main";
284         /* Post remove */
285         $this->lock_name   = $name;
286         $this->lock_dn     = $bb;
287         $this->postremove();
288       }
289     }
292     /****************
293       Create a new branch "insert Name"
294      ****************/
296     if((isset($_POST['UseBranchName']))&&(($this->dispNewBranch)||($this->dispNewFreeze))){
297       $_SESSION['LASTPOST'] = $_POST;
299       if($this->dispNewBranch){
300         $type = "branch";
301       }else{
302         $type = "freeze";
303       }
305       /* Check branch name */
306       $name = $_POST['BranchName'];
307       $is_ok = true;
308       $smarty->assign("BranchName",$name);
309       $base= "ou=fai,ou=configs,ou=systems,".$this->DivListFai->selectedBase;
311       /* Check used characters */
312       if(preg_match("/[^0-9a-z \ö\ä\ü\.-_:,]/i",$name)){
313         if($type == "branch"){
314           print_red(_("Specified branch name is invalid."));
315         }else{
316           print_red(_("Specified freeze name is invalid."));
317         }
318         $is_ok = false;
319       }
321       /* Check if this name is already in use */
322       if(!$this->CheckNewBranchName($_POST['BranchName'],$this->DivListFai->selectedBranch)){
323         print_red(_("This name is already in use."));
324         $is_ok = false;
325       }
327       if($is_ok){
328         $_SESSION['LASTPOST']['base'] = $base;
329         $_SESSION['LASTPOST']['type'] = $type;
330         $smarty->assign("iframe", true);
331         $smarty->assign("plugID", $_GET['plug']);
332         $display        = $smarty->fetch(get_template_path('faiNewBranch.tpl', TRUE, dirname(__FILE__)));
333         return($display);
334       }
335     }
338     /****************
339       Create a new branch 
340      ****************/
342     if(isset($_GET['PerformBranch'])){
343       /* Create it know */
344       $this->dispNewBranch = false;
345       $this->dispNewFreeze = false;
346       $base = $_SESSION['LASTPOST']['base'];
347       $_POST = $_SESSION['LASTPOST'];      
348       $name = $_POST['BranchName'];
350       $type = $_SESSION['LASTPOST']['type'];
351       $ldap = $this->config->get_ldap_link();
353       $baseToUse = $base;
354       if($this->DivListFai->selectedBranch != "main" ){
355         $baseToUse = $this->DivListFai->selectedBranch;
356       }
357   
358       /* Create new Release name to be able to set faidebianRelease for FAIpackageList */
359       
360       $CurrentReleases  = $this->getBranches();
361       $NewReleaseName   = $name;
362       if(isset($CurrentReleases[$this->DivListFai->selectedBranch])) {
363         if($this->DivListFai->selectedBranch != "main"){
364           $NewReleaseName = $CurrentReleases[$this->DivListFai->selectedBranch]."/".$name;
365           $NewReleaseName = preg_replace("#\/#","/",$NewReleaseName); 
366         }else{
367           $NewReleaseName   = $name;
368         }
369       }
371       $appsrc = preg_replace("/ou=fai,ou=configs,ou=systems,/","ou=apps,",$baseToUse); 
372       $appdst = preg_replace("/ou=fai,ou=configs,ou=systems,/","ou=apps,","ou=".$name.",".$baseToUse) ; 
374       $mimesrc = preg_replace("/ou=fai,ou=configs,ou=systems,/","ou=mime,",$baseToUse); 
375       $mimedst = preg_replace("/ou=fai,ou=configs,ou=systems,/","ou=mime,","ou=".$name.",".$baseToUse) ; 
377       /* Print header to have styles included */
378       echo "<!-- headers.tpl-->".$smarty->fetch(get_template_path('headers.tpl'));
379       echo "<body style='background-image:none;margin:3px;color:black'>";
381       /* Duplicate applications 
382        */
383       $ldap->cd ($appdst);
384       $ldap->recursive_remove();
385       $ldap->cd ($this->config->current['BASE']);
386       $ldap->copy_FAI_resource_recursive($appsrc,$appdst,$NewReleaseName,$type,true);
388       /* Duplicate mime types 
389        */
390       $ldap->cd ($appdst);
391       $ldap->recursive_remove();
392       $ldap->cd ($this->config->current['BASE']);
393       $ldap->copy_FAI_resource_recursive($mimesrc,$mimedst,$NewReleaseName,$type,true);
395       /* Duplicate fai objects 
396        */
397       $ldap->cd ("ou=".$name.",".$baseToUse);
398       $ldap->recursive_remove();
399       $ldap->cd ($this->config->current['BASE']);
400       $ldap->copy_FAI_resource_recursive($baseToUse,"ou=".$name.",".$baseToUse,$NewReleaseName,$type,true);
402       echo "<div style='width:100%;text-align:right;'><form name='form' method='post' action='?plug=".$_GET['plug']."' target='_parent'>
403               <br><input type='submit' name='CloseIFrame' value='"._("Continue")."'>
404             </form></div>";
406       /* Print footer to have valid html */
407       echo "</body></html>";
409       $this->dispNewFreeze = false; 
411       /* Postcreate */ 
413       /* Assign possible attributes */
414       $this->lock_type  = $type; 
415       $this->lock_name  = $name; 
416       $this->lock_dn    = $baseToUse;
417       $this->postcreate();
418       exit();
419     }
422     /****************
423       Display dialog to enter new Branch name
424      ****************/
426     if(($s_action == "branch_branch")||($this->dispNewBranch)){
427       $this->dispNewBranch=true;
428       $smarty->assign("iframe",false);
429                   $display      .= $smarty->fetch(get_template_path('faiNewBranch.tpl', TRUE, dirname(__FILE__)));
430       return($display);
431     }
432    
433  
434     /****************
435       Display dialog to enter new Freeze name
436      ****************/
438     if(($s_action == "freeze_branch")||($this->dispNewFreeze)){
439       $this->dispNewFreeze = true;
440       $smarty->assign("iframe",false);
441                   $display      .= $smarty->fetch(get_template_path('faiNewBranch.tpl', TRUE, dirname(__FILE__)));
442       return($display);
443     }
446     /****************
447       Create a new object 
448      ****************/
450     $types = array( "new_partition"     =>  "FAIpartitionTable",
451                     "new_script"        =>  "FAIscript",
452                     "new_hook"          =>  "FAIhook",
453                     "new_variable"      =>  "FAIvariable",
454                     "new_template"      =>  "FAItemplate",
455                     "new_package"       =>  "FAIpackageList");
457     if(isset($types[$s_action])){
458       $this->dialog = new askClassName($this->config,$this->dn,$this->ui,$types[$s_action]);
459     }
461     /* New Profile */
462     if($s_action == "new_profile"){
463       $this->dn = "new" ;
464       $a_setup= $this->get_type(array("objectClass"=>array("FAIprofile")));
466       $this->dialog = new $a_setup[0]($this->config,
467           $this->config->data['TABS'][$a_setup[2]],$this->dn);
468       $this->is_dialog = true;
469     }
472     /****************
473       Get from ask class name dialog 
474      ****************/
476     if($s_action == "select_class_name_finished"){
477       $this->dialog->save_object();
478       if(count($this->dialog->check())!=0){
479         foreach($this->dialog->check() as $msg){
480           print_red($msg);
481         }               
482       }else{
483         $this->dn = "new" ;
484         $a_setup= $this->get_type(array("objectClass"=>array($this->dialog->objectClass)));
485         $name = $this->dialog->save();
487         $this->dialog = new $a_setup[0]($this->config,
488             $this->config->data['TABS'][$a_setup[2]],$this->dn,$name);
489         $this->dialog->by_object[$a_setup[1]]->cn = $name;
490         $this->is_dialog = true;
491       }         
492     }   
495     /****************
496      Cancel dialogs 
497      ****************/
499                 if(isset($_POST['edit_cancel'])){
500                         unset($this->dialog);
501                         $this->dialog=NULL;
502                         $this->is_dialog = false;
503                         unset($_SESSION['objectinfo']);
504                         del_lock ($this->dn);
505                 }
508     /****************
509       Save sub dialogs 
510      ****************/
512                 /* This check if the given tab could be saved 
513                  * If it was possible to save it, remove dialog object. 
514                  * If it wasn't possible, show errors and keep dialog.
515                  */
516                 if((isset($_POST['edit_finish']) || isset($_POST['edit_apply'])) && (isset($this->dialog->config))){
517                         $this->dialog->save_object();
518       $msgs= $this->dialog->check();
519                         if(count($msgs)!=0){
520                                 foreach($msgs as $msg){
521                                         print_red($msg);
522                                 }
523                         }else{
524                                 $this->dialog->save();
525         if (!isset($_POST['edit_apply'])){
526           del_lock ($this->dn);
527           unset($this->dialog);
528           $this->dialog=NULL;
529           $this->is_dialog=false;
530           unset($_SESSION['objectinfo']);
531         }
532                         }
533                 }
536     /****************
537       Display currently open dialog 
538      ****************/
540                 /* If dialog is set, but $this->is_dialog==false, then 
541                  *  only the "abort" button is shown, this are dialogs that must not be saved.  
542                  * If is_dialog == true, we are currently editing tab objects.
543                  *  Here we need both, save and cancel
544                  */ 
546                 if(($this->dialog != NULL) && (isset($this->dialog->config))){
547                         $display .= $this->dialog->execute();
548                         /* Don't show buttons if tab dialog requests this */
549                         if (((isset($this->dialog->current))&&($this->dialog->by_object[$this->dialog->current]->is_dialog))){
550                                 
551                         }elseif(((isset($this->dialog->current))&&(!$this->dialog->by_object[$this->dialog->current]->is_dialog))){
552                                 $display.= "<p style=\"text-align:right\">\n";
553                                 $display.= "<input type=\"submit\" name=\"edit_finish\" style=\"width:80px\" value=\""._("Ok")."\">\n";
554                                 $display.= "&nbsp;\n";
555         if ($this->dn != "new"){
556           $display.= "<input type=submit name=\"edit_apply\" value=\""._("Apply")."\">\n";
557           $display.= "&nbsp;\n";
558         }
559                                 $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
560                                 $display.= "</p>";
561                         }elseif(!isset($this->dialog->current)){
562                                 $display.= "<p style=\"text-align:right\">\n";
563                                 $display.= "<input type=\"submit\" name=\"edit_continue\" value=\""._("Continue")."\">&nbsp;";
564                                 $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
565                                 $display.= "</p>";
566                         }
567                         return($display);
568                 }
569                 
571     /****************
572       Dialog display
573      ****************/
575     /* Check if there is a snapshot dialog open */
576     $base = $this->DivListFai->selectedBase;
577     if($str = $this->showSnapshotDialog($base,$this->get_used_snapshot_bases())){
578       return($str);
579     }
581     /* Display dialog with system list */
582     $this->DivListFai->parent = $this;
583     $this->DivListFai->execute();
584     $this->DivListFai->AddDepartments($this->DivListFai->selectedBase,4);
585     $this->reload();
586     $this->DivListFai->setEntries($this->objects);
587     return($this->DivListFai->Draw());
588         }
591   /* Return departments, that will be included within snapshot detection */
592   function get_used_snapshot_bases()
593   {
594     $tmp = array();
595     $types = array("hooks","scripts","disk","packages","profiles","templates","variables");
596     foreach($types as $type){
597       if($this->DivListFai->selectedBranch == "main"){
598         $tmp[] = "ou=".$type.",ou=fai,ou=configs,ou=systems,".$this->DivListFai->selectedBase;
599       }else{
600         $tmp[] = "ou=".$type.",".$this->DivListFai->selectedBranch;
601       }
602     }
603     return($tmp);
604   }
607   /* Get available branches for current base */
608   function getBranches($base = false,$prefix = "")
609   {
610     $ret = array("main"=>"/");
611     $ldap = $this->config->get_ldap_link();
612     if(!$base){
613       $base= "ou=fai,ou=configs,ou=systems,".$_SESSION['CurrentMainBase'];
614     }
615     $ldap->ls("(objectClass=FAIbranch)",$base);
616     while($attrs = $ldap->fetch()){
617       if((isset($attrs['ou']))&&($attrs['dn']!=$base)){
618         $ret[$attrs['dn']]= $prefix.$attrs['ou'][0];
619         $ret = array_merge($ret,$this->getBranches($attrs['dn'],"".$prefix.$attrs['ou'][0]."/"));
620       }
621     }
623     return ($ret);
624   }
626   
628   /* reload list of objects */
629   function reload()
630   {
631     /* Variable initialisation */
632     $str            = "";
633     $Regex          = $this->DivListFai->Regex;
634     $this->objects  = array();
636     /* Get base */
637     $base = "ou=fai,ou=configs,ou=systems,".$this->DivListFai->selectedBase;
638     if($this->DivListFai->selectedBranch != "main"){
639       $br = $this->getBranches();
640       if(isset($br[$this->DivListFai->selectedBranch])){
641         $base = $this->DivListFai->selectedBranch;
642       }else{
643         $base = "ou=fai,ou=configs,ou=systems,".$this->DivListFai->selectedBase;
644       }
645     }
647     /* Get resolved release dependencies */
648     $tmp = get_all_objects_for_given_base($base,"(&(|(objectClass=FAIpartitionTable)(objectClass=FAIpackageList)(objectClass=FAIscript)
649       (objectClass=FAIvariable)(objectClass=FAIhook)(objectClass=FAIprofile)(objectClass=FAItemplate))(cn=$Regex))");
651     /* Create a new list of FAI object 
652      * Generate List of Partitions,Hooks,Scripts,Templates,Profiles ... 
653      */
654     $ObjectTypes = array(
655         "FAIpartitionTable"  => array("OU"=>"ou=disk,"        , "CHKBOX"=>"ShowPartitions"),
656         "FAIpackageList"     => array("OU"=>"ou=packages,"    , "CHKBOX"=>"ShowPackages"),
657         "FAIscript"          => array("OU"=>"ou=scripts,"     , "CHKBOX"=>"ShowScripts"),
658         "FAIvariable"        => array("OU"=>"ou=variables,"   , "CHKBOX"=>"ShowVariables"),
659         "FAIhook"            => array("OU"=>"ou=hooks,"       , "CHKBOX"=>"ShowHooks"),
660         "FAIprofile"         => array("OU"=>"ou=profiles,"    , "CHKBOX"=>"ShowProfiles"),
661         "FAItemplate"        => array("OU"=>"ou=templates,"   , "CHKBOX"=>"ShowTemplates"));
663     /* Ge listed ldap objects */
664     $ldap = $this->config->get_ldap_link();
665     $ldap->cd($this->config->current['BASE']);
666     foreach($tmp as $entry){
668       /* Get some more informations about the object */ 
669       $ldap->cat($entry['dn'], array("cn","description","objectClass","FAIclass","FAIstate","objectClass"));
670       $object  = $ldap->fetch();
672       /* Walk through possible types */
673       foreach($ObjectTypes as $type => $rest){  
675         /* Skip all unchecked types */
676         if(! $this->DivListFai->$rest['CHKBOX']){
677           continue;
678         }
680         if(in_array($type,$object['objectClass'])){
682           /* Prepare object */
683           unset($object['objectClass']['count']);
684           if(!isset($object['description'][0])){
685             $object['description'][0]="";
686           }
688           /* Clean up object informations */
689           $obj['cn']                          = $object['cn'][0];
690           $obj['dn']                          = $object['dn'];
691           $obj['description']   = $object['description'][0];
692           $obj['objectClass']   = $object['objectClass'];
694           /* Append type to this string, to be able to check if the selected 
695            * entry is of type 'freeze' or 'branch'
696            */
697           if(isset($object['FAIstate'])){
698             $obj['FAIstate'] = $object['FAIstate'][0];
699             $str.="|".$obj['FAIstate'];
700           }else{
701             $obj['FAIstate'] ="";
702           }
703           $this->objects[strtolower($obj['cn']).$obj['cn'].$type] = $obj;
704           $this->objects[strtolower($obj['cn']).$obj['cn'].$type]['type']=$type;
705         }
706                         }
707                 }
709     /* Tell class what we have currently opened 
710         'main' has type '' */
711     if(preg_match("/freeze/",$str)){
712       $this->lock_type = "freeze";
713     }elseif(preg_match("/branch/",$str)){
714       $this->lock_type = "branch";
715     }else{
716       $this->lock_type = "";
717     }
719                 ksort($this->objects);
720                 reset ($this->objects);
721         
722                 /* use numeric index, thats a bit more secure */        
723                 $tmp0 = array();
724                 foreach($this->objects as $obj){
725                         $tmp0[]= $obj;
726                 }
727                 $this->objects = array();
728                 $this->objects = $tmp0;
729         }
731         function remove_lock()
732         {
733                 if (isset($this->dn)){
734                         del_lock ($this->dn);
735                 }
736         }
738         function get_type($array){
739                 if(in_array("FAIpartitionTable",$array['objectClass'])){
740                         return(array("tabsPartition","faiPartitionTable","FAIPARTITIONTABS"));
741                 }
742                 if(in_array("FAIscript",$array['objectClass'])){
743                         return(array("tabsScript","faiScript","FAISCRIPTTABS"));
744                 }
745                 if(in_array("FAItemplate",$array['objectClass'])){
746                         return(array("tabsTemplate","faiTemplate","FAITEMPLATETABS"));
747                 }
748                 if(in_array("FAIhook",$array['objectClass'])){
749                         return(array("tabsHook","faiHook","FAIHOOKTABS"));
750                 }
751                 if(in_array("FAIvariable",$array['objectClass'])){
752                         return(array("tabsVariable","faiVariable","FAIVARIABLETABS"));
753                 }
754                 if(in_array("FAIprofile",$array['objectClass'])){
755                         return(array("tabsProfile","faiProfile","FAIPROFILETABS"));
756                 }
757                 
758                 if(in_array("FAIpackageList",$array['objectClass'])){
759                         return(array("tabsPackage","faiPackage","FAIPACKAGETABS"));
760                 }
761         }
763   function CheckNewBranchName($name,$base)
764   {
765     $f = $this->DivListFai->selectedBranch;
766     if(empty($name)){
767       return(false);
768     }elseif(in_array($name,$this->getBranches($f))) {
769       return(false);
770     }elseif(empty($name)){
771       return(false);
772     }elseif(is_department_name_reserved($name,$base)){
773       return(false);
774     }
775     return(true);
776   }
778   function save_object()
779   {
780     $this->DivListFai->save_object();
781   }
784 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
785 ?>