This repository was archived by the owner on Dec 23, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcategories.php
More file actions
496 lines (434 loc) · 15.4 KB
/
Copy pathcategories.php
File metadata and controls
496 lines (434 loc) · 15.4 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
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
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
<?php
/**
* Allows to hide, show or delete the files assigend to the
* selected client.
*
* @package ProjectSend
* @subpackage Files
*/
$load_scripts = array(
'footable',
);
$allowed_levels = array(9,8);
require_once('sys.includes.php');
$active_nav = 'files';
$cc_active_page = 'Categories';
$page_title = __('Categories Administration','cftp_admin');
$current_level = get_current_user_level();
include('header.php');
?>
<script type="text/javascript">
$(document).ready( function() {
$("#do_action").click(function() {
var file_count = 0;
$("input[name='categories[]']").each( function () {
if($(this).prop("checked") == true){
var flag = $(this).closest('td').siblings().find('span').data('filecount');
file_count = file_count+flag;
}
});
var checks = $("td>input:checkbox").serializeArray();
if (checks.length == 0) {
alert('<?php _e('Please select at least one category to proceed.','cftp_admin'); ?>');
return false;
}
else {
var action = $('#categories_actions').val();
if (action == 'delete') {
var msg_1 = '<?php _e("You are about to delete",'cftp_admin'); ?>';
if(file_count > 0) {
var msg_2 = '<?php _e("categories that contains files. Are you sure you want to continue?",'cftp_admin'); ?>';
}
else {
var msg_2 = '<?php _e("categories. Are you sure you want to continue?",'cftp_admin'); ?>';
}
if (confirm(msg_1+' '+checks.length+' '+msg_2)) {
return true;
} else {
return false;
}
}
}
});
$("#process_category").submit(function() {
clean_form( this );
is_complete( this.category_name, '<?php echo $validation_no_name; ?>' );
// show the errors or continue if everything is ok
if (show_form_errors() == false) { return false; }
});
});
</script>
<div id="main">
<div id="content">
<!-- Added by B) -------------------->
<div class="container-fluid">
<div class="row">
<div class="col-md-12">
<h2 class="page-title txt-color-blueDark"><?php echo $page_title; ?></h2>
<a href="category-add.php" class="btn btn-sm btn-primary right-btn">New Category</a></div>
<?php
/**
* Messages set when adding or editing a category
*/
if ( !empty( $_GET['status'] ) ) {
$result_status = $_GET['status'];
switch ( $result_status ) {
case 'added':
$msg_text = __('The category was successfully created.','cftp_admin');
$msg_type = 'ok';
break;
case 'edited':
$msg_text = __('The category was successfully edited.','cftp_admin');
$msg_type = 'ok';
break;
}
echo system_message( $msg_type, $msg_text );
}
/**
* Apply the corresponding action to the selected categories.
*/
if ( isset( $_POST['categories_actions'] ) ) {
/** Continue only if 1 or more categories were selected. */
if ( !empty($_POST['categories'] ) ) {
/**
* Make a list of categories to avoid individual queries.
*/
$selected_categories = $_POST['categories'];
$get_categories_delete = get_categories(
array(
'id' => $selected_categories,
)
);
foreach ( $get_categories_delete['categories'] as $delete_cat ) {
$all_categories[$delete_cat['id']] = $delete_cat['name'];
}
$my_info = get_user_by_username(get_current_user_username());
$affected_users = 0;
switch($_POST['categories_actions']) {
case 'delete':
foreach ($selected_categories as $category) {
$this_category = new CategoriesActions();
$check_category = $this_category->check_category($category);
if($check_category['status']==true){
$delete_category = $this_category->delete_category($category);
$msg = __($check_category['msg'],'cftp_admin');
echo system_message('ok',$msg);
}else{
$msg = __($check_category['msg'],'cftp_admin');
echo system_message('error',$msg);
}
}
$log_action_number = 36;
break;
}
/** Record the action log */
foreach ($selected_categories as $category) {
$new_log_action = new LogActions();
$log_action_args = array(
'action' => $log_action_number,
'owner_id' => CURRENT_USER_ID,
'affected_account_name' => $all_categories[$category]
);
$new_record_action = $new_log_action->log_action_save($log_action_args);
}
}
else {
$msg = __('Please select at least one category.','cftp_admin');
echo system_message('error',$msg);
}
}
/** Get all the existing categories */
$params['search']= isset($_POST['search'])?$_POST['search']:'';
$get_categories = get_categories($params);
if(isset($get_categories['categories'])){
$categories = $get_categories['categories'];
}
if(isset($get_categories['arranged'])){
$categories = $get_categories['arranged'];
}
/**
* Adding or editing a category
*
* By default, the action is ADD category
*/
$form_information = array(
'type' => 'new_category',
'title' => __('Create new category','cftp_admin'),
);
/** Loading the form in EDIT mode */
if (
( !empty( $_GET['action'] ) && $_GET['action'] == 'edit' ) or
!empty( $_POST['editing_id'] )
) {
$action = 'edit';
$editing = !empty( $_POST['editing_id'] ) ? $_POST['editing_id'] : $_GET['id'];
$form_information = array(
'type' => 'edit_category',
'title' => __('Edit category','cftp_admin'),
);
/**
* Get the current information if just entering edit mode
*/
$category_name = $categories[$editing]['name'];
$category_parent = $categories[$editing]['parent'];
$category_description = $categories[$editing]['description'];
}
/**
* Process the action
*/
if ( isset( $_POST['btn_process'] ) ) {
/**
* Applies for both ADDING a new category as well
* as editing one but with the form already sent.
*/
$category_name = $_POST['category_name'];
$category_parent = $_POST['category_parent'];
$category_description = $_POST['category_description'];
$category_object = new CategoriesActions();
$arguments = array(
'name' => $category_name,
'parent' => $category_parent,
'description' => $category_description,
);
$validate = $category_object->validate_category( $arguments );
switch ( $form_information['type'] ) {
case 'new_category':
$arguments['action'] = 'add';
$redirect_status = 'added';
break;
case 'edit_category':
$arguments['action'] = 'edit';
$redirect_status = 'edited';
$arguments['id'] = ( $_POST ) ? $_POST['editing_id'] : $_GET['id'];
break;
}
if ( $validate === 1 ) {
$process = $category_object->save_category( $arguments );
if ( $process['query'] === 1 ) {
$redirect = true;
$status = $redirect_status;
}
else {
$msg = __('There was a problem savint to the database.','cftp_admin');
echo system_message('error', $msg);
}
}
else {
$msg = __('Please complete all the required fields.','cftp_admin');
echo system_message('error', $msg);
}
/** Redirect so the actions are reflected immediatly */
if ( isset( $redirect ) && $redirect === true ) {
while (ob_get_level()) ob_end_clean();
$location = BASE_URI . 'categories.php?status=' . $status;
header("Location: $location");
die();
}
}
?>
<div class="form_actions_left">
<div class="form_actions_limit_results">
<form action="categories.php" name="cat_search" method="post" class="form-inline">
<div class="form-group group_float">
<input type="text" name="search" id="search" value="<?php echo isset($_POST['search'])?$_POST['search']:''; ?>" class="txtfield form_actions_search_box form-control" />
</div>
<button type="submit" id="btn_proceed_search" class="btn btn-sm btn-default"><?php _e('Search','cftp_admin'); ?></button>
</form>
</div>
</div>
<form action="categories.php" name="selected_categories" id="selected_categories" method="post">
<div class="form_actions_right form-inline">
<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 categories actions','cftp_admin'); ?>:</label>
<select name="categories_actions" id="categories_actions" class="txtfield form-control">
<option value="delete"><?php _e('Delete','cftp_admin'); ?></option>
</select>
</div>
<button type="submit" name="do_action" 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 class="form_count_total"><?php _e('Showing','cftp_admin'); ?>: <span><?php echo $get_categories['count']; ?> <?php _e('categories','cftp_admin'); ?></span></p>
</div>
<div class="clear"></div>
<?php
if ( $get_categories['count'] == 0 ) {
if ( !empty( $get_categories['no_results_type'] ) ) {
switch ( $get_categories['no_results_type'] ) {
case 'search':
$no_results_message = __('Your search keywords returned no results.','cftp_admin');;
break;
}
}
else {
$no_results_message = __('There are no categories yet.','cftp_admin');;
}
echo system_message('error', $no_results_message);
}
?>
<div class="container-fluid">
<div class="row">
<div class="col-xs-12 col-sm-12 col-md-12">
<section id="no-more-tables">
<table id="categories_tbl" class="table table-striped table-bordered table-hover dataTable no-footer" data-page-size="<?php echo FOOTABLE_PAGING_NUMBER; ?>">
<thead>
<tr>
<th class="td_checkbox" data-sort-ignore="true">
<input type="checkbox" name="select_all" id="select_all" value="0" />
</th>
<th data-sort-ignore="true"><?php _e('Name','cftp_admin'); ?></th>
<th data-sort-ignore="true"><?php _e('Files*','cftp_admin'); ?></th>
<th data-hide="phone" data-sort-ignore="true"><?php _e('Description','cftp_admin'); ?></th>
<th data-hide="phone" data-sort-ignore="true"><?php _e('Actions','cftp_admin'); ?></th>
</tr>
</thead>
<tbody>
<?php
/**
* Having the formatting function here seems more convenient
* as the HTML layout is easier to edit on it's real context.
*/
$c = 0;
function format_category_row( $categories ) {
global $c;
$c++;
if ( !empty( $categories ) ) {
foreach ( $categories as $category ) {
$depth = ( $category['depth'] > 0 ) ? str_repeat( '—', $category['depth'] ) . ' ' : false;
?>
<tr>
<td>
<input type="checkbox" name="categories[]" value="<?php echo html_output($category["id"]); ?>" />
</td>
<td data-value="<?php echo $c; ?>">
<a href="category-edit.php?action=edit&id=<?php echo $category["id"]; ?>"><?php _e($depth . html_output($category["name"]),'cftp_admin'); ?></a></td>
<td>
<?php
$total = $category['file_count'];
if ( $total > 0 ) {
$class = 'success';
$files_link = 'manage-files.php?category=' . $category['id'];
$files_button = 'btn-primary';
}
else {
$class = 'danger';
$files_link = 'javascript:void(0);';
$files_button = 'btn-default disabled';
}
?>
<span class="label label-<?php echo $class; ?>" data-filecount="<?php echo $total; ?>">
<?php echo $total; ?>
</span>
</td>
<td><?php echo html_output($category["description"]); ?></td>
<td>
<a href="<?php echo $files_link; ?>" class="btn btn-sm <?php echo $files_button; ?>"><?php _e('Manage files','cftp_admin'); ?></a>
</td>
</tr>
<?php
$children = $category['children'];
if ( !empty( $children ) ) {
format_category_row( $children );
}
}
}
}
if ( $get_categories['count'] > 0 ) {
if(!empty($get_categories['arranged'])){
format_category_row( $get_categories['arranged'] );
}
else{
format_category_row( $get_categories['categories'] );
}
}
?>
</tbody>
</table>
<p>*NOTE: Count does not include files in subfolders.</p>
</section>
<nav aria-label="<?php _e('Results navigation','cftp_admin'); ?>">
<div class="pagination_wrapper text-center">
<ul class="pagination hide-if-no-paging"></ul>
</div>
</nav>
</div>
</form>
<form action="categories.php" name="process_category" id="process_category" method="post">
<input type="hidden" name="processing" id="processing" value="1">
<?php
if ( !empty( $action ) && $action == 'edit' ) {
?>
<input type="hidden" name="editing_id" id="editing_id" value="<?php echo $editing; ?>">
<?php
}
?>
<div class="col-xs-12 col-sm-12 col-md-4">
<?php //include_once( 'categories-form.php' ); ?>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<?php include('footer.php'); ?>
<style type="text/css">
/*-------------------- Responsive table by B) -----------------------*/
@media only screen and (max-width: 1200px) {
#content {
padding-top:30px;
}
/* Force table to not be like tables anymore */
#no-more-tables table,
#no-more-tables thead,
#no-more-tables tbody,
#no-more-tables th,
#no-more-tables td,
#no-more-tables tr {
display: block;
}
/* Hide table headers (but not display: none;, for accessibility) */
#no-more-tables thead tr {
position: absolute;
top: -9999px;
left: -9999px;
}
#no-more-tables tr { border: 1px solid #ccc; }
#no-more-tables td {
/* Behave like a "row" */
border: none;
border-bottom: 1px solid #eee;
position: relative;
padding-left: 50%;
white-space: normal;
text-align:left;
}
#no-more-tables td:before {
/* Now like a table header */
position: absolute;
/* Top/left values mimic padding */
top: 6px;
left: 6px;
width: 45%;
padding-right: 10px;
white-space: nowrap;
text-align:left;
font-weight: bold;
}
/*
Label the data
*/
td:nth-of-type(1):before { content: ""; }
td:nth-of-type(2):before { content: "Name"; }
td:nth-of-type(3):before { content: "Files"; }
td:nth-of-type(4):before { content: "Description"; }
td:nth-of-type(5):before { content: "Actions"; }
}
/*-------------------- Responsive table End--------------------------*/
</style>