-
Notifications
You must be signed in to change notification settings - Fork 4
/
email_save.php
executable file
·54 lines (42 loc) · 1.46 KB
/
email_save.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
<?php
/**
* Saves an email given a valid email ID with content and/or title and/or folder
*/
require_once "config.php";
if (isset($_REQUEST['id']) && is_numeric($_REQUEST['id'])) {
// is this a valid email?
$dbh = $pdo->prepare('SELECT id FROM emails WHERE id=?');
$dbh->execute(array($_REQUEST['id']));
$email = $dbh->fetch(PDO::FETCH_ASSOC);
if ($email) {
// what are we saving?
$properties = array();
if (isset($_REQUEST['content'])) $properties['content'] = $_REQUEST['content'];
if (isset($_REQUEST['email_name'])) $properties['email_name'] = $_REQUEST['email_name'];
if (isset($_REQUEST['folder'])) $properties['folder'] = $_REQUEST['folder'];
if (!empty($properties)) {
$query = "UPDATE emails SET ";
foreach ($properties as $key => $value) {
$query .= $key . " = ?, ";
}
$query .= "date_updated = now() where id = " . $email['id'];
try {
$pdo->beginTransaction();
$dbh = $pdo->prepare($query);
$dbh->execute(array_values($properties));
$pdo->commit();
echo json_encode(array('success' => true));
} catch (PDOException $e) {
$pdo->rollBack();
echo json_encode(array('success' => false, 'message' => $e->getMesage()));
}
} else {
echo json_encode(array('success' => false, 'message' => "Nothing saved"));
}
} else {
echo json_encode(array('success' => false, 'message' => "Invalid Email ID"));
}
} else {
echo json_encode(array('success' => false, 'message' => "Invalid Email ID"));
}
?>