Advertisement
Guest User

Untitled

a guest
Jul 6th, 2017
539
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.82 KB | None | 0 0
  1. <?php
  2. /***************************************************************************
  3.  *                                users.php
  4.  *                            -------------------
  5.  *   Project              : Flamework
  6.  *   Begin                : June 11, 2010
  7.  *   Copyright            : (C) 2010 Robert Herman ( maverfax@gmail.com )
  8.  *
  9.  ***************************************************************************/
  10.  
  11. class Subpage
  12. {
  13.     static $data = array
  14.     (
  15.         'message'    => 'You can manage your users here.',
  16.         'color'      => 'green',
  17.         'user'       => array(),
  18.         'type'       => 'username',
  19.         'search'     => '',
  20.         'results'        => array(),
  21.     );
  22.  
  23.     static function Build()
  24.     {
  25.         if(User::$isAdmin == FALSE)
  26.         {
  27.             redirect();
  28.         }
  29.        
  30.         if(isset($_GET['id']) && is_numeric($_GET['id']))
  31.         {
  32.             DB::query("SELECT * FROM top_topsites WHERE id = '{$_GET['id']}' LIMIT 1");
  33.  
  34.             if(DB::num_rows() > 0)
  35.             {
  36.                 self::$data['user'] = DB::fetch_row();
  37.  
  38.                 if(isset($_POST['edit']))
  39.                 {
  40.                     self::edit_user();
  41.                 }
  42.             }
  43.            
  44.             else
  45.             {
  46.                 $_GET['id'] = 'text';
  47.             }
  48.         }
  49.        
  50.         elseif(isset($_GET['type']) && isset($_GET['search']))
  51.         {
  52.             self::$data['type'] = $_GET['type'];
  53.             self::$data['search'] = $_GET['search'];
  54.             self::search();
  55.         }
  56.  
  57.         Load::view('users', self::$data, TRUE);
  58.     }
  59.  
  60.     static function search()
  61.     {
  62.         $search = $_GET['search'];
  63.         $type   = $_GET['type'];
  64.  
  65.         DB::query("SELECT * FROM top_topsites WHERE $type LIKE '%$search%'");
  66.  
  67.         if(DB::num_rows() > 0)
  68.         {
  69.             self::$data['results'] = DB::fetch_array();
  70.         }
  71.     }
  72.    
  73.     static function edit_user()
  74.     {
  75.         self::$data['color'] = 'red';
  76.  
  77.         $id = $_GET['id'];
  78.         $q  = "UPDATE top_topsites SET ";
  79.         $i  = 0;
  80.  
  81.         foreach($_POST as $k => $v)
  82.         {
  83.             $i++;
  84.            
  85.             if($i != count($_POST))
  86.             {
  87.                 if($k == 'username')
  88.                 {
  89.                     if($v != self::$data['user']['username'])
  90.                     {
  91.                         $v = DB::safe($v);
  92.  
  93.                         if(User::$username == self::$data['user']['username'])
  94.                         {
  95.                             $new_pass = md5($v . $_SESSION['password']);
  96.                             $q .= "`password` = '$new_pass', ";
  97.                             $_SESSION['username'] = $v;
  98.                         }
  99.                        
  100.                         else
  101.                         {
  102.                             $v = self::$data['user']['username'];
  103.                             self::$data['message'] = 'You cannot edit someone else\'s username.';
  104.                             return;
  105.                         }
  106.                     }
  107.                 }
  108.  
  109.  
  110.                 $q .= "`$k` = '$v'";
  111.                 $q .= ((count($_POST) - 1) == $i) ? ' ' : ', ';
  112.             }
  113.         }
  114.        
  115.         self::$data['color'] = 'green';
  116.         self::$data['message'] = 'Successfully saved settings';
  117.         $q .= "WHERE id = '$id' LIMIT 1";
  118.         DB::query($q);
  119.  
  120.         //Now, we need to update the info
  121.         DB::query("SELECT * FROM top_topsites WHERE id = '".$_GET['id']."' LIMIT 1");
  122.         self::$data['user'] = DB::fetch_row();
  123.     }
  124.  
  125.  
  126.     static function message($message, $color = 'red')
  127.     {
  128.         self::$data['message'] = '<b style=\'color:'.$color.';\'>'.$message.'</b>';
  129.     }
  130. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement