<?php
/**
*******************************************************************************
FiForms -- A collection of PHP classes designed
to facilitate rapid development of web-database software
Copyright (C) 2003 - 2007 Daniel McFeeters
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
The original author of this library can be contacted at the following
address:
Daniel McFeeters
182 Baker Rd.
Faubush, KY 42544-6526
email:databases [at] fiforms [dot] org
http://www.fiforms.org/
*******************************************************************************
viewform.php
Script to interpret an XML Form definition and build a form using FiForms
on the fly.
*******************************************************************************
**/
$startTime = microtime(true);
require_once('localconfig.php');
if($FIFORMS_CONFIG['USE_COMBINED'])
{
include_once(dirname(__FILE__).'/FiForms_combined.inc.php');
}
else
{
include_once($FIFORMS_CONFIG['INCLUDE_PATH'].'FiForms_genericIcons.inc.php');
include_once($FIFORMS_CONFIG['INCLUDE_PATH'].'FiForms_global.inc.php');
include_once($FIFORMS_CONFIG['INCLUDE_PATH'].'FiForms_FiForm.inc.php');
}
//print_r($FIFORMS_CONFIG);die();
if(!$FIFORMS_CONFIG['XML_PATH'])
{
die("View Form script is disabled on this server. This must be enabled in localconfig.php.");
}
$filename = str_replace('.xml','',$_GET['formname']);
$formname = str_replace(array("..","/","\\","%","*","$","(",")","\"","'",";","`"," ","="),"",$filename);
if($formname !== $filename || !file_exists($FIFORMS_CONFIG['XML_PATH'].$formname.".xml"))
{
die('Invalid Form Name');
}
// Create the DOMDocument object and load the XML form definition into $doc
$doc = new DOMDocument;
$doc->load($FIFORMS_CONFIG['XML_PATH'].$filename.".xml");
$frm = new FiForm();
$frm->loadXMLDef($doc);
//print_r($frm);die();
$logStat = $GLOBALS['FIFORMS_CONFIG']['PERF_STAT'];
$output = $frm->drawFormPage();
$encData = false;
// adapted from tinymce_compressor
$supportsGzip = false;
if (isset($_SERVER['HTTP_ACCEPT_ENCODING']))
{
$encodings = explode(',', strtolower(preg_replace("/\s+/", "", $_SERVER['HTTP_ACCEPT_ENCODING'])));
if ((in_array('gzip', $encodings) || in_array('x-gzip', $encodings)) && function_exists('gzencode') && !ini_get('zlib.output_compression'))
{
$enc = in_array('x-gzip', $encodings) ? "x-gzip" : "gzip";
$supportsGzip = true;
}
}
if(!$GLOBALS['FIFORMS_CONFIG']['DISABLE_GZIP'] && $supportsGzip)
{
header('Vary: Accept-Encoding');
header('Content-encoding: '.$enc);
$encData = gzencode($output);
echo $encData;
}
else
{
echo $output;
}
if($logStat)
{
$size = strlen($output);
$encsize = $encData ? strlen($encData) : $size;
$endTime = microtime(true);
$login = $_SERVER['PHP_AUTH_USER'];
$url = $_SERVER['REQUEST_URI'];
$sheetView = $frm->sheetView ? 'Y':'N';
$sql = addslashes($frm->wrapper->debugQueries);
$totaltime = $endTime - $startTime;
$dbtime = $frm->timing['QUERYEND'] - $frm->timing['QUERYSTART'];
$fpstype = $_POST ? 'POST' : 'GET';
$timepoints = "Start: $startTime\n";
$lasttime = $startTime;
foreach($frm->timing as $point => $time)
{
$lapse = $time - $lasttime;
$timepoints .= "$point: $time ($lapse)\n";
$lasttime = $time;
}
$timepoints .= "End: $endTime\n";
EOD;
@selectValue("INSERT INTO fiforms_performance.perfstat (FPS_LOGIN, FPS_APP, FPS_FORM, FPS_SHEETVIEW, FPS_URL, FPS_SQL, FPS_OUTPUTSIZE, FPS_DBTIME, FPS_TOTALTIME, FPS_TIMEPOINTS, FPS_TYPE, FPS_ENCODEDSIZE)
VALUES ('$login','$FIFORMS_CONFIG[XML_PATH]','$formname','$sheetView','$url','$sql','$size','$dbtime','$totaltime','$timepoints','$fpstype','$encsize');");
echo mysql_error();
}
?>