Rewrote some parts:
[mailer.git] / inc / extensions / ext-newsletter.php
index 0a3f6ce971bfd21165fffd456af7e395884af0c3..1ff4ca2acdcee39febeb8ef5ce41780f26d67cb9 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 /************************************************************************
- * MXChange v0.2.1                                    Start: 02/26/2005 *
- * ================                             Last change: 02/26/2005 *
+ * Mailer v0.2.1-FINAL                                Start: 02/26/2005 *
+ * ===================                          Last change: 02/26/2005 *
  *                                                                      *
  * -------------------------------------------------------------------- *
  * File              : ext-newsletter.php                               *
  * -------------------------------------------------------------------- *
  * Kurzbeschreibung  : Erweiterung zum Versenden von Newslettern        *
  * -------------------------------------------------------------------- *
- *                                                                      *
+ * $Revision::                                                        $ *
+ * $Date::                                                            $ *
+ * $Tag:: 0.2.1-FINAL                                                 $ *
+ * $Author::                                                          $ *
  * -------------------------------------------------------------------- *
- * Copyright (c) 2003 - 2008 by Roland Haeder                           *
- * For more information visit: http://www.mxchange.org                  *
+ * Copyright (c) 2003 - 2009 by Roland Haeder                           *
+ * Copyright (c) 2009 - 2013 by Mailer Developer Team                   *
+ * For more information visit: http://mxchange.org                      *
  *                                                                      *
  * This program is free software; you can redistribute it and/or modify *
  * it under the terms of the GNU General Public License as published by *
  ************************************************************************/
 
 // Some security stuff...
-if ((ereg(basename(__FILE__), $_SERVER['PHP_SELF'])))
-{
-       $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
-       require($INC);
-}
+if (!defined('__SECURITY')) {
+       die();
+} // END - if
 
 // Version number
