Location: PHPKode > projects > FiForms Framework > FiForms/scripts/createapp.php
<?php
/**
*******************************************************************************

    FiForms -- A collection of PHP classes designed 
    to facilitate rapid development of web-database software

    Copyright (C) 2003-2008  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/

Project Started May 4, 2003
*******************************************************************************
createapp.php

Note: Although this program is licensed under the GPL, certain specified templates contained in this program, and the output of this program which
reflects the contents of the specified template, are specifically released 
into the public domain by the authors of this program. Such templates will
be clearly marked in this source code by a notice similar to the following:

       * The following template is released into the public domain *

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

require_once('localconfig.php');
$checkpass = true;
require_once("authenticate.php");
require_once('promptpage.php');
require_once($FIFORMS_CONFIG['INCLUDE_PATH'].'FiConnect_MySQL.inc.php');
require_once($FIFORMS_CONFIG['AUTH_MODULE']);
$con = new FiConnect_MySQL();
$con->server = $FIFORMS_CONFIG['DEFAULT_SERVER'];
$con->auth = new FiFormsAuth();

if(!$_POST['app'])
{
       $con->list_dbs();
       $dbList = $con->formatResult("<select name=\"database\" onchange=\"document.getElementById('app').value = this.value;   document.getElementById('title').value = this.value+' Application';\"><option selected=\"selected\">***Select A Database***</option>","<option>%Database%</option>","</select>");

promptPage("Enter Application Parameters",<<<EOD
    <form action="createapp.php" method="post">
    <input type="hidden" name="password" value="$_POST[password]" />
    <table>
    <tr><td>Choose Primary Database</td><td>
    $dbList <!-- or&nbsp;Create&nbsp;Database:&nbsp;<input type="text" name="createdatabase" size="15"/> -->
    </td></tr>
    <tr><td>
    Unix Name </td><td>
  <input type="text" name="app" id="app" size="70" onchange=""/></td></tr>
    <tr><td>Application Title</td><td>
    <input type="text" name="title" id="title" size="70" /></td></tr>
    <tr><td>Description</td><td>
    
   
  <textarea name="description" rows="10" cols="70"></textarea></td></tr>
  
    <tr><td>License Category</td><td>
<select name="applcat">
<option value="gpl">GNU General Public License</option>
<option value="lgpl">GNU Lesser General Public License</option>
<option value="mpl">Mozilla Public License</option>
<option value="bsd">BSD License</option>
<option value="other_osi">Other OSI Approved License</option>
<option value="public_domain">Public Domain</option>
<option value="proprietary">Proprietary License</option>
<option value="other">Other License</option>
</select>
</td></tr>
    <tr><th>&nbsp;</th><td><i>Note: the templates generated by this script are released into the public domain, so you can subsequently modify, use, and destribute your XML application under any license you choose.</i></td></tr>
    <tr><td>Overwrite Application?</td><td>
  <input type="checkbox" name="overwrite"  /></td></tr>
  
   
  
    <tr><td></td><td>
    <input type="submit" value="Create Application" /></td></tr></table>
    </form>
    </body>
</html>
EOD
,"2%","2%","96%");
}
else
{
        $appname = $_POST['app'];
        $apptitle = $_POST['title'];
        $appauthor = $_POST['author'];
        $appcopyright = $_POST['copyright'];
        $appsummary = $_POST['description'];
        $appdatabase = $_POST['database'];
        $applcat = $_POST['applcat'];
        $appdir = $FIFORMS_CONFIG['APP_BASE'].$appname;
        $phpdir = $FIFORMS_CONFIG['SCRIPT_PATH']."/app/$appname";
        $year = date('Y');    
        $xmlversion = $_GLOBALS['FIFORMS_CONFIG']['XML_VERSION'];
        $condensed_version = str_replace('.','',$xmlversion);

        
    /* The following template is released into the public domain */
    $appinfo = <<<EOD
<?xml version="1.0" encoding="ISO-8859-1"?>
<application 
        xmlns="http://xml.fiforms.org/FiFormsApplication/" 
        name="$appname" 
        version="$xmlversion"
        url=""
        format="meta"
        >
  <title>$apptitle</title>
  <summary>$appsummary</summary> 
  <author>$appauthor</author>
  <copyright year="$year">$appcopyright</copyright>
  <license category="$applcat"></license>
  <database type="MySQL" host="localhost" socket="" />
  <schema default="default">$appdatabase</schema>
  <objects>
    <directory base="app" path="forms">
    </directory>
    <directory base="app" path="reports">     
    </directory>
    <directory base="app" path="menus">
      <xml name="maintenance.xml" />
      <xml name="main.xml" />
      <xml name="reports.xml" />
    </directory>
    <directory base="app" path="sql">
    </directory>
    <directory base="script" path="">
      <xml name="appconfig.php" />
    </directory>
  </objects>
</application>
EOD;
    $validatexml_sh = <<<EOD
#!/bin/bash
if test -d "\$FIFORMS_PATH"; then
echo FIFORMS_PATH is \$FIFORMS_PATH;
else
FIFORMS_PATH='/usr/share/fiforms';
echo USING DEFAULT PATH /usr/share/fiforms
fi

