Code

Fixed problem with not clickable buttons in fai package error msgs
[gosa.git] / plugins / admin / fai / class_divListFai.inc
1 <?php
3 class divListFai extends MultiSelectWindow
4 {
5   /* Current base */
6   var $selectedBase       = "";
7   var $selectedBranch     = "main";
8   var $AvailableBranches  = array();
9   var $departments        = array();
11   /* Regex */
12   var $Regex              = "*";
13   var $ShowProfiles;
14   var $ShowTemplates;
15   var $ShowScripts;
16   var $ShowHooks;
17   var $ShowVariables;
18   var $ShowPackages;
19   var $ShowPartitions;
21   /* Subsearch checkbox */
22   var $SubSearch;
24   var $parent             ;
25   var $ui                 ;
27   var $SaveAdditionalVars = array("selectedBranch");
29   function divListFai ($config,$parent)
30   {
31     MultiSelectWindow::MultiSelectWindow($config, "Fai", "fai");
32     
33     $this->parent       = $parent;
34     $this->ui           = get_userinfo();
36     /* Set default base */
37     if(!isset($_SESSION['CurrentMainBase'])){
38       $_SESSION['CurrentMainBase'] = $this->config->current['BASE'];
39     }
40     $this->selectedBase = $_SESSION['CurrentMainBase'];
42     /* Set list strings */
43     $this->SetTitle(_("List of FAI classes"));
44     $this->SetSummary(_("This table displays all FAI classes in the selected tree."));
46     /* Result page will look like a headpage */
47     $this->SetHeadpageMode();
48     $this->SetInformation(_("This menu allows you to create, delete and edit FAI classes."));
50     $this->EnableAplhabet   (true);
51   
52     /* Disable buttonsm */
53     $this->EnableCloseButton(false);
54     $this->EnableSaveButton (false);
56    /* Dynamic action col, depending on snapshot icons */
57     $action_col_size = 50;
58     if($this->parent->snapshotEnabled()){
59       $action_col_size += 20;
60     }
62     /* Toggle all selected / deselected */
63     $chk = "<input type='checkbox' id='select_all' name='select_all'
64                onClick='toggle_all_(\"^item_selected_[0-9]*$\",\"select_all\");' >";
66     /* set Page header */
67     $this->AddHeader(array("string"=> $chk,          "attach"=>"style='width:20px;'"));
68     $this->AddHeader(array("string" => "&nbsp;",                "attach" => "style='text-align:center;width:20px;'"));
69     $this->AddHeader(array("string" => _("Name of FAI class"),  "attach" => "style=''"));
70     $this->AddHeader(array("string" => _("Class type"),         "attach" => "style='width:200px;'"));
71     $this->AddHeader(array("string" => _("Actions"),            "attach" => "style='width:".$action_col_size."px;border-right:0px;text-align:right;'"));
73     $this->AddCheckBox("ShowProfiles"   , _("Display FAI profile objects")    ,_("Show profiles")     ,true);
74     $this->AddCheckBox("ShowTemplates"  , _("Display FAI template objects")   ,_("Show templates")    ,true);
75     $this->AddCheckBox("ShowScripts"    , _("Display FAI scripts")            ,_("Show scripts")      ,true);
76     $this->AddCheckBox("ShowHooks"      , _("Display FAI hooks")              ,_("Show hooks")        ,true);
77     $this->AddCheckBox("ShowVariables"  , _("Display FAI variables")          ,_("Show variables")    ,true);
78     $this->AddCheckBox("ShowPackages"   , _("Display FAI packages")           ,_("Show packages")     ,true);
79     $this->AddCheckBox("ShowPartitions" , _("Display FAI partitions")         ,_("Show partitions")   ,true);
81     /* Add SubSearch checkbox */
82     //$this->AddCheckBox(SEPERATOR);
83     //$this->AddCheckBox("SubSearch",  _("Select to search within subtrees"), _("Ignore subtrees"), false);
85     /*                  Name                 ,Text                              ,Default  , Connect with alphabet  */
86     $this->AddRegex   ("Regex",     _("Display users matching"),"*" , true);
87   }
89   function AddUserBoxToFilter($position){
90     $str = "";
91     if($position  == 2){
92       $smarty = get_smarty();
93       $smarty->assign("selectedBranch",$this->selectedBranch);
94       $smarty->assign("branchimage","images/branch.png");
95       $smarty->assign("branches",$this->AvailableBranches);
96       $str = $smarty->fetch(get_template_path('branch_selector.tpl', TRUE));
97     }
98     return($str);
99   }
101   function GenHeader()
102   {
103     /* Prepare departments,
104        which are shown in the listbox on top of the listbox
105      */
106     $options= "";
108     /* Get all departments within this subtree */
109     $ui= get_userinfo();
110     $first = "";
111     $found = FALSE;
112     $base = $this->config->current['BASE'];
114     /* Add base */
115     $tmp = array();
116     $tmp[] = array("dn"=>$this->config->current['BASE']);
117     $tmp=  array_merge($tmp,get_list("(&(|(ou=*)(description=*))(objectClass=gosaDepartment))", $this->module, $base,
118                     array("ou", "description"), GL_SIZELIMIT | GL_SUBSEARCH));
120     $deps = array();
121     foreach($tmp as $tm){
122       $deps[$tm['dn']] = $tm['dn'];
123     }
125     /* Load possible departments */
126     $ui= get_userinfo();
127     $tdeps= $ui->get_module_departments("fai");
128     $ids = $this->config->idepartments;
129     $first = "";
130     $found = FALSE;
131     foreach($ids as $dep => $name){
132       if(isset($deps[$dep]) && in_array_ics($dep, $tdeps)){
134         /* Keep first base dn in mind, we could need this
135          *  info if no valid base was found
136          */
137         if(empty($first)) {
138           $first = $dep['dn'];
139         }
141         $value = $ids[$dep];
142         if ($this->selectedBase == $dep){
143           $found = TRUE;
144           $options.= "<option selected='selected' value='".$dep."'>$value</option>";
145         } else {
146           $options.= "<option value='".$dep."'>$value</option>";
147         }
148       }
149     }
151     /* The currently used base is not visible with your acl setup.
152      * Set base to first useable base.
153      */
154     if(!$found){
155       $this->selectedBase = $first;
156     }
158     /* Add seperator */
159     $add_sep = false;
161     /* Get complete fai acls, to be able to check if we must show or hide the snapshot abilities */ 
162     $acl_all = $ui->has_complete_category_acls($this->selectedBase,$this->module);
164     /* Add default header */
165     $listhead = MultiSelectWindow::get_default_header();
167     $acl = $ui->get_permissions($this->selectedBase,"fai/faiProfile");
168     if(preg_match("/c/",$acl)){
169       $listhead .=" <input class='center' type='image' src='images/fai_new_profile.png' align='middle'
170         title='"._("New profile")."' name='Create_profile' alt='"._("P")."'>&nbsp;";
171       $listhead .=" <img class='center' src='images/list_seperator.png' align='middle' alt='' height='16' width='1'>&nbsp;";
172     }
174     /* Add snapshot icons, if we are allowed to write and create the complete fai module ($ui->has_complete_category_acls) */ 
175     if(preg_match("/(c.*w|w.*c)/",$acl_all)){ 
176       $listhead .= $this->get_snapshot_header($this->selectedBase);
177     }
179     /* Add copy & paste icons, currently disabled, this ability is not implemeneted yet */
180     if(preg_match("/(c.*w|w.*c)/",$acl_all) &&  isset($this->parent->CopyPasteHandler) && $this->parent->CopyPasteHandler){
181       $Copy_Paste = $this->parent->CopyPasteHandler->generatePasteIcon();
182     }
184     /* Append create icons for each fai component */
185     $arr = array(
186         array("images/fai_new_partitionTable.png" , _("New partition table")  ,"Create_partition" , _("PT") , "faiPartitionTable"),
187         array("images/fai_new_script.png"         , _("New scripts")          ,"Create_script"    , _("S")  , "faiScript"),
188         array("images/fai_new_hook.png"           , _("New hooks")            ,"Create_hook"      , _("H")  , "faiHook"),
189         array("images/fai_new_variable.png"       , _("New variables")        ,"Create_variable"  , _("V")  , "faiVariable"),
190         array("images/fai_new_template.png"       , _("New templates ")       ,"Create_template"  , _("I")  , "faiTemplate"),
191         array("images/fai_new_packages.png"       , _("New package list")     ,"Create_package"   , _("PK") , "faiPackage"));
193     foreach($arr as $ar){
194       $acl = $ui->get_permissions($this->selectedBase,"fai/".$ar[4]);
195       if(preg_match("/c/",$acl)){
196         $add_sep = true;
197         $listhead .=" <input class='center' type='image' src='".$ar[0]."' align='middle' title='".$ar[1]."' name='".$ar[2]."' alt='".$ar[3]."'>&nbsp;";
198       }
199     }
201     /* Add additional seperator */
202     if($add_sep){
203       $listhead .=" <img class='center' src='images/list_seperator.png' align='middle' alt='' height='16' width='1'>&nbsp;";
204     }
205   
206     $listhead .=  _("Base")."&nbsp;<select name='CurrentMainBase' onChange='mainform.submit()' class='center'>$options</select>".
207                   " <input class='center' type='image' src='images/list_submit.png' align='middle' 
208                   title='"._("Submit department")."' name='submit_department' alt='".  _("Submit")."'>&nbsp;";
210     /* Multiple options */
211     $listhead .= "&nbsp;<input class='center' type='image' align='middle' src='images/edittrash.png'
212         title='"._("Remove selected fai objects")."' alt='"._("Remove fai objects")."' name='remove_multiple_fai_objects'>&nbsp;";
214     /* Add multiple copy & cut icons */
215     if(is_object($this->parent->CopyPasteHandler)){
216       $listhead .= "&nbsp;<input class='center' type='image' align='middle' src='images/editcopy.png'
217         title='"._("Copy selected objects")."' alt='"._("Copy fai objects")."' name='multiple_copy_fai'>&nbsp;";
218       $listhead .= "&nbsp;<input class='center' type='image' align='middle' src='images/editcut.png'
219         title='"._("cut selected objects")."' alt='"._("Cut fai objects")."' name='multiple_cut_fai'>&nbsp;";
220       $listhead .= "</div>";
221     }
223     $listhead .="</div>";;
226     $this->SetListHeader($listhead);
227   }
229   /* so some basic settings */
230   function execute()
231   {
232     $this->ClearElementsList();
233     $this->GenHeader();
234     $this->AvailableBranches = $this->parent->getBranches();
235   }
237   function setEntries($list)
238   {
239     /********************
240       Variable init
241      ********************/
243      $objects = array(
244            "FAIpartitionTable"  => array("IMG"=> "images/fai_partitionTable.png", "NAME"=>"Partition table","KZL"=> "PT", "VAR"=>"ShowPartitions"),
245            "FAIpackageList"     => array("IMG"=> "images/fai_packages.png",       "NAME"=>"Package list" ,  "KZL"=> "PL", "VAR"=>"ShowPackages"),
246            "FAIscript"          => array("IMG"=> "images/fai_script.png",         "NAME"=>"Scripts" ,       "KZL"=> "S",  "VAR"=>"ShowScripts"),
247            "FAIvariable"        => array("IMG"=> "images/fai_variable.png",       "NAME"=>"Variables" ,     "KZL"=> "V",  "VAR"=>"ShowVariables"),
248            "FAIhook"            => array("IMG"=> "images/fai_hook.png",           "NAME"=>"Hooks",          "KZL"=> "H",  "VAR"=>"ShowHooks"),
249            "FAIprofile"         => array("IMG"=> "images/fai_profile.png",        "NAME"=>"Profile" ,       "KZL"=> "P",  "VAR"=>"ShowProfiles"),
250            "FAItemplate"        => array("IMG"=> "images/fai_template.png",       "NAME"=>"Templates" ,     "KZL"=> "T",  "VAR"=>"ShowTemplates"));
252     $editlink ="<a href='?plug=".$_GET['plug']."&amp;edit_entry=%KEY%' title='%TITLE%'>%NAME%</a>";
254     /* Dynamic action col, depending on snapshot icons */
255     $action_col_size = 50;
256     if($this->parent->snapshotEnabled()){
257       $action_col_size += 20;
258     }
260     /********************
261       Attach objects
262      ********************/
264      foreach($list as $key => $value){
265        $info     = "";
266        $img      = "";
267        $type     = $value['type'];
268        $abort    =false;
270        if(isset($objects[$type])){
271          $img   = "<img class='center' src='".$objects[$type]['IMG']."' title='".$objects[$type]['NAME']."' alt='".$objects[$type]['KZL']."'>";
272          $info  = $objects[$type]['NAME'];
273          $var   = $objects[$type]['VAR'];
274        }else{
275          $img   = "<img class='center' src='images/empty.png' alt=''>";
276          $info  = "";
277          $var   = "";
278        }
280        if((isset($value['description']))&&(!empty($value['description']))){
281          $desc= " [".$value['description']."]";
282        }else{
283          $desc= "";
284        }
287        if($value['FAIstate'] == "freeze"){
288          $action=  "<img src='images/closedlock.png' alt='F' class='center'><img src='images/empty.png' width='38' height='2' class='center' alt=''>";
289          $action.= "<input class='center' type='image' src='images/edit.png'  alt='"._("edit")."'
290            name='entry_edit_%KEY%' title='"._("Edit class")."'>";
291        }else{
292          $action= "<input class='center' type='image' src='images/edit.png'  alt='"._("edit")."'
293            name='entry_edit_%KEY%' title='"._("Edit class")."'>";
295          if(preg_match("/(c&w)/",$value['acl'])){
296            $action.= $this->GetSnapShotActions($value['dn']);;
297          }
299          if(preg_match("/d/",$value['acl'])){
300            $action.= "<input class='center' type='image' src='images/edittrash.png' alt='"._("delete")."'
301              name='entry_delete_%KEY%' title='"._("Delete class")."'>";
302          }
303        }
305        $edi = $editlink;
306        $acti = $action;
308        /* Create each field */
309        $field0 = array("string" => "<input type='checkbox' id='item_selected_".$key."' name='item_selected_".$key."'>" ,
310            "attach" => "style='width:20px;'");
311        $field1 = array("string" => $img , "attach" => "style='text-align:center;width:20px;'");
312        $field2 = array("string" => preg_replace(array("/%KEY%/","/%NAME%/","/%TITLE%/"),array($key,$value['cn'].$desc,preg_replace('/ /', '&nbsp;', @LDAP::fix($value['dn']))),$edi) , "attach" => "style=''");
313        $field3 = array("string" => $info, "attach" => "style='width:200px;'");
314        $field4 = array("string" => preg_replace("/%KEY%/",$key,$acti) , "attach" => "style='width:".$action_col_size."px;border-right:0px;text-align:right;'");
315        $this->AddElement(array($field0,$field1,$field2,$field3,$field4));
316      }
317   }
319   function Save()
320   {
321     MultiSelectWindow::Save();  
322   }
324   function save_object()
325   {
326     /* Save automatic created POSTs like regex, checkboxes */
327     MultiSelectWindow::save_object(); 
328     $_SESSION['faifilter']['branch'] = $this->selectedBranch; 
329   }
331 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
332 ?>