forked from osclass/Osclass
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathusers.php
executable file
·670 lines (568 loc) · 43.2 KB
/
users.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
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
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
<?php if ( ! defined('ABS_PATH')) exit('ABS_PATH is not loaded. Direct access is not allowed.');
/*
* Copyright 2014 Osclass
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
class CAdminUsers extends AdminSecBaseModel
{
//specific for this class
private $userManager;
function __construct()
{
parent::__construct();
//specific things for this class
$this->userManager = User::newInstance();
}
//Business Layer...
function doModel()
{
parent::doModel();
//specific things for this class
switch ($this->action) {
case('create'): // calling create view
$aRegions = array();
$aCities = array();
$aCountries = Country::newInstance()->listAll();
if( isset($aCountries[0]['pk_c_code']) ) {
$aRegions = Region::newInstance()->findByCountry($aCountries[0]['pk_c_code']);
}
if( isset($aRegions[0]['pk_i_id']) ) {
$aCities = City::newInstance()->findByRegion($aRegions[0]['pk_i_id']);
}
$this->_exportVariableToView( 'user', null );
$this->_exportVariableToView( 'countries', $aCountries );
$this->_exportVariableToView( 'regions', $aRegions );
$this->_exportVariableToView( 'cities', $aCities );
$this->_exportVariableToView( 'locales', OSCLocale::newInstance()->listAllEnabled() );
$this->doView("users/frm.php");
break;
case('create_post'): // creating the user...
osc_csrf_check();
require_once LIB_PATH . 'osclass/UserActions.php';
$userActions = new UserActions(true);
$success = $userActions->add();
switch($success) {
case 1: osc_add_flash_ok_message( _m("The user has been created. We've sent an activation e-mail"), 'admin');
break;
case 2: osc_add_flash_ok_message( _m('The user has been created successfully'), 'admin');
break;
default: osc_add_flash_error_message( $success, 'admin');
break;
}
$this->redirectTo(osc_admin_base_url(true) . '?page=users');
break;
case('edit'): // calling the edit view
$aUser = $this->userManager->findByPrimaryKey(Params::getParam("id"));
$aCountries = Country::newInstance()->listAll();
$aRegions = array();
if( $aUser['fk_c_country_code'] != '' ) {
$aRegions = Region::newInstance()->findByCountry($aUser['fk_c_country_code']);
} else if( count($aCountries) > 0 ) {
$aRegions = Region::newInstance()->findByCountry($aCountries[0]['pk_c_code']);
}
$aCities = array();
if( $aUser['fk_i_region_id'] != '' ) {
$aCities = City::newInstance()->findByRegion($aUser['fk_i_region_id']);
} else if( count($aRegions) > 0 ) {
$aCities = City::newInstance()->findByRegion($aRegions[0]['pk_i_id']);
}
$csrf_token = osc_csrf_token_url();
if( $aUser['b_active'] ) {
$actions[] = '<a class="btn float-left" href="'.osc_admin_base_url(true).'?page=users&action=deactivate&id[]='.$aUser['pk_i_id'].'&'.$csrf_token.'&value=INACTIVE">'.__('Deactivate') .'</a>';
} else {
$actions[] = '<a class="btn btn-red float-left" href="'.osc_admin_base_url(true).'?page=users&action=activate&id[]='.$aUser['pk_i_id'].'&'.$csrf_token.'&value=ACTIVE">'.__('Activate') .'</a>';
}
if( $aUser['b_enabled'] ) {
$actions[] = '<a class="btn float-left" href="'.osc_admin_base_url(true).'?page=users&action=disable&id[]='.$aUser['pk_i_id'].'&'.$csrf_token.'&value=DISABLE">'.__('Block') .'</a>';
} else {
$actions[] = '<a class="btn btn-red float-left" href="'.osc_admin_base_url(true).'?page=users&action=enable&id[]='.$aUser['pk_i_id'].'&'.$csrf_token.'&value=ENABLE">'.__('Unblock') .'</a>';
}
$this->_exportVariableToView("actions", $actions);
$this->_exportVariableToView("user", $aUser);
$this->_exportVariableToView("countries", $aCountries);
$this->_exportVariableToView("regions", $aRegions);
$this->_exportVariableToView("cities", $aCities);
$this->_exportVariableToView("locales", OSCLocale::newInstance()->listAllEnabled());
$this->doView("users/frm.php");
break;
case('edit_post'): // edit post
osc_csrf_check();
require_once LIB_PATH . 'osclass/UserActions.php';
$userActions = new UserActions(true);
$success = $userActions->edit( Params::getParam("id") );
if($success==1) {
osc_add_flash_ok_message( _m('The user has been updated'), 'admin');
} else if($success==2) {
osc_add_flash_ok_message( _m('The user has been updated and activated'), 'admin');
} else {
osc_add_flash_error_message( $success);
$this->redirectTo(osc_admin_base_url(true) . '?page=users&action=edit&id='.Params::getParam('id'));
}
$this->redirectTo(osc_admin_base_url(true) . '?page=users');
break;
case('resend_activation'):
//activate
osc_csrf_check();
require_once LIB_PATH . 'osclass/UserActions.php';
$iUpdated = 0;
$userId = Params::getParam('id');
if(!is_array($userId)) {
osc_add_flash_error_message( _m("User id isn't in the correct format"), 'admin');
$this->redirectTo(osc_admin_base_url(true) . '?page=users');
}
$userActions = new UserActions(true);
foreach($userId as $id) {
$iUpdated += $userActions->resend_activation($id);
}
if($iUpdated==0) {
osc_add_flash_error_message(_m('No users have been selected'), 'admin');
} else {
osc_add_flash_ok_message(sprintf( _mn('Activation email sent to one user', 'Activation email sent to %s users', $iUpdated), $iUpdated ), 'admin');
}
$this->redirectTo(osc_admin_base_url(true) . '?page=users');
break;
case('activate'): //activate
osc_csrf_check();
require_once LIB_PATH . 'osclass/UserActions.php';
$iUpdated = 0;
$userId = Params::getParam('id');
if( !is_array($userId) ) {
osc_add_flash_error_message( _m("User id isn't in the correct format"), 'admin');
$this->redirectTo(osc_admin_base_url(true) . '?page=users');
}
$userActions = new UserActions(true);
foreach($userId as $id) {
$iUpdated += $userActions->activate($id);
}
if( $iUpdated == 0 ) {
$msg = _m('No users have been activated');
} else {
$msg = sprintf( _mn('One user has been activated', '%s users have been activated', $iUpdated), $iUpdated );
}
osc_add_flash_ok_message($msg, 'admin');
$this->redirectTo( Params::getServerParam('HTTP_REFERER', false, false) );
break;
case('deactivate'): //deactivate
osc_csrf_check();
require_once LIB_PATH . 'osclass/UserActions.php';
$iUpdated = 0;
$userId = Params::getParam('id');
if( !is_array($userId) ) {
osc_add_flash_error_message( _m("User id isn't in the correct format"), 'admin');
$this->redirectTo(osc_admin_base_url(true) . '?page=users');
}
$userActions = new UserActions(true);
foreach($userId as $id) {
$iUpdated += $userActions->deactivate($id);
}
if( $iUpdated == 0 ) {
$msg = _m('No users have been deactivated');
} else {
$msg = sprintf( _mn('One user has been deactivated', '%s users have been deactivated', $iUpdated), $iUpdated );
}
osc_add_flash_ok_message($msg, 'admin');
$this->redirectTo( Params::getServerParam('HTTP_REFERER', false, false) );
break;
case('enable'):
osc_csrf_check();
require_once LIB_PATH . 'osclass/UserActions.php';
$iUpdated = 0;
$userId = Params::getParam('id');
if( !is_array($userId) ) {
osc_add_flash_error_message(_m("User id isn't in the correct format"), 'admin');
$this->redirectTo(osc_admin_base_url(true) . '?page=users');
}
$userActions = new UserActions(true);
foreach($userId as $id) {
$iUpdated += $userActions->enable($id);
}
if( $iUpdated == 0 ) {
$msg = _m('No users have been enabled');
} else {
$msg = sprintf( _mn('One user has been unblocked', '%s users have been unblocked', $iUpdated), $iUpdated );
}
osc_add_flash_ok_message($msg, 'admin');
$this->redirectTo( Params::getServerParam('HTTP_REFERER', false, false) );
break;
case('disable'):
osc_csrf_check();
require_once LIB_PATH . 'osclass/UserActions.php';
$iUpdated = 0;
$userId = Params::getParam('id');
if( !is_array($userId) ) {
osc_add_flash_error_message( _m("User id isn't in the correct format"), 'admin');
$this->redirectTo(osc_admin_base_url(true) . '?page=users');
}
$userActions = new UserActions(true);
foreach($userId as $id) {
$iUpdated += $userActions->disable($id);
}
if( $iUpdated == 0 ) {
$msg = _m('No users have been disabled');
} else {
$msg = sprintf( _mn('One user has been blocked', '%s users have been blocked', $iUpdated), $iUpdated );
}
osc_add_flash_ok_message($msg, 'admin');
$this->redirectTo( Params::getServerParam('HTTP_REFERER', false, false) );
break;
case('delete'): //delete
osc_csrf_check();
$iDeleted = 0;
$userId = Params::getParam('id');
if( !is_array($userId) ) {
osc_add_flash_error_message( _m("User id isn't in the correct format"), 'admin');
$this->redirectTo(osc_admin_base_url(true) . '?page=users');
}
foreach($userId as $id) {
$user = $this->userManager->findByPrimaryKey($id);
Log::newInstance()->insertLog('user', 'delete', $id, $user['s_email'], 'admin', osc_logged_admin_id());
if( $this->userManager->deleteUser($id) ) {
$iDeleted++;
}
}
if( $iDeleted == 0 ) {
$msg = _m('No users have been deleted');
} else {
$msg = sprintf( _mn('One user has been deleted', '%s users have been deleted', $iDeleted), $iDeleted );
}
osc_add_flash_ok_message($msg, 'admin');
$this->redirectTo(osc_admin_base_url(true) . '?page=users');
break;
case('delete_alerts'): //delete
$iDeleted = 0;
$alertId = Params::getParam('alert_id');
if( !is_array($alertId) ) {
osc_add_flash_error_message( _m("Alert id isn't in the correct format"), 'admin');
if(Params::getParam('user_id')=='') {
$this->redirectTo(osc_admin_base_url(true) . '?page=users&action=alerts');
} else {
$this->redirectTo(osc_admin_base_url(true) . '?page=users&action=edit&id='.Params::getParam('user_id'));
}
}
$mAlerts = new Alerts();
foreach($alertId as $id) {
Log::newInstance()->insertLog('user', 'delete_alerts', $id, $id, 'admin', osc_logged_admin_id());
$iDeleted += $mAlerts->delete(array('pk_i_id' => $id));
}
if( $iDeleted == 0 ) {
$msg = _m('No alerts have been deleted');
} else {
$msg = sprintf( _mn('One alert has been deleted', '%s alerts have been deleted', $iDeleted), $iDeleted );
}
osc_add_flash_ok_message($msg, 'admin');
if(Params::getParam('user_id')=='') {
$this->redirectTo(osc_admin_base_url(true) . '?page=users&action=alerts');
} else {
$this->redirectTo(osc_admin_base_url(true) . '?page=users&action=edit&id='.Params::getParam('user_id'));
}
break;
case('status_alerts'): //delete
$status = Params::getParam("status");
$iUpdated = 0;
$alertId = Params::getParam('alert_id');
if( !is_array($alertId) ) {
osc_add_flash_error_message( _m("Alert id isn't in the correct format"), 'admin');
if(Params::getParam('user_id')=='') {
$this->redirectTo(osc_admin_base_url(true) . '?page=users&action=alerts');
} else {
$this->redirectTo(osc_admin_base_url(true) . '?page=users&action=edit&id='.Params::getParam('user_id'));
}
}
$mAlerts = new Alerts();
foreach($alertId as $id) {
if($status==1) {
$iUpdated += $mAlerts->activate($id);
} else {
$iUpdated += $mAlerts->deactivate($id);
}
}
if($status==1) {
if( $iUpdated == 0 ) {
$msg = _m('No alerts have been activated');
} else {
$msg = sprintf( _mn('One alert has been activated', '%s alerts have been activated', $iUpdated), $iUpdated );
}
} else {
if( $iUpdated == 0 ) {
$msg = _m('No alerts have been deactivated');
} else {
$msg = sprintf( _mn('One alert has been deactivated', '%s alerts have been deactivated', $iUpdated), $iUpdated );
}
}
osc_add_flash_ok_message($msg, 'admin');
if(Params::getParam('user_id')=='') {
$this->redirectTo(osc_admin_base_url(true) . '?page=users&action=alerts');
} else {
$this->redirectTo(osc_admin_base_url(true) . '?page=users&action=edit&id='.Params::getParam('user_id'));
}
break;
case('settings'): // calling the users settings view
$this->doView('users/settings.php');
break;
case('settings_post'): // updating users
osc_csrf_check();
$iUpdated = 0;
$enabledUserValidation = Params::getParam('enabled_user_validation');
$enabledUserValidation = (($enabledUserValidation != '') ? true : false);
$enabledUserRegistration = Params::getParam('enabled_user_registration');
$enabledUserRegistration = (($enabledUserRegistration != '') ? true : false);
$enabledUsers = Params::getParam('enabled_users');
$enabledUsers = (($enabledUsers != '') ? true : false);
$notifyNewUser = Params::getParam('notify_new_user');
$notifyNewUser = (($notifyNewUser != '') ? true : false);
$usernameBlacklistTmp = explode(",", Params::getParam('username_blacklist'));
foreach($usernameBlacklistTmp as $k => $v) {
$usernameBlacklistTmp[$k] = strtolower(trim($v));
}
$usernameBlacklist = implode(",", $usernameBlacklistTmp);
$iUpdated += osc_set_preference('enabled_user_validation', $enabledUserValidation);
$iUpdated += osc_set_preference('enabled_user_registration', $enabledUserRegistration);
$iUpdated += osc_set_preference('enabled_users', $enabledUsers);
$iUpdated += osc_set_preference('notify_new_user', $notifyNewUser);
$iUpdated += osc_set_preference('username_blacklist', $usernameBlacklist);
if( $iUpdated > 0 ) {
osc_add_flash_ok_message( _m("User settings have been updated"), 'admin');
}
$this->redirectTo(osc_admin_base_url(true) . '?page=users&action=settings');
break;
case('alerts'): // manage alerts view
require_once osc_lib_path()."osclass/classes/datatables/AlertsDataTable.php";
// set default iDisplayLength
if( Params::getParam('iDisplayLength') != '' ) {
Cookie::newInstance()->push('listing_iDisplayLength', Params::getParam('iDisplayLength'));
Cookie::newInstance()->set();
} else {
// set a default value if it's set in the cookie
if( Cookie::newInstance()->get_value('listing_iDisplayLength') != '' ) {
Params::setParam('iDisplayLength', Cookie::newInstance()->get_value('listing_iDisplayLength'));
} else {
Params::setParam('iDisplayLength', 10 );
}
}
$this->_exportVariableToView('iDisplayLength', Params::getParam('iDisplayLength'));
// Table header order by related
if( Params::getParam('sort') == '') {
Params::setParam('sort', 'date');
}
if( Params::getParam('direction') == '') {
Params::setParam('direction', 'desc');
}
$page = (int)Params::getParam('iPage');
if($page==0) { $page = 1; };
Params::setParam('iPage', $page);
$params = Params::getParamsAsArray();
$alertsDataTable = new AlertsDataTable();
$alertsDataTable->table($params);
$aData = $alertsDataTable->getData();
if(count($aData['aRows']) == 0 && $page!=1) {
$total = (int)$aData['iTotalDisplayRecords'];
$maxPage = ceil( $total / (int)$aData['iDisplayLength'] );
$url = osc_admin_base_url(true).'?'.Params::getServerParam('QUERY_STRING', false, false);
if($maxPage==0) {
$url = preg_replace('/&iPage=(\d)+/', '&iPage=1', $url);
$this->redirectTo($url);
}
if($page > 1) {
$url = preg_replace('/&iPage=(\d)+/', '&iPage='.$maxPage, $url);
$this->redirectTo($url);
}
}
$this->_exportVariableToView('aData', $aData);
$this->_exportVariableToView('aRawRows', $alertsDataTable->rawRows());
$this->doView("users/alerts.php");
break;
case('ban'): // manage ban rules view
if(Params::getParam("action")!="") {
osc_run_hook("ban_rules_bulk_".Params::getParam("action"), Params::getParam('id'));
}
require_once osc_lib_path()."osclass/classes/datatables/BanRulesDataTable.php";
// set default iDisplayLength
if( Params::getParam('iDisplayLength') != '' ) {
Cookie::newInstance()->push('listing_iDisplayLength', Params::getParam('iDisplayLength'));
Cookie::newInstance()->set();
} else {
// set a default value if it's set in the cookie
if( Cookie::newInstance()->get_value('listing_iDisplayLength') != '' ) {
Params::setParam('iDisplayLength', Cookie::newInstance()->get_value('listing_iDisplayLength'));
} else {
Params::setParam('iDisplayLength', 10 );
}
}
$this->_exportVariableToView('iDisplayLength', Params::getParam('iDisplayLength'));
// Table header order by related
if( Params::getParam('sort') == '') {
Params::setParam('sort', 'date');
}
if( Params::getParam('direction') == '') {
Params::setParam('direction', 'desc');
}
$page = (int)Params::getParam('iPage');
if($page==0) { $page = 1; };
Params::setParam('iPage', $page);
$params = Params::getParamsAsArray();
$banRulesDataTable = new BanRulesDataTable();
$banRulesDataTable->table($params);
$aData = $banRulesDataTable->getData();
if(count($aData['aRows']) == 0 && $page!=1) {
$total = (int)$aData['iTotalDisplayRecords'];
$maxPage = ceil( $total / (int)$aData['iDisplayLength'] );
$url = osc_admin_base_url(true).'?'.Params::getServerParam('QUERY_STRING', false, false);
if($maxPage==0) {
$url = preg_replace('/&iPage=(\d)+/', '&iPage=1', $url);
$this->redirectTo($url);
}
if($page > 1) {
$url = preg_replace('/&iPage=(\d)+/', '&iPage='.$maxPage, $url);
$this->redirectTo($url);
}
}
$this->_exportVariableToView('aData', $aData);
$this->_exportVariableToView('aRawRows', $banRulesDataTable->rawRows());
$bulk_options = array(
array('value' => '', 'data-dialog-content' => '', 'label' => __('Bulk actions')),
array('value' => 'delete_ban_rule', 'data-dialog-content' => sprintf(__('Are you sure you want to %s the selected ban rules?'), strtolower(__('Delete'))),
'label' => __('Delete'))
);
$bulk_options = osc_apply_filter("ban_rule_bulk_filter", $bulk_options);
$this->_exportVariableToView('bulk_options', $bulk_options);
//calling the view...
$this->doView('users/ban.php');
break;
case('edit_ban_rule'):
$this->_exportVariableToView('rule', BanRule::newInstance()->findByPrimaryKey(Params::getParam('id')));
$this->doView('users/ban_frm.php');
break;
case('edit_ban_rule_post'):
osc_csrf_check();
if(Params::getParam('s_ip')=='' && Params::getParam('s_email')=='') {
osc_add_flash_warning_message( _m("Both rules can not be empty"), 'admin');
$this->redirectTo(osc_admin_base_url(true) . '?page=users&action=ban');
}
BanRule::newInstance()->update(array('s_name' => Params::getParam('s_name'), 's_ip' => Params::getParam('s_ip'), 's_email' => strtolower(Params::getParam('s_email'))), array('pk_i_id' => Params::getParam('id')));
osc_add_flash_ok_message(_m('Rule updated correctly'), 'admin');
$this->redirectTo(osc_admin_base_url(true) . '?page=users&action=ban');
break;
case('create_ban_rule'):
$this->_exportVariableToView('rule', null);
$this->doView('users/ban_frm.php');
break;
case('create_ban_rule_post'):
osc_csrf_check();
if(Params::getParam('s_ip')=='' && Params::getParam('s_email')=='') {
osc_add_flash_warning_message( _m("Both rules can not be empty"), 'admin');
$this->redirectTo(osc_admin_base_url(true) . '?page=users&action=ban');
}
BanRule::newInstance()->insert(array('s_name' => Params::getParam('s_name'), 's_ip' => Params::getParam('s_ip'), 's_email' => strtolower(Params::getParam('s_email'))));
osc_add_flash_ok_message(_m('Rule saved correctly'), 'admin');
$this->redirectTo(osc_admin_base_url(true) . '?page=users&action=ban');
break;
case('delete_ban_rule'): //delete ban rules
osc_csrf_check();
$iDeleted = 0;
$ruleId = Params::getParam('id');
if( !is_array($ruleId) ) {
osc_add_flash_error_message( _m("User id isn't in the correct format"), 'admin');
$this->redirectTo(osc_admin_base_url(true) . '?page=users&action=ban');
}
$ruleMgr = BanRule::newInstance();
foreach($ruleId as $id) {
if($ruleMgr->deleteByPrimaryKey($id)) {
$iDeleted++;
}
}
if( $iDeleted == 0 ) {
$msg = _m('No rules have been deleted');
} else {
$msg = sprintf( _mn('One ban rule has been deleted', '%s ban rules have been deleted', $iDeleted), $iDeleted );
}
osc_add_flash_ok_message($msg, 'admin');
$this->redirectTo(osc_admin_base_url(true) . '?page=users&action=ban');
break;
default: // manage users view
if(Params::getParam("action")!="") {
osc_run_hook("user_bulk_".Params::getParam("action"), Params::getParam('id'));
}
require_once osc_lib_path()."osclass/classes/datatables/UsersDataTable.php";
// set default iDisplayLength
if( Params::getParam('iDisplayLength') != '' ) {
Cookie::newInstance()->push('listing_iDisplayLength', Params::getParam('iDisplayLength'));
Cookie::newInstance()->set();
} else {
// set a default value if it's set in the cookie
if( Cookie::newInstance()->get_value('listing_iDisplayLength') != '' ) {
Params::setParam('iDisplayLength', Cookie::newInstance()->get_value('listing_iDisplayLength'));
} else {
Params::setParam('iDisplayLength', 10 );
}
}
$this->_exportVariableToView('iDisplayLength', Params::getParam('iDisplayLength'));
// Table header order by related
if( Params::getParam('sort') == '') {
Params::setParam('sort', 'date');
}
if( Params::getParam('direction') == '') {
Params::setParam('direction', 'desc');
}
$page = (int)Params::getParam('iPage');
if($page==0) { $page = 1; };
Params::setParam('iPage', $page);
$params = Params::getParamsAsArray();
$usersDataTable = new UsersDataTable();
$usersDataTable->table($params);
$aData = $usersDataTable->getData();
if(count($aData['aRows']) == 0 && $page!=1) {
$total = (int)$aData['iTotalDisplayRecords'];
$maxPage = ceil( $total / (int)$aData['iDisplayLength'] );
$url = osc_admin_base_url(true).'?'.Params::getServerParam('QUERY_STRING', false, false);
if($maxPage==0) {
$url = preg_replace('/&iPage=(\d)+/', '&iPage=1', $url);
$this->redirectTo($url);
}
if($page > 1) {
$url = preg_replace('/&iPage=(\d)+/', '&iPage='.$maxPage, $url);
$this->redirectTo($url);
}
}
$this->_exportVariableToView('aData', $aData);
$this->_exportVariableToView('withFilters', $usersDataTable->withFilters());
$this->_exportVariableToView('aRawRows', $usersDataTable->rawRows());
$bulk_options = array(
array('value' => '', 'data-dialog-content' => '', 'label' => __('Bulk actions')),
array('value' => 'activate', 'data-dialog-content' => sprintf(__('Are you sure you want to %s the selected users?'), strtolower(__('Activate'))), 'label' => __('Activate')),
array('value' => 'deactivate', 'data-dialog-content' => sprintf(__('Are you sure you want to %s the selected users?'), strtolower(__('Deactivate'))), 'label' => __('Deactivate')),
array('value' => 'enable', 'data-dialog-content' => sprintf(__('Are you sure you want to %s the selected users?'), strtolower(__('Unblock'))), 'label' => __('Unblock')),
array('value' => 'disable', 'data-dialog-content' => sprintf(__('Are you sure you want to %s the selected users?'), strtolower(__('Block'))), 'label' => __('Block')),
array('value' => 'delete', 'data-dialog-content' => sprintf(__('Are you sure you want to %s the selected users?'), strtolower(__('Delete'))), 'label' => __('Delete'))
);
if( osc_user_validation_enabled() ) {
$bulk_options[] = array('value' => 'resend_activation', 'data-dialog-content' => sprintf(__('Are you sure you want to %s the selected users?'), strtolower(__('Resend the activation to'))), 'label' => __('Resend activation'));
}
$bulk_options = osc_apply_filter("user_bulk_filter", $bulk_options);
$this->_exportVariableToView('bulk_options', $bulk_options);
//calling the view...
$this->doView('users/index.php');
break;
}
}
//hopefully generic...
function doView($file)
{
osc_run_hook("before_admin_html");
osc_current_admin_theme_path($file);
Session::newInstance()->_clearVariables();
osc_run_hook("after_admin_html");
}
}
/* file end: ./oc-admin/users.php */
?>