\$FIFORMS_PATH/doc/schema/11/validatexml.sh $1

EOD;

    /* The following template is released into the public domain */
    $mainmenu = <<<EOD
<?xml version="1.0" encoding="ISO-8859-1"?>
<reports xmlns="http://xml.fiforms.org/FiFormsMenu/" version="$xmlversion">
    <title>$apptitle</title>
    <summary>$appsummary</summary>
    <list href="reports.xml"/>
    <list href="maintenance.xml"/>
    <link href="index.php" title="Return to FiForms Applications Menu"/>
</reports>
EOD;

    /* The following template is released into the public domain */
    $maintenancemenu = <<<EOD
<?xml version="1.0" encoding="ISO-8859-1"?>
<reports xmlns="http://xml.fiforms.org/FiFormsMenu/" version="$xmlversion">
        <title>Maintenance Menu</title>
        <summary>Administrator Utilities</summary>
    <link href="designform.php?app=$appname" title="Create a Form"/>
    <link href="importdb.php?app=$appname" title="Import Database File"/>
    <link href="exportdb.php?app=$appname" title="Export Database File"/>
    <link href="uninstall.php?app=$appname" title="Uninstall Application"/>
        <list concise="concise" href="main.xml" linkback="linkback"/>
</reports>
EOD;

    /* The following template is released into the public domain */
    $reportsmenu = <<<EOD
<?xml version="1.0" encoding="ISO-8859-1"?>
<reports xmlns="http://xml.fiforms.org/FiFormsMenu/" version="$xmlversion">
        <title>Reports</title>
        <summary>Custom Reports and Queries</summary>
        <list concise="concise" href="main.xml" linkback="linkback"/>
</reports>
EOD;

    /* The following template is released into the public domain */

        $appconfig = <<<EOD
<?php
    // Local application-specific configuration file for $appname
    

?>
EOD;

    
$doneprompt = <<<EOD
<ul>
<li><a href="list.php?app=$appname&amp;index=main.xml">Open Application</a></li>
<li><a href="javascript:document.getElementById('designformform').submit()">Create Forms</a></li>
</ul>
<form action="designform.php?app=$appname" method="post" id="designformform">
<input type="hidden" name="password" value="$_POST[password]" />
</form>
EOD;
    if(file_exists($appdir) && !$_POST['overwrite'])
    {
        promptPage('Application Exists','<p>An application directory named '.$appdir.' already exsits. Please go back choose
        a different name or check the box to force overwriting of application.</p><p><a href="javascript:history.go(-1)">Click Here To Return</a></p>','25%','30%','50%');
        die();
    }
    @mkdir($appdir);
    if(!file_exists($appdir))
    {
        $appinfo = htmlentities($appinfo);
        $mainmenu = htmlentities($mainmenu);
        $maintenancemenu = htmlentities($maintenancemenu);
        $reportsmenu = htmlentities($reportsmenu);
        $appconfig = htmlentities($appconfig);
        promptPage('Could not create application directory '.$appdir,<<<EOD
            <p>The application directory $appdir could not be created. Please run the following commands to create the application structure:</p>
            <pre style="background-color: #ffffff; border-color: #000000; border-style: solid; border-width: 1px;">
mkdir $appdir
mkdir $appdir/forms
mkdir $appdir/reports
mkdir $appdir/menus
mkdir $appdir/sql
mkdir $phpdir
</pre>
            <p><i>Now create each of the following files:</i></p>
<h2>$appdir/appinfo.xml</h2>
<pre style="background-color: #ffffff; border-color: #000000; border-style: solid; border-width: 1px;">
$appinfo
</pre>
<h2>$appdir/menus/main.xml</h2>
<pre style="background-color: #ffffff; border-color: #000000; border-style: solid; border-width: 1px;">
$mainmenu
</pre>
<h2>$appdir/menus/maintenance.xml</h2>
<pre style="background-color: #ffffff; border-color: #000000; border-style: solid; border-width: 1px;">
$maintenancemenu
</pre>
<h2>$appdir/menus/reports.xml</h2>
<pre style="background-color: #ffffff; border-color: #000000; border-style: solid; border-width: 1px;">
$reportsmenu
</pre>
<h2>$phpdir/appconfig.php</h2>
<pre style="background-color: #ffffff; border-color: #000000; border-style: solid; border-width: 1px;">
$appconfig
</pre>
              $doneprompt
EOD
,'2%','2%','96%');
        die();
    }
    @mkdir($appdir."/forms");
    @mkdir($appdir."/reports");
    @mkdir($appdir."/menus");
    @mkdir($appdir."/sql");
    @mkdir($phpdir);
    file_put_contents($appdir."/appinfo.xml",$appinfo);
    file_put_contents($appdir."/menus/main.xml",$mainmenu);
    file_put_contents($appdir."/menus/maintenance.xml",$maintenancemenu);
    file_put_contents($appdir."/menus/reports.xml",$reportsmenu);
    file_put_contents($phpdir."/appconfig.php",$appconfig);
    //file_put_contents($phpdir."/installed_files.php",$installed_files);
    promptPage("Application Created",$doneprompt
,"2%","2%","96%");
}
 ?>
Return current item: FiForms Framework