public static function sendUddeimWinnerNotification($referrerid, $assignpoints, $newtotal) { $app = JFactory::getApplication(); $lang = JFactory::getLanguage(); $lang->load('com_alphauserpoints', JPATH_SITE); // get params definitions $params = JComponentHelper::getParams('com_alphauserpoints'); if (!$referrerid || $referrerid == 'GUEST') { return; } // check if component installed $uddeim_exist = JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_uddeim' . DS . 'admin.uddeimlib15.php'; if (!file_exists($uddeim_exist)) { return; } $FromName = $app->getCfg('fromname'); $userinfo = AlphaUserPointsHelper::getUserInfo($referrerid); $name = $userinfo->name; $fromIdUddeim = intval($params->get('fromIdUddeim')); if (!$userinfo->block && $fromIdUddeim > 0) { require_once JPATH_SITE . DS . "components" . DS . "com_uddeim" . DS . "uddeim.api.php"; // send notification to winner $message = sprintf(JText::_('AUP_EMAILWINNERNOTIFICATION_MSG_USER'), $name, AlphaUserPointsHelper::getFPoints($newtotal)); $uddeimapi = new uddeIMAPI(); $uddeimapi->sendNewMessage($fromIdUddeim, $userinfo->userid, $message); } }
function _make_raffle_now() { $app = JFactory::getApplication(); require_once JPATH_SITE . DS . 'components' . DS . 'com_alphauserpoints' . DS . 'helper.php'; $db = JFactory::getDBO(); // Proceed raffle now $cid = JFactory::getApplication()->input->get('cid', array(0), 'array'); $rowRaffle = $this->_edit_raffle(); $rowRaffle = $rowRaffle[0]; $jnow = JFactory::getDate(); $now = $jnow->toSql(); // add offset $config = JFactory::getConfig(); $tzoffset = $config->get('config.offset'); $datetimestamp = strtotime($now); $now = date('Y-m-d H:i:s', $datetimestamp + $tzoffset * 60 * 60); // get params definitions $params = JComponentHelper::getParams('com_alphauserpoints'); // Raffle date is not today ? if ($rowRaffle->raffledate != '0000-00-00 00:00:00' && $now < $rowRaffle->raffledate) { echo "<script> alert('" . JText::_('AUP_DATE_OF_RAFFLE_IS_NOT_TODAY') . "'); window.history.go(-1); </script>\n"; exit; } // load external plugins $dispatcher = JDispatcher::getInstance(); JPluginHelper::importPlugin('alphauserpoints'); $results = $dispatcher->trigger('onBeforeMakeRaffleAlphaUserPoints', array(&$rowRaffle, $now)); $winner1 = 0; $winner2 = 0; $winner3 = 0; $winner1_Referreid = 0; $winner2_Referreid = 0; $winner3_Referreid = 0; // exclude users if rule enabled $queryExclude = " AND `published`='1'"; // first raffle // select all users registered or only users with registration for this raffle if ($rowRaffle->inscription) { $query = "SELECT id, userid as uid FROM #__alpha_userpoints_raffle_inscriptions WHERE raffleid=" . $rowRaffle->id; } else { $query = "SELECT userid as uid FROM #__alpha_userpoints WHERE blocked='0'" . $queryExclude; } $db->setQuery($query); $listParticipants = $db->loadObjectList(); if (!$listParticipants) { echo "<script> alert('" . JText::_('AUP_NO_PARTICIPANT') . "'); window.history.go(-1); </script>\n"; exit; } $max = count($listParticipants) - 1; $choice = rand(0, $max); $winner1 = $listParticipants[$choice]->uid; if ($rowRaffle->numwinner > 1) { // 2th raffle without first winner if ($rowRaffle->inscription) { $query = "SELECT userid as uid FROM #__alpha_userpoints_raffle_inscriptions WHERE raffleid=" . $rowRaffle->id . " AND userid!='{$winner1}'"; } else { $query = "SELECT userid as uid FROM #__alpha_userpoints WHERE blocked='0' AND userid!='{$winner1}'" . $queryExclude; } $db->setQuery($query); $listParticipants2 = $db->loadObjectList(); $max2 = count($listParticipants2) - 1; $choice2 = rand(0, $max2); $winner2 = @$listParticipants2[$choice2]->uid; } if ($rowRaffle->numwinner == 3) { // 3th raffle without first and second winner if ($rowRaffle->inscription) { $query = "SELECT userid as uid FROM #__alpha_userpoints_raffle_inscriptions WHERE raffleid=" . $rowRaffle->id . " AND userid!='{$winner1}' AND userid!='{$winner2}'"; } else { $query = "SELECT userid as uid FROM #__alpha_userpoints WHERE blocked='0' AND userid!='{$winner1}' AND userid!='{$winner2}'" . $queryExclude; } $db->setQuery($query); $listParticipants3 = $db->loadObjectList(); $max3 = count($listParticipants3) - 1; $choice3 = rand(0, $max3); $winner3 = @$listParticipants3[$choice3]->uid; } // Save winner(s) $row = JTable::getInstance('raffle'); $row->load($rowRaffle->id); $row->winner1 = $winner1; $row->winner2 = $winner2; $row->winner3 = $winner3; if (!$row->store()) { JError::raiseError(500, $row->getError()); } // attribs points or coupon code if ($winner1) { $winner1_Referreid = AlphaUserPointsHelper::getAnyUserReferreID(intval($winner1)); } if ($winner2) { $winner2_Referreid = AlphaUserPointsHelper::getAnyUserReferreID(intval($winner2)); } if ($winner3) { $winner3_Referreid = AlphaUserPointsHelper::getAnyUserReferreID(intval($winner3)); } switch ($rowRaffle->rafflesystem) { case '1': // is coupon code ... // send notification by email if ($rowRaffle->sendcouponbyemail) { if ($winner1 && $rowRaffle->couponcodeid1) { $this->sendnotification4couponcode($winner1_Referreid, $this->_get_Coupon($rowRaffle->couponcodeid1)); } if ($winner2 && $rowRaffle->couponcodeid2) { $this->sendnotification4couponcode($winner2_Referreid, $this->_get_Coupon($rowRaffle->couponcodeid2)); } if ($winner3 && $rowRaffle->couponcodeid3) { $this->sendnotification4couponcode($winner3_Referreid, $this->_get_Coupon($rowRaffle->couponcodeid3)); } } // uddeim notification if ($params->get('sendMsgUddeim', 0) && $params->get('fromIdUddeim')) { // Uddeim notification integration require_once JPATH_SITE . DS . 'components' . DS . 'com_alphauserpoints' . DS . 'helpers' . DS . 'uddeim.api.php'; $SiteName = $app->getCfg('sitename'); if ($winner1 && $rowRaffle->couponcodeid1) { $message = sprintf(JText::_('AUP_EMAILNOTIFICATION_MSG_COUPONCODE'), $SiteName, $this->_get_Coupon($rowRaffle->couponcodeid1)); uddeIMAPI::sendNewMessage(intval($params->get('fromIdUddeim')), intval($winner1), $message); $message = ""; } if ($winner2 && $rowRaffle->couponcodeid2) { $message = sprintf(JText::_('AUP_EMAILNOTIFICATION_MSG_COUPONCODE'), $SiteName, $this->_get_Coupon($rowRaffle->couponcodeid2)); uddeIMAPI::sendNewMessage(intval($params->get('fromIdUddeim')), intval($winner2), $message); $message = ""; } if ($winner3 && $rowRaffle->couponcodeid3) { $message = sprintf(JText::_('AUP_EMAILNOTIFICATION_MSG_COUPONCODE'), $SiteName, $this->_get_Coupon($rowRaffle->couponcodeid3)); uddeIMAPI::sendNewMessage(intval($params->get('fromIdUddeim')), intval($winner3), $message); $message = ""; } } break; case '2': // e-mail with a download link as a price if ($winner1 && $rowRaffle->link2download1) { $this->sendnotificationDownload($winner1_Referreid, $rowRaffle->link2download1); } if ($winner2 && $rowRaffle->link2download2) { $this->sendnotificationDownload($winner2_Referreid, $rowRaffle->link2download2); } if ($winner3 && $rowRaffle->link2download3) { $this->sendnotificationDownload($winner3_Referreid, $rowRaffle->link2download3); } break; case '3': // just simple e-mail if ($winner1) { $this->sendSimpleEmail($winner1_Referreid, '1'); } if ($winner2) { $this->sendSimpleEmail($winner2_Referreid, '2'); } if ($winner3) { $this->sendSimpleEmail($winner3_Referreid, '3'); } break; default: // is points ... if ($winner1) { AlphaUserPointsHelper::newpoints('sysplgaup_raffle', $winner1_Referreid, '', $rowRaffle->description, $rowRaffle->pointstoearn1); } if ($winner2) { AlphaUserPointsHelper::newpoints('sysplgaup_raffle', $winner2_Referreid, '', $rowRaffle->description, $rowRaffle->pointstoearn2); } if ($winner3) { AlphaUserPointsHelper::newpoints('sysplgaup_raffle', $winner3_Referreid, '', $rowRaffle->description, $rowRaffle->pointstoearn3); } } // end switch $results = $dispatcher->trigger('onAfterMakeRaffleAlphaUserPoints', array(&$rowRaffle, $now)); $redirecturl = "index.php?option=com_alphauserpoints&task=raffle"; JControllerLegacy::setRedirect($redirecturl); JControllerLegacy::redirect(); }