Go Back   vb.org Archive > vBulletin 4 Discussion > vB4 General Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 11-28-2014, 08:59 PM
KGodel's Avatar
KGodel KGodel is offline
 
Join Date: May 2011
Location: Indiana
Posts: 332
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Mentor for Plugins - And Cron Help

Hey everyone!

I have recently done some neat little features for my community which may benefit others. I have currently done all the hard coding myself and have done certain features how I want them. I was wondering if anyone could point me towards an article on making a plugin or maybe walk me through it? I'd love to give back to the community in some way! Thanks!

--------------- Added [DATE]1417220241[/DATE] at [TIME]1417220241[/TIME] ---------------

In addition to the above request, I have an issue with a CRON task I am trying to do. It isn't being logged, and I'm not even sure that it is actually doing the process each night. Any help would be great!

PHP Code:
<?php

// Created by DrMath AKA James Will
// ######################## SET PHP ENVIRONMENT ###########################
error_reporting(E_ALL & ~E_NOTICE);
if (!
is_object($vbulletin->db)) {
    exit;
}

// ########################################################################
// ######################### START MAIN SCRIPT ############################
// ########################################################################
// $nextrun is the time difference between runs. Should be sent over from cron.php!!
// We only check the users that have been active since the lastrun to save a bit of cpu time.

$thisrun TIMENOW;
$lastrun $vbulletin->crondata['promos_lastrun'] ? $vbulletin->crondata['promos_lastrun'] : $thisrun - ($nextrun $thisrun);

// Define Basic Membergroups
$membergroups = array(235515253);
$leadergroups = array(5617182438505455565862);

// Define Usergroup Levels
$grouplevels = array();
// Group ID, Required Points, Rank Image Source
$grouplevels[] = array(353"<img src='images/ranks/v9/mem_stea.png' alt='Steadfast Member' />""Steadfast Member");
$grouplevels[] = array(518"<img src='images/ranks/v9/mem_seni.png' alt='Senior Member' />""Senior Member");
$grouplevels[] = array(5215"<img src='images/ranks/v9/mem_reno.png' alt='Renowned Member' />""Renowned Member");
$grouplevels[] = array(5325"<img src='images/ranks/v9/mem_visi.png' alt='Visionary Member' />""Visionary Member");

// Get list of userids
$userid_q $vbulletin->db->query_read("SELECT userid FROM " TABLE_PREFIX "user WHERE usergroupid NOT IN (3,4,5,20,21,23,45)");
while (
$row mysql_fetch_array($userid_qMYSQL_ASSOC)) {
    
$userids[] = $row["userid"];
}
// Gather the Info
//$totalpromos = 0;

foreach ($userids as $userid) {

    
// Query DB for Post Content //
    
$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)");
    
$recruits_q $vbulletin->db->query_read("SELECT COUNT(*) FROM " TABLE_PREFIX "user WHERE referrerid = $userid");
    
$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, 23)");
    
$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");


    
// Transfer to Arrays
    
$u_threads $vbulletin->db->fetch_array($threads_q);
    
$u_recruits $vbulletin->db->fetch_array($recruits_q);
    
$u_awards $vbulletin->db->fetch_array($awards_q);
    
$u_info $vbulletin->db->fetch_array($info_q);

    
$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 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 >= && $recruits <= 4) {
        
$totalpoints += $recruits;
    } elseif (
$recruits >= 5) {
        
$r5points floor($recruits 5);
        
$totalpoints += ($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 floor(($datediff 12) / 6);
        
$totalpoints += $m6ppoints;
    }

    
// Award Points

    
if ($awards 0) {
        
$apoints $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;
            }

            
// 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), $nextitem1);
        }

        
// If they earned a new usergroup, change it
        
if ($newgroup != null) {
            
$userinfo fetch_userinfo($userid);
            
$userdata = & datamanager_init('User'$vbulletinERRTYPE_ARRAY);
            
$userdata->set_existing($userinfo);
            
$userdata->setr('usergroupid'$newgroup);
            
$userdata->setr('usertitle'$newrank);
            
$userdata->save();
            
//$totalpromos ++;
        
}
    }
    
    
// If they are in leadership, check additional groups
    
