function _referral_user_save in User Referral 5
Same name and namespace in other branches
- 6 referral.module \_referral_user_save()
- 7 referral.module \_referral_user_save()
1 call to _referral_user_save()
File
- ./
referral.module, line 181
Code
function _referral_user_save($uid) {
if (!isset($_COOKIE[REFERRAL_COOKIE])) {
return;
}
$cookie = unserialize($_COOKIE[REFERRAL_COOKIE]);
db_query("INSERT INTO {referral} (uid, referral_uid, created, host, http_referer) VALUES (%d, %d, %d, '%s', '%s')", $uid, $cookie['uid'], $cookie['timestamp'], $cookie['ip'], $cookie['referer']);
if (db_affected_rows()) {
if (module_exists('userpoints')) {
$points = variable_get(REFERRAL_USERPOINTS, 1);
// Build the userpoints params array
$params = array(
'points' => $points,
'uid' => $cookie['uid'],
'operation' => 'referral',
'entity_id' => $cookie['uid'],
'entity_type' => 'user',
'reference' => 'referral',
);
// Award the points to the user
userpoints_userpointsapi($params);
// Check to see if the role needs to be elevated
//if (function_exists('userpoints_role_userpoints')) {
//userpoints_role_userpoints('points after', 0, $cookie[$uid], '');
//}
}
}
else {
watchdog('referral', t('INSERT of referral data failed.'), WATCHDOG_ERROR);
}
}