Example #1
0
 /**
  * Display the view.
  *
  * @param   string  $tpl  The name of the template file to parse; automatically searches through the template paths.
  *
  * @return  mixed  A string if successful, otherwise a Error object.
  *
  * @since   1.0.0
  */
 public function display($tpl = null)
 {
     $jinput = JFactory::getApplication()->input;
     $campaignId = $jinput->get('campaign', 0, 'integer');
     $campaigns = JModelLegacy::getInstance('Campaigns', 'CMDonationModel')->getCampaignsForFilter();
     $campaignList = array();
     $campaign = array();
     if (!empty($campaigns)) {
         foreach ($campaigns as $camp) {
             $campaignList[$camp->id] = htmlspecialchars($camp->name);
             if ($camp->id == $campaignId) {
                 $campaign = $camp;
             }
         }
     }
     $statistics = array();
     if (!empty($campaign)) {
         $statistics = CMDonationHelper::generateStatistics($campaignId);
     }
     $params = JComponentHelper::getParams('com_cmdonation');
     // Get payment methods.
     $paymentMethods = CMDonationHelper::getPaymentMethods();
     $this->assignRef('paymentMethods', $paymentMethods);
     $this->assignRef('params', $params);
     $this->assignRef('campaignList', $campaignList);
     $this->assignRef('campaignId', $campaignId);
     $this->assignRef('campaign', $campaign);
     $this->assignRef('statistics', $statistics);
     $this->submenu = CMDonationHelper::addSubmenu('statistics');
     $this->addToolbar($campaign, $statistics);
     parent::display($tpl);
 }
Example #2
0
 /**
  * Add the page title and toolbar.
  *
  * @return  void
  *
  * @since   1.0.0
  */
 protected function addToolbar()
 {
     JFactory::getApplication()->input->set('hidemainmenu', true);
     $user = JFactory::getUser();
     $isNew = $this->item->id == 0;
     $checkedOut = !($this->item->checked_out == 0 || $this->item->checked_out == $user->get('id'));
     $canDo = CMDonationHelper::getActions();
     JToolbarHelper::title(JText::_('COM_CMDONATION_MANAGER_DONATIONS'), 'donation icon-heart-2');
     // If not checked out, can save the item.
     if (!$checkedOut && ($canDo->get('core.edit') || $canDo->get('core.create'))) {
         JToolbarHelper::apply('donation.apply');
         JToolbarHelper::save('donation.save');
     }
     if (!$checkedOut && $canDo->get('core.create')) {
         JToolbarHelper::save2new('donation.save2new');
     }
     // If an existing item, can save to a copy.
     if (!$isNew && $canDo->get('core.create')) {
         JToolbarHelper::save2copy('donation.save2copy');
     }
     if (empty($this->item->id)) {
         JToolbarHelper::cancel('donation.cancel');
     } else {
         JToolbarHelper::cancel('donation.cancel', 'JTOOLBAR_CLOSE');
     }
 }
Example #3
0
 /**
  * Add the page title and toolbar.
  *
  * @return  void
  *
  * @since   1.0.0
  */
 protected function addToolbar()
 {
     $canDo = CMDonationHelper::getActions();
     JToolbarHelper::title(JText::_('COM_CMDONATION_MANAGER_DASHBOARD'), 'dashboard.png');
     if ($canDo->get('core.admin')) {
         JToolbarHelper::preferences('com_cmdonation');
     }
 }
