Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Created by DrMath AKA James Will
- require_once(DIR . '/custom/functions.php');
- page_header("Promote Everyone At Once (Hopefully)");
- // Define Basic Membergroups
- $membergroups = array(2, 35, 51, 52, 53);
- // Define Usergroup Levels
- $grouplevels = array();
- // Group ID, Required Points, Rank Image Source
- $grouplevels[] = array(35, 3, "<img src='images/ranks/current/mem_stea.png' alt='Steadfast Member' />", "Steadfast Member");
- $grouplevels[] = array(51, 8, "<img src='images/ranks/current/mem_seni.png' alt='Senior Member' />", "Senior Member");
- $grouplevels[] = array(52, 15, "<img src='images/ranks/current/mem_reno.png' alt='Renowned Member' />", "Renowned Member");
- $grouplevels[] = array(53, 25, "<img src='images/ranks/current/mem_visi.png' alt='Visionary Member' />", "Visionary Member");
- // Get list of userids
- $userid_q = $db->query_read_slave("SELECT userid FROM " . TABLE_PREFIX . "user WHERE usergroupid NOT IN (3,4,5,20,21,23,45)");
- $userids = mysql_fetch_array($userid_q);
- //while ($data = mysql_fetch_array($userid_q)) {
- // var_dump($data);
- // echo "<br/><br/>";
- //}
- // Gather the Info
- foreach ($userids[0] as &$user) {
- $userid = (int)$user;
- // Query DB for Post Content //
- $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)");
- $recruits_q = $db->query_read_slave("SELECT COUNT(*) FROM " . TABLE_PREFIX . "user WHERE referrerid = $userid");
- $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)");
- $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");
- // Transfer to Arrays
- $u_threads = mysql_fetch_array($threads_q);
- $u_recruits = mysql_fetch_array($recruits_q);
- $u_awards = mysql_fetch_array($awards_q);
- $u_info = mysql_fetch_array($info_q);
- // Get Counts
- $username = $u_info[0];
- if ($username == null) {
- goto error;
- }
- $posts = $u_info[1];
- $joindate = new DateTime(date("Y-m-d", $u_info[2]));
- $currentdate = new DateTime();
- $displaydate = vbdate($vbulletin->options['dateformat'], $u_info[2], true);
- //date
- $datediff = $currentdate->diff($joindate);
- $datediffm = $datediff->format('%m');
- $datediffy = $datediff->format('%y');
- $datediff = $datediffm + (12 * $datediffy);
- //end date
- $usergroup = $u_info[3];
- $othergroups = $u_info[4];
- $staffyesno = $u_info[5];
- $adminyesno = $u_info[6];
- $threads = $u_threads[0];
- $recruits = $u_recruits[0];
- $awards = $u_awards[0];
- $totalpoints = 0;
- // Post Points
- if ($posts >= 10) {
- $totalpoints += 1;
- }
- if ($posts >= 25) {
- $totalpoints += 1;
- }
- if ($posts >= 50) {
- $totalpoints += 1;
- }
- if ($posts >= 100) {
- $totalpoints += 1;
- }
- if ($posts >= 300) {
- $totalpoints += 5;
- }
- if ($posts >= 500) {
- $ppoints = 2 * floor($posts / 500);
- $totalpoints += $ppoints;
- }
- // Thread Points
- if ($threads >= 10) {
- $totalpoints += 1;
- }
- if ($threads >= 20) {
- $totalpoints += 1;
- }
- if ($threads >= 50) {
- $totalpoints += 2;
- }
- if ($threads >= 100) {
- $tpoints = floor($threads / 100);
- $totalpoints += $tpoints;
- }
- // Recruited Member Points
- if ($recruits >= 1 && $recruits <= 4) {
- $totalpoints += $recruits;
- } elseif ($recruits >= 5) {
- $r5points = floor($recruits / 5);
- $totalpoints += (4 + $r5points);
- }
- // Membership Length Points
- if ($datediff >= 1) {
- $totalpoints += 1;
- }
- if ($datediff >= 3) {
- $totalpoints += 1;
- }
- if ($datediff >= 6) {
- $totalpoints += 2;
- }
- if ($datediff >= 12) {
- $totalpoints += 5;
- }
- if ($datediff >= 18) {
- $m6ppoints = 3 * floor(($datediff - 12) / 6);
- $totalpoints += $m6ppoints;
- }
- // Award Points
- if ($awards > 0) {
- $apoints = 2 * $awards;
- $totalpoints += $apoints;
- }
- // Points for Positions
- if ($staffyesno == "Yes") {
- $staffpts = $totalpoints += 2;
- }
- if ($adminyesno == "Yes") {
- $adminpts = $totalpoints += 5;
- }
- // Begin Promotions
- $newgroup = $newrank = $newranktitle = "";
- // If they are not in leadership
- if (in_array($usergroup, $membergroups)) {
- // Go Through Each Rank and Check if They Can Achieve It
- foreach ($grouplevels as $level) {
- $groupid = $level[0];
- $reqpoints = $level[1];
- $rankcode = $level[2];
- $ranktitle = $level[3];
- // If they have points to rank up
- if ($totalpoints >= $reqpoints && $usergroup < $groupid) {
- $newgroup = $groupid;
- $newrank = $rankcode;
- $newranktitle = $ranktitle;
- }
- }
- // If they earned a new usergroup, change it
- if ($newgroup != null) {
- $userinfo = fetch_userinfo($userid);
- $userdata = & datamanager_init('User', $vbulletin, ERRTYPE_ARRAY);
- $userdata->set_existing($userinfo);
- $userdata->setr('usergroupid', $newgroup);
- $userdata->setr('usertitle', $newrank);
- $userdata->save();
- }
- // Update Chron Log
- $log = array($newgroup, '*', $newranktitle);
- // the "1" indicates to use the second line of the phrase specified for this task
- log_cron_action(serialize($log), $nextitem, 1);
- } else {
- // If they are in leadership, check additional groups
- // If no additional usergroup, set apprentice
- if ($othergroups == null) {
- $othergroups = "2";
- }
- foreach ($membergroups as $groupid) {
- $group = (string) $groupid;
- if (strpos($othergroups, $group) !== false) {
- $secgroup = $group;
- $secgroupid = $groupid;
- break;
- }
- }
- // Go Through Each Rank and Check if They Can Achieve It
- foreach ($grouplevels as $level) {
- $groupid = $level[0];
- $reqpoints = $level[1];
- $ranktitle = $level[3];
- // If they have points to rank up
- if ($totalpoints >= $reqpoints && $secgroupid < $groupid) {
- $newgroup = (string) $groupid;
- $newranktitle = $ranktitle;
- }
- }
- $othergroups = str_replace($secgroup, $newgroup, $othergroups);
- // If they earned a new usergroup, change it
- if ($newgroup != null) {
- $userinfo = fetch_userinfo($userid);
- $userdata = & datamanager_init('User', $vbulletin, ERRTYPE_ARRAY);
- $userdata->set_existing($userinfo);
- $userdata->setr('membergroupids', $othergroups);
- $userdata->save();
- }
- }
- }
- // Footer
- page_footer();
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement