b20002053bf91002ae2391e378b00307497ccc5c
1 <?php
3 class divListACL extends MultiSelectWindow
4 {
6 /* Current base */
7 var $selectedBase = "";
8 var $departments = array();
10 /* Regex */
11 var $Regex = "*";
13 /* CheckBoxes */
15 /* Subsearch checkbox */
16 var $SubSearch = false;
18 var $parent ;
19 var $ui ;
20 var $action_col_size;
23 function divListACL ($config,$parent)
24 {
25 MultiSelectWindow::MultiSelectWindow($config, "ACLs", "acl");
27 $this->parent = $parent;
28 $this->ui = get_userinfo();
30 /* Set list strings */
31 $this->SetTitle(_("List of acl"));
32 $this->SetSummary(_("List of acls"));
34 /* Result page will look like a headpage */
35 $this->SetHeadpageMode();
36 $this->SetInformation(_("This menu allows you to edit and delete selected acls."));
38 $this->EnableAplhabet (true);
40 /* Disable buttonsm */
41 $this->EnableCloseButton(false);
42 $this->EnableSaveButton (false);
44 /* Dynamic action col */
45 $this->action_col_size = 120;
47 /* set Page header */
48 $this->AddHeader(array("string"=>" ", "attach"=>"style='width:20px;'"));
49 $this->AddHeader(array("string"=>_("Summary")));
50 $this->AddHeader(array("string"=>_("Actions"), "attach" => "style='width:".$this->action_col_size."px;border-right:0px;text-align:right;'"));
52 /* Set dynamically filter checkboxes */
53 $this->set_filter_objectclasses();
55 /* Add SubSearch checkbox */
56 $this->AddCheckBox("SubSearch", _("Select to search within subtrees"), _("Ignore subtrees"), false);
59 /* Name ,Text ,Default , Connect with alphabet */
60 $this->AddRegex ("Regex", _("Display acls matching"),"*" , true);
61 }
64 function GenHeader()
65 {
66 /* Prepare departments,
67 which are shown in the listbox on top of the listbox
68 */
69 $options= "";
70 $Copy_Paste = "";
72 /* Get all departments within this subtree */
73 $ui= get_userinfo();
74 $first = "";
75 $found = FALSE;
76 $base = $this->config->current['BASE'];
78 /* Add base */
79 $tmp = array();
80 $tmp[] = array("dn"=>$this->config->current['BASE']);
81 $tmp= array_merge($tmp,get_list("(&(|(ou=*)(description=*))(objectClass=gosaDepartment))", $this->module, $base,
82 array("ou", "description"), GL_SIZELIMIT | GL_SUBSEARCH));
84 $deps = array();
85 foreach($tmp as $tm){
86 $deps[$tm['dn']] = $tm['dn'];
87 }
89 /* Load possible departments */
90 $ui= get_userinfo();
91 $tdeps= $ui->get_module_departments("acl");
92 $ids = $this->config->idepartments;
93 $first = "";
94 $found = FALSE;
95 foreach($ids as $dep => $name){
96 if(isset($deps[$dep]) && in_array_ics($dep, $tdeps)){
98 /* Keep first base dn in mind, we could need this
99 * info if no valid base was found
100 */
101 if(empty($first)) {
102 $first = $dep['dn'];
103 }
105 $value = $ids[$dep];
106 if ($this->selectedBase == $dep){
107 $found = TRUE;
108 $options.= "<option selected='selected' value='".$dep."'>$value</option>";
109 } else {
110 $options.= "<option value='".$dep."'>$value</option>";
111 }
112 }
113 }
115 /* The currently used base is not visible with your acl setup.
116 * Set base to first useable base.
117 */
118 if(!$found){
119 $this->selectedBase = $first;
120 }
122 /* Allow copy & paste for roles */
123 $acl_all = $ui->has_complete_category_acls($this->selectedBase,"acl");
124 $acl = $ui->get_permissions($this->selectedBase,"acl/acl");
126 /* Add default header */
127 $listhead = MultiSelectWindow::get_default_header();
129 /* Get copy & paste icon */
130 $Copy_Paste ="";
131 if(preg_match("/(c.*w|w.*c)/",$acl_all) && $this->parent->CopyPasteHandler){
132 $Copy_Paste = $this->parent->CopyPasteHandler->generatePasteIcon();
133 $addsep = true;
134 }
136 /* Add snapshot icons */
137 if(preg_match("/(c.*w|w.*c)/",$acl_all)){
138 $listhead .= $this->get_snapshot_header($this->selectedBase);
139 $add_sep = true;
140 }
142 if(preg_match("/c/",$ui->get_permissions($this->selectedBase,"acl/acl"))){
143 $add_sep = true;
144 $listhead .= "<input class='center' type='image' align='middle' src='images/list_new_acl_role.png'
145 name='new_acl_role' alt='"._("New acl role")."' title='"._("New acl role")."'> ";
146 }
148 $listhead .= $Copy_Paste.
149 _("Base")." <select name='CurrentMainBase' onChange='mainform.submit()' class='center'>$options</select>".
150 " <input class='center' type='image' src='images/list_submit.png' align='middle'
151 title='"._("Submit department")."' name='submit_department' alt='". _("Submit")."'> ".
152 "</div>";
154 $this->SetListHeader($listhead);
155 }
157 /* so some basic settings */
158 function execute()
159 {
160 $this->ClearElementsList();
161 $this->GenHeader();
162 }
164 function setEntries($list)
165 {
167 foreach($list as $key => $acl_entry){
169 /* Get copy & paste icon */
170 $acl = $this->ui->get_permissions($acl_entry['dn'],"acl/acl");
171 $acl_all = $this->ui->has_complete_category_acls($acl_entry['dn'],"acl");
172 $action = "";
174 if(in_array("gosaRole",$acl_entry['objectClass'])){
176 /* Role handling */
177 $editlink = "<a href='?plug=".$_GET['plug']."&id=%s&act=list_edit_role'>%s</a>";
178 $list_left_icon = "<img src='images/select_acl_role.png' alt='"._("Role")."'>";
179 $cn = htmlentities(utf8_decode($acl_entry['cn'][0])) ;
181 if(isset($acl_entry['description'][0])){
182 $cn .= " [".$acl_entry['description'][0]."]";
183 }
185 /* Add copy & paste handler */
186 if(($this->parent->CopyPasteHandler) && preg_match("/(c.*w|w.*c)/",$acl_all)){
187 $action.= "<input class='center' type='image'
188 src='images/editcut.png' alt='"._("cut")."' name='cut_%KEY%' title='"._("Cut this entry")."'> ";
189 $action.= "<input class='center' type='image'
190 src='images/editcopy.png' alt='"._("copy")."' name='copy_%KEY%' title='"._("Copy this entry")."'> ";
191 }
193 /* Add actions depending on acls */
194 if(preg_match("/r/", $acl)){
195 $action.= "<input class='center' type='image' src='images/edit.png' alt='"._("edit")."'
196 name='list_acl_role_edit_%KEY%' title='"._("Edit acl role")."'>";
197 }
199 /* Add snapshot functionality */
200 if(preg_match("/(c.*w|w.*c)/", $acl_all)){
201 $action.= $this->GetSnapShotActions($acl_entry['dn']);
202 }
204 if(preg_match("/d/", $acl)){
205 $action.= "<input class='center' type='image' src='images/edittrash.png' alt='"._("delete")."'
206 name='list_acl_role_del_%KEY%' title='"._("Delete acl role")."'>";
207 }
208 }else{
210 /* Acl handling */
211 $editlink = "<a href='?plug=".$_GET['plug']."&id=%s&act=list_edit_entry'>%s</a>";
212 $list_left_icon = "<img src='images/select_acl.png' alt='"._("Acl")."'>";
213 $cn = htmlentities(utf8_decode($acl_entry['dn']));
215 /* Add actions depending on acls */
216 if(preg_match("/r/", $acl)){
217 $action.= "<input class='center' type='image' src='images/edit.png' alt='"._("edit")."'
218 name='list_acl_edit_%KEY%' title='"._("Edit acl")."'>";
219 }
220 if(preg_match("/d/", $acl)){
221 $action.= "<input class='center' type='image' src='images/edittrash.png' alt='"._("delete")."'
222 name='list_acl_del_%KEY%' title='"._("Delete acl")."'>";
223 }
224 }
226 $field1 = array("string" => $list_left_icon, "attach"=> "style='text-align:center;width:20px;'");
227 $field2 = array("string" => sprintf($editlink,$key,$cn)." ","attach" => "");
228 $field3 = array("string" => preg_replace("/%KEY%/",$key,$action), "attach"=> "style='text-align:right;width:".$this->action_col_size."px;border-right:0px;'");
229 $this->AddElement(array($field1,$field2,$field3));
230 }
231 }
233 function Save()
234 {
235 MultiSelectWindow :: Save();
236 }
238 function save_object()
239 {
240 /* Save automatic created POSTs like regex, checkboxes */
241 MultiSelectWindow::save_object();
242 }
245 /* Add some additional checkboxes to the filter part, this should be generated dynamically. */
246 function set_filter_objectclasses()
247 {
248 }
250 /* Return objectClass names used in filter part */
251 function get_filter_objectclasses()
252 {
253 return(array("gosaAccount","gosaDepartment"));
254 }
257 /* Return plugin informations for acl handling */
258 function plInfo()
259 {
260 return (array(
261 "plShortName" => _("ACL")." & "._("ACL roles"),
262 "plDescription" => _("ACL")." & "._("ACL roles")." - ("._("Access control list").")",
263 "plSelfModify" => FALSE,
264 "plDepends" => array(),
265 "plPriority" => 0,
266 "plSection" => array("administration"),
267 "plCategory" => array("acl" => array("description" => _("ACL")." & "._("ACL roles"),
268 "objectClass" => array("gosaAcl","gosaRole"))),
269 "plProvidedAcls"=> array(
270 "cn" => _("Role name"),
271 "description" => _("Role description"))
273 ));
274 }
278 }
279 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
280 ?>