e9460770be246ff41b49ed7e3253390bae883007
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 /* Call parent execute */
63 plugin::execute();
64 $smarty = get_smarty(); // Smarty instance
65 $userfilter = get_global("userfilter"); // contains Filter Settings
66 $s_action = ""; // Contains the action to proceed
67 $s_entry = ""; // The value for s_action
68 $base_back = ""; // The Link for Backbutton
70 /* Start for New List Managment */
71 if(isset($_GET['act'])&&($_GET['act']=="dep_open")){
72 $s_action="open";
73 $s_entry = base64_decode($_GET['dep_id']);
74 $userfilter['depselect']= "".$this->config->departments[trim($s_entry)];
75 }
77 /* Test Posts */
78 foreach($_POST as $key => $val){
79 // Post for delete
80 if(preg_match("/user_del.*/",$key)){
81 $s_action = "del";
82 $s_entry = preg_replace("/user_".$s_action."_/i","",$key);
83 // Post for edit
84 }elseif(preg_match("/user_edit_.*/",$key)){
85 $s_action="edit";
86 $s_entry = preg_replace("/user_".$s_action."_/i","",$key);
87 // Post for new
88 }elseif(preg_match("/dep_back.*/i",$key)){
89 $s_action="back";
90 }elseif(preg_match("/user_new.*/",$key)){
91 $s_action="new";
92 }elseif(preg_match("/dep_home.*/i",$key)){
93 $s_action="home";
94 }elseif(preg_match("/user_tplnew.*/i",$key)){
95 $s_action="new_tpl";
96 }elseif(preg_match("/user_chgpw.*/i",$key)){
97 $s_action="change_pw";
98 $s_entry = preg_replace("/user_chgpw_/i","",$key);
99 }elseif(preg_match("/dep_root.*/i",$key)){
100 $s_action="root";
101 }elseif(preg_match("/userfrom_tpl.*/i",$key)){
102 $s_action="create_user_from_tpl";
103 $s_entry = preg_replace("/userfrom_tpl_/i","",$key);
104 }
105 }
107 if((isset($_GET['act']))&&($_GET['act']=="edit_entry")){
108 $s_action = "edit";
109 $s_entry = $_GET['id'];
110 }
112 $s_entry = preg_replace("/_.$/","",$s_entry);
114 if(preg_match("/.*-.*/",$s_entry)){
115 $s_tab = preg_replace("/^.*-/i","",$s_entry);
116 $s_entry = preg_replace("/-.*$/i","",$s_entry);
117 }else{
118 $s_tab = "user";
119 };
121 /* Department changed? */
122 if(isset($_POST['depselect']) && $_POST['depselect']){
123 $userfilter['depselect']= $_POST['depselect'];
124 }
126 /* Homebutton is posted */
127 if($s_action=="home"){
128 $userfilter['depselect']=(preg_replace("/^[^,]+,/","",$this->ui->dn));
129 $userfilter['depselect']=(preg_replace("/^[^,]+,/","",$userfilter['depselect']));
130 }
132 if($s_action=="root"){
133 $userfilter['depselect']=($this->config->current['BASE']);
134 }
137 /* If Backbutton is Posted */
138 if($s_action=="back"){
139 $base_back = preg_replace("/^[^,]+,/","",$userfilter['depselect']);
140 $base_back = convert_department_dn($base_back);
142 if(isset($this->config->departments[trim($base_back)])){
143 $userfilter['depselect']= $this->config->departments[trim($base_back)];
144 }else{
145 $userfilter['depselect']= $this->config->departments["/"];
146 }
147 }
149 /* End for new List Managment */
151 /* Save filter data if we are in the headpage */
152 if (!isset($this->usertab)){
153 if (isset($_POST['regexit'])){
154 $userfilter["regex"]= $_POST['regexit'];
155 }
156 }
157 if(isset($_POST['regexit'])){
158 foreach( array("functionalusers", "unixusers", "mailusers","sambausers", "proxyusers", "faxusers", "templates", "subsearch") as $type){
159 if (isset($_POST[$type])) {
160 $userfilter[$type]= "checked";
161 } else {
162 $userfilter[$type]= "";
163 }
164 }
165 }
166 if (isset($_GET['search'])){
167 $s= mb_substr($_GET['search'], 0, 1, "UTF8")."*";
168 if ($s == "**"){
169 $s= "*";
170 }
171 $userfilter['regex']= $s;
172 }
173 register_global("userfilter", $userfilter);
176 /* React on user interaction here */
177 if (($_SERVER["REQUEST_METHOD"] == "POST")||($_SERVER["REQUEST_METHOD"]== "GET")){
179 /* User wants to edit data? */
180 if ($s_action=="edit"){
182 /* Get 'dn' from posted 'uid', must be unique */
184 $this->dn= $this->list[trim($s_entry)]['dn'];
186 /* Check locking, save current plugin in 'back_plugin', so
187 the dialog knows where to return. */
188 if (($user= get_lock($this->dn)) != ""){
189 return(gen_locked_message ($user, $this->dn));
190 }
192 /* Lock the current entry, so everyone will get the
193 above dialog */
194 add_lock ($this->dn, $this->ui->dn);
196 /* Set up the users ACL's for this 'dn' */
197 $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
199 /* Register usertab to trigger edit dialog */
200 $this->usertab= new usertabs($this->config,
201 $this->config->data['TABS']['USERTABS'], $this->dn);
202 // $_POST[$s_tab]=$s_tab;
204 // This would be better
205 $this->usertab->current = $s_tab;
206 $this->usertab->set_acl($acl);
208 $_SESSION['objectinfo']= $this->dn;
209 }
210 }
212 /* Reset requested? */
213 if (isset($_POST['edit_cancel']) || isset($_POST['password_cancel'])){
214 if (isset($this->usertab)){
215 del_lock ($this->usertab->dn);
216 unset ($this->usertab);
217 }
218 $this->usertab= NULL;
219 $this->lognames= array();;
220 $this->sn= "";
221 $this->givenName= "";
222 $this->uid= "";
223 unset ($_SESSION['objectinfo']);
224 }
226 /* Password change requested */
227 if ($s_action=="change_pw"){
229 /* Get 'dn' from posted 'uid' */
230 $this->dn= $this->list[trim($s_entry)]['dn'];
232 /* Load permissions for selected 'dn' and check if
233 we're allowed to remove this 'dn' */
234 $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
235 $acl= get_module_permission($acl, "user", $this->dn);
236 if (chkacl($acl, "password") == ""){
238 /* User is allowed to change passwords, save 'dn' and 'acl' for next
239 dialog. */
240 $this->acl= $acl;
241 $_SESSION['objectinfo']= $this->dn;
242 return ($smarty->fetch(get_template_path('password.tpl', TRUE)));
244 } else {
245 /* User is not allowed. Show message and cancel. */
246 print_red (_("You are not allowed to set this users password!"));
247 }
248 }
250 /* Perform password change */
251 if (isset($_POST['password_finish'])){
253 /* For security reasons, check if user is allowed to set password again */
254 if (chkacl($this->acl, "password") == "" || chkacl($this->acl, "create")){
256 /* Check input and feed errors into 'message' */
257 $message= array();
259 /* Sanity checks... */
260 if ($_POST['new_password'] != $_POST['repeated_password']){
262 /* Matching passwords in new and repeated? */
263 $message[]= _("The passwords you've entered as 'New password' and 'Repeated new password' do not match.");
264 } else {
266 /* Empty password is not permitted by default. */
267 if ($_POST['new_password'] == ""){
268 $message[]= _("The password you've entered as 'New password' is empty.");
269 }
270 }
272 /* Errors, or change password? */
273 if (count($message) != 0){
275 /* Show error message and continue editing */
276 show_errors ($message);
277 return($smarty->fetch(get_template_path('password.tpl', TRUE)));
278 }
280 $config= $this->config;
281 $ldap_ui= $this->config->get_ldap_link();
282 if(isset($this->usertab->dn)){
283 $user = ($ldap_ui->fetch($ldap_ui->cat($this->usertab->dn)));
284 }else{
285 $user = ($ldap_ui->fetch($ldap_ui->cat($this->dn)));
286 }
287 if((is_array($user))&&(isset($user['uid']))){
288 $username= $user['uid'][0];
289 }
291 /* Set password, perform required steps */
292 if ($this->usertab){
293 if ($this->usertab->password_change_needed()){
294 $obj= $this->usertab->by_object['user'];
295 change_password ($this->usertab->dn, $_POST['new_password'],
296 0, $obj->pw_storage);
297 if (isset($config->data['MAIN']['EXTERNALPWDHOOK'])){
298 exec($config->data['MAIN']['EXTERNALPWDHOOK']." ".$username." ".$_POST['new_password'], $resarr);
299 }
301 gosa_log ("Password for '".$this->usertab->dn."' has been changed");
302 unset($this->usertab);
303 $this->usertab= NULL;
304 }
305 } else {
306 change_password ($this->dn, $_POST['new_password']);
307 if (isset($config->data['MAIN']['EXTERNALPWDHOOK'])){
308 exec($config->data['MAIN']['EXTERNALPWDHOOK']." ".$username." ".$_POST['new_password'], $resarr);
309 }
311 gosa_log ("Password for '".$this->dn."' has been changed");
312 }
313 } else {
315 /* Missing permissions, show message */
316 print_red (_("You are not allowed to set this users password!"));
317 }
319 /* Clean session, delete lock */
320 del_lock ($this->dn);
321 $this->reload();
322 unset ($this->usertab);
323 $this->usertab= NULL;
324 $this->lognames= array();;
325 $this->sn= "";
326 $this->givenName= "";
327 $this->uid= "";
328 unset ($_SESSION['objectinfo']);
329 }
332 /* Remove user was requested */
333 if ($s_action=="del"){
335 /* Get 'dn' from posted 'uid' */
336 $this->dn= $this->list[trim($s_entry)]['dn'];
338 /* Load permissions for selected 'dn' and check if
339 we're allowed to remove this 'dn' */
340 $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
341 $this->acl= get_module_permission($acl, "user", $this->dn);
342 if (chkacl($this->acl, "delete") == ""){
344 /* Check locking, save current plugin in 'back_plugin', so
345 the dialog knows where to return. */
346 if (($user= get_lock($this->dn)) != ""){
347 return(gen_locked_message ($user, $this->dn));
348 }
350 /* Lock the current entry, so nobody will edit it during deletion */
351 add_lock ($this->dn, $this->ui->dn);
352 $smarty->assign("info", sprintf(_("You're about to delete the user %s."), $this->dn));
353 return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
354 } else {
356 /* Obviously the user isn't allowed to delete. Show message and
357 clean session. */
358 print_red (_("You are not allowed to delete this user!"));
359 }
360 }
364 /* Confirmation for deletion has been passed. User should be deleted. */
365 if (isset($_POST['delete_user_confirm'])){
367 /* Some nice guy may send this as POST, so we've to check
368 for the permissions again. */
369 if (chkacl($this->acl, "delete") == ""){
371 /* Delete request is permitted, perform LDAP action */
372 $this->usertab= new usertabs($this->config, $this->config->data['TABS']['USERTABS'],
373 $this->dn);
374 $this->usertab->set_acl(array($this->acl));
375 $this->usertab->delete ();
376 gosa_log ("User object '".$this->dn."' has been removed");
377 unset ($this->usertab);
378 $this->usertab= NULL;
380 /* User list has changed, reload it. */
381 $this->reload ();
382 } else {
384 /* Normally this shouldn't be reached, send some extra
385 logs to notify the administrator */
386 print_red (_("You are not allowed to delete this user!"));
388 if(isset($this->ui->uid)){
389 gosa_log ("Warning: '".$this->ui->uid."' tried to trick user deletion.");
390 }
391 }
393 /* Remove lock file after successfull deletion */
394 del_lock ($this->dn);
395 }
398 /* Delete user canceled? */
399 if (isset($_POST['delete_cancel'])){
400 del_lock ($this->dn);
401 }
404 /* Finish user edit is triggered by the tabulator dialog, so
405 the user wants to save edited data. Check and save at this
406 point. */
407 if (isset($_POST['edit_finish'])){
409 /* Check tabs, will feed message array */
410 $this->usertab->last= $this->usertab->current;
411 $this->usertab->save_object();
412 $message= $this->usertab->check();
414 /* Save, or display error message? */
415 if (count($message) == 0){
417 /* No errors. Go ahead and prepare to ask for a password
418 in case we're creating a new user. 'dn' will be 'new'
419 in this case. It is set to the correct value later. */
420 if ($this->dn == "new"){
421 $set_pass= 1;
422 } else {
423 $set_pass= 0;
424 }
426 /* Save user data to ldap */
427 if($this->usertab->save() == 1){
428 gosa_log ("User object '".$this->dn."' saving failed.");
429 return;
430 }
431 gosa_log ("User object '".$this->dn."' has been saved");
433 /* User has been saved successfully, remove lock from
434 LDAP. */
435 if ($this->dn != "new"){
436 del_lock ($this->dn);
437 }
439 /* In case of new users, ask for a password */
440 if (($set_pass || $this->usertab->password_change_needed()) &&
441 !$this->is_template){
443 return($smarty->fetch(get_template_path('password.tpl', TRUE)));
444 }
446 /* There's no page reload so we have to read new users at
447 this point. */
448 $this->reload ();
449 unset ($this->usertab);
450 $this->usertab= NULL;
451 unset ($_SESSION['objectinfo']);
453 } else {
454 /* Ok. There seem to be errors regarding to the tab data,
455 show message and continue as usual. */
456 show_errors($message);
457 }
458 }
460 /* Generate template list */
461 if (($s_action=="new")||($s_action=="create_user_from_tpl")){
463 $this->templates= array();
465 $ldap= $this->config->get_ldap_link();
467 /* Create list of tempaltes */
468 foreach ($this->config->departments as $key => $value){
470 /* Get acls from different ou's */
471 $acl= get_permissions (get_people_ou().$value, $this->ui->subtreeACL);
472 $acl= get_module_permission($acl, "user", get_people_ou().$value);
474 /* If creation of a new user is allowed, append this template */
475 if (chkacl($acl, "create") == ""){
477 /* Search all templates from the current dn */
478 $ldap->cd (get_people_ou().$value);
479 $ldap->search ("(objectClass=gosaUserTemplate)", array("uid"));
481 /* Append */
482 if ($ldap->count() != 0){
483 while ($attrs= $ldap->fetch()){
484 $this->templates[$ldap->getDN()]=
485 $attrs['uid'][0]." - $key";
486 }
487 $this->templates['none']= _("none");
488 }
489 }
490 }
492 /* Sort templates */
493 natcasesort ($this->templates);
494 reset ($this->templates);
495 }
497 /* New user/template request */
498 if (($s_action=="create_user_from_tpl")||($s_action=="new") || ($s_action=="new_tpl")){
499 /* By default we set 'dn' to 'new', all relevant plugins will
500 react on this. */
501 $this->dn= "new";
502 if (isset($this->config->current['IDGEN'])){
503 $this->got_uid= false;
504 } else {
505 $this->got_uid= true;
506 }
508 /* Create new usertab object */
509 $this->usertab= new usertabs($this->config,
510 $this->config->data['TABS']['USERTABS'], $this->dn);
511 $this->usertab->set_acl(array(':all'));
512 $this->usertab->by_object['user']->base= $userfilter['depselect'];
514 /* Take care about templates */
515 if ($s_action=="new_tpl"){
516 $this->is_template= TRUE;
517 $this->usertab->set_template_mode ();
518 } else {
519 $this->is_template= FALSE;
520 }
522 /* Use template if there are any of them */
523 if ((count($this->templates) && !isset($_POST['new_template']))||($s_action=="create_user_from_tpl")){
524 foreach(array("sn", "givenName", "uid", "got_uid", "templates") as $attr){
525 $smarty->assign("$attr", $this->$attr);
526 }
527 if ($s_action=="create_user_from_tpl"){
528 $smarty->assign("template", $this->dn= $this->list[trim($s_entry)]['dn']);
529 } else {
530 $smarty->assign("template", "none");
531 }
532 $smarty->assign("edit_uid", "");
533 return($smarty->fetch(get_template_path('template.tpl', TRUE)));
534 }
535 }
537 /* Continue template editing */
538 if ((isset($_POST['template_continue']) && $_POST['template'] != 'none' && !isset($_POST['uid']))){
539 $this->sn= $_POST['sn'];
540 $this->givenName= $_POST['givenName'];
542 /* Check for requred values */
543 $message= array();
544 if ($this->sn == "") {
545 $message[]= _("The required field 'Name' is not set.");
546 }
547 if ($this->givenName == "") {
548 $message[]= _("The required field 'Given name' is not set.");
549 }
551 /* Check if dn is used */
552 $dn= preg_replace("/^[^,]+,/i", "", $_POST['template']);
553 $ldap= $this->config->get_ldap_link();
554 $ldap->cd ($dn);
555 $ldap->search ("(&(sn=".$this->sn.")(givenName=".$this->givenName."))", array("givenName"));
556 if ($ldap->count () != 0){
557 $message[]= _("A person with the choosen name is already used in this tree.");
558 }
560 /* Show error message / continue editing */
561 if (count($message) > 0){
562 show_errors ($message);
563 } else {
564 $attributes= array('sn' => $this->sn, 'givenName' => $this->givenName);
565 if (isset($this->config->current['IDGEN']) &&
566 $this->config->current['IDGEN'] != ""){
567 $uids= gen_uids ($this->config->current['IDGEN'], $attributes);
568 if (count($uids)){
569 $smarty->assign("edit_uid", "false");
570 $smarty->assign("uids", $uids);
571 $this->uid= current($uids);
572 }
573 } else {
574 $smarty->assign("edit_uid", "");
575 $this->uid= "";
576 }
577 $this->got_uid= true;
578 }
580 foreach(array("sn", "givenName", "uid", "got_uid", "templates") as $attr){
581 $smarty->assign("$attr", $this->$attr);
582 }
583 if (isset($_POST['template'])){
584 $smarty->assign("template", $_POST['template']);
585 }
586 return($smarty->fetch(get_template_path('template.tpl', TRUE)));
587 }
589 /* No template. Ok. Lets fill data into the normal user dialog */
590 if (isset($_POST['template_continue']) && $_POST['template'] == 'none'){
591 foreach(array("sn", "givenName", "uid") as $attr){
592 if (isset($_POST[$attr])){
593 $this->usertab->by_object['user']->$attr= $_POST[$attr];
594 }
595 }
596 }
598 /* Finish template preamble */
599 if (isset($_POST['template_continue']) && $_POST['template'] != 'none' && (isset($_POST['uid']))){
601 /* Might not be filled if IDGEN is unset */
602 $this->sn = $_POST['sn'];
603 $this->givenName = $_POST['givenName'];
605 /* Move user supplied data to sub plugins */
606 $this->uid = $_POST['uid'];
607 $this->usertab->uid = $this->uid;
608 $this->usertab->sn = $this->sn;
609 $this->usertab->givenName = $this->givenName;
610 $template_dn = $_POST['template'];
611 $this->usertab->adapt_from_template($template_dn);
612 $template_base = preg_replace("/^[^,]+,".get_people_ou()."/", '', $template_dn);
613 $this->usertab->by_object['user']->base= $template_base;
615 /* Set up the users ACL's for this 'dn' */
616 $acl= get_permissions ($template_base, $this->ui->subtreeACL);
617 $this->usertab->set_acl($acl);
618 }
620 if (isset($_POST['template_continue']) && ($_POST['template'] == 'none')){
621 $this->usertab->by_object['user']->base= $userfilter['depselect'];
622 }
624 /* Show tab dialog if object is present */
625 if ($this->usertab){
626 $display= $this->usertab->execute();
628 /* Don't show buttons if tab dialog requests this */
629 if (!$this->usertab->by_object[$this->usertab->current]->dialog){
630 $display.= "<p style=\"text-align:right\">\n";
631 $display.= "<input type=submit name=\"edit_finish\" value=\""._("Finish")."\">\n";
632 $display.= " \n";
633 $display.= "<input type=submit name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
634 $display.= "</p>";
635 }
636 return ($display);
637 }
639 $smarty= get_smarty();
641 /* Check sorting variable */
642 if (!isset($this->usertab) &&
643 !isset($_POST['new_user']) &&
644 !isset($_POST['new_template']) &&
645 !isset($_POST['delete_user']) &&
646 !isset($_POST['setpass_user']) &&
647 !isset($_POST['select_user'])){
648 $this->reload();
649 }
651 /* Check for exeeded sizelimit */
652 if (($message= check_sizelimit()) != ""){
653 return($message);
654 }
656 /* Prepare departments */
657 $options= "";
658 foreach ($this->config->idepartments as $key => $value){
659 if ($userfilter['depselect'] == $key){
660 $options.= "<option selected value='$key'>$value</option>";
661 } else {
662 $options.= "<option value='$key'>$value</option>";
663 }
664 }
666 /* NEW LIST MANAGMENT */
667 $listhead = "<div style='background:#F0F0F9;padding:5px;'>".
668 " <input type='image' align='middle' src='images/list_back.png' title='"._("Go up one department")."' alt='"._("Up")."' name='dep_back'> ".
669 " <input type='image' src='images/list_root.png' align='middle' title='"._("Go to root department")."' name='dep_root' alt='"._("Root")."'> ".
670 " <input type='image' align='middle' src='images/list_home.png' title='"._("Go to users department")."' alt='"._("Home")."' name='dep_home'> ".
671 " <img src='images/list_seperator.png' align='middle' alt='' height='16' width='1'> ".
672 " <input type='image' align='middle' src='images/list_new_user.png' title='"._("Create new user")."' alt='"._("New user")."' name='user_new'> ".
673 " <input type='image' align='middle' src='images/list_new.png' title='"._("Create new template")."' alt='"._("New template")."' name='user_tplnew'> ".
674 " <img src='images/list_seperator.png' align='middle' alt='' height='16' width='1'> ".
675 _("Current base")." <select name='depselect' onChange='mainform.submit()'>$options</select>".
676 " <input type='image' src='images/list_submit.png' align='middle' title='"._("Submit department")."' name='submit_department' alt='"._("Submit")."'> ".
677 "</div>";
679 $action= "<input type='image' src='images/edit.png' alt='"._("edit")."' name='user_edit_%KEY%' title='"._("Edit user")."'>";
680 $action.= "<input type='image' src='images/list_password.png' alt='"._("password")."' name='user_chgpw_%KEY%' title='"._("Change password")."'>";
681 $action.= "<input type='image' src='images/edittrash.png' alt='"._("delete")."' name='user_del_%KEY%' title='"._("Delete user")."'>";
685 $divlist = new divlist("userstab");
686 $divlist->SetHeader(array(
687 array("string" => " "),
688 array("string" => _("Username")." / "._("Department")),
689 array("string" => _("Properties")),
690 array("string" => _("Actions"), "attach" => "style='border:none'" )));
693 $divlist->SetSummary(_("This table displays all users, in the selected tree."));
694 $divlist->SetEntriesPerPage(0);
696 // Defining Links
697 $linkopen = "<a href='?plug=".$_GET['plug']."&act=dep_open&dep_id=%s'>%s</a>";
699 /* Insert departments in divlist*/
700 foreach($this->departments as $key=> $val){
702 if(!isset($this->config->departments[trim($key)])){
703 $this->config->departments[trim($key)]="";
704 }
706 $non_empty="";
707 $keys= str_replace("/","\/",$key);
708 foreach($this->config->departments as $keyd=>$vald ){
709 if(preg_match("/".$keys."\/.*/",$keyd)){
710 $non_empty="full";
711 }
712 }
714 $field1 = array("string" => "<img src='images/".$non_empty."folder.png' alt='department'>");
715 $field2 = array("string" => sprintf($linkopen,base64_encode($key),$val));
716 $field3 = array("string" => " ");
717 $field4 = array("string" => " ", "attach" => "style='border:none'");
720 $divlist->AddEntry(array($field1,$field2,$field3,$field4));
721 }
723 /* Pictures for Extensions */
724 $usrimg ="<input type='image' src='images/penguin.png' alt='"._("GOsa")."'
725 name='user_edit_%KEY%-user' title='"._("Edit generic properties")."'>";
726 $posiximg = "<input type='image' src='images/select_user.png' alt='"._("Posix")."'
727 name='user_edit_%KEY%-posixAccount' title='"._("Edit UNIX properties")."'>";
728 $eviroimg = "<input type='image' src='images/smallenv.png' alt='"._("Environment")."'
729 name='user_edit_%KEY%-environment' title='"._("Edit environment properties")."'>";
730 $mailimg = "<input type='image' src='images/mailto.png' alt='"._("Mail")."'
731 name='user_edit_%KEY%-mailAccount' title='"._("Edit mail properties")."'>";
732 $fonimg = "<input type='image' src='images/%image%' alt='"._("Phone")."'
733 name='user_edit_%KEY%-phoneAccount' title='"._("Edit phone properties")."%title%'>";
734 $faximg = "<input type='image' src='images/fax_small.png' alt='"._("Fax")."'
735 name='user_edit_%KEY%-gofaxAccount' title='"._("Edit fax properies")."'>";
736 $sambaimg = "<input type='image' src='images/select_winstation.png' alt='"._("Samba")."'
737 name='user_edit_%KEY%-sambaAccount' title='"._("Edit samba properties")."'>";
738 $tplcreateuserimg = "<input type='image' src='images/list_new.png' alt='"._("Create user from template")."'
739 name='userfrom_tpl_%KEY%' title='"._("Create user with this template")."'>";
742 $empty = "<img src='images/empty.png' style='width:16px;height:16px;' alt=''>";
744 // User and Template Images
745 $userimg = "<img src='images/select_user.png' alt='User' title='%s'>";
746 $tplimg = "<img src='images/select_template.png' alt='Template' title='%s'>";
747 $editlink = "<a href='?plug=".$_GET['plug']."&id=%s&act=edit_entry'>%s</a>";
749 // Defines Arrays to save User and Templates
750 $tpls = array();
751 $users= array();
753 /* Get Configuration for goFon DB (if it is set), to connect to the asterisk tables.
754 * Read Sip Table for specified account (for each user with phoneAccount).
755 * Check the attributes ip port and regseconds.
756 * If regseconds is set and >0 , the phone is logged in.
757 * Else the phone is currently not logged.
758 * If we can't read any Data from the DB or there is no goFon DB specified
759 * show old style without status icons.
760 */
761 $r_db =false;
762 $r_con =false;
763 if (isset($_SESSION['config']->data['SERVERS']['FON'])){
764 $a_SETUP= $_SESSION['config']->data['SERVERS']['FON'];
765 // Connect to DB server
767 /*
768 If you want to disable the status pictures, just comment out the next line
769 */
770 $r_con= @mysql_pconnect($a_SETUP['SERVER'],$a_SETUP['LOGIN'],$a_SETUP['PASSWORD']);
771 // Check if we are connected correctly
772 if($r_con){
773 $r_db = @mysql_select_db($a_SETUP['DB'],$r_con);
774 }
775 }
777 // Test Every Entry and generate divlist Array
778 foreach($this->list as $key => $val){
779 $connected = ""; // This string represents timestamp or offline status
780 $ip_port = ""; // String that will represent ip : port of the connected phone
781 if((in_array("goFonAccount" ,$val['objectClass']))){
783 /* Set defaults */
784 $fonac = preg_replace("/%image%/", "select_phone.png", $fonimg);
785 $fonac = preg_replace("/%KEY%/", "$key", $fonac);
786 $fonac = preg_replace("/%title%/", "", $fonac);
788 /* Database connection is ok ?*/
789 if($r_db){
790 $res= @mysql_query("SELECT regseconds,name,port,ipaddr FROM ".$a_SETUP['SIP_TABLE']." WHERE (name='".$val['uid'][0]."')");
791 $mysql_entry = @mysql_fetch_row($res);
792 if(is_array($mysql_entry)){
793 if((isset($mysql_entry[0]))&&($mysql_entry[0]>1)){
794 $connected = " | "._("Online")." : ".gmdate("d.m.Y H:i:s",($mysql_entry[0]+(60*60)));
795 $fonac = preg_replace("/%image%/", "select_phone_connected.png", $fonimg);
796 $fonac = preg_replace("/%KEY%/", "$key", $fonac);
797 $fonac = preg_replace("/%title%/", $connected, $fonac);
798 $ip_port= " - ".$mysql_entry[3].":".$mysql_entry[2];
799 }
800 if((isset($mysql_entry[0]))&&($mysql_entry[0]==0)){
801 $connected = " | "._("Offline");
802 $fonac = preg_replace("/%image%/", "select_phone.png", $fonimg);
803 $fonac = preg_replace("/%KEY%/", "$key", $fonac);
804 $fonac = preg_replace("/%title%/", $connected, $fonac);
805 }
806 }
807 }
808 }else{
809 $fonac=$empty;
810 }
814 // Specify Pics for Extensions
815 if(in_array("posixAccount" ,$val['objectClass'])){
816 $posix = preg_replace("/%KEY%/", "$key", $posiximg);
817 }else{
818 $posix=$empty;
819 }
821 if(in_array("gotoEnvironment" ,$val['objectClass'])){
822 $enviro = preg_replace("/%KEY%/", "$key", $eviroimg);
823 }else{
824 $enviro =$empty;
825 }
827 if(in_array("gosaMailAccount" ,$val['objectClass'])){
828 $maila = preg_replace("/%KEY%/", "$key", $mailimg);
829 }else{
830 $maila=$empty;
831 }
833 if(in_array("goFaxAccount" ,$val['objectClass'])){
834 $faxac = preg_replace("/%KEY%/", "$key", $faximg);
835 }else{
836 $faxac=$empty;
837 }
839 if(in_array("sambaSamAccount" ,$val['objectClass'])){
840 $samba = preg_replace("/%KEY%/", "$key", $sambaimg);
841 }else{
842 $samba=$empty;
843 }
845 if(in_array("gosaUserTemplate",$val['objectClass'])){
846 $tpl = preg_replace("/%KEY%/", "$key", $tplimg);
847 $s_img_create_from_template = preg_replace("/%KEY%/", "$key", $tplcreateuserimg);
848 }else{
849 $s_img_create_from_template = "";
850 $tpl=$userimg;
851 }
853 $usrimg2 = preg_replace("/%KEY%/", "$key", $usrimg);
855 // Generate caption for rows
856 if (isset($val["sn"]) && isset($val["givenName"])){
857 $display= $val["sn"][0].", ".$val["givenName"][0]." [".$val["uid"][0]."]";
858 } else {
859 $display= "[".$val["uid"][0]."]";
860 }
862 /* Create each field */
863 $field1 = array("string" => sprintf($tpl,$val['dn']),"attach"=>"style='width:20px;align:middle;'");
864 $field2 = array("string" => sprintf($editlink,$key,$display).$ip_port,"attach"=>"title='".$val['dn']."'");
865 $field3 = array("string" => $usrimg2." ".$posix." ".$enviro." ".$maila." ".$fonac." ".$faxac." ".$samba." ".$s_img_create_from_template, "attach" => "style='width:155px;'");
866 $field4 = array("string" => preg_replace("/%KEY%/", "$key", $action),"attach" => "style='border:none; text-align:right;width:48px'");
868 $add = array($field1,$field2,$field3,$field4);
870 // Template or User
871 if(in_array("gosaUserTemplate",$val['objectClass'])){
872 $tpls[strtolower( $val['sn']['0'].$val['uid']['0'])]=$add;
873 }else{
874 $users[strtolower( $val['sn']['0'].$val['uid']['0'])]=$add;
875 }
876 }
878 // Sort Entries
879 ksort($users);
880 ksort($tpls);
882 // Append Templates
883 foreach($tpls as $key => $val){
884 $divlist->AddEntry( $val, array(""));
885 }
886 // Append Users
887 foreach($users as $key => $val){
888 $divlist->AddEntry( $val, array(""));
889 }
890 /* Show main page */
891 //$smarty->assign("userlist", nl2br(htmlentities($divlist->DrawList())));
892 $smarty->assign("userlist", $divlist->DrawList());
893 $smarty->assign("userlisthead", $listhead);
895 /* END NEW LIST MANAGMENT
896 */
897 $smarty->assign("search_image", get_template_path('images/search.png'));
898 $smarty->assign("tree_image", get_template_path('images/tree.png'));
899 $smarty->assign("infoimage", get_template_path('images/info.png'));
900 $smarty->assign("launchimage", get_template_path('images/launch.png'));
901 $smarty->assign("deplist", $this->config->idepartments);
902 foreach( array("depselect", "functionalusers", "unixusers",
903 "mailusers", "sambausers", "proxyusers",
904 "faxusers", "templates", "subsearch") as $type){
906 $smarty->assign("$type", $userfilter[$type]);
907 }
909 $smarty->assign("regex", $userfilter["regex"]);
910 /* Extend if we are not using javascript */
911 $smarty->assign("apply", apply_filter());
912 $smarty->assign("alphabet", generate_alphabet());
913 $smarty->assign("hint", print_sizelimit_warning());
915 @mysql_close($r_con);
916 return ($smarty->fetch(get_template_path('headpage.tpl', TRUE)));
917 }
920 function reload()
921 {
922 /* Get config */
923 $userfilter= get_global('userfilter');
925 /* Set base for all searches */
926 $base= $userfilter['depselect'];
928 /* Regex filter? */
929 if ($userfilter['regex'] != ""){
930 $regex= $userfilter['regex'];
931 } else {
932 $regex= "*";
933 }
935 /* Set filter depending on selection */
936 if ($this->config->current['SAMBAVERSION'] == 3){
937 $samba= "sambaSamAccount";
938 } else {
939 $samba= "sambaAccount";
940 }
942 $filter="";
943 if ($userfilter['functionalusers'] == "checked"){
944 $filter.= "(&(objectClass=gosaAccount)(!(|(objectClass=posixAccount)(objectClass=gosaMailAccount)(objectClass=$samba)(objectClass=goFaxAccount)(objectClass=gosaProxyAccount))))";
945 }
946 if ($userfilter['unixusers'] == "checked"){
947 $filter.= "(objectClass=posixAccount)";
948 }
949 if ($userfilter['mailusers'] == "checked"){
950 $filter.= "(objectClass=gosaMailAccount)";
951 }
952 if ($userfilter['sambausers'] == "checked"){
953 $filter.= "(objectClass=$samba)";
954 }
955 if ($userfilter['proxyusers'] == "checked"){
956 $filter.= "(objectClass=gosaProxyAccount)";
957 }
958 if ($userfilter['faxusers'] == "checked"){
959 $filter.= "(objectClass=goFaxAccount)";
960 }
962 if ($userfilter['templates'] == "checked"){
963 $filter= "(|(objectClass=gosaUserTemplate)(&(objectClass=gosaAccount)(|$filter)))";
964 } else {
965 $filter= "(&(objectClass=gosaAccount)(!(objectClass=gosaUserTemplate))(|$filter))";
966 }
967 $filter= "(&(|(uid=$regex)(sn=$regex)(givenName=$regex))$filter)";
969 /* Generate userlist */
970 $ldap= $this->config->get_ldap_link(TRUE);
971 if ($userfilter['subsearch'] == "checked"){
972 $this->list= get_list($this->ui->subtreeACL, "$filter", TRUE, $base, array("uid", "givenName", "sn", "objectClass"), TRUE);
973 } else {
974 $base= get_people_ou().$base;
975 $this->list= get_list($this->ui->subtreeACL, "$filter", FALSE, $base, array("uid", "givenName", "sn", "objectClass"), TRUE);
976 }
980 /* NEW LIST MANAGMENT
981 * We also need to search for the departments
982 * So we are able to navigate like in konquerer
983 */
984 $base2 = preg_replace("/ou=people,/i","",$base);
986 $res3 = get_list2($this->ui->subtreeACL, "(&(|(ou=$regex)(description=$regex))(objectClass=gosaDepartment))",
987 TRUE, $base2, array("ou", "description"), TRUE);
989 $this->departments= array();
991 $tmp = array();
992 foreach ($res3 as $value){
993 $tmp[strtolower($value['dn']).$value['dn']]=$value;
994 }
995 ksort($tmp);
996 foreach($tmp as $value){
997 if($value["description"][0]!=".."){
998 $this->departments[$value['dn']]=convert_department_dn2($value['dn'])." - [".$value["description"][0]."]";
999 }else{
1000 $this->departments[$value['dn']]=$value["description"][0];
1001 }
1002 }
1003 /* END NEW LIST MANAGMENT
1004 */
1007 $this->userlist= array();
1009 foreach ($this->list as $value){
1010 if (isset($value["uid"][0]) && !preg_match('/\$$/', $value["uid"][0])){
1011 if (in_array_ics('gosaUserTemplate', $value['objectClass'])){
1012 $this->userlist[$value["dn"]]= "* ".$value["uid"][0]." ("._("Template").")";
1013 continue;
1014 }
1015 if (isset($value["givenName"][0]) && isset($value["sn"][0])){
1016 $this->userlist[$value["dn"]]= $value["sn"][0].", ".
1017 $value["givenName"][0].
1018 " [".$value["uid"][0]."]";
1019 } else {
1020 $this->userlist[$value["dn"]]= "[".$value["uid"][0]."]";
1021 }
1022 }
1023 }
1025 natcasesort ($this->userlist);
1026 reset ($this->userlist);
1027 }
1029 function remove_from_parent()
1030 {
1031 }
1034 /* Check values */
1035 function check()
1036 {
1037 }
1040 /* Save to LDAP */
1041 function save()
1042 {
1043 }
1045 function adapt_from_template($dn)
1046 {
1047 }
1049 function password_change_needed()
1050 {
1051 }
1053 function show_header($button_text, $text, $disabled= FALSE)
1054 {
1055 }
1057 function remove_lock()
1058 {
1059 if (isset($this->usertab->dn)){
1060 del_lock ($this->usertab->dn);
1061 }
1062 }
1064 }
1066 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1067 ?>