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();
53 $this->SetInformation(_("This menu allows you to create, delete and edit selected departments. Having a large number of departments, you might prefer the range selectors on top of the department list."));
55 /* Disable buttonsm */
56 $this->EnableCloseButton(false);
57 $this->EnableSaveButton (false);
61 /* Toggle all selected / deselected */
62 $chk = "<input type='checkbox' id='select_all' name='select_all'
63 onClick='toggle_all_(\"^item_selected_[a-zA-Z0-9\\/\=]*$\",\"select_all\");' >";
65 /* set Page header */
66 $this->AddHeader(array("string"=> $chk, "attach"=>"style='width:20px;'"));
67 $this->AddHeader(array("string" => " ", "attach" => "style='text-align:center;width:20px;'"));
68 $this->AddHeader(array("string"=>_("Department name"), "attach" => "style=''"));
69 $this->AddHeader(array("string" =>_("Actions"), "attach" => "style='width:60px;border-right:0px;text-align:right;'"));
72 /* Add SubSearch checkbox */
73 $this->AddCheckBox("SubSearch", _("Select to search within subtrees"), _("Search in subtrees"), false);
75 /* Name ,Text ,Default , Connect with alphabet */
76 $this->AddRegex ("Regex", _("Regular expression for matching department names"), "*" , true);
77 }
80 function GenHeader()
81 {
82 /* Prepare departments,
83 which are shown in the listbox on top of the listbox
84 */
85 $options= "";
87 /* Get all departments within this subtree */
88 $ui= get_userinfo();
89 $first = "";
90 $found = FALSE;
91 $base = $this->config->current['BASE'];
93 /* Add base */
94 $tmp = array();
95 $tmp[] = array("dn"=>$this->config->current['BASE']);
96 $tmp= array_merge($tmp,get_list("(&(|(ou=*)(description=*))(objectClass=gosaDepartment))", $this->module, $base,
97 array("ou", "description"), GL_SIZELIMIT | GL_SUBSEARCH));
99 $deps = array();
100 foreach($tmp as $tm){
101 $deps[$tm['dn']] = $tm['dn'];
102 }
104 /* Load possible departments */
105 $ui= get_userinfo();
106 $tdeps= $ui->get_module_departments("department");
107 $ids = $this->config->idepartments;
108 $first = "";
109 $found = FALSE;
110 foreach($ids as $dep => $name){
111 if(isset($deps[$dep]) && in_array_ics($dep, $tdeps)){
113 /* Keep first base dn in mind, we could need this
114 * info if no valid base was found
115 */
116 if(empty($first)) {
117 $first = $dep['dn'];
118 }
120 $value = $ids[$dep];
121 if ($this->selectedBase == $dep){
122 $found = TRUE;
123 $options.= "<option selected='selected' value='".$dep."'>$value</option>";
124 } else {
125 $options.= "<option value='".$dep."'>$value</option>";
126 }
127 }
128 }
130 /* The currently used base is not visible with your acl setup.
131 * Set base to first useable base.
132 */
133 if(!$found){
134 $this->selectedBase = $first;
135 }
137 /* Generate list head */
138 $ui = get_userinfo();
139 $acl = $ui->get_permissions("ou=dummy,".$this->selectedBase ,"department/department");
141 /* Add default header */
142 $listhead = MultiSelectWindow::get_default_header();
144 $listhead .=
145 " "._("Base")." <select name='CurrentMainBase' onChange='mainform.submit()' class='center'>$options</select>".
146 " <input class='center' type='image' src='images/list_submit.png' align='middle' ".
147 " title='"._("Submit department")."' name='submit_department' alt='"._("Submit")."'> ";
149 /* Create Layers menu */
150 $s = ".|"._("Actions")."|\n";
151 $s .= "..|<img src='images/list_new.png' alt='' border='0' class='center'>".
152 " "._("Create")."|\n";
154 /* Append create options */
155 if(preg_match("/c/",$acl)) {
156 $s.= "...|<input class='center' type='image' src='images/list_new_department' alt=''>".
157 " "._("Department")."|dep_new|\n";
158 }
159 $s.= "..|---|\n";
160 $s.= "..|<img src='images/edittrash.png' alt='' border='0' class='center'>".
161 " "._("Remove")."|"."remove_multiple|\n";
164 $this->SetDropDownHeaderMenu($s);
165 $this->SetListHeader($listhead);
166 }
168 function execute()
169 {
170 $this->ClearElementsList();
171 $this->GenHeader();
172 }
174 function setEntries($list)
175 {
176 $linkopen = "<a href='?plug=".$_GET['plug']."&act=dep_open&dep_id=%s'>%s</a>";
178 $ui = get_userinfo();
179 foreach($list as $key => $val) {
181 $actions= "";
183 $acl = $ui->get_permissions($this->config->departments[$key] ,"department/department");
184 if(preg_match("/r/",$acl)){
185 $actions.= "<input class='center' type='image' src='images/edit.png'
186 alt='"._("edit")."' name='dep_edit_%KEY%' title='"._("Edit this entry")."'>";
187 }
189 if(preg_match("/c/",$acl)){
190 $actions.= "<input class='center' type='image' src='images/edittrash.png'
191 alt='"._("delete")."' name='dep_del_%KEY%' title='"._("Delete this entry")."'>";
192 }
194 if(!isset($this->config->departments[trim($key)])){
195 $this->config->departments[trim($key)]="";
196 }
198 /* check if this department contains sub-departments
199 Display different image in this case
200 */
201 $non_empty="";
202 $nkey= normalizePreg($key);
203 foreach($this->config->departments as $keyd=>$vald ){
204 if(preg_match('/$nkey\/.*/',$keyd)){
205 $non_empty="full";
206 }
207 }
209 $title = preg_replace('/ /', ' ', @LDAP::fix($this->config->departments[$key]));
211 if($val == "."){
212 $field01 = array("string" => " ",
213 "attach" => "style='width:20px;'");
214 }else{
215 $field01 = array("string" => "<input type='checkbox' id='item_selected_".base64_encode($key)."'
216 name='item_selected_".base64_encode($key)."'>" ,
217 "attach" => "style='width:20px;'");
218 }
220 $field0 = array("string" => "<img src='images/".$non_empty."folder.png' title='"._("department")."' alt='department'>", "attach" => "style='text-align:center;width:20px;'");
221 $field1 = array("string" => sprintf($linkopen,base64_encode($key),$val), "attach" => "style='' title='".$title."'");
222 $field2 = array("string" => preg_replace("/%KEY%/", base64_encode($key), $actions), "attach" => "style='width:60px;border-right:0px;text-align:
223 right;'");
225 $this->AddElement( array($field01,$field0,$field1,$field2));
226 }
228 /* Create summary string for list footer */
229 $num_deps=count($list);
230 $num_dep_str = _("Number of listed departments");
231 $str = "<img class='center' src='images/folder.png'
232 title='".$num_dep_str."' alt='".$num_dep_str."'> ".$num_deps." ";
233 $this->set_List_Bottom_Info($str);
235 }
236 function Save()
237 {
238 MultiSelectWindow::Save();
239 }
241 function save_object()
242 {
243 /* Save automatic created POSTs like regex, checkboxes */
244 MultiSelectWindow::save_object();
245 }
246 }
247 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
248 ?>