forked from projectsend/projectsend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
clients-edit.php
249 lines (219 loc) · 7.41 KB
/
clients-edit.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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
<?php
/**
* Show the form to edit an existing client.
*
* @package ProjectSend
* @subpackage Clients
*
*/
$load_scripts = array(
'chosen',
);
$allowed_levels = array(9,8,0);
require_once('sys.includes.php');
$active_nav = 'clients';
/** Create the object */
$edit_client = new ClientActions();
/** Check if the id parameter is on the URI. */
if (isset($_GET['id'])) {
$client_id = $_GET['id'];
$page_status = (client_exists_id($client_id)) ? 1 : 2;
}
else {
/**
* Return 0 if the id is not set.
*/
$page_status = 0;
}
/**
* Get the clients information from the database to use on the form.
*/
if ($page_status === 1) {
$editing = $dbh->prepare("SELECT * FROM " . TABLE_USERS . " WHERE id=:id");
$editing->bindParam(':id', $client_id, PDO::PARAM_INT);
$editing->execute();
$editing->setFetchMode(PDO::FETCH_ASSOC);
while ( $data = $editing->fetch() ) {
$add_client_data_name = $data['name'];
$add_client_data_user = $data['user'];
$add_client_data_email = $data['email'];
$add_client_data_addr = $data['address'];
$add_client_data_phone = $data['phone'];
$add_client_data_intcont = $data['contact'];
$add_client_data_maxfilesize = $data['max_file_size'];
if ($data['notify'] == 1) { $add_client_data_notity = 1; } else { $add_client_data_notity = 0; }
if ($data['active'] == 1) { $add_client_data_active = 1; } else { $add_client_data_active = 0; }
}
/** Get groups where this client is member */
$get_groups = new MembersActions();
$get_arguments = array(
'client_id' => $client_id,
);
$found_groups = $get_groups->client_get_groups($get_arguments);
/** Get current membership requests */
$get_arguments['denied'] = 0;
$found_requests = $get_groups->get_membership_requests($get_arguments);
}
/**
* Form type
*/
if ($global_level != 0) {
$clients_form_type = 'edit_client';
$ignore_size = false;
}
else {
$clients_form_type = 'edit_client_self';
define('EDITING_SELF_ACCOUNT', true);
$ignore_size = true;
}
/**
* Compare the client editing this account to the on the db.
*/
if ($global_level == 0) {
if (isset($add_client_data_user) && $global_user != $add_client_data_user) {
$page_status = 3;
}
}
if ($_POST) {
/**
* If the user is not an admin, check if the id of the client
* that's being edited is the same as the current logged in one.
*/
if ($global_level == 0 || $global_level == 7) {
if ($client_id != CURRENT_USER_ID) {
die();
}
}
/**
* Clean the posted form values to be used on the user actions,
* and again on the form if validation failed.
* Also, overwrites the values gotten from the database so if
* validation failed, the new unsaved values are shown to avoid
* having to type them again.
*/
$add_client_data_name = $_POST['add_client_form_name'];
$add_client_data_user = $_POST['add_client_form_user'];
$add_client_data_email = $_POST['add_client_form_email'];
/** Optional fields: Address, Phone, Internal Contact, Notify */
$add_client_data_addr = (isset($_POST["add_client_form_address"])) ? $_POST["add_client_form_address"] : '';
$add_client_data_phone = (isset($_POST["add_client_form_phone"])) ? $_POST["add_client_form_phone"] : '';
$add_client_data_intcont = (isset($_POST["add_client_form_intcont"])) ? $_POST["add_client_form_intcont"] : '';
$add_client_data_notity = (isset($_POST["add_client_form_notify"])) ? 1 : 0;
if ( $ignore_size == false ) {
$add_client_data_maxfilesize = (isset($_POST["add_client_form_maxfilesize"])) ? $_POST["add_client_form_maxfilesize"] : '';
}
else {
$add_client_data_maxfilesize = $add_client_data_maxfilesize;
}
if ($global_level != 0) {
$add_client_data_active = (isset($_POST["add_client_form_active"])) ? 1 : 0;
}
/** Arguments used on validation and client creation. */
$edit_arguments = array(
'id' => $client_id,
'username' => $add_client_data_user,
'name' => $add_client_data_name,
'email' => $add_client_data_email,
'address' => $add_client_data_addr,
'phone' => $add_client_data_phone,
'contact' => $add_client_data_intcont,
'notify' => $add_client_data_notity,
'active' => $add_client_data_active,
'max_file_size' => $add_client_data_maxfilesize,
'type' => 'edit_client'
);
/**
* If the password field, or the verification are not completed,
* send an empty value to prevent notices.
*/
$edit_arguments['password'] = (isset($_POST['add_client_form_pass'])) ? $_POST['add_client_form_pass'] : '';
//$edit_arguments['password_repeat'] = (isset($_POST['add_client_form_pass2'])) ? $_POST['add_client_form_pass2'] : '';
/** Validate the information from the posted form. */
$edit_validate = $edit_client->validate_client($edit_arguments);
/** Create the client if validation is correct. */
if ($edit_validate == 1) {
$edit_response = $edit_client->edit_client($edit_arguments);
$edit_groups = (!empty( $_POST['add_client_group_request'] ) ) ? $_POST['add_client_group_request'] : array();
$memberships = new MembersActions;
$arguments = array(
'client_id' => $client_id,
'group_ids' => $edit_groups,
'request_by' => CURRENT_USER_USERNAME,
);
$memberships->group_request_membership($arguments);
}
$location = BASE_URI . 'clients-edit.php?id=' . $client_id . '&status=' . $edit_response['query'];
header("Location: $location");
die();
}
$page_title = __('Edit client','cftp_admin');
if (isset($add_client_data_user) && $global_user == $add_client_data_user) {
$page_title = __('My account','cftp_admin');
}
include('header.php');
?>
<div class="col-xs-12 col-sm-12 col-lg-6">
<?php
if (isset($_GET['status'])) {
/**
* Get the process state and show the corresponding ok or error message.
*/
switch ($_GET['status']) {
case 1:
$msg = __('Client edited correctly.','cftp_admin');
echo system_message('ok',$msg);
$saved_client = get_client_by_id($client_id);
/** Record the action log */
$new_log_action = new LogActions();
$log_action_args = array(
'action' => 14,
'owner_id' => CURRENT_USER_ID,
'affected_account' => $client_id,
'affected_account_name' => $saved_client['username'],
'get_user_real_name' => true
);
$new_record_action = $new_log_action->log_action_save($log_action_args);
break;
case 0:
$msg = __('There was an error. Please try again.','cftp_admin');
echo system_message('error',$msg);
break;
}
}
?>
<div class="white-box">
<div class="white-box-interior">
<?php
/**
* If the form was submited with errors, show them here.
*/
$valid_me->list_errors();
?>
<?php
$direct_access_error = __('This page is not intended to be accessed directly.','cftp_admin');
if ($page_status === 0) {
$msg = __('No client was selected.','cftp_admin');
echo system_message('error',$msg);
echo '<p>'.$direct_access_error.'</p>';
}
else if ($page_status === 2) {
$msg = __('There is no client with that ID number.','cftp_admin');
echo system_message('error',$msg);
echo '<p>'.$direct_access_error.'</p>';
}
else if ($page_status === 3) {
$msg = __("Your account type doesn't allow you to access this feature.",'cftp_admin');
echo system_message('error',$msg);
}
else {
/**
* Include the form.
*/
include('clients-form.php');
}
?>
</div>
</div>
</div>
<?php
include('footer.php');