Renamed ifSqlHasZeroNums() to ifSqlHasZeroNumRows() and improved some queries.
[mailer.git] / inc / libs / payout_functions.php
index ae0c105121c57e651421e65b277e81d82444b4fc..d7abac5fe2860013ffd654dc4ef2224974cfe437 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 /************************************************************************
- * MXChange v0.2.1                                    Start: 10/19/2003 *
- * ===============                              Last change: 08/12/2004 *
+ * Mailer v0.2.1-FINAL                                Start: 10/19/2003 *
+ * ===================                          Last change: 08/12/2004 *
  *                                                                      *
  * -------------------------------------------------------------------- *
  * File              : what-points.php                                  *
  * -------------------------------------------------------------------- *
  * Kurzbeschreibung  : Alle Ihrer gesammelten Punkte                    *
  * -------------------------------------------------------------------- *
- *                                                                      *
+ * $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 - 2015 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 (!defined('__SECURITY')) {
-       $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
-       require($INC);
-}
+       die();
+} // END - if
 
-//
-function PAYOUT_OUTPUT_PAYOUT_LIST ($points) {
-       // Replace german decimal comma with CPU's decimal dot
-       $points = strval(REVERT_COMMA($points));
+// Outputs all payout methods the user has
+function outputPayoutList ($points) {
+       // Enougth points?
        if ($points > 0) {
                // Pay this out!
-               $result = SQL_QUERY_ESC("SELECT id, type, rate, min_points
-FROM `{!_MYSQL_PREFIX!}_payout_types`
-WHERE %s >= min_points
-ORDER BY type", array($points), __FILE__, __LINE__);
-               if (SQL_NUMROWS($result) > 0) {
-                       OUTPUT_HTML("<br /><div align=\"center\">
-<div align=\"center\"><strong>{!PAYOUT_NOW!}:</strong></div><br />
-<ul>");
+               $result = sqlQueryEscaped('SELECT
+       `id`,
+       `type`,
+       `rate`,
+       `min_points`
+FROM
+       `{?_MYSQL_PREFIX?}_payout_types`
+WHERE
+       %s >= `min_points`
+ORDER BY
+       `type` ASC',
+                       array($points), __FUNCTION__, __LINE__);
+
+               // Some entries found?
+               if (!ifSqlHasZeroNumRows($result)) {
+                       // Init output
+                       $OUT = '';
+
                        // Now let's check
-                       while (list($id, $type, $rate, $mpoi) = SQL_FETCHROW($result)) {
-                               $type = COMPILE_CODE($type);
-                               if ($points >= $mpoi) {
-                                       // Ok we found one
-                                       $P = $points * $rate - 0.5;
-                                       OUTPUT_HTML("<li>{!PAYOUT_IN!}: <strong><a href=\"{!URL!}/modules.php?module=login&amp;what=payout&amp;payout=".$id."\">".$type." (".PAYOUT_MAX." ".round($P)." ".$type.")</a></strong></li>");
-                               }
-                       }
+                       while ($content = sqlFetchArray($result)) {
+                               // Are these points enougth?
+                               if ($points >= $content['min_points']) {
+                                       // Prepare content for template
+                                       $content['points'] = translateComma($points * $content['rate'] - 0.5);
+
+                                       // Load row template
+                                       $OUT .= loadTemplate('member_payout_li', TRUE, $content);
+                               } // END - if
+                       } // END - while
 
-                       OUTPUT_HTML("</ul></div>");
+                       // Load main template
+                       loadTemplate('member_payout_list', TRUE, $OUT);
                } else {
                        // No payout types setup so far
-                       LOAD_TEMPLATE("admin_settings_saved", false, "<div class=\"guest_failed\">{!PAYOUT_NO_PAYOUT_TYPES!}</div");
+                       displayErrorMessage('{--MEMBER_PAYOUT_SETUP_INCOMPLETE_LOW_POINTS--}');
                }
 
                // Free memory
-               SQL_FREERESULT($result);
+               sqlFreeResult($result);
        } else {
                // Points is empty
-               LOAD_TEMPLATE("admin_settings_saved", false, "<div class=\"guest_failed\">{!PAYOUT_NO_POINTS_ENTERED!}</div");
+               displayErrorMessage('{--MEMBER_PAYOUT_NO_POINTS_ENTERED--}');
        }
 }
 
+// "Translates" the payout status into a human-readable message
+function translatePayoutStatus ($status) {
+       // Try to get a message from given status
+       $message = '{--PAYOUT_STATUS_' . strtoupper($status) . '--}';
+
+       // Return it
+       return $message;
+}
+
+// "Getter" for payoutable user points
+function getPayoutPoints ($userid) {
+       // Is there cache?
+       if (!isset($GLOBALS[__FUNCTION__][$userid])) {
+               // Determine it
+               $GLOBALS[__FUNCTION__][$userid] = countSumTotalData($userid, 'user_points', 'points') - getUserUsedPoints($userid);
+       } // END - if
+
+       // Return it
+       return $GLOBALS[__FUNCTION__][$userid];
+}
+
 // [EOF]
 ?>