Simple Login Log - Version 1.1.1

Version Description

Download this release

Release Info

Developer maxchirkov
Plugin Icon wp plugin Simple Login Log
Version 1.1.1
Comparing to
See all releases

Code changes from version 1.0 to 1.1.1

languages/sll-fr_FR.mo ADDED
Binary file
languages/sll-zh_CN.mo ADDED
Binary file
readme.txt CHANGED
@@ -3,8 +3,8 @@ Contributors: maxchirkov
3
  Donate link: http://www.ibsteam.net/donate
4
  Tags: login, log, users
5
  Requires at least: 3.0
6
- Tested up to: 3.8
7
- Stable tag: 1.0
8
 
9
  This plugin keeps a log of WordPress user logins. Offers user and date filtering, and export features.
10
 
@@ -27,6 +27,8 @@ Simple log of user logins. Tracks user name, time of login, IP address and brows
27
  - German [de_DE] by Philipp Moore
28
  - Russian [ru_RU]
29
  - Ukrainian [ua_UA]
 
 
30
 
31
  * Author: Max Chirkov
32
  * Author URI: [http://simplerealtytheme.com/](http://simplerealtytheme.com/ "Real Estate Themes & Plugins for WordPress")
@@ -38,7 +40,7 @@ Simple log of user logins. Tracks user name, time of login, IP address and brows
38
  2. If you wish to set log truncation or opt-in to record failed login attempts, go to Settings => General. Scroll down to Simple Login Log.
39
  3. To view login log, go to Users => Login Log. You can export the log to CSV file form the same page.
40
 
41
- Screen Options are available at the top of the Login Log page. Click on the *Secreen Options* tab to expand the options section. You'll be able to change the number of results per page as well as hide/display table columns.
42
 
43
  == Screenshots ==
44
 
@@ -47,6 +49,17 @@ Screen Options are available at the top of the Login Log page. Click on the *Sec
47
 
48
  == Changelog ==
49
 
 
 
 
 
 
 
 
 
 
 
 
50
  **Version 1.0**
51
 
52
  - WP 3.8 compatibility update.
3
  Donate link: http://www.ibsteam.net/donate
4
  Tags: login, log, users
5
  Requires at least: 3.0
6
+ Tested up to: 4.6
7
+ Stable tag: 1.1.1
8
 
9
  This plugin keeps a log of WordPress user logins. Offers user and date filtering, and export features.
10
 
27
  - German [de_DE] by Philipp Moore
28
  - Russian [ru_RU]
29
  - Ukrainian [ua_UA]
30
+ - Chinese [zh_CN] by [Mihuwa](http://www.mihuwa.com/)
31
+ - French [fr_FR] by [Mehdi Hamida](http://www.lo-geek.fr/)
32
 
33
  * Author: Max Chirkov
34
  * Author URI: [http://simplerealtytheme.com/](http://simplerealtytheme.com/ "Real Estate Themes & Plugins for WordPress")
40
  2. If you wish to set log truncation or opt-in to record failed login attempts, go to Settings => General. Scroll down to Simple Login Log.
41
  3. To view login log, go to Users => Login Log. You can export the log to CSV file form the same page.
42
 
43
+ Screen Options are available at the top of the Login Log page. Click on the *Screen Options* tab to expand the options section. You'll be able to change the number of results per page as well as hide/display table columns.
44
 
45
  == Screenshots ==
46
 
49
 
50
  == Changelog ==
51
 
52
+ **Version 1.1.0**
53
+
54
+ - WP 4.6 compatibility update
55
+
56
+ **Version 1.1.0**
57
+
58
+ - Fixed: some SQL queries were requesting all records, which caused some sites to run out of memory.
59
+ - Numerous minor fixes and improvements.
60
+ - Added Chinese and French translations.
61
+ - New Feature: Delete All link - deletes all log records at once.
62
+
63
  **Version 1.0**
64
 
65
  - WP 3.8 compatibility update.
simple-login-log.php CHANGED
@@ -4,7 +4,7 @@
4
  Plugin URI: http://simplerealtytheme.com
5
  Description: This plugin keeps a log of WordPress user logins. Offers user filtering and export features.
6
  Author: Max Chirkov
7
- Version: 1.0
8
  Author URI: http://SimpleRealtyTheme.com
9
  */
10
 
@@ -12,7 +12,9 @@
12
 
13
  if( !class_exists( 'SimpleLoginLog' ) )
14
  {
15
- class SimpleLoginLog {
 
 
16
  private $db_ver = "1.2";
17
  public $table = 'simple_login_log';
18
  private $log_duration = null; //days
@@ -21,6 +23,7 @@ if( !class_exists( 'SimpleLoginLog' ) )
21
  private $login_success = 1;
22
  public $data_labels = array();
23
 
 
24
 
25
  function __construct()
26
  {
@@ -42,9 +45,6 @@ if( !class_exists( 'SimpleLoginLog' ) )
42
  //Get plugin's DB version
43
  $this->installed_ver = get_option( "sll_db_ver" );
44
 
45
-
46
-
47
-
48
  add_action( 'admin_menu', array($this, 'sll_admin_menu') );
49
  add_action('admin_init', array($this, 'settings_api_init') );
50
  add_action('admin_head', array($this, 'screen_options') );
@@ -57,6 +57,7 @@ if( !class_exists( 'SimpleLoginLog' ) )
57
 
58
  //Init CSV Export
59
  add_action('admin_init', array($this, 'init_csv_export') );
 
60
 
61
  //Style the log table
62
  add_action( 'admin_head', array($this, 'admin_header') );
@@ -92,6 +93,18 @@ if( !class_exists( 'SimpleLoginLog' ) )
92
  }
93
 
94
 
 
 
 
 
 
 
 
 
 
 
 
 
95
  function load_locale()
96
  {
97
  load_plugin_textdomain( 'sll', false, basename(dirname(__FILE__)) . '/languages/' );
@@ -141,9 +154,9 @@ if( !class_exists( 'SimpleLoginLog' ) )
141
 
142
  function init_login_actions()
143
  {
144
- //condition to check if "log failed attemts" option is selected
145
 
146
- //Action on successfull login
147
  add_action( 'wp_login', array($this, 'login_success') );
148
 
149
  //Action on failed login
@@ -210,6 +223,29 @@ if( !class_exists( 'SimpleLoginLog' ) )
210
  }
211
 
212
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
213
  /**
214
  * Runs via plugin activation hook & creates a database
215
  */
@@ -272,13 +308,12 @@ if( !class_exists( 'SimpleLoginLog' ) )
272
  */
273
  function db_update_1_1()
274
  {
275
-
276
  /* this version adds a new field "login_result"
277
  * check if this field exists
278
  */
279
  global $wpdb;
280
 
281
- $sql = "SELECT * FROM {$this->table}";
282
  $fields = $wpdb->get_row($sql, 'ARRAY_A');
283
 
284
  if( !$fields ){
@@ -310,7 +345,7 @@ if( !class_exists( 'SimpleLoginLog' ) )
310
  */
311
  global $wpdb;
312
 
313
- $sql = "SELECT * FROM {$this->table}";
314
  $fields = $wpdb->get_row($sql, 'ARRAY_A');
315
 
316
  if( !$fields ){
@@ -386,14 +421,7 @@ if( !class_exists( 'SimpleLoginLog' ) )
386
  return;
387
 
388
  echo '<style type="text/css">';
389
- echo '.wp-list-table .column-id { width: 5%; }';
390
- echo '.wp-list-table .column-uid { width: 10%; }';
391
- echo '.wp-list-table .column-user_login { width: 10%; }';
392
- echo '.wp-list-table .column-name { width: 15%; }';
393
- echo '.wp-list-table .column-time { width: 15%; }';
394
- echo '.wp-list-table .column-ip { width: 10%; }';
395
- echo '.wp-list-table .column-login_result { width: 10%; }';
396
- echo '.wp-list-table .login-failed { background: #ffd5d1; }';
397
  echo '</style>';
398
  }
399
 
@@ -427,7 +455,7 @@ if( !class_exists( 'SimpleLoginLog' ) )
427
  'user_login' => $user_login,
428
  'user_role' => $user_role,
429
  'time' => current_time('mysql'),
430
- 'ip' => isset( $_SERVER['HTTP_X_REAL_IP'] ) ? esc_attr( $_SERVER['HTTP_X_REAL_IP'] ) : esc_attr( $_SERVER['REMOTE_ADDR'] ),
431
  'login_result' => $this->login_success,
432
  'data' => $serialized_data,
433
  );
@@ -476,7 +504,13 @@ if( !class_exists( 'SimpleLoginLog' ) )
476
  }
477
 
478
 
479
- function log_get_data()
 
 
 
 
 
 
480
  {
481
  global $wpdb;
482
 
@@ -484,10 +518,13 @@ if( !class_exists( 'SimpleLoginLog' ) )
484
 
485
  $where = $this->make_where_query();
486
 
 
 
 
487
  if( is_array($where) && !empty($where) )
488
- $where = 'WHERE ' . implode(' AND ', $where);
489
 
490
- $sql = "SELECT * FROM $this->table $where ORDER BY time DESC";
491
  $data = $wpdb->get_results($sql, 'ARRAY_A');
492
 
493
  return $data;
@@ -499,11 +536,16 @@ if( !class_exists( 'SimpleLoginLog' ) )
499
 
500
  $log_table = $this->log_table;
501
 
502
- $log_table->items = $this->log_get_data();
503
  $log_table->prepare_items();
504
 
505
  echo '<div class="wrap srp">';
506
  echo '<h2>' . __('Login Log', 'sll') . '</h2>';
 
 
 
 
 
 
507
  echo '<div class="tablenav top">';
508
  echo '<div class="alignleft actions">';
509
  echo $this->date_filter();
@@ -541,7 +583,10 @@ if( !class_exists( 'SimpleLoginLog' ) )
541
 
542
  echo '<input type="hidden" name="page" value="login_log" />';
543
  echo '<input type="hidden" name="download-login-log" value="true" />';
544
- submit_button( __('Export Log to CSV', 'sll'), 'secondary' );
 
 
 
545
  echo '</form>';
546
  //if filtered results - add export filtered results button
547
  $where = false;
@@ -600,7 +645,9 @@ if( !class_exists( 'SimpleLoginLog' ) )
600
  function init_csv_export()
601
  {
602
  //Check if download was initiated
603
- $download = @esc_attr( $_GET['download-login-log'] );
 
 
604
  if($download)
605
  {
606
  check_admin_referer( 'ssl_export_log' );
@@ -683,6 +730,9 @@ if(!class_exists('WP_List_Table'))
683
 
684
  class SLL_List_Table extends WP_List_Table
685
  {
 
 
 
686
  function __construct()
687
  {
688
  global $sll, $_wp_column_headers;
@@ -695,7 +745,18 @@ class SLL_List_Table extends WP_List_Table
695
  ) );
696
 
697
  $this->data_labels = $sll->data_labels;
 
 
698
 
 
 
 
 
 
 
 
 
 
699
  }
700
 
701
 
@@ -716,7 +777,7 @@ class SLL_List_Table extends WP_List_Table
716
  return $item[$column_name];
717
  case 'user_login':
718
  return "<a href='" . add_query_arg( array('filter' => $item[$column_name]), menu_page_url('login_log', false) ) . "' title='" . __('Filter log by this name', 'sll') . "'>{$item[$column_name]}</a>";
719
- case 'name';
720
  $user_info = get_userdata($item['uid']);
721
  return ( is_object($user_info) ) ? $user_info->first_name . " " . $user_info->last_name : false;
722
  case 'login_result':
@@ -802,34 +863,7 @@ class SLL_List_Table extends WP_List_Table
802
  $failed = ( '0' == $_GET['result'] ) ? 'class="current"' : '';
803
  }
804
 
805
- //get number of successful and failed logins so we can display them in parentheces for each view
806
- global $wpdb, $sll;
807
 
808
- //building a WHERE SQL query for each view
809
- $where = $sll->make_where_query();
810
- //we only need the date filter, everything else need to be unset
811
- if( is_array($where) && isset($where['datefilter']) ){
812
- $where = array( 'datefilter' => $where['datefilter'] );
813
- }else{
814
- $where = false;
815
- }
816
-
817
- $where3 = $where2 = $where1 = $where;
818
- $where2['login_result'] = "login_result = '1'";
819
- $where3['login_result'] = "login_result = '0'";
820
-
821
- if(is_array($where1) && !empty($where1)){
822
- $where1 = 'WHERE ' . implode(' AND ', $where1);
823
- }
824
- $where2 = 'WHERE ' . implode(' AND ', $where2);
825
- $where3 = 'WHERE ' . implode(' AND ', $where3);
826
-
827
- $sql1 = "SELECT * FROM {$sll->table} {$where1}";
828
- $a = $wpdb->query($sql1);
829
- $sql2 = "SELECT * FROM {$sll->table} {$where2}";
830
- $s = $wpdb->query($sql2);
831
- $sql3 = "SELECT * FROM {$sll->table} {$where3}";
832
- $f = $wpdb->query($sql3);
833
 
834
  //if date filter is set, adjust views label to reflect the date
835
  $date_label = false;
@@ -856,9 +890,9 @@ class SLL_List_Table extends WP_List_Table
856
 
857
  //definition for views array
858
  $views = array(
859
- 'all' => $date_label . __('Login Results', 'sll') . ': <a ' . $all . ' href="' . $url . '">' . __('All', 'sll') . '</a>' . '(' .$a . ')',
860
- 'success' => '<a ' . $success . ' href="' . $url . '&result=1">' . __('Successful', 'sll') . '</a> (' . $s . ')',
861
- 'failed' => '<a ' . $failed . ' href="' . $url . '&result=0">' . __('Failed', 'sll') . '</a>' . '(' . $f . ')',
862
  );
863
 
864
  return $views;
@@ -867,6 +901,40 @@ class SLL_List_Table extends WP_List_Table
867
 
868
  function prepare_items()
869
  {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
870
  $screen = get_current_screen();
871
 
872
  /**
@@ -876,6 +944,12 @@ class SLL_List_Table extends WP_List_Table
876
  $per_page = get_option($per_page_option, 20);
877
  $per_page = ($per_page != false) ? $per_page : 20;
878
 
 
 
 
 
 
 
879
 
880
  /**
881
  * REQUIRED. Now we need to define our column headers. This includes a complete
@@ -916,7 +990,7 @@ class SLL_List_Table extends WP_List_Table
916
  * use sort and pagination data to build a custom query instead, as you'll
917
  * be able to use your precisely-queried data immediately.
918
  */
919
- $data = $this->items;
920
 
921
 
922
  /**
@@ -927,13 +1001,14 @@ class SLL_List_Table extends WP_List_Table
927
  * to a custom query. The returned data will be pre-sorted, and this array
928
  * sorting technique would be unnecessary.
929
  */
930
- function usort_reorder($a,$b){
931
- $orderby = (!empty($_REQUEST['orderby'])) ? $_REQUEST['orderby'] : 'time'; //If no sort, default to title
932
- $order = (!empty($_REQUEST['order'])) ? $_REQUEST['order'] : 'desc'; //If no order, default to asc
933
- $result = strcmp($a[$orderby], $b[$orderby]); //Determine sort order
934
- return ($order==='asc') ? $result : -$result; //Send final sort direction to usort
935
- }
936
- usort($data, 'usort_reorder');
 
937
 
938
 
939
  /***********************************************************************
@@ -960,7 +1035,19 @@ class SLL_List_Table extends WP_List_Table
960
  * without filtering. We'll need this later, so you should always include it
961
  * in your own package classes.
962
  */
963
- $total_items = count($data);
 
 
 
 
 
 
 
 
 
 
 
 
964
 
965
 
966
  /**
@@ -968,7 +1055,7 @@ class SLL_List_Table extends WP_List_Table
968
  * to ensure that the data is trimmed to only the current page. We can use
969
  * array_slice() to
970
  */
971
- $data = array_slice($data,(($current_page-1)*$per_page),$per_page);
972
 
973
 
974
 
@@ -976,7 +1063,7 @@ class SLL_List_Table extends WP_List_Table
976
  * REQUIRED. Now we can add our *sorted* data to the items property, where
977
  * it can be used by the rest of the class.
978
  */
979
- $this->items = $data;
980
 
981
 
982
  /**
4
  Plugin URI: http://simplerealtytheme.com
5
  Description: This plugin keeps a log of WordPress user logins. Offers user filtering and export features.
6
  Author: Max Chirkov
7
+ Version: 1.1.1
8
  Author URI: http://SimpleRealtyTheme.com
9
  */
10
 
12
 
13
  if( !class_exists( 'SimpleLoginLog' ) )
14
  {
15
+
16
+ class SimpleLoginLog
17
+ {
18
  private $db_ver = "1.2";
19
  public $table = 'simple_login_log';
20
  private $log_duration = null; //days
23
  private $login_success = 1;
24
  public $data_labels = array();
25
 
26
+ private $values;
27
 
28
  function __construct()
29
  {
45
  //Get plugin's DB version
46
  $this->installed_ver = get_option( "sll_db_ver" );
47
 
 
 
 
48
  add_action( 'admin_menu', array($this, 'sll_admin_menu') );
49
  add_action('admin_init', array($this, 'settings_api_init') );
50
  add_action('admin_head', array($this, 'screen_options') );
57
 
58
  //Init CSV Export
59
  add_action('admin_init', array($this, 'init_csv_export') );
60
+ add_action('admin_init', array($this, 'delete_all') );
61
 
62
  //Style the log table
63
  add_action( 'admin_head', array($this, 'admin_header') );
93
  }
94
 
95
 
96
+ function set($name, $value)
97
+ {
98
+ $this->values[$name] = $value;
99
+ }
100
+
101
+
102
+ function get($name)
103
+ {
104
+ return (isset($this->values[$name])) ? $this->values[$name] : false;
105
+ }
106
+
107
+
108
  function load_locale()
109
  {
110
  load_plugin_textdomain( 'sll', false, basename(dirname(__FILE__)) . '/languages/' );
154
 
155
  function init_login_actions()
156
  {
157
+ //condition to check if "log failed attempts" option is selected
158
 
159
+ //Action on successful login
160
  add_action( 'wp_login', array($this, 'login_success') );
161
 
162
  //Action on failed login
223
  }
224
 
225
 
226
+ function delete_all()
227
+ {
228
+ global $wpdb;
229
+
230
+ $nonce = isset($_REQUEST['_wpnonce']) ? $_REQUEST['_wpnonce'] : false;
231
+
232
+ if (!wp_verify_nonce($nonce, 'delete_sll'))
233
+ {
234
+ return;
235
+ }
236
+ else
237
+ {
238
+ $sql = "DELETE FROM {$this->table}";
239
+
240
+ if ($wpdb->query($sql))
241
+ {
242
+ $this->set('deleted', true);
243
+ }
244
+ }
245
+ }
246
+
247
+
248
+
249
  /**
250
  * Runs via plugin activation hook & creates a database
251
  */
308
  */
309
  function db_update_1_1()
310
  {
 
311
  /* this version adds a new field "login_result"
312
  * check if this field exists
313
  */
314
  global $wpdb;
315
 
316
+ $sql = "SELECT * FROM {$this->table} LIMIT 1";
317
  $fields = $wpdb->get_row($sql, 'ARRAY_A');
318
 
319
  if( !$fields ){
345
  */
346
  global $wpdb;
347
 
348
+ $sql = "SELECT * FROM {$this->table} LIMIT 1";
349
  $fields = $wpdb->get_row($sql, 'ARRAY_A');
350
 
351
  if( !$fields ){
421
  return;
422
 
423
  echo '<style type="text/css">';
424
+ echo 'table.users { table-layout: auto; }';
 
 
 
 
 
 
 
425
  echo '</style>';
426
  }
427
 
455
  'user_login' => $user_login,
456
  'user_role' => $user_role,
457
  'time' => current_time('mysql'),
458
+ 'ip' => isset($_SERVER['HTTP_X_FORWARDED_FOR']) ? esc_attr($_SERVER['HTTP_X_FORWARDED_FOR']) : esc_attr($_SERVER['REMOTE_ADDR']),
459
  'login_result' => $this->login_success,
460
  'data' => $serialized_data,
461
  );
504
  }
505
 
506
 
507
+ function getLimit()
508
+ {
509
+ return ' LIMIT ' . get_option('users_page_login_log_per_page', 20);
510
+ }
511
+
512
+
513
+ function log_get_data($orderby = false, $order = false, $limit = 0, $offset = 0)
514
  {
515
  global $wpdb;
516
 
518
 
519
  $where = $this->make_where_query();
520
 
521
+ $orderby = (!isset($orderby) || $orderby == '') ? 'time' : $orderby;
522
+ $order = (!isset($order) || $order == '') ? 'DESC' : $order;
523
+
524
  if( is_array($where) && !empty($where) )
525
+ $where = ' WHERE ' . implode(' AND ', $where);
526
 
527
+ $sql = "SELECT * FROM $this->table" . $where . " ORDER BY {$orderby} {$order} " . 'LIMIT ' . $limit . ' OFFSET ' . $offset;
528
  $data = $wpdb->get_results($sql, 'ARRAY_A');
529
 
530
  return $data;
536
 
537
  $log_table = $this->log_table;
538
 
 
539
  $log_table->prepare_items();
540
 
541
  echo '<div class="wrap srp">';
542
  echo '<h2>' . __('Login Log', 'sll') . '</h2>';
543
+
544
+ if ($this->get('deleted'))
545
+ {
546
+ echo '<div class="updated"><p>All records were deleted.</p></div>';
547
+ }
548
+
549
  echo '<div class="tablenav top">';
550
  echo '<div class="alignleft actions">';
551
  echo $this->date_filter();
583
 
584
  echo '<input type="hidden" name="page" value="login_log" />';
585
  echo '<input type="hidden" name="download-login-log" value="true" />';
586
+ echo '<p class="submit">';
587
+ echo '<input type="submit" name="submit" id="submit" class="button" value="Export Log to CSV">';
588
+ echo '&nbsp;&nbsp;<a id="delete-all" href="' . wp_nonce_url('users.php?page=login_log&action=delete', 'delete_sll') . '" onclick="return confirm(\'IMPORTANT: All User Log records will be deleted.\')">Delete All</a>';
589
+ echo '</p>';
590
  echo '</form>';
591
  //if filtered results - add export filtered results button
592
  $where = false;
645
  function init_csv_export()
646
  {
647
  //Check if download was initiated
648
+
649
+ $download = (isset($_GET['download-login-log'])) ? esc_attr($_GET['download-login-log']) : false;
650
+
651
  if($download)
652
  {
653
  check_admin_referer( 'ssl_export_log' );
730
 
731
  class SLL_List_Table extends WP_List_Table
732
  {
733
+ private $sllData;
734
+ protected $data_labels;
735
+
736
  function __construct()
737
  {
738
  global $sll, $_wp_column_headers;
745
  ) );
746
 
747
  $this->data_labels = $sll->data_labels;
748
+ }
749
+
750
 
751
+ function set($name, $value)
752
+ {
753
+ $this->sllData[$name] = $value;
754
+ }
755
+
756
+
757
+ function get($name)
758
+ {
759
+ return (isset($this->sllData[$name])) ? $this->sllData[$name] : false;
760
  }
761
 
762
 
777
  return $item[$column_name];
778
  case 'user_login':
779
  return "<a href='" . add_query_arg( array('filter' => $item[$column_name]), menu_page_url('login_log', false) ) . "' title='" . __('Filter log by this name', 'sll') . "'>{$item[$column_name]}</a>";
780
+ case 'name':
781
  $user_info = get_userdata($item['uid']);
782
  return ( is_object($user_info) ) ? $user_info->first_name . " " . $user_info->last_name : false;
783
  case 'login_result':
863
  $failed = ( '0' == $_GET['result'] ) ? 'class="current"' : '';
864
  }
865
 
 
 
866
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
867
 
868
  //if date filter is set, adjust views label to reflect the date
869
  $date_label = false;
890
 
891
  //definition for views array
892
  $views = array(
893
+ 'all' => $date_label . __('Login Results', 'sll') . ': <a ' . $all . ' href="' . $url . '">' . __('All', 'sll') . '</a>' . '(' .$this->get('allTotal') . ')',
894
+ 'success' => '<a ' . $success . ' href="' . $url . '&result=1">' . __('Successful', 'sll') . '</a> (' . $this->get('successTotal') . ')',
895
+ 'failed' => '<a ' . $failed . ' href="' . $url . '&result=0">' . __('Failed', 'sll') . '</a>' . '(' . $this->get('failedTotal') . ')',
896
  );
897
 
898
  return $views;
901
 
902
  function prepare_items()
903
  {
904
+ global $wpdb, $sll;
905
+
906
+ //get number of successful and failed logins so we can display them in parentheces for each view
907
+
908
+ //building a WHERE SQL query for each view
909
+ $where = $sll->make_where_query();
910
+ //we only need the date filter, everything else need to be unset
911
+ if( is_array($where) && isset($where['datefilter']) ){
912
+ $where = array( 'datefilter' => $where['datefilter'] );
913
+ }else{
914
+ $where = false;
915
+ }
916
+
917
+ $where3 = $where2 = $where1 = $where;
918
+ $where2['login_result'] = "login_result = '1'";
919
+ $where3['login_result'] = "login_result = '0'";
920
+
921
+ if(is_array($where1) && !empty($where1)){
922
+ $where1 = 'WHERE ' . implode(' AND ', $where1);
923
+ }
924
+ $where2 = 'WHERE ' . implode(' AND ', $where2);
925
+ $where3 = 'WHERE ' . implode(' AND ', $where3);
926
+
927
+ $sql1 = "SELECT count(*) FROM {$sll->table} {$where1}";
928
+ $allTotal = $wpdb->get_var($sql1);
929
+ $sql2 = "SELECT count(*) FROM {$sll->table} {$where2}";
930
+ $successTotal = $wpdb->get_var($sql2);
931
+ $sql3 = "SELECT count(*) FROM {$sll->table} {$where3}";
932
+ $failedTotal = $wpdb->get_var($sql3);
933
+
934
+ $this->set('allTotal', $allTotal);
935
+ $this->set('successTotal', $successTotal);
936
+ $this->set('failedTotal', $failedTotal);
937
+
938
  $screen = get_current_screen();
939
 
940
  /**
944
  $per_page = get_option($per_page_option, 20);
945
  $per_page = ($per_page != false) ? $per_page : 20;
946
 
947
+ $offset = $per_page * ($this->get_pagenum() - 1);
948
+
949
+ $orderby = (isset($_REQUEST['orderby']) && !empty($_REQUEST['orderby'])) ? $_REQUEST['orderby'] : false;
950
+ $order = (isset($_REQUEST['order']) && !empty($_REQUEST['order'])) ? $_REQUEST['order'] : false;
951
+
952
+ $this->items = $sll->log_get_data($orderby, $order, $per_page, $offset);
953
 
954
  /**
955
  * REQUIRED. Now we need to define our column headers. This includes a complete
990
  * use sort and pagination data to build a custom query instead, as you'll
991
  * be able to use your precisely-queried data immediately.
992
  */
993
+ // $data = $this->items;
994
 
995
 
996
  /**
1001
  * to a custom query. The returned data will be pre-sorted, and this array
1002
  * sorting technique would be unnecessary.
1003
  */
1004
+ // function usort_reorder($a,$b)
1005
+ // {
1006
+ // $orderby = (!empty($_REQUEST['orderby'])) ? $_REQUEST['orderby'] : 'time'; //If no sort, default to title
1007
+ // $order = (!empty($_REQUEST['order'])) ? $_REQUEST['order'] : 'desc'; //If no order, default to asc
1008
+ // $result = strcmp($a[$orderby], $b[$orderby]); //Determine sort order
1009
+ // return ($order==='asc') ? $result : -$result; //Send final sort direction to usort
1010
+ // }
1011
+ // usort($data, 'usort_reorder');
1012
 
1013
 
1014
  /***********************************************************************
1035
  * without filtering. We'll need this later, so you should always include it
1036
  * in your own package classes.
1037
  */
1038
+
1039
+ if (isset($_GET['result']) && $_GET['result'] == '1')
1040
+ {
1041
+ $total_items = $wpdb->get_var("SELECT COUNT(*) FROM $sll->table {$where2}");
1042
+ }
1043
+ else if(isset($_GET['result']) && $_GET['result'] == '0')
1044
+ {
1045
+ $total_items = $wpdb->get_var("SELECT COUNT(*) FROM $sll->table {$where3}");
1046
+ }
1047
+ else
1048
+ {
1049
+ $total_items = $wpdb->get_var("SELECT COUNT(*) FROM $sll->table");
1050
+ }
1051
 
1052
 
1053
  /**
1055
  * to ensure that the data is trimmed to only the current page. We can use
1056
  * array_slice() to
1057
  */
1058
+ // $data = array_slice($data,(($current_page-1)*$per_page),$per_page);
1059
 
1060
 
1061
 
1063
  * REQUIRED. Now we can add our *sorted* data to the items property, where
1064
  * it can be used by the rest of the class.
1065
  */
1066
+ // $this->items = $data;
1067
 
1068
 
1069
  /**