Rewrote 'we' word a little, rewrote mail order to use SQL_INSERTID() instead of anoth...
[mailer.git] / inc / libs / autopurge_functions.php
index 89abcf3deef75c61a67fe436968b9e9dc5b844ee..769099587ece6273c4c9a79d754b7d5562f57d70 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 /************************************************************************
- * MXChange v0.2.1                                    Start: 05/30/2004 *
- * ===============                              Last change: 08/09/2004 *
+ * Mailer v0.2.1-FINAL                                Start: 05/30/2004 *
+ * ===================                          Last change: 08/09/2004 *
  *                                                                      *
  * -------------------------------------------------------------------- *
  * File              : autopurge_functions.php                          *
  * -------------------------------------------------------------------- *
  * Kurzbeschreibung  : Spezielle Funktionen                             *
  * -------------------------------------------------------------------- *
- *                                                                      *
+ * $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 - 2012 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
+
+// Add points in autopurge-mode
+function addPointsAutoPurge ($userid, $points) {
+       // Is the userid valid?
+       if (!isValidUserId($userid)) {
+               // Please report all these bugs
+               reportBug(__FUNCTION__, __LINE__, 'Invalid call. userid=' . $userid . ',points=' . $points);
+       } // END - if
+
+       // Add points over the ref system directly now
+       initReferralSystem();
+       addPointsThroughReferralSystem('autopurge_add', $userid, $points);
+
+       // Send out mail to user
+       $message = loadEmailTemplate('member_autopurge_points', array('points' => $points), $userid);
+       sendEmail($userid, '{--MEMBER_AUTOPURGE_SUBJECT--}', $message);
 }
 
-function AUTOPURGE_ADD_POINTS($uid, $points) {
-       global $jackpot;
+// Checks whether auto-purging is enabled
+function isAutoPurgingActive () {
+       // Is there cache?
+       if (!isset($GLOBALS[__FUNCTION__])) {
+               // Determine it
+               $GLOBALS[__FUNCTION__] = (getConfig('auto_purge_active') == 'Y');
+       } // END - if
 
-       // Check if he has locked points or not
-       $result = SQL_QUERY_ESC("SELECT ref_payout FROM `{!MYSQL_PREFIX!}_user_data` WHERE userid=%s LIMIT 1",
-               array(bigintval($uid)), __FILE__, __LINE__);
-       list($payout) = SQL_FETCHROW($result);
-       SQL_FREERESULT($result);
+       // Return cache
+       return $GLOBALS[__FUNCTION__];
+}
 
-       if (($payout > 0) && (!empty($payout))) {
-               // Yes, he has.
-               $target = "locked_points";
-       } elseif ($payout == "0") {
-               // No, he has not
-               $target = "points";
-       }
+// Wrapper for 'autopurge_inactive
+function getAutopurgeInactive () {
+       // Is there cache?
+       if (!isset($GLOBALS[__FUNCTION__])) {
+               // Determine it
+               $GLOBALS[__FUNCTION__] = (getConfig('autopurge_inactive') == 'Y');
+       } // END - if
 
-       // Add points...
-       if (empty($payout)) {
-               // ... to jackpot account
-               ADD_JACKPOT($points);
-               if (empty($jackpot)) $jackpot = 0;
-               $jackpot += $points;
-       } else {
-               // .. to user's account
-               SQL_QUERY_ESC("UPDATE `{!MYSQL_PREFIX!}_user_points` SET %s=%s+%s WHERE userid=%s AND ref_depth=0 LIMIT 1",
-                       array($target, $target, $points, bigintval($uid)), __FILE__, __LINE__);
+       // Return cache
+       return $GLOBALS[__FUNCTION__];
+}
 
-               // Update mediadata as well
-               if ((GET_EXT_VERSION("mediadata") >= "0.0.4") && ($target == "points")) {
-                       // Update database
-                       MEDIA_UPDATE_ENTRY(array("total_points"), "add", $points);
-               }
+// Checks whether purging of inactive accounts is enabled
+function isAutopurgeInactiveEnabled () {
+       // Is there cache?
+       if (!isset($GLOBALS[__FUNCTION__])) {
+               // Determine it
+               $GLOBALS[__FUNCTION__] = (getAutopurgeInactive() == 'Y');
+       } // END - if
 
-               // Send out mail to user
-               $msg = LOAD_EMAIL_TEMPLATE("member_autopurge_points", TRANSLATE_COMMA($points), $uid);
-               SEND_EMAIL($uid, AUTOPURGE_MEMBER_SUBJECT, $msg);
-       }
+       // Return cache
+       return $GLOBALS[__FUNCTION__];
 }
 
-//
+// [EOF]
 ?>