-
Notifications
You must be signed in to change notification settings - Fork 0
/
groups.php
executable file
·434 lines (382 loc) · 12.5 KB
/
groups.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
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
<?php
/**
* Show the list of current groups.
*
* @package ProjectSend
* @subpackage Groups
*
*/
$footable_min = true; // delete this line after finishing pagination on every table
$load_scripts = array(
'footable',
);
$allowed_levels = array(9,8);
require_once('sys.includes.php');
$active_nav = 'groups';
$page_title = __('Groups administration','cftp_admin');
/**
* Used when viewing groups a certain client belongs to.
*/
if(!empty($_GET['member'])) {
$member = $_GET['member'];
/** Add the name of the client to the page's title. */
$sql_name = $dbh->prepare("SELECT name from " . TABLE_USERS . " WHERE id=:id");
$sql_name->bindParam(':id', $member, PDO::PARAM_INT);
$sql_name->execute();
if ( $sql_name->rowCount() > 0) {
$sql_name->setFetchMode(PDO::FETCH_ASSOC);
while ( $row_member = $sql_name->fetch() ) {
$page_title = ' '.__('Groups where','cftp_admin').' '.html_entity_decode($row_member['name']).' '.__('is member','cftp_admin');
}
$member_exists = 1;
/** Get groups where this client is member */
$get_groups = new MembersActions();
$get_arguments = array(
'client_id' => $member,
'return' => 'list',
);
$found_groups = $get_groups->client_get_groups($get_arguments);
if ( empty( $found_groups ) ) {
$found_groups = '';
}
}
else {
$no_results_error = 'client_not_exists';
}
}
include('header.php');
?>
<div class="col-xs-12">
<?php
/**
* Apply the corresponding action to the selected users.
*/
if(isset($_GET['action']) && $_GET['action'] != 'none') {
/** Continue only if 1 or more users were selected. */
if(!empty($_GET['batch'])) {
$selected_groups = $_GET['batch'];
$groups_to_get = implode( ',', array_map( 'intval', array_unique( $selected_groups ) ) );
/**
* Make a list of groups to avoid individual queries.
*/
$sql_grps = $dbh->prepare("SELECT id, name FROM " . TABLE_GROUPS . " WHERE FIND_IN_SET(id, :groups)");
$sql_grps->bindParam(':groups', $groups_to_get);
$sql_grps->execute();
$sql_grps->setFetchMode(PDO::FETCH_ASSOC);
while( $data_group = $sql_grps->fetch() ) {
$all_groups[$data_group['id']] = $data_group['name'];
}
switch($_GET['action']) {
case 'delete':
$deleted_groups = 0;
foreach ($selected_groups as $groups) {
$this_group = new GroupActions();
$delete_group = $this_group->delete_group($groups);
$deleted_groups++;
/** Record the action log */
$new_log_action = new LogActions();
$log_action_args = array(
'action' => 18,
'owner_id' => CURRENT_USER_ID,
'affected_account_name' => $all_groups[$groups]
);
$new_record_action = $new_log_action->log_action_save($log_action_args);
}
if ($deleted_groups > 0) {
$msg = __('The selected groups were deleted.','cftp_admin');
echo system_message('ok',$msg);
}
break;
}
}
else {
$msg = __('Please select at least one group.','cftp_admin');
echo system_message('error',$msg);
}
}
/**
* Generate the list of available groups.
*/
/**
* Generate an array of file count per group
*/
$files_amount = array();
$count_files_sql = $dbh->prepare("SELECT group_id, COUNT(file_id) as files FROM " . TABLE_FILES_RELATIONS . " WHERE group_id IS NOT NULL GROUP BY group_id");
$count_files_sql->execute();
$count_files = $count_files_sql->rowCount();
if ($count_files > 0) {
$count_files_sql->setFetchMode(PDO::FETCH_ASSOC);
while ( $crow = $count_files_sql->fetch() ) {
$files_amount[$crow['group_id']] = $crow['files'];
}
}
/**
* Generate an array of amount of users on each group
*/
$members_amount = array();
$count_members_sql = $dbh->prepare("SELECT group_id, COUNT(client_id) as members FROM " . TABLE_MEMBERS . " GROUP BY group_id");
$count_members_sql->execute();
$count_members = $count_members_sql->rowCount();
if ($count_members > 0) {
while ( $mrow = $count_members_sql->fetch() ) {
$members_amount[$mrow['group_id']] = $mrow['members'];
}
}
$params = array();
$cq = "SELECT * FROM " . TABLE_GROUPS;
/** Add the search terms */
if ( isset( $_GET['search'] ) && !empty( $_GET['search'] ) ) {
$cq .= " WHERE (name LIKE :name OR description LIKE :description)";
$next_clause = ' AND';
$no_results_error = 'search';
$search_terms = '%'.$_GET['search'].'%';
$params[':name'] = $search_terms;
$params[':description'] = $search_terms;
}
else {
$next_clause = ' WHERE';
}
/** Add the member */
if (isset($found_groups)) {
if ($found_groups != '') {
$cq .= $next_clause. " FIND_IN_SET(id, :groups)";
$params[':groups'] = $found_groups;
}
else {
$cq .= $next_clause. " id = NULL";
}
$no_results_error = 'is_not_member';
}
/**
* Add the order.
* Defaults to order by: name, order: ASC
*/
$cq .= sql_add_order( TABLE_GROUPS, 'name', 'asc' );
/**
* Pre-query to count the total results
*/
$count_sql = $dbh->prepare( $cq );
$count_sql->execute($params);
$count_for_pagination = $count_sql->rowCount();
/**
* Repeat the query but this time, limited by pagination
*/
$cq .= " LIMIT :limit_start, :limit_number";
$sql = $dbh->prepare( $cq );
$pagination_page = ( isset( $_GET["page"] ) ) ? $_GET["page"] : 1;
$pagination_start = ( $pagination_page - 1 ) * RESULTS_PER_PAGE;
$params[':limit_start'] = $pagination_start;
$params[':limit_number'] = RESULTS_PER_PAGE;
$sql->execute( $params );
$count = $sql->rowCount();
?>
<div class="form_actions_left">
<div class="form_actions_limit_results">
<?php show_search_form('groups.php'); ?>
</div>
</div>
<form action="groups.php" name="groups_list" method="get" class="form-inline">
<?php form_add_existing_parameters(); ?>
<div class="form_actions_right">
<div class="form_actions">
<div class="form_actions_submit">
<div class="form-group group_float">
<label class="control-label hidden-xs hidden-sm"><i class="glyphicon glyphicon-check"></i> <?php _e('Selected groups actions','cftp_admin'); ?>:</label>
<select name="action" id="action" class="txtfield form-control">
<?php
$actions_options = array(
'none' => __('Select action','cftp_admin'),
'delete' => __('Delete','cftp_admin'),
);
foreach ( $actions_options as $val => $text ) {
?>
<option value="<?php echo $val; ?>"><?php echo $text; ?></option>
<?php
}
?>
</select>
</div>
<button type="submit" id="do_action" class="btn btn-sm btn-default"><?php _e('Proceed','cftp_admin'); ?></button>
</div>
</div>
</div>
<div class="clear"></div>
<div class="form_actions_count">
<p><?php _e('Found','cftp_admin'); ?>: <span><?php echo $count_for_pagination; ?> <?php _e('groups','cftp_admin'); ?></span></p>
</div>
<div class="clear"></div>
<?php
if (!$count) {
if (isset($no_results_error)) {
switch ($no_results_error) {
case 'search':
$no_results_message = __('Your search keywords returned no results.','cftp_admin');
break;
case 'filter':
$no_results_message = __('The filters you selected returned no results.','cftp_admin');
break;
case 'client_not_exists':
$no_results_message = __('The client does not exist.','cftp_admin');
break;
case 'is_not_member':
$no_results_message = __('There are no groups where this client is member.','cftp_admin');
break;
}
}
else {
$no_results_message = __('There are no groups created yet.','cftp_admin');
}
echo system_message('error',$no_results_message);
}
if ($count > 0) {
/**
* Generate the table using the class.
*/
$table_attributes = array(
'id' => 'groups_tbl',
'class' => 'footable table',
);
$table = new generateTable( $table_attributes );
$thead_columns = array(
array(
'select_all' => true,
'attributes' => array(
'class' => array( 'td_checkbox' ),
),
),
array(
'sortable' => true,
'sort_url' => 'name',
'sort_default' => true,
'content' => __('Group name','cftp_admin'),
),
array(
'sortable' => true,
'sort_url' => 'description',
'content' => __('Description','cftp_admin'),
'hide' => 'phone',
),
array(
'content' => __('Members','cftp_admin'),
),
array(
'content' => __('Files','cftp_admin'),
'hide' => 'phone',
),
array(
'sortable' => true,
'sort_url' => 'active',
'content' => __('Public','cftp_admin'),
),
array(
'sortable' => true,
'sort_url' => 'created_by',
'content' => __('Created by','cftp_admin'),
'hide' => 'phone',
),
array(
'sortable' => true,
'sort_url' => 'timestamp',
'content' => __('Added on','cftp_admin'),
'hide' => 'phone',
),
array(
'content' => __('View','cftp_admin'),
'hide' => 'phone',
),
array(
'content' => __('Actions','cftp_admin'),
'hide' => 'phone',
),
);
$table->thead( $thead_columns );
$sql->setFetchMode(PDO::FETCH_ASSOC);
while ( $row = $sql->fetch() ) {
$table->add_row();
/**
* Prepare the information to be used later on the cells array
* 1- Get account creation date
*/
$date = date(TIMEFORMAT_USE,strtotime($row['timestamp']));
/**
* 2- Button class for the manage files link
*/
if ( isset( $files_amount[$row['id']] ) ) {
$files_link = 'manage-files.php?group_id=' . html_output( $row["id"] );
$files_btn = 'btn-primary';
}
else {
$files_link = '#';
$files_btn = 'btn-default disabled';
}
/**
* 3- Visibility
*/
if ($row['public'] == '1') {
$visibility_link = '<a href="javascript:void(0);" class="btn btn-primary btn-sm public_link" data-type="group" data-id="' . $row['id'] .'" data-token="' . html_output($row['public_token']) .'">';
$visibility_label = __('Public','cftp_admin');
}
else {
$visibility_link = '<a href="javascript:void(0);" class="btn btn-default btn-sm disabled" title="">';
$visibility_label = __('Private','cftp_admin');
}
/**
* Add the cells to the row
*/
$tbody_cells = array(
array(
'checkbox' => true,
'value' => $row["id"],
),
array(
'content' => html_output( $row["name"] ),
),
array(
'content' => html_output( $row["description"] ),
),
array(
'content' => ( isset( $members_amount[$row['id']] ) ) ? $members_amount[$row['id']] : '0',
),
array(
'content' => ( isset( $files_amount[$row['id']] ) ) ? $files_amount[$row['id']] : '0',
),
array(
//'content' => ( $row["public"] == '1' ) ? __('Yes','cftp_admin') : __('No','cftp_admin'),
'content' => $visibility_link . $visibility_label . '</a>',
),
array(
'content' => html_output( $row["created_by"] ),
),
array(
'content' => $date,
),
array(
'actions' => true,
'content' => '<a href="' . $files_link . '" class="btn ' . $files_btn . ' btn-sm">' . __('Files','cftp_admin') . '</a>',
),
array(
'actions' => true,
'content' => '<a href="groups-edit.php?id=' . html_output( $row["id"] ) . '" class="btn btn-primary btn-sm"><i class="fa fa-pencil"></i><span class="button_label">' . __('Edit','cftp_admin') . '</span></a>' . "\n"
),
);
foreach ( $tbody_cells as $cell ) {
$table->add_cell( $cell );
}
$table->end_row();
}
echo $table->render();
/**
* PAGINATION
*/
$pagination_args = array(
'link' => 'groups.php',
'current' => $pagination_page,
'pages' => ceil( $count_for_pagination / RESULTS_PER_PAGE ),
);
echo $table->pagination( $pagination_args );
}
?>
</form>
</div>
<?php
include('footer.php');