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. <?php
  2. // Created by DrMath AKA James Will
  3.  
  4. // ######################## SET PHP ENVIRONMENT ###########################
  5. error_reporting(E_ALL & ~E_NOTICE);
  6. if (!is_object($vbulletin->db))
  7. {
  8.     exit;
  9. }
  10.  
  11. // ########################################################################
  12. // ######################### START MAIN SCRIPT ############################
  13. // ########################################################################
  14.  
  15. // $nextrun is the time difference between runs. Should be sent over from cron.php!!
  16. // We only check the users that have been active since the lastrun to save a bit of cpu time.
  17.  
  18. $thisrun = TIMENOW;
  19. $lastrun = $vbulletin->crondata['promos_lastrun'] ? $vbulletin->crondata['promos_lastrun'] : $thisrun - ($nextrun - $thisrun);
  20.  
  21. // Define Basic Membergroups
  22. $membergroups = array(2,35,51,52,53);
  23.  
  24. // Define Usergroup Levels
  25. $grouplevels = array();
  26. // Group ID, Required Points, Rank Image Source
  27. $grouplevels[] = array(35,3,"<img src='images/ranks/current/mem_stea.png' alt='Steadfast Member' />","Steadfast Member");
  28. $grouplevels[] = array(51,8,"<img src='images/ranks/current/mem_seni.png' alt='Senior Member' />","Senior Member");
  29. $grouplevels[] = array(52,15,"<img src='images/ranks/current/mem_reno.png' alt='Renowned Member' />","Renowned Member");
  30. $grouplevels[] = array(53,25,"<img src='images/ranks/current/mem_visi.png' alt='Visionary Member' />","Visionary Member");
  31.  
  32. // Get list of userids
  33. $userid_q = $vbulletin->db->query_read("SELECT userid FROM " . TABLE_PREFIX . "user WHERE usergroupid NOT IN (3,4,5,20,21,23,45)");
  34. $userids = array();
  35. foreach ($useridq as $value) { $userids[] = $value; }
  36.  
  37. // Gather the Info
  38. foreach ($userids as $userid) {
  39.    
  40.     // Query DB for Post Content //
  41.     $threads_q = $vbulletin->db->query_read("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)");
  42.     $recruits_q = $vbulletin->db->query_read("SELECT COUNT(*) FROM " . TABLE_PREFIX . "user WHERE referrerid = $userid");
  43.     $awards_q = $vbulletin->db->query_read("SELECT COUNT(*) FROM " . TABLE_PREFIX . "award_user WHERE userid = $userid AND award_id NOT IN (6, 7, 10, 20)");
  44.     $info_q = $vbulletin->db->query_read("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");
  45.  
  46.  
  47.     // Transfer to Arrays
  48.     $u_threads = mysql_fetch_array($threads_q);
  49.     $u_recruits = mysql_fetch_array($recruits_q);
  50.     $u_awards = mysql_fetch_array($awards_q);
  51.     $u_info = mysql_fetch_array($info_q);
  52.  
  53.     // Get Counts
  54.     $username = $u_info[0];
  55.     if ($username == null) { goto error; }
  56.     $posts = $u_info[1];
  57.     $joindate = new DateTime(date("Y-m-d", $u_info[2]));
  58.     $currentdate = new DateTime();
  59.     $displaydate = vbdate($vbulletin->options['dateformat'], $u_info[2], true);
  60.     //date
  61.     $datediff = $currentdate->diff($joindate);
  62.     $datediffm = $datediff->format('%m');
  63.     $datediffy = $datediff->format('%y');
  64.     $datediff = $datediffm + (12 * $datediffy);
  65.     //end date
  66.     $usergroup = $u_info[3];
  67.     $othergroups = $u_info[4];
  68.     $staffyesno = $u_info[5];
  69.     $adminyesno = $u_info[6];
  70.     $threads = $u_threads[0];
  71.     $recruits = $u_recruits[0];
  72.     $awards = $u_awards[0];
  73.     $totalpoints = 0;
  74.    
  75.     // Post Points
  76.  
  77.     if ($posts >= 10) { $totalpoints += 1; }
  78.     if ($posts >= 25) { $totalpoints += 1; }
  79.     if ($posts >= 50) { $totalpoints += 1; }
  80.     if ($posts >= 100) { $totalpoints += 1; }
  81.     if ($posts >= 300) { $totalpoints += 5; }
  82.     if ($posts >= 500) { $ppoints = 2 * floor($posts / 500); $totalpoints += $ppoints; }
  83.  
  84.     // Thread Points
  85.  
  86.     if ($threads >= 10) { $totalpoints += 1; }
  87.     if ($threads >= 20) { $totalpoints += 1; }
  88.     if ($threads >= 50) { $totalpoints += 2; }
  89.     if ($threads >= 100) { $tpoints = floor($threads / 100); $totalpoints += $tpoints; }
  90.  
  91.     // Recruited Member Points
  92.  
  93.     if ($recruits >= 1 && $recruits <= 4) { $totalpoints += $recruits; }
  94.     elseif ($recruits >= 5 ) { $r5points = floor($recruits / 5); $totalpoints += (4 + $r5points); }
  95.  
  96.     // Membership Length Points
  97.  
  98.     if ($datediff >= 1) { $totalpoints += 1; }
  99.     if ($datediff >= 3) { $totalpoints += 1; }
  100.     if ($datediff >= 6) { $totalpoints += 2; }
  101.     if ($datediff >= 12) { $totalpoints += 5; }
  102.     if ($datediff >= 18) { $m6ppoints = 3 * floor(($datediff - 12) / 6); $totalpoints += $m6ppoints; }
  103.  
  104.     // Award Points
  105.  
  106.     if ($awards > 0) { $apoints = 2 * $awards; $totalpoints += $apoints; }
  107.  
  108.     // Points for Positions
  109.  
  110.     if ($staffyesno == "Yes") {$staffpts = $totalpoints += 2;}
  111.     if ($adminyesno == "Yes") {$adminpts = $totalpoints += 5;}
  112.    
  113.     // Begin Promotions
  114.     $newgroup = $newrank = $newranktitle = "";
  115.                            
  116.     // If they are not in leadership
  117.     if (in_array($usergroup, $membergroups)) {
  118.         // Go Through Each Rank and Check if They Can Achieve It
  119.         foreach ($grouplevels as $level) {
  120.             $groupid = $level[0];
  121.             $reqpoints = $level[1];
  122.             $rankcode = $level[2];
  123.             $ranktitle = $level[3];
  124.  
  125.             // If they have points to rank up
  126.             if ($totalpoints >= $reqpoints && $usergroup < $groupid) {
  127.                 $newgroup = $groupid;
  128.                 $newrank = $rankcode;
  129.                 $newranktitle = $ranktitle;
  130.             }
  131.         }
  132.  
  133.         // If they earned a new usergroup, change it
  134.         if ($newgroup != null) {$vbulletin->db->query_write("UPDATE " . TABLE_PREFIX . "user SET usergroupid = $newgroup, usertitle = $newrank WHERE userid = $userid"); }
  135.        
  136.         // Update Chron Log
  137.         $log = array($newgroup,'*',$newranktitle);
  138.     // the "1" indicates to use the second line of the phrase specified for this task
  139.     log_cron_action(serialize($log), $nextitem, 1);
  140.     }
  141.     else {
  142.         // If they are in leadership, check additional groups
  143.  
  144.         // If no additional usergroup, set apprentice
  145.         if ($othergroups == null) {$othergroups = "2";}
  146.  
  147.         foreach ($membergroups as $groupid) {
  148.             $group = (string)$groupid;
  149.             if (strpos($othergroups,$group) !== false) {
  150.                 $secgroup = $group;
  151.                 $secgroupid = $groupid;
  152.                 break;
  153.             }
  154.         }
  155.  
  156.          // Go Through Each Rank and Check if They Can Achieve It
  157.         foreach ($grouplevels as $level) {
  158.             $groupid = $level[0];
  159.             $reqpoints = $level[1];
  160.             $ranktitle = $level[3];
  161.  
  162.             // If they have points to rank up
  163.             if ($totalpoints >= $reqpoints && $secgroupid < $groupid) {
  164.                 $newgroup = (string)$groupid;
  165.                 $newranktitle = $ranktitle;
  166.             }
  167.         }
  168.  
  169.         $othergroups = str_replace($secgroup, $newgroup, $othergroups);
  170.  
  171.         // If they earned a new usergroup, change it
  172.         if ($newgroup != null) { $vbulletin->db->query_write("UPDATE " . TABLE_PREFIX . "user SET membergroupids = $othergroups WHERE userid = $userid"); }
  173.        
  174.         $log = array($newgroup,'*',$newranktitle);
  175.     // the "1" indicates to use the second line of the phrase specified for this task
  176.     log_cron_action(serialize($log), $nextitem, 1);
  177.  
  178.         }
  179.  
  180.     }
  181.    
  182.     $vbulletin->crondata['promos_lastrun'] = $thisrun;
  183.     build_datastore('crondata', serialize($vbulletin->crondata), 1);
  184.  
  185.  
  186. if ($vbulletin->debug AND VB_AREA == 'AdminCP')
  187. {
  188.     #echo '<pre>'; print_r($sql); print_r($sql_id); echo '</pre>';
  189. }
  190.  
  191.  
  192. /*======================================================================*\
  193. || ####################################################################
  194. || # Updated, Friday, June 20, 2014
  195. || ####################################################################
  196. \*======================================================================*/
  197. ?>
Advertisement
Add Comment
Please, Sign In to add comment