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 divListUsers extends MultiSelectWindow
24 {
26 /* Current base */
27 var $selectedBase = "";
28 var $departments = array();
30 /* Regex */
31 var $Regex = "*";
33 /* CheckBoxes */
34 var $ShowTemplates ;
35 var $ShowFunctionalUsers;
36 var $ShowUnixUsers;
37 var $ShowMailUsers;
38 var $ShowSambaUsers;
39 var $ShowProxyUsers;
41 /* Subsearch checkbox */
42 var $SubSearch = false;
44 var $parent ;
45 var $ui ;
47 function divListUsers (&$config,$parent)
48 {
49 MultiSelectWindow::MultiSelectWindow($config, "Users", "users");
51 $this->parent = $parent;
52 $this->ui = get_userinfo();
54 /* Set list strings */
55 $this->SetTitle(_("List of users"));
56 $this->SetSummary(_("List of users"));
58 /* Result page will look like a headpage */
59 $this->SetHeadpageMode();
61 $this->EnableAplhabet (true);
63 /* Disable buttonsm */
64 $this->EnableCloseButton(false);
65 $this->EnableSaveButton (false);
67 /* Dynamic action col, depending on snapshot icons */
68 $action_col_size = 122;
69 if($this->parent->snapshotEnabled()){
70 $action_col_size += 38;
71 }
73 /* Toggle all selected / deselected */
74 $chk = "<input type='checkbox' id='select_all' name='select_all' title='"._("Select all")."'
75 onClick='toggle_all_(\"^item_selected_[0-9]*$\",\"select_all\");' >";
77 /* set Page header */
78 $this->AddHeader(array("string"=> $chk, "attach"=>"style='width:20px;'"));
79 $this->AddHeader(array("string"=> " ", "attach"=>"style='width:20px;'"));
80 $this->AddHeader(array("string"=>_("Username")." / "._("Department")));
81 $this->AddHeader(array("string"=>_("Properties"), "attach" => "style='width:166px;'"));
82 $this->AddHeader(array("string"=>_("Actions"), "attach" => "style='width:".$action_col_size."px;border-right:0px;text-align:right;'"));
84 $this->AddCheckBox("ShowTemplates" ,msgPool::selectToView(_("Template")) ,sprintf(_("Show %s"),_("templates")), false);
85 $this->AddCheckBox("ShowFunctionalUsers",msgPool::selectToView(_("GOsa object"),"enabled"),sprintf(_("Show %s"),_("functional users")), true);
86 $this->AddCheckBox("ShowUnixUsers" ,msgPool::selectToView(_("Posix"),"enabled") ,sprintf(_("Show %s"),_("POSIX users")), true);
87 $this->AddCheckBox("ShowMailUsers" ,msgPool::selectToView(_("Mail"),"enabled") ,sprintf(_("Show %s"),_("mail users")), true);
88 $this->AddCheckBox("ShowSambaUsers" ,msgPool::selectToView(_("Samba"),"enabled") ,sprintf(_("Show %s"),_("samba users")), true);
89 $this->AddCheckBox("ShowProxyUsers" ,msgPool::selectToView(_("Proxy"),"enabled") ,sprintf(_("Show %s"),_("proxy users")), true);
91 /* Add SubSearch checkbox */
92 $this->AddCheckBox(SEPERATOR);
93 $this->AddCheckBox("SubSearch", msgPool::selectToView("","subsearch"), msgPool::selectToView("","subsearch_small"), false);
95 /* Name ,Text ,Default , Connect with alphabet */
96 $this->AddRegex ("Regex", _("Display users matching"),"*" , true);
97 }
100 function GenHeader()
101 {
102 /* Get all departments within this subtree */
103 $base = $this->config->current['BASE'];
104 $options = $this->create_department_list($this->module);
106 /* Get copy & paste icon */
107 $ui = get_userinfo();
108 $acl = $ui->get_permissions($this->selectedBase,"users/user");
109 $acl_all = $ui->has_complete_category_acls($this->selectedBase,"users");
111 /* Add default header */
112 $listhead = MultiSelectWindow::get_default_header();
113 $listhead .=
114 _("Base")." <select name='CurrentMainBase' onChange='mainform.submit()' class='center'>$options</select>".
115 " <input class='center' type='image' src='images/lists/submit.png' align='middle'
116 title='"._("Submit department")."' name='submit_department' alt='". _("Submit")."'> ";
119 /* Create Layers menu */
120 $s = ".|"._("Actions")."|\n";
122 /* Append create options */
123 if(preg_match("/c/",$acl)) {
124 $s .= "..|<img src='images/lists/new.png' alt='' border='0' class='center'>".
125 " "._("Create")."|\n";
126 $s.= "...|<input class='center' type='image' src='images/list_new_user.png' alt=''>".
127 " "._("User")."|user_new|\n";
128 $s.= "...|<input class='center' type='image' src='images/lists/new.png' alt=''>".
129 " "._("Template")."|user_tplnew|\n";
130 }
132 /* Multiple options */
133 $s.= "..|---|\n";
134 $s.= "..|<img src='images/lists/edit.png' alt='' border='0' class='center'>".
135 " "._("Edit")."|"."multiple_edit|\n";
136 $s.= "..|<img src='images/list_password.png' alt='' border='0' class='center'>".
137 " "._("Change password")."|"."multiple_password_change|\n";
138 $s.= "..|<img src='images/lists/trash.png' alt='' border='0' class='center'>".
139 " "._("Remove")."|"."remove_multiple|\n";
140 $s.= "..|<img src='images/wizard.png' alt='' border='0' class='center'>".
141 " "._("Apply template")."|"."templatize_multiple|\n";
143 /* Add event tag */
144 if(class_available("DaemonEvent")){
145 $events = DaemonEvent::get_event_types(USER_EVENT);
146 if(count($events['BY_CLASS'])){
147 $s.= "..|---|\n";
148 foreach($events['BY_CLASS'] as $name => $event){
149 $s.= "..|".$event['MenuImage']." ".$event['s_Menu_Name']."|event_".$name."\n";
150 }
151 }
152 }
154 $s .= $this->parent->get_copypaste_header($this->selectedBase,$this->module);
155 $s .= $this->parent->get_snapshot_header($this->selectedBase,$this->module);
157 $this->SetDropDownHeaderMenu($s);
158 $this->SetListHeader($listhead);
159 }
161 /* so some basic settings */
162 function execute()
163 {
164 $this->ClearElementsList();
165 $this->GenHeader();
166 }
168 function setEntries($list)
169 {
170 /********************
171 Variable init
172 ********************/
174 $num_users = 0;
175 $num_templates = 0;
177 /* Variable initialation */
178 $enviro = $posix = $maila = $faxac = $samba = $netatalk = "";
179 $empty = "<img class='center' src='images/empty.png' style='width:16px;height:16px;' alt='-'>";
180 $userimg = "<img class='center' src='images/select_user.png' alt='User' title='%s'>";
181 $tplimg = "<img class='center' src='images/select_template.png' alt='Template' title='%s'>";
182 $editlink = "<a href='?plug=".validate($_GET['plug'])."&id=%s&act=edit_entry'>%s</a>";
184 /* Dynamic action col, depending on snapshot icons */
185 $action_col_size = 122;
186 if($this->parent->snapshotEnabled()){
187 $action_col_size += 38;
188 }
190 /* Possilbe objectClass image combinations */
191 $possibleAccounts = array(
192 "posixAccount" => array("VAR"=>"posix" ,"IMG"=>"posiximg"),
193 "gotoEnvironment" => array("VAR"=>"enviro" ,"IMG"=>"eviroimg"),
194 "gosaMailAccount" => array("VAR"=>"maila" ,"IMG"=>"mailimg"),
195 "goFaxAccount" => array("VAR"=>"faxac" ,"IMG"=>"faximg"),
196 "sambaSamAccount" => array("VAR"=>"samba" ,"IMG"=>"sambaimg"),
197 "apple-user" => array("VAR"=>"netatalk" ,"IMG"=>"netatalkimg"));
199 /* Pictures for Extensions */
200 $usrimg ="<input class='center' type='image' src='images/select_user.png' alt='"._("GOsa")."'
201 name='user_edit_%KEY%-user' title='"._("Edit generic properties")."'>";
202 $posiximg = "<input class='center' type='image' src='images/penguin.png' alt='"._("Posix")."'
203 name='user_edit_%KEY%-posixAccount' title='"._("Edit UNIX properties")."'>";
204 $eviroimg = "<input class='center' type='image' src='images/smallenv.png' alt='"._("Environment")."'
205 name='user_edit_%KEY%-environment' title='"._("Edit environment properties")."'>";
206 $mailimg = "<input class='center' type='image' src='images/mailto.png' alt='"._("Mail")."'
207 name='user_edit_%KEY%-mailAccount' title='"._("Edit mail properties")."'>";
208 $fonimg = "<input class='center' type='image' src='images/%image%' alt='"._("Phone")."'
209 name='user_edit_%KEY%-phoneAccount' title='"._("Edit phone properties")."%title%'>";
210 $faximg = "<input class='center' type='image' src='images/fax_small.png' alt='"._("Fax")."'
211 name='user_edit_%KEY%-gofaxAccount' title='"._("Edit fax properies")."'>";
212 $sambaimg = "<input class='center' type='image' src='images/select_winstation.png' alt='"._("Samba")."'
213 name='user_edit_%KEY%-sambaAccount' title='"._("Edit samba properties")."'>";
214 $netatalkimg = "<input class='center' type='image' src='images/select_netatalk.png' alt='"._("Netatalk")."'
215 name='user_edit_%KEY%-netatalk' title='"._("Edit netatalk properties")."'>";
216 $tplcreateuserimg = "<input type='image' class='center' src='images/lists/new.png' alt='"._("Create user from template")."'
217 name='userfrom_tpl_%KEY%' title='"._("Create user with this template")."'>";
219 /********************
220 END :: Variable init
221 ********************/
224 /********************
225 Append entries to divlist
226 ********************/
228 $ui = get_userinfo();
230 // Test Every Entry and generate divlist Array
231 foreach($list as $key => $val){
233 /* Create action icons */
234 $action= "";
236 /* Add copy & cut icons */
237 $acl = $ui->get_permissions($val['dn'],"users/user");
238 $acl_all = $ui->has_complete_category_acls($val['dn'],"users");
240 /* Add copy & cut functionality */
241 $action.= $this->parent->get_copypaste_action($val['dn'],"users","user");
243 /* Add deactivate status */
244 $lock_status = "";
246 if(isset($val['userPassword'][0]) && preg_match("/^\{[^\}]/",$val['userPassword'][0])){
247 if(preg_match("/^[^\}]*+\}!/",$val['userPassword'][0])){
248 $lock_status = "<input class='center' type='image' src='images/lists/locked.png'
249 alt='"._("inactive")."' name='toggle_lock_status_%KEY%'>";
250 }else{
251 $lock_status = "<input class='center' type='image' src='images/lists/unlocked.png'
252 alt='"._("active")."' name='toggle_lock_status_%KEY%'>";
253 }
254 }else{
255 $lock_status = "<img src='images/empty.png' alt=' ' class='center'>";
256 }
258 /* Generate edit icon */
259 $action.= "<input class='center' type='image' src='images/lists/edit.png' alt='"._("edit")."'
260 name='user_edit_%KEY%' title='".msgPool::editButton(_("user"))."'>";
262 /* Add deactivate status if we are allowed to */
263 if (preg_match("/w/",$ui->get_permissions($val['dn'],"users/password"))){
264 $action.= $lock_status;
265 }else{
266 $action.="<img src='images/empty.png' alt=' ' class='center'>";
267 }
269 /* Add Password change icon, if we are able to write users/password */
270 if(!in_array_ics("gosaUserTemplate",$val['objectClass']) && preg_match("/w/",$ui->get_permissions($val['dn'],"users/password"))) {
271 $action.= "<input class='center' type='image' src='images/list_password.png' alt='"._("password")."'
272 name='user_chgpw_%KEY%' title='"._("Change password")."'>";
273 }else{
274 $action.= "<img class='center' src='images/empty.png' alt=' '
275 title='"._("Not allowed")."'>";
276 }
278 /* Add snapshot functionality */
279 $action.= $this->parent->get_snapshot_action($val['dn'],$this->module);
281 /* Add remove icon, if we are allowed to remove the current user */
282 if(preg_match("/d/",$acl)) {
283 $action.= "<input class='center' type='image' src='images/lists/trash.png' alt='"._("delete")."'
284 name='user_del_%KEY%' title='"._("Delete user")."'>";
285 }else{
286 $action.= "<img class='center' src='images/empty.png' alt=' '
287 title='"._("Not allowed")."'>";
288 }
290 /* Create phonaccopunt informationm, if conencted && is phoneAccount */
291 if((in_array("goFonAccount" ,$val['objectClass']))){
293 /* Set defaults */
294 $fonac = preg_replace("/%image%/", "select_phone.png", $fonimg);
295 $fonac = preg_replace("/%KEY%/", "$key", $fonac);
296 $fonac = preg_replace("/%title%/", "", $fonac);
298 }else{
299 $fonac=$empty;
300 }
302 /* Set images for different types of objectClasses */
303 foreach($possibleAccounts as $objectClass => $Settigns){
304 if(in_array($objectClass ,$val['objectClass'])){
305 $$Settigns['VAR'] = preg_replace("/%KEY%/", "$key", $$Settigns['IMG']);
306 }else{
307 $$Settigns['VAR'] = $empty;
308 }
309 }
311 /* Create userimg */
312 if(in_array("gosaUserTemplate",$val['objectClass'])){
313 $tpl = preg_replace("/%KEY%/", "$key", $tplimg);
314 $s_img_create_from_template = preg_replace("/%KEY%/", "$key", $tplcreateuserimg);
315 $num_templates ++;
316 }else{
317 $s_img_create_from_template = "";
318 $tpl = $userimg;
319 $num_users ++;
320 }
322 /* Insert key into userimg */
323 $usrimg2 = preg_replace("/%KEY%/", "$key", $usrimg);
325 // Generate caption for rows
326 if (isset($val["sn"]) && isset($val["givenName"])){
327 $display= $val["sn"][0].", ".$val["givenName"][0]." [".$val["uid"][0]."]";
328 } else {
329 $display= "[".$val["uid"][0]."]";
330 }
332 /* Connect all images */
333 $UseImg = $usrimg2." ".$posix." ".$enviro." ".$maila." ".$fonac." ".$faxac." ".$samba." ".$netatalk;
335 /* Cutted objects should be displayed in light grey */
336 if($this->parent->CopyPasteHandler){
337 foreach($this->parent->CopyPasteHandler->queue as $queue_key => $queue_data){
338 if($queue_data['dn'] == $val['dn']) {
339 $display = "<font color='#999999'>".$display."</font>";
340 break;
341 }
342 }
343 }
345 /* Create each field */
346 $field0 = array("string" => "<input type='checkbox' id='item_selected_".$key."' name='item_selected_".$key."'>" ,
347 "attach" => "style='width:20px;'");
348 $field1 = array("string" => sprintf($tpl,$val['dn']), "attach" => "style='text-align:center;width:20px;'");
349 $field2 = array("string" => sprintf($editlink,$key,$display), "attach" => "style='' title='".preg_replace('/ /', ' ', @LDAP::fix($val['dn']))."'");
350 $field3 = array("string" => $UseImg, "attach" => "style='width:166px;'");
351 $field4 = array("string" => $s_img_create_from_template.preg_replace("/%KEY%/", "$key", $action),
352 "attach" => "style='width:".$action_col_size."px;border-right:0px; text-align:right;'");
353 /* Add to list */
354 $add = array($field0,$field1,$field2,$field3,$field4);
355 $this->AddElement($add);
357 // Template or User
358 if(in_array("gosaUserTemplate",$val['objectClass'])){
359 $tpls[strtolower( $val['sn']['0'].$val['uid']['0'])]=$add;
360 }else{
361 $users[strtolower( $val['sn']['0'].$val['uid']['0'])]=$add;
362 }
363 }
366 /* Create summary string for list footer */
367 $num_deps=0;
368 if(!$this->SubSearch){
369 $num_deps = count($this->Added_Departments);
370 }
371 $num_users = count($list);
373 $num_user_str = _("Number of listed users");
374 $num_dep_str = _("Number of listed departments");
376 $str = "<img class='center' src='images/select_user.png'
377 title='".$num_user_str."' alt='".$num_user_str."'> ".$num_users." ";
378 $str.= "<img class='center' src='images/lists/folder.png'
379 title='".$num_dep_str."' alt='".$num_dep_str."'> ".$num_deps." ";
381 $this->set_List_Bottom_Info($str);
382 }
384 function Save()
385 {
386 MultiSelectWindow :: Save();
387 }
389 function save_object()
390 {
391 /* Save automatic created POSTs like regex, checkboxes */
392 MultiSelectWindow::save_object();
393 }
394 }
395 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
396 ?>