You are here

function referral_user in User Referral 5

Same name and namespace in other branches
  1. 6 referral.module \referral_user()

File

./referral.module, line 225

Code

function referral_user($op, $array = null, $arg_user) {
  global $user;
  switch ($op) {
    case 'insert':

      // The user is being created, save the complete referral data
      _referral_user_save($arg_user->uid);
      break;
    case 'delete':

      // The user is being deleted
      _referral_user_delete($arg_user->uid);
      break;
    case 'view':
      $referrals = array();
      $link = "referral/" . _referral_uid2ref($arg_user->uid);
      if (!variable_get(REFERRAL_DISPLAY_MODE, 0)) {
        if (user_access(REFERRAL_PERM_USE)) {
          if ($user->uid == $arg_user->uid) {

            // User is viewing own page, show referrals
            $referrals[] = array(
              'title' => t('Your referral link'),
              'value' => url($link, NULL, NULL, TRUE),
            );
            $referrals[] = array(
              'title' => t('Referrals'),
              'value' => l(t('View users you have referred'), 'referral/view'),
            );
          }
        }
      }
      if (!$user->uid) {
        $referrals[] = array(
          'title' => t('Referral link'),
          'value' => l(t('Register to this site using my referral link'), $link),
        );
        referral_set_cookie(arg(1));
      }
      if ($referrals) {
        return array(
          'Referrals' => $referrals,
        );
      }
      break;
  }
}