Code

469b0163bc93a34d4c6c0f1d270874bcc1686db4
[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       
139     /* Add default header */
140     $listhead = MultiSelectWindow::get_default_header();
142     $listhead .=  
143       " "._("Base")."&nbsp;<select name='CurrentMainBase' onChange='mainform.submit()' class='center'>$options</select>".
144       " <input class='center' type='image' src='images/lists/submit.png' align='middle' ".
145       "   title='"._("Submit department")."' name='submit_department' alt='"._("Submit")."'>&nbsp;";
147     /* Create Layers menu */
148     $s  = ".|"._("Actions")."|\n";
150     /* Append create options */
151     $s .= "..|<img src='images/lists/new.png' alt='' border='0' class='center'>".
152       "&nbsp;"._("Create")."|\n";
154     if(preg_match("/c/",$ui->get_permissions("ou=dummy,".$this->selectedBase  ,"department/department"))) {
155       $s.= "...|<input class='center' type='image' src='plugins/departments/images/department.png' alt=''>".
156         "&nbsp;"._("Department")."&nbsp;(ou)|dep_new_ou|\n";
158     }
160     if(preg_match("/c/",$ui->get_permissions("ou=dummy,".$this->selectedBase  ,"department/organization"))) {
161       $s.= "...|<input class='center' type='image' src='plugins/departments/images/organization.png' alt=''>".
162         "&nbsp;"._("Organization")."&nbsp;(o)|dep_new_o|\n";
163     }
165     if(preg_match("/c/",$ui->get_permissions("ou=dummy,".$this->selectedBase  ,"department/country"))) {
166       $s.= "...|<input class='center' type='image' src='plugins/departments/images/country.png' alt=''>".
167         "&nbsp;"._("Country")."&nbsp;(c)"."|dep_new_c|\n";
168     }
170     if(preg_match("/c/",$ui->get_permissions("ou=dummy,".$this->selectedBase  ,"department/locality"))) {
171       $s.= "...|<input class='center' type='image' src='plugins/departments/images/locality.png' alt=''>".
172         "&nbsp;"._("Locality")."&nbsp;(l)|dep_new_l|\n";
173     }
175     if(preg_match("/c/",$ui->get_permissions("ou=dummy,".$this->selectedBase  ,"department/alias"))) {
176       $s.= "...|<input class='center' type='image' src='plugins/departments/images/department_alias.png' alt=''>".
177         "&nbsp;"._("Alias")."|dep_new_alias|\n";
178     }
180     if(preg_match("/c/",$ui->get_permissions("ou=dummy,".$this->selectedBase  ,"department/referal"))) {
181       $s.= "...|<input class='center' type='image' src='plugins/departments/images/department_referal.png' alt=''>".
182         "&nbsp;"._("Referal")."|dep_new_referal|\n";
183     }
185     $s.= "..|---|\n";
186     $s.= "..|<img src='images/lists/trash.png' alt='' border='0' class='center'>".
187       "&nbsp;"._("Remove")."|"."remove_multiple|\n";
190     $this->SetDropDownHeaderMenu($s);
191     $this->SetListHeader($listhead);
192   }
194   function execute()
195   {
196     $this->ClearElementsList();
197     $this->GenHeader();
198   }
200   function setEntries($list)
201   {
202     $linkopen = "<a href='?plug=".$_GET['plug']."&amp;act=dep_open&amp;dep_id=%s'>%s</a>";
204  
205     /* Possible department types
206      */
207     $types['country']            = array("ACL" => "country",      "ATTR" => "c",
208         "TITLE"     => _("Department"),
209         "IMG_FULL"  => "plugins/departments/images/country.png", 
210         "IMG"       => "plugins/departments/images/country.png", "ABBR" => "c");
211     $types['locality']           = array("ACL" => "locality",     "ATTR" => "l",
212         "TITLE"     => _("Department"),
213         "IMG"       => "plugins/departments/images/locality.png", "ABBR" => "l");
214     $types['organizationalUnit'] = array("ACL" => "department",   "ATTR" => "ou",
215         "TITLE"     => _("Department"),
216         "IMG_FULL"  => "images/lists/folder-full.png", 
217         "IMG"       => "images/lists/folder.png", "ABBR" => "ou");
218     $types['organization']       = array("ACL" => "organization", "ATTR" => "o",
219         "TITLE"     => _("Department"),
220         "IMG"       => "plugins/departments/images/organization.png", "ABBR" => "o");
221     $types['Alias??']            = array("ACL" => "alias"     ,    "ATTR" => "alias?",
222         "TITLE"     => _("Department"),
223         "IMG"       => "plugins/departments/images/department_alias.png", "ABBR" => "alias");
224     $types['Referal??']          = array("ACL" => "referal",       "ATTR" => "referal?",
225         "TITLE"     => _("Department"),
226         "IMG"       => "plugins/departments/images/department_referal.png", "ABBR" => "referal");
228     $this->departments = $list;
230     $ui = get_userinfo();
231     foreach($list as $key => $val) {
233       $actions= "";      
235       /* Detect department type
236        */
237       $dep_data = array();
238       foreach($types as $type => $data){
239         if(in_array($type,$val['objectClass'])){
240           $dep_data  = $data;
241           break;
242         }
243       }
244     
245       /* Warn if there was an unknown department type found 
246        */ 
247       if(!count($dep_data)) {
248         trigger_error("Unknown department type given. Skipped '".$val['dn']."'.");
249         continue;
250       }
252       /* Get permissions 
253        */
254       $acl = $ui->get_permissions($val['dn'],"department/".$dep_data['ACL']);
255       $acl_all = $ui->has_complete_category_acls($val['dn'],"department");
257       /* Create actions 
258        */
259       $actions.= "<input class='center' type='image' src='images/lists/edit.png'
260         alt='"._("edit")."'   name='dep_edit_%KEY%' title='"._("Edit this entry")."'>";
261       if(preg_match("/d/",$acl)){
262         $actions.= "<input class='center' type='image' src='images/lists/trash.png'
263           alt='"._("delete")."'   name='dep_del_%KEY%' title='"._("Delete this entry")."'>";
264       }
266       /* Check if this department contains sub-departments
267          Display different image in this case
268        */
269       $sub_folders= FALSE;
270       foreach($this->config->departments as $keyd){
271         if(preg_match("/,".normalizePreg($val['dn'])."$/",$keyd)){
272           $sub_folders = TRUE;
273         }
274       }
276       /* Create entry name 
277        */      
278       $name = $val[$dep_data['ATTR']][0];
279       if(isset($val['description'])){
280         $name .=  " - [".$val["description"][0]."]";
281       }
283       /* Create title
284        */
285       $title = preg_replace('/ /', '&nbsp;', @LDAP::fix($val['dn']));
287       /* Create checkboxes infront of the entry 
288        */
289       if($name == "."){
290         $field01 = array("string" => "&nbsp;",
291             "attach" => "style='width:20px;'");
292       }else{
293         $field01 = array("string" => "<input type='checkbox' id='item_selected_".$key."' name='item_selected_".$key."'>" ,
294             "attach" => "style='width:20px;'");
295       }
297       /* Create image 
298        */
299       if($sub_folders){
300         $img =  "<img src='".$dep_data['IMG_FULL']."' class='center' title='".$dep_data['TITLE']."'>";
301       }else{
302         $img =  "<img src='".$dep_data['IMG']."' class='center' title='".$dep_data['TITLE']."'>";
303       }
304      
305       /* Append data to the listing 
306        */
307       $field0 = array("string" => $img, "attach" => "style='text-align:center;width:20px;'");
308       $field1 = array("string" => sprintf($linkopen,$key,$name), 
309           "attach" => "style='' title='".$title."'");
310       $field2 = array("string" => preg_replace("/%KEY%/", $key, $actions), 
311           "attach" => "style='width:60px;border-right:0px;text-align:right;'");
313       $this->AddElement( array($field01,$field0,$field1,$field2));
314     }
316     /* Create summary string for list footer */
317     $num_deps=count($list);
318     $num_dep_str = _("Number of listed departments");
319     $str = "<img class='center' src='images/lists/folder.png'
320               title='".$num_dep_str."' alt='".$num_dep_str."'>&nbsp;".$num_deps."&nbsp;&nbsp;&nbsp;&nbsp;";
321     $this->set_List_Bottom_Info($str);
323   }
324   function Save()
325   {
326     MultiSelectWindow::Save();
327   }
329   function save_object()
330   {
331     /* Save automatic created POSTs like regex, checkboxes */
332     MultiSelectWindow::save_object();   
333   }
335 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
336 ?>