diff --git a/announcement.php b/announcement.php deleted file mode 100644 index 6494e86..0000000 --- a/announcement.php +++ /dev/null @@ -1,27 +0,0 @@ -query($query) == TRUE) { - echo "Record added successfully"; - } else { - echo "Error added record: " . $link->error; - } - unlink("announcement.php"); - - } -} -?> diff --git a/balance.php b/balance.php deleted file mode 100644 index 59da1cd..0000000 --- a/balance.php +++ /dev/null @@ -1,25 +0,0 @@ -query($query) == TRUE) { - echo "Record added successfully"; - } else { - echo "Error added record: " . $link->error; - } - unlink("balance.php"); - - } -} -?> diff --git a/db.php b/db.php index c89eb54..51a07b3 100644 --- a/db.php +++ b/db.php @@ -1,9 +1,9 @@
addTPost($tble, $idCol); $mpty = $c->ifMpty($tble, $idCol); - $tmpfile = $tble . '.php'; + $tmpfile = 'tmp/' . $tble . '.php'; $myfile = fopen("$tmpfile", "w") or die("Unable to open file!"); $start = 'addItem($tble, $idCol); ?> @@ -246,7 +246,7 @@ function getID($tble) { $ecols = $c->updateData($tble, $idCol); $mpty = $c->ifMpty($tble, $idCol); - $tmpfile = $tble . '.php'; + $tmpfile = 'tmp/' . $tble . '.php'; $myfile = fopen("$tmpfile", "w") or die("Unable to open file!"); $content = 'editItem($tble, $id, $idCol); ?> diff --git a/index2.php b/index2.php new file mode 100644 index 0000000..f906bad --- /dev/null +++ b/index2.php @@ -0,0 +1,384 @@ + / + * Website Author: http://pepiuox.net/ / http://labemotion.net/ + * Author's licenses: http://pepiuox.net/license / http://labemotion.net/license + * Project Name: EasyCRUD + + * Contributors: + * Website Contributors: + + * Library list. + * Bootstrap http://www.getbootstrap.com + * Jquery http://www.jquery.com , + * Poppers https://popper.js.org/ + + * This file is a module or application for make simple CRUD based in PHP. + * Use of this source code is governed by an PEPIUOX / LAB EMOTION License included + * MIT License that can be found in the LICENSE file in the root directory of + * this source tree. + + * Distributed under the MIT License + * (license terms are at http://opensource.org/licenses/MIT). + + * */ +ob_start(); + +require_once("db.php"); + +$path = basename($_SERVER['REQUEST_URI']); +$file = basename($path); + +$fileName = basename($_SERVER['PHP_SELF']); + +if ($file == $fileName) { + header("Location: index.php?view=select"); +} + +function protect($string) { + $protection = htmlspecialchars(trim($string), ENT_QUOTES); + return $protection; +} + +/* Get id table as first column */ + +function getID($tble) { + global $link; + if (!empty(protect($_GET['tbl']))) { + $tble = protect($_GET['tbl']); + $query = "SELECT * from " . $tble; + if ($result = $link->query($query)) { + /* Get field information for first column */ + $result->field_seek(0); + $deletemeta = $result->fetch_field(); + return $deletemeta->name; + } + } +} + +$view = protect($_GET['view']); +?> + + + + + + + <?php +if (isset($_GET['tbl'])) { + $titleTbl = str_replace("_", " ", protect($_GET['tbl'])); +} +if ($view === "select") { + echo 'Select your table - PHP CRUD'; +} elseif ($view === "list") { + echo 'List ' . $titleTbl . ' - PHP CRUD'; +} elseif ($view === "add") { + echo 'Add ' . $titleTbl . ' - PHP CRUD'; +} elseif ($view === "edit") { + echo 'Edit ' . $titleTbl . ' - PHP CRUD'; +} elseif ($view === "delete") { + echo 'Delete ' . $titleTbl . ' - PHP CRUD'; +} +?> + + + + + + + + +
+
+
+

Form

+
+
+
+ + + +
+
+
+
+ +
+
+
+ Back to select List ' . $titleTbl . ''; + ?> +
+
+ ' . "\n"; + echo '' . "\n"; + echo '' . "\n"; + echo '' . "\n"; + $sql = "SELECT * FROM $tble"; + $result = $link->query($sql); + $i = 0; + while ($i < mysqli_num_fields($result)) { + $meta = mysqli_fetch_field($result); + $remp = str_replace("_", " ", $meta->name); + echo '' . "\n"; + $i = $i + 1; + } + echo '' . "\n"; + echo '' . "\n"; + echo '' . "\n"; + echo '' . "\n"; + + while ($row = mysqli_fetch_row($result)) { + echo '' . "\n"; + $count = count($row); + $y = 0; + while ($y < $count) { + $c_row = current($row); + if ($y == 0) { + echo '' . "\n"; + } else { + echo '' . "\n"; + } + next($row); + $y = $y + 1; + } + + $i_row = $row[0]; + echo ''; + + echo '' . "\n"; + $i = $i + 1; + } + echo '' . "\n"; + echo '
' . ucfirst($remp) . 'Add new
' . $c_row . '' . $c_row . ' + Edit + Delete +
' . "\n"; + echo '' . "\n"; + ?> +
+
+
+ +
+
+
+ Back to list Add ' . $tble . ''; + ?> +
+
+ +
+ + +' . $tble . ''; + $addQuery = 'SELECT * FROM ' . $tble; + $addResult = $link->query($addQuery); + + $idCol = getID($tble); + + + /* Init loop */ + + if (mysqli_num_fields($addResult) > 0) { + $addmetas = $addResult->fetch_fields(); + foreach ($addmetas as $addmeta) { + $remp = str_replace("_", " ", $addmeta->name); + if ($addmeta->name === $idCol) { + continue; + } else { + echo ' +
+ +
+ + ' . ucfirst($remp) . ' +
+
'; + } + } + } + /* End loop */ + echo ' +
+
+ +
+
'; + echo '
+'; + } else { + header("Location: index.php?view=select"); + } + ?> +
+
+
+ +
+
+
+ Back to list Edit ' . $tble . ''; + ?> +
+
+ +
+ + +' . $tble . ''; + + $editQuery = "SELECT * FROM $tble WHERE "; + $editQuery .= $idCol . "=" . $id; + + $editResult = $link->query($editQuery); + + if (mysqli_num_fields($editResult) > 0) { + $editmetas = $editResult->fetch_fields(); + $rqu = $editResult->fetch_array(); + foreach ($editmetas as $editmeta) { + $remp = str_replace("_", " ", $editmeta->name); + + if ($editmeta->name === $idCol) { + continue; + } else { + echo ' +
+ +
+ + ' . ucfirst($remp) . ' +
+
'; + } + } + } + echo ' +
+
+ +
+
'; + echo '
+'; + ?> + +
+
+
+ +
+
+
+ Back to list Delete ' . $tble . ''; + ?> +
+
+ query($deletequery); + echo '
+ ' . $tble . '' . "\n"; + $deletemetas = $deleteresult->fetch_fields(); + $drow = $deleteresult->fetch_array(); + + foreach ($deletemetas as $deletemeta) { + $cdta = $drow[$deletemeta->name]; + if ($deletemeta->name === $idCol) { + continue; + } else { + $remp = str_replace("_", " ", $deletemeta->name); + echo '
+ + +
' . "\n"; + } + } + echo '
+ +
' . "\n"; + echo '
' . "\n"; + } + ?> +
+
+
+ + + +