Even more rewrites/fixes from EL branch (please report any broken part after you...
[mailer.git] / inc / modules / member / what-rallyes.php
index 14a9597bc34c068f9ba968a998a5edde83fee3fa..52b19648003f718e96c9fe65dec1e28a7a7a600b 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 /************************************************************************
- * MXChange v0.2.1                                    Start: 06/29/2004 *
- * ================                             Last change: 08/22/2004 *
+ * Mailer v0.2.1-FINAL                                Start: 06/29/2004 *
+ * ===================                          Last change: 08/22/2004 *
  *                                                                      *
  * -------------------------------------------------------------------- *
  * File              : what-rallyes.php                                 *
  * -------------------------------------------------------------------- *
  * Kurzbeschreibung  : Ref-Rallyes                                      *
  * -------------------------------------------------------------------- *
- *                                                                      *
+ * $Revision::                                                        $ *
+ * $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 - 2008 by Roland Haeder                           *
+ * Copyright (c) 2003 - 2009 by Roland Haeder                           *
+ * Copyright (c) 2009, 2010 by Mailer Developer Team                    *
  * For more information visit: http://www.mxchange.org                  *
  *                                                                      *
  * This program is free software; you can redistribute it and/or modify *
  ************************************************************************/
 
 // Some security stuff...
-if (ereg(basename(__FILE__), $_SERVER['PHP_SELF']))
-{
-       $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
-       require($INC);
-}
- elseif (!IS_LOGGED_IN())
-{
-       LOAD_URL(URL."/modules.php?module=index");
-}
- elseif ((!EXT_IS_ACTIVE("rallye")) && (!IS_ADMIN()))
-{
-       ADD_FATAL(EXTENSION_PROBLEM_EXT_INACTIVE, "rallye");
-       return;
+if (!defined('__SECURITY')) {
+       die();
+} elseif (!isMember()) {
+       redirectToIndexMemberOnlyModule();
 }
 
 // Add description as navigation point
-ADD_DESCR("member", basename(__FILE__));
+addMenuDescription('member', __FILE__);
 
-OUTPUT_HTML ("<DIV align=\"center\">");
+if ((!isExtensionActive('rallye')) && (!isAdmin())) {
+       loadTemplate('admin_settings_saved', false, generateExtensionInactiveNotInstalledMessage('rallye'));
+       return;
+} // END - if
 
 // Check for possible running rallyes
-$ADMIN = " AND d.is_active='Y'";
-if (IS_ADMIN()) $ADMIN = "";
-$result = SQL_QUERY("SELECT DISTINCT d.id, d.admin_id, a.login, d.title, d.descr, d.template, d.start_time, d.end_time, d.min_users, d.min_prices
- FROM "._MYSQL_PREFIX."_rallye_data AS d, "._MYSQL_PREFIX."_admins AS a
- WHERE d.admin_id=a.id".$ADMIN." AND d.notified='Y'
- ORDER BY d.end_time LIMIT 1", __FILE__, __LINE__);
+$ADD = " AND d.is_active='Y'";
+if (isAdmin()) $ADD = '';
 
-if (SQL_NUMROWS($result) == 1)
-{
+$result = SQL_QUERY("SELECT
+       d.id, d.admin_id, a.login, d.title, d.descr, d.template, d.start_time, d.end_time, d.min_users, d.min_prices
+FROM
+       `{?_MYSQL_PREFIX?}_rallye_data` AS d
+INNER JOIN
+       `{?_MYSQL_PREFIX?}_admins` AS a
+ON
+       d.admin_id=a.id
+WHERE
+       d.notified='Y'" . $ADD . "
+ORDER BY
+       d.end_time ASC
+LIMIT 1", __FILE__, __LINE__);
+
+if (SQL_NUMROWS($result) == 1) {
        // Found some (normally one...
-       list($id, $aid, $login, $title, $descr, $templ, $start, $end, $min_users, $min_prices) = SQL_FETCHROW($result);
-       SQL_FREERESULT($result);
+       $content = SQL_FETCHARRAY($result);
 
        $expired = false;
-       if ($end < time())
-       {
+       if ($content['end_time'] < time()) {
                // Rallye is expired
-               define('__RALLYE_EXTRAS', RALLYE_HAS_EXPIRED);
+               $content['extras'] = getMessage('RALLYE_HAS_EXPIRED');
                $expired = true;
-       }
-        elseif (time() >= ($end - ONE_DAY))
-       {
+       } elseif (time() >= ($content['end_time'] - getConfig('ONE_DAY'))) {
                // Rallye will expire in less one day!
-               define('__RALLYE_EXTRAS', RALLYE_EXPIRE_ONE_DAY);
-       }
-        else
-       {
-               define('__RALLYE_EXTRAS', "<A href=\"".URL."/modules.php?module=login&amp;what=reflinks\">".RALLYE_GET_REFLINK."</A>");
+               $content['extras'] = getMessage('RALLYE_EXPIRE_ONE_DAY');
+       } else {
+               // Link to referal links page
+               $content['extras'] = '<a href="{%url=modules.php?module=login&amp;what=reflinks%}">{--RALLYE_GET_REFLINK--}</a>';
        }
-       // Set admin line (currently set to impressum, later to contact form)
-       define('__RALLYE_ADMIN', "<A href=\"".URL."/modules.php?module=index&amp;what=impressum&amp;admin=".$aid."\">".$login."</A>");
 
-       // Set title
-       define('__RALLYE_TITLE', COMPILE_CODE($title));
+       // Set admin line (currently set to impressum, later to contact form)
+       // @TODO Reactivate this: $content['admin'] = '<a href="{%url=modules.php?module=index&amp;what=impressum&amp;admin=' . $content['admin_id'] . '%}">' . $content['login'] . '</a>';
 
        // Handle description...
-       if ((empty($descr)) && (!empty($templ)))
-       {
+       if ((empty($content['descr'])) && (!empty($content['template']))) {
                // Use description from template
-               define('__RALLYE_DESCR', LOAD_TEMPLATE("rallye_".$templ, true));
-       }
-        else
-       {
-               // Use description from database
-               define('__RALLYE_DESCR', COMPILE_CODE($descr));
-       }
+               $content['descr'] = loadTemplate('rallye_' . $content['template'], true);
+       } // END - if
 
-       if ($min_users == 0)
-       {
-               // Rallye ends without user limitation
-               define('__RALLYE_MAX_USERS', RALLYE_END_NO_USER_LIMITATION);
-       }
-        else
-       {
-               // Rallye ends when X members are totally in your exchange
-               define('__RALLYE_MAX_USERS', RALLYE_END_USERS_1." ".$min_users." ".RALLYE_END_USERS_2);
-       }
-       if ($min_prices == 0)
-       {
-               // Rallye ends without user limitation
-               define('__RALLYE_MIN_PRICES', RALLYE_END_NO_PRICE_LIMITATION);
-       }
-        else
-       {
-               // Rallye ends when X members are totally in your exchange
-               define('__RALLYE_MIN_PRICES', RALLYE_END_PRICES_1." ".$min_prices." ".RALLYE_END_PRICES_2);
-       }
+       // Determine min_users/prices
+       $content['min_users']  = determineReferalRallyeMinimumUsers($content['min_users']);
+       $content['min_prices'] = determineReferalRallyeMinimumPrices($content['min_prices']);
 
        // Set start and end time
-       define('__RALLYE_START', MAKE_DATETIME($start, "1"));
-       define('__RALLYE_END'  , MAKE_DATETIME($end  , "1"));
+       $content['start'] = generateDateTime($content['start_time'], 1);
+       $content['end']   = generateDateTime($content['end_time']  , 1);
 
-       if ($expired)
-       {
-               define('__RALLYE_PRICES', RALLYE_LIST_WINNERS($id));
-               define('__RALLYE_TOP_USERS', "<DIV align=\"center\" class=\"big\">".__RALLYE_EXTRAS."</DIV>");
-               define('__RALLYE_CAN_WIN_THIS', RALLYE_OUR_WINNERS_ARE);
-       }
-        else
-       {
-               define('__RALLYE_PRICES', RALLYE_ADD_PRICES($id, "html"));
-               define('__RALLYE_TOP_USERS', RALLYE_ADD_TOPUSERS($id, $GLOBALS['userid']));
-               define('__RALLYE_CAN_WIN_THIS', RALLYE_YOU_CAN_WIN);
+       if ($expired === true) {
+               $content['prices']       = addReferalRallyeWinners($content['id']);
+               $content['top_users']    = '<div align="center" class="big">' . $content['extras'] . '</div>';
+               $content['can_win_this'] = getMessage('RALLYE_OUR_WINNERS_ARE');
+       } else {
+               $content['prices']       = addReferalRallyePrices($content['id'], 'html');
+               $content['top_users']    = addReferalRallyeTopUsers($content['id'], getMemberId());
+               $content['can_win_this'] = getMessage('RALLYE_YOU_CAN_WIN');
        }
 
        // And load final template
-       LOAD_TEMPLATE("guest_rallye_show");
-}
- else
-{
+       loadTemplate('guest_rallye_show', false, $content);
+} else {
        // No rallye found so far
-       LOAD_TEMPLATE("guest_no_rallyes");
+       loadTemplate('guest_no_rallyes');
 }
-//
-OUTPUT_HTML ("</DIV>");
-//
+
+// Free result
+SQL_FREERESULT($result);
+
+// [EOF]
 ?>