Adding Stats to Affiliate Pages
You can use quick_stats.php to add stats to a page in your system. This is included with your system but you'll have to set up a script to call it with.
Setting up the script
In your ../nats/includes folder create a php file. Let's call it mystats.php for example. In it you can use this code or alter to meet your needs:
<? include_once('quick_stats.php'); $data = quick_stats('normal', $GLOBALS['loginid'], 1); $top_data = top_stats('2', '2', '10'); $this->assign('top_data', $top_data); $this->assign('data', $data); ?>
There are two functions in the quick_stats.php script, quick_stats and top_stats.
The quick_stats call's first parameter designates the type; this can be set to owed (the amount of money built in payments that hasn't been paid), site (reseller stats broken down by site), and normal (reseller stats broken down by day). The second will get the login id and grabs the stats for that login id. The third designates a time period.
The top_stats function has five different types 1 (top sites by joins), 2 (top sites by ratio), 3 (top affiliates by ratio), 4 (worst affiliates by ratio), default (top affiliates by amount earned). The second input is the time period. The third input is the number of results to return.
Note: The top_stats function should be run as a cron that only updates once an hour. We strongly recommend that you store the results in a flat file and display them from the file.
Your options for time period are:
- 0 = today
- 1 = this period
- 2 = this month
- 3 = previous day
- 4 = previous period
- 5 = previous month
- 6 = freeform; to use this you will have to include a 4th and 5th parameter as start and end dates. These values can be dates or statements like "friday 3 weeks ago".
Including mystats.php on a template
Locate the template you would like stats to appear on in the ../nats/templates directory. Include mystats.php like this:
{include_php file="mystats.php"}
And use the following variables to get your stats:
- {$data.raw|default:0} gives you raw hits
- {$data.unq|default:0} gives you unique hits
- {$data.qual|default:0} gives you qualified hits
- {$data.signups|default:0} gives you joins
- {$data.a_signups|default:0} gives you active joins
- {$data.earned|default:0} gives you the amount earned on the sale
- {$data.ratio} gives you a ratio of joins to raw hits
Example top_stats_cron:
<? $do_db = 1; // we want to connect to the db $do_login = 0; // we want to try to login if login info is provided include_once('../includes/header.php'); include_once('../includes/quick_stats.php'); $top_data = top_stats(2, 1, 5); $filename = 'top_data.txt'; $data = ''; foreach($top_data as $order => $info){ $data_info = Array(); foreach($info as $field => $value){ $data_info[] = "'$field'='$value'"; } $data .= implode(', ', $data_info); $data .= "n"; } if (is_writable($filename)){ if (!$handle = fopen($filename, 'w')) { exit; } if (fwrite($handle, $data) === FALSE) { exit; } fclose($handle); } ?>
Example Smarty plugin to read top_data.txt file:
<? function smarty_function_get_top_stats($params, &$smarty){ $top_data = Array(); if(!$params['file']) return FALSE; $filename = $params['file']; if(!filesize($filename)) return FALSE; $handle = fopen($filename, 'r'); $contents = fread($handle, filesize($filename)); fclose($handle); $data = explode("\n", $contents); foreach($data as $values){ $values = substr($values, 1); $values = substr($values, 0, -1); $vdata = explode("', '", $values); $info = Array(); foreach($vdata as $vinfo){ list($field, $val) = explode("'='", $vinfo); $info[$field] = $val; } $top_data[] = $info; } $smarty->assign('top_data', $top_data); return; } ?>
Call to plugin on the template:
{get_top_stats file="/pathtonats/tools/top_data.txt"}