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","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 /* Get all departments within this subtree */
91 $ui= get_userinfo();
92 $base = $this->config->current['BASE'];
93 $options = $this->create_department_list($this->module);
95 /* Allow copy & paste for roles */
96 $acl_all = $ui->has_complete_category_acls($this->selectedBase,"acl");
97 $acl = $ui->get_permissions($this->selectedBase,"acl/acl");
99 /* Add default header */
100 $listhead = MultiSelectWindow::get_default_header();
101 $listhead .=
102 _("Base")." <select name='CurrentMainBase' onChange='mainform.submit()' class='center'>$options</select>".
103 " <input class='center' type='image' src='images/lists/submit.png' align='middle'
104 title='"._("Submit department")."' name='submit_department' alt='". _("Submit")."'> ";
107 /* Create Layers menu */
108 $s = ".|"._("Actions")."|\n";
109 /* Append create options */
110 if(preg_match("/c/",$acl)) {
111 $s .= "..|<img src='images/lists/new.png' alt='' border='0' class='center'>".
112 " "._("Create")."|\n";
113 $s.= "...|<input class='center' type='image' src='plugins/acl/images/new-role.png' alt=''>".
114 " "._("Role")."|new_acl_role|\n";
115 }
117 $s.= "..|<img src='images/lists/trash.png' alt='' border='0' class='center'>".
118 " "._("Remove")."|"."remove_multiple|\n";
121 /* Add Copy & Paste header */
122 $s .= $this->parent->get_copypaste_header($this->selectedBase,$this->module);
124 $s .= $this->parent->get_snapshot_header($this->selectedBase,$this->module);
126 $this->SetDropDownHeaderMenu($s);
127 $this->SetListHeader($listhead);
128 }
130 /* so some basic settings */
131 function execute()
132 {
133 $this->ClearElementsList();
134 $this->GenHeader();
135 }
137 function setEntries($list)
138 {
139 $ui = get_userinfo();
140 foreach($list as $key => $acl_entry){
142 $action = "";
144 /* Handle ACL role entries
145 */
146 if(in_array("gosaRole",$acl_entry['objectClass'])){
148 $acl = $this->ui->get_permissions($acl_entry['dn'],"acl/aclrole");
149 $acl_all = $this->ui->has_complete_category_acls($acl_entry['dn'],"acl");
151 $editlink = "<a href='?plug=".$_GET['plug']."&id=%s&act=list_edit_role'>%s</a>";
152 $list_left_icon = "<img src='plugins/acl/images/role.png' alt='"._("Role")."'>";
153 $cn = htmlentities(utf8_decode($acl_entry['cn'][0])) ;
155 if(isset($acl_entry['description'][0])){
156 $cn .= " [".$acl_entry['description'][0]."]";
157 }
159 /* Add copy & cut functionality */
160 $action.= $this->parent->get_copypaste_action($acl_entry['dn'],"acl","aclRole");
162 /* Add actions depending on acls */
163 if(preg_match("/r/", $acl)){
164 $action.= "<input class='center' type='image' src='images/lists/edit.png' alt='"._("edit")."'
165 name='list_acl_role_edit_%KEY%' title='"._("Edit acl role")."'>";
166 }
168 /* Add snapshot functionality */
169 $action.= $this->parent->get_snapshot_action($acl_entry['dn'],"acl");
171 }else{
173 /* Handle non-role ACL entries */
174 $acl = $this->ui->get_permissions($acl_entry['dn'],"acl/acl");
175 $acl_all = $this->ui->has_complete_category_acls($acl_entry['dn'],"acl");
177 /* Acl handling */
178 $editlink = "<a href='?plug=".$_GET['plug']."&id=%s&act=list_edit_entry'>%s</a>";
179 $list_left_icon = "<img src='images/lists/locked.png' alt='"._("ACL")."'>";
180 $cn = preg_replace('/\\\\,/', ',', LDAP::fix($acl_entry['dn']));
182 /* Add actions depending on acls */
183 if(preg_match("/r/", $acl)){
184 $action.= "<input class='center' type='image' src='images/lists/edit.png' alt='"._("edit")."'
185 name='list_acl_edit_%KEY%' title='"._("Edit acl")."'>";
186 }
187 }
189 /* Add delete actions */
190 if(preg_match("/d/", $acl)){
191 $action.= "<input class='center' type='image' src='images/lists/trash.png' alt='"._("delete")."'
192 name='list_acl_del_%KEY%' title='"._("Delete acl")."'>";
193 }
195 /* Add a checkbox in front of each entry
196 */
197 $field0 = array("string" => "<input type='checkbox' id='item_selected_".$key."' name='item_selected_".$key."'>" ,
198 "attach" => "style='width:20px;'");
200 /* Cutted objects should be displayed in light grey */
201 $display = $cn;
202 if($this->parent->CopyPasteHandler){
203 foreach($this->parent->CopyPasteHandler->queue as $queue_key => $queue_data){
204 if($queue_data['dn'] == $acl_entry['dn']) {
205 $display = "<font color='#999999'>".$display."</font>";
206 break;
207 }
208 }
209 }
211 $field1 = array("string" => $list_left_icon,
212 "attach"=> "style='text-align:center;width:20px;'");
213 $field2 = array("string" => sprintf($editlink,$key,$display)." ",
214 "attach" => "");
215 $field3 = array("string" => preg_replace("/%KEY%/",$key,$action),
216 "attach"=> "style='text-align:right;width:".$this->action_col_size."px;border-right:0px;'");
217 $this->AddElement(array($field0,$field1,$field2,$field3));
218 }
219 }
222 function Save()
223 {
224 MultiSelectWindow :: Save();
225 }
227 function save_object()
228 {
229 /* Save automatic created POSTs like regex, checkboxes */
230 MultiSelectWindow::save_object();
231 }
234 /* Add some additional checkboxes to the filter part, this should be generated dynamically. */
235 function set_filter_objectclasses()
236 {
237 }
239 /* Return objectClass names used in filter part */
240 function get_filter_objectclasses()
241 {
242 return(array("gosaAccount","gosaDepartment"));
243 }
247 }
248 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
249 ?>