This repository has been archived by the owner on Oct 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathback_edittag.php
83 lines (74 loc) · 2.18 KB
/
back_edittag.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<?php require 'common.php';?>
<?php
//TODO code is_endpoint
function editTag($is_endpoint, $eId, $eTagData){
$tagData = json_decode($eTagData);
$query = "
UPDATE tags INNER JOIN panels, users
SET tags.name = :name,
tags.description = :description,
tags.state = :state,
tags.category = :category,
tags.raw_cooked = :raw_cooked,
tags.fridge_freezer = :fridge_freezer,
tags.expiry_date = :expiry_date
WHERE tags.uid = :uid
AND tags.controluid = panels.uid
AND panels.accountid = :userid
";
if ($is_endpoint){
if ($tagData->expiry_date == null || $tagData->expiry_date == ''){
include_once 'getexpirydate.php';
$expiry_date = getExpiryDate($tagData->category, $tagData->raw_cooked, $tagData->fridge_freezer);
} else {
$expiry_date = $tagData->expiry_date;
}
}
if ($is_endpoint){
$query_params = array(
':userid' => $eId,
':uid' => $tagData->uid,
':name' => $tagData->name,
':description' => $tagData->description,
':state' => $tagData->state,
':category' => $tagData->category,
':raw_cooked' => $tagData->raw_cooked,
':fridge_freezer' => $tagData->fridge_freezer,
':expiry_date' => $expiry_date
);
} else {
$query_params = array(
':userid' => $_SESSION['user']['id'],
':uid' => $_POST['id'],
':name' => $_POST['name'],
':description' => $_POST['description'],
':state' => $_POST['state'],
':category' => $_POST['category'],
':raw_cooked' => $_POST['raw_cooked'],
':fridge_freezer' => $_POST['fridge_freezer'],
':expiry_date' => $_POST['expiry_date']
);
}
include 'common.php';
try
{
$stmt = $db->prepare($query);
$result = $stmt->execute($query_params);
if ($is_endpoint){
return true;
}
}
catch(PDOException $ex)
{
if ($is_endpoint){
return false;
}
die("Failed to run query: " . $ex->getMessage());
}
return true;
}
if (!empty($_POST)){
editTag(false, null, null);
header("Location: tags.php");
}
?>