-
Notifications
You must be signed in to change notification settings - Fork 0
/
hooks.php
142 lines (124 loc) · 6.56 KB
/
hooks.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
138
139
140
141
142
<?php
add_hook('AdminAreaFooterOutput', 1, function() {
$html = <<<HTML
</li><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css" integrity="sha512-iecdLmaskl7CVkqkXNQ/ZH/XLlvWZOJyj7Yy7tcenmpD1ypASozpmT/E0iPtmFIB46ZmdtAc9eNBvH0H/ZpiBw==" crossorigin="anonymous" referrerpolicy="no-referrer" />
<li><a href="#" data-toggle="modal" data-target="#modalPasswordChange"><i class="fa-solid fa-key"></i> Change Password</>
</a></li>
</li>
HTML;
return '<script type="text/javascript">jQuery("#summary-login-as-owner").parent().parent().append("' . preg_replace("/\r|\n/", "", str_replace('"', '\"', $html)) . '")</script>';
});
add_hook('AdminAreaFooterOutput', 1, function($vars){
$clientId = $_GET['userid'];
if($vars['helplink'] === 'Clients:Users_Tab')
{
$clientId = 'N/A';
}
return <<<HTML
<div class="modal fade" id="modalPasswordChange" role="dialog" aria-labelledby="PasswordResetLabel" aria-hidden="true">
<div class="modal-dialog">
<form action="#" onsubmit="sendRequest()" id="passwordChangeForm">
<div class="modal-content panel panel-primary">
<div id="modalPasswordChangeHeading" class="modal-header panel-heading">
<button type="button" class="close" data-dismiss="modal">
<span aria-hidden="true">×</span>
<span class="sr-only">Close</span>
</button>
<h4 class="modal-title" id="GenerateInvoicesLabel">Change User's Password</h4>
</div>
<div id="modalPasswordChangeBody" class="modal-body panel-body">
<div class="form-group">
<label for="password">New Password</label>
<input type="password" class="form-control" id="password" aria-describedby="passwordHelp" required>
<input type="hidden" id="userid" value="$clientId">
</div>
<div class="form-group">
<label for="confirmPassword">Confirm Password</label>
<input type="password" class="form-control" id="confirmPassword" aria-describedby="confirmPasswordHelp" required>
</div>
<div class="form-group form-check">
<input type="checkbox" name="sendToClient" class="form-check-input" id="sendToClient">
<label class="form-check-label" id="sendToClient" for="sendToClient">Send new password to client</label>
</div>
</div>
<div id="modalPasswordChangeFooter" class="modal-footer panel-footer">
<button type="submit" id="PasswordReset-Send" class="btn btn-primary">Set password</button>
<button type="button" id="PasswordReset-Cancel" class="btn btn-default" data-dismiss="modal">Cancel</button>
</div>
</div>
</form>
</div>
</div>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/toastr.css" integrity="sha512-3pIirOrwegjM6erE5gPSwkUzO+3cTjpnV9lexlNZqvupR64iZBnOOTiiLPb9M36zpMScbmUNIcHUqKD47M719g==" crossorigin="anonymous" referrerpolicy="no-referrer" />
HTML;
});
add_hook('AdminAreaFooterOutput', 1, function() {
return <<<HTML
<script type="text/JavaScript">
$(document).ready(function () {
// Listen to submit event on the <form> itself!
$('#passwordChangeForm').submit(function (e) {
// Prevent form submission which refreshes page
e.preventDefault();
});
});
function sendRequest() {
let xhr = new XMLHttpRequest();
xhr.open("POST", "addonmodules.php?module=PasswordChange&action=changePassword", true);
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xhr.onreadystatechange = function () {
if (xhr.readyState === 4) {
const response = JSON.parse(xhr.responseText);
toastr.options = {
"closeButton": true,
"progressBar": true,
"newestOnTop": false,
"positionClass": "toast-bottom-right",
"showDuration": "300",
"hideDuration": "1000",
"timeOut": "5000",
"extendedTimeOut": "1000",
"showEasing": "swing",
"hideEasing": "linear",
"showMethod": "fadeIn",
"hideMethod": "fadeOut"
}
if(response.result === 'error'){
if(response.message === 'emptyFields'){
toastr.error('Required fields are empty');
}else if(response.message === 'idIsNotAnInt'){
toastr.error('User ID is not an integer');
}else if(response.message === 'notmatching'){
toastr.error('Passwords does not match');
}else{
toastr.error('Unknown error');
}
}else{
if(response.message === 'sentToClient'){
toastr.success('Password has been changed and sent to client');
}else{
toastr.success('Password has been changed');
}
document.getElementById("password").value = '';
document.getElementById("confirmPassword").value = '';
}
}};
let password1 = document.getElementById("password").value;
let password2 = document.getElementById("confirmPassword").value;
let sendToClient = document.getElementById('sendToClient').checked;
let userId = document.getElementById('userid').value;
xhr.send("userid="+userId+"&password="+password1+"&confirmPassword="+password2+"&sendToClient="+sendToClient);
}
</script>
HTML;
});
add_hook('AdminAreaFooterOutput', 1, function() {
return <<<HTML
<script src="https://cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/toastr.min.js" integrity="sha512-VEd+nq25CkR676O+pLBnDW09R7VQX9Mdiij052gVCp5yVH3jGtH70Ho/UUv4mJDsEdTvqRCFZg0NKGiojGnUCw==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
HTML;
});
add_hook('AdminAreaFooterOutput', 1, function() {
return <<<HTML
<script>element = document.getElementById('Menu-Addons-Password Change for WHMCS').parentElement.remove();</script>
HTML;
});