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", array("acl","aclroles"));
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";
172 /* Add Copy & Paste header */
173 $s .= $this->parent->get_copypaste_header($this->selectedBase,$this->module);
175 $s .= $this->parent->get_snapshot_header($this->selectedBase,$this->module);
177 $this->SetDropDownHeaderMenu($s);
178 $this->SetListHeader($listhead);
179 }
181 /* so some basic settings */
182 function execute()
183 {
184 $this->ClearElementsList();
185 $this->GenHeader();
186 }
188 function setEntries($list)
189 {
190 $ui = get_userinfo();
191 foreach($list as $key => $acl_entry){
193 $action = "";
195 if(in_array("gosaRole",$acl_entry['objectClass'])){
197 /* Role handling */
198 $acl = $this->ui->get_permissions($acl_entry['dn'],"aclroles/aclRole");
199 $acl_all = $this->ui->has_complete_category_acls($acl_entry['dn'],"aclroles");
201 $editlink = "<a href='?plug=".$_GET['plug']."&id=%s&act=list_edit_role'>%s</a>";
202 $list_left_icon = "<img src='plugins/acl/images/role.png' alt='"._("Role")."'>";
203 $cn = htmlentities(utf8_decode($acl_entry['cn'][0])) ;
205 if(isset($acl_entry['description'][0])){
206 $cn .= " [".$acl_entry['description'][0]."]";
207 }
209 /* Add copy & cut functionality */
210 $action.= $this->parent->get_copypaste_action($acl_entry['dn'],"aclroles","aclRole");
212 /* Add actions depending on acls */
213 if(preg_match("/r/", $acl)){
214 $action.= "<input class='center' type='image' src='images/lists/edit.png' alt='"._("edit")."'
215 name='list_acl_role_edit_%KEY%' title='"._("Edit acl role")."'>";
216 }
218 /* Add snapshot functionality */
219 $action.= $this->parent->get_snapshot_action($acl_entry['dn'],"aclroles");
221 if(preg_match("/d/", $acl)){
222 $action.= "<input class='center' type='image' src='images/lists/trash.png' alt='"._("delete")."'
223 name='list_acl_role_del_%KEY%' title='"._("Delete acl role")."'>";
224 }
226 $field0 = array("string" => "<input type='checkbox' id='item_selected_".$key."' name='item_selected_".$key."'>" ,
227 "attach" => "style='width:20px;'");
229 }else{
231 $acl = $this->ui->get_permissions($acl_entry['dn'],"acl/acl");
232 $acl_all = $this->ui->has_complete_category_acls($acl_entry['dn'],"acl");
234 /* Acl handling */
235 $editlink = "<a href='?plug=".$_GET['plug']."&id=%s&act=list_edit_entry'>%s</a>";
236 $list_left_icon = "<img src='images/lists/locked.png' alt='"._("ACL")."'>";
237 $cn = htmlentities(utf8_decode($acl_entry['dn']));
239 /* Add actions depending on acls */
240 if(preg_match("/r/", $acl)){
241 $action.= "<input class='center' type='image' src='images/lists/edit.png' alt='"._("edit")."'
242 name='list_acl_edit_%KEY%' title='"._("Edit acl")."'>";
243 }
244 if(preg_match("/d/", $acl)){
245 $action.= "<input class='center' type='image' src='images/lists/trash.png' alt='"._("delete")."'
246 name='list_acl_del_%KEY%' title='"._("Delete acl")."'>";
247 }
248 $field0 = array("string" => "", "attach" => "style='width:20px;'");
249 }
251 /* Cutted objects should be displayed in light grey */
252 $display = $cn;
253 if($this->parent->CopyPasteHandler){
254 foreach($this->parent->CopyPasteHandler->queue as $queue_key => $queue_data){
255 if($queue_data['dn'] == $acl_entry['dn']) {
256 $display = "<font color='#999999'>".$display."</font>";
257 break;
258 }
259 }
260 }
262 $field1 = array("string" => $list_left_icon, "attach"=> "style='text-align:center;width:20px;'");
263 $field2 = array("string" => sprintf($editlink,$key,$display)." ","attach" => "");
264 $field3 = array("string" => preg_replace("/%KEY%/",$key,$action), "attach"=> "style='text-align:right;width:".$this->action_col_size."px;border-right:0px;'");
265 $this->AddElement(array($field0,$field1,$field2,$field3));
266 }
267 }
269 function Save()
270 {
271 MultiSelectWindow :: Save();
272 }
274 function save_object()
275 {
276 /* Save automatic created POSTs like regex, checkboxes */
277 MultiSelectWindow::save_object();
278 }
281 /* Add some additional checkboxes to the filter part, this should be generated dynamically. */
282 function set_filter_objectclasses()
283 {
284 }
286 /* Return objectClass names used in filter part */
287 function get_filter_objectclasses()
288 {
289 return(array("gosaAccount","gosaDepartment"));
290 }
294 }
295 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
296 ?>