1 <?php
3 class divListFai extends MultiSelectWindow
4 {
5 /* Regex */
6 var $Regex = "*";
7 var $ShowProfiles;
8 var $ShowTemplates;
9 var $ShowScripts;
10 var $ShowHooks;
11 var $ShowVariables;
12 var $ShowPackages;
13 var $ShowPartitions;
15 /* Subsearch checkbox */
16 var $SubSearch;
18 var $parent ;
19 var $ui ;
21 var $ShowOpsiLocal;
22 var $ShowOpsiNetboot;
24 function divListFai (&$config,$parent)
25 {
26 MultiSelectWindow::MultiSelectWindow($config, "Fai", "fai");
28 $this->parent = $parent;
29 $this->ui = get_userinfo();
31 /* Set list strings */
32 $this->SetTitle( _("List of classes"));
33 $this->SetSummary(_("List of deployment classes and packages"));
35 /* Result page will look like a headpage */
36 $this->SetHeadpageMode();
38 $this->EnableAplhabet (true);
40 /* Disable buttonsm */
41 $this->EnableCloseButton(false);
42 $this->EnableSaveButton (false);
44 /* Dynamic action col, depending on snapshot icons */
45 $action_col_size = 130;
47 /* Toggle all selected / deselected */
48 $chk = "<input type='checkbox' id='select_all' name='select_all' title='"._("Select all")."'
49 onClick='toggle_all_(\"^item_selected_[0-9]*$\",\"select_all\");' >";
51 /* set Page header */
52 $this->AddHeader(array("string"=> $chk, "attach"=>"style='width:20px;'"));
53 $this->AddHeader(array("string" => " ", "attach" => "style='text-align:center;width:20px;'"));
54 $this->AddHeader(array("string" => _("Class name"), "attach" => "style=''"));
55 $this->AddHeader(array("string" => _("Class type"), "attach" => "style='width:200px;'"));
56 $this->AddHeader(array("string" => _("Actions"), "attach" => "style='width:".$action_col_size."px;border-right:0px;text-align:right;'"));
58 $this->AddCheckBox("ShowProfiles" , sprintf(_("Display objects of type '%s'."),
59 _("Profile")) ,_("Show profiles") ,true);
60 $this->AddCheckBox("ShowTemplates" , sprintf(_("Display objects of type '%s'."),
61 _("Variable")) ,_("Show templates") ,true);
62 $this->AddCheckBox("ShowScripts" , sprintf(_("Display objects of type '%s'."),
63 _("Script")) ,_("Show scripts") ,true);
64 $this->AddCheckBox("ShowHooks" , sprintf(_("Display objects of type '%s'."),
65 _("Hook")) ,_("Show hooks") ,true);
66 $this->AddCheckBox("ShowVariables" , sprintf(_("Display objects of type '%s'."),
67 _("Variable")) ,_("Show variables") ,true);
68 $this->AddCheckBox("ShowPackages" , sprintf(_("Display objects of type '%s'."),
69 _("Package")) ,_("Show packages") ,true);
70 $this->AddCheckBox("ShowPartitions" , sprintf(_("Display objects of type '%s'."),
71 _("Partition")),_("Show partitions") ,true);
73 /* Add opsi checkboxes if opsi is enabled
74 */
75 if($this->parent->opsi instanceof opsi && $this->parent->opsi->enabled()){
76 $this->AddCheckBox("ShowOpsiNetboot" , sprintf(_("Display objects of type '%s'."),
77 _("Opsi netboot product")),_("Show opsi netboot pruducts") ,true);
78 $this->AddCheckBox("ShowOpsiLocal" , sprintf(_("Display objects of type '%s'."),
79 _("Opsi local product")),_("Show opsi locale pruducts") ,true);
80 }
82 /* Add SubSearch checkbox */
83 //$this->AddCheckBox(SEPERATOR);
84 //$this->AddCheckBox("SubSearch", msgPool::selectToView("","subsearch"), msgPool::selectToView("","subsearch_small"), false);
86 /* Name ,Text ,Default , Connect with alphabet */
87 $this->AddRegex ("Regex", _("Display users matching"),"*" , true);
88 }
90 function AddUserBoxToFilter($position)
91 {
92 $str = "";
93 if($position == 2){
95 /* Check if there are post commands available for fai management.
96 * If not, grey out freeze/branch and release remove buttons.
97 */
98 $r = $this->config->search("faiManagement", "POSTREMOVE",array('menu','tabs'));
99 $c = $this->config->search("faiManagement", "POSTCREATE",array('menu','tabs'));
101 $smarty = get_smarty();
102 $releases = $this->parent->getBranches();
104 $smarty->assign("allow_create", $c);
105 $smarty->assign("allow_remove", $r);
106 $smarty->assign("fai_release" , $releases[$this->parent->fai_release]);
107 $smarty->assign("fai_base" , $releases[$this->parent->fai_base]);
108 $smarty->assign("branchimage","plugins/fai/images/branch.png");
109 $smarty->assign("fai_releases", $releases);
110 $plug_id = 0;
111 if(isset($_GET['plug'])){
112 $plug_id = $_GET['plug'];
113 }
114 $smarty->assign("plug_id",$plug_id);
115 $str = $smarty->fetch(get_template_path('branch_selector.tpl', TRUE));
116 }
117 return($str);
118 }
120 function GenHeader()
121 {
122 /* Get all departments within this subtree */
123 $ui= get_userinfo();
124 $first = "";
125 $found = FALSE;
126 $base = $this->config->current['BASE'];
128 /* Add seperator */
129 $add_sep = false;
131 /* Get complete fai acls, to be able to check if we must show or hide the snapshot abilities */
132 $acl_all = $ui->has_complete_category_acls($this->parent->fai_base,$this->module);
134 /* Add default header */
135 $listhead = MultiSelectWindow::get_default_header(false);
137 /* Add additional seperator */
138 if($add_sep){
139 $listhead .=" <img class='center' src='images/lists/seperator.png' align='middle' alt='' height='16' width='1'> ";
140 }
142 $s = ".|"._("Actions")."|\n";
143 $s .= "..|<img src='images/lists/new.png' alt='' border='0' class='center'>".
144 " "._("Create")."|\n";
146 $acl = $ui->get_permissions($this->parent->fai_base,"fai/faiProfile");
147 if($this->parent->lock_type == "freeze" && !$this->parent->allow_freeze_object_attach){
148 $s.= "...|<input class='center' type='image' src='plugins/fai/images/freeze.png' alt=''>".
149 " "._("Freezed")."|\n";
150 }else{
151 if(preg_match("/c/",$acl)){
152 $s.= "...|<input class='center' type='image' src='plugins/fai/images/fai_new_profile.png' alt=''>".
153 " "._("Profile")."|Create_profile|\n";
154 }
156 /* Append create icons for each fai component */
157 $arr = array(
158 array("plugins/fai/images/fai_new_partitionTable.png" , _("Partition table") ,
159 "Create_partition" , _("PT") , "faiPartitionTable"),
160 array("plugins/fai/images/fai_new_script.png" , _("Scripts") ,
161 "Create_script" , _("S") , "faiScript"),
162 array("plugins/fai/images/fai_new_hook.png" , _("Hooks") ,
163 "Create_hook" , _("H") , "faiHook"),
164 array("plugins/fai/images/fai_new_variable.png" , _("Variables") ,
165 "Create_variable" , _("V") , "faiVariable"),
166 array("plugins/fai/images/fai_new_template.png" , _("Templates ") ,
167 "Create_template" , _("I") , "faiTemplate"),
168 array("plugins/fai/images/fai_new_packages.png" , _("Package list") ,
169 "Create_package" , _("PK") , "faiPackage"));
171 foreach($arr as $ar){
172 $acl = $ui->get_permissions($this->parent->fai_base,"fai/".$ar[4]);
173 if(preg_match("/c/",$acl)){
174 $s.= "...|<input class='center' type='image' src='".$ar[0]."' alt=''>".
175 " ".$ar[1]."|".$ar[2]."|\n";
176 }
177 }
178 }
180 /* Multiple options */
181 $s.= "..|<img src='images/lists/trash.png' alt='' border='0' class='center'>".
182 " "._("Remove")."|"."remove_multiple|\n";
185 /* Add Copy & Paste header */
186 $s .= $this->parent->get_copypaste_header($this->selectedBase,$this->module,TRUE,FALSE);
188 # /* Add snapshot icons, if we are allowed to write and create the complete fai module ($ui->has_complete_category_acls) */
189 # $s .= $this->parent->get_snapshot_header($this->selectedBase,$this->module);
191 $this->SetDropDownHeaderMenu($s);
192 $this->SetListHeader($listhead);
193 }
195 /* so some basic settings */
196 function execute()
197 {
198 $this->ClearElementsList();
199 $this->GenHeader();
200 $this->AvailableBranches = $this->parent->getBranches();
201 }
203 function setEntries($list)
204 {
205 /********************
206 Variable init
207 ********************/
209 $objects = array(
210 "FAIpartitionTable" => array("IMG"=> "plugins/fai/images/fai_partitionTable.png",
211 "NAME"=>_("Partition table"),"KZL"=> "PT", "VAR"=>"ShowPartitions"),
212 "FAIpackageList" => array("IMG"=> "plugins/fai/images/fai_packages.png",
213 "NAME"=>_("Package list") , "KZL"=> "PL", "VAR"=>"ShowPackages"),
214 "FAIscript" => array("IMG"=> "plugins/fai/images/fai_script.png",
215 "NAME"=>_("Scripts") , "KZL"=> "S", "VAR"=>"ShowScripts"),
216 "FAIvariable" => array("IMG"=> "plugins/fai/images/fai_variable.png",
217 "NAME"=>_("Variables") , "KZL"=> "V", "VAR"=>"ShowVariables"),
218 "FAIhook" => array("IMG"=> "plugins/fai/images/fai_hook.png",
219 "NAME"=>_("Hooks"), "KZL"=> "H", "VAR"=>"ShowHooks"),
220 "FAIprofile" => array("IMG"=> "plugins/fai/images/fai_profile.png",
221 "NAME"=>_("Profile") , "KZL"=> "P", "VAR"=>"ShowProfiles"),
222 "FAItemplate" => array("IMG"=> "plugins/fai/images/fai_template.png",
223 "NAME"=>_("Templates") , "KZL"=> "T", "VAR"=>"ShowTemplates"),
224 "opsi_netboot" => array("IMG"=> "plugins/opsi/images/netboot_package.png",
225 "NAME"=>_("Opsi netboot package") , "KZL"=> "ON", "VAR"=>"ShowOpsiNetboot"),
226 "opsi_local" => array("IMG"=> "plugins/opsi/images/local_package.png",
227 "NAME"=>_("Opsi local package") , "KZL"=> "OL", "VAR"=>"ShowOpsiLocal"));
230 /* Dynamic action col, depending on snapshot icons */
231 $action_col_size = 130;
232 # if($this->parent->snapshotEnabled()){
233 # $action_col_size += 32;
234 # }
236 /********************
237 Attach objects
238 ********************/
240 $cnts = array();
241 foreach($objects as $key => $data){
242 $cnts[$key] = 0;
243 }
245 foreach($list as $key => $value){
246 $info = "";
247 $img = "";
248 $type = $value['type'];
249 $abort =false;
251 $cnts[$type] ++;
253 if(isset($objects[$type])){
254 $img = "<img class='center' src='".$objects[$type]['IMG']."' title='".$objects[$type]['NAME']."' alt='".$objects[$type]['KZL']."'>";
255 $info = $objects[$type]['NAME'];
256 $var = $objects[$type]['VAR'];
257 }else{
258 $img = "<img class='center' src='images/empty.png' alt=''>";
259 $info = "";
260 $var = "";
261 }
263 if((isset($value['description']))&&(!empty($value['description']))){
264 $desc= " [".$value['description']."]";
265 }else{
266 $desc= "";
267 }
269 /* Add copy & cut icons */
270 $ui = get_userinfo();
271 $action ="";
272 $acl_all = $ui->has_complete_category_acls($this->parent->fai_base,$this->module);
274 if(preg_match("/^opsi_/",$type)){
275 $editlink ="<a href='?plug=".$_GET['plug']."&edit_opsi_entry=%KEY%' title='%TITLE%'>%NAME%</a>";
276 $action.= "<input class='center' type='image' src='images/lists/edit.png' alt='"._("edit")."'
277 name='entry_opsi_edit_%KEY%' title='"._("Edit product")."'><img src='images/empty.png' alt=' ' class='center'>";
278 }else{
280 /* Add copy & cut functionality */
281 $action.= $this->parent->get_copypaste_action($value['dn'],"fai",$value['class'],TRUE,FALSE);
283 if(preg_match("/^freeze/", $value['FAIstate'])){
284 $editlink ="<a href='?plug=".$_GET['plug']."&edit_freeze_entry=%KEY%' title='%TITLE%'>%NAME%</a>";
285 $action.= "<input class='center' type='image' src='images/lists/edit.png' alt='"._("edit")."'
286 name='entry_freeze_edit_%KEY%' title='"._("Edit class")."'>";
287 $action.= "<img src='images/lists/locked.png' alt='F' class='center'>";
288 }else{
289 $editlink ="<a href='?plug=".$_GET['plug']."&edit_entry=%KEY%' title='%TITLE%'>%NAME%</a>";
290 $action.= "<input class='center' type='image' src='images/lists/edit.png' alt='"._("edit")."'
291 name='entry_edit_%KEY%' title='"._("Edit class")."'>";
292 if(preg_match("/d/",$value['acl'])){
293 $action.= "<input class='center' type='image' src='images/lists/trash.png' alt='"._("delete")."'
294 name='entry_delete_%KEY%' title='"._("Delete class")."'>";
295 }
296 }
297 }
299 # $action.= $this->parent->get_snapshot_action($val['dn'],$this->module);
301 /* Cutted objects should be displayed in light grey */
302 $display = $value['cn'].$desc;
303 if($this->parent->CopyPasteHandler){
304 foreach($this->parent->CopyPasteHandler->queue as $queue_key => $queue_data){
305 if($queue_data['dn'] == $value['dn']) {
306 $display = "<font color='#999999'>".$display."</font>";
307 break;
308 }
309 }
310 }
311 $edi = $editlink;
312 $acti = $action;
314 $display = "<div style='overflow:hidden; height:1em;'>".$display."</div>";
316 /* Create each field */
317 $field0 = array("string" => "<input type='checkbox' id='item_selected_".$key."' name='item_selected_".$key."'>" ,
318 "attach" => "style='width:20px;'");
319 $field1 = array("string" => $img , "attach" => "style='text-align:center;width:20px;'");
320 $field2 = array("string" => preg_replace(array("/%KEY%/","/%NAME%/","/%TITLE%/"),array($key,$display,preg_replace('/ /', ' ', @LDAP::fix($value['dn']))),$edi) , "attach" => "style=''");
321 $field3 = array("string" => $info, "attach" => "style='width:200px;'");
322 $field4 = array("string" => preg_replace("/%KEY%/",$key,$acti) , "attach" => "style='width:".$action_col_size."px;border-right:0px;text-align:right;'");
323 $this->AddElement(array($field0,$field1,$field2,$field3,$field4));
324 }
326 /* Create summary string for list footer */
327 $num_deps=0;
328 if(!$this->SubSearch){
329 $num_deps = count($this->Added_Departments);
330 }
332 $profile_str = sprintf(_("Number of listed '%s'"),_("profiles"));
333 $partition_str = sprintf(_("Number of listed '%s'"),_("partitions"));
334 $script_str = sprintf(_("Number of listed '%s'"),_("scripts"));
335 $hook_str = sprintf(_("Number of listed '%s'"),_("hooks"));
336 $variable_str = sprintf(_("Number of listed '%s'"),_("variables"));
337 $template_str = sprintf(_("Number of listed '%s'"),_("templates"));
338 $package_str = sprintf(_("Number of listed '%s'"),_("packages"));
339 $dep_str = sprintf(_("Number of listed '%s'"),_("departments"));
341 $str = "<img class='center' src='".$objects['FAIprofile']['IMG']."'
342 title='".$profile_str."' alt='".$profile_str."'> ".$cnts['FAIprofile']." ";
343 $str.= "<img class='center' src='".$objects['FAIpartitionTable']['IMG']."'
344 title='".$partition_str."' alt='".$partition_str."'> ".$cnts['FAIpartitionTable']." ";
345 $str.= "<img class='center' src='".$objects['FAIscript']['IMG']."'
346 title='".$script_str."' alt='".$script_str."'> ".$cnts['FAIscript']." ";
347 $str.= "<img class='center' src='".$objects['FAIhook']['IMG']."'
348 title='".$hook_str."' alt='".$hook_str."'> ".$cnts['FAIhook']." ";
349 $str.= "<img class='center' src='".$objects['FAIvariable']['IMG']."'
350 title='".$variable_str."' alt='".$variable_str."'> ".$cnts['FAIvariable']." ";
351 $str.= "<img class='center' src='".$objects['FAItemplate']['IMG']."'
352 title='".$template_str."' alt='".$template_str."'> ".$cnts['FAItemplate']." ";
353 $str.= "<img class='center' src='".$objects['FAIpackageList']['IMG']."'
354 title='".$package_str."' alt='".$package_str."'> ".$cnts['FAIpackageList']." ";
355 $str.= "<img class='center' src='images/lists/folder.png'
356 title='".$dep_str."' alt='".$dep_str."'> ".$num_deps." ";
357 $this->set_List_Bottom_Info($str);
358 }
360 function Save()
361 {
362 MultiSelectWindow::Save();
363 }
365 function save_object()
366 {
367 /* Save automatic created POSTs like regex, checkboxes */
368 MultiSelectWindow::save_object();
369 }
370 }
371 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
372 ?>