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 classes"));
44 $this->SetSummary(_("List of deployment classes and packages"));
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" => _("Class name"), "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"));
279 /* Dynamic action col, depending on snapshot icons */
280 $action_col_size = 120;
281 # if($this->parent->snapshotEnabled()){
282 # $action_col_size += 32;
283 # }
285 /********************
286 Attach objects
287 ********************/
289 $cnts = array();
290 foreach($objects as $key => $data){
291 $cnts[$key] = 0;
292 }
294 foreach($list as $key => $value){
295 $info = "";
296 $img = "";
297 $type = $value['type'];
298 $abort =false;
300 $cnts[$type] ++;
302 if(isset($objects[$type])){
303 $img = "<img class='center' src='".$objects[$type]['IMG']."' title='".$objects[$type]['NAME']."' alt='".$objects[$type]['KZL']."'>";
304 $info = $objects[$type]['NAME'];
305 $var = $objects[$type]['VAR'];
306 }else{
307 $img = "<img class='center' src='images/empty.png' alt=''>";
308 $info = "";
309 $var = "";
310 }
312 if((isset($value['description']))&&(!empty($value['description']))){
313 $desc= " [".$value['description']."]";
314 }else{
315 $desc= "";
316 }
318 /* Add copy & cut icons */
319 $ui = get_userinfo();
320 $action ="";
321 $acl_all = $ui->has_complete_category_acls($this->selectedBase,$this->module);
322 if(preg_match("/(c.*w|w.*c)/",$acl_all) && $this->parent->CopyPasteHandler){
323 $action .= "<input class='center' type='image'
324 src='images/editcut.png' alt='"._("cut")."' name='cut_%KEY%' title='"._("Cut this entry")."'> ";
325 $action.= "<input class='center' type='image'
326 src='images/editcopy.png' alt='"._("copy")."' name='copy_%KEY%' title='"._("Copy this entry")."'> ";
327 }
329 if(preg_match("/^freeze/", $value['FAIstate'])){
330 $editlink ="<a href='?plug=".$_GET['plug']."&edit_freeze_entry=%KEY%' title='%TITLE%'>%NAME%</a>";
331 $action.= "<input class='center' type='image' src='images/edit.png' alt='"._("edit")."'
332 name='entry_freeze_edit_%KEY%' title='"._("Edit class")."'>";
333 $action.= "<img src='images/closedlock.png' alt='F' class='center'>";
334 }else{
335 $editlink ="<a href='?plug=".$_GET['plug']."&edit_entry=%KEY%' title='%TITLE%'>%NAME%</a>";
336 $action.= "<input class='center' type='image' src='images/edit.png' alt='"._("edit")."'
337 name='entry_edit_%KEY%' title='"._("Edit class")."'>";
338 if(preg_match("/d/",$value['acl'])){
339 $action.= "<input class='center' type='image' src='images/edittrash.png' alt='"._("delete")."'
340 name='entry_delete_%KEY%' title='"._("Delete class")."'>";
341 }
342 }
344 /* Cutted objects should be displayed in light grey */
345 $display = $value['cn'].$desc;
346 if($this->parent->CopyPasteHandler){
347 foreach($this->parent->CopyPasteHandler->queue as $queue_key => $queue_data){
348 if($queue_data['dn'] == $value['dn']) {
349 $display = "<font color='#999999'>".$display."</font>";
350 break;
351 }
352 }
353 }
354 $edi = $editlink;
355 $acti = $action;
357 /* Create each field */
358 $field0 = array("string" => "<input type='checkbox' id='item_selected_".$key."' name='item_selected_".$key."'>" ,
359 "attach" => "style='width:20px;'");
360 $field1 = array("string" => $img , "attach" => "style='text-align:center;width:20px;'");
361 $field2 = array("string" => preg_replace(array("/%KEY%/","/%NAME%/","/%TITLE%/"),array($key,$display,preg_replace('/ /', ' ', @LDAP::fix($value['dn']))),$edi) , "attach" => "style=''");
362 $field3 = array("string" => $info, "attach" => "style='width:200px;'");
363 $field4 = array("string" => preg_replace("/%KEY%/",$key,$acti) , "attach" => "style='width:".$action_col_size."px;border-right:0px;text-align:right;'");
364 $this->AddElement(array($field0,$field1,$field2,$field3,$field4));
365 }
367 /* Create summary string for list footer */
368 $num_deps=0;
369 if(!$this->SubSearch){
370 $num_deps = count($this->Added_Departments);
371 }
373 $profile_str = sprintf(_("Number of listed '%s'"),_("profiles"));
374 $partition_str = sprintf(_("Number of listed '%s'"),_("partitions"));
375 $script_str = sprintf(_("Number of listed '%s'"),_("scripts"));
376 $hook_str = sprintf(_("Number of listed '%s'"),_("hooks"));
377 $variable_str = sprintf(_("Number of listed '%s'"),_("variables"));
378 $template_str = sprintf(_("Number of listed '%s'"),_("templates"));
379 $package_str = sprintf(_("Number of listed '%s'"),_("packages"));
380 $dep_str = sprintf(_("Number of listed '%s'"),_("departments"));
382 $str = "<img class='center' src='".$objects['FAIprofile']['IMG']."'
383 title='".$profile_str."' alt='".$profile_str."'> ".$cnts['FAIprofile']." ";
384 $str.= "<img class='center' src='".$objects['FAIpartitionTable']['IMG']."'
385 title='".$partition_str."' alt='".$partition_str."'> ".$cnts['FAIpartitionTable']." ";
386 $str.= "<img class='center' src='".$objects['FAIscript']['IMG']."'
387 title='".$script_str."' alt='".$script_str."'> ".$cnts['FAIscript']." ";
388 $str.= "<img class='center' src='".$objects['FAIhook']['IMG']."'
389 title='".$hook_str."' alt='".$hook_str."'> ".$cnts['FAIhook']." ";
390 $str.= "<img class='center' src='".$objects['FAIvariable']['IMG']."'
391 title='".$variable_str."' alt='".$variable_str."'> ".$cnts['FAIvariable']." ";
392 $str.= "<img class='center' src='".$objects['FAItemplate']['IMG']."'
393 title='".$template_str."' alt='".$template_str."'> ".$cnts['FAItemplate']." ";
394 $str.= "<img class='center' src='".$objects['FAIpackageList']['IMG']."'
395 title='".$package_str."' alt='".$package_str."'> ".$cnts['FAIpackageList']." ";
396 $str.= "<img class='center' src='images/folder.png'
397 title='".$dep_str."' alt='".$dep_str."'> ".$num_deps." ";
398 $this->set_List_Bottom_Info($str);
399 }
401 function Save()
402 {
403 MultiSelectWindow::Save();
404 }
406 function save_object()
407 {
408 /* Save automatic created POSTs like regex, checkboxes */
409 MultiSelectWindow::save_object();
410 $faifilter = session::get('faifilter');
411 $faifilter['branch'] = $this->selectedBranch;
412 session::set('faifilter',$faifilter);
413 }
414 }
415 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
416 ?>