<?php
error_reporting(E_ALL);
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);
include('config.php');
include('functions.php');
require_once("class/typeClass.php");
$typeClass = new TypeClass('');
if (isset($_POST['tableName']) && isset($_POST['dataId']) && $_POST['action'] == 'update') {
//$columnId = substr($_POST['dataId'], 1);
$columnId = $_POST['dataId'];
echo '<span class="badge badge-success">' . $_POST['tableName'] . '</span>';
echo '<span class="badge badge-success">' . $columnId . '</span>';
echo '<br/>';
$columns = showColums($connect, $_POST['tableName']);
$countColumn = count($columns);
$rows = showOneRow($connect, $_POST['tableName'], $columnId);
// var_dump($rows[0][0]);
echo '<form id="updateForm" >';
echo '<input type="hidden" name="table_name_order" value="' . $_POST['tableName'] . '"/>';
echo '<input type="hidden" name="action" value="update"/>';
for ($x = 0; $x < $countColumn; $x++) {
if (isset($columns[$x][3]) && $columns[$x][3] == 'PRI') {
echo '<input type="hidden" name="table_name_order_id" value="' . $columns[$x][0] . '"/>';
}
$typePart = explode("(", $columns[$x][1]);
// echo $typePart[0];
$typeClass->setType($typePart[0]);
$typeClass->setPrimary($columns[$x][3]);
$typeClass->setRequired($columns[$x][2]);
$typeClass->setData($rows[0][$x]);
$typeClass->setLabel($columns[$x][0]);
if($typeClass->getType() == 'enum'){
$typeClass->setOptions($columns[$x][1]);
$typeClass->setData($rows[0][$x]);
}
if (isset($imageColums[$_POST['tableName']]) && $imageColums[$_POST['tableName']] == $columns[$x][0]) {
$typeClass->setType('image');
$imgAray = json_decode($rows[0][$x]);
echo '<textarea id="filesinput" style="display:none;" class="form-control" type="hidden" name="' . $columns[$x][0] . '" >'. json_encode($imgAray) .'</textarea> </div>';
$typeClass->setData($imgAray);
$html = '';
if($imgAray){
foreach ($imgAray as $img){
$html .='<img src="' . $img . '" style="float:left" class="img-thumbnail" width="75px" height="100px" />';
}
}
echo '<output id="resultimages" >' . $html . '</output>';
}
echo $typeClass->createInput();
}
echo '<input type="submit" value="Save" class="form-control btn btn-success">';
echo '</form>';
}
if (isset($_POST['tableName']) && $_POST['action'] == 'add') {
$inputType = 'text';
$columns = showColums($connect, $_POST['tableName']);
$countColumn = count($columns);
$rows = showRows($connect, $_POST['tableName']);
echo '<form id="addForm" method="post" action="" >';
echo '<input type="hidden" name="table_name_order" value="' . $_POST['tableName'] . '"/>';
echo '<input type="hidden" name="action" value="add"/>';
//echo $imageColums[$_POST['tableName']];
for ($x = 0; $x < $countColumn; $x++) {
// echo $columns[$x][2].' - '.$columns[$x][3].' - '.$columns[$x][4].' - '.$columns[$x][5];
$typePart = explode("(", $columns[$x][1]);
$typeClass->setType($typePart[0]);
$typeClass->setPrimary($columns[$x][3]);
$typeClass->setRequired($columns[$x][2]);
$typeClass->setData('');
$typeClass->setLabel($columns[$x][0]);
if($typeClass->getType() == 'enum'){
$typeClass->setData($columns[$x][1]);
}
if (isset($imageColums[$_POST['tableName']]) && $imageColums[$_POST['tableName']] == $columns[$x][0]) {
$typeClass->setType('image');
echo '<input id="filesinput" class="form-control" type="hidden" name="' . $columns[$x][0] . '" value="" /> </div>';
echo '<output id="resultimages" ></output>';
}
echo $typeClass->createInput();
}
echo '<input type="submit" value="Add" class="form-control btn btn-success">';
echo '</form>';
}
if (isset($_POST['tableName']) && isset($_POST['dataId']) && $_POST['action'] == 'dell') {
$columnId = $_POST['dataId'];
$tableName = $_POST['tableName'];
$columns = showColums($connect, $_POST['tableName']);
$countColumn = count($columns);
$primary = '';
for ($x = 0; $x < $countColumn; $x++) {
if ($columns[$x][3] == 'PRI') {
$primary = $columns[$x][0];
}
}
if ($primary != '') {
$query0 = "DELETE FROM $tableName WHERE $primary ='" . $columnId . "' ";
$statement0 = $connect->prepare($query0);
$res = $statement0->execute();
if ($res) {
echo $columnId . ' ID Deleted ';
} else {
echo $columnId . ' ID not deleted! ';
}
} else {
echo 'no primary key';
}
}
|