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 & paste handler */
210 if($ui->is_cutable($acl_entry['dn'],"aclroles","aclRole") && $this->parent->CopyPasteHandler){
211 $action .= "<input class='center' type='image'
212 src='images/lists/cut.png' alt='"._("cut")."' name='cut_%KEY%' title='"._("Cut this entry")."'> ";
213 }else{
214 $action.="<img src='images/empty.png' alt=' ' class='center'> ";
215 }
217 if($ui->is_copyable($acl_entry['dn'],"aclroles","aclRole") && $this->parent->CopyPasteHandler){
218 $action.= "<input class='center' type='image'
219 src='images/lists/copy.png' alt='"._("copy")."' name='copy_%KEY%' title='"._("Copy this entry")."'> ";
220 }else{
221 $action.="<img src='images/empty.png' alt=' ' class='center'> ";
222 }
225 /* Add actions depending on acls */
226 if(preg_match("/r/", $acl)){
227 $action.= "<input class='center' type='image' src='images/lists/edit.png' alt='"._("edit")."'
228 name='list_acl_role_edit_%KEY%' title='"._("Edit acl role")."'>";
229 }
231 /* Add snapshot functionality */
232 $action.= $this->parent->get_snapshot_action($acl_entry['dn'],"aclroles");
234 if(preg_match("/d/", $acl)){
235 $action.= "<input class='center' type='image' src='images/lists/trash.png' alt='"._("delete")."'
236 name='list_acl_role_del_%KEY%' title='"._("Delete acl role")."'>";
237 }
239 $field0 = array("string" => "<input type='checkbox' id='item_selected_".$key."' name='item_selected_".$key."'>" ,
240 "attach" => "style='width:20px;'");
242 }else{
244 $acl = $this->ui->get_permissions($acl_entry['dn'],"acl/acl");
245 $acl_all = $this->ui->has_complete_category_acls($acl_entry['dn'],"acl");
247 /* Acl handling */
248 $editlink = "<a href='?plug=".$_GET['plug']."&id=%s&act=list_edit_entry'>%s</a>";
249 $list_left_icon = "<img src='images/lists/locked.png' alt='"._("ACL")."'>";
250 $cn = htmlentities(utf8_decode($acl_entry['dn']));
252 /* Add actions depending on acls */
253 if(preg_match("/r/", $acl)){
254 $action.= "<input class='center' type='image' src='images/lists/edit.png' alt='"._("edit")."'
255 name='list_acl_edit_%KEY%' title='"._("Edit acl")."'>";
256 }
257 if(preg_match("/d/", $acl)){
258 $action.= "<input class='center' type='image' src='images/lists/trash.png' alt='"._("delete")."'
259 name='list_acl_del_%KEY%' title='"._("Delete acl")."'>";
260 }
261 $field0 = array("string" => "", "attach" => "style='width:20px;'");
262 }
264 /* Cutted objects should be displayed in light grey */
265 $display = $cn;
266 if($this->parent->CopyPasteHandler){
267 foreach($this->parent->CopyPasteHandler->queue as $queue_key => $queue_data){
268 if($queue_data['dn'] == $acl_entry['dn']) {
269 $display = "<font color='#999999'>".$display."</font>";
270 break;
271 }
272 }
273 }
275 $field1 = array("string" => $list_left_icon, "attach"=> "style='text-align:center;width:20px;'");
276 $field2 = array("string" => sprintf($editlink,$key,$display)." ","attach" => "");
277 $field3 = array("string" => preg_replace("/%KEY%/",$key,$action), "attach"=> "style='text-align:right;width:".$this->action_col_size."px;border-right:0px;'");
278 $this->AddElement(array($field0,$field1,$field2,$field3));
279 }
280 }
282 function Save()
283 {
284 MultiSelectWindow :: Save();
285 }
287 function save_object()
288 {
289 /* Save automatic created POSTs like regex, checkboxes */
290 MultiSelectWindow::save_object();
291 }
294 /* Add some additional checkboxes to the filter part, this should be generated dynamically. */
295 function set_filter_objectclasses()
296 {
297 }
299 /* Return objectClass names used in filter part */
300 function get_filter_objectclasses()
301 {
302 return(array("gosaAccount","gosaDepartment"));
303 }
307 }
308 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
309 ?>