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 (!isset($_SESSION["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 $_SESSION["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 if (isset($_POST['regexit'])){
147 $userfilter["regex"]= $_POST['regexit'];
148 }
149 }
150 if(isset($_POST['regexit'])){
151 foreach( array("functionalusers", "unixusers", "mailusers","sambausers", "proxyusers", "faxusers", "templates", "subsearch") as $type){
152 if (isset($_POST[$type])) {
153 $userfilter[$type]= "checked";
154 } else {
155 $userfilter[$type]= "";
156 }
157 }
158 }
159 if (isset($_GET['search'])){
160 $s= mb_substr($_GET['search'], 0, 1, "UTF8")."*";
161 if ($s == "**"){
162 $s= "*";
163 }
164 $userfilter['regex']= $s;
165 }
166 register_global("userfilter", $userfilter);
169 /* React on user interaction here */
170 if (($_SERVER["REQUEST_METHOD"] == "POST")||($_SERVER["REQUEST_METHOD"]== "GET")){
172 /* User wants to edit data? */
173 if ($s_action=="edit"){
175 /* Get 'dn' from posted 'uid', must be unique */
177 $this->dn= $this->list[trim($s_entry)]['dn'];
179 /* Check locking, save current plugin in 'back_plugin', so
180 the dialog knows where to return. */
181 if (($user= get_lock($this->dn)) != ""){
182 return(gen_locked_message ($user, $this->dn));
183 }
185 /* Lock the current entry, so everyone will get the
186 above dialog */
187 add_lock ($this->dn, $this->ui->dn);
189 /* Set up the users ACL's for this 'dn' */
190 $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
192 /* Register usertab to trigger edit dialog */
193 $this->usertab= new usertabs($this->config,
194 $this->config->data['TABS']['USERTABS'], $this->dn);
195 $this->usertab->set_acl($acl);
197 $_SESSION['objectinfo']= $this->dn;
198 }
199 }
201 /* Reset requested? */
202 if (isset($_POST['edit_cancel']) || isset($_POST['password_cancel'])){
203 if (isset($this->usertab)){
204 del_lock ($this->usertab->dn);
205 unset ($this->usertab);
206 }
207 $this->usertab= NULL;
208 $this->lognames= array();;
209 $this->sn= "";
210 $this->givenName= "";
211 $this->uid= "";
212 unset ($_SESSION['objectinfo']);
213 }
215 /* Password change requested */
216 if ($s_action=="change_pw"){
218 /* Get 'dn' from posted 'uid' */
219 $this->dn= $this->list[trim($s_entry)]['dn'];
221 /* Load permissions for selected 'dn' and check if
222 we're allowed to remove this 'dn' */
223 $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
224 $acl= get_module_permission($acl, "user", $this->dn);
225 if (chkacl($acl, "password") == ""){
227 /* User is allowed to change passwords, save 'dn' and 'acl' for next
228 dialog. */
229 $this->acl= $acl;
230 $_SESSION['objectinfo']= $this->dn;
231 return ($smarty->fetch(get_template_path('password.tpl', TRUE)));
233 } else {
234 /* User is not allowed. Show message and cancel. */
235 print_red (_("You are not allowed to set this users password!"));
236 }
237 }
239 /* Perform password change */
240 if (isset($_POST['password_finish'])){
242 /* For security reasons, check if user is allowed to set password again */
243 if (chkacl($this->acl, "password") == "" || chkacl($this->acl, "create")){
245 /* Check input and feed errors into 'message' */
246 $message= array();
248 /* Sanity checks... */
249 if ($_POST['new_password'] != $_POST['repeated_password']){
251 /* Matching passwords in new and repeated? */
252 $message[]= _("The passwords you've entered as 'New password' and 'Repeated new password' do not match.");
253 } else {
255 /* Empty password is not permitted by default. */
256 if ($_POST['new_password'] == ""){
257 $message[]= _("The password you've entered as 'New password' is empty.");
258 }
259 }
261 /* Errors, or change password? */
262 if (count($message) != 0){
264 /* Show error message and continue editing */
265 show_errors ($message);
266 return($smarty->fetch(get_template_path('password.tpl', TRUE)));
267 }
269 /* Set password, perform required steps */
270 if ($this->usertab){
271 if ($this->usertab->password_change_needed()){
272 $obj= $this->usertab->by_object['user'];
273 change_password ($this->usertab->dn, $_POST['new_password'],
274 0, $obj->pw_storage);
275 gosa_log ("Password for '".$this->usertab->dn."' has been changed");
276 unset($this->usertab);
277 $this->usertab= NULL;
278 }
279 } else {
280 change_password ($this->dn, $_POST['new_password']);
281 gosa_log ("Password for '".$this->dn."' has been changed");
282 }
283 } else {
285 /* Missing permissions, show message */
286 print_red (_("You are not allowed to set this users password!"));
287 }
289 /* Clean session, delete lock */
290 del_lock ($this->dn);
291 $this->reload();
292 unset ($this->usertab);
293 $this->usertab= NULL;
294 $this->lognames= array();;
295 $this->sn= "";
296 $this->givenName= "";
297 $this->uid= "";
298 unset ($_SESSION['objectinfo']);
299 }
302 /* Remove user was requested */
303 if ($s_action=="del"){
305 /* Get 'dn' from posted 'uid' */
306 $this->dn= $this->list[trim($s_entry)]['dn'];
308 /* Load permissions for selected 'dn' and check if
309 we're allowed to remove this 'dn' */
310 $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
311 $this->acl= get_module_permission($acl, "user", $this->dn);
312 if (chkacl($this->acl, "delete") == ""){
314 /* Check locking, save current plugin in 'back_plugin', so
315 the dialog knows where to return. */
316 if (($user= get_lock($this->dn)) != ""){
317 return(gen_locked_message ($user, $this->dn));
318 }
320 /* Lock the current entry, so nobody will edit it during deletion */
321 add_lock ($this->dn, $this->ui->dn);
322 $smarty->assign("info", sprintf(_("You're about to delete the user %s."), $this->dn));
323 return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
324 } else {
326 /* Obviously the user isn't allowed to delete. Show message and
327 clean session. */
328 print_red (_("You are not allowed to delete this user!"));
329 }
330 }
334 /* Confirmation for deletion has been passed. User should be deleted. */
335 if (isset($_POST['delete_user_confirm'])){
337 /* Some nice guy may send this as POST, so we've to check
338 for the permissions again. */
339 if (chkacl($this->acl, "delete") == ""){
341 /* Delete request is permitted, perform LDAP action */
342 $this->usertab= new usertabs($this->config, $this->config->data['TABS']['USERTABS'],
343 $this->dn);
344 $this->usertab->set_acl(array($this->acl));
345 $this->usertab->delete ();
346 gosa_log ("User object '".$this->dn."' has been removed");
347 unset ($this->usertab);
348 $this->usertab= NULL;
350 /* User list has changed, reload it. */
351 $this->reload ();
352 } else {
354 /* Normally this shouldn't be reached, send some extra
355 logs to notify the administrator */
356 print_red (_("You are not allowed to delete this user!"));
358 if(isset($this->ui->uid)){
359 gosa_log ("Warning: '".$this->ui->uid."' tried to trick user deletion.");
360 }
361 }
363 /* Remove lock file after successfull deletion */
364 del_lock ($this->dn);
365 }
368 /* Delete user canceled? */
369 if (isset($_POST['delete_cancel'])){
370 del_lock ($this->dn);
371 }
374 /* Finish user edit is triggered by the tabulator dialog, so
375 the user wants to save edited data. Check and save at this
376 point. */
377 if (isset($_POST['edit_finish'])){
379 /* Check tabs, will feed message array */
380 $this->usertab->last= $this->usertab->current;
381 $this->usertab->save_object();
382 $message= $this->usertab->check();
384 /* Save, or display error message? */
385 if (count($message) == 0){
387 /* No errors. Go ahead and prepare to ask for a password
388 in case we're creating a new user. 'dn' will be 'new'
389 in this case. It is set to the correct value later. */
390 if ($this->dn == "new"){
391 $set_pass= 1;
392 } else {
393 $set_pass= 0;
394 }
396 /* Save user data to ldap */
397 if($this->usertab->save() == 1){
398 gosa_log ("User object '".$this->dn."' saving failed.");
399 return;
400 }
401 gosa_log ("User object '".$this->dn."' has been saved");
403 /* User has been saved successfully, remove lock from
404 LDAP. */
405 if ($this->dn != "new"){
406 del_lock ($this->dn);
407 }
409 /* In case of new users, ask for a password */
410 if (($set_pass || $this->usertab->password_change_needed()) &&
411 !$this->is_template){
413 return($smarty->fetch(get_template_path('password.tpl', TRUE)));
414 }
416 /* There's no page reload so we have to read new users at
417 this point. */
418 $this->reload ();
419 unset ($this->usertab);
420 $this->usertab= NULL;
421 unset ($_SESSION['objectinfo']);
423 } else {
424 /* Ok. There seem to be errors regarding to the tab data,
425 show message and continue as usual. */
426 show_errors($message);
427 }
428 }
430 /* Generate template list */
431 if ($s_action=="new"){
432 $this->templates= array();
433 $ldap= $this->config->get_ldap_link();
434 foreach ($this->config->departments as $key => $value){
435 $acl= get_permissions (get_people_ou().$value, $this->ui->subtreeACL);
436 $acl= get_module_permission($acl, "user", get_people_ou().$value);
437 if (chkacl($acl, "create") == ""){
438 $ldap->cd (get_people_ou().$value);
439 $ldap->search ("(objectClass=gosaUserTemplate)", array("uid"));
441 if ($ldap->count() != 0){
442 while ($attrs= $ldap->fetch()){
443 $this->templates[$ldap->getDN()]=
444 $attrs['uid'][0]." - $key";
445 }
446 $this->templates['none']= _("none");
447 }
448 }
449 }
450 natcasesort ($this->templates);
451 reset ($this->templates);
452 }
454 /* New user/template request */
455 if (($s_action=="new") || ($s_action=="new_tpl")){
456 /* By default we set 'dn' to 'new', all relevant plugins will
457 react on this. */
458 $this->dn= "new";
459 if (isset($this->config->current['IDGEN'])){
460 $this->got_uid= false;
461 } else {
462 $this->got_uid= true;
463 }
465 /* Create new usertab object */
466 $this->usertab= new usertabs($this->config,
467 $this->config->data['TABS']['USERTABS'], $this->dn);
468 $this->usertab->set_acl(array(':all'));
470 /* Take care about templates */
471 if ($s_action=="new_tpl"){
472 $this->is_template= TRUE;
473 $this->usertab->set_template_mode ();
474 } else {
475 $this->is_template= FALSE;
476 }
478 /* Use template if there are any of them */
479 if (count($this->templates) && !isset($_POST['new_template'])){
480 foreach(array("sn", "givenName", "uid", "got_uid", "templates") as $attr){
481 $smarty->assign("$attr", $this->$attr);
482 }
483 if (isset($_POST['template'])){
484 $smarty->assign("template", $_POST['template']);
485 } else {
486 $smarty->assign("template", "");
487 }
488 $smarty->assign("edit_uid", "");
489 return($smarty->fetch(get_template_path('template.tpl', TRUE)));
490 }
491 }
493 /* Continue template editing */
494 if (isset($_POST['template_continue']) && $_POST['template'] != 'none' && !isset($_POST['uid'])){
495 $this->sn= $_POST['sn'];
496 $this->givenName= $_POST['givenName'];
498 /* Check for requred values */
499 $message= array();
500 if ($this->sn == "") {
501 $message[]= _("The required field 'Name' is not set.");
502 }
503 if ($this->givenName == "") {
504 $message[]= _("The required field 'Given name' is not set.");
505 }
507 /* Check if dn is used */
508 $dn= preg_replace("/^[^,]+,/i", "", $_POST['template']);
509 $ldap= $this->config->get_ldap_link();
510 $ldap->cd ($dn);
511 $ldap->search ("(&(sn=".$this->sn.")(givenName=".$this->givenName."))", array("givenName"));
512 if ($ldap->count () != 0){
513 $message[]= _("A person with the choosen name is already used in this tree.");
514 }
516 /* Show error message / continue editing */
517 if (count($message) > 0){
518 show_errors ($message);
519 } else {
520 $attributes= array('sn' => $this->sn, 'givenName' => $this->givenName);
521 if (isset($this->config->current['IDGEN']) &&
522 $this->config->current['IDGEN'] != ""){
523 $uids= gen_uids ($this->config->current['IDGEN'], $attributes);
524 if (count($uids)){
525 $smarty->assign("edit_uid", "false");
526 $smarty->assign("uids", $uids);
527 $this->uid= current($uids);
528 }
529 } else {
530 $smarty->assign("edit_uid", "");
531 $this->uid= "";
532 }
533 $this->got_uid= true;
534 }
536 foreach(array("sn", "givenName", "uid", "got_uid", "templates") as $attr){
537 $smarty->assign("$attr", $this->$attr);
538 }
539 if (isset($_POST['template'])){
540 $smarty->assign("template", $_POST['template']);
541 }
542 return($smarty->fetch(get_template_path('template.tpl', TRUE)));
543 }
545 /* No template. Ok. Lets fill data into the normal user dialog */
546 if (isset($_POST['template_continue']) && $_POST['template'] == 'none'){
547 foreach(array("sn", "givenName", "uid") as $attr){
548 if (isset($_POST[$attr])){
549 $this->usertab->by_object['user']->$attr= $_POST[$attr];
550 }
551 }
552 }
554 /* Finish template preamble */
555 if (isset($_POST['template_continue']) && $_POST['template'] != 'none' && (isset($_POST['uid']))){
557 /* Might not be filled if IDGEN is unset */
558 $this->sn= $_POST['sn'];
559 $this->givenName= $_POST['givenName'];
561 /* Move user supplied data to sub plugins */
562 $this->uid= $_POST['uid'];
563 $this->usertab->uid= $this->uid;
564 $this->usertab->sn= $this->sn;
565 $this->usertab->givenName= $this->givenName;
566 $template_dn= $_POST['template'];
567 $this->usertab->adapt_from_template($template_dn);
568 $template_base= $userfilter['depselect'];//preg_replace("/^[^,]+,".get_people_ou()."/", '', $template_dn);
569 $this->usertab->by_object['user']->base= $template_base;
571 /* Set up the users ACL's for this 'dn' */
572 $acl= get_permissions ($template_base, $this->ui->subtreeACL);
573 $this->usertab->set_acl($acl);
574 }
576 /* Show tab dialog if object is present */
577 if ($this->usertab){
578 $display= $this->usertab->execute();
580 /* Don't show buttons if tab dialog requests this */
581 if (!$this->usertab->by_object[$this->usertab->current]->dialog){
582 $display.= "<p style=\"text-align:right\">\n";
583 $display.= "<input type=submit name=\"edit_finish\" value=\""._("Finish")."\">\n";
584 $display.= " \n";
585 $display.= "<input type=submit name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
586 $display.= "</p>";
587 }
588 return ($display);
589 }
591 $smarty= get_smarty();
593 /* Check sorting variable */
594 if (!isset($this->usertab) &&
595 !isset($_POST['new_user']) &&
596 !isset($_POST['new_template']) &&
597 !isset($_POST['delete_user']) &&
598 !isset($_POST['setpass_user']) &&
599 !isset($_POST['select_user'])){
600 $this->reload();
601 }
603 /* Check for exeeded sizelimit */
604 if (($message= check_sizelimit()) != ""){
605 return($message);
606 }
608 /* Prepare departments */
609 $options= "";
610 foreach ($this->config->idepartments as $key => $value){
611 if ($userfilter['depselect'] == $key){
612 $options.= "<option selected value='$key'>$value</option>";
613 } else {
614 $options.= "<option value='$key'>$value</option>";
615 }
616 }
618 /* NEW LIST MANAGMENT */
619 $listhead = "<div style='background:#F0F0F9;padding:5px;'>".
620 " <input type='image' align='middle' src='images/list_back.png' title='"._("Go up one department")."' alt='"._("Up")."' name='dep_back'> ".
621 " <input type='image' src='images/list_root.png' align='middle' title='"._("Go to root department")."' name='dep_root' alt='"._("Root")."'> ".
622 " <input type='image' align='middle' src='images/list_home.png' title='"._("Go to users department")."' alt='"._("Home")."' name='dep_home'> ".
623 " <img src='images/list_seperator.png' align='middle' alt='' height='16' width='1'> ".
624 " <input type='image' align='middle' src='images/list_new_user.png' title='"._("Create new user")."' alt='"._("New user")."' name='user_new'> ".
625 " <input type='image' align='middle' src='images/list_new.png' title='"._("Create new template")."' alt='"._("New template")."' name='user_tplnew'> ".
626 " <img src='images/list_seperator.png' align='middle' alt='' height='16' width='1'> ".
627 _("Current base")." <select name='depselect' onChange='mainform.submit()'>$options</select>".
628 " <input type='image' src='images/list_submit.png' align='middle' title='"._("Submit department")."' name='submit_department' alt='"._("Submit")."'> ".
629 "</div>";
631 $action= "<input type='image' src='images/edit.png' alt='"._("edit")."' name='user_edit_%KEY%' title='"._("Edit user")."'>";
632 $action.= "<input type='image' src='images/list_password.png' alt='"._("password")."' name='user_chgpw_%KEY%' title='"._("Change password")."'>";
633 $action.= "<input type='image' src='images/editdelete.png' alt='"._("delete")."' name='user_del_%KEY%' title='"._("Delete user")."'>";
637 $divlist = new divlist("userstab");
638 $divlist->SetHeader(array(
639 array("string" => " "),
640 array("string" => _("Username")." / "._("Department")),
641 array("string" => _("Properties")),
642 array("string" => _("Actions"), "attach" => "style='border:none'" )));
645 $divlist->SetSummary(_("This table displays all users, in the selected tree."));
646 $divlist->SetEntriesPerPage(20);
648 // Defining Links
649 $linkopen = "<a href='?plug=".$_GET['plug']."&act=dep_open&dep_id=%s'>%s</a>";
651 foreach($this->departments as $key=> $val){
653 $field1 = array("string" => "<img src='images/folder.png' alt='department'>");
654 $field2 = array("string" => sprintf($linkopen,base64_encode($key),$val));
655 $field3 = array("string" => " ");
656 $field4 = array("string" => " ", "attach" => "style='border:none'");
659 $divlist->AddEntry(array($field1,$field2,$field3,$field4));
660 }
662 // Pictures for Extensions
663 $usrimg = "<img src='images/penguin.png' alt='U' title='"._("GOsa") ."'>";
664 $posiximg = "<img src='images/select_user.png' alt='P' title='"._("Posix") ."'>";
665 $mailimg = "<img src='images/mailto.png' alt='M' title='"._("Mail") ."'>";
666 $fonimg = "<img src='images/select_phone.png' alt='T' title='"._("Phone") ."'>";
667 $faximg = "<img src='images/fax_small.png' alt='F' title='"._("Fax") ."'>";
668 $sambaimg = "<img src='images/select_winstation.png' alt='S' title='"._("Samba") ."'>";
670 // Space
671 $empty = "<img src='images/empty.png' style='width:16px;height:16px;' alt=''>";
673 // User and Template Images
674 $userimg = "<img src='images/select_user.png' alt='User' title='%s'>";
675 $tplimg = "<img src='images/select_template.png' alt='Template' title='%s'>";
677 $editlink = "<a href='?plug=".$_GET['plug']."&id=%s&act=edit_entry'>%s</a>";
679 // Defines Arrays to save User and Templates
680 $tpls = array();
681 $users= array();
683 // Test Every Entry and generate divlist Array
684 foreach($this->list as $key => $val){
686 // Specify Pics for Extensions
687 if(in_array("posixAccount" ,$val['objectClass'])) $posix = $posiximg; else $posix=$empty;
688 if(in_array("gosaMailAccount" ,$val['objectClass'])) $maila = $mailimg; else $maila=$empty;
689 if(in_array("goFonAccount" ,$val['objectClass'])) $fonac = $fonimg; else $fonac=$empty;
690 if(in_array("goFaxAccount" ,$val['objectClass'])) $faxac = $faximg; else $faxac=$empty;
691 if(in_array("sambaSamAccount" ,$val['objectClass'])) $samba = $sambaimg; else $samba=$empty;
692 if(in_array("gosaUserTemplate",$val['objectClass'])) $tpl = $tplimg; else $tpl=$userimg;
694 // Generate Array to Add
695 if (isset($val["sn"]) && isset($val["givenName"])){
696 $display= $val["sn"][0].", ".$val["givenName"][0]." [".$val["uid"][0]."]";
697 } else {
698 $display= "[".$val["uid"][0]."]";
699 }
701 $field1 = array("string" => sprintf($tpl,$val['dn']),"attach"=>"style='width:20px;align:middle;'");
702 $field2 = array("string" => sprintf($editlink,$key,$display),"attach"=>"title='".$val['dn']."'");
703 $field3 = array("string" => $usrimg." ".$posix." ".$maila." ".$fonac." ".$faxac." ".$samba,"attach" => "style='width:118px;'");
704 $field4 = array("string" => preg_replace("/%KEY%/", "$key", $action),"attach" => "style='border:none; text-align:right;width:48px'");
706 $add = array($field1,$field2,$field3,$field4);
708 // Template or User
709 if(in_array("gosaUserTemplate",$val['objectClass'])){
710 $tpls[strtolower( $val['sn']['0'].$val['uid']['0'])]=$add;
711 }else{
712 $users[strtolower( $val['sn']['0'].$val['uid']['0'])]=$add;
713 }
714 }
716 // Sort Entries
717 ksort($users);
718 ksort($tpls);
720 // Append Templates
721 foreach($tpls as $key => $val){
722 $divlist->AddEntry( $val, array(""));
723 }
724 // Append Users
725 foreach($users as $key => $val){
726 $divlist->AddEntry( $val, array(""));
727 }
728 /* Show main page */
729 //$smarty->assign("userlist", nl2br(htmlentities($divlist->DrawList())));
730 $smarty->assign("userlist", $divlist->DrawList());
731 $smarty->assign("userlisthead", $listhead);
733 /* END NEW LIST MANAGMENT
734 */
735 $smarty->assign("search_image", get_template_path('images/search.png'));
736 $smarty->assign("tree_image", get_template_path('images/tree.png'));
737 $smarty->assign("infoimage", get_template_path('images/info.png'));
738 $smarty->assign("launchimage", get_template_path('images/launch.png'));
739 $smarty->assign("deplist", $this->config->idepartments);
740 foreach( array("depselect", "functionalusers", "unixusers",
741 "mailusers", "sambausers", "proxyusers",
742 "faxusers", "templates", "subsearch") as $type){
744 $smarty->assign("$type", $userfilter[$type]);
745 }
747 $smarty->assign("regex", $userfilter["regex"]);
748 /* Extend if we are not using javascript */
749 $smarty->assign("apply", apply_filter());
750 $smarty->assign("alphabet", generate_alphabet());
751 $smarty->assign("hint", print_sizelimit_warning());
753 return ($smarty->fetch(get_template_path('headpage.tpl', TRUE)));
754 }
757 function reload()
758 {
759 /* Get config */
760 $userfilter= get_global('userfilter');
762 /* Set base for all searches */
763 $base= $userfilter['depselect'];
765 /* Regex filter? */
766 if ($userfilter['regex'] != ""){
767 $regex= $userfilter['regex'];
768 } else {
769 $regex= "*";
770 }
772 /* Set filter depending on selection */
773 if ($this->config->current['SAMBAVERSION'] == 3){
774 $samba= "sambaSamAccount";
775 } else {
776 $samba= "sambaAccount";
777 }
779 $filter="";
780 if ($userfilter['functionalusers'] == "checked"){
781 $filter.= "(&(objectClass=gosaAccount)(!(|(objectClass=posixAccount)(objectClass=gosaMailAccount)(objectClass=$samba)(objectClass=goFaxAccount)(objectClass=gosaProxyAccount))))";
782 }
783 if ($userfilter['unixusers'] == "checked"){
784 $filter.= "(objectClass=posixAccount)";
785 }
786 if ($userfilter['mailusers'] == "checked"){
787 $filter.= "(objectClass=gosaMailAccount)";
788 }
789 if ($userfilter['sambausers'] == "checked"){
790 $filter.= "(objectClass=$samba)";
791 }
792 if ($userfilter['proxyusers'] == "checked"){
793 $filter.= "(objectClass=gosaProxyAccount)";
794 }
795 if ($userfilter['faxusers'] == "checked"){
796 $filter.= "(objectClass=goFaxAccount)";
797 }
799 if ($userfilter['templates'] == "checked"){
800 $filter= "(|(objectClass=gosaUserTemplate)(&(objectClass=gosaAccount)(|$filter)))";
801 } else {
802 $filter= "(&(objectClass=gosaAccount)(!(objectClass=gosaUserTemplate))(|$filter))";
803 }
804 $filter= "(&(|(uid=$regex)(sn=$regex)(givenName=$regex))$filter)";
806 /* Generate userlist */
807 $ldap= $this->config->get_ldap_link(TRUE);
808 if ($userfilter['subsearch'] == "checked"){
809 $this->list= get_list($this->ui->subtreeACL, "$filter", TRUE, $base, array("uid", "givenName", "sn", "objectClass"), TRUE);
810 } else {
811 $base= get_people_ou().$base;
812 $this->list= get_list($this->ui->subtreeACL, "$filter", FALSE, $base, array("uid", "givenName", "sn", "objectClass"), TRUE);
813 }
817 /* NEW LIST MANAGMENT
818 * We also need to search for the departments
819 * So we are able to navigate like in konquerer
820 */
821 $base2 = preg_replace("/ou=people,/i","",$base);
823 $res3 = get_list2($this->ui->subtreeACL, "(&(|(ou=$regex)(description=$regex))(objectClass=gosaDepartment))",
824 TRUE, $base2, array("ou", "description"), TRUE);
826 $this->departments= array();
828 $tmp = array();
829 foreach ($res3 as $value){
830 $tmp[strtolower($value['dn']).$value['dn']]=$value;
831 }
832 ksort($tmp);
833 foreach($tmp as $value){
834 if($value["description"][0]!=".."){
835 $this->departments[$value['dn']]=convert_department_dn2($value['dn'])." - [".$value["description"][0]."]";
836 }else{
837 $this->departments[$value['dn']]=$value["description"][0];
838 }
839 }
840 /* END NEW LIST MANAGMENT
841 */
844 $this->userlist= array();
846 foreach ($this->list as $value){
847 if (isset($value["uid"][0]) && !preg_match('/\$$/', $value["uid"][0])){
848 if (in_array_ics('gosaUserTemplate', $value['objectClass'])){
849 $this->userlist[$value["dn"]]= "* ".$value["uid"][0]." ("._("Template").")";
850 continue;
851 }
852 if (isset($value["givenName"][0]) && isset($value["sn"][0])){
853 $this->userlist[$value["dn"]]= $value["sn"][0].", ".
854 $value["givenName"][0].
855 " [".$value["uid"][0]."]";
856 } else {
857 $this->userlist[$value["dn"]]= "[".$value["uid"][0]."]";
858 }
859 }
860 }
862 natcasesort ($this->userlist);
863 reset ($this->userlist);
864 }
866 function remove_from_parent()
867 {
868 }
871 /* Check values */
872 function check()
873 {
874 }
877 /* Save to LDAP */
878 function save()
879 {
880 }
882 function adapt_from_template($dn)
883 {
884 }
886 function password_change_needed()
887 {
888 }
890 function show_header($button_text, $text, $disabled= FALSE)
891 {
892 }
894 function remove_lock()
895 {
896 if (isset($this->usertab->dn)){
897 del_lock ($this->usertab->dn);
898 }
899 }
901 }
903 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
904 ?>