Example #4
0
 /**
  * Function to export donor list to CSV.
  *
  * @return  void
  *
  * @since   1.0.0
  */
 public function export_donors()
 {
     $app = JFactory::getApplication();
     $params = JComponentHelper::getParams('com_cmdonation');
     $campaignId = $app->input->get('campaign', 0, 'integer');
     // Make sure campaign exists.
     $campaign = JModelAdmin::getInstance('Campaign', 'CMDonationModel')->getItem($campaignId);
     if (empty($campaign)) {
         $app->enqueueMessage(JText::_('COM_CMDONATION_CAMPAIGN_NOT_FOUND'), 'error');
         $app->redirect(JRoute::_('index.php?option=com_cmdonation'));
     }
     // Get campaign's donations.
     $donations = JModelAdmin::getInstance('Donations', 'CMDonationModel')->getDonationsForCSV($campaignId);
     $data = array(array(JText::_('COM_CMDONATION_DONATION_FIRST_NAME_LABEL'), JText::_('COM_CMDONATION_DONATION_LAST_NAME_LABEL'), JText::_('COM_CMDONATION_DONATION_EMAIL_LABEL'), JText::_('COM_CMDONATION_DONATION_COUNTRY_LABEL'), JText::_('COM_CMDONATION_DONATION_AMOUNT_LABEL'), JText::_('COM_CMDONATION_DONATION_COMPLETED_LABEL'), JText::_('COM_CMDONATION_DONATION_PAYMENT_METHOD_LABEL')));
     if (!empty($donations)) {
         include JPATH_ROOT . '/administrator/components/com_cmdonation/helpers/countries.php';
         $currencySign = $params->get('currency_sign');
         $currencySignPosition = $params->get('currency_sign_position');
         $decimals = $params->get('decimals');
         $decimalPoint = $params->get('decimal_point');
         $thousandSeparator = $params->get('thousand_separator');
         foreach ($donations as $donation) {
             if (array_key_exists($donation->country_code, $countryList)) {
                 $countryName = JText::_($countryList[$donation->country_code]);
             } else {
                 $countryName = '';
             }
             $amount = CMDonationHelper::showDonationAmount($donation->amount, $currencySign, $currencySignPosition, $decimals, $decimalPoint, $thousandSeparator, false);
             $paymentMethod = CMDonationHelper::displayPaymentMethodName($donation->payment_method_id);
             $data[] = array($donation->first_name, $donation->last_name, $donation->email, $countryName, $amount, $donation->completed, $paymentMethod);
         }
     }
     $delimiter = $params->get('csv_delimiter_character', ',');
     $enclosure = $params->get('csv_enclosure_character', 'double');
     if ($enclosure == 'double') {
         $enclosure = '"';
     } else {
         $enclosure = "'";
     }
     $filename = JApplication::stringURLSafe($campaign->name);
     if ($filename == '') {
         $filename = JFactory::getDate()->format("Y-m-d-H-i-s");
     }
     $filename .= '.csv';
     header("Content-type: text/csv");
     header("Content-Disposition: attachment; filename={$filename}");
     header("Pragma: no-cache");
     header("Expires: 0");
     $output = fopen("php://output", "w");
     foreach ($data as $row) {
         fputcsv($output, $row, $delimiter, $enclosure);
     }
     fclose($output);
     JFactory::getApplication()->close();
 }
