Advertisement
Guest User

Page Version

a guest
Jun 21st, 2014
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 8.15 KB | None | 0 0
  1. <?php
  2. // Created by DrMath AKA James Will
  3. require_once(DIR . '/custom/functions.php');
  4.  
  5. page_header("Promote Everyone At Once (Hopefully)");
  6.  
  7. // Define Basic Membergroups
  8. $membergroups = array(2, 35, 51, 52, 53);
  9.  
  10. // Define Usergroup Levels
  11. $grouplevels = array();
  12. // Group ID, Required Points, Rank Image Source
  13. $grouplevels[] = array(35, 3, "<img src='images/ranks/current/mem_stea.png' alt='Steadfast Member' />", "Steadfast Member");
  14. $grouplevels[] = array(51, 8, "<img src='images/ranks/current/mem_seni.png' alt='Senior Member' />", "Senior Member");
  15. $grouplevels[] = array(52, 15, "<img src='images/ranks/current/mem_reno.png' alt='Renowned Member' />", "Renowned Member");
  16. $grouplevels[] = array(53, 25, "<img src='images/ranks/current/mem_visi.png' alt='Visionary Member' />", "Visionary Member");
  17.  
  18. // Get list of userids
  19. $userid_q = $db->query_read_slave("SELECT userid FROM " . TABLE_PREFIX . "user WHERE usergroupid NOT IN (3,4,5,20,21,23,45)");
  20. $userids = mysql_fetch_array($userid_q);
  21. while ($row = mysql_fetch_array($userid_q, MYSQL_ASSOC)) {
  22.     $userids[] = $row["userid"];
  23. }
  24. //while ($data = mysql_fetch_array($userid_q)) {
  25. //    var_dump($data);
  26. //    echo "<br/><br/>";
  27. //}
  28.  
  29. // Gather the Info
  30.  
  31. $totalpromos = 0;
  32.  
  33. foreach ($userids as $userid) {
  34.     //foreach ($u1 as $user) {
  35.         //echo $user;
  36.         //$userid = (int)$user;
  37.  
  38.  
  39.         // Query DB for Post Content //
  40.         $threads_q = $db->query_read_slave("SELECT COUNT(*) FROM " . TABLE_PREFIX . "thread WHERE postuserid = $userid AND forumid NOT IN (13, 19, 28, 43, 47, 49, 71, 86, 126, 141,162, 167, 168, 178, 180, 181, 219, 222, 233, 237, 238, 239, 243, 254, 255, 256, 259, 267, 284, 285, 287, 301, 304, 306, 307, 312, 313, 314, 316, 319, 337, 338, 345, 346, 375, 381, 384, 385, 391, 396, 402)");
  41.         $recruits_q = $db->query_read_slave("SELECT COUNT(*) FROM " . TABLE_PREFIX . "user WHERE referrerid = $userid");
  42.         $awards_q = $db->query_read_slave("SELECT COUNT(*) FROM " . TABLE_PREFIX . "award_user WHERE userid = $userid AND award_id NOT IN (6, 7, 10, 20)");
  43.         $info_q = $db->query_read_slave("SELECT user.username, user.posts, user.joindate, user.usergroupid, user.membergroupids, userfield.field49, userfield.field50 FROM " . TABLE_PREFIX . "user as user LEFT JOIN " . TABLE_PREFIX . "userfield as userfield ON (userfield.userid=user.userid) WHERE user.userid = $userid");
  44.  
  45.  
  46.         // Transfer to Arrays
  47.         $u_threads = mysql_fetch_array($threads_q);
  48.         $u_recruits = mysql_fetch_array($recruits_q);
  49.         $u_awards = mysql_fetch_array($awards_q);
  50.         $u_info = mysql_fetch_array($info_q);
  51.  
  52.         $posts = $u_info[1];
  53.         $joindate = new DateTime(date("Y-m-d", $u_info[2]));
  54.         $currentdate = new DateTime();
  55.         $displaydate = vbdate($vbulletin->options['dateformat'], $u_info[2], true);
  56.         //date
  57.         $datediff = $currentdate->diff($joindate);
  58.         $datediffm = $datediff->format('%m');
  59.         $datediffy = $datediff->format('%y');
  60.         $datediff = $datediffm + (12 * $datediffy);
  61.         //end date
  62.         $usergroup = $u_info[3];
  63.         $othergroups = $u_info[4];
  64.         $staffyesno = $u_info[5];
  65.         $adminyesno = $u_info[6];
  66.         $threads = $u_threads[0];
  67.         $recruits = $u_recruits[0];
  68.         $awards = $u_awards[0];
  69.         $totalpoints = 0;
  70.  
  71.         // Post Points
  72.  
  73.         if ($posts >= 10) {
  74.             $totalpoints += 1;
  75.         }
  76.         if ($posts >= 25) {
  77.             $totalpoints += 1;
  78.         }
  79.         if ($posts >= 50) {
  80.             $totalpoints += 1;
  81.         }
  82.         if ($posts >= 100) {
  83.             $totalpoints += 1;
  84.         }
  85.         if ($posts >= 300) {
  86.             $totalpoints += 5;
  87.         }
  88.         if ($posts >= 500) {
  89.             $ppoints = 2 * floor($posts / 500);
  90.             $totalpoints += $ppoints;
  91.         }
  92.  
  93.         // Thread Points
  94.  
  95.         if ($threads >= 10) {
  96.             $totalpoints += 1;
  97.         }
  98.         if ($threads >= 20) {
  99.             $totalpoints += 1;
  100.         }
  101.         if ($threads >= 50) {
  102.             $totalpoints += 2;
  103.         }
  104.         if ($threads >= 100) {
  105.             $tpoints = floor($threads / 100);
  106.             $totalpoints += $tpoints;
  107.         }
  108.  
  109.         // Recruited Member Points
  110.  
  111.         if ($recruits >= 1 && $recruits <= 4) {
  112.             $totalpoints += $recruits;
  113.         } elseif ($recruits >= 5) {
  114.             $r5points = floor($recruits / 5);
  115.             $totalpoints += (4 + $r5points);
  116.         }
  117.  
  118.         // Membership Length Points
  119.  
  120.         if ($datediff >= 1) {
  121.             $totalpoints += 1;
  122.         }
  123.         if ($datediff >= 3) {
  124.             $totalpoints += 1;
  125.         }
  126.         if ($datediff >= 6) {
  127.             $totalpoints += 2;
  128.         }
  129.         if ($datediff >= 12) {
  130.             $totalpoints += 5;
  131.         }
  132.         if ($datediff >= 18) {
  133.             $m6ppoints = 3 * floor(($datediff - 12) / 6);
  134.             $totalpoints += $m6ppoints;
  135.         }
  136.  
  137.         // Award Points
  138.  
  139.         if ($awards > 0) {
  140.             $apoints = 2 * $awards;
  141.             $totalpoints += $apoints;
  142.         }
  143.  
  144.         // Points for Positions
  145.  
  146.         if ($staffyesno == "Yes") {
  147.             $staffpts = $totalpoints += 2;
  148.         }
  149.         if ($adminyesno == "Yes") {
  150.             $adminpts = $totalpoints += 5;
  151.         }
  152.  
  153.         // Begin Promotions
  154.         $newgroup = $newrank = $newranktitle = "";
  155.  
  156.         // If they are not in leadership
  157.         if (in_array($usergroup, $membergroups)) {
  158.             // Go Through Each Rank and Check if They Can Achieve It
  159.             foreach ($grouplevels as $level) {
  160.                 $groupid = $level[0];
  161.                 $reqpoints = $level[1];
  162.                 $rankcode = $level[2];
  163.                 $ranktitle = $level[3];
  164.  
  165.                 // If they have points to rank up
  166.                 if ($totalpoints >= $reqpoints && $usergroup < $groupid) {
  167.                     $newgroup = $groupid;
  168.                     $newrank = $rankcode;
  169.                     $newranktitle = $ranktitle;
  170.                 }
  171.             }
  172.  
  173.             // If they earned a new usergroup, change it
  174.             if ($newgroup != null) {
  175.                 $userinfo = fetch_userinfo($userid);
  176.                 $userdata = & datamanager_init('User', $vbulletin, ERRTYPE_ARRAY);
  177.                 $userdata->set_existing($userinfo);
  178.                 $userdata->setr('usergroupid', $newgroup);
  179.                 $userdata->setr('usertitle', $newrank);
  180.                 $userdata->save();
  181.                 $totalpromos ++;
  182.             }
  183.         } else {
  184.             // If they are in leadership, check additional groups
  185.             // If no additional usergroup, set apprentice
  186.             if ($othergroups == null) {
  187.                 $othergroups = "2";
  188.             }
  189.  
  190.             foreach ($membergroups as $groupid) {
  191.                 $group = (string) $groupid;
  192.                 if (strpos($othergroups, $group) !== false) {
  193.                     $secgroup = $group;
  194.                     $secgroupid = $groupid;
  195.                     break;
  196.                 }
  197.             }
  198.  
  199.             // Go Through Each Rank and Check if They Can Achieve It
  200.             foreach ($grouplevels as $level) {
  201.                 $groupid = $level[0];
  202.                 $reqpoints = $level[1];
  203.                 $ranktitle = $level[3];
  204.  
  205.                 // If they have points to rank up
  206.                 if ($totalpoints >= $reqpoints && $secgroupid < $groupid) {
  207.                     $newgroup = (string) $groupid;
  208.                     $newranktitle = $ranktitle;
  209.                 }
  210.             }
  211.  
  212.             $othergroups = str_replace($secgroup, $newgroup, $othergroups);
  213.  
  214.             // If they earned a new usergroup, change it
  215.             if ($newgroup != null) {
  216.                 $userinfo = fetch_userinfo($userid);
  217.                 $userdata = & datamanager_init('User', $vbulletin, ERRTYPE_ARRAY);
  218.                 $userdata->set_existing($userinfo);
  219.                 $userdata->setr('membergroupids', $othergroups);
  220.                 $userdata->save();
  221.                 $totalpromos ++;
  222.             }
  223.         }
  224.     //}
  225. }
  226.  
  227. echo "<p>A total of $totalpromos users were promoted.</p>";
  228.  
  229. // Footer
  230. page_footer();
  231.  
  232. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement