Browse Source

passage à sqlite

master
BARRAUX Arthur 3 years ago
parent
commit
487089e5a9
  1. BIN
      database/ticket_panne.db
  2. 7
      login/cible.php
  3. 30
      prof/cible/index.php
  4. 5
      referant/admin.php
  5. 19
      referant/cible/admin.php
  6. 10
      referant/cible/edit.php
  7. 25
      referant/cible/export.php
  8. 4
      referant/cible/search.php
  9. 6
      referant/cible/slider.php
  10. 5
      referant/index.php
  11. 1
      referant/js/edit.js
  12. 5
      referant/liste.php
  13. 79
      ticket.sql

BIN
database/ticket_panne.db

Binary file not shown.

7
login/cible.php

@ -1,10 +1,10 @@
<?php
if (isset($_POST['login']) && isset($_POST['pwd'])) {
$bdd = new PDO('mysql:host=localhost;dbname=ticket;charset:utf8', 'root', '');
$bdd = new SQLite3('../database/ticket_panne.db', SQLITE3_OPEN_READWRITE);
$reponse = $bdd->query("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 '<meta http-equiv="refresh" content="0;URL=index.php">';
?>
?>

30
prof/cible/index.php

@ -1,22 +1,22 @@
<?php
$bdd = new PDO('mysql:host=localhost;dbname=ticket;charset:utf8', 'root', '');
$bdd = new SQLite3('../../database/ticket_panne.db', SQLITE3_OPEN_READWRITE);
$req = $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)');
$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';
?>

5
referant/admin.php

@ -1,12 +1,11 @@
<?php
include '../sessions/session_restraintes.php';
$bdd = new PDO('mysql:host=localhost;dbname=ticket;charset:utf8', 'root', '');
$bdd = new SQLite3('../database/ticket_panne.db', SQLITE3_OPEN_READWRITE);
$reponse = $bdd->query("SELECT * FROM logins");
$arr = [];
while ($line = $reponse->fetch()) {
while ($line = $reponse->fetchArray()) {
$arr[$line[0]] = $line[1];
}
$reponse->closeCursor();
?>
<html>

19
referant/cible/admin.php

@ -1,8 +1,15 @@
<?php
<?php
$decode = json_decode($_POST['value'], TRUE);
$bdd = new PDO('mysql:host=localhost;dbname=ticket;charset:utf8', 'root', '');
$update = $bdd->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()));
?>
$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()));
?>

10
referant/cible/edit.php

@ -1,7 +1,7 @@
<?php
<?php
$decode = json_decode($_POST['value'], TRUE);
$bdd = new PDO('mysql:host=localhost;dbname=ticket;charset:utf8', 'root', '');
$request = 'UPDATE pannes SET
$bdd = new SQLite3('../../database/ticket_panne.db', SQLITE3_OPEN_READWRITE);
$request = 'UPDATE pannes SET
dates = "' .$decode["dates"] .'",
details = "' .$decode["details"] .'",
lieu = "' .$decode["lieu"] .'",
@ -17,5 +17,5 @@ WHERE ID= "' .$decode['id'] .'"';
$update = $bdd->query($request);
$traitement = $bdd->query("SELECT * FROM pannes WHERE ID=" .$decode['id']);
print_r(json_encode($traitement->fetch()));
?>
print_r(json_encode($traitement->fetchArray()));
?>

25
referant/cible/export.php

@ -1,15 +1,30 @@
<?php
$connect = mysqli_connect("localhost", "root", "", "ticket");
$query = "SELECT * FROM `" .$_POST['bdd'] ."`";
$title = array_keys(mysqli_fetch_assoc(mysqli_query($connect, $query)));
// $connect = mysqli_connect("localhost", "root", "", "ticket");
// $query = "SELECT * FROM `" .$_POST['bdd'] ."`";
// $title = array_keys(mysqli_fetch_assoc(mysqli_query($connect, $query)));
//
// 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)) {
// fputcsv($output, $row);
// }
// fclose($output);
//
$bdd = new SQLite3('../../database/ticket_panne.db', SQLITE3_OPEN_READWRITE);
$response = $bdd->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);

4
referant/cible/search.php

@ -1,12 +1,12 @@
<?php
$bdd = new PDO('mysql:host=localhost;dbname=ticket;charset:utf8', 'root', '');
$bdd = new SQLite3('../../database/ticket_panne.db', SQLITE3_OPEN_READWRITE);
try {
// $reponse = $bdd->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);
};

6
referant/cible/slider.php

@ -1,9 +1,9 @@
<?php
$bdd = new PDO('mysql:host=localhost;dbname=ticket;charset:utf8', 'root', '');
$bdd = new SQLite3('../../database/ticket_panne.db', SQLITE3_OPEN_READWRITE);
$update = $bdd->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;
?>
?>

5
referant/index.php

@ -36,12 +36,12 @@ include '../sessions/session_restraintes.php';
</tr>
<?php
$bdd = new PDO('mysql:host=localhost;dbname=ticket;charset:utf8', 'root', '');
$bdd = new SQLite3('../database/ticket_panne.db', SQLITE3_OPEN_READWRITE);
$reponse = $bdd->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();
?>
</tbody>
</table>

1
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];
}

5
referant/liste.php

@ -33,15 +33,14 @@ include '../sessions/session_restraintes.php';
<td>valider</td>
</tr>
<?php
$bdd = new PDO('mysql:host=localhost;dbname=ticket;charset:utf8', 'root', '');
$bdd = new SQLite3('../database/ticket_panne.db', SQLITE3_OPEN_READWRITE);
$reponse = $bdd->query("SELECT * FROM pannes ORDER BY ID");
while ($line = $reponse->fetch()) {
while ($line = $reponse->fetchArray()) {
$class = $line[0];
include 'include/line.php';
}
$reponse->closeCursor();
?>
</tbody>
</table>

79
ticket.sql

@ -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 */;
Loading…
Cancel
Save