/
templates.php
76 lines (58 loc) · 2.47 KB
/
templates.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
<?php
class PHPlist_API_Templates{
static function templatesGet() {
PHPlist_API_Common::select( 'Templates', "SELECT * FROM " . $GLOBALS['table_prefix'] . "template ORDER BY listorder;" );
}
static function templateGet( $id=0 ) {
if ( $id==0 ) $id = $_REQUEST['id'];
PHPlist_API_Common::select( 'Template', "SELECT * FROM " . $GLOBALS['table_prefix'] . "template WHERE id=" . $id . ";", true );
}
static function templateGetByTitle( $title='' ) {
if ( empty($title) ) $title = $_REQUEST['title'];
PHPlist_API_Common::select( 'Template', "SELECT * FROM " . $GLOBALS['table_prefix'] . "template WHERE title='" . $title . "';", true );
}
static function templateAdd(){
$sql = "INSERT INTO " . $GLOBALS['table_prefix'] . "template (title, template) VALUES (:title, :template);";
try {
$db = PHPlist_API_PDO::getConnection();
$stmt = $db->prepare($sql);
$stmt->bindParam("title", $_REQUEST['title']);
$stmt->bindParam("template", $_REQUEST['template']);
$stmt->execute();
$id = $db->lastInsertId();
$db = null;
PHPlist_API_Templates::templateGet( $id );
} catch(PDOException $e) {
PHPlist_API_Response::outputError($e);
}
}
static function templateUpdate(){
$sql = "UPDATE " . $GLOBALS['table_prefix'] . "template SET title=:title, template=:template WHERE id=:id;";
try {
$db = PHPlist_API_PDO::getConnection();
$stmt = $db->prepare($sql);
$stmt->bindParam("id", $_REQUEST['id']);
$stmt->bindParam("title", $_REQUEST['title']);
$stmt->bindParam("template", $_REQUEST['template']);
$stmt->execute();
$db = null;
PHPlist_API_Templates::templateGet( $_REQUEST['id'] );
} catch(PDOException $e) {
PHPlist_API_Response::outputError($e);
}
}
static function templateDelete(){
$sql = "DELETE FROM " . $GLOBALS['table_prefix'] . "template WHERE id=:id;";
try {
$db = PHPlist_API_PDO::getConnection();
$stmt = $db->prepare($sql);
$stmt->bindParam("id", $_REQUEST['id']);
$stmt->execute();
$db = null;
PHPlist_API_Response::outputDeleted( 'Template', $_REQUEST['id'] );
} catch(PDOException $e) {
PHPlist_API_Response::outputError($e);
}
}
}
?>