Guest User

Untitled

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