<?php
include("include/config.php");
include("include/protect.class.php");
include("include/jdf.php");
include('include/functions.php');

$prot=new protect();
if ($prot->showPage) {
$db=new DB($globalConfig['dbase'], $globalConfig['dbhost'],$globalConfig['dbuser'], $globalConfig['dbpass']);

	$action = $_GET['act'];
	
	switch($action){

		
		case 'users':

				$tableName = 'u_users';
				$fields = array('DISTINCT(email)');
				$names = array(1 => 'email');
				$fileName = 'usersEmail';
				sql2XLS($fileName, $tableName, $fields, $names);
							
			break;

		case 'usersTell':
				$tableName = 'u_users';
				$fields = array('DISTINCT(mobile)');
				$names = array(1 => 'mobile');
				$fileName = 'mobile';
				sql2XLS($fileName, $tableName, $fields, $names);
							
			break;


		case 'activeUsers':

				$tableName = 'u_users u, goroohe_karbaran g';
				$fields = array('ID', 
								'userName', 
								'name_lastname', 
								'email', 
								'tell', 
								'start_date', 
								'expire_date', 
								'company', 
								'website', 
								'address');
				
				$names = array(	1 => 'ID', 
								2 => 'userName', 
								3 => 'FullName', 
								4 => 'email', 
								5 => 'tellNum', 
								6 => 'startDate', 
								7 => 'expireDate', 
								8 => 'company', 
								9 => 'website', 
								10 => 'address');
								
				$whereClaus = 'WHERE g.groupid <> 7 AND u.ID = g.user_id';
				$orderBy = 'ORDER BY u.ID DESC';
				$fileName = 'activeUsers';
				sql2XLS($fileName, $tableName, $fields, $names, $whereClaus, $orderBy);
							
			break;


		case 'testUsers':
				
				$tableName = 'sms_test_record';
				$fields = array('DISTINCT(email)');
				$names = array(1 => 'email');
				$fileName = 'testUsers';
				sql2XLS($fileName, $tableName, $fields, $names);
				
		break;
		
		case 'detaileusers2':
			
				$userID = (int)$_GET['uid'];
				$tableName = 'detaileusers2';
				$fields = array('userID',
								 'to_num',
								 'companyName', 
								 'amount', 
								 'date',
								 'date',
								 'date',
								 'date',
								 'date',
								 'date',
								 'date',
								 'date',
								 'date',
								 'date',
								 'date',
								 );
				
				$names = array(1 => 'from_num', 2 => 'to_num', 3 => 'text_message', 4 => 'amount', 5 => 'date');
				$whereClaus = "WHERE userID = $userID ";
				$orderBy = '';
				$fileName = 'جزئیات کاربر';
				sql2XLS($fileName, $tableName, $fields, $names, $whereClaus, $orderBy);
						
			break;
			
		case 'userSmsOut':
			
				$userID = (int)$_GET['uid'];
				$tableName = 'sms_records';
				$fields = array('from_num', 'to_num', 'text_message', 'amount', 'date');
				$names = array(1 => 'from_num', 2 => 'to_num', 3 => 'text_message', 4 => 'amount', 5 => 'date');
				$whereClaus = "WHERE user_id = $userID AND smsType = 1";
				$orderBy = 'ORDER BY date DESC';
				$fileName = 'outgoingSMS';
				sql2XLS($fileName, $tableName, $fields, $names, $whereClaus, $orderBy);
						
			break;
			
		case 'activeUsers':
			
				$userID = (int)$_GET['uid'];
				$tableName = 'sms_records';
				$fields = array('from_num', 'to_num', 'text_message', 'amount', 'date');
				$names = array(1 => 'from_num', 2 => 'to_num', 3 => 'text_message', 4 => 'amount', 5 => 'date');
				$whereClaus = "WHERE user_id = $userID AND smsType = 1";
				$orderBy = 'ORDER BY date DESC';
				$fileName = 'outgoingSMS';
				sql2XLS($fileName, $tableName, $fields, $names, $whereClaus, $orderBy);
						
			break;
			
	}

}
?>
