Location: PHPKode > projects > FiForms Framework > FiForms/scripts/createSchema.php
<?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/

*******************************************************************************
createSchema.php

Script to create a database and form on the fly, based on an XML form definition.

*******************************************************************************
**/

    require_once('localconfig.php');
    require_once($FIFORMS_CONFIG['INCLUDE_PATH']."FiReports_FiReportXML.inc.php");

    if(!$FIFORMS_CONFIG['ALLOW_DD_OPERATIONS'])
    {
        die("Data definition operations are disabled on this server. This must be enabled in localconfig.php.");
    }
        $rptDef = new FiReportXML();
        if(!$_POST['formname'])
        {
?>
<html>
<head>
<title>Generate Data Definition for Form <?php echo $_GET['formname']; ?></title>
</head>
<body>
<form action="createSchema.php?app=<?php echo $_GET['app']; ?>" method="post">
<p>
Click the button below to create the necessary database items.
</p>
<input name="formname" type="hidden" value="<?php echo $_GET['formname']?>" />
<input name="app" type="hidden" value="<?php echo $_GET['app']?>" />
<input name="createDB" type="hidden" value="<?php echo $_GET['createDB']?>" />
<input type="submit" value="Create Form Definition" />
</form>
</body>
</html>
<?php
    die();
        }
    $filename = str_replace('.xml','',$_POST['formname']);
    $formname = str_replace(array("..","/","\\","%","*","$","(",")","\"","'",";","`"," ","="),"",$filename);
    if($formname !== $filename || !file_exists($FIFORMS_CONFIG['XML_PATH'].$formname.".xml"))
    {
       die('Invalid Form Name');
    }
    
    
    // use xsltproc to create the script to create the database;
      $xslt = new xsltWrapper();
      $xslt->params['createDB'] = $_POST['createDB'];
      $xslt->params['formpath'] = $FIFORMS_CONFIG['XML_PATH'];
      //die($FIFORMS_CONFIG['XML_PATH'].$filename.".xml");
      $createScript = $xslt->transformFileByFile($FIFORMS_CONFIG['XML_PATH'].$filename.".xml",$FIFORMS_CONFIG['SCRIPT_PATH'].'createSchema.xsl');
      //header('Content-type: text/plain');
      if(!$createScript)
      {
          die($xslt->errorMsg);
      }
      //die($createScript);
          $rptDef->loadDefinition($createScript);
          $rptDef->outputXMLNS = TRUE;
          $rptDef->stylesheet = $GLOBALS['FIFORMS_CONFIG']['SCRIPT_PATH']."createSchemaFinal.xsl"; 
          $rptDef->serverTransform = TRUE;
          $rptDef->mimetype = "text/html";
      $rptDef->generateReport();
?>
Return current item: FiForms Framework