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 function divListFai (&$config,$parent)
22 {
23 MultiSelectWindow::MultiSelectWindow($config, "Fai", "fai");
25 $this->parent = $parent;
26 $this->ui = get_userinfo();
28 /* Set list strings */
29 $this->SetTitle( _("List of classes"));
30 $this->SetSummary(_("List of deployment classes and packages"));
32 /* Result page will look like a headpage */
33 $this->SetHeadpageMode();
35 $this->EnableAplhabet (true);
37 /* Disable buttonsm */
38 $this->EnableCloseButton(false);
39 $this->EnableSaveButton (false);
41 /* Dynamic action col, depending on snapshot icons */
42 $action_col_size = 120;
44 /* Toggle all selected / deselected */
45 $chk = "<input type='checkbox' id='select_all' name='select_all'
46 onClick='toggle_all_(\"^item_selected_[0-9]*$\",\"select_all\");' >";
48 /* set Page header */
49 $this->AddHeader(array("string"=> $chk, "attach"=>"style='width:20px;'"));
50 $this->AddHeader(array("string" => " ", "attach" => "style='text-align:center;width:20px;'"));
51 $this->AddHeader(array("string" => _("Class name"), "attach" => "style=''"));
52 $this->AddHeader(array("string" => _("Class type"), "attach" => "style='width:200px;'"));
53 $this->AddHeader(array("string" => _("Actions"), "attach" => "style='width:".$action_col_size."px;border-right:0px;text-align:right;'"));
55 $this->AddCheckBox("ShowProfiles" , sprintf(_("Display objects of type '%s'."),_("Profile")) ,_("Show profiles") ,true);
56 $this->AddCheckBox("ShowTemplates" , sprintf(_("Display objects of type '%s'."),_("Variable")) ,_("Show templates") ,true);
57 $this->AddCheckBox("ShowScripts" , sprintf(_("Display objects of type '%s'."),_("Script")) ,_("Show scripts") ,true);
58 $this->AddCheckBox("ShowHooks" , sprintf(_("Display objects of type '%s'."),_("Hook")) ,_("Show hooks") ,true);
59 $this->AddCheckBox("ShowVariables" , sprintf(_("Display objects of type '%s'."),_("Variable")) ,_("Show variables") ,true);
60 $this->AddCheckBox("ShowPackages" , sprintf(_("Display objects of type '%s'."),_("Package")) ,_("Show packages") ,true);
61 $this->AddCheckBox("ShowPartitions" , sprintf(_("Display objects of type '%s'."),_("Partition")),_("Show partitions") ,true);
63 /* Add SubSearch checkbox */
64 //$this->AddCheckBox(SEPERATOR);
65 //$this->AddCheckBox("SubSearch", msgPool::selectToView("","subsearch"), msgPool::selectToView("","subsearch_small"), false);
67 /* Name ,Text ,Default , Connect with alphabet */
68 $this->AddRegex ("Regex", _("Display users matching"),"*" , true);
69 }
71 function AddUserBoxToFilter($position)
72 {
73 $str = "";
74 if($position == 2){
76 /* Check if there are post commands available for fai management.
77 * If not, grey out freeze/branch and release remove buttons.
78 */
79 $r = $this->config->search("faiManagement", "POSTREMOVE",array('menu','tabs'));
80 $c = $this->config->search("faiManagement", "POSTCREATE",array('menu','tabs'));
82 $smarty = get_smarty();
83 $releases = $this->parent->getBranches();
84 $smarty->assign("allow_create", $c);
85 $smarty->assign("allow_remove", $r);
86 $smarty->assign("fai_release" , $releases[$this->parent->fai_release]);
87 $smarty->assign("fai_base" , $releases[$this->parent->fai_base]);
88 $smarty->assign("branchimage","images/branch.png");
89 $smarty->assign("fai_releases", $releases);
90 $plug_id = 0;
91 if(isset($_GET['plug'])){
92 $plug_id = $_GET['plug'];
93 }
94 $smarty->assign("plug_id",$plug_id);
95 $str = $smarty->fetch(get_template_path('branch_selector.tpl', TRUE));
96 }
97 return($str);
98 }
100 function GenHeader()
101 {
102 /* Get all departments within this subtree */
103 $ui= get_userinfo();
104 $first = "";
105 $found = FALSE;
106 $base = $this->config->current['BASE'];
108 /* Add seperator */
109 $add_sep = false;
111 /* Get complete fai acls, to be able to check if we must show or hide the snapshot abilities */
112 $acl_all = $ui->has_complete_category_acls($this->parent->fai_base,$this->module);
114 /* Add default header */
115 $listhead = MultiSelectWindow::get_default_header();
117 /* Add additional seperator */
118 if($add_sep){
119 $listhead .=" <img class='center' src='images/list_seperator.png' align='middle' alt='' height='16' width='1'> ";
120 }
122 $s = ".|"._("Actions")."|\n";
123 $s .= "..|<img src='images/list_new.png' alt='' border='0' class='center'>".
124 " "._("Create")."|\n";
126 $acl = $ui->get_permissions($this->parent->fai_base,"fai/faiProfile");
127 if(preg_match("/c/",$acl)){
128 $s.= "...|<input class='center' type='image' src='images/fai_new_profile.png' alt=''>".
129 " "._("Profile")."|Create_profile|\n";
130 }
132 /* Append create icons for each fai component */
133 $arr = array(
134 array("images/fai_new_partitionTable.png" , _("Partition table") ,"Create_partition" , _("PT") , "faiPartitionTable"),
135 array("images/fai_new_script.png" , _("Scripts") ,"Create_script" , _("S") , "faiScript"),
136 array("images/fai_new_hook.png" , _("Hooks") ,"Create_hook" , _("H") , "faiHook"),
137 array("images/fai_new_variable.png" , _("Variables") ,"Create_variable" , _("V") , "faiVariable"),
138 array("images/fai_new_template.png" , _("Templates ") ,"Create_template" , _("I") , "faiTemplate"),
139 array("images/fai_new_packages.png" , _("Package list") ,"Create_package" , _("PK") , "faiPackage"));
141 foreach($arr as $ar){
142 $acl = $ui->get_permissions($this->parent->fai_base,"fai/".$ar[4]);
143 if(preg_match("/c/",$acl)){
144 $s.= "...|<input class='center' type='image' src='".$ar[0]."' alt=''>".
145 " ".$ar[1]."|".$ar[2]."|\n";
146 }
147 }
149 /* Multiple options */
150 $s.= "..|<img src='images/lists/trash.png' alt='' border='0' class='center'>".
151 " "._("Remove")."|"."remove_multiple|\n";
153 /* Add multiple copy & cut icons */
154 if(is_object($this->parent->CopyPasteHandler)){
155 $s.= "..|---|\n";
156 $s.= "..|<img src='images/lists/copy.png' alt='' border='0' class='center'>".
157 " "._("Copy")."|"."multiple_copy_systems|\n";
158 $s.= "..|<img src='images/lists/cut.png' alt='' border='0' class='center'>".
159 " "._("Cut")."|"."multiple_cut_systems|\n";
160 }
162 /* Add copy & paste icons, currently disabled, this ability is not implemeneted yet */
163 if(!($this->parent->lock_type == "freeze" && !$this->parent->allow_freeze_object_attach) &&
164 preg_match("/(c.*w|w.*c)/",$acl_all) && isset($this->parent->CopyPasteHandler) && $this->parent->CopyPasteHandler){
165 $s .= "..|---|\n";
166 if($this->parent->CopyPasteHandler->entries_queued()){
167 $img = "<img border='0' class='center' src='images/lists/paste.png' alt=''>";
168 $s.="..|".$img." "._("Paste")."|editPaste|\n";
169 }else{
170 $img = "<img border='0' class='center' src='images/lists/paste.png' alt=''>";
171 $s.="..|".$img." "._("Paste")."\n";
172 }
173 }
175 # /* Add snapshot icons, if we are allowed to write and create the complete fai module ($ui->has_complete_category_acls) */
176 # if(preg_match("/(c.*w|w.*c)/",$acl_all)){
177 # if($this->parent->snapshotEnabled()){
178 # $s .= "..|---|\n";
179 # $s .= $this->get_snapshot_header(TRUE);
180 # }
181 # }
183 $this->SetDropDownHeaderMenu($s);
184 $this->SetListHeader($listhead);
185 }
187 /* so some basic settings */
188 function execute()
189 {
190 $this->ClearElementsList();
191 $this->GenHeader();
192 $this->AvailableBranches = $this->parent->getBranches();
193 }
195 function setEntries($list)
196 {
197 /********************
198 Variable init
199 ********************/
201 $objects = array(
202 "FAIpartitionTable" => array("IMG"=> "images/fai_partitionTable.png", "NAME"=>_("Partition table"),"KZL"=> "PT", "VAR"=>"ShowPartitions"),
203 "FAIpackageList" => array("IMG"=> "images/fai_packages.png", "NAME"=>_("Package list") , "KZL"=> "PL", "VAR"=>"ShowPackages"),
204 "FAIscript" => array("IMG"=> "images/fai_script.png", "NAME"=>_("Scripts") , "KZL"=> "S", "VAR"=>"ShowScripts"),
205 "FAIvariable" => array("IMG"=> "images/fai_variable.png", "NAME"=>_("Variables") , "KZL"=> "V", "VAR"=>"ShowVariables"),
206 "FAIhook" => array("IMG"=> "images/fai_hook.png", "NAME"=>_("Hooks"), "KZL"=> "H", "VAR"=>"ShowHooks"),
207 "FAIprofile" => array("IMG"=> "images/fai_profile.png", "NAME"=>_("Profile") , "KZL"=> "P", "VAR"=>"ShowProfiles"),
208 "FAItemplate" => array("IMG"=> "images/fai_template.png", "NAME"=>_("Templates") , "KZL"=> "T", "VAR"=>"ShowTemplates"));
211 /* Dynamic action col, depending on snapshot icons */
212 $action_col_size = 120;
213 # if($this->parent->snapshotEnabled()){
214 # $action_col_size += 32;
215 # }
217 /********************
218 Attach objects
219 ********************/
221 $cnts = array();
222 foreach($objects as $key => $data){
223 $cnts[$key] = 0;
224 }
226 foreach($list as $key => $value){
227 $info = "";
228 $img = "";
229 $type = $value['type'];
230 $abort =false;
232 $cnts[$type] ++;
234 if(isset($objects[$type])){
235 $img = "<img class='center' src='".$objects[$type]['IMG']."' title='".$objects[$type]['NAME']."' alt='".$objects[$type]['KZL']."'>";
236 $info = $objects[$type]['NAME'];
237 $var = $objects[$type]['VAR'];
238 }else{
239 $img = "<img class='center' src='images/empty.png' alt=''>";
240 $info = "";
241 $var = "";
242 }
244 if((isset($value['description']))&&(!empty($value['description']))){
245 $desc= " [".$value['description']."]";
246 }else{
247 $desc= "";
248 }
250 /* Add copy & cut icons */
251 $ui = get_userinfo();
252 $action ="";
253 $acl_all = $ui->has_complete_category_acls($this->parent->fai_base,$this->module);
254 if(preg_match("/(c.*w|w.*c)/",$acl_all) && $this->parent->CopyPasteHandler){
255 $action .= "<input class='center' type='image'
256 src='images/lists/cut.png' alt='"._("cut")."' name='cut_%KEY%' title='"._("Cut this entry")."'> ";
257 $action.= "<input class='center' type='image'
258 src='images/lists/copy.png' alt='"._("copy")."' name='copy_%KEY%' title='"._("Copy this entry")."'> ";
259 }
261 if(preg_match("/^freeze/", $value['FAIstate'])){
262 $editlink ="<a href='?plug=".$_GET['plug']."&edit_freeze_entry=%KEY%' title='%TITLE%'>%NAME%</a>";
263 $action.= "<input class='center' type='image' src='images/edit.png' alt='"._("edit")."'
264 name='entry_freeze_edit_%KEY%' title='"._("Edit class")."'>";
265 $action.= "<img src='images/lists/locked.png' alt='F' class='center'>";
266 }else{
267 $editlink ="<a href='?plug=".$_GET['plug']."&edit_entry=%KEY%' title='%TITLE%'>%NAME%</a>";
268 $action.= "<input class='center' type='image' src='images/edit.png' alt='"._("edit")."'
269 name='entry_edit_%KEY%' title='"._("Edit class")."'>";
270 if(preg_match("/d/",$value['acl'])){
271 $action.= "<input class='center' type='image' src='images/lists/trash.png' alt='"._("delete")."'
272 name='entry_delete_%KEY%' title='"._("Delete class")."'>";
273 }
274 }
276 /* Cutted objects should be displayed in light grey */
277 $display = $value['cn'].$desc;
278 if($this->parent->CopyPasteHandler){
279 foreach($this->parent->CopyPasteHandler->queue as $queue_key => $queue_data){
280 if($queue_data['dn'] == $value['dn']) {
281 $display = "<font color='#999999'>".$display."</font>";
282 break;
283 }
284 }
285 }
286 $edi = $editlink;
287 $acti = $action;
289 /* Create each field */
290 $field0 = array("string" => "<input type='checkbox' id='item_selected_".$key."' name='item_selected_".$key."'>" ,
291 "attach" => "style='width:20px;'");
292 $field1 = array("string" => $img , "attach" => "style='text-align:center;width:20px;'");
293 $field2 = array("string" => preg_replace(array("/%KEY%/","/%NAME%/","/%TITLE%/"),array($key,$display,preg_replace('/ /', ' ', @LDAP::fix($value['dn']))),$edi) , "attach" => "style=''");
294 $field3 = array("string" => $info, "attach" => "style='width:200px;'");
295 $field4 = array("string" => preg_replace("/%KEY%/",$key,$acti) , "attach" => "style='width:".$action_col_size."px;border-right:0px;text-align:right;'");
296 $this->AddElement(array($field0,$field1,$field2,$field3,$field4));
297 }
299 /* Create summary string for list footer */
300 $num_deps=0;
301 if(!$this->SubSearch){
302 $num_deps = count($this->Added_Departments);
303 }
305 $profile_str = sprintf(_("Number of listed '%s'"),_("profiles"));
306 $partition_str = sprintf(_("Number of listed '%s'"),_("partitions"));
307 $script_str = sprintf(_("Number of listed '%s'"),_("scripts"));
308 $hook_str = sprintf(_("Number of listed '%s'"),_("hooks"));
309 $variable_str = sprintf(_("Number of listed '%s'"),_("variables"));
310 $template_str = sprintf(_("Number of listed '%s'"),_("templates"));
311 $package_str = sprintf(_("Number of listed '%s'"),_("packages"));
312 $dep_str = sprintf(_("Number of listed '%s'"),_("departments"));
314 $str = "<img class='center' src='".$objects['FAIprofile']['IMG']."'
315 title='".$profile_str."' alt='".$profile_str."'> ".$cnts['FAIprofile']." ";
316 $str.= "<img class='center' src='".$objects['FAIpartitionTable']['IMG']."'
317 title='".$partition_str."' alt='".$partition_str."'> ".$cnts['FAIpartitionTable']." ";
318 $str.= "<img class='center' src='".$objects['FAIscript']['IMG']."'
319 title='".$script_str."' alt='".$script_str."'> ".$cnts['FAIscript']." ";
320 $str.= "<img class='center' src='".$objects['FAIhook']['IMG']."'
321 title='".$hook_str."' alt='".$hook_str."'> ".$cnts['FAIhook']." ";
322 $str.= "<img class='center' src='".$objects['FAIvariable']['IMG']."'
323 title='".$variable_str."' alt='".$variable_str."'> ".$cnts['FAIvariable']." ";
324 $str.= "<img class='center' src='".$objects['FAItemplate']['IMG']."'
325 title='".$template_str."' alt='".$template_str."'> ".$cnts['FAItemplate']." ";
326 $str.= "<img class='center' src='".$objects['FAIpackageList']['IMG']."'
327 title='".$package_str."' alt='".$package_str."'> ".$cnts['FAIpackageList']." ";
328 $str.= "<img class='center' src='images/lists/folder.png'
329 title='".$dep_str."' alt='".$dep_str."'> ".$num_deps." ";
330 $this->set_List_Bottom_Info($str);
331 }
333 function Save()
334 {
335 MultiSelectWindow::Save();
336 }
338 function save_object()
339 {
340 /* Save automatic created POSTs like regex, checkboxes */
341 MultiSelectWindow::save_object();
342 }
343 }
344 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
345 ?>