forked from projectsend/projectsend
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclients-add.php
More file actions
129 lines (113 loc) · 4.5 KB
/
clients-add.php
File metadata and controls
129 lines (113 loc) · 4.5 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
<?php
/**
* Show the form to add a new client.
*/
require_once 'bootstrap.php';
check_access_enhanced(['create_clients', 'manage_clients'], 'any');
$active_nav = 'clients';
$page_title = __('Add client', 'cftp_admin');
$page_id = 'client_form';
$new_client = new \ProjectSend\Classes\Users();
include_once ADMIN_VIEWS_DIR . DS . 'header.php';
// Set checkboxes as 1 to default them to checked when first entering the form
$client_arguments = array(
'notify_upload' => 1,
'active' => 1,
'notify_account' => 1,
'require_password_change' => 1,
);
if ($_POST) {
/**
* Clean the posted form values to be used on the clients actions,
* and again on the form if validation failed.
*/
$client_arguments = array(
'username' => $_POST['username'],
'password' => $_POST['password'],
'name' => $_POST['name'],
'email' => $_POST['email'],
'role_id' => \ProjectSend\Classes\Roles::getClientRoleId(),
'address' => (isset($_POST["address"])) ? $_POST['address'] : '',
'phone' => (isset($_POST["phone"])) ? $_POST['phone'] : '',
'contact' => (isset($_POST["contact"])) ? $_POST['contact'] : '',
'max_file_size' => (isset($_POST["max_file_size"])) ? $_POST['max_file_size'] : '',
'max_disk_quota' => (isset($_POST["max_disk_quota"])) ? $_POST['max_disk_quota'] : '',
'notify_upload' => (isset($_POST["notify_upload"])) ? 1 : 0,
'notify_account' => (isset($_POST["notify_account"])) ? 1 : 0,
'active' => (isset($_POST["active"])) ? 1 : 0,
'can_upload_public' => (isset($_POST["can_upload_public"])) ? 1 : 0,
'require_password_change' => (isset($_POST["require_password_change"])) ? true : false,
'type' => 'new_client',
);
// Process custom fields
$custom_field_data = [];
foreach ($_POST as $key => $value) {
if (strpos($key, 'custom_field_') === 0) {
$field_id = str_replace('custom_field_', '', $key);
$custom_field_data[$field_id] = $value;
}
}
// Validate the information from the posted form.
$new_client->setType('new_client');
$new_client->set($client_arguments);
$new_client->custom_field_data = $custom_field_data;
$create = $new_client->create();
// Record the action log
$logger = new \ProjectSend\Classes\ActionsLog;
$record = $logger->addEntry([
'action' => 3,
'owner_user' => CURRENT_USER_USERNAME,
'owner_id' => CURRENT_USER_ID,
'affected_account' => $new_client->id,
'affected_account_name' => $new_client->name
]);
$add_to_groups = (!empty($_POST['groups_request'])) ? $_POST['groups_request'] : '';
if (!empty($add_to_groups)) {
array_map('encode_html', $add_to_groups);
$memberships = new \ProjectSend\Classes\GroupsMemberships;
$memberships->clientAddToGroups([
'client_id' => $new_client->getId(),
'group_ids' => $add_to_groups,
'added_by' => CURRENT_USER_USERNAME,
]);
}
if ($create['status'] === 'success') {
$flash->success($create['message']);
if (isset($create['email'])) {
switch ($create['email']) {
case 2:
$flash->success(__('A welcome message was not sent to the new account owner.', 'cftp_admin'));
break;
case 1:
$flash->success(__('A welcome message with login information was sent to the new account owner.', 'cftp_admin'));
break;
case 0:
$flash->error(__("E-mail notification couldn't be sent.", 'cftp_admin'));
break;
}
}
ps_redirect(BASE_URI . 'clients-edit.php?id=' . $create['id']);
} else {
// Don't redirect on error - let the page continue to render with form values intact
}
}
?>
<div class="row">
<div class="col-12 col-sm-12 col-lg-6">
<div class="white-box">
<div class="white-box-interior">
<?php
// Display validation errors if form submission failed
if (!empty($create['errors'])) {
echo $create['errors'];
}
// If the form was submitted with errors, show them here.
$clients_form_type = 'new_client';
include_once FORMS_DIR . DS . 'clients.php';
?>
</div>
</div>
</div>
</div>
<?php
include_once ADMIN_VIEWS_DIR . DS . 'footer.php';