busby1
6th August 2007, 11:15 AM
This will add a button next to your apply filter button in the Affiliate transaction view within the control panel.
When clicked, will activate a CSV down load of the current filter settings
Create a file named csv_report.php containing:
<?header("Expires: 0");
header("Cache-control: private");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-Description: File Transfer");
header("Content-Type: application/vnd.ms-excel");
header("Content-disposition: attachment; filename=transaction_report.csv");
include_once('global.php');
$page = QUnit_Global::newobj('QUnit_UI_MainPage');
$page->setDefaultView('MainPage');
$page->user_type = USERTYPE_USER;
$page->setFilePrefix('Affiliate_Affiliates_Views_');
$page->process();?>
up load this file to /affiliates
Next:
Find the file:
/templates/affiliate/yourskin/re_trans_filter.tpl.php
Find the line:
<input type="submit" class="formbutton" value="<?=L_G_APPLYFILTER?>">
and replace with:
<input type="button" class="formbutton" value="<?=L_G_APPLYFILTER?>" onclick="document.getElementById('reporttype').value='trans actions';document.forms[0].action='index.php';document.forms[0].submit();"> <input type="button" class="formbutton" value="Download CSV" onclick="document.getElementById('reporttype').value='csv'; document.forms[0].action='csv_report.php';document.forms[0].submit();">
Next:
find file:
/include/Affiliate/Affiliates/Views/AffReports.class.php
Find the line:
case 'subid':
if($this->showReportSubId())
return;
break;
}
}
}
Replace with:
case 'subid':
if($this->showReportSubId())
return;
break;
case 'csv':
if($this->showReportTransactionsCSV())
return;
break;
}
}
}
//------------------------------------------------------------------------
function showReportTransactionsCSV()
{
$this->navigationAddURL(L_G_TRANSACTIONS,'index.php?md=Af filiate_Affiliates_Views_AffReports&reporttype=transactions');
$this->getCampaignsForFilter();
$panel_settings = QUnit_Global::newObj('Affiliate_Affiliates_Views_A ffPanelSettings');
$this->assign('a_description', L_G_AFF_TRANSACTION_DESCRIPTION);
$this->assign('a_panel_settings', $panel_settings->loadPanelSettings('transactions'));
$this->addContent('section_descriptions');
$this->assign('a_form_preffix', 'rq_');
$this->assign('a_form_name', 'FilterForm');
$this->assign('a_filterColumns', array('t.orderid' => L_G_ORDERID,
't.data1' => L_G_DATA1,
't.data2' => L_G_DATA2,
't.data3' => L_G_DATA3,));
if ($_REQUEST['commited'] != 'yes') {
//--------------------------------------
// try to load settings from session
foreach($_SESSION as $k => $v)
{
if(strstr($k, 'rq_status') !== false && ($_REQUEST['status_comitted'] == '1')) {
continue;
}
if(strstr($k, 'rq_transtype') !== false && ($_REQUEST['transtype_comitted'] == '1')) {
continue;
}
if(strpos($k, 'rq_') === 0 && $_REQUEST[$k] == '')
$_REQUEST[$k] = $v;
if($k == 'numrows' && $_REQUEST[$k] == '')
$_REQUEST[$k] = $v;
}
}
//--------------------------------------
// get default settings for unset variables
if(empty($_REQUEST['numrows'])) $_REQUEST['numrows'] = 20;
if($_REQUEST['rq_campaign'] == '') $_REQUEST['rq_campaign'] = '_';
if($_REQUEST['rq_transtype'] == '') $_REQUEST['rq_transtype'] = $GLOBALS['Auth']->getAllowedCommissionTypes();
if($_REQUEST['rq_status'] == '') $_REQUEST['rq_status'] = '_';
if($_REQUEST['rq_reporttype'] == '') $_REQUEST['rq_reporttype'] = 'today';
if($_REQUEST['rq_day1'] == '') $_REQUEST['rq_day1'] = date("j");
if($_REQUEST['rq_month1'] == '') $_REQUEST['rq_month1'] = date("n");
if($_REQUEST['rq_year1'] == '') $_REQUEST['rq_year1'] = date("Y");
if($_REQUEST['rq_day2'] == '') $_REQUEST['rq_day2'] = date("j");
if($_REQUEST['rq_month2'] == '') $_REQUEST['rq_month2'] = date("n");
if($_REQUEST['rq_year2'] == '') $_REQUEST['rq_year2'] = date("Y");
if($_REQUEST['rq_timeselect'] == '') $_REQUEST['rq_timeselect'] = TIME_PRESET;
if($_REQUEST['rq_timepreset'] == '') $_REQUEST['rq_timepreset'] = TIME_TODAY;
//--------------------------------------
// put settings into session
$_SESSION['numrows'] = $_REQUEST['numrows'];
$_SESSION['rq_campaign'] = $_REQUEST['rq_campaign'];
$_SESSION['rq_transtype'] = $_REQUEST['rq_transtype'];
$_SESSION['rq_status'] = $_REQUEST['rq_status'];
$_SESSION['rq_reporttype'] = $_REQUEST['rq_reporttype'];
$_SESSION['rq_day1'] = $_REQUEST['rq_day1'];
$_SESSION['rq_month1'] = $_REQUEST['rq_month1'];
$_SESSION['rq_year1'] = $_REQUEST['rq_year1'];
$_SESSION['rq_day2'] = $_REQUEST['rq_day2'];
$_SESSION['rq_month2'] = $_REQUEST['rq_month2'];
$_SESSION['rq_year2'] = $_REQUEST['rq_year2'];
$_SESSION['rq_custom1'] = $_REQUEST['rq_custom1'];
$_SESSION['rq_custom2'] = $_REQUEST['rq_custom2'];
$_SESSION['rq_custom3'] = $_REQUEST['rq_custom3'];
$_SESSION['rq_custom1data'] = $_REQUEST['rq_custom1data'];
$_SESSION['rq_custom2data'] = $_REQUEST['rq_custom2data'];
$_SESSION['rq_custom3data'] = $_REQUEST['rq_custom3data'];
$_SESSION['rq_timeselect'] = $_REQUEST['rq_timeselect'];
$_SESSION['rq_timepreset'] = $_REQUEST['rq_timepreset'];
// process time filter
if($_REQUEST['rq_timeselect'] == TIME_PRESET) {
$_REQUEST = array_merge($_REQUEST, getTimerangeForPreset($_REQUEST['rq_timepreset'], 'rq_'));
}
QUnit_Global::includeClass('Affiliate_Merchants_Vi ews_CampaignManager');
$campaigns = $this->viewCampManager->getCampaignsAsArray();
$list_data1 = QUnit_Global::newobj('QCore_RecordSet');
$list_data1->setTemplateRS($campaigns);
$this->assign('a_list_data1', $list_data1);
$this->assign('a_curyear', date("Y"));
$this->addContent('rep_trans_filter');
$CampaignID = preg_replace('/[\'\"]/', '', $_REQUEST['rq_campaign']);
if(empty($_REQUEST['list_page']))
$page = 0;
else
$page = $_REQUEST['list_page'];
if($_REQUEST['rq_transtype'] != '')
{
$transType = $_REQUEST['rq_transtype'];
}
if($_REQUEST['rq_status'] != '' && $_REQUEST['rq_status'] != '_')
$status = $_REQUEST['rq_status'];
else
$status = '';
$AffiliateID = $GLOBALS['Auth']->getUserID();
if ($_REQUEST['rq_advanced_filter_show'] == '1') {
$custom1data = preg_replace('/[\'\"]/', '', $_REQUEST['rq_custom1data']);
$custom2data = preg_replace('/[\'\"]/', '', $_REQUEST['rq_custom2data']);
$custom3data = preg_replace('/[\'\"]/', '', $_REQUEST['rq_custom3data']);
$transType = ($_REQUEST['rq_transtype'] == '') ? array() : $_REQUEST['rq_transtype'];
$status = ($_REQUEST['rq_status'] == '') ? array() : $_REQUEST['rq_status'];
$extrafilter = array();
if ($custom1data != '')
$extrafilter[$_REQUEST['rq_custom1']] = $custom1data;
if ($custom2data != '')
$extrafilter[$_REQUEST['rq_custom2']] = $custom2data;
if ($custom3data != '')
$extrafilter[$_REQUEST['rq_custom3']] = $custom3data;
$conditions = array(
'CampaignID' => $CampaignID,
'UserID' => $AffiliateID,
'TransactionType' => $transType,
'Status' => $status,
'denyStatus' => $this->denyStatus,
'day1' => $_REQUEST['rq_day1'],
'month1' => $_REQUEST['rq_month1'],
'year1' => $_REQUEST['rq_year1'],
'day2' => $_REQUEST['rq_day2'],
'month2' => $_REQUEST['rq_month2'],
'year2' => $_REQUEST['rq_year2'],
'extrafilter' => $extrafilter
);
} else {
$conditions = array(
'CampaignID' => $CampaignID,
'UserID' => $AffiliateID,
'TransactionType' => array_keys($GLOBALS['Auth']->getSupportedCommissions(false)),
'day1' => $_REQUEST['rq_day1'],
'month1' => $_REQUEST['rq_month1'],
'year1' => $_REQUEST['rq_year1'],
'day2' => $_REQUEST['rq_day2'],
'month2' => $_REQUEST['rq_month2'],
'year2' => $_REQUEST['rq_year2'],
'denyStatus' => $this->denyStatus,
);
}
$transdata = $this->blSaleStat->getTransactionsStats($conditions);
$summaries = $this->blSaleStat->getTransactionsSummaries($conditions);
echo ('ID, Commission, Total Cost, Order ID, Created, Data1, Data2, Data3' . "\r\n");
$t_data = $transdata['transactions'];
for($i=0;$i<count($t_data);$i++)
{
if((float)$t_data[$i][commission] != 0)
{
echo ("{$t_data[$i][transid]}, {$t_data[$i][commission]}, {$t_data[$i][totalcost]}, {$t_data[$i][orderid]}, {$t_data[$i][datecreated]}, {$t_data[$i][data1]}, {$t_data[$i][data2]}, {$t_data[$i][data3]}\r\n");
}
}
$list_data = QUnit_Global::newobj('QCore_RecordSet');
$list_data->setTemplateRS($transdata['transactions']);
$this->assign('a_list_data', $list_data);
if($AffiliateID != '')
{
$this->assign('a_summaries', $summaries[$AffiliateID]);
}
else
{
$summ = array();
foreach($summaries as $aff => $summary)
{
$summ['paid'] += $summary['paid'];
$summ['pending'] += $summary['pending'];
$summ['approved'] += $summary['approved'];
$summ['reversed'] += $summary['reversed'];
$summ['totalcost'] += $summary['totalcost'];
}
$this->assign('a_summaries', $summ);
}
$this->pageLimitsAssign();
$this->assign('a_geo_allowed', $GLOBALS['Auth']->getSetting('Glob_acct_geo_allowed'));
if($GLOBALS['Auth']->getSetting('Glob_acct_geo_allowed') == '1') {
$blIpCountry = QUnit_Global::newObj('QCore_Bl_IpCountry');
$this->assign('a_country_info', $blIpCountry->getCountriesAsArray());
}
$this->setSupportedResults($CampaignID);
$this->addContent('rep_trans_list');
}
Coding complete upload and test.
When clicked, will activate a CSV down load of the current filter settings
Create a file named csv_report.php containing:
<?header("Expires: 0");
header("Cache-control: private");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-Description: File Transfer");
header("Content-Type: application/vnd.ms-excel");
header("Content-disposition: attachment; filename=transaction_report.csv");
include_once('global.php');
$page = QUnit_Global::newobj('QUnit_UI_MainPage');
$page->setDefaultView('MainPage');
$page->user_type = USERTYPE_USER;
$page->setFilePrefix('Affiliate_Affiliates_Views_');
$page->process();?>
up load this file to /affiliates
Next:
Find the file:
/templates/affiliate/yourskin/re_trans_filter.tpl.php
Find the line:
<input type="submit" class="formbutton" value="<?=L_G_APPLYFILTER?>">
and replace with:
<input type="button" class="formbutton" value="<?=L_G_APPLYFILTER?>" onclick="document.getElementById('reporttype').value='trans actions';document.forms[0].action='index.php';document.forms[0].submit();"> <input type="button" class="formbutton" value="Download CSV" onclick="document.getElementById('reporttype').value='csv'; document.forms[0].action='csv_report.php';document.forms[0].submit();">
Next:
find file:
/include/Affiliate/Affiliates/Views/AffReports.class.php
Find the line:
case 'subid':
if($this->showReportSubId())
return;
break;
}
}
}
Replace with:
case 'subid':
if($this->showReportSubId())
return;
break;
case 'csv':
if($this->showReportTransactionsCSV())
return;
break;
}
}
}
//------------------------------------------------------------------------
function showReportTransactionsCSV()
{
$this->navigationAddURL(L_G_TRANSACTIONS,'index.php?md=Af filiate_Affiliates_Views_AffReports&reporttype=transactions');
$this->getCampaignsForFilter();
$panel_settings = QUnit_Global::newObj('Affiliate_Affiliates_Views_A ffPanelSettings');
$this->assign('a_description', L_G_AFF_TRANSACTION_DESCRIPTION);
$this->assign('a_panel_settings', $panel_settings->loadPanelSettings('transactions'));
$this->addContent('section_descriptions');
$this->assign('a_form_preffix', 'rq_');
$this->assign('a_form_name', 'FilterForm');
$this->assign('a_filterColumns', array('t.orderid' => L_G_ORDERID,
't.data1' => L_G_DATA1,
't.data2' => L_G_DATA2,
't.data3' => L_G_DATA3,));
if ($_REQUEST['commited'] != 'yes') {
//--------------------------------------
// try to load settings from session
foreach($_SESSION as $k => $v)
{
if(strstr($k, 'rq_status') !== false && ($_REQUEST['status_comitted'] == '1')) {
continue;
}
if(strstr($k, 'rq_transtype') !== false && ($_REQUEST['transtype_comitted'] == '1')) {
continue;
}
if(strpos($k, 'rq_') === 0 && $_REQUEST[$k] == '')
$_REQUEST[$k] = $v;
if($k == 'numrows' && $_REQUEST[$k] == '')
$_REQUEST[$k] = $v;
}
}
//--------------------------------------
// get default settings for unset variables
if(empty($_REQUEST['numrows'])) $_REQUEST['numrows'] = 20;
if($_REQUEST['rq_campaign'] == '') $_REQUEST['rq_campaign'] = '_';
if($_REQUEST['rq_transtype'] == '') $_REQUEST['rq_transtype'] = $GLOBALS['Auth']->getAllowedCommissionTypes();
if($_REQUEST['rq_status'] == '') $_REQUEST['rq_status'] = '_';
if($_REQUEST['rq_reporttype'] == '') $_REQUEST['rq_reporttype'] = 'today';
if($_REQUEST['rq_day1'] == '') $_REQUEST['rq_day1'] = date("j");
if($_REQUEST['rq_month1'] == '') $_REQUEST['rq_month1'] = date("n");
if($_REQUEST['rq_year1'] == '') $_REQUEST['rq_year1'] = date("Y");
if($_REQUEST['rq_day2'] == '') $_REQUEST['rq_day2'] = date("j");
if($_REQUEST['rq_month2'] == '') $_REQUEST['rq_month2'] = date("n");
if($_REQUEST['rq_year2'] == '') $_REQUEST['rq_year2'] = date("Y");
if($_REQUEST['rq_timeselect'] == '') $_REQUEST['rq_timeselect'] = TIME_PRESET;
if($_REQUEST['rq_timepreset'] == '') $_REQUEST['rq_timepreset'] = TIME_TODAY;
//--------------------------------------
// put settings into session
$_SESSION['numrows'] = $_REQUEST['numrows'];
$_SESSION['rq_campaign'] = $_REQUEST['rq_campaign'];
$_SESSION['rq_transtype'] = $_REQUEST['rq_transtype'];
$_SESSION['rq_status'] = $_REQUEST['rq_status'];
$_SESSION['rq_reporttype'] = $_REQUEST['rq_reporttype'];
$_SESSION['rq_day1'] = $_REQUEST['rq_day1'];
$_SESSION['rq_month1'] = $_REQUEST['rq_month1'];
$_SESSION['rq_year1'] = $_REQUEST['rq_year1'];
$_SESSION['rq_day2'] = $_REQUEST['rq_day2'];
$_SESSION['rq_month2'] = $_REQUEST['rq_month2'];
$_SESSION['rq_year2'] = $_REQUEST['rq_year2'];
$_SESSION['rq_custom1'] = $_REQUEST['rq_custom1'];
$_SESSION['rq_custom2'] = $_REQUEST['rq_custom2'];
$_SESSION['rq_custom3'] = $_REQUEST['rq_custom3'];
$_SESSION['rq_custom1data'] = $_REQUEST['rq_custom1data'];
$_SESSION['rq_custom2data'] = $_REQUEST['rq_custom2data'];
$_SESSION['rq_custom3data'] = $_REQUEST['rq_custom3data'];
$_SESSION['rq_timeselect'] = $_REQUEST['rq_timeselect'];
$_SESSION['rq_timepreset'] = $_REQUEST['rq_timepreset'];
// process time filter
if($_REQUEST['rq_timeselect'] == TIME_PRESET) {
$_REQUEST = array_merge($_REQUEST, getTimerangeForPreset($_REQUEST['rq_timepreset'], 'rq_'));
}
QUnit_Global::includeClass('Affiliate_Merchants_Vi ews_CampaignManager');
$campaigns = $this->viewCampManager->getCampaignsAsArray();
$list_data1 = QUnit_Global::newobj('QCore_RecordSet');
$list_data1->setTemplateRS($campaigns);
$this->assign('a_list_data1', $list_data1);
$this->assign('a_curyear', date("Y"));
$this->addContent('rep_trans_filter');
$CampaignID = preg_replace('/[\'\"]/', '', $_REQUEST['rq_campaign']);
if(empty($_REQUEST['list_page']))
$page = 0;
else
$page = $_REQUEST['list_page'];
if($_REQUEST['rq_transtype'] != '')
{
$transType = $_REQUEST['rq_transtype'];
}
if($_REQUEST['rq_status'] != '' && $_REQUEST['rq_status'] != '_')
$status = $_REQUEST['rq_status'];
else
$status = '';
$AffiliateID = $GLOBALS['Auth']->getUserID();
if ($_REQUEST['rq_advanced_filter_show'] == '1') {
$custom1data = preg_replace('/[\'\"]/', '', $_REQUEST['rq_custom1data']);
$custom2data = preg_replace('/[\'\"]/', '', $_REQUEST['rq_custom2data']);
$custom3data = preg_replace('/[\'\"]/', '', $_REQUEST['rq_custom3data']);
$transType = ($_REQUEST['rq_transtype'] == '') ? array() : $_REQUEST['rq_transtype'];
$status = ($_REQUEST['rq_status'] == '') ? array() : $_REQUEST['rq_status'];
$extrafilter = array();
if ($custom1data != '')
$extrafilter[$_REQUEST['rq_custom1']] = $custom1data;
if ($custom2data != '')
$extrafilter[$_REQUEST['rq_custom2']] = $custom2data;
if ($custom3data != '')
$extrafilter[$_REQUEST['rq_custom3']] = $custom3data;
$conditions = array(
'CampaignID' => $CampaignID,
'UserID' => $AffiliateID,
'TransactionType' => $transType,
'Status' => $status,
'denyStatus' => $this->denyStatus,
'day1' => $_REQUEST['rq_day1'],
'month1' => $_REQUEST['rq_month1'],
'year1' => $_REQUEST['rq_year1'],
'day2' => $_REQUEST['rq_day2'],
'month2' => $_REQUEST['rq_month2'],
'year2' => $_REQUEST['rq_year2'],
'extrafilter' => $extrafilter
);
} else {
$conditions = array(
'CampaignID' => $CampaignID,
'UserID' => $AffiliateID,
'TransactionType' => array_keys($GLOBALS['Auth']->getSupportedCommissions(false)),
'day1' => $_REQUEST['rq_day1'],
'month1' => $_REQUEST['rq_month1'],
'year1' => $_REQUEST['rq_year1'],
'day2' => $_REQUEST['rq_day2'],
'month2' => $_REQUEST['rq_month2'],
'year2' => $_REQUEST['rq_year2'],
'denyStatus' => $this->denyStatus,
);
}
$transdata = $this->blSaleStat->getTransactionsStats($conditions);
$summaries = $this->blSaleStat->getTransactionsSummaries($conditions);
echo ('ID, Commission, Total Cost, Order ID, Created, Data1, Data2, Data3' . "\r\n");
$t_data = $transdata['transactions'];
for($i=0;$i<count($t_data);$i++)
{
if((float)$t_data[$i][commission] != 0)
{
echo ("{$t_data[$i][transid]}, {$t_data[$i][commission]}, {$t_data[$i][totalcost]}, {$t_data[$i][orderid]}, {$t_data[$i][datecreated]}, {$t_data[$i][data1]}, {$t_data[$i][data2]}, {$t_data[$i][data3]}\r\n");
}
}
$list_data = QUnit_Global::newobj('QCore_RecordSet');
$list_data->setTemplateRS($transdata['transactions']);
$this->assign('a_list_data', $list_data);
if($AffiliateID != '')
{
$this->assign('a_summaries', $summaries[$AffiliateID]);
}
else
{
$summ = array();
foreach($summaries as $aff => $summary)
{
$summ['paid'] += $summary['paid'];
$summ['pending'] += $summary['pending'];
$summ['approved'] += $summary['approved'];
$summ['reversed'] += $summary['reversed'];
$summ['totalcost'] += $summary['totalcost'];
}
$this->assign('a_summaries', $summ);
}
$this->pageLimitsAssign();
$this->assign('a_geo_allowed', $GLOBALS['Auth']->getSetting('Glob_acct_geo_allowed'));
if($GLOBALS['Auth']->getSetting('Glob_acct_geo_allowed') == '1') {
$blIpCountry = QUnit_Global::newObj('QCore_Bl_IpCountry');
$this->assign('a_country_info', $blIpCountry->getCountriesAsArray());
}
$this->setSupportedResults($CampaignID);
$this->addContent('rep_trans_list');
}
Coding complete upload and test.