if (in_array($usergroup$leadergroups)) {
        
        
// If no additional usergroup, set apprentice
        
if ($othergroups == null) {
            
$othergroups "2";
        }

        foreach (
$membergroups as $gid) {
            
$group = (string) $gid;
            if (
in_array($groupexplode(",",$othergroups)) !== false) {
                
$secgroup $group;
                
$secgroupid $gid;
                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;
            }

            
$log = array($newgroup'*'$newranktitle);
            
// the "1" indicates to use the second line of the phrase specified for this task
            
log_cron_action(serialize($log), $nextitem1);
        }

        
$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'$vbulletinERRTYPE_ARRAY);
            
$userdata->set_existing($userinfo);
            
$userdata->setr('membergroupids'$othergroups);
            
$userdata->save();
            
//$totalpromos ++;
        
}
    }
}

$vbulletin->crondata['promos_lastrun'] = $thisrun;
build_datastore('crondata'serialize($vbulletin->crondata), 1);


if (
$vbulletin->debug AND VB_AREA == 'AdminCP') {
    
#echo '<pre>'; print_r($sql); print_r($sql_id); echo '</pre>';
}


/* ======================================================================*\
  || ####################################################################
  || # Updated, July 26, 2014
  || ####################################################################
  \*====================================================================== */
?>
Reply With Quote
  #2  
Old 11-28-2014, 11:50 PM
ozzy47's Avatar
ozzy47 ozzy47 is offline
 
Join Date: Jul 2009
Location: USA
Posts: 10,929
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Well I have not gone through the whole code, but at the end you need something like this.

