Login   Register  
PHP Classes
elePHPant
Icontem

File: example/php2hexv3.0.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Eric Bruggema  >  PHP2HEX  >  example/php2hexv3.0.php  >  Download  
File: example/php2hexv3.0.php
Role: Sample output
Content type: text/plain
Description: Installation script example, this is what the script will create. Download this script to extract the other files as listed (containing the whole PHP2HEX package!)
Class: PHP2HEX
Generate PHP application installation scripts
Author: By
Last change: - Added chmod functionality
Date: 8 years ago
Size: 42,859 bytes
 

Contents

Class file image Download
<?php
error_reporting(E_ALL);

// we use sessions in this version for saving data
session_start();


// if calculator is required, ask for calculator
if (isSet($_GET['calculator']))
{
    include("calculator.include.php");
    exit();
}

// include files
include("php2hexv3.0.include.php");  // global functions
include("php2hex.class.php");        // the hexcode class
include("php2mysql.class.php");      // mysql class
include("rc4.class.php");            // code and decode data with 'key'

$linemax = 80;                       // maximum length of hex code on each line
$version = "3.0.1";                  // script version
$tpldir  = "./templates/";           // template directory
$hexdir  = "./hexscripts/";          // where to save and store hex sources
$srcdir  = "./hexsources/";          // if user choose to save file on server, here to find

if (strstr($_SERVER['HTTP_USER_AGENT'], 'Win'))
{
    $enter = "\r\n";
}
elseif (strstr($_SERVER['HTTP_USER_AGENT'], 'Mac'))
{
    $enter = "\r";
}
else
{
    $enter = "\n";
}

