Location: PHPKode > scripts > Installation Automation > installation-automation/documentation.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
    <head>
        <title>Installation Class Documentation</title>
        <style type="text/css">
            body {
                margin: 0;
                padding: 0;
            }
            
            .doc {
                width: 100%;
                height: 100%;
            }
            
            .doc h1 {
                width: 95%;
                border-top: 2px solid #000000;
                border-bottom: 3px dashed #000000;
                background-color: #cecece;
                padding-left: 5%;
                margin: 0;
            }
            
            .doc h2 {
                width: 80%;
                border-bottom: 1px dashed #000000;
                background-color: #cecece;
                padding-left: 20%;
                margin: 0;
            }
            
            .doc p, pre {
                text-indent: 30px;
                background-color: #eeeeee;
                padding: 5px 5px 5px 5px;
                margin: 0;
            }
            
            .doc p a, h1 a {
                text-decoration: none;
            }
            
            .doc ul {
                margin: 0;
                list-style-type: none;
            }
            
            pre {
                border: 1px dashed #000000;
                padding: 5px 5px 5px 5px;
                margin-top: 5px;
            }
            
            pre:before {
                content: 'CODE: ';
                background-color: #000000;
                color: #ffffff;
                width: 100%;
                display: block;
            }
        </style>
    </head>
    <body>
        <h1 style="text-align: center; width: 100%;">Installation Class Documentation</h1>
        <div class="doc">
            <h1 id="contents">Contents</h1>
            <p>
                <ins><ul>
                    <li><a href="#intro">Introduction</a></li>
                    <li><a href="#usability">How to use</a></li>
                    <li><a href="#variables" id="consts.vars">Constants / Variables</a>
                        <ul>
                            <li><a href="#stages">stages</a></li>
                            <li><a href="#use_sql">use_sql</a></li>
                            <li><a href="#sql">sql</a></li>
                            <li><a href="#vcreate_global">create_global</a></li>
                            <li><a href="#gl_loc">gl_loc</a></li>
                            <li><a href="#globals">globals</a></li>
                            <li><a href="#global_type">global_type</a></li>
                            <li><a href="#forms">forms</a></li>
                            <li><a href="#sqls">sqls</a></li>
                            <li><a href="#force_errors">force_errors</a></li>
                            <li><a href="#vdebug">debug</a></li>
                            <li><a href="#redirect_type">redirect_type</a></li>
                            <li><a href="#redirect_loc">redirect_loc</a></li>
                            <li><a href="#verror">error</a></li>
                            <li><a href="#errno">errno</a></li>
                            <li><a href="#global_loc">global_loc</a></li>
                            <li><a href="#vadd">add</a></li>
                        </ul></li>
                    <li><a href="#functions" id="funcs">Functions</a>
                        <ul>
                            <li><a href="#setup">setup</a></li>
                            <li><a href="#cont">cont</a></li>
                            <li><a href="#advance">advance</a></li>
                            <li><a href="#set_sql">set_sql</a></li>
                            <li><a href="#create_global">create_global</a></li>
                            <li><a href="#do_sql">do_sql</a></li>
                            <li><a href="#redirect">redirect</a></li>
                            <li><a href="#error">error</a></li>
                            <li><a href="#debug">debug</a></li>
                        </ul></li>
                    <li><a href="#funcs_repos" id="funcs_repository">Functions Repository</a>
                        <ul>
                            <li><a href="#check_sql">check_sql</a></li>
                            <li><a href="#get_xml">get_xml</a></li>
                            <li><a href="#add">add</a></li>
                        </ul></li>
                    <li><a href="#editing" id="edit">Editing the class</a>
                        <ul>
                            <li><a href="#add_gltypes">Adding Global File Types</a></li>
                            <li><a href="#add_redtypes">Adding Redirection Types</a></li>
                        </ul></li>
                    <li><a href="#examples">Usage Examples</a></li>
                    <li><a href="#credits">Credits / Copyrights</a></li>
                </ul></ins>
            </p>
        </div>
        <div class="doc">
        
            <h1 id="intro">Introduction <a href="#usability">>></a></h1>
            <p>
                This class was created to be an advanced global installation file that would be used to install and setup various PHP applications with MySQL. What this class does essentially is go through the processes you put in the forms and continues from one form to another in order you set the <a href="#stages">stages</a>.
            </p>
            <p>
                This class is mainly for the installation, or the setup of the SQL database and configuration file rather then anything more extreme then that.
            </p>
            <p>
                Also, just to note, the program I have doesn't have a check-spelling utility so, pardon any mistakes you may see in the documentation. If it bothers you too much, I'm sure you know how to open the source of the documentation and the edit those changes... then send me a copy of the mistak-less documentation :)
            </p>
            <p>
                This class is <strong>NOT</strong> a utility to install applications, but a utility to automate the transmission from one stage of installation to another for an application you are writting (along with the SQL and the SQL Global File generation). This class is intended for the use by developers in need of an easy to use installation class that could be easily manipulated to fit their needs. Please enjoy this free, open-source project.
            </p>
            
            <h1 id="usability"><a href="#intro"><<</a> Usability <a href="#variables">>></a></h1>
            <p>
                I tried to make this class as easy to use as possible. Of course, since every application would consist of different SQL table creations and that type of stuff, but other then that, I tried to make the actualy syntax and usability as easy to understand and implement as possible.
            </p>
            <p>
                There are a few things that should be known here. The first thing is that the directory structure is relevant to the class and you would see, as you look through the class source, that some variables ask for directories and/or filenames of some specific files. Some files that the class asks for requires to certain stuff such as the <a href="#sqls">sqls</a>.
            </p>
            <p>
                As any programmer would know, you would need to include the installation class and then initiate the installation class object and store it into a variable. Below is an example of what I am talking about:
                <ins><pre>&lt;?php
    require "install.php";
    
    $inst = new install();
