A lot has been rewritten, ext-teams added, ext-forced continued:
[mailer.git] / inc / libs / doubler_functions.php
index f80d13630d12a2324943b70e3ece7a4307debcf2..ecec2572b34b0b0d446b13d2cc677d5c950afa8e 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 /************************************************************************
- * MXChange v0.2.1                                    Start: 02/17/2005 *
- * ===============                              Last change: 02/17/2005 *
+ * Mailer v0.2.1-FINAL                                Start: 02/17/2005 *
+ * ===================                          Last change: 02/17/2005 *
  *                                                                      *
  * -------------------------------------------------------------------- *
  * File              : doubler_functions.php                            *
  * -------------------------------------------------------------------- *
  * Kurzbeschreibung  : Funktionen fuer den Newsletter an die Gaeste     *
  * -------------------------------------------------------------------- *
- *                                                                      *
+ * $Revision::                                                        $ *
+ * $Date::                                                            $ *
+ * $Tag:: 0.2.1-FINAL                                                 $ *
+ * $Author::                                                          $ *
  * -------------------------------------------------------------------- *
- * Copyright (c) 2003 - 2008 by Roland Haeder                           *
+ * Copyright (c) 2003 - 2009 by Roland Haeder                           *
+ * 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 *
 
 // Some security stuff...
 if (!defined('__SECURITY')) {
-       $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
-       require($INC);
-}
+       die();
+} // END - if
 
 // Generates a HTML table based on given data
 // @TODO Lame description
-function DOUBLER_GENERATE_TABLE ($uid="0", $done='N', $ref='N', $sort="ASC") {
-       global $_CONFIG;
-       if (empty($cnt)) $cnt = 0;
-       $ADD = ""; $DT_MODE = 0;
-       if ($uid > 0) {
+function generateDoublerTable ($userid = NULL, $done = 'N', $ref = 'N', $sort = 'ASC') {
+       $add = ''; $DT_MODE = '0';
+       if (isValidUserId($userid)) {
                // Load entries only from a single user
-               $ADD = " AND userid='".bigintval($uid)."'";
-               $MODE = "member"; $COLS = "4"; $DT_MODE = "2";
-               $NOT_FOUND = DOUBLER_MEMBER_NO_ENTRIES_FOUND;
+               $add = sprintf(" AND `userid`=%s", bigintval($userid));
+               $mode = 'member'; $COLS = 4; $DT_MODE = 2;
+               $message = '{--MEMBER_DOUBLER_NO_ENTRIES_FOUND--}';
        } else {
                // Guest mode!
-               $MODE = "guest"; $COLS = "3"; $DT_MODE = "3";
-               $NOT_FOUND = DOUBLER_GUEST_NO_ENTRIES_FOUND;
+               $mode = 'guest'; $COLS = 3; $DT_MODE = 3;
+               $message = '{--GUEST_DOUBLER_NO_ENTRIES_FOUND--}';
        }
 
-       if (($done == "Y") && ($sort == "ASC")) {
+       if (($done == 'Y') && ($sort == 'ASC')) {
                // Already payed out points (latest payouts first)
                $limit = getConfig('doubler_display_old');
-       } elseif ($sort == "ASC") {
+       } elseif ($sort == 'ASC') {
                // List entries which will receive their payout soon
                $limit = getConfig('doubler_display_pay');
-       } elseif ($sort == "DESC") {
+       } elseif ($sort == 'DESC') {
                // Newest entries
                $limit = getConfig('doubler_display_new');
        }
 
        // List entries
-       $result = SQL_QUERY("SELECT userid, refid, points, timemark
-FROM `{!MYSQL_PREFIX!}_doubler`
-WHERE completed='".$done."' AND is_ref='".$ref."'".$ADD."
-ORDER BY timemark ".$sort."
-LIMIT ".$limit, __FILE__, __LINE__);
+       $result = SQL_QUERY_ESC("SELECT
+       `userid`,`refid`,`points`,`timemark`
+FROM
+       `{?_MYSQL_PREFIX?}_doubler`
+WHERE
+       `completed`='%s' AND
+       `is_ref`='%s'
+       " . $add . "
+ORDER BY
+       `timemark` %s
+LIMIT %s",
+               array(
+                       $done,
+                       $ref,
+                       $sort,
+                       $limit
+               ), __FUNCTION__, __LINE__);
 
-       if (SQL_NUMROWS($result) > 0) {
+       if (!SQL_HASZERONUMS($result)) {
                // List entries
-               $OUT = ""; $SW = 2;
-               while(list($uid, $rid, $points, $time) = SQL_FETCHROW($result)) {
-                       if (IS_ADMIN()) {
+               $OUT = '';
+               while ($content = SQL_FETCHARRAY($result)) {
+                       // Rewrite userid/refid only if admin is in
+                       // @TODO Can't this be moved into EL?
+                       if (isAdmin()) {
+                               // Set empty userid/refid
+                               $content['userid'] = '---';
+                               $content['refid']  = '---';
+
                                // Set links to admin area
-                               if ($uid > 0) { $uid = ADMIN_USER_PROFILE_LINK($uid); } else { $uid = "---"; }
-                               if ($rid > 0) { $rid = ADMIN_USER_PROFILE_LINK($rid); } else { $rid = "---"; }
-                       }
+                               if (isValidUserId($content['userid'])) $content['userid'] = generateUserProfileLink($content['userid']);
+                               if (isValidUserId($content['refid']))  $content['refid']  = generateUserProfileLink($content['refid']);
+                       } // END - if
 
                        // Prepare data for the row template
-                       $content = array(
-                               'uid'    => $uid,
-                               'rid'    => $rid,
-                               'points' => TRANSLATE_COMMA($points),
-                               'stamp'  => MAKE_DATETIME($time, $DT_MODE),
-                               'sw'     => $SW,
-                       );
+                       $content['timemark'] = generateDateTime($content['timemark'], $DT_MODE);
 
                        // Load template and switch color
-                       $OUT .= LOAD_TEMPLATE($MODE."_doubler_list_rows", true, $content);
-                       $SW = 3 - $SW;
-               }
+                       $OUT .= loadTemplate($mode . '_doubler_list_rows', true, $content);
+               } // END - while
 
                // Free memory
                SQL_FREERESULT($result);
        } else {
                // List no entries
-               $OUT = "<tr>
-  <td colspan=\"".$COLS."\" align=\"center\" class=\"doubler_big_row bottom2\">
-    ".LOAD_TEMPLATE("admin_settings_saved", true, $NOT_FOUND)."
+               $OUT = '<tr>
+  <td colspan="' . $COLS . '" align="center" class="bottom">
+    ' . displayMessage($message, true) . '
   </td>
-</tr>\n";
+</tr>';
        }
 
        // Return template
-       return LOAD_TEMPLATE($MODE."_doubler_list", true, $OUT);
+       return loadTemplate($mode . '_doubler_list', true, $OUT);
 }
 
-//
-function DOUBLER_GET_TOTAL_POINTS_LEFT() {
+// Get total points left in doubler pot
+function getDoublerTotalPointsLeft() {
        // Initialize variables
-       $points = 0;
+       $points = '0';
 
-       if (getConfig('doubler_own') == "Y") {
+       if (getConfig('doubler_own') == 'Y') {
                // Take points from doubler's own account
                $points += getConfig('doubler_points') - getConfig('doubler_used');
-       }
+       } // END - if
 
-       if (getConfig('doubler_jackpot') == "Y") {
+       if ((getConfig('doubler_jackpot') == 'Y') && (isExtensionActive('jackpot'))) {
                // Load jackpot
-               $result = SQL_QUERY("SELECT points FROM `{!MYSQL_PREFIX!}_jackpot` WHERE ok='ok' LIMIT 1", __FILE__, __LINE__);
-               list($jackpot) = SQL_FETCHROW($result);
-               SQL_FREERESULT($result);
+               $jackpot = getJackpotPoints();
 
                if (!empty($jackpot)) $points += $jackpot;
-       }
+       } // END - if
 
-       if (getConfig('doubler_uid') > 0) {
+       if (isValidUserId(getConfig('doubler_userid'))) {
                // Get user's points
-               $user = GET_TOTAL_DATA(getConfig('doubler_uid'), "user_points", "points");
+               $user = getTotalPoints(getConfig('doubler_userid'));
                $points += $user;
-       }
+       } // END - if
 
        // Return value
        return $points;
 }
-//
+
+//-----------------------------------------------------------------------------
+//                      Wrapper functions for ext-doubler
+//-----------------------------------------------------------------------------
+
+// "Getter" for doubler_userid
+function getDoublerUserid () {
+       // Is it cached?
+       if (!isset($GLOBALS['doubler_userid'])) {
+               // Get it
+               $GLOBALS['doubler_userid'] = getConfig('doubler_userid');
+       } // END - if
+
+       // Return cache
+       return $GLOBALS['doubler_userid'];
+}
+
+// "Getter" for doubler_timeout
+function getDoublerTimeout () {
+       // Do we have cache?
+       if (!isset($GLOBALS[__FUNCTION__])) {
+               // Determine it
+               $GLOBALS[__FUNCTION__] = getConfig('doubler_timeout');
+       } // END - if
+
+       // Return cache
+       return $GLOBALS[__FUNCTION__];
+}
+
+// "Getter" for doubler_send_mode
+function getDoublerSendMode () {
+       // Do we have cache?
+       if (!isset($GLOBALS[__FUNCTION__])) {
+               // Determine it
+               $GLOBALS[__FUNCTION__] = getConfig('doubler_send_mode');
+       } // END - if
+
+       // Return cache
+       return $GLOBALS[__FUNCTION__];
+}
+
+// "Getter" for doubler_ref
+function getDoublerRef () {
+       // Do we have cache?
+       if (!isset($GLOBALS[__FUNCTION__])) {
+               // Determine it
+               $GLOBALS[__FUNCTION__] = getConfig('doubler_ref');
+       } // END - if
+
+       // Return cache
+       return $GLOBALS[__FUNCTION__];
+}
+
+// "Getter" for doubler_points
+function getDoublerPoints () {
+       // Do we have cache?
+       if (!isset($GLOBALS[__FUNCTION__])) {
+               // Determine it
+               $GLOBALS[__FUNCTION__] = getConfig('doubler_points');
+       } // END - if
+
+       // Return cache
+       return $GLOBALS[__FUNCTION__];
+}
+
+// "Getter" for doubler_min
+function getDoublerMin () {
+       // Do we have cache?
+       if (!isset($GLOBALS[__FUNCTION__])) {
+               // Determine it
+               $GLOBALS[__FUNCTION__] = getConfig('doubler_min');
+       } // END - if
+
+       // Return cache
+       return $GLOBALS[__FUNCTION__];
+}
+
+// "Getter" for doubler_max
+function getDoublerMax () {
+       // Do we have cache?
+       if (!isset($GLOBALS[__FUNCTION__])) {
+               // Determine it
+               $GLOBALS[__FUNCTION__] = getConfig('doubler_max');
+       } // END - if
+
+       // Return cache
+       return $GLOBALS[__FUNCTION__];
+}
+
+// "Getter" for doubler_counter
+function getDoublerCounter () {
+       // Do we have cache?
+       if (!isset($GLOBALS[__FUNCTION__])) {
+               // Determine it
+               $GLOBALS[__FUNCTION__] = getConfig('doubler_counter');
+       } // END - if
+
+       // Return cache
+       return $GLOBALS[__FUNCTION__];
+}
+
+// "Getter" for doubler_charge
+function getDoublerCharge () {
+       // Do we have cache?
+       if (!isset($GLOBALS[__FUNCTION__])) {
+               // Determine it
+               $GLOBALS[__FUNCTION__] = getConfig('doubler_charge');
+       } // END - if
+
+       // Return cache
+       return $GLOBALS[__FUNCTION__];
+}
+
+// [EOF]
 ?>