rcfunctions.inc

来自「java开源项目源代码」· INC 代码 · 共 813 行 · 第 1/3 页

INC
813
字号
	// Fetch the language dependent db entries	$ReportName = $myrow['reportname'];	// Enter some export file info for language translation	$CSVOutput .= '/* Report Name: '.$ReportName.' */'.$crlf;	$CSVOutput .= '/* Export File Generated: : '.date('Y-m-d h:m:s', time()).' */'.$crlf.$crlf.$crlf;	$CSVOutput .= '/* Language Fields. */'.$crlf;	$CSVOutput .= '/* Only modify the language portion between the single quotes after the colon. */'.$crlf.$crlf;	$CSVOutput .= '/* Report Name and Title Information: */'.$crlf;	$CSVOutput .= "ReportName:'".DB_escape_string($ReportName)."'".$crlf;	if ($myrow['reporttype']<>'frm') {		$CSVOutput .= "Title1Desc:'".DB_escape_string($myrow['title1desc'])."'".$crlf;		$CSVOutput .= "Title2Desc:'".DB_escape_string($myrow['title2desc'])."'".$crlf;	}	// Now add the report fields	$CSVOutput .= $crlf.'/* Report Field Description Information: */'.$crlf;	$sql = "SELECT * FROM ".DBRptFields." WHERE reportid = ".$ReportID." ORDER BY entrytype, seqnum;";	$Result=DB_query($sql,$db,'','',false,true);	$i=0;	while ($FieldRows = DB_fetch_assoc($Result)) {		if ($FieldRows['entrytype']<>'dateselect' AND $FieldRows['entrytype']<>'trunclong') {			$CSVOutput .= "FieldDesc".$i.":'".DB_escape_string($FieldRows['displaydesc'])."'".$crlf;		}		$sql = 'FieldData'.$i.':';		foreach ($FieldRows as $key=>$value) {			if ($key<>'id' AND $key<>'reportid') $sql .= $key."='".DB_escape_string($value)."', ";		}		$sql = substr($sql,0,-2).";"; // Strip the last comma and space and add a semicolon		$FieldData[$i] = $sql;		$i++;	}	$CSVOutput .= '/* End of language fields. */'.$crlf.$crlf;	$CSVOutput .= '/* DO NOT EDIT BELOW THIS LINE! */'.$crlf.$crlf.$crlf;	$CSVOutput .= '/* SQL report data. */'.$crlf;	// Build the report sql string	$RptData = 'ReportData:';	foreach ($myrow as $key=>$value) if ($key<>'id') $RptData .= $key."='".DB_escape_string($value)."', ";	$RptData = substr($RptData,0,-2).";"; // Strip the last comma and space and add a semicolon	$CSVOutput .= $RptData.$crlf.$crlf;	$CSVOutput .= '/* SQL field data. */'.$crlf;	for ($i=0; $i<count($FieldData); $i++) $CSVOutput .= $FieldData[$i].$crlf;	$CSVOutput .= $crlf;	$CSVOutput .= '/* End of Export File */'.$crlf;	// export the file 	$FileSize = strlen($CSVOutput);	header("Content-type: application/txt");	header("Content-disposition: attachment; filename=".preg_replace('/ /','',$ReportName).".rpt.txt; size=".$FileSize);	// These next two lines are needed for MSIE    header('Pragma: cache');    header('Cache-Control: public, must-revalidate, max-age=0');	print $CSVOutput;	exit();  }function ImportReport($RptName) {	global $db;	if ($_POST['RptFileName']<>'') { // then a locally stored report was chosen		$arrSQL = file(DefRptPath.$_POST['RptFileName']);	} else { // check for an uploaded file		$Rtn['result'] = 'error';		if ($_FILES['reportfile']['error']) { // php error uploading file			switch ($_FILES['reportfile']['error']) {				case '1': $Rtn['message'] = RPT_IMP_ERMSG1; break;				case '2': $Rtn['message'] = RPT_IMP_ERMSG2; break;				case '3': $Rtn['message'] = RPT_IMP_ERMSG3; break;				case '4': $Rtn['message'] = RPT_IMP_ERMSG4; break;				default:  $Rtn['message'] = RPT_IMP_ERMSG5.$_FILES['reportfile']['error'].'.';			}		} elseif (!is_uploaded_file($_FILES['reportfile']['tmp_name'])) { // file uploaded			$Rtn['message'] = RPT_IMP_ERMSG10;		} elseif (strpos($_FILES['reportfile']['type'],'txt') === false)  { // not a text file, error			$Rtn['message'] = RPT_IMP_ERMSG6;		} elseif ($_FILES['reportfile']['size']==0) { // report contains no data, error			$Rtn['message'] = RPT_IMP_ERMSG7;		} else { // passed all error checking, read file and reset error message			$arrSQL = file($_FILES['reportfile']['tmp_name']);			$Rtn['result']='';		}		if ($Rtn['result']=='error') return $Rtn;	}		$Title1Desc = ''; // Initialize to null, not used for forms	$Title2Desc = '';	foreach ($arrSQL as $sql) { // find the report translated reportname and title information		if (strpos($sql,'ReportName:')===0) $ReportName = substr(trim($sql),12,-1);		if (strpos($sql,'Title1Desc:')===0) $Title1Desc = substr(trim($sql),12,-1);		if (strpos($sql,'Title2Desc:')===0) $Title2Desc = substr(trim($sql),12,-1);	}	// check for valid file, duplicate report name	if ($RptName=='') $RptName = $ReportName; // then no report was entered use reportname from file	$sql= "SELECT id FROM ".DBReports." WHERE reportname='".DB_escape_string($RptName)."';";	$Result=DB_query($sql,$db,'','',false,true);	if (DB_num_rows($Result)>0) { // the report name already exists, error 		$Rtn['result'] = 'error';		$Rtn['message'] = RPT_REPDUP;		return $Rtn;	}	// Find the line with the table reports element, needs to be written first	$ValidReportSQL = false;	foreach ($arrSQL as $sql) { // find the main reports sql statement, language and execute it		if (strpos($sql,'ReportData:')===0) {			$sql="INSERT INTO ".DBReports." SET ".substr(trim($sql),11);			$Result=DB_query($sql,$db,'','',false,true);			$ValidReportSQL = true;		}	}	if (!$ValidReportSQL) { // no valid report sql statement found in the text file, error		$Rtn['result'] = 'error';		$Rtn['message'] = RPT_IMP_ERMSG8;		return $Rtn;	}	// fetch the id of the row inserted 	$ReportID = DB_Last_Insert_ID($db,DBReports,'id');	// update the translated report name and title fields into the newly imported report	$sql = "UPDATE ".DBReports." SET 			reportname = '".$RptName."', 			title1desc = '".$Title1Desc."', 			title2desc = '".$Title2Desc."' 		WHERE id = ".$ReportID.";";	$Result=DB_query($sql,$db,'','',false,true);	foreach ($arrSQL as $sql) { // fetch the translations for the field descriptions		if (strpos($sql,'FieldDesc')===0) { // then it's a field description, find the index and save			$sql = trim($sql);			$FldIndex = substr($sql,9,strpos($sql,':')-9);			$Language[$FldIndex] = substr($sql,strpos($sql,':')+2,-1);		}	}	foreach ($arrSQL as $sql) {		if (strpos($sql,'FieldData')===0) { // a valid field, write it			$sql = trim($sql);			$FldIndex = substr($sql,9,strpos($sql,':')-9);			$sql="INSERT INTO ".DBRptFields." SET ".substr($sql,strpos($sql,':')+1);			$Result=DB_query($sql,$db,'','',false,true);			$FieldID = DB_Last_Insert_ID($db,DBRptFields, 'id');			if ($FieldID<>0) { // A field was successfully written update the report id				if (isset($Language[$FldIndex])) $DispSQL = "displaydesc='".$Language[$FldIndex]."', ";					else $DispSQL = '';				$tsql = "UPDATE ".DBRptFields." SET ".$DispSQL." reportid='".$ReportID."' 					WHERE id=".$FieldID.";";				$Result=DB_query($tsql,$db,'','',false,true);			}		}	}	$Rtn['result'] = 'success';	$Rtn['message'] = $RptName.RPT_IMP_ERMSG9;	return $Rtn;}function CreateTableList($ReportID,$Table) {	global $db;	$sql = "SELECT table".$Table." FROM ".DBReports." WHERE id='".$ReportID."'";	$Result=DB_query($sql,$db,'','',false,true);	$myrow = DB_fetch_row($Result);		$TableList = '';		$Result=DB_show_tables($db);	while ($mytable=DB_fetch_row($Result)) {		$tablename = strtolower($mytable[0]);		if ($myrow[0] == $tablename) $TableList .= "<OPTION SELECTED Value='" . $tablename . "'>" . $tablename . "</OPTION>";			else $TableList .= "<OPTION Value='" . $tablename . "'>" . $tablename . "</OPTION>";	}	return $TableList;} // CreateTableListfunction CreateLinkList($ReportID,$Table) {	global $db;	$sql = "SELECT table1, table2, table3, table4, table5, table6		FROM ".DBReports." WHERE id='".$ReportID."'";	$Result=DB_query($sql,$db,'','',false,true);	$myrow = DB_fetch_row($Result);	$LinkList = ''; $j = 0; 	/* Get list of link tables from foreign keys */	for ($i = 0; $i < $Table; $i++) {		$comments = '';		$sql = "SELECT table1, table2 FROM reportlinks WHERE table1 = '" . $myrow[$i] . "'";		$Result=DB_query($sql,$db,'','',false,true);		while($mytable=DB_fetch_row($Result)) {			if ($myrow[$Table]) {				if ($myrow[$Table] == $mytable[1]){					$LinkList .= "<OPTION SELECTED Value='" . $mytable[1] . "'>" . $mytable[1];				} else {					$LinkList .= "<OPTION Value='" . $mytable[1] . "'>" . $mytable[1];				}			} else {				if ($j == 0){					$LinkList .= "<OPTION SELECTED Value='" . $mytable[1] . "'>" . $mytable[1];				} else {					$LinkList .= "<OPTION Value='" . $mytable[1] . "'>" . $mytable[1];				}				$j++;			}		} // while	} // for	if (!$myrow[$Table] && $Table > $j) {		$LinkList = '';	}	return $LinkList;}function CreateLinkEqList($ReportID,$Table) {	global $db;	$sql = "SELECT table1, 		table2, table2criteria, 		table3, table3criteria, 		table4, table4criteria, 		table5, table5criteria, 		table6, table6criteria		FROM ".DBReports." WHERE id='".$ReportID."'";	$Result=DB_query($sql,$db,'','',false,true);	$myrow = DB_fetch_row($Result);	$LinkEqList = ''; $j = 0;	/* Get list of foreign key constraints */	for ($i = 0; $i < $Table; $i++) {		$comments = '';		$sql = "SELECT table1, table2, equation FROM reportlinks WHERE table1 = '" . $myrow[$i] . "'";		$Result=DB_query($sql,$db,'','',false,true);		while($mytable=DB_fetch_row($Result)) {			if ($myrow[$Table+3]) {				if ($myrow[$Table+3] == $mytable[2]){					$LinkEqList .= "<OPTION SELECTED Value='" . $mytable[2] . "'>" . $mytable[2];				} else {					$LinkEqList .= "<OPTION Value='" . $mytable[2] . "'>" . $mytable[2];				}			} else {				if ($j == 0){					$LinkEqList .= "<OPTION SELECTED Value='" . $mytable[2] . "'>" . $mytable[2];				} else {					$LinkEqList .= "<OPTION Value='" . $mytable[2] . "'>" . $mytable[2];				}				$j++;			}		} // while	} // for	if (!$myrow[$Table] && $Table > $j) {		$LinkEqList = '';	}	return $LinkEqList;} // CreateLinkEqListfunction CreateFieldList($ReportID,$FName,$Type) {	global $db;	if ($Type=='Company') { // then pull from the company information table		$myrow[]=CompanyDataBase;	} else { // pull from user selected tables for this report		$sql = "SELECT table1, table2, table3, table4, table5, table6			FROM " . DBReports . " WHERE id='" . $ReportID . "'";		$Result=DB_query($sql,$db,'','',false,true);		$myrow = DB_fetch_row($Result);	}	$FieldList = '';	for ($i = 0; $i < 6; $i++) {		if ($myrow[$i]) {			$Result = DB_show_fields($myrow[$i],$db);			while ($mytable=DB_fetch_row($Result)) {				$fieldname = strtolower($myrow[$i]) . "." . strtolower($mytable[0]);				if ($FName == $fieldname){					$FieldList .= "<OPTION SELECTED Value='" . $fieldname . "'>" . $fieldname . "</OPTION>";				} else {					$FieldList .= "<OPTION Value='" . $fieldname . "'>" . $fieldname . "</OPTION>";				}			} // while		} // if	} // for	return $FieldList;}  // CreateFieldList?>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?