forked from projectsend/projectsend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
actions-log.php
320 lines (280 loc) · 9.21 KB
/
actions-log.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
<?php
/**
* Show the list of activities logged.
*
* @package ProjectSend
* @subpackage Log
*
*/
$footable_min = true; // delete this line after finishing pagination on every table
$load_scripts = array(
'footable',
);
$allowed_levels = array(9);
require_once('sys.includes.php');
$active_nav = 'tools';
$page_title = __('Recent activities log','cftp_admin');
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. */
switch($_GET['action']) {
case 'delete':
$selected_actions = $_GET['batch'];
$delete_ids = implode( ',', $selected_actions );
if ( !empty( $_GET['batch'] ) ) {
$statement = $dbh->prepare("DELETE FROM " . TABLE_LOG . " WHERE FIND_IN_SET(id, :delete)");
$params = array(
':delete' => $delete_ids,
);
$statement->execute( $params );
$msg = __('The selected activities were deleted.','cftp_admin');
echo system_message('ok',$msg);
}
else {
$msg = __('Please select at least one activity.','cftp_admin');
echo system_message('error',$msg);
}
break;
case 'clear':
$keep = '5,8,9';
$statement = $dbh->prepare("DELETE FROM " . TABLE_LOG . " WHERE NOT ( FIND_IN_SET(action, :keep) ) ");
$params = array(
':keep' => $keep,
);
$statement->execute( $params );
$msg = __('The log was cleared. Only data used for statistics remained. You can delete them manually if you want.','cftp_admin');
echo system_message('ok',$msg);
break;
}
}
$params = array();
/**
* Get the actually requested items
*/
$cq = "SELECT * FROM " . TABLE_LOG;
/** Add the search terms */
if ( isset($_GET['search']) && !empty($_GET['search'] ) ) {
$cq .= " WHERE (owner_user LIKE :owner OR affected_file_name LIKE :file OR affected_account_name LIKE :account)";
$next_clause = ' AND';
$no_results_error = 'search';
$search_terms = '%'.$_GET['search'].'%';
$params[':owner'] = $search_terms;
$params[':file'] = $search_terms;
$params[':account'] = $search_terms;
}
else {
$next_clause = ' WHERE';
}
/** Add the activities filter */
if (isset($_GET['activity']) && $_GET['activity'] != 'all') {
$cq .= $next_clause. " action=:status";
$status_filter = $_GET['activity'];
$params[':status'] = $status_filter;
$no_results_error = 'filter';
}
/**
* Add the order.
* Defaults to order by: id, order: DESC
*/
$cq .= sql_add_order( TABLE_LOG, 'id', 'DESC' );
/**
* 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_LOG;
$params[':limit_start'] = $pagination_start;
$params[':limit_number'] = RESULTS_PER_PAGE_LOG;
$sql->execute( $params );
$count = $sql->rowCount();
?>
<div class="form_actions_left">
<div class="form_actions_limit_results">
<?php show_search_form('actions-log.php'); ?>
<form action="actions-log.php" name="actions_filters" method="get" class="form-inline form_filters">
<?php form_add_existing_parameters( array('activity') ); ?>
<div class="form-group group_float">
<label for="activity" class="sr-only"><?php _e('Filter activities','cftp_admin'); ?></label>
<select name="activity" id="activity" class="form-control">
<option value="all"><?php _e('All activities','cftp_admin'); ?></option>
<?php
global $activities_references;
foreach ( $activities_references as $val => $text ) {
?>
<option value="<?php echo $val; ?>" <?php if ( isset( $_GET['activity'] ) && $_GET['activity'] == $val ) { echo 'selected="selected"'; } ?>><?php echo $text; ?></option>
<?php
}
?>
</select>
</div>
<button type="submit" id="btn_proceed_filter_clients" class="btn btn-sm btn-default"><?php _e('Filter','cftp_admin'); ?></button>
</form>
</div>
</div>
<form action="actions-log.php" name="actions_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('Activities actions','cftp_admin'); ?>:</label>
<select name="action" id="action" class="form-control">
<?php
$actions_options = array(
'none' => __('Select action','cftp_admin'),
'log_download' => __('Download as csv','cftp_admin'),
'delete' => __('Delete selected','cftp_admin'),
'log_clear' => __('Clear entire log','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('activities','cftp_admin'); ?></span></p>
</div>
<div class="clear"></div>
<?php
if (!$count) {
if (isset($no_results_error)) {
switch ($no_results_error) {
case 'filter':
$no_results_message = __('The filters you selected returned no results.','cftp_admin');
break;
}
}
else {
$no_results_message = __('There are no activities recorded.','cftp_admin');
}
echo system_message('error',$no_results_message);
}
?>
<?php
/**
* Generate the table using the class.
*/
$table_attributes = array(
'id' => 'activities_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' => 'timestamp',
'sort_default' => true,
'content' => __('Date','cftp_admin'),
),
array(
'sortable' => true,
'sort_url' => 'owner_id',
'content' => __('Author','cftp_admin'),
),
array(
'sortable' => true,
'sort_url' => 'action',
'content' => __('Activity','cftp_admin'),
'hide' => 'phone',
),
array(
'content' => '',
'hide' => 'phone',
),
array(
'content' => '',
'hide' => 'phone',
),
array(
'content' => '',
'hide' => 'phone',
),
);
$table->thead( $thead_columns );
$sql->setFetchMode(PDO::FETCH_ASSOC);
while ( $log = $sql->fetch() ) {
$this_action = render_log_action(
array(
'action' => $log['action'],
'timestamp' => $log['timestamp'],
'owner_id' => $log['owner_id'],
'owner_user' => $log['owner_user'],
'affected_file' => $log['affected_file'],
'affected_file_name' => $log['affected_file_name'],
'affected_account' => $log['affected_account'],
'affected_account_name' => $log['affected_account_name']
)
);
$date = date(TIMEFORMAT_USE,strtotime($log['timestamp']));
$table->add_row();
$tbody_cells = array(
array(
'checkbox' => true,
'value' => $log["id"],
),
array(
'content' => $date,
),
array(
'content' => ( !empty( $this_action["1"] ) ) ? html_output( $this_action["1"] ) : '',
),
array(
'content' => html_output( $this_action["text"] ),
),
array(
'content' => ( !empty( $this_action["2"] ) ) ? html_output( $this_action["2"] ) : '',
),
array(
'content' => ( !empty( $this_action["3"] ) ) ? html_output( $this_action["3"] ) : '',
),
array(
'content' => ( !empty( $this_action["4"] ) ) ? html_output( $this_action["4"] ) : '',
),
);
foreach ( $tbody_cells as $cell ) {
$table->add_cell( $cell );
}
$table->end_row();
}
echo $table->render();
/**
* PAGINATION
*/
$pagination_args = array(
'link' => 'actions-log.php',
'current' => $pagination_page,
'pages' => ceil( $count_for_pagination / RESULTS_PER_PAGE_LOG ),
);
echo $table->pagination( $pagination_args );
?>
</form>
</div>
<?php
include('footer.php');