Skip to content
This repository has been archived by the owner on Apr 24, 2019. It is now read-only.

Commit

Permalink
Adding more charts to orders.php
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyler Hall committed Aug 8, 2009
1 parent 43a70e4 commit 585b514
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 39 deletions.
73 changes: 52 additions & 21 deletions includes/class.objects.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,37 @@ function getBody($order)
{
return str_replace(array('{first_name}', '{last_name}', '{payer_email}', '{license}'), array($order->first_name, $order->last_name, $order->payer_email, $order->license), $this->email_body);
}

function ordersPerMonth()
{
$db = Database::getDatabase();

$orders = $db->getRows("SELECT DATE_FORMAT(dt, '%Y-%m') as dtstr, COUNT(*) FROM orders WHERE type = 'PayPal' AND app_id = '{$this->id}' GROUP BY CONCAT(YEAR(dt), '-', MONTH(dt)) ORDER BY YEAR(dt) ASC, MONTH(dt) ASC");
$keys = gimme($orders, 'dtstr');
$values = gimme($orders, 'COUNT(*)');
$orders = array();
for($i = 0; $i < count($keys); $i++)
$orders[$keys[$i]] = $values[$i];

$first_order_date = $db->getValue("SELECT dt FROM orders ORDER BY dt ASC LIMIT 1");
list($year, $month) = explode('-', dater($first_order_date, 'Y-n'));
do
{
if(!isset($orders["$year-$month"]))
$orders["$year-" . str_pad($month, 2, '0', STR_PAD_LEFT)] = 0;

$month++;
if($month == 13)
{
$month = 1;
$year++;
}
}
while($year <> date('Y') && $month <> date('m'));

ksort($orders);
return $orders;
}
}

class Order extends DBObject
Expand Down Expand Up @@ -143,7 +174,7 @@ function emailLicense()
if($app->license_type == 'ap')
$this->emailLicenseAP();
else
$this->emailLicenseSMTP();
$this->emailLicenseCustom();
}

public function emailLicenseCustom()
Expand Down Expand Up @@ -192,26 +223,26 @@ public function emailLicenseAP()
// define('SMTP_PASSWORD', 'some-password');
// define('SMTP_HOST', 'ssl://smtp.gmail.com');
// define('SMTP_PORT', 465);
public function emailLicenseSMTP()
{
$app = new Application($this->app_id);

$tmp = tempnam('/tmp', 'foo');
file_put_contents($tmp, $this->license);

$hdrs = array('From' => $app->from_email, 'Subject' => $app->email_subject);

$mime = new Mail_mime("\r\n");
$mime->setTXTBody($app->getBody($this));
$mime->setHTMLBody('');
// $mime->addAttachment($tmp, 'application/octet-stream', $app->license_filename, true, 'base64');

$body = $mime->get();
$hdrs = $mime->headers($hdrs);

$smtp =& Mail::factory('smtp', array('host' => SMTP_HOST, 'port' => SMTP_PORT, 'auth' => true, 'username' => SMTP_USERNAME, 'password' => SMTP_PASSWORD));
$mail = $smtp->send($this->payer_email, $hdrs, $body);
}
// public function emailLicenseSMTP()
// {
// $app = new Application($this->app_id);
//
// $tmp = tempnam('/tmp', 'foo');
// file_put_contents($tmp, $this->license);
//
// $hdrs = array('From' => $app->from_email, 'Subject' => $app->email_subject);
//
// $mime = new Mail_mime("\r\n");
// $mime->setTXTBody($app->getBody($this));
// $mime->setHTMLBody('');
// // $mime->addAttachment($tmp, 'application/octet-stream', $app->license_filename, true, 'base64');
//
// $body = $mime->get();
// $hdrs = $mime->headers($hdrs);
//
// $smtp =& Mail::factory('smtp', array('host' => SMTP_HOST, 'port' => SMTP_PORT, 'auth' => true, 'username' => SMTP_USERNAME, 'password' => SMTP_PASSWORD));
// $mail = $smtp->send($this->payer_email, $hdrs, $body);
// }

public function downloadLicense()
{
Expand Down
64 changes: 46 additions & 18 deletions orders.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
$Auth->requireAdmin('login.php');

$applications = DBObject::glob('Application', 'SELECT * FROM applications ORDER BY name');


$db = Database::getDatabase();

Expand All @@ -20,15 +19,30 @@
$pager = new Pager(@$_GET['page'], 50, $total_num_orders);
$orders = DBObject::glob('Order', "SELECT * FROM orders ORDER BY dt DESC LIMIT {$pager->firstRecord}, {$pager->perPage}");
}

