Advertisement
Guest User

Untitled

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