private function sendNotificationOnUpdateRank($userinfo, $result) { $app = JFactory::getApplication(); $lang = JFactory::getLanguage(); $lang->load('com_alphauserpoints', JPATH_SITE); jimport('joomla.mail.helper'); require_once JPATH_ROOT . '/components/com_alphauserpoints/helper.php'; // get params definitions $params = JComponentHelper::getParams('com_alphauserpoints'); $jsNotification = $params->get('jsNotification', 0); $jsNotificationAdmin = $params->get('fromIdUddeim', 0); $SiteName = $app->getCfg('sitename'); $MailFrom = $app->getCfg('mailfrom'); $FromName = $app->getCfg('fromname'); $sef = $app->getCfg('sef'); $email = $userinfo->email; $subject = $result->emailsubject; $body = $result->emailbody; $formatMail = $result->emailformat; $bcc2admin = $result->bcc2admin; $subject = str_replace('{username}', $userinfo->username, $subject); $subject = str_replace('{points}', AlphaUserPointsHelper::getFPoints($userinfo->points), $subject); $body = str_replace('{username}', $userinfo->username, $body); $body = str_replace('{points}', AlphaUserPointsHelper::getFPoints($userinfo->points), $body); $subject = JMailHelper::cleanSubject($subject); if (!$jsNotification) { $mailer = JFactory::getMailer(); $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); } } $send = $mailer->Send(); } else { require_once JPATH_ROOT . '/components/com_community/libraries/core.php'; $params = new CParameter(''); CNotificationLibrary::add('system_messaging', $jsNotificationAdmin, $userinfo->id, $subject, $body, '', $params); if ($bcc2admin) { // get all users allowed to receive e-mail system $query = "SELECT id" . " FROM #__users" . " WHERE sendEmail='1' AND block='0'"; $db->setQuery($query); $rowsAdmins = $db->loadObjectList(); foreach ($rowsAdmins as $rowsAdmin) { $mailer->addBCC($rowsAdmin->id); CNotificationLibrary::add('system_messaging', $userinfo->id, $rowsAdmin->id, $subject, $body, '', $params); } } } }
public static function getCurrentTotalPoints($referreid = '', $userid = 0, $formatted = 0) { $db = JFactory::getDBO(); $currenttotalpoints = 0; if ($referreid != '') { $query = "SELECT points FROM #__alpha_userpoints WHERE `referreid`='" . $referreid . "' AND `blocked`='0'"; $db->setQuery($query); $currenttotalpoints = $db->loadResult(); } elseif ($userid >= 1) { $query = "SELECT points FROM #__alpha_userpoints WHERE `userid`='" . intval($userid) . "' AND `blocked`='0'"; $db->setQuery($query); $currenttotalpoints = $db->loadResult(); } else { return; } if ($formatted) { $currenttotalpoints = AlphaUserPointsHelper::getFPoints($currenttotalpoints); } return $currenttotalpoints; }
public function onUserAfterSave($user, $isnew, $succes, $msg) { if ($isnew) { $app = JFactory::getApplication(); $lang = JFactory::getLanguage(); $lang->load('com_alphauserpoints', JPATH_SITE); $jnow = JFactory::getDate(); $now = $jnow->toSql(); require_once JPATH_SITE . DS . 'components' . DS . 'com_alphauserpoints' . DS . 'helper.php'; // get params definitions $params = JComponentHelper::getParams('com_alphauserpoints'); $prefixSelfRegister = $params->get('prefix_selfregister'); $prefixReferralRegister = $params->get('prefix_referralregister'); $referrerid = trim(@$_SESSION['referrerid']); unset($_SESSION['referrerid']); $db = JFactory::getDBO(); $query = "SELECT * FROM #__alpha_userpoints_rules WHERE `plugin_function`='sysplgaup_newregistered' AND `published`='1'"; $db->setQuery($query); $result = $db->loadObjectList(); $prefixNewReferreid = $referrerid != '' ? strtoupper($prefixReferralRegister) : strtoupper($prefixSelfRegister); // if rule enabled if ($result) { if (!$params->get('referralIDtype')) { $newreferreid = strtoupper(uniqid($prefixNewReferreid, false)); } else { $newreferreid = $prefixNewReferreid . strtoupper($user['username']); $newreferreid = str_replace(' ', '-', $newreferreid); $newreferreid = str_replace(',', '-', $newreferreid); $newreferreid = str_replace("'", "-", $newreferreid); } JTable::addIncludePath(JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_alphauserpoints' . DS . 'tables'); $row = JTable::getInstance('userspoints'); // insert this new user into alphauserpoints table $row->id = NULL; $row->userid = $user['id']; $row->referreid = $newreferreid; $row->points = $result[0]->points; $row->max_points = 0; $row->last_update = $now; $row->referraluser = $referrerid; $row->published = 1; $row->shareinfos = 1; if (isset($user['profile']) && count($user['profile'])) { foreach ($user['profile'] as $k => $v) { $value = str_replace('"', '', $v); $row = $this->checkProfileField($k, $row, $value); } } if (!$row->store()) { JError::raiseError(500, $row->getError()); } // save new points into alphauserpoints table details $row2 = JTable::getInstance('userspointsdetails'); $row2->id = NULL; $row2->referreid = $newreferreid; $row2->points = $result[0]->points; $row2->insert_date = $now; $row2->expire_date = $result[0]->rule_expire; $row2->status = $result[0]->autoapproved; $row2->rule = $result[0]->id; $row2->approved = $result[0]->autoapproved; $row2->datareference = JText::_('AUP_WELCOME'); if (!$row2->store()) { JError::raiseError(500, $row2->getError()); } // frontend message if ($result[0]->displaymsg) { $msg = str_replace('{username}', $user['username'], $result[0]->msg); if ($msg != '') { $app->enqueueMessage(str_replace('{points}', AlphaUserPointsHelper::getFPoints($result[0]->points), JText::_($msg))); } else { $app->enqueueMessage(sprintf(JText::_('AUP_CONGRATULATION'), $result[0]->points)); } } // send notification if ($result[0]->notification) { AlphaUserPointsHelper::sendnotification($newreferreid, $result[0]->points, $result[0]->points, $result[0], 1); } if ($referrerid) { $data = htmlspecialchars($user['name'], ENT_QUOTES, 'UTF-8') . " (" . $user['username'] . ") "; $data = sprintf(JText::_('AUP_X_HASJOINEDTHEWEBSITE'), $data); $this->sysplgaup_invitewithsuccess($referrerid, $data); } return true; } else { return false; } } }