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