1<?php
2/**
3 * Add default templates including default system template
4 */
5
6/**
7 * Define template contents
8 */
9$systemTemplate = <<<EOD
10<div style="margin:0; text-align:center; width:100%; background:#EEE;min-width:240px;height:100%;"><br />
11    <div style="width:96%;margin:0 auto; border-top:6px solid #369;border-bottom: 6px solid #369;background:#DEF;" >
12        <h3 style="margin-top:5px;background-color:#69C; font-weight:normal; color:#FFF; text-align:center; margin-bottom:5px; padding:10px; line-height:1.2; font-size:21px; text-transform:capitalize;">[SUBJECT]</h3>
13        <div style="text-align:justify;background:#FFF;padding:20px; border-top:2px solid #369;min-height:200px;font-size:13px; border-bottom:2px solid #369;">[CONTENT]<div style="clear:both"></div></div>
14        <div style="clear:both;background:#69C;font-weight:normal; padding:10px;color:#FFF;text-align:center;font-size:11px;margin:5px 0px">[FOOTER]<br/>[SIGNATURE]</div>
15    </div>
16<br /></div>
17EOD;
18
19/**
20 * Really Simple Free Responsive HTML Email Template
21 * @author Lee Munroe
22 * @author Angel Gonzalez
23 * @link https://github.com/algzb/responsive-html-email-template-for-PHPLIST
24 * @link https://github.com/leemunroe/responsive-html-email-template
25 * @license
26 *
27 * The MIT License (MIT)
28 *
29 * Copyright (c) [2013] [Lee Munroe]
30 *
31 * Permission is hereby granted, free of charge, to any person obtaining a copy
32 * of this software and associated documentation files (the "Software"), to deal
33 * in the Software without restriction, including without limitation the rights
34 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
35 * copies of the Software, and to permit persons to whom the Software is
36 * furnished to do so, subject to the following conditions:
37 *
38 * The above copyright notice and this permission notice shall be included in all
39 * copies or substantial portions of the Software.
40 *
41 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
42 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
43 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
44 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
45 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
46 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
47 * SOFTWARE.
48 */
49$simpleResponsiveTemplate = <<<EOD
50<!doctype html>
51<html>
52    <head><meta name="viewport" content="width=device-width" /><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
53	    <title>[SUBJECT]</title>
54	    <style type="text/css">/* -------------------------------------
55              GLOBAL RESETS
56          ------------------------------------- */
57
58          /*All the styling goes here*/
59
60          img {
61            border: none;
62            -ms-interpolation-mode: bicubic;
63            max-width: 100%;
64          }
65
66          /* -------------------------------------
67              BODY & CONTAINER
68          ------------------------------------- */
69          .body {
70            background-color: #f6f6f6;
71            width: 100%;
72          }
73          /* Set a max-width, and make it display as block so it will automatically stretch to that width, but will also shrink down on a phone or something */
74          .templatecontainer {
75            display: block;
76            margin: 0 auto !important;
77            /* makes it centered */
78            max-width: 580px;
79            padding: 10px;
80            width: 580px;
81          }
82          .logo {
83          padding-bottom: 10px;
84          }
85
86          /* This should also be a block element, so that it will fill 100% of the .container */
87          .templatecontent {
88            box-sizing: border-box;
89            display: block;
90            margin: 0 auto;
91            max-width: 580px;
92            padding: 10px;
93          }
94          /* -------------------------------------
95              HEADER, FOOTER, MAIN
96          ------------------------------------- */
97          .main {
98            background: #ffffff;
99            border-radius: 3px;
100            width: 100%;
101          }
102          .wrapper {
103            box-sizing: border-box;
104            padding: 20px;
105          }
106          .templatecontent-block {
107            padding-bottom: 10px;
108            padding-top: 10px;
109          }
110          .footer {
111            clear: both;
112            margin-top: 10px;
113            text-align: center;
114            width: 100%;
115          }
116            .footer td,
117            .footer p,
118            .footer span,
119            .footer a {
120              color: #999999;
121              font-size: 12px;
122              text-align: center;
123          }
124          /* -------------------------------------
125              TYPOGRAPHY
126          ------------------------------------- */
127          h1,
128          h2,
129          h3,
130          h4 {
131            color: #000000;
132            font-family: sans-serif;
133            font-weight: 400;
134            line-height: 1.4;
135            margin: 0;
136            margin-bottom: 30px;
137          }
138          h1 {
139            font-size: 35px;
140            font-weight: 300;
141            text-align: center;
142            text-transform: capitalize;
143          }
144          p,
145          ul,
146          ol {
147            font-family: sans-serif;
148            font-size: 14px;
149            font-weight: normal;
150            margin: 0;
151            margin-bottom: 15px;
152          }
153            p li,
154            ul li,
155            ol li {
156              list-style-position: inside;
157              margin-left: 5px;
158          }
159          /* -------------------------------------
160              BUTTONS
161          ------------------------------------- */
162          .templatebtn {
163            box-sizing: border-box;
164            width: 100%; }
165            .templatebtn > tbody > tr > td {
166              padding-bottom: 15px; }
167            .templatebtn table {
168              width: auto;
169          }
170            .templatebtn table td {
171              background-color: #ffffff;
172              border-radius: 5px;
173              text-align: center;
174          }
175            .templatebtn a {
176              background-color: #ffffff;
177              border: solid 1px #3498db;
178              border-radius: 5px;
179              box-sizing: border-box;
180              color: #3498db;
181              cursor: pointer;
182              display: inline-block;
183              font-size: 14px;
184              font-weight: bold;
185              margin: 0;
186              padding: 12px 25px;
187              text-decoration: none;
188              text-transform: capitalize;
189          }
190          .templatebtn-primary table td {
191            background-color: #3498db;
192          }
193          .templatebtn-primary a {
194            background-color: #3498db;
195            border-color: #3498db;
196            color: #ffffff;
197          }
198          /* -------------------------------------
199              OTHER STYLES THAT MIGHT BE USEFUL
200          ------------------------------------- */
201          .last {
202            margin-bottom: 0;
203          }
204          .first {
205            margin-top: 0;
206          }
207          .align-center {
208            text-align: center;
209          }
210          .align-right {
211            text-align: right;
212          }
213          .align-left {
214            text-align: left;
215          }
216          .clear {
217            clear: both;
218          }
219          .mt0 {
220            margin-top: 0;
221          }
222          .mb0 {
223            margin-bottom: 0;
224          }
225          .preheader {
226            color: transparent;
227            display: none;
228            height: 0;
229            max-height: 0;
230            max-width: 0;
231            opacity: 0;
232            overflow: hidden;
233            mso-hide: all;
234            visibility: hidden;
235            width: 0;
236          }
237          .powered-by a {
238            text-decoration: none;
239          }
240          hr {
241            border: 0;
242            border-bottom: 1px solid #f6f6f6;
243            margin: 20px 0;
244          }
245          /* -------------------------------------
246              RESPONSIVE AND MOBILE FRIENDLY STYLES
247          ------------------------------------- */
248          @media only screen and (max-width: 620px) {
249            table[class=body] h1 {
250              font-size: 28px !important;
251              margin-bottom: 10px !important;
252            }
253            table[class=body] p,
254            table[class=body] ul,
255            table[class=body] ol,
256            table[class=body] td,
257            table[class=body] span,
258            table[class=body] a {
259              font-size: 16px !important;
260            }
261            table[class=body] .wrapper,
262            table[class=body] .article {
263              padding: 10px !important;
264            }
265            table[class=body] .templatecontent {
266              padding: 0 !important;
267            }
268            table[class=body] .templatecontainer {
269              padding: 0 !important;
270              width: 100% !important;
271            }
272            table[class=body] .main {
273              border-left-width: 0 !important;
274              border-radius: 0 !important;
275              border-right-width: 0 !important;
276            }
277            table[class=body] .templatebtn table {
278              width: 100% !important;
279            }
280            table[class=body] .templatebtn a {
281              width: 100% !important;
282            }
283            table[class=body] .img-responsive {
284              height: auto !important;
285              max-width: 100% !important;
286              width: auto !important;
287            }
288          }
289          /* -------------------------------------
290              PRESERVE THESE STYLES IN THE HEAD
291          ------------------------------------- */
292          @media all {
293            .ExternalClass {
294              width: 100%;
295            }
296            .ExternalClass,
297            .ExternalClass p,
298            .ExternalClass span,
299            .ExternalClass font,
300            .ExternalClass td,
301            .ExternalClass div {
302              line-height: 100%;
303            }
304            .apple-link a {
305              font-family: inherit !important;
306              font-size: inherit !important;
307              font-weight: bold !important;
308              line-height: inherit !important;
309            }
310            .templatebtn-primary table td:hover {
311              background-color: #34495e !important;
312            }
313            .templatebtn-primary a:hover {
314              background-color: #34495e !important;
315              border-color: #34495e !important;
316            }
317          }
318	    </style>
319    </head>
320    <body style=" background-color: #f6f6f6;font-family: sans-serif;-webkit-font-smoothing: antialiased;font-size: 14px;line-height: 1.4;margin: 0;padding: 0;-ms-text-size-adjust: 100%;-webkit-text-size-adjust: 100%;">
321    <p>&nbsp;</p>
322
323    <table border="0" cellpadding="0" cellspacing="0" class="body" role="presentation" style="border-collapse: separate;mso-table-lspace: 0pt;mso-table-rspace: 0pt;width: 100%;">
324	    <tbody>
325		    <tr>
326			    <td style="font-family: sans-serif;font-size: 14px;vertical-align: top;">&nbsp;</td>
327			    <td class="container" style="font-family: sans-serif;font-size: 14px;vertical-align: top;">
328			    <div class="templatecontent">
329			    <div class="logo">
330			    <center><img src="[LOGO]" /></center>
331			    </div>
332			    <!-- START CENTERED WHITE CONTAINER -->
333
334			    <table class="main" role="presentation" style="border-collapse: separate;mso-table-lspace: 0pt;mso-table-rspace: 0pt;width: 100%;"><!-- START MAIN CONTENT AREA -->
335				    <tbody>
336					    <tr>
337						    <td class="wrapper" style="font-family: sans-serif;font-size: 14px;vertical-align: top;">
338						    <table border="0" cellpadding="0" cellspacing="0" role="presentation" style="border-collapse: separate;mso-table-lspace: 0pt;mso-table-rspace: 0pt;width: 100%;">
339							    <tbody>
340								    <tr>
341									    <td style="font-family: sans-serif;font-size: 14px;vertical-align: top;">
342                                            <span class="preheader">This is preheader text. Some clients will show this text as a preview.</span>
343                                            [CONTENT]
344                                        </td>
345								    </tr>
346							    </tbody>
347						    </table>
348						    </td>
349					    </tr>
350					    <!-- END MAIN CONTENT AREA -->
351				    </tbody>
352			    </table>
353			    <!-- START FOOTER -->
354
355			    <div class="footer">
356			    <table border="0" cellpadding="0" cellspacing="0" role="presentation" style="border-collapse: separate;mso-table-lspace: 0pt;mso-table-rspace: 0pt;width: 100%;">
357				    <tbody>
358					    <tr>
359						   <td class="templatecontent-block" style="font-family: sans-serif;font-size: 13px;vertical-align: top;">
360                                                    <span class="apple-link">[FOOTER]</span>
361						    <div>
362                                <div style="color: #3498db; text-decoration: underline;">[CONTACT]</div>|<div>
363                                <a href="[FORWARDURL]" style="color: #3498db; text-decoration: underline;">Forward this message</a></div>
364                                                    </div>
365						    </td>
366					    </tr>
367				    </tbody>
368			    </table>
369			    </div>
370			    <!-- END FOOTER --><!-- END CENTERED WHITE CONTAINER --></div>
371			    </td>
372			    <td>&nbsp;</td>
373		    </tr>
374	    </tbody>
375    </table>
376    </body>
377</html>
378EOD;
379
380/**
381 * Handle requests to add template
382 */
383if (isset($_POST['Submit'])) {
384    $radioVal = $_POST['template'];
385    switch ($radioVal) {
386        case 'systemTemplate':
387            $title = "System template";
388            $content = $systemTemplate;
389            break;
390
391        case 'simpleResponsiveTemplate':
392            $title = "Simple responsive template";
393            $content = $simpleResponsiveTemplate;
394            break;
395    }
396    $exists = Sql_Fetch_Row_Query(sprintf('
397        select
398            *
399        from
400            %s
401        where
402            title = "%s"'
403        , $GLOBALS['tables']['template']
404        , $title
405    ));
406
407    if ($exists[0]) {
408        $messages = '<div class="actionresult alert alert-warning">';
409        $messages .= s('This default template already exists');
410        $messages .= '</div>';
411        echo $messages;
412        echo '<p>';
413        echo PageLinkButton('templates', s('Go back to templates'));
414        echo '</p>';
415    } else {
416        Sql_Query(sprintf('insert into %s (title,template,template_text,listorder) values("%s","%s","[CONTENT]",0)',
417            $GLOBALS['tables']['template'], $title, addslashes($content)));
418        $newid = Sql_Insert_Id();
419        if ($title === 'System template') {
420            saveConfig('systemmessagetemplate', $newid);
421        }
422        $messages = '<div class="actionresult alert alert-success">';
423        $messages .= s('The selected default template has been added as template with ID') . ' ' . $newid . ' ';
424        $messages .= '</div>';
425        echo $messages;
426        echo '<p>';
427        echo '' . PageLinkButton('templates', s('Go back to templates')) . '';
428        echo '' . PageLinkButton('template&amp;id=' . $newid, s('Edit the added template')) . '';
429        echo '</p>';
430    }
431}
432
433/**
434 * Print page contents
435 */
436echo '<h2>'.s('Default templates suite').'</h2>';
437
438echo formStart();
439echo '
440    <div>
441      <input type="radio" name="template" value="systemTemplate" checked>System template<br>
442      <input type="radio" name="template" value="simpleResponsiveTemplate">Simple responsive template<br>
443      <input type="submit" value="Select"  name="Submit">
444    </form>
445</div>';
446