public function onMembershipPayment($plugin, $data, $extra, $membership, $transaction, $html) { if (!$this->canRun()) { return; } if ($plugin != 'rsmembership2co') { return false; } // Set tax. $transaction->price += $this->_getTax($transaction->price); // Set the custom hash. $transaction->custom = md5($transaction->params . ' ' . uniqid('2checkout')); // Is it a demo purchase? $demo = !$this->params->get('mode'); // Set the URL for the form $url = sprintf('https://%s.2checkout.com/checkout/purchase', $demo ? 'sandbox' : 'www'); // Set our vars $vars = array('sid' => $this->params->get('id'), 'mode' => '2CO', 'li_0_name' => $this->params->get('message_type') ? $membership->name : JText::sprintf('PLG_SYSTEM_RSMEMBERSHIP2CO_MEMBERSHIP_PURCHASE_ON', RSMembershipHelper::showDate($transaction->date)), 'li_0_price' => $this->_convertNumber($transaction->price), 'x_receipt_link_url' => JUri::root() . 'index.php?option=com_rsmembership&oldtwocopayment=1', 'currency_code' => RSMembershipHelper::getConfig('currency'), 'custom' => $transaction->custom, 'vendor_order_id' => $transaction->custom); if ($membership->recurring && $membership->period > 0) { $vars['li_0_recurrence'] = $this->getRecurrence($membership->period, $membership->period_type); // Get duration. if ($membership->recurring_times) { if (preg_match('#[0-9]+#', $vars['li_0_recurrence'], $match)) { $vars['li_0_duration'] = str_replace($match[0], $match[0] * $membership->recurring_times, $vars['li_0_recurrence']); } } else { $vars['li_0_duration'] = 'Forever'; } } // Add demo mode. if ($demo) { $vars['demo'] = 'Y'; } // Mark the transaction as complete. if ($membership->activation == 2) { $transaction->status = 'completed'; } $html = ''; $html .= '<p>' . JText::_('PLG_SYSTEM_RSMEMBERSHIP2CO_PLEASE_WAIT_REDIRECT') . '</p>'; $html .= '<form method="post" action="' . $url . '" id="twocoForm">'; foreach ($vars as $key => $value) { $html .= '<input type="hidden" name="' . $key . '" value="' . htmlentities($value, ENT_COMPAT, 'utf-8') . '" />' . "\n"; } $html .= '</form>'; $html .= '<script type="text/javascript">'; $html .= 'function twocoFormSubmit() { document.getElementById(\'twocoForm\').submit() }'; $html .= 'try { window.addEventListener ? window.addEventListener("load",twocoFormSubmit,false) : window.attachEvent("onload",twocoFormSubmit); }'; $html .= 'catch (err) { twocoFormSubmit(); }'; $html .= '</script>'; return $html; }
function getYears() { $return = array(); $tmp = new stdClass(); $tmp->value = 0; $tmp->text = JText::_('COM_RSMEMBERSHIP_EVERY_YEAR'); $return[] = $tmp; // $max = date('Y', RSMembershipHelper::getCurrentDate()); $max = RSMembershipHelper::showDate(time(), 'Y'); for ($i = $max; $i <= $max + 50; $i++) { $tmp = new stdClass(); $tmp->value = $i; $tmp->text = $i; $return[] = $tmp; } return $return; }
public static function buildCSV($type, $data, $fileHash = '', $customFields = null) { require_once JPATH_COMPONENT . '/helpers/helper.php'; $rows = ''; if ($fileHash == '') { // Build header switch ($type) { case 'subscribers': $headers = array(JText::_('COM_RSMEMBERSHIP_SUBSCRIBER_ID'), JText::_('COM_RSMEMBERSHIP_ENABLED'), JText::_('COM_RSMEMBERSHIP_NAME'), JText::_('COM_RSMEMBERSHIP_USERNAME'), JText::_('COM_RSMEMBERSHIP_EMAIL')); if ($customFields) { foreach ($customFields as $id => $properties) { $headers[] = JText::_($properties->label); } } break; case 'subscriptions': $headers = array(JText::_('COM_RSMEMBERSHIP_MEMBERSHIP'), JText::_('COM_RSMEMBERSHIP_USERNAME'), JText::_('COM_RSMEMBERSHIP_EMAIL'), JText::_('COM_RSMEMBERSHIP_STATUS'), JText::_('COM_RSMEMBERSHIP_NOTIFIED'), JText::_('COM_RSMEMBERSHIP_START_DATE'), JText::_('COM_RSMEMBERSHIP_START_END'), JText::_('JPUBLISHED')); break; } // Add header to rows $rows .= '"' . implode('","', $headers) . '"' . "\n"; } // Add the data to rows foreach ($data as $i => $entry) { $row = (array) $entry; switch ($type) { case 'subscribers': $row['block'] = $row['block'] ? JText::_('JNO') : JText::_('JYES'); break; case 'subscriptions': unset($row['membership_id']); unset($row['id']); unset($row['user_id']); $row['membership_start'] = RSMembershipHelper::showDate($row['membership_start']); $row['membership_end'] = $row['membership_end'] != '0000-00-00 00:00:00' ? RSMembershipHelper::showDate($row['membership_end']) : ' - '; $row['notified'] = $row['notified'] != '0000-00-00 00:00:00' ? RSMembershipHelper::showDate($row['notified']) : ' - '; $row['status'] = JText::_('COM_RSMEMBERSHIP_STATUS_' . $row['status']); $row['published'] = $row['published'] ? JText::_('JYES') : JText::_('JNO'); break; } $rows .= '"' . implode('","', $row) . '"'; $rows .= "\n"; } return $rows; }
public function _getDefaultFilters() { $db = JFactory::getDBO(); $query = $db->getQuery(true); $filters = array(); // set the default values for fields in xml $filters['report'] = 'report_2'; $filters['from_date'] = ''; $filters['to_date'] = RSMembershipHelper::showDate(JFactory::getDate()->toUnix(), 'Y-m-d'); $filters['unit'] = 'day'; $filters['user_id'] = ''; $filters['memberships'] = array_keys(RSMembershipHelper::getMembershipsList(false)); $filters['status_memberships'] = array(0, 1, 2, 3); $filters['status_transactions'] = array('pending', 'completed', 'denied'); $filters['price_from'] = 0; $filters['price_to'] = ''; $filters['transaction_types'] = array('new', 'upgrade', 'addextra', 'renew'); $query->select('DISTINCT(gateway)')->from($db->qn('#__rsmembership_transactions'))->order($db->qn('gateway') . ' ASC'); $db->setQuery($query); $filters['gateways'] = $db->loadColumn(); return $filters; }
public function save($data) { $db = JFactory::getDBO(); $query = $db->getQuery(true); if (empty($data['id'])) { $data['date_added'] = RSMembershipHelper::showDate(time(), 'Y-m-d H:i:s'); } parent::save($data); $coupon_id = $this->getState($this->getName() . '.id', 'id'); // delete $query->delete()->from($db->qn('#__rsmembership_coupon_items'))->where($db->qn('coupon_id') . ' = ' . $db->q($coupon_id)); $db->setQuery($query); $db->execute(); // insert in coupon_items if (!empty($data['used_for'])) { foreach ($data['used_for'] as $membership_item) { $query->clear(); $query->insert($db->qn('#__rsmembership_coupon_items'))->set($db->qn('coupon_id') . ' = ' . $db->q($coupon_id) . ', ' . $db->qn('membership_id') . ' = ' . $db->q($membership_item)); $db->setQuery($query); $db->execute(); } } return true; }
if (!empty($params['extras'])) { foreach ($params['extras'] as $extra) { echo $this->cache->extra_values[$extra] . '<br />'; } } break; case 'renew': if (!empty($params['membership_id'])) { echo $this->cache->memberships[$params['membership_id']]; } break; } ?> </td> <td><?php echo RSMembershipHelper::showDate($row->date); ?> </td> <td><?php echo $this->escape($row->ip); ?> </td> <td><?php echo RSMembershipHelper::getPriceFormat($row->price); ?> </td> <td><?php echo JText::_('COM_RSMEMBERSHIP_TRANSACTION_STATUS_' . strtoupper($row->status)); ?> </td> <td><?php
foreach ($this->items as $i => $item) { ?> <tr class="row<?php echo $i % 2; ?> "> <td width="1%" nowrap="nowrap"><?php echo $this->pagination->getRowOffset($i); ?> </td> <td width="1%" nowrap="nowrap"><?php echo JHtml::_('grid.id', $i, $item->id); ?> </td> <td width="1%" nowrap="nowrap"><?php echo RSMembershipHelper::showDate($item->date); ?> </td> <td width="1%" nowrap="nowrap"><?php echo $this->escape($item->ip); ?> </td> <td><?php echo $this->escape($item->path); ?> </td> </tr> <?php } ?> <tfoot>
public function onMembershipPayment($plugin, $data, $extra, $membership, $transaction, $html) { if (!$this->canRun()) { return; } if ($plugin != 'rsmembershippaypal') { return false; } $db = JFactory::getDBO(); $query = $db->getQuery(true); $transaction->price += $this->_getTax($transaction->price); $extra_total = 0; foreach ($extra as $row) { $extra_total += $row->price; } $query->select('*')->from($db->qn('#__rsmembership_memberships'))->where($db->qn('id') . ' = ' . $db->q((int) $membership->id)); $db->setQuery($query); $db_membership = $db->loadObject(); $transaction->custom = md5($transaction->params . ' ' . time()); $url = $this->params->get('mode') ? 'https://www.paypal.com/cgi-bin/webscr' : 'https://www.sandbox.paypal.com/cgi-bin/webscr'; $html = ''; $html .= '<p>' . JText::_('PLG_SYSTEM_RSMEMBERSHIPPAYPAL_PLEASE_WAIT_REDIRECT') . '</p>'; $html .= '<form method="post" action="' . $url . '" id="paypalForm">'; $html .= '<input type="hidden" name="business" value="' . $this->escape($this->params->get('email')) . '" />'; $html .= '<input type="hidden" name="charset" value="utf-8" />'; if ($this->params->get('message_type')) { $html .= '<input type="hidden" name="item_name" value="' . $this->escape($membership->name) . '" />'; } else { $html .= '<input type="hidden" name="item_name" value="' . $this->escape(JText::sprintf('PLG_SYSTEM_RSMEMBERSHIPPAYPAL_MEMBERSHIP_PURCHASE_ON', RSMembershipHelper::showDate($transaction->date))) . '" />'; } $html .= '<input type="hidden" name="currency_code" value="' . $this->escape(RSMembershipHelper::getConfig('currency')) . '" />'; if ($membership->recurring && $membership->period > 0 && $transaction->type == 'new') { $html .= '<input type="hidden" name="cmd" value="_xclick-subscriptions" />'; $html .= '<input type="hidden" name="no_shipping" value="1" />'; $html .= '<input type="hidden" name="no_note" value="1" />'; $html .= '<input type="hidden" name="src" value="1" />'; $html .= '<input type="hidden" name="sra" value="1" />'; if ($membership->recurring_times > 0) { $html .= '<input type="hidden" name="srt" value="' . ($membership->recurring_times > 52 ? 52 : $membership->recurring_times) . '" />'; } // trial period if ($membership->use_trial_period) { // initial price $price = $this->_convertNumber($transaction->price); $html .= '<input type="hidden" name="a1" value="' . $price . '" />'; list($p, $t) = $this->_convertPeriod($db_membership->trial_period, $db_membership->trial_period_type); $html .= '<input type="hidden" name="p1" value="' . $p . '" />'; $html .= '<input type="hidden" name="t1" value="' . $t . '" />'; // renewal price (+tax) $price = $this->_convertNumber($membership->use_renewal_price ? $db_membership->renewal_price + $this->_getTax($db_membership->renewal_price) : $db_membership->price + $this->_getTax($db_membership->price)); // add extras $price += $extra_total; $html .= '<input type="hidden" name="a3" value="' . $price . '" />'; list($p, $t) = $this->_convertPeriod($db_membership->period, $db_membership->period_type); $html .= '<input type="hidden" name="p3" value="' . $p . '" />'; $html .= '<input type="hidden" name="t3" value="' . $t . '" />'; } else { // different renewal price ? if ($membership->use_renewal_price) { // initial price $price = $this->_convertNumber($transaction->price); $html .= '<input type="hidden" name="a1" value="' . $price . '" />'; list($p, $t) = $this->_convertPeriod($db_membership->period, $db_membership->period_type); $html .= '<input type="hidden" name="p1" value="' . $p . '" />'; $html .= '<input type="hidden" name="t1" value="' . $t . '" />'; // renewal price (+tax) $price = $this->_convertNumber($membership->renewal_price + $this->_getTax($membership->renewal_price)); // add extras $price += $extra_total; $html .= '<input type="hidden" name="a3" value="' . $price . '" />'; list($p, $t) = $this->_convertPeriod($db_membership->period, $db_membership->period_type); $html .= '<input type="hidden" name="p3" value="' . $p . '" />'; $html .= '<input type="hidden" name="t3" value="' . $t . '" />'; } else { // renewal price $price = $this->_convertNumber($transaction->price); $html .= '<input type="hidden" name="a3" value="' . $price . '" />'; list($p, $t) = $this->_convertPeriod($membership->period, $membership->period_type); $html .= '<input type="hidden" name="p3" value="' . $p . '" />'; $html .= '<input type="hidden" name="t3" value="' . $t . '" />'; } } } else { $html .= '<input type="hidden" name="cmd" value="_xclick" />'; $html .= '<input type="hidden" name="amount" value="' . $this->_convertNumber($transaction->price) . '" />'; } if ($db_membership->activation == 2) { $transaction->status = 'completed'; } $uri = JUri::getInstance(); $base = $uri->toString(array('scheme', 'user', 'pass', 'host', 'port')); $return = $base . JRoute::_('index.php?option=com_rsmembership&task=thankyou', false); $html .= '<input type="hidden" name="notify_url" value="' . JRoute::_(JURI::root() . 'index.php?option=com_rsmembership&paypalpayment=1') . '" />'; $html .= '<input type="hidden" name="bn" value="RSJoomla_SP" />'; $html .= '<input type="hidden" name="custom" value="' . $this->escape($transaction->custom) . '" />'; $html .= '<input type="hidden" name="return" value="' . $this->escape($return) . '" />'; $html .= '<input type="hidden" name="rm" value="1" />'; if ($cancel = $this->params->get('cancel_return')) { $replace = array('{live_site}', '{membership_id}'); $with = array(JURI::root(), $membership->id); $cancel = str_replace($replace, $with, $cancel); $html .= '<input type="hidden" name="cancel_return" value="' . $cancel . '" />'; } $html .= '</form>'; $html .= '<script type="text/javascript">'; $html .= 'function paypalFormSubmit() { window.setTimeout(function() { document.getElementById(\'paypalForm\').submit() }, 5500); }'; $html .= 'try { window.addEventListener ? window.addEventListener("load",paypalFormSubmit,false) : window.attachEvent("onload",paypalFormSubmit); }'; $html .= 'catch (err) { paypalFormSubmit(); }'; $html .= '</script>'; return $html; }
public function getReportData($post_filters) { $db = JFactory::getDBO(); $query = $db->getQuery(true); $return = array(); $sql_filters = array(); $output = array(); $data = array(); $from_date = $post_filters['from_date']; $to_date = $post_filters['to_date']; $report = $post_filters['report']; $date_column = $report == 'report_2' || $report == 'report_3' ? 'date' : 'membership_start'; $memberships = isset($post_filters['memberships']) ? $post_filters['memberships'] : array(); JArrayHelper::toInteger($memberships, array()); if ($from_date || $to_date) { $start = !empty($from_date) ? JFactory::getDate($from_date)->toSql() : ''; // check if the to_date has the time attatched and remove it $to_date = trim(str_replace('00:00:00', '', $to_date)); // set the current date to the current date and time for catching data even the current day if ($to_date == JHtml::date('now', 'Y-m-d')) { $to_date = JHtml::date('now', 'Y-m-d H:i:s'); } $stop = JFactory::getDate($to_date)->toSql(); if ($start && $stop) { $query->where($db->qn($date_column) . ' >= ' . $db->q($start) . ' AND ' . $db->qn($date_column) . ' <= ' . $db->q($stop)); } elseif ($start) { $query->where($db->qn($date_column) . ' >= ' . $db->q($start)); } elseif ($stop) { $query->where($db->qn($date_column) . ' <= ' . $db->q($stop)); } } $unit = $post_filters['unit']; $format = 'Y-m-d'; if ($unit == 'day') { $format = 'Y-m-d'; } elseif ($unit == 'month') { $format = 'Y-m'; } elseif ($unit == 'year') { $format = 'Y'; } elseif ($unit == 'quarter') { $format = 'Y-m'; } $user_id = $post_filters['user_id']; if (!empty($user_id)) { $query->where($db->qn('user_id') . ' = ' . $db->q($user_id)); } if ($report == 'report_2' || $report == 'report_3') { $transaction_types = $post_filters['transaction_types']; if (!empty($transaction_types)) { $query->where($db->qn('type') . ' IN (\'' . implode($db->q(','), $transaction_types) . '\')'); } $gateways = isset($post_filters['gateways']) ? $post_filters['gateways'] : array(); if (!empty($gateways)) { $query->where($db->qn('gateway') . ' IN (\'' . implode($db->q(','), $gateways) . '\')'); } if (!empty($memberships) && !empty($transaction_types)) { $where_membership_id = "("; foreach ($memberships as $mem) { $where_membership_id .= $db->qn('params') . " LIKE " . $db->q("membership_id=" . $mem); $where_membership_id .= " OR " . $db->qn('params') . " LIKE " . $db->q("%;membership_id=" . $mem); $where_membership_id .= " OR " . $db->qn('params') . " LIKE " . $db->q("membership_id=" . $mem . ";%"); $where_membership_id .= " OR " . $db->qn('params') . " LIKE " . $db->q("%;membership_id=" . $mem . ";%"); $where_membership_id .= " OR " . $db->qn('params') . " LIKE " . $db->q("%;from_id=" . $mem . ";%"); $where_membership_id .= " OR " . $db->qn('params') . " LIKE " . $db->q("%;to_id=" . $mem . ""); if ($mem != end($memberships)) { $where_membership_id .= " OR "; } } $where_membership_id .= ")"; $query->where($where_membership_id); } $status = $post_filters['status_transactions']; if (!empty($status)) { $query->where($db->qn('status') . ' IN (\'' . implode($db->q(','), $status) . '\')'); } } else { if (!empty($memberships)) { $query->where($db->qn('membership_id') . ' IN (\'' . implode($db->q(','), $memberships) . '\')'); } $status = $post_filters['status_memberships']; if (!empty($status)) { $query->where($db->qn('status') . ' IN (\'' . implode($db->q(','), $status) . '\')'); } } if ($report == 'report_1' || $report == 'report_2') { $price_from = $post_filters['price_from']; if (!empty($price_from)) { $query->where($db->qn('price') . ' >= (' . $price_from . ') '); } $price_to = $post_filters['price_to']; if (!empty($price_to)) { $query->where($db->qn('price') . ' <= (' . $price_to . ') '); } } // ordering $query->order($db->qn($date_column) . ' ASC'); switch ($report) { case 'report_1': // query $query->select($db->qn('membership_id') . ', ' . $db->qn($date_column))->from($db->qn('#__rsmembership_membership_subscribers')); $db->setQuery($query); $subscribers = $db->loadObjectList(); $query->clear(); if (!empty($subscribers)) { foreach ($subscribers as $subscriber) { if ($unit == 'quarter') { $format = $this->getQuarter(JFactory::getDate($subscriber->membership_start)->toUnix()); } $date = RSMembershipHelper::showDate($subscriber->membership_start, $format); $membership = $this->getMembershipName($subscriber->membership_id); @($return['units'][$date] = $date); @($return['memberships'][$date][$membership] += 1); @($return['totals'][$date] += 1); } } if (!empty($return['totals'])) { foreach ($return['units'] as $date) { foreach ($memberships as $membership) { $membership = $this->getMembershipName($membership); if (empty($return['memberships'][$date][$membership])) { $return['memberships'][$date][$membership] = 0; } } } // Building the header data response foreach ($memberships as $mem) { $data[0][] = $this->getMembershipName($mem); } asort($data[0]); array_unshift($data[0], JText::_('COM_RSMEMBERSHIP_REPORTS_PERIOD')); foreach ($return['memberships'] as $return_date => $return_values) { ksort($return['memberships'][$return_date]); } // adding data values foreach ($return['memberships'] as $date => $memberships) { $membership_values = array_values($memberships); array_unshift($membership_values, $date); $data[] = $membership_values; } } $output['data'] = $data; $output['options'] = new stdClass(); $output['options']->title = JText::_('COM_RSMEMBERSHIP_REPORT_1'); $output['options']->hAxis = new stdClass(); $output['options']->hAxis->title = JText::_('COM_RSMEMBERSHIP_' . $unit); $output['options']->hAxis->titleTextStyle = "color: 'red'"; $output['options']->crosshair = new stdClass(); $output['options']->crosshair->trigger = 'both'; $output['options']->pointSize = '5'; break; case 'report_2': // query $query->select($db->qn('id') . ', ' . $db->qn('type') . ', ' . $db->qn('params') . ', ' . $db->qn($date_column))->from($db->qn('#__rsmembership_transactions')); $db->setQuery($query); $transactions = $db->loadObjectList(); $query->clear(); if (!empty($transactions)) { foreach ($transactions as $i => $transaction) { if ($unit == 'quarter') { $format = $this->getQuarter(JFactory::getDate($transaction->{$date_column})->toUnix()); } $date = RSMembershipHelper::showDate($transaction->{$date_column}, $format); @($return['units'][$date] = $date); @($return['transactions'][$date][JText::_('COM_RSMEMBERSHIP_TRANSACTION_' . strtoupper($transaction->type))] += 1); @($return['totals'][$date] += 1); } } if (!empty($return['totals'])) { foreach ($return['units'] as $date) { foreach ($transaction_types as $transaction) { if (empty($return['transactions'][$date][JText::_('COM_RSMEMBERSHIP_TRANSACTION_' . strtoupper($transaction))])) { $return['transactions'][$date][JText::_('COM_RSMEMBERSHIP_TRANSACTION_' . strtoupper($transaction))] = 0; } } } // Building the header data response foreach ($transaction_types as $trans) { $data[0][] = JText::_('COM_RSMEMBERSHIP_TRANSACTION_' . strtoupper($trans)); } asort($data[0]); array_unshift($data[0], JText::_('COM_RSMEMBERSHIP_REPORTS_PERIOD')); foreach ($return['transactions'] as $return_transaction => $return_values) { ksort($return['transactions'][$date]); } // adding data values foreach ($return['transactions'] as $date => $trans) { $transaction_values = array_values($trans); array_unshift($transaction_values, $date); $data[] = $transaction_values; } } $output['data'] = $data; $output['options'] = new stdClass(); $output['options']->title = JText::_('COM_RSMEMBERSHIP_REPORT_2'); $output['options']->hAxis = new stdClass(); $output['options']->hAxis->title = JText::_('COM_RSMEMBERSHIP_' . $unit); $output['options']->hAxis->titleTextStyle = "color: 'red'"; $output['options']->crosshair = new stdClass(); $output['options']->crosshair->trigger = 'both'; $output['options']->pointSize = '5'; break; case 'report_3': $query->select('SUM(' . $db->qn('t.price') . ') AS daysum')->select('DATE(' . $db->qn('t.date') . ') AS date')->select($db->qn('t.currency'))->select($db->qn('t.status'))->from($db->qn('#__rsmembership_transactions', 't')); $query->group(' DATE(' . $db->qn('t.date') . '), ' . $db->qn('t.status')); $db->setQuery($query); $sales = $db->loadObjectList(); $query->clear(); // getting the currency $currency = isset($sales[0]->currency) ? $sales[0]->currency : ''; $statuses = array(JText::_('COM_RSMEMBERSHIP_REPORTS_PERIOD')); $dates = array(); $amounts = array(); // get the statuses amount from the selected period and unit foreach ($sales as $sale) { $statuses[] = $sale->status; if ($unit == 'quarter') { $format = $this->getQuarter(JFactory::getDate($sale->date)->toUnix()); } $currentDate = RSMembershipHelper::showDate($sale->date, $format); if (!in_array($currentDate, $dates)) { $dates[] = RSMembershipHelper::showDate($sale->date, $format); } if ($unit == 'month' || $unit == 'year' || $unit == 'quarter') { if (isset($amounts[$currentDate][$sale->status])) { $amounts[$currentDate][$sale->status] += $sale->daysum; } else { $amounts[$currentDate][$sale->status] = $sale->daysum; } } else { $amounts[$currentDate][$sale->status] = $sale->daysum; } } $statuses = array_unique($statuses); // get the statuses names from the language file $name_statuses = $statuses; foreach ($name_statuses as $i => $status) { if ($i > 0) { $name_statuses[$i] = array('number' => JText::_('COM_RSMEMBERSHIP_TRANSACTION_STATUS_' . strtoupper($status))); } else { $name_statuses[$i] = array('string' => $status); } } // preparing the data for the output $totalIncome = array(); $countIncomes = array(); foreach ($dates as $date) { $entrance = array($date); foreach ($statuses as $i => $status) { if ($i > 0) { if (!isset($totalIncome[$status])) { $totalIncome[$status] = 0; } if (!isset($countIncomes[$status])) { $countIncomes[$status] = 0; } $entrance[] = isset($amounts[$date][$status]) ? (double) $amounts[$date][$status] : 0; $entrance[] = '<div style="padding:5px;"><strong>' . JText::_('COM_RSMEMBERSHIP_' . $unit) . ':</strong> ' . $date . '<br/><strong>' . JText::_('COM_RSMEMBERSHIP_AMOUNT') . ':</strong> ' . (isset($amounts[$date][$status]) ? (double) $amounts[$date][$status] : 0) . ' ' . $currency . '</div>'; $totalIncome[$status] += isset($amounts[$date][$status]) ? (double) $amounts[$date][$status] : 0; $countIncomes[$status]++; } } $data[] = $entrance; } $averageIncome = array(); foreach ($totalIncome as $key => $total) { $averageIncome[$key] = $countIncomes[$key] > 0 ? round($total / $countIncomes[$key], 2) : 0; } // building the output $new_columns = array(); foreach ($name_statuses as $i => $status) { if ($i > 0) { $new_columns[] = $status; $new_columns[] = array('type' => 'string', 'role' => 'tooltip'); } else { $new_columns[] = $status; } } $output['columns'] = $new_columns; $output['rows'] = array(); if (isset($data) && count($data) > 0) { foreach ($data as $entrance) { $output['rows'][] = $entrance; } } $output['options'] = new stdClass(); $output['options']->title = JText::_('COM_RSMEMBERSHIP_REPORT_3'); $output['options']->hAxis = new stdClass(); $output['options']->hAxis->title = JText::_('COM_RSMEMBERSHIP_' . $unit); $output['options']->hAxis->titleTextStyle = "color: 'red'"; $output['options']->crosshair = new stdClass(); $output['options']->crosshair->trigger = 'both'; $output['options']->pointSize = '5'; $output['options']->vAxis = new stdClass(); $output['options']->vAxis->format = '#,### ' . $currency; $output['options']->tooltip = new stdClass(); $output['options']->tooltip->isHtml = true; $output['info'] = new stdClass(); $output['info']->total = $totalIncome; $output['info']->average = $averageIncome; $output['info']->currency = $currency; break; } unset($return); return $output; }
/** * @package RSMembership! * @copyright (C) 2014 www.rsjoomla.com * @license GPL, http://www.gnu.org/licenses/gpl-2.0.html */ defined('_JEXEC') or die('Restricted access'); ?> <table class="rsmem_transaction_info_table"> <tr> <td width="200"><?php echo JText::_('COM_RSMEMBERSHIP_DATE'); ?> </td> <td><?php echo RSMembershipHelper::showDate($this->item->transaction_data->date); ?> </td> </tr> <tr> <td width="200"><?php echo JText::_('COM_RSMEMBERSHIP_TYPE'); ?> </td> <td><?php echo JText::_('COM_RSMEMBERSHIP_TRANSACTION_' . strtoupper($this->item->transaction_data->type)); ?> </td> </tr> <tr> <td width="200"><?php
public static function sendNotifications($memberships, $cid = null, $resend = false) { // Get custom fields $db = JFactory::getDBO(); $query = $db->getQuery(true); $date = JFactory::getDate(); $fields = RSMembership::getCustomFields(); $config = RSMembershipConfig::getInstance(); $update_ids = array(); foreach ($memberships as $membership) { $date = JFactory::getDate(); $interval = $membership->expire_notify_interval; $date->modify("+{$interval} days"); // Select all the subscriptions that match (about to expire) $query->clear(); $query->select($db->qn('u.id', 'user_id'))->select($db->qn('u.email', 'user_email'))->select($db->qn('u.name', 'user_name'))->select($db->qn('u.username', 'user_username'))->select($db->qn('mu.id', 'muid'))->select($db->qn('mu.extras'))->select($db->qn('mu.membership_end'))->select($db->qn('mu.from_transaction_id'))->from($db->qn('#__rsmembership_membership_subscribers', 'mu'))->join('left', $db->qn('#__users', 'u') . ' ON ' . $db->qn('mu.user_id') . ' = ' . $db->qn('u.id'))->where($db->qn('mu.status') . ' = ' . $db->q(MEMBERSHIP_STATUS_ACTIVE))->where($db->qn('mu.published') . ' = ' . $db->q(1)); if (!$resend) { $query->where($db->qn('mu.notified') . ' = ' . $db->q($db->getNullDate())); } $query->where($db->qn('mu.membership_end') . ' != ' . $db->q($db->getNulldate()))->where($db->qn('mu.membership_end') . ' < ' . $db->q($date->toSql()))->where($db->qn('mu.membership_id') . ' = ' . $db->q($membership->id)); if ($cid != null && is_array($cid) && count($cid) > 0) { $ids = implode($db->q(','), $cid); $query->where($db->qn('mu.id') . ' IN (' . $ids . ')'); } $db->setQuery($query, 0, $config->get('expire_emails')); $results = $db->loadObjectList(); // No results, next membership if (empty($results)) { continue; } $now = JFactory::getDate()->toUnix(); $sentToUser = false; $sentToAdmin = false; foreach ($results as $result) { $extras = ''; // Performance check if ($result->extras && (strpos($membership->user_email_expire_text . $membership->user_email_expire_subject, '{extras}') !== false || strpos($membership->admin_email_expire_text . $membership->admin_email_expire_subject, '{extras}') !== false)) { $extras = RSMembershipHelper::getExtrasNames($result->extras); } $expireDate = JFactory::getDate($result->membership_end); $expireIn = ceil(($expireDate->toUnix() - $now) / 86400); $placeholders = array('{membership}' => $membership->name, '{membership_end}' => RSMembershipHelper::showDate($result->membership_end), '{extras}' => $extras, '{email}' => $result->user_email, '{name}' => $result->user_name, '{username}' => $result->user_username, '{interval}' => $expireIn); $replace = array_keys($placeholders); $with = array_values($placeholders); $query->clear(); $query->select('*')->from($db->qn('#__rsmembership_subscribers'))->where($db->qn('user_id') . ' = ' . $db->q($result->user_id)); $db->setQuery($query); $user_data_tmp = $db->loadObject(); $user_data = array(); foreach ($fields as $field) { $field_id = 'f' . $field->id; $user_data[$field->name] = isset($user_data_tmp->{$field_id}) ? $user_data_tmp->{$field_id} : ''; } unset($user_data_tmp); foreach ($fields as $field) { $name = $field->name; $replace[] = '{' . $name . '}'; if (isset($user_data[$name])) { $with[] = is_array($user_data[$name]) ? implode("\n", $user_data[$name]) : $user_data[$name]; } else { $with[] = ''; } } $membership_fields = RSMembership::getCustomMembershipFields($membership->id); $transaction_user_data = RSMembership::getUserData($result->from_transaction_id); foreach ($membership_fields as $field) { $name = $field->name; $replace[] = '{' . $name . '}'; if (isset($transaction_user_data->membership_fields[$name])) { $with[] = is_array($transaction_user_data->membership_fields[$name]) ? implode("\n", $transaction_user_data->membership_fields[$name]) : $transaction_user_data->membership_fields[$name]; } else { $with[] = ''; } } $jconfig = JFactory::getConfig(); if ($membership->user_email_expire_subject) { $message = str_replace($replace, $with, $membership->user_email_expire_text); // from address $from = $membership->user_email_use_global ? $jconfig->get('mailfrom') : $membership->user_email_from_addr; // from name $fromName = $membership->user_email_use_global ? $jconfig->get('fromname') : $membership->user_email_from; // recipient $recipient = $result->user_email; // user email // subject $subject = str_replace($replace, $with, $membership->user_email_expire_subject); // body $body = $message; // mode $mode = $membership->user_email_mode; // cc $cc = null; // bcc $bcc = null; // attachments $query->clear(); $query->select($db->qn('path'))->from($db->qn('#__rsmembership_membership_attachments'))->where($db->qn('membership_id') . ' = ' . $db->q($membership->id))->where($db->qn('email_type') . ' = ' . $db->q('user_email_expire'))->where($db->qn('published') . '=' . $db->q('1'))->order($db->qn('ordering') . ' ASC'); $db->setQuery($query); $attachment = $db->loadColumn(); // reply to $replyto = $from; // reply to name $replytoname = $fromName; // send to user RSMembershipHelper::sendMail($from, $fromName, $recipient, $subject, $body, $mode, $cc, $bcc, $attachment, $replyto, $replytoname); $sentToUser = true; self::syslog('expiry-notification', "Membership: " . $membership->name . " (" . $membership->id . ") | Email sent to {$recipient} (Subject: {$subject})"); } // admin emails if ($membership->admin_email_expire_subject) { $message = str_replace($replace, $with, $membership->admin_email_expire_text); // from address $from = trim($membership->admin_email_from_addr) != '' ? $membership->admin_email_from_addr : $result->user_email; // from name $fromName = $result->user_name; // recipient $recipient = $membership->admin_email_to_addr; // subject $subject = str_replace($replace, $with, $membership->admin_email_expire_subject); // body $body = $message; // mode $mode = $membership->admin_email_mode; // cc $cc = null; // bcc $bcc = null; // attachments $attachment = null; // reply to $replyto = $from; // reply to name $replytoname = $fromName; // send to admin if ($subject != '') { RSMembershipHelper::sendMail($from, $fromName, $recipient, $subject, $body, $mode, $cc, $bcc, $attachment, $replyto, $replytoname); $sentToAdmin = true; self::syslog('expiry-notification', "Membership: " . $membership->name . " (" . $membership->id . ") | Admin email sent to {$recipient} (Subject: {$subject})"); } } if ($sentToUser || $sentToAdmin) { $update_ids[] = $result->muid; } } } if (!empty($update_ids)) { $query->clear(); $query->update($db->qn('#__rsmembership_membership_subscribers'))->set($db->qn('notified') . ' = ' . $db->q($date->toSql()))->where($db->qn('id') . ' IN (\'' . implode($db->q(','), $update_ids) . '\')'); $db->setQuery($query); $db->execute(); return true; } else { return false; } }
<span class="pull-left rsme_faded"><?php echo JText::_('COM_RSMEMBERSHIP_MEMBERSHIP_START'); ?> : </span> <strong><?php echo RSMembershipHelper::showDate($this->membership->membership_start); ?> </strong> </div> <div class="span6 pull-left"> <span class="pull-left rsme_faded"><?php echo JText::_('COM_RSMEMBERSHIP_MEMBERSHIP_END'); ?> : </span> <strong><?php echo $this->membership->membership_end != '0000-00-00 00:00:00' ? RSMembershipHelper::showDate($this->membership->membership_end) : JText::_('COM_RSMEMBERSHIP_UNLIMITED'); ?> </strong> </div> </div> <?php } ?> <!-- Membership Renew --> <div class="row-fluid"> <?php if (!$this->membership->no_renew) { ?> <div class="pull-left span6"> <span class="rsme_faded rsme_vcenter"><?php echo JText::_('COM_RSMEMBERSHIP_RENEW');
echo RSMembershipHelper::showDate($row->date_added); ?> </td> <td><a href="<?php echo JRoute::_('index.php?option=com_rsmembership&task=coupon.edit&id=' . $row->id); ?> "><?php echo $row->name != '' ? $this->escape($row->name) : JText::_('COM_RSMEMBERSHIP_NO_TITLE'); ?> </a></td> <td nowrap="nowrap"><?php echo $row->date_start != '0000-00-00 00:00:00' ? RSMembershipHelper::showDate($row->date_start) : '-'; ?> </td> <td nowrap="nowrap"><?php echo $row->date_end != '0000-00-00 00:00:00' ? RSMembershipHelper::showDate($row->date_end) : '-'; ?> </td> <td><?php echo $row->discount_type ? RSMembershipHelper::getPriceFormat($this->escape($row->discount_price)) : $this->escape($row->discount_price) . '%'; ?> </td> <td width="1%" nowrap="nowrap" align="center"><?php echo JHtml::_('jgrid.published', $row->published, $i, 'coupons.'); ?> </td> </tr> <?php $k = 1 - $k; } ?>