Mahor rewrite:
[mailer.git] / inc / extensions / ext-autopurge.php
index 1a0d6bda37fae1cb4917b61f3c09c1814c571a8d..e84271257361ab7e7fd4a00b3d1a266f24d5251e 100644 (file)
@@ -32,8 +32,7 @@
  ************************************************************************/
 
 // Some security stuff...
-if ((ereg(basename(__FILE__), $_SERVER['PHP_SELF'])))
-{
+if (!defined('__SECURITY')) {
        $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
        require($INC);
 }
@@ -49,30 +48,24 @@ $EXT_VER_HISTORY = array("0.0", "0.1", "0.1.1", "0.1.2", "0.1.3", "0.1.4", "0.1.
 
 switch ($EXT_LOAD_MODE)
 {
-case "register": // Do stuff when installtion is running (modules.php?module=admin&action=login is called)
+case "register": // Do stuff when installation is running (modules.php?module=admin&action=login is called)
        // SQL commands to run
-       $SQLs[] = "alter table "._MYSQL_PREFIX."_pool modify data_type enum('TEMP','SEND','NEW','ADMIN','ACTIVE','DELETED') not null default 'TEMP'";
+       $SQLs[] = "ALTER TABLE "._MYSQL_PREFIX."_pool MODIFY data_type ENUM('TEMP','SEND','NEW','ADMIN','ACTIVE','DELETED') NOT NULL DEFAULT 'TEMP'";
        if (EXT_IS_ACTIVE("bonus"))
        {
-               $SQLs[] = "alter table "._MYSQL_PREFIX."_bonus modify data_type enum('NEW','QUEUE','SEND','DELETED') not null default 'NEW'";
+               $SQLs[] = "ALTER TABLE "._MYSQL_PREFIX."_bonus MODIFY data_type ENUM('NEW','QUEUE','SEND','DELETED') NOT NULL DEFAULT 'NEW'";
        }
        break;
 
 case "remove": // Do stuff when removing extension
        // SQL commands to run
-       $SQLs[] = "alter table "._MYSQL_PREFIX."_pool modify data_type enum('TEMP','SEND','NEW','ADMIN','ACTIVE') not null default 'TEMP'";
+       $SQLs[] = "ALTER TABLE "._MYSQL_PREFIX."_pool MODIFY data_type ENUM('TEMP','SEND','NEW','ADMIN','ACTIVE') NOT NULL DEFAULT 'TEMP'";
        if (EXT_IS_ACTIVE("bonus"))
        {
-               $SQLs[] = "alter table "._MYSQL_PREFIX."_bonus modify data_type enum('NEW','QUEUE','SEND') not null default 'NEW'";
+               $SQLs[] = "ALTER TABLE "._MYSQL_PREFIX."_bonus MODIFY data_type ENUM('NEW','QUEUE','SEND') NOT NULL DEFAULT 'NEW'";
        }
-       $SQLs[] = "ALTER TABLE "._MYSQL_PREFIX."_config DROP autopurge_inactive";
-       $SQLs[] = "ALTER TABLE "._MYSQL_PREFIX."_config DROP autopurge_unconfirmed";
-       $SQLs[] = "ALTER TABLE "._MYSQL_PREFIX."_config DROP ap_inactive_since";
-       $SQLs[] = "ALTER TABLE "._MYSQL_PREFIX."_config DROP ap_inactive_time";
-       $SQLs[] = "ALTER TABLE "._MYSQL_PREFIX."_config DROP ap_unconfirmed_time";
-       $SQLs[] = "DELETE LOW_PRIORITY FROM "._MYSQL_PREFIX."_admin_menu WHERE action='setup' AND what='config_autopurge' LIMIT 1";
-       $SQLs[] = "DELETE LOW_PRIORITY FROM "._MYSQL_PREFIX."_admin_menu WHERE action='user' AND what='list_autopurge' LIMIT 1";
-       $SQLs[] = "ALTER TABLE "._MYSQL_PREFIX."_user_data DROP ap_notified";
+       $SQLs[] = "DELETE LOW_PRIORITY FROM `"._MYSQL_PREFIX."_admin_menu` WHERE what IN('config_autopurge','list_autopurge') LIMIT 2";
+       $SQLs[] = "ALTER TABLE `"._MYSQL_PREFIX."_user_data` DROP ap_notified";
        break;
 
 case "activate": // Do stuff when admin activates this extension
@@ -89,14 +82,14 @@ case "update": // Update an extension
        switch ($EXT_VER)
        {
        case "0.1": // SQL queries for v0.1
-               $SQLs[] = "ALTER TABLE "._MYSQL_PREFIX."_config ADD autopurge_inactive enum('Y', 'N') not null default 'Y'";
-               $SQLs[] = "ALTER TABLE "._MYSQL_PREFIX."_config ADD autopurge_unconfirmed enum('Y', 'N') not null default 'Y'";
-               $SQLs[] = "ALTER TABLE "._MYSQL_PREFIX."_config ADD ap_inactive_since bigint(20) not null default '2592000'";
-               $SQLs[] = "ALTER TABLE "._MYSQL_PREFIX."_config ADD ap_inactive_time bigint(20) not null default '25200'";
-               $SQLs[] = "ALTER TABLE "._MYSQL_PREFIX."_config ADD ap_unconfirmed_time bigint(20) not null default '432000'";
-               $SQLs[] = "INSERT INTO "._MYSQL_PREFIX."_admin_menu (action, what, title, descr, sort) VALUES ('setup', 'config_autopurge', 'Auto-Löschung', 'Automatisch inaktive oder nicht bestätigte Accounts löschen.', '12')";
-               $SQLs[] = "INSERT INTO "._MYSQL_PREFIX."_admin_menu (action, what, title, descr, sort) VALUES ('user', 'list_autopurge', 'Inaktive finden', 'Lassen Sie sich vor dem täglichen Reset anzeigen, welche Mitglieder als inaktiv erkannt werden und welche gelöscht werden.', '10')";
-               $SQLs[] = "ALTER TABLE "._MYSQL_PREFIX."_user_data ADD ap_notified bigint(20) not null default '0'";
+               $SQLs[] = "ALTER TABLE `"._MYSQL_PREFIX."_config` ADD autopurge_inactive ENUM('Y','N') NOT NULL DEFAULT 'Y'";
+               $SQLs[] = "ALTER TABLE `"._MYSQL_PREFIX."_config` ADD autopurge_unconfirmed ENUM('Y','N') NOT NULL DEFAULT 'Y'";
+               $SQLs[] = "ALTER TABLE `"._MYSQL_PREFIX."_config` ADD ap_inactive_since BIGINT(20) UNSIGNED NOT NULL DEFAULT '2592000'";
+               $SQLs[] = "ALTER TABLE `"._MYSQL_PREFIX."_config` ADD ap_inactive_time BIGINT(20) UNSIGNED NOT NULL DEFAULT '25200'";
+               $SQLs[] = "ALTER TABLE `"._MYSQL_PREFIX."_config` ADD ap_unconfirmed_time BIGINT(20) UNSIGNED NOT NULL DEFAULT '432000'";
+               $SQLs[] = "INSERT INTO `"._MYSQL_PREFIX."_admin_menu` (`action`,`what`,`title`,`descr`,`sort`) VALUES ('setup','config_autopurge','Auto-Löschung','Automatisch inaktive oder nicht bestätigte Accounts löschen.','12')";
+               $SQLs[] = "INSERT INTO `"._MYSQL_PREFIX."_admin_menu` (`action`,`what`,`title`,`descr`,`sort`) VALUES ('user','list_autopurge','Inaktive finden','Lassen Sie sich vor dem täglichen Reset anzeigen, welche Mitglieder als inaktiv erkannt werden und welche gelöscht werden.','10')";
+               $SQLs[] = "ALTER TABLE `"._MYSQL_PREFIX."_user_data` ADD ap_notified BIGINT(20) UNSIGNED NOT NULL DEFAULT 0";
 
                // Update notes (these will be set as task text!)
                $UPDATE_NOTES = "Automatisches L&ouml:schen von inaktiven bzw. nicht bestätigten Accounts hinzugefügt.";
@@ -109,7 +102,7 @@ case "update": // Update an extension
 
        case "0.1.4": // SQL queries for v0.1.4
                // Update notes (these will be set as task text!)
-               $UPDATE_NOTES = "Fehler <FONT class=\"admin_failed\">Warning: Missing argument 2 for create_timestamp_from_selections() in ".PATH."inc/libs/pro_functions.php on line 227</FONT> behoben.";
+               $UPDATE_NOTES = "Fehler <FONT class=\"admin_failed\">Warning: Missing argument 2 for create_timestamp_from_selections() in {!PATH!}inc/libs/pro_functions.php on line 227</FONT> behoben.";
                break;
 
        case "0.1.5": // SQL queries for v0.1.5
@@ -134,20 +127,20 @@ case "update": // Update an extension
                break;
 
        case "0.1.9": // SQL queries for v0.1.9
-               $SQLs[] = "ALTER TABLE "._MYSQL_PREFIX."_config ADD autopurge_tasks enum('Y', 'N') not null default 'Y'";
-               $SQLs[] = "ALTER TABLE "._MYSQL_PREFIX."_config ADD ap_tasks_time bigint(20) not null default '".(60*60*24*7)."'";
+               $SQLs[] = "ALTER TABLE `"._MYSQL_PREFIX."_config` ADD autopurge_tasks ENUM('Y','N') NOT NULL DEFAULT 'Y'";
+               $SQLs[] = "ALTER TABLE `"._MYSQL_PREFIX."_config` ADD ap_tasks_time BIGINT(20) UNSIGNED NOT NULL DEFAULT '".(getConfig('one_day')*7)."'";
 
                // Update notes (these will be set as task text!)
-               $UPDATE_NOTES = "Bereinigung von zu l&ouml;schenden Aufgaben klappt wieder. Zeitlimit f&uuml;r genanntes kann eingestellt werden (Default = 7 Tage).<BR><BR><U>Bitte aktualisieren Sie auch die Admin-Templates!</U>";
+               $UPDATE_NOTES = "Bereinigung von zu l&ouml;schenden Aufgaben klappt wieder. Zeitlimit f&uuml;r genanntes kann eingestellt werden (Default = 7 Tage).<br /><br /><U>Bitte aktualisieren Sie auch die Admin-Templates!</U>";
                break;
 
        case "0.2.0": // SQL queries for v0.2.0
-               $SQLs[] = "ALTER TABLE "._MYSQL_PREFIX."_config ADD ap_in_notify enum('Y', 'N') not null default 'Y'";
-               $SQLs[] = "ALTER TABLE "._MYSQL_PREFIX."_config ADD ap_un_notify enum('Y', 'N') not null default 'Y'";
-               $SQLs[] = "ALTER TABLE "._MYSQL_PREFIX."_config ADD ap_tasks_notify enum('Y', 'N') not null default 'Y'";
+               $SQLs[] = "ALTER TABLE `"._MYSQL_PREFIX."_config` ADD ap_in_notify ENUM('Y','N') NOT NULL DEFAULT 'Y'";
+               $SQLs[] = "ALTER TABLE `"._MYSQL_PREFIX."_config` ADD ap_un_notify ENUM('Y','N') NOT NULL DEFAULT 'Y'";
+               $SQLs[] = "ALTER TABLE `"._MYSQL_PREFIX."_config` ADD ap_tasks_notify ENUM('Y','N') NOT NULL DEFAULT 'Y'";
 
                // Update notes (these will be set as task text!)
-               $UPDATE_NOTES = "Mail wird bei L&ouml;schung von Aufgaben ausgesendet.<BR><BR><U>Bitte aktualisieren Sie auch die Admin-Templates!</U>";
+               $UPDATE_NOTES = "Mail wird bei L&ouml;schung von Aufgaben ausgesendet.<br /><br /><U>Bitte aktualisieren Sie auch die Admin-Templates!</U>";
                break;
 
        case "0.2.1": // SQL queries for v0.2.1
@@ -172,7 +165,7 @@ case "update": // Update an extension
 
        case "0.2.5": // SQL queries for v0.2.5
                // Update notes (these will be set as task text!)
-               $UPDATE_NOTES = "Seit <A href=\"".SERVER_URL."/patches/340-Gast_Mitgliedsmenue_Deaktivieren.zip\">Patch 340</A> &uuml;berfl&uuml;ssige HTML-Tags entfernt.";
+               $UPDATE_NOTES = "Seit <A href=\"#\">Patch 340</A> &uuml;berfl&uuml;ssige HTML-Tags entfernt.";
                break;
 
        case "0.2.6": // SQL queries for v0.2.6
@@ -211,9 +204,9 @@ case "update": // Update an extension
                break;
 
        case "0.3.3": // SQL queries for v0.3.3
-               $SQLs[] = "ALTER TABLE "._MYSQL_PREFIX."_config ADD ap_del_mails enum('Y', 'N') not null default 'Y'";
-               $SQLs[] = "ALTER TABLE "._MYSQL_PREFIX."_config ADD ap_dm_notify enum('Y', 'N') not null default 'Y'";
-               $SQLs[] = "ALTER TABLE "._MYSQL_PREFIX."_config ADD ap_dm_timeout bigint(20) not null default '86400'";
+               $SQLs[] = "ALTER TABLE `"._MYSQL_PREFIX."_config` ADD ap_del_mails ENUM('Y','N') NOT NULL DEFAULT 'Y'";
+               $SQLs[] = "ALTER TABLE `"._MYSQL_PREFIX."_config` ADD ap_dm_notify ENUM('Y','N') NOT NULL DEFAULT 'Y'";
+               $SQLs[] = "ALTER TABLE `"._MYSQL_PREFIX."_config` ADD ap_dm_timeout BIGINT(20) UNSIGNED NOT NULL DEFAULT '86400'";
 
                // Update notes (these will be set as task text!)
                $UPDATE_NOTES = "Von bereits gel&ouml;schten Mitgliedern die Mails l&ouml;schen integriert.";
@@ -231,7 +224,7 @@ case "update": // Update an extension
 
        case "0.3.6": // SQL queries for v0.3.6
                // Update notes (these will be set as task text!)
-               $UPDATE_NOTES = "Die Accounts der Standart-Referral-ID, der Bonus-ID, Bettellink-ID und der Verdoppler-ID werden nun nicht mehr gel&ouml;scht und tauchen auch unterhalb der Inaktiven-Liste nicht mehr auf.";
+               $UPDATE_NOTES = "Die Accounts der Standart-Referal-ID, der Bonus-ID, Bettellink-ID und der Verdoppler-ID werden nun nicht mehr gel&ouml;scht und tauchen auch unterhalb der Inaktiven-Liste nicht mehr auf.";
                break;
 
        case "0.3.7": // SQL queries for v0.3.7
@@ -256,38 +249,20 @@ case "update": // Update an extension
        }
        break;
 
-default: // Do stuff when extension is loaded
-       $DUMMY = LOAD_CONFIG("0");
-       // Transfer all to the $CONFIG array...
-       $CONFIG['ap_inactive']    = $DUMMY['autopurge_inactive'];    // Autopurge inactive accounts (yes/no)
-       $CONFIG['ap_unconfirmed'] = $DUMMY['autopurge_unconfirmed']; // Autopurge unconfirmed accounts (yes/no)
-       $CONFIG['ap_tasks']       = $DUMMY['autopurge_tasks'];       // Autopurge out-dated tasks (yes/no)
-       $CONFIG['ap_in_mail']     = $DUMMY['ap_in_notify'];          // Send email to admin when purging inactive accounts (yes/no)
-       $CONFIG['ap_un_mail']     = $DUMMY['ap_un_notify'];          // Send email to admin when purging unconfirmed accounts (yes/no)
-       $CONFIG['ap_tasks_mail']  = $DUMMY['ap_tasks_notify'];       // Send email to admin when purging out-dated tasks (yes/no)
-       $CONFIG['ap_in_since']    = $DUMMY['ap_inactive_since'];     // Timeout for confirmed accounts when they become inactive (seconds)
-       $CONFIG['ap_in_time']     = $DUMMY['ap_inactive_time'];      // Timeout for inactive accounts when they are automatically deleted (seconds)
-       $CONFIG['ap_un_time']     = $DUMMY['ap_unconfirmed_time'];   // Timeout for unconfirmed accounts when they are automatically deleted (seconds)
-       $CONFIG['ap_tasks_time']  = $DUMMY['ap_tasks_time'];         // Timeout for out-dated tasks
-       $CONFIG['ap_del_mails']   = $DUMMY['ap_del_mails'];          // Autopurge mails from deleted users?
-       $CONFIG['ap_dm_notify']   = $DUMMY['ap_dm_notify'];          // Send email to admin when purging mails from deleted users (yes/no)
-       $CONFIG['ap_dm_timeout']  = $DUMMY['ap_dm_timeout'];         // Timeout for mails from deleted users
-
-       // Save some RAM...
-       unset($DUMMY);
+case "test": // For testing purposes. For details see file inc/modules/admin/what-extensions.php, arround line 305.
+       break;
 
+default: // Do stuff when extension is loaded
        // Do we have a daily-reset-run?
-       if (defined('__DAILY_RESET') && (!DEBUG_MODE) && ($CSS != 1))
+       if (isBooleanConstantAndTrue('__DAILY_RESET') && (!DEBUG_MODE) && ($CSS != 1))
        {
                // Yes, we have. So let's auto-purge some campaigns, inactive users and unconfirmed accounts
-               $INC_POOL[] = PATH."inc/autopurge.php";
+               $INC_POOL[] = sprintf("%sinc/autopurge.php", PATH);
        }
        break;
 }
-// Language file prefix
-$EXT_LANG_PREFIX = "autopurge";
 
-// Extension is always active?
+// Keep this extension always active!
 $EXT_ALWAYS_ACTIVE = "Y";
 
 //