Introduced wrapper function addCreateTableSql(), fixed parameter order:
[mailer.git] / inc / extensions / ext-rallye.php
index a8c4d3d9c9c222ff9e78a29482a40b6696dd2eac..21f53da8ff8f09b4842a9177fb03d736506c4134 100644 (file)
  * $Date::                                                            $ *
  * $Tag:: 0.2.1-FINAL                                                 $ *
  * $Author::                                                          $ *
- * Needs to be in all Files and every File needs "svn propset           *
- * svn:keywords Date Revision" (autoprobset!) at least!!!!!!            *
  * -------------------------------------------------------------------- *
  * Copyright (c) 2003 - 2009 by Roland Haeder                           *
- * Copyright (c) 2009, 2010 by Mailer Developer Team                    *
+ * Copyright (c) 2009 - 2011 by Mailer Developer Team                   *
  * For more information visit: http://www.mxchange.org                  *
  *                                                                      *
  * This program is free software; you can redistribute it and/or modify *
@@ -51,42 +49,42 @@ setExtensionVersionHistory(array('0.0', '0.0.1', '0.0.2', '0.0.3', '0.0.4', '0.0
 switch (getExtensionMode()) {
        case 'register': // Do stuff when installation is running (modules.php?module=admin is called)
                // SQL commands to run
-               addExtensionSql("DROP TABLE IF EXISTS `{?_MYSQL_PREFIX?}_rallye_data`");
-               addExtensionSql("DROP TABLE IF EXISTS `{?_MYSQL_PREFIX?}_rallye_prices`");
-               addExtensionSql("DROP TABLE IF EXISTS `{?_MYSQL_PREFIX?}_rallye_users`");
-               addExtensionSql("CREATE TABLE `{?_MYSQL_PREFIX?}_rallye_data` (
-id BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
-admin_id BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
-title VARCHAR(255) NOT NULL DEFAULT '',
-descr LONGTEXT NOT NULL,
-template VARCHAR(255) NOT NULL DEFAULT '',
-start_time VARCHAR(10) NOT NULL DEFAULT 0,
-end_time VARCHAR(10) NOT NULL DEFAULT 0,
-auto_add_new_user ENUM('Y','N') NOT NULL DEFAULT 'Y',
-is_active ENUM('Y','N') NOT NULL DEFAULT 'N',
-send_notify ENUM('Y','N') NOT NULL DEFAULT 'Y',
-notified ENUM('Y','N') NOT NULL DEFAULT 'N',
-KEY (admin_id),
-PRIMARY KEY (id)
-) TYPE={?_TABLE_TYPE?}");
-               addExtensionSql("CREATE TABLE `{?_MYSQL_PREFIX?}_rallye_prices` (
-id BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
-rallye_id BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
-price_level BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
-points BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
-info LONGTEXT NOT NULL,
-KEY (rallye_id),
-PRIMARY KEY (id)
-) TYPE={?_TABLE_TYPE?}");
-               addExtensionSql("CREATE TABLE `{?_MYSQL_PREFIX?}_rallye_users` (
-id BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
-rallye_id BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
-userid BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
-refs BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
-KEY (rallye_id),
-KEY (userid),
-PRIMARY KEY (id)
-) TYPE={?_TABLE_TYPE?}");
+               addDropTableSql('rallye_data');
+               addCreateTableSql('rallye_data', "(
+`id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
+`admin_id` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
+`title` VARCHAR(255) NOT NULL DEFAULT '',
+`descr` LONGTEXT NOT NULL,
+`template` VARCHAR(255) NOT NULL DEFAULT '',
+`start_time` VARCHAR(10) NOT NULL DEFAULT 0,
+`end_time` VARCHAR(10) NOT NULL DEFAULT 0,
+`auto_add_new_user` ENUM('Y','N') NOT NULL DEFAULT 'Y',
+`is_active` ENUM('Y','N') NOT NULL DEFAULT 'N',
+`send_notify` ENUM('Y','N') NOT NULL DEFAULT 'Y',
+`notified` ENUM('Y','N') NOT NULL DEFAULT 'N',
+KEY (`admin_id`),
+PRIMARY KEY (`id`)
+) ENGINE = {?_TABLE_TYPE?} CHARACTER SET utf8 COLLATE utf8_general_ci COMMENT = 'Main rallye data'");
+               addDropTableSql('rallye_prices');
+               addCreateTableSql('rallye_prices', "(
+`id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
+`rallye_id` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
+`price_level` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
+`points` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
+`info` LONGTEXT NOT NULL,
+INDEX (`rallye_id`),
+PRIMARY KEY (`id`)
+) ENGINE = {?_TABLE_TYPE?} CHARACTER SET utf8 COLLATE utf8_general_ci COMMENT = 'Prices data for a rallye'");
+               addDropTableSql('rallye_users');
+               addCreateTableSql('rallye_users', "(
+`id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
+`rallye_id` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
+`userid` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
+`refs` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
+INDEX (`rallye_id`),
+INDEX (`userid`),
+PRIMARY KEY (`id`)
+) ENGINE = {?_TABLE_TYPE?} CHARACTER SET utf8 COLLATE utf8_general_ci COMMENT = 'Rallye->user connection table'");
 
                // Admin menu
                addAdminMenuSql('rallye', NULL, 'Rallye-Management','Richten Sie neue Ref-Rallyes ein, die zeitgesteuert anfangen und aufhöhren. Dabei wird alles weitere automatisch geregelt.',9);
@@ -104,9 +102,9 @@ PRIMARY KEY (id)
 
        case 'remove': // Do stuff when removing extension
                // Drop tables
-               addExtensionSql("DROP TABLE IF EXISTS `{?_MYSQL_PREFIX?}_rallye_data`");
-               addExtensionSql("DROP TABLE IF EXISTS `{?_MYSQL_PREFIX?}_rallye_prices`");
-               addExtensionSql("DROP TABLE IF EXISTS `{?_MYSQL_PREFIX?}_rallye_users`");
+               addDropTableSql('rallye_data');
+               addDropTableSql('rallye_prices');
+               addDropTableSql('rallye_users');
 
                // Remove menus
                addExtensionSql("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_admin_menu` WHERE `action`='rallye'");
@@ -114,7 +112,7 @@ PRIMARY KEY (id)
                addExtensionSql("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_member_menu` WHERE `what`='rallyes'");
 
                // Unregister filter
-               unregisterFilter('extra_autopurge', 'RALLYE_EXTRA_AUTOPURGE', true, getExtensionDryRun());
+               unregisterFilter(__FUNCTION__, __LINE__, 'extra_autopurge', 'RALLYE_EXTRA_AUTOPURGE', true, isExtensionDryRun());
                break;
 
        case 'activate': // Do stuff when admin activates this extension
@@ -218,8 +216,8 @@ PRIMARY KEY (id)
                                break;
 
                        case '0.2.0': // SQL queries for v0.2.0
-                               addExtensionSql("ALTER TABLE `{?_MYSQL_PREFIX?}_rallye_data` ADD min_users BIGINT(20) UNSIGNED NOT NULL DEFAULT 0");
-                               addExtensionSql("ALTER TABLE `{?_MYSQL_PREFIX?}_rallye_data` ADD min_prices BIGINT(20) UNSIGNED NOT NULL DEFAULT 3");
+                               addExtensionSql("ALTER TABLE `{?_MYSQL_PREFIX?}_rallye_data` ADD `min_users` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0");
+                               addExtensionSql("ALTER TABLE `{?_MYSQL_PREFIX?}_rallye_data` ADD `min_prices` BIGINT(20) UNSIGNED NOT NULL DEFAULT 3");
 
                                // Update notes (these will be set as task text!)
                                setExtensionUpdateNotes("Ablaufen der Rallyes intergriert. Bauen Sie in Ihr Template <strong>templates/de/emails/member/member_rallye_notify.tpl</strong> folgende zwei Zeilen ein:<br />
@@ -309,41 +307,41 @@ Zudem sollten Sie mindestens folgende Templates (in <strong>templates/".getLangu
 
                        case '0.3.5': // SQL queries for 0.3.5
                                // This update depends on sql_patches
-                               addExtensionUpdateDependency('sql_patches');
+                               addExtensionDependency('sql_patches');
 
                                // Register filter
-                               registerFilter('extra_autopurge', 'RALLYE_EXTRA_AUTOPURGE', false, true, getExtensionDryRun());
+                               registerFilter('extra_autopurge', 'RALLYE_EXTRA_AUTOPURGE', false, true, isExtensionDryRun());
 
                                // Update notes (these will be set as task text!)
                                setExtensionUpdateNotes("Filter hinzugef&uuml;gt und ist von <strong>sql_patches</strong> abh&auml;ngig.");
                                break;
-               }
+               } // END - switch
                break;
 
        case 'modify': // When the extension got modified
                break;
 
-       case 'test': // For testing purposes. For details see file inc/modules/admin/what-extensions.php, arround line 305.
+       case 'test': // For testing purposes
                break;
 
        case 'init': // Do stuff when extension is initialized
                // Do stuff only when not in CSS mode
-               // @TODO Move this code into rallye_functions.php
-               if (getOutputMode() != 1) {
+               // @TODO Move this code into a hook
+               if (!isCssOutputMode()) {
                        // Get total member count
-                       $total = countSumTotalData('CONFIRMED', 'user_data', 'userid', 'status', true);
+                       $total = getTotalConfirmedUser();
 
                        // Add more data on higher versions
                        $ADD1 = ''; $ADD2 = ''; $OR = '';
                        if (isExtensionInstalledAndNewer('rallye', '0.2.0')) {
                                $ADD1 = ", `min_users`, `min_prices`";
-                               $ADD2 = ", d.min_users, d.min_prices";
-                               $OR   = " OR (d.min_users <= ".$total." AND d.min_users > 0)";
+                               $ADD2 = ", d.`min_users`, d.`min_prices`";
+                               $OR   = " OR (d.`min_users` <= " . $total . " AND d.`min_users` > 0)";
                        } // END  - if
 
                        // Check for new started but not notified rallyes
                        $result = SQL_QUERY("SELECT SQL_SMALL_RESULT
-       `id`, `title`, `start_time`, `end_time`, `send_notify`".$ADD1."
+       `id`, `title`, `start_time`, `end_time`, `send_notify`" . $ADD1 . "
 FROM
        `{?_MYSQL_PREFIX?}_rallye_data`
 WHERE
@@ -363,14 +361,14 @@ LIMIT 1", __FILE__, __LINE__);
 
                        // Check for expired rallyes
                        $result = SQL_QUERY("SELECT SQL_SMALL_RESULT
-       d.id, d.title, d.start_time, d.end_time, d.send_notify".$ADD2."
+       d.`id`, d.`title`, d.`start_time`, d.`end_time`, d.`send_notify`" . $ADD2 . "
 FROM
        `{?_MYSQL_PREFIX?}_rallye_data` AS d
 WHERE
-       d.is_active='Y' AND
-       d.notified='Y' AND
-       d.expired='N' AND
-       (d.end_time <= UNIX_TIMESTAMP()".$OR.")
+       d.`is_active`='Y' AND
+       d.`notified`='Y' AND
+       d.`expired`='N' AND
+       (d.`end_time` <= UNIX_TIMESTAMP()".$OR.")
 LIMIT 1", __FILE__, __LINE__);
                        if ((SQL_NUMROWS($result) == 1) && (isExtensionActive('autopurge'))) {
                                // End rallye here...