1 <?php
2 /*
3 * This code is part of GOsa (http://www.gosa-project.org)
4 * Copyright (C) 2003-2008 GONICUS GmbH
5 *
6 * ID: $$Id$$
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
23 class userManagement extends management
24 {
25 var $plHeadline = "Users";
26 var $plDescription = "Manage aspects of user accounts like generic, POSIX, samba and mail settings";
27 var $plIcon = "plugins/users/images/user.png";
29 var $sn = "";
30 var $givenName = "";
31 var $uid = "";
32 var $got_uid = "";
33 var $edit_uid = "";
35 var $pwd_change_queue = array();
36 var $force_hash_type = array();
38 // Tab definition
39 protected $tabClass = "usertabs";
40 protected $tabType = "USERTABS";
41 protected $aclCategory = "users";
42 protected $aclPlugin = "user";
43 protected $objectName = "user";
45 protected $proposal = "";
46 protected $proposalEnabled = FALSE;
47 protected $proposalSelected = FALSE;
49 function __construct($config,$ui)
50 {
51 $this->config = $config;
52 $this->ui = $ui;
54 $this->storagePoints = array(get_ou("core", "userRDN"));
56 // Build filter
57 if (session::global_is_set(get_class($this)."_filter")){
58 $filter= session::global_get(get_class($this)."_filter");
59 } else {
60 $filter = new filter(get_template_path("user-filter.xml", true));
61 $filter->setObjectStorage($this->storagePoints);
62 }
63 $this->setFilter($filter);
65 // Build headpage
66 $headpage = new listing(get_template_path("user-list.xml", true));
67 $headpage->registerElementFilter("lockLabel", "userManagement::filterLockLabel");
68 $headpage->registerElementFilter("lockImage", "userManagement::filterLockImage");
69 $headpage->registerElementFilter("filterProperties", "userManagement::filterProperties");
70 $headpage->setFilter($filter);
72 // Add copy&paste and snapshot handler.
73 if ($this->config->boolValueIsTrue("core", "copyPaste")){
74 $this->cpHandler = new CopyPasteHandler($this->config);
75 }
76 if($this->config->get_cfg_value("core","enableSnapshots") == "true"){
77 $this->snapHandler = new SnapshotHandler($this->config);
78 }
80 parent::__construct($config, $ui, "users", $headpage);
82 // Register special user actions
83 $this->registerAction("lock", "lockEntry");
84 $this->registerAction("lockUsers", "lockUsers");
85 $this->registerAction("unlockUsers", "lockUsers");
86 $this->registerAction("new_template", "newTemplate");
87 $this->registerAction("newfromtpl", "newUserFromTemplate");
88 $this->registerAction("templateContinue", "templateContinue");
89 $this->registerAction("templatize", "templatizeUsers");
90 $this->registerAction("templatizeContinue", "templatizeContinue");
92 $this->registerAction("password", "changePassword");
93 $this->registerAction("passwordQueue", "handlePasswordQueue");
94 $this->registerAction("passwordCancel", "closeDialogs");
96 $this->registerAction("sendMessage", "sendMessage");
97 $this->registerAction("saveEventDialog", "saveEventDialog");
98 $this->registerAction("abortEventDialog", "closeDialogs");
100 // Register shortcut icon actions
101 $this->registerAction("edit_user","editEntry");
102 $this->registerAction("edit_posixAccount","editEntry");
103 $this->registerAction("edit_mailAccount","editEntry");
104 $this->registerAction("edit_sambaAccount","editEntry");
105 $this->registerAction("edit_netatalk","editEntry");
106 $this->registerAction("edit_environment","editEntry");
107 $this->registerAction("edit_gofaxAccount","editEntry");
108 $this->registerAction("edit_phoneAccount","editEntry");
109 }
112 // Inject user actions
113 function detectPostActions()
114 {
115 $action = management::detectPostActions();
116 if(isset($_POST['template_continue'])) $action['action'] = "templateContinue";
117 if(isset($_POST['templatize_continue'])) $action['action'] = "templatizeContinue";
118 if(isset($_POST['save_event_dialog'])) $action['action'] = "saveEventDialog";
119 if(isset($_POST['abort_event_dialog'])) $action['action'] = "abortEventDialog";
120 if(isset($_POST['password_cancel'])){
121 $action['action'] = "passwordCancel";
122 }elseif((count($this->pwd_change_queue) || isset($_POST['password_finish']) || isset($_POST['refreshProposal']))){
123 $action['action'] = "passwordQueue";
124 }
125 return($action);
126 }
129 function editEntry($action="",$target=array(),$all=array(), $altTabClass ="", $altTabType = "", $altAclCategory="")
130 {
131 $str = management::editEntry($action,$target);
132 if($str) return($str);
134 if(preg_match("/^edit_/",$action)){
135 $tab = preg_replace("/^edit_/","",$action);
136 if(isset($this->tabObject->by_object[$tab])){
137 $this->tabObject->current = $tab;
138 }else{
139 trigger_error("Unknown tab: ".$tab);
140 }
141 }
142 }
145 function closeDialogs()
146 {
147 management::closeDialogs();
148 $this->pwd_change_queue = array();
149 }
152 /*! \brief Sends a message to a set of users using gosa-si events.
153 */
154 function sendMessage($action="",$target=array(),$all=array())
155 {
156 if(class_available("DaemonEvent")){
157 $uids = array();
158 $ldap = $this->config->get_ldap_link();
159 $ldap->cd($this->config->current['BASE']);
160 foreach($target as $dn){
161 $ldap->cat($dn,array('uid'));
162 $attrs = $ldap->fetch();
163 if(isset($attrs['uid'][0])){
164 $uids[] = $attrs['uid'][0];
165 }
166 }
167 if(count($uids)){
168 $events = DaemonEvent::get_event_types(USER_EVENT);
169 $event = "DaemonEvent_notify";
170 if(isset($events['BY_CLASS'][$event])){
171 $type = $events['BY_CLASS'][$event];
172 $this->dialogObject = new $type['CLASS_NAME']($this->config);
173 $this->dialogObject->add_users($uids);
174 $this->dialogObject->set_type(SCHEDULED_EVENT);
175 }
176 }
177 }
178 }
181 /*! \brief Sends a message to a set of users using gosa-si events.
182 */
183 function saveEventDialog()
184 {
185 $this->dialogObject->save_object();
186 $msgs = $this->dialogObject->check();
187 if(count($msgs)){
188 msg_dialog::displayChecks($msgs);
189 }else{
190 $o_queue = new gosaSupportDaemon();
191 $o_queue->append($this->dialogObject);
192 if($o_queue->is_error()){
193 msg_dialog::display(_("Infrastructure error"), msgPool::siError($o_queue->get_error()),ERROR_DIALOG);
194 }
195 $this->closeDialogs();
196 }
197 }
200 /*! \brief Intiates template creation.
201 */
202 function newTemplate($action,$entry)
203 {
204 $this->newEntry();
205 $this->tabObject->set_template_mode ();
206 }
209 /*! \brief Queues a set of users for password changes
210 */
211 function changePassword($action="",$target=array(),$all=array())
212 {
213 $this->dn ="";
214 $this->pwd_change_queue = $target;
216 // Check permisions
217 $disallowed = array();
218 foreach($this->pwd_change_queue as $key => $dn){
219 if(!preg_match("/w/",$this->ui->get_permissions($dn,$this->aclCategory."/password"))){
220 unset($this->pwd_change_queue[$key]);
221 $disallowed[] = $dn;
222 }
223 }
224 if(count($disallowed)){
225 msg_dialog::display(_("Permission"),msgPool::permModify($disallowed),INFO_DIALOG);
226 }
228 // Now display change dialog.
229 return($this->handlePasswordQueue());
230 }
234 function refreshProposal()
235 {
236 $this->proposal = passwordMethod::getPasswordProposal($this->config);
237 $this->proposalEnabled = (!empty($this->proposal));
238 }
241 function handlePasswordQueue()
242 {
243 // skip if nothing is to do
244 if(empty($this->dn) && !count($this->pwd_change_queue)) return;
246 // Refresh proposal if requested
247 if(isset($_POST['refreshProposal'])) $this->refreshProposal();
248 if(isset($_POST['proposalSelected'])) $this->proposalSelected = get_post('proposalSelected') == 1;
250 $smarty = get_smarty();
251 $smarty->assign("proposal" , $this->proposal);
252 $smarty->assign("proposalEnabled" , $this->proposalEnabled);
253 $smarty->assign("proposalSelected" , $this->proposalSelected);
255 // Get next entry from queue.
256 if(empty($this->dn) && count($this->pwd_change_queue)){
258 // Generate new proposal
259 $this->refreshProposal();
260 $this->proposalSelected = ($this->proposal != "");
261 $smarty->assign("proposal" , $this->proposal);
262 $smarty->assign("proposalEnabled" , $this->proposalEnabled);
263 $smarty->assign("proposalSelected" , $this->proposalSelected);
265 $this->dn = array_pop($this->pwd_change_queue);
266 set_object_info($this->dn);
267 return ($smarty->fetch(get_template_path('password.tpl', TRUE)));
268 }
270 // If we've just refreshed the proposal then do not check the password for validity.
271 if(isset($_POST['refreshProposal'])){
272 return ($smarty->fetch(get_template_path('password.tpl', TRUE)));
273 }
275 // Check permissions
276 if(isset($_POST['password_finish'])){
278 $dn = $this->dn;
279 $acl = $this->ui->get_permissions($dn, "users/password");
280 $cacl= $this->ui->get_permissions($dn, "users/user");
281 if (preg_match('/w/', $acl) || preg_match('/c/', $cacl)){
283 // Get posted passwords
284 if($this->proposalSelected){
285 $new_password = $this->proposal;
286 $repeated_password = $this->proposal;
287 }else{
288 $new_password = get_post('new_password');
289 $repeated_password = get_post('repeated_password');
290 }
292 // Check posted passwords now.
293 $message= array();
294 if ($new_password != $repeated_password){
295 $message[]= _("The passwords you've entered as 'New password' and 'Repeated new password' do not match.");
296 } else {
297 if ($new_password == ""){
298 $message[] = msgPool::required(_("New password"));
299 }
300 }
302 // Display errors
303 if (count($message) != 0){
304 msg_dialog::displayChecks($message);
305 return($smarty->fetch(get_template_path('password.tpl', TRUE)));
306 }
308 // Change cassword
309 if(isset($this->force_hash_type[$this->dn])){
310 if(!change_password ($this->dn, $new_password,0,$this->force_hash_type[$this->dn])){
311 return($smarty->fetch(get_template_path('password.tpl', TRUE)));
312 }
313 }else{
314 if(!change_password ($this->dn, $new_password)){
315 return($smarty->fetch(get_template_path('password.tpl', TRUE)));
316 }
317 }
318 if ($this->config->get_cfg_value("core","passwordHook") != ""){
319 exec($this->config->get_cfg_value("core","passwordHook")." ".$username." ".$new_password, $resarr);
320 }
321 new log("modify","users/".get_class($this),$this->dn,array(),"Password has been changed");
322 $this->dn ="";
324 } else {
325 msg_dialog::display(_("Password change"),
326 _("You have no permission to change this users password!"),
327 WARNING_DIALOG);
328 }
329 }
331 // Cleanup
332 if(!count($this->pwd_change_queue) && $this->dn=""){
333 $this->remove_lock();
334 $this->closeDialogs();
335 }else{
336 return($this->handlePasswordQueue());
337 }
338 }
341 /*! \brief Save user modifications.
342 * Whenever we save a 'new' user, request a password change for him.
343 */
344 function saveChanges()
345 {
346 $str = management::saveChanges();
348 if(!empty($str)) return($str);
350 if($this->last_tabObject instanceOf multi_plug){
351 foreach($this->last_tabObject->a_handles as $user){
352 if($user->password_change_needed()){
353 $this->force_hash_type[$user->dn] = $user->by_object['user']->pw_storage;
354 $this->pwd_change_queue[] = $user->dn;
355 }
356 }
357 return($this->handlePasswordQueue());
358 }
360 if(isset($this->last_tabObject->by_object['user']) && $this->last_tabObject->by_object['user']->password_change_needed()){
361 $this->force_hash_type[$this->last_tabObject->dn] = $this->last_tabObject->by_object['user']->pw_storage;
362 $this->pwd_change_queue[] = $this->last_tabObject->dn;
363 return($this->handlePasswordQueue());
364 }
365 }
367 function cancelEdit()
368 {
369 $str = management::cancelEdit();
370 if(!empty($str)) return($str);
372 if(isset($this->last_tabObject->by_object['user']) &&
373 $this->last_tabObject->by_object['user']->dn != "new" &&
374 $this->last_tabObject->by_object['user']->password_change_needed()){
375 $this->force_hash_type[$this->last_tabObject->dn] = $this->last_tabObject->by_object['user']->pw_storage;
376 $this->pwd_change_queue[] = $this->last_tabObject->dn;
377 return($this->handlePasswordQueue());
378 }
379 }
382 /*! \brief Intiates user creation.
383 * If we've user templates, then the user will be asked to use to use one.
384 * -> See 'templateContinue' for further handling.
385 */
386 function newUserFromTemplate($action="",$target=array(),$all=array())
387 {
388 // Call parent method, it knows whats to do, locking and so on ...
389 $str = management::newEntry($action,$target,$all);
390 if(!empty($str)) return($str);
392 // Reset uid selection.
393 $this->got_uid= "";
395 // Use template if there are any of them
396 $templates = array();
397 $templates['none']= _("none");
398 $templates = array_merge($templates,$this->get_templates());
400 // We've templates, so preset the current template and display the input dialog.
401 if (count($templates)){
402 $smarty = get_smarty();
403 foreach(array("sn", "givenName", "uid", "got_uid") as $attr){
404 $smarty->assign("$attr", "");
405 }
406 $smarty->assign("template", array_pop($target));
407 $smarty->assign("templates", $templates);
408 $smarty->assign("edit_uid", "");
409 return($smarty->fetch(get_template_path('template.tpl', TRUE)));
411 // -> See 'templateContinue' for further handling!
412 }
413 }
417 /*! \brief Intiates user creation.
418 * If we've user templates, then the user will be asked
419 * if he wants to use one.
420 * -> See 'templateContinue' for further handling.
421 */
422 function newEntry($action="",$target=array(),$all=array(), $altTabClass ="", $altTabType = "", $altAclCategory="")
423 {
425 // Call parent method, it manages everything, locking, object creation...
426 $str = management::newEntry($action,$target,$all);
427 if(!empty($str)) return($str);
429 // If we've at least one template, then ask the user if he wants to use one?
430 $templates = array();
431 $templates['none']= _("none");
432 $templates = array_merge($templates,$this->get_templates());
434 // Display template selection
435 if (count($templates) > 1){
436 $smarty = get_smarty();
438 // Set default variables, normally empty.
439 foreach(array("sn", "givenName", "uid", "got_uid") as $attr){
440 $smarty->assign($attr, "");
441 }
442 $smarty->assign("template", "none");
443 $smarty->assign("templates", $templates);
444 $smarty->assign("edit_uid", "");
445 return($smarty->fetch(get_template_path('template.tpl', TRUE)));
447 // -> See 'templateContinue' for further handling!
448 }
449 }
452 /* !\brief This method is called whenever a template selection was displayed.
453 * Here we act on the use selection.
454 * - Does the user want to create a user from template?
455 * - Create user without template?
456 * - Input correct, every value given and valid?
457 */
458 function templateContinue()
459 {
460 // Get the list of available templates.
461 $templates = array();
462 $templates['none']= _("none");
463 $templates = array_merge($templates,$this->get_templates());
465 // Input validation, if someone wants to create a user from a template
466 // then validate the given values.
467 $message = array();
468 if(!isset($_POST['template']) || (empty($_POST['template']))){
469 $message[]= msgPool::invalid(_("Template"));
470 }
471 if(!isset($_POST['sn']) || (empty($_POST['sn']))){
472 $message[]= msgPool::required(_("Name"));
473 }
474 if(!isset($_POST['givenName']) || (empty($_POST['givenName']))){
475 $message[]= msgPool::required(_("Given name"));
476 }
478 /********************
479 * 1 We've had input errors - Display errors and show input dialog again.
480 ********************/
482 if (count($message) > 0){
483 msg_dialog::displayChecks($message);
485 // Preset input fields with user input.
486 $smarty = get_smarty();
487 foreach(array("sn", "givenName", "uid", "template") as $attr){
488 if(isset($_POST[$attr])){
489 $smarty->assign("$attr", get_post($attr));
490 }else{
491 $smarty->assign("$attr", "");
492 }
493 }
495 $smarty->assign("templates",$templates);
496 $smarty->assign("got_uid", $this->got_uid);
497 $smarty->assign("edit_uid",false);
498 return($smarty->fetch(get_template_path('template.tpl', TRUE)));
499 }
502 /********************
503 * 2 There was a template selected, now ask for the uid.
504 ********************/
506 if ($_POST['template'] != 'none' && !isset($_POST['uid'])){
508 // Remember user input.
509 $smarty = get_smarty();
510 $this->sn = $_POST['sn'];
511 $this->givenName = $_POST['givenName'];
513 // Avoid duplicate entries, check if such a user already exists.
514 $dn= preg_replace("/^[^,]+,/i", "", $_POST['template']);
515 $ldap= $this->config->get_ldap_link();
516 $ldap->cd ($dn);
517 $ldap->search ("(&(sn=".normalizeLdap($this->sn).")(givenName=".normalizeLdap($this->givenName)."))", array("givenName"));
518 if ($ldap->count () != 0){
519 msg_dialog::displayChecks(array(msgPool::duplicated(_("Name"))));
520 }else{
522 // Preset uid field by using the idGenerator
523 $attributes= array('sn' => $this->sn, 'givenName' => $this->givenName);
524 if ($this->config->get_cfg_value("core","idGenerator") != ""){
525 $uids= gen_uids ($this->config->get_cfg_value("core","idGenerator"), $attributes);
526 if (count($uids)){
527 $smarty->assign("edit_uid", "false");
528 $smarty->assign("uids", $uids);
529 $this->uid= current($uids);
530 }
531 } else {
532 $smarty->assign("edit_uid", "");
533 $this->uid= "";
534 }
535 $this->got_uid= true;
536 }
538 // Assign user input
539 foreach(array("sn", "givenName", "uid", "got_uid") as $attr){
540 $smarty->assign("$attr", $this->$attr);
541 }
542 if (isset($_POST['template'])){
543 $smarty->assign("template", $_POST['template']);
544 }
545 $smarty->assign("templates",$templates);
546 return($smarty->fetch(get_template_path('template.tpl', TRUE)));
547 }
550 /********************
551 * 3 No template - Ok. Lets fill the data into the user object and skip templating here.
552 ********************/
553 if ($_POST['template'] == 'none'){
554 foreach(array("sn", "givenName", "uid") as $attr){
555 if (isset($_POST[$attr])){
556 $this->tabObject->by_object['user']->$attr= $_POST[$attr];
557 }
558 }
560 // The user Tab object is already instantiated, so just go back and let the
561 // management class do the rest.
562 return("");
563 }
566 /********************
567 * 4 Template selected and uid given - Ok, then lets adapt tempalte values.
568 ********************/
569 if(isset($_POST['uid'])){
571 // Move user supplied data to sub plugins
572 foreach(array("uid","sn","givenName") as $attr){
573 $this->$attr = $_POST[$attr];
574 $this->tabObject->$attr = $this->$attr;
575 $this->tabObject->by_object['user']->$attr = $this->$attr;
576 }
578 // Adapt template values.
579 $template_dn = $_POST['template'];
580 $this->tabObject->adapt_from_template($template_dn, array("uid","cn","givenName","sn"));
581 $template_base = preg_replace("/^[^,]+,".preg_quote(get_people_ou(), '/i')."/", '', $template_dn);
582 $this->tabObject->by_object['user']->base= $template_base;
584 // The user Tab object is already instantiated, so just go back and let the
585 // management class do the rest.
586 return("");
587 }
588 }
591 /* !\brief This method applies a template to a set of users.
592 */
593 function templatizeUsers($action="",$target=array(),$all=array())
594 {
595 $this->dns = array();
596 if(count($target)){
598 // Get the list of available templates.
599 $templates = $this->get_templates();
601 // Check entry locking
602 foreach($target as $dn){
603 if (($user= get_lock($dn)) != ""){
604 $this->dn = $dn;
605 return(gen_locked_message ($user, $dn));
606 }
607 $this->dns[] = $dn;
608 }
610 // Display template
611 $smarty = get_smarty();
612 $smarty->assign("templates", $templates);
613 return($smarty->fetch(get_template_path('templatize.tpl', TRUE)));
614 }
615 }
618 /* !\brief This method is called whenever the templatize dialog was used.
619 */
620 function templatizeContinue()
621 {
622 // Template readable?
623 $template= get_post('template');
624 $acl = $this->ui->get_permissions($template, $this->aclCategory."/".$this->aclPlugin);
625 if (preg_match('/r/', $acl)){
626 $tab = $this->tabClass;
627 foreach ($this->dns as $dn){
629 // User writeable
630 $acl = $this->ui->get_permissions($dn, $this->aclCategory."/".$this->aclPlugin);
631 if (preg_match('/w/', $acl)){
632 $this->tabObject= new $tab($this->config, $this->config->data['TABS'][$this->tabType], $dn, $this->aclCategory);
633 $this->tabObject->adapt_from_template($template, array("sn", "givenName", "uid"));
634 $this->tabObject->save();
635 } else {
636 msg_dialog::display(_("Permission error"), msgPool::permModify($dn), ERROR_DIALOG);
637 }
638 }
639 } else {
640 msg_dialog::display(_("Permission error"), msgPool::permView($template), ERROR_DIALOG);
641 }
643 // Cleanup!
644 $this->remove_lock();
645 $this->closeDialogs();
646 }
649 /* !\brief Lock/unlock multiple users.
650 */
651 function lockUsers($action,$target,$all)
652 {
653 if(!count($target)) return;
654 if($action == "lockUsers"){
655 $this->lockEntry($action,$target, $all, "lock");
656 }else{
657 $this->lockEntry($action,$target, $all, "unlock");
658 }
659 }
662 /* !\brief Locks/unlocks the given user(s).
663 */
664 function lockEntry($action,$entry, $all, $type = "toggle")
665 {
667 // Filter out entries we are not allowed to modify
668 $disallowed = array();
669 $dns = array();
670 foreach($entry as $dn){
671 if (!preg_match("/w/",$this->ui->get_permissions($dn,"users/password"))){
672 $disallowed[] = $dn;
673 }else{
674 $allowed[] = $dn;
675 }
676 }
677 if(count($disallowed)){
678 msg_dialog::display(_("Permission"),msgPool::permDelete($disallowed),INFO_DIALOG);
679 }
681 // Try to lock/unlock the rest of the entries.
682 $ldap = $this->config->get_ldap_link();
683 foreach($allowed as $dn){
684 $ldap->cat($dn, array('userPassword'));
685 if($ldap->count() == 1){
687 // We can't lock empty passwords.
688 $val = $ldap->fetch();
689 if(!isset($val['userPassword'])){
690 continue;
691 }
693 // Detect the password method and try to lock/unlock.
694 $pwd = $val['userPassword'][0];
695 $method = passwordMethod::get_method($pwd,$val['dn']);
696 $success= true;
697 if($method instanceOf passwordMethod){
698 if($type == "toggle"){
699 if($method->is_locked($this->config,$val['dn'])){
700 $success= $method->unlock_account($this->config,$val['dn']);
701 }else{
702 $success= $method->lock_account($this->config,$val['dn']);
703 }
704 }elseif($type == "lock" && !$method->is_locked($this->config,$val['dn'])){
705 $success= $method->lock_account($this->config,$val['dn']);
706 }elseif($type == "unlock" && $method->is_locked($this->config,$val['dn'])){
707 $success= $method->unlock_account($this->config,$val['dn']);
708 }
710 // Check if everything went fine.
711 if (!$success){
712 $hn= $method->get_hash_name();
713 if (is_array($hn)){
714 $hn= $hn[0];
715 }
716 msg_dialog::display(_("Account locking"),
717 sprintf(_("Password method '%s' does not support locking. Account (%s) has not been locked!"),
718 $hn,$dn),WARNING_DIALOG);
719 }
720 }else{
721 // Can't lock unknown methods.
722 }
723 }
724 }
725 }
728 /* !\brief This method returns a list of all available templates.
729 */
730 function get_templates()
731 {
732 $templates= array();
733 $ldap= $this->config->get_ldap_link();
734 foreach ($this->config->departments as $key => $value){
735 $acl = $this->ui->get_permissions($value,$this->aclCategory."/".$this->aclPlugin);
736 if (preg_match("/c/",$acl)){
738 // Search all templates from the current dn.
739 $ldap->cd (get_people_ou().$value);
740 $ldap->search ("(objectClass=gosaUserTemplate)", array("uid"));
741 if ($ldap->count() != 0){
742 while ($attrs= $ldap->fetch()){
743 $templates[$ldap->getDN()]= $attrs['uid'][0]." - ".LDAP::fix($key);
744 }
745 }
746 }
747 }
748 natcasesort ($templates);
749 reset ($templates);
750 return($templates);
751 }
754 function copyPasteHandler($action="",$target=array(),$all=array(),
755 $altTabClass ="", $altTabType = "", $altAclCategory="",$altAclPlugin="")
756 {
757 if ($this->config->boolValueIsTrue("core", "copyPaste")){
758 $this->cpHandler->lastdn = "";
759 $str = management::copyPasteHandler($action,$target,$all);
760 if($this->cpHandler->lastdn != "" && isset($_POST['passwordTodo']) && $_POST['passwordTodo'] == "new"){
761 $this->pwd_change_queue[] = $this->cpHandler->lastdn;
762 return($this->handlePasswordQueue());
763 }
764 return($str);
765 }
767 return "";
768 }
771 static function filterLockImage($userPassword)
772 {
773 $image= "images/empty.png";
774 if(isset($userPassword[0]) && preg_match("/^\{[^\}]/",$userPassword[0])){
775 if(preg_match("/^[^\}]*+\}!/",$userPassword[0])){
776 $image= "images/lists/locked.png";
777 }else{
778 $image= "images/lists/unlocked.png";
779 }
780 }
781 return $image;
782 }
785 static function filterLockLabel($userPassword)
786 {
787 $label= "";
788 if(isset($userPassword[0]) && preg_match("/^\{[^\}]/",$userPassword[0])){
789 if(preg_match("/^[^\}]*+\}!/",$userPassword[0])){
790 $label= _("Unlock account")."<rowClass:entry-locked/><rowLabel:locked/>";
791 }else{
792 $label= _("Lock account");
793 }
794 }
795 return $label;
796 }
799 static function filterProperties($row, $classes)
800 {
801 $result= "";
802 $map= array( "gosaAccount" => array( "image" => "plugins/users/images/select_user.png",
803 "plugin" => "user",
804 "alt" => _("Generic"),
805 "title" => _("Edit generic properties")),
806 "posixAccount" => array("image" => "images/penguin.png",
807 "plugin" => "posixAccount",
808 "alt" => _("POSIX"),
809 "title" => _("Edit POSIX properties")),
810 "gosaMailAccount" => array("image" => "images/mailto.png",
811 "alt" => _("Mail"),
812 "plugin" => "mailAccount",
813 "title" => _("Edit mail properties")),
814 "sambaSamAccount" => array("image" => "plugins/systems/images/select_winstation.png",
815 "plugin" => "sambaAccount",
816 "alt" => _("Samba"),
817 "title" => _("Edit samba properties")),
818 "apple-user" => array("image" => "plugins/netatalk/images/select_netatalk.png",
819 "plugin" => "netatalk",
820 "alt" => _("Netatalk"),
821 "title" => _("Edit netatalk properties")),
822 "gotoEnvironment" => array("image" => "plugins/users/images/small_environment.png",
823 "plugin" => "environment",
824 "alt" => _("Environment"),
825 "title" => _("Edit environment properties")),
826 "goFaxAccount" => array("image" => "plugins/users/images/fax_small.png",
827 "plugin" => "gofaxAccount",
828 "alt" => _("FAX"),
829 "title" => _("Edit FAX properties")),
830 "goFonAccount" => array("image" => "plugins/gofon/images/select_phone.png",
831 "plugin" => "phoneAccount",
832 "alt" => _("Phone"),
833 "title" => _("Edit phone properties")));
835 // Walk thru map
836 foreach ($map as $oc => $properties) {
837 if (in_array_ics($oc, $classes)) {
838 $result.= image($properties['image'], "listing_edit_".$properties['plugin']."_$row", $properties['title']);
839 } else {
840 $result.= image('images/empty.png');
841 }
842 }
843 return $result;
844 }
846 }
847 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
848 ?>