addUserBL.php
5.63 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
<?php
/**
* BL information for adding a unit
*
* @author Mukhtar Dharsey
* @date 5 February 2003
* @package presentation.lookAndFeel.knowledgeTree.
*
*/
require_once("../../../../../config/dmsDefaults.php");
if (checkSession()) {
require_once("$default->fileSystemRoot/lib/visualpatterns/PatternListBox.inc");
require_once("$default->fileSystemRoot/lib/visualpatterns/PatternCreate.inc");
require_once("addUserUI.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/presentation/webpageTemplate.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");
$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", "sms_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,$fSmsNotification,0,1,0);
} else {
$oUser = new User($fUsername,$fName,0,0,$fEmail,$fMobile,$fEmailNotification,$fSmsNotification,$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()) {
$oPatternCustom->setHtml(getPageSuccess());
} else {
$oPatternCustom->setHtml(getPageGroupFail());
}
} else {
$oPatternCustom->setHtml(getPageFail());
}
} else {
if ($default->authenticationClass == "DBAuthenticator") {
$aAttributes = array("" => array ("username", "name", "email", "mobile", "email_notification", "sms_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();
}
?>