Code

Added download link
[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 $lock_type    = "";    // should be branch/freeze
43   var $lock_name    = "";
44   var $lock_dn      = "";  
46         /* attribute list for save action */
47         var $attributes         = array("lock_type","lock_name","lock_dn");     //      Attributes Managed by this plugin 
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   var $DivListFai;
59         /* construction/reconstruction 
60          */
61         function faiManagement ($config, $ui)
62         {
63                 /* Set defaults */
64                 $this->dn                       = "";
65                 $this->config   = $config;
66                 $this->ui                       = $ui;  
67     
68     /* Creat dialog object */
69     $this->DivListFai = new divListFai($this->config,$this);
70         }
72         function execute()
73         {
74     /* Call parent execute */
75     plugin::execute();
77     /* Initialise vars and smarty */
78                 $smarty         = get_smarty();
79                 $smarty->assign("BranchName","");
80     
81                 $display        = "";
82     $s_action   = "";
83                 $s_entry        = "";
84     
85     /* If an entry was locked, these vars will be stored in a session to allow direct edit */
86     $_SESSION['LOCK_VARS_TO_USE'] = array("/^edit_entry$/","/^id$/","/^entry_edit_/","/^entry_delete_/");
89     /****************
90       Handle posts 
91      ****************/
93                 /* Check ImageButton posts
94                  * Create new tab ich new_xx is posted
95                  */
96     $posts = array( "/remove_branch/"=>"remove_branch",    "/branch_branch/"=>"branch_branch",
97                     "/freeze_branch/"=>"freeze_branch",    "/create_partition/i"=>"new_partition",
98                     "/create_script/i"=>"new_script",      "/create_hook/i"=>"new_hook",
99                     "/create_variable/i"=>"new_variable",  "/create_template/i"=>"new_template",
100                     "/create_package/i"=>"new_package",    "/create_profile/i"=>"new_profile",
101                     "/edit_continue/"=>"select_class_name_finished");
103                 foreach($_POST as $name => $value){
104       foreach($posts as $reg => $act ){
105         if(preg_match($reg,$name)){
106           $s_action = $act;
107         }
108       }
109                         if(preg_match("/^entry_edit_.*/",$name)){
110                                 $s_entry = preg_replace("/^entry_edit_/","",$name);
111                                 $s_entry = preg_replace("/_.*$/","",$s_entry);
112                                 $s_action = "edit";
113                         }elseif(preg_match("/^entry_delete_.*/",$name)){
114                                 $s_entry = preg_replace("/^entry_delete_/","",$name);
115                                 $s_entry = preg_replace("/_.*$/","",$s_entry);
116         $s_action = "delete";
117       }
118     }
120                 if(isset($_GET['edit_entry'])){
121                         $s_entry = $_GET['edit_entry'];
122                         $s_action = "edit";
123                 }
124     
125     if((isset($_POST['CancelBranchName'])) || (isset($_POST['CloseIFrame']))){
126       $this->dispNewBranch = false;
127       $this->dispNewFreeze = false;
128     }
131     /****************
132       Delete confirme dialog 
133      ****************/
135                 if ($s_action=="delete"){
137                         /* Get 'dn' from posted termlinst */
138                         $this->dn= $this->objects[$s_entry]['dn'];
140                         /* Load permissions for selected 'dn' and check if
141                            we're allowed to remove this 'dn' */
142                         $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
143                         $this->acl= get_module_permission($acl, "FAIclass", $this->dn);
144                         if (chkacl($this->acl, "delete") == ""){
146                                 /* Check locking, save current plugin in 'back_plugin', so the dialog knows where to return. */
147                                 if (($user= get_lock($this->dn)) != ""){
148                                         return(gen_locked_message ($user, $this->dn));
149                                 }
151                                 /* Lock the current entry, so nobody will edit it during deletion */
152                                 add_lock ($this->dn, $this->ui->dn);
153                                 $smarty->assign("warning", sprintf(_("You're about to delete all information about the FAI class at '%s'."), @LDAP::fix($this->dn)));
154                                 return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
155                         } else {
157                                 /* Obviously the user isn't allowed to delete. Show message and
158                                    clean session. */
159                                 print_red (_("You are not allowed to delete this component!"));
160                         }
161                 }
164     /****************
165       Delete aborted  
166      ****************/
168                 /* Delete canceled? */
169                 if (isset($_POST['delete_cancel'])){
170                         del_lock ($this->dn);
171                 }
174     /****************
175       Delete confirmed 
176      ****************/
178                 /* Deltetion was confirmed, so delete this entry
179                  */
180                 if (isset($_POST['delete_terminal_confirm'])){
182                         /* Some nice guy may send this as POST, so we've to check
183                            for the permissions again. */
184                         if (chkacl($this->acl, "delete") == ""){
186                                 /* Find out more about the object type */
187                                 $ldap     = $this->config->get_ldap_link();
188                                 $ldap->cat($this->dn, array('objectClass'));
189                                 $attrs  = $ldap->fetch();
190                                 $type     = $this->get_type($attrs);                    
191                                 $this->dialog = new $type[0]($this->config,     $this->config->data['TABS'][$type[2]], $this->dn);
192                                 $this->dialog->set_acl(array($this->acl));
194                                 $this->dialog->by_object[$type[1]]->remove_from_parent ();
195                                 unset ($this->dialog);
196                                 gosa_log ("FAI class '".$this->dn."' has been removed");
197                                 $this->dialog= NULL;
198                         } else {
200                                 /* Normally this shouldn't be reached, send some extra
201                                    logs to notify the administrator */
202                                 print_red (_("You are not allowed to delete this component!"));
203                                 gosa_log ("Warning: '".$this->ui->uid."' tried to trick system ".
204                                                 "deletion.");
205                         }
207                         /* Remove lock file after successfull deletion */
208                         del_lock ($this->dn);
209                 }
212     /****************
213       Edit entry 
214      ****************/
216                 if(($s_action == "edit") && (!isset($this->dialog->config))){
217                         $entry    = $this->objects[$s_entry];
218                         $a_setup  = $this->get_type($entry);
219                         $this->dn = $entry['dn'];
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                         }
225                         add_lock ($this->dn, $this->ui->dn);
227                         $this->dialog     = new $a_setup[0]($this->config,$this->config->data['TABS'][$a_setup[2]],$this->dn);
228                         $this->is_dialog  = true;
230       if($entry['FAIstate'] == "freeze"){
231         $this->dialog->set_acl(array("*none*"))  ;
232       }
233                         $_SESSION['objectinfo'] = $this->dn;
234                 }
237     /*  Branch handling 
238         09.01.2006
239     */
241     /****************
242       Remove branch
243      ****************/
245     /* Remove branch 
246      */
247     if($s_action == "remove_branch"){
248       $base= $this->DivListFai->selectedBranch;
250       /* Load permissions for selected 'dn' and check if
251          we're allowed to remove this 'dn' */
252       $acl= get_permissions ($this->DivListFai->selectedBase, $this->ui->subtreeACL);
253       $this->acl= get_module_permission($acl, "FAIclass", $base);
254       if (chkacl($this->acl, "delete") == ""){
255         $smarty->assign("info", sprintf(_("You're about to delete a fai branch / freeze  '%s'."), $this->DivListFai->selectedBranch));
256         return($smarty->fetch(get_template_path('remove_branch.tpl',TRUE)));
257       } else {
258         print_red (_("You are not allowed to delete this release!"));
259       }
260     }
262     
263     /****************
264       Remove branch confirmed
265      ****************/
267     if(isset($_POST['delete_branch_confirm'])){
268       $bb =  $this->DivListFai->selectedBranch;
269       if(!isset($ldap)){
270         $ldap = $this->config->get_ldap_link();
271       }
273       $br = $this->getBranches();
275       if(isset($br[$bb])){
276         $name = $br[$bb];
277         $ldap->cd($bb);
278         $ldap->recursive_remove();
279         $ldap->cd(preg_replace('/,ou=fai,ou=configs,ou=systems,/', ',ou=apps,', $bb));
280         $ldap->recursive_remove();
281         $this->DivListFai->selectedBranch = "main";
283         /* Post remove */
284         $this->lock_name   = $name;
285         $this->lock_dn     = $bb;
286         $this->postremove();
287       }
288     }
291     /****************
292       Create a new branch "insert Name"
293      ****************/
295     if((isset($_POST['UseBranchName']))&&(($this->dispNewBranch)||($this->dispNewFreeze))){
296       $_SESSION['LASTPOST'] = $_POST;
298       if($this->dispNewBranch){
299         $type = "branch";
300       }else{
301         $type = "freeze";
302       }
304       /* Check branch name */
305       $name = $_POST['BranchName'];
306       $is_ok = true;
307       $smarty->assign("BranchName",$name);
308       $base= "ou=fai,ou=configs,ou=systems,".$this->DivListFai->selectedBase;
310       /* Check used characters */
311       if(preg_match("/[^0-9a-z \ö\ä\ü\.-_:,]/i",$name)){
312         if($type == "branch"){
313           print_red(_("Specified branch name is invalid."));
314         }else{
315           print_red(_("Specified freeze name is invalid."));
316         }
317         $is_ok = false;
318       }
320       /* Check if this name is already in use */
321       if(!$this->CheckNewBranchName($_POST['BranchName'],$this->DivListFai->selectedBranch)){
322         print_red(_("This name is already in use."));
323         $is_ok = false;
324       }
326       if($is_ok){
327         $_SESSION['LASTPOST']['base'] = $base;
328         $_SESSION['LASTPOST']['type'] = $type;
329         $smarty->assign("iframe", true);
330         $smarty->assign("plugID", $_GET['plug']);
331         $display        = $smarty->fetch(get_template_path('faiNewBranch.tpl', TRUE, dirname(__FILE__)));
332         return($display);
333       }
334     }
337     /****************
338       Create a new branch 
339      ****************/
341     if(isset($_GET['PerformBranch'])){
342       /* Create it know */
343       $this->dispNewBranch = false;
344       $this->dispNewFreeze = false;
345       $base = $_SESSION['LASTPOST']['base'];
346       $_POST = $_SESSION['LASTPOST'];      
347       $name = $_POST['BranchName'];
349       $type = $_SESSION['LASTPOST']['type'];
350       $ldap = $this->config->get_ldap_link();
352       $baseToUse = $base;
353       if($this->DivListFai->selectedBranch != "main" ){
354         $baseToUse = $this->DivListFai->selectedBranch;
355       }
356   
357       /* Create new Release name to be able to set faidebianRelease for FAIpackageList */
358       
359       $CurrentReleases  = $this->getBranches();
360       $NewReleaseName   = $name;
361       if(isset($CurrentReleases[$this->DivListFai->selectedBranch])) {
362         if($this->DivListFai->selectedBranch != "main"){
363           $NewReleaseName = $CurrentReleases[$this->DivListFai->selectedBranch]."/".$name;
364           $NewReleaseName = preg_replace("#\/#","/",$NewReleaseName); 
365         }else{
366           $NewReleaseName   = $name;
367         }
368       }
370       $appsrc = preg_replace("/ou=fai,ou=configs,ou=systems,/","ou=apps,",$baseToUse); 
371       $appdst = preg_replace("/ou=fai,ou=configs,ou=systems,/","ou=apps,","ou=".$name.",".$baseToUse) ; 
373       $mimesrc = preg_replace("/ou=fai,ou=configs,ou=systems,/","ou=mime,",$baseToUse); 
374       $mimedst = preg_replace("/ou=fai,ou=configs,ou=systems,/","ou=mime,","ou=".$name.",".$baseToUse) ; 
376       /* Print header to have styles included */
377       echo "<!-- headers.tpl-->".$smarty->fetch(get_template_path('headers.tpl'));
378       echo "<body style='background-image:none;margin:3px;color:black'>";
380       /* Duplicate applications 
381        */
382       $ldap->cd ($appdst);
383       $ldap->recursive_remove();
384       $ldap->cd ($this->config->current['BASE']);
385       $ldap->copy_FAI_resource_recursive($appsrc,$appdst,$NewReleaseName,$type,true);
387       /* Duplicate mime types 
388        */
389       $ldap->cd ($appdst);
390       $ldap->recursive_remove();
391       $ldap->cd ($this->config->current['BASE']);
392       $ldap->copy_FAI_resource_recursive($mimesrc,$mimedst,$NewReleaseName,$type,true);
394       /* Duplicate fai objects 
395        */
396       $ldap->cd ("ou=".$name.",".$baseToUse);
397       $ldap->recursive_remove();
398       $ldap->cd ($this->config->current['BASE']);
399       $ldap->copy_FAI_resource_recursive($baseToUse,"ou=".$name.",".$baseToUse,$NewReleaseName,$type,true);
401       echo "<div style='width:100%;text-align:right;'><form name='form' method='post' action='?plug=".$_GET['plug']."' target='_parent'>
402               <br><input type='submit' name='CloseIFrame' value='"._("Continue")."'>
403             </form></div>";
405       /* Print footer to have valid html */
406       echo "</body></html>";
408       $this->dispNewFreeze = false; 
410       /* Postcreate */ 
412       /* Assign possible attributes */
413       $this->lock_type  = $type; 
414       $this->lock_name  = $name; 
415       $this->lock_dn    = $baseToUse;
416       $this->postcreate();
417       exit();
418     }
421     /****************
422       Display dialog to enter new Branch name
423      ****************/
425     if(($s_action == "branch_branch")||($this->dispNewBranch)){
426       $this->dispNewBranch=true;
427       $smarty->assign("iframe",false);
428                   $display      .= $smarty->fetch(get_template_path('faiNewBranch.tpl', TRUE, dirname(__FILE__)));
429       return($display);
430     }
431    
432  
433     /****************
434       Display dialog to enter new Freeze name
435      ****************/
437     if(($s_action == "freeze_branch")||($this->dispNewFreeze)){
438       $this->dispNewFreeze = true;
439       $smarty->assign("iframe",false);
440                   $display      .= $smarty->fetch(get_template_path('faiNewBranch.tpl', TRUE, dirname(__FILE__)));
441       return($display);
442     }
445     /****************
446       Create a new object 
447      ****************/
449     $types = array( "new_partition"     =>  "FAIpartitionTable",
450                     "new_script"        =>  "FAIscript",
451                     "new_hook"          =>  "FAIhook",
452                     "new_variable"      =>  "FAIvariable",
453                     "new_template"      =>  "FAItemplate",
454                     "new_package"       =>  "FAIpackageList");
456     if(isset($types[$s_action])){
457       $this->dialog = new askClassName($this->config,$this->dn,$this->ui,$types[$s_action]);
458     }
460     /* New Profile */
461     if($s_action == "new_profile"){
462       $this->dn = "new" ;
463       $a_setup= $this->get_type(array("objectClass"=>array("FAIprofile")));
465       $this->dialog = new $a_setup[0]($this->config,
466           $this->config->data['TABS'][$a_setup[2]],$this->dn);
467       $this->is_dialog = true;
468     }
471     /****************
472       Get from ask class name dialog 
473      ****************/
475     if($s_action == "select_class_name_finished"){
476       $this->dialog->save_object();
477       if(count($this->dialog->check())!=0){
478         foreach($this->dialog->check() as $msg){
479           print_red($msg);
480         }               
481       }else{
482         $this->dn = "new" ;
483         $a_setup= $this->get_type(array("objectClass"=>array($this->dialog->objectClass)));
484         $name = $this->dialog->save();
486         $this->dialog = new $a_setup[0]($this->config,
487             $this->config->data['TABS'][$a_setup[2]],$this->dn,$name);
488         $this->dialog->by_object[$a_setup[1]]->cn = $name;
489         $this->is_dialog = true;
490       }         
491     }   
494     /****************
495      Cancel dialogs 
496      ****************/
498                 if(isset($_POST['edit_cancel'])){
499                         unset($this->dialog);
500                         $this->dialog=NULL;
501                         $this->is_dialog = false;
502                         unset($_SESSION['objectinfo']);
503                         del_lock ($this->dn);
504                 }
507     /****************
508       Save sub dialogs 
509      ****************/
511                 /* This check if the given tab could be saved 
512                  * If it was possible to save it, remove dialog object. 
513                  * If it wasn't possible, show errors and keep dialog.
514                  */
515                 if((isset($_POST['edit_finish']) || isset($_POST['edit_apply'])) && (isset($this->dialog->config))){
516                         $this->dialog->save_object();
517       $msgs= $this->dialog->check();
518                         if(count($msgs)!=0){
519                                 foreach($msgs as $msg){
520                                         print_red($msg);
521                                 }
522                         }else{
523                                 $this->dialog->save();
524         if (!isset($_POST['edit_apply'])){
525           del_lock ($this->dn);
526           unset($this->dialog);
527           $this->dialog=NULL;
528           $this->is_dialog=false;
529           unset($_SESSION['objectinfo']);
530         }
531                         }
532                 }
535     /****************
536       Display currently open dialog 
537      ****************/
539                 /* If dialog is set, but $this->is_dialog==false, then 
540                  *  only the "abort" button is shown, this are dialogs that must not be saved.  
541                  * If is_dialog == true, we are currently editing tab objects.
542                  *  Here we need both, save and cancel
543                  */ 
545                 if(($this->dialog != NULL) && (isset($this->dialog->config))){
546                         $display .= $this->dialog->execute();
547                         /* Don't show buttons if tab dialog requests this */
548                         if (((isset($this->dialog->current))&&($this->dialog->by_object[$this->dialog->current]->is_dialog))){
549                                 
550                         }elseif(((isset($this->dialog->current))&&(!$this->dialog->by_object[$this->dialog->current]->is_dialog))){
551                                 $display.= "<p style=\"text-align:right\">\n";
552                                 $display.= "<input type=\"submit\" name=\"edit_finish\" style=\"width:80px\" value=\""._("Ok")."\">\n";
553                                 $display.= "&nbsp;\n";
554         if ($this->dn != "new"){
555           $display.= "<input type=submit name=\"edit_apply\" value=\""._("Apply")."\">\n";
556           $display.= "&nbsp;\n";
557         }
558                                 $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
559                                 $display.= "</p>";
560                         }elseif(!isset($this->dialog->current)){
561                                 $display.= "<p style=\"text-align:right\">\n";
562                                 $display.= "<input type=\"submit\" name=\"edit_continue\" value=\""._("Continue")."\">&nbsp;";
563                                 $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
564                                 $display.= "</p>";
565                         }
566                         return($display);
567                 }
568                 
570     /****************
571       Dialog display
572      ****************/
574     /* Check if there is a snapshot dialog open */
575     $base = $this->DivListFai->selectedBase;
576     if($str = $this->showSnapshotDialog($base,$this->get_used_snapshot_bases())){
577       return($str);
578     }
580     /* Display dialog with system list */
581     $this->DivListFai->parent = $this;
582     $this->DivListFai->execute();
583     $this->DivListFai->AddDepartments($this->DivListFai->selectedBase,4);
584     $this->reload();
585     $this->DivListFai->setEntries($this->objects);
586     return($this->DivListFai->Draw());
587         }
590   /* Return departments, that will be included within snapshot detection */
591   function get_used_snapshot_bases()
592   {
593     $tmp = array();
594     $types = array("hooks","scripts","disk","packages","profiles","templates","variables");
595     foreach($types as $type){
596       if($this->DivListFai->selectedBranch == "main"){
597         $tmp[] = "ou=".$type.",ou=fai,ou=configs,ou=systems,".$this->DivListFai->selectedBase;
598       }else{
599         $tmp[] = "ou=".$type.",".$this->DivListFai->selectedBranch;
600       }
601     }
602     return($tmp);
603   }
606   /* Get available branches for current base */
607   function getBranches($base = false,$prefix = "")
608   {
609     $ret = array("main"=>"/");
610     $ldap = $this->config->get_ldap_link();
611     if(!$base){
612       $base= "ou=fai,ou=configs,ou=systems,".$_SESSION['CurrentMainBase'];
613     }
614     $ldap->ls("(objectClass=FAIbranch)",$base);
615     while($attrs = $ldap->fetch()){
616       if((isset($attrs['ou']))&&($attrs['dn']!=$base)){
617         $ret[$attrs['dn']]= $prefix.$attrs['ou'][0];
618         $ret = array_merge($ret,$this->getBranches($attrs['dn'],"".$prefix.$attrs['ou'][0]."/"));
619       }
620     }
622     return ($ret);
623   }
625   
626   /* reload list of objects */
627         function reload()
628         {
629     /* Create a new list of FAI object 
630      * Generate List of Partitions,Hooks,Scripts,Templates,Profiles ... 
631      */
632     $ObjectTypes = array(
633         "FAIpartitionTable"  => array("OU"=>"ou=disk,"       , "CHKBOX"=>"ShowPartitions"),
634         "FAIpackageList"     => array("OU"=>"ou=packages,"    , "CHKBOX"=>"ShowPackages"),
635         "FAIscript"          => array("OU"=>"ou=scripts,"     , "CHKBOX"=>"ShowScripts"),
636         "FAIvariable"        => array("OU"=>"ou=variables,"   , "CHKBOX"=>"ShowVariables"),
637         "FAIhook"            => array("OU"=>"ou=hooks,"       , "CHKBOX"=>"ShowHooks"),
638         "FAIprofile"         => array("OU"=>"ou=profiles,"    , "CHKBOX"=>"ShowProfiles"),
639         "FAItemplate"        => array("OU"=>"ou=templates,"   , "CHKBOX"=>"ShowTemplates"));
641     /* Set base for all searches */
642     $base           = "ou=fai,ou=configs,ou=systems,".$this->DivListFai->selectedBase;
643     if($this->DivListFai->selectedBranch != "main"){
644       $br = $this->getBranches();
645       if(isset($br[$this->DivListFai->selectedBranch])){
646         $base = $this->DivListFai->selectedBranch;
647       }else{
648         $base = "ou=fai,ou=configs,ou=systems,".$this->DivListFai->selectedBase;
649       }
650     }
652     $Regex          = $this->DivListFai->Regex;
653     $str            = "";
654     $objects        = array();
655     $this->objects  = array();
657     /* Walk through possible sub departments and fetch all FAI objects */
658                 foreach($ObjectTypes as $type => $obj){
660       /* Skip all unchecked types */
661       if(! $this->DivListFai->$obj['CHKBOX']){
662         continue;
663       }
665       /* Fetch objects from fai sub department */
666       $res= get_list("(&(objectClass=".$type.")(cn=$Regex))", $this->ui->subtreeACL, $obj['OU'].$base,
667             array("cn","description","objectClass","FAIclass","FAIstate"), GL_SIZELIMIT);
669       /* Walk through objects */
670                         foreach($res as $object){
672         /* Prepare object */
673                                 unset($object['objectClass']['count']);
674                                 if(!isset($object['description'][0])){
675                                         $object['description'][0]="";
676                                 }
677                                 
678                                 /* Clean up object informations */
679                                 $obj['cn']                            = $object['cn'][0];
680                                 $obj['dn']                            = $object['dn'];
681                                 $obj['description']   = $object['description'][0];
682                                 $obj['objectClass']   = $object['objectClass'];
684         /* Append type to this string, to be able to check if the selected 
685          * entry is of type 'freeze' or 'branch'
686          */
687         if(isset($object['FAIstate'])){
688           $obj['FAIstate'] = $object['FAIstate'][0];
689           $str.="|".$obj['FAIstate'];
690         }else{
691           $obj['FAIstate'] ="";
692         }
693                                 $this->objects[strtolower($obj['cn']).$obj['cn'].$type] = $obj;
694                                 $this->objects[strtolower($obj['cn']).$obj['cn'].$type]['type']=$type;
695                         }
696                 }
698     /* Tell class what we have currently opened 
699         'main' has type '' */
700     if(preg_match("/freeze/",$str)){
701       $this->lock_type = "freeze";
702     }elseif(preg_match("/branch/",$str)){
703       $this->lock_type = "branch";
704     }else{
705       $this->lock_type = "";
706     }
708                 ksort($this->objects);
709                 reset ($this->objects);
710         
711                 /* use numeric index, thats a bit more secure */        
712                 $tmp0 = array();
713                 foreach($this->objects as $obj){
714                         $tmp0[]= $obj;
715                 }
716                 $this->objects = array();
717                 $this->objects = $tmp0;
718         }
720         function remove_lock()
721         {
722                 if (isset($this->dn)){
723                         del_lock ($this->dn);
724                 }
725         }
727         function get_type($array){
728                 if(in_array("FAIpartitionTable",$array['objectClass'])){
729                         return(array("tabsPartition","faiPartitionTable","FAIPARTITIONTABS"));
730                 }
731                 if(in_array("FAIscript",$array['objectClass'])){
732                         return(array("tabsScript","faiScript","FAISCRIPTTABS"));
733                 }
734                 if(in_array("FAItemplate",$array['objectClass'])){
735                         return(array("tabsTemplate","faiTemplate","FAITEMPLATETABS"));
736                 }
737                 if(in_array("FAIhook",$array['objectClass'])){
738                         return(array("tabsHook","faiHook","FAIHOOKTABS"));
739                 }
740                 if(in_array("FAIvariable",$array['objectClass'])){
741                         return(array("tabsVariable","faiVariable","FAIVARIABLETABS"));
742                 }
743                 if(in_array("FAIprofile",$array['objectClass'])){
744                         return(array("tabsProfile","faiProfile","FAIPROFILETABS"));
745                 }
746                 
747                 if(in_array("FAIpackageList",$array['objectClass'])){
748                         return(array("tabsPackage","faiPackage","FAIPACKAGETABS"));
749                 }
750         }
752   function CheckNewBranchName($name,$base)
753   {
754     $f = $this->DivListFai->selectedBranch;
755     if(empty($name)){
756       return(false);
757     }elseif(in_array($name,$this->getBranches($f))) {
758       return(false);
759     }elseif(empty($name)){
760       return(false);
761     }elseif(is_department_name_reserved($name,$base)){
762       return(false);
763     }
764     return(true);
765   }
767   function save_object()
768   {
769     $this->DivListFai->save_object();
770   }
773 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
774 ?>