Code

Updated template
[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     /* Toggle all selected / deselected */
48     $chk = "<input type='checkbox' id='select_all' name='select_all'
49       onClick='toggle_all_(\"^item_selected_[0-9]*$\",\"select_all\");' >";
51     /* set Page header */
52     $this->AddHeader(array("string"=> $chk,          "attach"=>"style='width:20px;'"));
53     $this->AddHeader(array("string"=>"&nbsp;",          "attach"=>"style='width:20px;'"));
54     $this->AddHeader(array("string"=>_("Summary")));
55     $this->AddHeader(array("string"=>_("Actions"),      "attach" => "style='width:".$this->action_col_size."px;border-right:0px;text-align:right;'"));
57     /* Set dynamically filter checkboxes */
58     $this->set_filter_objectclasses();   
59  
60     /* Add SubSearch checkbox */
61     $this->AddCheckBox("SubSearch",  _("Select to search within subtrees"), _("Ignore subtrees"), false);
64     /*                  Name                 ,Text                              ,Default  , Connect with alphabet  */
65     $this->AddRegex   ("Regex",     _("Display acls matching"),"*" , true);
66   }
69   function GenHeader()
70   {
71      /* Prepare departments,
72        which are shown in the listbox on top of the listbox
73      */
74     $options= "";
75     $Copy_Paste = "";
77     /* Get all departments within this subtree */
78     $ui= get_userinfo();
79     $first = "";
80     $found = FALSE;
81     $base = $this->config->current['BASE'];
83     /* Add base */
84     $tmp = array();
85     $tmp[] = array("dn"=>$this->config->current['BASE']);
86     $tmp=  array_merge($tmp,get_list("(&(|(ou=*)(description=*))(objectClass=gosaDepartment))", $this->module, $base,
87                     array("ou", "description"), GL_SIZELIMIT | GL_SUBSEARCH));
89     $deps = array();
90     foreach($tmp as $tm){
91       $deps[$tm['dn']] = $tm['dn'];
92     }
94     /* Load possible departments */
95     $ui= get_userinfo();
96     $tdeps= $ui->get_module_departments("acl");
97     $ids = $this->config->idepartments;
98     $first = "";
99     $found = FALSE;
100     foreach($ids as $dep => $name){
101       if(isset($deps[$dep]) && in_array_ics($dep, $tdeps)){
103         /* Keep first base dn in mind, we could need this
104          *  info if no valid base was found
105          */
106         if(empty($first)) {
107           $first = $dep['dn'];
108         }
110         $value = $ids[$dep];
111         if ($this->selectedBase == $dep){
112           $found = TRUE;
113           $options.= "<option selected='selected' value='".$dep."'>$value</option>";
114         } else {
115           $options.= "<option value='".$dep."'>$value</option>";
116         }
117       }
118     }
120     /* The currently used base is not visible with your acl setup.
121      * Set base to first useable base.
122      */
123     if(!$found){
124       $this->selectedBase = $first;
125     }
127     /* Allow copy & paste for roles */ 
128     $acl_all  = $ui->has_complete_category_acls($this->selectedBase,"acl");
129     $acl      = $ui->get_permissions($this->selectedBase,"acl/acl");
131     /* Add default header */
132     $listhead = MultiSelectWindow::get_default_header();
134     /* Get copy & paste icon */
135     $Copy_Paste ="";
136     if(preg_match("/(c.*w|w.*c)/",$acl_all) &&  $this->parent->CopyPasteHandler){
137       $Copy_Paste = $this->parent->CopyPasteHandler->generatePasteIcon();
138       $addsep = true;
139     }
141     /* Add snapshot icons */
142     if(preg_match("/(c.*w|w.*c)/",$acl_all)){
143       $listhead .= $this->get_snapshot_header($this->selectedBase);
144       $add_sep = true;
145     }
147     if(preg_match("/c/",$ui->get_permissions($this->selectedBase,"acl/acl"))){
148       $add_sep = true;
149       $listhead .= "<input class='center' type='image' align='middle' src='images/list_new_acl_role.png'
150         name='new_acl_role'     alt='"._("New acl role")."' title='"._("New acl role")."'>&nbsp;";
151     }
153     $listhead .= $Copy_Paste. 
154       _("Base")."&nbsp;<select name='CurrentMainBase' onChange='mainform.submit()' class='center'>$options</select>".
155       " <input class='center' type='image' src='images/list_submit.png' align='middle' 
156       title='"._("Submit department")."' name='submit_department' alt='".  _("Submit")."'>&nbsp;";
158         /* Add multiple copy & cut icons */
159     if(is_object($this->parent->CopyPasteHandler)){
160       $listhead .= "&nbsp;<input class='center' type='image' align='middle' src='images/editcopy.png'
161         title='"._("Copy selected objects")."' alt='"._("Copy objects")."' name='multiple_copy_objects'>&nbsp;";
162       $listhead .= "&nbsp;<input class='center' type='image' align='middle' src='images/editcut.png'
163         title='"._("cut selected objects")."' alt='"._("Cut objects")."' name='multiple_cut_objects'>&nbsp;";
164       $listhead .= "</div>";
165     }
167     $listhead .= "</div>";
169     $this->SetListHeader($listhead);
170   }
172   /* so some basic settings */
173   function execute()
174   {
175     $this->ClearElementsList();
176     $this->GenHeader();
177   }
179   function setEntries($list)
180   {
182     foreach($list as $key => $acl_entry){
184       /* Get copy & paste icon */
185       $acl        = $this->ui->get_permissions($acl_entry['dn'],"acl/acl");
186       $acl_all    = $this->ui->has_complete_category_acls($acl_entry['dn'],"acl");
187       $action     = "";
189       if(in_array("gosaRole",$acl_entry['objectClass'])){
191         /* Role handling */
192         $editlink       = "<a href='?plug=".$_GET['plug']."&amp;id=%s&amp;act=list_edit_role'>%s</a>";
193         $list_left_icon = "<img src='images/select_acl_role.png' alt='"._("Role")."'>";
194         $cn = htmlentities(utf8_decode($acl_entry['cn'][0])) ;
196         if(isset($acl_entry['description'][0])){
197           $cn .= "&nbsp;[".$acl_entry['description'][0]."]";
198         }
200         /* Add copy & paste handler */
201         if(($this->parent->CopyPasteHandler) && preg_match("/(c.*w|w.*c)/",$acl_all)){
202           $action.= "<input class='center' type='image'
203             src='images/editcut.png' alt='"._("cut")."' name='cut_%KEY%' title='"._("Cut this entry")."'>&nbsp;";
204           $action.= "<input class='center' type='image'
205             src='images/editcopy.png' alt='"._("copy")."' name='copy_%KEY%' title='"._("Copy this entry")."'>&nbsp;";
206         }
208         /* Add actions depending on acls */
209         if(preg_match("/r/", $acl)){
210           $action.= "<input class='center' type='image' src='images/edit.png' alt='"._("edit")."'     
211             name='list_acl_role_edit_%KEY%' title='"._("Edit acl role")."'>";
212         }
214         /* Add snapshot functionality */
215         if(preg_match("/(c.*w|w.*c)/", $acl_all)){
216           $action.= $this->GetSnapShotActions($acl_entry['dn']);
217         }
219         if(preg_match("/d/", $acl)){
220           $action.= "<input class='center' type='image' src='images/edittrash.png' alt='"._("delete")."' 
221             name='list_acl_role_del_%KEY%' title='"._("Delete acl role")."'>";
222         }
223       }else{
225         /* Acl handling */
226         $editlink       = "<a href='?plug=".$_GET['plug']."&amp;id=%s&amp;act=list_edit_entry'>%s</a>";
227         $list_left_icon = "<img src='images/select_acl.png' alt='"._("Acl")."'>";
228         $cn = htmlentities(utf8_decode($acl_entry['dn'])); 
230         /* Add actions depending on acls */
231         if(preg_match("/r/", $acl)){
232           $action.= "<input class='center' type='image' src='images/edit.png' alt='"._("edit")."'     
233             name='list_acl_edit_%KEY%' title='"._("Edit acl")."'>";
234         }
235         if(preg_match("/d/", $acl)){
236           $action.= "<input class='center' type='image' src='images/edittrash.png' alt='"._("delete")."' 
237             name='list_acl_del_%KEY%' title='"._("Delete acl")."'>";
238         }
239       }
241       if(in_array("gosaRole",$acl_entry['objectClass'])){
242         $field0 = array("string" => "<input type='checkbox' id='item_selected_".$key."' name='item_selected_".$key."'>" ,
243             "attach" => "style='width:20px;'");
244       }else{
245         $field0 = array("string" => "", "attach" => "style='width:20px;'");
246       }
247   
248       $field1 = array("string" => $list_left_icon, "attach"=> "style='text-align:center;width:20px;'");
249       $field2 = array("string" => sprintf($editlink,$key,$cn)."&nbsp;","attach" => "");
250       $field3 = array("string" => preg_replace("/%KEY%/",$key,$action), "attach"=> "style='text-align:right;width:".$this->action_col_size."px;border-right:0px;'");
251       $this->AddElement(array($field0,$field1,$field2,$field3));
252     }
253   }
255   function Save()
256   {
257     MultiSelectWindow :: Save();  
258   }
260   function save_object()
261   {
262     /* Save automatic created POSTs like regex, checkboxes */
263     MultiSelectWindow::save_object();   
264   }
267   /* Add some additional checkboxes to the filter part, this should be generated dynamically. */
268   function set_filter_objectclasses()
269   { 
270   }
271   
272   /* Return objectClass names used in filter part */  
273   function get_filter_objectclasses()
274   {
275     return(array("gosaAccount","gosaDepartment"));
276   }
278   
279   /* Return plugin informations for acl handling */
280   function plInfo()
281   {
282     return (array(
283           "plShortName"   => _("ACL")."&nbsp;&amp;&nbsp;"._("ACL roles"),
284           "plDescription" => _("ACL")."&nbsp;&amp;&nbsp;"._("ACL roles")."&nbsp;-&nbsp;("._("Access control list").")",
285           "plSelfModify"  => FALSE,
286           "plDepends"     => array(),
287           "plPriority"    => 0,
288           "plSection"     => array("administration"),
289           "plCategory"    => array("acl" => array("description"  => _("ACL")."&nbsp;&amp;&nbsp;"._("ACL roles"),
290                                                           "objectClass"  => array("gosaAcl","gosaRole"))),
291           "plProvidedAcls"=> array(
292             "cn"          => _("Role name"),
293             "description" => _("Role description"))
295           ));
296   }
301 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
302 ?>