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 $r = "" != search_config($this->config->data,"faiManagement","POSTREMOVE");
95 $c = "" != search_config($this->config->data,"faiManagement","POSTCREATE");
97 $smarty = get_smarty();
98 $smarty->assign("allow_create", $c);
99 $smarty->assign("allow_remove", $r);
100 $smarty->assign("selectedBranch",$this->selectedBranch);
101 $smarty->assign("branchimage","images/branch.png");
102 $smarty->assign("branches",$this->AvailableBranches);
103 $str = $smarty->fetch(get_template_path('branch_selector.tpl', TRUE));
104 }
105 return($str);
106 }
108 function GenHeader()
109 {
110 /* Prepare departments,
111 which are shown in the listbox on top of the listbox
112 */
113 $options= "";
115 /* Get all departments within this subtree */
116 $ui= get_userinfo();
117 $first = "";
118 $found = FALSE;
119 $base = $this->config->current['BASE'];
121 /* Add base */
122 $tmp = array();
123 $tmp[] = array("dn"=>$this->config->current['BASE']);
124 $tmp= array_merge($tmp,get_list("(&(|(ou=*)(description=*))(objectClass=gosaDepartment))", $this->module, $base,
125 array("ou", "description"), GL_SIZELIMIT | GL_SUBSEARCH));
127 $deps = array();
128 foreach($tmp as $tm){
129 $deps[$tm['dn']] = $tm['dn'];
130 }
132 /* Load possible departments */
133 $ui= get_userinfo();
134 $tdeps= $ui->get_module_departments("fai");
135 $ids = $this->config->idepartments;
136 $first = "";
137 $found = FALSE;
138 foreach($ids as $dep => $name){
139 if(isset($deps[$dep]) && in_array_ics($dep, $tdeps)){
141 /* Keep first base dn in mind, we could need this
142 * info if no valid base was found
143 */
144 if(empty($first)) {
145 $first = $dep['dn'];
146 }
148 $value = $ids[$dep];
149 if ($this->selectedBase == $dep){
150 $found = TRUE;
151 $options.= "<option selected='selected' value='".$dep."'>$value</option>";
152 } else {
153 $options.= "<option value='".$dep."'>$value</option>";
154 }
155 }
156 }
158 /* The currently used base is not visible with your acl setup.
159 * Set base to first useable base.
160 */
161 if(!$found){
162 $this->selectedBase = $first;
163 }
165 /* Add seperator */
166 $add_sep = false;
168 /* Get complete fai acls, to be able to check if we must show or hide the snapshot abilities */
169 $acl_all = $ui->has_complete_category_acls($this->selectedBase,$this->module);
171 /* Add default header */
172 $listhead = MultiSelectWindow::get_default_header();
174 $acl = $ui->get_permissions($this->selectedBase,"fai/faiProfile");
175 if(preg_match("/c/",$acl)){
176 $listhead .=" <input class='center' type='image' src='images/fai_new_profile.png' align='middle'
177 title='"._("New profile")."' name='Create_profile' alt='"._("P")."'> ";
178 $listhead .=" <img class='center' src='images/list_seperator.png' align='middle' alt='' height='16' width='1'> ";
179 }
181 /* Add snapshot icons, if we are allowed to write and create the complete fai module ($ui->has_complete_category_acls) */
182 if(preg_match("/(c.*w|w.*c)/",$acl_all)){
183 $listhead .= $this->get_snapshot_header($this->selectedBase);
184 }
186 /* Add copy & paste icons, currently disabled, this ability is not implemeneted yet */
187 if(preg_match("/(c.*w|w.*c)/",$acl_all) && isset($this->parent->CopyPasteHandler) && $this->parent->CopyPasteHandler){
188 $Copy_Paste = $this->parent->CopyPasteHandler->generatePasteIcon();
189 }
191 /* Append create icons for each fai component */
192 $arr = array(
193 array("images/fai_new_partitionTable.png" , _("New partition table") ,"Create_partition" , _("PT") , "faiPartitionTable"),
194 array("images/fai_new_script.png" , _("New scripts") ,"Create_script" , _("S") , "faiScript"),
195 array("images/fai_new_hook.png" , _("New hooks") ,"Create_hook" , _("H") , "faiHook"),
196 array("images/fai_new_variable.png" , _("New variables") ,"Create_variable" , _("V") , "faiVariable"),
197 array("images/fai_new_template.png" , _("New templates ") ,"Create_template" , _("I") , "faiTemplate"),
198 array("images/fai_new_packages.png" , _("New package list") ,"Create_package" , _("PK") , "faiPackage"));
200 foreach($arr as $ar){
201 $acl = $ui->get_permissions($this->selectedBase,"fai/".$ar[4]);
202 if(preg_match("/c/",$acl)){
203 $add_sep = true;
204 $listhead .=" <input class='center' type='image' src='".$ar[0]."' align='middle' title='".$ar[1]."' name='".$ar[2]."' alt='".$ar[3]."'> ";
205 }
206 }
208 /* Add additional seperator */
209 if($add_sep){
210 $listhead .=" <img class='center' src='images/list_seperator.png' align='middle' alt='' height='16' width='1'> ";
211 }
213 $listhead .= _("Base")." <select name='CurrentMainBase' onChange='mainform.submit()' class='center'>$options</select>".
214 " <input class='center' type='image' src='images/list_submit.png' align='middle'
215 title='"._("Submit department")."' name='submit_department' alt='". _("Submit")."'> ";
217 /* Multiple options */
218 $listhead .= " <input class='center' type='image' align='middle' src='images/edittrash.png'
219 title='"._("Remove selected fai objects")."' alt='"._("Remove fai objects")."' name='remove_multiple_fai_objects'> ";
221 /* Add multiple copy & cut icons */
222 if(is_object($this->parent->CopyPasteHandler)){
223 $listhead .= " <input class='center' type='image' align='middle' src='images/editcopy.png'
224 title='"._("Copy selected objects")."' alt='"._("Copy fai objects")."' name='multiple_copy_fai'> ";
225 $listhead .= " <input class='center' type='image' align='middle' src='images/editcut.png'
226 title='"._("cut selected objects")."' alt='"._("Cut fai objects")."' name='multiple_cut_fai'> ";
227 $listhead .= "</div>";
228 }
230 $listhead .="</div>";;
233 $this->SetListHeader($listhead);
234 }
236 /* so some basic settings */
237 function execute()
238 {
239 $this->ClearElementsList();
240 $this->GenHeader();
241 $this->AvailableBranches = $this->parent->getBranches();
242 }
244 function setEntries($list)
245 {
246 /********************
247 Variable init
248 ********************/
250 $objects = array(
251 "FAIpartitionTable" => array("IMG"=> "images/fai_partitionTable.png", "NAME"=>"Partition table","KZL"=> "PT", "VAR"=>"ShowPartitions"),
252 "FAIpackageList" => array("IMG"=> "images/fai_packages.png", "NAME"=>"Package list" , "KZL"=> "PL", "VAR"=>"ShowPackages"),
253 "FAIscript" => array("IMG"=> "images/fai_script.png", "NAME"=>"Scripts" , "KZL"=> "S", "VAR"=>"ShowScripts"),
254 "FAIvariable" => array("IMG"=> "images/fai_variable.png", "NAME"=>"Variables" , "KZL"=> "V", "VAR"=>"ShowVariables"),
255 "FAIhook" => array("IMG"=> "images/fai_hook.png", "NAME"=>"Hooks", "KZL"=> "H", "VAR"=>"ShowHooks"),
256 "FAIprofile" => array("IMG"=> "images/fai_profile.png", "NAME"=>"Profile" , "KZL"=> "P", "VAR"=>"ShowProfiles"),
257 "FAItemplate" => array("IMG"=> "images/fai_template.png", "NAME"=>"Templates" , "KZL"=> "T", "VAR"=>"ShowTemplates"));
259 $editlink ="<a href='?plug=".$_GET['plug']."&edit_entry=%KEY%' title='%TITLE%'>%NAME%</a>";
261 /* Dynamic action col, depending on snapshot icons */
262 $action_col_size = 50;
263 if($this->parent->snapshotEnabled()){
264 $action_col_size += 20;
265 }
267 /********************
268 Attach objects
269 ********************/
271 foreach($list as $key => $value){
272 $info = "";
273 $img = "";
274 $type = $value['type'];
275 $abort =false;
277 if(isset($objects[$type])){
278 $img = "<img class='center' src='".$objects[$type]['IMG']."' title='".$objects[$type]['NAME']."' alt='".$objects[$type]['KZL']."'>";
279 $info = $objects[$type]['NAME'];
280 $var = $objects[$type]['VAR'];
281 }else{
282 $img = "<img class='center' src='images/empty.png' alt=''>";
283 $info = "";
284 $var = "";
285 }
287 if((isset($value['description']))&&(!empty($value['description']))){
288 $desc= " [".$value['description']."]";
289 }else{
290 $desc= "";
291 }
294 if($value['FAIstate'] == "freeze"){
295 $action= "<img src='images/closedlock.png' alt='F' class='center'><img src='images/empty.png' width='38' height='2' class='center' alt=''>";
296 $action.= "<input class='center' type='image' src='images/edit.png' alt='"._("edit")."'
297 name='entry_edit_%KEY%' title='"._("Edit class")."'>";
298 }else{
299 $action= "<input class='center' type='image' src='images/edit.png' alt='"._("edit")."'
300 name='entry_edit_%KEY%' title='"._("Edit class")."'>";
302 if(preg_match("/(c&w)/",$value['acl'])){
303 $action.= $this->GetSnapShotActions($value['dn']);;
304 }
306 if(preg_match("/d/",$value['acl'])){
307 $action.= "<input class='center' type='image' src='images/edittrash.png' alt='"._("delete")."'
308 name='entry_delete_%KEY%' title='"._("Delete class")."'>";
309 }
310 }
312 $edi = $editlink;
313 $acti = $action;
315 /* Create each field */
316 $field0 = array("string" => "<input type='checkbox' id='item_selected_".$key."' name='item_selected_".$key."'>" ,
317 "attach" => "style='width:20px;'");
318 $field1 = array("string" => $img , "attach" => "style='text-align:center;width:20px;'");
319 $field2 = array("string" => preg_replace(array("/%KEY%/","/%NAME%/","/%TITLE%/"),array($key,$value['cn'].$desc,preg_replace('/ /', ' ', @LDAP::fix($value['dn']))),$edi) , "attach" => "style=''");
320 $field3 = array("string" => $info, "attach" => "style='width:200px;'");
321 $field4 = array("string" => preg_replace("/%KEY%/",$key,$acti) , "attach" => "style='width:".$action_col_size."px;border-right:0px;text-align:right;'");
322 $this->AddElement(array($field0,$field1,$field2,$field3,$field4));
323 }
324 }
326 function Save()
327 {
328 MultiSelectWindow::Save();
329 }
331 function save_object()
332 {
333 /* Save automatic created POSTs like regex, checkboxes */
334 MultiSelectWindow::save_object();
335 $_SESSION['faifilter']['branch'] = $this->selectedBranch;
336 }
337 }
338 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
339 ?>