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);
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" => " ", "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 /* Get all departments within this subtree */
80 $ui= get_userinfo();
81 $base = $this->config->current['BASE'];
82 $options = $this->create_department_list($this->module);
83 $listhead = MultiSelectWindow::get_default_header();
84 $listhead .=
85 " "._("Base")." <select name='CurrentMainBase' onChange='mainform.submit()' class='center'>$options</select>".
86 " <input class='center' type='image' src='images/lists/submit.png' align='middle' ".
87 " title='"._("Submit department")."' name='submit_department' alt='"._("Submit")."'> ";
89 /* Create Layers menu */
90 $s = ".|"._("Actions")."|\n";
92 /* Append create options */
93 $s .= "..|<img src='images/lists/new.png' alt='' border='0' class='center'>".
94 " "._("Create")."|\n";
96 /* Add all createable department types
97 */
98 $types = $this->parent->get_support_departments();
99 foreach($types as $type){
100 if(preg_match("/c/",$ui->get_permissions($this->selectedBase ,"department/".$type['ACL']))){
101 $s.= "...|<input class='center' type='image' src='".$type['IMG']."' alt='".$type['ATTR']."'>".
102 " ".$type['TITLE']." (".$type['ATTR'].")|dep_new_".$type['ATTR']."|\n";
103 }
104 }
106 /* Add remove action
107 */
108 $s.= "..|---|\n";
109 $s.= "..|<img src='images/lists/trash.png' alt='' border='0' class='center'>".
110 " "._("Remove")."|"."remove_multiple|\n";
113 $this->SetDropDownHeaderMenu($s);
114 $this->SetListHeader($listhead);
115 }
117 function execute()
118 {
119 $this->ClearElementsList();
120 $this->GenHeader();
121 }
123 function setEntries($list)
124 {
125 $linkopen = "<a href='?plug=".$_GET['plug']."&post_id=".$this->post_id."&act=dep_open&dep_id=%s'>%s</a>";
126 $types = $this->parent->get_support_departments();
127 $this->departments = $list;
129 $ui = get_userinfo();
130 foreach($list as $key => $val) {
132 $actions= "";
134 /* Detect department type
135 */
136 $dep_data = array();
137 foreach($types as $type => $data){
138 if(in_array($type,$val['objectClass'])){
139 $dep_data = $data;
140 break;
141 }
142 }
144 /* Warn if there was an unknown department type found
145 */
146 if(!count($dep_data)) {
147 trigger_error("Unknown department type given. Skipped '".$val['dn']."'.");
148 continue;
149 }
151 /* Get permissions
152 */
153 $acl = $ui->get_permissions($val['dn'],"department/".$dep_data['ACL']);
155 /* Create actions
156 */
157 $actions.= "<input class='center' type='image' src='images/lists/edit.png'
158 alt='"._("edit")."' name='dep_edit_%KEY%' title='"._("Edit this entry")."'>";
159 if(preg_match("/d/",$acl)){
160 $actions.= "<input class='center' type='image' src='images/lists/trash.png'
161 alt='"._("delete")."' name='dep_del_%KEY%' title='"._("Delete this entry")."'>";
162 }
164 /* Create entry name
165 */
166 $name = $val[$dep_data['ATTR']][0];
167 if(isset($val['description'])){
168 $name .= " - [".$val["description"][0]."]";
169 }
171 /* Create title
172 */
173 $title = LDAP::fix($val['dn']);
175 /* Create checkboxes infront of the entry
176 */
177 if($name == "."){
178 $field01 = array("string" => " ",
179 "attach" => "style='width:20px;'");
180 }else{
181 $field01 = array("string" => "<input type='checkbox' id='item_selected_".$key."' name='item_selected_".$key."'>" ,
182 "attach" => "style='width:20px;'");
183 }
185 $img = "<img alt='".$dep_data['ATTR']."' src='".$dep_data['IMG']."'
186 class='center' title='".$dep_data['TITLE']."'>";
188 /* Append data to the listing
189 */
190 $field0 = array("string" => $img, "attach" => "style='text-align:center;width:20px;'");
191 $field1 = array("string" => sprintf($linkopen,$key,$name),
192 "attach" => "style='' title='".$title."'");
193 $field2 = array("string" => preg_replace("/%KEY%/", $key, $actions),
194 "attach" => "style='width:60px;border-right:0px;text-align:right;'");
196 $this->AddElement( array($field01,$field0,$field1,$field2));
197 }
199 /* Create summary string for list footer */
200 $num_deps=count($list);
201 $num_dep_str = _("Number of listed departments");
202 $str = "<img class='center' src='images/lists/folder.png'
203 title='".$num_dep_str."' alt='".$num_dep_str."'> ".$num_deps." ";
204 $this->set_List_Bottom_Info($str);
206 }
207 function Save()
208 {
209 MultiSelectWindow::Save();
210 }
212 function save_object()
213 {
214 /* Save automatic created POSTs like regex, checkboxes */
215 MultiSelectWindow::save_object();
216 }
217 }
218 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
219 ?>