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 /* set Page header */
63 $this->AddHeader(array("string" => " ", "attach" => "style='text-align:center;width:20px;'"));
64 $this->AddHeader(array("string" => _("Name of FAI class"), "attach" => "style=''"));
65 $this->AddHeader(array("string" => _("Class type"), "attach" => "style='width:200px;'"));
66 $this->AddHeader(array("string" => _("Actions"), "attach" => "style='width:".$action_col_size."px;border-right:0px;text-align:right;'"));
68 $this->AddCheckBox("ShowProfiles" , _("Display FAI profile objects") ,_("Show profiles") ,true);
69 $this->AddCheckBox("ShowTemplates" , _("Display FAI template objects") ,_("Show templates") ,true);
70 $this->AddCheckBox("ShowScripts" , _("Display FAI scripts") ,_("Show scripts") ,true);
71 $this->AddCheckBox("ShowHooks" , _("Display FAI hooks") ,_("Show hooks") ,true);
72 $this->AddCheckBox("ShowVariables" , _("Display FAI variables") ,_("Show variables") ,true);
73 $this->AddCheckBox("ShowPackages" , _("Display FAI packages") ,_("Show packages") ,true);
74 $this->AddCheckBox("ShowPartitions" , _("Display FAI partitions") ,_("Show partitions") ,true);
76 /* Add SubSearch checkbox */
77 //$this->AddCheckBox(SEPERATOR);
78 //$this->AddCheckBox("SubSearch", _("Select to search within subtrees"), _("Ignore subtrees"), false);
80 /* Name ,Text ,Default , Connect with alphabet */
81 $this->AddRegex ("Regex", _("Display users matching"),"*" , true);
82 }
84 function AddUserBoxToFilter($position){
85 $str = "";
86 if($position == 2){
87 $smarty = get_smarty();
88 $smarty->assign("selectedBranch",$this->selectedBranch);
89 $smarty->assign("branchimage","images/branch.png");
90 $smarty->assign("branches",$this->AvailableBranches);
91 $str = $smarty->fetch(get_template_path('branch_selector.tpl', TRUE));
92 }
93 return($str);
94 }
96 function GenHeader()
97 {
98 /* Prepare departments,
99 which are shown in the listbox on top of the listbox
100 */
101 $options= "";
103 /* Get all departments within this subtree */
104 $base = $this->config->current['BASE'];
105 $deps= get_list("(&(|(ou=*)(description=*))(objectClass=gosaDepartment))", $this->module, $base,
106 array("ou", "description"), GL_SIZELIMIT | GL_SUBSEARCH);
108 /* Load possible departments */
109 $ui= get_userinfo();
110 $tdeps= $ui->get_module_departments("fai");
111 $ids = $this->config->idepartments;
112 foreach($deps as $dep){
113 if(isset($ids[$dep['dn']]) && in_array_ics($dep['dn'], $tdeps)){
114 $value = $ids[$dep['dn']];
115 if ($this->selectedBase == $dep['dn']){
116 $options.= "<option selected='selected' value='".$dep['dn']."'>$value</option>";
117 } else {
118 $options.= "<option value='".$dep['dn']."'>$value</option>";
119 }
120 }
121 }
123 /* Add seperator */
124 $add_sep = false;
126 /* Get complete fai acls, to be able to check if we must show or hide the snapshot abilities */
127 $acl_all = $ui->has_complete_category_acls($this->selectedBase,$this->module);
129 /* Create listhead, it will be shown on top of the divlist.
130 * It provides general navigation and object creation
131 */
132 $listhead =
133 "<div style='background:#F0F0F9;padding:5px;'> ".
134 "<input class='center' type='image' src='images/list_root.png' align='middle'
135 title='"._("Go to root department")."' name='dep_root' alt='". _("Root")."'> ".
136 "<input class='center' type='image' src='images/list_up.png' align='middle'
137 title='"._("Go up one department")."' name='dep_back' alt='"._("Up"). "'> ".
138 "<input class='center' type='image' src='images/list_home.png' align='middle'
139 title='"._("Go to users home department")."' name='dep_home' alt='"._("Home")."'> ".
140 " <input class='center' type='image' src='images/list_reload.png' align='middle' title='"._("Reload list")."' name='submit_department' alt='".
141 _("Submit")."'> ".
142 "<img class='center' src=\"images/list_seperator.png\" alt=\"\" align=\"middle\" height=\"16\" width=\"1\"> ";
144 $acl = $ui->get_permissions($this->selectedBase,"fai/faiProfile");
145 if(preg_match("/c/",$acl)){
146 $listhead .=" <input class='center' type='image' src='images/fai_new_profile.png' align='middle'
147 title='"._("New profile")."' name='Create_profile' alt='"._("P")."'> ";
148 $listhead .=" <img class='center' src='images/list_seperator.png' align='middle' alt='' height='16' width='1'> ";
149 }
151 /* Add snapshot icons, if we are allowed to write and create the complete fai module ($ui->has_complete_category_acls) */
152 if(preg_match("/(c.*w|w.*c)/",$acl_all)){
153 $listhead .= $this->get_snapshot_header($this->selectedBase);
154 }
156 /* Add copy & paste icons, currently disabled, this ability is not implemeneted yet */
157 if(preg_match("/(c.*w|w.*c)/",$acl_all) && isset($this->parent->CopyPasteHandler) && $this->parent->CopyPasteHandler){
158 $Copy_Paste = $this->parent->CopyPasteHandler->generatePasteIcon();
159 }
161 /* Append create icons for each fai component */
162 $arr = array(
163 array("images/fai_new_partitionTable.png" , _("New partition table") ,"Create_partition" , _("PT") , "faiPartitionTable"),
164 array("images/fai_new_script.png" , _("New scripts") ,"Create_script" , _("S") , "faiScript"),
165 array("images/fai_new_hook.png" , _("New hooks") ,"Create_hook" , _("H") , "faiHook"),
166 array("images/fai_new_variable.png" , _("New variables") ,"Create_variable" , _("V") , "faiVariable"),
167 array("images/fai_new_template.png" , _("New templates ") ,"Create_template" , _("I") , "faiTemplate"),
168 array("images/fai_new_packages.png" , _("New package list") ,"Create_package" , _("PK") , "faiPackage"));
170 foreach($arr as $ar){
171 $acl = $ui->get_permissions($this->selectedBase,"fai/".$ar[4]);
172 if(preg_match("/c/",$acl)){
173 $add_sep = true;
174 $listhead .=" <input class='center' type='image' src='".$ar[0]."' align='middle' title='".$ar[1]."' name='".$ar[2]."' alt='".$ar[3]."'> ";
175 }
176 }
178 /* Add additional seperator */
179 if($add_sep){
180 $listhead .=" <img class='center' src='images/list_seperator.png' align='middle' alt='' height='16' width='1'> ";
181 }
183 $listhead .= _("Base")." <select name='CurrentMainBase' onChange='mainform.submit()' class='center'>$options</select>".
184 " <input class='center' type='image' src='images/list_submit.png' align='middle'
185 title='"._("Submit department")."' name='submit_department' alt='". _("Submit")."'> ".
186 "</div>";
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 $objects = array(
206 "FAIpartitionTable" => array("IMG"=> "images/fai_partitionTable.png", "NAME"=>"Partition table","KZL"=> "PT", "VAR"=>"ShowPartitions"),
207 "FAIpackageList" => array("IMG"=> "images/fai_packages.png", "NAME"=>"Package list" , "KZL"=> "PL", "VAR"=>"ShowPackages"),
208 "FAIscript" => array("IMG"=> "images/fai_script.png", "NAME"=>"Scripts" , "KZL"=> "S", "VAR"=>"ShowScripts"),
209 "FAIvariable" => array("IMG"=> "images/fai_variable.png", "NAME"=>"Variables" , "KZL"=> "V", "VAR"=>"ShowVariables"),
210 "FAIhook" => array("IMG"=> "images/fai_hook.png", "NAME"=>"Hooks", "KZL"=> "H", "VAR"=>"ShowHooks"),
211 "FAIprofile" => array("IMG"=> "images/fai_profile.png", "NAME"=>"Profile" , "KZL"=> "P", "VAR"=>"ShowProfiles"),
212 "FAItemplate" => array("IMG"=> "images/fai_template.png", "NAME"=>"Templates" , "KZL"=> "T", "VAR"=>"ShowTemplates"));
214 $editlink ="<a href='?plug=".$_GET['plug']."&edit_entry=%KEY%' title='%TITLE%'>%NAME%</a>";
216 /* Dynamic action col, depending on snapshot icons */
217 $action_col_size = 50;
218 if($this->parent->snapshotEnabled()){
219 $action_col_size += 20;
220 }
222 /********************
223 Attach objects
224 ********************/
226 foreach($list as $key => $value){
227 $info = "";
228 $img = "";
229 $type = $value['type'];
230 $abort =false;
232 if(isset($objects[$type])){
233 $img = "<img class='center' src='".$objects[$type]['IMG']."' title='".$objects[$type]['NAME']."' alt='".$objects[$type]['KZL']."'>";
234 $info = $objects[$type]['NAME'];
235 $var = $objects[$type]['VAR'];
236 }else{
237 $img = "<img class='center' src='images/empty.png' alt=''>";
238 $info = "";
239 $var = "";
240 }
242 if((isset($value['description']))&&(!empty($value['description']))){
243 $desc= " [".$value['description']."]";
244 }else{
245 $desc= "";
246 }
249 if($value['FAIstate'] == "freeze"){
250 $action= "<img src='images/closedlock.png' alt='F' class='center'><img src='images/empty.png' width='38' height='2' class='center' alt=''>";
251 $action.= "<input class='center' type='image' src='images/edit.png' alt='"._("edit")."'
252 name='entry_edit_%KEY%' title='"._("Edit class")."'>";
253 }else{
254 $action= "<input class='center' type='image' src='images/edit.png' alt='"._("edit")."'
255 name='entry_edit_%KEY%' title='"._("Edit class")."'>";
257 if(preg_match("/(c&w)/",$value['acl'])){
258 $action.= $this->GetSnapShotActions($value['dn']);;
259 }
261 if(preg_match("/d/",$value['acl'])){
262 $action.= "<input class='center' type='image' src='images/edittrash.png' alt='"._("delete")."'
263 name='entry_delete_%KEY%' title='"._("Delete class")."'>";
264 }
265 }
267 $edi = $editlink;
268 $acti = $action;
270 $field1 = array("string" => $img , "attach" => "style='text-align:center;width:20px;'");
271 $field2 = array("string" => preg_replace(array("/%KEY%/","/%NAME%/","/%TITLE%/"),array($key,$value['cn'].$desc,preg_replace('/ /', ' ', @LDAP::fix($value['dn']))),$edi) , "attach" => "style=''");
272 $field3 = array("string" => $info, "attach" => "style='width:200px;'");
273 $field4 = array("string" => preg_replace("/%KEY%/",$key,$acti) , "attach" => "style='width:".$action_col_size."px;border-right:0px;text-align:right;'");
274 $this->AddElement(array($field1,$field2,$field3,$field4));
275 }
276 }
278 function Save()
279 {
280 MultiSelectWindow::Save();
281 }
283 function save_object()
284 {
285 /* Save automatic created POSTs like regex, checkboxes */
286 MultiSelectWindow::save_object();
287 $_SESSION['faifilter']['branch'] = $this->selectedBranch;
288 }
289 }
290 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
291 ?>