Code

Updated ACL checks.
[gosa.git] / gosa-core / plugins / admin / departments / class_divListDepartment.inc
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 divListDepartment extends MultiSelectWindow
24 {
26   /* Current base */
27   var $selectedBase       = "";
28   var $departments        = array();
30   /* Regex */
31   var $Regex              = "*";
32   
33   /* Subsearch checkbox */
34   var $SubSearch          = false;
36   var $parent             ;
37   var $ui                 ;
39   function divListDepartment (&$config, &$parent)
40   {
41     MultiSelectWindow::MultiSelectWindow($config, "Department", "department");
42     
43     $this->parent       = &$parent;
44     $this->ui           = get_userinfo();
46     /* Set list strings */
47     $this->SetTitle(_("List of departments"));
48     $this->SetSummary(_("List of departments"));
49     $this->EnableAplhabet   (true);
51     /* Result page will look like a headpage */
52     $this->SetHeadpageMode();
53   
54     /* Disable buttonsm */
55     $this->EnableCloseButton(false);
56     $this->EnableSaveButton (false);
60    /* Toggle all selected / deselected */
61     $chk = "<input type='checkbox' id='select_all' name='select_all' title='"._("Select all")."'
62                onClick='toggle_all_(\"^item_selected_[a-zA-Z0-9\\/\=]*$\",\"select_all\");' >";
64     /* set Page header */
65     $this->AddHeader(array("string"=> $chk,          "attach"=>"style='width:20px;'"));
66     $this->AddHeader(array("string" => "&nbsp;", "attach" => "style='text-align:center;width:20px;'"));
67     $this->AddHeader(array("string"=>_("Department name"), "attach" => "style=''"));
68     $this->AddHeader(array("string" =>_("Actions"), "attach" => "style='width:60px;border-right:0px;text-align:right;'"));
71     /* Add SubSearch checkbox */    
72     $this->AddCheckBox("SubSearch",  msgPool::selectToView("","subsearch"), msgPool::selectToView("","subsearch_small"), false);
74     /*                  Name                 ,Text                              ,Default  , Connect with alphabet  */
75     $this->AddRegex   ("Regex",     _("Regular expression for matching department names"), "*" , true);
76   }
79   function GenHeader()
80   {
81     /* Prepare departments,
82        which are shown in the listbox on top of the listbox
83     */
84     $options= "";
86     /* Get all departments within this subtree */
87     $ui= get_userinfo();
88     $first = "";
89     $found = FALSE;
90     $base = $this->config->current['BASE'];
92     /* Add base */
93     $tmp = array();
94     $tmp[] = array("dn"=>$this->config->current['BASE']);
95     $tmp=  array_merge($tmp,get_list("(&(|(ou=*)(description=*))(objectClass=gosaDepartment))", $this->module, $base,
96                     array("ou", "description"), GL_SIZELIMIT | GL_SUBSEARCH));
98     $deps = array();
99     foreach($tmp as $tm){
100       $deps[$tm['dn']] = $tm['dn'];
101     }
103     /* Load possible departments */
104     $ui= get_userinfo();
105     $tdeps= $ui->get_module_departments("department");
106     $ids = $this->config->idepartments;
107     $first = "";
108     $found = FALSE;
109     foreach($ids as $dep => $name){
110       if(isset($deps[$dep]) && in_array_ics($dep, $tdeps)){
112         /* Keep first base dn in mind, we could need this
113          *  info if no valid base was found
114          */
115         if(empty($first)) {
116           $first = $dep['dn'];
117         }
119         $value = $ids[$dep];
120         if ($this->selectedBase == $dep){
121           $found = TRUE;
122           $options.= "<option selected='selected' value='".$dep."'>$value</option>";
123         } else {
124           $options.= "<option value='".$dep."'>$value</option>";
125         }
126       }
127     }
129     /* The currently used base is not visible with your acl setup.
130      * Set base to first useable base.
131      */
132     if(!$found){
133       $this->selectedBase = $first;
134     }
136     /* Generate list head */
137     $ui = get_userinfo();
138     $acl = $ui->get_permissions("ou=dummy,".$this->selectedBase  ,"department/department");
139       
140     /* Add default header */
141     $listhead = MultiSelectWindow::get_default_header();
143     $listhead .=  
144       " "._("Base")."&nbsp;<select name='CurrentMainBase' onChange='mainform.submit()' class='center'>$options</select>".
145       " <input class='center' type='image' src='images/lists/submit.png' align='middle' ".
146       "   title='"._("Submit department")."' name='submit_department' alt='"._("Submit")."'>&nbsp;";
148     /* Create Layers menu */
149     $s  = ".|"._("Actions")."|\n";
151     /* Append create options */
152     if(preg_match("/c/",$acl)) {
153       $s .= "..|<img src='images/lists/new.png' alt='' border='0' class='center'>".
154         "&nbsp;"._("Create")."|\n";
155       $s.= "...|<input class='center' type='image' src='plugins/departments/images/department.png' alt=''>".
156         "&nbsp;"._("Department")."|dep_new|\n";
157       $s.= "..|---|\n";
158     }
159     $s.= "..|<img src='images/lists/trash.png' alt='' border='0' class='center'>".
160       "&nbsp;"._("Remove")."|"."remove_multiple|\n";
163     $this->SetDropDownHeaderMenu($s);
164     $this->SetListHeader($listhead);
165   }
167   function execute()
168   {
169     $this->ClearElementsList();
170     $this->GenHeader();
171   }
173   function setEntries($list)
174   {
175     $linkopen = "<a href='?plug=".$_GET['plug']."&amp;act=dep_open&amp;dep_id=%s'>%s</a>";
177     $ui = get_userinfo();
178     foreach($list as $key => $val) {
180       $actions= "";      
182       $acl = $ui->get_permissions($this->config->departments[$key] ,"department/department");
183       $acl_all = $ui->has_complete_category_acls($this->config->departments[$key] ,"department");
185       $actions.= "<input class='center' type='image' src='images/lists/edit.png'
186         alt='"._("edit")."'   name='dep_edit_%KEY%' title='"._("Edit this entry")."'>";
188       if(preg_match("/d/",$acl)){
189         $actions.= "<input class='center' type='image' src='images/lists/trash.png'
190           alt='"._("delete")."'   name='dep_del_%KEY%' title='"._("Delete this entry")."'>";
191       }
193       if(!isset($this->config->departments[trim($key)])){
194         $this->config->departments[trim($key)]="";
195       }
197       /* check if this department contains sub-departments
198          Display different image in this case
199        */
200       $non_empty="";
201       $nkey= normalizePreg($key);
202       foreach($this->config->departments as $keyd=>$vald ){
203         if(preg_match('/$nkey\/.*/',$keyd)){
204           $non_empty="full";
205         }
206       }
208       $title = preg_replace('/ /', '&nbsp;', @LDAP::fix($this->config->departments[$key]));
210       if($val == "."){
211         $field01 = array("string" => "&nbsp;",
212             "attach" => "style='width:20px;'");
213       }else{
214         $field01 = array("string" => "<input type='checkbox' id='item_selected_".base64_encode($key)."' 
215             name='item_selected_".base64_encode($key)."'>" ,
216             "attach" => "style='width:20px;'");
217       }
219       $field0 = array("string" => "<img src='images/".$non_empty."lists/folder.png' title='"._("department")."' alt='department'>", "attach" => "style='text-align:center;width:20px;'");
220       $field1 = array("string" => sprintf($linkopen,base64_encode($key),$val), "attach" => "style='' title='".$title."'");
221       $field2 = array("string" => preg_replace("/%KEY%/", base64_encode($key), $actions), "attach" => "style='width:60px;border-right:0px;text-align:
222           right;'");
224       $this->AddElement( array($field01,$field0,$field1,$field2));
225     }
227     /* Create summary string for list footer */
228     $num_deps=count($list);
229     $num_dep_str = _("Number of listed departments");
230     $str = "<img class='center' src='images/lists/folder.png'
231               title='".$num_dep_str."' alt='".$num_dep_str."'>&nbsp;".$num_deps."&nbsp;&nbsp;&nbsp;&nbsp;";
232     $this->set_List_Bottom_Info($str);
234   }
235   function Save()
236   {
237     MultiSelectWindow::Save();
238   }
240   function save_object()
241   {
242     /* Save automatic created POSTs like regex, checkboxes */
243     MultiSelectWindow::save_object();   
244   }
246 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
247 ?>