Example #5
0
 /**
  * Add the page title and toolbar.
  *
  * @return  void
  *
  * @since   1.0.0
  */
 protected function addToolbar()
 {
     $state = $this->get('State');
     $canDo = CMDonationHelper::getActions();
     JToolbarHelper::title(JText::_('COM_CMDONATION_MANAGER_DONATIONS'), 'donation icon-heart-2');
     if ($canDo->get('core.create')) {
         JToolbarHelper::addNew('donation.add');
     }
     if ($canDo->get('core.edit')) {
         JToolbarHelper::editList('donation.edit');
     }
     if ($canDo->get('core.edit.state')) {
         JToolbarHelper::checkin('donations.checkin');
     }
     if ($canDo->get('core.delete')) {
         JToolBarHelper::deleteList(JText::_('COM_CMDONATION_WARNING_DELETE_ITEMS'), 'donations.delete');
     }
 }
 /**
  * Method to get the field input for a list of content types.
  *
  * @return  string  The field input.
  *
  * @since   1.0.0
  */
 protected function getInput()
 {
     // Initialize some field attributes.
     $size = $this->element['size'] ? ' size="' . (int) $this->element['size'] . '"' : '';
     $maxLength = $this->element['maxlength'] ? ' maxlength="' . (int) $this->element['maxlength'] . '"' : '';
     $class = $this->element['class'] ? ' class="' . (string) $this->element['class'] . '"' : '';
     $readonly = (string) $this->element['readonly'] == 'true' ? ' readonly="readonly"' : '';
     $disabled = (string) $this->element['disabled'] == 'true' ? ' disabled="disabled"' : '';
     $required = $this->required ? ' required="required" aria-required="true"' : '';
     // Initialize JavaScript field attributes.
     $onchange = $this->element['onchange'] ? ' onchange="' . (string) $this->element['onchange'] . '"' : '';
     $input = '<input type="text" name="' . $this->name . '" id="' . $this->id . '" value="' . htmlspecialchars($this->value, ENT_COMPAT, 'UTF-8') . '"' . $class . $size . $disabled . $readonly . $onchange . $maxLength . $required . '/>';
     $instruction = '<p></p><p>' . JText::_('COM_CMDONATION_PAYMENT_METHOD_INSTRUCTION_ENTER');
     $instruction .= '<ul>';
     $paymentMethods = CMDonationHelper::getPaymentMethods();
     if (!empty($paymentMethods)) {
         foreach ($paymentMethods as $method) {
             $instruction .= '<li>' . JText::sprintf('COM_CMDONATION_PAYMENT_METHOD_INSTRUCTION_FOR', $method->name, $method->title) . '</li>';
         }
     }
     $instruction .= '<li>' . JText::_('COM_CMDONATION_PAYMENT_METHOD_INSTRUCTION_CUSTOM') . '</li>';
     $instruction .= '</ul></p>';
     return $input . $instruction;
 }
 /**
  * Genarate top country's HTML.
  *
  * @param   integer  $campaignId  Campaign ID.
  * @param   integer  $limit       Number of donations.
  *
  * @return  string   HTML.
  *
  * @since   1.0.0
  */
 function buildTopCountryTable($campaignId, $limit = 10)
 {
     if ($limit <= 0) {
         $limit = 10;
     }
     // Component settings.
     $params = JComponentHelper::getParams('com_cmdonation');
     $countryDisplay = $params->get('country_list_country', 'both');
     $contributionColumn = $params->get('contribution_column', '1');
     $lowestColumn = $params->get('lowest_column', '1');
     $averageColumn = $params->get('average_column', '1');
     $highestColumn = $params->get('highest_column', '1');
     $currencySign = $params->get('currency_sign', '');
     $currencySignPosition = $params->get('currency_sign_position', 'before');
     $decimals = $params->get('decimals', '2');
     $decimalPoint = $params->get('decimal_point', ',');
     $thousandSeparator = $params->get('thousand_separator', '.');
     $rowNumberColumn = $params->get('row_number_column', '1');
     $result = CMDonationHelper::generateCountryStatistics($campaignId, $params);
     $countries = $result['countries'];
     @ob_start();
     include $this->layoutPath . 'top_countries.php';
     $html = @ob_get_clean();
     return $html;
 }
Example #8
0
				<td class="pure-text-center"><?php 
            echo CMDonationHelper::showCountryName($donor->country_code);
            ?>
				<td class="pure-text-center"><?php 
            echo CMDonationHelper::showCountryFlag($donor->country_code);
            ?>
				<?php 
        }
        ?>
				<td class="pure-text-center"><?php 
        echo $donor->donation_quantity;
        ?>
</td>
				<td class="pure-text-center">
					<?php 
        echo CMDonationHelper::showDonationAmount($donor->amount, $currencySign, $currencySignPosition, $decimals, $decimalPoint, $thousandSeparator);
        ?>
				</td>
			</tr>
			<?php 
    }
    ?>
		</tbody>
	</table>
<?php 
} else {
    ?>
	<div class="text-error"><?php 
    echo JText::_('COM_CMDONATION_NO_DONATIONS');
    ?>
</div>
Example #9
0
        echo CMDonationHelper::showCountryFlag($item->country_code);
        ?>
						</td>
						<?php 
    }
    ?>
						<td class="nowrap pure-text-center pure-hidden-phone">
							<?php 
    if ($item->anonymous) {
        echo '<i class="fa fa-check"></i>';
    }
    ?>
						</td>
						<td class="nowrap pure-text-center pure-hidden-phone">
							<?php 
    echo CMDonationHelper::displayPaymentMethodName($item->payment_method_id, $paymentMethods);
    ?>
						</td>
						<td class="nowrap pure-text-center pure-hidden-phone">
							<?php 
    echo JHtml::_('date', $item->created, $dateFormat);
    ?>
						</td>
					</tr>
					<?php 
}
?>
				</tbody>
			</table>

			<input type="hidden" name="task" value="" />
