diff --git a/administrator/components/com_giveaway/config.xml b/administrator/components/com_giveaway/config.xml new file mode 100644 index 0000000..8ceeb9c --- /dev/null +++ b/administrator/components/com_giveaway/config.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/administrator/components/com_giveaway/controllers/swaglist.php b/administrator/components/com_giveaway/controllers/swaglist.php index 26ff25e..67d068f 100644 --- a/administrator/components/com_giveaway/controllers/swaglist.php +++ b/administrator/components/com_giveaway/controllers/swaglist.php @@ -2,6 +2,8 @@ defined( '_JEXEC' ) or die( 'Restricted access' ); jimport('joomla.application.component.controller'); +//error_reporting(E_ALL); +//ini_set('display_errors', 'On'); class GiveawayControllerSwaglist extends JController { @@ -69,6 +71,90 @@ public function import() $this->setRedirect('index.php?option=com_giveaway&view=swaglist', 'Swag Imported'); } + function simulate() { + $email = JRequest::getVar('simulateemail'); + $this->sendswagmail($email); + } + + function sendemail() { + $this->sendswagmail(); + } + + function sendswagmail($winneremail = null) { + $params = &JComponentHelper::getParams( 'com_giveaway' ); + $mainframe = JFactory::getApplication(); + + $subject = $params->get('email_subject'); + $body = $params->get('email_message'); + $fromname = $params->get('email_fromname', $mainframe->getCfg('fromname')); + $fronemail = $params->get('email_fromemail', $mainframe->getCfg('mailfrom')); + + $db = JFactory::getDBO(); + $qry = 'SELECT s.swag_id, s.name as swagname, a.attendee_id, a.name AS attendee_name, a.email + FROM #__giveaway_swag AS s + LEFT JOIN #__giveaway_attendee AS a ON s.attendee_id=a.attendee_id + '; + $db->setQuery($qry); + $swagrows = $db->loadAssocList(); + + echo ''; + echo ''; + foreach ($swagrows as $swagrow) { + $text = $body; + $recipient = $winneremail ? $winneremail : $swagrow['email']; + + foreach ($swagrow as $k=>$v) { + $text = str_replace('{'.$k.'}', $v, $text); + } + + $done = JUtility::sendmail($fronemail, $fromname, $recipient, $subject, $text); + $status = $done ? JText::_('Mail Sent') : JText::_('Mail not sent'); + echo ''; + echo ''; + } + echo '
Attendee NameAttendee EmailSwagStatus
'.$swagrow['attendee_name'].''.$recipient.''.$swagrow['swagname'].''.$status.'
'; + + } + + function randomassign() { + $db = JFactory::getDBO(); + + $qry = "SELECT COUNT(-1) FROM #__giveaway_swag"; + $swags = $db->setQuery($qry); + $swag_count = $db->loadResult(); + + if (!$swag_count) { + $this->setRedirect('index.php?option=com_giveaway&view=swaglist', 'No Swags'); + } + + $qry = "SELECT attendee_id FROM #__giveaway_attendee LIMIT {$swag_count}"; + $db->setQuery($qry); + $winners = $db->loadResultArray(); + + $done = 0; + $tmp_array = array(); + for ($i=0; $i<$swag_count; $i++) { + + // Populate tmp array if its empty + // This is to ensure all attendees get at least 1 swag + if (!count($tmp_array)) { + $tmp_array = $winners; + } + + $key = array_rand($tmp_array); + $winner = $tmp_array[$key]; + $qry = "UPDATE #__giveaway_swag SET attendee_id = {$winner} WHERE (attendee_id = 0 OR attendee_id IS NULL) LIMIT 1"; + $db->setQuery($qry); + if ($db->query()) { + $tmp_array[$key]; + $done++; + } + } + + $this->setRedirect('index.php?option=com_giveaway&view=swaglist', 'Swags randomly assigned to attendees'); + + } + function display() { $view = JRequest::getVar('view', ''); diff --git a/administrator/components/com_giveaway/views/attendeelist/tmpl/default.php b/administrator/components/com_giveaway/views/attendeelist/tmpl/default.php index eef76f2..79a3f7e 100644 --- a/administrator/components/com_giveaway/views/attendeelist/tmpl/default.php +++ b/administrator/components/com_giveaway/views/attendeelist/tmpl/default.php @@ -6,6 +6,7 @@ JToolBarHelper::deleteList(); JToolBarHelper::editList(); JToolBarHelper::addNew(); +JToolBarHelper::preferences('com_giveaway', 400, 600); ?>
@@ -71,4 +72,4 @@ -
\ No newline at end of file + diff --git a/administrator/components/com_giveaway/views/swaglist/tmpl/default.php b/administrator/components/com_giveaway/views/swaglist/tmpl/default.php index 5cdd0b0..e12f751 100644 --- a/administrator/components/com_giveaway/views/swaglist/tmpl/default.php +++ b/administrator/components/com_giveaway/views/swaglist/tmpl/default.php @@ -3,9 +3,13 @@ JToolBarHelper::title( 'Swag List' ); +JToolBarHelper::custom('simulate', 'assign', 'assign', 'Simulate Email', false); +JToolBarHelper::custom('sendemail', 'assign', 'assign', 'Send Gifts!', false); +JToolBarHelper::custom('randomassign', 'assign', 'assign', 'Random Assign', false); JToolBarHelper::deleteList(); JToolBarHelper::editList(); JToolBarHelper::addNew(); +JToolBarHelper::preferences('com_giveaway', 400, 600); $document = JFactory::getDocument(); $document->addScript(JURI::base() . 'components/com_giveaway/views/swaglist/tmpl/default.js'); @@ -13,6 +17,28 @@ ?> +

Download CSV

@@ -61,6 +87,7 @@ +

 

@@ -80,4 +107,4 @@ - \ No newline at end of file +