1 <?php
3 class divListACL extends MultiSelectWindow
4 {
6 /* Current base */
7 var $selectedBase = "";
8 var $departments = array();
10 /* Regex */
11 var $Regex = "*";
13 /* CheckBoxes */
15 /* Subsearch checkbox */
16 var $SubSearch = false;
18 var $parent ;
19 var $ui ;
20 var $action_col_size;
23 function divListACL (&$config, &$parent)
24 {
25 MultiSelectWindow::MultiSelectWindow($config, "ACLs", "acl");
27 $this->parent = &$parent;
28 $this->ui = get_userinfo();
30 /* Set list strings */
31 $this->SetTitle(_("List of acl"));
32 $this->SetSummary(_("List of acls"));
34 /* Result page will look like a headpage */
35 $this->SetHeadpageMode();
36 $this->SetInformation(_("This menu allows you to edit and delete selected acls."));
38 $this->EnableAplhabet (true);
40 /* Disable buttonsm */
41 $this->EnableCloseButton(false);
42 $this->EnableSaveButton (false);
44 /* Dynamic action col */
45 $this->action_col_size = 120;
47 /* Toggle all selected / deselected */
48 $chk = "<input type='checkbox' id='select_all' name='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='width:20px;'"));
54 $this->AddHeader(array("string"=>_("Summary")));
55 $this->AddHeader(array("string"=>_("Actions"), "attach" => "style='width:".$this->action_col_size."px;border-right:0px;text-align:right;'"));
57 /* Set dynamically filter checkboxes */
58 $this->set_filter_objectclasses();
60 /* Add SubSearch checkbox */
61 $this->AddCheckBox("SubSearch", _("Select to search within subtrees"), _("Ignore subtrees"), false);
64 /* Name ,Text ,Default , Connect with alphabet */
65 $this->AddRegex ("Regex", _("Display acls matching"),"*" , true);
66 }
69 function GenHeader()
70 {
71 /* Prepare departments,
72 which are shown in the listbox on top of the listbox
73 */
74 $options= "";
75 $Copy_Paste = "";
77 /* Get all departments within this subtree */
78 $ui= get_userinfo();
79 $first = "";
80 $found = FALSE;
81 $base = $this->config->current['BASE'];
83 /* Add base */
84 $tmp = array();
85 $tmp[] = array("dn"=>$this->config->current['BASE']);
86 $tmp= array_merge($tmp,get_list("(&(|(ou=*)(description=*))(objectClass=gosaDepartment))", $this->module, $base,
87 array("ou", "description"), GL_SIZELIMIT | GL_SUBSEARCH));
89 $deps = array();
90 foreach($tmp as $tm){
91 $deps[$tm['dn']] = $tm['dn'];
92 }
94 /* Load possible departments */
95 $ui= get_userinfo();
96 $tdeps= $ui->get_module_departments("acl");
97 $ids = $this->config->idepartments;
98 $first = "";
99 $found = FALSE;
100 foreach($ids as $dep => $name){
101 if(isset($deps[$dep]) && in_array_ics($dep, $tdeps)){
103 /* Keep first base dn in mind, we could need this
104 * info if no valid base was found
105 */
106 if(empty($first)) {
107 $first = $dep['dn'];
108 }
110 $value = $ids[$dep];
111 if ($this->selectedBase == $dep){
112 $found = TRUE;
113 $options.= "<option selected='selected' value='".$dep."'>$value</option>";
114 } else {
115 $options.= "<option value='".$dep."'>$value</option>";
116 }
117 }
118 }
120 /* The currently used base is not visible with your acl setup.
121 * Set base to first useable base.
122 */
123 if(!$found){
124 $this->selectedBase = $first;
125 }
127 /* Allow copy & paste for roles */
128 $acl_all = $ui->has_complete_category_acls($this->selectedBase,"acl");
129 $acl = $ui->get_permissions($this->selectedBase,"acl/acl");
131 /* Add default header */
132 $listhead = MultiSelectWindow::get_default_header();
133 $listhead .=
134 _("Base")." <select name='CurrentMainBase' onChange='mainform.submit()' class='center'>$options</select>".
135 " <input class='center' type='image' src='images/list_submit.png' align='middle'
136 title='"._("Submit department")."' name='submit_department' alt='". _("Submit")."'> ";
139 /* Create Layers menu */
140 $s = ".|"._("Actions")."|\n";
141 $s .= "..|<img src='images/list_new.png' alt='' border='0' class='center'>".
142 " "._("Create")."|\n";
144 /* Append create options */
145 if(preg_match("/c/",$acl)) {
146 $s.= "...|<input class='center' type='image' src='images/list_new_acl_role.png' alt=''>".
147 " "._("Role")."|new_acl_role|\n";
148 }
150 /* Multiple options */
151 $s.= "..|---|\n";
152 $s.= "..|<img src='images/edittrash.png' alt='' border='0' class='center'>".
153 " "._("Remove")."|"."remove_multiple|\n";
155 /* Add multiple copy & cut icons */
156 if(is_object($this->parent->CopyPasteHandler)){
157 $s.= "..|---|\n";
158 $s.= "..|<img src='images/editcopy.png' alt='' border='0' class='center'>".
159 " "._("Copy")."|"."multiple_copy_systems|\n";
160 $s.= "..|<img src='images/editcut.png' alt='' border='0' class='center'>".
161 " "._("Cut")."|"."multiple_cut_systems|\n";
163 if($this->parent->CopyPasteHandler->entries_queued()){
164 $img = "<img border='0' class='center' src='images/editpaste.png' alt=''>";
165 $s.="..|".$img." "._("Paste")."|editPaste|\n";
166 }else{
167 $img = "<img border='0' class='center' src='images/cant_editpaste.png' alt=''>";
168 $s.="..|".$img." "._("Paste")."\n";
169 }
170 }
172 /* Add snapshot icons */
173 if(preg_match("/(c.*w|w.*c)/",$acl_all)){
174 $str = $this->get_snapshot_header(TRUE) ;
175 if(!empty($str)){
176 $s .= "..|---|\n";
177 $s .= $str;
178 }
179 }
181 $this->SetDropDownHeaderMenu($s);
182 $this->SetListHeader($listhead);
183 }
185 /* so some basic settings */
186 function execute()
187 {
188 $this->ClearElementsList();
189 $this->GenHeader();
190 }
192 function setEntries($list)
193 {
195 foreach($list as $key => $acl_entry){
197 /* Get copy & paste icon */
198 $acl = $this->ui->get_permissions($acl_entry['dn'],"acl/acl");
199 $acl_all = $this->ui->has_complete_category_acls($acl_entry['dn'],"acl");
200 $action = "";
202 if(in_array("gosaRole",$acl_entry['objectClass'])){
204 /* Role handling */
205 $editlink = "<a href='?plug=".$_GET['plug']."&id=%s&act=list_edit_role'>%s</a>";
206 $list_left_icon = "<img src='images/select_acl_role.png' alt='"._("Role")."'>";
207 $cn = htmlentities(utf8_decode($acl_entry['cn'][0])) ;
209 if(isset($acl_entry['description'][0])){
210 $cn .= " [".$acl_entry['description'][0]."]";
211 }
213 /* Add copy & paste handler */
214 if(($this->parent->CopyPasteHandler) && preg_match("/(c.*w|w.*c)/",$acl_all)){
215 $action.= "<input class='center' type='image'
216 src='images/editcut.png' alt='"._("cut")."' name='cut_%KEY%' title='"._("Cut this entry")."'> ";
217 $action.= "<input class='center' type='image'
218 src='images/editcopy.png' alt='"._("copy")."' name='copy_%KEY%' title='"._("Copy this entry")."'> ";
219 }
221 /* Add actions depending on acls */
222 if(preg_match("/r/", $acl)){
223 $action.= "<input class='center' type='image' src='images/edit.png' alt='"._("edit")."'
224 name='list_acl_role_edit_%KEY%' title='"._("Edit acl role")."'>";
225 }
227 /* Add snapshot functionality */
228 if(preg_match("/(c.*w|w.*c)/", $acl_all)){
229 $action.= $this->GetSnapShotActions($acl_entry['dn']);
230 }
232 if(preg_match("/d/", $acl)){
233 $action.= "<input class='center' type='image' src='images/edittrash.png' alt='"._("delete")."'
234 name='list_acl_role_del_%KEY%' title='"._("Delete acl role")."'>";
235 }
236 }else{
238 /* Acl handling */
239 $editlink = "<a href='?plug=".$_GET['plug']."&id=%s&act=list_edit_entry'>%s</a>";
240 $list_left_icon = "<img src='images/select_acl.png' alt='"._("Acl")."'>";
241 $cn = htmlentities(utf8_decode($acl_entry['dn']));
243 /* Add actions depending on acls */
244 if(preg_match("/r/", $acl)){
245 $action.= "<input class='center' type='image' src='images/edit.png' alt='"._("edit")."'
246 name='list_acl_edit_%KEY%' title='"._("Edit acl")."'>";
247 }
248 if(preg_match("/d/", $acl)){
249 $action.= "<input class='center' type='image' src='images/edittrash.png' alt='"._("delete")."'
250 name='list_acl_del_%KEY%' title='"._("Delete acl")."'>";
251 }
252 }
254 if(in_array("gosaRole",$acl_entry['objectClass'])){
255 $field0 = array("string" => "<input type='checkbox' id='item_selected_".$key."' name='item_selected_".$key."'>" ,
256 "attach" => "style='width:20px;'");
257 }else{
258 $field0 = array("string" => "", "attach" => "style='width:20px;'");
259 }
261 /* Cutted objects should be displayed in light grey */
262 $display = $cn;
263 if($this->parent->CopyPasteHandler){
264 foreach($this->parent->CopyPasteHandler->queue as $queue_key => $queue_data){
265 if($queue_data['dn'] == $acl_entry['dn']) {
266 $display = "<font color='#999999'>".$display."</font>";
267 break;
268 }
269 }
270 }
272 $field1 = array("string" => $list_left_icon, "attach"=> "style='text-align:center;width:20px;'");
273 $field2 = array("string" => sprintf($editlink,$key,$display)." ","attach" => "");
274 $field3 = array("string" => preg_replace("/%KEY%/",$key,$action), "attach"=> "style='text-align:right;width:".$this->action_col_size."px;border-right:0px;'");
275 $this->AddElement(array($field0,$field1,$field2,$field3));
276 }
277 }
279 function Save()
280 {
281 MultiSelectWindow :: Save();
282 }
284 function save_object()
285 {
286 /* Save automatic created POSTs like regex, checkboxes */
287 MultiSelectWindow::save_object();
288 }
291 /* Add some additional checkboxes to the filter part, this should be generated dynamically. */
292 function set_filter_objectclasses()
293 {
294 }
296 /* Return objectClass names used in filter part */
297 function get_filter_objectclasses()
298 {
299 return(array("gosaAccount","gosaDepartment"));
300 }
304 }
305 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
306 ?>