shoropio

custom_functions.php

Feb 6th, 2018
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.70 KB | None | 0 0
  1. <?php
  2. /*
  3. UserSpice 4
  4. An Open Source PHP User Management System
  5. by the UserSpice Team at http://UserSpice.com
  6.  
  7. This program is free software: you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation, either version 3 of the License, or
  10. (at your option) any later version.
  11.  
  12. This program is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. GNU General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with this program.  If not, see <http://www.gnu.org/licenses/>.
  19. */
  20.  
  21. //Put your custom functions in this file and they will be automatically included.
  22.  
  23. //bold("<br><br>custom helpers included");
  24.  
  25. // Get Roles
  26. function getRoles($id, $opts = []){
  27.     $db = DB::getInstance();
  28.     $userQ = $db->query("SELECT * FROM user_permission_matches WHERE user_id = ? ORDER BY permission_id DESC",array($id));
  29.     $c = $userQ->count();
  30.  
  31.     if($c > 0){
  32.         $u = $userQ->first();
  33.         echoPerm($u->permission_id);
  34.     }
  35. }
  36.  
  37.     function echoPerm($id){
  38.         $db = DB::getInstance();
  39.         $p = $db->query("SELECT * FROM permissions WHERE id = ?",array($id))->first();
  40.         echo $p->name;
  41.     }
  42.  
  43. // Generate Random String
  44. function generateRandomString($length = 10) {
  45.     $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
  46.     $charactersLength = strlen($characters);
  47.     $randomString = '';
  48.     for ($i = 0; $i < $length; $i++) {
  49.         $randomString .= $characters[rand(0, $charactersLength - 1)];
  50.     }
  51.     return $randomString;
  52. }
Advertisement
Add Comment
Please, Sign In to add comment