forked from projectsend/projectsend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclients-edit.php
158 lines (135 loc) · 4.95 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
<?php
/**
* Show the form to edit an existing client.
*/
$allowed_levels = array(9, 8, 0);
require_once 'bootstrap.php';
$active_nav = 'clients';
// Check if the id parameter is on the URI.
if (!isset($_GET['id'])) {
exit_with_error_code(403);
}
$client_id = (int)$_GET['id'];
if (!client_exists_id($client_id)) {
exit_with_error_code(403);
}
// Create the object
$edit_client = new \ProjectSend\Classes\Users($client_id);
$client_arguments = $edit_client->getProperties();
// Get groups where this client is member
$get_groups = new \ProjectSend\Classes\GroupsMemberships;
$get_arguments = [
'client_id' => $client_id,
];
$found_groups = $get_groups->getGroupsByClient($get_arguments);
// Get current membership requests
$get_arguments['denied'] = 0;
$found_requests = $get_groups->getMembershipRequests($get_arguments);
// Form type
if (CURRENT_USER_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 (CURRENT_USER_LEVEL == 0) {
if (isset($client_arguments) && CURRENT_USER_USERNAME != $client_arguments['username']) {
exit_with_error_code(403);
}
}
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 (CURRENT_USER_LEVEL == 0 || CURRENT_USER_LEVEL == 7) {
if ($client_id != CURRENT_USER_ID) {
exit_with_error_code(403);
}
}
/**
* 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.
*/
$client_arguments = array(
'id' => $client_id,
'username' => $_POST['username'],
'role' => 0,
'name' => $_POST['name'],
'email' => $_POST['email'],
'address' => (isset($_POST["address"])) ? $_POST['address'] : null,
'phone' => (isset($_POST["phone"])) ? $_POST['phone'] : null,
'contact' => (isset($_POST["contact"])) ? $_POST['contact'] : null,
'notify_upload' => (isset($_POST["notify_upload"])) ? 1 : 0,
'max_file_size' => $client_arguments['max_file_size'],
'can_upload_public' => $client_arguments['can_upload_public'],
'active' => $client_arguments['active'],
'type' => 'edit_client',
);
if ($ignore_size == false) {
$client_arguments['max_file_size'] = (isset($_POST["max_file_size"])) ? $_POST["max_file_size"] : null;
}
if (CURRENT_USER_LEVEL != 0) {
$client_arguments['can_upload_public'] = (isset($_POST["can_upload_public"])) ? 1 : 0;
$client_arguments['active'] = (isset($_POST["active"])) ? 1 : 0;
}
/**
* If the password field, or the verification are not completed,
* send an empty value to prevent notices.
*/
$client_arguments['password'] = (isset($_POST['password'])) ? $_POST['password'] : null;
/** Validate the information from the posted form. */
$edit_client->set($client_arguments);
$edit_client->setType("existing_client");
$edit_response = $edit_client->edit();
$edit_groups = (!empty($_POST['groups_request'])) ? $_POST['groups_request'] : array();
$memberships = new \ProjectSend\Classes\GroupsMemberships;
$arguments = [
'client_id' => $client_id,
'group_ids' => $edit_groups,
'request_by' => CURRENT_USER_USERNAME,
];
if (in_array(CURRENT_USER_LEVEL, [8, 9])) {
$memberships->clientEditGroups($arguments);
} else {
$memberships->updateMembershipRequests($arguments);
}
if ($edit_response['query'] == 1) {
if ($client_id == CURRENT_USER_ID) {
$flash->success(__('Profile edited successfully'));
} else {
$flash->success(__('Client saved successfully'));
}
} else {
$flash->error(__('There was an error saving to the database'));
}
ps_redirect(BASE_URI . 'clients-edit.php?id=' . $client_id);
}
$page_title = __('Edit client', 'cftp_admin');
if (isset($client_arguments['username']) && CURRENT_USER_USERNAME == $client_arguments['username']) {
$page_title = __('My account', 'cftp_admin');
}
$page_id = 'client_form';
include_once ADMIN_VIEWS_DIR . DS . 'header.php';
?>
<div class="row">
<div class="col-12 col-sm-12 col-lg-6">
<div class="white-box">
<div class="white-box-interior">
<?php
// If the form was submitted with errors, show them here.
echo $edit_client->getValidationErrors();
include_once FORMS_DIR . DS . 'clients.php';
?>
</div>
</div>
</div>
</div>
<?php
include_once ADMIN_VIEWS_DIR . DS . 'footer.php';