Code

Added country class.
[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")."&nbsp;(ou)|dep_new_ou|\n";
158       $s.= "...|<input class='center' type='image' src='plugins/departments/images/department.png' alt=''>".
159         "&nbsp;"._("Organization")."&nbsp;(o)|dep_new_o|\n";
161       $s.= "...|<input class='center' type='image' src='plugins/departments/images/department.png' alt=''>".
162         "&nbsp;"._("Country")."&nbsp;(c)"."|dep_new_c|\n";
164       $s.= "...|<input class='center' type='image' src='plugins/departments/images/department.png' alt=''>".
165         "&nbsp;"._("Locality")."&nbsp;(l)|dep_new_l|\n";
167       $s.= "...|<input class='center' type='image' src='plugins/departments/images/department.png' alt=''>".
168         "&nbsp;"._("Alias")."|dep_new_alias|\n";
170       $s.= "...|<input class='center' type='image' src='plugins/departments/images/department.png' alt=''>".
171         "&nbsp;"._("Referal")."|dep_new_referal|\n";
173       $s.= "..|---|\n";
174     }
175     $s.= "..|<img src='images/lists/trash.png' alt='' border='0' class='center'>".
176       "&nbsp;"._("Remove")."|"."remove_multiple|\n";
179     $this->SetDropDownHeaderMenu($s);
180     $this->SetListHeader($listhead);
181   }
183   function execute()
184   {
185     $this->ClearElementsList();
186     $this->GenHeader();
187   }
189   function setEntries($list)
190   {
191     $linkopen = "<a href='?plug=".$_GET['plug']."&amp;act=dep_open&amp;dep_id=%s'>%s</a>";
193     $ui = get_userinfo();
194     foreach($list as $key => $val) {
196       $actions= "";      
198       $acl = $ui->get_permissions($this->config->departments[$key] ,"department/department");
199       $acl_all = $ui->has_complete_category_acls($this->config->departments[$key] ,"department");
201       $actions.= "<input class='center' type='image' src='images/lists/edit.png'
202         alt='"._("edit")."'   name='dep_edit_%KEY%' title='"._("Edit this entry")."'>";
204       if(preg_match("/d/",$acl)){
205         $actions.= "<input class='center' type='image' src='images/lists/trash.png'
206           alt='"._("delete")."'   name='dep_del_%KEY%' title='"._("Delete this entry")."'>";
207       }
209       if(!isset($this->config->departments[trim($key)])){
210         $this->config->departments[trim($key)]="";
211       }
213       /* check if this department contains sub-departments
214          Display different image in this case
215        */
216       $non_empty="";
217       $nkey= normalizePreg($key);
218       foreach($this->config->departments as $keyd=>$vald ){
219         if(preg_match('/$nkey\/.*/',$keyd)){
220           $non_empty="full";
221         }
222       }
224       $title = preg_replace('/ /', '&nbsp;', @LDAP::fix($this->config->departments[$key]));
226       if($val == "."){
227         $field01 = array("string" => "&nbsp;",
228             "attach" => "style='width:20px;'");
229       }else{
230         $field01 = array("string" => "<input type='checkbox' id='item_selected_".base64_encode($key)."' 
231             name='item_selected_".base64_encode($key)."'>" ,
232             "attach" => "style='width:20px;'");
233       }
235       $field0 = array("string" => "<img src='images/".$non_empty."lists/folder.png' title='"._("department")."' alt='department'>", "attach" => "style='text-align:center;width:20px;'");
236       $field1 = array("string" => sprintf($linkopen,base64_encode($key),$val), "attach" => "style='' title='".$title."'");
237       $field2 = array("string" => preg_replace("/%KEY%/", base64_encode($key), $actions), "attach" => "style='width:60px;border-right:0px;text-align:
238           right;'");
240       $this->AddElement( array($field01,$field0,$field1,$field2));
241     }
243     /* Create summary string for list footer */
244     $num_deps=count($list);
245     $num_dep_str = _("Number of listed departments");
246     $str = "<img class='center' src='images/lists/folder.png'
247               title='".$num_dep_str."' alt='".$num_dep_str."'>&nbsp;".$num_deps."&nbsp;&nbsp;&nbsp;&nbsp;";
248     $this->set_List_Bottom_Info($str);
250   }
251   function Save()
252   {
253     MultiSelectWindow::Save();
254   }
256   function save_object()
257   {
258     /* Save automatic created POSTs like regex, checkboxes */
259     MultiSelectWindow::save_object();   
260   }
262 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
263 ?>