-
Notifications
You must be signed in to change notification settings - Fork 30
/
campaigns.php
178 lines (162 loc) · 7.05 KB
/
campaigns.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
<?php
namespace phpListRestapi;
defined('PHPLISTINIT') || die;
/**
* Class Campaigns
* Manage phplist Campaigns.
*/
class Campaigns
{
public static function campaignGet($id = 0)
{
if ($id == 0) {
$id = $_REQUEST['id'];
}
$params = array(
'id' => array($id,PDO::PARAM_INT),
);
Common::select('Campaign', 'SELECT * FROM '.$GLOBALS['tables']['message'].' WHERE id=:id;',$params, true);
}
public static function campaignsCount()
{
Common::select('Campaign', 'SELECT count(id) as total FROM '.$GLOBALS['tables']['message'],array(),true);
}
/**
* Get all the Campaigns in the system.
*
* <p><strong>Parameters:</strong><br/>
* [order_by] {string} name of column to sort, default "id".<br/>
* [order] {string} sort order asc or desc, default: asc.<br/>
* [limit] {integer} limit the result, default 10 (max 10)<br/>
* [offset] {integer} offset of the result, default 0.<br/>
* </p>
* <p><strong>Returns:</strong><br/>
* List of Campaigns.
* </p>
*/
public static function campaignsGet($order_by = 'modified', $order = 'desc', $limit = 10, $offset = 0)
{
if (isset($_REQUEST['order_by']) && !empty($_REQUEST['order_by'])) {
$order_by = $_REQUEST['order_by'];
$order_by = preg_replace('/[^a-zA-Z0-9_$]/', '', $order_by);
if (isset($_REQUEST['order']) && !empty($_REQUEST['order']) &&
(strtolower($_REQUEST['order'] == 'asc') || strtolower($_REQUEST['order'] == 'desc'))) {
$order = $_REQUEST['order'];
}
}
if (isset($_REQUEST['limit']) && !empty($_REQUEST['limit'])) {
$limit = intval($_REQUEST['limit']);
}
if (isset($_REQUEST['offset']) && !empty($_REQUEST['offset'])) {
$offset = intval($_REQUEST['offset']);
}
if ($limit > 10) {
$limit = 10;
}
$params = array (
'limit' => array($limit,PDO::PARAM_INT),
'offset' => array($offset,PDO::PARAM_INT),
);
Common::select('Campaigns', 'SELECT * FROM '.$GLOBALS['tables']['message']." ORDER BY $order_by $order LIMIT :limit OFFSET :offset;",$params);
}
/**
* Add a new campaign.
*
* <p><strong>Parameters:</strong><br/>
* [*subject] {string} <br/>
* [*fromfield] {string} <br/>
* [*replyto] {string} <br/>
* [*message] {string} <br/>
* [*textmessage] {string} <br/>
* [*footer] {string} <br/>
* [*status] {string} <br/>
* [*sendformat] {string} <br/>
* [*template] {string} <br/>
* [*embargo] {string} <br/>
* [*rsstemplate] {string} <br/>
* [*owner] {string} <br/>
* [htmlformatted] {string} <br/>
* <p><strong>Returns:</strong><br/>
* The message added.
* </p>
*/
public static function campaignAdd()
{
$sql = 'INSERT INTO '.$GLOBALS['tables']['message'].' (subject, fromfield, replyto, message, textmessage, footer, entered, status, sendformat, template, embargo, rsstemplate, owner, htmlformatted ) VALUES ( :subject, :fromfield, :replyto, :message, :textmessage, :footer, now(), :status, :sendformat, :template, :embargo, :rsstemplate, :owner, :htmlformatted );';
try {
$db = PDO::getConnection();
$stmt = $db->prepare($sql);
$stmt->bindParam('subject', $_REQUEST['subject'], PDO::PARAM_STR);
$stmt->bindParam('fromfield', $_REQUEST['fromfield'], PDO::PARAM_STR);
$stmt->bindParam('replyto', $_REQUEST['replyto'], PDO::PARAM_STR);
$stmt->bindParam('message', $_REQUEST['message'], PDO::PARAM_STR);
$stmt->bindParam('textmessage', $_REQUEST['textmessage'], PDO::PARAM_STR);
$stmt->bindParam('footer', $_REQUEST['footer'], PDO::PARAM_STR);
$stmt->bindParam('status', $_REQUEST['status'], PDO::PARAM_STR);
$stmt->bindParam('sendformat', $_REQUEST['sendformat'], PDO::PARAM_STR);
$stmt->bindParam('template', $_REQUEST['template'], PDO::PARAM_INT);
$stmt->bindParam('embargo', $_REQUEST['embargo'], PDO::PARAM_STR);
$stmt->bindParam('rsstemplate', $_REQUEST['rsstemplate'], PDO::PARAM_STR);
$stmt->bindParam('owner', $_REQUEST['owner'], PDO::PARAM_INT);
$stmt->bindParam('htmlformatted', $_REQUEST['htmlformatted'], PDO::PARAM_STR);
$stmt->execute();
$id = $db->lastInsertId();
$db = null;
self::campaignGet($id);
} catch (\Exception $e) {
Response::outputError($e);
}
}
/**
* Update existing campaign.
*
* <p><strong>Parameters:</strong><br/>
* [*id] {integer} <br/>
* [*subject] {string} <br/>
* [*fromfield] {string} <br/>
* [*replyto] {string} <br/>
* [*message] {string} <br/>
* [*textmessage] {string} <br/>
* [*footer] {string} <br/>
* [*status] {string} <br/>
* [*sendformat] {string} <br/>
* [*template] {string} <br/>
* [*embargo] {string} <br/>
* [*rsstemplate] {string} <br/>
* [owner] {string} <br/>
* [htmlformatted] {string} <br/>
* <p><strong>Returns:</strong><br/>
* The message added.
* </p>
*/
public static function campaignUpdate($id = 0)
{
if ($id == 0) {
$id = $_REQUEST['id'];
}
$sql = 'UPDATE '.$GLOBALS['tables']['message'].' SET subject=:subject, fromfield=:fromfield, replyto=:replyto, message=:message, textmessage=:textmessage, footer=:footer, status=:status, sendformat=:sendformat, template=:template, sendstart=:sendstart, rsstemplate=:rsstemplate, owner=:owner, htmlformatted=:htmlformatted WHERE id=:id;';
try {
$db = PDO::getConnection();
$stmt = $db->prepare($sql);
$stmt->bindParam('id', $id, PDO::PARAM_INT);
$stmt->bindParam('subject', $_REQUEST['subject'], PDO::PARAM_STR);
$stmt->bindParam('fromfield', $_REQUEST['fromfield'], PDO::PARAM_STR);
$stmt->bindParam('replyto', $_REQUEST['replyto'], PDO::PARAM_STR);
$stmt->bindParam('message', $_REQUEST['message'], PDO::PARAM_STR);
$stmt->bindParam('textmessage', $_REQUEST['textmessage'], PDO::PARAM_STR);
$stmt->bindParam('footer', $_REQUEST['footer'], PDO::PARAM_STR);
$stmt->bindParam('status', $_REQUEST['status']);
$stmt->bindParam('sendformat', $_REQUEST['sendformat'], PDO::PARAM_STR);
$stmt->bindParam('template', $_REQUEST['template'], PDO::PARAM_INT);
$stmt->bindParam('embargo', $_REQUEST['embargo'], PDO::PARAM_STR);
$stmt->bindParam('rsstemplate', $_REQUEST['rsstemplate'], PDO::PARAM_STR);
$stmt->bindParam('owner', $_REQUEST['owner'], PDO::PARAM_INT);
$stmt->bindParam('htmlformatted', $_REQUEST['htmlformatted'], PDO::PARAM_BOOL);
$stmt->execute();
$db = null;
self::campaignGet($id);
} catch (\Exception $e) {
Response::outputError($e);
}
}
}