Code

Migrated group management
[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);
58    /* Toggle all selected / deselected */
59     $chk = "<input type='checkbox' id='select_all' name='select_all' title='"._("Select all")."'
60                onClick='toggle_all_(\"^item_selected_[a-zA-Z0-9\\/\=]*$\",\"select_all\");' >";
62     /* set Page header */
63     $this->AddHeader(array("string"=> $chk,          "attach"=>"style='width:20px;'"));
64     $this->AddHeader(array("string" => "&nbsp;", "attach" => "style='text-align:center;width:20px;'"));
65     $this->AddHeader(array("string"=>_("Department name"), "attach" => "style=''"));
66     $this->AddHeader(array("string" =>_("Actions"), "attach" => "style='width:60px;border-right:0px;text-align:right;'"));
69     /* Add SubSearch checkbox */    
70     $this->AddCheckBox("SubSearch",  msgPool::selectToView("","subsearch"), msgPool::selectToView("","subsearch_small"), false);
72     /*                  Name                 ,Text                              ,Default  , Connect with alphabet  */
73     $this->AddRegex   ("Regex",     _("Regular expression for matching department names"), "*" , true);
74   }
77   function GenHeader()
78   {
79     /* Prepare departments,
80        which are shown in the listbox on top of the listbox
81     */
82     $options= "";
84     /* Get all departments within this subtree */
85     $ui= get_userinfo();
86     $first = "";
87     $found = FALSE;
88     $base = $this->config->current['BASE'];
90     /* Add base */
91     $tmp = array();
92     $tmp[] = array("dn"=>$this->config->current['BASE']);
93     $tmp=  array_merge($tmp,get_list("(&(|(ou=*)(description=*))(objectClass=gosaDepartment))", $this->module, $base,
94                     array("ou", "description"), GL_SIZELIMIT | GL_SUBSEARCH));
96     $deps = array();
97     foreach($tmp as $tm){
98       $deps[$tm['dn']] = $tm['dn'];
99     }
101     /* Load possible departments */
102     $ui= get_userinfo();
103     $tdeps= $ui->get_module_departments("department");
104     $ids = $this->config->idepartments;
105     $first = "";
106     $found = FALSE;
107     foreach($ids as $dep => $name){
108       if(isset($deps[$dep]) && in_array_ics($dep, $tdeps)){
110         /* Keep first base dn in mind, we could need this
111          *  info if no valid base was found
112          */
113         if(empty($first)) {
114           $first = $dep['dn'];
115         }
117         $value = $ids[$dep];
118         if ($this->selectedBase == $dep){
119           $found = TRUE;
120           $options.= "<option selected='selected' value='".$dep."'>$value</option>";
121         } else {
122           $options.= "<option value='".$dep."'>$value</option>";
123         }
124       }
125     }
127     /* The currently used base is not visible with your acl setup.
128      * Set base to first useable base.
129      */
130     if(!$found){
131       $this->selectedBase = $first;
132     }
134     /* Generate list head */
135     $ui = get_userinfo();
136       
137     /* Add default header */
138     $listhead = MultiSelectWindow::get_default_header();
140     $listhead .=  
141       " "._("Base")."&nbsp;<select name='CurrentMainBase' onChange='mainform.submit()' class='center'>$options</select>".
142       " <input class='center' type='image' src='images/lists/submit.png' align='middle' ".
143       "   title='"._("Submit department")."' name='submit_department' alt='"._("Submit")."'>&nbsp;";
145     /* Create Layers menu */
146     $s  = ".|"._("Actions")."|\n";
148     /* Append create options */
149     $s .= "..|<img src='images/lists/new.png' alt='' border='0' class='center'>".
150       "&nbsp;"._("Create")."|\n";
152     /* Add all createable department types 
153      */
154     $types = $this->parent->get_support_departments();
155     foreach($types as $type){
156       if(preg_match("/c/",$ui->get_permissions("ou=dummy,".$this->selectedBase  ,"department/".$type['ACL']))){
157       $s.= "...|<input class='center' type='image' src='".$type['IMG']."' alt='".$type['ATTR']."'>".
158         "&nbsp;".$type['TITLE']."&nbsp;(".$type['ATTR'].")|dep_new_".$type['ATTR']."|\n";
159       }
160     }
162     /* Add remove action 
163      */
164     $s.= "..|---|\n";
165     $s.= "..|<img src='images/lists/trash.png' alt='' border='0' class='center'>".
166       "&nbsp;"._("Remove")."|"."remove_multiple|\n";
169     $this->SetDropDownHeaderMenu($s);
170     $this->SetListHeader($listhead);
171   }
173   function execute()
174   {
175     $this->ClearElementsList();
176     $this->GenHeader();
177   }
179   function setEntries($list)
180   {
181     $linkopen = "<a href='?plug=".$_GET['plug']."&amp;post_id=".$this->post_id."&amp;act=dep_open&amp;dep_id=%s'>%s</a>";
183     $types = $this->parent->get_support_departments();
185     $this->departments = $list;
187     $ui = get_userinfo();
188     foreach($list as $key => $val) {
190       $actions= "";      
192       /* Detect department type
193        */
194       $dep_data = array();
195       foreach($types as $type => $data){
196         if(in_array($type,$val['objectClass'])){
197           $dep_data  = $data;
198           break;
199         }
200       }
201     
202       /* Warn if there was an unknown department type found 
203        */ 
204       if(!count($dep_data)) {
205         trigger_error("Unknown department type given. Skipped '".$val['dn']."'.");
206         continue;
207       }
209       /* Get permissions 
210        */
211       $acl = $ui->get_permissions($val['dn'],"department/".$dep_data['ACL']);
212       $acl_all = $ui->has_complete_category_acls($val['dn'],"department");
214       /* Create actions 
215        */
216       $actions.= "<input class='center' type='image' src='images/lists/edit.png'
217         alt='"._("edit")."'   name='dep_edit_%KEY%' title='"._("Edit this entry")."'>";
218       if(preg_match("/d/",$acl)){
219         $actions.= "<input class='center' type='image' src='images/lists/trash.png'
220           alt='"._("delete")."'   name='dep_del_%KEY%' title='"._("Delete this entry")."'>";
221       }
223       /* Check if this department contains sub-departments
224          Display different image in this case
225        */
226       $sub_folders= FALSE;
227       foreach($this->config->departments as $keyd){
228         if(preg_match("/,".normalizePreg($val['dn'])."$/",$keyd)){
229           $sub_folders = TRUE;
230         }
231       }
233       /* Create entry name 
234        */      
235       $name = $val[$dep_data['ATTR']][0];
236       if(isset($val['description'])){
237         $name .=  " - [".$val["description"][0]."]";
238       }
240       /* Create title
241        */
242       $title = preg_replace('/ /', '&nbsp;', @LDAP::fix($val['dn']));
244       /* Create checkboxes infront of the entry 
245        */
246       if($name == "."){
247         $field01 = array("string" => "&nbsp;",
248             "attach" => "style='width:20px;'");
249       }else{
250         $field01 = array("string" => "<input type='checkbox' id='item_selected_".$key."' name='item_selected_".$key."'>" ,
251             "attach" => "style='width:20px;'");
252       }
254       /* Create image 
255        */
256       if($sub_folders){
257         $img =  "<img alt='".$dep_data['ATTR']."' src='".$dep_data['IMG_FULL']."' 
258           class='center' title='".$dep_data['TITLE']."'>";
259       }else{
260         $img =  "<img alt='".$dep_data['ATTR']."' src='".$dep_data['IMG']."' 
261           class='center' title='".$dep_data['TITLE']."'>";
262       }
263      
264       /* Append data to the listing 
265        */
266       $field0 = array("string" => $img, "attach" => "style='text-align:center;width:20px;'");
267       $field1 = array("string" => sprintf($linkopen,$key,$name), 
268           "attach" => "style='' title='".$title."'");
269       $field2 = array("string" => preg_replace("/%KEY%/", $key, $actions), 
270           "attach" => "style='width:60px;border-right:0px;text-align:right;'");
272       $this->AddElement( array($field01,$field0,$field1,$field2));
273     }
275     /* Create summary string for list footer */
276     $num_deps=count($list);
277     $num_dep_str = _("Number of listed departments");
278     $str = "<img class='center' src='images/lists/folder.png'
279               title='".$num_dep_str."' alt='".$num_dep_str."'>&nbsp;".$num_deps."&nbsp;&nbsp;&nbsp;&nbsp;";
280     $this->set_List_Bottom_Info($str);
282   }
283   function Save()
284   {
285     MultiSelectWindow::Save();
286   }
288   function save_object()
289   {
290     /* Save automatic created POSTs like regex, checkboxes */
291     MultiSelectWindow::save_object();   
292   }
294 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
295 ?>