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 products"));
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" => _("Class name"), "attach" => "style=''"));
54 $this->AddHeader(array("string" => _("Class types"), "attach" => "style='width:200px;'"));
55 $this->AddHeader(array("string" => _("Actions"), "attach" => "style='width:".$action_col_size."px;border-right:0px;text-align:right;'"));
57 $this->AddCheckBox("ShowProfiles" , sprintf(_("Display objects of type '%s'."),
58 _("Profile")) ,_("Show profiles") ,true);
59 $this->AddCheckBox("ShowTemplates" , sprintf(_("Display objects of type '%s'."),
60 _("Variable")) ,_("Show templates") ,true);
61 $this->AddCheckBox("ShowScripts" , sprintf(_("Display objects of type '%s'."),
62 _("Script")) ,_("Show scripts") ,true);
63 $this->AddCheckBox("ShowHooks" , sprintf(_("Display objects of type '%s'."),
64 _("Hook")) ,_("Show hooks") ,true);
65 $this->AddCheckBox("ShowVariables" , sprintf(_("Display objects of type '%s'."),
66 _("Variable")) ,_("Show variables") ,true);
67 $this->AddCheckBox("ShowPackages" , sprintf(_("Display objects of type '%s'."),
68 _("Package")) ,_("Show packages") ,true);
69 $this->AddCheckBox("ShowPartitions" , sprintf(_("Display objects of type '%s'."),
70 _("Partition")),_("Show partitions") ,true);
72 /* Add opsi checkboxes if opsi is enabled
73 */
74 if($this->parent->opsi instanceof opsi && $this->parent->opsi->enabled()){
75 $this->AddCheckBox("ShowOpsiNetboot" , sprintf(_("Display objects of type '%s'."),
76 _("OPSI netboot product")),_("Show netboot products") ,true);
77 $this->AddCheckBox("ShowOpsiLocal" , sprintf(_("Display objects of type '%s'."),
78 _("OPSI localboot product")),_("Show localboot products") ,true);
79 }
81 /* Add SubSearch checkbox */
82 //$this->AddCheckBox(SEPERATOR);
83 //$this->AddCheckBox("SubSearch", msgPool::selectToView("","subsearch"), msgPool::selectToView("","subsearch_small"), 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 $releases = $this->parent->getBranches();
103 $smarty->assign("allow_create", $c);
104 $smarty->assign("allow_remove", $r);
105 $smarty->assign("fai_release" , $releases[$this->parent->fai_release]);
106 $smarty->assign("fai_base" , $releases[$this->parent->fai_base]);
107 $smarty->assign("branchimage","plugins/fai/images/branch.png");
108 $smarty->assign("fai_releases", $releases);
109 $plug_id = 0;
110 if(isset($_GET['plug'])){
111 $plug_id = $_GET['plug'];
112 }
113 $smarty->assign("plug_id",$plug_id);
114 $str = $smarty->fetch(get_template_path('branch_selector.tpl', TRUE));
115 }
116 return($str);
117 }
119 function GenHeader()
120 {
121 /* Get all departments within this subtree */
122 $ui= get_userinfo();
123 $first = "";
124 $found = FALSE;
125 $base = $this->config->current['BASE'];
127 /* Add seperator */
128 $add_sep = false;
130 /* Add default header */
131 $listhead = MultiSelectWindow::get_default_header(false);
133 /* Add additional seperator */
134 if($add_sep){
135 $listhead .=" <img class='center' src='images/lists/seperator.png' align='middle' alt='' height='16' width='1'> ";
136 }
138 $s = ".|"._("Actions")."|\n";
139 $s .= "..|<img src='images/lists/new.png' alt='' border='0' class='center'>".
140 " "._("Create")."|\n";
142 $acl = $ui->get_permissions($this->parent->acl_base,"fai/faiProfile");
143 if($this->parent->lock_type == "freeze" && !$this->parent->allow_freeze_object_attach){
144 $s.= "...|<input class='center' type='image' src='plugins/fai/images/freeze.png' alt=''>".
145 " "._("Freezed")."|\n";
146 }else{
147 if(preg_match("/c/",$acl)){
148 $s.= "...|<input class='center' type='image' src='plugins/fai/images/fai_new_profile.png' alt=''>".
149 " "._("Profile")."|Create_profile|\n";
150 }
152 /* Append create icons for each fai component */
153 $arr = array(
154 array("plugins/fai/images/fai_new_partitionTable.png" , _("Partition table") ,
155 "Create_partition" , _("PT") , "faiPartitionTable"),
156 array("plugins/fai/images/fai_new_script.png" , _("Scripts") ,
157 "Create_script" , _("S") , "faiScript"),
158 array("plugins/fai/images/fai_new_hook.png" , _("Hooks") ,
159 "Create_hook" , _("H") , "faiHook"),
160 array("plugins/fai/images/fai_new_variable.png" , _("Variables") ,
161 "Create_variable" , _("V") , "faiVariable"),
162 array("plugins/fai/images/fai_new_template.png" , _("Templates ") ,
163 "Create_template" , _("I") , "faiTemplate"),
164 array("plugins/fai/images/fai_new_packages.png" , _("Package list") ,
165 "Create_package" , _("PK") , "faiPackage"));
167 foreach($arr as $ar){
168 $acl = $ui->get_permissions($this->parent->acl_base,"fai/".$ar[4]);
169 if(preg_match("/c/",$acl)){
170 $s.= "...|<input class='center' type='image' src='".$ar[0]."' alt=''>".
171 " ".$ar[1]."|".$ar[2]."|\n";
172 }
173 }
174 }
176 /* Multiple options */
177 $s.= "..|<img src='images/lists/trash.png' alt='' border='0' class='center'>".
178 " "._("Remove")."|"."remove_multiple|\n";
181 /* Add Copy & Paste header */
182 $s .= $this->parent->get_copypaste_header($this->selectedBase,$this->module,TRUE,FALSE);
184 # /* Add snapshot icons, if we are allowed to write and create the complete fai module ($ui->has_complete_category_acls) */
185 # $s .= $this->parent->get_snapshot_header($this->selectedBase,$this->module);
187 $this->SetDropDownHeaderMenu($s);
188 $this->SetListHeader($listhead);
189 }
191 /* so some basic settings */
192 function execute()
193 {
194 $this->ClearElementsList();
195 $this->GenHeader();
196 $this->AvailableBranches = $this->parent->getBranches();
197 }
199 function setEntries($list)
200 {
201 /********************
202 Variable init
203 ********************/
205 $edit_link = "<a href=\"?plug=".$_GET['plug']."&id=%s&act=edit\">%s</a>";
206 $objects = array(
207 "FAIpartitionTable" => array("IMG"=> "plugins/fai/images/fai_partitionTable.png",
208 "NAME"=>_("Partition table"),"KZL"=> "PT", "VAR"=>"ShowPartitions"),
209 "FAIpackageList" => array("IMG"=> "plugins/fai/images/fai_packages.png",
210 "NAME"=>_("Package list") , "KZL"=> "PL", "VAR"=>"ShowPackages"),
211 "FAIscript" => array("IMG"=> "plugins/fai/images/fai_script.png",
212 "NAME"=>_("Scripts") , "KZL"=> "S", "VAR"=>"ShowScripts"),
213 "FAIvariable" => array("IMG"=> "plugins/fai/images/fai_variable.png",
214 "NAME"=>_("Variables") , "KZL"=> "V", "VAR"=>"ShowVariables"),
215 "FAIhook" => array("IMG"=> "plugins/fai/images/fai_hook.png",
216 "NAME"=>_("Hooks"), "KZL"=> "H", "VAR"=>"ShowHooks"),
217 "FAIprofile" => array("IMG"=> "plugins/fai/images/fai_profile.png",
218 "NAME"=>_("Profile") , "KZL"=> "P", "VAR"=>"ShowProfiles"),
219 "FAItemplate" => array("IMG"=> "plugins/fai/images/fai_template.png",
220 "NAME"=>_("Templates") , "KZL"=> "T", "VAR"=>"ShowTemplates"),
221 "opsi_netboot" => array("IMG"=> "plugins/opsi/images/netboot_package.png",
222 "NAME"=>_("OPSI netboot product") , "KZL"=> "ON", "VAR"=>"ShowOpsiNetboot"),
223 "opsi_local" => array("IMG"=> "plugins/opsi/images/local_package.png",
224 "NAME"=>_("OPSI localboot product") , "KZL"=> "OL", "VAR"=>"ShowOpsiLocal"));
227 /* Dynamic action col, depending on snapshot icons */
228 $action_col_size = 130;
230 /********************
231 Attach objects
232 ********************/
234 /* Initialize summary attributes
235 */
236 $cnts = array();
237 foreach($objects as $key => $data){
238 $cnts[$key] = 0;
239 }
241 /* Walk through entries an build up a printable row for each object
242 */
243 foreach($list as $key => $value){
245 /* Build up edit icons - depending on read acls for the current type
246 */
247 $name = "";
248 $name = "";
249 $icon_list = "";
250 $opsi_only = TRUE;
251 foreach($objects as $type => $type_data){
252 if(isset($value[$type])){
253 $name = $value[$type]['cn'];
254 $icon_list .= "<input type='image' src='".$type_data['IMG']."' title='".$type_data['NAME']."'
255 alt='".$type_data['KZL']."' class='center' name='edit_".$key."_".$type."'>\n";
256 $cnts[$type] ++;
257 if(!in_array($type,array("opsi_local","opsi_netboot"))){
258 $opsi_only = FALSE;
259 }
260 }else{
261 $icon_list .= "<img src='images/empty.png' alt=' ' class='center'>\n";
262 }
263 }
265 /* Create checkbox
266 */
267 $checkbox = " ";
268 if(!$opsi_only){
269 $checkbox = "<input type='checkbox' id='item_selected_".$key."' name='item_selected_".$key."'>";
270 }
272 /* Create actions string
273 */
274 $actions = "";
275 if($opsi_only){
276 $actions.= "<input type='image' name='group_edit_".$key."' class='center'
277 src='images/lists/edit.png'>";
278 $actions.= "<img class='center' src='images/empty.png' alt=' '>";
279 }else{
280 $actions.= '<input class="center" src="images/lists/copy.png" alt="Kopieren" name="group_copy_'.$key.'"
281 title="Diesen Eintrag kopieren" type="image"> ';
283 $actions.= "<input type='image' name='group_edit_".$key."' class='center'
284 src='images/lists/edit.png'>";
285 $actions.= "<input type='image' name='group_remove_".$key."' class='center'
286 src='images/lists/trash.png'>";
287 }
289 /* Create list
290 */
291 $field1 = array(
292 "string" => $checkbox ,
293 "attach" => "style='width:20px;'");
294 $field2 = array(
295 "string" => sprintf($edit_link,$key,$name),
296 "attach" => "style=''");
297 $field3 = array(
298 "string" => $icon_list ,
299 "attach" => "style='width:200px;'");
300 $field4 = array(
301 "string" => $actions,
302 "attach" => "style='width:".$action_col_size."px;border-right: 0px;text-align:right;'");
304 $this->AddElement(array($field1,$field2,$field3,$field4));
305 }
307 /* Create summary string for list footer */
308 $num_deps=0;
309 if(!$this->SubSearch){
310 $num_deps = count($this->Added_Departments);
311 }
313 $profile_str = sprintf(_("Number of listed '%s'"),_("profiles"));
314 $partition_str = sprintf(_("Number of listed '%s'"),_("partitions"));
315 $script_str = sprintf(_("Number of listed '%s'"),_("scripts"));
316 $hook_str = sprintf(_("Number of listed '%s'"),_("hooks"));
317 $variable_str = sprintf(_("Number of listed '%s'"),_("variables"));
318 $template_str = sprintf(_("Number of listed '%s'"),_("templates"));
319 $package_str = sprintf(_("Number of listed '%s'"),_("packages"));
320 $dep_str = sprintf(_("Number of listed '%s'"),_("departments"));
321 $opsi_netboot = sprintf(_("Number of listed '%s'"),_("netboot products"));
322 $opsi_local = sprintf(_("Number of listed '%s'"),_("localboot products"));
324 $str = "<img class=\"center\" src=\"".$objects['FAIprofile']['IMG']."\"
325 title=\"".$profile_str."\" alt=\"".$profile_str."\"> ".$cnts['FAIprofile']." ";
326 $str.= "<img class=\"center\" src=\"".$objects['FAIpartitionTable']['IMG']."\"
327 title=\"".$partition_str."\" alt=\"".$partition_str."\"> ".$cnts['FAIpartitionTable']." ";
328 $str.= "<img class=\"center\" src=\"".$objects['FAIscript']['IMG']."\"
329 title=\"".$script_str."\" alt=\"".$script_str."\"> ".$cnts['FAIscript']." ";
330 $str.= "<img class=\"center\" src=\"".$objects['FAIhook']['IMG']."\"
331 title=\"".$hook_str."\" alt=\"".$hook_str."\"> ".$cnts['FAIhook']." ";
332 $str.= "<img class=\"center\" src=\"".$objects['FAIvariable']['IMG']."\"
333 title=\"".$variable_str."\" alt=\"".$variable_str."\"> ".$cnts['FAIvariable']." ";
334 $str.= "<img class=\"center\" src=\"".$objects['FAItemplate']['IMG']."\"
335 title=\"".$template_str."\" alt=\"".$template_str."\"> ".$cnts['FAItemplate']." ";
336 $str.= "<img class=\"center\" src=\"".$objects['FAIpackageList']['IMG']."\"
337 title=\"".$package_str."\" alt=\"".$package_str."\"> ".$cnts['FAIpackageList']." ";
338 $str.= "<img class=\"center\" src='images/lists/folder.png'
339 title=\"".$dep_str."\" alt=\"".$dep_str."\"> ".$num_deps." ";
341 if($this->parent->opsi instanceof opsi && $this->parent->opsi->enabled()){
342 $str.= "<img class=\"center\" src=\"".$objects['opsi_netboot']['IMG']."\"
343 title=\"".$opsi_netboot."\" alt=\"".$opsi_netboot."\"> ".$cnts['opsi_netboot']." ";
344 $str.= "<img class=\"center\" src=\"".$objects['opsi_local']['IMG']."\"
345 title=\"".$opsi_local."\" alt=\"".$opsi_local."\"> ".$cnts['opsi_local']." ";
346 }
347 $this->set_List_Bottom_Info($str);
348 }
350 function Save()
351 {
352 MultiSelectWindow::Save();
353 }
355 function save_object()
356 {
357 /* Save automatic created POSTs like regex, checkboxes */
358 MultiSelectWindow::save_object();
359 }
360 }
361 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
362 ?>