This commit is contained in:
Walter Hupfeld 2024-02-17 08:42:54 +01:00
parent 0df6729f8b
commit 91a8c4e567
14 changed files with 42 additions and 59 deletions

View File

@ -30,7 +30,7 @@
$query = $db->query($strSQL); $query = $db->query($strSQL);
// Fetch the first row // Fetch the first row
$row = $query->fetchArray(SQLITE3_ASSOC); $row = $query->fetch(PDO::FETCH_ASSOC);
// If no results are found, echo a message and stop // If no results are found, echo a message and stop
if ($row == false){ if ($row == false){
@ -49,7 +49,7 @@
echo $line . "\n"; echo $line . "\n";
// Fetch the next line // Fetch the next line
$row = $query->fetchArray(SQLITE3_ASSOC); $row = $query->fetch(PDO::FETCH_ASSOC);
} }
// Prints the column names // Prints the column names

View File

@ -37,7 +37,7 @@
$stmt = $db->prepare("SELECT * FROM files where loc_id = :loc_id"); $stmt = $db->prepare("SELECT * FROM files where loc_id = :loc_id");
$stmt->bindValue(":loc_id", $numDelete, SQLITE3_TEXT); $stmt->bindValue(":loc_id", $numDelete, SQLITE3_TEXT);
$result = $stmt->execute(); $result = $stmt->execute();
if ($row = $result->fetchArray()) { if ($row = $result->fetch(PDO::FETCH_ASSOC)) {
$strFilename = $row['filename']; $strFilename = $row['filename'];
$strFilename = $uploaddir . $strFilename; $strFilename = $uploaddir . $strFilename;
unset($strFilename); unset($strFilename);
@ -67,7 +67,7 @@
$stmt = $db->prepare("SELECT * FROM files where id = :id"); $stmt = $db->prepare("SELECT * FROM files where id = :id");
$stmt->bindValue(":id", $numDelete, SQLITE3_TEXT); $stmt->bindValue(":id", $numDelete, SQLITE3_TEXT);
$result = $stmt->execute(); $result = $stmt->execute();
if ($row=$result->fetchArray()) { if ($row=$result->fetch(PDO::FETCH_ASSOC)) {
$strFilename = $row['filename']; $strFilename = $row['filename'];
$strFilename = $uploaddir . $strFilename; $strFilename = $uploaddir . $strFilename;
unset($strFilename); unset($strFilename);
@ -181,7 +181,7 @@
//$strSQL="SELECT * FROM location ORDER BY created_at DESC"; //$strSQL="SELECT * FROM location ORDER BY created_at DESC";
$strSQL="SELECT l.id as lid,l.*,adr.* FROM location l LEFT JOIN address adr ON l.id=adr.loc_id ORDER BY created_at ASC"; $strSQL="SELECT l.id as lid,l.*,adr.* FROM location l LEFT JOIN address adr ON l.id=adr.loc_id ORDER BY created_at ASC";
$result = $db->query($strSQL); $result = $db->query($strSQL);
while ($row = $result->fetchArray()) { while ($row = $result->fetch(PDO::FETCH_ASSOC)) {
$id = $row['lid']; $id = $row['lid'];
echo "<tr>"; echo "<tr>";
echo "<td>".$id."</td>"; echo "<td>".$id."</td>";
@ -194,7 +194,7 @@
echo "<td>"; echo "<td>";
$strSQL = "SELECT id,username,comment,created_at FROM comment WHERE loc_id=".$id; $strSQL = "SELECT id,username,comment,created_at FROM comment WHERE loc_id=".$id;
$comments = $db->query($strSQL); $comments = $db->query($strSQL);
while ($comment = $comments->fetchArray()) { while ($comment = $comments->fetch(PDO::FETCH_ASSOC)) {
echo "<div class='comment'>"; echo "<div class='comment'>";
echo "<em>".$comment['username']." schrieb am "; echo "<em>".$comment['username']." schrieb am ";
$numDatum = strtotime($comment['created_at']); $numDatum = strtotime($comment['created_at']);
@ -215,7 +215,7 @@
echo "<td id='img_".$id."'>"; echo "<td id='img_".$id."'>";
$strSQL = "SELECT id,filename FROM files WHERE loc_id=".$id; $strSQL = "SELECT id,filename FROM files WHERE loc_id=".$id;
$files=$db->query($strSQL); $files=$db->query($strSQL);
if ($file=$files->fetchArray()) { if ($file=$files->fetch(PDO::FETCH_ASSOC)) {
echo "<a href='../images/".$file['filename']."' data-lightbox='radweg".$id."'>"; echo "<a href='../images/".$file['filename']."' data-lightbox='radweg".$id."'>";
echo "<img src='../images/".$file['filename']."' style='width:150px'></a>"; echo "<img src='../images/".$file['filename']."' style='width:150px'></a>";
echo "<a href='".$_SERVER['PHP_SELF']."?delfid=".$file['id']."&csrf=".$_SESSION['csrf_token']."'><i class='fa fa-trash'></i></a>"; echo "<a href='".$_SERVER['PHP_SELF']."?delfid=".$file['id']."&csrf=".$_SESSION['csrf_token']."'><i class='fa fa-trash'></i></a>";

View File

@ -20,7 +20,7 @@ $boolLogin=true;
$strPassword = trim($_POST['password']); $strPassword = trim($_POST['password']);
$strSQL = "SELECT username,passwordhash FROM user WHERE username='$strUser'"; $strSQL = "SELECT username,passwordhash FROM user WHERE username='$strUser'";
$result = $db->query($strSQL); $result = $db->query($strSQL);
if ($row=$result->fetchArray()) { if ($row=$result->fetch(PDO::FETCH_ASSOC)) {
if (password_verify($strPassword,$row['passwordhash'])) { if (password_verify($strPassword,$row['passwordhash'])) {
session_start(); session_start();
$_SESSION['user']=$strUser; $_SESSION['user']=$strUser;

View File

@ -72,7 +72,7 @@
$strScript=""; $strScript="";
$strSQL="SELECT l.id as lid,l.*,adr.* FROM location l LEFT JOIN address adr ON l.id=adr.loc_id ORDER BY city,postcode,suburb,hamlet,road ASC"; $strSQL="SELECT l.id as lid,l.*,adr.* FROM location l LEFT JOIN address adr ON l.id=adr.loc_id ORDER BY city,postcode,suburb,hamlet,road ASC";
$result = $db->query($strSQL); $result = $db->query($strSQL);
while ($row = $result->fetchArray()) { while ($row = $result->fetch(PDO::FETCH_ASSOC)) {
$id = $row['lid']; $id = $row['lid'];
$numDatum= strtotime($row['created_at']); $numDatum= strtotime($row['created_at']);
$strDatum= date("d.m.Y",$numDatum); $strDatum= date("d.m.Y",$numDatum);
@ -86,7 +86,7 @@
echo "<td>"; echo "<td>";
$strSQL = "SELECT id,username,comment,created_at FROM comment WHERE loc_id=".$id; $strSQL = "SELECT id,username,comment,created_at FROM comment WHERE loc_id=".$id;
$comments = $db->query($strSQL); $comments = $db->query($strSQL);
while ($comment = $comments->fetchArray()) { while ($comment = $comments->fetch(PDO::FETCH_ASSOC)) {
echo "<div class='comment'>"; echo "<div class='comment'>";
echo "<em>".$comment['username']." schrieb am "; echo "<em>".$comment['username']." schrieb am ";
$numDatum = strtotime($comment['created_at']); $numDatum = strtotime($comment['created_at']);
@ -102,7 +102,7 @@
echo "<td>"; echo "<td>";
$strSQL = "SELECT id,filename FROM files WHERE loc_id=".$id; $strSQL = "SELECT id,filename FROM files WHERE loc_id=".$id;
$files=$db->query($strSQL); $files=$db->query($strSQL);
if ($file=$files->fetchArray()) { if ($file=$files->fetch(PDO::FETCH_ASSOC)) {
echo "<img src='../images/".$file['filename']."' style='width:200px'>"; echo "<img src='../images/".$file['filename']."' style='width:200px'>";
} }
echo "</td>"; echo "</td>";

View File

@ -11,7 +11,7 @@ $result = $db->query("SELECT * FROM location ORDER BY created_at ASC");
$coords_array = array (); $coords_array = array ();
while ($row = $result->fetchArray(SQLITE3_ASSOC)) { while ($row = $result->fetch(PDO::FETCH_ASSOC)) {
$coords_array[]=$row; $coords_array[]=$row;
} }

View File

@ -1,6 +1,7 @@
<?php <?php
$dbFilename="../db/locations.db"; $dbFilename="../db/locations.db";
require_once("../config.db.php");
require_once("../config.php"); require_once("../config.php");
require_once("../lib/functions.php"); require_once("../lib/functions.php");
require_once("../lib/geocoding.php"); require_once("../lib/geocoding.php");
@ -55,7 +56,7 @@ $stmt->execute();
// fetch last_id - sqlite // fetch last_id - sqlite
$strSQL="SELECT id FROM location ORDER BY id DESC limit 1"; $strSQL="SELECT id FROM location ORDER BY id DESC limit 1";
$result = $db->query($strSQL); $result = $db->query($strSQL);
if ($row = $result->fetchArray()) { if ($row = $result->fetch(PDO::FETCH_ASSOC)) {
$id = $row['id']; $id = $row['id'];
} }
@ -79,7 +80,7 @@ if ($boolUploadOk) {
// Retrun Markertext of entry // Retrun Markertext of entry
$strSQL="SELECT loc.*,f.filename FROM location loc LEFT JOIN files f ON loc.id=f.loc_id ORDER BY loc.id DESC limit 1"; $strSQL="SELECT loc.*,f.filename FROM location loc LEFT JOIN files f ON loc.id=f.loc_id ORDER BY loc.id DESC limit 1";
$result = $db->query($strSQL); $result = $db->query($strSQL);
if ($row = $result->fetchArray()) { if ($row = $result->fetch(PDO::FETCH_ASSOC)) {
$markerText=generate_tooltip_description($row); $markerText=generate_tooltip_description($row);
$markerText=stripcslashes($markerText); $markerText=stripcslashes($markerText);
} }

12
config.db.php Normal file
View File

@ -0,0 +1,12 @@
<?
$db_server = "mariadb";
$db_user = "root";
$db_passwd = "g0r@w@";
$db_name = "nrw_melder";
$cachetime = 0;
try {
$db = new PDO('mysql:host='.$db_server.';dbname='.$db_name.';charset=utf8mb4', $db_user, $db_passwd);
} catch (PDOException $e) {echo "Fehler: ".$e->getMessage(); die();}

View File

@ -8,17 +8,12 @@
* Datum: 18.05.2021 * Datum: 18.05.2021
******************************** */ ******************************** */
require_once("config.db.php");
date_default_timezone_set('UTC');
if (!isset($dbFilename)) {
$dbFilename = "db/locations.db";
}
$db = new SQLite3($dbFilename);
$strSQL="select * from config"; $strSQL = "select * from config";
$result = $db->query($strSQL); $result = $db->query($strSQL);
while ($row = $result->fetchArray(SQLITE3_ASSOC)) { while ($row = $result->fetch(PDO::FETCH_ASSOC)) {
switch ($row['key']) { switch ($row['key']) {
case "uploaddir" : case "uploaddir" :
$uploaddir=$row['value']; $uploaddir=$row['value'];

View File

@ -4,15 +4,16 @@
* Ideenmelder * Ideenmelder
* Autor: Walter Hupfeld, Hamm * Autor: Walter Hupfeld, Hamm
* E-Mail: info@hupfeld-software.de * E-Mail: info@hupfeld-software.de
* Version: 1.0 * Version: 2.0
* Datum: 18.05.2021 * Datum: 16.02.2024
******************************** */ ******************************** */
if (!file_exists("db/locations.db")) { if (!file_exists("db/locations.db")) {
header("Location: setup.php"); header("Location: setup.php");
} }
require("config.php"); require("config.db.php");
require("config.php");
require_once("lib/functions.php"); require_once("lib/functions.php");
$ref=(isset($_GET['ref']) && ($_GET['ref']==1)); $ref=(isset($_GET['ref']) && ($_GET['ref']==1));
@ -32,7 +33,7 @@
$arrMarker = array(); $arrMarker = array();
$arrDescription = array(); $arrDescription = array();
while ($row = $result->fetchArray()) { while ($row = $result->fetch(PDO::FETCH_ASSOC)) {
$id=$row['id']; $id=$row['id'];
$topic = $row['topic']; $topic = $row['topic'];
$numLng = $row['lng']; $numLng = $row['lng'];

View File

@ -56,7 +56,7 @@ function generate_tooltip_description($row) {
$strSQL = "SELECT username,comment,created_at FROM comment WHERE loc_id=".$id; $strSQL = "SELECT username,comment,created_at FROM comment WHERE loc_id=".$id;
$result = $db->query($strSQL); $result = $db->query($strSQL);
while ($comment = $result->fetchArray()) { while ($comment = $result->fetch(PDO::FETCH_ASSOC)) {
$strDescription .= "<div class=\'comment\'>"; $strDescription .= "<div class=\'comment\'>";
$strDescription .= "<em>".$comment['username']." schrieb am "; $strDescription .= "<em>".$comment['username']." schrieb am ";
$numDatum = strtotime($comment['created_at']); $numDatum = strtotime($comment['created_at']);

View File

@ -79,7 +79,7 @@ function fillAddressTable($db,$limit=20) {
// Get all ids from address table and write to array // Get all ids from address table and write to array
$strSQL="select loc_id from address"; $strSQL="select loc_id from address";
$result=$db->query($strSQL); $result=$db->query($strSQL);
while ($row=$result->fetchArray()) { while ($row=$result->fetch(PDO::FETCH_ASSOC)) {
$arrIds[]=$row['loc_id']; $arrIds[]=$row['loc_id'];
} }
@ -95,7 +95,7 @@ function fillAddressTable($db,$limit=20) {
$strTable .= "<th>".$key."</th>"; $strTable .= "<th>".$key."</th>";
} }
$strTable .= "</tr>"; $strTable .= "</tr>";
while ($row=$result->fetchArray()) { while ($row=$result->fetch(PDO::FETCH_ASSOC)) {
$id=$row['id']; $id=$row['id'];
if (!in_array($id,$arrIds) && $counter<$limit) { if (!in_array($id,$arrIds) && $counter<$limit) {
$counter++; $counter++;

View File

@ -107,7 +107,7 @@
$strSQL="SELECT loc.*,f.filename FROM location loc LEFT JOIN files f ON loc.id=f.loc_id ORDER BY created_at DESC"; $strSQL="SELECT loc.*,f.filename FROM location loc LEFT JOIN files f ON loc.id=f.loc_id ORDER BY created_at DESC";
$result = $db->query($strSQL); $result = $db->query($strSQL);
$numCounter=1; $numCounter=1;
while ($row = $result->fetchArray()) { while ($row = $result->fetch(PDO::FETCH_ASSOC)) {
$numDatum= strtotime($row['created_at']); $numDatum= strtotime($row['created_at']);
$id=$row['id']; $id=$row['id'];
$datum= date("d.m.Y",$numDatum); $datum= date("d.m.Y",$numDatum);
@ -126,7 +126,7 @@
echo "<td>"; echo "<td>";
$strSQL = "SELECT username,comment,created_at FROM comment WHERE loc_id=".$id; $strSQL = "SELECT username,comment,created_at FROM comment WHERE loc_id=".$id;
$comments = $db->query($strSQL); $comments = $db->query($strSQL);
while ($comment = $comments->fetchArray()) { while ($comment = $comments->fetch(PDO::FETCH_ASSOC)) {
echo "<div class='comment'>"; echo "<div class='comment'>";
echo "<em>".$comment['username']." schrieb am "; echo "<em>".$comment['username']." schrieb am ";
$numDatum = strtotime($comment['created_at']); $numDatum = strtotime($comment['created_at']);

View File

@ -71,33 +71,7 @@
} }
?> ?>
</li> </li>
<li class="list-group-item">
<?php
/** **************************************************
*
* Datenbank anlegen
*
************************************************** */
echo "Datenbankverzeichnis anlegen: ";
if (file_exists("db/locations.db")) {
echo "Datenbank existiert bereits.";
$boolError=true;
die ("Abbruch");
} else {
if (file_exists("db") && is_writable("db")) {
echo "Datenbankverzeichnis existiert bereits";
} else {
if (mkdir("db",0755)) {
echo "Datenbankverzeichnis angelegt. ";
} else {
echo "<span class='error'>Datenbankverzeichnis konnte nicht angelegt werden.</span>";
$boolError=true;
}
}
}
?>
</li>
<li class="list-group-item"> <li class="list-group-item">
<?php <?php
/** ************************************************** /** **************************************************

View File

@ -9,9 +9,9 @@
******************************** */ ******************************** */
$dbFilename = "db/locations.db"; require("config.db.php");
$db = new SQLite3($dbFilename);
$db->query("TRUNCATE config");
$boolActive = (isset($_POST['active'])) ? "1" : "0"; $boolActive = (isset($_POST['active'])) ? "1" : "0";
$boolRating = (isset($_POST['rating'])) ? "1" : "0"; $boolRating = (isset($_POST['rating'])) ? "1" : "0";