diff --git a/add_item.php b/add_item.php
index f1cce9c..bb130f7 100644
--- a/add_item.php
+++ b/add_item.php
@@ -10,6 +10,7 @@ $ItemPrice = $_POST['ItemPrice'];
$ItemLink = $_POST['ItemLink'];
$ItemImage = $_POST['ItemImage'];
$ListID = $_POST['ItemListID'];
+$nextPriority = 0;
#--- check if the provided Link is a valid URL
@@ -42,13 +43,20 @@ if ($conn->connect_error) {
die('Connection failed: ' . $conn->connect_error);
}
-$stmt = $conn->prepare('INSERT INTO whishes (title, description, link, image, price, whislist) VALUES (?, ?, ?, ?, ?, ?)');
+$stmt = 'SELECT MAX( priority ) AS maxprio FROM whishes WHERE whislist = ' . $ListID . ';';
+$result = $conn->query($stmt);
-if (false === $stmt) {
- die('prepare() failed: ' . htmlspecialchars($mysqli->error));
+while ($row = mysqli_fetch_array($result)) {
+ $nextPriority = $row['maxprio'] + 1;
}
-$rc = $stmt->bind_param('ssssii', $ItemTitle, $ItemDescription, $ItemLink, $imageLocalLink, $ItemPriceCents, $ListID);
+$stmt = $conn->prepare('INSERT INTO whishes (title, description, link, image, price, whislist, priority) VALUES (?, ?, ?, ?, ?, ?, ?)');
+
+if (false === $stmt) {
+ die('prepare() failed: ' . htmlspecialchars($conn->error));
+}
+
+$rc = $stmt->bind_param('ssssiii', $ItemTitle, $ItemDescription, $ItemLink, $imageLocalLink, $ItemPriceCents, $ListID, $nextPriority);
if (false === $rc) {
die('bind_param() failed: ' . htmlspecialchars($stmt->error));
}
diff --git a/include/get_pw_hash.php b/include/get_pw_hash.php
new file mode 100644
index 0000000..dbe57e1
--- /dev/null
+++ b/include/get_pw_hash.php
@@ -0,0 +1,4 @@
+Löschen'
+
+ '
);
}
@@ -139,6 +140,9 @@ function wishlistMainBuilder($ListID, $sortby)
case 'random':
$sort = 'RAND()';
break;
+ case 'priority':
+ $sort = 'priority DESC';
+ break;
}
$sql = 'SELECT ID, title, description, link, image, reserved, price, date FROM whishes WHERE whislist = ' . $ListID . ' ORDER BY ' . $sort;
diff --git a/index.php b/index.php
index c6dfe69..db82317 100644
--- a/index.php
+++ b/index.php
@@ -8,7 +8,7 @@ include_once('config/config.php');
$ListID = -1;
$loggedin = false;
-$sortby = 'date_asc';
+$sortby = 'priority';
if (isset($_GET['list'])) {
$ListID = $_GET['list'];
@@ -16,6 +16,8 @@ if (isset($_GET['list'])) {
if (isset($_POST['sortby'])) {
$sortby = $_POST['sortby'];
+} else if (isset($_POST['sortby_transfer'])) {
+ $sortby = $_POST['sortby_transfer'];
}
if (isset($_SESSION['listid'])) {
@@ -62,8 +64,8 @@ if (isset($_POST['listadd'])) {
die('Connection failed: ' . $conn->connect_error);
}
- $sql = 'INSERT INTO lists (title, description, edit_pw) VALUES ("' . $listName . '", "' .$listDescription. '","' . $listPassword . '")';
-
+ $sql = 'INSERT INTO lists (title, description, edit_pw) VALUES ("' . $listName . '", "' . $listDescription . '","' . $listPassword . '")';
+
$result = $conn->query($sql);
if ($conn->query($sql) === TRUE) {
@@ -73,11 +75,10 @@ if (isset($_POST['listadd'])) {
$loggedin = true;
$actual_link = 'http://' . $_SERVER['HTTP_HOST'] . '/?list=' . $last_id;
header('Location: ' . $actual_link);
-
} else {
$message = array('msg' => 'Error: ' . $sql . '
' . $conn->error, 'type' => 'error');
}
-
+
$conn->close();
}
@@ -128,6 +129,31 @@ if (isset($_POST['reservation'])) {
$conn->close();
}
+if (isset($_POST['pushprio'])) {
+
+ $nextPriority = 0;
+
+ $conn = new mysqli($servername, $username, $password, $db);
+
+ // Check connection
+ if ($conn->connect_error) {
+ die('Connection failed: ' . $conn->connect_error);
+ }
+
+ $stmt = 'SELECT MAX( priority ) AS maxprio FROM whishes WHERE whislist = ' . $ListID . ';';
+ $result = $conn->query($stmt);
+
+ while ($row = mysqli_fetch_array($result)) {
+ $nextPriority = $row['maxprio'] + 1;
+ }
+
+ $sql = 'UPDATE whishes SET priority=' . $nextPriority . ' WHERE ID = ' . $_POST['WhishID'];
+ if ($conn->query($sql) === TRUE)
+ $message = array('msg' => 'Wunschpriorität aktualisiert', 'type' => 'success');
+ else
+ $message = array('msg' => 'Uups, irgendwas ist schief gegangen!', 'type' => 'danger');
+}
+
if (isset($_POST['delete']) && $loggedin == true) {
if (isset($_POST['WhishID'])) {
@@ -221,6 +247,7 @@ if (isset($_POST['delete']) && $loggedin == true) {
?>