$db = Database::getDatabase();
$order_totals = $db->getRows("SELECT DATE_FORMAT(dt, '%b') as dtstr, COUNT(*) FROM orders WHERE type = 'PayPal' GROUP BY CONCAT(YEAR(dt), '-', MONTH(dt)) ORDER BY YEAR(dt) ASC, MONTH(dt) ASC");
$chart = new googleChart(implode(',', gimme($order_totals, 'COUNT(*)')));
$chart->showGrid = 1;
$chart->dimensions = '280x100';
$labels = gimme($order_totals, 'dtstr', 5);
$chart->setLabelsMinMax(4,'left');
$chart->setLabels($labels, 'bottom');

// Orders Per Month
$order_totals = $db->getRows("SELECT DATE_FORMAT(dt, '%b') as dtstr, COUNT(*) FROM orders WHERE type = 'PayPal' GROUP BY CONCAT(YEAR(dt), '-', MONTH(dt)) ORDER BY YEAR(dt) ASC, MONTH(dt) ASC");
$opm = new googleChart(implode(',', gimme($order_totals, 'COUNT(*)')), 'line');
$opm->showGrid = 1;
$opm->dimensions = '280x100';
$opm->setLabelsMinMax(4,'left');

// Orders Per Week
$order_totals = $db->getRows("SELECT WEEK(dt) as dtstr, COUNT(*) FROM orders WHERE type = 'PayPal' GROUP BY CONCAT(YEAR(dt), WEEK(dt)) ORDER BY YEAR(dt) ASC, WEEK(dt) ASC");
$opw = new googleChart(implode(',', gimme($order_totals, 'COUNT(*)')), 'line');
$opw->showGrid = 1;
$opw->dimensions = '280x100';
$opw->setLabelsMinMax(4,'left');

// Orders Per Month Per Application
$data = array();
foreach($applications as $app)
$data[$app->name] = $app->ordersPerMonth();
$opma = new googleChart();
$opma->smartDataLabel($data);
$opma->showGrid = 1;
$opma->dimensions = '280x100';
$opma->setLabelsMinMax(4,'left');
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
Expand Down Expand Up @@ -79,7 +93,6 @@
</div>
<div class="bd">
<ul class="pager">

<li><a href="orders.php?page=<?PHP echo $pager->prevPage(); ?>&amp;id=<?PHP echo @$app_id; ?>">&#171; Prev</a></li>
<?PHP for($i = 1; $i <= $pager->numPages; $i++) : ?>
<?PHP if($i == $pager->page) : ?>
Expand Down Expand Up @@ -119,33 +132,48 @@
</table>

<ul class="pager">

<li><a href="orders.php?page=<?PHP echo $pager->prevPage(); ?>">&#171; Prev</a></li>
<li><a href="orders.php?page=<?PHP echo $pager->prevPage(); ?>&amp;id=<?PHP echo @$app_id; ?>">&#171; Prev</a></li>
<?PHP for($i = 1; $i <= $pager->numPages; $i++) : ?>
<?PHP if($i == $pager->page) : ?>
<li class="active"><a href="orders.php?page=<?PHP echo $i; ?>"><?PHP echo $i; ?></a></li>
<li class="active"><a href="orders.php?page=<?PHP echo $i; ?>&amp;id=<?PHP echo @$app_id; ?>"><?PHP echo $i; ?></a></li>
<?PHP else : ?>
<li><a href="orders.php?page=<?PHP echo $i; ?>"><?PHP echo $i; ?></a></li>
<li><a href="orders.php?page=<?PHP echo $i; ?>&amp;id=<?PHP echo @$app_id; ?>"><?PHP echo $i; ?></a></li>
<?PHP endif; ?>
<?PHP endfor; ?>
<li><a href="orders.php?page=<?PHP echo $pager->nextPage(); ?>">Next &#187;</a></li>
<li><a href="orders.php?page=<?PHP echo $pager->nextPage(); ?>&amp;id=<?PHP echo @$app_id; ?>">Next &#187;</a></li>
</ul>
</div>
</div>

</div></div>
</div>
<div id="sidebar" class="yui-b">
<div class="block">
<div class="hd">
<h2>Total Orders Per Month</h2>
</div>
<div class="bd">
<?PHP $opm->draw(); ?>
</div>
</div>

<div class="block">
<div class="hd">
<h2>Orders Per Week</h2>
</div>
<div class="bd">
<?PHP $opw->draw(); ?>
</div>
</div>

<div class="block">
<div class="hd">
<h2>Orders Per Month</h2>
</div>
<div class="bd">
<?PHP $chart->draw(); ?>
<?PHP $opma->draw(); ?>
</div>
</div>

</div>
</div>

Expand Down
16 changes: 16 additions & 0 deletions return.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?PHP
require 'includes/master.inc.php';

$o = new Order();
$o->select($_GET['tx'], 'txn_id');

if($o->ok())
{
$app = new Application($o->app_id);
redirect($app->return_url . '?email=' . $o->payer_email . '&reg=' . $o->license);
}
else
{
die("Thank you for your order. Your registration information will be emailed to you shortly. If you have any questions, feel free to contact <a href='mailto:[email protected]'>[email protected]</a>");
}

0 comments on commit 585b514

Please sign in to comment.