Content Management System für ein GLC-System (Garment life cycles)
Unser System hat eine festgelegte Ordnerstruktur, die die Übersichtlichkeit des Projektes während der10.1) Administrative Dateien
Die Administrativen Dateien in der Ebene "admin" werden wie folgt verwendet:10.1.1) labconnect.php
Diese Datei baut die Verbindung mit dem MYSQL-Server auf. Dabei müssen der Hostname, Datenbankname, Benutzername und das Passwort bekannt und richtig angegeben werden. Der Inhalt könnte wie folgt aussehen:<?php mysql_connect("localhost", "your_username", "your_password"); mysql_select_db("your_databasename"); function db_connect() { $result = new mysqli("localhost", "your_username", "your_password", "your_databasename"); if (!$result) return FALSE; $result->autocommit(TRUE); return $result; } function get_cgi_param ($feld, $default) { $var = $default; $rmeth = $_SERVER['REQUEST_METHOD']; if ($rmeth == 'GET') { if (isset ($_GET[$feld]) && $_GET[$feld] != "") { $var = $_GET[$feld]; } } elseif ($rmeth == 'POST') { if (isset ($_POST[$feld]) && $_POST[$feld] != "") { $var = $_POST[$feld]; } } return $var; } ?>
10.1.2) labheader.php
Diese Datei beinhaltet das Grundgerüst, die Navigation und den administrativen Bereich, den für das ganze Projekt verwendet wird.<?php session_start(); ?> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta content="text/html; charset=utf-8" http-equiv="Content-Type" /> <title>GLC by Mehdi Bandegani</title> <link href="css/bootstrap.min.css" rel="stylesheet"> <link href="css/startmin.css" rel="stylesheet"> <link href="css/font-awesome.min.css" rel="stylesheet" type="text/css"> </head> <body> <!-- Begin wrapper --> <div id="wrapper"> <!-- Begin top nav --> <nav class="navbar navbar-default navbar-fixed-top" role="navigation" style="background-color: #F0F8FF;"> <div class="row"> <div class="col-md-1 col-lg-1 col-sm-12 col-xs-12"></div><!-- free col-md-1 --> <div class="col-md-10 col-lg-10 col-sm-12 col-xs-12"> <ul class="nav navbar-nav"> <li><a href="../index.php"><span class="fa fa-home"></span> HOME</a></li> <li><a href="../doc/labdescription.php"><span class="fa fa-edit"></span> DESCRIPTION</a></li> <li><a href="../shop/index.php"><span class="fa fa-cart"></span> GLC </a></li> <?php if ($_SESSION['editor_user'] || $_SESSION['admin_user']){ ?> <li><a href="lablogout.php"><span class="fa fa-user"> LOGOUT </span></a></li> <li><a href="labadmin.php"><span class="fa fa-user-secret"> ADMIN </span></a></li> <?php } else { ?> <li><a href="lablogin.php"><span class="fa fa-user-plus"> LOGIN </span></a></li> <?php } ?> </ul> </div> <!-- End col-10 --> <div class="col-md-1 col-lg-1 col-sm-12 col-xs-12"></div><!-- free col-md-1 --> </div><!-- End row --> </nav> <!-- End top nav --> <br /><br /><br />
10.1.3) labfooter.php
Diese Datei beinhaltet den Abschluss vom dem Grundgerüst, JS-Dateien und den Fußbereich vom administrativen Bereich, den für das ganze Projekt verwendet wird.</div><!-- End wrapper --> <!-- Begin footer --> <footer class="page-footer font-small blue-grey lighten-5"> <div class="footer-copyright text-center py-3" style="background-color: #F0F8FF;"> <ul class="list-unstyled"> <br /> <li> <a href="https://www.haw-hamburg.de/startseite.html">HAW-Hamburg</a> </li> <li> <a href="https://design.haw-hamburg.de/home/das-department-design/">Departement Design</a> </li> <li> <a href="https://vorlesungsverzeichnis.design.haw-hamburg.de/">Vorlesungsverzeichnis</a> </li> </ul> <a href="http://www.bandegani.de/"> <span class="fa fa-copyright"></span>2021 Copyright bandegani.de </a> </div> </footer><!-- End footer --> <!-- jQuery --> <script src="js/jquery.min.js"></script> <!-- Bootstrap Core JavaScript --> <script src="js/bootstrap.min.js"></script> <!-- Menu Plugin JavaScript --> <script src="js/startmin.js"></script> <!-- Labsidenav Plugin JavaScript --> <script src="js/metisMenu.min.js"></script> <script> // tooltip demo $('.tooltip-demo').tooltip({ selector: '[data-toggle=tooltip]', container: 'body' }) // popover demo $('[data-toggle=popover]').popover() $('.carousel').carousel() </script> </body> </html>
<?php
header("Location: ../index.php");
?>
Abb. 10.2.1 Tabellenschema für das GLC-System
Abb. 10.2.2 Datenbanktabelle tblusers
CREATE TABLE IF NOT EXISTS `tblusers` (
`user_id` int(11) NOT NULL,
`prename` varchar(50) DEFAULT NULL,
`name` varchar(50) DEFAULT NULL,
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`updated_at` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`email` varchar(100) NOT NULL,
`password` varchar(80) DEFAULT NULL,
`encrypted_password` varchar(80) DEFAULT NULL,
`role` varchar(20) NOT NULL,
`pic` varchar(100) DEFAULT NULL,
`content` varchar(120) DEFAULT NULL
) ENGINE=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
ALTER TABLE `tblusers`
ADD PRIMARY KEY (`user_id`);
ALTER TABLE `tblusers`
MODIFY `user_id` int(11) NOT NULL AUTO_INCREMENT,AUTO_INCREMENT=1;
Abb. 10.2.3 Datenbanktabelle (tblcategories)
CREATE TABLE IF NOT EXISTS `tblcategories` (
`cat_id` int(3) NOT NULL,
`name` varchar(30) NOT NULL,
`activ` tinyint(1) NOT NULL DEFAULT '0'
) ENGINE=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
ALTER TABLE `tblcategories`
ADD PRIMARY KEY (`cat_id`);
ALTER TABLE `tblcategories`
MODIFY `cat_id` int(3) NOT NULL AUTO_INCREMENT,AUTO_INCREMENT=1;
Abb. 10.2.4 Datenbanktabelle (tblsubcategories)
CREATE TABLE IF NOT EXISTS `tblsubcategories` (
`subcat_id` tinyint(4) NOT NULL,
`name` varchar(100) CHARACTER SET latin1 NOT NULL,
`cat_id` int(2) NOT NULL,
`activ` tinyint(1) NOT NULL DEFAULT '0'
) ENGINE=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
ALTER TABLE `tblsubcategories`
ADD PRIMARY KEY (`subcat_id`);
ALTER TABLE `tblsubcategories`
MODIFY `subcat_id` tinyint(4) NOT NULL AUTO_INCREMENT,AUTO_INCREMENT=1;
Mit dem Feld (cat_id) kann die Beziehung zu der Tabelle (tblcategories) hergestellt werden.
Abb. 10.2.5 Datenbanktabelle (tblarticles)
CREATE TABLE IF NOT EXISTS `tblarticles` (
`article_id` int(11) NOT NULL,
`name` varchar(60) NOT NULL,
`code` varchar(60) CHARACTER SET latin1 NOT NULL,
`clothname` varchar(50) NOT NULL,
`care_id` int(11) NOT NULL,
`pic` varchar(150) DEFAULT NULL,
`type` varchar(150) DEFAULT NULL,
`picbarcode` varchar(150) DEFAULT NULL,
`modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`price` float(7,2) NOT NULL,
`content` varchar(250) DEFAULT NULL,
`activ` tinyint(1) NOT NULL DEFAULT '0',
`primacy` tinyint(1) NOT NULL DEFAULT '1',
`counter` int(11) NOT NULL
) ENGINE=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
ALTER TABLE `tblarticles`
ADD PRIMARY KEY (`article_id`);
ALTER TABLE `tblarticles`
MODIFY `article_id` int(11) NOT NULL AUTO_INCREMENT,AUTO_INCREMENT=1;
Mit den Feld (care_id) wird die Beziehungen zu den Tabelle (tblcare)hergestellt.
Abb. 10.2.6 Datenbanktabelle (tblarticle_subcategory)
CREATE TABLE IF NOT EXISTS `tblarticle_subcategory` ( `subcat_id` int(11) DEFAULT NULL, `article_id` int(11) DEFAULT NULL ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
Abb. 10.2.7 Datenbanktabelle (tblarticle_user)
CREATE TABLE IF NOT EXISTS `tblarticle_user` ( `user_id` int(11) DEFAULT NULL, `article_id` int(11) DEFAULT NULL ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
Abb. 10.2.8 Datenbanktabelle (tblcare)
CREATE TABLE IF NOT EXISTS `tblcare` (
`care_id` int(11) NOT NULL,
`strcode` varchar(7) NOT NULL,
`marktype` varchar(10) NOT NULL DEFAULT 'single',
`content` text,
`pic` varchar(150) DEFAULT NULL
) ENGINE=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
ALTER TABLE `tblcare`
ADD PRIMARY KEY (`care_id`);
ALTER TABLE `tblcare`
MODIFY `care_id` int(11) NOT NULL AUTO_INCREMENT,AUTO_INCREMENT=1;
Abb. 10.2.9 Datenbanktabelle (tblorders)
CREATE TABLE IF NOT EXISTS `tblorders` ( `order_id` int(11) NOT NULL, `customer_id` int(11) NOT NULL, `delivery_id` int(11) NOT NULL, `modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, `status` tinyint(4) NOT NULL, `session` varchar(100) CHARACTER SET latin1 NOT NULL, `total` float NOT NULL ) ENGINE=MyISAM DEFAULT CHARSET=utf8; ALTER TABLE `tblorders` ADD PRIMARY KEY (`order_id`); ALTER TABLE `tblorders` MODIFY `order_id` int(11) NOT NULL AUTO_INCREMENT;
Abb. 10.2.10 Datenbanktabelle (tblorderitems)
CREATE TABLE IF NOT EXISTS `tblorderitems` ( `orderitem_id` int(11) NOT NULL, `order_id` int(11) NOT NULL, `article_id` int(11) NOT NULL, `number` int(11) NOT NULL, `quantity` int(11) NOT NULL, `price` float(6,2) NOT NULL ) ENGINE=MyISAM DEFAULT CHARSET=utf8; ALTER TABLE `tblorderitems` ADD PRIMARY KEY (`orderitem_id`); ALTER TABLE `tblorderitems` MODIFY `orderitem_id` int(11) NOT NULL AUTO_INCREMENT;
Abb. 10.2.11 Datenbanktabelle (tblpayments)
CREATE TABLE IF NOT EXISTS `tblpayments` (
`payment_id` int(10) NOT NULL,
`order_id` int(11) NOT NULL,
`invoice_no` int(10) NOT NULL,
`amount` int(10) NOT NULL,
`payment_mode` varchar(50) CHARACTER SET latin1 NOT NULL,
`ref_no` int(10) NOT NULL,
`payment_date` date NOT NULL
) ENGINE=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
ALTER TABLE `tblpayments`
ADD PRIMARY KEY (`payment_id`);
ALTER TABLE `tblpayments`
MODIFY `payment_id` int(10) NOT NULL AUTO_INCREMENT,AUTO_INCREMENT=1;
Abb. 10.2.12 Datenbanktabelle (tblcustomers)
CREATE TABLE IF NOT EXISTS `tblcustomers` (
`customer_id` int(11) NOT NULL,
`prename` varchar(50) CHARACTER SET latin1 NOT NULL,
`name` varchar(50) CHARACTER SET latin1 NOT NULL,
`address` varchar(50) CHARACTER SET latin1 DEFAULT NULL,
`city` varchar(50) CHARACTER SET latin1 DEFAULT NULL,
`region` varchar(30) CHARACTER SET latin1 COLLATE latin1_general_ci DEFAULT NULL,
`country` varchar(50) CHARACTER SET latin1 DEFAULT NULL,
`postcode` varchar(10) CHARACTER SET latin1 DEFAULT NULL,
`phone` varchar(20) CHARACTER SET latin1 DEFAULT NULL,
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`email` varchar(100) NOT NULL,
`password` varchar(80) DEFAULT NULL,
`encrypted_password` varchar(80) DEFAULT NULL,
`activ` tinyint(1) NOT NULL DEFAULT '0'
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
ALTER TABLE `tblcustomers`
ADD PRIMARY KEY (`customer_id`);
ALTER TABLE `tblcustomers`
MODIFY `customer_id` int(11) NOT NULL AUTO_INCREMENT,AUTO_INCREMENT=1;
Abb. 10.2.13 Datenbanktabelle (tbldeliveries)
CREATE TABLE IF NOT EXISTS `tbldeliveries` (
`delivery_id` int(11) NOT NULL,
`prename` varchar(50) CHARACTER SET latin1 NOT NULL,
`name` varchar(50) CHARACTER SET latin1 NOT NULL,
`address` varchar(50) CHARACTER SET latin1 DEFAULT NULL,
`city` varchar(50) CHARACTER SET latin1 DEFAULT NULL,
`region` varchar(30) CHARACTER SET latin1 COLLATE latin1_general_ci DEFAULT NULL,
`country` varchar(50) CHARACTER SET latin1 DEFAULT NULL,
`postcode` varchar(10) CHARACTER SET latin1 DEFAULT NULL,
`phone` varchar(20) CHARACTER SET latin1 DEFAULT NULL,
`modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`email` varchar(100) NOT NULL,
`activ` tinyint(1) NOT NULL DEFAULT '0'
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
ALTER TABLE `tbldeliveries`
ADD PRIMARY KEY (`delivery_id`);
ALTER TABLE `tbldeliveries`
MODIFY `delivery_id` int(11) NOT NULL AUTO_INCREMENT,AUTO_INCREMENT=1;
10.3.1) labsidenav.php
Diese Datei soll in dem Unterordner "admin" sich befinden und stellt die Navigation der Dateien für die Verwaltung der Stammdaten.<!-- navbar left --> <div class="navbar-default sidebar" role="navigation" style="background-color: #F0F8FF;"> <div class="sidebar-nav navbar-collapse" style="background-color: #F0F8FF;"> <ul class="nav" id="side-menu"> <li class="sidebar-search"> <div class="input-group custom-search-form"> <input type="text" class="form-control" placeholder="Search..."> <span class="input-group-btn"> <button class="btn btn-primary" type="button"> <i class="fa fa-search"></i> </button> </span> </div> </li> <li> <!-- for table 2 --> <a href="#">Management Categories<span class="fa arrow"></span></a> <ul class="nav nav-second-level"> <li><a href="labaddcategory.php">Insert Category</a></li> <li><a href="labeditcategory.php">Edit Category</a></li> <li><a href="labdeletecategory.php">Delete Category</a></li> </ul> </li> <li> <!-- for table 3 --> <a href="#">Management Subcategories<span class="fa arrow"></span></a> <ul class="nav nav-second-level"> <li><a href="labaddsubcategory.php">Insert Subcategory</a></li> <li><a href="labeditsubcategory.php">Edit Subcategory</a></li> <li><a href="labdeletesubcategory.php">Delete Subcategory</a></li> </ul> </li> <li> <!-- for table 4 --> <a href="#">Management Articles<span class="fa arrow"></span></a> <ul class="nav nav-second-level"> <li><a href="labaddarticle.php">Insert Article</a></li> <li><a href="labeditarticle.php">Edit Article</a></li> <li><a href="labdeletearticle.php">Delete Article</a></li> <!--li><a href="labaddbarcode.php">Insert Barcode</a></li--> </ul> </li> <li> <!-- for table 17 --> <a href="#">Management Care<span class="fa arrow"></span></a> <ul class="nav nav-second-level"> <li><a href="labaddcare.php">Insert Care</a></li> <li><a href="labeditcare.php">Edit Care</a></li> <li><a href="labdeletecare.php">Delete Care</a></li> </ul> </li> <li> <!-- for table 10 --> <a href="#">Management Customers<span class="fa arrow"></span></a> <ul class="nav nav-second-level"> <li><a href="labaddcustomer.php">Insert Customer</a></li> <li><a href="labeditcustomer.php">Edit Customer</a></li> <li><a href="labdeletecustomer.php">Delete Customer</a></li> </ul> </li> <li> <!-- for table 11 --> <a href="#">Management Deliveries<span class="fa arrow"></span></a> <ul class="nav nav-second-level"> <li><a href="labadddelivery.php">Insert Delivery</a></li> <li><a href="labeditdelivery.php">Edit Delivery</a></li> <li><a href="labdeletedelivery.php">Delete Delivery</a></li> </ul> </li> <?php if ($_SESSION["admin_user"]){ ?> <li> <!-- for table 1 --> <a href="#">Management Users<span class="fa arrow"></span></a> <ul class="nav nav-second-level"> <li><a href="labadduser.php">Insert Users</a></li> <li><a href="labedituser.php">Edit Users</a></li> <li><a href="labdeleteuser.php">Delete Users</a></li> </ul> </li> <?php } ?> </ul> </div> </div> <br /><br />
10.3.2) labadmin.php
Es gibt in diesem GLC-System 3 verschiedene Benutzer(admin, editor und subscriber), die in der Tabelle "tblusers" festgelegt wurden. Der Benutzer "admin" hat alle Rechte. Der Benutzer "editor" hat auch alle Rechte nur nicht die Verwaltung der Benutzerdaten. Der Benutzer "subscriber" ist nur für die Kommentare von den Webbesuchern festgelegt worden und hat kein Recht, Datensätze zu verwalten. Die Datei "labadmin.php" soll in dem Unterordner "admin" sich befinden und überprüft die 3 Benutzerrechte.<?php include("labheader.php"); session_start(); if(isset($_GET["section"])) { $section = $_GET["section"]; } else { $section = ""; } if ($_SESSION["editor_user"] || $_SESSION["admin_user"]){ include("labsidenav.php"); ?> <div id="page-wrapper"><div class="container-fluid"> <div class="row"> <div class="col-md-2 col-lg-2 col-sm-12 col-xs-12"></div> <span class="label label-success">Select the entry on the left, you want to use to manage the data records!</span> </div> </div> </div> <?php } elseif ($_SESSION["subscriber_user"]) { ?> <div id="page-wrapper"><div class="container-fluid"> <div class="row"> <div class="col-md-2 col-lg-2 col-sm-12 col-xs-12"></div> <span class="label label-danger">You are subscriber. You are not authorized to manage data!</span> </div> </div> </div> <?php } else { ?> <div id="page-wrapper"><div class="container-fluid"> <div class="row"> <div class="col-md-2 col-lg-2 col-sm-12 col-xs-12"></div> <span class="label label-danger">You could not be registered. You must be logged in to see this manage the data records!</span> </div> </div> </div> <?php } include("labfooter.php"); ?>
Wir wollen uns am System anmelden, um z.B. Artikel-, Kategorie- oder Unterkategoriedaten usw. zu verwalten. Um uns anzumelden, müssen wir zuerst die Felder im Formular (Abb. 10.3.3) ausfüllen und dann auf die Schaltfläche Login klicken. Der Benutzer, dessen Datensatz in der Tabelle(tblusers) eingetragen ist, kann die Daten für das Shopsystem verwalten.
Abb. 10.3.3 Login-Formular bei der Datei (lablogin.php)
<?php include("labheader.php"); session_start(); include ("labconnect.php"); if(isset($_POST["send"])) { if ($_POST["email"] && $_POST["password"]) { $email = $_POST["email"]; $password=md5($_POST["password"]); $sqlstr = "select * from tblusers where email='$email' and password = '$password'"; $res = mysql_query($sqlstr) or die ("no connection to the database ".mysql_error()); $num = mysql_fetch_array($res); if ($num["email"]==$email && $num["password"]==$password){ if ($num["role"]=="admin"){ // the admin_user have all access rights! $_SESSION["admin_user"] = $email; $_SESSION["user_id"] = $num["user_id"]; } elseif ($num["role"]=="editor") { $_SESSION["editor_user"] = $email; $_SESSION["user_id"] = $num["user_id"]; } elseif ($num["role"]=="subscriber") { $_SESSION["subscriber_user"] = $email; $_SESSION["user_id"] = $num["user_id"]; } header("Location: labadmin.php"); } else { ?> <div class="row"> <div class="col-md-12 col-sm-12 col-xs-12"></div> <span class="label label-danger">You could not be registered. You must be logged in to see this page.!</span> </div> <?php } ?> <div class="row"> <div class="col-md-12 col-sm-12 col-xs-12"></div> <span class="label label-danger">Your username or password is incorrect!</span> </div> <?php } mysql_free_result($res); } ?> <div class="row"><!-- Begin row --> <div class="col-md-4 col-lg-4 col-sm-12 col-xs-12"></div><!-- free col --> <div class="col-md-4 col-lg-4 col-sm-12 col-xs-12"><!-- Begin col --> <div class="panel panel-primary"><!-- Begin Panel --> <div class="panel-heading"> <h2 class="panel-title">Login - Formular</h2> </div> <div class="panel-body"> <form enctype="multipart/form-data" method="post" action="lablogin.php"> <div class="form-group"> <label class="control-label" for="inputUsername">Username:</label> <input type="text" name="email" class="form-control" id="inputUsername" required> <div style="height: 15px;"></div> </div> <div class="form-group"> <label class="control-label" for="inputPassword">Password:</label> <input type="Password" name="password" class="form-control" id="inputPassword" required> <div style="height: 15px;"></div> </div> <div class="form-group"> <button type="submit" name="send" class="btn btn-primary"> <span class="fa fa-lock"></span> Login</button> </div> </form> </div> </div><!-- End Panel --> </div> <!-- End col --> <div class="col-md-4 col-lg-4 col-sm-12 col-xs-12"></div><!-- free col --> </div><!-- End row --> <?php include("labfooter.php");?>
Mit der Rubrik "LOGOUT im Navigationsbereich wird die Datei "lablogout.php" ausgeführt, in dem der Benutzer sich am System abmelden kann.
<?php session_start(); $old_user = $_SESSION["editor_user"]; unset($_SESSION["editor_user"]); $old_admin = $_SESSION["admin_user"]; unset($_SESSION["admin_user"]); session_destroy(); if (!empty($old_user)) { require_once("labheader.php"); ?> <div id="page-wrapper"><div class="container-fluid"> <div class="row"> <div class="col-md-2 col-lg-2 col-sm-12 col-xs-12"></div> <span class="label label-success">You are Logout!</span> </div> </div> </div> <?php require_once("labfooter.php"); } else { header("Location: lablogin.php"); } ?>
Wenn der Hauptbenutzer angemeldet ist, können alle Datensätze in alle Tabellen u.a (tblusers) hinzugefügt werden. Die Abb.10.3.5a und Abb.10.3.5b zeigen den Ablauf, um einen Datensatz in die Tabelle (tblusers) hinzuzufügen.
Abb. 10.3.5a User-Formular bei der Datei (labadduser.php)
Abb. 10.3.5b Die Liste der eingetragenen Benutzern
<?php session_start(); include("labheader.php"); include("labconnect.php"); include("labsidenav.php"); $user_id = $_SESSION["user_id"]; if($user_id<=0){ ?> <div id="page-wrapper"><div class="container-fluid"> <div class="bg-darkred fg-white"> <span class="label label-danger">You are not logged in!</span> </div> </div></div> <?php } else { if(isset($_FILES["pic"])){ $errors= array(); $pic_name = $_FILES["pic"]["name"]; $pic_size = $_FILES["pic"]["size"]; $pic_tmp = $_FILES["pic"]["tmp_name"]; $pic_type = $_FILES["pic"]["type"]; $pic_ext=strtolower(end(explode('.',$_FILES["pic"]["name"]))); $unique_image = substr(md5(time()), 0, 10).'.'.$pic_ext; $uploaded_image = "uploads/user/".$unique_image; $prename = $_POST["prename"]; $name = $_POST["name"]; $prename = $_POST["prename"]; $email = $_POST["email"]; $password = MD5($_POST["password"]); $role = $_POST["role"]; $content = $_POST["content"]; if(empty($errors)==true) { $type = pathinfo($pic_name, PATHINFO_EXTENSION); $picExists = true; while ($picExists) { if (!file_exists($uploadDirectory.$uploaded_image)) { $picExists = false; } } move_uploaded_file($pic_tmp,$uploadDirectory.$uploaded_image); $mediaType = "something"; switch ($type) { case "jpg": case "jpeg": case "gif": case "png": default: $mediaType = "image"; break; } $sqlstr = "INSERT INTO tblusers (prename, name, email, role, password, content, pic) VALUES('$prename','$name', '$email', '$role', '$password','$content', '$uploaded_image')"; $res = mysql_query($sqlstr) or die ("no connection to the database ".mysql_error()); $num = mysql_affected_rows(); // for new article_count if ($num>0) { display_list_users(); }else{ ?> <div id="page-wrapper"><div class="container-fluid"> <div class="bg-darkred fg-white"> <span class="label label-danger">No record has been added to the database!</span> </div> </div></div> <?php } }else{ print_r($errors); } }else { ?> <div id="page-wrapper"><div class="container-fluid"> <div class="row"> <div class="col-md-12 col-lg-12 col-sm-12 col-xs-12"> <div class="panel panel-primary"> <div class="panel-heading"> <h2 class="panel-title">Insert user - Form</h2> </div> <div class="panel-body"> <form method="post" enctype="multipart/form-data" action="labadduser.php"> <div class="form-group"> <label class="control-label" for="inputName">Name:</label> <input type="text" name="name" class="form-control" id="inputName" placeholder="Enter name"> </div> <div class="form-group"> <label class="control-label" for="inputPrename">Prename:</label> <input type="text" name="prename" class="form-control" id="inputPrename" placeholder="Enter prename"> </div> <div class="form-group"> <label class="control-label" for="inputEmail">Email:</label> <input type="email" name="email" class="form-control" id="inputEmail" placeholder="Enter email"> </div> <div class="form-group"> <label class="control-label" for="inputPassword">Password:</label> <input type="password" name="password" class="form-control" id="inputPassword" placeholder="Enter password"> </div> <div class="form-group"> <label>a image for user</label> <input type="file" name="pic" class="form-control" id="uploadFile" data-role="file" required /></p> </div> <div class="form-group"> <label class="control-label">Role:</label> <select name="role" class="form-control" data-role="select"> <option value="admin">admin</option> <option value="editor">editor</option> <option value="admin">subscriber</option> </select> </div> <div class="form-group"> <label>content:</label> <textarea name="content" data-role="textarea" class="form-control" rows="3"></textarea> </div> <div class="form-group"> <button type="submit" name="send" class="btn btn-primary"> <span class="fa fa-send"></span> Insert the record</button> </div> </form> </div> </div> </div> </div> </div></div> <?php } }// End of $user_id function display_list_users(){ $sqlstr = "select * from tblusers ORDER BY user_id"; $res = mysql_query($sqlstr) or die ("no connection to the database ".mysql_error()); $num = mysql_num_rows($res); ?> <div id="page-wrapper"><div class="container-fluid"> <div class="row"> <div class="col-md-12 col-lg-12 col-sm-12 col-xs-12"> <div class="panel panel-primary"> <div class="panel-heading"> <h2 class="panel-title">List the database: <small>tblusers</small></h2> </div> <div class="panel-body"> <div class="table-responsive"><table class="table"> <thead> <tr><th>user_id</th><th>prename</th><th>name</th><th>email</th><th>password</th><th>role</th><th>pic</th><th>content</th></tr> </thead> <tbody> <?php while ($row = mysql_fetch_assoc($res)) { ?> <tr> <td><?php echo $row["user_id"]; ?></td> <td><?php echo $row["prename"]; ?></td> <td><?php echo $row["name"]; ?></td> <td><?php echo $row["email"]; ?></td> <td><?php echo $row["password"]; ?></td> <td><?php echo $row["role"]; ?></td> <td><img src="<?php echo $row["pic"]; ?>" style="height:80px; width:80px;"></td> <td><?php echo $row["content"]; ?></td> </tr> <?php } ?> </tbody> </table></div> </div> </div> </div> </div> </div></div> <?php mysql_free_result($res); } include("labfooter.php"); ?>
Wenn der Hauptbenutzer angemeldet ist, kann er die Datensätze von der Tabelle (tblusers) ändern. Die Abb.10.3.6a, Abb.10.3.6b und Abb.10.3.6c zeigen den Ablauf, um einen Datensatz in die Tabelle (tblusers) zu ändern.
Abb. 10.3.6a Liste der eingetragenen Benutzern als Formular bei der Datei (labedituser.php)
Abb. 10.3.6b Der ausgewählte Eintrag
Abb. 10.3.6c Die Liste der eingetragenen Benutzern bzw. des geänderten Eintrages
<?php session_start(); include("labheader.php"); include("labconnect.php"); include("labsidenav.php"); $uploadDirectory = __DIR__."/"; $user_id = $_SESSION["user_id"]; if($user_id<=0){ ?> <div id="page-wrapper"><div class="container-fluid"> <div class="bg-darkred fg-white"> <span class="label label-danger">You are not logged in!</span> </div> </div></div> <?php } else { if(isset($_POST["send"])){ // Delete old_image if (picdelete($_SESSION["picalt"])==false){ ?> <div id="page-wrapper"><div class="container-fluid"> <div class="bg-darkred fg-white"> <span class="label label-danger">Image file not find!!</span> </div> </div></div> <?php } $errors= array(); $pic_name = $_FILES["pic"]["name"]; $pic_size = $_FILES["pic"]["size"]; $pic_tmp = $_FILES["pic"]["tmp_name"]; $pic_type = $_FILES["pic"]["type"]; $pic_ext=strtolower(end(explode('.',$_FILES["pic"]["name"]))); $unique_image = substr(md5(time()), 0, 10).'.'.$pic_ext; $uploaded_image = "uploads/user/".$unique_image; $prename = $_POST["prename"]; $name = $_POST["name"]; $prename = $_POST["prename"]; $email = $_POST["email"]; if($_SESSION["passwordalt"]==$_POST["password"] ){ $password =$_POST["password"]; } else { $password = MD5($_POST["password"]); } $role = $_POST["role"]; $content = $_POST["content"]; if(empty($errors)==true) { $type = pathinfo($pic_name, PATHINFO_EXTENSION); $picExists = true; while ($picExists) { if (!file_exists($uploadDirectory.$uploaded_image)) { $picExists = false; } } move_uploaded_file($pic_tmp,$uploadDirectory.$uploaded_image); $mediaType = "something"; switch ($type) { case "jpg": case "jpeg": case "gif": case "png": default: $mediaType = "image"; break; } $sqlstr = "UPDATE tblusers SET prename='$prename', name='$name', email='$email', password='$password', role='$role', content='$content', pic='$uploaded_image' WHERE user_id = " . $_POST["oripn"]; $res = mysql_query($sqlstr) or die ("erroror inserting data ".mysql_error()); $num = mysql_affected_rows(); if ($num<0) { ?> <div id="page-wrapper"><div class="container-fluid"> <div class="bg-darkred fg-white"> <span class="label label-danger">No record has been added to the database!</span> </div> </div></div> <?php } }else{ print_r($errors); } } if (isset($_POST["selectID"])) { $sqlstr = "select * from tblusers where user_id = " . $_POST["selectID"]; $res = mysql_query($sqlstr); $row = mysql_fetch_assoc($res); $_SESSION["picalt"]=$row["pic"]; $_SESSION["passportalt"]=$row["password"]; ?> <div id="page-wrapper"><div class="container-fluid"> <div class="row"> <div class="col-md-12 col-lg-12 col-sm-12 col-xs-12"> <div class="panel panel-primary"> <div class="panel-heading"> <h2 class="panel-title">Edit User - Form</h2> </div> <div class="panel-body"> <form action="labedituser.php" method="POST" enctype="multipart/form-data"> <div class="form-group"> <label>user_id:</label> <input type="text" name="user_id" class="form-control" value="<?php echo $_POST["selectID"]; ?>" disabled /> </div> <div class="form-group"> <label>Prename:</label> <input type="text" name="prename" class="form-control" value="<?php echo $row["prename"]; ?>"> </div> <div class="form-group"> <label>Name:</label> <input type="text" name="name" class="form-control" value="<?php echo $row["name"]; ?>"> </div> <div class="form-group"> <label class="control-label">Email-address:</label> <input type="email" name="email" class="form-control" value="<?php echo $row["email"]; ?>"> </div> <div class="form-group"> <label class="control-label">password:</label> <input type="password" name="password" class="form-control" value="<?php echo $row["password"]; ?>"> </div> <div class="form-group"> <label class="control-label">Role:</label> <select name="role" class="form-control" data-role="select"> <option value="admin">admin</option> <option value="editor">editor</option> <option value="admin">subscriber</option> </select> </div> <div class="form-group"> <label>Image for user:</label> <img src="<?php echo $row["pic"]?>" width="100px" height="100px"> <!--input type="file" name="pic" id="uploadFile" data-role="file" class="form-control" data-caption="Choose user image file" required /--> <input type="file" name="pic" id="uploadFile"> </div> <div class="form-group"> <label>Content:</label> <textarea class="form-control" rows="3" name="content"> <?php echo $row["content"]?> </textarea> </div> <div class="form-group"> <input type="hidden" name="oripn" value="<?php echo $_POST["selectID"]; ?>" /> <button type="submit" name="send" class="btn btn-primary"> <span class="fa fa-edit"></span> Edit the record</button> </div> </form> </div> </div> </div> </div> </div></div> <?php mysql_free_result($res); }else { display_edit_users(); } } // end of $user_id function display_edit_users(){ $sqlstr = "select * from tblusers ORDER BY user_id DESC"; $res = mysql_query($sqlstr) or die ("no connection to the database ".mysql_error()); $num = mysql_num_rows($res); ?> <div id="page-wrapper"><div class="container-fluid"> <div class="row"> <div class="col-md-12 col-lg-12 col-sm-12 col-xs-12"> <div class="panel panel-primary"> <div class="panel-heading"> <h2 class="panel-title">List the database: <small>tblusers</small></h2> </div> <div class="panel-body"> <form method="post" enctype="multipart/form-data" action="labedituser.php"> <div class="table-responsive"><table class="table"> <thead> <tr><th>user_id</th><th>prename</th><th>name</th><th>email</th><th>password</th><th>role</th><th>pic</th><th>content</th><th>select</th></tr> </thead> <tbody> <?php while ($row = mysql_fetch_assoc($res)) { ?> <tr> <td><?php echo $row["user_id"]; ?></td> <td><?php echo $row["prename"]; ?></td> <td><?php echo $row["name"]; ?></td> <td><?php echo $row["email"]; ?></td> <td><?php echo $row["password"]; ?></td> <td><?php echo $row["role"]; ?></td> <td><img src="<?php echo $row["pic"]; ?>" style="height:80px; width:80px;"></td> <td><?php echo $row["content"]; ?></td> <td><input type="checkbox" name="selectID" value="<?php echo $row["user_id"]; ?>" data-role="checkbox"></td> </tr> <?php } ?> </tbody> </table></div> <button type="submit" class="btn btn-primary"> <span class="fa fa-eye"></span> View the record</button> </form> </div> </div> </div> </div> </div></div> <?php mysql_free_result($res); } function picdelete($pic) { if ( file_exists($pic) ) { if( @unlink($pic) !== true ) throw new Exception("Could not delete file: " . $pic . " Please close all applications that are using it."); } return true; } include("labfooter.php"); ?>
Wenn der Hauptbenutzer angemeldet ist, kann er die Datensätze von der Tabelle (tblusers) löschen. Die Abb.10.3.7a, Abb.10.3.7b und Abb.10.3.7c zeigen den Ablauf, um einen Datensatz in die Tabelle (tblusers) zu löschen.
Abb. 10.3.7a Liste der eingetragenen Benutzern als Formular bei der Datei (labdeleteuser.php)
Abb. 10.3.7b Der ausgewählte Eintrag
Abb. 10.3.7c Die Liste der eingetragenen Benutzern bzw. des gel&oum;schten Eintrages
<?php session_start(); include("labheader.php"); include("labconnect.php"); include("labsidenav.php"); $uploadDirectory = __DIR__."/"; $user_id = $_SESSION["user_id"]; if($user_id<=0){ ?> <div id="page-wrapper"><div class="container-fluid"> <div class="bg-darkred fg-white"> <span class="label label-danger">You are not logged in!</span> </div> </div></div> <?php } else { if(isset($_POST["send"])){ // Delete old_image if (picdelete($_SESSION["picold"])==false){ ?> <div id="page-wrapper"><div class="container-fluid"> <div class="bg-darkred fg-white"> <span class="label label-danger">Image file not find!!</span> </div> </div></div> <?php } $sqlstr = "DELETE FROM tblusers WHERE user_id = " . $_POST["oripn"]; $res = mysql_query($sqlstr) or die ("erroror inserting data ".mysql_error()); $num = mysql_affected_rows(); if ($num<0) { ?> <div id="page-wrapper"><div class="container-fluid"> <div class="bg-darkred fg-white"> <span class="label label-danger">No record has been deleted to the database!</span> </div> </div></div> <?php } } if (isset($_POST["selectID"])) { $sqlstr = "select * from tblusers where user_id = " . $_POST["selectID"]; $res = mysql_query($sqlstr); $row = mysql_fetch_assoc($res); $_SESSION["picold"]=$row["pic"]; ?> <div id="page-wrapper"><div class="container-fluid"> <div class="row"> <div class="col-md-12 col-lg-12 col-sm-12 col-xs-12"> <div class="panel panel-primary"> <div class="panel-heading"> <h2 class="panel-title">Delete User - Form</h2> </div> <div class="panel-body"> <form action="labdeleteuser.php" method="POST" enctype="multipart/form-data"> <div class="form-group"> <label>user_id:</label> <input type="text" name="user_id" class="form-control" value="<?php echo $_POST["selectID"]; ?>" disabled /> </div> <div class="form-group"> <label>prename:</label> <input type="text" name="prename" class="form-control" value="<?php echo $row["prename"]; ?>"> </div> <div class="form-group"> <label>name:</label> <input type="text" name="name" class="form-control" value="<?php echo $row["name"]; ?>"> </div> <div class="form-group"> <label class="control-label">Email-address:</label> <input type="email" name="email" class="form-control" value="<?php echo $row["email"]; ?>"> </div> <div class="form-group"> <label class="control-label">password:</label> <input type="password" name="password" class="form-control" value="<?php echo $row["password"]; ?>"> </div> <div class="form-group"> <label class="control-label">Role:</label> <select name="role" class="form-control" data-role="select"> <option value="admin">admin</option> <option value="editor">editor</option> <option value="admin">subscriber</option> </select> </div> <div class="form-group"> <label>Content:</label> <textarea class="form-control" rows="3" name="content"> <?php echo $row["content"]?> </textarea> </div> <div class="form-group"> <input type="hidden" name="oripn" value="<?php echo $_POST["selectID"]; ?>" /> <button type="submit" name="send" class="btn btn-primary"> <span class="fa fa-trash"></span> Delete the record</button> </div> </form> </div> </div> </div> </div> </div></div> <?php mysql_free_result($res); }else { display_delete_users(); } } // end of $user_id function display_delete_users(){ $sqlstr = "select * from tblusers ORDER BY user_id DESC"; $res = mysql_query($sqlstr) or die ("no connection to the database ".mysql_error()); $num = mysql_num_rows($res); ?> <div id="page-wrapper"><div class="container-fluid"> <div class="row"> <div class="col-md-12 col-lg-12 col-sm-12 col-xs-12"> <div class="panel panel-primary"> <div class="panel-heading"> <h2 class="panel-title">List the database: <small>tblusers</small></h2> </div> <div class="panel-body"> <form method="post" enctype="multipart/form-data" action="labdeleteuser.php"> <div class="table-responsive"><table class="table"> <thead> <tr><th>user_id</th><th>prename</th><th>name</th><th>email</th><th>password</th><th>role</th><th>pic</th><th>content</th><th>select</th></tr> </thead> <tbody> <?php while ($row = mysql_fetch_assoc($res)) { ?> <tr> <td><?php echo $row["user_id"]; ?></td> <td><?php echo $row["prename"]; ?></td> <td><?php echo $row["name"]; ?></td> <td><?php echo $row["email"]; ?></td> <td><?php echo $row["password"]; ?></td> <td><?php echo $row["role"]; ?></td> <td><img src="<?php echo $row["pic"]; ?>" style="height:80px; width:80px;"></td> <td><?php echo $row["content"]; ?></td> <td><input type="checkbox" name="selectID" value="<?php echo $row["user_id"]; ?>" data-role="checkbox"></td> </tr> <?php } ?> </tbody> </table></div> <button type="submit" class="btn btn-primary"> <span class="fa fa-eye"></span> View the record</button> </form> </div> </div> </div> </div> </div></div> <?php mysql_free_result($res); } function picdelete($pic) { if ( file_exists($pic) ) { if( @unlink($pic) !== true ) throw new Exception("Could not delete file: " . $pic . " Please close all applications that are using it."); } return true; } include("labfooter.php"); ?>
Wenn ein Benutzer angemeldet ist, können u.a. Datensätze in die entsprechenden Tabellen in dem Fall (tblcategories) hinzugefügt werden. Die Abb.10.4.1a und Abb.10.4.1b zeigen den Ablauf, um einen Datensatz in die Tabelle (tblcategories) hinzuzufügen.
Abb. 10.4.1a Kategorie-Formular bei der Datei (labaddcategory.php)
Abb. 10.4.1b Die Liste der eingetragen Datensätze für Kategorie
<?php session_start(); include("labheader.php"); include("labconnect.php"); include("labsidenav.php"); $user_id = $_SESSION["user_id"]; if($user_id<=0){ ?> <div id="page-wrapper"><div class="container-fluid"> <div class="bg-darkred fg-white"> <span class="label label-danger">You are not logged in!</span> </div> </div></div> <?php } else { if(isset($_POST["send"])){ if(isset($_POST["activ"])) { $activ=1; }else { $activ=0; } $name=$_POST["name"]; $sqlstr = "insert tblcategories (name, activ) values ('$name', '$activ')"; $res = mysql_query($sqlstr) or die ("no connection to the database ".mysql_error()); $num = mysql_affected_rows(); if ($num>0) { display_list_categories(); } else { ?> <div id="page-wrapper"><div class="container-fluid"> <div class="bg-darkred fg-white"> <span class="label label-danger">No record has been added to the database!</span> </div> </div></div> <?php } mysql_free_result($res); }else { ?> <div id="page-wrapper"><div class="container-fluid"> <div class="row"> <div class="col-md-12 col-lg-12 col-sm-12 col-xs-12"> <div class="panel panel-primary"> <div class="panel-heading"> <h2 class="panel-title">Insert category - Form</h2> </div> <div class="panel-body"> <form method="post" enctype="multipart/form-data" action="labaddcategory.php"> <div class="form-group"> <label class="control-label" for="inputName">Name:</label> <input type="text" name="name" class="form-control" id="inputName" placeholder="Enter Category name"> </div> <div class="form-group"> <label>Activ: </label> <input type="checkbox" name="activ"><br /> <small class="text-muted">If the entry should be active, the checkbox must be clicked!</small> </div> <div class="form-group"> <button type="submit" name="send" class="btn btn-primary"> <span class="fa fa-send"></span> Insert the record</button> </div> </form> </div> </div> </div> </div> </div></div> <?php } }// End of $user_id function display_list_categories(){ $sqlstr = "select * from tblcategories ORDER BY cat_id"; $res = mysql_query($sqlstr) or die ("no connection to the database ".mysql_error()); $num = mysql_num_rows($res); ?> <div id="page-wrapper"><div class="container-fluid"> <div class="row"> <div class="col-md-12 col-lg-12 col-sm-12 col-xs-12"> <div class="panel panel-primary"> <div class="panel-heading"> <h2 class="panel-title">List the database: <small>tblcategories</small></h2> </div> <div class="panel-body"> <div class="table-responsive"><table class="table"> <thead> <tr><th>cat_id</th><th>name</th><th>activ</th></tr> </thead> <tbody> <?php while ($row = mysql_fetch_assoc($res)) { ?> <tr> <td><?php echo $row["cat_id"]; ?></td> <td><?php echo $row["name"]; ?></td> <td><?php echo $row["activ"]; ?></td> </tr> <?php } ?> </tbody> </table></div> </div> </div> </div> </div> </div></div> <?php mysql_free_result($res); } include("labfooter.php"); ?>
Wenn ein Benutzer angemeldet ist, können u.a. Datensätze in die entsprechenden Tabellen in dem Fall (tblcategories) geändert werden. Die Abb.10.4.2a, Abb.10.4.2b und Abb.10.4.2c zeigen den Ablauf, um einen Datensatz in die Tabelle (tblcategories) zu ändern.
Abb. 10.4.2a Kategorie-Tabellenformular für die Änderung eines Datensatzes (labeditcategory.php)
Abb. 10.4.2b Kategorie-Formular für die Änderung eines Datensatzes (labeditcategory.php)
Abb. 10.4.2c Kategorie-Tabellenformular nach der Änderung eines Datensatzes (labeditcategory.php)
<?php session_start(); include("labheader.php"); include("labconnect.php"); include("labsidenav.php"); $user_id = $_SESSION["user_id"]; if($user_id<=0){ ?> <div id="page-wrapper"><div class="container-fluid"> <div class="bg-darkred fg-white"> <span class="label label-danger">You are not logged in!</span> </div> </div></div> <?php } else { if(isset($_POST["send"])){ if(isset($_POST["activ"])) { $activ=1; }else { $activ=0; } $name=$_POST["name"]; $sqlstr = "update tblcategories set name='$name', activ='$activ' where cat_id=" . $_POST["oripn"]; $res = mysql_query($sqlstr) or die ("no connection to the database ".mysql_error()); $num = mysql_affected_rows(); if ($num<=0) { ?> <div id="page-wrapper"><div class="container-fluid"> <div class="bg-darkred fg-white"> <span class="label label-danger">The record has not been changed!</span> </div> </div></div> <?php } mysql_free_result($res); } if (isset($_POST["selectID"])) { $sqlstr = "select * from tblcategories where cat_id= " . $_POST["selectID"]; $res = mysql_query($sqlstr); $row = mysql_fetch_assoc($res); ?> <div id="page-wrapper"><div class="container-fluid"> <div class="row"> <div class="col-md-12 col-lg-12 col-sm-12 col-xs-12"> <div class="panel panel-primary"> <div class="panel-heading"> <h2 class="panel-title">Edit Category - Form</h2> </div><div class="table-responsive"> <div class="panel-body"> <form method="post" enctype="multipart/form-data" action="labeditcategory.php"> <div class="form-group"> <label class="control-label">Id:</label> <input type="text" name="cat_id" class="form-control" value="<?php echo $_POST["selectID"]; ?>" disabled /> </div> <div class="form-group"> <label class="control-label">Category name:</label> <input type="text" name="name" class="form-control" value="<?php echo $row["name"]; ?>"> </div> <?php if ($row["activ"] ==1){ ?> <div class="form-group"> <label>Activ: </label> <input type="checkbox" name="activ" checked> </div> <?php } else { ?> <div class="form-group"> <label>Activ: </label> <input type="checkbox" name="activ"> </div> <?php } ?> <div class="form-group"> <input type="hidden" name="oripn" value="<?php echo $_POST["selectID"]; ?>" /> <button type="submit" name="send" class="btn btn-primary"> <span class="fa fa-edit"></span> Edit the record</button> </div> </form> </div> </div> </div> </div> </div></div> <?php mysql_free_result($res); } else { display_edit_category(); } } // end of $user_id function display_edit_category(){ $sqlstr = "select * from tblcategories ORDER BY cat_id"; $res = mysql_query($sqlstr) or die ("no connection to the database ".mysql_error()); $num = mysql_num_rows($res); ?> <div id="page-wrapper"><div class="container-fluid"> <div class="row"> <div class="col-md-12 col-lg-12 col-sm-12 col-xs-12"> <div class="panel panel-primary"> <div class="panel-heading"> <h2 class="panel-title">List the database: <small>tblcategories</small></h2> </div> <div class="panel-body"> <form method="post" enctype="multipart/form-data" action="labeditcategory.php"> <div class="table-responsive"><table class="table"> <thead> <tr><th>cat_id</th><th>name</th><th>activ</th><th>select</th></tr> </thead> <tbody> <?php while ($row = mysql_fetch_assoc($res)) { ?> <tr> <td><?php echo $row["cat_id"]; ?></td> <td><?php echo $row["name"]; ?></td> <td><?php echo $row["activ"]; ?></td> <td><input type="checkbox" name="selectID" value="<?php echo $row["cat_id"]; ?>" data-role="checkbox"></td> </tr> <?php } ?> </tbody> </table></div> <button type="submit" class="btn btn-primary"> <span class="fa fa-eye"></span> View the record</button> </form> </div> </div> </div> </div> </div></div> <?php mysql_free_result($res); } include("labfooter.php"); ?>
Wenn ein Benutzer angemeldet ist, können u.a. Datensätze aus den entsprechenden Tabellen in dem Fall (tblcategories) gelöscht werden. Die Abb.10.4.3a, Abb.10.4.3b und Abb.10.4.3c zeigen den Ablauf, um einen Datensatz aus der Tabelle (tblcategories) zu löschen.
Abb. 10.4.3a Kategorie-Tabellenformular für das Löschen eines Datensatzes (labdeletecategory.php)
Abb. 10.4.3b Kategorie-Formular für das Löschen eines Datensatzes (labdeletecategory.php)
Abb. 10.4.3c Kategorie-Formular für das Löschen eines Datensatzes (labdeletecategory.php)
Der Inhalt der Datei (labdeletecategory.php)
<?php session_start(); include("labheader.php"); include("labconnect.php"); include("labsidenav.php"); $user_id = $_SESSION["user_id"]; if($user_id<=0){ ?> <div id="page-wrapper"><div class="container-fluid"> <div class="bg-darkred fg-white"> <span class="label label-danger">You are not logged in!</span> </div> </div></div> <?php } else { if(isset($_POST["send"])){ $sqlstr = "DELETE FROM tblcategories WHERE cat_id = " . $_POST["oripn"]; $res = mysql_query($sqlstr) or die ("no connection to the database ".mysql_error()); $num = mysql_affected_rows(); if ($num<=0) { ?> <div id="page-wrapper"><div class="container-fluid"> <div class="bg-darkred fg-white"> <span class="label label-danger">The record has not been deleted!</span> </div> </div></div> <?php } mysql_free_result($res); } if (isset($_POST["selectID"])) { $sqlstr = "select * from tblcategories where cat_id= " . $_POST["selectID"]; $res = mysql_query($sqlstr); $row = mysql_fetch_assoc($res); ?> <div id="page-wrapper"><div class="container-fluid"> <div class="row"> <div class="col-md-12 col-lg-12 col-sm-12 col-xs-12"> <div class="panel panel-primary"> <div class="panel-heading"> <h2 class="panel-title">Delete Category - Form</h2> </div> <div class="panel-body"> <form method="post" enctype="multipart/form-data" action="labdeletecategory.php"> <div class="form-group"> <label class="control-label">Id:</label> <input type="text" name="cat_id" class="form-control" value="<?php echo $_POST["selectID"]; ?>" disabled /> </div> <div class="form-group"> <label class="control-label">Category name:</label> <input type="text" name="name" class="form-control" value="<?php echo $row["name"]; ?>"> </div> <?php if ($row["activ"] ==1){ ?> <div class="form-group"> <label>Activ: </label> <input type="checkbox" name="activ" checked> </div> <?php } else { ?> <div class="form-group"> <label>Activ: </label> <input type="checkbox" name="activ"> </div> <?php } ?> <div class="form-group"> <input type="hidden" name="oripn" value="<?php echo $_POST["selectID"]; ?>" /> <button type="submit" name="send" class="btn btn-primary"> <span class="fa fa-trash"></span> Delete the record</button> </div> </form> </div> </div> </div> </div> </div></div> <?php mysql_free_result($res); } else { display_delete_category(); } } // end of $user_id function display_delete_category(){ $sqlstr = "select * from tblcategories ORDER BY cat_id"; $res = mysql_query($sqlstr) or die ("no connection to the database ".mysql_error()); $num = mysql_num_rows($res); ?> <div id="page-wrapper"><div class="container-fluid"> <div class="row"> <div class="col-md-12 col-lg-12 col-sm-12 col-xs-12"> <div class="panel panel-primary"> <div class="panel-heading"> <h2 class="panel-title">List the database: <small>tblcategories</small></h2> </div> <div class="panel-body"> <form method="post" enctype="multipart/form-data" action="labdeletecategory.php"> <div class="table-responsive"><table class="table"> <thead> <tr><th>cat_id</th><th>name</th><th>activ</th><th>Select</th></tr> </thead> <tbody> <?php while ($row = mysql_fetch_assoc($res)) { ?> <tr> <td><?php echo $row["cat_id"]; ?></td> <td><?php echo $row["name"]; ?></td> <td><?php echo $row["activ"]; ?></td> <td><input type="checkbox" name="selectID" value="<?php echo $row["cat_id"]; ?>" data-role="checkbox"></td> </tr> <?php } ?> </tbody> </table></div> <button type="submit" class="btn btn-primary"> <span class="fa fa-eye"></span> View the record</button> </form> </div> </div> </div> </div> </div></div> <?php mysql_free_result($res); } include("labfooter.php"); ?>
Wenn ein Benutzer angemeldet ist, können u.a. Datensätze in die entsprechenden Tabellen in dem Fall (tblsubcategories) hinzugefügt werden. Die Abb.10.4.4a und Abb.10.4.4b zeigen den Ablauf, um einen Datensatz in die Tabelle (tblsubcategories) hinzuzufügen.
Abb. 10.4.4a Unterkategorie-Formular für einen neuen Datensatz (labaddsubcategory.php)
Abb. 10.4.4b Hinzugefügter Datensatz (labaddsubcategory.php)
Der Inhalt der Datei (labaddsubcategory.php)
<?php session_start(); include("labheader.php"); include("labconnect.php"); include("labsidenav.php"); $user_id = $_SESSION["user_id"]; if($user_id<=0){ ?> <div id="page-wrapper"><div class="container-fluid"> <div class="bg-darkred fg-white"> <span class="label label-danger">You are not logged in!</span> </div> </div></div> <?php } else { if(isset($_POST["send"])){ if(isset($_POST["activ"])) { $activ=1; }else { $activ=0; } $name=$_POST["name"]; $cat_id = get_cgi_param ("cat_id", 0); if($cat_id){ $sqlstr = "insert tblsubcategories (name, cat_id, activ) values ('$name', '$cat_id', '$activ')"; $res = mysql_query($sqlstr) or die ("no connection to the database ".mysql_error()); $num = mysql_affected_rows(); if ($num>0) { display_list_subcategories(); } else { ?> <div id="page-wrapper"><div class="container-fluid"> <div class="bg-darkred fg-white"> <span class="label label-danger">No record has been added to the database!</span> </div> </div></div> <?php } mysql_free_result($res); }else { ?> <div id="page-wrapper"><div class="container-fluid"> <div class="bg-darkred fg-white"> <span class="label label-danger">ou must selected a category name!!</span> </div> </div></div> <?php } }else { ?> <div id="page-wrapper"><div class="container-fluid"> <div class="row"> <div class="col-md-12 col-lg-12 col-sm-12 col-xs-12"> <div class="panel panel-primary"> <div class="panel-heading"> <h2 class="panel-title">Insert subcategory - Form</h2> </div> <div class="panel-body"> <form method="post" enctype="multipart/form-data" action="labaddsubcategory.php"> <div class="form-group"> <label class="control-label" for="inputName">Subcategory name:</label> <input type="text" name="name" class="form-control" id="inputName" placeholder="Enter subcategory name"> </div> <div class="form-group"> <label class="control-label" for="inputSubcategoryname">Category name:</label> <select name="cat_id" class="form-control" id="inputSubcategoryname" data-role="select"> <?php $sqlstr = "SELECT cat_id, name FROM tblcategories ORDER BY name ASC"; $res = mysql_query($sqlstr) or die ("no connection to the database ".mysql_error()); while (list ($cat_id, $name) = mysql_fetch_row ($res)) { echo ("<option value=\"$cat_id\">$name (cat_id: $cat_id)</option>\n"); } ?> </select> </div> <div class="form-group"> <label>Activ: </label> <input type="checkbox" name="activ"><br /> <small class="text-muted">If the entry should be active, the checkbox must be clicked!</small> </div> <div class="form-group"> <button type="submit" name="send" class="btn btn-primary"> <span class="fa fa-send"></span> Insert the record</button> </div> </form> </div> </div> </div> </div> </div></div> <?php mysql_free_result($res); } }// End of $user_id function display_list_subcategories(){ $sqlstr = "select * from tblsubcategories ORDER BY subcat_id "; $res = mysql_query($sqlstr) or die ("no connection to the database ".mysql_error()); $num = mysql_num_rows($res); ?> <div id="page-wrapper"><div class="container-fluid"> <div class="row"> <div class="col-md-12 col-lg-12 col-sm-12 col-xs-12"> <div class="panel panel-primary"> <div class="panel-heading"> <h2 class="panel-title">List the database: <small>tblsubcategories</small></h2> </div> <div class="panel-body"> <div class="table-responsive"><table class="table"> <thead> <tr><th>subcat_id</th><th>name</th><th>cat_id</th><th>activ</th></tr> </thead> <tbody> <?php while ($row = mysql_fetch_assoc($res)) { ?> <tr> <td><?php echo $row["subcat_id"]; ?></td> <td><?php echo $row["name"]; ?></td> <td><?php echo $row["cat_id"]; ?></td> <td><?php echo $row["activ"]; ?></td> </tr> <?php } ?> </tbody> </table></div> </div> </div> </div> </div> </div></div> <?php mysql_free_result($res); } include("labfooter.php"); ?>
Wenn ein Benutzer angemeldet ist, können u.a. Datensätze in die entsprechenden Tabellen in dem Fall (tblsubcategories) geändert werden. Die Abb.10.4.5a, Abb.10.4.5b und Abb.10.4.5c zeigen den Ablauf, um einen Datensatz in die Tabelle (tblsubcategories) zu ändern.
Abb. 10.4.5a Unterkategorie-Tabellenformular für die Änderung eines Datensatzes (labeditsubcategory.php)
Abb. 10.4.5b Unterkategorie-Tabelle nach der Änderung eines Datensatzes (labeditsubcategory.php)
Abb. 10.4.5c Unterkategorie-Tabelle nach der Änderung eines Datensatzes (labeditsubcategory.php)
Der Inhalt der Datei (labeditsubcategory.php)
<?php session_start(); include("labheader.php"); include("labconnect.php"); include("labsidenav.php"); $user_id = $_SESSION["user_id"]; if($user_id<=0){ ?> <div id="page-wrapper"><div class="container-fluid"> <div class="bg-darkred fg-white"> <span class="label label-danger">You are not logged in!</span> </div> </div></div> <?php } else { if(isset($_POST["send"])){ if(isset($_POST["activ"])) { $activ=1; }else { $activ=0; } $name=$_POST["name"]; $cat_id = get_cgi_param ("cat_id", 0); if($cat_id){ $sqlstr = "update tblsubcategories set name='$name', activ ='$activ', cat_id ='$cat_id' where subcat_id = " . $_POST["oripn"]; $res = mysql_query($sqlstr) or die ("no connection to the database ".mysql_error()); $num = mysql_affected_rows(); if ($num<=0) { ?> <div id="page-wrapper"><div class="container-fluid"> <div class="bg-darkred fg-white"> <span class="label label-danger">No record has been changed!!</span> </div> </div></div> <?php } mysql_free_result($res); }else { ?> <div id="page-wrapper"><div class="container-fluid"> <div class="bg-darkred fg-white"> <span class="label label-danger">ou must selected a category name!!</span> </div> </div></div> <?php } } if (isset($_POST["selectID"])) { $sqlstr = "select * from tblsubcategories where subcat_id = " . $_POST["selectID"]; $res = mysql_query($sqlstr); $row = mysql_fetch_assoc($res); ?> <div id="page-wrapper"><div class="container-fluid"> <div class="row"> <div class="col-md-12 col-lg-12 col-sm-12 col-xs-12"> <div class="panel panel-primary"> <div class="panel-heading"> <h2 class="panel-title">Edit Subcategory - Form</h2> </div> <div class="panel-body"> <form method="post" enctype="multipart/form-data" action="labeditsubcategory.php"> <div class="form-group"> <label class="control-label">Id:</label> <input type="text" name="subcat_id" class="form-control" value="<?php echo $_POST["selectID"]; ?>" disabled /> </div> <div class="form-group"> <label class="control-label">Subcategory name:</label> <input type="text" name="name" class="form-control" value="<?php echo $row["name"]; ?>"> </div> <div class="form-group"> <label class="control-label">Category name:</label> <select name="cat_id" class="form-control" data-role="select"> <?php $sqlstr = "SELECT cat_id, name FROM tblcategories ORDER BY name ASC"; $res = mysql_query($sqlstr) or die ("no connection to the database ".mysql_error()); while (list ($cat_id, $name) = mysql_fetch_row ($res)) { echo ("<option value=\"$cat_id\">$name (cat_id: $cat_id)</option>\n"); } ?> </select> </div> <?php if ($row["activ"] ==1){ ?> <div class="form-group"> <label>Activ: </label> <input type="checkbox" name="activ" checked> </div> <?php } else { ?> <div class="form-group"> <label>Activ: </label> <input type="checkbox" name="activ"> </div> <?php } ?> <div class="form-group"> <input type="hidden" name="oripn" value="<?php echo $_POST["selectID"]; ?>" /> <button type="submit" name="send" class="btn btn-primary"> <span class="fa fa-edit"></span> Edit the record</button> </div> </form> </div> </div> </div> </div> </div></div> <?php } else { display_edit_subcategories(); } } // end of $user_id function display_edit_subcategories(){ $sqlstr = "select * from tblsubcategories ORDER BY subcat_id "; $res = mysql_query($sqlstr) or die ("no connection to the database ".mysql_error()); $num = mysql_num_rows($res); ?> <div id="page-wrapper"><div class="container-fluid"> <div class="row"> <div class="col-md-12 col-lg-12 col-sm-12 col-xs-12"> <div class="panel panel-primary"> <div class="panel-heading"> <h2 class="panel-title">List the database: <small>tblsubcategories</small></h2> </div> <div class="panel-body"> <form method="post" enctype="multipart/form-data" action="labeditsubcategory.php"> <div class="table-responsive"><table class="table"> <thead> <tr><th>subcat_id</th><th>name</th><th>activ</th><th>cat_id</th><th>select</th></tr> </thead> <tbody> <?php while ($row = mysql_fetch_assoc($res)) { ?> <tr> <td><?php echo $row["subcat_id"]; ?></td> <td><?php echo $row["name"]; ?></td> <td><?php echo $row["activ"]; ?></td> <td><?php echo $row["cat_id"]; ?></td> <td><input type="checkbox" name="selectID" value="<?php echo $row["subcat_id"]; ?>" data-role="checkbox"></td> </tr> <?php } ?> </tbody> </table></div> <button type="submit" class="btn btn-primary"> <span class="fa fa-eye"></span> View the record</button> </form> </div> </div> </div> </div> </div></div> <?php mysql_free_result($res); } include("labfooter.php"); ?>
Wenn ein Benutzer angemeldet ist, können u.a. Datensätze aus den entsprechenden Tabellen in dem Fall (tblsubcategory) gelöscht werden. Die Abb.10.4.6a, Abb.10.4.6b und Abb.10.4.6c zeigen den Ablauf, um einen Datensatz aus der Tabelle (tblsubcategory) zu löschen.
Abb. 10.4.6a Unterkategorie-Tabellenformular für das Löschen eines Datensatzes (labdeletesubcategory.php)
Abb. 10.4.6b Unterkategorie-Formular für das Löschen eines Datensatzes (labdeletesubcategory.php)
Abb. 10.4.6c Unterkategorie-Formular für das Löschen eines Datensatzes (labdeletesubcategory.php)
Der Inhalt der Datei (labeditsubcategory.php)
<?php session_start(); include("labheader.php"); include("labconnect.php"); include("labsidenav.php"); $user_id = $_SESSION["user_id"]; if($user_id<=0){ ?> <div id="page-wrapper"><div class="container-fluid"> <div class="bg-darkred fg-white"> <span class="label label-danger">You are not logged in!</span> </div> </div></div> <?php } else { if(isset($_POST["send"])){ $sqlstr = "DELETE FROM tblsubcategories WHERE subcat_id = " . $_POST["oripn"]; $res = mysql_query($sqlstr) or die ("no connection to the database ".mysql_error()); $num = mysql_affected_rows(); if ($num<=0) { ?> <div id="page-wrapper"><div class="container-fluid"> <div class="bg-darkred fg-white"> <span class="label label-danger">No record has been deleted!!</span> </div> </div></div> <?php } } if (isset($_POST["selectID"])) { $sqlstr = "select * from tblsubcategories where subcat_id = " . $_POST["selectID"]; $res = mysql_query($sqlstr); $row = mysql_fetch_assoc($res); ?> <div id="page-wrapper"><div class="container-fluid"> <div class="row"> <div class="col-md-12 col-lg-12 col-sm-12 col-xs-12"> <div class="panel panel-primary"> <div class="panel-heading"> <h2 class="panel-title">Delete Subcategory - Form</h2> </div> <div class="panel-body"> <form method="post" enctype="multipart/form-data" action="labdeletesubcategory.php"> <div class="form-group"> <label class="control-label">Id:</label> <input type="text" name="subcat_id" class="form-control" value="<?php echo $_POST["selectID"]; ?>" disabled /> </div> <div class="form-group"> <label class="control-label">Subcategory name:</label> <input type="text" name="name" class="form-control" value="<?php echo $row["name"]; ?>"> </div> <div class="form-group"> <label class="control-label">Category name:</label> <select name="cat_id" class="form-control" data-role="select"> <?php $sqlstr = "SELECT cat_id, name FROM tblcategories ORDER BY name ASC"; $res = mysql_query($sqlstr) or die ("no connection to the database ".mysql_error()); while (list ($cat_id, $name) = mysql_fetch_row ($res)) { echo ("<option value=\"$cat_id\">$name (cat_id: $cat_id)</option>\n"); } ?> </select> </div> <?php if ($row["activ"] ==1){ ?> <div class="form-group"> <label>Activ: </label> <input type="checkbox" name="activ" checked> </div> <?php } else { ?> <div class="form-group"> <label>Activ: </label> <input type="checkbox" name="activ"> </div> <?php } ?> <div class="form-group"> <input type="hidden" name="oripn" value="<?php echo $_POST["selectID"]; ?>" /> <button type="submit" name="send" class="btn btn-primary"> <span class="fa fa-trash"></span> Delete the record</button> </div> </form> </div> </div> </div> </div> </div></div> <?php } else { display_delete_subcategories(); } } // end of $user_id function display_delete_subcategories(){ $sqlstr = "select * from tblsubcategories ORDER BY subcat_id "; $res = mysql_query($sqlstr) or die ("no connection to the database ".mysql_error()); $num = mysql_num_rows($res); ?> <div id="page-wrapper"><div class="container-fluid"> <div class="row"> <div class="col-md-12 col-lg-12 col-sm-12 col-xs-12"> <div class="panel panel-primary"> <div class="panel-heading"> <h2 class="panel-title">List the database: <small>tblsubcategories</small></h2> </div> <div class="panel-body"> <form method="post" enctype="multipart/form-data" action="labdeletesubcategory.php"> <div class="table-responsive"><table class="table"> <thead> <tr><th>subcat_id</th><th>name</th><th>activ</th><th>cat_id</th><th>select</th></tr> </thead> <tbody> <?php while ($row = mysql_fetch_assoc($res)) { ?> <tr> <td><?php echo $row["subcat_id"]; ?></td> <td><?php echo $row["name"]; ?></td> <td><?php echo $row["activ"]; ?></td> <td><?php echo $row["cat_id"]; ?></td> <td><input type="checkbox" name="selectID" value="<?php echo $row["subcat_id"]; ?>" data-role="checkbox"></td> </tr> <?php } ?> </tbody> </table></div> <button type="submit" class="btn btn-primary"> <span class="fa fa-eye"></span> View the record</button> </form> </div> </div> </div> </div> </div></div> <?php mysql_free_result($res); } include("labfooter.php"); ?>
Wenn ein Benutzer angemeldet ist, können u.a. Datensätze in die entsprechenden Tabellen in dem Fall (tblarticles) hinzugefügt werden. Die Abb.10.4.7a und Abb.10.4.7b zeigen den Ablauf, um einen Datensatz in die Tabelle (tblarticles) hinzuzufügen.
Abb. 10.4.7a Artikel-Formular für einen neuen Datensatz (labaddarticle.php)
Abb. 10.4.7b Hinzugefügter Datensatz (labaddarticle.php)
Der Inhalt der Datei (labaddarticle.php)
<?php session_start(); include("labheader.php"); include("labconnect.php"); include("labsidenav.php"); $uploadDirectory = __DIR__."/"; $user_id = $_SESSION["user_id"]; if($user_id<=0){ ?> <div id="page-wrapper"><div class="container-fluid"> <div class="bg-darkred fg-white"> <span class="label label-danger">You are not logged in!</span> </div> </div></div> <?php } else { if(isset($_FILES["pic"])){ $errors= array(); $pic_name = $_FILES["pic"]["name"]; $pic_size = $_FILES["pic"]["size"]; $pic_tmp = $_FILES["pic"]["tmp_name"]; $pic_type = $_FILES["pic"]["type"]; $pic_ext=strtolower(end(explode('.',$_FILES["pic"]["name"]))); $unique_image = substr(md5(time()), 0, 10).'.'.$pic_ext; $uploaded_image = "uploads/product/".$unique_image; $name = $_POST["name"]; $code =$_POST["code"]; $picbarcode=create_qrcode($code); $price =$_POST["price"]; $clothname = $_POST["clothname"]; $subcat_id = get_cgi_param ("subcat_id", 0); $care_id = get_cgi_param ("care_id", 0); $content = $_POST["content"]; if(isset($_POST["primacy"])) { $primacy=1; }else { $primacy=0; } if(isset($_POST["activ"])) { $activ=1; }else { $activ=0; } if(empty($errors)==true) { $type = pathinfo($pic_name, PATHINFO_EXTENSION); $picExists = true; while ($picExists) { if (!file_exists($uploadDirectory.$uploaded_image)) { $picExists = false; } } move_uploaded_file($pic_tmp,$uploadDirectory.$uploaded_image); $mediaType = "something"; switch ($type) { case "mp4": case "mkv": case "mov": case "ogg": case "webm": $mediaType = "video"; break; case "jpg": case "jpeg": case "gif": case "png": default: $mediaType = "image"; break; } $sqlstr = "INSERT INTO tblarticles (name, code, clothname, care_id, price, content, pic, type, picbarcode, activ, primacy, counter) VALUES('$name','$code','$clothname', '$care_id','$price', '$content', '$uploaded_image', '$mediaType','$picbarcode', '$activ', '$primacy', 1)"; $res = mysql_query($sqlstr) or die ("no connection to the database ".mysql_error()); $sqlstr1 = "select * from tblarticles ORDER BY article_id"; $res1 = mysql_query($sqlstr1) or die ("no connection to the database ".mysql_error()); $num1 = mysql_num_rows($res1); // for new article_count if ($num1>0) { $sqlstr2="INSERT INTO tblarticle_subcategory(subcat_id, article_id) VALUES ('$subcat_id', '$num1')"; $res2 = mysql_query($sqlstr2) or die ("no connection to the database ".mysql_error()); $sqlstr3="INSERT INTO tblarticle_user (user_id, article_id) VALUES ('$user_id', '$num1')"; $res3 = mysql_query($sqlstr3) or die ("no connection to the database ".mysql_error()); $num3 = mysql_affected_rows(); if($num3>0){ display_list_articles(); }else{ ?> <div id="page-wrapper"><div class="container-fluid"> <div class="bg-darkred fg-white"> <span class="label label-danger">No record has been added to the database!</span> </div> </div></div> <?php } }else { ?> <div id="page-wrapper"><div class="container-fluid"> <div class="bg-darkred fg-white"> <span class="label label-danger">No record has been added to the database!</span> </div> </div></div> <?php } }else{ print_r($errors); } }else { ?> <div id="page-wrapper"><div class="container-fluid"> <div class="row"> <div class="col-md-12 col-lg-12 col-sm-12 col-xs-12"> <div class="panel panel-primary"> <div class="panel-heading"> <h2 class="panel-title">Insert Article - Form</h2> </div> <div class="panel-body"> <form method="post" enctype="multipart/form-data" action="labaddarticle.php"> <div class="form-group"> <label>name:</label> <input type="text" name="name" class="form-control" placeholder="Enter Article name"> </div> <div class="form-group"> <label>code:</label> <input type="text" name="code" class="form-control" placeholder="Enter Article code"> </div> <div class="form-group"> <label>clothname:</label> <input type="text" name="clothname" class="form-control" placeholder="Enter Cloth name"> </div> <div class="form-group"> <label class="control-label">care:</label> <select name="care_id" class="form-control" data-role="select"> <?php $sqlstr = "SELECT care_id, strcode FROM tblcare ORDER BY strcode ASC"; $res = mysql_query($sqlstr) or die ("no connection to the database ".mysql_error()); while (list($care_id, $strcode) = mysql_fetch_row ($res)) { echo ("<option value=\"$care_id\">$strcode (care_id: $care_id)</option>\n"); } ?> </select> </div> <div class="form-group"> <label class="control-label">subcategory:</label> <select name="subcat_id" class="form-control" data-role="select"> <?php $sqlstr1 = "SELECT subcat_id, name FROM tblsubcategories ORDER BY name ASC"; $res1 = mysql_query($sqlstr1) or die ("no connection to the database ".mysql_error()); while (list($subcat_id, $name) = mysql_fetch_row ($res1)) { echo ("<option value=\"$subcat_id\">$name (subcat_id: $subcat_id)</option>\n"); } ?> </select> </div> <div class="form-group"> <label>activ: </label> <input type="checkbox" name="activ"><br /> <small class="text-muted">If the entry should be active, the checkbox must be clicked!</small> </div> <div class="form-group"> <label>primacy: </label> <input type="checkbox" name="primacy"><br /> <small class="text-muted">If the entry should be active, the checkbox must be clicked!</small> </div> <div class="form-group"> <label>a image or a movieclip for article</label> <input type="file" name="pic" class="form-control" id="uploadFile" data-role="file" required /></p> </div> <div class="form-group"> <label>price:</label> <input type="text" name="price" class="form-control"placeholder="Enter Article price"> </div> <div class="form-group"> <label>content:</label> <textarea name="content" data-role="textarea" class="form-control" rows="3"></textarea> </div> <div class="form-group"> <button type="submit" name="send" class="btn btn-primary"> <span class="fa fa-send"></span> Insert the record</button> </div> </form> </div> </div> </div> </div> </div></div> <?php } }// End of $user_id function display_list_articles(){ $sqlstr = "select * from tblarticles ORDER BY article_id DESC"; $res = mysql_query($sqlstr) or die ("no connection to the database ".mysql_error()); $num = mysql_num_rows($res); ?> <div id="page-wrapper"><div class="container-fluid"> <div class="row"> <div class="col-md-12 col-lg-12 col-sm-12 col-xs-12"> <div class="panel panel-primary"> <div class="panel-heading"> <h2 class="panel-title">List the database: <small>tblarticles</small></h2> </div> <div class="panel-body"> <h2>Insert the database: <small>tblarticle</small><h2> <div class="table-responsive"><table class="table"> <thead> <tr><th>id</th><th>name</th><th>code</th><th>clothname</th><th>care_id</th><th>pic</th> <th>barcode</th><th>price</th><th>content</th><th>activ</th><th>primacy</th><th>counter</th></tr> </thead> <tbody> <?php while ($row = mysql_fetch_assoc($res)) { ?> <tr> <td><?php echo $row["article_id"]; ?></td> <td><?php echo $row["name"]; ?></td> <td><?php echo $row["code"]; ?></td> <td><?php echo $row["clothname"]; ?></td> <td><?php echo $row["care_id"]; ?></td> <?php if ($row["type"] == "image") { echo "<td><img src='".$row['pic']."' style='height:60px; width:80px;'></td>"; } else if ($row["type"] == "video") { echo "<td><video src='".$row['pic']."' style='height:60px; width:80px;' controls/></td>"; } ?> <td><img src="<?php echo $row["picbarcode"]; ?>" style="height:60px; width:60px;"></td> <td><?php echo $row["price"]; ?></td> <td><?php echo $row["content"]; ?></td> <td><?php echo $row["activ"]; ?></td> <td><?php echo $row["primacy"]; ?></td> <td><?php echo $row["counter"]; ?></td> </tr> <?php } ?> </tbody> </table></div> </div> </div> </div> </div> </div></div> <?php } function create_qrcode($data) { $uploadDirectory = __DIR__."/"; //set it to writable location, a place for temp generated PNG files $PNG_TEMP_DIR = dirname(__FILE__).DIRECTORY_SEPARATOR."uploads/barcode".DIRECTORY_SEPARATOR; //html PNG location prefix $PNG_WEB_DIR = "uploads/barcode/"; include ("barcodeg/qrlib.php"); //ofcourse we need rights to create temp dir if (!file_exists($PNG_TEMP_DIR)) mkdir($PNG_TEMP_DIR); $filename = $PNG_WEB_DIR."qrcode.png"; if (isset($data)) { //it's very important! if (trim($data) == "") die('data cannot be empty! <a href="?">back</a>'); $filename=$PNG_WEB_DIR.'qr'.md5($data).".png"; $pathfile=$filename; QRcode::png($data, $filename, 2); return $pathfile; } else { QRcode::png('PHP QR Code :)', $filename, 2); } } mysql_free_result($res); mysql_free_result($res1); mysql_free_result($res2); mysql_free_result($res3); include("labfooter.php"); ?>
Wenn ein Benutzer angemeldet ist, können u.a. Datensätze in die entsprechenden Tabellen in dem Fall (tblarticles) geändert werden. Die Abb.10.4.8a, Abb.10.4.8b und Abb.10.4.8c zeigen den Ablauf, um einen Datensatz in die Tabelle (tblarticles) zu ändern.
Abb. 10.4.8a Artikel-Tabellenformular für die Änderung eines Datensatzes (labeditarticle.php)
Abb. 10.4.8b Artikel-Tabelle nach der Änderung eines Datensatzes (labeditarticle.php)
Abb. 10.4.8c Artikel-Tabelle nach der Änderung eines Datensatzes (labeditarticle.php)
Der Inhalt der Datei (labeditarticle.php)
<?php session_start(); include("labheader.php"); include("labconnect.php"); include("labsidenav.php"); $uploadDirectory = __DIR__."/"; $user_id = $_SESSION["user_id"]; if($user_id<=0){ ?> <div id="page-wrapper"><div class="container-fluid"> <div class="bg-darkred fg-white"> <span class="label label-danger">You are not logged in!</span> </div> </div></div> <?php } else { if(isset($_POST["send"])){ // Delete old_image if (picdelete($_SESSION["picold"])==false){ ?> <div id="page-wrapper"><div class="container-fluid"> <div class="bg-darkred fg-white"> <span class="label label-danger">Image file not find!!</span> </div> </div></div> <?php } if (picdelete($_SESSION["picbarcodeold"])==false){ ?> <div id="page-wrapper"><div class="container-fluid"> <div class="bg-darkred fg-white"> <span class="label label-danger">Image file not find!!</span> </div> </div></div> <?php } $errors= array(); $pic_name = $_FILES["pic"]["name"]; $pic_size = $_FILES["pic"]["size"]; $pic_tmp = $_FILES["pic"]["tmp_name"]; $pic_type = $_FILES["pic"]["type"]; $pic_ext=strtolower(end(explode('.',$_FILES["pic"]["name"]))); $unique_image = substr(md5(time()), 0, 10).'.'.$pic_ext; $uploaded_image = "uploads/product/".$unique_image; $name = $_POST["name"]; $code =$_POST["code"]; $picbarcode=create_qrcode($code); $price =$_POST["price"]; $clothname = $_POST["clothname"]; $subcat_id = get_cgi_param ("subcat_id", 0); $care_id = get_cgi_param ("care_id", 0); $content = $_POST["content"]; if(isset($_POST["primacy"])) { $primacy=1; }else { $primacy=0; } if(isset($_POST["activ"])) { $activ=1; }else { $activ=0; } if(empty($errors)==true) { $type = pathinfo($pic_name, PATHINFO_EXTENSION); $picExists = true; while ($picExists) { if (!file_exists($uploadDirectory.$uploaded_image)) { $picExists = false; } } move_uploaded_file($pic_tmp,$uploadDirectory.$uploaded_image); $mediaType = "something"; switch ($type) { case "mp4": case "mkv": case "mov": case "ogg": case "webm": $mediaType = "video"; break; case "jpg": case "jpeg": case "gif": case "png": default: $mediaType = "image"; break; } $sqlstr = "UPDATE tblarticles SET name='$name', code='$code', clothname='$clothname', care_id='$care_id', price='$price', content='$content', pic='$uploaded_image', type='$mediaType', picbarcode='$picbarcode' , activ='$activ' , primacy='$primacy' WHERE article_id = " . $_POST["oripn"]; $res = mysql_query($sqlstr) or die ("erroror inserting data ".mysql_error()); $num = mysql_affected_rows(); if ($num<0) { ?> <div id="page-wrapper"><div class="container-fluid"> <div class="bg-darkred fg-white"> <span class="label label-danger">No record has been added to the database!</span> </div> </div></div> <?php } }else{ print_r($errors); } } if (isset($_POST["selectID"])) { $sqlstr = "select * from tblarticles where article_id = " . $_POST["selectID"]; $res = mysql_query($sqlstr); $row = mysql_fetch_assoc($res); $_SESSION["picold"]=$row["pic"]; $_SESSION["picbarcodeold"]=$row["picbarcode"]; ?> <div id="page-wrapper"><div class="container-fluid"> <div class="row"> <div class="col-md-12 col-lg-12 col-sm-12 col-xs-12"> <div class="panel panel-primary"> <div class="panel-heading"> <h2 class="panel-title">Edit article - Form</h2> </div> <div class="panel-body"> <form action="labeditarticle.php" method="POST" enctype="multipart/form-data"> <div class="form-group"> <label>Article_id:</label> <input type="text" name="article_id" class="form-control" value="<?php echo $_POST["selectID"]; ?>" disabled /> </div> <div class="form-group"> <label>name:</label> <input type="text" name="name" class="form-control" value="<?php echo $row["name"]; ?>"> </div> <div class="form-group"> <label>code:</label> <input type="text" name="code" class="form-control" value="<?php echo $row["code"]; ?>"> </div> <div class="form-group"> <label>clothname:</label> <input type="text" name="clothname" class="form-control" value="<?php echo $row["clothname"]; ?>"> </div> <div class="form-group"> <label class="control-label">Care string code:</label> <select name="care_id" class="form-control" data-role="select"> <?php $sqlstr = "SELECT care_id, strcode FROM tblcare ORDER BY strcode ASC"; $res = mysql_query($sqlstr) or die ("no connection to the database ".mysql_error()); while (list($care_id, $strcode) = mysql_fetch_row ($res)) { echo ("<option value=\"$care_id\">$strcode (care_id: $care_id)</option>\n"); } ?> </select> </div> <div class="form-group"> <label class="control-label">subcategory name:</label> <select name="subcat_id" class="form-control" data-role="select"> <?php $sqlstr1 = "SELECT subcat_id, name FROM tblsubcategories ORDER BY name ASC"; $res1 = mysql_query($sqlstr1) or die ("no connection to the database ".mysql_error()); while (list($subcat_id, $name) = mysql_fetch_row ($res1)) { echo ("<option value=\"$subcat_id\">$name (subcat_id: $subcat_id)</option>\n"); } ?> </select> </div> <?php if ($row["activ"] ==1){ ?> <div class="form-group"> <label>Activ: </label> <input type="checkbox" name="activ" checked> </div> <?php } else { ?> <div class="form-group"> <label>Activ: </label> <input type="checkbox" name="activ"> </div> <?php } ?> <?php if ($row["primacy"] ==1){ ?> <div class="form-group"> <label>Primacy: </label> <input type="checkbox" name="primacy" checked> </div> <?php } else { ?> <div class="form-group"> <label>Primacy: </label> <input type="checkbox" name="primacy"> </div> <?php } ?> <div class="form-group"> <label>Image for article:</label> <img src="<?php echo $row["pic"]?>" width="100px" height="80px"> <input type="file" name="pic" id="uploadFile" data-role="file" class="form-control" required /> </div> <div class="form-group"> <label>price:</label> <input type="text" name="price" class="form-control" value="<?php echo $row["price"]; ?>"> </div> <div class="form-group"> <label>Content:</label> <textarea class="form-control" rows="3" name="content"> <?php echo $row["content"]?> </textarea> </div> <div class="form-group"> <input type="hidden" name="oripn" value="<?php echo $_POST["selectID"]; ?>" /> <button type="submit" name="send" class="btn btn-primary"> <span class="fa fa-edit"></span> Edit the record</button> </div> </form> </div> </div> </div> </div> </div></div> <?php mysql_free_result($res); }else { display_edit_article(); } } // end of $user_id function display_edit_article(){ $sqlstr = "select * from tblarticles ORDER BY article_id DESC"; $res = mysql_query($sqlstr) or die ("no connection to the database ".mysql_error()); $num = mysql_num_rows($res); ?> <div id="page-wrapper"><div class="container-fluid"> <div class="row"> <div class="col-md-12 col-lg-12 col-sm-12 col-xs-12"> <div class="panel panel-primary"> <div class="panel-heading"> <h2 class="panel-title">List the database: <small>tblcare</small></h2> </div> <div class="panel-body"> <form method="post" enctype="multipart/form-data" action="labeditarticle.php"> <div class="table-responsive"><table class="table"> <thead> <tr><th>id</th><th>name</th><th>code</th><th>clothname</th><th>pic</th> <th>barcode</th><th>price</th><th>content</th><th>activ</th><th>primacy</th><th>select</th></tr> </thead> <tbody> <?php while ($row = mysql_fetch_assoc($res)) { ?> <tr> <td><?php echo $row["article_id"]; ?></td> <td><?php echo $row["name"]; ?></td> <td><?php echo $row["code"]; ?></td> <td><?php echo $row["clothname"]; ?></td> <?php if ($row["type"] == "image") { echo "<td><img src='".$row["pic"]."' style='height:60px; width:80px;'></td>"; } else if ($row["type"] == "video") { echo "<td><video src='".$row["pic"]."' style='height:60px; width:80px;' controls/></td>"; } ?> <td><img src="<?php echo $row["picbarcode"]; ?>" style="height:60px; width:60px;"></td> <td><?php echo $row["price"]; ?></td> <td><?php echo $row["content"]; ?></td> <td><?php echo $row["activ"]; ?></td> <td><?php echo $row["primacy"]; ?></td> <td><input type="checkbox" name="selectID" value="<?php echo $row["article_id"]; ?>" data-role="checkbox"></td> </tr> <?php } ?> </tbody> </table></div> <button type="submit" class="btn btn-primary"> <span class="fa fa-eye"></span> View the record</button> </form> </div> </div> </div> </div> </div></div> <?php mysql_free_result($res); } function picdelete($pic) { if ( file_exists($pic) ) { if( @unlink($pic) !== true ) throw new Exception('Could not delete file: ' . $pic . ' Please close all applications that are using it.'); } return true; } function create_qrcode($data) { $uploadDirectory = __DIR__."/"; //set it to writable location, a place for temp generated PNG files $PNG_TEMP_DIR = dirname(__FILE__).DIRECTORY_SEPARATOR."uploads/barcode".DIRECTORY_SEPARATOR; //html PNG location prefix $PNG_WEB_DIR = "uploads/barcode/"; include "barcodeg/qrlib.php"; //ofcourse we need rights to create temp dir if (!file_exists($PNG_TEMP_DIR)) mkdir($PNG_TEMP_DIR); $filename = $PNG_WEB_DIR."qrcode.png"; if (isset($data)) { //it's very important! if (trim($data) == "") die('data cannot be empty! <a href="?">back</a>'); $filename=$PNG_WEB_DIR."qr".md5($data).".png"; $pathfile=$filename; QRcode::png($data, $filename, 2); return $pathfile; } else { QRcode::png('PHP QR Code :)', $filename, 2); } } include("labfooter.php"); ?>
Wenn ein Benutzer angemeldet ist, können u.a. Datensätze aus den entsprechenden Tabellen in dem Fall (tblarticles) gelöscht werden. Die Abb.10.4.9a, Abb.10.4.9b und Abb.10.4.9c zeigen den Ablauf, um einen Datensatz aus der Tabelle (tblarticles) zu löschen.
Abb. 10.4.9a Artikel-Tabellenformular für das Löschen eines Datensatzes (labdeletearticle.php)
Abb. 10.4.9b Artikel-Formular für das Löschen eines Datensatzes (labdeletearticle.php)
Abb. 10.4.9c Artikel-Formular für das Löschen eines Datensatzes (labdeletearticle.php)
Der Inhalt der Datei (labdeletearticle.php)
<?php session_start(); include("labheader.php"); include("labconnect.php"); include("labsidenav.php"); $uploadDirectory = __DIR__."/"; $user_id = $_SESSION["user_id"]; if($user_id<=0){ ?> <div id="page-wrapper"><div class="container-fluid"> <div class="bg-darkred fg-white"> <span class="label label-danger">You are not logged in!</span> </div> </div></div> <?php } else { if(isset($_POST["send"])){ // Delete old_image if (picdelete($_SESSION["picold"])==false){ ?> <div id="page-wrapper"><div class="container-fluid"> <div class="bg-darkred fg-white"> <span class="label label-danger">Image file not find!!</span> </div> </div></div> <?php } if (picdelete($_SESSION["picbarcodeold"])==false){ ?> <div id="page-wrapper"><div class="container-fluid"> <div class="bg-darkred fg-white"> <span class="label label-danger">Image file not find!!</span> </div> </div></div> <?php } $errors= array(); if(empty($errors)==true) { $sqlstr = "DELETE FROM tblarticles WHERE article_id = " . $_POST["oripn"]; $res = mysql_query($sqlstr) or die ("erroror inserting data ".mysql_error()); $num = mysql_affected_rows(); if ($num<0) { ?> <div id="page-wrapper"><div class="container-fluid"> <div class="bg-darkred fg-white"> <span class="label label-danger">No record has been added to the database!</span> </div> </div></div> <?php } }else{ print_r($errors); } } if (isset($_POST["selectID"])) { $sqlstr = "select * from tblarticles where article_id = " . $_POST["selectID"]; $res = mysql_query($sqlstr); $row = mysql_fetch_assoc($res); $_SESSION["picold"]=$row["pic"]; $_SESSION["picbarcodeold"]=$row["picbarcode"]; ?> <div id="page-wrapper"><div class="container-fluid"> <div class="row"> <div class="col-md-12 col-lg-12 col-sm-12 col-xs-12"> <div class="panel panel-primary"> <div class="panel-heading"> <h2 class="panel-title">Delete article - Form</h2> </div> <div class="panel-body"> <form action="labdeletearticle.php" method="POST" enctype="multipart/form-data"> <div class="form-group"> <label>Article_id:</label> <input type="text" name="article_id" class="form-control" value="<?php echo $_POST["selectID"]; ?>" disabled /> </div> <div class="form-group"> <label>name:</label> <input type="text" name="name" class="form-control" value="<?php echo $row["name"]; ?>"> </div> <div class="form-group"> <label>code:</label> <input type="text" name="code" class="form-control" value="<?php echo $row["code"]; ?>"> </div> <div class="form-group"> <label>clothname:</label> <input type="text" name="clothname" class="form-control" value="<?php echo $row["clothname"]; ?>"> </div> <div class="form-group"> <label class="control-label">Care string code:</label> <select name="care_id" class="form-control" data-role="select"> <?php $sqlstr = "SELECT care_id, strcode FROM tblcare ORDER BY strcode ASC"; $res = mysql_query($sqlstr) or die ("no connection to the database ".mysql_error()); while (list($care_id, $strcode) = mysql_fetch_row ($res)) { echo ("<option value=\"$care_id\">$strcode (care_id: $care_id)</option>\n"); } ?> </select> </div> <div class="form-group"> <label class="control-label">subcategory name:</label> <select name="subcat_id" class="form-control" data-role="select"> <?php $sqlstr1 = "SELECT subcat_id, name FROM tblsubcategories ORDER BY name ASC"; $res1 = mysql_query($sqlstr1) or die ("no connection to the database ".mysql_error()); while (list($subcat_id, $name) = mysql_fetch_row ($res1)) { echo ("<option value=\"$subcat_id\">$name (subcat_id: $subcat_id)</option>\n"); } ?> </select> </div> <?php if ($row["activ"] ==1){ ?> <div class="form-group"> <label>Activ: </label> <input type="checkbox" name="activ" checked> </div> <?php } else { ?> <div class="form-group"> <label>Activ: </label> <input type="checkbox" name="activ"> </div> <?php } ?> <?php if ($row["primacy"] ==1){ ?> <div class="form-group"> <label>Primacy: </label> <input type="checkbox" name="primacy" checked> </div> <?php } else { ?> <div class="form-group"> <label>Primacy: </label> <input type="checkbox" name="primacy"> </div> <?php } ?> <div class="form-group"> <label>Image for article:</label> <img src="<?php echo $row["pic"]?>" width="100px" height="80px"> </div> <div class="form-group"> <label>price:</label> <input type="text" name="price" class="form-control" value="<?php echo $row["price"]; ?>"> </div> <div class="form-group"> <label>Content:</label> <textarea class="form-control" rows="3" name="content"> <?php echo $row["content"]?> </textarea> </div> <div class="form-group"> <input type="hidden" name="oripn" value="<?php echo $_POST["selectID"]; ?>" /> <button type="submit" name="send" class="btn btn-primary"> <span class="fa fa-trash"></span> Delete the record</button> </div> </form> </div> </div> </div> </div> </div></div> <?php mysql_free_result($res); }else { display_delete_article(); } } // end of $user_id function display_delete_article(){ $sqlstr = "select * from tblarticles ORDER BY article_id DESC"; $res = mysql_query($sqlstr) or die ("no connection to the database ".mysql_error()); $num = mysql_num_rows($res); ?> <div id="page-wrapper"><div class="container-fluid"> <div class="row"> <div class="col-md-12 col-lg-12 col-sm-12 col-xs-12"> <div class="panel panel-primary"> <div class="panel-heading"> <h2 class="panel-title">List the database: <small>tblarticles</small></h2> </div> <div class="panel-body"> <form method="post" enctype="multipart/form-data" action="labdeletearticle.php"> <div class="table-responsive"><table class="table"> <thead> <tr><th>id</th><th>name</th><th>code</th><th>clothname</th><th>pic</th> <th>barcode</th><th>price</th><th>content</th><th>activ</th><th>primacy</th><th>select</th></tr> </thead> <tbody> <?php while ($row = mysql_fetch_assoc($res)) { ?> <tr> <td><?php echo $row["article_id"]; ?></td> <td><?php echo $row["name"]; ?></td> <td><?php echo $row["code"]; ?></td> <td><?php echo $row["clothname"]; ?></td> <?php if ($row["type"] == "image") { echo "<td><img src='".$row["pic"]."' style='height:60px; width:80px;'></td>"; } else if ($row["type"] == "video") { echo "<td><video src='".$row["pic"]."' style='height:60px; width:80px;' controls/></td>"; } ?> <td><img src="<?php echo $row["picbarcode"]; ?>" style="height:60px; width:60px;"></td> <td><?php echo $row["price"]; ?></td> <td><?php echo $row["content"]; ?></td> <td><?php echo $row["activ"]; ?></td> <td><?php echo $row["primacy"]; ?></td> <td><input type="checkbox" name="selectID" value="<?php echo $row["article_id"]; ?>" data-role="checkbox"></td> </tr> <?php } ?> </tbody> </table></div> <button type="submit" class="btn btn-primary"> <span class="fa fa-eye"></span> View the record</button> </form> </div> </div> </div> </div> </div></div> <?php mysql_free_result($res); } function picdelete($pic) { if ( file_exists($pic) ) { if( @unlink($pic) !== true ) throw new Exception('Could not delete file: ' . $pic . ' Please close all applications that are using it.'); } return true; } include("labfooter.php"); ?>
Wenn ein Benutzer angemeldet ist, können u.a. Datensätze in die entsprechenden Tabellen in dem Fall (tblcare) hinzugefügt werden. Die Abb.10.5.1a und Abb.10.5.1b zeigen den Ablauf, um einen Datensatz in die Tabelle (tblcare) hinzuzufügen.
Abb. 10.5.1a Pflegezeichen-Formular für einen neuen Datensatz (labaddcare.php)
Abb. 10.5.1b Hinzugefügter Datensatz (labaddcare.php)
Der Inhalt der Datei (labaddcare.php)
<?php session_start(); include("labheader.php"); include("labconnect.php"); include("labsidenav.php"); $uploadDirectory = __DIR__."/"; $user_id = $_SESSION["user_id"]; if($user_id<=0){ ?> <div id="page-wrapper"><div class="container-fluid"> <div class="bg-darkred fg-white"> <span class="label label-danger">You are not logged in!</span> </div> </div></div> <?php } else { if(isset($_FILES["pic"])){ $errors= array(); $pic_name = $_FILES["pic"]["name"]; $pic_size = $_FILES["pic"]["size"]; $pic_tmp = $_FILES["pic"]["tmp_name"]; $pic_type = $_FILES["pic"]["type"]; $pic_ext=strtolower(end(explode('.',$_FILES["pic"]["name"]))); $unique_image = substr(md5(time()), 0, 10).'.'.$pic_ext; $uploaded_image = "uploads/care/".$unique_image; $strcode = $_POST["strcode"]; $marktype = $_POST["marktype"]; $content = $_POST["content"]; if(empty($errors)==true) { $type = pathinfo($pic_name, PATHINFO_EXTENSION); $picExists = true; while ($picExists) { if (!file_exists($uploadDirectory.$uploaded_image)) { $picExists = false; } } move_uploaded_file($pic_tmp,$uploadDirectory.$uploaded_image); $mediaType = "something"; switch ($type) { case "jpg": case "jpeg": case "gif": case "png": default: $mediaType = "image"; break; } $sqlstr = "INSERT INTO tblcare (strcode, marktype, content, pic) VALUES('$strcode','$marktype', '$content', '$uploaded_image')"; $res = mysql_query($sqlstr) or die ("no connection to the database ".mysql_error()); $num = mysql_affected_rows(); if ($num>0) { display_list_care(); }else{ ?> <div id="page-wrapper"><div class="container-fluid"> <div class="bg-darkred fg-white"> <span class="label label-danger">No record has been added to the database!</span> </div> </div></div> <?php } }else{ print_r($errors); } }else { ?> <div id="page-wrapper"><div class="container-fluid"> <div class="row"> <div class="col-md-12 col-lg-12 col-sm-12 col-xs-12"> <div class="panel panel-primary"> <div class="panel-heading"> <h2 class="panel-title">Insert Care - Form</h2> </div> <div class="panel-body"> <form method="post" enctype="multipart/form-data" action="labaddcare.php"> <div class="form-group"> <label>Stringcode:</label> <input type="text" name="strcode" class="form-control" placeholder="Enter Stringcode"> </div> <div class="form-group"> <label>Single or multiple Mark:</label> <input type="text" name="marktype" class="form-control" placeholder="Enter Single or multiple Mark"> </div> <div class="form-group"> <label>a image for care</label> <input type="file" name="pic" class="form-control" id="uploadFile" data-role="file" required /></p> </div> <div class="form-group"> <label>content:</label> <textarea name="content" data-role="textarea" class="form-control" rows="3"></textarea> </div> <div class="form-group"> <button type="submit" name="send" class="btn btn-primary"> <span class="fa fa-send"></span> Insert the record</button> </div> </form> </div> </div> </div> </div> </div></div> <?php } }// End of $user_id function display_list_care(){ $sqlstr = "select * from tblcare ORDER BY care_id DESC"; $res = mysql_query($sqlstr) or die ("no connection to the database ".mysql_error()); $num = mysql_num_rows($res); ?> <div id="page-wrapper"><div class="container-fluid"> <div class="row"> <div class="col-md-12 col-lg-12 col-sm-12 col-xs-12"> <div class="panel panel-primary"> <div class="panel-heading"> <h2 class="panel-title">List the database: <small>tblcare</small></h2> </div> <div class="panel-body"> <h2>Insert the database: <small>tblcare</small><h2> <div class="table-responsive"><table class="table"> <thead> <tr><th>id</th><th>Stringcode</th><th>Mark</th><th>pic</th> <th>content</th></tr> </thead> <tbody> <?php while ($row = mysql_fetch_assoc($res)) { ?> <tr> <td><?php echo $row["care_id"]; ?></td> <td><?php echo $row["strcode"]; ?></td> <td><?php echo $row["marktype"]; ?></td> <td><img src="<?php echo $row["pic"]; ?>" style="height:20px; width:80px;"></td> <td><?php echo $row["content"]; ?></td> </tr> <?php } ?> </tbody> </table></div> </div> </div> </div> </div> </div></div> <?php } mysql_free_result($res); include("labfooter.php"); ?>
Wenn ein Benutzer angemeldet ist, können u.a. Datensätze in die entsprechenden Tabellen in dem Fall (tblcare) geändert werden. Die Abb.10.5.2a, Abb.10.5.2b und Abb.10.5.2c zeigen den Ablauf, um einen Datensatz in die Tabelle (tblcare) zu ändern.
Abb. 10.5.2a Pflegezeichen-Tabellenformular für die Änderung eines Datensatzes (labeditcare.php)
Abb. 10.5.2b Pflegezeichen-Tabelle nach der Änderung eines Datensatzes (labeditcare.php)
Abb. 10.5.2c Pflegezeichen-Tabelle nach der Änderung eines Datensatzes (labeditcare.php)
Der Inhalt der Datei (labeditcare.php)
<?php session_start(); include("labheader.php"); include("labconnect.php"); include("labsidenav.php"); $uploadDirectory = __DIR__."/"; $user_id = $_SESSION["user_id"]; if($user_id<=0){ ?> <div id="page-wrapper"><div class="container-fluid"> <div class="bg-darkred fg-white"> <span class="label label-danger">You are not logged in!</span> </div> </div></div> <?php } else { if(isset($_POST["send"])){ // Delete old_image if (picdelete($_SESSION["picold"])==false){ ?> <div id="page-wrapper"><div class="container-fluid"> <div class="bg-darkred fg-white"> <span class="label label-danger">Image file not find!!</span> </div> </div></div> <?php } $errors= array(); $pic_name = $_FILES["pic"]["name"]; $pic_size = $_FILES["pic"]["size"]; $pic_tmp = $_FILES["pic"]["tmp_name"]; $pic_type = $_FILES["pic"]["type"]; $pic_ext=strtolower(end(explode('.',$_FILES["pic"]["name"]))); $unique_image = substr(md5(time()), 0, 10).'.'.$pic_ext; $uploaded_image = "uploads/care/".$unique_image; $strcode = $_POST["strcode"]; $marktype = $_POST["marktype"]; $content = $_POST["content"]; if(empty($errors)==true) { $type = pathinfo($pic_name, PATHINFO_EXTENSION); $picExists = true; while ($picExists) { if (!file_exists($uploadDirectory.$uploaded_image)) { $picExists = false; } } move_uploaded_file($pic_tmp,$uploadDirectory.$uploaded_image); $mediaType = "something"; switch ($type) { case "jpg": case "jpeg": case "gif": case "png": default: $mediaType = "image"; break; } $sqlstr = "UPDATE tblcare SET strcode='$strcode', marktype='$marktype', content='$content', pic='$uploaded_image' WHERE care_id = " . $_POST["oripn"]; $res = mysql_query($sqlstr) or die ("erroror inserting data ".mysql_error()); $num = mysql_affected_rows(); if ($num<0) { ?> <div id="page-wrapper"><div class="container-fluid"> <div class="bg-darkred fg-white"> <span class="label label-danger">No record has been added to the database!</span> </div> </div></div> <?php } }else{ print_r($errors); } } if (isset($_POST["selectID"])) { $sqlstr = "select * from tblcare where care_id = " . $_POST["selectID"]; $res = mysql_query($sqlstr); $row = mysql_fetch_assoc($res); $_SESSION["picold"]=$row["pic"]; ?> <div id="page-wrapper"><div class="container-fluid"> <div class="row"> <div class="col-md-12 col-lg-12 col-sm-12 col-xs-12"> <div class="panel panel-primary"> <div class="panel-heading"> <h2 class="panel-title">Edit Care - Form</h2> </div> <div class="panel-body"> <form action="labeditcare.php" method="POST" enctype="multipart/form-data"> <div class="form-group"> <label>Care_id:</label> <input type="text" name="care_id" class="form-control" value="<?php echo $_POST["selectID"]; ?>" disabled /> </div> <div class="form-group"> <label>Stringcode:</label> <input type="text" name="strcode" class="form-control" value="<?php echo $row["strcode"]; ?>"> </div> <div class="form-group"> <label>Single or multiple Mark:</label> <input type="text" name="marktype" class="form-control" value="<?php echo $row["marktype"]; ?>"> </div> <div class="form-group"> <label>Image for care:</label> <img src="<?php echo $row["pic"]?>" width="100px" height="20px"> <input type="file" name="pic" id="uploadFile" data-role="file" class="form-control" data-caption="Choose care image file" required /> </div> <div class="form-group"> <label>Content:</label> <textarea class="form-control" rows="3" name="content"> <?php echo $row["content"]?> </textarea> </div> <div class="form-group"> <input type="hidden" name="oripn" value="<?php echo $_POST["selectID"]; ?>" /> <button type="submit" name="send" class="btn btn-primary"> <span class="fa fa-edit"></span> Edit the record</button> </div> </form> </div> </div> </div> </div> </div></div> <?php mysql_free_result($res); }else { display_edit_care(); } } // end of $user_id function display_edit_care(){ $sqlstr = "select * from tblcare ORDER BY care_id DESC"; $res = mysql_query($sqlstr) or die ("no connection to the database ".mysql_error()); $num = mysql_num_rows($res); ?> <div id="page-wrapper"><div class="container-fluid"> <div class="row"> <div class="col-md-12 col-lg-12 col-sm-12 col-xs-12"> <div class="panel panel-primary"> <div class="panel-heading"> <h2 class="panel-title">List the database: <small>tblcare</small></h2> </div> <div class="panel-body"> <form method="post" enctype="multipart/form-data" action="labeditcare.php"> <div class="table-responsive"><table class="table"> <thead> <tr><th>id</th><th>Stringcode</th><th>Mark</th><th>pic</th><th>content</th><th>select</th></tr> </thead> <tbody> <?php while ($row = mysql_fetch_assoc($res)) { ?> <tr> <td><?php echo $row["care_id"]; ?></td> <td><?php echo $row["strcode"]; ?></td> <td><?php echo $row["marktype"]; ?></td> <td><img src="<?php echo $row["pic"]; ?>" style="height:20px; width:80px;"></td> <td><?php echo $row["content"]; ?></td> <td><input type="checkbox" name="selectID" value="<?php echo $row["care_id"]; ?>" data-role="checkbox"></td> </tr> <?php } ?> </tbody> </table></div> <button type="submit" class="btn btn-primary"> <span class="fa fa-eye"></span> View the record</button> </form> </div> </div> </div> </div> </div></div> <?php mysql_free_result($res); } function picdelete($pic) { if ( file_exists($pic) ) { if( @unlink($pic) !== true ) throw new Exception('Could not delete file: ' . $pic . ' Please close all applications that are using it.'); } return true; } include("labfooter.php"); ?>
Wenn ein Benutzer angemeldet ist, können u.a. Datensätze aus den entsprechenden Tabellen in dem Fall (tblcare) gelöscht werden. Die Abb.10.5.3a, Abb.10.5.3b und Abb.10.5.3c zeigen den Ablauf, um einen Datensatz aus der Tabelle (tblcare) zu löschen.
Abb. 10.5.3a Pflegezeichen-Tabellenformular für das Löschen eines Datensatzes (labdeletecare.php)
Abb. 10.5.3b Pflegezeichen-Formular für das Löschen eines Datensatzes (labdeletecare.php)
Abb. 10.5.3c Pflegezeichen-Formular für das Löschen eines Datensatzes (labdeletecare.php)
Der Inhalt der Datei (labdeletecare.php)
<?php session_start(); include("labheader.php"); include("labconnect.php"); include("labsidenav.php"); $uploadDirectory = __DIR__."/"; $user_id = $_SESSION["user_id"]; if($user_id<=0){ ?> <div id="page-wrapper"><div class="container-fluid"> <div class="bg-darkred fg-white"> <span class="label label-danger">You are not logged in!</span> </div> </div></div> <?php } else { if(isset($_POST["send"])){ // Delete old_image if (picdelete($_SESSION["picold"])==false){ ?> <div id="page-wrapper"><div class="container-fluid"> <div class="bg-darkred fg-white"> <span class="label label-danger">Image file not find!!</span> </div> </div></div> <?php } $sqlstr = "DELETE FROM tblcare WHERE care_id = " . $_POST["oripn"]; $res = mysql_query($sqlstr) or die ("erroror inserting data ".mysql_error()); $num = mysql_affected_rows(); if ($num<0) { ?> <div id="page-wrapper"><div class="container-fluid"> <div class="bg-darkred fg-white"> <span class="label label-danger">No record has been deleted to the database!</span> </div> </div></div> <?php } } if (isset($_POST["selectID"])) { $sqlstr = "select * from tblcare where care_id = " . $_POST["selectID"]; $res = mysql_query($sqlstr); $row = mysql_fetch_assoc($res); $_SESSION["picold"]=$row["pic"]; ?> <div id="page-wrapper"><div class="container-fluid"> <div class="row"> <div class="col-md-12 col-lg-12 col-sm-12 col-xs-12"> <div class="panel panel-primary"> <div class="panel-heading"> <h2 class="panel-title">Delete Care - Form</h2> </div> <div class="panel-body"> <form action="labdeletecare.php" method="POST" enctype="multipart/form-data"> <div class="form-group"> <label>Care_id:</label> <input type="text" name="care_id" class="form-control" value="<?php echo $_POST["selectID"]; ?>" disabled /> </div> <div class="form-group"> <label>Stringcode:</label> <input type="text" name="strcode" class="form-control" value="<?php echo $row["strcode"]; ?>"> </div> <div class="form-group"> <label>Single or multiple Mark:</label> <input type="text" name="marktype" class="form-control" value="<?php echo $row["marktype"]; ?>"> </div> <div class="form-group"> <label>Content:</label> <textarea class="form-control" rows="3" name="content"> <?php echo $row["content"]?> </textarea> </div> <div class="form-group"> <input type="hidden" name="oripn" value="<?php echo $_POST["selectID"]; ?>" /> <button type="submit" name="send" class="btn btn-primary"> <span class="fa fa-trash"></span> Delete the record</button> </div> </form> </div> </div> </div> </div> </div></div> <?php mysql_free_result($res); }else { display_delete_care(); } } // end of $user_id function display_delete_care(){ $sqlstr = "select * from tblcare ORDER BY care_id DESC"; $res = mysql_query($sqlstr) or die ("no connection to the database ".mysql_error()); $num = mysql_num_rows($res); ?> <div id="page-wrapper"><div class="container-fluid"> <div class="row"> <div class="col-md-12 col-lg-12 col-sm-12 col-xs-12"> <div class="panel panel-primary"> <div class="panel-heading"> <h2 class="panel-title">List the database: <small>tblcare</small></h2> </div> <div class="panel-body"> <form method="post" enctype="multipart/form-data" action="labdeletecare.php"> <div class="table-responsive"><table class="table"> <thead> <tr><th>id</th><th>Stringcode</th><th>Mark</th><th>pic</th><th>content</th><th>select</th></tr> </thead> <tbody> <?php while ($row = mysql_fetch_assoc($res)) { ?> <tr> <td><?php echo $row["care_id"]; ?></td> <td><?php echo $row["strcode"]; ?></td> <td><?php echo $row["marktype"]; ?></td> <td><img src="<?php echo $row["pic"]; ?>" style="height:20px; width:80px;"></td> <td><?php echo $row["content"]; ?></td> <td><input type="checkbox" name="selectID" value="<?php echo $row["care_id"]; ?>" data-role="checkbox"></td> </tr> <?php } ?> </tbody> </table></div> <button type="submit" class="btn btn-primary"> <span class="fa fa-eye"></span> View the record</button> </form> </div> </div> </div> </div> </div></div> <?php mysql_free_result($res); } function picdelete($pic) { if ( file_exists($pic) ) { if( @unlink($pic) !== true ) throw new Exception("Could not delete file: " . $pic . " Please close all applications that are using it."); } return true; } include("labfooter.php"); ?>
Wenn ein Benutzer angemeldet ist, können u.a. Datensätze in die entsprechenden Tabellen in dem Fall (tblcustomers) hinzugefügt werden. Die Abb.10.5.4a und Abb.10.5.4b zeigen den Ablauf, um einen Datensatz in die Tabelle (tblcustomers) hinzuzufügen.
Abb. 10.5.4a Kunden-Formular für einen neuen Datensatz (labaddcustomer.php)
Abb. 10.5.4b Hinzugefügter Datensatz (labaddcustomer.php)
Der Inhalt der Datei (labaddcustomer.php)
<?php session_start(); include("labheader.php"); include("labconnect.php"); include("labsidenav.php"); $user_id = $_SESSION["user_id"]; if($user_id<=0){ ?> <div id="page-wrapper"><div class="container-fluid"> <div class="bg-darkred fg-white"> <span class="label label-danger">You are not logged in!</span> </div> </div></div> <?php } else { if(isset($_POST["send"])){ if(isset($_POST["activ"])) { $activ=1; }else { $activ=0; } $sqlstr = "insert tblcustomers (name, prename, address, postcode, city, region, country, phone, email, password, activ) values " . "('" . $_POST["name"] . "', " . "'" . $_POST["prename"] . "', " . "'" . $_POST["address"] . "', " . "'" . $_POST["postcode"] . "', " . "'" . $_POST["city"] . "', " . "'" . $_POST["region"] . "', " . "'" . $_POST["country"] . "', " . "'" . $_POST["phone"] . "', " . "'" . $_POST["email"] . "', " . "'" . MD5($_POST["password"]) . "', " . "'" . $activ . "')"; $res = mysql_query($sqlstr) or die ("no connection to the database ".mysql_error()); $num = mysql_affected_rows(); if ($num>0) { display_list_customers(); } else { ?> <div id="page-wrapper"><div class="container-fluid"> <div class="bg-darkred fg-white"> <span class="label label-danger">No record has been added to the database!</span> </div> </div></div> <?php } mysql_free_result($res); }else { ?> <div id="page-wrapper"><div class="container-fluid"> <div class="row"> <div class="col-md-12 col-lg-12 col-sm-12 col-xs-12"> <div class="panel panel-primary"> <div class="panel-heading"> <h2 class="panel-title">Insert Customer - Form</h2> </div> <div class="panel-body"> <form method="post" enctype="multipart/form-data" action="labaddcustomer.php"> <div class="form-group"> <label class="control-label" for="inputName">Name:</label> <input type="text" name="name" class="form-control" id="inputName" placeholder="Enter Customer name"> </div> <div class="form-group"> <label class="control-label" for="inputPrename">Prename:</label> <input type="text" name="prename" class="form-control" id="inputPrename" placeholder="Enter Prename"> </div> <div class="form-group"> <label class="control-label" for="inputAddress">Address:</label> <input type="text" name="address" class="form-control" id="inputAddress" placeholder="Enter Address"> </div> <div class="form-group"> <label class="control-label" for="inputPostcode">Postcode:</label> <input type="text" name="postcode" class="form-control" id="inputPostcode" placeholder="Enter Postcode"> </div> <div class="form-group"> <label class="control-label" for="inputCity">City:</label> <input type="text" name="city" class="form-control" id="inputCity" placeholder="Enter City"> </div> <div class="form-group"> <label class="control-label" for="inputRegion">Region:</label> <input type="text" name="region" class="form-control" id="inputRegion" placeholder="Enter Region"> </div> <div class="form-group"> <label class="control-label" for="inputCountry">Country:</label> <input type="text" name="country" class="form-control" id="inputCountry" placeholder="Enter Country"> </div> <div class="form-group"> <label class="control-label" for="inputPhonenumber">Phonenumber:</label> <input type="text" name="phone" class="form-control" id="inputPhonenumber" placeholder="Enter Phonenumber"> </div> <div class="form-group"> <label class="control-label" for="inputEmail">Email-Address:</label> <input type="text" name="email" class="form-control" id="inputEmail" placeholder="Enter Email-Address"> </div> <div class="form-group"> <label class="control-label" for="inputPassword">Password:</label> <input type="password" name="password" class="form-control" id="inputPassword" placeholder="Enter Password"> </div> <div class="form-group"> <label>Activ: </label> <input type="checkbox" name="activ"><br /> <small class="text-muted">If the entry should be active, the checkbox must be clicked!</small> </div> <div class="form-group"> <button type="submit" name="send" class="btn btn-primary"> <span class="fa fa-send"></span> Insert the record</button> </div> </form> </div> </div> </div> </div> </div></div> <?php } }// End of $user_id function display_list_customers(){ $sqlstr = "select * from tblcustomers ORDER BY customer_id "; $res = mysql_query($sqlstr) or die ("no connection to the database ".mysql_error()); $num = mysql_num_rows($res); ?> <div id="page-wrapper"><div class="container-fluid"> <div class="row"> <div class="col-md-12 col-lg-12 col-sm-12 col-xs-12"> <div class="panel panel-primary"> <div class="panel-heading"> <h2 class="panel-title">List the database: <small>tblcustomers</small></h2> </div> <div class="panel-body"> <h2>Insert the database: <small>tblcustomer</small><h2> <div class="table-responsive"><table class="table"> <thead> <tr><th>customer_id</th><th>name</th><th>prename</th><th>address</th><th>postcode</th><th>city</th> <th>region</th><th>country</th><th>phone</th><th>email</th><th>password</th><th>activ</th></tr> </thead> <tbody> <?php while ($row = mysql_fetch_assoc($res)) { ?> <tr> <td><?php echo $row["customer_id"]; ?></td> <td><?php echo $row["name"]; ?></td> <td><?php echo $row["prename"]; ?></td> <td><?php echo $row["address"]; ?></td> <td><?php echo $row["postcode"]; ?></td> <td><?php echo $row["city"]; ?></td> <td><?php echo $row["region"]; ?></td> <td><?php echo $row["country"]; ?></td> <td><?php echo $row["phone"]; ?></td> <td><?php echo $row["email"]; ?></td> <td><?php echo $row["password"]; ?></td> <td><?php echo $row["activ"]; ?></td> </tr> <?php } ?> </tbody> </table></div> </div> </div> </div> </div> </div></div> <?php mysql_free_result($res); } include("labfooter.php"); ?>
Wenn ein Benutzer angemeldet ist, können u.a. Datensätze in die entsprechenden Tabellen in dem Fall (tblcustomers) geändert werden. Die Abb.10.5.5a, Abb.10.5.5b und Abb.10.5.5c zeigen den Ablauf, um einen Datensatz in die Tabelle (tblcustomers) zu ändern.
Abb. 10.5.5a Kunden-Tabellenformular für die Änderung eines Datensatzes (labeditcustomer.php)
Abb. 10.5.5b Kunden-Tabelle nach der Änderung eines Datensatzes (labeditcustomer.php)
Abb. 10.5.5c Kunden-Tabelle nach der Änderung eines Datensatzes (labeditcustomer.php)
Der Inhalt der Datei (labeditcustomer.php)
<?php session_start(); include("labheader.php"); include("labconnect.php"); include("labsidenav.php"); $user_id = $_SESSION["user_id"]; if($user_id<=0){ ?> <div id="page-wrapper"><div class="container-fluid"> <div class="bg-darkred fg-white"> <span class="label label-danger">You are not logged in!</span> </div> </div></div> <?php } else { if(isset($_POST["send"])){ if(isset($_POST["activ"])) { $activ=1; }else { $activ=0; } $sqlstr = "update tblcustomers set " . " name = '" . $_POST["name"] . "'," . " prename = '" . $_POST["prename"] . "'," . " address = '" . $_POST["address"] . "'," . " postcode = '" . $_POST["postcode"] . "'," . " city = '" . $_POST["city"] . "'," . " region = '" . $_POST["region"] . "'," . " country = '" . $_POST["country"] . "'," . " phone = '" . $_POST["phone"] . "'," . " email = '" . $_POST["email"] . "'," . " password = '" . MD5($_POST["password"]) . "'," . " activ = '" . $activ . "'" . " where customer_id = " . $_POST["oripn"]; $res = mysql_query($sqlstr) or die ("no connection to the database ".mysql_error()); $num = mysql_affected_rows(); if ($num<=0) {?> <div id="page-wrapper"><div class="container-fluid"> <div class="bg-darkred fg-white"> <span class="label label-danger">The record has not been changed!</span> </div> </div></div> <?php } mysql_free_result($res); } if (isset($_POST["selectID"])) { $sqlstr = "select * from tblcustomers where customer_id = " . $_POST["selectID"]; $res = mysql_query($sqlstr); $row = mysql_fetch_assoc($res); ?> <div id="page-wrapper"><div class="container-fluid"> <div class="row"> <div class="col-md-12 col-lg-12 col-sm-12 col-xs-12"> <div class="panel panel-primary"> <div class="panel-heading"> <h2 class="panel-title">Edit Customer - Form</h2> </div> <div class="panel-body"> <form method="post" enctype="multipart/form-data" action="labeditcustomer.php"> <div class="form-group"> <label class="control-label">customer_id:</label> <input type="text" name="customer_id" class="form-control" value="<?php echo $_POST["selectID"]; ?>" disabled /> </div> <div class="form-group"> <label class="control-label">name:</label> <input type="text" name="name" class="form-control" value="<?php echo $row["name"]; ?>"> </div> <div class="form-group"> <label class="control-label">prename:</label> <input type="text" name="prename" class="form-control" value="<?php echo $row["prename"]; ?>"> </div> <div class="form-group"> <label class="control-label">address:</label> <input type="text" name="address" class="form-control" value="<?php echo $row["address"]; ?>"> </div> <div class="form-group"> <label class="control-label">postcode:</label> <input type="text" name="postcode" class="form-control" value="<?php echo $row["postcode"]; ?>"> </div> <div class="form-group"> <label class="control-label">city:</label> <input type="text" name="city" class="form-control" value="<?php echo $row["city"]; ?>"> </div> <div class="form-group"> <label class="control-label">region:</label> <input type="text" name="region" class="form-control" value="<?php echo $row["region"]; ?>"> </div> <div class="form-group"> <label class="control-label">country:</label> <input type="text" name="country" class="form-control" value="<?php echo $row["country"]; ?>"> </div> <div class="form-group"> <label class="control-label">phonenumber:</label> <input type="text" name="phone" class="form-control" value="<?php echo $row["phone"]; ?>"> </div> <div class="form-group"> <label class="control-label">Email-address:</label> <input type="email" name="email" class="form-control" value="<?php echo $row["email"]; ?>"> </div> <div class="form-group"> <label class="control-label">password:</label> <input type="password" name="password" class="form-control" value="<?php echo $row["password"]; ?>"> </div> <?php if ($row["activ"] ==1){ ?> <div class="form-group"> <label>Activ : </label> <input type="checkbox" name="activ" checked> </div> <?php } else { ?> <div class="form-group"> <label>Activ: </label> <input type="checkbox" name="activ"> </div> <?php } ?> <div class="form-group"> <input type="hidden" name="oripn" value="<?php echo $_POST["selectID"]; ?>" /> <button type="submit" name="send" class="btn btn-primary"> <span class="fa fa-edit"></span> Edit the record</button> </div> </form> </div> </div> </div> </div> </div></div> <?php mysql_free_result($res); } else { display_edit_customers(); } } // end of $user_id function display_edit_customers(){ $sqlstr = "select * from tblcustomers ORDER BY customer_id "; $res = mysql_query($sqlstr) or die ("no connection to the database ".mysql_error()); $num = mysql_num_rows($res); ?> <div id="page-wrapper"><div class="container-fluid"> <div class="row"> <div class="col-md-12 col-lg-12 col-sm-12 col-xs-12"> <div class="panel panel-primary"> <div class="panel-heading"> <h2 class="panel-title">List the database: <small>tblcustomers</small></h2> </div> <div class="panel-body"> <form method="post" enctype="multipart/form-data" action="labeditcustomer.php"> <div class="table-responsive"><table class="table"> <thead> <tr><th>customer_id</th><th>name</th><th>prename</th><th>address</th><th>postcode</th><th>city</th><th>region</th> <th>country</th><th>phone</th><th>email</th><th>password</th><th>activ</th><th>Select</th> </tr> </thead><tbody> <?php while ($row = mysql_fetch_assoc($res)) { ?> <tr> <td><?php echo $row["customer_id"]; ?></td> <td><?php echo $row["name"]; ?></td> <td><?php echo $row["prename"]; ?></td> <td><?php echo $row["address"]; ?></td> <td><?php echo $row["postcode"]; ?></td> <td><?php echo $row["city"]; ?></td> <td><?php echo $row["region"]; ?></td> <td><?php echo $row["country"]; ?></td> <td><?php echo $row["phone"]; ?></td> <td><?php echo $row["email"]; ?></td> <td><?php echo MD5($row["password"]); ?></td> <td><?php echo $row["activ"]; ?></td> <td><input type="checkbox" name="selectID" value="<?php echo $row["customer_id"]; ?>" data-role="checkbox"></td> </tr> <?php } ?> </tbody> </table></div> <button type="submit" class="btn btn-primary"> <span class="fa fa-eye"></span> View the record</button> </form> </div> </div> </div> </div> </div></div> <?php mysql_free_result($res); } include("labfooter.php"); ?>
Wenn ein Benutzer angemeldet ist, können u.a. Datensätze aus den entsprechenden Tabellen in dem Fall (tblcustomers) gelöscht werden. Die Abb.10.5.6a, Abb.10.5.6b und Abb.10.5.6c zeigen den Ablauf, um einen Datensatz aus der Tabelle (tblcustomers) zu löschen.
Abb. 10.5.6a Kunden-Tabellenformular für das Löschen eines Datensatzes (labdeletecustomer.php)
Abb. 10.5.6b Kunden-Formular für das Löschen eines Datensatzes (labdeletecustomer.php)
Abb. 10.5.6c Kunden-Formular für das Löschen eines Datensatzes (labdeletecustomer.php)
Der Inhalt der Datei (labdeletecustomer.php)
<?php session_start(); include("labheader.php"); include("labconnect.php"); include("labsidenav.php"); $user_id = $_SESSION["user_id"]; if($user_id<=0){ ?> <div id="page-wrapper"><div class="container-fluid"> <div class="bg-darkred fg-white"> <span class="label label-danger">You are not logged in!</span> </div> </div></div> <?php } else { if(isset($_POST["send"])){ $sqlstr = "DELETE FROM tblcustomers WHERE customer_id = " . $_POST["oripn"]; $res = mysql_query($sqlstr) or die ("no connection to the database ".mysql_error()); $num = mysql_affected_rows(); if ($num<=0) {?> <div id="page-wrapper"><div class="container-fluid"> <div class="bg-darkred fg-white"> <span class="label label-danger">The record has not been deleted!</span> </div> </div></div> <?php } mysql_free_result($res); } if (isset($_POST["selectID"])) { $sqlstr = "select * from tblcustomers where customer_id = " . $_POST["selectID"]; $res = mysql_query($sqlstr); $row = mysql_fetch_assoc($res); ?> <div id="page-wrapper"><div class="container-fluid"> <div class="row"> <div class="col-md-12 col-lg-12 col-sm-12 col-xs-12"> <div class="panel panel-primary"> <div class="panel-heading"> <h2 class="panel-title">Delete Customer - Form</h2> </div> <div class="panel-body"> <form method="post" enctype="multipart/form-data" action="labdeletecustomer.php"> <div class="form-group"> <label class="control-label">customer_id:</label> <input type="text" name="customer_id" class="form-control" value="<?php echo $_POST["selectID"]; ?>" disabled /> </div> <div class="form-group"> <label class="control-label">name:</label> <input type="text" name="name" class="form-control" value="<?php echo $row["name"]; ?>"> </div> <div class="form-group"> <label class="control-label">prename:</label> <input type="text" name="prename" class="form-control" value="<?php echo $row["prename"]; ?>"> </div> <div class="form-group"> <label class="control-label">address:</label> <input type="text" name="address" class="form-control" value="<?php echo $row["address"]; ?>"> </div> <div class="form-group"> <label class="control-label">postcode:</label> <input type="text" name="postcode" class="form-control" value="<?php echo $row["postcode"]; ?>"> </div> <div class="form-group"> <label class="control-label">city:</label> <input type="text" name="city" class="form-control" value="<?php echo $row["city"]; ?>"> </div> <div class="form-group"> <label class="control-label">region:</label> <input type="text" name="region" class="form-control" value="<?php echo $row["region"]; ?>"> </div> <div class="form-group"> <label class="control-label">country:</label> <input type="text" name="country" class="form-control" value="<?php echo $row["country"]; ?>"> </div> <div class="form-group"> <label class="control-label">phonenumber:</label> <input type="text" name="phone" class="form-control" value="<?php echo $row["phone"]; ?>"> </div> <div class="form-group"> <label class="control-label">Email-address:</label> <input type="email" name="email" class="form-control" value="<?php echo $row["email"]; ?>"> </div> <div class="form-group"> <label class="control-label">password:</label> <input type="password" name="password" class="form-control" value="<?php echo $row["password"]; ?>"> </div> <?php if ($row["activ"] ==1){ ?> <div class="form-group"> <label>Activ : </label> <input type="checkbox" name="activ" checked> </div> <?php } else { ?> <div class="form-group"> <label>Activ: </label> <input type="checkbox" name="activ"> </div> <?php } ?> <div class="form-group"> <input type="hidden" name="oripn" value="<?php echo $_POST["selectID"]; ?>" /> <button type="submit" name="send" class="btn btn-primary"> <span class="fa fa-trash"></span> Delete the record</button> </div> </form> </div> </div> </div> </div> </div></div> <?php mysql_free_result($res); } else { display_delete_customers(); } } // end of $user_id function display_delete_customers(){ $sqlstr = "select * from tblcustomers ORDER BY customer_id "; $res = mysql_query($sqlstr) or die ("no connection to the database ".mysql_error()); $num = mysql_num_rows($res); ?> <div id="page-wrapper"><div class="container-fluid"> <div class="row"> <div class="col-md-12 col-lg-12 col-sm-12 col-xs-12"> <div class="panel panel-primary"> <div class="panel-heading"> <h2 class="panel-title">List the database: <small>tblcustomers</small></h2> </div> <div class="panel-body"> <form method="post" enctype="multipart/form-data" action="labdeletecustomer.php"> <div class="table-responsive"><table class="table"> <thead> <tr><th>customer_id</th><th>name</th><th>prename</th><th>address</th><th>postcode</th><th>city</th><th>region</th> <th>country</th><th>phone</th><th>email</th><th>password</th><th>activ</th><th>Select</th> </tr> </thead><tbody> <?php while ($row = mysql_fetch_assoc($res)) { ?> <tr> <td><?php echo $row["customer_id"]; ?></td> <td><?php echo $row["name"]; ?></td> <td><?php echo $row["prename"]; ?></td> <td><?php echo $row["address"]; ?></td> <td><?php echo $row["postcode"]; ?></td> <td><?php echo $row["city"]; ?></td> <td><?php echo $row["region"]; ?></td> <td><?php echo $row["country"]; ?></td> <td><?php echo $row["phone"]; ?></td> <td><?php echo $row["email"]; ?></td> <td><?php echo MD5($row["password"]); ?></td> <td><?php echo $row["activ"]; ?></td> <td><input type="checkbox" name="selectID" value="<?php echo $row["customer_id"]; ?>" data-role="checkbox"></td> </tr> <?php } ?> </tbody> </table></div> <button type="submit" class="btn btn-primary"> <span class="fa fa-eye"></span> View the record</button> </form> </div> </div> </div> </div> </div></div> <?php mysql_free_result($res); } include("labfooter.php"); ?>
Wenn ein Benutzer angemeldet ist, können u.a. Datensätze in die entsprechenden Tabellen in dem Fall (tbldeliveries) hinzugefügt werden. Die Abb.10.5.7a und Abb.10.5.7b zeigen den Ablauf, um einen Datensatz in die Tabelle (tbldeliveries) hinzuzufügen.
Abb. 10.5.7a Versand-Formular für einen neuen Datensatz (labadddelivery.php)
Abb. 10.5.7b Hinzugefügter Datensatz (labadddelivery.php)
Der Inhalt der Datei (labadddelivery.php)
<?php session_start(); include("labheader.php"); include("labconnect.php"); include("labsidenav.php"); $user_id = $_SESSION["user_id"]; if($user_id<=0){ ?> <div id="page-wrapper"><div class="container-fluid"> <div class="bg-darkred fg-white"> <span class="label label-danger">You are not logged in!</span> </div> </div></div> <?php } else { if(isset($_POST["send"])){ if(isset($_POST["activ"])) { $activ=1; }else { $activ=0; } $sqlstr = "insert tbldeliveries (name, prename, address, postcode, city, region, country, phone, email, activ) values " . "('" . $_POST["name"] . "', " . "'" . $_POST["prename"] . "', " . "'" . $_POST["address"] . "', " . "'" . $_POST["postcode"] . "', " . "'" . $_POST["city"] . "', " . "'" . $_POST["region"] . "', " . "'" . $_POST["country"] . "', " . "'" . $_POST["phone"] . "', " . "'" . $_POST["email"] . "', " . "'" . $activ. "')"; $res = mysql_query($sqlstr) or die ("no connection to the database ".mysql_error()); $num = mysql_affected_rows(); if ($num>0) { display_list_deliveries(); } else { ?> <div id="page-wrapper"><div class="container-fluid"> <div class="bg-darkred fg-white"> <span class="label label-danger">No record has been added to the database!</span> </div> </div></div> <?php } mysql_free_result($res); }else { ?> <div id="page-wrapper"><div class="container-fluid"> <div class="row"> <div class="col-md-12 col-lg-12 col-sm-12 col-xs-12"> <div class="panel panel-primary"> <div class="panel-heading"> <h2 class="panel-title">Insert delivery - Form</h2> </div> <div class="panel-body"> <form method="post" enctype="multipart/form-data" action="labadddelivery.php"> <div class="form-group"> <label class="control-label" for="inputName">Name:</label> <input type="text" name="name" class="form-control" id="inputName" placeholder="Enter deliver name"> </div> <div class="form-group"> <label class="control-label" for="inputPrename">Prename:</label> <input type="text" name="prename" class="form-control" id="inputPrename" placeholder="Enter Prename"> </div> <div class="form-group"> <label class="control-label" for="inputAddress">Address:</label> <input type="text" name="address" class="form-control" id="inputAddress" placeholder="Enter Address"> </div> <div class="form-group"> <label class="control-label" for="inputPostcode">Postcode:</label> <input type="text" name="postcode" class="form-control" id="inputPostcode" placeholder="Enter Postcode"> </div> <div class="form-group"> <label class="control-label" for="inputCity">City:</label> <input type="text" name="city" class="form-control" id="inputCity" placeholder="Enter City"> </div> <div class="form-group"> <label class="control-label" for="inputRegion">Region:</label> <input type="text" name="region" class="form-control" id="inputRegion" placeholder="Enter Region"> </div> <div class="form-group"> <label class="control-label" for="inputCountry">Country:</label> <input type="text" name="country" class="form-control" id="inputCountry" placeholder="Enter Country"> </div> <div class="form-group"> <label class="control-label" for="inputPhonenumber">Phonenumber:</label> <input type="text" name="phone" class="form-control" id="inputPhonenumber" placeholder="Enter Phonenumber"> </div> <div class="form-group"> <label class="control-label" for="inputEmail">Email-Address:</label> <input type="text" name="email" class="form-control" id="inputEmail" placeholder="Enter Email-Address"> </div> <div class="form-group"> <label>Activ: </label> <input type="checkbox" name="activ"><br /> <small class="text-muted">If the entry should be active, the checkbox must be clicked!</small> </div> <div class="form-group"> <button type="submit" name="send" class="btn btn-primary"> <span class="fa fa-send"></span> Insert the record</button> </div> </form> </div> </div> </div> </div> </div></div> <?php } }// End of $user_id function display_list_deliveries(){ $sqlstr = "select * from tbldeliveries ORDER BY delivery_id "; $res = mysql_query($sqlstr) or die ("no connection to the database ".mysql_error()); $num = mysql_num_rows($res); ?> <div id="page-wrapper"><div class="container-fluid"> <div class="row"> <div class="col-md-12 col-lg-12 col-sm-12 col-xs-12"> <div class="panel panel-primary"> <div class="panel-heading"> <h2 class="panel-title">List the database: <small>tbldeliveries</small></h2> </div> <div class="panel-body"> <h2>Insert the database: <small>tbldeliveries</small><h2> <div class="table-responsive"><table class="table"> <thead> <tr><th>delivery_id</th><th>name</th><th>prename</th><th>address</th><th>postcode</th><th>city</th> <th>region</th><th>country</th><th>phone</th><th>email</th><th>activ</th></tr> </thead> <tbody> <?php while ($row = mysql_fetch_assoc($res)) { ?> <tr> <td><?php echo $row["delivery_id"]; ?></td> <td><?php echo $row["name"]; ?></td> <td><?php echo $row["prename"]; ?></td> <td><?php echo $row["address"]; ?></td> <td><?php echo $row["postcode"]; ?></td> <td><?php echo $row["city"]; ?></td> <td><?php echo $row["region"]; ?></td> <td><?php echo $row["country"]; ?></td> <td><?php echo $row["phone"]; ?></td> <td><?php echo $row["email"]; ?></td> <td><?php echo $row["activ"]; ?></td> </tr> <?php } ?> </tbody> </table></div> </div> </div> </div> </div> </div></div> <?php mysql_free_result($res); } include("labfooter.php"); ?>
Wenn ein Benutzer angemeldet ist, können u.a. Datensätze in die entsprechenden Tabellen in dem Fall (tbldeliveries) geändert werden. Die Abb.10.5.8a, Abb.10.5.8b und Abb.10.5.8c zeigen den Ablauf, um einen Datensatz in die Tabelle (tbldeliveries) zu ändern.
Abb. 10.5.8a Versand-Tabellenformular für die Änderung eines Datensatzes (labeditdelivery.php)
Abb. 10.5.8b Versand-Tabelle nach der Änderung eines Datensatzes (labeditdelivery.php)
Abb. 10.5.8c Versand-Tabelle nach der Änderung eines Datensatzes (labeditdelivery.php)
Der Inhalt der Datei (labeditdelivery.php)
<?php session_start(); include("labheader.php"); include("labconnect.php"); include("labsidenav.php"); $user_id = $_SESSION["user_id"]; if($user_id<=0){ ?> <div id="page-wrapper"><div class="container-fluid"> <div class="bg-darkred fg-white"> <span class="label label-danger">You are not logged in!</span> </div> </div></div> <?php } else { if(isset($_POST["send"])){ if(isset($_POST["activ"])) { $activ=1; }else { $activ=0; } $sqlstr = "update tbldeliveries set " . " name = '" . $_POST["name"] . "'," . " prename = '" . $_POST["prename"] . "'," . " address = '" . $_POST["address"] . "'," . " postcode = '" . $_POST["postcode"] . "'," . " city = '" . $_POST["city"] . "'," . " region = '" . $_POST["region"] . "'," . " country = '" . $_POST["country"] . "'," . " phone = '" . $_POST["phone"] . "'," . " email = '" . $_POST["email"] . "'," . " activ = '" . $activ . "'" . " where delivery_id = " . $_POST["oripn"]; $res = mysql_query($sqlstr) or die ("no connection to the database ".mysql_error()); $num = mysql_affected_rows(); if ($num<=0) {?> <div id="page-wrapper"><div class="container-fluid"> <div class="bg-darkred fg-white"> <span class="label label-danger">The record has not been changed!</span> </div> </div></div> <?php } mysql_free_result($res); } if (isset($_POST["selectID"])) { $sqlstr = "select * from tbldeliveries where delivery_id = " . $_POST["selectID"]; $res = mysql_query($sqlstr); $row = mysql_fetch_assoc($res); ?> <div id="page-wrapper"><div class="container-fluid"> <div class="row"> <div class="col-md-12 col-lg-12 col-sm-12 col-xs-12"> <div class="panel panel-primary"> <div class="panel-heading"> <h2 class="panel-title">Edit Delivery - Form</h2> </div> <div class="panel-body"> <form method="post" enctype="multipart/form-data" action="labeditdelivery.php"> <div class="form-group"> <label class="control-label">customer_id:</label> <input type="text" name="delivery_id" class="form-control" value="<?php echo $_POST["selectID"]; ?>" disabled /> </div> <div class="form-group"> <label class="control-label">name:</label> <input type="text" name="name" class="form-control" value="<?php echo $row["name"]; ?>"> </div> <div class="form-group"> <label class="control-label">prename:</label> <input type="text" name="prename" class="form-control" value="<?php echo $row["prename"]; ?>"> </div> <div class="form-group"> <label class="control-label">address:</label> <input type="text" name="address" class="form-control" value="<?php echo $row["address"]; ?>"> </div> <div class="form-group"> <label class="control-label">postcode:</label> <input type="text" name="postcode" class="form-control" value="<?php echo $row["postcode"]; ?>"> </div> <div class="form-group"> <label class="control-label">city:</label> <input type="text" name="city" class="form-control" value="<?php echo $row["city"]; ?>"> </div> <div class="form-group"> <label class="control-label">region:</label> <input type="text" name="region" class="form-control" value="<?php echo $row["region"]; ?>"> </div> <div class="form-group"> <label class="control-label">country:</label> <input type="text" name="country" class="form-control" value="<?php echo $row["country"]; ?>"> </div> <div class="form-group"> <label class="control-label">phonenumber:</label> <input type="text" name="phone" class="form-control" value="<?php echo $row["phone"]; ?>"> </div> <div class="form-group"> <label class="control-label">Email-address:</label> <input type="email" name="email" class="form-control" value="<?php echo $row["email"]; ?>"> </div> <?php if ($row["activ"] ==1){ ?> <div class="form-group"> <label>activ : </label> <input type="checkbox" name="activ" checked> </div> <?php } else { ?> <div class="form-group"> <label>Registered : </label> <input type="checkbox" name="activ"> </div> <?php } ?> <div class="form-group"> <input type="hidden" name="oripn" value="<?php echo $_POST["selectID"]; ?>" /> <button type="submit" name="send" class="btn btn-primary"> <span class="fa fa-edit"></span> Edit the record</button> </div> </form> </div> </div> </div> </div> </div></div> <?php mysql_free_result($res); } else { display_edit_deliveries(); } } // end of $user_id function display_edit_deliveries(){ $sqlstr = "select * from tbldeliveries ORDER BY delivery_id "; $res = mysql_query($sqlstr) or die ("no connection to the database ".mysql_error()); $num = mysql_num_rows($res); ?> <div id="page-wrapper"><div class="container-fluid"> <div class="row"> <div class="col-md-12 col-lg-12 col-sm-12 col-xs-12"> <div class="panel panel-primary"> <div class="panel-heading"> <h2 class="panel-title">List the database: <small>tbldeliveries</small></h2> </div> <div class="panel-body"> <form method="post" enctype="multipart/form-data" action="labeditdelivery.php"> <div class="table-responsive"><table class="table"> <thead> <tr><th>delivery_id</th><th>name</th><th>prename</th><th>address</th><th>postcode</th><th>city</th><th>region</th> <th>country</th><th>phone</th><th>email</th><th>activ</th><th>Select</th> </tr> </thead><tbody> <?php while ($row = mysql_fetch_assoc($res)) { ?> <tr> <td><?php echo $row["delivery_id"]; ?></td> <td><?php echo $row["name"]; ?></td> <td><?php echo $row["prename"]; ?></td> <td><?php echo $row["address"]; ?></td> <td><?php echo $row["postcode"]; ?></td> <td><?php echo $row["city"]; ?></td> <td><?php echo $row["region"]; ?></td> <td><?php echo $row["country"]; ?></td> <td><?php echo $row["phone"]; ?></td> <td><?php echo $row["email"]; ?></td> <td><?php echo $row["activ"]; ?></td> <td><input type="checkbox" name="selectID" value="<?php echo $row["delivery_id"]; ?>" data-role="checkbox"></td> </tr> <?php } ?> </tbody> </table></div> <button type="submit" class="btn btn-primary"> <span class="fa fa-eye"></span> View the record</button> </form> </div> </div> </div> </div> </div></div> <?php mysql_free_result($res); } include("labfooter.php"); ?>
Wenn ein Benutzer angemeldet ist, können u.a. Datensätze aus den entsprechenden Tabellen in dem Fall (tbldeliveries) gelöscht werden. Die Abb.10.5.9a, Abb.10.5.9b und Abb.10.5.9c zeigen den Ablauf, um einen Datensatz aus der Tabelle (tbldeliveries) zu löschen.
Abb. 10.5.9a Versand-Tabellenformular für das Löschen eines Datensatzes (labdeletedelivery.php)
Abb. 10.5.9b Versand-Formular für das Löschen eines Datensatzes (labdeletedelivery.php)
Abb. 10.5.9c Versand-Formular für das Löschen eines Datensatzes (labdeletedelivery.php)
Der Inhalt der Datei (labdeletedelivery.php)
<?php session_start(); include("labheader.php"); include("labconnect.php"); include("labsidenav.php"); $user_id = $_SESSION["user_id"]; if($user_id<=0){ ?> <div id="page-wrapper"><div class="container-fluid"> <div class="bg-darkred fg-white"> <span class="label label-danger">You are not logged in!</span> </div> </div></div> <?php } else { if(isset($_POST["send"])){ $sqlstr = "DELETE FROM tbldeliveries WHERE delivery_id = " . $_POST["oripn"]; $res = mysql_query($sqlstr) or die ("no connection to the database ".mysql_error()); $num = mysql_affected_rows(); if ($num<=0) {?> <div id="page-wrapper"><div class="container-fluid"> <div class="bg-darkred fg-white"> <span class="label label-danger">The record has not been deleted!</span> </div> </div></div> <?php } mysql_free_result($res); } if (isset($_POST["selectID"])) { $sqlstr = "select * from tbldeliveries where delivery_id = " . $_POST["selectID"]; $res = mysql_query($sqlstr); $row = mysql_fetch_assoc($res); ?> <div id="page-wrapper"><div class="container-fluid"> <div class="row"> <div class="col-md-12 col-lg-12 col-sm-12 col-xs-12"> <div class="panel panel-primary"> <div class="panel-heading"> <h2 class="panel-title">Delete Delivery - Form</h2> </div> <div class="panel-body"> <form method="post" enctype="multipart/form-data" action="labdeletedelivery.php"> <div class="form-group"> <label class="control-label">customer_id:</label> <input type="text" name="delivery_id" class="form-control" value="<?php echo $_POST["selectID"]; ?>" disabled /> </div> <div class="form-group"> <label class="control-label">name:</label> <input type="text" name="name" class="form-control" value="<?php echo $row["name"]; ?>"> </div> <div class="form-group"> <label class="control-label">prename:</label> <input type="text" name="prename" class="form-control" value="<?php echo $row["prename"]; ?>"> </div> <div class="form-group"> <label class="control-label">address:</label> <input type="text" name="address" class="form-control" value="<?php echo $row["address"]; ?>"> </div> <div class="form-group"> <label class="control-label">postcode:</label> <input type="text" name="postcode" class="form-control" value="<?php echo $row["postcode"]; ?>"> </div> <div class="form-group"> <label class="control-label">city:</label> <input type="text" name="city" class="form-control" value="<?php echo $row["city"]; ?>"> </div> <div class="form-group"> <label class="control-label">region:</label> <input type="text" name="region" class="form-control" value="<?php echo $row["region"]; ?>"> </div> <div class="form-group"> <label class="control-label">country:</label> <input type="text" name="country" class="form-control" value="<?php echo $row["country"]; ?>"> </div> <div class="form-group"> <label class="control-label">phonenumber:</label> <input type="text" name="phone" class="form-control" value="<?php echo $row["phone"]; ?>"> </div> <div class="form-group"> <label class="control-label">Email-address:</label> <input type="email" name="email" class="form-control" value="<?php echo $row["email"]; ?>"> </div> <?php if ($row["activ"] ==1){ ?> <div class="form-group"> <label>activ : </label> <input type="checkbox" name="activ" checked> </div> <?php } else { ?> <div class="form-group"> <label>Registered : </label> <input type="checkbox" name="activ"> </div> <?php } ?> <div class="form-group"> <input type="hidden" name="oripn" value="<?php echo $_POST["selectID"]; ?>" /> <button type="submit" name="send" class="btn btn-primary"> <span class="fa fa-trash"></span> Delete the record</button> </div> </form> </div> </div> </div> </div> </div></div> <?php mysql_free_result($res); } else { display_delete_deliveries(); } } // end of $user_id function display_delete_deliveries(){ $sqlstr = "select * from tbldeliveries ORDER BY delivery_id "; $res = mysql_query($sqlstr) or die ("no connection to the database ".mysql_error()); $num = mysql_num_rows($res); ?> <div id="page-wrapper"><div class="container-fluid"> <div class="row"> <div class="col-md-12 col-lg-12 col-sm-12 col-xs-12"> <div class="panel panel-primary"> <div class="panel-heading"> <h2 class="panel-title">List the database: <small>tbldeliveries</small></h2> </div> <div class="panel-body"> <form method="post" enctype="multipart/form-data" action="labdeletedelivery.php"> <div class="table-responsive"><table class="table"> <thead> <tr><th>delivery_id</th><th>name</th><th>prename</th><th>address</th><th>postcode</th><th>city</th><th>region</th> <th>country</th><th>phone</th><th>email</th><th>activ</th><th>Select</th> </tr> </thead><tbody> <?php while ($row = mysql_fetch_assoc($res)) { ?> <tr> <td><?php echo $row["delivery_id"]; ?></td> <td><?php echo $row["name"]; ?></td> <td><?php echo $row["prename"]; ?></td> <td><?php echo $row["address"]; ?></td> <td><?php echo $row["postcode"]; ?></td> <td><?php echo $row["city"]; ?></td> <td><?php echo $row["region"]; ?></td> <td><?php echo $row["country"]; ?></td> <td><?php echo $row["phone"]; ?></td> <td><?php echo $row["email"]; ?></td> <td><?php echo $row["activ"]; ?></td> <td><input type="checkbox" name="selectID" value="<?php echo $row["delivery_id"]; ?>" data-role="checkbox"></td> </tr> <?php } ?> </tbody> </table></div> <button type="submit" class="btn btn-primary"> <span class="fa fa-eye"></span> View the record</button> </form> </div> </div> </div> </div> </div></div> <?php mysql_free_result($res); } include("labfooter.php"); ?>
10.6.1) labconnect.php
Diese Datei, wie es schon im Abschnitt 10.1.1 erklärt wurde, befindet sich im Unterordner "shop".<?php mysql_connect("localhost", "your_username", "your_password"); mysql_select_db("your_databasename"); function db_connect() { $result = new mysqli("localhost", "your_username", "your_password", "your_databasename"); if (!$result) return FALSE; $result->autocommit(TRUE); return $result; } function get_cgi_param ($feld, $default) { $var = $default; $rmeth = $_SERVER['REQUEST_METHOD']; if ($rmeth == 'GET') { if (isset ($_GET[$feld]) && $_GET[$feld] != "") { $var = $_GET[$feld]; } } elseif ($rmeth == 'POST') { if (isset ($_POST[$feld]) && $_POST[$feld] != "") { $var = $_POST[$feld]; } } return $var; } ?>
10.6.2) labheader.php
Diese Datei befindet sich im Unterordner "shop" und beinhaltet das Grundgerüst, die Navigation und CSS-Dateien für die Website-Besucher.<?php session_start(); include "labconnect.php"; ?> <!doctype html> <html class="no-js" lang=""> <head> <meta charset="utf-8"> <meta http-equiv="x-ua-compatible" content="ie=edge"> <title> GLC by Mehdi Bandegani</title> <meta name="description" content=""> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="css/bootstrap.min.css" /> <link rel="stylesheet" href="css/startmin.css"/> <link rel="stylesheet" href="css/font-awesome.min.css" /> <!--Google Fonts--> <link href="https://fonts.googleapis.com/css?family=Roboto+Condensed|Titillium+Web" rel="stylesheet" /> <!--glc Nav CSS--> <link rel="stylesheet" href="css/glc-nav.css" /> </head> <body> <div id="wrapper"> <section> <header class="dev-head endless-river sticky"> <div class="menu-trigger"> <div class="nav-icon"> <span></span> <span></span> <span></span> <span></span> </div> </div> <!--//menu-trigger--> <div class="logo"> <a href="#"> <img src="image/haw-logo.jpg" title="Logo"> </a> </div> <!--//logo--> <div class="phone" style="display: none;"> <a href="tel:+4940428754627"> <i class="fa fa-phone"></i> </a> </div> <!--//phone--> <div class="dev-nav"> <ul class="trigger-board"> <li class="about hvr-radial-out" title="About"><i class="fa fa-user"></i></li> <li class="work hvr-radial-out" title="Work"><i class="fa fa-industry"></i></li> <li class="contact hvr-radial-out" title="Contact"> <i class="fa fa-envelope"></i></li> <li class="address hvr-radial-out" title="Address"><i class="fa fa-map"></i></li> </ul> <div class="dev-profile active"> <img src="image/logo1.jpg" alt="glc"--> <h5>Garment life cycles </h5> <div class="social"> <a href="#"> <div class="hvr-float-shadow"> <i class="fa fa-facebook"></i></div> </a> <a href="#"> <div class="hvr-float-shadow"> <i class="fa fa-twitter"></i> </div> </a> <a href="#"> <div class="hvr-float-shadow"> <i class="fa fa-google-plus"></i></div> </a> </div> <!--//social--> </div> <!--//dev-profile--> <div class="dev-work"> <h6> Was wir machen? </h6> <p><i> Wir befassen uns </i><br> überwiegend mit Grundlagen in den Bereichen Natur- und Ingenieurwissenschaften, Textilwissenschaften, Bekleidungstechnik sowie Arbeits- und Wirtschaftswissenschaften. </p> </div> <!--//dev-work--> <div class="dev-contact-form"> <h6> Contact Form</h6> <form method="get" action="#3"> <input name="name" type="text" placeholder="Your Name"> <input name="email" type="text" placeholder="Your Email"> <textarea rows="3"> </textarea> <button class="dev-ctn-btn" type="submit"> Send Message</button> </form> </div><!--//dev-contact-form--> <div class="dev-address"> <h5> HAW Hamburg </h5> <h6>Armgarstraße 24</h6> </h6>22087 Hamburg</h6> <h4><b>Phone: </b>+4940428754627</h4> </div> <!--//dev-address--> <nav><!-- Beginn of Navigation --> <ul class="navigation"> <li> <a href="../index.php" style="padding-top: 0px;"><span class="dropdown-heading fa fa-home"> HOME </span></a> </li> <li class="has-sub"> <span class="dropdown-heading"> <i class="fa fa-info"></i> Info</span> <ul> <li> <a href="../doc/labdescription.php">DESCRIPTION</a> </li> <li> <a href="labproductfair.php">PRODUCT FAIRNESS</a> </li> <li> <a href="labrecycling.php">RECYCLING</a> </li> </ul> </li> <?php $sqlstr_cat="SELECT cat_id, name FROM tblcategories WHERE 1"; $res_cat = mysql_query($sqlstr_cat) or die ("no connection to the database ".mysql_error()); ?> <?php while ($row_cat = mysql_fetch_assoc($res_cat)) { ?> <li class="has-sub"> <span class="dropdown-heading"> <i class="fa fa-codepen"></i> <?php echo $row_cat["name"];?> </span> <ul> <?php $sqlstr_subcat="SELECT subcat_id, cat_id, name FROM tblsubcategories WHERE cat_id=".$row_cat["cat_id"]; $res_subcat = mysql_query($sqlstr_subcat) or die ("no connection to the database ".mysql_error()); while ($row_subcat = mysql_fetch_assoc($res_subcat)) { ?> <li><a href="labarticle.php?subcat_id=<?php echo $row_subcat["subcat_id"]?>"> <?php echo $row_subcat["name"];?></a></li> <?php } ?> </ul> </li> <?php }?> <?php if ($_SESSION["editor_user"] || $_SESSION["admin_user"]){ ?> <li><a href="../admin/lablogout.php" style="padding-top: 0px;"><span class="dropdown-heading fa fa-user"> LOGOUT </span></a></li> <li><a href="../admin/labadmin.php" style="padding-top: 0px;"><span class="dropdown-heading fa fa-user-secret"> ADMIN </span></a></li> <?php } else { ?> <li><a href="../admin/lablogin.php" style="padding-top: 0px;"><span class="dropdown-heading fa fa-user-plus"> LOGIN </span></a></li> <?php } ?> </ul> </nav> </div><!--//dev-nav--> </header> <div class="dim-overlay" style="display: none"></div> </section> <br /><br /><br /> <?php $heute = date("F j, Y, g:i a"); ?> <h2 style="text-align:right;"><small><?php echo $heute; ?></small></h2>
10.6.3) labfooter.php
Diese Datei befindet sich im Unterordner "shop" und beinhaltet den Abschluss vom dem Grundgerüst, die JS-Dateien und den Fußbereich für die Website-Besucher.<!-- Begin footer --> <footer class="page-footer font-small blue-grey lighten-5"> <div class="footer-copyright text-center py-3" style="background-color: #F0F8FF;"> <ul class="list-unstyled"> <br /> <li> <a href="https://www.haw-hamburg.de/startseite.html">HAW-Hamburg</a> </li> <li> <a href="https://design.haw-hamburg.de/home/das-department-design/">Departement Design</a> </li> <li> <a href="https://vorlesungsverzeichnis.design.haw-hamburg.de/">Vorlesungsverzeichnis</a> </li> </ul> <a href="http://www.bandegani.de/"> <span class="fa fa-copyright"></span>2021 Copyright bandegani.de </a> </div> </footer><!-- End footer --> <div class="dmtop"></div> </div><!-- end wrapper --> <script src="js/jquery.min.js"></script> <!-- Bootstrap Core JavaScript --> <script src="js/bootstrap.min.js"></script> <!-- Metis Menu Plugin JavaScript --> <script src="js/metisMenu.min.js"></script> <!-- Custom Theme JavaScript --> <script src="js/startmin.js"></script> <script src="js/glc-nav.js"> </script> </body> </html>
10.6.4) labproductfair.php
Diese Datei befindet sich im Unterordner "shop" und wird eingesetzt, um das Kleidungsstück bei "Wie fair ist mein Kleidungsstück?" zu finden und anzuzeigen.<?php session_start(); include ("labheader.php"); ?> <section class="section"> <div class="container"> <div class="row"> <div class="col-lg-3 col-md-3 col-sm-12 col-xs-12"> <div class="sidebar"> <!-- Bild 300x600 --> <!-- Recent Reviews --> <div class="widget"> <h2 style="background: #1528E7; color:#fff">Neu eingetroffen</h2> <div class="blog-list-widget"> <div class="list-group"> <?php $sqlstr_current = "SELECT * FROM tblarticles ORDER BY modified DESC LIMIT 3"; $res_current = mysql_query($sqlstr_current) or die ("no connection to the database ".mysql_error()); while ($row_current = mysql_fetch_assoc($res_current)) { ?> <div class="w-100 justify-content-between"> <?php if ($row_current["type"] == "image") { ?> <img src="../admin/<?php echo $row_current["pic"];?>" class="img-fluid img-responsive"> <?php } else if ($row_current["type"] == "video") { ?> <video src="../admin/<?php echo $row_current["pic"];?>" type="video/mp4" class="img-fluid img-responsive" controls/></video> <?php } ?> <span class="color-orange"><h4><a href="labarticle.php?article_id=<?php echo $row_current["article_id"]; ?>" title=""> <h4><?php echo $row_current["name"];?></h4> <h4><?php echo $row_current["price"]." EURO";?></h4></a></span> </div> <?php } ?> </div> </div><!-- end blog-list --> </div><!-- end widget --> <div class="widget"> <h2 style="background: #1528E7; color:#fff">Das könnte Ihnen auch gefallen</h2> <div class="blog-list-widget"> <div class="list-group"> <?php $sqlstr_similar = "SELECT tblarticles.name, tblarticles.code, tblarticles.clothname, tblarticles.content, tblarticles.counter, tblarticles.price, tblarticles.pic, tblarticles.type, tblarticles.modified, tblarticles.article_id FROM tblarticle_subcategory JOIN tblarticles on tblarticles.article_id=tblarticle_subcategory.article_id AND tblarticles.activ='1' AND tblarticles.primacy='1' ORDER BY modified DESC LIMIT 3"; $res_similar = mysql_query($sqlstr_similar) or die ("no connection to the database ".mysql_error()); while ($row_similar = mysql_fetch_assoc($res_similar)) { ?> <div class="w-100 justify-content-between"> <?php if ($row_similar["type"] == "image") { ?> <img src="../admin/<?php echo $row_similar["pic"];?>" class="img-fluid img-responsive"> <?php } else if ($row_current["type"] == "video") { ?> <video src="../admin/<?php echo $row_similar["pic"];?>" type="video/mp4" class="img-fluid img-responsive" controls/></video> <?php } ?> <span class="color-orange"><h4><a href="labarticle.php?article_id=<?php echo $row_similar["article_id"]; ?>" title=""> <h4><?php echo $row_similar["name"];?></h4> <h4><?php echo $row_similar["price"]." EURO";?></h4></a></span> </div> <?php } ?> </div> </div><!-- end blog-list --> </div><!-- end widget --> <div class="widget"> <div class="banner-spot clearfix"> <div class="banner-img" <img src="upload/banner_03.jpg" alt="" class="img-fluid"> </div><!-- end banner-img --> </div><!-- end banner --> </div><!-- end widget --> </div><!-- end sidebar --> </div><!-- end col --> <div class="col-lg-9 col-md-9 col-sm-12 col-xs-12"> <div class="page-wrapper"> <div class="blog-grid-system"> <h2 style="text-align:center;">Wie fair ist mein Kleidungsstück?</h2> <div class="row"> <hr> <div class="panel panel-primary"> <div class="panel-heading"> <h3 class="panel-title" style="text-align:center;">Wie fair ist mein Kleidungsstück? </h3> </div> <div class="panel-body"> <form action="labproductfair.php" enctype="multipart/form-data" method = "post"> <div class="form-group"> <label class="control-label" for="inputBcode">Enter Barcode:</label> <input type="text" name="barcode" class="form-control" id="inputBcode" required> <div style="height: 15px;"></div> </div> <div class="form-group"> <button type="submit" name="send" class="btn btn-primary"> <span class="fa fa-search"></span> Search</button> </div> </form> </div> </div> <?php if(isset($_POST["send"])){ $sqlstr_article= "SELECT * FROM tblarticles WHERE code like '". $_POST["barcode"]."'"; $res_article = mysql_query($sqlstr_article) or die ("no connection to the database ".mysql_error()); $num_article = mysql_num_rows($res_article); $row_article = mysql_fetch_array( $res_article); $barcode_str=explode("-", $_POST["barcode"]); //$resut_teil=$row["woho"].$row["fapay"].$row["unions"].$row["health"].$row["secpro"].$row["envstand"]; $row__article_str=explode("-", $row_article["code"]); if($num_article<=0){ ?> <div class="bg-darkred fg-white w-100">No entry in the database!</div> <?php } else { ?> <div class="panel panel-info"> <div class="panel-heading"> <h3><?php echo $row_article["name"];?></h3> <h4><?php echo $row_article["code"];?></h4> </div> <div class="panel-body"> <?php if ($row_article["type"] == "image") { ?> <img src="../admin/<?php echo $row_article["pic"];?>" class="img-fluid img-responsive"> <?php } else if ($row_article["type"] == "video") { ?> <video src="../admin/<?php echo $row_article["pic"];?>" type="video/mp4" class="img-fluid img-responsive" controls/></video> <?php } ?> <hr /> <img src="../admin/<?php echo $row_article["picbarcode"];?>" class="img-fluid img-responsive"> </div> <div class="panel-footer"> <?php if($row__article_str[2][0]==1){ ?> <div class="checkbox" style="background-color: #00FF00;"> <label><input type="checkbox" value="Working Hours" disabled>Working Hours</label> </div> <?php } else { ?> <div class="checkbox" disabled style="background-color: #FF0000;"> <label><input type="checkbox" value="Working Hours" disabled>Working Hours</label> </div> <?php } if($row__article_str[2][1]==1){ ?> <div class="checkbox" style="background-color: #00FF00;"> <label><input type="checkbox" value="Fair Payment" disabled>Fair Payment</label> </div> <?php } else { ?> <div class="checkbox" disabled style="background-color: #FF0000;"> <label><input type="checkbox" value="Fair Payment" disabled>Fair Payment</label> </div> <?php } if($row__article_str[2][2]==1){ ?> <div class="checkbox" style="background-color: #00FF00;"> <label><input type="checkbox" value="Unions" disabled>Unions</label> </div> <?php } else { ?> <div class="checkbox" disabled style="background-color: #FF0000;"> <label><input type="checkbox" value="Unions" disabled>Unions</label> </div> <?php } if($row__article_str[2][3]==1){ ?> <div class="checkbox" style="background-color: #00FF00;"> <label><input type="checkbox" value="Unions" disabled>Health standard</label> </div> <?php } else { ?> <div class="checkbox" disabled style="background-color: #FF0000;"> <label><input type="checkbox" value="Health standard" disabled>Health standard</label> </div> <?php } if($row__article_str[2][4]==1){ ?> <div class="checkbox" style="background-color: #00FF00;"> <label><input type="checkbox" value="Security protetion" disabled>Security protetion</label> </div> <?php } else { ?> <div class="checkbox" disabled style="background-color: #FF0000;"> <label><input type="checkbox" value="Security protetion" disabled>Security protetion</label> </div> <?php } if($barcode_str[2][5]==1){ ?> <div class="checkbox" style="background-color: #00FF00;"> <label><input type="checkbox" value="Environmental standard" disabled>Environmental standard</label> </div> <?php } else { ?> <div class="checkbox" disabled style="background-color: #FF0000;"> <label><input type="checkbox" value="Environmental standard" disabled>Environmental standard</label> </div> <?php }?> </div> <?php $resut=$row__article_str[2][0]+$row__article_str[2][1]+$row__article_str[2][2]+ $row__article_str[2][3]+$row__article_str[2][4]+$row__article_str[2][5]; if($resut<3){ ?> <div class="panel-footer" style="background-color: #FF0000;"> <span>The producer does not pay attention to all rights!</span> </div> <?php } elseif($resut>=3 && $resut<=4){ ?> <div class="panel-footer" style="background-color: #FFFF00;"> <span>The producer pays attention to some rights!</span> </div> <?php } else { ?> <div class="panel-footer" style="background-color: #00FF00;"> <span>The producer pays attention to all rights!</span> </div> <?php } ?> </div> <?php } mysql_free_result($res); } ?> </div> </div><!-- end row --> </div><!-- end blog-grid-system --> </div><!-- end page-wrapper --> </div><!-- end col --> </div><!-- end row --> </div><!-- end container --> </section><!-- end section --> <?php include("labfooter.php"); ?>
10.6.5) labrecycling.php
Diese Datei befindet sich im Unterordner "shop" und wird eingesetzt, um das Kleidungsstück bei "Wie gut recyclebar ist mein Kleidungsstück?" zu finden und anzuzeigen.<?php session_start(); include ("labheader.php"); ?> <section class="section"> <div class="container"> <div class="row"> <div class="col-lg-3 col-md-3 col-sm-12 col-xs-12"> <div class="sidebar"> <!-- Bild 300x600 --> <!-- Recent Reviews --> <div class="widget"> <h2 style="background: #1528E7; color:#fff">Neu eingetroffen</h2> <div class="blog-list-widget"> <div class="list-group"> <?php $sqlstr_current = "SELECT * FROM tblarticles ORDER BY modified DESC LIMIT 3"; $res_current = mysql_query($sqlstr_current) or die ("no connection to the database ".mysql_error()); while ($row_current = mysql_fetch_assoc($res_current)) { ?> <div class="w-100 justify-content-between"> <?php if ($row_current["type"] == "image") { ?> <img src="../admin/<?php echo $row_current["pic"];?>" class="img-fluid img-responsive"> <?php } else if ($row_current["type"] == "video") { ?> <video src="../admin/<?php echo $row_current["pic"];?>" type="video/mp4" class="img-fluid img-responsive" controls/></video> <?php } ?> <span class="color-orange"><h4><a href="labarticle.php?article_id=<?php echo $row_current["article_id"]; ?>" title=""> <h4><?php echo $row_current["name"];?></h4> <h4><?php echo $row_current["price"]." EURO";?></h4></a></span> </div> <?php } ?> </div> </div><!-- end blog-list --> </div><!-- end widget --> <div class="widget"> <h2 style="background: #1528E7; color:#fff">Das könnte Ihnen auch gefallen</h2> <div class="blog-list-widget"> <div class="list-group"> <?php $sqlstr_similar = "SELECT tblarticles.name, tblarticles.code, tblarticles.clothname, tblarticles.content, tblarticles.counter, tblarticles.price, tblarticles.pic, tblarticles.type, tblarticles.modified, tblarticles.article_id FROM tblarticle_subcategory JOIN tblarticles on tblarticles.article_id=tblarticle_subcategory.article_id AND tblarticles.activ='1' AND tblarticles.primacy='1' ORDER BY modified DESC LIMIT 3"; $res_similar = mysql_query($sqlstr_similar) or die ("no connection to the database ".mysql_error()); while ($row_similar = mysql_fetch_assoc($res_similar)) { ?> <div class="w-100 justify-content-between"> <?php if ($row_similar["type"] == "image") { ?> <img src="../admin/<?php echo $row_similar["pic"];?>" class="img-fluid img-responsive"> <?php } else if ($row_current["type"] == "video") { ?> <video src="../admin/<?php echo $row_similar["pic"];?>" type="video/mp4" class="img-fluid img-responsive" controls/></video> <?php } ?> <span class="color-orange"><h4><a href="labarticle.php?article_id=<?php echo $row_similar["article_id"]; ?>" title=""> <h4><?php echo $row_similar["name"];?></h4> <h4><?php echo $row_similar["price"]." EURO";?></h4></a></span> </div> <?php } ?> </div> </div><!-- end blog-list --> </div><!-- end widget --> <div class="widget"> <div class="banner-spot clearfix"> <div class="banner-img" <img src="upload/banner_03.jpg" alt="" class="img-fluid"> </div><!-- end banner-img --> </div><!-- end banner --> </div><!-- end widget --> </div><!-- end sidebar --> </div><!-- end col --> <div class="col-lg-9 col-md-9 col-sm-12 col-xs-12"> <div class="page-wrapper"> <div class="blog-grid-system"> <h2 style="text-align:center;">Wie gut recyclebar ist mein Kleidungsstück?</h2> <div class="row"> <hr> <div class="panel panel-primary"> <div class="panel-heading"> <h3 class="panel-title" style="text-align:center;">Wie gut recyclebar ist mein Kleidungsstück? </h3> </div> <div class="panel-body"> <form action="labrecycling.php" enctype="multipart/form-data" method = "post"> <div class="form-group"> <label class="control-label" for="inputBcode">Enter Barcode:</label> <input type="text" name="barcode" class="form-control" id="inputBcode" required> <div style="height: 15px;"></div> </div> <div class="form-group"> <button type="submit" name="send" class="btn btn-primary"> <span class="fa fa-search"></span> Search</button> </div> </form> </div> </div> <?php if(isset($_POST["send"])){ $sqlstr_article= "SELECT * FROM tblarticles WHERE code like '". $_POST["barcode"]."'"; $res_article = mysql_query($sqlstr_article) or die ("no connection to the database ".mysql_error()); $num_article = mysql_num_rows($res_article); $row_article = mysql_fetch_array( $res_article); $barcode_str=explode("-", $_POST["barcode"]); //$resut_teil=$row["woho"].$row["fapay"].$row["unions"].$row["health"].$row["secpro"].$row["envstand"]; $row__article_str=explode("-", $row_article["code"]); if($num_article<=0){ ?> <div class="bg-darkred fg-white w-100">No entry in the database!</div> <?php } else { ?> <div class="panel panel-info"> <div class="panel-heading"> <h3><?php echo $row_article["name"];?></h3> <h4><?php echo $row_article["code"];?></h4> </div> <div class="panel-body"> <?php if ($row_article["type"] == "image") { ?> <img src="../admin/<?php echo $row_article["pic"];?>" class="img-fluid img-responsive"> <?php } else if ($row_article["type"] == "video") { ?> <video src="../admin/<?php echo $row_article["pic"];?>" type="video/mp4" class="img-fluid img-responsive" controls/></video> <?php } ?> <hr /> <img src="../admin/<?php echo $row_article["picbarcode"];?>" class="img-fluid img-responsive"> </div> <div class="panel-footer"> <?php if($row__article_str[4]=="XXA"){ ?> <div style="background-color: #00FF00;"> <span>Class A: by Dr. Katrin Prinz</span><br /> <span><b>Note:</b> Classes A=1, B=2 and C>=3 have components or fibers. </span> </div> <?php } elseif($row__article_str[4]=="XBX"){ ?> <div style="background-color: #FFFF00;"> <span>Class A: by Dr. Katrin Prinz</span><br /> <span><b>Note:</b> Classes A=1, B=2 and C>=3 have components or fibers. </span> </div> <?php } elseif($row__article_str[4]=="CXX"){ ?> <div style="background-color: #FF0000;"> <span>Class A: by Dr. Katrin Prinz</span><br /> <span><b>Note:</b> Classes A=1, B=2 and C>=3 have components or fibers. </span> </div> <?php } else { ?> <div class="bg-darkred fg-white w-100"> <span><b>This class is unknown!</b></span> </div> </div> <?php } ?> </div> <?php } mysql_free_result($res); } ?> </div> </div><!-- end row --> </div><!-- end blog-grid-system --> </div><!-- end page-wrapper --> </div><!-- end col --> </div><!-- end row --> </div><!-- end container --> </section><!-- end section --> <?php include("labfooter.php");?>
10.6.6) labstart.php
Diese Datei befindet sich im Unterordner "shop" und beinhaltet alle Artikel, die in der Tabelle "tblarticles" zur Verfügung stehen.<?php session_start(); include ("labheader.php"); ?> <section class="section"> <div class="container"> <div class="row"> <div class="col-lg-3 col-md-3 col-sm-12 col-xs-12"> <div class="sidebar"> <!-- Bild 300x600 --> <!-- Recent Reviews --> <div class="widget"> <h2 style="background: #1528E7; color:#fff">Neu eingetroffen</h2> <div class="blog-list-widget"> <div class="list-group"> <?php $sqlstr_current = "SELECT * FROM tblarticles ORDER BY modified DESC LIMIT 3"; $res_current = mysql_query($sqlstr_current) or die ("no connection to the database ".mysql_error()); while ($row_current = mysql_fetch_assoc($res_current)) { ?> <div class="w-100 justify-content-between"> <?php if ($row_current["type"] == "image") { ?> <img src="../admin/<?php echo $row_current["pic"];?>" class="img-fluid img-responsive"> <?php } else if ($row_current["type"] == "video") { ?> <video src="../admin/<?php echo $row_current["pic"];?>" type="video/mp4" class="img-fluid img-responsive" controls/></video> <?php } ?> <span class="color-orange"><h4><a href="labarticle.php?article_id=<?php echo $row_current["article_id"]; ?>" title=""> <h4><?php echo $row_current["name"];?></h4> <h4><?php echo $row_current["price"]." EURO";?></h4></a></span> </div> <?php } mysql_free_result($res_current); ?> </div> </div><!-- end blog-list --> </div><!-- end widget --> <div class="widget"> <h2 style="background: #1528E7; color:#fff">Das könnte Ihnen auch gefallen</h2> <div class="blog-list-widget"> <div class="list-group"> <?php $sqlstr_similar = "SELECT tblarticles.name, tblarticles.code, tblarticles.clothname, tblarticles.content, tblarticles.counter, tblarticles.price, tblarticles.pic, tblarticles.type, tblarticles.modified, tblarticles.article_id FROM tblarticle_subcategory JOIN tblarticles on tblarticles.article_id=tblarticle_subcategory.article_id AND tblarticles.activ='1' AND tblarticles.primacy='1' ORDER BY modified DESC LIMIT 3"; $res_similar = mysql_query($sqlstr_similar) or die ("no connection to the database ".mysql_error()); while ($row_similar = mysql_fetch_assoc($res_similar)) { ?> <div class="w-100 justify-content-between"> <?php if ($row_similar["type"] == "image") { ?> <img src="../admin/<?php echo $row_similar["pic"];?>" class="img-fluid img-responsive"> <?php } else if ($row_current["type"] == "video") { ?> <video src="../admin/<?php echo $row_similar["pic"];?>" type="video/mp4" class="img-fluid img-responsive" controls/></video> <?php } ?> <span class="color-orange"><h4><a href="labarticle.php?article_id=<?php echo $row_similar["article_id"]; ?>" title=""> <h4><?php echo $row_similar["name"];?></h4> <h4><?php echo $row_similar["price"]." EURO";?></h4></a></span> </div> <?php } mysql_free_result($res_similar); ?> </div> </div><!-- end blog-list --> </div><!-- end widget --> <div class="widget"> <div class="banner-spot clearfix"> <div class="banner-img" <img src="upload/banner_03.jpg" alt="" class="img-fluid"> </div><!-- end banner-img --> </div><!-- end banner --> </div><!-- end widget --> </div><!-- end sidebar --> </div><!-- end col --> <div class="col-lg-9 col-md-9 col-sm-12 col-xs-12"> <div class="page-wrapper"> <div class="blog-grid-system"> <h2 style="text-align:center;">Aktuelle Artikel</h2> <div class="row"> <?php $showRecordPerPage = 4; if(isset($_GET["page"]) && !empty($_GET["page"])){ $currentPage = $_GET["page"]; }else{ $currentPage = 1; } $startFrom = ($currentPage * $showRecordPerPage) - $showRecordPerPage; $sqlstr_page = "SELECT * FROM tblarticles"; $res_page = mysql_query($sqlstr_page) or die ("no connection to the database ".mysql_error()); $totalArticle = mysqli_num_rows($res_page); $lastPage = ceil($totalArticle/$showRecordPerPage); $firstPage = 1; $nextPage = $currentPage + 1; $previousPage = $currentPage - 1; $sqlstr_artcile = "SELECT tblarticles.name, tblarticles.code, tblarticles.clothname, tblarticles.content, tblarticles.counter, tblarticles.price, tblarticles.pic, tblarticles.type, tblarticles.article_id FROM tblarticle_subcategory JOIN tblarticles on tblarticles.article_id=tblarticle_subcategory.article_id AND tblarticles.activ='1' AND tblarticles.primacy='1' ORDER BY tblarticles.article_id ASC LIMIT $startFrom, $showRecordPerPage"; $res_article = mysql_query($sqlstr_artcile) or die ("no connection to the database ".mysql_error()); while ($row_article = mysql_fetch_assoc($res_article)) { ?> <div class="col-md-6"> <div class="blog-box"> <div class="post-media"><a href="labshowarticle.php?article_id=<?php echo $row_article["article_id"]; ?>" title=""> <?php if ($row_article["type"] == "image") { ?> <img src="../admin/<?php echo $row_article["pic"];?>" class="img-fluid img-responsive"> <?php } else if ($row_article["type"] == "video") { ?> <video src="../admin/<?php echo $row_article["pic"];?>" type="video/mp4" class="img-fluid img-responsive" controls/></video> <?php } ?> <div class="hovereffect"></div></a> </div> <div class="blog-meta big-meta"> <span class="color-orange"><h4><a href="labshowarticle.php?article_id=<?php echo $row_article["article_id"]; ?>" title=""> <?php echo $row_article["code"];?> <?php echo $row_article["name"];?><br /> <b><i><?php echo $row_article["price"]." EURO";?></i></b><br /> <?php echo $row_article["clothname"];?></h4></span></a> <h5><i class="fa fa-eye"></i><?php echo $row_article["counter"];?></h5> </div> </div> </div> <?php } mysql_free_result($res_article); ?> </div><!-- end row --> </div><!-- end blog-grid-system --> </div><!-- end page-wrapper --> <hr class="invis3"> <div class="row" style="display:flex;justify-content:center; padding:14px"> <ul class="pagination pagination-lg justify-content-center"> <?php if($currentPage != $firstPage) { ?> <li class="page-item"> <a class="page-link" href="labstart.php?page=<?php echo $firstPage ?>" tabindex="-1" aria-label="Previous"> <span aria-hidden="true">First</span> </a> </li> <?php } ?> <?php if($currentPage >= 2) { ?> <li class="page-item"><a class="page-link" href="labstart.php?page=<?php echo $previousPage; ?>"><?php echo $previousPage ?></a></li> <?php } ?> <li class="page-item active"><a class="page-link" href="labstart.php?page=<?php echo $currentPage; ?>"><?php echo $currentPage ?></a></li> <?php if($currentPage != $lastPage) { ?> <li class="page-item"><a class="page-link" href="labstart.php?page=<?php echo $nextPage; ?>"><?php echo $nextPage ?></a></li> <li class="page-item"><a class="page-link" href="labstart.php?page=<?php echo $lastPage; ?>" aria-label="Next"> <span aria-hidden="true">last</a></span> </li> <?php } ?> </ul> </div> <?php mysql_free_result($res_page); ?> </div><!-- end col --> </div><!-- end row --> </div><!-- end container --> </section><!-- end section --> <?php include("labfooter.php");?>
10.6.7) labarticle.php
Diese Datei befindet sich im Unterordner "shop". Nach der Auswahl einer Unterkategorie werden alle Artikel, die dazu gehören, auf der Besucherseite angezeigt.<?php session_start(); include("labheader.php"); if(!$_SESSION["items"]) $_SESSION["items"] = "0"; if(!$_SESSION["totalprice"]) $_SESSION["totalprice"] = "0.00"; if(isset($_POST["article_id"])){ $article_id = $_POST["article_id"]; }elseif(!isset($_GET["article_id"]) ||$_GET["article_id"]==NULL ){ header("Location:labshowarticle.php"); }else{ $article_id=$_GET["article_id"]; } $subcat_id=$_GET["subcat_id"]; if ($subcat_id<=0 ) { $subcat_id=2; } $_SESSION["subcat_id"]=$subcat_id; ?> <section class="section"> <div class="container"> <div class="row"> <div class="col-lg-3 col-md-3 col-sm-12 col-xs-12"> <div class="sidebar"> <!-- Bild 300x600 --> <!-- Recent Reviews --> <div class="widget"> <h2 style="background: #1528E7; color:#fff">Neu eingetroffen</h2> <div class="blog-list-widget"> <div class="list-group"> <?php $sqlstr_current = "SELECT tblarticles.name, tblarticles.code, tblarticles.clothname, tblarticles.content, tblarticles.counter, tblarticles.price, tblarticles.pic, tblarticles.type, tblarticles.modified, tblarticles.article_id FROM tblarticle_subcategory JOIN tblarticles on tblarticles.article_id=tblarticle_subcategory.article_id AND tblarticle_subcategory.subcat_id='$subcat_id' AND tblarticles.activ='1' AND tblarticles.primacy='1' ORDER BY modified DESC LIMIT 3"; $res_current = mysql_query($sqlstr_current) or die ("no connection to the database ".mysql_error()); while ($row_current = mysql_fetch_assoc($res_current)) { ?> <div class="w-100 justify-content-between"> <?php if ($row_current["type"] == "image") { ?> <img src="../admin/<?php echo $row_current["pic"];?>" class="img-fluid img-responsive"> <?php } else if ($row_current["type"] == "video") { ?> <video src="../admin/<?php echo $row_current["pic"];?>" type="video/mp4" class="img-fluid img-responsive" controls/></video> <?php } ?> <span class="color-orange"><h4><a href="labshowarticle.php?article_id=<?php echo $row_current["article_id"]; ?>" title=""> <h4><?php echo $row_current["name"];?></h4> <h4><?php echo $row_current["price"]." EURO";?></h4></a></span> </div> <?php } mysql_free_result($res_current); ?> </div> </div><!-- end blog-list --> </div><!-- end widget --> <div class="widget"> <h2 style="background: #1528E7; color:#fff">Das könnte Ihnen auch gefallen</h2> <div class="blog-list-widget"> <div class="list-group"> <?php $sqlstr_similar = "SELECT tblarticles.name, tblarticles.code, tblarticles.clothname, tblarticles.content, tblarticles.counter, tblarticles.price, tblarticles.pic, tblarticles.type, tblarticles.modified, tblarticles.article_id FROM tblarticle_subcategory JOIN tblarticles on tblarticles.article_id=tblarticle_subcategory.article_id AND tblarticle_subcategory.subcat_id='$subcat_id' AND tblarticles.activ='1' AND tblarticles.primacy='1' ORDER BY counter DESC LIMIT 3"; $res_similar = mysql_query($sqlstr_similar) or die ("no connection to the database ".mysql_error()); while ($row_similar = mysql_fetch_assoc($res_similar)) { ?> <div class="w-100 justify-content-between"> <?php if ($row_similar["type"] == "image") { ?> <img src="../admin/<?php echo $row_similar["pic"];?>" class="img-fluid img-responsive"> <?php } else if ($row_current["type"] == "video") { ?> <video src="../admin/<?php echo $row_similar["pic"];?>" type="video/mp4" class="img-fluid img-responsive" controls/></video> <?php } ?> <span class="color-orange"><h4><a href="labshowarticle.php?article_id=<?php echo $row_similar["article_id"]; ?>" title=""> <h4><?php echo $row_similar["name"];?></h4> <h4><?php echo $row_similar["price"]." EURO";?></h4></a></span> </div> <?php } mysql_free_result($res_similar); ?> </div> </div><!-- end blog-list --> </div><!-- end widget --> <div class="widget"> <div class="banner-spot clearfix"> <div class="banner-img" <img src="upload/banner_03.jpg" alt="" class="img-fluid"> </div><!-- end banner-img --> </div><!-- end banner --> </div><!-- end widget --> </div><!-- end sidebar --> </div><!-- end col --> <?php $sqlstr_artcile = "SELECT tblarticles.name, tblarticles.code, tblarticles.clothname, tblarticles.content, tblarticles.counter, tblarticles.price, tblarticles.pic, tblarticles.type, tblarticles.article_id FROM tblarticle_subcategory JOIN tblarticles on tblarticles.article_id=tblarticle_subcategory.article_id and tblarticle_subcategory.subcat_id=$subcat_id AND tblarticles.activ='1' AND tblarticles.primacy='1' ORDER BY tblarticles.article_id"; $res_article = mysql_query($sqlstr_artcile) or die ("no connection to the database ".mysql_error()); $num_article = mysql_num_rows($res_article); $sqlstr_subcat = "SELECT * FROM tblsubcategories WHERE subcat_id=$subcat_id"; $res_subcat = mysql_query($sqlstr_subcat) or die ("no connection to the database ".mysql_error()); while ($row_subcat = mysql_fetch_assoc($res_subcat)) { $subcatname= $row_subcat["name"]; } if($num_article >0){ ?> <div class="col-lg-9 col-md-9 col-sm-12 col-xs-12"> <div class="page-wrapper"> <div class="blog-grid-system"> <h2 style="text-align:center;"><?php echo "<b>Untergategorie-> </b>".$subcatname;?></h2> <div class="row"> <?php while ($row_article = mysql_fetch_assoc($res_article)) { ?> <div class="col-md-6"><div class="blog-box"> <div class="post-media"><a href="labshowarticle.php?article_id=<?php echo $row_article["article_id"]; ?>" title=""> <?php if ($row_article["type"] == "image") { ?> <img src="../admin/<?php echo $row_article["pic"];?>" class="img-fluid img-responsive"> <?php } else if ($row_article["type"] == "video") { ?> <video src="../admin/<?php echo $row_article["pic"];?>" type="video/mp4" class="img-fluid img-responsive" controls/></video> <?php } ?> <div class="hovereffect"></div></a></div> <div class="blog-meta big-meta"> <span class="color-orange"><h4><a href="labshowarticle.php?article_id=<?php echo $row_article["article_id"]; ?>" title=""> <?php echo $row_article["code"];?></h4> <h4><?php echo $row_article["name"];?></h4> <h4><?php echo $row_article["price"]." EURO";?></h4> <h4><?php echo $row_article["clothname"];?><h4> <h5><i class="fa fa-eye"></i><?php echo $row_article["counter"];?></h5></a></span> </div> </div> </div> <?php } mysql_free_result($res_article); ?> </div><!-- end row --> </div><!-- end blog-grid-system --> </div><!-- end page-wrapper --> </div><!-- end col --> <?php } else { ?> <div class="col-lg-9 col-md-9 col-sm-12 col-xs-12"> <div class="page-wrapper"> <div class="blog-grid-system"> <h2 style="text-align:center;"><?php echo "Für die gewählte Unterkategorie <b>".$subcatname."</b> existiert kein Artikel!";?></h2> <div class="row"> </div><!-- end row --> </div><!-- end blog-grid-system --> </div><!-- end page-wrapper --> </div><!-- end col --> <?php } mysql_free_result($res_subcat); mysql_free_result($res_article); ?> </div><!-- end row --> </div><!-- end container --> </section><!-- end section --> <?php include("labfooter.php"); ?>
10.6.8) labshowarticle.php
Diese Datei befindet sich im Unterordner "shop". Nach einer Auswahl eines Artikels wird er detailliert angezeigt. Somit kann der Besucher ins Warenkorb eintragen.<?php session_start(); include("labheader.php"); if(isset($_POST["article_id"])){ $article_id = $_POST["article_id"]; }elseif(!isset($_GET["article_id"]) ||$_GET["article_id"]==NULL ){ header("Location:labshowarticle.php"); }else{ $article_id=$_GET["article_id"]; } $subcat_id=$_SESSION["subcat_id"]; $sqlstr_counter = "UPDATE tblarticles SET tblarticles.counter = tblarticles.counter + 1 WHERE tblarticles.article_id=$article_id"; $res_counter = mysql_query($sqlstr_counter) or die ("no connection to the database ".mysql_error()); $num_counter = mysql_affected_rows(); if ($num_counter<0) {?> <div id="page-wrapper"><div class="container-fluid"> <div class="bg-darkred fg-white"> This selected article was not accepted! </div> </div></div> <?php } mysql_free_result($res_counter); ?> <section class="section"> <div class="container"> <div class="row"> <div class="col-lg-3 col-md-3 col-sm-12 col-xs-12"> <div class="sidebar"> <!-- Bild 300x600 --> <!-- Recent Reviews --> <div class="widget"> <h2 style="background: #1528E7; color:#fff">Neu eingetroffen</h2> <div class="blog-list-widget"> <div class="list-group"> <?php $sqlstr_current = "SELECT tblarticles.name, tblarticles.code, tblarticles.clothname, tblarticles.content, tblarticles.counter, tblarticles.price, tblarticles.pic, tblarticles.type, tblarticles.modified, tblarticles.article_id FROM tblarticle_subcategory JOIN tblarticles on tblarticles.article_id=tblarticle_subcategory.article_id AND tblarticle_subcategory.subcat_id='$subcat_id' AND tblarticles.activ='1' AND tblarticles.primacy='1' ORDER BY modified DESC LIMIT 3"; $res_current = mysql_query($sqlstr_current) or die ("no connection to the database ".mysql_error()); while ($row_current = mysql_fetch_assoc($res_current)) { ?> <div class="w-100 justify-content-between"> <?php if ($row_current["type"] == "image") { ?> <img src="../admin/<?php echo $row_current["pic"];?>" class="img-fluid img-responsive"> <?php } else if ($row_current["type"] == "video") { ?> <video src="../admin/<?php echo $row_current["pic"];?>" type="video/mp4" class="img-fluid img-responsive" controls/></video> <?php } ?> <span class="color-orange"><h4><a href="labshowarticle.php?article_id=<?php echo $row_current["article_id"]; ?>" title=""> <h4><?php echo $row_current["name"];?></h4> <h4><?php echo $row_current["price"]." EURO";?></h4></a></span> </div> <?php mysql_free_result($res_current); } ?> </div> </div><!-- end blog-list --> </div><!-- end widget --> <div class="widget"> <h2 style="background: #1528E7; color:#fff">Das könnte Ihnen auch gefallen</h2> <div class="blog-list-widget"> <div class="list-group"> <?php $sqlstr_similar = "SELECT tblarticles.name, tblarticles.code, tblarticles.clothname, tblarticles.content, tblarticles.counter, tblarticles.price, tblarticles.pic, tblarticles.type, tblarticles.modified, tblarticles.article_id FROM tblarticle_subcategory JOIN tblarticles on tblarticles.article_id=tblarticle_subcategory.article_id AND tblarticle_subcategory.subcat_id='$subcat_id' AND tblarticles.activ='1' AND tblarticles.primacy='1' ORDER BY counter DESC LIMIT 3"; $res_similar = mysql_query($sqlstr_similar) or die ("no connection to the database ".mysql_error()); while ($row_similar = mysql_fetch_assoc($res_similar)) { ?> <div class="w-100 justify-content-between"> <?php if ($row_similar["type"] == "image") { ?> <img src="../admin/<?php echo $row_similar["pic"];?>" class="img-fluid img-responsive"> <?php } else if ($row_current["type"] == "video") { ?> <video src="../admin/<?php echo $row_similar["pic"];?>" type="video/mp4" class="img-fluid img-responsive" controls/></video> <?php } ?> <span class="color-orange"><h4><a href="labshowarticle.php?article_id=<?php echo $row_similar["article_id"]; ?>" title=""> <h4><?php echo $row_similar["name"];?></h4> <h4><?php echo $row_similar["price"]." EURO";?></h4></a></span> </div> <?php } mysql_free_result($res_similar); ?> </div> </div><!-- end blog-list --> </div><!-- end widget --> <div class="widget"> <div class="banner-spot clearfix"> <div class="banner-img" <img src="upload/banner_03.jpg" alt="" class="img-fluid"> </div><!-- end banner-img --> </div><!-- end banner --> </div><!-- end widget --> </div><!-- end sidebar --> </div><!-- end col --> <div class="col-lg-9 col-md-9 col-sm-12 col-xs-12"> <?php $sqlstr_artcile = "SELECT * FROM tblarticles WHERE article_id=$article_id"; $res_article = mysql_query($sqlstr_artcile) or die ("no connection to the database ".mysql_error()); while ($row_article = mysql_fetch_assoc($res_article)) { ?> <div class="panel panel-info"> <div class="panel-heading"> <h3><b>Name: </b><?php echo $row_article["name"];?></h3> <h3><b>Code: </b><?php echo $row_article["code"];?></h3> <h3><b>Preis: </b><?php echo number_format($row_article["price"],2,",",".")." EURO";?></h3> </div> <div class="panel-body"> <?php if ($row_article["type"] == "image") { ?> <img src="../admin/<?php echo $row_article["pic"];?>" class="img-fluid img-responsive"> <?php } else if ($row_article["type"] == "video") { ?> <video src="../admin/<?php echo $row_article["pic"];?>" type="video/mp4" class="img-fluid img-responsive" controls/></video> <?php } ?> </div> <div class="panel-footer bg-info text-primary"> <h4><a href="labshowcart.php?new=<?php echo $article_id;?>" class="button"><span class="fa fa-shopping-cart"></span>add shopping</a> <a href="labcheckout.php" class="button"><span class="fa fa-paypal"></span>Continue to pay</a></h4> </div> </div> <?php } mysql_free_result($res_article); ?> </div><!-- end col --> </div><!-- end row --> </div><!-- end container --> </section><!-- end section --> <?php include("labfooter.php"); ?>
10.6.9) labshowcart.php
Diese Datei befindet sich im Unterordner "shop". Nach einer Auswahl eines Artikels (siehe den Abschnitt 10.6.8) und dem Klick auf der Schaltfläche "shopping add" wird diese Datei ausgeführt und alle Artikel im Warenkorb werden dann angezeigt.<?php session_start(); include("labheader.php"); if(isset($_POST["article_id"])){ $article_id = $_POST["article_id"]; }elseif(!isset($_GET["article_id"]) ||$_GET["article_id"]==NULL ){ header("Location:labshowarticle.php"); }else{ $article_id=$_GET["article_id"]; } $subcat_id=$_SESSION["subcat_id"]; @ $new = $_GET["new"]; if ($new) { // new article has been selected if (!isset($_SESSION["cart"])) { $_SESSION["cart"] = array(); $_SESSION["items"] = 0; $_SESSION["totalprice"] = "0.00"; } if (isset($_SESSION["cart"][$new])) $_SESSION["cart"][$new]++; else $_SESSION["cart"][$new] = 1; $_SESSION["totalprice"] = calculate_price($_SESSION["cart"]); $_SESSION["items"] = calculate_items($_SESSION["cart"]); } if (isset($_POST["save"])) { foreach ($_SESSION["cart"] as $nummer => $qty) { if ($_POST[$nummer] == "0") unset($_SESSION["cart"][$nummer]); else $_SESSION["cart"][$nummer] = $_POST[$nummer]; } $_SESSION["totalprice"] = calculate_price($_SESSION["cart"]); $_SESSION["items"] = calculate_items($_SESSION["cart"]); } ?> <section class="section"> <div class="container"> <div class="row"> <div class="col-lg-3 col-md-3 col-sm-12 col-xs-12"> <div class="sidebar"> <!-- Bild 300x600 --> <!-- Recent Reviews --> <div class="widget"> <h2 style="background: #1528E7; color:#fff">Neu im Warenkorb</h2> <div class="blog-list-widget"> <div class="list-group"> <?php $sqlstr_current = "SELECT tblarticles.name, tblarticles.code, tblarticles.clothname, tblarticles.content, tblarticles.counter, tblarticles.price, tblarticles.pic, tblarticles.type, tblarticles.modified, tblarticles.article_id FROM tblarticle_subcategory JOIN tblarticles on tblarticles.article_id=tblarticle_subcategory.article_id AND tblarticle_subcategory.subcat_id='$subcat_id' AND tblarticles.activ='1' AND tblarticles.primacy='1' ORDER BY modified DESC LIMIT 3"; $res_current = mysql_query($sqlstr_current) or die ("no connection to the database ".mysql_error()); while ($row_current = mysql_fetch_assoc($res_current)) { ?> <div class="w-100 justify-content-between"> <?php if ($row_current["type"] == "image") { ?> <img src="../admin/<?php echo $row_current["pic"];?>" class="img-fluid img-responsive"> <?php } else if ($row_current["type"] == "video") { ?> <video src="../admin/<?php echo $row_current["pic"];?>" type="video/mp4" class="img-fluid img-responsive" controls/></video> <?php } ?> <span class="color-orange"><h4><a href="labshowarticle.php?article_id=<?php echo $row_current["article_id"]; ?>" title=""> <h4><?php echo $row_current["name"];?></h4> <h4><?php echo $row_current["price"]." EURO";?></h4></a></span> </div> <?php mysql_free_result($res_current); } ?> </div> </div><!-- end blog-list --> </div><!-- end widget --> <div class="widget"> <h2 style="background: #1528E7; color:#fff">Das könnte Ihnen auch gefallen</h2> <div class="blog-list-widget"> <div class="list-group"> <?php $sqlstr_similar = "SELECT tblarticles.name, tblarticles.code, tblarticles.clothname, tblarticles.content, tblarticles.counter, tblarticles.price, tblarticles.pic, tblarticles.type, tblarticles.modified, tblarticles.article_id FROM tblarticle_subcategory JOIN tblarticles on tblarticles.article_id=tblarticle_subcategory.article_id AND tblarticle_subcategory.subcat_id='$subcat_id' AND tblarticles.activ='1' AND tblarticles.primacy='1' ORDER BY counter DESC LIMIT 3"; $res_similar = mysql_query($sqlstr_similar) or die ("no connection to the database ".mysql_error()); while ($row_similar = mysql_fetch_assoc($res_similar)) { ?> <div class="w-100 justify-content-between"> <?php if ($row_similar["type"] == "image") { ?> <img src="../admin/<?php echo $row_similar["pic"];?>" class="img-fluid img-responsive"> <?php } else if ($row_current["type"] == "video") { ?> <video src="../admin/<?php echo $row_similar["pic"];?>" type="video/mp4" class="img-fluid img-responsive" controls/></video> <?php } ?> <span class="color-orange"><h4><a href="labshowarticle.php?article_id=<?php echo $row_similar["article_id"]; ?>" title=""> <h4><?php echo $row_similar["name"];?></h4> <h4><?php echo $row_similar["price"]." EURO";?></h4></a></span> </div> <?php } mysql_free_result($res_similar); ?> </div> </div><!-- end blog-list --> </div><!-- end widget --> <div class="widget"> <div class="banner-spot clearfix"> <div class="banner-img" <img src="upload/banner_03.jpg" alt="" class="img-fluid"> </div><!-- end banner-img --> </div><!-- end banner --> </div><!-- end widget --> </div><!-- end sidebar --> </div><!-- end col --> <div class="col-lg-9 col-md-9 col-sm-12 col-xs-12"> <?php if ($_SESSION["cart"] && array_count_values($_SESSION["cart"])) display_cart($_SESSION["cart"]); else {?> <div id="page-wrapper"><div class="container-fluid"> <div class="bg-darkred fg-white"> This selected article was not accepted! </div> </div></div> <?php } if ($new) { $details = get_articlesdetails($new); if ($details["subcat_id"]) $url = "labarticle.php?subcat_id=" . $details["subcat_id"]; } ?> </div><!-- end col --> </div><!-- end row --> </div><!-- end container --> </section><!-- end section --> <?php function display_cart($cart, $change = TRUE) {?> <div class="col-md-12 col-lg-12 col-sm-12 col-xs-12"> <div class="table-responsive"><table class="table table-bordered"> <form method="post" enctype="multipart/form-data" action="labshowcart.php"> <thead> <tr><th>Pos.</th><th>Name</th><th>Beschreibung</th><th>Preis</th> <th>Anzahl</th><th>Gesamt</th></tr> </thead> <tbody> <?php $i=0; foreach ($cart as $article_id => $qty) { $i=$i+1; $article = get_articlesdetails($article_id); ?> <tr><td><?php echo $i; ?> </td> <?php $articleurl = "labshowarticle.php?article_id=" . $article_id; echo "<td><a href = $articleurl>" . $article["name"] . "</a></td>"; echo "<td>content" . $article["content"]. "</td>"; echo "<td>" . number_format($article["price"], 2)."</td>"; // If we allow changes, sets are in text boxes if ($change == TRUE) echo "<td><input type='text' name=$article_id value=$qty size=3></td>"; else echo $qty; echo "<td align='center'>" . number_format($article["price"] * $qty, 2) . "</td>"; ?> </tr> <?php } ?> <!-- Show line with total --> </tbody> <thead> <tr> <th colspan = "<?php echo (4 + $images); ?>"></th> <th><?php echo $_SESSION["items"]; ?></th> <th><?php echo number_format($_SESSION["totalprice"], 2); ?></th> </tr> </thead> <!--save changes Button --> <?php if ($change == TRUE) { ?> <tr> <td colspan = "<?php echo (4 + $images); ?>"></td> <td> <input type = "hidden" name = "save" value = true> <button type="image" name="save Changes" class="btn btn-primary"> <span class="fa fa-save "></span> Änderung speichern</button> </td> <td></td> </tr> <?php } ?> <a href="labarticle.php?subcat_id=<?php echo $subcat_id; ?>" class="button"> <span class="fa fa-shopping-cart"></span> add shopping</a> <a href="labcheckout.php" class="button"><span class="fa fa-paypal"></span> Continue to pay</a> </form> </table> </div> </div> <?php } function get_articles($subcat_id) { // Query database for the articles of a category if (!$subcat_id || $subcat_id == "") return FALSE; $sqlstr = "select * from tblarticles where subcat_id='$subcat_id'"; $res = mysql_query($sqlstr) or die ("no connection to the database ".mysql_error()); $num = mysql_num_rows($res); if ($num == 0) return FALSE; for ($count = 0; $row=mysql_fetch_assoc($res); $count++) $res_array[$count] = $row; return $res_array; } function calculate_price($cart) { // Calculate the total price for all items in the shopping cart $price = 0.0; if (is_array($cart)) { $conn = db_connect(); foreach($cart as $article_id => $qty) { $sqlstr = "select price from tblarticles where article_id='$article_id'"; $res = $conn->query($sqlstr); if ($res) { $item = $res->fetch_object(); $item_price = $item->price; $price += $item_price * $qty; } } } return $price; } function calculate_items($cart) { // Calculate the number of items in your cart $items = 0; if (is_array($cart)) { foreach($cart as $article_id => $qty) { $items += $qty; } } return $items; } function get_articlesdetails($article_id) { if (!$article_id || $article_id == "") return FALSE; $conn = db_connect(); $sqlstr = "select * from tblarticles where article_id='$article_id'"; $res = @$conn->query($sqlstr); if (!$res) return FALSE; $res = @$res->fetch_assoc(); return $res; } ?> <?php include("labfooter.php"); ?>
10.6.10) labcheckout.php
Diese Datei befindet sich im Unterordner "shop". Wenn der Besucher auf die Schaltfläche "Continue to pay" (siehe den Abschnitt 10.6.9)klickt, wird diese Datei ausgeführt. Der Besucher kann seine Kontaktdaten für den Einkauf von ausgewählten Artikeln (sogenannten Bestellung) eingeben<?php session_start(); include("labheader.php"); if(isset($_POST["article_id"])){ $article_id = $_POST["article_id"]; }elseif(!isset($_GET["article_id"]) ||$_GET["article_id"]==NULL ){ header("Location:labshowarticle.php"); }else{ $article_id=$_GET["article_id"]; } $subcat_id=$_SESSION["subcat_id"]; @ $new = $_GET["new"]; if ($new) { // new article has been selected if (!isset($_SESSION["cart"])) { $_SESSION["cart"] = array(); $_SESSION["items"] = 0; $_SESSION["totalprice"] = "0.00"; } if (isset($_SESSION["cart"][$new])) $_SESSION["cart"][$new]++; else $_SESSION["cart"][$new] = 1; $_SESSION["totalprice"] = calculate_price($_SESSION["cart"]); $_SESSION["items"] = calculate_items($_SESSION["cart"]); } if (isset($_POST["save"])) { foreach ($_SESSION["cart"] as $nummer => $qty) { if ($_POST[$nummer] == "0") unset($_SESSION["cart"][$nummer]); else $_SESSION["cart"][$nummer] = $_POST[$nummer]; } $_SESSION["totalprice"] = calculate_price($_SESSION["cart"]); $_SESSION["items"] = calculate_items($_SESSION["cart"]); } ?> <section class="section"> <div class="container"> <div class="row"> <div class="col-lg-3 col-md-3 col-sm-12 col-xs-12"> <div class="sidebar"> <!-- Bild 300x600 --> <!-- Recent Reviews --> <div class="widget"> <h2 style="background: #1528E7; color:#fff">Neu im Warenkorb</h2> <div class="blog-list-widget"> <div class="list-group"> <?php $sqlstr_current = "SELECT tblarticles.name, tblarticles.code, tblarticles.clothname, tblarticles.content, tblarticles.counter, tblarticles.price, tblarticles.pic, tblarticles.type, tblarticles.modified, tblarticles.article_id FROM tblarticle_subcategory JOIN tblarticles on tblarticles.article_id=tblarticle_subcategory.article_id AND tblarticle_subcategory.subcat_id='$subcat_id' AND tblarticles.activ='1' AND tblarticles.primacy='1' ORDER BY modified DESC LIMIT 3"; $res_current = mysql_query($sqlstr_current) or die ("no connection to the database ".mysql_error()); while ($row_current = mysql_fetch_assoc($res_current)) { ?> <div class="w-100 justify-content-between"> <?php if ($row_current["type"] == "image") { ?> <img src="../admin/<?php echo $row_current["pic"];?>" class="img-fluid img-responsive"> <?php } else if ($row_current["type"] == "video") { ?> <video src="../admin/<?php echo $row_current["pic"];?>" type="video/mp4" class="img-fluid img-responsive" controls/></video> <?php } ?> <span class="color-orange"><h4><a href="labshowarticle.php?article_id=<?php echo $row_current["article_id"]; ?>" title=""> <h4><?php echo $row_current["name"];?></h4> <h4><?php echo $row_current["price"]." EURO";?></h4></a></span> </div> <?php mysql_free_result($res_current); } ?> </div> </div><!-- end blog-list --> </div><!-- end widget --> <div class="widget"> <h2 style="background: #1528E7; color:#fff">Das könnte Ihnen auch gefallen</h2> <div class="blog-list-widget"> <div class="list-group"> <?php $sqlstr_similar = "SELECT tblarticles.name, tblarticles.code, tblarticles.clothname, tblarticles.content, tblarticles.counter, tblarticles.price, tblarticles.pic, tblarticles.type, tblarticles.modified, tblarticles.article_id FROM tblarticle_subcategory JOIN tblarticles on tblarticles.article_id=tblarticle_subcategory.article_id AND tblarticle_subcategory.subcat_id='$subcat_id' AND tblarticles.activ='1' AND tblarticles.primacy='1' ORDER BY counter DESC LIMIT 3"; $res_similar = mysql_query($sqlstr_similar) or die ("no connection to the database ".mysql_error()); while ($row_similar = mysql_fetch_assoc($res_similar)) { ?> <div class="w-100 justify-content-between"> <?php if ($row_similar["type"] == "image") { ?> <img src="../admin/<?php echo $row_similar["pic"];?>" class="img-fluid img-responsive"> <?php } else if ($row_current["type"] == "video") { ?> <video src="../admin/<?php echo $row_similar["pic"];?>" type="video/mp4" class="img-fluid img-responsive" controls/></video> <?php } ?> <span class="color-orange"><h4><a href="labshowarticle.php?article_id=<?php echo $row_similar["article_id"]; ?>" title=""> <h4><?php echo $row_similar["name"];?></h4> <h4><?php echo $row_similar["price"]." EURO";?></h4></a></span> </div> <?php } mysql_free_result($res_similar); ?> </div> </div><!-- end blog-list --> </div><!-- end widget --> <div class="widget"> <div class="banner-spot clearfix"> <div class="banner-img" <img src="upload/banner_03.jpg" alt="" class="img-fluid"> </div><!-- end banner-img --> </div><!-- end banner --> </div><!-- end widget --> </div><!-- end sidebar --> </div><!-- end col --> <div class="col-lg-9 col-md-9 col-sm-12 col-xs-12"> <?php if ($_SESSION["cart"] && array_count_values($_SESSION["cart"])){ display_checkout_form(); display_cart($_SESSION["cart"]); } else { ?> <div id="page-wrapper"><div class="container-fluid"> <div class="bg-darkred fg-white"> eYou have no items in your shopping cart </div> </div></div> <?php } if ($new) { $details = get_articlesdetails($new); if ($details["subcat_id"]) $url = "labarticle.php?subcat_id=" . $details["subcat_id"]; } ?> </div><!-- end col --> </div><!-- end row --> </div><!-- end container --> </section><!-- end section --> <?php function display_cart($cart, $change = TRUE) {?> <div class="col-md-12 col-lg-12 col-sm-12 col-xs-12"> <div class="table-responsive"><table class="table table-bordered"> <form method="post" enctype="multipart/form-data" action="labshowcart.php"> <thead> <tr><th>Pos.</th><th>Name</th><th>Beschreibung</th><th>Preis</th> <th>Anzahl</th><th>Gesamt</th></tr> </thead> <tbody> <?php $i=0; foreach ($cart as $article_id => $qty) { $i=$i+1; $article = get_articlesdetails($article_id); ?> <tr><td><?php echo $i; ?> </td> <?php $articleurl = "labshowarticle.php?article_id=" . $article_id; echo "<td><a href = $articleurl>" . $article["name"] . "</a></td>"; echo "<td>content" . $article["content"]. "</td>"; echo "<td>" . number_format($article["price"], 2)."</td>"; // If we allow changes, sets are in text boxes if ($change == TRUE) echo "<td><input type='text' name=$article_id value=$qty size=3></td>"; else echo $qty; echo "<td align='center'>" . number_format($article["price"] * $qty, 2) . "</td>"; ?> </tr> <?php } ?> <!-- Show line with total --> </tbody> <thead> <tr> <th colspan = "<?php echo (4 + $images); ?>"></th> <th><?php echo $_SESSION["items"]; ?></th> <th><?php echo number_format($_SESSION["totalprice"], 2); ?></th> </tr> </thead> <!--save changes Button --> <?php if ($change == TRUE) { ?> <tr> <td colspan = "<?php echo (4 + $images); ?>"></td> <td> <input type = "hidden" name = "save" value = true> <button type="image" name="save Changes" class="btn btn-primary"> <span class="fa fa-save "></span> Änderung speichern</button> </td> <td></td> </tr> <?php } ?> <a href="labarticle.php?subcat_id=<?php echo $subcat_id; ?>" class="button"> <span class="fa fa-shopping-cart"></span> add shopping</a> <a href="labcheckout.php" class="button"><span class="fa fa-paypal"></span> Continue to pay</a> </form> </table> </div> </div> <?php } function get_articles($subcat_id) { // Query database for the articles of a category if (!$subcat_id || $subcat_id == "") return FALSE; $sqlstr = "select * from tblarticles where subcat_id='$subcat_id'"; $res = mysql_query($sqlstr) or die ("no connection to the database ".mysql_error()); $num = mysql_num_rows($res); if ($num == 0) return FALSE; for ($count = 0; $row=mysql_fetch_assoc($res); $count++) $res_array[$count] = $row; return $res_array; } function calculate_price($cart) { // Calculate the total price for all items in the shopping cart $price = 0.0; if (is_array($cart)) { $conn = db_connect(); foreach($cart as $article_id => $qty) { $sqlstr = "select price from tblarticles where article_id='$article_id'"; $res = $conn->query($sqlstr); if ($res) { $item = $res->fetch_object(); $item_price = $item->price; $price += $item_price * $qty; } } } return $price; } function calculate_items($cart) { // Calculate the number of items in your cart $items = 0; if (is_array($cart)) { foreach($cart as $article_id => $qty) { $items += $qty; } } return $items; } function get_articlesdetails($article_id) { if (!$article_id || $article_id == "") return FALSE; $conn = db_connect(); $sqlstr = "select * from tblarticles where article_id='$article_id'"; $res = @$conn->query($sqlstr); if (!$res) return FALSE; $res = @$res->fetch_assoc(); return $res; } function display_checkout_form() { ?> <div class="col-md-12 col-lg-12 col-sm-12 col-xs-12"> <div class="table-responsive"><table class="table table-bordered"> <form method="post" enctype="multipart/form-data" action="labpurchase.php"> <div class="form-group"> <label class="control-label" for="inputName">Name:</label> <input type="text" name="name" class="form-control" id="inputName" placeholder="Enter Customer name"> </div> <div class="form-group"> <label class="control-label" for="inputPrename">Prename:</label> <input type="text" name="prename" class="form-control" id="inputPrename" placeholder="Enter Prename"> </div> <div class="form-group"> <label class="control-label" for="inputAddress">Address:</label> <input type="text" name="address" class="form-control" id="inputAddress" placeholder="Enter Address"> </div> <div class="form-group"> <label class="control-label" for="inputPostcode">Postcode:</label> <input type="text" name="postcode" class="form-control" id="inputPostcode" placeholder="Enter Postcode"> </div> <div class="form-group"> <label class="control-label" for="inputCity">City:</label> <input type="text" name="city" class="form-control" id="inputCity" placeholder="Enter City"> </div> <div class="form-group"> <label class="control-label" for="inputRegion">Region:</label> <input type="text" name="region" class="form-control" id="inputRegion" placeholder="Enter Region"> </div> <div class="form-group"> <label class="control-label" for="inputCountry">Country:</label> <input type="text" name="country" class="form-control" id="inputCountry" placeholder="Enter Country"> </div> <div class="form-group"> <label class="control-label" for="inputPhonenumber">Phone:</label> <input type="text" name="phone" class="form-control" id="inputPhonenumber" placeholder="Enter Phonenumber"> </div> <div class="form-group"> <label class="control-label" for="inputEmail">Email-Address:</label> <input type="text" name="email" class="form-control" id="inputEmail" placeholder="Enter Email-Address"> </div> <div class="form-group"> <label class="control-label" for="inputPassword">Password:</label> <input type="password" name="password" class="form-control" id="inputPassword" placeholder="Enter Password"> </div> <div class="form-group"> <label>Activ: </label> <input type="checkbox" name="activ"><br /> <small class="text-muted">If the entry should be active, the checkbox must be clicked!</small> </div> <div class="form-group"> <button type="submit" name="Pay" class="btn btn-primary"> <span class="fa fa-send"></span> Speichern</button> </div> </form> </table> </div> </div> <?php } ?> <?php include("labfooter.php"); ?>