id; // the member to process starting with new Greenie $reportData = ""; // start blank report $processUserData = true; // switch to turn on/off data processing for display onscreen & writing to tables $updateRecordSwitch = true; // turn off to test data output $debugOutputToScreen = false; // echo variable data to screen for review. $debugRecordDataToScreen = false; // echo record info to screen while( $buildUpPoints ) { $tierTracker++; // count the tiers $xuser = JFactory::getUser($pickMe); // load user data $pickUser = $xuser->id; $db = JFactory::getDbo(); // load the AUP data $query = $db->getQuery(true); $query ->select($db->quoteName(array('userid', 'points', 'referraluser', 'levelrank', 'leveldate'))) ->from($db->quoteName('#__alpha_userpoints')) ->where($db->quoteName('userid') . ' = '. $db->quote($pickUser)); $db->setQuery($query); $row = $db->loadRow(); $thisUserId = $xuser->id; // set values for This User $thisUserName = $xuser->name; $thisUserUsername = $xuser->username; $thisUserPoints = $row[1]; $thisUserSponsor = $row[2]; $thisUserRank = $row[3]; $thisUserRankDate = $row[4]; switch (true) { // determine This User's rank and status case ( $thisUserPoints < 60 ) : $thisUserRank = 1; $thisUserStatus = "Greenie"; $thisUserNextPoints = 60; $thisUserNextStatus = "Picker"; $nextUserAddPoints = 50; break; case ( $thisUserPoints < 310 ) : $thisUserRank =2; $thisUserStatus = "Picker"; $thisUserNextPoints = 310; $thisUserNextStatus = "Grader"; $nextUserAddPoints = 300; break; case ( $thisUserPoints < 1810 ) : $thisUserRank = 3; $thisUserStatus = "Grader"; $thisUserNextPoints = 1810; $thisUserNextStatus = "Trader"; $nextUserAddPoints = 1800; break; case ( $thisUserPoints < 10810 ) : $thisUserRank = 4; $thisUserStatus = "Trader"; $thisUserNextPoints = 10810; $thisUserNextStatus = "Roaster"; $nextUserAddPoints = 10800; break; case ( $thisUserPoints < 64810 ) : $thisUserRank = 5; $thisUserStatus = "Roaster"; $thisUserNextPoints = 64810; $thisUserNextStatus = "Merchant"; $nextUserAddPoints = 64800; break; case ( $thisUserPoints < 388810 ) : $thisUserRank = 6; $thisUserStatus = "Merchant"; $thisUserNextPoints = 388810; $thisUserNextStatus = "Baron"; $nextUserAddPoints = 388800; break; default : $thisUserRank = 7; $thisUserStatus = "Baron"; } switch ( $tierTracker ) { // report changes to This User case 1: // first user is New Greenie - no points added $processUserData = false; // as no points are ever added here, do not process $lastAddPoints = 10; $lastNextStatus = "Greenie"; break; default : $processUserData = true; $addedPoints = $lastAddPoints; if( $tierTracker == 2 ) { $datareference = "New $lastNextStatus: $lastUserName joined +$addedPoints points!"; } else { $datareference = "$lastUserName advanced to $lastNextStatus +$addedPoints points!"; } if( $thisUserPoints + $lastAddPoints >= $thisUserNextPoints ) { $lastAddPoints = $nextUserAddPoints; } else { $buildUpPoints = false; } } $lastUserName = $thisUserName; // lock values for source of points to This User $lastNextStatus = $thisUserNextStatus; $pickMe = $thisUserSponsor; if( $pickMe < 400 ) { $buildUpPoints = false; } if( $processUserData ) { // record results $pointstogo = $thisUserNextPoints - ( $thisUserPoints + $addPoints ); $thisUserNewPointsTotal = $thisUserPoints + $addedPoints; // this user's points after applying bonuses switch (true) { // determine this User's new rank based on new points total case ( $thisUserNewPointsTotal < 60 ) : $thisUserNewRank = 1; break; case ( $thisUserNewPointsTotal < 310 ) : $thisUserNewRank = 2; break; case ( $thisUserNewPointsTotal < 1810 ) : $thisUserNewRank = 3; break; case ( $thisUserNewPointsTotal < 10810 ) : $thisUserNewRank = 4; break; case ( $thisUserNewPointsTotal < 64810 ) : $thisUserNewRank = 5; break; case ( $thisUserNewPointsTotal < 388810 ) : $thisUserNewRank = 6; break; default : $thisUserNewRank = 7; } $actionDate = date("Y-m-d H:i:s"); $levelDateFormat = date("Y-m-d"); if( $thisUserNewRank == $thisUserRank ) { $levelDateFormat = $thisUserRankDate; } // if not ranking up then do not change rank date if( $updateRecordSwitch) { $profile = new stdClass(); // Create and populate the details record $profile->referreid = $thisUserId; $profile->points = $addedPoints; $profile->insert_date = $actionDate; $profile->status = 1; $profile->rule = 10; $profile->datareference = $datareference; $result = JFactory::getDbo()->insertObject('#__alpha_userpoints_details', $profile); $object = new stdClass(); // upate the user record $object->userid = $thisUserId; $object->points = $thisUserNewPointsTotal; $object->last_update = $actionDate; $object->levelrank = $thisUserNewRank; $object->leveldate = $levelDateFormat; $result = JFactory::getDbo()->updateObject('#__alpha_userpoints', $object, 'userid'); } if( $debugOutputToScreen ) { $reportData .= "User: $thisUserId
"; $reportData .= "Username: $thisUserName
"; $reportData .= "Points: $thisUserPoints
"; $reportData .= "Rank: $thisUserRank
"; $reportData .= "as of: $thisUserRankDate
"; $reportData .= "Sponsor ID: $thisUserSponsor
"; $reportData .= "Status: $thisUserStatus
"; $reportData .= "Next Status: $thisUserNextStatus
"; $reportData .= "Points to go: $pointstogo
"; $reportData .= "Message: $datareference
"; $reportData .= "Date: $actionDate
"; $reportData .= "Tier: $tierTracker
"; } if( $debugRecordDataToScreen ) { $reportData .= "alpha_userpoints_details
"; // report of data to be inserted into new record $reportData .= "referreid: $thisUserId
"; $reportData .= "points: $addedPoints
"; $reportData .= "insert_date: $actionDate
"; $reportData .= "status: 1
"; $reportData .= "rule: 10
"; $reportData .= "datareference: $datareference
"; $reportData .= "alpha_userpoints
"; // report of data to update record $reportData .= "userid: $thisUserId
"; // record to be updated $reportData .= "points: $thisUserNewPointsTotal
"; $reportData .= "last_update: $actionDate
"; $reportData .= "levelrank: $thisUserNewRank
"; $reportData .= "leveldate: $levelDateFormat
"; } if( $debugOutputToScreen || $debugRecordDataToScreen ) { $reportData .= "
"; } } if ( $tierTracker > 6 ) { $buildUpPoints = false; } } if( $debugOutputToScreen || $debugRecordDataToScreen ) { echo $reportData; } ?>