6c3c8cebf8f9d51da5cec7299d94e7bbfe92a3d2
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 }elseif(preg_match("/userfrom_tpl.*/i",$key)){
100 $s_action="create_user_from_tpl";
101 $s_entry = preg_replace("/userfrom_tpl_/i","",$key);
102 }
103 }
105 if((isset($_GET['act']))&&($_GET['act']=="edit_entry")){
106 $s_action = "edit";
107 $s_entry = $_GET['id'];
108 }
110 $s_entry = preg_replace("/_.$/","",$s_entry);
112 if(preg_match("/.*-.*/",$s_entry)){
113 $s_tab = preg_replace("/^.*-/i","",$s_entry);
114 $s_entry = preg_replace("/-.*$/i","",$s_entry);
115 }else{
116 $s_tab = "user";
117 };
119 /* Department changed? */
120 if(isset($_POST['depselect']) && $_POST['depselect']){
121 $userfilter['depselect']= $_POST['depselect'];
122 }
124 /* Homebutton is posted */
125 if($s_action=="home"){
126 $userfilter['depselect']=(preg_replace("/^[^,]+,/","",$this->ui->dn));
127 $userfilter['depselect']=(preg_replace("/^[^,]+,/","",$userfilter['depselect']));
128 }
130 if($s_action=="root"){
131 $userfilter['depselect']=($this->config->current['BASE']);
132 }
135 /* If Backbutton is Posted */
136 if($s_action=="back"){
137 $base_back = preg_replace("/^[^,]+,/","",$userfilter['depselect']);
138 $base_back = convert_department_dn($base_back);
140 if(isset($this->config->departments[trim($base_back)])){
141 $userfilter['depselect']= $this->config->departments[trim($base_back)];
142 }else{
143 $userfilter['depselect']= $this->config->departments["/"];
144 }
145 }
147 /* End for new List Managment */
149 /* Save filter data if we are in the headpage */
150 if (!isset($this->usertab)){
151 if (isset($_POST['regexit'])){
152 $userfilter["regex"]= $_POST['regexit'];
153 }
154 }
155 if(isset($_POST['regexit'])){
156 foreach( array("functionalusers", "unixusers", "mailusers","sambausers", "proxyusers", "faxusers", "templates", "subsearch") as $type){
157 if (isset($_POST[$type])) {
158 $userfilter[$type]= "checked";
159 } else {
160 $userfilter[$type]= "";
161 }
162 }
163 }
164 if (isset($_GET['search'])){
165 $s= mb_substr($_GET['search'], 0, 1, "UTF8")."*";
166 if ($s == "**"){
167 $s= "*";
168 }
169 $userfilter['regex']= $s;
170 }
171 register_global("userfilter", $userfilter);
174 /* React on user interaction here */
175 if (($_SERVER["REQUEST_METHOD"] == "POST")||($_SERVER["REQUEST_METHOD"]== "GET")){
177 /* User wants to edit data? */
178 if ($s_action=="edit"){
180 /* Get 'dn' from posted 'uid', must be unique */
182 $this->dn= $this->list[trim($s_entry)]['dn'];
184 /* Check locking, save current plugin in 'back_plugin', so
185 the dialog knows where to return. */
186 if (($user= get_lock($this->dn)) != ""){
187 return(gen_locked_message ($user, $this->dn));
188 }
190 /* Lock the current entry, so everyone will get the
191 above dialog */
192 add_lock ($this->dn, $this->ui->dn);
194 /* Set up the users ACL's for this 'dn' */
195 $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
197 /* Register usertab to trigger edit dialog */
198 $this->usertab= new usertabs($this->config,
199 $this->config->data['TABS']['USERTABS'], $this->dn);
200 // $_POST[$s_tab]=$s_tab;
202 // This would be better
203 $this->usertab->current = $s_tab;
204 $this->usertab->set_acl($acl);
206 $_SESSION['objectinfo']= $this->dn;
207 }
208 }
210 /* Reset requested? */
211 if (isset($_POST['edit_cancel']) || isset($_POST['password_cancel'])){
212 if (isset($this->usertab)){
213 del_lock ($this->usertab->dn);
214 unset ($this->usertab);
215 }
216 $this->usertab= NULL;
217 $this->lognames= array();;
218 $this->sn= "";
219 $this->givenName= "";
220 $this->uid= "";
221 unset ($_SESSION['objectinfo']);
222 }
224 /* Password change requested */
225 if ($s_action=="change_pw"){
227 /* Get 'dn' from posted 'uid' */
228 $this->dn= $this->list[trim($s_entry)]['dn'];
230 /* Load permissions for selected 'dn' and check if
231 we're allowed to remove this 'dn' */
232 $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
233 $acl= get_module_permission($acl, "user", $this->dn);
234 if (chkacl($acl, "password") == ""){
236 /* User is allowed to change passwords, save 'dn' and 'acl' for next
237 dialog. */
238 $this->acl= $acl;
239 $_SESSION['objectinfo']= $this->dn;
240 return ($smarty->fetch(get_template_path('password.tpl', TRUE)));
242 } else {
243 /* User is not allowed. Show message and cancel. */
244 print_red (_("You are not allowed to set this users password!"));
245 }
246 }
248 /* Perform password change */
249 if (isset($_POST['password_finish'])){
251 /* For security reasons, check if user is allowed to set password again */
252 if (chkacl($this->acl, "password") == "" || chkacl($this->acl, "create")){
254 /* Check input and feed errors into 'message' */
255 $message= array();
257 /* Sanity checks... */
258 if ($_POST['new_password'] != $_POST['repeated_password']){
260 /* Matching passwords in new and repeated? */
261 $message[]= _("The passwords you've entered as 'New password' and 'Repeated new password' do not match.");
262 } else {
264 /* Empty password is not permitted by default. */
265 if ($_POST['new_password'] == ""){
266 $message[]= _("The password you've entered as 'New password' is empty.");
267 }
268 }
270 /* Errors, or change password? */
271 if (count($message) != 0){
273 /* Show error message and continue editing */
274 show_errors ($message);
275 return($smarty->fetch(get_template_path('password.tpl', TRUE)));
276 }
278 $config= $this->config;
279 $ldap_ui= $this->config->get_ldap_link();
280 if(isset($this->usertab->dn)){
281 $user = ($ldap_ui->fetch($ldap_ui->cat($this->usertab->dn)));
282 }else{
283 $user = ($ldap_ui->fetch($ldap_ui->cat($this->dn)));
284 }
285 if((is_array($user))&&(isset($user['uid']))){
286 $username= $user['uid'][0];
287 }
289 /* Set password, perform required steps */
290 if ($this->usertab){
291 if ($this->usertab->password_change_needed()){
292 $obj= $this->usertab->by_object['user'];
293 change_password ($this->usertab->dn, $_POST['new_password'],
294 0, $obj->pw_storage);
295 if (isset($config->data['MAIN']['EXTERNALPWDHOOK'])){
296 exec($config->data['MAIN']['EXTERNALPWDHOOK']." ".$username." ".$_POST['new_password'], $resarr);
297 }
299 gosa_log ("Password for '".$this->usertab->dn."' has been changed");
300 unset($this->usertab);
301 $this->usertab= NULL;
302 }
303 } else {
304 change_password ($this->dn, $_POST['new_password']);
305 if (isset($config->data['MAIN']['EXTERNALPWDHOOK'])){
306 exec($config->data['MAIN']['EXTERNALPWDHOOK']." ".$username." ".$_POST['new_password'], $resarr);
307 }
309 gosa_log ("Password for '".$this->dn."' has been changed");
310 }
311 } else {
313 /* Missing permissions, show message */
314 print_red (_("You are not allowed to set this users password!"));
315 }
317 /* Clean session, delete lock */
318 del_lock ($this->dn);
319 $this->reload();
320 unset ($this->usertab);
321 $this->usertab= NULL;
322 $this->lognames= array();;
323 $this->sn= "";
324 $this->givenName= "";
325 $this->uid= "";
326 unset ($_SESSION['objectinfo']);
327 }
330 /* Remove user was requested */
331 if ($s_action=="del"){
333 /* Get 'dn' from posted 'uid' */
334 $this->dn= $this->list[trim($s_entry)]['dn'];
336 /* Load permissions for selected 'dn' and check if
337 we're allowed to remove this 'dn' */
338 $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
339 $this->acl= get_module_permission($acl, "user", $this->dn);
340 if (chkacl($this->acl, "delete") == ""){
342 /* Check locking, save current plugin in 'back_plugin', so
343 the dialog knows where to return. */
344 if (($user= get_lock($this->dn)) != ""){
345 return(gen_locked_message ($user, $this->dn));
346 }
348 /* Lock the current entry, so nobody will edit it during deletion */
349 add_lock ($this->dn, $this->ui->dn);
350 $smarty->assign("info", sprintf(_("You're about to delete the user %s."), $this->dn));
351 return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
352 } else {
354 /* Obviously the user isn't allowed to delete. Show message and
355 clean session. */
356 print_red (_("You are not allowed to delete this user!"));
357 }
358 }
362 /* Confirmation for deletion has been passed. User should be deleted. */
363 if (isset($_POST['delete_user_confirm'])){
365 /* Some nice guy may send this as POST, so we've to check
366 for the permissions again. */
367 if (chkacl($this->acl, "delete") == ""){
369 /* Delete request is permitted, perform LDAP action */
370 $this->usertab= new usertabs($this->config, $this->config->data['TABS']['USERTABS'],
371 $this->dn);
372 $this->usertab->set_acl(array($this->acl));
373 $this->usertab->delete ();
374 gosa_log ("User object '".$this->dn."' has been removed");
375 unset ($this->usertab);
376 $this->usertab= NULL;
378 /* User list has changed, reload it. */
379 $this->reload ();
380 } else {
382 /* Normally this shouldn't be reached, send some extra
383 logs to notify the administrator */
384 print_red (_("You are not allowed to delete this user!"));
386 if(isset($this->ui->uid)){
387 gosa_log ("Warning: '".$this->ui->uid."' tried to trick user deletion.");
388 }
389 }
391 /* Remove lock file after successfull deletion */
392 del_lock ($this->dn);
393 }
396 /* Delete user canceled? */
397 if (isset($_POST['delete_cancel'])){
398 del_lock ($this->dn);
399 }
402 /* Finish user edit is triggered by the tabulator dialog, so
403 the user wants to save edited data. Check and save at this
404 point. */
405 if (isset($_POST['edit_finish'])){
407 /* Check tabs, will feed message array */
408 $this->usertab->last= $this->usertab->current;
409 $this->usertab->save_object();
410 $message= $this->usertab->check();
412 /* Save, or display error message? */
413 if (count($message) == 0){
415 /* No errors. Go ahead and prepare to ask for a password
416 in case we're creating a new user. 'dn' will be 'new'
417 in this case. It is set to the correct value later. */
418 if ($this->dn == "new"){
419 $set_pass= 1;
420 } else {
421 $set_pass= 0;
422 }
424 /* Save user data to ldap */
425 if($this->usertab->save() == 1){
426 gosa_log ("User object '".$this->dn."' saving failed.");
427 return;
428 }
429 gosa_log ("User object '".$this->dn."' has been saved");
431 /* User has been saved successfully, remove lock from
432 LDAP. */
433 if ($this->dn != "new"){
434 del_lock ($this->dn);
435 }
437 /* In case of new users, ask for a password */
438 if (($set_pass || $this->usertab->password_change_needed()) &&
439 !$this->is_template){
441 return($smarty->fetch(get_template_path('password.tpl', TRUE)));
442 }
444 /* There's no page reload so we have to read new users at
445 this point. */
446 $this->reload ();
447 unset ($this->usertab);
448 $this->usertab= NULL;
449 unset ($_SESSION['objectinfo']);
451 } else {
452 /* Ok. There seem to be errors regarding to the tab data,
453 show message and continue as usual. */
454 show_errors($message);
455 }
456 }
458 /* Generate template list */
459 if (($s_action=="new")||($s_action=="create_user_from_tpl")){
460 $this->templates= array();
461 $ldap= $this->config->get_ldap_link();
462 foreach ($this->config->departments as $key => $value){
463 $acl= get_permissions (get_people_ou().$value, $this->ui->subtreeACL);
464 $acl= get_module_permission($acl, "user", get_people_ou().$value);
465 if (chkacl($acl, "create") == ""){
466 $ldap->cd (get_people_ou().$value);
467 $ldap->search ("(objectClass=gosaUserTemplate)", array("uid"));
469 if ($ldap->count() != 0){
470 while ($attrs= $ldap->fetch()){
471 $this->templates[$ldap->getDN()]=
472 $attrs['uid'][0]." - $key";
473 }
474 $this->templates['none']= _("none");
475 }
476 }
477 }
478 natcasesort ($this->templates);
479 reset ($this->templates);
480 }
482 /* New user/template request */
483 if (($s_action=="create_user_from_tpl")||($s_action=="new") || ($s_action=="new_tpl")){
484 /* By default we set 'dn' to 'new', all relevant plugins will
485 react on this. */
486 $this->dn= "new";
487 if (isset($this->config->current['IDGEN'])){
488 $this->got_uid= false;
489 } else {
490 $this->got_uid= true;
491 }
493 /* Create new usertab object */
494 $this->usertab= new usertabs($this->config,
495 $this->config->data['TABS']['USERTABS'], $this->dn);
496 $this->usertab->set_acl(array(':all'));
498 /* Take care about templates */
499 if ($s_action=="new_tpl"){
500 $this->is_template= TRUE;
501 $this->usertab->set_template_mode ();
502 } else {
503 $this->is_template= FALSE;
504 }
506 /* Use template if there are any of them */
507 if ((count($this->templates) && !isset($_POST['new_template']))||($s_action=="create_user_from_tpl")){
508 foreach(array("sn", "givenName", "uid", "got_uid", "templates") as $attr){
509 $smarty->assign("$attr", $this->$attr);
510 }
511 if ($s_action=="create_user_from_tpl"){
512 $smarty->assign("template", $this->dn= $this->list[trim($s_entry)]['dn']);
513 } else {
514 $smarty->assign("template", "");
515 }
516 $smarty->assign("edit_uid", "");
517 return($smarty->fetch(get_template_path('template.tpl', TRUE)));
518 }
519 }
521 /* Continue template editing */
522 if ((isset($_POST['template_continue']) && $_POST['template'] != 'none' && !isset($_POST['uid']))){
523 $this->sn= $_POST['sn'];
524 $this->givenName= $_POST['givenName'];
526 /* Check for requred values */
527 $message= array();
528 if ($this->sn == "") {
529 $message[]= _("The required field 'Name' is not set.");
530 }
531 if ($this->givenName == "") {
532 $message[]= _("The required field 'Given name' is not set.");
533 }
535 /* Check if dn is used */
536 $dn= preg_replace("/^[^,]+,/i", "", $_POST['template']);
537 $ldap= $this->config->get_ldap_link();
538 $ldap->cd ($dn);
539 $ldap->search ("(&(sn=".$this->sn.")(givenName=".$this->givenName."))", array("givenName"));
540 if ($ldap->count () != 0){
541 $message[]= _("A person with the choosen name is already used in this tree.");
542 }
544 /* Show error message / continue editing */
545 if (count($message) > 0){
546 show_errors ($message);
547 } else {
548 $attributes= array('sn' => $this->sn, 'givenName' => $this->givenName);
549 if (isset($this->config->current['IDGEN']) &&
550 $this->config->current['IDGEN'] != ""){
551 $uids= gen_uids ($this->config->current['IDGEN'], $attributes);
552 if (count($uids)){
553 $smarty->assign("edit_uid", "false");
554 $smarty->assign("uids", $uids);
555 $this->uid= current($uids);
556 }
557 } else {
558 $smarty->assign("edit_uid", "");
559 $this->uid= "";
560 }
561 $this->got_uid= true;
562 }
564 foreach(array("sn", "givenName", "uid", "got_uid", "templates") as $attr){
565 $smarty->assign("$attr", $this->$attr);
566 }
567 if (isset($_POST['template'])){
568 $smarty->assign("template", $_POST['template']);
569 }
570 return($smarty->fetch(get_template_path('template.tpl', TRUE)));
571 }
573 /* No template. Ok. Lets fill data into the normal user dialog */
574 if (isset($_POST['template_continue']) && $_POST['template'] == 'none'){
575 foreach(array("sn", "givenName", "uid") as $attr){
576 if (isset($_POST[$attr])){
577 $this->usertab->by_object['user']->$attr= $_POST[$attr];
578 }
579 }
580 }
582 /* Finish template preamble */
583 if (isset($_POST['template_continue']) && $_POST['template'] != 'none' && (isset($_POST['uid']))){
585 /* Might not be filled if IDGEN is unset */
586 $this->sn = $_POST['sn'];
587 $this->givenName = $_POST['givenName'];
589 /* Move user supplied data to sub plugins */
590 $this->uid = $_POST['uid'];
591 $this->usertab->uid = $this->uid;
592 $this->usertab->sn = $this->sn;
593 $this->usertab->givenName = $this->givenName;
594 $template_dn = $_POST['template'];
595 $this->usertab->adapt_from_template($template_dn);
596 $template_base = preg_replace("/^[^,]+,".get_people_ou()."/", '', $template_dn);
597 $this->usertab->by_object['user']->base= $template_base;
599 /* Set up the users ACL's for this 'dn' */
600 $acl= get_permissions ($template_base, $this->ui->subtreeACL);
601 $this->usertab->set_acl($acl);
602 }
604 if (isset($_POST['template_continue']) && ($_POST['template'] == 'none')){
605 $this->usertab->by_object['user']->base= $userfilter['depselect'];
606 }
608 /* Show tab dialog if object is present */
609 if ($this->usertab){
610 $display= $this->usertab->execute();
612 /* Don't show buttons if tab dialog requests this */
613 if (!$this->usertab->by_object[$this->usertab->current]->dialog){
614 $display.= "<p style=\"text-align:right\">\n";
615 $display.= "<input type=submit name=\"edit_finish\" value=\""._("Finish")."\">\n";
616 $display.= " \n";
617 $display.= "<input type=submit name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
618 $display.= "</p>";
619 }
620 return ($display);
621 }
623 $smarty= get_smarty();
625 /* Check sorting variable */
626 if (!isset($this->usertab) &&
627 !isset($_POST['new_user']) &&
628 !isset($_POST['new_template']) &&
629 !isset($_POST['delete_user']) &&
630 !isset($_POST['setpass_user']) &&
631 !isset($_POST['select_user'])){
632 $this->reload();
633 }
635 /* Check for exeeded sizelimit */
636 if (($message= check_sizelimit()) != ""){
637 return($message);
638 }
640 /* Prepare departments */
641 $options= "";
642 foreach ($this->config->idepartments as $key => $value){
643 if ($userfilter['depselect'] == $key){
644 $options.= "<option selected value='$key'>$value</option>";
645 } else {
646 $options.= "<option value='$key'>$value</option>";
647 }
648 }
650 /* NEW LIST MANAGMENT */
651 $listhead = "<div style='background:#F0F0F9;padding:5px;'>".
652 " <input type='image' align='middle' src='images/list_back.png' title='"._("Go up one department")."' alt='"._("Up")."' name='dep_back'> ".
653 " <input type='image' src='images/list_root.png' align='middle' title='"._("Go to root department")."' name='dep_root' alt='"._("Root")."'> ".
654 " <input type='image' align='middle' src='images/list_home.png' title='"._("Go to users department")."' alt='"._("Home")."' name='dep_home'> ".
655 " <img src='images/list_seperator.png' align='middle' alt='' height='16' width='1'> ".
656 " <input type='image' align='middle' src='images/list_new_user.png' title='"._("Create new user")."' alt='"._("New user")."' name='user_new'> ".
657 " <input type='image' align='middle' src='images/list_new.png' title='"._("Create new template")."' alt='"._("New template")."' name='user_tplnew'> ".
658 " <img src='images/list_seperator.png' align='middle' alt='' height='16' width='1'> ".
659 _("Current base")." <select name='depselect' onChange='mainform.submit()'>$options</select>".
660 " <input type='image' src='images/list_submit.png' align='middle' title='"._("Submit department")."' name='submit_department' alt='"._("Submit")."'> ".
661 "</div>";
663 $action= "<input type='image' src='images/edit.png' alt='"._("edit")."' name='user_edit_%KEY%' title='"._("Edit user")."'>";
664 $action.= "<input type='image' src='images/list_password.png' alt='"._("password")."' name='user_chgpw_%KEY%' title='"._("Change password")."'>";
665 $action.= "<input type='image' src='images/edittrash.png' alt='"._("delete")."' name='user_del_%KEY%' title='"._("Delete user")."'>";
669 $divlist = new divlist("userstab");
670 $divlist->SetHeader(array(
671 array("string" => " "),
672 array("string" => _("Username")." / "._("Department")),
673 array("string" => _("Properties")),
674 array("string" => _("Actions"), "attach" => "style='border:none'" )));
677 $divlist->SetSummary(_("This table displays all users, in the selected tree."));
678 $divlist->SetEntriesPerPage(20);
680 // Defining Links
681 $linkopen = "<a href='?plug=".$_GET['plug']."&act=dep_open&dep_id=%s'>%s</a>";
683 /* Insert departments in divlist*/
684 foreach($this->departments as $key=> $val){
686 if(!isset($this->config->departments[trim($key)])){
687 $this->config->departments[trim($key)]="";
688 }
690 $non_empty="";
691 $keys= str_replace("/","\/",$key);
692 foreach($this->config->departments as $keyd=>$vald ){
693 if(preg_match("/".$keys."\/.*/",$keyd)){
694 $non_empty="full";
695 }
696 }
698 $field1 = array("string" => "<img src='images/".$non_empty."folder.png' alt='department'>");
699 $field2 = array("string" => sprintf($linkopen,base64_encode($key),$val));
700 $field3 = array("string" => " ");
701 $field4 = array("string" => " ", "attach" => "style='border:none'");
704 $divlist->AddEntry(array($field1,$field2,$field3,$field4));
705 }
707 /* Pictures for Extensions */
708 $usrimg ="<input type='image' src='images/penguin.png' alt='"._("GOsa")."'
709 name='user_edit_%KEY%-user' title='"._("Edit generic properties")."'>";
710 $posiximg = "<input type='image' src='images/select_user.png' alt='"._("Posix")."'
711 name='user_edit_%KEY%-posixAccount' title='"._("Edit UNIX properties")."'>";
712 $eviroimg = "<input type='image' src='images/network.png' alt='"._("Environment")."'
713 name='user_edit_%KEY%-environment' title='"._("Edit environment properties")."'>";
714 $mailimg = "<input type='image' src='images/mailto.png' alt='"._("Mail")."'
715 name='user_edit_%KEY%-mailAccount' title='"._("Edit mail properties")."'>";
716 $fonimg = "<input type='image' src='images/%image%' alt='"._("Phone")."'
717 name='user_edit_%KEY%-phoneAccount' title='"._("Edit phone properties")."%title%'>";
718 $faximg = "<input type='image' src='images/fax_small.png' alt='"._("Fax")."'
719 name='user_edit_%KEY%-gofaxAccount' title='"._("Edit fax properies")."'>";
720 $sambaimg = "<input type='image' src='images/select_winstation.png' alt='"._("Samba")."'
721 name='user_edit_%KEY%-sambaAccount' title='"._("Edit samba properties")."'>";
722 $tplcreateuserimg = "<input type='image' src='images/list_new.png' alt='"._("Create user from template")."'
723 name='userfrom_tpl_%KEY%' title='"._("Create user with this template")."'>";
726 $empty = "<img src='images/empty.png' style='width:16px;height:16px;' alt=''>";
728 // User and Template Images
729 $userimg = "<img src='images/select_user.png' alt='User' title='%s'>";
730 $tplimg = "<img src='images/select_template.png' alt='Template' title='%s'>";
731 $editlink = "<a href='?plug=".$_GET['plug']."&id=%s&act=edit_entry'>%s</a>";
733 // Defines Arrays to save User and Templates
734 $tpls = array();
735 $users= array();
737 /* Get Configuration for goFon DB (if it is set), to connect to the asterisk tables.
738 * Read Sip Table for specified account (for each user with phoneAccount).
739 * Check the attributes ip port and regseconds.
740 * If regseconds is set and >0 , the phone is logged in.
741 * Else the phone is currently not logged.
742 * If we can't read any Data from the DB or there is no goFon DB specified
743 * show old style without status icons.
744 */
745 $r_db =false;
746 $r_con =false;
747 if (isset($_SESSION['config']->data['SERVERS']['FON'])){
748 $a_SETUP= $_SESSION['config']->data['SERVERS']['FON'];
749 // Connect to DB server
751 /*
752 If you want to disable the status pictures, just comment out the next line
753 */
754 $r_con= @mysql_connect($a_SETUP['SERVER'],$a_SETUP['LOGIN'],$a_SETUP['PASSWORD']);
755 // Check if we are connected correctly
756 if($r_con){
757 $r_db = @mysql_select_db($a_SETUP['DB'],$r_con);
758 }
759 }
761 // Test Every Entry and generate divlist Array
762 foreach($this->list as $key => $val){
763 $connected = ""; // This string represents timestamp or offline status
764 $ip_port = ""; // String that will represent ip : port of the connected phone
765 if((in_array("goFonAccount" ,$val['objectClass']))){
767 /* Set defaults */
768 $fonac = preg_replace("/%image%/", "select_phone.png", $fonimg);
769 $fonac = preg_replace("/%KEY%/", "$key", $fonac);
770 $fonac = preg_replace("/%title%/", "", $fonac);
772 /* Database connection is ok ?*/
773 if($r_db){
774 $res= @mysql_query("SELECT regseconds,name,port,ipaddr FROM ".$a_SETUP['SIP_TABLE']." WHERE (name='".$val['uid'][0]."')");
775 $mysql_entry = @mysql_fetch_row($res);
776 if(is_array($mysql_entry)){
777 if((isset($mysql_entry[0]))&&($mysql_entry[0]>1)){
778 $connected = " | "._("Online")." : ".gmdate("d.m.Y H:i:s",($mysql_entry[0]+(60*60)));
779 $fonac = preg_replace("/%image%/", "select_phone_connected.png", $fonimg);
780 $fonac = preg_replace("/%KEY%/", "$key", $fonac);
781 $fonac = preg_replace("/%title%/", $connected, $fonac);
782 $ip_port= " - ".$mysql_entry[3].":".$mysql_entry[2];
783 }
784 if((isset($mysql_entry[0]))&&($mysql_entry[0]==0)){
785 $connected = " | "._("Offline");
786 $fonac = preg_replace("/%image%/", "select_phone.png", $fonimg);
787 $fonac = preg_replace("/%KEY%/", "$key", $fonac);
788 $fonac = preg_replace("/%title%/", $connected, $fonac);
789 }
790 }
791 }
792 }else{
793 $fonac=$empty;
794 }
796 // Specify Pics for Extensions
797 if(in_array("posixAccount" ,$val['objectClass'])){
798 $posix = preg_replace("/%KEY%/", "$key", $posiximg);
799 }else{
800 $posix=$empty;
801 }
803 if(in_array("gotoEnvironment" ,$val['objectClass'])){
804 $enviro = preg_replace("/%KEY%/", "$key", $eviroimg);
805 }else{
806 $enviro =$empty;
807 }
809 if(in_array("gosaMailAccount" ,$val['objectClass'])){
810 $maila = preg_replace("/%KEY%/", "$key", $mailimg);
811 }else{
812 $maila=$empty;
813 }
815 if(in_array("goFaxAccount" ,$val['objectClass'])){
816 $faxac = preg_replace("/%KEY%/", "$key", $faximg);
817 }else{
818 $faxac=$empty;
819 }
821 if(in_array("sambaSamAccount" ,$val['objectClass'])){
822 $samba = preg_replace("/%KEY%/", "$key", $sambaimg);
823 }else{
824 $samba=$empty;
825 }
827 if(in_array("gosaUserTemplate",$val['objectClass'])){
828 $tpl = preg_replace("/%KEY%/", "$key", $tplimg);
829 $s_img_create_from_template = preg_replace("/%KEY%/", "$key", $tplcreateuserimg);
830 }else{
831 $s_img_create_from_template = "";
832 $tpl=$userimg;
833 }
835 $usrimg2 = preg_replace("/%KEY%/", "$key", $usrimg);
837 // Generate caption for rows
838 if (isset($val["sn"]) && isset($val["givenName"])){
839 $display= $val["sn"][0].", ".$val["givenName"][0]." [".$val["uid"][0]."]";
840 } else {
841 $display= "[".$val["uid"][0]."]";
842 }
844 /* Create each field */
845 $field1 = array("string" => sprintf($tpl,$val['dn']),"attach"=>"style='width:20px;align:middle;'");
846 $field2 = array("string" => sprintf($editlink,$key,$display).$ip_port,"attach"=>"title='".$val['dn']."'");
847 $field3 = array("string" => $usrimg2." ".$posix." ".$enviro." ".$maila." ".$fonac." ".$faxac." ".$samba." ".$s_img_create_from_template, "attach" => "style='width:150px;'");
848 $field4 = array("string" => preg_replace("/%KEY%/", "$key", $action),"attach" => "style='border:none; text-align:right;width:48px'");
850 $add = array($field1,$field2,$field3,$field4);
852 // Template or User
853 if(in_array("gosaUserTemplate",$val['objectClass'])){
854 $tpls[strtolower( $val['sn']['0'].$val['uid']['0'])]=$add;
855 }else{
856 $users[strtolower( $val['sn']['0'].$val['uid']['0'])]=$add;
857 }
858 }
860 // Sort Entries
861 ksort($users);
862 ksort($tpls);
864 // Append Templates
865 foreach($tpls as $key => $val){
866 $divlist->AddEntry( $val, array(""));
867 }
868 // Append Users
869 foreach($users as $key => $val){
870 $divlist->AddEntry( $val, array(""));
871 }
872 /* Show main page */
873 //$smarty->assign("userlist", nl2br(htmlentities($divlist->DrawList())));
874 $smarty->assign("userlist", $divlist->DrawList());
875 $smarty->assign("userlisthead", $listhead);
877 /* END NEW LIST MANAGMENT
878 */
879 $smarty->assign("search_image", get_template_path('images/search.png'));
880 $smarty->assign("tree_image", get_template_path('images/tree.png'));
881 $smarty->assign("infoimage", get_template_path('images/info.png'));
882 $smarty->assign("launchimage", get_template_path('images/launch.png'));
883 $smarty->assign("deplist", $this->config->idepartments);
884 foreach( array("depselect", "functionalusers", "unixusers",
885 "mailusers", "sambausers", "proxyusers",
886 "faxusers", "templates", "subsearch") as $type){
888 $smarty->assign("$type", $userfilter[$type]);
889 }
891 $smarty->assign("regex", $userfilter["regex"]);
892 /* Extend if we are not using javascript */
893 $smarty->assign("apply", apply_filter());
894 $smarty->assign("alphabet", generate_alphabet());
895 $smarty->assign("hint", print_sizelimit_warning());
897 return ($smarty->fetch(get_template_path('headpage.tpl', TRUE)));
898 }
901 function reload()
902 {
903 /* Get config */
904 $userfilter= get_global('userfilter');
906 /* Set base for all searches */
907 $base= $userfilter['depselect'];
909 /* Regex filter? */
910 if ($userfilter['regex'] != ""){
911 $regex= $userfilter['regex'];
912 } else {
913 $regex= "*";
914 }
916 /* Set filter depending on selection */
917 if ($this->config->current['SAMBAVERSION'] == 3){
918 $samba= "sambaSamAccount";
919 } else {
920 $samba= "sambaAccount";
921 }
923 $filter="";
924 if ($userfilter['functionalusers'] == "checked"){
925 $filter.= "(&(objectClass=gosaAccount)(!(|(objectClass=posixAccount)(objectClass=gosaMailAccount)(objectClass=$samba)(objectClass=goFaxAccount)(objectClass=gosaProxyAccount))))";
926 }
927 if ($userfilter['unixusers'] == "checked"){
928 $filter.= "(objectClass=posixAccount)";
929 }
930 if ($userfilter['mailusers'] == "checked"){
931 $filter.= "(objectClass=gosaMailAccount)";
932 }
933 if ($userfilter['sambausers'] == "checked"){
934 $filter.= "(objectClass=$samba)";
935 }
936 if ($userfilter['proxyusers'] == "checked"){
937 $filter.= "(objectClass=gosaProxyAccount)";
938 }
939 if ($userfilter['faxusers'] == "checked"){
940 $filter.= "(objectClass=goFaxAccount)";
941 }
943 if ($userfilter['templates'] == "checked"){
944 $filter= "(|(objectClass=gosaUserTemplate)(&(objectClass=gosaAccount)(|$filter)))";
945 } else {
946 $filter= "(&(objectClass=gosaAccount)(!(objectClass=gosaUserTemplate))(|$filter))";
947 }
948 $filter= "(&(|(uid=$regex)(sn=$regex)(givenName=$regex))$filter)";
950 /* Generate userlist */
951 $ldap= $this->config->get_ldap_link(TRUE);
952 if ($userfilter['subsearch'] == "checked"){
953 $this->list= get_list($this->ui->subtreeACL, "$filter", TRUE, $base, array("uid", "givenName", "sn", "objectClass"), TRUE);
954 } else {
955 $base= get_people_ou().$base;
956 $this->list= get_list($this->ui->subtreeACL, "$filter", FALSE, $base, array("uid", "givenName", "sn", "objectClass"), TRUE);
957 }
961 /* NEW LIST MANAGMENT
962 * We also need to search for the departments
963 * So we are able to navigate like in konquerer
964 */
965 $base2 = preg_replace("/ou=people,/i","",$base);
967 $res3 = get_list2($this->ui->subtreeACL, "(&(|(ou=$regex)(description=$regex))(objectClass=gosaDepartment))",
968 TRUE, $base2, array("ou", "description"), TRUE);
970 $this->departments= array();
972 $tmp = array();
973 foreach ($res3 as $value){
974 $tmp[strtolower($value['dn']).$value['dn']]=$value;
975 }
976 ksort($tmp);
977 foreach($tmp as $value){
978 if($value["description"][0]!=".."){
979 $this->departments[$value['dn']]=convert_department_dn2($value['dn'])." - [".$value["description"][0]."]";
980 }else{
981 $this->departments[$value['dn']]=$value["description"][0];
982 }
983 }
984 /* END NEW LIST MANAGMENT
985 */
988 $this->userlist= array();
990 foreach ($this->list as $value){
991 if (isset($value["uid"][0]) && !preg_match('/\$$/', $value["uid"][0])){
992 if (in_array_ics('gosaUserTemplate', $value['objectClass'])){
993 $this->userlist[$value["dn"]]= "* ".$value["uid"][0]." ("._("Template").")";
994 continue;
995 }
996 if (isset($value["givenName"][0]) && isset($value["sn"][0])){
997 $this->userlist[$value["dn"]]= $value["sn"][0].", ".
998 $value["givenName"][0].
999 " [".$value["uid"][0]."]";
1000 } else {
1001 $this->userlist[$value["dn"]]= "[".$value["uid"][0]."]";
1002 }
1003 }
1004 }
1006 natcasesort ($this->userlist);
1007 reset ($this->userlist);
1008 }
1010 function remove_from_parent()
1011 {
1012 }
1015 /* Check values */
1016 function check()
1017 {
1018 }
1021 /* Save to LDAP */
1022 function save()
1023 {
1024 }
1026 function adapt_from_template($dn)
1027 {
1028 }
1030 function password_change_needed()
1031 {
1032 }
1034 function show_header($button_text, $text, $disabled= FALSE)
1035 {
1036 }
1038 function remove_lock()
1039 {
1040 if (isset($this->usertab->dn)){
1041 del_lock ($this->usertab->dn);
1042 }
1043 }
1045 }
1047 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1048 ?>