rcfunctions.inc

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

INC
813
字号
	$sql = "UPDATE ".DBRptFields." SET seqnum='".$NewSeqNum."' WHERE id = ".$OrigID.";";	$Result=DB_query($sql,$db,'','',false,true);	return true;}function InsertSequence($SeqNum, $EntryType) {// This function creates a hole in the sequencing to allow inserting new data	global $db, $ReportID, $Type;	if (!$SeqNum) $SeqNum = 999; // set sequence to max if not entered	// read the sequence numbers for the given EntryType	$sql = "SELECT id FROM ".DBRptFields." 		WHERE reportid = ".$ReportID." AND entrytype = '".$EntryType."' 		ORDER BY seqnum;";	$Result=DB_query($sql,$db,'','',false,true);	while ($FieldID = DB_fetch_array($Result)) { $IDList[] = $FieldID['id']; }	$NumRows = DB_num_rows($Result);	if (!$IDList OR ($NumRows < $SeqNum)) { $SeqNum = DB_num_rows($Result) + 1;	}	if ($SeqNum <= $NumRows) { // shift the fields down to make a sequence hole		for ($j=$SeqNum-1; $j<$NumRows; $j++) {			$sql = "UPDATE ".DBRptFields." SET seqnum = ".($j+2)." WHERE id=".$IDList[$j].";";			$Result=DB_query($sql,$db,'','',false,true);		}	}	if (!isset($_POST['Visible'])) $Visible = '0'; else $Visible = $_POST['Visible'];	if (!isset($_POST['ColumnBreak'])) $ColumnBreak = '0'; else $ColumnBreak = $_POST['ColumnBreak'];	if (!isset($_POST['Params'])) {		$Params = '0'; 	} elseif ($Type=='frm' AND $EntryType=='fieldlist') {		$EntryIndex['index'] = $_POST['Params'];		$Params = serialize($EntryIndex);	} else {		$Params = $_POST['Params'];	}	$sql = "INSERT INTO ".DBRptFields."			(reportid, entrytype, seqnum, fieldname, displaydesc, visible, columnbreak, params)		VALUES (".$ReportID.",'".$EntryType."',".$SeqNum.",'".DB_escape_string($_POST['FieldName'])."',			'".DB_escape_string($_POST['DisplayDesc'])."','".$Visible."','".$ColumnBreak."','".$Params."');";	$Result=DB_query($sql,$db,'','',false,true);	return $SeqNum;}function DeleteSequence($SeqNum, $EntryType) {// This function removes a sequence field and fills the sequence hole left behind	global $db, $ReportID;	//  delete the sequence number from the list	$sql = "DELETE FROM ".DBRptFields." 		WHERE reportid = ".$ReportID." AND entrytype = '".$EntryType."' AND seqnum = ".$SeqNum.";";	$Result=DB_query($sql,$db,'','',false,true);	// read in the remaining sequences and re-number	$sql = "SELECT id FROM ".DBRptFields." 		WHERE reportid = ".$ReportID." AND entrytype = '".$EntryType."' 		ORDER BY seqnum;";	$Result=DB_query($sql,$db,'','',false,true);	while ($FieldID = DB_fetch_array($Result)) { $IDList[] = $FieldID['id']; }	$NumRows = DB_num_rows($Result);	if ($NumRows >= $SeqNum) {	// then not at end of list re-number sequences		for ($j=$SeqNum-1; $j<$NumRows; $j++) {			$sql = "UPDATE ".DBRptFields." SET seqnum = ".($j+1)." WHERE id=".$IDList[$j].";";			$Result=DB_query($sql,$db,'','',false,true);		}	}	return true;}function InsertFormSeq(&$Params, $Insert) {// This function creates a hole in the sequencing to allow inserting new form table field data	$SeqNum = $_POST['TblSeqNum'];	if (!$SeqNum) $SeqNum = count($Params['Seq'])+1; // set sequence to last entry if not entered	if (isset($Params['Seq'][$SeqNum-1]) AND $Insert=='insert') { 		// then the sequence number exists make a hole for this insert		for ($j=count($Params['Seq']); $j>=$SeqNum; $j--) {			$Params['Seq'][$j] = $Params['Seq'][$j-1]; // move the array element down one			$Params['Seq'][$j]['TblSeqNum'] = $j+1; // increment the sequence number		}	} // else it's an update which we do anyway	// Fill in the new data	$Params['Seq'][$SeqNum-1]['TblSeqNum'] = $SeqNum;	$Params['Seq'][$SeqNum-1]['TblField'] = $_POST['TblField'];	$Params['Seq'][$SeqNum-1]['TblDesc'] = $_POST['TblDesc'];	$Params['Seq'][$SeqNum-1]['Processing'] = $_POST['Processing'];	$Params['Seq'][$SeqNum-1]['Font'] = $_POST['Font'];	$Params['Seq'][$SeqNum-1]['FontSize'] = $_POST['FontSize'];	$Params['Seq'][$SeqNum-1]['FontAlign'] = $_POST['FontAlign'];	$Params['Seq'][$SeqNum-1]['FontColor'] = $_POST['FontColor'];	$Params['Seq'][$SeqNum-1]['TblColWidth'] = $_POST['TblColWidth'];	if (!isset($_POST['TblShow'])) $Params['Seq'][$SeqNum-1]['TblShow'] = '0'; 		else $Params['Seq'][$SeqNum-1]['TblShow'] = '1';	return true;}function ModFormTblEntry(&$Params) {	for ($i=1; $i<100; $i++) { // see if a button was pressed		if (isset($_POST['up'.$i.'_x']) AND $i<>1) { // sequence up[i] was pressed, swap it with the element before			$Temp = $Params['Seq'][$i-1];			$Params['Seq'][$i-1] = $Params['Seq'][$i-2];			$Params['Seq'][$i-2] = $Temp;			// update the sequence numbers			$Params['Seq'][$i-1]['TblSeqNum'] = $i;			$Params['Seq'][$i-2]['TblSeqNum'] = $i-1;			return true;		}		if (isset($_POST['dn'.$i.'_x']) AND $i<>count($Params['Seq'])) { // sequence dn[i] was pressed, swap it with the element after			$Temp = $Params['Seq'][$i-1];			$Params['Seq'][$i-1] = $Params['Seq'][$i];			$Params['Seq'][$i] = $Temp;			// update the sequence numbers			$Params['Seq'][$i-1]['TblSeqNum'] = $i;			$Params['Seq'][$i]['TblSeqNum'] = $i+1;			return true;		}		if (isset($_POST['ed'.$i.'_x'])) { // sequence ed[i] was pressed			// set the defaults to the sequence selected			// Set the form with the values from the sequence selected			$Params['TblSeqNum'] = $Params['Seq'][$i-1]['TblSeqNum'];			$Params['TblField'] = $Params['Seq'][$i-1]['TblField'];			$Params['TblDesc'] = $Params['Seq'][$i-1]['TblDesc'];			$Params['Processing'] = $Params['Seq'][$i-1]['Processing'];			$Params['Font'] = $Params['Seq'][$i-1]['Font'];			$Params['FontSize'] = $Params['Seq'][$i-1]['FontSize'];			$Params['FontAlign'] = $Params['Seq'][$i-1]['FontAlign'];			$Params['FontColor'] = $Params['Seq'][$i-1]['FontColor'];			$Params['TblColWidth'] = $Params['Seq'][$i-1]['TblColWidth'];			$Params['TblShow'] = $Params['Seq'][$i-1]['TblShow']; 			return 'edit';		}		if (isset($_POST['rm'.$i.'_x'])) { // sequence rm[i] was pressed, delete the entry			for ($j=$i; $j<count($Params['Seq']); $j++) {				$Params['Seq'][$j-1] = $Params['Seq'][$j];				$Params['Seq'][$j-1]['TblSeqNum'] = $j;			}			$Temp = array_pop($Params['Seq']);			break;		}	}	return true;}function ValidateField($ReportID, $FieldName, $Description) {	global $db, $Type;	// This function checks the fieldname and field reference and validates that it is good.	// first check if a form (fieldname is not provided unless it's the form page break field)	if ($Type=='frm' AND $Description<>'TestField') { // then check for non-zero description unless a fieldname is present		if (strlen($Description)<1) return false; else return true;	}	// fetch the table values to build sql	$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);	$Prefs = DB_fetch_assoc($Result);	// Check for a non-blank entry in the field description or fieldname	if (strlen($FieldName)<1 OR strlen($Description)<1) return false;	// Build the table to search, then test inputs to see if they are valid	$strTable = $Prefs['table1'];	if ($Prefs['table2']) $strTable .= ' INNER JOIN '.$Prefs['table2']. ' ON '.$Prefs['table2criteria'];	if ($Prefs['table3']) $strTable .= ' INNER JOIN '.$Prefs['table3']. ' ON '.$Prefs['table3criteria'];	if ($Prefs['table4']) $strTable .= ' INNER JOIN '.$Prefs['table4']. ' ON '.$Prefs['table4criteria'];	if ($Prefs['table5']) $strTable .= ' INNER JOIN '.$Prefs['table5']. ' ON '.$Prefs['table5criteria'];	if ($Prefs['table6']) $strTable .= ' INNER JOIN '.$Prefs['table6']. ' ON '.$Prefs['table6criteria'];	$sql = "SELECT ".$FieldName." FROM ".$strTable." LIMIT 1";	$Result=DB_query($sql,$db,'','',false,false);	// Try to fetch one row, if we have a row, sql was valid	if (DB_num_rows($Result)<1) return false; else return true;}function ReadDefReports() {	global $ReportGroups;	$dh = opendir(DefRptPath);	$i=0;	while ($DefRpt = readdir($dh)) {		$pinfo = pathinfo(DefRptPath.$DefRpt);		if ($pinfo['extension']=='txt') { // then it's a report file read name and type			$FileLines = file(DefRptPath.$DefRpt);			foreach ($FileLines as $OneLine) { // find the main reports sql statement, language and execute it				if (strpos($OneLine,'ReportData:')===0) { // then it's the line we'er after with reportname and groupname					$GrpPos = strpos($OneLine,"groupname='")+11;					$GrpName = substr($OneLine, $GrpPos, strpos($OneLine, "',", $GrpPos)-$GrpPos);					$RptPos = strpos($OneLine,"reportname='")+12;					$RptName = substr($OneLine, $RptPos, strpos($OneLine, "',", $RptPos)-$RptPos);					$ReportList[$i]['GrpName'] = $GrpName;					$ReportList[$i]['RptName'] = $RptName;					$ReportList[$i]['FileName'] = $pinfo[basename];					$i++;				}			}		}	}	closedir($dh);	$OptionList = '';	$LstGroup = '';	$CloseOptGrp = false;	$i=0;	while ($Temp=$ReportList[$i]) {		if ($Temp['GrpName']<>$LstGroup) { // then it's a new group, close old group and start new group			if ($LstGroup<>'') echo '</optgroup>';			$CloseOptGrp = true; // we need to close the last option group			$LstGroup = $Temp['GrpName'];			$OptionList .= '<optgroup label="'.$ReportGroups[$Temp['GrpName']].'" title="'.$Temp['GrpName'].'">';		}		$GrpMember = $ReportGroups[$Temp['GrpName']];		if (!$GrpMember) $Temp['GrpName'] = RPT_MISC;		$OptionList .= '<option value="'.$Temp['FileName'].'">'.$Temp['RptName'].'</option>';		$i++;	}	if ($CloseOptGrp) $OptionList .= '</optgroup>';	return $OptionList;}function ReadImages($Default) {	$OptionList = '';	$dh = opendir(DefRptPath);	while ($DefRpt = readdir($dh)) {		$pinfo = pathinfo(DefRptPath.$DefRpt);		$Ext = strtoupper($pinfo['extension']);		if ($Ext=='JPG' OR $Ext=='JPEG' OR $Ext=='PNG') { 			if ($Default==$pinfo['basename']) $checked=' selected'; else $checked = '';			$OptionList .= '<option value="'.$pinfo['basename'].'"'.$checked.'> '.$pinfo['basename'].'</option>';		}	}	closedir($dh);	return $OptionList;}function ImportImage() {	global $db;	if ($_POST['ImgChoice']=='Select') { // then a locally stored image was chosen, return with image name		$Rtn['result'] = 'success';		$Rtn['message'] = $_POST['ImgFileName'].RPT_IMP_ERMSG9;		$Rtn['filename'] = $_POST['ImgFileName'];		return $Rtn;	}	$Rtn['result'] = 'error';	if ($_FILES['imagefile']['error']) { // php error uploading file		switch ($_FILES['imagefile']['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['imagefile']['error'].'.';		}	} elseif (!is_uploaded_file($_FILES['imagefile']['tmp_name'])) { // file uploaded		$Rtn['message'] = RPT_IMP_ERMSG10;	} elseif (strpos($_FILES['imagefile']['type'],'image')===false) { // not an imsge file extension		$Rtn['message'] = RPT_IMP_ERMSG6; 	} elseif ($_FILES['imagefile']['size']==0) { // report contains no data, error		$Rtn['message'] = RPT_IMP_ERMSG7;	} else { // passed all error checking, save the image		$success = move_uploaded_file($_FILES['imagefile']['tmp_name'],DefRptPath.$_FILES['imagefile']['name']);		if (!$success) { // someone tried to hack the script			$Rtn['message'] = 'Upload error. File cannot be processed, check directory permissions!';		} else {			$Rtn['result'] = 'success';			$Rtn['message'] = $_FILES['imagefile']['name'].RPT_IMP_ERMSG9;			$Rtn['filename'] = $_FILES['imagefile']['name'];		}	}	return $Rtn;}function ExportReport($ReportID) {	global $db;	$crlf = chr(10);	$CSVOutput = '/* Report Builder Export Tool */'.$crlf;	$CSVOutput .= 'version:1.0'.$crlf;	// Fetch the core report data from table reports	$sql = "SELECT * FROM ".DBReports." WHERE id = ".$ReportID.";";	$Result=DB_query($sql,$db,'','',false,true);	$myrow = DB_fetch_assoc($Result);

⌨️ 快捷键说明

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