PHP Classes

File: data_action_orj.php

Recommend this page to a friend!
  Classes of Mehmet Kidiman   Developbat PHP CRUD   data_action_orj.php   Download  
File: data_action_orj.php
Role: Example script
Content type: text/plain
Description: Example script
Class: Developbat PHP CRUD
Show pages to manage table records using Bootstrap
Author: By
Last change:
Date: 3 years ago
Size: 7,279 bytes
 

Contents

Class file image Download
<?php

error_reporting
(E_ALL);
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);

include(
'config.php');
include(
'functions.php');


if (isset(
$_POST['tableName']) && isset($_POST['dataId']) && $_POST['action'] == 'update') {

   
$inputType = 'text';

   
//$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++) {


       
$typePart = explode("(", $columns[$x][1]);
       
// echo $typePart[0];

       
$inputType = inputType($typePart[0]);

        if (
$columns[$x][3] == 'PRI') {
           
$primary = 'readonly=""';

            echo
'<input type="hidden" name="table_name_order_id" value="' . $columns[$x][0] . '"/>';
        } else {
           
$primary = '';
        }
        if (
$columns[$x][4] == 'NULL' && $columns[$x][3] == 'YES') {
           
$required = '';
        } else {
           
$required = 'required';
        }

        if (isset(
$imageColums[$_POST['tableName']]) && $imageColums[$_POST['tableName']] == $columns[$x][0]) {
           
$imgAray = json_decode($rows[0][$x]);
            echo
'<div class="form-group">
               <label for="'
. $columns[$x][0] . '">' . $columns[$x][0] . ' </label>';
            echo
'<input id="files" class="form-control" type="file" value="" /> </div>';
          
// echo '<input id="filesinput" class="form-control" type="hidden" name="' . $columns[$x][0] . '" value="' . json_encode($imgAray) . '" /> </div>';
           
echo '<textarea id="filesinput" class="form-control" type="hidden" name="' . $columns[$x][0] . '" >'. json_encode($imgAray) .'</textarea> </div>';
         
$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>';

        } else {
       
//var_dump($columns[$x]);
       
if ($inputType != 'option') {
            echo
'<div class="form-group">
         <label for="'
. $columns[$x][0] . '">' . $columns[$x][0] . ' </label>';
            echo
'<input id="' . $columns[$x][0] . '" class="form-control" type="' . $inputType . '" name="' . $columns[$x][0] . '" value="' . $rows[0][$x] . '" ' . $required . ' ' . $primary . ' /> </div>';
        } else {

           
$nobraclet = trim($columns[$x][1], "enum'()'");
           
$anumaray = explode("','", $nobraclet);
            echo
'<div class="form-group">
         <label for="'
. $columns[$x][0] . '">' . $columns[$x][0] . ' </label>';
            echo
'<select class="form-control" id="' . $columns[$x][0] . '" name="' . $columns[$x][0] . '">';
            foreach (
$anumaray as $option) {
                if (
$rows[0][$x] == $option) {
                    echo
'<option value="' . $option . '" selected="">' . $option . '</option>';
                } else {
                    echo
'<option value="' . $option . '">' . $option . '</option>';
                }

            }
            echo
'</select></div>';
        }
    }
    }

    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++) {


       
$typePart = explode("(", $columns[$x][1]);

       
$inputType = inputType($typePart[0]);

        if (
$columns[$x][3] == 'PRI') {

        } else {
            if (
$columns[$x][4] == 'NULL') {
               
$required = '';
            } else {
               
$required = 'required';
            }

          
// var_dump($imageColums[$_POST['tableName']]);
            //echo $imageColums[$_POST['tableName']] .' - ' . [$columns[$x][0]];

           
if (isset($imageColums[$_POST['tableName']]) && $imageColums[$_POST['tableName']] == $columns[$x][0]) {
                echo
'<div class="form-group">
               <label for="'
. $columns[$x][0] . '">' . $columns[$x][0] . ' </label>';
                echo
'<input id="files" class="form-control" type="file" value="" /> </div>';
                echo
'<input id="filesinput" class="form-control" type="text" name="' . $columns[$x][0] . '" value="" /> </div>';
                echo
'<output id="resultimages" />';

            } else {

                if (
$inputType != 'option') {
                    echo
'<div class="form-group">
         <label for="'
. $columns[$x][0] . '">' . $columns[$x][0] . ' </label>';
                    echo
'<input id="' . $columns[$x][0] . '" class="form-control" type="' . $inputType . '" name="' . $columns[$x][0] . '" value="" ' . $required . '/> </div>';

                } else {

                   
$nobraclet = trim($columns[$x][1], "enum'()'");
                   
$anumaray = explode("','", $nobraclet);
                    echo
'<div class="form-group">
         <label for="'
. $columns[$x][0] . '">' . $columns[$x][0] . ' </label>';
                    echo
'<select class="form-control" id="' . $columns[$x][0] . '" name="' . $columns[$x][0] . '">';
                    foreach (
$anumaray as $option) {
                        echo
'<option value="' . $option . '">' . $option . '</option>';
                    }
                    echo
'</select></div>';
                }


            }


        }
    }

    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';
    }


}