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'
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/list_submit.png' align='middle'
155 title='"._("Submit department")."' name='submit_department' alt='". _("Submit")."'> ";
158 /* Create Layers menu */
159 $s = ".|"._("Actions")."|\n";
160 $s .= "..|<img src='images/list_new.png' alt='' border='0' class='center'>".
161 " "._("Create")."|\n";
163 /* Append create options */
164 if(preg_match("/c/",$acl)) {
165 $s.= "...|<input class='center' type='image' src='images/list_new_acl_role.png' alt=''>".
166 " "._("Role")."|new_acl_role|\n";
167 }
169 /* Multiple options */
170 $s.= "..|---|\n";
171 $s.= "..|<img src='images/edittrash.png' alt='' border='0' class='center'>".
172 " "._("Remove")."|"."remove_multiple|\n";
174 /* Add multiple copy & cut icons */
175 if(is_object($this->parent->CopyPasteHandler)){
176 $s.= "..|---|\n";
177 $s.= "..|<img src='images/editcopy.png' alt='' border='0' class='center'>".
178 " "._("Copy")."|"."multiple_copy_systems|\n";
179 $s.= "..|<img src='images/editcut.png' alt='' border='0' class='center'>".
180 " "._("Cut")."|"."multiple_cut_systems|\n";
182 if($this->parent->CopyPasteHandler->entries_queued()){
183 $img = "<img border='0' class='center' src='images/editpaste.png' alt=''>";
184 $s.="..|".$img." "._("Paste")."|editPaste|\n";
185 }else{
186 $img = "<img border='0' class='center' src='images/cant_editpaste.png' alt=''>";
187 $s.="..|".$img." "._("Paste")."\n";
188 }
189 }
191 /* Add snapshot icons */
192 if(preg_match("/(c.*w|w.*c)/",$acl_all)){
193 $str = $this->get_snapshot_header(TRUE) ;
194 if(!empty($str)){
195 $s .= "..|---|\n";
196 $s .= $str;
197 }
198 }
200 $this->SetDropDownHeaderMenu($s);
201 $this->SetListHeader($listhead);
202 }
204 /* so some basic settings */
205 function execute()
206 {
207 $this->ClearElementsList();
208 $this->GenHeader();
209 }
211 function setEntries($list)
212 {
214 foreach($list as $key => $acl_entry){
216 /* Get copy & paste icon */
217 $acl = $this->ui->get_permissions($acl_entry['dn'],"acl/acl");
218 $acl_all = $this->ui->has_complete_category_acls($acl_entry['dn'],"acl");
219 $action = "";
221 if(in_array("gosaRole",$acl_entry['objectClass'])){
223 /* Role handling */
224 $editlink = "<a href='?plug=".$_GET['plug']."&id=%s&act=list_edit_role'>%s</a>";
225 $list_left_icon = "<img src='images/select_acl_role.png' alt='"._("Role")."'>";
226 $cn = htmlentities(utf8_decode($acl_entry['cn'][0])) ;
228 if(isset($acl_entry['description'][0])){
229 $cn .= " [".$acl_entry['description'][0]."]";
230 }
232 /* Add copy & paste handler */
233 if(($this->parent->CopyPasteHandler) && preg_match("/(c.*w|w.*c)/",$acl_all)){
234 $action.= "<input class='center' type='image'
235 src='images/editcut.png' alt='"._("cut")."' name='cut_%KEY%' title='"._("Cut this entry")."'> ";
236 $action.= "<input class='center' type='image'
237 src='images/editcopy.png' alt='"._("copy")."' name='copy_%KEY%' title='"._("Copy this entry")."'> ";
238 }
240 /* Add actions depending on acls */
241 if(preg_match("/r/", $acl)){
242 $action.= "<input class='center' type='image' src='images/edit.png' alt='"._("edit")."'
243 name='list_acl_role_edit_%KEY%' title='"._("Edit acl role")."'>";
244 }
246 /* Add snapshot functionality */
247 if(preg_match("/(c.*w|w.*c)/", $acl_all)){
248 $action.= $this->GetSnapShotActions($acl_entry['dn']);
249 }
251 if(preg_match("/d/", $acl)){
252 $action.= "<input class='center' type='image' src='images/edittrash.png' alt='"._("delete")."'
253 name='list_acl_role_del_%KEY%' title='"._("Delete acl role")."'>";
254 }
255 }else{
257 /* Acl handling */
258 $editlink = "<a href='?plug=".$_GET['plug']."&id=%s&act=list_edit_entry'>%s</a>";
259 $list_left_icon = "<img src='images/select_acl.png' alt='"._("ACL")."'>";
260 $cn = htmlentities(utf8_decode($acl_entry['dn']));
262 /* Add actions depending on acls */
263 if(preg_match("/r/", $acl)){
264 $action.= "<input class='center' type='image' src='images/edit.png' alt='"._("edit")."'
265 name='list_acl_edit_%KEY%' title='"._("Edit acl")."'>";
266 }
267 if(preg_match("/d/", $acl)){
268 $action.= "<input class='center' type='image' src='images/edittrash.png' alt='"._("delete")."'
269 name='list_acl_del_%KEY%' title='"._("Delete acl")."'>";
270 }
271 }
273 if(in_array("gosaRole",$acl_entry['objectClass'])){
274 $field0 = array("string" => "<input type='checkbox' id='item_selected_".$key."' name='item_selected_".$key."'>" ,
275 "attach" => "style='width:20px;'");
276 }else{
277 $field0 = array("string" => "", "attach" => "style='width:20px;'");
278 }
280 /* Cutted objects should be displayed in light grey */
281 $display = $cn;
282 if($this->parent->CopyPasteHandler){
283 foreach($this->parent->CopyPasteHandler->queue as $queue_key => $queue_data){
284 if($queue_data['dn'] == $acl_entry['dn']) {
285 $display = "<font color='#999999'>".$display."</font>";
286 break;
287 }
288 }
289 }
291 $field1 = array("string" => $list_left_icon, "attach"=> "style='text-align:center;width:20px;'");
292 $field2 = array("string" => sprintf($editlink,$key,$display)." ","attach" => "");
293 $field3 = array("string" => preg_replace("/%KEY%/",$key,$action), "attach"=> "style='text-align:right;width:".$this->action_col_size."px;border-right:0px;'");
294 $this->AddElement(array($field0,$field1,$field2,$field3));
295 }
296 }
298 function Save()
299 {
300 MultiSelectWindow :: Save();
301 }
303 function save_object()
304 {
305 /* Save automatic created POSTs like regex, checkboxes */
306 MultiSelectWindow::save_object();
307 }
310 /* Add some additional checkboxes to the filter part, this should be generated dynamically. */
311 function set_filter_objectclasses()
312 {
313 }
315 /* Return objectClass names used in filter part */
316 function get_filter_objectclasses()
317 {
318 return(array("gosaAccount","gosaDepartment"));
319 }
323 }
324 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
325 ?>