Current File : /home/pacjaorg/public_html/km/administrator/components/com_djclassifieds/controllers/payments.php |
<?php
/**
* @package DJ-Classifieds
* @copyright Copyright (C) DJ-Extensions.com, All rights reserved.
* @license http://www.gnu.org/licenses GNU/GPL
* @author url: http://dj-extensions.com
* @author email: contact@dj-extensions.com
*/
defined('_JEXEC') or die;
class DJClassifiedsControllerPayments extends JControllerAdmin
{
function changeStatus()
{
$app = JFactory::getApplication();
$ids = $app->input->get('cid');
if(!empty($ids[0])){
$id = $ids[0];
$status = $app->input->get('change_status_'.$id);
}else{
$app->enqueueMessage(JText::_('COM_DJCLASSIFIEDS_WRONG_PAYMENT'), 'error');
$app->redirect('index.php?option=com_djclassifieds&view=payments');
}
JTable::addIncludePath(JPATH_ADMINISTRATOR.'/components/com_djclassifieds/tables');
$row = JTable::getInstance('Payments', 'DJClassifiedsTable');
$row->load($id);
$row->status = $status;
$row->store();
$app->triggerEvent('onAfterPaymentStatusChange', array($row));
$app->enqueueMessage(JText::_('COM_DJCLASSIFIEDS_PAYMENT_STATUS_CHANGED'), 'success');
$app->redirect('index.php?option=com_djclassifieds&view=payments');
}
function complete()
{
$app = JFactory::getApplication();
$ids = $app->input->get('cid');
$item_id = $app->input->getInt('item_id');
if(!empty($ids[0])){
$id = $ids[0];
}else{
$app->enqueueMessage(JText::_('COM_DJCLASSIFIEDS_WRONG_PAYMENT'), 'error');
$app->redirect('index.php?option=com_djclassifieds&view=payments');
}
JTable::addIncludePath(JPATH_ADMINISTRATOR.'/components/com_djclassifieds/tables');
$row = JTable::getInstance('Payments', 'DJClassifiedsTable');
$row->load($id);
DJClassifiedsPayment::completePayment($id, $row->price);
$app->enqueueMessage(JText::_('COM_DJCLASSIFIEDS_PAYMENT_COMPLETED'), 'success');
if($row->type == '0' && !DJClassifiedsPayment::isPayTypePromsOnly($row->type_details)){
$item_row = JTable::getInstance('Items', 'DJClassifiedsTable');
$item_row->load($row->item_id);
if($item_row->published){
$app->enqueueMessage(JText::_('COM_DJCLASSIFIEDS_STATUS_CHANGED_ADVERT_PUBLISHED'), 'success');
}
}elseif($row->type == '1'){
$app->enqueueMessage(JText::_('COM_DJCLASSIFIEDS_STATUS_CHANGED_POINTS_PACKAGE_ADDED'), 'success');
}elseif($row->type == '2'){
$app->enqueueMessage(JText::_('COM_DJCLASSIFIEDS_STATUS_CHANGED_PROMOTION_MOVE_TO_TOP_ACTIVATED'), 'success');
}elseif($row->type == '3'){
$app->enqueueMessage(JText::_('COM_DJCLASSIFIEDS_STATUS_CHANGED_SUBSCRIPTION_PLAN_ADDED'), 'success');
}
if($item_id){ // call from the item page
$redirect = 'index.php?option=com_djclassifieds&view=item&layout=edit&id='.$item_id;
}else{
$redirect = 'index.php?option=com_djclassifieds&view=payments';
}
$app->redirect($redirect);
}
function delete()
{
$app = JFactory::getApplication();
$db = JFactory::getDBO();
$cid = $app->input->get('cid');
if($cid){
$cids = implode(',', $cid);
$query = "DELETE FROM #__djcf_payments WHERE id IN ( ".$cids." )";
$db->setQuery($query);
$db->execute();
}
$app->enqueueMessage(JText::_('COM_DJCLASSIFIEDS_N_ITEMS_DELETED'), 'success');
$app->redirect('index.php?option=com_djclassifieds&view=payments');
}
public function export()
{
$app = JFactory::getApplication();
$db = JFactory::getDBO();
$cid = $app->input->get('cid', array(), 'array');
/*
while (ob_get_level() > 0) // removing page's html content
{
ob_end_clean();
}
*/
$query = $db->getQuery(true);
$query->select(array('p.id payment_id','p.item_id', 'p.user_id', 'REPLACE(p.method, "djcf", "") method', 'p.date', 'p.status', 'p.price'))
->from('#__djcf_payments p');
if($cid){
$query->where('p.id IN ('.implode(',',$cid).')');
}
$app->triggerEvent('onDJClassifiedsAdminExportPaymentsQuery', array(&$query));
$db->setQuery($query);
$payments = $db->loadObjectList();
$array = array_map(function($i){return (array)$i;}, $payments);
$filename = 'payments_'.urlencode(JFactory::getDate()->toSQL()).".csv";
$delimiter = ";";
//ob_start();
header('Content-Type: application/csv');
header('Content-Disposition: attachment; filename="'.$filename.'";');
$f = fopen('php://output', 'w');
foreach($array as $key => $line){
if(!$key){
fputcsv($f, array_keys($line), $delimiter);
}
fputcsv($f, $line, $delimiter);
}
fclose($f);
// ob_end_clean();
$app->close();
}
}