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();
60 $this->SetInformation(_("This menu allows you to create, edit and delete selected users. Having a great number of users, you may want to use the range selectors on top of the user list."));
62 $this->EnableAplhabet (true);
64 /* Disable buttonsm */
65 $this->EnableCloseButton(false);
66 $this->EnableSaveButton (false);
68 /* Dynamic action col, depending on snapshot icons */
69 $action_col_size = 122;
70 if($this->parent->snapshotEnabled()){
71 $action_col_size += 38;
72 }
74 /* Toggle all selected / deselected */
75 $chk = "<input type='checkbox' id='select_all' name='select_all'
76 onClick='toggle_all_(\"^item_selected_[0-9]*$\",\"select_all\");' >";
78 /* set Page header */
79 $this->AddHeader(array("string"=> $chk, "attach"=>"style='width:20px;'"));
80 $this->AddHeader(array("string"=> " ", "attach"=>"style='width:20px;'"));
81 $this->AddHeader(array("string"=>_("Username")." / "._("Department")));
82 $this->AddHeader(array("string"=>_("Properties"), "attach" => "style='width:166px;'"));
83 $this->AddHeader(array("string"=>_("Actions"), "attach" => "style='width:".$action_col_size."px;border-right:0px;text-align:right;'"));
85 $this->AddCheckBox("ShowTemplates" ,_("Select to see template pseudo users") ,_("Show templates") , false);
86 $this->AddCheckBox("ShowFunctionalUsers",_("Select to see users that have only a GOsa object"),_("Show functional users") , true);
87 $this->AddCheckBox("ShowUnixUsers" ,_("Select to see users that have posix settings") ,_("Show unix users") , true);
88 $this->AddCheckBox("ShowMailUsers" ,_("Select to see users that have mail settings") ,_("Show mail users") , true);
89 $this->AddCheckBox("ShowSambaUsers" ,_("Select to see users that have samba settings") ,_("Show samba users") , true);
90 $this->AddCheckBox("ShowProxyUsers" ,_("Select to see users that have proxy settings") ,_("Show proxy users") , true);
92 /* Add SubSearch checkbox */
93 $this->AddCheckBox(SEPERATOR);
94 $this->AddCheckBox("SubSearch", _("Select to search within subtrees"), _("Search in subtrees"), false);
96 /* Name ,Text ,Default , Connect with alphabet */
97 $this->AddRegex ("Regex", _("Display users matching"),"*" , true);
98 }
101 function GenHeader()
102 {
103 /* Prepare departments,
104 which are shown in the listbox on top of the listbox
105 */
106 $options= "";
108 /* Get all departments within this subtree */
109 $base = $this->config->current['BASE'];
111 /* Add base */
112 $tmp = array();
113 $tmp[] = array("dn"=>$this->config->current['BASE']);
114 $tmp= array_merge($tmp,get_list("(&(|(ou=*)(description=*))(objectClass=gosaDepartment))", $this->module, $base,
115 array("ou", "description"), GL_SIZELIMIT | GL_SUBSEARCH));
117 $deps = array();
118 foreach($tmp as $tm){
119 $deps[$tm['dn']] = $tm['dn'];
120 }
123 /* Load possible departments */
124 $ui= get_userinfo();
125 $tdeps= $ui->get_module_departments("users");
126 $ids = $this->config->idepartments;
127 $first = "";
128 $found = FALSE;
129 foreach($ids as $dep => $name){
130 if(isset($deps[$dep]) && in_array_ics($dep, $tdeps)){
132 /* Keep first base dn in mind, we could need this
133 * info if no valid base was found
134 */
135 if(empty($first)) {
136 $first = $dep['dn'];
137 }
139 $value = $ids[$dep];
140 if ($this->selectedBase == $dep){
141 $found = TRUE;
142 $options.= "<option selected='selected' value='".$dep."'>$value</option>";
143 } else {
144 $options.= "<option value='".$dep."'>$value</option>";
145 }
146 }
147 }
149 /* The currently used base is not visible with your acl setup.
150 * Set base to first useable base.
151 */
152 if(!$found){
153 $this->selectedBase = $first;
154 }
156 /* Get copy & paste icon */
157 $acl_all = $ui->has_complete_category_acls($this->selectedBase,"users") ;
158 $acl = $ui->get_permissions($this->selectedBase,"users/user");
160 /* Add default header */
161 $listhead = MultiSelectWindow::get_default_header();
162 $listhead .=
163 _("Base")." <select name='CurrentMainBase' onChange='mainform.submit()' class='center'>$options</select>".
164 " <input class='center' type='image' src='images/list_submit.png' align='middle'
165 title='"._("Submit department")."' name='submit_department' alt='". _("Submit")."'> ";
168 /* Create Layers menu */
169 $s = ".|"._("Actions")."|\n";
170 $s .= "..|<img src='images/list_new.png' alt='' border='0' class='center'>".
171 " "._("Create")."|\n";
173 /* Append create options */
174 if(preg_match("/c/",$acl)) {
175 $s.= "...|<input class='center' type='image' src='images/list_new_user.png' alt=''>".
176 " "._("User")."|user_new|\n";
177 $s.= "...|<input class='center' type='image' src='images/list_new.png' alt=''>".
178 " "._("Template")."|user_tplnew|\n";
179 }
181 /* Multiple options */
182 $s.= "..|---|\n";
183 $s.= "..|<img src='images/edit.png' alt='' border='0' class='center'>".
184 " "._("Edit")."|"."multiple_edit|\n";
185 $s.= "..|<img src='images/list_password.png' alt='' border='0' class='center'>".
186 " "._("Change password")."|"."multiple_password_change|\n";
187 $s.= "..|<img src='images/edittrash.png' alt='' border='0' class='center'>".
188 " "._("Remove")."|"."remove_multiple|\n";
190 if(class_available("DaemonEvent_notify")){
191 $events = DaemonEvent::get_event_types();
192 $event = $events['BY_CLASS']['DaemonEvent_notify'];
193 $s.= "..|---|\n";
194 $s.= "..|".$event['MenuImage']." ".$event['s_Menu_Name']."|trigger_event_DaemonEvent_notify\n";
195 }
197 /* Add multiple copy & cut icons */
198 if(is_object($this->parent->CopyPasteHandler) && preg_match("/(c.*w|w.*c)/",$acl_all)){
199 $s.= "..|---|\n";
200 $s.= "..|<img src='images/editcopy.png' alt='' border='0' class='center'>".
201 " "._("Copy")."|"."multiple_copy_systems|\n";
202 $s.= "..|<img src='images/editcut.png' alt='' border='0' class='center'>".
203 " "._("Cut")."|"."multiple_cut_systems|\n";
205 if($this->parent->CopyPasteHandler->entries_queued()){
206 $img = "<img border='0' class='center' src='images/editpaste.png' alt=''>";
207 $s.="..|".$img." "._("Paste")."|editPaste|\n";
208 }else{
209 $img = "<img border='0' class='center' src='images/cant_editpaste.png' alt=''>";
210 $s.="..|".$img." "._("Paste")."\n";
211 }
212 }
214 /* Add snapshot icons */
215 if(preg_match("/(c.*w|w.*c)/",$acl_all)){
216 $s .= "..|---|\n";
217 $s .= $this->get_snapshot_header(TRUE);
218 }
220 $this->SetDropDownHeaderMenu($s);
221 $this->SetListHeader($listhead);
222 }
224 /* so some basic settings */
225 function execute()
226 {
227 $this->ClearElementsList();
228 $this->GenHeader();
229 }
231 function setEntries($list)
232 {
233 /********************
234 Variable init
235 ********************/
237 $num_users = 0;
238 $num_templates = 0;
240 /* Variable initialation */
241 $enviro = $posix = $maila = $faxac = $samba = $netatalk = "";
242 $empty = "<img class='center' src='images/empty.png' style='width:16px;height:16px;' alt='-'>";
243 $userimg = "<img class='center' src='images/select_user.png' alt='User' title='%s'>";
244 $tplimg = "<img class='center' src='images/select_template.png' alt='Template' title='%s'>";
245 $editlink = "<a href='?plug=".validate($_GET['plug'])."&id=%s&act=edit_entry'>%s</a>";
247 /* Dynamic action col, depending on snapshot icons */
248 $action_col_size = 122;
249 if($this->parent->snapshotEnabled()){
250 $action_col_size += 38;
251 }
253 /* Possilbe objectClass image combinations */
254 $possibleAccounts = array(
255 "posixAccount" => array("VAR"=>"posix" ,"IMG"=>"posiximg"),
256 "gotoEnvironment" => array("VAR"=>"enviro" ,"IMG"=>"eviroimg"),
257 "gosaMailAccount" => array("VAR"=>"maila" ,"IMG"=>"mailimg"),
258 "goFaxAccount" => array("VAR"=>"faxac" ,"IMG"=>"faximg"),
259 "sambaSamAccount" => array("VAR"=>"samba" ,"IMG"=>"sambaimg"),
260 "apple-user" => array("VAR"=>"netatalk" ,"IMG"=>"netatalkimg"));
262 /* Pictures for Extensions */
263 $usrimg ="<input class='center' type='image' src='images/select_user.png' alt='"._("GOsa")."'
264 name='user_edit_%KEY%-user' title='"._("Edit generic properties")."'>";
265 $posiximg = "<input class='center' type='image' src='images/penguin.png' alt='"._("Posix")."'
266 name='user_edit_%KEY%-posixAccount' title='"._("Edit UNIX properties")."'>";
267 $eviroimg = "<input class='center' type='image' src='images/smallenv.png' alt='"._("Environment")."'
268 name='user_edit_%KEY%-environment' title='"._("Edit environment properties")."'>";
269 $mailimg = "<input class='center' type='image' src='images/mailto.png' alt='"._("Mail")."'
270 name='user_edit_%KEY%-mailAccount' title='"._("Edit mail properties")."'>";
271 $fonimg = "<input class='center' type='image' src='images/%image%' alt='"._("Phone")."'
272 name='user_edit_%KEY%-phoneAccount' title='"._("Edit phone properties")."%title%'>";
273 $faximg = "<input class='center' type='image' src='images/fax_small.png' alt='"._("Fax")."'
274 name='user_edit_%KEY%-gofaxAccount' title='"._("Edit fax properies")."'>";
275 $sambaimg = "<input class='center' type='image' src='images/select_winstation.png' alt='"._("Samba")."'
276 name='user_edit_%KEY%-sambaAccount' title='"._("Edit samba properties")."'>";
277 $netatalkimg = "<input class='center' type='image' src='images/select_netatalk.png' alt='"._("Netatalk")."'
278 name='user_edit_%KEY%-netatalk' title='"._("Edit netatalk properties")."'>";
279 $tplcreateuserimg = "<input type='image' class='center' src='images/list_new.png' alt='"._("Create user from template")."'
280 name='userfrom_tpl_%KEY%' title='"._("Create user with this template")."'>";
282 /********************
283 END :: Variable init
284 ********************/
287 /********************
288 Append entries to divlist
289 ********************/
291 $ui = get_userinfo();
293 // Test Every Entry and generate divlist Array
294 foreach($list as $key => $val){
296 /* Create action icons */
297 $action= "";
299 /* Add copy & cut icons */
300 $acl_all = $ui->has_complete_category_acls($this->selectedBase,"users") ;
301 $acl = $ui->get_permissions($val['dn'],"users/user");
302 if(preg_match("/(c.*w|w.*c)/",$acl_all) && $this->parent->CopyPasteHandler){
303 $action .= "<input class='center' type='image'
304 src='images/editcut.png' alt='"._("cut")."' name='cut_%KEY%' title='"._("Cut this entry")."'> ";
305 $action.= "<input class='center' type='image'
306 src='images/editcopy.png' alt='"._("copy")."' name='copy_%KEY%' title='"._("Copy this entry")."'> ";
307 }
309 /* Add deactivate status */
310 $lock_status = "";
312 if(isset($val['userPassword'][0]) && preg_match("/^\{[^\}]/",$val['userPassword'][0])){
313 if(preg_match("/^[^\}]*+\}!/",$val['userPassword'][0])){
314 $lock_status = "<input class='center' type='image' src='images/closedlock.png'
315 alt='"._("Deactivated")."' name='toggle_lock_status_%KEY%'>";
316 }else{
317 $lock_status = "<input class='center' type='image' src='images/openlock.png'
318 alt='"._("Active")."' name='toggle_lock_status_%KEY%'>";
319 }
320 }else{
321 $lock_status = "<img src='images/empty.png' alt=' ' class='center'>";
322 }
324 /* Generate edit icon */
325 $action.= "<input class='center' type='image' src='images/edit.png' alt='"._("edit")."'
326 name='user_edit_%KEY%' title='"._("Edit user")."'>";
328 /* Add deactivate status if we are allowed to */
329 if (preg_match("/w/",$acl_all)){
330 $action.= $lock_status;
331 }
333 /* Add Password change icon, if we are able to write users/password */
334 if(!in_array_ics("gosaUserTemplate",$val['objectClass']) && preg_match("/w/",$ui->get_permissions($val['dn'],"users/password"))) {
335 $action.= "<input class='center' type='image' src='images/list_password.png' alt='"._("password")."'
336 name='user_chgpw_%KEY%' title='"._("Change password")."'>";
337 }else{
338 $action.= "<img class='center' src='images/empty.png' alt=' '
339 title='"._("You are not allowed to change the password for this user.")."'>";
340 }
342 /* Add snapshot icon */
343 if(preg_match("/(c.*w|w.*c)/",$acl_all)){
344 $action.= $this->GetSnapShotActions($val['dn']);
345 }
347 /* Add remove icon, if we are allowed to remove the current user */
348 if(preg_match("/d/",$ui->get_permissions($val['dn'],"users/user"))) {
349 $action.= "<input class='center' type='image' src='images/edittrash.png' alt='"._("delete")."'
350 name='user_del_%KEY%' title='"._("Delete user")."'>";
351 }else{
352 $action.= "<img class='center' src='images/empty.png' alt=' '
353 title='"._("You are not allowed to remove this user.")."'>";
354 }
356 /* Create phonaccopunt informationm, if conencted && is phoneAccount */
357 if((in_array("goFonAccount" ,$val['objectClass']))){
359 /* Set defaults */
360 $fonac = preg_replace("/%image%/", "select_phone.png", $fonimg);
361 $fonac = preg_replace("/%KEY%/", "$key", $fonac);
362 $fonac = preg_replace("/%title%/", "", $fonac);
364 }else{
365 $fonac=$empty;
366 }
368 /* Set images for different types of objectClasses */
369 foreach($possibleAccounts as $objectClass => $Settigns){
370 if(in_array($objectClass ,$val['objectClass'])){
371 $$Settigns['VAR'] = preg_replace("/%KEY%/", "$key", $$Settigns['IMG']);
372 }else{
373 $$Settigns['VAR'] = $empty;
374 }
375 }
377 /* Create userimg */
378 if(in_array("gosaUserTemplate",$val['objectClass'])){
379 $tpl = preg_replace("/%KEY%/", "$key", $tplimg);
380 $s_img_create_from_template = preg_replace("/%KEY%/", "$key", $tplcreateuserimg);
381 $num_templates ++;
382 }else{
383 $s_img_create_from_template = "";
384 $tpl = $userimg;
385 $num_users ++;
386 }
388 /* Insert key into userimg */
389 $usrimg2 = preg_replace("/%KEY%/", "$key", $usrimg);
391 // Generate caption for rows
392 if (isset($val["sn"]) && isset($val["givenName"])){
393 $display= $val["sn"][0].", ".$val["givenName"][0]." [".$val["uid"][0]."]";
394 } else {
395 $display= "[".$val["uid"][0]."]";
396 }
398 /* Connect all images */
399 $UseImg = $usrimg2." ".$posix." ".$enviro." ".$maila." ".$fonac." ".$faxac." ".$samba." ".$netatalk;
401 /* Cutted objects should be displayed in light grey */
402 if($this->parent->CopyPasteHandler){
403 foreach($this->parent->CopyPasteHandler->queue as $queue_key => $queue_data){
404 if($queue_data['dn'] == $val['dn']) {
405 $display = "<font color='#999999'>".$display."</font>";
406 break;
407 }
408 }
409 }
411 /* Create each field */
412 $field0 = array("string" => "<input type='checkbox' id='item_selected_".$key."' name='item_selected_".$key."'>" ,
413 "attach" => "style='width:20px;'");
414 $field1 = array("string" => sprintf($tpl,$val['dn']), "attach" => "style='text-align:center;width:20px;'");
415 $field2 = array("string" => sprintf($editlink,$key,$display), "attach" => "style='' title='".preg_replace('/ /', ' ', @LDAP::fix($val['dn']))."'");
416 $field3 = array("string" => $UseImg, "attach" => "style='width:166px;'");
417 $field4 = array("string" => $s_img_create_from_template.preg_replace("/%KEY%/", "$key", $action),
418 "attach" => "style='width:".$action_col_size."px;border-right:0px; text-align:right;'");
419 /* Add to list */
420 $add = array($field0,$field1,$field2,$field3,$field4);
421 $this->AddElement($add);
423 // Template or User
424 if(in_array("gosaUserTemplate",$val['objectClass'])){
425 $tpls[strtolower( $val['sn']['0'].$val['uid']['0'])]=$add;
426 }else{
427 $users[strtolower( $val['sn']['0'].$val['uid']['0'])]=$add;
428 }
429 }
432 /* Create summary string for list footer */
433 $num_deps=0;
434 if(!$this->SubSearch){
435 $num_deps = count($this->Added_Departments);
436 }
437 $num_users = count($list);
439 $num_user_str = _("Number of listed users");
440 $num_dep_str = _("Number of listed departments");
442 $str = "<img class='center' src='images/select_user.png'
443 title='".$num_user_str."' alt='".$num_user_str."'> ".$num_users." ";
444 $str.= "<img class='center' src='images/folder.png'
445 title='".$num_dep_str."' alt='".$num_dep_str."'> ".$num_deps." ";
447 $this->set_List_Bottom_Info($str);
448 }
450 function Save()
451 {
452 MultiSelectWindow :: Save();
453 }
455 function save_object()
456 {
457 /* Save automatic created POSTs like regex, checkboxes */
458 MultiSelectWindow::save_object();
459 }
460 }
461 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
462 ?>