<?php

include 'icl/showreportsetting.inc.php';

function addreportsetting(){
	
	$reportname=SQET('reportname');
	$reportgroup=SQET('reportgroup');
	$reportfunc=SQET('reportfunc');
	$reportkey=SQET('reportkey');
	$reportdesc=SQET('reportdesc');
	
	global $db;
	global $lang;
	
	checkgskey('addreportsetting');
	
	$user=userinfo();
	$gsid=$user['gsid']+0;
	
	if (!$user['groups']['devreports']) apperror('access denied');
	
	$query="select * from ".TABLENAME_REPORTS." where (gsid=? or gsid=0) and reportkey=?";
	$rs=sql_prep($query,$db,array($gsid,$reportkey));
	if ($myrow=sql_fetch_assoc($rs)) apperror('Report key must be unique');
	
	
	$query="insert into ".TABLENAME_REPORTS." (gsid,reportname_$lang,reportgroup_$lang,reportfunc,reportkey,reportdesc_$lang) values (?,?,?,?,?,?) ";
	$rs=sql_prep($query,$db,array($gsid,$reportname,$reportgroup,$reportfunc,$reportkey,$reportdesc));
	$reportid=sql_insert_id($db,$rs)+0;

	if (!$reportid) {
		apperror(_tr('error_creating_record'));
	}
	
	logaction("added Report Settings #$reportid $reportname",array('reportid'=>$reportid,'reportname'=>"$reportname"));
	
	header('newrecid:'.$reportid);
	header('newkey:reportsetting_'.$reportid);
	header('newparams:showreportsetting&reportid='.$reportid);
	
	showreportsetting($reportid);
}