Example #10
0
 /**
  * Method to receive donation amount and take user to payment service's donation page.
  *
  * @return  void
  *
  * @since   1.0.0
  */
 public function submit()
 {
     $app = JFactory::getApplication();
     $jinput = $app->input;
     $amount = $jinput->post->get('amount', 0, 'float');
     $anonymous = $jinput->post->get('anonymous', false, 'boolean');
     $campaignId = $jinput->post->get('campaign_id', 0, 'integer');
     $paymentMethodName = $jinput->post->get('payment_method', '', 'word');
     $returnUrlBase64 = $jinput->post->get('return_url', '', 'base64 ');
     $recurring = $jinput->post->get('recurring', false, 'boolean');
     $recurringCycle = $jinput->post->get('recurring_cycle', '', 'word');
     // Convert return URL.
     if (empty($returnUrlBase64)) {
         $returnUrl = JRoute::_('index.php', false);
         $returnUrlBase64 = base64_encode($returnUrl);
     } else {
         $returnUrl = JRoute::_(base64_decode($returnUrlBase64), false);
     }
     // Validate data.
     // Check for valid amount.
     if ($amount <= 0) {
         $app->enqueueMessage(JText::_('COM_CMDONATION_ERROR_INVALID_AMOUNT'), 'error');
         $app->redirect($returnUrl);
     }
     // Check for campaign's existence.
     $campaign = JModelLegacy::getInstance('Campaign', 'CMDonationModel')->getCampaignById($campaignId);
     if (!isset($campaign->id)) {
         $app->enqueueMessage(JText::_('COM_CMDONATION_ERROR_INVALID_CAMPAIGN'), 'error');
         $app->redirect($returnUrl);
     }
     // Check if payment method exist
     $paymentMethod = CMDonationHelper::getPaymentMethodById($paymentMethodName);
     if (!isset($paymentMethod->name) || empty($paymentMethod->name)) {
         $app->enqueueMessage(JText::_('COM_CMDONATION_ERROR_NO_PAYMENT_METHODS_SELECTED'), 'error');
         $app->redirect($returnUrl);
     }
     $params = JComponentHelper::getParams('com_cmdonation');
     $isRecurringEnabled = $params->get('recurring_donation', false, 'boolean');
     $supportedRecurringCycles = $params->get('recurring_cycles', array(), 'array');
     if ($recurring) {
         if (!$isRecurringEnabled || count($supportedRecurringCycles) == 0) {
             $app->enqueueMessage(JText::_('COM_CMDONATION_ERROR_RECURRING_DISABLED'), 'error');
             $app->redirect($returnUrl);
         }
         if (count($supportedRecurringCycles) == 1) {
             $recurringCycle = $supportedRecurringCycles[0];
         } elseif (count($supportedRecurringCycles) > 1) {
             if (!in_array($recurringCycle, $supportedRecurringCycles)) {
                 $app->enqueueMessage(JText::_('COM_CMDONATION_ERROR_SELECT_RECURRING_CYCLE'), 'error');
                 $app->redirect($returnUrl);
             }
         }
     }
     // Save donation to database.
     $date = JFactory::getDate();
     $data = array('campaign_id' => $campaignId, 'anonymous' => (string) $anonymous, 'amount' => $amount, 'payment_method_id' => $paymentMethodName, 'status' => 'INCOMPLETE', 'created' => $date->toSql(), 'recurring' => $recurring, 'recurring_cycle' => $recurringCycle, 'first_donation_id' => 0);
     $donationModel = JModelLegacy::getInstance('Donation', 'CMDonationModel');
     $donationId = $donationModel->saveNewDonation($data);
     // Save donation ID in session to use in Thank You and Cancel page.
     $session = JFactory::getSession();
     $donations = $session->get('donations', array(), 'CMDonation');
     $donations[$donationId] = $donationId;
     $session->set('donations', $donations, 'CMDonation');
     // Everything is ok now. Set variables and display the view.
     $data = new StdClass();
     $data->payment_method = $paymentMethodName;
     $data->amount = $amount;
     $data->campaign_name = $campaign->name;
     $data->donation_id = $donationId;
     $data->recurring = $recurring;
     $data->recurring_cycle = $recurringCycle;
     $data->return_url = $returnUrl;
     $data->return_url_64 = $returnUrlBase64;
     $this->data = $data;
     $this->display(false, array());
 }