forked from poppyred/1.6.x
/
domains.edit.user.moveorg.php
executable file
·137 lines (96 loc) · 3.14 KB
/
domains.edit.user.moveorg.php
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
<?php
include_once('ressources/class.templates.inc');
include_once('ressources/class.ldap.inc');
include_once('ressources/class.users.menus.inc');
include_once('ressources/class.user.inc');
include_once('ressources/class.ini.inc');
if(!CheckRights()){
$tpl=new templates();
$error=$tpl->_ENGINE_parse_body("{ERROR_NO_PRIVS}");
echo "alert('$error')";
die();
}
if(isset($_GET["popup"])){popup();exit;}
if(isset($_POST["nextou"])){moveuser();exit;}
js();
function js(){
$page=CurrentPageName();
$tpl=new templates();
$uid=$_GET["userid"];
$title=$tpl->_ENGINE_parse_body($uid.'::{change_organization}');
$html="
function user_changeorg_load(){
YahooWin4('500','$page?popup=yes&userid={$_GET["userid"]}','$title');
}
user_changeorg_load();";
echo $html;
}
function popup(){
$page=CurrentPageName();
$tpl=new templates();
$ldap=new clladp();
$u=new user($_GET["userid"]);
$oldorg=$u->ou;
$ous=$ldap->hash_get_ou(true);
unset($ous[$u->ou]);
$ous[null]="{select}";
$success=$tpl->javascript_parse_text("{success}");
$field=Field_array_Hash($ous,"nextou",null,"style:font-size:16px;padding:3px");
$html="
<div class=explain id='useranimateddiv'>{change_user_organization_text}</div>
<table style='width:99%' class=form>
<tr>
<td class=legend>{organization}:</td>
<td>$field</td>
</tr>
<tr>
<td colspan=2 align=right><hr>". button("{move}","MoveUserToOu()")."</td>
</tr>
</table>
<script>
function MoveUserToOu(){
var XHR = new XHRConnection();
AnimateDiv('useranimateddiv');
XHR.appendData('nextou',document.getElementById('nextou').value);
XHR.appendData('ou','$u->ou');
XHR.appendData('userid','{$_GET["userid"]}');
XHR.sendAndLoad('$page', 'POST',x_MoveUserToOu);
}
var x_MoveUserToOu= function (obj) {
var ou=document.getElementById('nextou').value;
var results=trim(obj.responseText);
if(results.length>2){alert('<'+results+'>');user_changeorg_load();return;}
YahooUserHide();
YahooWin4Hide();
if(document.getElementById('org_main')){RefreshTab('org_main');}
alert('$success {$_GET["userid"]} -> '+ou);
}
</script>
";
echo $tpl->_ENGINE_parse_body($html);
}
function moveuser(){
$u=new user($_POST["userid"]);
$dn=$u->dn;
$gplist=$u->Groups_list();
if(preg_match("#^(.+?),#", $dn,$re)){$newRdn=$re[1];}else{$newRdn="cn={$_POST["userid"]}";}
$ldap=new clladp();
$newParent="ou=users,ou={$_POST["nextou"]},dc=organizations,$ldap->suffix";
if(!ldap_rename($ldap->ldap_connection, $dn, $newRdn, $newParent, true)){
echo 'Error number ' . ldap_errno($ldap->ldap_connection) . "\nAction:LDAP Ldap_rename\ndn:$dn -> $newRdn,$newParent\n" . ldap_err2str(ldap_errno($ldap->ldap_connection));
return;
}
while ( list ( $gid, $name ) = each ( $gplist ) ) {
$gp=new groups($gid);
$gp->DeleteUserFromThisGroup($_POST["userid"]);
}
}
function CheckRights(){
if(!$_REQUEST["userid"]){return false;}
$usersprivs=new usersMenus();
if($usersprivs->AsSystemAdministrator){return true;}
if($usersprivs->AsAnAdministratorGeneric){return true;}
if($usersprivs->AllowAddGroup){return true;}
if($usersprivs->AllowAddUsers){return true;}
return false;
}