PHP Code:
if ($emails)
{
    
log_cron_action($emails$nextitem1);

As far as what you have hard coded, what is it that it does, and how does it execute ect.
Reply With Quote
  #3  
Old 11-29-2014, 04:10 AM
KGodel's Avatar
KGodel KGodel is offline
 
Join Date: May 2011
Location: Indiana
Posts: 332
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

So, our community is like an umbrella clans for divisions that operate in specific games. As such, it is important for us to maintain a roster. Divisions also have certain stages. So, the system works like this.

First, we have a system via the ACP where we can add games to the roster. The games possible are based off of a profile field we've added, so for instance:

field5 contains the list of all supported games. The possible games you can add to the roster grabs from this field to generate it's list.

You then add a short-code for the game (basically what will go after the url, so ?game=shortcode), the title of your in-game name field (Battle.net ID, Steam, Summoner Name, etc), you list what profile field contains that information, and a status for the game. Below is a screenshot.



The rest is hard coded. The main roster page is a page of all leadership roles. This would be a setting of "usergroup ids" to determine which groups are leaders, as well as what order they should be in, and the heading.

I believe the roster is accessible for all visitors, http://www.zealotgaming.com/forum/pages.php?pageid=15

There is also a sort-order of usergroups on how they display of individual games. For example, admins are community-wide leaders, so we list the leaders of the individual games first on those rosters. Again, this setting could be altered. There is also a list of usergroups who do NOT appear on the roster, such as an inactive usergroup or banned or whatever. Also an easy setting I think to add.

So what I think I basically need to save are the following settings:

Main Leadership Roster
-List of Leader Usergroups in order you want them to appear. (Heading will be the usergroup name)

Games List (Or whatever you want to call it)
-Profile field that contains the list of possible games/groups
-List of different "statuses" or categories for each group
-The sorting order of groups you want to use.
-List of usergroups you do not want shown on the roster.

A lot of these are lists, some of which could be checkboxes or simply have a sort ID number like they do in various other mods.

I hope I explained it well. Hopefully it makes sense based on the screenshot and the link.

NOTE: I do have the cron log in my code.

PHP Code:
            $log = array($newgroup'*'$newranktitle);
            
// the "1" indicates to use the second line of the phrase specified for this task
            
log_cron_action(serialize($log), $nextitem1); 
Reply With Quote
  #4  
Old 11-29-2014, 09:24 AM
ozzy47's Avatar
ozzy47 ozzy47 is offline
 
Join Date: Jul 2009
Location: USA
Posts: 10,929
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Did you try manually running the task, and see if it shows in the log then?
Reply With Quote
  #5  
Old 11-29-2014, 02:07 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

In the Scheduled Task Manager, edit your task and make sure "Log Entries" is set to Yes.
Reply With Quote
  #6  
Old 11-29-2014, 03:32 PM
KGodel's Avatar
KGodel KGodel is offline
 
Join Date: May 2011
Location: Indiana
Posts: 332
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I have done both, still not in the logs.
Reply With Quote
  #7  
Old 12-04-2014, 11:48 PM
KGodel's Avatar
KGodel KGodel is offline
 
Join Date: May 2011
Location: Indiana
Posts: 332
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Friendly bump. I still haven't been able to pinpoint the problem in the cron job that is preventing the log from saving.
Reply With Quote
  #8  
Old 12-04-2014, 11:57 PM
ozzy47's Avatar
ozzy47 ozzy47 is offline
 
Join Date: Jul 2009
Location: USA
Posts: 10,929
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I am not sure, you would thing it would log, but for some reason it is not. Kinda hard to tell without actually testing out the whole process.

Is it actually doing what you have it set to do in the cron, if it automatically runs, or you run it manually?
Have you checked your server error logs at the time it is supposed to run and see if their are any errors?
Reply With Quote
  #9  
Old 12-05-2014, 02:23 AM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

You have the log function call in a place where it logs rank changes (although I think it should be inside the 'if' statement). Maybe put one at the end (and maybe near the beginning as well) to make sure your task is actually running. (Well, I mean to check if it's a logging problem or some other problem).
Reply With Quote
  #10  
Old 12-05-2014, 04:55 AM
KGodel's Avatar
KGodel KGodel is offline
 
Join Date: May 2011
Location: Indiana
Posts: 332
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I did change the placement of the log statements. After further testing I've determined the process isn't running, or rather when I run it, it doesn't work. I have a page that manually does this if the user visits, and I simply copied the code over and changed it to cycle through each user, which makes me confused. Now I have to determine why.

CRON
PHP Code:
<?php

// Created by DrMath AKA James Will
// ######################## SET PHP ENVIRONMENT ###########################
error_reporting(E_ALL & ~E_NOTICE);
if (!
is_object($vbulletin->db)) {
    exit;
}

// ########################################################################
// ######################### START MAIN SCRIPT ############################
// ########################################################################
// $nextrun is the time difference between runs. Should be sent over from cron.php!!
// We only check the users that have been active since the lastrun to save a bit of cpu time.

$thisrun TIMENOW;
$lastrun $vbulletin->crondata['promos_lastrun'] ? $vbulletin->crondata['promos_lastrun'] : $thisrun - ($nextrun $thisrun);

// Define Basic Membergroups
$membergroups = array(235515253);
$leadergroups = array(5617182438505455565862);

// Define Usergroup Levels
$grouplevels = array();
// Group ID, Required Points, Rank Image Source
$grouplevels[] = array(353"<img src='images/ranks/v9/mem_stea.png' alt='Steadfast Member' />""Steadfast Member");
$grouplevels[] = array(518"<img src='images/ranks/v9/mem_seni.png' alt='Senior Member' />""Senior Member");
$grouplevels[] = array(5215"<img src='images/ranks/v9/mem_reno.png' alt='Renowned Member' />""Renowned Member");
$grouplevels[] = array(5325"<img src='images/ranks/v9/mem_visi.png' alt='Visionary Member' />""Visionary Member");

// Get list of userids
$userid_q $vbulletin->db->query_read("SELECT userid FROM " TABLE_PREFIX "user WHERE usergroupid NOT IN (3,4,5,20,21,23,45)");
while (
$row mysql_fetch_array($userid_qMYSQL_ASSOC)) {
    
$userids[] = $row["userid"];
}
// Gather the Info
//$totalpromos = 0;

foreach ($userids as $userid) {

    
// Query DB for Post Content //
    
$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)");
    
$recruits_q $vbulletin->db->query_read("SELECT COUNT(*) FROM " TABLE_PREFIX "user WHERE referrerid = $userid");
    
$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, 23)");
    
$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");


    
// Transfer to Arrays
    
$u_threads $vbulletin->db->fetch_array($threads_q);
    
$u_recruits $vbulletin->db->fetch_array($recruits_q);
    
$u_awards $vbulletin->db->fetch_array($awards_q);
    
$u_info $vbulletin->db->fetch_array($info_q);

    
$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 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 >= && $recruits <= 4) {
        
$totalpoints += $recruits;
    } elseif (
$recruits >= 5) {
        
$r5points floor($recruits 5);
        
$totalpoints += ($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 floor(($datediff 12) / 6);
        
$totalpoints += $m6ppoints;
    }

    
// Award Points

    
if ($awards 0) {
        
$apoints $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;
                
$log = array($newgroup'*'$newranktitle);
            }           
        }

        
