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 = 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" => " ", "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 = ("" != search_config($this->config->data,"faiManagement","POSTREMOVE"));
98 $c = ("" != search_config($this->config->data,"faiManagement","POSTCREATE"));
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 $str = $smarty->fetch(get_template_path('branch_selector.tpl', TRUE));
107 }
108 return($str);
109 }
111 function GenHeader()
112 {
113 /* Prepare departments,
114 which are shown in the listbox on top of the listbox
115 */
116 $options= "";
118 /* Get all departments within this subtree */
119 $ui= get_userinfo();
120 $first = "";
121 $found = FALSE;
122 $base = $this->config->current['BASE'];
124 /* Add base */
125 $tmp = array();
126 $tmp[] = array("dn"=>$this->config->current['BASE']);
127 $tmp= array_merge($tmp,get_list("(&(|(ou=*)(description=*))(objectClass=gosaDepartment))", $this->module, $base,
128 array("ou", "description"), GL_SIZELIMIT | GL_SUBSEARCH));
130 $deps = array();
131 foreach($tmp as $tm){
132 $deps[$tm['dn']] = $tm['dn'];
133 }
135 /* Load possible departments */
136 $ui= get_userinfo();
137 $tdeps= $ui->get_module_departments("fai");
138 $ids = $this->config->idepartments;
139 $first = "";
140 $found = FALSE;
141 foreach($ids as $dep => $name){
142 if(isset($deps[$dep]) && in_array_ics($dep, $tdeps)){
144 /* Keep first base dn in mind, we could need this
145 * info if no valid base was found
146 */
147 if(empty($first)) {
148 $first = $dep['dn'];
149 }
151 $value = $ids[$dep];
152 if ($this->selectedBase == $dep){
153 $found = TRUE;
154 $options.= "<option selected='selected' value='".$dep."'>$value</option>";
155 } else {
156 $options.= "<option value='".$dep."'>$value</option>";
157 }
158 }
159 }
161 /* The currently used base is not visible with your acl setup.
162 * Set base to first useable base.
163 */
164 if(!$found){
165 $this->selectedBase = $first;
166 }
168 /* Add seperator */
169 $add_sep = false;
171 /* Get complete fai acls, to be able to check if we must show or hide the snapshot abilities */
172 $acl_all = $ui->has_complete_category_acls($this->selectedBase,$this->module);
174 /* Add default header */
175 $listhead = MultiSelectWindow::get_default_header();
177 $acl = $ui->get_permissions($this->selectedBase,"fai/faiProfile");
178 if(preg_match("/c/",$acl)){
179 $listhead .=" <input class='center' type='image' src='images/fai_new_profile.png' align='middle'
180 title='"._("New profile")."' name='Create_profile' alt='"._("P")."'> ";
181 $listhead .=" <img class='center' src='images/list_seperator.png' align='middle' alt='' height='16' width='1'> ";
182 }
184 /* Add snapshot icons, if we are allowed to write and create the complete fai module ($ui->has_complete_category_acls) */
185 if(preg_match("/(c.*w|w.*c)/",$acl_all)){
186 $listhead .= $this->get_snapshot_header($this->selectedBase);
187 }
189 /* Add copy & paste icons, currently disabled, this ability is not implemeneted yet */
190 if(preg_match("/(c.*w|w.*c)/",$acl_all) && isset($this->parent->CopyPasteHandler) && $this->parent->CopyPasteHandler){
191 $Copy_Paste = $this->parent->CopyPasteHandler->generatePasteIcon();
192 }
194 /* Append create icons for each fai component */
195 $arr = array(
196 array("images/fai_new_partitionTable.png" , _("New partition table") ,"Create_partition" , _("PT") , "faiPartitionTable"),
197 array("images/fai_new_script.png" , _("New scripts") ,"Create_script" , _("S") , "faiScript"),
198 array("images/fai_new_hook.png" , _("New hooks") ,"Create_hook" , _("H") , "faiHook"),
199 array("images/fai_new_variable.png" , _("New variables") ,"Create_variable" , _("V") , "faiVariable"),
200 array("images/fai_new_template.png" , _("New templates ") ,"Create_template" , _("I") , "faiTemplate"),
201 array("images/fai_new_packages.png" , _("New package list") ,"Create_package" , _("PK") , "faiPackage"));
203 foreach($arr as $ar){
204 $acl = $ui->get_permissions($this->selectedBase,"fai/".$ar[4]);
205 if(preg_match("/c/",$acl)){
206 $add_sep = true;
207 $listhead .=" <input class='center' type='image' src='".$ar[0]."' align='middle' title='".$ar[1]."' name='".$ar[2]."' alt='".$ar[3]."'> ";
208 }
209 }
211 /* Add additional seperator */
212 if($add_sep){
213 $listhead .=" <img class='center' src='images/list_seperator.png' align='middle' alt='' height='16' width='1'> ";
214 }
216 $listhead .= _("Base")." <select name='CurrentMainBase' onChange='mainform.submit()' class='center'>$options</select>".
217 " <input class='center' type='image' src='images/list_submit.png' align='middle'
218 title='"._("Submit department")."' name='submit_department' alt='". _("Submit")."'> ";
220 /* Multiple options */
221 $listhead .= " <input class='center' type='image' align='middle' src='images/edittrash.png'
222 title='"._("Remove selected fai objects")."' alt='"._("Remove fai objects")."' name='remove_multiple_fai_objects'> ";
224 /* Add multiple copy & cut icons */
225 if(is_object($this->parent->CopyPasteHandler)){
226 $listhead .= " <input class='center' type='image' align='middle' src='images/editcopy.png'
227 title='"._("Copy selected objects")."' alt='"._("Copy fai objects")."' name='multiple_copy_fai'> ";
228 $listhead .= " <input class='center' type='image' align='middle' src='images/editcut.png'
229 title='"._("cut selected objects")."' alt='"._("Cut fai objects")."' name='multiple_cut_fai'> ";
230 $listhead .= "</div>";
231 }
233 $listhead .="</div>";;
236 $this->SetListHeader($listhead);
237 }
239 /* so some basic settings */
240 function execute()
241 {
242 $this->ClearElementsList();
243 $this->GenHeader();
244 $this->AvailableBranches = $this->parent->getBranches();
245 }
247 function setEntries($list)
248 {
249 /********************
250 Variable init
251 ********************/
253 $objects = array(
254 "FAIpartitionTable" => array("IMG"=> "images/fai_partitionTable.png", "NAME"=>"Partition table","KZL"=> "PT", "VAR"=>"ShowPartitions"),
255 "FAIpackageList" => array("IMG"=> "images/fai_packages.png", "NAME"=>"Package list" , "KZL"=> "PL", "VAR"=>"ShowPackages"),
256 "FAIscript" => array("IMG"=> "images/fai_script.png", "NAME"=>"Scripts" , "KZL"=> "S", "VAR"=>"ShowScripts"),
257 "FAIvariable" => array("IMG"=> "images/fai_variable.png", "NAME"=>"Variables" , "KZL"=> "V", "VAR"=>"ShowVariables"),
258 "FAIhook" => array("IMG"=> "images/fai_hook.png", "NAME"=>"Hooks", "KZL"=> "H", "VAR"=>"ShowHooks"),
259 "FAIprofile" => array("IMG"=> "images/fai_profile.png", "NAME"=>"Profile" , "KZL"=> "P", "VAR"=>"ShowProfiles"),
260 "FAItemplate" => array("IMG"=> "images/fai_template.png", "NAME"=>"Templates" , "KZL"=> "T", "VAR"=>"ShowTemplates"));
262 $editlink ="<a href='?plug=".$_GET['plug']."&edit_entry=%KEY%' title='%TITLE%'>%NAME%</a>";
264 /* Dynamic action col, depending on snapshot icons */
265 $action_col_size = 50;
266 if($this->parent->snapshotEnabled()){
267 $action_col_size += 20;
268 }
270 /********************
271 Attach objects
272 ********************/
274 $cnts = array();
275 foreach($objects as $key => $data){
276 $cnts[$key] = 0;
277 }
279 foreach($list as $key => $value){
280 $info = "";
281 $img = "";
282 $type = $value['type'];
283 $abort =false;
285 $cnts[$type] ++;
287 if(isset($objects[$type])){
288 $img = "<img class='center' src='".$objects[$type]['IMG']."' title='".$objects[$type]['NAME']."' alt='".$objects[$type]['KZL']."'>";
289 $info = $objects[$type]['NAME'];
290 $var = $objects[$type]['VAR'];
291 }else{
292 $img = "<img class='center' src='images/empty.png' alt=''>";
293 $info = "";
294 $var = "";
295 }
297 if((isset($value['description']))&&(!empty($value['description']))){
298 $desc= " [".$value['description']."]";
299 }else{
300 $desc= "";
301 }
304 if($value['FAIstate'] == "freeze"){
305 $action= "<img src='images/closedlock.png' alt='F' class='center'><img src='images/empty.png' width='38' height='2' class='center' alt=''>";
306 $action.= "<input class='center' type='image' src='images/edit.png' alt='"._("edit")."'
307 name='entry_edit_%KEY%' title='"._("Edit class")."'>";
308 }else{
309 $action= "<input class='center' type='image' src='images/edit.png' alt='"._("edit")."'
310 name='entry_edit_%KEY%' title='"._("Edit class")."'>";
312 if(preg_match("/(c&w)/",$value['acl'])){
313 $action.= $this->GetSnapShotActions($value['dn']);;
314 }
316 if(preg_match("/d/",$value['acl'])){
317 $action.= "<input class='center' type='image' src='images/edittrash.png' alt='"._("delete")."'
318 name='entry_delete_%KEY%' title='"._("Delete class")."'>";
319 }
320 }
322 $edi = $editlink;
323 $acti = $action;
325 /* Cutted objects should be displayed in light grey */
326 $display = $value['cn'].$desc;
327 if($this->parent->CopyPasteHandler){
328 foreach($this->parent->CopyPasteHandler->queue as $queue_key => $queue_data){
329 if($queue_data['dn'] == $value['dn']) {
330 $display = "<font color='#999999'>".$display."</font>";
331 break;
332 }
333 }
334 }
336 /* Create each field */
337 $field0 = array("string" => "<input type='checkbox' id='item_selected_".$key."' name='item_selected_".$key."'>" ,
338 "attach" => "style='width:20px;'");
339 $field1 = array("string" => $img , "attach" => "style='text-align:center;width:20px;'");
340 $field2 = array("string" => preg_replace(array("/%KEY%/","/%NAME%/","/%TITLE%/"),array($key,$display,preg_replace('/ /', ' ', @LDAP::fix($value['dn']))),$edi) , "attach" => "style=''");
341 $field3 = array("string" => $info, "attach" => "style='width:200px;'");
342 $field4 = array("string" => preg_replace("/%KEY%/",$key,$acti) , "attach" => "style='width:".$action_col_size."px;border-right:0px;text-align:right;'");
343 $this->AddElement(array($field0,$field1,$field2,$field3,$field4));
344 }
346 /* Create summary string for list footer */
347 $num_deps=0;
348 if(!$this->SubSearch){
349 $num_deps = count($this->Added_Departments);
350 }
352 $profile_str = _("Number of listed profiles");
353 $partition_str = _("Number of listed partitions");
354 $script_str = _("Number of listed scripts");
355 $hook_str = _("Number of listed hooks");
356 $variable_str = _("Number of listed variables");
357 $template_str = _("Number of listed templates");
358 $package_str = _("Number of listed packages");
359 $dep_str = _("Number of listed departments");
361 $str = "<img class='center' src='".$objects['FAIprofile']['IMG']."'
362 title='".$profile_str."' alt='".$profile_str."'> ".$cnts['FAIprofile']." ";
363 $str.= "<img class='center' src='".$objects['FAIpartitionTable']['IMG']."'
364 title='".$partition_str."' alt='".$partition_str."'> ".$cnts['FAIpartitionTable']." ";
365 $str.= "<img class='center' src='".$objects['FAIscript']['IMG']."'
366 title='".$script_str."' alt='".$script_str."'> ".$cnts['FAIscript']." ";
367 $str.= "<img class='center' src='".$objects['FAIhook']['IMG']."'
368 title='".$hook_str."' alt='".$hook_str."'> ".$cnts['FAIhook']." ";
369 $str.= "<img class='center' src='".$objects['FAIvariable']['IMG']."'
370 title='".$variable_str."' alt='".$variable_str."'> ".$cnts['FAIvariable']." ";
371 $str.= "<img class='center' src='".$objects['FAItemplate']['IMG']."'
372 title='".$template_str."' alt='".$template_str."'> ".$cnts['FAItemplate']." ";
373 $str.= "<img class='center' src='".$objects['FAIpackageList']['IMG']."'
374 title='".$package_str."' alt='".$package_str."'> ".$cnts['FAIpackageList']." ";
375 $str.= "<img class='center' src='images/folder.png'
376 title='".$dep_str."' alt='".$dep_str."'> ".$num_deps." ";
377 $this->set_List_Bottom_Info($str);
378 }
380 function Save()
381 {
382 MultiSelectWindow::Save();
383 }
385 function save_object()
386 {
387 /* Save automatic created POSTs like regex, checkboxes */
388 MultiSelectWindow::save_object();
389 $_SESSION['faifilter']['branch'] = $this->selectedBranch;
390 }
391 }
392 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
393 ?>