summaryrefslogtreecommitdiff
path: root/update.php
blob: e0e738a0d9829f05e6bd92717940f66d4fd233e5 (plain)
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
/*
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program 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 General Public License for more details.
 */
?>
<?php
/* vim: set ts=4 sw=4 et : */

require_once __DIR__ . "/check_auth.php";
require_once __DIR__ . "/../includes/common.php";

if (!isset($_POST['table']) || !isset($_POST['n']) || !isset($_POST['v']) || !isset($_POST['id'])) {
    echo "false";
    $mysqli->close();
    exit(0);
}

$t = filter_input(INPUT_POST, 'table', FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_BACKTICK);
$n = filter_input(INPUT_POST, 'n', FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_BACKTICK);

$bps = "si";
if (isset($_POST['num']) && $_POST['num'] == 'true')
    $bps = "ii";

if ($n === 'etfav' && $t === 'email_templates') {
    if ($_POST['v'] < 1) {
        $sql = "DELETE FROM email_templates_fav WHERE tid=? AND userid=?";
        $stmt = $mysqli->prepare($sql);
        $stmt->bind_param("ii", $_POST['id'], $_SESSION['auth_userid']);
        $stmt->execute();
        $stmt->reset();
    } else {
        $sql = "INSERT INTO email_templates_fav (tid, userid) VALUES (?, ?)";
        $stmt = $mysqli->prepare($sql);
        $stmt->bind_param("ii", $_POST['id'], $_SESSION['auth_userid']);
        $stmt->execute();
        $stmt->reset();
    }

    echo "true";

    $mysqli->close();
    exit(0);
}

if ($n === 'salutation' && $t === 'Personen') {
    $sql = "INSERT INTO Personen_Prefs (persid, userid, salutation) VALUES (?, ?, ?)";
    $stmt = $mysqli->prepare($sql);
    $stmt->bind_param("iii", $_POST['id'], $_SESSION['auth_userid'], $_POST['v']);
    $stmt->execute();
    $stmt->reset();

    $sql = "UPDATE Personen_Prefs SET salutation=? WHERE persid=? AND userid=?";
    $stmt = $mysqli->prepare($sql);
    $stmt->bind_param("iii", $_POST['v'], $_POST['id'], $_SESSION['auth_userid']);
    $stmt->execute();
    $stmt->reset();

    echo "true";

    $mysqli->close();
    exit(0);
}

$sql = "UPDATE `" . $t . "` SET `" . $n . "`=? WHERE ID=? LIMIT 1;";
if (isset($_POST['idcell']) && $_POST['idcell'] != 'false') {
    $idcell = filter_input(INPUT_POST, 'idcell', FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_BACKTICK);
    $sql = "UPDATE `" . $t . "` SET `" . $n . "`=? WHERE `" . $idcell . "`=? LIMIT 1;";
    $bps = 'ss';
    if (isset($_POST['num']) && $_POST['num'] == 'true')
        $bps = 'is';
}
$stmt = $mysqli->prepare($sql);
#echo $sql . "|" . $bps . "|" . $_POST['v'] . "|" . $_POST['id'] . "@";

$stmt->bind_param($bps, $_POST['v'], $_POST['id']);
$stmt->execute();

preg_match_all('!\d+!', $mysqli->info, $m);
if ($m[0][0] == 1 || $m[0][1] == 1 || $stmt->affected_rows == 1)
    echo "true";
else
    echo "false";

$stmt->reset();
$mysqli->close();
exit(0);