Location: PHPKode > projects > SureInvoice > sureinvoice-1.0/report_export.php
<?
require_once('includes/common.php');
checkLogin();

require_once('includes/SI_Project.php');
require_once('includes/SI_Company.php');
require_once('includes/SI_TaskActivity.php');
require_once('includes/SI_Task.php');

$title = 'Reports';
$activity = new SI_TaskActivity();

if(!isset($_REQUEST['billable'])){
	$_REQUEST['billable'] = 'N';
}

	if(!$loggedin_user->hasRight('admin') && !$loggedin_user->isDeveloper()){
		$_REQUEST['billable'] = 'Y';
		$_REQUEST['company_id'] = $loggedin_user->company_id;
	}

	if(!$loggedin_user->hasRight('admin') && $loggedin_user->isDeveloper()){
		$_REQUEST['resource_id'] = $loggedin_user->id;
	}

	$activities = $activity->find($_REQUEST['start_ts'], $_REQUEST['end_ts']+86400, $_REQUEST['resource_id'], $_REQUEST['company_id'], $_REQUEST['billable']);
	if($activities === FALSE){
		$error_msg .= "Error getting report data!\n";
		debug_message($activity->getLastError());
	}

$csv_output = '';
for($i=0; $i<count($activities); $i++){
	if($i == 0){
		// Print the header
		$csv_output = "Company,Project,Task,Started,Completed,Time Spent\n";	
	}
	
	$csv_output .= '"'.$activities[$i]->company_name.
		'","'.$activities[$i]->project_name.
		'","'.$activities[$i]->task_name.
		'","'.($activities[$i]->start_ts>0 ? date("n/j/y H:i", $activities[$i]->start_ts) : "None").
		'","'.($activities[$i]->end_ts>0 ? date("n/j/y H:i", $activities[$i]->end_ts) : "None").
		'","'.($activities[$i]->start_ts>0 && $activities[$i]->end_ts>0 && $activities[$i]->end_ts > $activities[$i]->start_ts ? formatLengthOfTime($activities[$i]->end_ts - $activities[$i]->start_ts) : "").
		"\"\n";
}

if(!empty($csv_output)){
	header('Content-type: text/csv');
	header('Content-Disposition: attachment; filename="sureinvoice_report.csv"');
	print($csv_output);		
}
?>
Return current item: SureInvoice