if ($_SERVER['REQUEST_METHOD'] == "POST")
{
    saveSession();

    switch ($_POST['action'])
    {
       case "Save":
            if (isSet($_POST['save_file']))
            {
                if (stristr($_POST['save_file'], '.hex'))
                {
                    $sFile = $hexdir . $_POST['save_file'];
                }
                else
                {
                    $sFile = $hexdir . $_POST['save_file'] . '.hex';
                }

                $fd = fopen($sFile, "w+");
                    fputs($fd, serialize($_SESSION['submit']));
                fclose($fd);
            }
        break;

        case "Load":
            if (isSet($_POST['load_file']) && stristr($_POST['load_file'], ".hex"))
            {
                $fd = fopen($hexdir . $_POST['load_file'], 'r');
                    $_SESSION['submit'] = unserialize(fread($fd, filesize($hexdir . $_POST['load_file'])));
                fclose($fd);
            }
        break;

        case "Clear":
            session_unregister("submit");
        break;

        case "Build":
            // Build archive

            $p2h = new php2hex;
            $m2h = new mysql2hex;

            ob_start();

            if (isSet($_SESSION['submit']))
            {
                $template = $tpldir . "/" . $_SESSION['submit']['inst_layout'];
                if (isSet($_SESSION['submit']['inst_layout']) && is_dir($template))
                {
                    $first   = getFileData($template . "/first.inc");
                    $last    = getFileData($template . "/last.inc");
                }
                else
                {
                    echo 'include files cannot be found..';
                }
            }
            else
            {
                echo 'sorry cant build archive from nothing...';
            }
            
            if (isSet($_POST['save_file']))
            {
                if (stristr($_POST['save_file'], '.hex'))
                {
                    $sFile = $hexdir . $_POST['save_file'];
                }
                else
                {
                    $sFile = $hexdir . $_POST['save_file'] . '.hex';
                }

                if (isSet($_POST['save_build']) && $_POST['save_build'] == "yes")
                {
                    $fd = fopen($sFile, "w+");
                    fputs($fd, serialize($_SESSION['submit']));
                    fclose($fd);
                }
            }

            if (isSet($_POST['download']))
            {
                switch ($_POST['download'])
                {
                    case "new":
                        header("Content-type: text/document");
                        if (len(getSesData('save_file')) > 2)
                        {
                             header("Content-Disposition: attachment; filename=" . str_replace(".hex", "", getSesData('save_file')) . ".php");
                        }
                        else
                        {
                             header("Content-Disposition: attachment; filename=installersource.php");
                        }
                        echo $first;

                    case "preview":
                        echo '<pre>';
                        echo htmlspecialchars($first);
                    break;
                    
                    case "save":
                        ob_start();
                        echo $first;
                    break;

                    default:
                        header("Content-type: text/document");
                        header("Content-Disposition: attachment; filename=installersource.php");
                        echo $first;
                    break;
                }
            }
            else
            {
                header("Content-type: text/document");
                header("Content-Disposition: attachment; filename=filename.php");
                echo $first;
            }

            echo '/* Created by PHP2HeX Local (tool) v2.5 */' . $enter . $enter;

            if (isSet($_SESSION['submit']['disclamer_text']) && strlen($_SESSION['submit']['disclamer_text']) > 3)
            {
                if (isSet($_SESSION['submit']['disclamer_title']) && strlen($_SESSION['submit']['disclamer_title']) > 5)
                {
                    $title = getSesData('disclamer_title');
                }
                else
                {
                    $title = "License / Disclamer";
                }

                if (isSet($_SESSION['submit']['disclamer_text']) && strlen($_SESSION['submit']['disclamer_text']) > 10)
                {
                    // good license
?>

$i = array(
"title" => "<?php echo $title; ?>",
"data" => array(
<?php echo $p2h->parseHex(gzCompress(nl2br(getSesData('disclamer_text')))); ?>));
<?php
                }
            }

            if (isSet($_SESSION['submit']['inst_runpsw']) && strlen($_SESSION['submit']['inst_runpsw']) > 4)
            {
                if ($_SESSION['submit']['inst_runpsw'] == $_SESSION['submit']['inst_runpswcheck'])
                {
                    $psw = $_SESSION['submit']['inst_runpsw'];
?>
// if you remove this part all data will be corrupted
$psw = '<?php echo md5($psw); ?>';
<?php
                }
            }

            if (isSet($_SESSION['submit']['functions']) && is_array($_SESSION['submit']['functions']))
            {
?>
$cf = array('<?php echo implode("', '", $_SESSION['submit']['functions']); ?>');
<?php
            }

            if (isSet($_POST['inst_runatend']) && strlen($_SESSION['submit']['inst_runatend']) > 3)
            {
?>
$startatend = "<?php echo $_SESSION['submit']['inst_runatend']; ?>";
<?php
            }

            if (isSet($_SESSION['submit']['item']) && is_array($_SESSION['submit']['item']))
            {
?>
$f = array();
<?php
                foreach($_SESSION['submit']['item'] as $key => $value)
                {
                    switch($_SESSION['submit']['itemtype'][$key])
                    {
                        case "directory":
                        // nothing yet
                        break;

                        case "file":

                            $bufsize = filesize($_SESSION['submit']['itemlocal'][$key]);
                            $fd = fopen($_SESSION['submit']['itemlocal'][$key], "rb");
                                $buffer = fread($fd, $bufsize);
                            fclose($fd);

                            // check if this need to be coded (using psw)
                            if (isSet($psw))
                            {
                                // code data
                                $bufCom = rc4crypt($psw, gzcompress($buffer));
                            }
                            else
                            {
                                // only zip data
                                $bufCom = gzcompress($buffer);
                            }
?>

$f[] = array(
"name" => "<?php echo $_SESSION['submit']['itemname'][$key]; ?>",
<?php if (isSet($_SESSION['submit']['itemchmod'][$key]) && is_numeric($_SESSION['submit']['itemchmod'][$key]))
{
?>
"mod"  => "<?php echo $_SESSION['submit']['itemchmod'][$key]; ?>",
<?php } ?>
"size" => "<?php echo $bufsize; ?>",
"gzip" => "<?php echo strlen($bufCom); ?>",
"dir"  => "<?php echo $_SESSION['submit']['itempath'][$key]; ?>",
"data" => array(
<?php echo $p2h->parseHex($bufCom); ?>));
<?php
                        break;
                    }
                }
            }

            if (isSet($_SESSION['submit']['mysql']) && is_array($_SESSION['submit']['mysql']))
            {
?>
$mysqldb = "<?php echo $_SESSION['submit']['mysql_db']; ?>";
$m = array();
<?php

                $m2h->openCon($_SESSION['submit']['mysql_host'],
                              $_SESSION['submit']['mysql_user'],
                              $_SESSION['submit']['mysql_psw'],
                              $_SESSION['submit']['mysql_db']);

                foreach ($_SESSION['submit']['mysql'] as $table => $todo)
                {
                    if (is_array($todo))
                    {
                        if (isSet($todo['drop']))
                        {
?>
$m[] = array(
"type"  => "drop",
"name"  => "<?php echo $table; ?>");

<?php
                        }

                        if (isSet($todo['create']))
                        {
                            $tableCreate = $m2h->getTable($table);

                            if (isSet($psw))
                            {
                                // code data
                                $tableCom = rc4crypt($psw, gzcompress($tableCreate));
                            }
                            else
                            {
                                // only zip data
                                $tableCom = gzcompress($tableCreate);
                            }

?>
$m[] = array(
"type"  => "create",
"name"  => "<?php echo $table; ?>",
"size"  => "<?php echo strlen($tableCreate); ?>",
"gzip"  => "<?php echo strlen($tableCom); ?>",
"data"  => array(<?php echo $enter . $p2h->parseHex($tableCom) . '));' . $enter . $enter; ?>
<?

                        }

                        if (isSet($todo['insert']))
                        {
                            $data        = $m2h->getTableData($table);
                            
                            if ($data != false)
                            {

                                $tableIns    = $data['insert'];
                                $tableCount  = $data['items'];

                                if (isSet($psw))
                                {
                                    // code data
                                    $tableInsCom = rc4crypt($psw, gzcompress($tableIns));
                                }
                                else
                                {
                                    // only zip data
                                    $tableInsCom = gzcompress($tableIns);
                                }
?>
$m[] = array(
"type"  => "insert",
"name"  => "<?php echo $table; ?>",
"count" => "<?php echo $tableCount; ?>",
"size"  => "<?php echo strlen($tableIns); ?>",
"gzip"  => "<?php echo strlen($tableInsCom); ?>",
"data"  => array(<?php echo $enter . $p2h->parseHex($tableInsCom) . '));' . $enter . $enter;?>
<?
                            }
                            // else no data in table.
                        }
                    }
                }
            }

            if (isSet($_SESSION['submit']['download']))
            {
                switch ($_SESSION['submit']['download'])
                {
                    case "new":
                    case "preview":
                        echo htmlspecialchars($last);
                        echo '<pre>';
                    break;
                    
                    case "save":
                        echo $last;
                        $code = ob_get_contents();
                        ob_end_clean();

                        if (!is_dir($srcdir))
                        {
                            mkdir($srcdir, 0666);
                        }
                        
                        if (strlen(getSesData('save_file')) > 2)
                        {
                            $sFile = $srcdir . str_replace(".hex", "", getSesData('save_file')) . ".php";
                        }
                        else
                        {
                            $sFile = $srcdir . date("y-m-d_His") . "installersource.php";
                        }
                        
                        $fd = fopen($sFile, "w+");
                        fputs($fd, $code);
                        fclose($fd);
                        
                        echo 'Saving file to server completed: ' . $sFile;
                        exit();


                    break;

                    default:
                        echo $last;
                    break;
                }
            }
            else
            {
                echo $last;
            }

            ob_end_flush();

            exit();
        break;

    }
}



?>

<!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>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>PHP2HEX v3.0</title>
    
    <script src="php2hexv3.0.js" type="text/javascript"></script>
    
    <link rel="Stylesheet" href="php2hexv3.0.css" type="text/css" />
</head>

<body>
    <form method="post" name="form">
    <div class="container">
        <div class="top">
            <h1>PHP</h1>
            <h2>2</h2>
            <h3>HEX</h3>
        </div>

        <div class="bar">
            <div class="left">
                 <div class="bartitle">the Ultimate Script Installer Archive Creator</div>
            </div>
            <div class="right">
                 <div class="barlinks"><a href="#">Homepage</a> |
                                       <a href="#">Submit your script</a> |
                                       <a href="#">Forum</a> |
                                       <a href="#">About</a> |
                                       <a href="javascript:c(8);">Help</a> |
                                       <a href="javascript:c(9);">Credits</a>
                 </div>
            </div>
        </div>

        <div class="content">
            <div class="menu">
                <p>Welcome to the first and only php script installer archive creator, wich you can use to make a installer for your scripts to spread them on the easy way</p>
                <div class="menuitems">
                    <ul>
                        <li><a href="javascript:c(1);" onmouseover="h('Step 1 - Preferences', 'Here you can set all preferences of the installer script');">Step 1 - Global configuration</a></li>
                        <li><a href="javascript:c(2);" onmouseover="h('Step 2 - Installer data', 'For the information that the installer will contain like files and or mysql database information you need to fill in.');">Step 2 - File and MySQL</a></li>
                        <li><a href="javascript:c(3);" onmouseover="h('Step 3 - Installer checks', 'The installer can check things, display disclamer/licences and more, to setup these settings use this step.');">Step 3 - Installer checks</a></li>
                        <li><a href="javascript:c(4);" onmouseover="h('Step 4 - File selection', 'If you have chosen for including files into the installer, please remove or change security settings with this step.');">Step 4 - Files</a></li>
                        <li><a href="javascript:c(5);" onmouseover="h('Step 5 - MySQL selection', 'If your installer script also needs to extract database information, please take this step to include or exclude database information structures.');">Step 5 - MySQL</a></li>
                        <li><a href="javascript:c(6);" onmouseover="h('Step 6 - Installer settings', 'Ofcource your installer need to be configured aswel.');">Step 6 - Installer settings</a></li>
                        <li><a href="javascript:c(7);" onmouseover="h('Step 7 - Final step', 'If you check this step you see what will be insterted into the installer and you can build the new installer script.');">Step 7 - Build</a></li>
                    </ul>
                    <ul>
                        <li><input type="submit" name="action" value="Clear" /></li>
                    </ul>
                </div>
                
                <div class="itemtitle"><strong id="step_title">Step description: </strong></div>
                <div class="itemtext" id="step_text">
                    Mouse over the 'Steps' and see the functionality.
                </div>

                <p class="pp">If you have saved a previous installation script, you can look it up here and load it. But beware if you load a script all your inputs will be lost!</p>

                <div class="loadtitle"><strong>Load file</strong></div>
                <div class="loadtext">
                    <select name="load_file">
                    <?php echo getSaveFiles($hexdir); ?>
                    </select>&nbsp;<input type="submit" name="action" value="Load" />
                </div>
            </div>

            <div class="main">
                <div style="padding-left: 20px; padding-top: 20px;">
                    <div id="step0">
                         <h2 class="h2top">PHP2HEX - Welcome</h2>
                         
                         <p>Welcome at the new and restyled version of PHP2HEX, this version contains a new layout and some little code improvements due the reason lot's of people didn't know how it worked... now all things will be done step by step with lot's of details attatched to them. I hope you use this for your own scripting work and if you have any idea's for it please send that to our email (eric a@t bruggema.nl)</p>
                         
                         <p>In the near feature you will expect the following new additions.</p>
                         
                         <ul class="table">
                             <li>Choose installer layout</li>
                             <li>Two layouts for installer (Standard, SuperRembo)</li>
                             <li>Adding password to archive</li>
                             <li>Setting rights on directories</li>
                             <li>Smaller installer code</li>
                             <li>And ofcource more and more</li>
                         </ul>
                         
                         <p>If you have any suggestions and or idea's we could build in, then we'd like to hear that from you. You can always get in touch with us by sending an email to eric [at] bruggema punt nl with your idea's, bugs and what ever!</p>
                         
                         <p>Notice: All rights to these codes are (c) Eric Bruggema and modifications are allowed after email</p>
                         
                         <p>Click on STEP 1 to start the progress</p>
                    </div>

                    <div id="step1" style="display: none;">
                        <h2 class="h2top">Save file</h2>

                        <p>Here you need to write down the name of the file you'd like to save to, please note that the files will be saved with the extension .hex</p>

                        <ul class="table">
                            <li>Filename
                                <p><input class="inp" name="save_file" type="text" value="<?php echo getSesData('save_file'); ?>" /></p>
                            </li>
                            <li>Would you like to save the file with building the archive?
                                <p><input class="noborder" name="save_build" type="checkbox" value="yes" <?php echo getSesCheck('save_build'); ?> />Yes! please</p>
                            </li>
                            <li>Click here to save the current settings session
                                <p><input type="submit" name="action" value="Save" style="width: 100px;" /></p>
                            </li>
                        </ul>

                        <h2>Download / Preview</h2>

                        <p>When you start the script and let the installer be build, would you like to have the new source as a download or do you like to preview it in the brouwser window?</p>

                        <ul class="centertable">
                            <li><strong>Download</strong>
                                <p><input class="noborder" type="radio" name="download" value="download" <?php echo getSesRad('download', 'download'); ?> /></p>
                            </li>
                            <li><strong>Preview</strong>
                                <p><input class="noborder" type="radio" name="download" value="preview" <?php echo getSesRad('download', 'preview'); ?> /></p>
                            </li>
                            <li><strong>Save on Server</strong>
                                <p><input class="noborder" type="radio" name="download" value="save" <?php echo getSesRad('download', 'save'); ?> /></p>
                            </li>
                        </ul>
                        
                        <p class="right"><input type="submit" name="action[1]" value="Next step >>" /></p>
                    </div>

                    <div id="step2" style="display: none;">
                        <h2 class="h2top">Installer files &amp; directories</h2>

                        <p>Please define the directory where we can load the files from</p>

                        <ul id="filex" class="table" <?php if(strlen(getSesData('directory')) > 2){ echo 'style="display:none;"';} ?>>
                            <li>Select initial directory
                                <p><input name="bestandje" type="file" onchange="getFile(this.value);" /></p>
                            </li>
                        </ul>
                        
                        <div id="path"  <?php if(strlen(getSesData('directory')) < 2){ echo 'style="display:none;"';} ?>>
                            <ul class="table">
                                <li>Start directory
                                    <p><input class="inp" type="text" id="directory" name="directory" value="<?php echo getSesData('directory'); ?>" /></p>
                                </li>
                                <li>Remove part (from directory, only at end)
                                    <p><input class="inp" type="text" id="newdirectory" name="removepart" value="<?php echo getSesData('removepart'); ?>" /></p>
                                </li>
                                <li>
                                    <p><strong>for example:</strong> <br />start Directory (/user/project/freephpscript) and <br />Removepart (/user/project/)<br /> then the base directory of your script will become '<strong>freephpscript</strong>/'(your files)</p>
                                </li>
                                <li>Include subdirectories?
                                    <p><input type="checkbox" name="subdirs" value="yes" style="width: 20px;" <?php echo getSesCheck('subdirs'); ?> /></p>
                                </li>
                                <li>Would you like to load another directory?
                                    <p><input type="button" name="reload" value="Reset path" onclick="resetGetFile();" /></p>
                                </li>
                            </ul>
                        </div>

                        <h2>MySQL information</h2>

                        <p>All MySQL database information is required, except the password.</p>

                        <ul class="table">
                            <li>Host
                                <p><input class="inp" type="text" id="mysql_host" name="mysql_host" value="<?php echo getSesData('mysql_host'); ?>" /></p>
                            </li>
                            <li>Username
                                <p><input class="inp" type="text" id="mysql_user" name="mysql_user" value="<?php echo getSesData('mysql_user'); ?>" /></p>
                            </li>
                            <li>Password
                                <p><input class="inp" type="password" id="mysql_psw" name="mysql_psw" value="<?php echo getSesData('mysql_psw'); ?>" /></p>
                            </li>
                            <li>Database name?
                                <p><input class="inp" type="text" id="mysql_db" name="mysql_db" value="<?php echo getSesData('mysql_db'); ?>" /></p>
                            </li>
                        </ul>

                        <p class="right"><input type="submit" name="action[2]" value="Next step >>" /></p>
                    </div>

                    <div id="step3" style="display: none;">
                        <h2 class="h2top">Disclamer</h2>

                        <p>If you would like to add a disclamer into your project please write down all the information required</p>

                        <ul class="table">
                            <li>Title
                                <p><input class="inp" name="disclamer_title" type="text" value="<?php echo getSesData('disclamer_title'); ?>" /></p>
                            </li>
                            <li>Text
                                 <p><textarea name="disclamer_text" class="inp" rows="2" cols="2" style="height: 100px;"><?php echo getSesData('disclamer_text'); ?></textarea></p>
                            </li>
                        </ul>

                        <h2>Function checks</h2>

                        <p>This installer can also do some function checks for you, to check if the functions exist on the system witch is installing the script</p>

                        <ul class="table">
                            <li>Function
                                <p><input class="inp" name="addfunctiontmp" id="addfunction" type="text" />
                                <input name="add" type="button" value="Add" style="width: 50px;"  onclick="funca();" /></p>
                            </li>
                            <li>PHP Functions
                                <p><select name="addphpfunctions" id="phpfunctions" style="width: 250px;">
                                <?php $arr = get_defined_functions(); sort($arr['internal'], SORT_STRING); foreach ($arr['internal'] as $key) { echo '<option value="' . $key . '">' . $key . '</option>';}?>
                                </select>
                                &nbsp;<input name="submit" type="button" value="Add" style="width: 50px;" onclick="funcb(document.getElementById('phpfunctions').options[document.getElementById('phpfunctions').selectedIndex].value);" /></p>
                            </li>
                            <li>Selected functions that will included in the installer, click on a item to remove
                                <p><select name="functions[]" id="functions" class="inp" style="height: 100px;" multiple="multiple">
                                <?php echo getSesOptions('functions', true); ?>
                                </select></p>
                            </li>
                        </ul>

                        <p class="right"><input type="submit" name="action[3]" value="Next step >>" /></p>

                    </div>

                    <div id="step4" style="display: none;">
                        <h2 class="h2top">Files &amp; Directories</h2>

<?php

if (isSet($_SESSION['submit']['directory']) && is_dir($_SESSION['submit']['directory']))
{
?>
<br />
<h3>Files from `<?php echo $_SESSION['submit']['directory']; ?>`</h3>
<p>If you would like to check all, click <a href="javascript:checkAll('step4');">here</a></p>
<table align="center" style="border-top: 1px solid black; border-left: 1px solid black; border-right: 1px solid black;" width="100%">
<tr>
    <td style="width:40px">Tag</td>
    <td style="width:35px">Chmod</td>
    <td>Files / Directory(s)</td>
    <td style="width:85px">Size</td>
</tr>
<?php
    $counter = 0;
    doDirTree($_SESSION['submit']['directory']);
?>
</table>
<?php
}
?>

                        <p class="right"><input type="submit" name="action[4]" value="Next step >>" /></p>
                    </div>

                    <div id="step5" style="display: none;">
                        <h2 class="h2top">Database</h2>


<?php
// start mysql
if (isSet($_SESSION['submit']['mysql_db']) && strlen($_SESSION['submit']['mysql_db']) > 2)
{
?>
<br />
<h3>MySQL tables from `<?php echo $_SESSION['submit']['mysql_db']; ?>`</h3>
<div id="mysqldata">
<table align="center" border="1" style="border: 1px solid black;" width="550">
<tr>
    <td style="width:30px"><a href="#" onClick="unCheck('drop');">Drop</a></td>
    <td style="width:30px"><a href="#" onClick="unCheck('create');">Table</a></td>
    <td style="width:30px"><a href="#" onClick="unCheck('insert');">Insert</a></td>
    <td style="width:370px">Table</td>
    <td style="width:90px">Size</td>
</tr>
<?php

    $con = @mysql_connect($_SESSION['submit']['mysql_host'],
                          $_SESSION['submit']['mysql_user'],
                          $_SESSION['submit']['mysql_psw']);

    if ($con != false)
    {
        $db = @mysql_select_db($_SESSION['submit']['mysql_db'],
                               $con);

        if ($db != false)
        {
            $query = mysql_list_tables($_SESSION['submit']['mysql_db']);
            $items = mysql_num_rows($query);

            for ($a = 0; $a < $items; $a++)
            {
                $row = mysql_fetch_row($query);

                $table = $row[0];
                $q = mysql_result(mysql_query("SELECT count(*) FROM `" . $table . "`"), 0);

echo '<tr>
    <td class="center">
        <input type="checkbox" checked="checked" name="mysql[' . $table . '][drop]" value="ON" />
    </td>
    <td class="center">
       <input type="checkbox" checked="checked" name="mysql[' . $table . '][create]" value="ON" />
    </td>
    <td class="center">
       <input type="checkbox" checked="checked" name="mysql[' . $table . '][insert]" value="ON" />
    </td>
    <td>'. $table. '</td>
    <td>' . $q . '</td>
</tr>' . "\r\n";

            }
        }
        else
        {
            echo '<tr><td colspan="5"><h3>Sorry cannot connect to database</h3></td></tr>';
        }
    }
    else
    {
        echo '<tr><td colspan="5"><h3>Sorry cannot connect to host</h3></td></tr>';
    }

?>
</table>
</div>
<?php
// end mysql
}
?>

                        <p class="right"><input type="submit" name="action[5]" value="Next step >>" /></p>
                    </div>

                    <div id="step6" style="display: none;">
                        <h2 class="h2top">Installer settings</h2>
                        
                        <p>At last you need to specify some settings for the installer</p>

                        <h2>Layout - Installer style</h2>

                        <p>Due the possibilities in this version of PHP2HEX you can also choose the layout of the installer, we cannot provide you with any examples but you know what it is when you try it!</p>

                        <ul class="table">
                            <li>Layout
                                <p><select class="inp" name="inst_layout">
<?php

if ($dir = opendir($tpldir))
{
    while (($file = readdir($dir)) !== false)
    {
        if (is_dir($tpldir . $file) && $file != "." && $file != "..")
        {
            if ($_SESSION['submit']['inst_layout'] == $file)
            {
                echo '<option value="' . $file . '" selected="selected">' . $file . '</option>';
            }
            else
            {
                echo '<option value="' . $file . '">' . $file . '</option>';
            }
        }
    }
    closedir($dir);
}
?>
                                </select></p>
                            </li>
                        </ul>

                        <h2>Run at and</h2>

                        <p>With a windows/unix installer you'd also be able to specify a file that will be started after a succesful installation, in this installer that's also possible.</p>

                        <ul class="table">
                            <li>Please select the file you'd like to run after the succesfull installation.
                                <p><select class="inp" name="inst_runatend">
                                   <option>-- Select --</option>
<?php

if (isSet($_SESSION['submit']['item']))
{
    foreach ($_SESSION['submit']['item'] as $key => $name)
    {
        $file = ($_SESSION['submit']['itempath'][$key] == "" ? "" : $_SESSION['submit']['itempath'][$key] . CHR(47)) . $_SESSION['submit']['itemname'][$key];
        if ($_SESSION['submit']['inst_runatend'] == $file)
        {
            echo '<option value="' . $file . '" selected="selected">' . $file . '</option>';
        }
        else
        {
            echo '<option value="' . $file . '">' . $file . '</option>';
        }
    }
}
?>
                                </select></p>
                            </li>
                        </ul>

                        <h2>Password</h2>

                        <p>If you like you can also add a password to your archive, and users need to specify the password to install the script, all the data will be encrypted with the password you give.</p>

                        <ul class="table">
                            <li>Password
                                <p><input class="inp" name="inst_runpsw" type="password" value="<?php echo getSesData('inst_runpsw'); ?>" /></p>
                            </li>
                            <li>Again
                                <p><input class="inp" name="inst_runpswcheck" type="password" value="<?php echo getSesData('inst_runpswcheck'); ?>" /></p>
                            </li>
                        </ul>

                        <p class="right"><input type="submit" name="action[6]" value="Next step >>" /></p>
                    </div>
                    
                    <div id="step7" style="display: none;">
                        <h2 class="h2top">Build</h2>

                        <p>In the box you'll see wich steps the script will take after you click the build button, all operations are covered here</p>

                        <p style="width: 90%; height: 250px; overflow: auto; border: 1px solid gray;">
<?php

// disclamer
if (isSet($_SESSION['submit']['disclamer_text']))
{
    echo '* adding disclamer<br />';
    echo 'Title: ' . getSesData('disclamer_title') . '<br />';
    echo 'Text : ' . nl2br(getSesData('disclamer_text')) . '<br />';
    echo '<br />';
}

// function checks
if (isSet($_SESSION['submit']['functions']) && is_array($_SESSION['submit']['functions']))
{
    echo '* Including functions checks for the following functions: <br />';
    foreach ($_SESSION['submit']['functions'] as $func)
    {
        echo 'function: ' . $func . '<br />';
    }
    echo '<br />';
}

// files
if (isSet($_SESSION['submit']['item']))
{
    echo '* Including files & directories<br />';

    foreach($_SESSION['submit']['item'] as $key => $value)
    {
        switch($_SESSION['submit']['itemtype'][$key])
        {
            case "file":
                echo "file: " . $_SESSION['submit']['itemname'][$key] . '<br />';
            break;
        }
    }
    echo '<br />';
}

if (isSet($_SESSION['submit']['mysql']) && is_array($_SESSION['submit']['mysql']))
{
    echo '* Including MySQL information<br />';
    foreach ($_SESSION['submit']['mysql'] as $table => $todo)
    {
        if (is_array($todo))
        {
            if (isSet($todo['drop']))
            {
                echo 'drop table: ' . $table . '<br />';
            }

            if (isSet($todo['create']))
            {
                echo 'create table: ' . $table . '<br />';
            }

            if (isSet($todo['insert']))
            {
                echo 'insert table data of table: ' . $table . '<br />';
            }
        }
        echo '<br />';
    }
}

echo '* installer template : ' .  $_SESSION['submit']['inst_layout'] . '<br />';
echo '<br />';

if (isSet($_SESSION['submit']['inst_runatend']) && strlen($_SESSION['submit']['inst_runatend']) > 0)
{
    echo '* Run file at end<br />';
    echo 'file: ' . $_SESSION['submit']['inst_runatend'] . '<br />';
    echo '<br />';
}

if (isSet($_SESSION['submit']['inst_runpsw']) && strlen($_SESSION['submit']['inst_runpsw']) > 4)
{
    if ($_SESSION['submit']['inst_runpsw'] == $_SESSION['submit']['inst_runpswcheck'])
    {
        echo '* installer password : PASSWORD HIDDEN<br />';
        echo '<br />';
    }
}

?>
                        </p>

                        <p class="right"><input type="submit" name="action" value="Build" /></p>
                    </div>

                    <div id="step8" style="display: none;">

                        <h2 class="h2top">Step 1 (Settings)</h2>
                        <ul>
                            <li><strong>Installer Data</strong>
                                <p>For Files, The installer can only work if you add files and or database information. Please select a local directory from your harddisk where the files are that you would include in your archive. Select one of the files and select subdirs if you like to include directories above the 'selected' directory.<br /><br />For MySQL, enter the host, username, password (if required) and the database name. Note: After selecting a base directory and or MySQL database information press the 'Reload' button to let the script gather the information of the Files and or MySQL database</p>
                            </li>
                            <li><strong>Disclamer</strong>
                                <p>If your script/program has a license and you want the users to read that license first, you can add that here</p>
                            </li>
                            <li><strong>Function checks</strong>
                                <p>Some of the scripts require special functions (like gd, zip, etc) and you can add here the functions that need to be installed on the 'installed' system</p>
                            </li>
                            <li><strong>Run at end</strong>
                                <p>After the installation of the script has been succesfull you can start after 10 seconds one of the project files (ie. index.html)</p>
                            </li>
                        </ul>

                        <h2>Step 2 (Files/Database)</h2>
                        <ul>
                            <li><strong>Files</strong>
                                <p>After you have applied the settings (step 1) and you have pressed 'Reload' you can see the files here. Unselect the files you don't want to include in your archive. Add the 'CHMOD' rights to let the script change the rights for the file</p>
                            </li>
                            <li><strong>Database</strong>
                                <p>All your database information is here to see, unselect drop, create and or insert if you don't want to include these kind of MySQL instructions</p>
                            </li>
                        </ul>

                        <h2>Step 3</h2>
                        <p>After you have completed all steps and you are ready to build the archive, please press the 'Build' button to comply!</p>
                    </div>
                    
                    <div id="step9" style="display: none;">

                        <p style="margin: 0px;">All credits for the people who build this version of php or had anything to do with it on what for kind of way.</p>
                        <h2>Program design</h2>
                        <ul>
                            <li><strong>Eric Bruggema</strong>
                                <p>Scripter, css, xhtml, javascript, php, mysql</p>
                            </li>
                        </ul>

                        <h2>Graphical design</h2>
                        <ul>
                            <li><strong>Eric Bruggema</strong>
                                <p>Second version > 2.5.1</p>
                            </li>
                            <li><strong>L.J. Pilon</strong>
                                <p>First version &lt; 2.5.1</p>
                            </li>
                        </ul>

                        <h2>Beta testing</h2>
                        <ul>
                            <li><strong>L.J. Pilon</strong>
                                <p>Version checker, for all little bugs and or user friendly testing</p>
                            </li>
                        </ul>

                        <h2>Used programs</h2>
                        <ul>
                            <li><strong>PHP Coder PRO</strong>
                                <p>Quite nice little script editor for PHP/Javascript and much more scripting languages</p>
                            </li>
                            <li><strong>NotePad</strong>
                                <p>The best little program to work with text files that windows has init</p>
                            </li>
                        </ul>

                        <h2>Script using</h2>
                        <ul>
                            <li><strong>PHP</strong>
                            </li>
                            <li><strong>MySQL</strong>
                            </li>
                            <li><strong>XHTML v1.0</strong>
                            </li>
                            <li><strong>CSS v3.0</strong>
                            </li>
                            <li><strong>Javascript v3.0</strong>
                            </li>
                        </ul>
                    </div>

                </div>

                <div style="clear: both;"></div>
            </div>
        </div>
    </div>
    </form>
    
<?php
if ($_SERVER['REQUEST_METHOD'] == "POST" && isSet($_POST['action']) && is_array($_POST['action']))
{
    foreach ($_POST['action'] as $key => $id)
    {
        if ($key < 7)
        {
            echo '<script type="text/javascript">c(' . ($key +1) . ');</script>';
        }
    }
}
?>


</body>
</html>