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 = "*";
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");
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();
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" => " ", "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");
140 /* Add default header */
141 $listhead = MultiSelectWindow::get_default_header();
143 $listhead .=
144 " "._("Base")." <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")."'> ";
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 " "._("Create")."|\n";
155 $s.= "...|<input class='center' type='image' src='plugins/departments/images/department.png' alt=''>".
156 " "._("Department")." (ou)|dep_new_ou|\n";
158 $s.= "...|<input class='center' type='image' src='plugins/departments/images/department.png' alt=''>".
159 " "._("Organization")." (o)|dep_new_o|\n";
161 $s.= "...|<input class='center' type='image' src='plugins/departments/images/department.png' alt=''>".
162 " "._("Country")." (c)"."|dep_new_c|\n";
164 $s.= "...|<input class='center' type='image' src='plugins/departments/images/department.png' alt=''>".
165 " "._("Locality")." (l)|dep_new_l|\n";
167 $s.= "...|<input class='center' type='image' src='plugins/departments/images/department.png' alt=''>".
168 " "._("Alias")."|dep_new_alias|\n";
170 $s.= "...|<input class='center' type='image' src='plugins/departments/images/department.png' alt=''>".
171 " "._("Referal")."|dep_new_referal|\n";
173 $s.= "..|---|\n";
174 }
175 $s.= "..|<img src='images/lists/trash.png' alt='' border='0' class='center'>".
176 " "._("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']."&act=dep_open&dep_id=%s'>%s</a>";
193 $ui = get_userinfo();
194 foreach($list as $key => $val) {
196 $actions= "";
198 if(!isset($this->config->departments[$key])){
200 $field01 = array("string" => " ", "attach" => "style='width:20px;'");
201 $field0 = array("string" => "<img src='images/".$non_empty."lists/folder.png'
202 title='"._("department")."' alt='department'>",
203 "attach" => "style='text-align:center;width:20px;'");
204 $field1 = array("string" => $val, "attach" => "style='' title='".$val."'");
205 $field2 = array("string" => "", "attach" => "style='border-right: 0px;'");
207 }else{
208 $acl = $ui->get_permissions($this->config->departments[$key] ,"department/department");
209 $acl_all = $ui->has_complete_category_acls($this->config->departments[$key] ,"department");
211 $actions.= "<input class='center' type='image' src='images/lists/edit.png'
212 alt='"._("edit")."' name='dep_edit_%KEY%' title='"._("Edit this entry")."'>";
214 if(preg_match("/d/",$acl)){
215 $actions.= "<input class='center' type='image' src='images/lists/trash.png'
216 alt='"._("delete")."' name='dep_del_%KEY%' title='"._("Delete this entry")."'>";
217 }
219 if(!isset($this->config->departments[trim($key)])){
220 $this->config->departments[trim($key)]="";
221 }
223 /* check if this department contains sub-departments
224 Display different image in this case
225 */
226 $non_empty="";
227 $nkey= normalizePreg($key);
228 foreach($this->config->departments as $keyd=>$vald ){
229 if(preg_match('/$nkey\/.*/',$keyd)){
230 $non_empty="full";
231 }
232 }
234 $title = preg_replace('/ /', ' ', @LDAP::fix($this->config->departments[$key]));
236 if($val == "."){
237 $field01 = array("string" => " ",
238 "attach" => "style='width:20px;'");
239 }else{
240 $field01 = array("string" => "<input type='checkbox' id='item_selected_".base64_encode($key)."'
241 name='item_selected_".base64_encode($key)."'>" ,
242 "attach" => "style='width:20px;'");
243 }
245 $field0 = array("string" => "<img src='images/".$non_empty."lists/folder.png' title='"._("department")."' alt='department'>", "attach" => "style='text-align:center;width:20px;'");
246 $field1 = array("string" => sprintf($linkopen,base64_encode($key),$val), "attach" => "style='' title='".$title."'");
247 $field2 = array("string" => preg_replace("/%KEY%/", base64_encode($key), $actions), "attach" => "style='width:60px;border-right:0px;text-align:
248 right;'");
250 }
251 $this->AddElement( array($field01,$field0,$field1,$field2));
252 }
254 /* Create summary string for list footer */
255 $num_deps=count($list);
256 $num_dep_str = _("Number of listed departments");
257 $str = "<img class='center' src='images/lists/folder.png'
258 title='".$num_dep_str."' alt='".$num_dep_str."'> ".$num_deps." ";
259 $this->set_List_Bottom_Info($str);
261 }
262 function Save()
263 {
264 MultiSelectWindow::Save();
265 }
267 function save_object()
268 {
269 /* Save automatic created POSTs like regex, checkboxes */
270 MultiSelectWindow::save_object();
271 }
272 }
273 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
274 ?>