<?php
if ( !defined( 'SMARTY_DIR' ) ) {
	include_once( '../init.php' );
}

include ( 'sessioninc.php' );

define( 'PAGE_ID', 'promo_mgt' );

if ( !checkAdminPermission( PAGE_ID ) ) {

	header( 'location: not_authorize.php' );
	exit;
}

$promos_data = array();

$promos =& $osDB->getAll("select * from !", array(PROMO_TABLE) ) ;

foreach ($promos as $promo_rec) {
	$promo_rec['userlist'] =& $osDB->getAll('select prm.userid,usr.username, prm.used_date from ! as usr, ! as prm where usr.id=prm.userid and prm.promocode = ? order by prm.promocode, prm.used_date desc', array(USER_TABLE, PROMO_USED_TABLE, $promo_rec['promocode']) );
	$promo_rec['cnt'] = count($promo_rec['userlist']);

	$promos_data[] = $promo_rec;

}

$t->assign('data', $promos_data);

unset($promos_data, $promos);

$t->assign( 'lang', $lang );

$t->assign('rendered_page', $t->fetch('admin/promoreport.tpl'));

$t->display( 'admin/index.tpl' );

?>