-
Notifications
You must be signed in to change notification settings - Fork 1
/
preview.php
executable file
·284 lines (258 loc) · 9.4 KB
/
preview.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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
<?php
require_once('config.php');
require_once('db.php');
require_once('mail.php');
$db = new db($dbLang, $dbName);
$rights = checklogin($access);
$usr_id = -1;
if ($gCurrentUser)
$usr_id = $gCurrentUser->getValue('usr_id');
$header_location = "Location: " . $baseUrl . "login.php";
if ($rights == 0)
{
header("$header_location");
}
$selector = $rights == 1 ? 'pref_id > 0' : "pref_id = $rights OR pref_id = -$rights";
$articles = $db->query("SELECT * FROM content WHERE $selector ORDER BY pref_id");
foreach ($articles as $article) {
if($rights == 1 && $article['pref_id'] == 1) {
$main_text = explode("%%LO CONTENT%%", stripslashes($article['content']));
}
else if ($rights != 1 && $article['pref_id'] == $rights) {
$main_text = array(stripslashes($article['content']),"");
}
else {
if(isset($article['second_eyes_usr_id']) && $article['pref_id'] > 0) {
$lo = decodePrefs($article['pref_id']);
$pre = "--------------- Information der LO " . $lo[0] . " ";
$pre .= str_repeat("-", 72 - strlen(mb_convert_encoding($pre,'ISO-8859-15','UTF-8'))) . "\n";
$post = "\n" . str_repeat("-", strlen(mb_convert_encoding($pre,'ISO-8859-15','UTF-8')) - 1) . "\n";
if (strlen(stripslashes($article['content'])) > 10)
$lo_text[] = $pre . stripslashes($article['content']) . $post;
}
}
}
$preview_text_lo = implode('<br><br>', $lo_text);
$preview_text = $main_text[0].'<br><br>'.$preview_text_lo.'<br><br>'.$main_text[1];
$testmail = false;
$eyes = " first_eyes_usr_id IS NOT NULL AND second_eyes_usr_id IS NOT NULL ";
if (isset($_POST['test']) && isset($_POST['testmail']))
{
$testmail = true;
$eyes = " 1 ";
}
$sendbo = $db->query("SELECT * FROM content WHERE " . $eyes . " AND pref_id = $rights;");
$sendsubject = $db->query("SELECT * FROM content WHERE " . $eyes . " AND pref_id = -$rights;");
$sendlos = $db->query("SELECT * FROM content WHERE " . $eyes . " AND pref_id != 1 AND pref_id > 0;");
if (count($sendbo) == 1)
$mailtext = stripslashes($sendbo[0]['content']);
$subject_r = $db->query("SELECT * FROM content WHERE pref_id = -$rights;");
if (count($subject_r) == 1)
$subject = stripslashes($subject_r[0]['content']);
else
$subject = '';
$users = $db->query("SELECT * FROM users WHERE confirmed AND prefs & $rights");
if (count($sendbo) == 1 && count($sendsubject) == 1)
{
$may_send_mails = true;
}
if ($testmail)
{
$mailaddr = $db->escape($_POST['testmail']);
$users = $db->query("SELECT * FROM users WHERE confirmed AND prefs & $rights AND email = $mailaddr LIMIT 1");
}
if ($testmail || (isset($_POST['sendmails']) && $may_send_mails)) {
if (!($rights > 0))
{
header("$header_location");
}
$sendmails = true;
$may_send_mails = false;
}
$db->close();
end:
?>
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="utf-8">
<title>Piraten-Newsletter</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Hier können sich Interessenten und Mitglieder für den Newsletter der Piratenpartei Österreichs anmelden.">
<meta name="author" content="Piratenpartei Österreichs">
<!-- Le styles -->
<link href="css/bootstrap.css" rel="stylesheet">
<style type="text/css">
body {
background-color: #4c2582;
padding-top: 60px;
padding-bottom: 40px;
}
footer {
color: white;
}
</style>
<link href="css/bootstrap-responsive.css" rel="stylesheet">
<!-- Fav and touch icons
<link rel="shortcut icon" href="ico/favicon.ico">
<link rel="apple-touch-icon-precomposed" sizes="144x144" href="ico/apple-touch-icon-144-precomposed.png">
<link rel="apple-touch-icon-precomposed" sizes="114x114" href="ico/apple-touch-icon-114-precomposed.png">
<link rel="apple-touch-icon-precomposed" sizes="72x72" href="ico/apple-touch-icon-72-precomposed.png">
<link rel="apple-touch-icon-precomposed" href="ico/apple-touch-icon-57-precomposed.png">-->
</head>
<body>
<div class="container">
<div class="row">
<?php
if ($sendmails)
{
echo '
<div class="span12">
<div class="well">
<h3 id="please_wait">Bitte warten...</h3>
<p>
';
$db = new db($dbLang, $dbName);
if (!$testmail)
{
if ($rights == 1)
$db->query("UPDATE content SET first_eyes_usr_id = NULL, second_eyes_usr_id = NULL;");
else
$db->query("UPDATE content SET first_eyes_usr_id = NULL, second_eyes_usr_id = NULL WHERE pref_id = $rights OR pref_id = -$rights;");
}
$user_count = count($users);
$nth = 10;
$lo_real_id = 1;
foreach ($users as $user)
{
if ($rights != 1)
{
$user_mailtext = stripslashes($sendbo[0]['content']);
$lo_real_id = $sendbo[0]['pref_id'];
}
else
{
$lo_mailtext = '';
foreach ($sendlos as $sendlo)
{
$lo = decodePrefs($sendlo['pref_id']);
$pre = "--------------- Information der LO " . $lo[0] . " ";
$pre .= str_repeat("-", 72 - strlen(mb_convert_encoding($pre,'ISO-8859-15','UTF-8'))) . "\n";
$post = "\n" . str_repeat("-", strlen(mb_convert_encoding($pre,'ISO-8859-15','UTF-8')) - 1) . "\n";
if (strlen(stripslashes($article['content'])) > 10 && intval($sendlo['pref_id']) & intval($user['prefs']))
$lo_mailtext .= $pre . stripslashes($sendlo['content']) . $post;
}
$user_mailtext = str_replace('%%LO CONTENT%%',$lo_mailtext,$mailtext);
$lo_real_id = 1;
}
mail_utf8($db,$user['email'], "$subject", $user_mailtext, from_header($lo_real_id), change_link($user['sid']));
if ($testmail)
{
echo '<p>Versand an ' . $user['email'] . " erfolgt.</p>\n";
}
$i++;
if ($i % ($user_count / $nth) == 0) {
echo $i . " / " . $user_count . "<br />";
}
}
echo '
</p>
';
if ($i > 0)
echo '
<h3>Versand wird in den nächsten 10 Minuten abgeschlossen.</h3>
';
echo '
<script type="text/javascript">document.getElementById("please_wait").style.display="none";</script>
</div>
</div><!--/span-->
';
if (!$testmail)
{
if ($rights == 1)
$db->query("UPDATE content SET first_eyes_usr_id = NULL, second_eyes_usr_id = NULL;");
else
$db->query("UPDATE content SET first_eyes_usr_id = NULL, second_eyes_usr_id = NULL WHERE pref_id = $rights OR pref_id = -$rights;");
}
$db->close();
}?>
<div class="span8">
<div class="well">
<h1>Vorschau</h1>
<p><form action="preview.php" method="POST">
<?php
if ($may_send_mails)
echo '
<input type="hidden" name="sendmails" value="true" />
<input type="submit" class="btn btn-success" value="Newsletter aussenden" />
';
?>
<a class="btn" href="create.php">Newsletter bearbeiten</a>
<textarea style="width:180px;" rows="1" name="testmail"></textarea>
<input type="submit" class="btn btn-success" name="test" value="Test an diese Mailadresse aussenden" />
</form></p>
<p>Betreff: <?php echo $subject;?></p>
<p><?php echo "<pre>".$preview_text."</pre>";?></p>
</div>
</div>
<div class="span4">
<?php
$article = $subject_r[0];
$admins = "";
$prefs = decodePrefs($article['pref_id']);
$send = true;
if (isset($article['first_eyes_usr_id'])) {$admins[] = $article['first_eyes_usr_id'];}
if (isset($article['second_eyes_usr_id'])) {$admins[] = $article['second_eyes_usr_id'];} else {$send = false;}
$admins = getAdminNames($admins);
if ($send) {$send_color = "alert-success";} else {$send_color = "alert-danger";}
echo '
<div class="alert '.$send_color.'">
<p>Betreff '.$prefs[0].'</br>
Versandfreigabe erfolgt durch: '.implode(", ", $admins).'</p>
</div>
';
foreach ($articles as $article)
{
if ($article['pref_id'] < 0) {continue;}
if ($rights != 1 && !(intval($article['pref_id']) & $rights))
continue;
$admins = "";
$prefs = decodePrefs($article['pref_id']);
$send = true;
if (isset($article['first_eyes_usr_id'])) {$admins[] = $article['first_eyes_usr_id'];}
if (isset($article['second_eyes_usr_id'])) {$admins[] = $article['second_eyes_usr_id'];} else {$send = false;}
$admins = getAdminNames($admins);
if ($send) {$send_color = "alert-success";} else {$send_color = "alert-danger";}
echo '
<div class="alert '.$send_color.'">
<p>Bereich: '.$prefs[0].'</br>
Versandfreigabe erfolgt durch: '.implode(", ", $admins).'</p>
</div>
';
}
?>
</div>
</div><!--/span-->
</div><!--/row-->
<footer>
<p><a href="https://wiki.piratenpartei.at/wiki/Piratenwiki:Impressum">Impressum</a></p>
</footer>
</div><!--/.fluid-container-->
<!-- Le javascript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script src="js/jquery.js"></script>
<script src="js/bootstrap-transition.js"></script>
<script src="js/bootstrap-alert.js"></script>
<script src="js/bootstrap-modal.js"></script>
<script src="js/bootstrap-dropdown.js"></script>
<script src="js/bootstrap-scrollspy.js"></script>
<script src="js/bootstrap-tab.js"></script>
<script src="js/bootstrap-tooltip.js"></script>
<script src="js/bootstrap-popover.js"></script>
<script src="js/bootstrap-button.js"></script>
<script src="js/bootstrap-collapse.js"></script>
<script src="js/bootstrap-carousel.js"></script>
<script src="js/bootstrap-typeahead.js"></script>
</body>
</html>