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();
139 /* Add default header */
140 $listhead = MultiSelectWindow::get_default_header();
142 $listhead .=
143 " "._("Base")." <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")."'> ";
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 " "._("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 " "._("Department")." (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 " "._("Organization")." (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 " "._("Country")." (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 " "._("Locality")." (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 " "._("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 " "._("Referal")."|dep_new_referal|\n";
183 }
185 $s.= "..|---|\n";
186 $s.= "..|<img src='images/lists/trash.png' alt='' border='0' class='center'>".
187 " "._("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']."&act=dep_open&dep_id=%s'>%s</a>";
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_FULL" => "plugins/departments/images/locality.png",
214 "IMG" => "plugins/departments/images/locality.png", "ABBR" => "l");
215 $types['organizationalUnit'] = array("ACL" => "department", "ATTR" => "ou",
216 "TITLE" => _("Department"),
217 "IMG_FULL" => "images/lists/folder-full.png",
218 "IMG" => "images/lists/folder.png", "ABBR" => "ou");
219 $types['organization'] = array("ACL" => "organization", "ATTR" => "o",
220 "TITLE" => _("Department"),
221 "IMG_FULL" => "plugins/departments/images/organization.png",
222 "IMG" => "plugins/departments/images/organization.png", "ABBR" => "o");
223 $types['Alias??'] = array("ACL" => "alias" , "ATTR" => "alias?",
224 "TITLE" => _("Department"),
225 "IMG_FULL" => "plugins/departments/images/department_alias.png",
226 "IMG" => "plugins/departments/images/department_alias.png", "ABBR" => "alias");
227 $types['Referal??'] = array("ACL" => "referal", "ATTR" => "referal?",
228 "TITLE" => _("Department"),
229 "IMG_FULL" => "plugins/departments/images/department_referal.png",
230 "IMG" => "plugins/departments/images/department_referal.png", "ABBR" => "referal");
232 $this->departments = $list;
234 $ui = get_userinfo();
235 foreach($list as $key => $val) {
237 $actions= "";
239 /* Detect department type
240 */
241 $dep_data = array();
242 foreach($types as $type => $data){
243 if(in_array($type,$val['objectClass'])){
244 $dep_data = $data;
245 break;
246 }
247 }
249 /* Warn if there was an unknown department type found
250 */
251 if(!count($dep_data)) {
252 trigger_error("Unknown department type given. Skipped '".$val['dn']."'.");
253 continue;
254 }
256 /* Get permissions
257 */
258 $acl = $ui->get_permissions($val['dn'],"department/".$dep_data['ACL']);
259 $acl_all = $ui->has_complete_category_acls($val['dn'],"department");
261 /* Create actions
262 */
263 $actions.= "<input class='center' type='image' src='images/lists/edit.png'
264 alt='"._("edit")."' name='dep_edit_%KEY%' title='"._("Edit this entry")."'>";
265 if(preg_match("/d/",$acl)){
266 $actions.= "<input class='center' type='image' src='images/lists/trash.png'
267 alt='"._("delete")."' name='dep_del_%KEY%' title='"._("Delete this entry")."'>";
268 }
270 /* Check if this department contains sub-departments
271 Display different image in this case
272 */
273 $sub_folders= FALSE;
274 foreach($this->config->departments as $keyd){
275 if(preg_match("/,".normalizePreg($val['dn'])."$/",$keyd)){
276 $sub_folders = TRUE;
277 }
278 }
280 /* Create entry name
281 */
282 $name = $val[$dep_data['ATTR']][0];
283 if(isset($val['description'])){
284 $name .= " - [".$val["description"][0]."]";
285 }
287 /* Create title
288 */
289 $title = preg_replace('/ /', ' ', @LDAP::fix($val['dn']));
291 /* Create checkboxes infront of the entry
292 */
293 if($name == "."){
294 $field01 = array("string" => " ",
295 "attach" => "style='width:20px;'");
296 }else{
297 $field01 = array("string" => "<input type='checkbox' id='item_selected_".$key."' name='item_selected_".$key."'>" ,
298 "attach" => "style='width:20px;'");
299 }
301 /* Create image
302 */
303 if($sub_folders){
304 $img = "<img src='".$dep_data['IMG_FULL']."' class='center' title='".$dep_data['TITLE']."'>";
305 }else{
306 $img = "<img src='".$dep_data['IMG']."' class='center' title='".$dep_data['TITLE']."'>";
307 }
309 /* Append data to the listing
310 */
311 $field0 = array("string" => $img, "attach" => "style='text-align:center;width:20px;'");
312 $field1 = array("string" => sprintf($linkopen,$key,$name),
313 "attach" => "style='' title='".$title."'");
314 $field2 = array("string" => preg_replace("/%KEY%/", $key, $actions),
315 "attach" => "style='width:60px;border-right:0px;text-align:right;'");
317 $this->AddElement( array($field01,$field0,$field1,$field2));
318 }
320 /* Create summary string for list footer */
321 $num_deps=count($list);
322 $num_dep_str = _("Number of listed departments");
323 $str = "<img class='center' src='images/lists/folder.png'
324 title='".$num_dep_str."' alt='".$num_dep_str."'> ".$num_deps." ";
325 $this->set_List_Bottom_Info($str);
327 }
328 function Save()
329 {
330 MultiSelectWindow::Save();
331 }
333 function save_object()
334 {
335 /* Save automatic created POSTs like regex, checkboxes */
336 MultiSelectWindow::save_object();
337 }
338 }
339 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
340 ?>