/** * Run right at the end of the form processing * form needs to be set to record in database for this to hook to be called * * @throws Exception * * @return bool */ public function onAfterProcess() { $params = $this->getParams(); $api_AUP = JPATH_SITE . '/components/com_alphauserpoints/helper.php'; if (JFile::exists($api_AUP)) { $w = new FabrikWorker(); $this->data = $this->getProcessData(); require_once $api_AUP; $aup = new AlphaUserPointsHelper(); // Define which user will receive the points. $userId = $params->get('user_id', ''); $userId = (int) $w->parseMessageForPlaceholder($userId, $this->data, false); $aupId = $aup->getAnyUserReferreID($userId); // Replace these if you want to show a specific reference for the attributed points - doesn't seem to effect anything $keyReference = ''; // Shown in the user details page - description of what the point is for $dataReference = $params->get('data_reference', ''); $dataReference = $w->parseMessageForPlaceholder($dataReference, $this->data, false); // Override the plugin default points $randomPoints = $params->get('random_points', 0); if ($params->get('random_points_eval', '0') == '1') { if (!empty($randomPoints)) { $randomPoints = $w->parseMessageForPlaceholder($randomPoints, $this->data, false); $randomPoints = @eval($randomPoints); FabrikWorker::logEval($randomPoints, 'Caught exception on eval in aup plugin : %s'); } $randomPoints = (double) $randomPoints; } else { $randomPoints = (double) $w->parseMessageForPlaceholder($randomPoints, $this->data, false); } // If set to be greater than $randompoints then this is the # of points assigned (not sure when this would be used - commenting out for now) $referralUserPoints = 0; $aupPlugin = $params->get('aup_plugin', 'plgaup_fabrik'); $aupPlugin = $w->parseMessageForPlaceholder($aupPlugin, $this->data, false); if (!$aup->checkRuleEnabled($aupPlugin, 0, $aupId)) { throw new Exception('Alpha User Points plugin not published'); } $aup->userpoints($aupPlugin, $aupId, $referralUserPoints, $keyReference, $dataReference, $randomPoints); } }
public static function updateUserPoints($result, $referrerid, $assignpoints, $now, $referraluserpoints, $autoapproved, $rule_plugin = '', $rule_id = '', $rule_name = '', $datareference = '', $frontmessage = '') { $app = JFactory::getApplication(); $lang = JFactory::getLanguage(); $lang->load('com_alphauserpoints', JPATH_SITE); $user = JFactory::getUser(); $username = $user->id ? $user->username : ''; $displaymsg = $result->displaymsg; $msg = str_replace('{username}', $username, $result->msg); $method = $result->method; $db = JFactory::getDBO(); // get params definitions $params = JComponentHelper::getParams('com_alphauserpoints'); $query = "SELECT id FROM #__alpha_userpoints WHERE `referreid`='{$referrerid}'"; $db->setQuery($query); $referrerUser = $db->loadResult(); JTable::addIncludePath(JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_alphauserpoints' . DS . 'tables'); $row = JTable::getInstance('userspoints'); // update points into alpha_userpoints table $row->load(intval($referrerUser)); $referraluser = $row->referraluser; $newtotal = !$referraluserpoints ? $row->points + $assignpoints : $row->points + $referraluserpoints; $row->last_update = $now; $checkWinner = 0; if ($row->max_points >= 1 && $newtotal > $row->max_points) { // Max total was reached ! //$newtotal = $row->max_points; if (AlphaUserPointsHelper::checkRuleEnabled('sysplgaup_winnernotification', 0, $referrerid)) { // get email admins in rule $query = "SELECT `content_items` FROM #__alpha_userpoints_rules WHERE `plugin_function`='sysplgaup_winnernotification'"; $db->setQuery($query); $emailadmins = $db->loadResult(); if ($autoapproved || $referraluserpoints) { AlphaUserPointsHelper::sendwinnernotification($referrerid, $assignpoints, $newtotal, $emailadmins); // Uddeim notification integration if ($params->get('sendMsgUddeim', 0)) { AlphaUserPointsHelper::sendUddeimWinnerNotification($referrerid, $assignpoints, $newtotal); } $checkWinner = 1; } } } if ($autoapproved) { if ($rule_plugin == 'sysplgaup_invitewithsuccess') { $row->referrees = $row->referrees + 1; } $row->points = $newtotal; $db->updateObject('#__alpha_userpoints', $row, 'id'); } if ($displaymsg && !$referraluserpoints) { $realcurrentreferrerid = AlphaUserPointsHelper::getAnyUserReferreID($user->id); switch ($rule_plugin) { case 'sysplgaup_bonuspoints': case 'sysplgaup_recommend': case 'sysplgaup_reader2author': case 'sysplgaup_buypointswithpaypal': case 'sysplgaup_invite': // No need congratulation... break; case 'sysplgaup_invitewithsuccess': // number points in message = assign points to new user $numpoints = AlphaUserPointsHelper::getPointsRule('sysplgaup_newregistered'); if ($numpoints && $user->id) { if ($msg != '') { $msg = str_replace('{points}', AlphaUserPointsHelper::getFPoints($numpoints), JText::_($msg)); $msg = str_replace('{newtotal}', AlphaUserPointsHelper::getFPoints($newtotal), $msg); $app->enqueueMessage($msg); } else { $app->enqueueMessage(sprintf(JText::_('AUP_CONGRATULATION'), AlphaUserPointsHelper::getFPoints($numpoints))); } } break; default: if ($referrerid == $realcurrentreferrerid && $user->id) { if ($assignpoints > 0) { if ($msg != '') { $msg = str_replace('{points}', AlphaUserPointsHelper::getFPoints($assignpoints), JText::_($msg)); $msg = str_replace('{newtotal}', AlphaUserPointsHelper::getFPoints($newtotal), $msg); $app->enqueueMessage($msg); } else { $app->enqueueMessage(sprintf(JText::_('AUP_CONGRATULATION'), AlphaUserPointsHelper::getFPoints($assignpoints))); if ($rule_plugin == 'sysplgaup_happybirthday') { $frontmessage = JText::_('AUP_HAPPYBIRTHDAY'); } } } elseif ($assignpoints < 0) { if ($msg != '') { $msg = str_replace('{points}', AlphaUserPointsHelper::getFPoints(abs($assignpoints)), JText::_($msg)); $msg = str_replace('{newtotal}', AlphaUserPointsHelper::getFPoints($newtotal), $msg); $app->enqueueMessage($msg); } else { $app->enqueueMessage(sprintf(JText::_('AUP_X_POINTS_HAS_BEEN_DEDUCTED_FROM_YOUR_ACCOUNT'), AlphaUserPointsHelper::getFPoints(abs($assignpoints)))); } } } } } if ($rule_plugin == 'sysplgaup_custom' && $datareference) { $rule_name = JText::_($datareference); } // email notification if ($result->notification && !$checkWinner) { $result->datareference = JText::_($datareference); AlphaUserPointsHelper::sendnotification($referrerid, $assignpoints, $newtotal, $result); // load external plugins $dispatcher = JDispatcher::getInstance(); JPluginHelper::importPlugin('alphauserpoints'); $results = $dispatcher->trigger('onSendNotificationAlphaUserPoints', array(&$result, $rule_name, $assignpoints, $newtotal, $referrerid, $user->id)); } // Uddeim notification integration if ($params->get('sendMsgUddeim', 0) && !$checkWinner) { AlphaUserPointsHelper::sendUddeimNotification($referrerid, $assignpoints, $newtotal, $rule_name); } // load external plugins $dispatcher = JDispatcher::getInstance(); JPluginHelper::importPlugin('alphauserpoints'); $results = $dispatcher->trigger('onUpdateAlphaUserPoints', array(&$result, $rule_name, $assignpoints, $referrerid, $user->id)); // checking rank and medals and update if necessary if ($rule_id == '') { $rule_id = AlphaUserPointsHelper::getRuleID($rule_plugin); } AlphaUserPointsHelper::checkRankMedal($referrerid, $rule_id); // referral points rule if ($referraluser != '' && $rule_plugin != 'sysplgaup_buypointswithpaypal' && $rule_plugin != 'sysplgaup_raffle' && $assignpoints > 0) { // if not already assigned $query = "SELECT * FROM #__alpha_userpoints_rules WHERE `plugin_function`='sysplgaup_referralpoints' AND `published`='1' AND (`rule_expire`>'{$now}' OR `rule_expire`='0000-00-00 00:00:00')"; $db->setQuery($query); $referralpoints = $db->loadObjectList(); if ($referralpoints) { $referraluserpoints = round($assignpoints * $referralpoints[0]->points / 100, 2); if ($referraluserpoints > 0) { AlphaUserPointsHelper::userpoints('sysplgaup_referralpoints', $referraluser, $referraluserpoints); } } } // check change user group rule //if ( $rule_plugin!='sysplgaup_changelevel1' && $rule_plugin!='sysplgaup_changelevel2' && $rule_plugin!='sysplgaup_changelevel3' ) //{ AlphaUserPointsHelper::checkChangeLevel($referrerid, AlphaUserPointsHelper::getCurrentTotalPoints($referrerid)); //} if ($frontmessage != '') { AlphaUserPointsHelper::displayMessageSystem($frontmessage); } // load external plugins $dispatcher = JDispatcher::getInstance(); JPluginHelper::importPlugin('alphauserpoints'); $results = $dispatcher->trigger('onAfterUpdateAlphaUserPoints', array(&$result, $rule_name, $assignpoints, $referrerid, $user->id)); // link up rule if ($result->linkup) { $plugin_function_linkup = AlphaUserPointsHelper::getPluginFunction($result->linkup); AlphaUserPointsHelper::newpoints($plugin_function_linkup, $referrerid); } }
function _save_profile() { $app = JFactory::getApplication(); // initialize variables $db = JFactory::getDBO(); $post = JRequest::get('post'); $profilecomplete = 0; if ($post['referreid'] == '') { echo "<script>window.history.go(-1);</script>\n"; exit; } JTable::addIncludePath(JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_alphauserpoints' . DS . 'tables'); $row = JTable::getInstance('userspoints'); if (!isset($post['gender'])) { $post['gender'] = 0; } if ($post['birthdate'] == '') { $post['birthdate'] = '0000-00-00'; } elseif ($post['birthdate'] != '') { // Check format date to save $valdat = $post['birthdate']; $format = substr($valdat, -5, 1); if ($format == '-' || $format == '/') { // french format $cday = substr($valdat, -10, 2); $cmonth = substr($valdat, -7, 2); $cyear = substr($valdat, -4, 4); $post['birthdate'] = $cyear . '-' . $cmonth . '-' . $cday; } } $curdate = date("Y-m-d"); if ($post['birthdate'] >= $curdate) { $post['birthdate'] = '0000-00-00'; } if (!$row->bind($post)) { echo "<script> alert('" . $row->getError() . "'); window.history.go(-1); </script>\n"; exit; } if (!$row->store()) { echo "<script> alert('" . $row->getError() . "'); window.history.go(-1); </script>\n"; exit; } $app->enqueueMessage(JText::_('AUP_CHANGE_SAVED')); // check if all field are complete for the profile complete rule if ($post['gender'] > 0 && $post['birthdate'] != '' && $post['birthdate'] != '0000-00-00' && $post['aboutme'] != '' && $post['city'] != '' && $post['avatar'] != '' && $post['job'] != '' && $post['education'] != '' && $post['graduationyear'] != '') { $profilecomplete = 1; } // rules for Profile require_once JPATH_SITE . DS . 'components' . DS . 'com_alphauserpoints' . DS . 'helper.php'; if ($profilecomplete) { // assigns points when the user upload his avatar: this rule can be assigned only once per user AlphaUserPointsHelper::userpoints('sysplgaup_profilecomplete', '', 0, $post['referreid']); } else { // remove points if profile has been complete and now remove required fields for profile complete -> return state incomplete $rule = AlphaUserPointsHelper::checkRuleEnabled('sysplgaup_profilecomplete'); if ($rule) { // rule published // get ID of rule named 'sysplgaup_profilecomplete' $rule_id = $rule[0]->id; $query = "DELETE FROM #__alpha_userpoints_details WHERE rule='" . $rule_id . "' AND referreid='" . $post['referreid'] . "' AND keyreference='" . $post['referreid'] . "'"; $db->setQuery($query); $db->query(); // recount for this user $this->checkNewTotal($post['referreid'], $rule_id); } } }
public function savecustompoints() { // specific user $app = JFactory::getApplication(); $referrerid = JFactory::getApplication()->input->get('cid', '', 'string'); $name = JFactory::getApplication()->input->get('name', '', 'string'); $points = JFactory::getApplication()->input->get('points', 0, 'float'); $reason = JFactory::getApplication()->input->get('reason', '', 'SAFE_HTML '); if ($referrerid) { require_once JPATH_SITE . DS . 'components' . DS . 'com_alphauserpoints' . DS . 'helper.php'; AlphaUserPointsHelper::userpoints('sysplgaup_custom', $referrerid, 0, '', $reason, $points); AlphaUserPointsHelper::checkRankMedal($referrerid); } $this->setRedirect('index.php?option=com_alphauserpoints&task=showdetails&cid=' . $referrerid . '&name=' . $name); $this->redirect(); }
public function uploadavatar() { $app = JFactory::getApplication(); $db = JFactory::getDBO(); $user = JFactory::getUser(); // load language for component media $lang = JFactory::getLanguage(); $lang->load('com_media', JPATH_SITE); $lang = JFactory::getLanguage(); $lang->load('com_media', JPATH_ADMINISTRATOR); $params = JComponentHelper::getParams('com_media'); require_once JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_media' . DS . 'helpers' . DS . 'media.php'; define('COM_AUP_MEDIA_BASE_IMAGE', JPATH_ROOT . DS . 'components' . DS . 'com_alphauserpoints' . DS . 'assets' . DS . 'images'); // Check for request forgeries JRequest::checkToken('request') or jexit('Invalid Token'); $files = JFactory::getApplication()->input->files->get('filedata', '', 'array'); $file = $files[0]; $folder = JFactory::getApplication()->input->get('folder', 'avatars', 'path'); $format = JFactory::getApplication()->input->get('format', 'html', 'cmd'); $return = JFactory::getApplication()->input->get('return-url', null, 'base64'); $referrerid = JFactory::getApplication()->input->get('referrerid', '', 'string'); $err = null; // Set FTP credentials, if given jimport('joomla.client.helper'); JClientHelper::setCredentialsFromRequest('ftp'); // Make the filename safe jimport('joomla.filesystem.file'); $file['name'] = JFile::makeSafe($file['name']); if (isset($file['name']) && $referrerid != '') { $extention = JFile::getExt($file['name']); $newnameavatar = strtolower($referrerid . '.' . $extention); //chmod (COM_AUP_MEDIA_BASE_IMAGE.DS.$folder, 0755) ; $filepath = JPath::clean(COM_AUP_MEDIA_BASE_IMAGE . DS . $folder . DS . $newnameavatar); // erase old avatar if (file_exists($filepath)) { @unlink($filepath); } if (!MediaHelper::canUpload($file, $err)) { if ($format == 'json') { jimport('joomla.error.log'); $log = JLog::getInstance('upload.error.php'); $log->addEntry(array('comment' => 'Invalid: ' . $filepath . ': ' . $err)); header('HTTP/1.0 415 Unsupported Media Type'); jexit('Error. Unsupported Media Type!'); } else { JError::raiseNotice(100, JText::_($err)); // REDIRECT if ($return) { $this->setRedirect(base64_decode($return)); $this->redirect(); } return; } } if (JFile::exists($filepath)) { if ($format == 'json') { jimport('joomla.error.log'); $log = JLog::getInstance('upload.error.php'); $log->addEntry(array('comment' => 'File already exists: ' . $filepath)); header('HTTP/1.0 409 Conflict'); jexit('Error. File already exists'); } else { JError::raiseNotice(100, JText::_('UPLOAD FAILED. FILE ALREADY EXISTS')); // REDIRECT if ($return) { $this->setRedirect(base64_decode($return)); $this->redirect(); } return; } } if (!JFile::upload($file['tmp_name'], $filepath)) { if ($format == 'json') { jimport('joomla.error.log'); $log = JLog::getInstance('upload.error.php'); $log->addEntry(array('comment' => 'Cannot upload: ' . $filepath)); header('HTTP/1.0 400 Bad Request'); jexit('ERROR. UNABLE TO UPLOAD FILE'); } else { JError::raiseWarning(100, JText::_('ERROR. UNABLE TO UPLOAD FILE')); // REDIRECT if ($return) { $this->setRedirect(base64_decode($return)); $this->redirect(); } return; } } else { // SAVE IN PROFIL USER ALPHAUSERPOINTS $query = "UPDATE #__alpha_userpoints" . "\n SET avatar='" . $newnameavatar . "'" . "\n WHERE referreid='" . $referrerid . "' AND userid='" . $user->id . "'"; $db->setQuery($query); if (!$db->query()) { JError::raiseError(500, $db->getErrorMsg()); return false; } require_once JPATH_SITE . DS . 'components' . DS . 'com_alphauserpoints' . DS . 'helper.php'; if ($format == 'json') { jimport('joomla.error.log'); $log = JLog::getInstance(); $log->addEntry(array('comment' => $folder)); jexit('Upload complete'); // apply rule for upload avatar AlphaUserPointsHelper::userpoints('sysplgaup_uploadavatar', '', 0, $referrerid); } else { $app->enqueueMessage(JText::_('UPLOAD COMPLETE')); // apply rule for upload avatar AlphaUserPointsHelper::userpoints('sysplgaup_uploadavatar', '', 0, $referrerid); // REDIRECT if ($return) { $this->setRedirect(base64_decode($return)); $this->redirect(); } return; } } } else { $this->setRedirect('index.php', 'Invalid Request', 'error'); $this->redirect(); } }
public function sysplgaup_invitewithsuccess($referrerid, $data) { $ip = $_SERVER["REMOTE_ADDR"]; require_once JPATH_SITE . DS . 'components' . DS . 'com_alphauserpoints' . DS . 'helper.php'; $keyreference = AlphaUserPointsHelper::buildKeyreference('sysplgaup_invitewithsuccess', $ip); AlphaUserPointsHelper::userpoints('sysplgaup_invitewithsuccess', $referrerid, 0, $ip, $data); }
function _customrulepoints($cids, $reason, $points) { $app = JFactory::getApplication(); // initialize variables $db = JFactory::getDBO(); $query = "SELECT `id` FROM #__alpha_userpoints_rules WHERE `plugin_function`='sysplgaup_custom'"; $db->setQuery($query); $rule_id = $db->loadResult(); JArrayHelper::toInteger($cids); if (count($cids)) { require_once JPATH_SITE . DS . 'components' . DS . 'com_alphauserpoints' . DS . 'helper.php'; foreach ($cids as $cid) { $query = "SELECT referreid FROM #__alpha_userpoints WHERE id='" . $cid . "'"; $db->setQuery($query); $referrerid = $db->loadResult(); if ($referrerid) { AlphaUserPointsHelper::userpoints('sysplgaup_custom', $referrerid, 0, '', $reason, $points); $this->checkTotalAfterRecalculate($referrerid, $rule_id); } } $app->enqueueMessage(JText::_('AUP_RECALCULATION_MADE')); } $redirecturl = "index.php?option=com_alphauserpoints&task=statistics"; JControllerLegacy::setRedirect($redirecturl); JControllerLegacy::redirect(); }
public function sendinvite() { $app = JFactory::getApplication(); JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN')); // active user $user = JFactory::getUser(); $db = JFactory::getDBO(); jimport('joomla.mail.helper'); $model = $this->getModel('alphauserpoints'); $view = $this->getView('invite', 'html'); $SiteName = $app->getCfg('sitename'); $MailFrom = $app->getCfg('mailfrom'); $FromName = $app->getCfg('fromname'); $jnow = JFactory::getDate(); $now = $jnow->toSql(); $uri = JURI::getInstance(); $base = $uri->toString(array('scheme', 'host', 'port')); $params = $model->_getParamsAUP(); $cparams = JComponentHelper::getParams('com_alphauserpoints'); $referrerid = $model->_getReferreid(); if ($referrerid) { $link = getLinkToInvite($referrerid, $cparams->get('systemregistration')); } else { $link = $base . JRoute::_(''); } if ($params->get('userecaptcha') == 1 || $params->get('userecaptcha') == 2 && !$user->id) { require_once JPATH_SITE . DS . 'components' . DS . 'com_alphauserpoints' . DS . 'assets' . DS . 'recaptcha' . DS . 'recaptchalib.php'; $privatekey = $params->get('privkey'); // the response from reCAPTCHA $resp = null; // the error code from reCAPTCHA, if any $error = null; // was there a reCAPTCHA response? $recaptcha_response_field = JFactory::getApplication()->input->get('recaptcha_response_field', '', 'string'); //if ($_POST["recaptcha_response_field"]) { if ($recaptcha_response_field) { $resp = recaptcha_check_answer($privatekey, $_SERVER["REMOTE_ADDR"], $_POST["recaptcha_challenge_field"], $recaptcha_response_field); if (!$resp->is_valid) { // set the error code so that we can display it $error = $resp->error; JError::raiseWarning(0, $error); return $this->display(); } } else { JError::raiseWarning(0, 'Captcha'); return $this->display(); } } // An array of e-mail headers we do not want to allow as input $headers = array('Content-Type:', 'MIME-Version:', 'Content-Transfer-Encoding:', 'bcc:', 'cc:'); // An array of the input fields to scan for injected headers $fields = array('mailto', 'sender', 'from', 'subject'); /* * Here is the meat and potatoes of the header injection test. We * iterate over the array of form input and check for header strings. * If we fine one, send an unauthorized header and die. */ foreach ($fields as $field) { foreach ($headers as $header) { if (strpos(@$_POST[$field], $header) !== false) { JError::raiseError(403, ''); } } } /* * Free up memory */ unset($headers, $fields); $imported_emails = $_POST['importedemails']; $other_emails = JRequest::getString('other_recipients', '', 'post'); $sender = JRequest::getString('sender', '', 'post'); // Check for a valid to address $errorMail = false; // build list emails if ($imported_emails == '' && $other_emails != '') { $emails = $other_emails; } elseif ($other_emails == '' && $imported_emails != '') { $emails = $imported_emails; } elseif ($imported_emails != '' && $other_emails != '') { $emails = $imported_emails . "," . $other_emails; } else { $emails = ""; $errorMail = JText::_('AUP_EMAIL_INVALID'); JError::raiseWarning(0, $errorMail); } $emails = @explode(',', $emails); // Check for a valid from address if (!$MailFrom || !JMailHelper::isEmailAddress($MailFrom)) { $errorMail = JText::sprintf('AUP_EMAIL_INVALID', $MailFrom); JError::raiseWarning(0, $errorMail); } if ($errorMail) { return $this->display(); } // Build the message to send $msg = JText::_('AUP_EMAIL_MSG_INVITE'); $custommessage = JRequest::getString('custommessage', '', 'post'); $formatMail = '0'; $bcc2admin = '0'; if ($params->get('templateinvite', 0)) { JTable::addIncludePath(JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_alphauserpoints' . DS . 'tables'); $row = JTable::getInstance('template_invite'); $row->load(intval($params->get('templateinvite'))); $subject = $row->emailsubject; $body = $row->emailbody; $body = str_replace('{name}', $sender, $body); $body = str_replace('{custom}', $custommessage, $body); $body = str_replace('{link}', $link, $body); $bcc2admin = $row->bcc2admin; $formatMail = $row->emailformat; } else { $subject = JText::_('AUP_YOUAREINVITEDTOREGISTERON') . " " . $SiteName; $body = sprintf($msg, $SiteName, $sender, $link) . " \n" . $custommessage; } // Clean the email data $subject = JMailHelper::cleanSubject($subject); //$body = JMailHelper::cleanBody($body); require_once JPATH_SITE . DS . 'components' . DS . 'com_alphauserpoints' . DS . 'helper.php'; // Limit $max = $params->get('maxemailperinvite'); $maxperday = $params->get('maxinvitesperday'); $delay = intval($params->get('delaybetweeninvites')); $counter = 0; $rule_ID = $model->_getRuleID('sysplgaup_invite'); $refer_ID = AlphaUserPointsHelper::getAnyUserReferreID($user->id); $numpoints4invite = AlphaUserPointsHelper::getPointsRule('sysplgaup_invite'); $totalpointsearned = 0; $currentmaxperday = $model->_checkCurrentMaxPerDay($rule_ID, $user->id, $referrerid, $_SERVER["REMOTE_ADDR"]); $checkdelay = 1; if ($delay) { $checkdelay = $model->_checkLastInviteForDelay($rule_ID, $user->id, $referrerid, $_SERVER["REMOTE_ADDR"], $delay); } if (!$checkdelay) { $errorTime = JText::_('AUP_DELAY_BETWEEN_INVITES_INVALID'); JError::raiseWarning(0, $errorTime); return $this->display(); } if ($currentmaxperday < $maxperday) { $mailer = JFactory::getMailer(); foreach ($emails as $email) { $aEmails[0] = $model->_extractEmailsFromString($email); $email = $aEmails[0][0]; if (JMailHelper::isEmailAddress($email)) { $mailer->setSender(array($MailFrom, $FromName)); $mailer->setSubject($subject); $mailer->isHTML((bool) $formatMail); $mailer->CharSet = "utf-8"; $mailer->setBody($body); $mailer->addRecipient($email); if ($bcc2admin) { // get all users allowed to receive e-mail system $query = "SELECT email" . " FROM #__users" . " WHERE sendEmail='1' AND block='0'"; $db->setQuery($query); $rowsAdmins = $db->loadObjectList(); foreach ($rowsAdmins as $rowsAdmin) { $mailer->addBCC($rowsAdmin->email); } } if ($mailer->Send() === true) { if ($user->id) { if (AlphaUserPointsHelper::checkRuleEnabled('sysplgaup_invite')) { // insert email for tracking $email2 = str_replace("@", " [at] ", $email); // change @ because can be display on frontend in latest activity $keyreference = AlphaUserPointsHelper::buildKeyreference('sysplgaup_invite', $email); AlphaUserPointsHelper::userpoints('sysplgaup_invite', $refer_ID, 0, $keyreference, $email2); $totalpointsearned = $totalpointsearned + $numpoints4invite; } } else { // guest user : Insert IP and email fortracking JTable::addIncludePath(JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_alphauserpoints' . DS . 'tables'); $row = JTable::getInstance('userspointsdetails'); $row->id = NULL; $row->referreid = 'GUEST'; $row->points = 0; $row->insert_date = $now; $row->expire_date = ''; $row->rule = $rule_ID; $row->approved = 1; $row->status = 1; $row->keyreference = $_SERVER["REMOTE_ADDR"]; $row->datareference = $email; if (!$row->store()) { JError::raiseError(500, $row->getError()); } } $counter++; $currentmaxperday++; } if ($counter == $max || $currentmaxperday == $maxperday) { break; } } } if ($totalpointsearned) { $app->enqueueMessage(sprintf(JText::_('AUP_CONGRATULATION'), $totalpointsearned)); } } else { $maxperdaylimit = JText::_('AUP_MAXINVITESPERDAY') . " " . $maxperday; $app->enqueueMessage($maxperdaylimit); } switch ($counter) { case '0': $message = JText::_('AUP_NO_EMAIL_HAS_BEEN_SENT'); break; case '1': $message = JText::_('AUP_EMAIL_SENT'); break; default: $message = JText::_('AUP_EMAILS_SENT'); $message = sprintf($message, $counter); break; } $app->enqueueMessage($message); $this->setRedirect('index.php?option=com_alphauserpoints&view=invite&Itemid=' . JFactory::getApplication()->input->get('Itemid', '')); $this->redirect(); }