360b039ae0d57e0e754fe49d4afd01b2ed20cdba
[mailer.git] / inc / extensions / ext-newsletter.php
1 <?php
2 /************************************************************************
3  * Mailer v0.2.1-FINAL                                Start: 02/26/2005 *
4  * ===================                          Last change: 02/26/2005 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : ext-newsletter.php                               *
8  * -------------------------------------------------------------------- *
9  * Short description : Extension for sending newsletters                *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Erweiterung zum Versenden von Newslettern        *
12  * -------------------------------------------------------------------- *
13  * $Revision::                                                        $ *
14  * $Date::                                                            $ *
15  * $Tag:: 0.2.1-FINAL                                                 $ *
16  * $Author::                                                          $ *
17  * Needs to be in all Files and every File needs "svn propset           *
18  * svn:keywords Date Revision" (autoprobset!) at least!!!!!!            *
19  * -------------------------------------------------------------------- *
20  * Copyright (c) 2003 - 2009 by Roland Haeder                           *
21  * For more information visit: http://www.mxchange.org                  *
22  *                                                                      *
23  * This program is free software; you can redistribute it and/or modify *
24  * it under the terms of the GNU General Public License as published by *
25  * the Free Software Foundation; either version 2 of the License, or    *
26  * (at your option) any later version.                                  *
27  *                                                                      *
28  * This program is distributed in the hope that it will be useful,      *
29  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
30  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
31  * GNU General Public License for more details.                         *
32  *                                                                      *
33  * You should have received a copy of the GNU General Public License    *
34  * along with this program; if not, write to the Free Software          *
35  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
36  * MA  02110-1301  USA                                                  *
37  ************************************************************************/
38
39 // Some security stuff...
40 if (!defined('__SECURITY')) {
41         die();
42 } // END - if
43
44 // Version number
45 setThisExtensionVersion('0.2.0');
46
47 // Version history array (add more with , '0.1.0' and so on)
48 setExtensionVersionHistory(array('0.0', '0.0.1', '0.0.2', '0.0.3', '0.0.4', '0.0.5', '0.0.6', '0.0.7', '0.0.8', '0.0.9', '0.1.0', '0.1.1', '0.1.2', '0.2.0'));
49
50 switch (getExtensionMode()) {
51         case 'register': // Do stuff when installation is running (modules.php?module=admin is called)
52                 // SQL commands to run
53                 addExtensionSql('');
54                 break;
55
56         case 'remove': // Do stuff when removing extension
57                 // SQL commands to run
58                 addExtensionSql("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_admin_menu` WHERE `action`='newsletter'");
59                 addExtensionSql("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_member_menu` WHERE `what`='newsletter'");
60                 addExtensionSql("DROP TABLE IF EXISTS `{?_MYSQL_PREFIX?}_newsletter_data`");
61                 addExtensionSql("DROP TABLE IF EXISTS `{?_MYSQL_PREFIX?}_newsletter_topics`");
62                 addExtensionSql("DROP TABLE IF EXISTS `{?_MYSQL_PREFIX?}_newsletter_orders`");
63                 break;
64
65         case 'activate': // Do stuff when admin activates this extension
66                 // SQL commands to run
67                 addExtensionSql("UPDATE `{?_MYSQL_PREFIX?}_member_menu` SET `locked`='N', `visible`='Y' WHERE `what`='newsletter' LIMIT 1");
68                 break;
69
70         case 'deactivate': // Do stuff when admin deactivates this extension
71                 // SQL commands to run
72                 addExtensionSql("UPDATE `{?_MYSQL_PREFIX?}_member_menu` SET `locked`='Y', `visible`='N' WHERE `what`='newsletter' LIMIT 1");
73                 break;
74
75         case 'update': // Update an extension
76                 switch (getCurrentExtensionVersion()) {
77                         case '0.0.1': // SQL queries for v0.0.1
78                                 addAdminMenuSql('newsletter', NULL, 'Newsletter','Einstellungen am Newsletter, Newsletter versenden, usw.', 3);
79                                 addAdminMenuSql('newsletter','config_newsletter','Einstellungen','Einstellungen am Newsletter vornehmen.', 3);
80                                 addExtensionSql("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_admin_menu` WHERE `what`='newsletter' LIMIT 1");
81                                 addMemberMenuSql('main','newsletter','Newsletter-Empfang','N','Y', 10);
82                                 addExtensionSql("ALTER TABLE `{?_MYSQL_PREFIX?}_user_data` ADD `nl_receive` ENUM('Y','N') NOT NULL DEFAULT 'Y'");
83
84                                 // Update notes (these will be set as task text!)
85                                 setExtensionUpdateNotes("Men&uuml;punkte hinzuf&uuml;gen und Mitgliedereinstellung.");
86                                 break;
87
88                         case '0.0.2': // SQL queries for v0.0.2
89                                 // Update notes (these will be set as task text!)
90                                 setExtensionUpdateNotes("URL im Versendeformular und Option <em>Immer aktiv</em> f&uuml;r diese Erweiterung deaktiviert.");
91                                 break;
92
93                         case '0.0.3': // SQL queries for v0.0.3
94                                 // Update notes (these will be set as task text!)
95                                 setExtensionUpdateNotes("W&ouml;rter <strong>{?mt_word?}</strong>, <strong>{?mt_word2?}</strong> und <strong>{?mt_word3?}</strong> sind austauschbar.");
96                                 break;
97
98                         case '0.0.4': // SQL queries for v0.0.4
99                                 // Update notes (these will be set as task text!)
100                                 setExtensionUpdateNotes("HTML-Code ausgelagert in Templates und SQL-Anweisungen abgesichert.");
101                                 break;
102
103                         case '0.0.5': // SQL queries for v0.0.5
104                                 // Update notes (these will be set as task text!)
105                                 setExtensionUpdateNotes("Abspeichern von Einstellungen repariert.");
106                                 break;
107
108                         case '0.0.6': // SQL queries for v0.0.6
109                                 // Update notes (these will be set as task text!)
110                                 setExtensionUpdateNotes("Bitte Script inc/monthly_newsletter.php l&ouml;schen!");
111                                 break;
112
113                         case '0.0.7': // SQL queries for v0.0.7
114                                 // Update notes (these will be set as task text!)
115                                 setExtensionUpdateNotes("Script <strong>inc/monthly/monthly_newsletter.php</strong> wird nicht mehr ausgef&uuml;hrt, wenn die Erweiterung nicht aktiviert ist.");
116                                 break;
117
118                         case '0.0.8': // SQL queries for v0.0.8
119                                 // Update notes (these will be set as task text!)
120                                 setExtensionUpdateNotes("Sicherheitsupdate f&uuml;r die Include-Befehle.");
121                                 break;
122
123                         case '0.0.9': // SQL queries for v0.0.9
124                                 // Update notes (these will be set as task text!)
125                                 setExtensionUpdateNotes("Nur bei installierter Erweiterung <strong>html_mail</strong> k&ouml;nnen Sie auch HTML-Mails versenden.");
126                                 break;
127
128                         case '0.1.0': // SQL queries for v0.2.1
129                                 // Update notes (these will be set as task text!)
130                                 setExtensionUpdateNotes("Nur bei installierter Erweiterung <strong>html_mail</strong> k&ouml;nnen Sie auch HTML-Mails versenden.");
131                                 break;
132
133                         case '0.1.1': // SQL queries for v0.1.1
134                                 // Update notes (these will be set as task text!)
135                                 setExtensionUpdateNotes("W&auml;hrung auf die Erweiterung <a href=\"#\"><strong>ext-other.zip</strong></a> verlagert. Bitte auch diese aktualisieren.");
136                                 break;
137
138                         case '0.1.2': // SQL queries for v0.1.2
139                                 // Update notes (these will be set as task text!)
140                                 setExtensionUpdateNotes("Fehlerhinweis bei deaktivierter Erweiterung verbessert.");
141                                 break;
142
143                         case '0.2.0': // SQL queries for v0.2.0
144                                 // Tables:
145                                 // - Main data table
146                                 addExtensionSql("DROP TABLE IF EXISTS `{?_MYSQL_PREFIX?}_newsletter_data`");
147                                 addExtensionSql("CREATE TABLE `{?_MYSQL_PREFIX?}_newsletter_data` (
148 `nl_id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
149 `nl_subject` VARCHAR(255) NOT NULL DEFAULT '{OPEN_CONFIG}nl_default_subject{CLOSE_CONFIG}',
150 `nl_header_text` MEDIUMTEXT,
151 `nl_footer_text` MEDIUMTEXT,
152 `nl_created` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
153 `nl_send` TIMESTAMP NOT NULL DEFAULT '0000-00-00 00:00',
154 `nl_ready` ENUM('Y','N') NOT NULL DEFAULT 'N',
155 `nl_sent` ENUM('Y','N') NOT NULL DEFAULT 'N',
156 `nl_expired` ENUM('Y','N') NOT NULL DEFAULT 'N',
157 `nl_do_archive` ENUM('Y','N') NOT NULL DEFAULT 'Y',
158 `nl_recipients` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
159 `nl_received` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
160 `nl_total_clicks` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
161 PRIMARY KEY (`nl_id`)
162 ) TYPE={?_TABLE_TYPE?} COMMENT='General newsletter data'");
163
164                                 // - Topics data table
165                                 addExtensionSql("DROP TABLE IF EXISTS `{?_MYSQL_PREFIX?}_newsletter_topics`");
166                                 addExtensionSql("CREATE TABLE `{?_MYSQL_PREFIX?}_newsletter_topics` (
167 `nl_topic_id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
168 `nl_id` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
169 `nl_topic_title` VARCHAR(255) NOT NULL DEFAULT '',
170 `nl_topic_text` MEDIUMTEXT,
171 INDEX `newsletter_id` (`nl_id`),
172 PRIMARY KEY (`nl_topic_id`)
173 ) TYPE={?_TABLE_TYPE?} COMMENT='Newsletter topics'");
174
175                                 // - Sponsor orders data table
176                                 addExtensionSql("DROP TABLE IF EXISTS `{?_MYSQL_PREFIX?}_newsletter_orders`");
177                                 addExtensionSql("CREATE TABLE `{?_MYSQL_PREFIX?}_newsletter_orders` (
178 `nl_order_id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
179 `nl_sponsor_id` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
180 `nl_id` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
181 `nl_topic_id` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
182 `nl_order_placed` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
183 `nl_order_accepted` ENUM('Y','N') NOT NULL DEFAULT 'N',
184 UNIQUE KEY `sponsor_nl_topic` (`nl_sponsor_id`,`nl_id`,`nl_topic_id`),
185 INDEX `topic` (`nl_topic_id`),
186 PRIMARY KEY (`nl_order_id`)
187 ) TYPE={?_TABLE_TYPE?} COMMENT='Newsletter orders'");
188
189                                 // Configuration
190                                 addExtensionSql("ALTER TABLE `{?_MYSQL_PREFIX?}_config` ADD `nl_expire` BIGINT(20) UNSIGNED NOT NULL DEFAULT ".(getConfig('ONE_DAY') * 7)."");
191                                 addExtensionSql("ALTER TABLE `{?_MYSQL_PREFIX?}_config` ADD `nl_archive_expire` BIGINT(20) UNSIGNED NOT NULL DEFAULT ".(getConfig('ONE_DAY') * 14)."");
192                                 addExtensionSql("ALTER TABLE `{?_MYSQL_PREFIX?}_config` ADD `nl_default_subject` VARCHAR(255) NOT NULL DEFAULT 'Newsletter vom {OPEN_CONFIG}CURRENT_DATE{CLOSE_CONFIG}'");
193                                 addExtensionSql("ALTER TABLE `{?_MYSQL_PREFIX?}_config` ADD `nl_default_header` MEDIUMTEXT");
194                                 addExtensionSql("ALTER TABLE `{?_MYSQL_PREFIX?}_config` ADD `nl_default_footer` MEDIUMTEXT");
195                                 addExtensionSql("ALTER TABLE `{?_MYSQL_PREFIX?}_config` ADD `nl_archive` ENUM('Y','N') NOT NULL DEFAULT 'Y'");
196
197                                 // Admin menu
198                                 addAdminMenuSql('newsletter', 'add_newsletter','Neuen erstellen','Legen Sie hier einen neuen Newsletter mit Betreff und Verfallsdatum an.', 1);
199
200                                 // Update notes (these will be set as task text!)
201                                 setExtensionUpdateNotes("Komplett&uuml;berarbeitung der Erweiterung, siehe neuer Beschreibungstext.");
202                                 break;
203                 } // END - switch
204                 break;
205
206         case 'modify': // When the extension got modified
207                 break;
208
209         case 'test': // For testing purposes. For details see file inc/modules/admin/what-extensions.php, arround line 305.
210                 break;
211
212         case 'init': // Do stuff when extension is initialized
213                 // URL ends which are used to indentify the end of an URL or email link
214                 // Don't use these chars in links... ;-)
215                 // @TODO Move these into configuration
216                 $GLOBALS['url_ends'] = array(
217                         ' ',
218                         "\n",
219                         "\r",
220                         ')',
221                 );
222
223                 // Valid email chars (without @, or do you want to have another @ inside your email addresses?)
224                 $GLOBALS['valid_email_chars'] = array(
225                         'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s',
226                         't','u','v','w','x','y','z','a','B','C','D','E','F','G','H','I','J','K','L',
227                         'M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','-','.','_',0,1,
228                         2,3,4,5,6,7,8,9
229                 );
230                 break;
231
232         default: // Unknown extension mode
233                 DEBUG_LOG(__FILE__, __LINE__, sprintf("Unknown extension mode %s detected.", getExtensionMode()));
234                 break;
235 } // END - switch
236
237 // [EOF]
238 ?>