Code

Fixed some typos
[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  */
20 require "tabsPartition.inc";
21 require "tabsVariable.inc";
22 require "tabsHook.inc";
23 require "tabsTemplate.inc";
24 require "tabsScript.inc";
25 require "tabsProfile.inc";
26 require "tabsPackage.inc";
28 class faiManagement extends plugin
29 {
30         /* Definitions */
31         var $plHeadline                 = "FAI";
32         var $plDescription              = "Fully Automatic Installation - management";
34         /* CLI vars */
35         var $cli_summary                = "Handling of FAI entries";
36         var $cli_description    = "This plugin represents a management tool\n
37                 which allows us to manage all needed attributes for fully automatic installations (FAI)";
38         var $cli_parameters             = array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
40         /* Headpage attributes */
41         var $departments= array();
42         var $deptabs= NULL;
44         /* attribute list for save action */
45         var $attributes                 = array();      //      Attributes Managed by this plugin, none, 
46         //      because this is only an overview over all objects already defined in FAI.
47         var $objectclasses              = array();      //      ObjectClasses which the attributes are related to
48         var $dialog                             = array();      //      This object contains every dialog we have currently opened
50         var $objects                    = array();      //      This array contains all available objects shown in divlist
51         var $is_dialog                  = false;
53         /* construction/reconstruction 
54          * The Filter ($faifilter stored in $_SESSION['faifilter']) defines the last 
55          *  selected department and filter options
56          * If it is not defined already we create a new fresh faifilter.
57          */
58         function faiManagement ($config, $ui)
59         {
60                 $this->ui                       = $ui;  
62                 /* Set current dn to "", */
63                 $this->dn                       = "";
65                 /* Assign config */
66                 $this->config           = $config;
68                 /* Get global filter config */
69                 if (!is_global("faifilter")){
70                         $base   = get_base_from_people($ui->dn);
71                         $faifilter= array("base" => $base,
72                                         "regex" => "*");
73                         $faifilter['ShowProfiles']      = true;
74                         $faifilter['ShowTemplates'] = true;
75                         $faifilter['ShowScripts']       = true;
76                         $faifilter['ShowHooks']         = true;
77                         $faifilter['ShowVariables']     = true;
78                         $faifilter['ShowPackages']      = true;
79                         $faifilter['ShowPartitions']=true;
80                         register_global("faifilter", $faifilter);
81                 }
82         }
84         function execute()
85         {
87         /* Call parent execute */
88         plugin::execute();
90                 $display        = "";
91                 $smarty         = get_smarty();
92                 $s_action       = "";
93                 $s_entry        = "";
94                 /* filter management 
95                  * Filter will be changed if POST['regex'] or $_GET['search'] isset
96                  * New Filter will be stored in session and is used to generate list contents
97                  */     
98                 $faifilter = $_SESSION['faifilter'];
100                 /* Filter is posted by apply button 
101                  * Check every single chkbox 
102                  */
103                 if(isset($_POST['regex'])){
104                         $faifilter['regex'] = $_POST['regex']."*";
105                         foreach(array("ShowPartitions","ShowProfiles","ShowTemplates","ShowScripts","ShowHooks","ShowVariables","ShowPackages") as $attrs){
106                                 if(isset($_POST[$attrs])){
107                                         $faifilter[$attrs] = true;
108                                 }else{
109                                         $faifilter[$attrs] = false;
110                                 }
111                         }
112                 }
114                 /* Check ImageButton posts
115                  * Create new tab ich new_xx is posted
116                  */
117                 foreach($_POST as $key => $val){
118                         if(preg_match("/create_partition/i",$key)){
119                                 $s_action = "new_partition";
120                         }elseif(preg_match("/create_script/i",$key)){
121                                 $s_action = "new_script";
122                         }elseif(preg_match("/create_hook/i",$key)){
123                                 $s_action = "new_hook";
124                         }elseif(preg_match("/create_variable/i",$key)){
125                                 $s_action = "new_variable";
126                         }elseif(preg_match("/create_template/i",$key)){
127                                 $s_action = "new_template";
128                         }elseif(preg_match("/create_package/i",$key)){
129                                 $s_action = "new_package";
130                         }elseif(preg_match("/create_profile/i",$key)){
131                                 $s_action = "new_profile";
132                         }elseif(preg_match("/edit_continue/",$key)){
133                                 $s_action = "select_class_name_finished";
134                         }elseif(preg_match("/^entry_edit_.*/",$key)){
135                                 $s_entry = preg_replace("/^entry_edit_/","",$key);
136                                 $s_entry = preg_replace("/_.*$/","",$s_entry);
137                                 $s_action = "edit";
138                         }elseif(preg_match("/^entry_delete_.*/",$key)){
139                                 $s_entry = preg_replace("/^entry_delete_/","",$key);
140                                 $s_entry = preg_replace("/_.*$/","",$s_entry);
141                                 $s_action = "delete";
142                         }elseif(preg_match("/dep_back.*/i",$key)){
143                 $s_action="back";
144             }elseif(preg_match("/dep_home.*/i",$key)){
145                 $s_action="home";
146             }elseif(preg_match("/dep_root.*/i",$key)){
147                 $s_action="root";
148                         }
150                 }
152                 if($s_action=="root"){
153                         $faifilter['base']=($this->config->current['BASE']);
154                 }
156                 if($s_action=="home"){
157                         $faifilter['base']=(preg_replace("/^[^,]+,/","",$this->ui->dn));
158                         $faifilter['base']=(preg_replace("/^[^,]+,/","",$faifilter['base']));
159                 }
161                 if($s_action=="back"){
162                         $base_back          = preg_replace("/^[^,]+,/","",$faifilter['base']);
163                         $base_back          = convert_department_dn($base_back);
165                         if(isset($this->config->departments[trim($base_back)])){
166                                 $faifilter['base']= $this->config->departments[trim($base_back)];
167                         }else{
168                                 $faifilter['base']= $this->config->departments["/"];
169                         }
170                 }
172                 if(isset($_GET['act'])&&($_GET['act']=="dep_open")){
173             $s_action="open";
174             $s_entry = base64_decode($_GET['dep_id']);
175             $faifilter['base']= $this->config->departments[trim($s_entry)];
176         }
178                 if(isset($_GET['edit_entry'])){
179                         $s_entry = $_GET['edit_entry'];
180                         $s_action = "edit";
181                 }
183                 /* Confirm dialog 
184                  * Delte object 
185          */
186                 if ($s_action=="delete"){
188                         /* Get 'dn' from posted termlinst */
189                         $this->dn= $this->objects[$s_entry]['dn'];
191                         /* Load permissions for selected 'dn' and check if
192                            we're allowed to remove this 'dn' */
193                         $acl=           get_permissions ($this->dn, $this->ui->subtreeACL);
194                         $this->acl= get_module_permission($acl, "FAIclass", $this->dn);
195                         if (chkacl($this->acl, "delete") == ""){
197                                 /* Check locking, save current plugin in 'back_plugin', so the dialog knows where to return. */
198                                 if (($user= get_lock($this->dn)) != ""){
199                                         return(gen_locked_message ($user, $this->dn));
200                                 }
202                                 /* Lock the current entry, so nobody will edit it during deletion */
203                                 add_lock ($this->dn, $this->ui->dn);
204                                 $smarty->assign("warning", sprintf(_("You're about to delete all information about the FAI class at '%s'."), $this->dn));
205                                 return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
206                         } else {
208                                 /* Obviously the user isn't allowed to delete. Show message and
209                                    clean session. */
210                                 print_red (_("You are not allowed to delete this component!"));
211                         }
212                 }
214                 /* Delete canceled? */
215                 if (isset($_POST['delete_cancel'])){
216                         del_lock ($this->dn);
217                 }
220                 /* Deltetion was confirmed, so delete this entry
221                  */
222                 if (isset($_POST['delete_terminal_confirm'])){
224                         /* Some nice guy may send this as POST, so we've to check
225                            for the permissions again. */
226                         if (chkacl($this->acl, "delete") == ""){
228                                 /* Find out more about the object type */
229                                 $ldap   = $this->config->get_ldap_link();
230                                 $ldap->cat($this->dn);
231                                 $attrs  = $ldap->fetch();
233                                 $type   = $this->get_type($attrs);                      
235                                 $this->dialog= new $type[0]($this->config,      $this->config->data['TABS'][$type[2]], $this->dn);
236                                 $this->dialog->set_acl(array($this->acl));
238                                 $this->dialog->by_object[$type[1]]->remove_from_parent ();
239                                 unset ($this->dialog);
240                                 gosa_log ("FAI class '".$this->dn."' has been removed");
241                                 $this->dialog= NULL;
243                                 /* Terminal list has changed, reload it. */
244                                 $this->reload ();
245                         } else {
247                                 /* Normally this shouldn't be reached, send some extra
248                                    logs to notify the administrator */
249                                 print_red (_("You are not allowed to delete this component!"));
250                                 gosa_log ("Warning: '".$this->ui->uid."' tried to trick system ".
251                                                 "deletion.");
252                         }
254                         /* Remove lock file after successfull deletion */
255                         del_lock ($this->dn);
256                 }
258                 /* Edit Entry */
259                 if($s_action == "edit"){
260                         $entry  = $this->objects[$s_entry];
262                         $a_setup = ($this->get_type($entry));
263                 
264                         $this->dn = $entry['dn'];
265                         /* Check locking, save current plugin in 'back_plugin', so the dialog knows where to return. */
266                         if (($user= get_lock($this->dn)) != ""){
267                                 return(gen_locked_message ($user, $this->dn));
268                         }
269                         add_lock ($this->dn, $this->ui->dn);
271                         $this->dialog= new $a_setup[0]($this->config,
272                                         $this->config->data['TABS'][$a_setup[2]],$this->dn);
273                         $this->is_dialog = true;
274                         $_SESSION['objectinfo'] = $this->dn;
275                 }
278                 /* Dialog handling */
279                 if($s_action == "new_partition"){
280                         $this->dialog = new askClassName($this->config,$this->dn,$this->ui,"FAIpartitionTable");
281                 }
283                 /* Dialog handling */
284                 if($s_action == "new_script"){
285                         $this->dialog = new askClassName($this->config,$this->dn,$this->ui,"FAIscript");
286                 }
288                 /* Dialog handling */
289                 if($s_action == "new_hook"){
290                         $this->dialog = new askClassName($this->config,$this->dn,$this->ui,"FAIhook");
291                 }
293                 /* Dialog handling */
294                 if($s_action == "new_variable"){
295                         $this->dialog = new askClassName($this->config,$this->dn,$this->ui,"FAIvariable");
296                 }
298                 /* Dialog handling */
299                 if($s_action == "new_template"){
300                         $this->dialog = new askClassName($this->config,$this->dn,$this->ui,"FAItemplate");
301                 }
303                 /* Dialog handling */
304                 if($s_action == "new_package"){
305                         $this->dialog = new askClassName($this->config,$this->dn,$this->ui,"FAIpackageList");
306                 }
308                 /* New Profile */
309                 if($s_action == "new_profile"){
310                         $this->dn = "new" ;
311                         $a_setup= $this->get_type(array("objectClass"=>array("FAIprofile")));
313                         $this->dialog = new $a_setup[0]($this->config,
314                                         $this->config->data['TABS'][$a_setup[2]],$this->dn);
315                         $this->is_dialog = true;
317                 }
319                 if($s_action == "select_class_name_finished"){
320                         $this->dialog->save_object();
321                         if(count($this->dialog->check())!=0){
322                                 foreach($this->dialog->check() as $msg){
323                                         print_red($msg);
324                                 }               
325                         }else{
326                                 $this->dn = "new" ;
327                                 $a_setup= $this->get_type(array("objectClass"=>array($this->dialog->objectClass)));
328                                 $name = $this->dialog->save();
330                                 $this->dialog = new $a_setup[0]($this->config,
331                                                 $this->config->data['TABS'][$a_setup[2]],$this->dn,$name);
332                                 $this->dialog->by_object[$a_setup[1]]->cn = $name;
333                                 $this->is_dialog = true;
334                         }               
335                 }       
338                 /* Search is set */
339                 if(isset($_GET['search'])){
340                         $faifilter['regex']=$_GET['search']."*";
341                 }
343                 /* Department select */
344                 if((isset($_POST['base']))&&($s_action=="")){
345                         $faifilter['base']=$_POST['base'];
346                 }
348                 /* remove double asterisks and save new filter */
349                 $faifilter['regex'] = preg_replace("/\*\*/","*",$faifilter['regex']);
350                 $_SESSION['faifilter']= $faifilter;
352                 /* Edit dialog was canceled 
353                  * Remove dialog an show management dialog
354                  */
355                 if(isset($_POST['edit_cancel'])){
356                         unset($this->dialog);
357                         $this->dialog=NULL;
358                         $this->is_dialog = false;
359                         unset($_SESSION['objectinfo']);
360                         del_lock ($this->dn);
361                 }
363                 /* This check if the given tab could be saved 
364                  * If it was possible to save it, remove dialog object. 
365                  * If it wasn't possible, show errors and keep dialog.
366                  */
367                 if(isset($_POST['edit_finish'])){
368                         $this->dialog->save_object();
369                         if(count($this->dialog->check())!=0){
370                                 foreach($this->dialog->check() as $msg){
371                                         print_red($msg);
372                                 }
373                         }else{
374                                 del_lock ($this->dn);
375                                 $this->dialog->save();
376                                 unset($this->dialog);
377                                 $this->dialog=NULL;
378                                 $this->is_dialog=false;
379                                 unset($_SESSION['objectinfo']);
380                         }
381                 }
383                 /* If dialog is set, but $this->is_dialog==false, then 
384                  *  only the "abort" button is shown, this are dialogs that must not be saved.  
385                  * If is_dialog == true, we are currently editing tab objects.
386                  *  Here we need both, save and cancel
387                  */ 
389                 if($this->dialog != NULL){
390                         $display .= $this->dialog->execute();
391                         /* Don't show buttons if tab dialog requests this */
392                         if (((isset($this->dialog->current))&&($this->dialog->by_object[$this->dialog->current]->is_dialog))){
393                                 
394                         }elseif(((isset($this->dialog->current))&&(!$this->dialog->by_object[$this->dialog->current]->is_dialog))){
395                                 $display.= "<p style=\"text-align:right\">\n";
396                                 $display.= "<input type=\"submit\" name=\"edit_finish\" value=\""._("Finish")."\">\n";
397                                 $display.= "&nbsp;\n";
398                                 $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
399                                 $display.= "</p>";
400                         }elseif(!isset($this->dialog->current)){
401                                 $display.= "<p style=\"text-align:right\">\n";
402                                 $display.= "<input type=\"submit\" name=\"edit_continue\" value=\""._("Continue")."\">&nbsp;";
403                                 $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
404                                 $display.= "</p>";
405                         }
406                         return($display);
407                 }
409                 /* Show Management template
410                  * The following code will only be reached if no dialog (tabs or dialogs)
411                  *  are currently opened.
412                  * Assign all reguired vars to template engine
413                  */
415                 /* Prepare departments */
416                 $options= "";
417                 foreach ($this->config->idepartments as $key => $value){
418                         if ($faifilter['base'] == $key){
419                                 $options.= "<option selected='selected' value='$key'>$value</option>";
420                         } else {
421                                 $options.= "<option value='$key'>$value</option>";
422                         }
423                 }
425                 /* Create listhead, it will be shown on top of the divlist. 
426                  * It provides general navigation and object creation
427                  */
428                 $faihead = 
429                         "<div style='background:#F0F0F9;padding:5px;'>&nbsp;".
431                         "<input class='center' type='image' src='images/list_up.png' align='middle' 
432                         title='"._("Go up one department")."' name='dep_back' alt='"._("Up"). "'>&nbsp;".
434                         "<input class='center' type='image' src='images/list_root.png' align='middle' 
435                         title='"._("Go to root department")."' name='dep_root' alt='".      _("Root")."'>&nbsp;".
437                         "<input class='center' type='image' src='images/list_home.png' align='middle' 
438                         title='"._("Go to users home department")."' name='dep_home' alt='"._("Home")."'>&nbsp;".
440                         "<img class='center' src=\"images/list_seperator.png\" alt=\"\" align=\"middle\" height=\"16\" width=\"1\">&nbsp;".
441                         
442                         " <input class='center' type='image' src='images/fai_new_profile.png' align='middle' 
443                         title='"._("New profile")."' name='Create_profile' alt='"._("P")."'>&nbsp;".
444                         
445                         "<img class='center' src=\"images/list_seperator.png\" alt=\"\" align=\"middle\" height=\"16\" width=\"1\">&nbsp;".
446                                 
447                         " <input class='center' type='image' src='images/fai_new_partitionTable.png' align='middle' 
448                         title='"._("New partition table")."' name='Create_partition' alt='"._("PT")."'>&nbsp;".
450                         " <input class='center' type='image' src='images/fai_new_script.png' align='middle' 
451                         title='"._("New scripts")."' name='Create_script' alt='"._("S")."'>&nbsp;".
453                         " <input class='center' type='image' src='images/fai_new_hook.png' align='middle' 
454                         title='"._("New hooks")."' name='Create_hook' alt='"._("H")."'>&nbsp;".
456                         " <input class='center' type='image' src='images/fai_new_variable.png' align='middle' 
457                         title='"._("New variables")."' name='Create_variable' alt='"._("V")."'>&nbsp;".
458                         
459                         " <input class='center' type='image' src='images/fai_new_template.png' align='middle' 
460                         title='"._("New templates")."' name='Create_template' alt='"._("T")."'>&nbsp;".
462                         " <input class='center' type='image' src='images/fai_new_packages.png' align='middle' 
463                         title='"._("New package list")."' name='Create_package' alt='"._("PK")."'>&nbsp;".
465                         " <img class='center' src='images/list_seperator.png' align='middle' alt='' height='16' width='1'>&nbsp;".
467                         _("Current base")."&nbsp;<select name='base' onChange='mainform.submit()' class='center'>$options</select>".
468                         " <input class='center' type='image' src='images/list_submit.png' align='middle' title='"._("Submit department")."' name='submit_department' alt='"._("Submit")."'>&nbsp;".
469                         
470                         "</div>";
472                 $this->reload();
474                 /* Create list with objects */
475                 $divlist = new divlist("faiManagement"); 
476                 $divlist->SetEntriesPerPage(0);
477                 $divlist->SetSummary(_("This table displays all systems, in the selected tree."));
479                 $divlist->SetHeader(array(
480                                         array("string" => "&nbsp;", "attach" => "style='text-align:center;width:20px;'"),
481                                         array("string" => _("Name of FAI class"), "attach" => "style=''"),
482                                         array("string" => _("Class type"), "attach" => "style='width:200px;'"),
483                                         array("string" => _("Actions"), "attach" => "style='width:60px;border-right:0px;text-align:right;'")));
486                 $action  = "<input class='center' type='image' src='images/edit.png'    alt='"._("edit")."'   name='entry_edit_%KEY%' title='"._("Edit class")."'>";
487                 $action .= "<input class='center' type='image' src='images/edittrash.png' alt='"._("delete")."' name='entry_delete_%KEY%' title='"._("Delete class")."'>";
489                 $editlink ="<a href='?plug=".$_GET['plug']."&amp;edit_entry=%KEY%'>%NAME%</a>";                 
490                 $linkopen = "<a href='?plug=".$_GET['plug']."&amp;act=dep_open&amp;dep_id=%s'>%s</a>";
492                 foreach($this->departments as $key => $val) {
493                         if(!isset($this->config->departments[trim($key)])){
494                                 $this->config->departments[trim($key)]="";
495                         }
497                         $non_empty="";
498                         $keys= str_replace("/","\/",$key);
499                         foreach($this->config->departments as $keyd=>$vald ){
500                                 if(preg_match("/".$keys."\/.*/",$keyd)){
501                                         $non_empty="full";
502                                 }
503                         }
506                         $title = $this->config->departments[$key];
507                         $field0 = array("string" => "<img src='images/".$non_empty."folder.png' title='"._("department")."' alt='department'>", "attach" => "style='text-align:center;width:20px;'");
508                         $field1 = array("string" => sprintf($linkopen,base64_encode($key),$val), "attach" => "style='' title='".$title."'");
509                         $field2 = array("string" => "&nbsp;", "attach" => "style='width:200px;'");
510                         $field3 = array("string" => "&nbsp;", "attach" => "style='width:60px;border-right:0px;text-align:right;'");
512                         $divlist->AddEntry( array($field0,$field1,$field2,$field3));
514                 }
517                 /* Attach objects */
518                 foreach($this->objects as $key => $value){
519                                 $info= "";
520                                 $img = "";
521                                 $type = $value['type'];
522                                 $abort=false;
524                                 switch($type) {
525                                         case "FAIpartitionTable"        : 
526                                                 if(!$faifilter['ShowPartitions']){ 
527                                                         $abort = true;
528                                                 }
529                                         $img="<img class='center' src='images/fai_partitionTable.png' title='"._("Partition table")."' alt='PT'>";
530                                         $info = _("Partition table");
531                                         break;
532                                         case "FAIpackageList"           : 
533                                                 if(!$faifilter['ShowPackages']){ 
534                                                         $abort = true;
535                                                 }
536                                         $img="<img class='center' src='images/fai_packages.png' title='"._("Package list")."' alt='PL'>";
537                                         $info = _("Package list");
538                                         break;
539                                         case "FAIscript"                        : 
540                                                 if(!$faifilter['ShowScripts']){ 
541                                                         $abort = true;
542                                                 }
543                                         $img="<img class='center' src='images/fai_script.png' title='"._("Scripts")."' alt='S'>";
544                                         $info = _("Scripts");
545                                         break;
546                                         case "FAIvariable"                      : 
547                                                 if(!$faifilter['ShowVariables']){ 
548                                                         $abort = true;
549                                                 }
550                                         $img="<img class='center' src='images/fai_variable.png' title='"._("Variables")."' alt='V'>";
551                                         $info = _("Variables");
552                                         break;
553                                         case "FAIhook"                          :
554                                                 if(!$faifilter['ShowHooks']){ 
555                                                         $abort = true;
556                                                 }
557                                         $img="<img class='center' src='images/fai_hook.png' title='"._("Hooks")."' alt='H'>";
558                                         $info = _("Hooks");
559                                         break;
560                                         case "FAIprofile"                       : 
561                                                 if(!$faifilter['ShowProfiles']){ 
562                                                         $abort = true;
563                                                 }
564                                         $img="<img class='center' src='images/fai_profile.png' title='"._("Profile")."' alt='P'>";
565                                         $info = _("Profile");
566                                         break;
567                                         case "FAItemplate"                      : 
568                                                 if(!$faifilter['ShowTemplates']){ 
569                                                         $abort = true;
570                                                 }
571                                         $img="<img class='center' src='images/fai_template.png' title='"._("Templates")."' alt='T'>";
572                                         $info = _("Templates");
573                                         break;
574                                         default                                         : 
575                                         $img="<img class='center' src='images/empty.png' alt=''>";$info = "";break;
577                                 }
578                                 
579                                 if(!$abort)     {
580                                         if((isset($value['description']))&&(!empty($value['description']))){
581                                                 $desc= " [".$value['description']."]";
582                                         }else{
583                                                 $desc= "";
584                                         }
586                                         $field1 = array("string" => $img , "attach" => "style='text-align:center;width:20px;'");
587                                         $field2 = array("string" => preg_replace(array("/%KEY%/","/%NAME%/"),array($key,$value['cn'].$desc),$editlink) , "attach" => "style=''");
588                                         $field3 = array("string" => $info, "attach" => "style='width:200px;'");
589                                         $field4 = array("string" => preg_replace("/%KEY%/",$key,$action) , "attach" => "style='width:60px;border-right:0px;text-align:right;'");
590                                         $divlist->AddEntry(array($field1,$field2,$field3,$field4));
592                         }
593                 }
595                 foreach($faifilter as $attrs => $value){
596                         if($value){
597                                 $smarty->assign($attrs."CHK", " checked ");
598                         }else{
599                                 $smarty->assign($attrs."CHK", " ");
600                         }
601                 }
603                 /* Assign all reguired vars to template engine */
604                 $smarty->assign("faihead"               , $faihead);    
605                 $smarty->assign("failist"               , $divlist->DrawList());
606                 $smarty->assign("regex"                 , $faifilter['regex']); 
607                 $smarty->assign("infoimage"             , get_template_path('images/info.png'));
608                 $smarty->assign("launchimage"   , get_template_path('images/launch.png'));
609                 $smarty->assign("alphabet"              , generate_alphabet());
610                 $smarty->assign("apply"                 , apply_filter());
611                 $smarty->assign("search_image"  , get_template_path('images/search.png'));
612                 $smarty->assign("hint", print_sizelimit_warning());
614                 $display        = $smarty->fetch(get_template_path('headpage.tpl', TRUE, dirname(__FILE__)));
615                 return ($display);
616         }
619         function reload()
620         {
621                 /* Create a new list of FAI object 
622                  * Object list depends on faifilter['regex']
623                  * Generate List of Partitions,Hooks,Scripts,Templates,Profiles ... 
624                  */
625                 $faifilter= get_global('faifilter');
626                 // Added for dirlist function...
628                 /* Set base for all searches */
629                 $base= "ou=fai,ou=configs,ou=systems,".$faifilter['base'];
630                 $regex = $faifilter['regex'];   
632                 /* Array to save objects */
633                 $objects = array();
634         
635                 $this->objects=array();
637                 /* NEW LIST MANAGMENT
638                  * We also need to search for the departments
639                  * So we are able to navigate like in konquerer
640                  */
641                 $base2 = $faifilter['base'];
643                 $res3 =  get_list2($this->ui->subtreeACL, "(&(|(ou=$regex)(description=$regex))(objectClass=gosaDepartment))",
644                                 TRUE, $base2, array("ou", "description"), TRUE);
646                 $this->departments= array();
647                 $tmp = array();
648                 foreach ($res3 as $value){
649                         $tmp[strtolower($value['dn']).$value['dn']]=$value;
650                 }
651                 ksort($tmp);
652                 foreach($tmp as $value){
653                         if(isset($value["description"][0])){
654                                 $this->departments[$value['dn']]=convert_department_dn2($value['dn'])." - [".$value["description"][0]."]";
655                         }else{
656                                 $this->departments[$value['dn']]=convert_department_dn2($value['dn']);//$value["description"][0];
657                         }
658                 }
660                 /* END NEW LIST MANAGMENT
661                  */
663         
664                 $res= get_list($this->ui->subtreeACL, "(objectClass=organizationalUnit)", 
665                                 FALSE, $base, array("cn","description","objectClass"),TRUE);
667                 foreach($res as $objecttypes){
668                         $res2 = get_list($this->ui->subtreeACL, "(&(objectClass=*)(cn=".$regex."))",
669                                         FALSE, $objecttypes['dn'], array("cn","description","objectClass","FAIclass"),TRUE);
670                         foreach($res2 as $object){
671                                 $type= "";      
672                                 unset($object['objectClass']['count']);
673                                 if(!isset($object['description'][0])){
674                                         $object['description'][0]="";
675                                 }
676                                 
677                                 /* Clean up object informations */
678                                 $obj['cn']                      = $object['cn'][0];
679                                 $obj['dn']                      = $object['dn'];
680                                 $obj['description'] = $object['description'][0];
681                                 $obj['objectClass'] = $object['objectClass'];
683                                 if(in_array("FAIpartitionTable",$obj['objectClass'])){
684                                         $type = "FAIpartitionTable";
685                                 }elseif(in_array("FAIpackageList",$obj['objectClass'])){
686                                         $type = "FAIpackageList";
687                                 }elseif(in_array("FAIscript",$obj['objectClass'])){
688                                         $type = "FAIscript";
689                                 }elseif(in_array("FAIvariable",$obj['objectClass'])){
690                                         $type = "FAIvariable";
691                                 }elseif(in_array("FAIhook",$obj['objectClass'])){
692                                         $type = "FAIhook";
693                                 }elseif(in_array("FAIprofile",$obj['objectClass'])){
694                                         $obj['FAIclass']        = $object['FAIclass'][0];
695                                         $type = "FAIprofile";
696                                 }elseif(in_array("FAItemplate",$obj['objectClass'])){
697                                         $type = "FAItemplate";
698                                 }
699                                 $this->objects[strtolower($obj['cn']).$obj['cn'].$type] = $obj;
700                                 $this->objects[strtolower($obj['cn']).$obj['cn'].$type]['type']=$type;
701  
702                         }
703                 }
704                 ksort($this->objects);
705                 reset ($this->objects);
706         
707                 /* use numeric index, thats a bit more secure */        
708                 $tmp0 = array();
709                 foreach($this->objects as $obj){
710                         $tmp0[]= $obj;
711                 }
712                 $this->objects = array();
713                 $this->objects = $tmp0;
715         }
717         function remove_lock()
718         {
719                 if (isset($this->dn)){
720                         del_lock ($this->dn);
721                 }
722         }
724         function get_type($array){
725                 if(in_array("FAIpartitionTable",$array['objectClass'])){
726                         return(array("tabsPartition","faiPartitionTable","FAIPARTITIONTABS"));
727                 }
728                 if(in_array("FAIscript",$array['objectClass'])){
729                         return(array("tabsScript","faiScript","FAISCRIPTTABS"));
730                 }
731                 if(in_array("FAItemplate",$array['objectClass'])){
732                         return(array("tabsTemplate","faiTemplate","FAITEMPLATETABS"));
733                 }
734                 if(in_array("FAIhook",$array['objectClass'])){
735                         return(array("tabsHook","faiHook","FAIHOOKTABS"));
736                 }
737                 if(in_array("FAIvariable",$array['objectClass'])){
738                         return(array("tabsVariable","faiVariable","FAIVARIABLETABS"));
739                 }
740                 if(in_array("FAIprofile",$array['objectClass'])){
741                         return(array("tabsProfile","faiProfile","FAIPROFILETABS"));
742                 }
743                 
744                 if(in_array("FAIpackageList",$array['objectClass'])){
745                         return(array("tabsPackage","faiPackage","FAIPACKAGETABS"));
746                 }
747         }
751 ?>