<?
function generateNumberF($template_id,$date,$table,$date_field,$show_number=1){
	global $timedate;
	$r=$GLOBALS['db']->fetchByAssoc($GLOBALS['db']->query("select * from ecmdocumenttemplates where id='".$template_id."'"));
	$per=$r['documents_per'];
	$format=$r['document_number_format_id'];
	//$date=$timedate->to_display($date, $timedate->get_date_format(), "Y-m-d");
	$exp=explode("-",$date);
	if($per=="day")$daten=$date;
	if($per=="month")$daten=$exp[0]."-".$exp[1];
	if($per=="year")$daten=$exp[0];
	$r=$GLOBALS['db']->fetchByAssoc($GLOBALS['db']->query("select number from ".$table." where ".$date_field." like '".$daten."%' order by number desc limit 1"));
	$no=$r['number']+1;

	if($format[1]=="/")$sep="/";
	elseif($format[1]==".")$sep=".";
	elseif($format[1]=="-")$sep="-";
	else $sep="";
	
	if($format=="NR/D/M/Y")$sep="/";
	if($format=="NR.D.M.Y")$sep=".";
	if($format=="NR D/M/Y")$sep=" ";
	if($format=="NR-D-M-Y")$sep="-";
	if($format=="NRDMY")$sep="";

	$format=str_replace("NR",$no,$format);
	$format=str_replace("Y",$exp[0],$format);
	$format=str_replace("M",$exp[1],$format);
	$format=str_replace("D",$exp[2],$format);

	$number="ZD".$sep.$format;
	if($show_number)return $number;
	else return $no;
}
?>