// If they earned a new usergroup, change it
        
if ($newgroup != null) {
            
$userinfo fetch_userinfo($userid);
            
$userdata = & datamanager_init('User'$vbulletinERRTYPE_ARRAY);
            
$userdata->set_existing($userinfo);
            
$userdata->setr('usergroupid'$newgroup);
            
$userdata->setr('usertitle'$newrank);
            
$userdata->save();
            
//$totalpromos ++;
            // the "1" indicates to use the second line of the phrase specified for this task
            
log_cron_action($log$nextitem1);
        }
    }
    
    
// If they are in leadership, check additional groups
    
if (in_array($usergroup$leadergroups)) {
        
        
// If no additional usergroup, set apprentice
        
if ($othergroups == null) {
            
$othergroups "2";
        }

        foreach (
$membergroups as $gid) {
            
$group = (string) $gid;
            if (
in_array($groupexplode(",",$othergroups)) !== false) {
                
$secgroup $group;
                
$secgroupid $gid;
                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;
                
$log = array($newgroup'%'$newranktitle);
            }
        }

        
$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'$vbulletinERRTYPE_ARRAY);
            
$userdata->set_existing($userinfo);
            
$userdata->setr('membergroupids'$othergroups);
            
$userdata->save();
            
//$totalpromos ++;
            // the "1" indicates to use the second line of the phrase specified for this task
            
log_cron_action($log$nextitem1);
        }
    }
}

$vbulletin->crondata['promos_lastrun'] = $thisrun;
build_datastore('crondata'serialize($vbulletin->crondata), 1);


if (
$vbulletin->debug AND VB_AREA == 'AdminCP') {
    
#echo '<pre>'; print_r($sql); print_r($sql_id); echo '</pre>';
}


/* ======================================================================*\
  || ####################################################################
  || # Updated, July 26, 2014
  || ####################################################################
  \*====================================================================== */
?>
MANUAL PAGE
PHP Code:
// If Viewing your own stats, Check if you can level up
    
if ($userid == $vbulletin->userinfo[userid]) {

        
$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) {
                
$userdata = & datamanager_init('User'$vbulletinERRTYPE_ARRAY);
                
$userdata->set_existing($vbulletin->userinfo);
                
$userdata->setr('usergroupid'$newgroup);
                
$userdata->setr('usertitle'$newrank);
                
$userdata->save();

                
//$db->query_write("UPDATE " . TABLE_PREFIX . "user SET usergroupid = $newgroup, usertitle = $newrank WHERE userid = $userid");
                
echo "<p><img src='images/important.png' alt='Important!'/> You qualified for a new rank! Your rank is now $newranktitle! Congratulations</p>";
            }
        }
        if (
in_array($usergroup$leadergroups)) {
            
// If they are in leadership, check additional groups
            // If no additional usergroup, set apprentice
            
if ($othergroups == "") {
                
$othergroups "2";
            }

            foreach (
$membergroups as $gid) {
                
$group = (string) $gid;
                if (
in_array($groupexplode(",",$othergroups)) !== false) {
                    
$secgroup $group;
                    
$secgroupid $gid;
                    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) {
                
$userdata = & datamanager_init('User'$vbulletinERRTYPE_ARRAY);
                
$userdata->set_existing($vbulletin->userinfo);
                
$userdata->setr('membergroupids'$othergroups);
                
$userdata->save();

                
//$db->query_write("UPDATE " . TABLE_PREFIX . "user SET usergroupid = $newgroup, usertitle = $newrank WHERE userid = $userid");
                
echo "<p><img src='images/important.png' alt='Important!'/> You qualified for a new rank! Your rank is now $newranktitle! Congratulations</p>";
                echo 
"<p>2nd Group: $secgroup and NewGroup = $groupid<p/>";
                echo 
$othergroups;
            }
        }
    } 
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 05:13 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.10563 seconds
  • Memory Usage 2,539KB
  • Queries Executed 13 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (5)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (10)post_thanks_box
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (10)post_thanks_postbit_info
  • (10)postbit
  • (10)postbit_onlinestatus
  • (10)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete