ec1d42213d0086d2d2740b5e22acc5278c92555c
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 }
75 /* Test Posts */
76 foreach($_POST as $key => $val){
77 // Post for delete
78 if(preg_match("/user_del.*/",$key)){
79 $s_action = "del";
80 $s_entry = preg_replace("/user_".$s_action."_/i","",$key);
81 // Post for edit
82 }elseif(preg_match("/user_edit_.*/",$key)){
83 $s_action="edit";
84 $s_entry = preg_replace("/user_".$s_action."_/i","",$key);
85 // Post for new
86 }elseif(preg_match("/dep_back.*/i",$key)){
87 $s_action="back";
88 }elseif(preg_match("/user_new.*/",$key)){
89 $s_action="new";
90 }elseif(preg_match("/dep_home.*/i",$key)){
91 $s_action="home";
92 }elseif(preg_match("/user_tplnew.*/i",$key)){
93 $s_action="new_tpl";
94 }elseif(preg_match("/user_chgpw.*/i",$key)){
95 $s_action="change_pw";
96 $s_entry = preg_replace("/user_chgpw_/i","",$key);
97 }elseif(preg_match("/dep_root.*/i",$key)){
98 $s_action="root";
99 }
100 }
102 if((isset($_GET['act']))&&($_GET['act']=="edit_entry")){
103 $s_action ="edit";
104 $s_entry = $_GET['id'];
105 }
107 $s_entry = preg_replace("/_.$/","",$s_entry);
108 if(preg_match("/.*-.*/",$s_entry)){
109 $s_tab = preg_replace("/^.*-/i","",$s_entry);
110 $s_entry = preg_replace("/-.*$/i","",$s_entry);
111 }else{
112 $s_tab = "user";
113 };
115 /* Department changed? */
116 if(isset($_POST['depselect']) && $_POST['depselect']){
117 $userfilter['depselect']= $_POST['depselect'];
118 }
120 /* Homebutton is posted */
121 if($s_action=="home"){
122 $userfilter['depselect']=(preg_replace("/^[^,]+,/","",$this->ui->dn));
123 $userfilter['depselect']=(preg_replace("/^[^,]+,/","",$userfilter['depselect']));
124 }
126 if($s_action=="root"){
127 $userfilter['depselect']=($this->config->current['BASE']);
128 }
131 /* If Backbutton is Posted */
132 if($s_action=="back"){
133 $base_back = preg_replace("/^[^,]+,/","",$userfilter['depselect']);
134 $base_back = convert_department_dn($base_back);
136 if(isset($this->config->departments[trim($base_back)])){
137 $userfilter['depselect']= $this->config->departments[trim($base_back)];
138 }else{
139 $userfilter['depselect']= $this->config->departments["/"];
140 }
141 }
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 // $_POST[$s_tab]=$s_tab;
197 // This would be better
198 $this->usertab->current = $s_tab;
199 $this->usertab->set_acl($acl);
201 $_SESSION['objectinfo']= $this->dn;
202 }
203 }
205 /* Reset requested? */
206 if (isset($_POST['edit_cancel']) || isset($_POST['password_cancel'])){
207 if (isset($this->usertab)){
208 del_lock ($this->usertab->dn);
209 unset ($this->usertab);
210 }
211 $this->usertab= NULL;
212 $this->lognames= array();;
213 $this->sn= "";
214 $this->givenName= "";
215 $this->uid= "";
216 unset ($_SESSION['objectinfo']);
217 }
219 /* Password change requested */
220 if ($s_action=="change_pw"){
222 /* Get 'dn' from posted 'uid' */
223 $this->dn= $this->list[trim($s_entry)]['dn'];
225 /* Load permissions for selected 'dn' and check if
226 we're allowed to remove this 'dn' */
227 $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
228 $acl= get_module_permission($acl, "user", $this->dn);
229 if (chkacl($acl, "password") == ""){
231 /* User is allowed to change passwords, save 'dn' and 'acl' for next
232 dialog. */
233 $this->acl= $acl;
234 $_SESSION['objectinfo']= $this->dn;
235 return ($smarty->fetch(get_template_path('password.tpl', TRUE)));
237 } else {
238 /* User is not allowed. Show message and cancel. */
239 print_red (_("You are not allowed to set this users password!"));
240 }
241 }
243 /* Perform password change */
244 if (isset($_POST['password_finish'])){
246 /* For security reasons, check if user is allowed to set password again */
247 if (chkacl($this->acl, "password") == "" || chkacl($this->acl, "create")){
249 /* Check input and feed errors into 'message' */
250 $message= array();
252 /* Sanity checks... */
253 if ($_POST['new_password'] != $_POST['repeated_password']){
255 /* Matching passwords in new and repeated? */
256 $message[]= _("The passwords you've entered as 'New password' and 'Repeated new password' do not match.");
257 } else {
259 /* Empty password is not permitted by default. */
260 if ($_POST['new_password'] == ""){
261 $message[]= _("The password you've entered as 'New password' is empty.");
262 }
263 }
265 /* Errors, or change password? */
266 if (count($message) != 0){
268 /* Show error message and continue editing */
269 show_errors ($message);
270 return($smarty->fetch(get_template_path('password.tpl', TRUE)));
271 }
273 /* Set password, perform required steps */
274 if ($this->usertab){
275 if ($this->usertab->password_change_needed()){
276 $obj= $this->usertab->by_object['user'];
277 change_password ($this->usertab->dn, $_POST['new_password'],
278 0, $obj->pw_storage);
279 gosa_log ("Password for '".$this->usertab->dn."' has been changed");
280 unset($this->usertab);
281 $this->usertab= NULL;
282 }
283 } else {
284 change_password ($this->dn, $_POST['new_password']);
285 gosa_log ("Password for '".$this->dn."' has been changed");
286 }
287 } else {
289 /* Missing permissions, show message */
290 print_red (_("You are not allowed to set this users password!"));
291 }
293 /* Clean session, delete lock */
294 del_lock ($this->dn);
295 $this->reload();
296 unset ($this->usertab);
297 $this->usertab= NULL;
298 $this->lognames= array();;
299 $this->sn= "";
300 $this->givenName= "";
301 $this->uid= "";
302 unset ($_SESSION['objectinfo']);
303 }
306 /* Remove user was requested */
307 if ($s_action=="del"){
309 /* Get 'dn' from posted 'uid' */
310 $this->dn= $this->list[trim($s_entry)]['dn'];
312 /* Load permissions for selected 'dn' and check if
313 we're allowed to remove this 'dn' */
314 $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
315 $this->acl= get_module_permission($acl, "user", $this->dn);
316 if (chkacl($this->acl, "delete") == ""){
318 /* Check locking, save current plugin in 'back_plugin', so
319 the dialog knows where to return. */
320 if (($user= get_lock($this->dn)) != ""){
321 return(gen_locked_message ($user, $this->dn));
322 }
324 /* Lock the current entry, so nobody will edit it during deletion */
325 add_lock ($this->dn, $this->ui->dn);
326 $smarty->assign("info", sprintf(_("You're about to delete the user %s."), $this->dn));
327 return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
328 } else {
330 /* Obviously the user isn't allowed to delete. Show message and
331 clean session. */
332 print_red (_("You are not allowed to delete this user!"));
333 }
334 }
338 /* Confirmation for deletion has been passed. User should be deleted. */
339 if (isset($_POST['delete_user_confirm'])){
341 /* Some nice guy may send this as POST, so we've to check
342 for the permissions again. */
343 if (chkacl($this->acl, "delete") == ""){
345 /* Delete request is permitted, perform LDAP action */
346 $this->usertab= new usertabs($this->config, $this->config->data['TABS']['USERTABS'],
347 $this->dn);
348 $this->usertab->set_acl(array($this->acl));
349 $this->usertab->delete ();
350 gosa_log ("User object '".$this->dn."' has been removed");
351 unset ($this->usertab);
352 $this->usertab= NULL;
354 /* User list has changed, reload it. */
355 $this->reload ();
356 } else {
358 /* Normally this shouldn't be reached, send some extra
359 logs to notify the administrator */
360 print_red (_("You are not allowed to delete this user!"));
362 if(isset($this->ui->uid)){
363 gosa_log ("Warning: '".$this->ui->uid."' tried to trick user deletion.");
364 }
365 }
367 /* Remove lock file after successfull deletion */
368 del_lock ($this->dn);
369 }
372 /* Delete user canceled? */
373 if (isset($_POST['delete_cancel'])){
374 del_lock ($this->dn);
375 }
378 /* Finish user edit is triggered by the tabulator dialog, so
379 the user wants to save edited data. Check and save at this
380 point. */
381 if (isset($_POST['edit_finish'])){
383 /* Check tabs, will feed message array */
384 $this->usertab->last= $this->usertab->current;
385 $this->usertab->save_object();
386 $message= $this->usertab->check();
388 /* Save, or display error message? */
389 if (count($message) == 0){
391 /* No errors. Go ahead and prepare to ask for a password
392 in case we're creating a new user. 'dn' will be 'new'
393 in this case. It is set to the correct value later. */
394 if ($this->dn == "new"){
395 $set_pass= 1;
396 } else {
397 $set_pass= 0;
398 }
400 /* Save user data to ldap */
401 if($this->usertab->save() == 1){
402 gosa_log ("User object '".$this->dn."' saving failed.");
403 return;
404 }
405 gosa_log ("User object '".$this->dn."' has been saved");
407 /* User has been saved successfully, remove lock from
408 LDAP. */
409 if ($this->dn != "new"){
410 del_lock ($this->dn);
411 }
413 /* In case of new users, ask for a password */
414 if (($set_pass || $this->usertab->password_change_needed()) &&
415 !$this->is_template){
417 return($smarty->fetch(get_template_path('password.tpl', TRUE)));
418 }
420 /* There's no page reload so we have to read new users at
421 this point. */
422 $this->reload ();
423 unset ($this->usertab);
424 $this->usertab= NULL;
425 unset ($_SESSION['objectinfo']);
427 } else {
428 /* Ok. There seem to be errors regarding to the tab data,
429 show message and continue as usual. */
430 show_errors($message);
431 }
432 }
434 /* Generate template list */
435 if ($s_action=="new"){
436 $this->templates= array();
437 $ldap= $this->config->get_ldap_link();
438 foreach ($this->config->departments as $key => $value){
439 $acl= get_permissions (get_people_ou().$value, $this->ui->subtreeACL);
440 $acl= get_module_permission($acl, "user", get_people_ou().$value);
441 if (chkacl($acl, "create") == ""){
442 $ldap->cd (get_people_ou().$value);
443 $ldap->search ("(objectClass=gosaUserTemplate)", array("uid"));
445 if ($ldap->count() != 0){
446 while ($attrs= $ldap->fetch()){
447 $this->templates[$ldap->getDN()]=
448 $attrs['uid'][0]." - $key";
449 }
450 $this->templates['none']= _("none");
451 }
452 }
453 }
454 natcasesort ($this->templates);
455 reset ($this->templates);
456 }
458 /* New user/template request */
459 if (($s_action=="new") || ($s_action=="new_tpl")){
460 /* By default we set 'dn' to 'new', all relevant plugins will
461 react on this. */
462 $this->dn= "new";
463 if (isset($this->config->current['IDGEN'])){
464 $this->got_uid= false;
465 } else {
466 $this->got_uid= true;
467 }
469 /* Create new usertab object */
470 $this->usertab= new usertabs($this->config,
471 $this->config->data['TABS']['USERTABS'], $this->dn);
472 $this->usertab->set_acl(array(':all'));
474 /* Take care about templates */
475 if ($s_action=="new_tpl"){
476 $this->is_template= TRUE;
477 $this->usertab->set_template_mode ();
478 } else {
479 $this->is_template= FALSE;
480 }
482 /* Use template if there are any of them */
483 if (count($this->templates) && !isset($_POST['new_template'])){
484 foreach(array("sn", "givenName", "uid", "got_uid", "templates") as $attr){
485 $smarty->assign("$attr", $this->$attr);
486 }
487 if (isset($_POST['template'])){
488 $smarty->assign("template", $_POST['template']);
489 } else {
490 $smarty->assign("template", "");
491 }
492 $smarty->assign("edit_uid", "");
493 return($smarty->fetch(get_template_path('template.tpl', TRUE)));
494 }
495 }
497 /* Continue template editing */
498 if (isset($_POST['template_continue']) && $_POST['template'] != 'none' && !isset($_POST['uid'])){
499 $this->sn= $_POST['sn'];
500 $this->givenName= $_POST['givenName'];
502 /* Check for requred values */
503 $message= array();
504 if ($this->sn == "") {
505 $message[]= _("The required field 'Name' is not set.");
506 }
507 if ($this->givenName == "") {
508 $message[]= _("The required field 'Given name' is not set.");
509 }
511 /* Check if dn is used */
512 $dn= preg_replace("/^[^,]+,/i", "", $_POST['template']);
513 $ldap= $this->config->get_ldap_link();
514 $ldap->cd ($dn);
515 $ldap->search ("(&(sn=".$this->sn.")(givenName=".$this->givenName."))", array("givenName"));
516 if ($ldap->count () != 0){
517 $message[]= _("A person with the choosen name is already used in this tree.");
518 }
520 /* Show error message / continue editing */
521 if (count($message) > 0){
522 show_errors ($message);
523 } else {
524 $attributes= array('sn' => $this->sn, 'givenName' => $this->givenName);
525 if (isset($this->config->current['IDGEN']) &&
526 $this->config->current['IDGEN'] != ""){
527 $uids= gen_uids ($this->config->current['IDGEN'], $attributes);
528 if (count($uids)){
529 $smarty->assign("edit_uid", "false");
530 $smarty->assign("uids", $uids);
531 $this->uid= current($uids);
532 }
533 } else {
534 $smarty->assign("edit_uid", "");
535 $this->uid= "";
536 }
537 $this->got_uid= true;
538 }
540 foreach(array("sn", "givenName", "uid", "got_uid", "templates") as $attr){
541 $smarty->assign("$attr", $this->$attr);
542 }
543 if (isset($_POST['template'])){
544 $smarty->assign("template", $_POST['template']);
545 }
546 return($smarty->fetch(get_template_path('template.tpl', TRUE)));
547 }
549 /* No template. Ok. Lets fill data into the normal user dialog */
550 if (isset($_POST['template_continue']) && $_POST['template'] == 'none'){
551 foreach(array("sn", "givenName", "uid") as $attr){
552 if (isset($_POST[$attr])){
553 $this->usertab->by_object['user']->$attr= $_POST[$attr];
554 }
555 }
556 }
558 /* Finish template preamble */
559 if (isset($_POST['template_continue']) && $_POST['template'] != 'none' && (isset($_POST['uid']))){
561 /* Might not be filled if IDGEN is unset */
562 $this->sn= $_POST['sn'];
563 $this->givenName= $_POST['givenName'];
565 /* Move user supplied data to sub plugins */
566 $this->uid= $_POST['uid'];
567 $this->usertab->uid= $this->uid;
568 $this->usertab->sn= $this->sn;
569 $this->usertab->givenName= $this->givenName;
570 $template_dn= $_POST['template'];
571 $this->usertab->adapt_from_template($template_dn);
572 $template_base= $userfilter['depselect'];//preg_replace("/^[^,]+,".get_people_ou()."/", '', $template_dn);
573 $this->usertab->by_object['user']->base= $template_base;
575 /* Set up the users ACL's for this 'dn' */
576 $acl= get_permissions ($template_base, $this->ui->subtreeACL);
577 $this->usertab->set_acl($acl);
578 }
580 /* Show tab dialog if object is present */
581 if ($this->usertab){
582 $display= $this->usertab->execute();
584 /* Don't show buttons if tab dialog requests this */
585 if (!$this->usertab->by_object[$this->usertab->current]->dialog){
586 $display.= "<p style=\"text-align:right\">\n";
587 $display.= "<input type=submit name=\"edit_finish\" value=\""._("Finish")."\">\n";
588 $display.= " \n";
589 $display.= "<input type=submit name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
590 $display.= "</p>";
591 }
592 return ($display);
593 }
595 $smarty= get_smarty();
597 /* Check sorting variable */
598 if (!isset($this->usertab) &&
599 !isset($_POST['new_user']) &&
600 !isset($_POST['new_template']) &&
601 !isset($_POST['delete_user']) &&
602 !isset($_POST['setpass_user']) &&
603 !isset($_POST['select_user'])){
604 $this->reload();
605 }
607 /* Check for exeeded sizelimit */
608 if (($message= check_sizelimit()) != ""){
609 return($message);
610 }
612 /* Prepare departments */
613 $options= "";
614 foreach ($this->config->idepartments as $key => $value){
615 if ($userfilter['depselect'] == $key){
616 $options.= "<option selected value='$key'>$value</option>";
617 } else {
618 $options.= "<option value='$key'>$value</option>";
619 }
620 }
622 /* NEW LIST MANAGMENT */
623 $listhead = "<div style='background:#F0F0F9;padding:5px;'>".
624 " <input type='image' align='middle' src='images/list_back.png' title='"._("Go up one department")."' alt='"._("Up")."' name='dep_back'> ".
625 " <input type='image' src='images/list_root.png' align='middle' title='"._("Go to root department")."' name='dep_root' alt='"._("Root")."'> ".
626 " <input type='image' align='middle' src='images/list_home.png' title='"._("Go to users department")."' alt='"._("Home")."' name='dep_home'> ".
627 " <img src='images/list_seperator.png' align='middle' alt='' height='16' width='1'> ".
628 " <input type='image' align='middle' src='images/list_new_user.png' title='"._("Create new user")."' alt='"._("New user")."' name='user_new'> ".
629 " <input type='image' align='middle' src='images/list_new.png' title='"._("Create new template")."' alt='"._("New template")."' name='user_tplnew'> ".
630 " <img src='images/list_seperator.png' align='middle' alt='' height='16' width='1'> ".
631 _("Current base")." <select name='depselect' onChange='mainform.submit()'>$options</select>".
632 " <input type='image' src='images/list_submit.png' align='middle' title='"._("Submit department")."' name='submit_department' alt='"._("Submit")."'> ".
633 "</div>";
635 $action= "<input type='image' src='images/edit.png' alt='"._("edit")."' name='user_edit_%KEY%' title='"._("Edit user")."'>";
636 $action.= "<input type='image' src='images/list_password.png' alt='"._("password")."' name='user_chgpw_%KEY%' title='"._("Change password")."'>";
637 $action.= "<input type='image' src='images/editdelete.png' alt='"._("delete")."' name='user_del_%KEY%' title='"._("Delete user")."'>";
641 $divlist = new divlist("userstab");
642 $divlist->SetHeader(array(
643 array("string" => " "),
644 array("string" => _("Username")." / "._("Department")),
645 array("string" => _("Properties")),
646 array("string" => _("Actions"), "attach" => "style='border:none'" )));
649 $divlist->SetSummary(_("This table displays all users, in the selected tree."));
650 $divlist->SetEntriesPerPage(20);
652 // Defining Links
653 $linkopen = "<a href='?plug=".$_GET['plug']."&act=dep_open&dep_id=%s'>%s</a>";
655 foreach($this->departments as $key=> $val){
657 if(!isset($this->config->departments[trim($key)])){
658 $this->config->departments[trim($key)]="";
659 }
661 $non_empty="";
662 $keys= str_replace("/","\/",$key);
663 foreach($this->config->departments as $keyd=>$vald ){
664 if(preg_match("/".$keys."\/.*/",$keyd)){
665 $non_empty="full";
666 }
667 }
672 $field1 = array("string" => "<img src='images/".$non_empty."folder.png' alt='department'>");
673 $field2 = array("string" => sprintf($linkopen,base64_encode($key),$val));
674 $field3 = array("string" => " ");
675 $field4 = array("string" => " ", "attach" => "style='border:none'");
678 $divlist->AddEntry(array($field1,$field2,$field3,$field4));
679 }
681 // Pictures for Extensions
682 $usrimg ="<input type='image' src='images/penguin.png' alt='"._("GOsa")."' name='user_edit_%KEY%-user' title='"._("Edit generic properties")."'>";
683 $posiximg = "<input type='image' src='images/select_user.png' alt='"._("Posix")."' name='user_edit_%KEY%-posixAccount' title='"._("Edit UNIX properties")."'>";
684 $mailimg = "<input type='image' src='images/mailto.png' alt='"._("Mail")."' name='user_edit_%KEY%-mailAccount' title='"._("Edit mail properties")."'>";
685 $fonimg = "<input type='image' src='images/%image%' alt='"._("Phone")."' name='user_edit_%KEY%-phoneAccount' title='"._("Edit phone properties")."%title%'>";
686 $faximg = "<input type='image' src='images/fax_small.png' alt='"._("Fax")."' name='user_edit_%KEY%-gofaxAccount' title='"._("Edit fax properies")."'>";
687 $sambaimg = "<input type='image' src='images/select_winstation.png' alt='"._("Samba")."' name='user_edit_%KEY%-sambaAccount' title='"._("Edit samba properties")."'>";
688 $empty = "<img src='images/empty.png' style='width:16px;height:16px;' alt=''>";
690 // User and Template Images
691 $userimg = "<img src='images/select_user.png' alt='User' title='%s'>";
692 $tplimg = "<img src='images/select_template.png' alt='Template' title='%s'>";
694 $editlink = "<a href='?plug=".$_GET['plug']."&id=%s&act=edit_entry'>%s</a>";
696 // Defines Arrays to save User and Templates
697 $tpls = array();
698 $users= array();
700 // Get Configuration
701 $a_SETUP = $_SESSION['config']->data['SERVERS']['FON'];
702 // Connect to DB server
703 $r_con = @mysql_connect($a_SETUP['SERVER'],$a_SETUP['LOGIN'],$a_SETUP['PASSWORD']);
704 // Check if we are connected correctly
705 $r_db=false;
706 if($r_con){
707 $r_db = @mysql_select_db($a_SETUP['DB'],$r_con);
708 }
710 // Test Every Entry and generate divlist Array
711 foreach($this->list as $key => $val){
712 $connected = "";
713 $ip_port= "";
714 if((in_array("goFonAccount" ,$val['objectClass']))){
715 $fonac = preg_replace("/%image%/", "select_phone.png", $fonimg);
716 $fonac = preg_replace("/%KEY%/", "$key", $fonac);
717 $fonac = preg_replace("/%title%/", "", $fonac);
719 if($r_db){
720 $res= @mysql_query("SELECT regseconds,name,port,ipaddr FROM ".$a_SETUP['SIP_TABLE']." WHERE (name='".$val['uid'][0]."')");
721 $mysql_entry = @mysql_fetch_row($res);
722 if(is_array($mysql_entry)){
723 if((isset($mysql_entry[0]))&&($mysql_entry[0]>1)){
724 $connected = " | "._("Online")." : ".gmdate("d.m.Y H:i:s",($mysql_entry[0]+(60*60)));
725 $fonac = preg_replace("/%image%/", "select_phone_connected.png", $fonimg);
726 $fonac = preg_replace("/%KEY%/", "$key", $fonac);
727 $fonac = preg_replace("/%title%/", $connected, $fonac);
728 $ip_port= " - ".$mysql_entry[3].":".$mysql_entry[2];
729 }
730 if((isset($mysql_entry[0]))&&($mysql_entry[0]==0)){
731 $connected = " | "._("Offline");
732 $fonac = preg_replace("/%image%/", "select_phone_notconnected.png", $fonimg);
733 $fonac = preg_replace("/%KEY%/", "$key", $fonac);
734 $fonac = preg_replace("/%title%/", $connected, $fonac);
735 }
736 }
737 }
738 }else{
739 $fonac=$empty;
740 }
742 // Specify Pics for Extensions
743 if(in_array("posixAccount" ,$val['objectClass'])) $posix = preg_replace("/%KEY%/", "$key", $posiximg); else $posix=$empty;
744 if(in_array("gosaMailAccount" ,$val['objectClass'])) $maila = preg_replace("/%KEY%/", "$key", $mailimg); else $maila=$empty;
745 if(in_array("goFaxAccount" ,$val['objectClass'])) $faxac = preg_replace("/%KEY%/", "$key", $faximg); else $faxac=$empty;
746 if(in_array("sambaSamAccount" ,$val['objectClass'])) $samba = preg_replace("/%KEY%/", "$key", $sambaimg); else $samba=$empty;
747 if(in_array("gosaUserTemplate",$val['objectClass'])) $tpl = preg_replace("/%KEY%/", "$key", $tplimg); else $tpl=$userimg;
749 $usrimg = preg_replace("/%KEY%/", "$key", $usrimg);
751 // Generate Array to Add
752 if (isset($val["sn"]) && isset($val["givenName"])){
753 $display= $val["sn"][0].", ".$val["givenName"][0]." [".$val["uid"][0]."]";
754 } else {
755 $display= "[".$val["uid"][0]."]";
756 }
758 $field1 = array("string" => sprintf($tpl,$val['dn']),"attach"=>"style='width:20px;align:middle;'");
759 $field2 = array("string" => sprintf($editlink,$key,$display).$ip_port,"attach"=>"title='".$val['dn']."'");
760 $field3 = array("string" => $usrimg." ".$posix." ".$maila." ".$fonac." ".$faxac." ".$samba,"attach" => "style='width:118px;'");
761 $field4 = array("string" => preg_replace("/%KEY%/", "$key", $action),"attach" => "style='border:none; text-align:right;width:48px'");
763 $add = array($field1,$field2,$field3,$field4);
765 // Template or User
766 if(in_array("gosaUserTemplate",$val['objectClass'])){
767 $tpls[strtolower( $val['sn']['0'].$val['uid']['0'])]=$add;
768 }else{
769 $users[strtolower( $val['sn']['0'].$val['uid']['0'])]=$add;
770 }
771 }
773 // Sort Entries
774 ksort($users);
775 ksort($tpls);
777 // Append Templates
778 foreach($tpls as $key => $val){
779 $divlist->AddEntry( $val, array(""));
780 }
781 // Append Users
782 foreach($users as $key => $val){
783 $divlist->AddEntry( $val, array(""));
784 }
785 /* Show main page */
786 //$smarty->assign("userlist", nl2br(htmlentities($divlist->DrawList())));
787 $smarty->assign("userlist", $divlist->DrawList());
788 $smarty->assign("userlisthead", $listhead);
790 /* END NEW LIST MANAGMENT
791 */
792 $smarty->assign("search_image", get_template_path('images/search.png'));
793 $smarty->assign("tree_image", get_template_path('images/tree.png'));
794 $smarty->assign("infoimage", get_template_path('images/info.png'));
795 $smarty->assign("launchimage", get_template_path('images/launch.png'));
796 $smarty->assign("deplist", $this->config->idepartments);
797 foreach( array("depselect", "functionalusers", "unixusers",
798 "mailusers", "sambausers", "proxyusers",
799 "faxusers", "templates", "subsearch") as $type){
801 $smarty->assign("$type", $userfilter[$type]);
802 }
804 $smarty->assign("regex", $userfilter["regex"]);
805 /* Extend if we are not using javascript */
806 $smarty->assign("apply", apply_filter());
807 $smarty->assign("alphabet", generate_alphabet());
808 $smarty->assign("hint", print_sizelimit_warning());
810 return ($smarty->fetch(get_template_path('headpage.tpl', TRUE)));
811 }
814 function reload()
815 {
816 /* Get config */
817 $userfilter= get_global('userfilter');
819 /* Set base for all searches */
820 $base= $userfilter['depselect'];
822 /* Regex filter? */
823 if ($userfilter['regex'] != ""){
824 $regex= $userfilter['regex'];
825 } else {
826 $regex= "*";
827 }
829 /* Set filter depending on selection */
830 if ($this->config->current['SAMBAVERSION'] == 3){
831 $samba= "sambaSamAccount";
832 } else {
833 $samba= "sambaAccount";
834 }
836 $filter="";
837 if ($userfilter['functionalusers'] == "checked"){
838 $filter.= "(&(objectClass=gosaAccount)(!(|(objectClass=posixAccount)(objectClass=gosaMailAccount)(objectClass=$samba)(objectClass=goFaxAccount)(objectClass=gosaProxyAccount))))";
839 }
840 if ($userfilter['unixusers'] == "checked"){
841 $filter.= "(objectClass=posixAccount)";
842 }
843 if ($userfilter['mailusers'] == "checked"){
844 $filter.= "(objectClass=gosaMailAccount)";
845 }
846 if ($userfilter['sambausers'] == "checked"){
847 $filter.= "(objectClass=$samba)";
848 }
849 if ($userfilter['proxyusers'] == "checked"){
850 $filter.= "(objectClass=gosaProxyAccount)";
851 }
852 if ($userfilter['faxusers'] == "checked"){
853 $filter.= "(objectClass=goFaxAccount)";
854 }
856 if ($userfilter['templates'] == "checked"){
857 $filter= "(|(objectClass=gosaUserTemplate)(&(objectClass=gosaAccount)(|$filter)))";
858 } else {
859 $filter= "(&(objectClass=gosaAccount)(!(objectClass=gosaUserTemplate))(|$filter))";
860 }
861 $filter= "(&(|(uid=$regex)(sn=$regex)(givenName=$regex))$filter)";
863 /* Generate userlist */
864 $ldap= $this->config->get_ldap_link(TRUE);
865 if ($userfilter['subsearch'] == "checked"){
866 $this->list= get_list($this->ui->subtreeACL, "$filter", TRUE, $base, array("uid", "givenName", "sn", "objectClass"), TRUE);
867 } else {
868 $base= get_people_ou().$base;
869 $this->list= get_list($this->ui->subtreeACL, "$filter", FALSE, $base, array("uid", "givenName", "sn", "objectClass"), TRUE);
870 }
874 /* NEW LIST MANAGMENT
875 * We also need to search for the departments
876 * So we are able to navigate like in konquerer
877 */
878 $base2 = preg_replace("/ou=people,/i","",$base);
880 $res3 = get_list2($this->ui->subtreeACL, "(&(|(ou=$regex)(description=$regex))(objectClass=gosaDepartment))",
881 TRUE, $base2, array("ou", "description"), TRUE);
883 $this->departments= array();
885 $tmp = array();
886 foreach ($res3 as $value){
887 $tmp[strtolower($value['dn']).$value['dn']]=$value;
888 }
889 ksort($tmp);
890 foreach($tmp as $value){
891 if($value["description"][0]!=".."){
892 $this->departments[$value['dn']]=convert_department_dn2($value['dn'])." - [".$value["description"][0]."]";
893 }else{
894 $this->departments[$value['dn']]=$value["description"][0];
895 }
896 }
897 /* END NEW LIST MANAGMENT
898 */
901 $this->userlist= array();
903 foreach ($this->list as $value){
904 if (isset($value["uid"][0]) && !preg_match('/\$$/', $value["uid"][0])){
905 if (in_array_ics('gosaUserTemplate', $value['objectClass'])){
906 $this->userlist[$value["dn"]]= "* ".$value["uid"][0]." ("._("Template").")";
907 continue;
908 }
909 if (isset($value["givenName"][0]) && isset($value["sn"][0])){
910 $this->userlist[$value["dn"]]= $value["sn"][0].", ".
911 $value["givenName"][0].
912 " [".$value["uid"][0]."]";
913 } else {
914 $this->userlist[$value["dn"]]= "[".$value["uid"][0]."]";
915 }
916 }
917 }
919 natcasesort ($this->userlist);
920 reset ($this->userlist);
921 }
923 function remove_from_parent()
924 {
925 }
928 /* Check values */
929 function check()
930 {
931 }
934 /* Save to LDAP */
935 function save()
936 {
937 }
939 function adapt_from_template($dn)
940 {
941 }
943 function password_change_needed()
944 {
945 }
947 function show_header($button_text, $text, $disabled= FALSE)
948 {
949 }
951 function remove_lock()
952 {
953 if (isset($this->usertab->dn)){
954 del_lock ($this->usertab->dn);
955 }
956 }
958 }
960 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
961 ?>