forked from elabftw/elabftw
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheditDB-exec.php
95 lines (87 loc) · 3.44 KB
/
editDB-exec.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
84
85
86
87
88
89
90
91
92
93
94
95
<?php
/********************************************************************************
* *
* Copyright 2012 Nicolas CARPi (nicolas.carpi@gmail.com) *
* http://www.elabftw.net/ *
* *
********************************************************************************/
/********************************************************************************
* This file is part of eLabFTW. *
* *
* eLabFTW is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Affero General Public License as *
* published by the Free Software Foundation, either version 3 of *
* the License, or (at your option) any later version. *
* *
* eLabFTW is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied *
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR *
* PURPOSE. See the GNU Affero General Public License for more details. *
* *
* You should have received a copy of the GNU Affero General Public *
* License along with eLabFTW. If not, see <http://www.gnu.org/licenses/>. *
* *
********************************************************************************/
require_once 'inc/common.php';
// formkey stuff
//require_once 'lib/classes/formkey.class.php';
//$formKey = new formKey();
//Array to store validation errors
$msg_arr = array();
//Validation error flag
$errflag = false;
// CHECKS
/*
// Check the form_key
if (!isset($_POST['form_key']) || !$formKey->validate()) {
// form key is invalid
$msg_arr[] = 'The form key is invalid !';
$errflag = true;
}
*/
// ID
if (is_pos_int($_POST['item_id'])) {
$id = $_POST['item_id'];
} else {
$id='';
$msg_arr[] = 'The id parameter is not valid !';
$errflag = true;
}
$title = check_title($_POST['title']);
$date = check_date($_POST['date']);
$body = check_body($_POST['body']);
// Store stuff in Session to get it back if error input
$_SESSION['new_title'] = $title;
$_SESSION['new_date'] = $date;
// If input errors, redirect back to the edit form
if ($errflag) {
$_SESSION['errors'] = $msg_arr;
session_write_close();
header("location: database.php?mode=edit&id=$id");
exit();
}
// SQL for editDB
$sql = "UPDATE items
SET title = :title,
date = :date,
body = :body,
userid = :userid
WHERE id = :id";
$req = $pdo->prepare($sql);
$result = $req->execute(array(
'title' => $title,
'date' => $date,
'body' => $body,
'userid' => $_SESSION['userid'],
'id' => $id
));
// Check if insertion is successful
if ($result) {
// unset session variables
unset($_SESSION['new_title']);
unset($_SESSION['new_date']);
unset($_SESSION['errors']);
header("location: database.php?mode=view&id=$id");
} else {
die();
}