PHP Classes

File: index.php

Recommend this page to a friend!
  Classes of Craig Smith   classGen   index.php   Download  
File: index.php
Role: Example script
Content type: text/plain
Description: Html form for the input of paramters needed for the class
Class: classGen
Generate a class file from dynamic specifications
Author: By
Last change:
Date: 15 years ago
Size: 7,404 bytes
 

Contents

Class file image Download
<?php
if(@$_GET['action'] == 'delete')
{
    @
unlink('generatedclasses/' . $_GET['fname']);
    echo
'DELETED<br>';
}
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html lang="en">
    <head>
        <title>JHClassCreator</title>
    </head>
   
    <style>
    body {
        font-family:arial;
    }
    </style>

    <script>
        function addParameters()
        {
            var ni = document.getElementById('paramDiv');
            var numi = document.getElementById('Parameter_Value');
            var num = (document.getElementById('Parameter_Value').value -1)+ 2;
            numi.value = num;
            var newdiv = document.createElement('div');
            var divIdName = 'param'+num+'Div';
            newdiv.setAttribute('id',divIdName);
            newdiv.innerHTML = '<B>Add Attribute</b><br> Name : <input type="text" name="attribute['+num+'][name]"><br>Description : <input type="text" name="attribute['+num+'][description]"><br>Type : <input type="text" name="attribute['+num+'][type]"><br>Default Value : <input type="text" name="attribute['+num+'][default]"><a href=\'#\' onclick="removeElement(\''+divIdName+'\',\'paramDiv\')">[ - ]</a><hr>';
            ni.appendChild(newdiv);
        }

        function addMethods()
        {
            var ni = document.getElementById('methodDiv');
            var numi = document.getElementById('Method_Value');
            var num = (document.getElementById('Method_Value').value -1)+ 2;
            numi.value = num;
            var newdiv = document.createElement('div');
            var divIdName = 'method'+num+'Div';
            newdiv.setAttribute('id',divIdName);
            newdiv.innerHTML = '<B>Add Method</b><br> Name : <input type="text" name="method['+num+'][name]"><br>Parameters : <input type="text" name="method['+num+'][params]"><br>Description : <input type="text" name="method['+num+'][description]"><br>Content : <textarea rows="5" cols="50" name="method['+num+'][content]"></textarea><a href=\'#\' onclick="removeElement(\''+divIdName+'\',\'methodDiv\')">[ - ]</a><hr>';
            ni.appendChild(newdiv);
        }

        function removeElement(divNum, mainDiv)
        {
            var d = document.getElementById(mainDiv);
            var olddiv = document.getElementById(divNum);
            d.removeChild(olddiv);
        }

        function showhide(id)
        {
            if (document.getElementById)
            {
                obj = document.getElementById(id);
                if (obj.style.display == "none")
                {
                    obj.style.display = "";
                } else {
                    obj.style.display = "none";
                }
            }
        }
    </script>
   
    <body>
<?php
if(@$_GET['fname'] && @$_GET['action'] != 'delete') {
?>
<strong>Your Class has been Generated, you can download it at the bottom of the screen</strong><hr>
<?php
}
?>
<strong><a href="javascript:void()" onclick="showhide('about');">Script Details</a></strong>
        <div class="about" id="about" style="display:none;">
            <p>Fill out the fields on the page, remember no html tags are allowed<br>
            click the [ + ] next to the parameters for each attribute you wish to add to the class,<br>
            in the description field, type in using the * as a new line seperator<br>
            Click the [ + ] next to the methods for each method you wish to add<br>
            in the description field again use the * as a new line seperator<br>
            the Content field can handle html and php references and will keep all indentations you use.<br>
            Good Luck.</p>
        </div>
        <hr />
        <form action="generate.php" method="post">
        <table>
            <tr>
                <td>Your Name / Company</td>
                <td><Input type="text" name="author[name]"></td>
            </tr>
            <tr>
                <td>Your Email Address</td>
                <td><input type="text" name="author[email]"></tD>
            </tr>
            <tR>
                <td>Script Version</td>
                <td><input type="text" name="author[version]"></td>
            </tr>
            <tr>
                <td>Copyright</td>
                <td><input type="text" name="author[copyright]"></td>
            </tr>
            <tr>
                <td>Package</td>
                <td><input type="text" name="author[package]"></td>
            </tr>
            <tr>
                <td>Class Name</td>
                <td><input type="text" name="class[name]"></td>
            </tr>
            <tr>
                <td>Extends</td>
                <td><input type="text" name="class[extends]"></td>
            </tr>
            <tr>
                <td>Class Type</td>
                <td><select name="class[type]">
                        <option value="">Standard</option>
                        <option value="Abstract">Abstract</option>
                        </select></td>
            </tr>
            <tr>
                <td valign="top">Class Description (no HTML)</td>
                <td><textarea name="class_description" rows="5" cols="30"></textarea></td>
            </tr>
            <tr>
                <td valign="top">Parameters <input type="hidden" value="0" id="Parameter_Value" />
                    <a href="javascript:void(0);" onclick="addParameters();">[ + ]</a></td>
                <td>
                    <div id="paramDiv"> </div>
                </td>
            </tr>
   
            <tr>
                <td valign="top">Methods <input type="hidden" value="0" id="Method_Value" />
                    <a href="javascript:void(0);" onclick="addMethods();">[ + ]</a></td>
                <td>
                    <div id="methodDiv"></div>
                </td>
            </tr>
            <tr>
                <td></td>
                <Td><input type="submit" value="Generate"></td>
            </tr>
        </table>
    </form>

    <h1><a href="javascript:void()" onclick="showhide('generated');">Generated Class Files</a></h1>
    <div id="generated" style="display:none;">
        <table>
            <tr>
                <td>Class name</td>
                <td>Created</td>
                <td></td>
            </tr>
            <?php
           
//list our downloads
           
$d = dir("generatedclasses");
           
$path = $d->path;
            while (
false !== ($entry = $d->read())) {
            if(
$entry[0] == ".") continue;
           
?>
<tr>
                <td><a href="<?php echo $path . '/' . $entry;?>" target="_BLANK">
                    <?php echo str_replace(".php.txt","", $entry);?></td>
                <td>
                <?php
                $filename
= $path . '/' . $entry;
                if (
file_exists($filename)) {
                    echo
date ("F d Y H:i:s.", filemtime($filename));
                }
               
?></td>
                <td>
                    <a href="index.php?action=delete&fname=<?php echo $entry;?>">Delete</a>
                </td>
            </tr>
        <?php
       
}
       
$d->close();
       
?>
</table>
  </div>
</body>
</html>