From 487089e5a9824a08bbfe37a591b23df2320e9541 Mon Sep 17 00:00:00 2001 From: "barraux.a" Date: Tue, 16 Nov 2021 22:11:39 +0100 Subject: [PATCH] =?UTF-8?q?passage=20=C3=A0=20sqlite?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- database/ticket_panne.db | Bin 0 -> 16384 bytes login/cible.php | 7 ++-- prof/cible/index.php | 30 +++++++-------- referant/admin.php | 5 +-- referant/cible/admin.php | 19 ++++++--- referant/cible/edit.php | 10 ++--- referant/cible/export.php | 25 +++++++++--- referant/cible/search.php | 4 +- referant/cible/slider.php | 6 +-- referant/index.php | 5 +-- referant/js/edit.js | 1 + referant/liste.php | 5 +-- ticket.sql | 79 -------------------------------------- 13 files changed, 68 insertions(+), 128 deletions(-) create mode 100755 database/ticket_panne.db delete mode 100644 ticket.sql diff --git a/database/ticket_panne.db b/database/ticket_panne.db new file mode 100755 index 0000000000000000000000000000000000000000..f93fba35a831d77e9dfd491e6ffc473ddddd2a4e GIT binary patch literal 16384 zcmeI3&2Az`5P%18yk0LqK?qq0Ic|#sYk7&7fx)}VWdUQyiX8zqQJh0I4HUyT!whuy z*qhBMQ63@pM3ExJ&*5_(A$v$3A$fq*fPe7D8)3^3TaOn(=;uI#{wQ#EsQtw{m|9Kzg%yVsc2uqH zH`pt(4_!WjN2s~+?FZp|E168_yVlg^n7b~>**S8{LVh-wXAhSd%kORHne8gDK(J>Y5g-CYfCvx)B0vO)01H6vgEg1d^p0HMCpvzq~FBbhx zi$<5U=rHkX?1#kniD&WO<7csEbSe5r{3x!!$!a7^1c(3;AOb{y2oM1xKm>@ue}lm1 z_hZ`nMkbp{uH%LZ z*Y&(FSyOn99Gnye5(;Ib?p&N>F%!$iA+%r0B@4;5&0O~W%zm+87&Xs5@qEGhz-j`E zww4REi=UJolt5XvY;YexPImi@GmHDZA#~~-E4l6&7vONEY~`b7qf*w35(cM*vRSbD zdY22q{pT@LThz4XauC`ohL%pQW^O{OjO?E9q&H9u`WB$=7i{F&SPl+?>s|(jwOr?P z0)vSZ)?-C~u`AV3 z4Trvw&O?7i1Shr{bp^eBNX z8JwJ^R+HwWALgLx6{DwpO(?0YDZTU%RCrZYM7(h8=-<1xno^62W=-uHSF-xkoj z+!0m@CcB<*U7UC7+qf?S2Sy_}0VXjm8P4tlt9w09VeE)OA{HUPUc{vi*Vb{V&DHG9 zQYIGPv4GDUj-r_37rzK#J=|bmmf+)|jg!|d9B_8&#UbXZgIczl`LJI-+B-VxY&T{} zh*EaoNv+y$S394U-oeFF$t31pDwVoP`x1UBvD4_w*7okscB@lw?QZYvw05P1kIi6f z;YMj?<;G)FdU}UaYxgry6HHFf!vWPqa@KB=uQE+OZ;aW%OL|#1JM||<#VnbRp9J;) tP~tBQf7FNo5g-CYfCvx)B0vO)01+SpM1Tkof&USKquery("SELECT * FROM logins"); - while ($line = $reponse->fetch()) { + while ($line = $reponse->fetchArray()) { if ($line[0] == $_POST['login'] && $line[1] == $_POST['pwd']) { session_start(); $_SESSION['login'] = $_POST['login']; @@ -12,9 +12,8 @@ if (isset($_POST['login']) && isset($_POST['pwd'])) { header('location: ../prof/index.php'); } } - $reponse->closeCursor(); } echo ''; -?> \ No newline at end of file +?> diff --git a/prof/cible/index.php b/prof/cible/index.php index 86d2c29..5479093 100755 --- a/prof/cible/index.php +++ b/prof/cible/index.php @@ -1,22 +1,22 @@ prepare('INSERT INTO pannes(dates, details, lieu, salle, pos, materiel, marque, model, nserie, demandeur, traitement) VALUES(:dates, :details, :lieu, :salle, :pos, :materiel, :marque, :model, :nserie, :demandeur, :traitement)'); +$stmt = $bdd->prepare('INSERT INTO pannes(dates, details, lieu, salle, pos, materiel, marque, model, nserie, demandeur, traitement) VALUES(:dates, :details, :lieu, :salle, :pos, :materiel, :marque, :model, :nserie, :demandeur, :traitement)'); -$req->execute(array( - 'dates' => $_POST['dates'], - 'details' => $_POST['details'], - 'lieu' => $_POST['lieu'], - 'salle' => $_POST['salle'], - 'pos' => $_POST['pos'], - 'materiel' => $_POST['materiel'], - 'marque' => $_POST['marque'], - 'model' => $_POST['model'], - 'nserie' => $_POST['nserie'], - 'demandeur' => $_POST['demandeur'], - 'traitement' => 0 - )); +$stmt->bindValue(':dates', $_POST['dates']); +$stmt->bindValue(':details', $_POST['details']); +$stmt->bindValue(':lieu', $_POST['lieu']); +$stmt->bindValue(':salle', $_POST['salle']); +$stmt->bindValue(':pos', $_POST['pos']); +$stmt->bindValue(':materiel', $_POST['materiel']); +$stmt->bindValue(':marque', $_POST['marque']); +$stmt->bindValue(':model', $_POST['model']); +$stmt->bindValue(':nserie', $_POST['nserie']); +$stmt->bindValue(':demandeur', $_POST['demandeur']); +$stmt->bindValue(':traitement', 0); + +$stmt->execute(); echo 'Votre ticket à bien été pris en compte'; ?> diff --git a/referant/admin.php b/referant/admin.php index 1770ca7..3a420a8 100755 --- a/referant/admin.php +++ b/referant/admin.php @@ -1,12 +1,11 @@ query("SELECT * FROM logins"); $arr = []; - while ($line = $reponse->fetch()) { + while ($line = $reponse->fetchArray()) { $arr[$line[0]] = $line[1]; } - $reponse->closeCursor(); ?> diff --git a/referant/cible/admin.php b/referant/cible/admin.php index e067375..463ca49 100755 --- a/referant/cible/admin.php +++ b/referant/cible/admin.php @@ -1,8 +1,15 @@ -query('UPDATE `logins` SET `pwd` = "' .$decode['pwd'] .'" WHERE `login` = "' .$decode['login'] .'"'); +$bdd = new SQLite3('../../database/ticket_panne.db', SQLITE3_OPEN_READWRITE); -$traitement = $bdd->query("SELECT * FROM `logins` WHERE `login`= '" .$decode['login'] ."'"); -print_r(json_encode($traitement->fetch())); -?> \ No newline at end of file +$stmt = $bdd->prepare('UPDATE `logins` SET `pwd` = :pwd WHERE `login` = :login'); +$stmt->bindValue(':pwd', $decode['pwd']); +$stmt->bindValue(':login', $decode['login']); + +$stmt->execute(); + +$select = $bdd->prepare("SELECT * FROM `logins` WHERE `login` = :login"); +$select->bindValue(':login', $decode['login']); +$traitement = $select->execute(); +print_r(json_encode($traitement->fetchArray())); +?> diff --git a/referant/cible/edit.php b/referant/cible/edit.php index c0d3529..9e5407b 100755 --- a/referant/cible/edit.php +++ b/referant/cible/edit.php @@ -1,7 +1,7 @@ -query($request); $traitement = $bdd->query("SELECT * FROM pannes WHERE ID=" .$decode['id']); -print_r(json_encode($traitement->fetch())); -?> \ No newline at end of file +print_r(json_encode($traitement->fetchArray())); +?> diff --git a/referant/cible/export.php b/referant/cible/export.php index 9a7aa6c..38a9497 100644 --- a/referant/cible/export.php +++ b/referant/cible/export.php @@ -1,15 +1,30 @@ query("SELECT * FROM `" .$_POST['bdd'] ."`"); +$title = array_keys($response->fetchArray(SQLITE3_ASSOC)); header('Content-Type: text/csv; charset=utf-8'); header('Content-Disposition: attachment; filename=' .$_POST['bdd'] .'.csv'); $output = fopen("php://output", "w"); fputcsv($output, $title); -$result = mysqli_query($connect, $query); -while($row = mysqli_fetch_assoc($result)) { + +while($row = $response->fetchArray(SQLITE3_ASSOC)) { fputcsv($output, $row); } fclose($output); diff --git a/referant/cible/search.php b/referant/cible/search.php index d361c52..6c8f308 100755 --- a/referant/cible/search.php +++ b/referant/cible/search.php @@ -1,12 +1,12 @@ query("SELECT * FROM pannes WHERE `" .$_POST['champ'] ."`='" .$_POST['value'] ."'"); $reponse = $bdd->prepare("SELECT * FROM pannes WHERE `" .$_POST['champ'] ."`='" .$_POST['value'] ."'"); $reponse->execute(); $result = []; - while ($line = $reponse->fetch()) { + while ($line = $reponse->fetchArray()) { array_push($result, $line); }; diff --git a/referant/cible/slider.php b/referant/cible/slider.php index c4be944..396fa2f 100755 --- a/referant/cible/slider.php +++ b/referant/cible/slider.php @@ -1,9 +1,9 @@ query("UPDATE pannes SET traitement = " .$_POST['is_checked'] ." WHERE ID = " .$_POST['id']); $traitement = $bdd->query("SELECT traitement FROM pannes WHERE ID=" .$_POST['id']); -$res = $traitement->fetch()['traitement']; +$res = $traitement->fetchArray()['traitement']; echo $res; -?> \ No newline at end of file +?> diff --git a/referant/index.php b/referant/index.php index db16e75..17d2ba6 100755 --- a/referant/index.php +++ b/referant/index.php @@ -36,12 +36,12 @@ include '../sessions/session_restraintes.php'; query("SELECT * FROM pannes ORDER BY ID DESC"); for ($j=0; $j < 3; $j++) { - $line = $reponse->fetch(); + $line = $reponse->fetchArray(); if ($line['traitement'] == 0) { $class = $line[0]; include 'include/line.php'; @@ -50,7 +50,6 @@ include '../sessions/session_restraintes.php'; $j--; } } - $reponse->closeCursor(); ?> diff --git a/referant/js/edit.js b/referant/js/edit.js index a15cc9b..88558d3 100644 --- a/referant/js/edit.js +++ b/referant/js/edit.js @@ -38,6 +38,7 @@ function Edit(clas) { data.append('value', JSON.stringify(value)); xhr.onreadystatechange = function() { if (this.readyState == 4 && this.status == 200) { + console.log(this.response); for (let i=1; i<11; i++) { obj[i].innerHTML = this.response[i]; } diff --git a/referant/liste.php b/referant/liste.php index 918b971..cc71c64 100755 --- a/referant/liste.php +++ b/referant/liste.php @@ -33,15 +33,14 @@ include '../sessions/session_restraintes.php'; valider query("SELECT * FROM pannes ORDER BY ID"); - while ($line = $reponse->fetch()) { + while ($line = $reponse->fetchArray()) { $class = $line[0]; include 'include/line.php'; } - $reponse->closeCursor(); ?> diff --git a/ticket.sql b/ticket.sql deleted file mode 100644 index 460be26..0000000 --- a/ticket.sql +++ /dev/null @@ -1,79 +0,0 @@ --- phpMyAdmin SQL Dump --- version 5.1.1 --- https://www.phpmyadmin.net/ --- --- Host: localhost --- Generation Time: Oct 30, 2021 at 07:45 PM --- Server version: 10.4.21-MariaDB --- PHP Version: 8.0.10 - -SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO"; -START TRANSACTION; -SET time_zone = "+00:00"; - - -/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; -/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; -/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; -/*!40101 SET NAMES utf8mb4 */; - --- --- Database: `ticket` --- - --- -------------------------------------------------------- - --- --- Table structure for table `logins` --- - -CREATE TABLE `logins` ( - `login` varchar(255) NOT NULL, - `pwd` varchar(255) NOT NULL -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; - --- -------------------------------------------------------- - --- --- Table structure for table `pannes` --- - -CREATE TABLE `pannes` ( - `ID` int(11) NOT NULL, - `dates` date NOT NULL, - `details` text NOT NULL, - `lieu` text NOT NULL, - `salle` varchar(255) NOT NULL, - `pos` text NOT NULL, - `materiel` varchar(255) NOT NULL, - `marque` varchar(255) NOT NULL, - `model` varchar(255) NOT NULL, - `nserie` text NOT NULL, - `demandeur` text NOT NULL, - `traitement` tinyint(1) NOT NULL -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; - --- --- Indexes for dumped tables --- - --- --- Indexes for table `pannes` --- -ALTER TABLE `pannes` - ADD PRIMARY KEY (`ID`); - --- --- AUTO_INCREMENT for dumped tables --- - --- --- AUTO_INCREMENT for table `pannes` --- -ALTER TABLE `pannes` - MODIFY `ID` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=9; -COMMIT; - -/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; -/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; -/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; \ No newline at end of file