addUserBL.php
6.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
<?php
/**
* $Id$
*
* Add a user.
*
* Copyright (c) 2003 Jam Warehouse http://www.jamwarehouse.com
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* @version $Revision$
* @author Mukhtar Dharsey, Jam Warehouse (Pty) Ltd, South Africa
* @package administration.usermanagement
*/
require_once("../../../../../config/dmsDefaults.php");
KTUtil::extractGPC('fAddToDb', 'fEmail', 'fEmailNotification', 'fFromDb');
KTUtil::extractGPC('fGroupID', 'fLdap', 'fMobile', 'fName', 'fPassword');
KTUtil::extractGPC('fSearch', 'fSelectedUser', 'fUsername');
require_once("$default->fileSystemRoot/lib/visualpatterns/PatternListBox.inc");
require_once("$default->fileSystemRoot/lib/visualpatterns/PatternCreate.inc");
require_once("$default->fileSystemRoot/lib/users/User.inc");
require_once("$default->fileSystemRoot/lib/groups/Group.inc");
require_once("$default->fileSystemRoot/lib/groups/GroupUserLink.inc");
require_once("$default->fileSystemRoot/lib/security/Permission.inc");
require_once("$default->fileSystemRoot/lib/visualpatterns/PatternCustom.inc");
require_once("$default->fileSystemRoot/lib/foldermanagement/Folder.inc");
require_once("$default->fileSystemRoot/presentation/lookAndFeel/knowledgeTree/foldermanagement/folderUI.inc");
require_once("$default->fileSystemRoot/presentation/Html.inc");
require_once("$default->fileSystemRoot/presentation/lookAndFeel/knowledgeTree/administration/adminUI.inc");
require_once("addUserUI.inc");
if (checkSession()) {
require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc");
$oPatternCustom = & new PatternCustom();
//create db object
$oAuth = new $default->authenticationClass;
// user attributes to search for
if ($default->authenticationClass == "DBAuthenticator") {
$aAttributes = array ("username", "name", "email", "mobile", "email_notification");
$bLdap = false;
} else {
//if its using LDAP get these attributes
// FIXME: move these to $default(ldapSettings.inc) and map them to DN, username, display name, email, mobile
if ($default->ldapServerType == "ActiveDirectory") {
$aAttributes = array ("dn", "samaccountname", "givenname", "sn", "userPrincipalName", "telephonenumber");
} else {
$aAttributes = array ("dn", "uid", "givenname", "sn", "mail", "mobile");
}
$bLdap = true;
}
if (isset($fSearch)) {
//get user name
$sSearch = $fName;
// search for users
$aResults = $oAuth->searchUsers($sSearch, $aAttributes);
//post array to page
if (isset($aResults)) {
if(count($aResults) == 0) {
$oPatternCustom->setHtml(getPageUsernameNotFound());
} else {
if (count($aResults) > 1) {
// display results in a listbox
$oPatternCustom->setHtml(getSelectUserPage($aResults));
$main->setFormAction($_SERVER["PHP_SELF"]. "?fSelectedUser=1");
} else {
if($bLdap) {
$oPatternCustom->setHtml(getDetailsLDAPPage($sSearch,$aResults, $oAuth->oLdap->getUserIdentifier()));
if ($default->bNN4) {
$main->setOnLoadJavaScript("disable(document.MainForm.fLdap);disable(document.MainForm.fUsername)");
}
$main->setFormAction($_SERVER["PHP_SELF"]. "?fAddToDb=1");
} else {
$oPatternCustom->setHtml(getDetailsDBPage($sSearch,$aResults));
$main->setFormAction($_SERVER["PHP_SELF"]. "?fAddToDb=1&fFromDb=1");
}
}
}
} else {
$oPatternCustom->setHtml(getAddPageFail());
$main->setFormAction($_SERVER["PHP_SELF"]);
}
} else if (isset($fSelectedUser)) {
// user has been selected
// retrieve user details
$aResult = $oAuth->getUser($fName, $aAttributes);
// display details page
if ($bLdap) {
$oPatternCustom->setHtml(getDetailsLDAPPage($fName,$aResult, $oAuth->oLdap->getUserIdentifier()));
if ($default->bNN4) {
$main->setOnLoadJavaScript("disable(document.MainForm.fLdap);disable(document.MainForm.fUsername)");
}
$main->setFormAction($_SERVER["PHP_SELF"]. "?fAddToDb=1");
} else {
$oPatternCustom->setHtml(getDetailsDBPage($fName,$aResult));
$main->setFormAction($_SERVER["PHP_SELF"]. "?fAddToDb=1&fFromDb=1");
}
} else if(isset($fAddToDb)) {
// if db authentication
if(isset($fFromDb)) {
$oUser = new User($fUsername,$fName,$fPassword,0,$fEmail,$fMobile,$fEmailNotification,false,0,1,0);
} else {
$oUser = new User($fUsername,$fName,0,0,$fEmail,$fMobile,$fEmailNotification,false,$fLdap,1,0);
}
if($oUser->create()) {
// now add the user to the initial group
$default->log->info("adding user id " . $oUser->getID() . " to group id $fGroupID");
$oUserGroup = new GroupUserLink($fGroupID,$oUser->getID());
if ($oUserGroup->create()) {
// FIXME: update search permissions for the group
// redirect to list page
controllerRedirect("listUsers");
} else {
$oPatternCustom->setHtml(getPageGroupFail());
}
} else {
$oPatternCustom->setHtml(getPageFail());
}
} else {
if ($default->authenticationClass == "DBAuthenticator") {
$aAttributes = array("" => array ("username", "name", "email", "mobile", "email_notification"));
$oPatternCustom->setHtml(getDetailsDBPage(null,$aAttributes));
$main->setFormAction($_SERVER["PHP_SELF"]. "?fAddToDb=1&fFromDb=1");
} else {
// if nothing happens...just reload edit page
$oPatternCustom->setHtml(getSearchPage(null));
$main->setFormAction($_SERVER["PHP_SELF"]. "?fSearch=1");
}
}
$main->setCentralPayload($oPatternCustom);
$main->setHasRequiredFields(true);
$main->render();
}
?>