<?php
require_once('class.field.php');
session_start();
if(isset($_POST['add'])){
$field = new field();
$field->name = $_POST['fieldName'];
$field->istype = $_POST['fieldType'];
$field->isdefault = $_POST['defaultValue'];
$field->isnullable = $_POST['fieldNullable'];
$field->iskey = $_POST['fieldKey'];
$field->isautoupdate = $_POST['fieldAutoupdate'];
$_SESSION['fields'][] = $field;
}
if(isset($_GET['action']) && $_GET['action'] == "delete" && isset($_GET['id'])){
unset($_SESSION['fields'][$_GET['id']]);
$_SESSION['fields'] = array_values($_SESSION['fields']);
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="">
<link rel="icon" href="../../favicon.ico">
<title>PHP Class And SQL Code Generator</title>
<!-- Bootstrap core CSS -->
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
<style type="text/css">
body {
min-height: 2000px;
padding-top: 70px;
}
#defaultValue{
height: 34px;
padding: 6px 12px;
font-size: 14px;
line-height: 1.42857143;
color: #555;
background-color: #fff;
background-image: none;
border: 1px solid #ccc;
border-radius: 4px;
}
</style>
</head>
<body>
<!-- Fixed navbar -->
<nav class="navbar navbar-default navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="index.php">PHP Generator</a>
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li><a href="clear.php">Reset</a></li>
<li><a href="getSettings.php">Connection settings</a></li>
</ul>
</div>
</nav>
<div class="container">
<div class="row">
<div class="col-md-12">
<h2 class="page-header">PHP Class And SQL Code Generator</h2>
<form class="form-inline" method="post" action="index.php">
<div class="form-group">
<label class="sr-only" for="fieldName">FieldName</label>
<input type="text" class="form-control" id="fieldName" placeholder="fieldName" name="fieldName" required="required" autofocus="autofocus">
</div>
<div class="form-group">
<label class="sr-only" for="fieldType">FieldType</label>
<select class="form-control" id="fieldType" name="fieldType">
<option>Varchar(255)</option>
<option>Text</option>
<option>Datetime</option>
<option>Int(11)</option>
</select>
</div>
<div class="form-group">
<label class="sr-only" for="defaultValue">Default Value (SQL)</label>
<input type="text" name="defaultValue" id="defaultValue" list="values" placeholder="defaultValue">
<datalist id="values">
<option value="CURRENT_TIMESTAMP">
<option value="null">
<option value="0">
</datalist>
</div>
<div class="form-group">
<select class="form-control" id="fieldNullable" name="fieldNullable">
<option selected="selected">Nullable</option>
<option>NOT Nullable</option>
</select>
</div>
<div class="form-group">
<select class="form-control" id="fieldKey" name="fieldKey">
<option>Key</option>
<option selected="selected">NOT key</option>
</select>
</div>
<div class="form-group">
<select class="form-control" id="fieldAutoupdate" name="fieldAutoupdate">
<option>Autoupdate</option>
<option selected="selected">NOT autoupdate</option>
</select>
</div>
<button type="submit" class="btn btn-default" name="add">Add Field</button>
</form>
</div>
</div>
<div class="row">
<div class="col-md-12">
<table class="table">
<thead>
<tr>
<th></th>
<th>Name</th>
<th>Type</th>
<th>Default</th>
<th>Nullable</th>
<th>Key</th>
<th>AutoUpdate</th>
</tr>
</thead>
<tbody>
<?php
if (!empty($_SESSION['fields'])){
$counter = 0;
foreach ($_SESSION['fields'] as $temp) {
echo "<tr><td><a href='index.php?action=delete&id=$counter'><i class='fa fa-trash-o' aria-hidden='true'></i></a></td>";
echo "<td>".$temp->name."</td>";
echo "<td>".$temp->istype."</td>";
echo "<td>".$temp->isdefault."</td>"; //<p class="bg-success">...</p>
echo "<td>".$temp->isnullable."</td>";
echo "<td>".$temp->iskey."</td>"; //<p class="bg-success">...</p>
echo "<td>".$temp->isautoupdate."</td>"; //<p class="bg-success">...</p>
echo "</tr>";
$counter++;
}
}
?>
</tbody>
</table>
</div>
</div>
<div class="row">
<div class="col-md-12">
<form action="generateFile.php" method="post">
<div class="form-group">
<label for="classname">Name</label>
<input type="text" class="form-control" id="classname" placeholder="class name" name="classname" required="required">
</div>
<div class="form-group">
<label for="comments">Comment</label>
<textarea class="form-control" rows="3" id="comments" name="comments"></textarea>
<button type="submit" class="btn btn-default" name="genereer">Generate Code</button>
</div>
</form>
<i>Do not forget to add the connection file (settings.php) => generate it using the link in the navbar!</i>
</div>
</div>
</div> <!-- /container -->
<!-- Bootstrap core JavaScript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</body>
</html>
|