Code

Updated divlists to include the ldap base
[gosa.git] / plugins / admin / acl / class_divListACL.inc
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;
21   
23   function divListACL ($config,$parent)
24   {
25     MultiSelectWindow::MultiSelectWindow($config, "ACLs", "acl");
26     
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);
39   
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"=>"&nbsp;",          "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();   
54  
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'];
77     $deps= get_list("(&(|(ou=*)(description=*))(objectClass=gosaDepartment))", "acl", $base,
78                     array("ou", "description"), GL_SIZELIMIT | GL_SUBSEARCH);
80     /* Add base */
81     $deps[] = array("dn"=>$this->config->current['BASE']);
83     /* Load possible departments */
84     $ui     = get_userinfo();
85     $tdeps  = $ui->get_module_departments("acl");
86     $ids    = $this->config->idepartments;
87     foreach($deps as $dep){
88       if(isset($ids[$dep['dn']]) && in_array_ics($dep['dn'], $tdeps)){
90         /* Keep first base dn in mind, we could need this
91          *  info if no valid base was found
92          */
93         if(empty($first)) {
94           $first = $dep['dn'];
95         }
96   
97         $value = $ids[$dep['dn']];
98         if ($this->selectedBase == $dep['dn']){
99           $options.= "<option selected='selected' value='".$dep['dn']."'>$value</option>";
100         } else {
101           $options.= "<option value='".$dep['dn']."'>$value</option>";
102         }
103       }
104     }
106     /* The currently used base is not visible with your acl setup.
107      * Set base to first useable base.
108      */
109     if(!$found){
110       $this->selectedBase = $first;
111     }
113     /* Allow copy & paste for roles */ 
114     $acl_all  = $ui->has_complete_category_acls($this->selectedBase,"acl");
115     $acl      = $ui->get_permissions($this->selectedBase,"acl/acl");
117     /* Add default header */
118     $listhead = MultiSelectWindow::get_default_header();
120     /* Get copy & paste icon */
121     $Copy_Paste ="";
122     if(preg_match("/(c.*w|w.*c)/",$acl_all) &&  $this->parent->CopyPasteHandler){
123       $Copy_Paste = $this->parent->CopyPasteHandler->generatePasteIcon();
124       $addsep = true;
125     }
127     /* Add snapshot icons */
128     if(preg_match("/(c.*w|w.*c)/",$acl_all)){
129       $listhead .= $this->get_snapshot_header($this->selectedBase);
130       $add_sep = true;
131     }
133     if(preg_match("/c/",$ui->get_permissions($this->selectedBase,"acl/acl"))){
134       $add_sep = true;
135       $listhead .= "<input class='center' type='image' align='middle' src='images/list_new_acl_role.png'
136         name='new_acl_role'     alt='"._("New acl role")."' title='"._("New acl role")."'>&nbsp;";
137     }
139     $listhead .= $Copy_Paste. 
140       _("Base")."&nbsp;<select name='CurrentMainBase' onChange='mainform.submit()' class='center'>$options</select>".
141       " <input class='center' type='image' src='images/list_submit.png' align='middle' 
142       title='"._("Submit department")."' name='submit_department' alt='".  _("Submit")."'>&nbsp;".
143       "</div>";
145     $this->SetListHeader($listhead);
146   }
148   /* so some basic settings */
149   function execute()
150   {
151     $this->ClearElementsList();
152     $this->GenHeader();
153   }
155   function setEntries($list)
156   {
158     foreach($list as $key => $acl_entry){
160       /* Get copy & paste icon */
161       $acl        = $this->ui->get_permissions($acl_entry['dn'],"acl/acl");
162       $acl_all    = $this->ui->has_complete_category_acls($acl_entry['dn'],"acl");
163       $action     = "";
165       if(in_array("gosaRole",$acl_entry['objectClass'])){
167         /* Role handling */
168         $editlink       = "<a href='?plug=".$_GET['plug']."&amp;id=%s&amp;act=list_edit_role'>%s</a>";
169         $list_left_icon = "<img src='images/select_acl_role.png' alt='"._("Role")."'>";
170         $cn = htmlentities(utf8_decode($acl_entry['cn'][0])) ;
172         if(isset($acl_entry['description'][0])){
173           $cn .= "&nbsp;[".$acl_entry['description'][0]."]";
174         }
176         /* Add copy & paste handler */
177         if(($this->parent->CopyPasteHandler) && preg_match("/(c.*w|w.*c)/",$acl_all)){
178           $action.= "<input class='center' type='image'
179             src='images/editcut.png' alt='"._("cut")."' name='cut_%KEY%' title='"._("Cut this entry")."'>&nbsp;";
180           $action.= "<input class='center' type='image'
181             src='images/editcopy.png' alt='"._("copy")."' name='copy_%KEY%' title='"._("Copy this entry")."'>&nbsp;";
182         }
184         /* Add actions depending on acls */
185         if(preg_match("/r/", $acl)){
186           $action.= "<input class='center' type='image' src='images/edit.png' alt='"._("edit")."'     
187             name='list_acl_role_edit_%KEY%' title='"._("Edit acl role")."'>";
188         }
190         /* Add snapshot functionality */
191         if(preg_match("/(c.*w|w.*c)/", $acl_all)){
192           $action.= $this->GetSnapShotActions($acl_entry['dn']);
193         }
195         if(preg_match("/d/", $acl)){
196           $action.= "<input class='center' type='image' src='images/edittrash.png' alt='"._("delete")."' 
197             name='list_acl_role_del_%KEY%' title='"._("Delete acl role")."'>";
198         }
199       }else{
201         /* Acl handling */
202         $editlink       = "<a href='?plug=".$_GET['plug']."&amp;id=%s&amp;act=list_edit_entry'>%s</a>";
203         $list_left_icon = "<img src='images/select_acl.png' alt='"._("Acl")."'>";
204         $cn = htmlentities(utf8_decode($acl_entry['dn'])); 
206         /* Add actions depending on acls */
207         if(preg_match("/r/", $acl)){
208           $action.= "<input class='center' type='image' src='images/edit.png' alt='"._("edit")."'     
209             name='list_acl_edit_%KEY%' title='"._("Edit acl")."'>";
210         }
211         if(preg_match("/d/", $acl)){
212           $action.= "<input class='center' type='image' src='images/edittrash.png' alt='"._("delete")."' 
213             name='list_acl_del_%KEY%' title='"._("Delete acl")."'>";
214         }
215       }
217       $field1 = array("string" => $list_left_icon, "attach"=> "style='text-align:center;width:20px;'");
218       $field2 = array("string" => sprintf($editlink,$key,$cn)."&nbsp;","attach" => "");
219       $field3 = array("string" => preg_replace("/%KEY%/",$key,$action), "attach"=> "style='text-align:right;width:".$this->action_col_size."px;border-right:0px;'");
220       $this->AddElement(array($field1,$field2,$field3));
221     }
222   }
224   function Save()
225   {
226     MultiSelectWindow :: Save();  
227   }
229   function save_object()
230   {
231     /* Save automatic created POSTs like regex, checkboxes */
232     MultiSelectWindow::save_object();   
233   }
236   /* Add some additional checkboxes to the filter part, this should be generated dynamically. */
237   function set_filter_objectclasses()
238   { 
239   }
240   
241   /* Return objectClass names used in filter part */  
242   function get_filter_objectclasses()
243   {
244     return(array("gosaAccount","gosaDepartment"));
245   }
247   
248   /* Return plugin informations for acl handling */
249   function plInfo()
250   {
251     return (array(
252           "plShortName"   => _("ACL")."&nbsp;&amp;&nbsp;"._("ACL roles"),
253           "plDescription" => _("ACL")."&nbsp;&amp;&nbsp;"._("ACL roles")."&nbsp;-&nbsp;("._("Access control list").")",
254           "plSelfModify"  => FALSE,
255           "plDepends"     => array(),
256           "plPriority"    => 0,
257           "plSection"     => array("administration"),
258           "plCategory"    => array("acl" => array("description"  => _("ACL")."&nbsp;&amp;&nbsp;"._("ACL roles"),
259                                                           "objectClass"  => array("gosaAcl","gosaRole"))),
260           "plProvidedAcls"=> array(
261             "cn"          => _("Role name"),
262             "description" => _("Role description"))
264           ));
265   }
270 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
271 ?>