?></pre></ins>
            </p>
            <p>
                The important parts that would go to the installation main page (The page the user who is installing the application would use) is:
                <ins><pre>&lt;?php
    require "install.php";
    
    $inst = new install();
    
    $inst->setup();

    if(isset($_POST['submit']))
    {
        $inst->cont();
    }
?></pre></ins>
            </p>
            <p>
                Anything additional that could go between the class initiation and the <strong>$inst->setup();</strong> is optional, and yet, neccessary if the defaults from the class changes. What I am talking about is the following variables/constants:
                <ins><ul>
                    <li><a href="#stages">stages</a> <a href="#usability_ast1">*</a></li>
                    <li><a href="#vcreate_global">create_global</a></li>
                    <li><a href="#gl_loc">gl_loc</a></li>
                    <li><a href="#globals">globals</a></li>
                    <li><a href="#global_type">global_type</a></li>
                    <li><a href="#forms">forms</a> <a href="#usability_ast1">*</a></li>
                    <li><a href="#sqls">sqls</a></li>
                    <li><a href="#redirect_type">redirect_type</a></li>
                    <li><a href="#redirect_loc">redirect_loc</a> <a href="#usability_ast1">*</a></li>
                </ul></ins>
            </p>
            <p id="usability_ast1" style="font-size: 12px;">
                * = Required/Mandatory field that needs to be set either in class or in installation main page
            </p>
            <p>
                Example usage of those variables are described in their appropriate places throughout this documentation. I suggest you read through them thoroughly to understand the full extend of this class and what you can do with it in terms of configuration.
            </p>
            <p>
                In the example syntax provided above, you will see that the code checks if 'submit' is set VIA post method. This is so that once a user completes a form and clicks submit (which shouldn't be named 'submit' but a different name) and then the form page processes the form (as in validifies the MySQL host, username and password and sends it to the installation class), then there would be another form with the submit button named 'submit' which would work merely as a 'Continue' button. Check out the <a href="#examples">examples</a> on what I am talking about.
            </p>
            <p>
                This class does not allow for independent use to install more than one application. The stages and all of the possible configurations should be hard-coded into the class at the beginning and not the short-handed way (<strong>$inst->stages = array('stage 1', stage 2');</strong>). Sorry for any inconvenience that this could have caused you, but this is how it works.
            </p>
            <p>
                More to your convenience then mine, I tried my best to fill my code with descriptive comments as to what each line of code does, so editing or visualizing what the code does should be easy (I hope). I also tried to keep the code organized with a few additional functions (<a href="#funcs_repos">Functions Repository</a>) that would help you in your form processning.
            </p>
            
            <h1 id="variables"><a href="#usability"><<</a> Constants / Variables <a href="#stages">>></a></h1>
            <p>
                As any other classes, this class has certain configurable variable/constant that serves it's purpose throughout the class. I suggest you read through at least the ones mentioned in the <a href="#usability">previous section</a> of this documentation to understand the full use and extent of this class in terms of basic functionality of this class.
            </p>
            
            <h2 id="stages"><a href="#variables"><<</a> Stages <a href="#use_sql">>></a></h2>
            <p>
                This variable defines the types of stages that there would be in the whole installation process. The different types of stages (or pages in other words) should be stored in an array in the order that the stages would be done by the user using the application which uses this class.
            </p>
            <p>
                The default value for this variable is:
                <ins><pre>array('stage 1','stage 2','stage 3','stage 4'); (Line 18)</pre></ins>
            </p>
            <p>
                The functions that use this array are <a href="#setup">setup</a>, <a href="#cont">cont</a>, and <a href="#advance">advance</a>. What they use this array for is to determine on which stage the user is on, which form to include, what is the next stage and redirecting the user to the next stage when the need arises.
            </p>
            
            <h2 id="use_sql"><a href="#stages"><<</a> use_sql <a href="#sql">>></a></h2>
            <p>
                This variable is more of a preference variable that performs different functions if set to different things. The possible values that it could be set to are:<br /><br />
                <ins><ul>
                    <li><strong>true</strong> - If you have an SQL file and you want it carried out. (Default)</li>
                    <li><strong>false</strong> - No matter about the SQL file... ignore that file completely.</li>
                </ul></ins>
            </p>
            <p>
                This variable and <a href="#sqls">sqls</a> are directly related in their functionality and they are used only with each other. This would make more sense later on.
            </p>
            
            <h2 id="sql"><a href="#use_sql"><<</a> sql <a href="#vcreate_global">>></a></h2>
            <p>
                What this variable does is hold the submitted host, username, password and database name of the MySQL server that the user submits. This variable is later on used in <a href="#create_global">create_global</a> and <a href="#do_sql">do_sql</a> for certain reasons. This variable is set from your database form (a stage that requests database information), and that form should be submitted to <a href="#set_sql">set_sql</a>. An example of what I am talking about is:
                <ins><pre>&lt;form method="post" action="&lt;?=$_SERVER['REQUEST_URI'];?>">
&lt;p>Database Name: &lt;input type="text" name="dbname" size="10" />&lt;br />
   MySQL User: &lt;input type="text" name="sqluser" size="10" />&lt;br />
   MySQL Host: &lt;input type="text" name="sqlhost" size="10" />&lt;br />
   MySQL Pass: &lt;input type="password" name="sqlpass" size="10" />&lt;br />
   Table Prefix: &lt;input type="text" name="tblpre" size="10" value="upl_" />&lt;br />
   &lt;input type="submit" name="fsubmit" value="Submit" /> &lt;input type="reset" value="Reset" />
&lt;/p>&lt;/form>
&lt;?php
    if(isset($_POST['fsubmit']))
    {
        $inst = new instal();

        $inst-><a href="#set_sql">set_sql</a>($_POST['sqlhost'], $_POST['sqluser'],  $_POST['sqlpass'], $_POST['dbname'], $_POST['tblpre']);
    }
?>
&lt;form method="post" action="&lt;?=$_SERVER['REQUEST_URI'];?>">
&lt;p>&lt;input type="image" name="submit" value="Continue" />&lt;/p>
&lt;/form></pre></ins>
            </p>
            <p>
                What that does is submits the user submitted data and passes it into the <a href="#set_sql">set_sql</a> function. That function then uses those passed arguements to set the sql array that would be used throughout some functions mentioned before. After that it gives you another form to continue to another page. You would understand that a bit more if you remember the syntax example code given in <a href="#usability">usability</a> part of the documentation. You would notice that the syntax example there checks for the existence of 'fsubmit' before it continues (<a href="#cont">cont</a>), which is an important function in automation of this installation class.
            </p>
            <p>
                If you read the example code given in <a href="#usability">usability</a> you will see that that code example is checkinf for the existence of 'submit' in the POST method. It should be set in the form page when all the processing is done.
            </p>
            
            <h2 id="vcreate_global"><a href="#sql"><<</a> create_global <a href="#gl_loc">>></a></h2>
            <p>
                This variable merely turns on/off the generation of an SQL Global File. Possible values that it could be set to are:
            </p>
            <p>
                <ins><ul>
                    <li><strong>true</strong> - You want the SQL Global File to be generated. (Default)</li>
                    <li><strong>false</strong> - You don't want the SQL Global File to be generated.</li>
                </ul></ins>
            </p>
            <p>
                To explain the SQL Global File a little bit, what's inside of it is the information stored into the <a href="#sql">sql</a> array... the MySQL host, user, pass, database name and the table prefix for easy access. Read more in <a href="#create_global">create_global</a> (The function for this) to get more information on it.
            </p>
            
            <h2 id="gl_loc"><a href="#vcreate_global"><<</a> gl_loc <a href="#globals">>></a></h2>
            <p>
                This variable holds the directory in which the SQL Global File would be created to. This variable would be significant if, and only if <a href="#vcreate_global">create_global</a> is set to true.
            </p>
            
            <h2 id="globals"><a href="#gl_loc"><<</a> globals <a href="#global_type">>></a></h2>
            <p>
                This variable holds the actual name for the global file (does <strong>NOT</strong> include the dot and file extension at the name). This variable is significant if, and only if <a href="#vcreate_global">create_global</a> is set to true. An example of a valid value for this would be 'global'.
            </p>
            
            <h2 id="global_type"><a href="#globals"><<</a> global_type <a href="#forms">>></a></h2>
            <p>
                This variable holds the type that the global file would be. As the previous two, it is significant if, and only if <a href="#vcreate_global">create_global</a> is set to true. Possible arguements that could this variable could be set (currently) are:
            </p>
            <p>
                <ins><ul>
                    <li><strong>XML</strong> - The SQL Global File generated would be an XML file. (Default)</li>
                    <li><strong>PHP</strong> - The SQL Global File generated would be a PHP file.</li>
                </ul></ins>
            </p>
            <p>
                This also would be used as the extension of the global file... this is why you need to leave out the extension at the global file name you set at <a href="#globals">globals</a>.
            </p>
            
            <h2 id="forms"><a href="#global_type"><<</a> forms <a href="#sqls">>></a></h2>
            <p>
                This variable holds the directory where the neccessary forms are located at. There should be the same amount of forms as there are <a href="#stages">stages</a> and they should be named the same as the <a href="#stages">stages</a>.
            </p>
            
            <h2 id="sqls"><a href="#forms"><<</a> sqls <a href="#force_errors">>></a></h2>
            <p>
                This variable holds the full URL to the file holding the SQL queries that would be carried out at the end. The document is supposed to have at least one array and (currently) max of two arrays. The first array would hold the CREATE SQL queries and that array should be named <strong>$create</strong>, and the other array would hold the INSERT SQL queries and that array should be named <strong>$insert</strong>. An example of what I am talking about is:
            </p>
            <p>
                <ins><pre>&lt;?php
    $create = array('CREATE TABLE Persons ( P_Id int, LastName varchar(255), FirstName varchar(255), Address varchar(255), City varchar(255))');
    $insert = array("INSERT INTO Persons VALUES (4,'Nilsen', 'Johan', 'Bakken 2', 'Stavanger')");
?></pre></ins>
            </p>
            <p>
                There could be as many CREATE or INSERT queries in there as you need, but keep the CREATE statement as CREATE TABLE and <strong>NOT</strong> CREATE DATABASE since most MySQL users don't allow their average MySQL user to be able to create a database for security reasons.
            </p>
            
            <h2 id="force_errors"><a href="#sqls"><<</a> force_errors <a href="#vdebug">>></a></h2>
            <p>
                What this variable does is force the script to die and print the error on each occurent if any occures. It will die and print the first one it comes accross in the script execution. The possible values that could go into it are:
            </p>
            <p>
                <ins><ul>
                    <li><strong>true</strong> - You want to force the script to die and print the errors on screen.</li>
                    <li><strong>false</strong> - You don't want to force the script to die and print the errors on screen. (Default)</li>
                </ul></ins>
            </p>
            
            <h2 id="vdebug"><a href="#force_errors"><<</a> debug <a href="#redirect_type">>></a></h2>
            <p>
                This variable turns the debug mode on/off. The functionality this variable allows could be combined with <a href="#force_errors">force_errors</a>, although I am not saying it would be enhanced with the combination.
            </p>
            <p>
                <ins><ul>
                    <li><strong>true</strong> - You want to 'debug' the error upon it's occurence. (Default)</li>
                    <li><strong>false</strong> - You don't want to 'debug' the error upon it's occurence.</li>
                </ul></ins>
            </p>
            
            <h2 id="redirect_type"><a href="#vdebug"><<</a> redirect_type <a href="#redirect_loc">>></a></h2>
            <p>
                This variable holds the type of redirection we would use for the class's redirection needs. Possible values it could be set to are:
            </p>
            <p>
                <ins><ul>
                    <li><strong>HEADER</strong> - Redirection would be carried out through the Headers.</li>
                    <li><strong>JavaScript</strong> - Redirection would be carried out through the JavaScript window location script. (Default)</li>
                </ul></ins>
            </p>
            
            <h2 id="redirect_loc"><a href="#redirect_type"><<</a> redirect_loc <a href="#verror">>></a></h2>
            <p>
                This variable holds the full URI where the installation script should redirect to once the installation is finished (This class determines if installation is finished if it has finished with the last stage). Since there is an unknown problem with the header redirection on this part, I hard-coded the value of <a href="#redirect_type">redirect_type</a> to 'JavaScript' right before the execution of the redirection to the main page. HEADER works fine between the stages though.
            </p>
            
            <h2 id="verror"><a href="#redirect_loc"><<</a> error <a href="#errno">>></a></h2>
            <p>
                This variable holds an array of all generated errors in the class. This variable is set by itself, so don't mess with it.
            </p>
            
            <h2 id="errno"><a href="#verror"><<</a> errno <a href="#global_loc">>></a></h2>
            <p>
                This holds the total number of generated errors in the class. This variable is set by itself, so don't mess with it.
            </p>
            
            <h2 id="global_loc"><a href="#errno"><<</a> global_loc <a href="#vadd">>></a></h2>
            <p>
                This variable holds the parsed URL to the generated SQL Global File. This is set by it self so don't mess with it.
            </p>
            
            <h2 id="vadd"><a href="#global_loc"><<</a> add <a href="#functions">>></a></h2>
            <p>
                This variable is there for any other needs that you may have from an installation class. This variable is for you to set to whatever you want, maybe to set something that an SQL query uses in the SQL Query file (<a href="#sqls">sqls</a>). It is set through the function <a href="#add">add</a> much like <a href="#set_sql">set_sql</a> sets <a href="#sql">sql</a>.
            </p>
            
            <h1 id="functions"><a href="#vadd"><<</a> Functions <a href="#setup">>></a></h1>
            <p>
                There are some important functions and some un-important functions. The functions that you absolutely <strong>should</strong> become familiar with are <a href="#setup">setup</a> and <a href="#cont">cont</a>, since they are the brains of the whole automation process. If you need to edit some of the functionality I suggest you look through the <a href="#editing">editing</a> section of this documentation, and if that doesn't satisfy your need, then read on about the functions and see if that helps you any.
            </p>
            
            <h2 id="setup"><a href="#functions"><<</a> setup <a href="#cont">>></a></h2>
            <p>
                This is one of the important functions that is responsible for one part of the automation of the class: in includes the form for the current stage. (Be sure the form is the same name of the stage). It checks for what the current stage is and includes the form. If the previous stage finished was the last stage, then <strong>setup</strong> would not be called on, but the the user would be redirected to the location you specified in <a href="#redirect_loc">redirect_loc</a>.
            </p>
            
            <h2 id="cont"><a href="#setup"><<</a> cont <a href="#advance">>></a></h2>
            <p>
                This function is the important function that is held responsible for the redirection to the next stage from the current stage. It calls on a function (<a href="#advance">advance</a>) which determines the next stage and then this function determines if the user is finished with the installation. If the user is finished with the installation, then this function goes through which ever is suitable for the situation.
            </p>
            
            <h2 id="advance"><a href="#cont"><<</a> advance <a href="#set_sql">>></a></h2>
            <p>
                This functions determines the next stage from the current stage.
            </p>
            
            <h2 id="set_sql"><a href="#advance"><<</a> set_sql <a href="#create_global">>></a></h2>
            <p>
                This function should be called upon when you are submitting the database information and need to set the SQL array to whatever it needs to be. See an example given on <a href="#sql">sql</a> (the variable).
            </p>
            <p>
                Because of the stages and since the class creates the global file at the end of the whole installation process, we are storing the submitted information into a session, so make sure you start the session with <strong><a href="http://www.php.net/session_start">session_start</a></strong>.
            </p>
            
            <h2 id="create_global"><a href="#set_sql"><<</a> create_global <a href="#do_sql">>></a></h2>
            <p>
                This function generates the SQL GLobal File if you have set it on with <a href="#vcreate_global">create_global</a> (The variable, not the function). This function in it's current states only generates XML and PHP types (Depends which one you requested with <a href="#global_type">global_type</a>). If you want to create more types please read on it in my <a href="#add_gltypes">editing</a> section.
            </p>
            
            <h2 id="do_sql"><a href="#create_global"><<</a> do_sql <a href="#redirect">>></a></h2>
            <p>
                This function carries out the SQL Queries found in the variable, <a href="#sqls">sqls</a>, if you set it on using <a href="#use_sql">use_sql</a>. To understand it more, read <a href="#sqls">sqls</a> if you havenm't done so already.
            </p>
            
            <h2 id="redirect"><a href="#do_sql"><<</a> redirect <a href="#error">>></a></h2>
            <p>
                This functions determines what type of redirection you need (using <a href="#redirect_type">redirect_type</a>) and redirects the user either to the next stage or to the location you specified in <a href="#redirect_loc">redirect_loc</a> once the installation process is complete.
            </p>
            
            <h2 id="error"><a href="#redirect"><<</a> error <a href="#debug">>></a></h2>
            <p>
                This function is a basic error processing function that sets the error array to it's appropriate value submitted into it as an arguement and it parses the error array using the configurable variables set at class start. Those variables are (They were talked about previously):<br /><br />
                <ins><ul>
                    <li><a href="#force_errors">force_errors</a></li>
                    <li><a href="#vdebug">debug</a></li>
                </ul></ins>
            </p>
            <p>
                If you have the <a href="#force_errors">force_errors</a> set to true, then this function would die on error generation and print out the error. If <a href="#vdebug">debug</a> is set to true, then this function would call on <a href="#debug">debug</a> and basically do the same thing.
            </p>
            
            <h2 id="debug"><a href="#error"><<</a> debug <a href="#funcs_repos">>></a></h2>
            <p>
                This function would print the error after it was generated and carry out with the installation class. I suggest you use it like this only for troubleshooting and not for the actual application, as it could completely ruin the installation class. I also would suggest you do this without doing any SQL or creating the SQL Global File, because if there would be any errors, they could mess things up, or create new ones on the second go. If you set <a href="#force_errors">force_errors</a> to true, than this function would act exactly the same as <a href="#error">error</a>.
            </p>
            
            <h1 id="funcs_repos"><a href="#debug"><<</a> Functions Repository <a href="#check_sql">>></a></h1>
            <p>
                Along with this class, I included some essential and useful functions for you to use to enhance your experience with this class. Some functions here are for you to use later on (Such as <a href="#get_xml">get_xml</a>). This functions are here to help with your installation stages that you may have (Much of the functions here deal with SQL).
            </p>
            
            <h2 id="check_sql"><a href="#funcs_repos"><<</a> check_sql <a href="#get_xml">>></a></h2>
            <p>
                This function checks the validity of the MySQL Credentials (MySQL Host, user, password and database name) submitted by the user. This is meant to be used with conjunction with your MySQL/Database stage. This function asks for all, host, user, password and database name, since it checks for the MySQL Credentials and the database.
            </p>
            
            <h2 id="get_xml"><a href="#check_sql"><<</a> get_xml <a href="#add">>></a></h2>
            <p>
                This function is for your later use if you decided to use an XML SQL Global File. This function is to show you how to retrieve a certain value from the XML file. Below is a simple example:<br />
                <strong>global.xml</strong>
                <ins><pre>&lt;?xml version="1.0" encoding="ISO-8859-1"?>
&lt;database>
    &lt;host>localhost&lt;/host>
    &lt;user>root&lt;/user>
    &lt;pass>my_sql_pass&lt;/pass>
    &lt;dbname>my_sql_database&lt;/dbname>
    &lt;table_prefix>tbl_prefix_&lt;/table_prefix>
&lt;/database></pre></ins>
                <strong>retrieve.php</strong>
                <ins><pre>&lt;?php
function get_xml($what)
{
    // Loading the global XML file
    $db = (array) simplexml_load_file('global.xml');
    
    // Returing the requested variable to the user
    return (string) $db[$what];
}

$link = mysql_connect(get_xml('host'), get_xml('user'), get_xml('pass'));
?></pre></ins>
            </p>
            <p>
                Obviously, the syntax for that would be a little different if you are coding in OOP (Object Oriented Programming: classes). Which would mean that the above usage of <strong>get_xml('value')</strong> would change to <strong>$this->get_xml('value')</strong>.
            </p>
            
            <h2 id="add"><a href="#get_xml"><<</a> add <a href="#editing">>></a></h2>
            <p>
                This function is for your other installation needs. This function sets the variable <a href="#vadd">add</a> to whatever you request this to be. The code for this function looks like:
                <ins><pre>&lt;?php
function add($value, $key = 00)
{
    // Checking if the key should be numeric
    if($key == 00)
    {
        // Getting the next available numeric key so we wouldn't over ride a value
        foreach($this->add as $id => $val)
        {
            // Checking if the key is numeric
            if(is_numeric($id))
            {
                $keyed = $id;
            }
        }
        
        // Incrementing the last numeric key by one
        $key = $keyed + 1;
        
        // Unsetting the useless $val
        unset($val);
    }
    
    // Generating the array 
    $this->add[$key] = $value;
    
    // Returning the entire array
    return $this->add;
}
?></pre></ins>
            </p>
            <p>
                There are a couple things you should know about this class as far as it's usage goes, as I tried to make it as flexible to your needs as much as possible. This function is capable of creating an array with numeric keys that goes in order and textual keys with those keys mixed around.
            </p>
            <p>
                A simple explanation of the two arguments that is configurable here are:<br /><br />
                <ins><ul>
                    <li><strong>$value</strong> - The value to add to the additional variable (Should be a string)</li>
                    <li><strong>$key</strong> - This variable could be set to the following possible values (Determines the type of key we will have... numeric or textual).
                        <ul>
                            <li><strong>00</strong> - This would make the function generate numeric keys incrementing by one starting from 0 (Default array parsing by PHP... default value is 00).</li>
                            <li><strong>value</strong> - Not 'value' exactly, but whatever you need the key to be.</li>
                        </ul>
                    </li>
                </ul></ins>
            </p>
            
            <h1 id="editing"><a href="#add"><<</a> Editing the Class <a href="#add_gltypes">>></a></h1>
            <p>
                I tried to make it easy for you to edit this class. I put descriptions of each function there, and just about at every line of PHP code, there is a comment explaining what it does, so it should be easy for you to go through the class and know what is happening there. This (I hope) would make it easy for you to know what you need to do to edit or manipulate the class in any way you need to.
            </p>
            <p>
                You need to know what you are doing before changing/manipulating the code so you won't mess it up. Before editing/manipulating the class, I suggest you either save a back-up copy or remember when you downloaded the class from, so you could easily replace the one you accidentally messed up.
            </p>
            
            <h2 id="add_gltypes"><a href="#editing"><<</a> Adding Global File Types <a href="#add_redtypes">>></a></h2>
            <p>
                Adding global types should be easy. If you look at the code for the function <a href="#create_global">create_global</a>, you would see that it is using a switch that checks the file type you need, and then it sets the variable <strong>$content</strong> with the code holding the required information for the file. The code is in the language that the global file type would be in. Also, notice that the global file type variable <a href="#global_type">global_type</a> is also used as the extension of the filename when it is created. The code I'm talking about is:
                <ins><pre>&lt;?php
function create_global()
{
    // Creating the location where the global would be and it's name with extension type
    $global_loc = $this->gl_loc . $this->globals . '.' . strtolower($this->global_type);
    
    // Checking what kind of global file it would be... PHP or XML
    switch($this->global_type)
    {
        case 'XML':
            $content = &lt;&lt;&lt;EOT
&lt;?xml version="1.0" encoding="ISO-8859-1"?>
&lt;database>
&lt;host>{$_SESSION['sql']['HOST']}&lt;/host>
&lt;user>{$_SESSION['sql']['USER']}&lt;/user>
&lt;pass>{$_SESSION['sql']['PASS']}&lt;/pass>
&lt;dbname>{$_SESSION['sql']['DBASE']}&lt;/dbname>
&lt;table_prefix>{$_SESSION['sql']['TBL_PRE']}&lt;/table_prefix>
&lt;/database>
EOT;
            
            break;
        case 'PHP':
            $content = &lt;&lt;&lt;EOT
&lt;?php

/* The global configuration file */

// The MySQL Host
\$host = "{$_SESSION['sql']['HOST']}";

// The MySQL User
\$user = "{$_SESSION['sql']['USER']}";

// The MySQL password
\$pass = "{$_SESSION['sql']['PASS']}";

// The MySQL Database Name
\$dbname = "{$_SESSION['sql']['DBASE']}";

// The MySQL Table Prefix
\$tbl_pre = "{$_SESSION['sql']['TBL_PRE']}";

?>
EOT;
            break;
        default:
            // Neither of the correct options were given. Defaulting to XML
            $this->global_type = 'XML';
            $this->create_global();
            break;
    }
    
    // Setting the location of the global file into the class variable
    $this->global_loc = $global_loc;
    
    // Creating the Global File
    if(touch($this->global_loc) != false)
    {
        // Putting the contents into the global file
        if(file_put_contents($global_loc, $content) != false)
        {
            // Checking if we are to create SQL tables into the created database
            if($this->use_sql == true)
            {
                $this->do_sql();
            }
            else
            {
                $this->redirect($this->redirect_loc);
            }
        }
        
        // The contents weren't put into the global file. Set the error and return false
        $this->error('GLOBAL_FILE_CONTENT', "Contents were failed to be put into the global file  {$this->global_loc}");
        return false;
    }
    
    // The file failed to be created. Set the error and return false.
    $this->error('GLOBAL_FILE_CREATION', "The global file ({$this->global_loc}) failed to be created.");
    return false;
}

EOT;
            break;
        default:
            // Neither of the correct options were given. Defaulting to XML
            $this->global_type = 'XML';
            $this->create_global();
            break;
    }
    
    // Setting the location of the global file into the class variable
    $this->global_loc = $global_loc;
    
    // Creating the Global File
    if(touch($this->global_loc) != false)
    {
        // Putting the contents into the global file
        if(file_put_contents($global_loc, $content) != false)
        {
            // Checking if we are to create SQL tables into the created database
            if($this->use_sql == true)
            {
                $this->do_sql();
            }
            else
            {
                $this->redirect($this->redirect_loc);
            }
        }
        
        // The contents weren't put into the global file. Set the error and return false
        $this->error('GLOBAL_FILE_CONTENT', "Contents were failed to be put into the global file  {$this->global_loc}");
        return false;
    }
    
    // The file failed to be created. Set the error and return false.
    $this->error('GLOBAL_FILE_CREATION', "The global file ({$this->global_loc}) failed to be created.");
    return false;
}
?></pre></ins>
            </p>
            <p>
                To add another possible global file type, simply add another case in there with the variable <strong>$content</strong> holding the code in the language that the file type should hold. Simple as that.
            </p>
            
            <h2 id="add_redtypes"><a href="#add_gltypes"><<</a> Adding Redirection Types <a href="#examples">>></a></h2>
            <p>
                Adding redirection types is just as easy. The function uses the switch statement, where all you have to do is add another case checking the variable <strong>$this->redirect_type</strong> for a possible redirection type you could have. The function looks like:
                <ins><pre>&lt;?php
function redirect($page)
{
    // Redirecting the user to the next stage based on the preferable redirection type
    switch($this->redirect_type)
    {
        case "HEADER":
            // It's header... turning the output buffering on
            ob_start();
            
            // Redirecting the user
            header("LOCATION: {$page}");
            
            // Sending the content and turning the output buffer off
            ob_end_flush();
            break;
        case "JavaScript":
            // Redirecting the user with JavaScript
            echo "&lt;script language=\"JavaScript\">window.location=\"{$page}\";&lt;/script>";
            break:
        default:
            // Not one possible redirection type is given... using JavaScript by default
            $this->redirect_type = 'JavaScript';
            $this->redirect($page);
            break;
    }
}
?></pre></ins>
            </p>
            
            <h1 id="examples"><a href="#add_redtypes"><<</a> Examples <a href="#credits">>></a></h1>
            <p>
                The following example uses the following configurations:<br /><br />
                <ins><ul>
                    <li><a href="#vcreate_global">$create_global</a> = true</li>
                    <li><a href="#use_sql">$use_sql</a> = false</li>
                    <li><a href="#force_errors">$force_errors</a> = false</li>
                    <li><a href="#vdebug">$debug</a> = false</li>
                </ul></ins>
                <a href="example.php">Example</a>
            </p>
            
            <h1 id="credits"><a href="#examples"><<</a> Credits</h1>
            <p>
                Creator(s) of this class is:<br /><br />
                <ins><ul>
                    <li><a href="http://www.wedevoy.com">Bogey</a></li>
                </ul></ins>
            </p>
        </div>
    </body>
</html>
Return current item: Installation Automation