dd6d643e677e0a16537edeecffd3c5a1bd470f70
1 <?php
2 /*
3 * This code is part of GOsa (http://www.gosa-project.org)
4 * Copyright (C) 2003-2008 GONICUS GmbH
5 *
6 * ID: $$Id$$
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
23 class divListACL extends MultiSelectWindow
24 {
26 /* Current base */
27 var $selectedBase = "";
28 var $departments = array();
30 /* Regex */
31 var $Regex = "*";
33 /* CheckBoxes */
35 /* Subsearch checkbox */
36 var $SubSearch = false;
38 var $parent ;
39 var $ui ;
40 var $action_col_size;
43 function divListACL (&$config, &$parent)
44 {
45 MultiSelectWindow::MultiSelectWindow($config, "ACLs", "acl");
47 $this->parent = &$parent;
48 $this->ui = get_userinfo();
50 /* Set list strings */
51 $this->SetTitle(_("List of acl"));
52 $this->SetSummary(_("List of acls"));
54 /* Result page will look like a headpage */
55 $this->SetHeadpageMode();
56 $this->SetInformation(_("This menu allows you to edit and delete selected acls."));
58 $this->EnableAplhabet (true);
60 /* Disable buttonsm */
61 $this->EnableCloseButton(false);
62 $this->EnableSaveButton (false);
64 /* Dynamic action col */
65 $this->action_col_size = 120;
67 /* Toggle all selected / deselected */
68 $chk = "<input type='checkbox' id='select_all' name='select_all'
69 onClick='toggle_all_(\"^item_selected_[0-9]*$\",\"select_all\");' >";
71 /* set Page header */
72 $this->AddHeader(array("string"=> $chk, "attach"=>"style='width:20px;'"));
73 $this->AddHeader(array("string"=>" ", "attach"=>"style='width:20px;'"));
74 $this->AddHeader(array("string"=>_("Summary")));
75 $this->AddHeader(array("string"=>_("Actions"), "attach" => "style='width:".$this->action_col_size."px;border-right:0px;text-align:right;'"));
77 /* Set dynamically filter checkboxes */
78 $this->set_filter_objectclasses();
80 /* Add SubSearch checkbox */
81 $this->AddCheckBox("SubSearch", _("Select to search within subtrees"), _("Ignore subtrees"), false);
84 /* Name ,Text ,Default , Connect with alphabet */
85 $this->AddRegex ("Regex", _("Display acls matching"),"*" , true);
86 }
89 function GenHeader()
90 {
91 /* Prepare departments,
92 which are shown in the listbox on top of the listbox
93 */
94 $options= "";
95 $Copy_Paste = "";
97 /* Get all departments within this subtree */
98 $ui= get_userinfo();
99 $first = "";
100 $found = FALSE;
101 $base = $this->config->current['BASE'];
103 /* Add base */
104 $tmp = array();
105 $tmp[] = array("dn"=>$this->config->current['BASE']);
106 $tmp= array_merge($tmp,get_list("(&(|(ou=*)(description=*))(objectClass=gosaDepartment))", $this->module, $base,
107 array("ou", "description"), GL_SIZELIMIT | GL_SUBSEARCH));
109 $deps = array();
110 foreach($tmp as $tm){
111 $deps[$tm['dn']] = $tm['dn'];
112 }
114 /* Load possible departments */
115 $ui= get_userinfo();
116 $tdeps= $ui->get_module_departments("acl");
117 $ids = $this->config->idepartments;
118 $first = "";
119 $found = FALSE;
120 foreach($ids as $dep => $name){
121 if(isset($deps[$dep]) && in_array_ics($dep, $tdeps)){
123 /* Keep first base dn in mind, we could need this
124 * info if no valid base was found
125 */
126 if(empty($first)) {
127 $first = $dep['dn'];
128 }
130 $value = $ids[$dep];
131 if ($this->selectedBase == $dep){
132 $found = TRUE;
133 $options.= "<option selected='selected' value='".$dep."'>$value</option>";
134 } else {
135 $options.= "<option value='".$dep."'>$value</option>";
136 }
137 }
138 }
140 /* The currently used base is not visible with your acl setup.
141 * Set base to first useable base.
142 */
143 if(!$found){
144 $this->selectedBase = $first;
145 }
147 /* Allow copy & paste for roles */
148 $acl_all = $ui->has_complete_category_acls($this->selectedBase,"acl");
149 $acl = $ui->get_permissions($this->selectedBase,"acl/acl");
151 /* Add default header */
152 $listhead = MultiSelectWindow::get_default_header();
153 $listhead .=
154 _("Base")." <select name='CurrentMainBase' onChange='mainform.submit()' class='center'>$options</select>".
155 " <input class='center' type='image' src='images/list_submit.png' align='middle'
156 title='"._("Submit department")."' name='submit_department' alt='". _("Submit")."'> ";
159 /* Create Layers menu */
160 $s = ".|"._("Actions")."|\n";
161 $s .= "..|<img src='images/list_new.png' alt='' border='0' class='center'>".
162 " "._("Create")."|\n";
164 /* Append create options */
165 if(preg_match("/c/",$acl)) {
166 $s.= "...|<input class='center' type='image' src='images/list_new_acl_role.png' alt=''>".
167 " "._("Role")."|new_acl_role|\n";
168 }
170 /* Multiple options */
171 $s.= "..|---|\n";
172 $s.= "..|<img src='images/edittrash.png' alt='' border='0' class='center'>".
173 " "._("Remove")."|"."remove_multiple|\n";
175 /* Add multiple copy & cut icons */
176 if(is_object($this->parent->CopyPasteHandler)){
177 $s.= "..|---|\n";
178 $s.= "..|<img src='images/editcopy.png' alt='' border='0' class='center'>".
179 " "._("Copy")."|"."multiple_copy_systems|\n";
180 $s.= "..|<img src='images/editcut.png' alt='' border='0' class='center'>".
181 " "._("Cut")."|"."multiple_cut_systems|\n";
183 if($this->parent->CopyPasteHandler->entries_queued()){
184 $img = "<img border='0' class='center' src='images/editpaste.png' alt=''>";
185 $s.="..|".$img." "._("Paste")."|editPaste|\n";
186 }else{
187 $img = "<img border='0' class='center' src='images/cant_editpaste.png' alt=''>";
188 $s.="..|".$img." "._("Paste")."\n";
189 }
190 }
192 /* Add snapshot icons */
193 if(preg_match("/(c.*w|w.*c)/",$acl_all)){
194 $str = $this->get_snapshot_header(TRUE) ;
195 if(!empty($str)){
196 $s .= "..|---|\n";
197 $s .= $str;
198 }
199 }
201 $this->SetDropDownHeaderMenu($s);
202 $this->SetListHeader($listhead);
203 }
205 /* so some basic settings */
206 function execute()
207 {
208 $this->ClearElementsList();
209 $this->GenHeader();
210 }
212 function setEntries($list)
213 {
215 foreach($list as $key => $acl_entry){
217 /* Get copy & paste icon */
218 $acl = $this->ui->get_permissions($acl_entry['dn'],"acl/acl");
219 $acl_all = $this->ui->has_complete_category_acls($acl_entry['dn'],"acl");
220 $action = "";
222 if(in_array("gosaRole",$acl_entry['objectClass'])){
224 /* Role handling */
225 $editlink = "<a href='?plug=".$_GET['plug']."&id=%s&act=list_edit_role'>%s</a>";
226 $list_left_icon = "<img src='images/select_acl_role.png' alt='"._("Role")."'>";
227 $cn = htmlentities(utf8_decode($acl_entry['cn'][0])) ;
229 if(isset($acl_entry['description'][0])){
230 $cn .= " [".$acl_entry['description'][0]."]";
231 }
233 /* Add copy & paste handler */
234 if(($this->parent->CopyPasteHandler) && preg_match("/(c.*w|w.*c)/",$acl_all)){
235 $action.= "<input class='center' type='image'
236 src='images/editcut.png' alt='"._("cut")."' name='cut_%KEY%' title='"._("Cut this entry")."'> ";
237 $action.= "<input class='center' type='image'
238 src='images/editcopy.png' alt='"._("copy")."' name='copy_%KEY%' title='"._("Copy this entry")."'> ";
239 }
241 /* Add actions depending on acls */
242 if(preg_match("/r/", $acl)){
243 $action.= "<input class='center' type='image' src='images/edit.png' alt='"._("edit")."'
244 name='list_acl_role_edit_%KEY%' title='"._("Edit acl role")."'>";
245 }
247 /* Add snapshot functionality */
248 if(preg_match("/(c.*w|w.*c)/", $acl_all)){
249 $action.= $this->GetSnapShotActions($acl_entry['dn']);
250 }
252 if(preg_match("/d/", $acl)){
253 $action.= "<input class='center' type='image' src='images/edittrash.png' alt='"._("delete")."'
254 name='list_acl_role_del_%KEY%' title='"._("Delete acl role")."'>";
255 }
256 }else{
258 /* Acl handling */
259 $editlink = "<a href='?plug=".$_GET['plug']."&id=%s&act=list_edit_entry'>%s</a>";
260 $list_left_icon = "<img src='images/select_acl.png' alt='"._("Acl")."'>";
261 $cn = htmlentities(utf8_decode($acl_entry['dn']));
263 /* Add actions depending on acls */
264 if(preg_match("/r/", $acl)){
265 $action.= "<input class='center' type='image' src='images/edit.png' alt='"._("edit")."'
266 name='list_acl_edit_%KEY%' title='"._("Edit acl")."'>";
267 }
268 if(preg_match("/d/", $acl)){
269 $action.= "<input class='center' type='image' src='images/edittrash.png' alt='"._("delete")."'
270 name='list_acl_del_%KEY%' title='"._("Delete acl")."'>";
271 }
272 }
274 if(in_array("gosaRole",$acl_entry['objectClass'])){
275 $field0 = array("string" => "<input type='checkbox' id='item_selected_".$key."' name='item_selected_".$key."'>" ,
276 "attach" => "style='width:20px;'");
277 }else{
278 $field0 = array("string" => "", "attach" => "style='width:20px;'");
279 }
281 /* Cutted objects should be displayed in light grey */
282 $display = $cn;
283 if($this->parent->CopyPasteHandler){
284 foreach($this->parent->CopyPasteHandler->queue as $queue_key => $queue_data){
285 if($queue_data['dn'] == $acl_entry['dn']) {
286 $display = "<font color='#999999'>".$display."</font>";
287 break;
288 }
289 }
290 }
292 $field1 = array("string" => $list_left_icon, "attach"=> "style='text-align:center;width:20px;'");
293 $field2 = array("string" => sprintf($editlink,$key,$display)." ","attach" => "");
294 $field3 = array("string" => preg_replace("/%KEY%/",$key,$action), "attach"=> "style='text-align:right;width:".$this->action_col_size."px;border-right:0px;'");
295 $this->AddElement(array($field0,$field1,$field2,$field3));
296 }
297 }
299 function Save()
300 {
301 MultiSelectWindow :: Save();
302 }
304 function save_object()
305 {
306 /* Save automatic created POSTs like regex, checkboxes */
307 MultiSelectWindow::save_object();
308 }
311 /* Add some additional checkboxes to the filter part, this should be generated dynamically. */
312 function set_filter_objectclasses()
313 {
314 }
316 /* Return objectClass names used in filter part */
317 function get_filter_objectclasses()
318 {
319 return(array("gosaAccount","gosaDepartment"));
320 }
324 }
325 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
326 ?>