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, "ACL", "acl");
47 $this->parent = &$parent;
48 $this->ui = get_userinfo();
50 /* Set list strings */
51 $this->SetTitle(_("List of acls"));
52 $this->SetSummary(_("List of acls"));
54 /* Result page will look like a headpage */
55 $this->SetHeadpageMode();
57 $this->EnableAplhabet (true);
59 /* Disable buttonsm */
60 $this->EnableCloseButton(false);
61 $this->EnableSaveButton (false);
63 /* Dynamic action col */
64 $this->action_col_size = 120;
66 /* Toggle all selected / deselected */
67 $chk = "<input type='checkbox' id='select_all' name='select_all' title='"._("Select all")."'
68 onClick='toggle_all_(\"^item_selected_[0-9]*$\",\"select_all\");' >";
70 /* set Page header */
71 $this->AddHeader(array("string"=> $chk, "attach"=>"style='width:20px;'"));
72 $this->AddHeader(array("string"=>" ", "attach"=>"style='width:20px;'"));
73 $this->AddHeader(array("string"=>_("Summary")));
74 $this->AddHeader(array("string"=>_("Actions"), "attach" => "style='width:".$this->action_col_size."px;border-right:0px;text-align:right;'"));
76 /* Set dynamically filter checkboxes */
77 $this->set_filter_objectclasses();
79 /* Add SubSearch checkbox */
80 $this->AddCheckBox("SubSearch", msgPool::selectToView("","subsearch"), msgPool::selectToView("","subsearch_small"), false);
83 /* Name ,Text ,Default , Connect with alphabet */
84 $this->AddRegex ("Regex", _("Display acls matching"),"*" , true);
85 }
88 function GenHeader()
89 {
90 /* Prepare departments,
91 which are shown in the listbox on top of the listbox
92 */
93 $options= "";
94 $Copy_Paste = "";
96 /* Get all departments within this subtree */
97 $ui= get_userinfo();
98 $first = "";
99 $found = FALSE;
100 $base = $this->config->current['BASE'];
102 /* Add base */
103 $tmp = array();
104 $tmp[] = array("dn"=>$this->config->current['BASE']);
105 $tmp= array_merge($tmp,get_list("(&(|(ou=*)(description=*))(objectClass=gosaDepartment))", $this->module, $base,
106 array("ou", "description"), GL_SIZELIMIT | GL_SUBSEARCH));
108 $deps = array();
109 foreach($tmp as $tm){
110 $deps[$tm['dn']] = $tm['dn'];
111 }
113 /* Load possible departments */
114 $ui= get_userinfo();
115 $tdeps= $ui->get_module_departments("acl");
116 $ids = $this->config->idepartments;
117 $first = "";
118 $found = FALSE;
119 foreach($ids as $dep => $name){
120 if(isset($deps[$dep]) && in_array_ics($dep, $tdeps)){
122 /* Keep first base dn in mind, we could need this
123 * info if no valid base was found
124 */
125 if(empty($first)) {
126 $first = $dep['dn'];
127 }
129 $value = $ids[$dep];
130 if ($this->selectedBase == $dep){
131 $found = TRUE;
132 $options.= "<option selected='selected' value='".$dep."'>$value</option>";
133 } else {
134 $options.= "<option value='".$dep."'>$value</option>";
135 }
136 }
137 }
139 /* The currently used base is not visible with your acl setup.
140 * Set base to first useable base.
141 */
142 if(!$found){
143 $this->selectedBase = $first;
144 }
146 /* Allow copy & paste for roles */
147 $acl_all = $ui->has_complete_category_acls($this->selectedBase,"acl");
148 $acl = $ui->get_permissions($this->selectedBase,"acl/acl");
150 /* Add default header */
151 $listhead = MultiSelectWindow::get_default_header();
152 $listhead .=
153 _("Base")." <select name='CurrentMainBase' onChange='mainform.submit()' class='center'>$options</select>".
154 " <input class='center' type='image' src='images/lists/submit.png' align='middle'
155 title='"._("Submit department")."' name='submit_department' alt='". _("Submit")."'> ";
158 /* Create Layers menu */
159 $s = ".|"._("Actions")."|\n";
160 /* Append create options */
161 if(preg_match("/c/",$acl)) {
162 $s .= "..|<img src='images/lists/new.png' alt='' border='0' class='center'>".
163 " "._("Create")."|\n";
164 $s.= "...|<input class='center' type='image' src='plugins/acl/images/new-role.png' alt=''>".
165 " "._("Role")."|new_acl_role|\n";
166 }
168 $s.= "..|<img src='images/lists/trash.png' alt='' border='0' class='center'>".
169 " "._("Remove")."|"."remove_multiple|\n";
171 if(is_object($this->parent->CopyPasteHandler) && preg_match("/r/",$acl_all)){
172 $s.= "..|---|\n";
173 $s.= "..|<img src='images/lists/copy.png' alt='' border='0' class='center'>".
174 " "._("Copy")."|"."multiple_copy_systems|\n";
175 $s.= "..|<img src='images/lists/cut.png' alt='' border='0' class='center'>".
176 " "._("Cut")."|"."multiple_cut_systems|\n";
177 }
179 /* Copy & paste icons */
180 if(is_object($this->parent->CopyPasteHandler) && $this->parent->CopyPasteHandler->entries_queued()){
181 $img = "<img border='0' class='center' src='images/lists/paste.png' alt=''>";
182 $s.="..|".$img." "._("Paste")."|editPaste|\n";
183 }else{
184 $img = "<img border='0' class='center' src='images/lists/paste-grey.png' alt=''>";
185 $s.="..|".$img." "._("Paste")."\n";
186 }
188 /* Add snapshot icons */
189 if(preg_match("/(c.*w|w.*c)/",$acl_all)){
190 $s .= "..|---|\n";
191 $s .= $this->get_snapshot_header(TRUE);
192 }
194 $this->SetDropDownHeaderMenu($s);
195 $this->SetListHeader($listhead);
196 }
198 /* so some basic settings */
199 function execute()
200 {
201 $this->ClearElementsList();
202 $this->GenHeader();
203 }
205 function setEntries($list)
206 {
207 $ui = get_userinfo();
208 foreach($list as $key => $acl_entry){
210 /* Get copy & paste icon */
211 $acl = $this->ui->get_permissions($acl_entry['dn'],"acl/acl");
212 $acl_all = $this->ui->has_complete_category_acls($acl_entry['dn'],"acl");
213 $action = "";
215 if(in_array("gosaRole",$acl_entry['objectClass'])){
217 /* Role handling */
218 $editlink = "<a href='?plug=".$_GET['plug']."&id=%s&act=list_edit_role'>%s</a>";
219 $list_left_icon = "<img src='plugins/acl/images/role.png' alt='"._("Role")."'>";
220 $cn = htmlentities(utf8_decode($acl_entry['cn'][0])) ;
222 if(isset($acl_entry['description'][0])){
223 $cn .= " [".$acl_entry['description'][0]."]";
224 }
226 /* Add copy & paste handler */
227 if($ui->is_cutable($acl_entry['dn'],"acl","aclRole") && $this->parent->CopyPasteHandler){
228 $action .= "<input class='center' type='image'
229 src='images/lists/cut.png' alt='"._("cut")."' name='cut_%KEY%' title='"._("Cut this entry")."'> ";
230 }else{
231 $action.="<img src='images/empty.png' alt=' ' class='center'> ";
232 }
234 if($ui->is_copyable($acl_entry['dn'],"acl","aclRole") && $this->parent->CopyPasteHandler){
235 $action.= "<input class='center' type='image'
236 src='images/lists/copy.png' alt='"._("copy")."' name='copy_%KEY%' title='"._("Copy this entry")."'> ";
237 }else{
238 $action.="<img src='images/empty.png' alt=' ' class='center'> ";
239 }
242 /* Add actions depending on acls */
243 if(preg_match("/r/", $acl)){
244 $action.= "<input class='center' type='image' src='images/lists/edit.png' alt='"._("edit")."'
245 name='list_acl_role_edit_%KEY%' title='"._("Edit acl role")."'>";
246 }
248 /* Add snapshot functionality */
249 if(preg_match("/(c.*w|w.*c)/", $acl_all)){
250 $action.= $this->GetSnapShotActions($acl_entry['dn']);
251 }
253 if(preg_match("/d/", $acl)){
254 $action.= "<input class='center' type='image' src='images/lists/trash.png' alt='"._("delete")."'
255 name='list_acl_role_del_%KEY%' title='"._("Delete acl role")."'>";
256 }
257 }else{
259 /* Acl handling */
260 $editlink = "<a href='?plug=".$_GET['plug']."&id=%s&act=list_edit_entry'>%s</a>";
261 $list_left_icon = "<img src='images/lists/locked.png' alt='"._("ACL")."'>";
262 $cn = htmlentities(utf8_decode($acl_entry['dn']));
264 /* Add actions depending on acls */
265 if(preg_match("/r/", $acl)){
266 $action.= "<input class='center' type='image' src='images/lists/edit.png' alt='"._("edit")."'
267 name='list_acl_edit_%KEY%' title='"._("Edit acl")."'>";
268 }
269 if(preg_match("/d/", $acl)){
270 $action.= "<input class='center' type='image' src='images/lists/trash.png' alt='"._("delete")."'
271 name='list_acl_del_%KEY%' title='"._("Delete acl")."'>";
272 }
273 }
275 if(in_array("gosaRole",$acl_entry['objectClass'])){
276 $field0 = array("string" => "<input type='checkbox' id='item_selected_".$key."' name='item_selected_".$key."'>" ,
277 "attach" => "style='width:20px;'");
278 }else{
279 $field0 = array("string" => "", "attach" => "style='width:20px;'");
280 }
282 /* Cutted objects should be displayed in light grey */
283 $display = $cn;
284 if($this->parent->CopyPasteHandler){
285 foreach($this->parent->CopyPasteHandler->queue as $queue_key => $queue_data){
286 if($queue_data['dn'] == $acl_entry['dn']) {
287 $display = "<font color='#999999'>".$display."</font>";
288 break;
289 }
290 }
291 }
293 $field1 = array("string" => $list_left_icon, "attach"=> "style='text-align:center;width:20px;'");
294 $field2 = array("string" => sprintf($editlink,$key,$display)." ","attach" => "");
295 $field3 = array("string" => preg_replace("/%KEY%/",$key,$action), "attach"=> "style='text-align:right;width:".$this->action_col_size."px;border-right:0px;'");
296 $this->AddElement(array($field0,$field1,$field2,$field3));
297 }
298 }
300 function Save()
301 {
302 MultiSelectWindow :: Save();
303 }
305 function save_object()
306 {
307 /* Save automatic created POSTs like regex, checkboxes */
308 MultiSelectWindow::save_object();
309 }
312 /* Add some additional checkboxes to the filter part, this should be generated dynamically. */
313 function set_filter_objectclasses()
314 {
315 }
317 /* Return objectClass names used in filter part */
318 function get_filter_objectclasses()
319 {
320 return(array("gosaAccount","gosaDepartment"));
321 }
325 }
326 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
327 ?>