-$EXT_VERSION = "0.1.2";
-
-// Auto-set extension version
-if (empty($EXT_VER)) $EXT_VER = $EXT_VERSION;
-
-// Version history array (add more with , "0.1" and so on)
-$EXT_VER_HISTORY = 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");
-
-switch ($EXT_LOAD_MODE)
-{
-case "register": // Do stuff when installtion is running (modules.php?module=admin&action=login is called)
-       // SQL commands to run
-       $SQLs[] = "";
-       break;
-
-case "remove": // Do stuff when removing extension
-       // SQL commands to run
-       $SQLs[] = "DELETE LOW_PRIORITY FROM "._MYSQL_PREFIX."_admin_menu WHERE action='newsletter' AND what != 'send_newsletter' LIMIT 3";
-       $SQLs[] = "DELETE LOW_PRIORITY FROM "._MYSQL_PREFIX."_member_menu WHERE what='newsletter' LIMIT 1";
-       break;
-
-case "activate": // Do stuff when admin activates this extension
-       // SQL commands to run
-       $SQLs[] = "UPDATE "._MYSQL_PREFIX."_member_menu SET locked='N', visible='Y' WHERE what='newsletter' LIMIT 1";
-       break;
-
-case "deactivate": // Do stuff when admin deactivates this extension
-       // SQL commands to run
-       $SQLs[] = "UPDATE "._MYSQL_PREFIX."_member_menu SET locked='Y', visible='N' WHERE what='newsletter' LIMIT 1";
-       break;
-
-case "update": // Update an extension
-       switch ($EXT_VER)
-       {
-       case "0.0.1": // SQL queries for v0.0.1
-               $SQLs[] = "INSERT INTO "._MYSQL_PREFIX."_admin_menu (action, what, title, descr, sort) VALUES ('newsletter', '', 'Newsletter', 'Einstellungen am Newsletter, Newsletter versenden, Abbestellungen auflisten usw.', 3)";
-               $SQLs[] = "INSERT INTO "._MYSQL_PREFIX."_admin_menu (action, what, title, descr, sort) VALUES ('newsletter', 'list_newsletter', 'Abbestellungen', 'Alle Abbestellungen auflisten und bearbeiten.', 2)";
-               $SQLs[] = "INSERT INTO "._MYSQL_PREFIX."_admin_menu (action, what, title, descr, sort) VALUES ('newsletter', 'config_newsletter', 'Einstellungen', 'Geb&uuml;hr zum Abbestellen des Newsletters usw. sind hier einstellbar.', 3)";
-               $SQLs[] = "UPDATE "._MYSQL_PREFIX."_admin_menu SET action='newsletter', what='send_newsletter', title='Versenden', sort='1' WHERE what='newsletter' LIMIT 1";
-               $SQLs[] = "INSERT INTO "._MYSQL_PREFIX."_member_menu (action, what, title, visible, locked, sort) VALUES ('main', 'newsletter', 'Newsletter-Empfang', 'N', 'Y', 10)";
-               $SQLs[] = "ALTER TABLE "._MYSQL_PREFIX."_config ADD nl_charge float(10,2) not null default '5.00'";
-               $SQLs[] = "ALTER TABLE "._MYSQL_PREFIX."_user_data ADD nl_receive enum('Y', 'N') not null default 'Y'";
-               $SQLs[] = "ALTER TABLE "._MYSQL_PREFIX."_user_data ADD nl_until varchar(10) not null default '0'";
-               $SQLs[] = "ALTER TABLE "._MYSQL_PREFIX."_user_data ADD nl_timespan varchar(10) not null default '0'";
-
-               // Update notes (these will be set as task text!)
-               $UPDATE_NOTES = "Vor der eigentlichen Freigabe dieser Erweiterungen habe ich sie versehendlich im Archiv mit auf den Server hochgeladen. Diese Version f&uuml;gt die bereits angek&uuml;ndigte Funktionalit&auml;ten, wie zum Beispiel das Einstellen der Abschaltgeb&uuml;hr.";
-               break;
+setThisExtensionVersion('0.2.0');
 
-       case "0.0.2": // SQL queries for v0.0.2
-               // Update notes (these will be set as task text!)
-               $UPDATE_NOTES = "URL im Versendeformular und Option <I>Immer aktiv</I> f&uuml;r diese Erweiterung deaktiviert.";
-               break;
+// Version history array (add more with , '0.0.1' and so on)
+setExtensionVersionHistory(array('0.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'));
 
-       case "0.0.3": // SQL queries for v0.0.3
-               // Update notes (these will be set as task text!)
-               $UPDATE_NOTES = "W&ouml;rter <STRONG>Mailtausch</STRONG>, <STRONG>Mailtausches</STRONG> und <STRONG>Mailtauscher</STRONG> sind austauschbar.";
-               break;
+// This extension is in development (non-productive)
+enableExtensionProductive(FALSE);
 
-       case "0.0.4": // SQL queries for v0.0.4
-               // Update notes (these will be set as task text!)
-               $UPDATE_NOTES = "HTML-Code ausgelagert in Templates und SQL-Anweisungen abgesichert.";
+switch (getExtensionMode()) {
+       case 'setup': // Do stuff when installation is running
+               // SQL commands to run
+               addExtensionSql('');
                break;
 
-       case "0.0.5": // SQL queries for v0.0.5
-               // Update notes (these will be set as task text!)
-               $UPDATE_NOTES = "Abspeichern von Einstellungen repariert.";
+       case 'remove': // Do stuff when removing extension
+               // SQL commands to run
+               addExtensionSql("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_admin_menu` WHERE `action`='newsletter'");
+               addExtensionSql("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_member_menu` WHERE `what`='newsletter'");
+               addDropTableSql('newsletter_data');
+               addDropTableSql('newsletter_topics');
+               addDropTableSql('newsletter_orders');
                break;
 
-       case "0.0.6": // SQL queries for v0.0.6
-               // Update notes (these will be set as task text!)
-               $UPDATE_NOTES = "Bitte Script inc/monthly_newsletter.php l&ouml;schen!";
+       case 'activate': // Do stuff when admin activates this extension
                break;
 
-       case "0.0.7": // SQL queries for v0.0.7
-               // Update notes (these will be set as task text!)
-               $UPDATE_NOTES = "Script <STRONG>inc/monthly/monthly_newsletter.php</STRONG> wird nicht mehr ausgef&uuml;hrt, wenn die Erweiterung nicht aktiviert ist.";
+       case 'deactivate': // Do stuff when admin deactivates this extension
                break;
 
-       case "0.0.8": // SQL queries for v0.0.8
-               // Update notes (these will be set as task text!)
-               $UPDATE_NOTES = "Sicherheitsupdate f&uuml;r die Include-Befehle.";
+       case 'update': // Update an extension
+               switch (getCurrentExtensionVersion()) {
+                       case '0.0.1': // SQL queries for v0.0.1
+                               addAdminMenuSql('newsletter', NULL, 'Newsletter','Einstellungen am Newsletter, Newsletter versenden, usw.', 3);
+                               addExtensionSql("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_admin_menu` WHERE `what` IN ('newsletter','config_newsletter') LIMIT 1");
+                               addExtensionAddTableColumnSql('user_data', 'nl_receive', "ENUM('Y','N') NOT NULL DEFAULT 'Y'");
+
+                               // Update notes (these will be set as task text!)
+                               setExtensionUpdateNotes('Men&uuml;punkte hinzuf&uuml;gen und Mitgliedereinstellung.');
+                               break;
+
+                       case '0.0.2': // SQL queries for v0.0.2
+                               // Update notes (these will be set as task text!)
+                               setExtensionUpdateNotes('URL im Versendeformular und Option <span class="bad">Immer aktiv</span> f&uuml;r diese Erweiterung deaktiviert.');
+                               break;
+
+                       case '0.0.3': // SQL queries for v0.0.3
+                               // Update notes (these will be set as task text!)
+                               setExtensionUpdateNotes('W&ouml;rter <strong>{?mt_word?}</strong>, <strong>{?mt_word2?}</strong> und <strong>{?mt_word3?}</strong> sind austauschbar.');
+                               break;
+
+                       case '0.0.4': // SQL queries for v0.0.4
+                               // Update notes (these will be set as task text!)
+                               setExtensionUpdateNotes('HTML-Code ausgelagert in Templates und SQL-Anweisungen abgesichert.');
+                               break;
+
+                       case '0.0.5': // SQL queries for v0.0.5
+                               // Update notes (these will be set as task text!)
+                               setExtensionUpdateNotes('Abspeichern von Einstellungen repariert.');
+                               break;
+
+                       case '0.0.6': // SQL queries for v0.0.6
+                               // Update notes (these will be set as task text!)
+                               setExtensionUpdateNotes('Bitte Script inc/monthly_newsletter.php l&ouml;schen!');
+                               break;
+
+                       case '0.0.7': // SQL queries for v0.0.7
+                               // Update notes (these will be set as task text!)
+                               setExtensionUpdateNotes('Script <strong>inc/monthly/monthly_newsletter.php</strong> wird nicht mehr ausgef&uuml;hrt, wenn die Erweiterung nicht aktiviert ist.');
+                               break;
+
+                       case '0.0.8': // SQL queries for v0.0.8
+                               // Update notes (these will be set as task text!)
+                               setExtensionUpdateNotes('Sicherheitsupdate f&uuml;r die Include-Befehle.');
+                               break;
+
+                       case '0.0.9': // SQL queries for v0.0.9
+                               // Update notes (these will be set as task text!)
+                               setExtensionUpdateNotes('Nur bei installierter Erweiterung <strong>html_mail</strong> k&ouml;nnen Sie auch HTML-Mails versenden.');
+                               break;
+
+                       case '0.1.0': // SQL queries for v0.2.1
+                               // Update notes (these will be set as task text!)
+                               setExtensionUpdateNotes('Nur bei installierter Erweiterung <strong>html_mail</strong> k&ouml;nnen Sie auch HTML-Mails versenden.');
+                               break;
+
+                       case '0.1.1': // SQL queries for v0.1.1
+                               // Update notes (these will be set as task text!)
+                               setExtensionUpdateNotes('W&auml;hrung auf die Erweiterung <a href="#"><strong>ext-other.zip</strong></a> verlagert. Bitte auch diese aktualisieren.');
+                               break;
+
+                       case '0.1.2': // SQL queries for v0.1.2
+                               // Update notes (these will be set as task text!)
+                               setExtensionUpdateNotes('Fehlerhinweis bei deaktivierter Erweiterung verbessert.');
+                               break;
+
+                       case '0.2.0': // SQL queries for v0.2.0
+                               // Tables:
+                               // - Main data table
+                               addDropTableSql('newsletter_data');
+                               addCreateTableSql('newsletter_data', "
+`nl_id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
+`nl_subject` VARCHAR(255) NOT NULL DEFAULT '{OPEN_CONFIG}nl_default_subject{CLOSE_CONFIG}',
+`nl_header_text` MEDIUMTEXT NOT NULL,
+`nl_footer_text` MEDIUMTEXT NOT NULL,
+`nl_created` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
+`nl_send` TIMESTAMP NOT NULL DEFAULT '0000-00-00 00:00',
+`nl_ready` ENUM('Y','N') NOT NULL DEFAULT 'N',
+`nl_sent` ENUM('Y','N') NOT NULL DEFAULT 'N',
+`nl_expired` ENUM('Y','N') NOT NULL DEFAULT 'N',
+`nl_do_archive` ENUM('Y','N') NOT NULL DEFAULT 'Y',
+`nl_recipients` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
+`nl_received` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
+`nl_total_clicks` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
+PRIMARY KEY (`nl_id`)",
+                                       'General newsletter data');
+
+                               // - Topics data table
+                               addDropTableSql('newsletter_topics');
+                               addCreateTableSql('newsletter_topics', "
+`nl_topic_id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
+`nl_id` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
+`nl_topic_title` VARCHAR(255) NOT NULL DEFAULT '',
+`nl_topic_text` MEDIUMTEXT NOT NULL,
+`nl_topic_clicks` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
+PRIMARY KEY (`nl_topic_id`),
+INDEX `newsletter_id` (`nl_id`)",
+                                       'Newsletter topics');
+
+                               // - Sponsor orders data table
+                               addDropTableSql('newsletter_orders');
+                               addCreateTableSql('newsletter_orders', "
+`nl_order_id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
+`nl_sponsor_id` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
+`nl_id` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
+`nl_topic_id` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
+`nl_order_placed` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
+`nl_order_accepted` ENUM('Y','N') NOT NULL DEFAULT 'N',
+PRIMARY KEY (`nl_order_id`),
+UNIQUE INDEX `sponsor_nl_topic` (`nl_sponsor_id`, `nl_id`, `nl_topic_id`),
+INDEX `topic` (`nl_topic_id`)",
+                                       'Newsletter orders');
+
+                               // Configuration
+                               addConfigAddSql('nl_expire', 'BIGINT(20) UNSIGNED NOT NULL DEFAULT ' . (getOneDay() * 7));
+                               addConfigAddSql('nl_archive_expire', 'BIGINT(20) UNSIGNED NOT NULL DEFAULT ' . (getOneDay() * 14));
+                               addConfigAddSql('nl_default_subject', "VARCHAR(255) NOT NULL DEFAULT 'Newsletter vom {OPEN_CONFIG}CURRENT_DATE{CLOSE_CONFIG}'");
+                               addConfigAddSql('nl_default_header', 'MEDIUMTEXT NOT NULL,');
+                               addConfigAddSql('nl_default_footer', 'MEDIUMTEXT NOT NULL,');
+                               addConfigAddSql('nl_archive', "ENUM('Y','N') NOT NULL DEFAULT 'Y'");
+
+                               // Admin menu
+                               addAdminMenuSql('newsletter', 'list_newsletter', 'Newsletter Verwalten', 'Legen Sie hier einen neuen Newsletter mit Betreff und Verfallsdatum an und listen Sie bestehende auf. Die Grunddaten lassen sich hier ebenfalls &auml;ndern.', 1);
+                               addAdminMenuSql('newsletter', 'list_newsletter_topic', 'Thema verwalten', 'Legen Sie hier ein weiteres Thema an oder editieren bzw. l&ouml;schen Sie bestehende.', 2);
+                               addAdminMenuSql('newsletter', 'list_newsletter_ordrs', 'Buchungen verwalten', 'Verwalten Sie hier die Buchungen im Newsletter von Ihren Sponsoren.', 3);
+                               addAdminMenuSql('newsletter', 'config_newsletter', 'Einstellungen', 'Einstellungen am Newsletter vornehmen.', 4);
+
+                               // Remove member menu
+                               addExtensionSql("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_member_menu` WHERE `what`='newsletter' LIMIT 1");
+
+                               // Update notes (these will be set as task text!)
+                               setExtensionUpdateNotes('Komplett&uuml;berarbeitung der Erweiterung, siehe neuer Beschreibungstext.');
+                               break;
+               } // END - switch
                break;
 
-       case "0.0.9": // SQL queries for v0.0.9
-               // Update notes (these will be set as task text!)
-               $UPDATE_NOTES = "Nur bei installierter Erweiterung <STRONG>html_mail</STRONG> k&ouml;nnen Sie auch HTML-Mails versenden.";
+       case 'modify': // When the extension got modified
                break;
 
-       case "0.1.0": // SQL queries for v0.2.1
-               $SQLs[] = "ALTER TABLE "._MYSQL_PREFIX."_config ADD nl_month char(2) not null default '".date("m", time())."'";
-
-               // Update notes (these will be set as task text!)
-               $UPDATE_NOTES = "Nur bei installierter Erweiterung <STRONG>html_mail</STRONG> k&ouml;nnen Sie auch HTML-Mails versenden.";
+       case 'test': // For testing purposes
                break;
 
-       case "0.1.1": // SQL queries for v0.1.1
-               $SQLs[] = "ALTER TABLE "._MYSQL_PREFIX."_config DROP nl_currency";
-
-               // Update notes (these will be set as task text!)
-               $UPDATE_NOTES = "W&auml;hrung auf die Erweiterung <A href=\"".SERVER_URL."/extensions/ext-other.zip\"><STRONG>ext-other.zip</STRONG></A> verlagert. Bitte auch diese aktualisieren.";
+       case 'init': // Do stuff when extension is initialized
+               // URL ends which are used to indentify the end of an URL or email link
+               // Don't use these chars in links... ;-)
+               // @TODO Move these into configuration
+               $GLOBALS['url_ends'] = array(
+                       ' ',
+                       PHP_EOL,
+                       chr(13),
+                       ')',
+               );
+
+               // Valid email chars (without @, or do you want to have another @ inside your email addresses?)
+               $GLOBALS['valid_email_chars'] = array(
+                       'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s',
+                       't','u','v','w','x','y','z','A','B','C','D','E','F','G','H','I','J','K','L',
+                       'M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','-','.','_','0','1',
+                       '2','3','4','5','6','7','8','9'
+               );
                break;
 
-       case "0.1.2": // SQL queries for v0.1.2
-               // Update notes (these will be set as task text!)
-               $UPDATE_NOTES = "Fehlerhinweis bei deaktivierter Erweiterung verbessert.";
+       default: // Unknown extension mode
+               reportBug(__FILE__, __LINE__, sprintf('Unknown extension mode %s in extension %s detected.', getExtensionMode(), getCurrentExtensionName()));
                break;
-       }
-       break;
-
-default: // Do stuff when extension is loaded
-       $dummy = LOAD_CONFIG();
-       $_CONFIG = array_merge($_CONFIG, $dummy);
-       unset($dummy);
-
-       // URL ends which are used to indentify the end of an URL or email link
-       // Don't use these chars in links... ;-)
-       //
-       $URL_ENDS = array(
-               " ",
-               "\n",
-               "\r",
-               ")",
-       );
-
-       // Valid email chars (without @, or do you want to have another @ inside your email addy?)
-       $VALID_EMAIL_CHARS = array(
-               'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's',
-               't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L',
-               'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',   '-', '.', '_', '0', '1',
-               '2', '3', '4', '5', '6', '7', '8', '9'
-       );
-
-       if (defined('__DAILY_RESET') && (!DEBUG_MODE) && ($CSS != 1))
-       {
-               // Daily reset was run so let's check out for expired newsletter orders
-               $INC_POOL[] = PATH."inc/monthly/monthly_newsletter.php";
-       }
-       break;
-}
-
-// Language file prefix
-$EXT_LANG_PREFIX = "newsletter";
-
-// Extension is always active?
-$EXT_ALWAYS_ACTIVE = 'N';
-
-//
+} // END - switch
+
+// [EOF]
 ?>