@@ -17,9 +17,8 @@ function admin_index()
1717
1818 $ this ->set ('title_for_layout ' , $ this ->Lang ->get ("BAN__HOME " ));
1919 $ this ->layout = 'admin ' ;
20-
20+ $ this -> loadModel ( " user " );
2121 $ this ->loadModel ("Ban " );
22- $ this ->loadModel ("User " );
2322 $ banned_users = $ this ->Ban ->find ("all " );
2423
2524 $ users = $ this ->User ->find ("all " );
@@ -34,6 +33,7 @@ function admin_add()
3433
3534 $ this ->set ('title_for_layout ' , $ this ->Lang ->get ("BAN__HOME " ));
3635 $ this ->layout = 'admin ' ;
36+ $ this ->set ('type ' , $ this ->Configuration ->getKey ('member_page_type ' ));
3737
3838 if ($ this ->request ->is ("post " )) {
3939 $ this ->autoRender = false ;
@@ -79,12 +79,11 @@ public function admin_get_users_not_ban()
7979 0 => ['label ' => 'success ' , 'name ' => $ this ->Lang ->get ('USER__RANK_MEMBER ' )],
8080 2 => ['label ' => 'warning ' , 'name ' => $ this ->Lang ->get ('USER__RANK_MODERATOR ' )],
8181 3 => ['label ' => 'danger ' , 'name ' => $ this ->Lang ->get ('USER__RANK_ADMINISTRATOR ' )],
82- 4 => ['label ' => 'danger ' , 'name ' => $ this ->Lang ->get ('USER__RANK_ADMINISTRATOR ' )],
83- 5 => ['label ' => 'primary ' , 'name ' => $ this ->Lang ->get ('USER__RANK_BANNED ' )]
82+ 4 => ['label ' => 'danger ' , 'name ' => $ this ->Lang ->get ('USER__RANK_ADMINISTRATOR ' )]
8483 ];
8584 $ this ->loadModel ('Rank ' );
8685 $ custom_ranks = $ this ->Rank ->find ('all ' );
87- foreach ($ custom_ranks as $ value ) {
86+ foreach ($ custom_ranks as $ key => $ value ) {
8887 $ available_ranks [$ value ['Rank ' ]['rank_id ' ]] = [
8988 'label ' => 'info ' ,
9089 'name ' => $ value ['Rank ' ]['name ' ]
@@ -100,7 +99,7 @@ public function admin_get_users_not_ban()
10099 $ response = $ this ->DataTable ->getResponse ();
101100 $ users = $ response ['aaData ' ];
102101 $ data = [];
103- foreach ($ users as $ value ) {
102+ foreach ($ users as $ key => $ value ) {
104103 $ checkIsBan = $ this ->Ban ->find ('first ' , ["conditions " => ['user_id ' => $ value ['User ' ]['id ' ]]]);
105104
106105 if ($ checkIsBan != null )
@@ -127,4 +126,33 @@ public function admin_get_users_not_ban()
127126 }
128127 }
129128 }
129+
130+ function admin_liveSearch ($ query = false )
131+ {
132+ $ this ->autoRender = false ;
133+ $ this ->response ->type ('json ' );
134+ if ($ this ->isConnected and $ this ->Permissions ->can ('MANAGE_USERS ' )) {
135+ $ this ->loadModel ("User " );
136+ if ($ query != false ) {
137+ $ result = $ this ->User ->find ('all ' , ['conditions ' => ['pseudo LIKE ' => $ query . '% ' ]]);
138+ foreach ($ result as $ key => $ value ) {
139+ $ checkIsBan = $ this ->Ban ->find ('first ' , ["conditions " => ['user_id ' => $ value ['User ' ]['id ' ]]]);
140+
141+ if ($ checkIsBan != null )
142+ continue ;
143+
144+ if ($ this ->Permissions ->have ($ value ['User ' ]['rank ' ], "CAN_BE_BAN " ))
145+ continue ;
146+
147+ $ users [] = ['pseudo ' => $ value ['User ' ]['pseudo ' ], 'id ' => $ value ['User ' ]['id ' ]];
148+ }
149+ $ response = (empty ($ result )) ? ['status ' => false ] : ['status ' => true , 'data ' => $ users ];
150+ $ this ->response ->body ($ response );
151+ } else {
152+ $ this ->response ->body (json_encode (['status ' => false ]));
153+ }
154+ } else {
155+ $ this ->response ->body (json_encode (['status ' => false ]));
156+ }
157+ }
130158}
0 commit comments