Code

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