1 <?php
2 /*
3 This code is part of GOsa (https://gosa.gonicus.de)
4 Copyright (C) 2003 Cajus Pollmeier
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20 require "tabs_user.inc";
22 class userManagement extends plugin
23 {
24 /* Definitions */
25 var $plHeadline= "Users";
26 var $plDescription= "This does something";
28 /* Dialog attributes */
29 var $usertab= NULL;
30 var $userlist= array();
31 var $ui= NULL;
32 var $acl= "";
33 var $templates= array();
34 var $got_uid= false;
35 var $departments=array();
37 function userManagement ($config, $ui)
38 {
39 /* Save configuration for internal use */
40 $this->config= $config;
41 $this->ui= $ui;
43 /* Get global filter config */
44 if (!is_global("userfilter")){
45 $base= get_base_from_people($ui->dn);
46 $userfilter= array( "mailusers" => "checked",
47 "unixusers" => "checked",
48 "templates" => "",
49 "subsearch" => "",
50 "proxyusers" => "checked",
51 "sambausers" => "checked",
52 "faxusers" => "checked",
53 "functionalusers" => "checked",
54 "depselect" => $base,
55 "regex" => "*");
56 register_global("userfilter", $userfilter);
57 }
58 }
60 function execute()
61 {
62 $smarty = get_smarty(); // Smarty instance
63 $userfilter = get_global("userfilter"); // contains Filter Settings
64 $s_action = ""; // Contains the action to proceed
65 $s_entry = ""; // The value for s_action
66 $base_back = ""; // The Link for Backbutton
68 /* Start for New List Managment */
69 if(isset($_GET['act'])&&($_GET['act']=="dep_open")){
70 $s_action="open";
71 $s_entry = base64_decode($_GET['dep_id']);
72 $userfilter['depselect']= "".$this->config->departments[trim($s_entry)];
73 $this->reload();
74 }
76 /* Test Posts */
77 foreach($_POST as $key => $val){
78 // Post for delete
79 if(preg_match("/user_del.*/",$key)){
80 $s_action = "del";
81 $s_entry = preg_replace("/user_".$s_action."_/i","",$key);
82 // Post for edit
83 }elseif(preg_match("/user_edit_.*/",$key)){
84 $s_action="edit";
85 $s_entry = preg_replace("/user_".$s_action."_/i","",$key);
86 // Post for new
87 }elseif(preg_match("/dep_back.*/i",$key)){
88 $s_action="back";
89 }elseif(preg_match("/user_new.*/",$key)){
90 $s_action="new";
91 }elseif(preg_match("/dep_home.*/i",$key)){
92 $s_action="home";
93 }elseif(preg_match("/user_tplnew.*/i",$key)){
94 $s_action="new_tpl";
95 }elseif(preg_match("/user_chgpw.*/i",$key)){
96 $s_action="change_pw";
97 $s_entry = preg_replace("/user_chgpw_/i","",$key);
98 }elseif(preg_match("/dep_root.*/i",$key)){
99 $s_action="root";
100 }
101 }
103 if((isset($_GET['act']))&&($_GET['act']=="edit_entry")){
104 $s_action ="edit";
105 $s_entry = $_GET['id'];
106 }
108 $s_entry = preg_replace("/_.$/","",$s_entry);
110 /* Department changed? */
111 if(isset($_POST['depselect']) && $_POST['depselect']){
112 $userfilter['depselect']= $_POST['depselect'];
113 $this->reload();
114 }
116 /* Homebutton is posted */
117 if($s_action=="home"){
118 $userfilter['depselect']=(preg_replace("/^[^,]+,/","",$this->ui->dn));
119 $userfilter['depselect']=(preg_replace("/^[^,]+,/","",$userfilter['depselect']));
120 $this->reload();
121 }
123 if($s_action=="root"){
124 $userfilter['depselect']=($this->config->current['BASE']);
125 $this->reload();
126 }
129 /* If Backbutton is Posted */
130 if($s_action=="back"){
131 $base_back = preg_replace("/^[^,]+,/","",$userfilter['depselect']);
132 $base_back = convert_department_dn($base_back);
134 if(isset($this->config->departments[trim($base_back)])){
135 $userfilter['depselect']= $this->config->departments[trim($base_back)];
136 }else{
137 $userfilter['depselect']= $this->config->departments["/"];
138 }
139 $this->reload();
140 }
142 /* End for new List Managment */
144 /* Save filter data if we are in the headpage */
145 if (!isset($this->usertab)){
146 foreach( array("regex") as $type){
147 if (isset($_POST[$type])){
148 $userfilter[$type]= $_POST[$type];
149 }
150 }
151 }
152 if(isset($_POST['regex'])){
153 foreach( array("functionalusers", "unixusers", "mailusers","sambausers", "proxyusers", "faxusers", "templates", "subsearch") as $type){
154 if (isset($_POST[$type])) {
155 $userfilter[$type]= "checked";
156 } else {
157 $userfilter[$type]= "";
158 }
159 }
160 }
161 if (isset($_GET['search'])){
162 $s= mb_substr($_GET['search'], 0, 1, "UTF8")."*";
163 if ($s == "**"){
164 $s= "*";
165 }
166 $userfilter['regex']= $s;
167 }
168 register_global("userfilter", $userfilter);
171 /* React on user interaction here */
172 if (($_SERVER["REQUEST_METHOD"] == "POST")||($_SERVER["REQUEST_METHOD"]== "GET")){
174 /* User wants to edit data? */
175 if ($s_action=="edit"){
177 /* Get 'dn' from posted 'uid', must be unique */
179 $this->dn= $this->list[trim($s_entry)]['dn'];
181 /* Check locking, save current plugin in 'back_plugin', so
182 the dialog knows where to return. */
183 if (($user= get_lock($this->dn)) != ""){
184 return(gen_locked_message ($user, $this->dn));
185 }
187 /* Lock the current entry, so everyone will get the
188 above dialog */
189 add_lock ($this->dn, $this->ui->dn);
191 /* Set up the users ACL's for this 'dn' */
192 $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
194 /* Register usertab to trigger edit dialog */
195 $this->usertab= new usertabs($this->config,
196 $this->config->data['TABS']['USERTABS'], $this->dn);
197 $this->usertab->set_acl($acl);
199 $_SESSION['objectinfo']= $this->dn;
200 }
201 }
203 /* Reset requested? */
204 if (isset($_POST['edit_cancel']) || isset($_POST['password_cancel'])){
205 if (isset($this->usertab)){
206 del_lock ($this->usertab->dn);
207 unset ($this->usertab);
208 }
209 $this->usertab= NULL;
210 $this->lognames= array();;
211 $this->sn= "";
212 $this->givenName= "";
213 $this->uid= "";
214 unset ($_SESSION['objectinfo']);
215 }
217 /* Password change requested */
218 if ($s_action=="change_pw"){
220 /* Get 'dn' from posted 'uid' */
221 $this->dn= $this->list[trim($s_entry)]['dn'];
223 /* Load permissions for selected 'dn' and check if
224 we're allowed to remove this 'dn' */
225 $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
226 $acl= get_module_permission($acl, "user", $this->dn);
227 if (chkacl($acl, "password") == ""){
229 /* User is allowed to change passwords, save 'dn' and 'acl' for next
230 dialog. */
231 $this->acl= $acl;
232 $_SESSION['objectinfo']= $this->dn;
233 return ($smarty->fetch(get_template_path('password.tpl', TRUE)));
235 } else {
236 /* User is not allowed. Show message and cancel. */
237 print_red (_("You are not allowed to set this users password!"));
238 }
239 }
241 /* Perform password change */
242 if (isset($_POST['password_finish'])){
244 /* For security reasons, check if user is allowed to set password again */
245 if (chkacl($this->acl, "password") == "" || chkacl($this->acl, "create")){
247 /* Check input and feed errors into 'message' */
248 $message= array();
250 /* Sanity checks... */
251 if ($_POST['new_password'] != $_POST['repeated_password']){
253 /* Matching passwords in new and repeated? */
254 $message[]= _("The passwords you've entered as 'New password' and 'Repeated new password' do not match.");
255 } else {
257 /* Empty password is not permitted by default. */
258 if ($_POST['new_password'] == ""){
259 $message[]= _("The password you've entered as 'New password' is empty.");
260 }
261 }
263 /* Errors, or change password? */
264 if (count($message) != 0){
266 /* Show error message and continue editing */
267 show_errors ($message);
268 return($smarty->fetch(get_template_path('password.tpl', TRUE)));
269 }
271 /* Set password, perform required steps */
272 if ($this->usertab){
273 if ($this->usertab->password_change_needed()){
274 $obj= $this->usertab->by_object['user'];
275 change_password ($this->usertab->dn, $_POST['new_password'],
276 0, $obj->pw_storage);
277 gosa_log ("Password for '".$this->usertab->dn."' has been changed");
278 unset($this->usertab);
279 $this->usertab= NULL;
280 }
281 } else {
282 change_password ($this->dn, $_POST['new_password']);
283 gosa_log ("Password for '".$this->dn."' has been changed");
284 }
285 } else {
287 /* Missing permissions, show message */
288 print_red (_("You are not allowed to set this users password!"));
289 }
291 /* Clean session, delete lock */
292 del_lock ($this->dn);
293 $this->reload();
294 unset ($this->usertab);
295 $this->usertab= NULL;
296 $this->lognames= array();;
297 $this->sn= "";
298 $this->givenName= "";
299 $this->uid= "";
300 unset ($_SESSION['objectinfo']);
301 }
304 /* Remove user was requested */
305 if ($s_action=="del"){
307 /* Get 'dn' from posted 'uid' */
308 $this->dn= $this->list[trim($s_entry)]['dn'];
310 /* Load permissions for selected 'dn' and check if
311 we're allowed to remove this 'dn' */
312 $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
313 $this->acl= get_module_permission($acl, "user", $this->dn);
314 if (chkacl($this->acl, "delete") == ""){
316 /* Check locking, save current plugin in 'back_plugin', so
317 the dialog knows where to return. */
318 if (($user= get_lock($this->dn)) != ""){
319 return(gen_locked_message ($user, $this->dn));
320 }
322 /* Lock the current entry, so nobody will edit it during deletion */
323 add_lock ($this->dn, $this->ui->dn);
324 $smarty->assign("info", sprintf(_("You're about to delete the user %s."), $this->dn));
325 return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
326 } else {
328 /* Obviously the user isn't allowed to delete. Show message and
329 clean session. */
330 print_red (_("You are not allowed to delete this user!"));
331 }
332 }
336 /* Confirmation for deletion has been passed. User should be deleted. */
337 if (isset($_POST['delete_user_confirm'])){
339 /* Some nice guy may send this as POST, so we've to check
340 for the permissions again. */
341 if (chkacl($this->acl, "delete") == ""){
343 /* Delete request is permitted, perform LDAP action */
344 $this->usertab= new usertabs($this->config, $this->config->data['TABS']['USERTABS'],
345 $this->dn);
346 $this->usertab->set_acl(array($this->acl));
347 $this->usertab->delete ();
348 gosa_log ("User object '".$this->dn."' has been removed");
349 unset ($this->usertab);
350 $this->usertab= NULL;
352 /* User list has changed, reload it. */
353 $this->reload ();
354 } else {
356 /* Normally this shouldn't be reached, send some extra
357 logs to notify the administrator */
358 print_red (_("You are not allowed to delete this user!"));
360 if(isset($this->ui->uid)){
361 gosa_log ("Warning: '".$this->ui->uid."' tried to trick user deletion.");
362 }
363 }
365 /* Remove lock file after successfull deletion */
366 del_lock ($this->dn);
367 }
370 /* Delete user canceled? */
371 if (isset($_POST['delete_cancel'])){
372 del_lock ($this->dn);
373 }
376 /* Finish user edit is triggered by the tabulator dialog, so
377 the user wants to save edited data. Check and save at this
378 point. */
379 if (isset($_POST['edit_finish'])){
381 /* Check tabs, will feed message array */
382 $this->usertab->last= $this->usertab->current;
383 $this->usertab->save_object();
384 $message= $this->usertab->check();
386 /* Save, or display error message? */
387 if (count($message) == 0){
389 /* No errors. Go ahead and prepare to ask for a password
390 in case we're creating a new user. 'dn' will be 'new'
391 in this case. It is set to the correct value later. */
392 if ($this->dn == "new"){
393 $set_pass= 1;
394 } else {
395 $set_pass= 0;
396 }
398 /* Save user data to ldap */
399 if($this->usertab->save() == 1){
400 gosa_log ("User object '".$this->dn."' saving failed.");
401 return;
402 }
403 gosa_log ("User object '".$this->dn."' has been saved");
405 /* User has been saved successfully, remove lock from
406 LDAP. */
407 if ($this->dn != "new"){
408 del_lock ($this->dn);
409 }
411 /* In case of new users, ask for a password */
412 if (($set_pass || $this->usertab->password_change_needed()) &&
413 !$this->is_template){
415 return($smarty->fetch(get_template_path('password.tpl', TRUE)));
416 }
418 /* There's no page reload so we have to read new users at
419 this point. */
420 $this->reload ();
421 unset ($this->usertab);
422 $this->usertab= NULL;
423 unset ($_SESSION['objectinfo']);
425 } else {
426 /* Ok. There seem to be errors regarding to the tab data,
427 show message and continue as usual. */
428 show_errors($message);
429 }
430 }
432 /* Generate template list */
433 if ($s_action=="new"){
434 $this->templates= array();
435 $ldap= $this->config->get_ldap_link();
436 foreach ($this->config->departments as $key => $value){
437 $acl= get_permissions (get_people_ou().$value, $this->ui->subtreeACL);
438 $acl= get_module_permission($acl, "user", get_people_ou().$value);
439 if (chkacl($acl, "create") == ""){
440 $ldap->cd (get_people_ou().$value);
441 $ldap->search ("(objectClass=gosaUserTemplate)", array("uid"));
443 if ($ldap->count() != 0){
444 while ($attrs= $ldap->fetch()){
445 $this->templates[$ldap->getDN()]=
446 $attrs['uid'][0]." - $key";
447 }
448 $this->templates['none']= _("none");
449 }
450 }
451 }
452 natcasesort ($this->templates);
453 reset ($this->templates);
454 }
456 /* New user/template request */
457 if (($s_action=="new") || ($s_action=="new_tpl")){
458 /* By default we set 'dn' to 'new', all relevant plugins will
459 react on this. */
460 $this->dn= "new";
461 if (isset($this->config->current['IDGEN'])){
462 $this->got_uid= false;
463 } else {
464 $this->got_uid= true;
465 }
467 /* Create new usertab object */
468 $this->usertab= new usertabs($this->config,
469 $this->config->data['TABS']['USERTABS'], $this->dn);
470 $this->usertab->set_acl(array(':all'));
472 /* Take care about templates */
473 if ($s_action=="new_tpl"){
474 $this->is_template= TRUE;
475 $this->usertab->set_template_mode ();
476 } else {
477 $this->is_template= FALSE;
478 }
480 /* Use template if there are any of them */
481 if (count($this->templates) && !isset($_POST['new_template'])){
482 foreach(array("sn", "givenName", "uid", "got_uid", "templates") as $attr){
483 $smarty->assign("$attr", $this->$attr);
484 }
485 if (isset($_POST['template'])){
486 $smarty->assign("template", $_POST['template']);
487 } else {
488 $smarty->assign("template", "");
489 }
490 $smarty->assign("edit_uid", "");
491 return($smarty->fetch(get_template_path('template.tpl', TRUE)));
492 }
494 }
496 /* Continue template editing */
497 if (isset($_POST['template_continue']) && $_POST['template'] != 'none' && !isset($_POST['uid'])){
498 $this->sn= $_POST['sn'];
499 $this->givenName= $_POST['givenName'];
501 /* Check for requred values */
502 $message= array();
503 if ($this->sn == "") {
504 $message[]= _("The required field 'Name' is not set.");
505 }
506 if ($this->givenName == "") {
507 $message[]= _("The required field 'Given name' is not set.");
508 }
510 /* Check if dn is used */
511 $dn= preg_replace("/^[^,]+,/i", "", $_POST['template']);
512 $ldap= $this->config->get_ldap_link();
513 $ldap->cd ($dn);
514 $ldap->search ("(&(sn=".$this->sn.")(givenName=".$this->givenName."))", array("givenName"));
515 if ($ldap->count () != 0){
516 $message[]= _("A person with the choosen name is already used in this tree.");
517 }
519 /* Show error message / continue editing */
520 if (count($message) > 0){
521 show_errors ($message);
522 } else {
523 $attributes= array('sn' => $this->sn, 'givenName' => $this->givenName);
524 if (isset($this->config->current['IDGEN']) &&
525 $this->config->current['IDGEN'] != ""){
526 $uids= gen_uids ($this->config->current['IDGEN'], $attributes);
527 if (count($uids)){
528 $smarty->assign("edit_uid", "false");
529 $smarty->assign("uids", $uids);
530 $this->uid= current($uids);
531 }
532 } else {
533 $smarty->assign("edit_uid", "");
534 $this->uid= "";
535 }
536 $this->got_uid= true;
537 }
539 foreach(array("sn", "givenName", "uid", "got_uid", "templates") as $attr){
540 $smarty->assign("$attr", $this->$attr);
541 }
542 if (isset($_POST['template'])){
543 $smarty->assign("template", $_POST['template']);
544 }
545 return($smarty->fetch(get_template_path('template.tpl', TRUE)));
546 }
548 /* No template. Ok. Lets fill data into the normal user dialog */
549 if (isset($_POST['template_continue']) && $_POST['template'] == 'none'){
550 foreach(array("sn", "givenName", "uid") as $attr){
551 if (isset($_POST[$attr])){
552 $this->usertab->by_object['user']->$attr= $_POST[$attr];
553 }
554 }
555 }
557 /* Finish template preamble */
558 if (isset($_POST['template_continue']) && $_POST['template'] != 'none' && (isset($_POST['uid']))){
560 /* Might not be filled if IDGEN is unset */
561 $this->sn= $_POST['sn'];
562 $this->givenName= $_POST['givenName'];
564 /* Move user supplied data to sub plugins */
565 $this->uid= $_POST['uid'];
566 $this->usertab->uid= $this->uid;
567 $this->usertab->sn= $this->sn;
568 $this->usertab->givenName= $this->givenName;
569 $template_dn= $_POST['template'];
570 $this->usertab->adapt_from_template($template_dn);
571 $template_base= preg_replace("/^[^,]+,".get_people_ou()."/", '', $template_dn);
572 $this->usertab->by_object['user']->base= $template_base;
574 /* Set up the users ACL's for this 'dn' */
575 $acl= get_permissions ($template_base, $this->ui->subtreeACL);
576 $this->usertab->set_acl($acl);
577 }
579 /* Show tab dialog if object is present */
580 if ($this->usertab){
581 $display= $this->usertab->execute();
583 /* Don't show buttons if tab dialog requests this */
584 if (!$this->usertab->by_object[$this->usertab->current]->dialog){
585 $display.= "<p style=\"text-align:right\">\n";
586 $display.= "<input type=submit name=\"edit_finish\" value=\""._("Finish")."\">\n";
587 $display.= " \n";
588 $display.= "<input type=submit name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
589 $display.= "</p>";
590 }
591 return ($display);
592 }
594 $smarty= get_smarty();
596 /* Check sorting variable */
597 if (!isset($this->usertab) &&
598 !isset($_POST['new_user']) &&
599 !isset($_POST['new_template']) &&
600 !isset($_POST['delete_user']) &&
601 !isset($_POST['setpass_user']) &&
602 !isset($_POST['select_user'])){
603 $this->reload();
604 }
606 /* Check for exeeded sizelimit */
607 if (($message= check_sizelimit()) != ""){
608 return($message);
609 }
611 /* Prepare departments */
612 $options= "";
613 foreach ($this->config->idepartments as $key => $value){
614 if ($userfilter['depselect'] == $key){
615 $options.= "<option selected value='$key'>$value</option>";
616 } else {
617 $options.= "<option value='$key'>$value</option>";
618 }
619 }
621 /* NEW LIST MANAGMENT */
622 $listhead = "<div style='background:#F0F0F9;padding:5px;'>".
623 " <input type='image' align='middle' src='images/list_back.png' title='"._("Go up one department")."' alt='"._("Up")."' name='dep_back'> ".
624 " <input type='image' src='images/list_root.png' align='middle' title='"._("Go to root department")."' name='dep_root' alt='"._("Root")."'> ".
625 " <input type='image' align='middle' src='images/list_home.png' title='"._("Go to users department")."' alt='"._("Home")."' name='dep_home'> ".
626 " <img src='images/list_seperator.png' align='middle' alt='' height='16' width='1'> ".
627 " <input type='image' align='middle' src='images/list_new_user.png' title='"._("Create new user")."' alt='"._("New user")."' name='user_new'> ".
628 " <input type='image' align='middle' src='images/list_new.png' title='"._("Create new template")."' alt='"._("New template")."' name='user_tplnew'> ".
629 " <img src='images/list_seperator.png' align='middle' alt='' height='16' width='1'> ".
630 _("Current base")." <select name='depselect' onChange='mainform.submit()'>$options</select>".
631 " <input type='image' src='images/list_submit.png' align='middle' title='"._("Submit department")."' name='submit_department' alt='"._("Submit")."'> ".
632 "</div>";
634 $action= "<input type='image' src='images/edit.png' alt='"._("edit")."' name='user_edit_%KEY%' title='"._("Edit user")."'>";
635 $action.= "<input type='image' src='images/list_password.png' alt='"._("password")."' name='user_chgpw_%KEY%' title='"._("Change password")."'>";
636 $action.= "<input type='image' src='images/editdelete.png' alt='"._("delete")."' name='user_del_%KEY%' title='"._("Delete user")."'>";
640 $divlist = new divlist();
641 $divlist->SetHeader(array(
642 array("string" => " "),
643 array("string" => _("Username")." / "._("Department")),
644 array("string" => _("Properties")),
645 array("string" => _("Actions"), "attach" => "style='border:none'" )));
648 $divlist->SetSummary(_("This table displays all users, in the selected tree."));
649 $divlist->SetEntriesPerPage(20);
651 // Defining Links
652 $linkopen = "<a href='?plug=".$_GET['plug']."&act=dep_open&dep_id=%s'>%s</a>";
654 foreach($this->departments as $key=> $val){
656 $field1 = array("string" => "<img src='images/folder.png' alt='department'>");
657 $field2 = array("string" => sprintf($linkopen,base64_encode($key),$val));
658 $field3 = array("string" => " ");
659 $field4 = array("string" => " ", "attach" => "style='border:none'");
662 $divlist->AddEntry(array($field1,$field2,$field3,$field4));
663 }
665 // Pictures for Extensions
666 $usrimg = "<img src='images/penguin.png' alt='U' title='"._("GOsa") ."'>";
667 $posiximg = "<img src='images/select_user.png' alt='P' title='"._("Posix") ."'>";
668 $mailimg = "<img src='images/mailto.png' alt='M' title='"._("Mail") ."'>";
669 $fonimg = "<img src='images/select_phone.png' alt='T' title='"._("Phone") ."'>";
670 $faximg = "<img src='images/fax_small.png' alt='F' title='"._("Fax") ."'>";
671 $sambaimg = "<img src='images/select_winstation.png' alt='S' title='"._("Samba") ."'>";
673 // Space
674 $empty = "<img src='images/nothing.png' style='width:16px;height:16px;' alt=''>";
676 // User and Template Images
677 $userimg = "<img src='images/select_user.png' alt='User' title='%s'>";
678 $tplimg = "<img src='images/select_template.png' alt='Template' title='%s'>";
680 $editlink = "<a href='?plug=".$_GET['plug']."&id=%s&act=edit_entry'>%s</a>";
682 // Defines Arrays to save User and Templates
683 $tpls = array();
684 $users= array();
686 // Test Every Entry and generate divlist Array
687 foreach($this->list as $key => $val){
689 // Specify Pics for Extensions
690 if(in_array("posixAccount" ,$val['objectClass'])) $posix = $posiximg; else $posix=$empty;
691 if(in_array("gosaMailAccount" ,$val['objectClass'])) $maila = $mailimg; else $maila=$empty;
692 if(in_array("goFonAccount" ,$val['objectClass'])) $fonac = $fonimg; else $fonac=$empty;
693 if(in_array("goFaxAccount" ,$val['objectClass'])) $faxac = $faximg; else $faxac=$empty;
694 if(in_array("sambaSamAccount" ,$val['objectClass'])) $samba = $sambaimg; else $samba=$empty;
695 if(in_array("gosaUserTemplate",$val['objectClass'])) $tpl = $tplimg; else $tpl=$userimg;
697 // Generate Array to Add
698 if (isset($val["sn"]) && isset($val["givenName"])){
699 $display= $val["sn"][0].", ".$val["givenName"][0]." [".$val["uid"][0]."]";
700 } else {
701 $display= "[".$val["uid"][0]."]";
702 }
704 $field1 = array("string" => sprintf($tpl,$val['dn']),"attach"=>"style='width:20px;align:middle;'");
705 $field2 = array("string" => sprintf($editlink,$key,$display),"attach"=>"title='".$val['dn']."'");
706 $field3 = array("string" => $usrimg." ".$posix." ".$maila." ".$fonac." ".$faxac." ".$samba,"attach" => "style='width:118px;'");
707 $field4 = array("string" => preg_replace("/%KEY%/", "$key", $action),"attach" => "style='border:none; text-align:right;width:48px'");
709 $add = array($field1,$field2,$field3,$field4);
711 // Template or User
712 if(in_array("gosaUserTemplate",$val['objectClass'])){
713 $tpls[strtolower( $val['sn']['0'].$val['uid']['0'])]=$add;
714 }else{
715 $users[strtolower( $val['sn']['0'].$val['uid']['0'])]=$add;
716 }
717 }
719 // Sort Entries
720 ksort($users);
721 ksort($tpls);
723 // Append Templates
724 foreach($tpls as $key => $val){
725 $divlist->AddEntry( $val, array(""));
726 }
727 // Append Users
728 foreach($users as $key => $val){
729 $divlist->AddEntry( $val, array(""));
730 }
731 /* Show main page */
732 //$smarty->assign("userlist", nl2br(htmlentities($divlist->DrawList())));
733 $smarty->assign("userlist", $divlist->DrawList());
734 $smarty->assign("userlisthead", $listhead);
736 /* END NEW LIST MANAGMENT
737 */
738 $smarty->assign("search_image", get_template_path('images/search.png'));
739 $smarty->assign("tree_image", get_template_path('images/tree.png'));
740 $smarty->assign("infoimage", get_template_path('images/info.png'));
741 $smarty->assign("launchimage", get_template_path('images/launch.png'));
742 $smarty->assign("deplist", $this->config->idepartments);
743 foreach( array("depselect", "regex", "functionalusers", "unixusers",
744 "mailusers", "sambausers", "proxyusers",
745 "faxusers", "templates", "subsearch") as $type){
747 $smarty->assign("$type", $userfilter[$type]);
748 }
750 /* Extend if we are not using javascript */
751 $smarty->assign("apply", apply_filter());
752 $smarty->assign("alphabet", generate_alphabet());
753 $smarty->assign("hint", print_sizelimit_warning());
755 return ($smarty->fetch(get_template_path('headpage.tpl', TRUE)));
756 }
759 function reload()
760 {
761 /* Get config */
762 $userfilter= get_global('userfilter');
764 /* Set base for all searches */
765 $base= $userfilter['depselect'];
767 /* Regex filter? */
768 if ($userfilter['regex'] != ""){
769 $regex= $userfilter['regex'];
770 } else {
771 $regex= "*";
772 }
774 /* Set filter depending on selection */
775 if ($this->config->current['SAMBAVERSION'] == 3){
776 $samba= "sambaSamAccount";
777 } else {
778 $samba= "sambaAccount";
779 }
781 $filter="";
782 if ($userfilter['functionalusers'] == "checked"){
783 $filter.= "(&(objectClass=gosaAccount)(!(|(objectClass=posixAccount)(objectClass=gosaMailAccount)(objectClass=$samba)(objectClass=goFaxAccount)(objectClass=gosaProxyAccount))))";
784 }
785 if ($userfilter['unixusers'] == "checked"){
786 $filter.= "(objectClass=posixAccount)";
787 }
788 if ($userfilter['mailusers'] == "checked"){
789 $filter.= "(objectClass=gosaMailAccount)";
790 }
791 if ($userfilter['sambausers'] == "checked"){
792 $filter.= "(objectClass=$samba)";
793 }
794 if ($userfilter['proxyusers'] == "checked"){
795 $filter.= "(objectClass=gosaProxyAccount)";
796 }
797 if ($userfilter['faxusers'] == "checked"){
798 $filter.= "(objectClass=goFaxAccount)";
799 }
801 if ($userfilter['templates'] == "checked"){
802 $filter= "(|(objectClass=gosaUserTemplate)(&(objectClass=gosaAccount)(|$filter)))";
803 } else {
804 $filter= "(&(objectClass=gosaAccount)(!(objectClass=gosaUserTemplate))(|$filter))";
805 }
806 $filter= "(&(|(uid=$regex)(sn=$regex)(givenName=$regex))$filter)";
808 /* Generate userlist */
809 $ldap= $this->config->get_ldap_link(TRUE);
810 if ($userfilter['subsearch'] == "checked"){
811 $this->list= get_list($this->ui->subtreeACL, "$filter", TRUE, $base, array("uid", "givenName", "sn", "objectClass"), TRUE);
812 } else {
813 $base= get_people_ou().$base;
814 $this->list= get_list($this->ui->subtreeACL, "$filter", FALSE, $base, array("uid", "givenName", "sn", "objectClass"), TRUE);
815 }
819 /* NEW LIST MANAGMENT
820 * We also need to search for the departments
821 * So we are able to navigate like in konquerer
822 */
823 $base2 = preg_replace("/ou=people,/i","",$base);
825 $res3 = get_list2($this->ui->subtreeACL, "(&(|(ou=$regex)(description=$regex))(objectClass=gosaDepartment))",
826 TRUE, $base2, array("ou", "description"), TRUE);
828 $this->departments= array();
829 foreach ($res3 as $value){
830 if($value["description"][0]!=".."){
831 $this->departments[$value['dn']]= convert_department_dn2($value['dn'])." - [".$value["description"][0]."]";
832 }else{
833 $this->departments[$value['dn']]=$value["description"][0];
834 }
835 }
837 /* END NEW LIST MANAGMENT
838 */
841 $this->userlist= array();
843 foreach ($this->list as $value){
844 if (isset($value["uid"][0]) && !preg_match('/\$$/', $value["uid"][0])){
845 if (in_array_ics('gosaUserTemplate', $value['objectClass'])){
846 $this->userlist[$value["dn"]]= "* ".$value["uid"][0]." ("._("Template").")";
847 continue;
848 }
849 if (isset($value["givenName"][0]) && isset($value["sn"][0])){
850 $this->userlist[$value["dn"]]= $value["sn"][0].", ".
851 $value["givenName"][0].
852 " [".$value["uid"][0]."]";
853 } else {
854 $this->userlist[$value["dn"]]= "[".$value["uid"][0]."]";
855 }
856 }
857 }
859 natcasesort ($this->userlist);
860 reset ($this->userlist);
861 }
863 function remove_from_parent()
864 {
865 }
868 /* Check values */
869 function check()
870 {
871 }
874 /* Save to LDAP */
875 function save()
876 {
877 }
879 function adapt_from_template($dn)
880 {
881 }
883 function password_change_needed()
884 {
885 }
887 function show_header($button_text, $text, $disabled= FALSE)
888 {
889 }
891 function remove_lock()
892 {
893 if (isset($this->usertab->dn)){
894 del_lock ($this->usertab->dn);
895 }
896 }
898 }
900 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
901 ?>