Guest
Public paste!

Untitled

By: a guest | Feb 9th, 2010 | Syntax: PHP | Size: 2.76 KB | Hits: 51 | Expires: Never
This paste has a previous version, view the difference. Copy text to clipboard
  1. function user_active_flip($mode, $user_id_ary, $reason = INACTIVE_MANUAL)
  2. {
  3.         global $config, $db, $user, $auth;
  4.  
  5.         $deactivated = $activated = 0;
  6.         $sql_statements = array();
  7.  
  8.         if (!is_array($user_id_ary))
  9.         {
  10.                 $user_id_ary = array($user_id_ary);
  11.         }
  12.  
  13.         if (!sizeof($user_id_ary))
  14.         {
  15.                 return;
  16.         }
  17.  
  18.         $sql = 'SELECT user_id, group_id, user_type, user_inactive_reason
  19.                 FROM ' . USERS_TABLE . '
  20.                 WHERE ' . $db->sql_in_set('user_id', $user_id_ary);
  21.         $result = $db->sql_query($sql);
  22.  
  23.         while ($row = $db->sql_fetchrow($result))
  24.         {
  25.                 $sql_ary = array();
  26.  
  27.                 if ($row['user_type'] == USER_IGNORE || $row['user_type'] == USER_FOUNDER ||
  28.                         ($mode == 'activate' && $row['user_type'] != USER_INACTIVE) ||
  29.                         ($mode == 'deactivate' && $row['user_type'] == USER_INACTIVE))
  30.                 {
  31.                         continue;
  32.                 }
  33.  
  34.                 if ($row['user_type'] == USER_INACTIVE)
  35.                 {
  36.                         $activated++;
  37.  
  38.                         if (!is_dir('/~joeshow1/bettingwars/profile/users/'.$user_row[username])) {
  39.                                 $src='/~joeshow1/bettingwars/profile/default';
  40.                                 $dst='/~joeshow1/bettingwars/profile/users/'.$user_row[username];
  41.                                 function recurse_copy($src,$dst) {
  42.                                         $dir = opendir($src);
  43.                                         @mkdir($dst);
  44.                                         while (false !== ( $file = readdir($dir)) ) {
  45.                                                 if (( $file != '.' ) && ( $file != '..' )) {
  46.                                                         if ( is_dir($src . '/' . $file) ) {
  47.                                                                 recurse_copy($src . '/' . $file,$dst . '/' . $file);
  48.                                                         } else {
  49.                                                                 copy($src . '/' . $file,$dst . '/' . $file);
  50.                                                         }
  51.                                                 }
  52.                                         }
  53.                                         closedir($dir);
  54.                                 }
  55.                                 recurse_copy($src,$dst);
  56.  
  57.                                 //BCB   BETTING WARS
  58.                                 @ $bet_db = new mysqli('localhost', 'xxxx', 'xxxx', 'joeshow1_betting');
  59.                                 $query = "insert into total_db values ('".$user_row['username']."','100','100','0','0')";
  60.                                 $bet_db->query($query);
  61.  
  62.                         }
  63.  
  64.                 }
  65.                 else
  66.                 {
  67.                         $deactivated++;
  68.  
  69.                         // Remove the users session key...
  70.                         $user->reset_login_keys($row['user_id']);
  71.                 }
  72.  
  73.                 $sql_ary += array(
  74.                         'user_type'                             => ($row['user_type'] == USER_NORMAL) ? USER_INACTIVE : USER_NORMAL,
  75.                         'user_inactive_time'    => ($row['user_type'] == USER_NORMAL) ? time() : 0,
  76.                         'user_inactive_reason'  => ($row['user_type'] == USER_NORMAL) ? $reason : 0,
  77.                 );
  78.  
  79.                 $sql_statements[$row['user_id']] = $sql_ary;
  80.         }
  81.         $db->sql_freeresult($result);
  82.  
  83.         if (sizeof($sql_statements))
  84.         {
  85.                 foreach ($sql_statements as $user_id => $sql_ary)
  86.                 {
  87.                         $sql = 'UPDATE ' . USERS_TABLE . '
  88.                                 SET ' . $db->sql_build_array('UPDATE', $sql_ary) . '
  89.                                 WHERE user_id = ' . $user_id;
  90.                         $db->sql_query($sql);
  91.                 }
  92.  
  93.                 $auth->acl_clear_prefetch(array_keys($sql_statements));
  94.         }
  95.  
  96.         if ($deactivated)
  97.         {
  98.                 set_config_count('num_users', $deactivated * (-1), true);
  99.         }
  100.  
  101.         if ($activated)
  102.         {
  103.                 set_config_count('num_users', $activated, true);
  104.         }
  105.  
  106.         // Update latest username
  107.         update_last_username();
  108. }