b15485c82dc890e3d8dd540711496e1f7d38e1c1
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");
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);
52 /* Disable buttonsm */
53 $this->EnableCloseButton(false);
54 $this->EnableSaveButton (false);
56 /* Dynamic action col, depending on snapshot icons */
57 $action_col_size = 80;
58 # if($this->parent->snapshotEnabled()){
59 # $action_col_size += 32;
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" => " ", "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"), _("Search in subtrees"), false);
85 /* Name ,Text ,Default , Connect with alphabet */
86 $this->AddRegex ("Regex", _("Display users matching"),"*" , true);
87 }
89 function AddUserBoxToFilter($position)
90 {
91 $str = "";
92 if($position == 2){
94 /* Check if there are post commands available for fai management.
95 * If not, grey out freeze/branch and release remove buttons.
96 */
97 $r = $this->config->search("faiManagement", "POSTREMOVE",array('menu','tabs'));
98 $c = $this->config->search("faiManagement", "POSTCREATE",array('menu','tabs'));
100 $smarty = get_smarty();
101 $smarty->assign("allow_create", $c);
102 $smarty->assign("allow_remove", $r);
103 $smarty->assign("selectedBranch",$this->selectedBranch);
104 $smarty->assign("branchimage","images/branch.png");
105 $smarty->assign("branches",$this->AvailableBranches);
106 $plug_id = 0;
107 if(isset($_GET['plug'])){
108 $plug_id = $_GET['plug'];
109 }
110 $smarty->assign("plug_id",$plug_id);
111 $str = $smarty->fetch(get_template_path('branch_selector.tpl', TRUE));
112 }
113 return($str);
114 }
116 function GenHeader()
117 {
118 /* Prepare departments,
119 which are shown in the listbox on top of the listbox
120 */
121 $options= "";
123 /* Get all departments within this subtree */
124 $ui= get_userinfo();
125 $first = "";
126 $found = FALSE;
127 $base = $this->config->current['BASE'];
129 /* Add base */
130 $tmp = array();
131 $tmp[] = array("dn"=>$this->config->current['BASE']);
132 $tmp= array_merge($tmp,get_list("(&(|(ou=*)(description=*))(objectClass=gosaDepartment))", $this->module, $base,
133 array("ou", "description"), GL_SIZELIMIT | GL_SUBSEARCH));
135 $deps = array();
136 foreach($tmp as $tm){
137 $deps[$tm['dn']] = $tm['dn'];
138 }
140 /* Load possible departments */
141 $ui= get_userinfo();
142 $tdeps= $ui->get_module_departments("fai");
143 $ids = $this->config->idepartments;
144 $first = "";
145 $found = FALSE;
146 foreach($ids as $dep => $name){
147 if(isset($deps[$dep]) && in_array_ics($dep, $tdeps)){
149 /* Keep first base dn in mind, we could need this
150 * info if no valid base was found
151 */
152 if(empty($first)) {
153 $first = $dep['dn'];
154 }
156 $value = $ids[$dep];
157 if ($this->selectedBase == $dep){
158 $found = TRUE;
159 $options.= "<option selected='selected' value='".$dep."'>$value</option>";
160 } else {
161 $options.= "<option value='".$dep."'>$value</option>";
162 }
163 }
164 }
166 /* The currently used base is not visible with your acl setup.
167 * Set base to first useable base.
168 */
169 if(!$found){
170 $this->selectedBase = $first;
171 }
173 /* Add seperator */
174 $add_sep = false;
176 /* Get complete fai acls, to be able to check if we must show or hide the snapshot abilities */
177 $acl_all = $ui->has_complete_category_acls($this->selectedBase,$this->module);
179 /* Add default header */
180 $listhead = MultiSelectWindow::get_default_header();
182 /* Add additional seperator */
183 if($add_sep){
184 $listhead .=" <img class='center' src='images/list_seperator.png' align='middle' alt='' height='16' width='1'> ";
185 }
187 $listhead .= _("Base")." <select name='CurrentMainBase' onChange='mainform.submit()' class='center'>$options</select>".
188 " <input class='center' type='image' src='images/list_submit.png' align='middle'
189 title='"._("Submit department")."' name='submit_department' alt='". _("Submit")."'> ";
192 $s = ".|"._("Actions")."|\n";
193 $s .= "..|<img src='images/list_new.png' alt='' border='0' class='center'>".
194 " "._("Create")."|\n";
196 $acl = $ui->get_permissions($this->selectedBase,"fai/faiProfile");
197 if(preg_match("/c/",$acl)){
198 $s.= "...|<input class='center' type='image' src='images/fai_new_profile.png' alt=''>".
199 " "._("Profile")."|Create_profile|\n";
200 }
202 /* Append create icons for each fai component */
203 $arr = array(
204 array("images/fai_new_partitionTable.png" , _("Partition table") ,"Create_partition" , _("PT") , "faiPartitionTable"),
205 array("images/fai_new_script.png" , _("Scripts") ,"Create_script" , _("S") , "faiScript"),
206 array("images/fai_new_hook.png" , _("Hooks") ,"Create_hook" , _("H") , "faiHook"),
207 array("images/fai_new_variable.png" , _("Variables") ,"Create_variable" , _("V") , "faiVariable"),
208 array("images/fai_new_template.png" , _("Templates ") ,"Create_template" , _("I") , "faiTemplate"),
209 array("images/fai_new_packages.png" , _("Package list") ,"Create_package" , _("PK") , "faiPackage"));
211 foreach($arr as $ar){
212 $acl = $ui->get_permissions($this->selectedBase,"fai/".$ar[4]);
213 if(preg_match("/c/",$acl)){
214 $s.= "...|<input class='center' type='image' src='".$ar[0]."' alt=''>".
215 " ".$ar[1]."|".$ar[2]."|\n";
216 }
217 }
219 /* Multiple options */
220 $s.= "..|<img src='images/edittrash.png' alt='' border='0' class='center'>".
221 " "._("Remove")."|"."remove_multiple|\n";
223 /* Add multiple copy & cut icons */
224 if(is_object($this->parent->CopyPasteHandler)){
225 $s.= "..|---|\n";
226 $s.= "..|<img src='images/editcopy.png' alt='' border='0' class='center'>".
227 " "._("Copy")."|"."multiple_copy_systems|\n";
228 $s.= "..|<img src='images/editcut.png' alt='' border='0' class='center'>".
229 " "._("Cut")."|"."multiple_cut_systems|\n";
230 }
232 /* Add copy & paste icons, currently disabled, this ability is not implemeneted yet */
233 if(preg_match("/(c.*w|w.*c)/",$acl_all) && isset($this->parent->CopyPasteHandler) && $this->parent->CopyPasteHandler){
234 $s .= "..|---|\n";
235 if($this->parent->CopyPasteHandler->entries_queued()){
236 $img = "<img border='0' class='center' src='images/editpaste.png' alt=''>";
237 $s.="..|".$img." "._("Paste")."|editPaste|\n";
238 }else{
239 $img = "<img border='0' class='center' src='images/cant_editpaste.png' alt=''>";
240 $s.="..|".$img." "._("Paste")."\n";
241 }
242 }
244 # /* Add snapshot icons, if we are allowed to write and create the complete fai module ($ui->has_complete_category_acls) */
245 # if(preg_match("/(c.*w|w.*c)/",$acl_all)){
246 # if($this->parent->snapshotEnabled()){
247 # $s .= "..|---|\n";
248 # $s .= $this->get_snapshot_header(TRUE);
249 # }
250 # }
252 $this->SetDropDownHeaderMenu($s);
253 $this->SetListHeader($listhead);
254 }
256 /* so some basic settings */
257 function execute()
258 {
259 $this->ClearElementsList();
260 $this->GenHeader();
261 $this->AvailableBranches = $this->parent->getBranches();
262 }
264 function setEntries($list)
265 {
266 /********************
267 Variable init
268 ********************/
270 $objects = array(
271 "FAIpartitionTable" => array("IMG"=> "images/fai_partitionTable.png", "NAME"=>_("Partition table"),"KZL"=> "PT", "VAR"=>"ShowPartitions"),
272 "FAIpackageList" => array("IMG"=> "images/fai_packages.png", "NAME"=>_("Package list") , "KZL"=> "PL", "VAR"=>"ShowPackages"),
273 "FAIscript" => array("IMG"=> "images/fai_script.png", "NAME"=>_("Scripts") , "KZL"=> "S", "VAR"=>"ShowScripts"),
274 "FAIvariable" => array("IMG"=> "images/fai_variable.png", "NAME"=>_("Variables") , "KZL"=> "V", "VAR"=>"ShowVariables"),
275 "FAIhook" => array("IMG"=> "images/fai_hook.png", "NAME"=>_("Hooks"), "KZL"=> "H", "VAR"=>"ShowHooks"),
276 "FAIprofile" => array("IMG"=> "images/fai_profile.png", "NAME"=>_("Profile") , "KZL"=> "P", "VAR"=>"ShowProfiles"),
277 "FAItemplate" => array("IMG"=> "images/fai_template.png", "NAME"=>_("Templates") , "KZL"=> "T", "VAR"=>"ShowTemplates"));
279 $editlink ="<a href='?plug=".$_GET['plug']."&edit_entry=%KEY%' title='%TITLE%'>%NAME%</a>";
281 /* Dynamic action col, depending on snapshot icons */
282 $action_col_size = 80;
283 # if($this->parent->snapshotEnabled()){
284 # $action_col_size += 32;
285 # }
287 /********************
288 Attach objects
289 ********************/
291 $cnts = array();
292 foreach($objects as $key => $data){
293 $cnts[$key] = 0;
294 }
296 foreach($list as $key => $value){
297 $info = "";
298 $img = "";
299 $type = $value['type'];
300 $abort =false;
302 $cnts[$type] ++;
304 if(isset($objects[$type])){
305 $img = "<img class='center' src='".$objects[$type]['IMG']."' title='".$objects[$type]['NAME']."' alt='".$objects[$type]['KZL']."'>";
306 $info = $objects[$type]['NAME'];
307 $var = $objects[$type]['VAR'];
308 }else{
309 $img = "<img class='center' src='images/empty.png' alt=''>";
310 $info = "";
311 $var = "";
312 }
314 if((isset($value['description']))&&(!empty($value['description']))){
315 $desc= " [".$value['description']."]";
316 }else{
317 $desc= "";
318 }
320 /* Add copy & cut icons */
321 $ui = get_userinfo();
322 $action ="";
323 $acl_all = $ui->has_complete_category_acls($this->selectedBase,$this->module);
324 if(preg_match("/(c.*w|w.*c)/",$acl_all) && $this->parent->CopyPasteHandler){
325 $action .= "<input class='center' type='image'
326 src='images/editcut.png' alt='"._("cut")."' name='cut_%KEY%' title='"._("Cut this entry")."'> ";
327 $action.= "<input class='center' type='image'
328 src='images/editcopy.png' alt='"._("copy")."' name='copy_%KEY%' title='"._("Copy this entry")."'> ";
329 }
331 if($value['FAIstate'] == "freeze"){
332 $action.= "<img src='images/closedlock.png' alt='F' class='center'><img src='images/empty.png' width='38' height='2' class='center' alt=''>";
333 $action.= "<input class='center' type='image' src='images/edit.png' alt='"._("edit")."'
334 name='entry_edit_%KEY%' title='"._("Edit class")."'>";
335 }else{
336 $action.= "<input class='center' type='image' src='images/edit.png' alt='"._("edit")."'
337 name='entry_edit_%KEY%' title='"._("Edit class")."'>";
339 # if(preg_match("/(c)/",$value['acl']) && preg_match("/(w)/",$value['acl'])){
340 # $action.= $this->GetSnapShotActions($value['dn']);;
341 # }
343 if(preg_match("/d/",$value['acl'])){
344 $action.= "<input class='center' type='image' src='images/edittrash.png' alt='"._("delete")."'
345 name='entry_delete_%KEY%' title='"._("Delete class")."'>";
346 }
347 }
349 /* Cutted objects should be displayed in light grey */
350 $display = $value['cn'].$desc;
351 if($this->parent->CopyPasteHandler){
352 foreach($this->parent->CopyPasteHandler->queue as $queue_key => $queue_data){
353 if($queue_data['dn'] == $value['dn']) {
354 $display = "<font color='#999999'>".$display."</font>";
355 break;
356 }
357 }
358 }
359 $edi = $editlink;
360 $acti = $action;
362 /* Create each field */
363 $field0 = array("string" => "<input type='checkbox' id='item_selected_".$key."' name='item_selected_".$key."'>" ,
364 "attach" => "style='width:20px;'");
365 $field1 = array("string" => $img , "attach" => "style='text-align:center;width:20px;'");
366 $field2 = array("string" => preg_replace(array("/%KEY%/","/%NAME%/","/%TITLE%/"),array($key,$display,preg_replace('/ /', ' ', @LDAP::fix($value['dn']))),$edi) , "attach" => "style=''");
367 $field3 = array("string" => $info, "attach" => "style='width:200px;'");
368 $field4 = array("string" => preg_replace("/%KEY%/",$key,$acti) , "attach" => "style='width:".$action_col_size."px;border-right:0px;text-align:right;'");
369 $this->AddElement(array($field0,$field1,$field2,$field3,$field4));
370 }
372 /* Create summary string for list footer */
373 $num_deps=0;
374 if(!$this->SubSearch){
375 $num_deps = count($this->Added_Departments);
376 }
378 $profile_str = _("Number of listed profiles");
379 $partition_str = _("Number of listed partitions");
380 $script_str = _("Number of listed scripts");
381 $hook_str = _("Number of listed hooks");
382 $variable_str = _("Number of listed variables");
383 $template_str = _("Number of listed templates");
384 $package_str = _("Number of listed packages");
385 $dep_str = _("Number of listed departments");
387 $str = "<img class='center' src='".$objects['FAIprofile']['IMG']."'
388 title='".$profile_str."' alt='".$profile_str."'> ".$cnts['FAIprofile']." ";
389 $str.= "<img class='center' src='".$objects['FAIpartitionTable']['IMG']."'
390 title='".$partition_str."' alt='".$partition_str."'> ".$cnts['FAIpartitionTable']." ";
391 $str.= "<img class='center' src='".$objects['FAIscript']['IMG']."'
392 title='".$script_str."' alt='".$script_str."'> ".$cnts['FAIscript']." ";
393 $str.= "<img class='center' src='".$objects['FAIhook']['IMG']."'
394 title='".$hook_str."' alt='".$hook_str."'> ".$cnts['FAIhook']." ";
395 $str.= "<img class='center' src='".$objects['FAIvariable']['IMG']."'
396 title='".$variable_str."' alt='".$variable_str."'> ".$cnts['FAIvariable']." ";
397 $str.= "<img class='center' src='".$objects['FAItemplate']['IMG']."'
398 title='".$template_str."' alt='".$template_str."'> ".$cnts['FAItemplate']." ";
399 $str.= "<img class='center' src='".$objects['FAIpackageList']['IMG']."'
400 title='".$package_str."' alt='".$package_str."'> ".$cnts['FAIpackageList']." ";
401 $str.= "<img class='center' src='images/folder.png'
402 title='".$dep_str."' alt='".$dep_str."'> ".$num_deps." ";
403 $this->set_List_Bottom_Info($str);
404 }
406 function Save()
407 {
408 MultiSelectWindow::Save();
409 }
411 function save_object()
412 {
413 /* Save automatic created POSTs like regex, checkboxes */
414 MultiSelectWindow::save_object();
415 $_SESSION['faifilter']['branch'] = $this->selectedBranch;
416 }
417 }
418 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
419 ?>