X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=inc%2Fmysql-manager.php;h=10b170f64110536234d35705385dbd168e1d78b9;hb=08c97b2c1a4b0e4d662827a07f33281d0776891e;hp=ca2a83d8eee5b4ae7ca0fbccfbc9692c59fe06ec;hpb=0d04965b62daa3f867aeebfac26900f1dad604d3;p=mailer.git
diff --git a/inc/mysql-manager.php b/inc/mysql-manager.php
index ca2a83d8ee..10b170f641 100644
--- a/inc/mysql-manager.php
+++ b/inc/mysql-manager.php
@@ -101,7 +101,7 @@ function CHECK_MODULE($mod) {
if ((!isBooleanConstantAndTrue('mxchange_installed')) || (isBooleanConstantAndTrue('mxchange_installing')) || (!isBooleanConstantAndTrue('admin_registered'))) return "done";
// Check if cache is latest version
- $locked = 'Y'; $hidden = 'N'; $admin = 'N'; $mem = 'N'; $found = false;
+ $locked = "Y"; $hidden = "N"; $admin = "N"; $mem = "N"; $found = false;
if ((GET_EXT_VERSION("cache") >= "0.1.2") && (isset($cacheArray['modules']['module'])) && (is_array($cacheArray['modules']['module']))) {
// Is the module cached?
if (isset($cacheArray['modules']['locked'][$mod_chk])) {
@@ -132,16 +132,16 @@ function CHECK_MODULE($mod) {
// Check returned values against current access permissions
//
// Admin access ----- Guest access ----- --- Guest or member? ---
- if ((IS_ADMIN()) || (($locked == 'N') && ($admin == 'N') && (($mem == 'N') || (IS_LOGGED_IN())))) {
+ if ((IS_ADMIN()) || (($locked == "N") && ($admin == "N") && (($mem == "N") || (IS_LOGGED_IN())))) {
// If you are admin you are welcome for everything!
$ret = "done";
- } elseif ($locked == 'Y') {
+ } elseif ($locked == "Y") {
// Module is locked
$ret = "locked";
- } elseif (($mem == 'Y') && (!IS_LOGGED_IN())) {
+ } elseif (($mem == "Y") && (!IS_LOGGED_IN())) {
// You have to login first!
$ret = "mem_only";
- } elseif (($admin == 'Y') && (!IS_ADMIN())) {
+ } elseif (($admin == "Y") && (!IS_ADMIN())) {
// Only the Admin is allowed to enter this module!
$ret = "admin_only";
}
@@ -209,7 +209,7 @@ function ADD_DESCR($ACC_LVL, $file, $return = false, $output = true) {
$MOD_CHECK = $GLOBALS['module'];
break;
}
- $AND = " AND what=''";
+ $AND = " AND (what='' OR what IS NULL)";
} elseif (ereg("what-", $file)) {
// This is an admin what file!
$type = "what";
@@ -267,7 +267,7 @@ function ADD_DESCR($ACC_LVL, $file, $return = false, $output = true) {
if ($return) {
// Return title
return $ret;
- } elseif (((GET_EXT_VERSION("sql_patches") >= "0.2.3") && ($_CONFIG['youre_here'] == 'Y')) || ((IS_ADMIN()) && ($MOD_CHECK == "admin"))) {
+ } elseif (((GET_EXT_VERSION("sql_patches") >= "0.2.3") && ($_CONFIG['youre_here'] == "Y")) || ((IS_ADMIN()) && ($MOD_CHECK == "admin"))) {
// Output HTML code
$OUT = $prefix."".$ret."\n";
//* DEBUG: */ echo __LINE__."*".$type."/".$GLOBALS['what']."*
\n";
@@ -306,7 +306,7 @@ function ADD_MENU($MODE, $act, $wht) {
}
// Load SQL data and add the menu to the output stream...
- $result_main = SQL_QUERY_ESC("SELECT title, action FROM "._MYSQL_PREFIX."_%s_menu WHERE what='' ".$AND." ORDER BY sort",
+ $result_main = SQL_QUERY_ESC("SELECT title, action FROM "._MYSQL_PREFIX."_%s_menu WHERE (what='' OR what IS NULL) ".$AND." ORDER BY sort",
array($MODE), __FILE__, __LINE__);
//* DEBUG: */ echo __LINE__."/".$main_cnt."/".$main_action."/".$sub_what.":".$GLOBALS['what']."*
\n";
if (SQL_NUMROWS($result_main) > 0) {
@@ -364,7 +364,7 @@ function ADD_MENU($MODE, $act, $wht) {
} else {
// This is a menu block... ;-)
$BLOCK_MODE = true;
- $INC_BLOCK = sprintf(PATH."inc/modules/%s/action-%s.php", $MODE, $main_action);
+ $INC_BLOCK = sprintf("%sinc/modules/%s/action-%s.php", PATH, $MODE, $main_action);
if ((file_exists($INC_BLOCK)) && (is_readable($INC_BLOCK))) {
// Load include file
if ((!EXT_IS_ACTIVE($main_action)) || ($main_action == "online")) OUTPUT_HTML("
@@ -400,8 +400,8 @@ function IS_ADMIN($admin="")
// If admin login is not given take current from cookies...
if ((empty($admin)) && (isSessionVariableSet('admin_login')) && (isSessionVariableSet('admin_md5'))) {
// Get admin login and password from session/cookies
- $admin = SQL_ESCAPE(get_session('admin_login'));
- $passCookie = SQL_ESCAPE(get_session('admin_md5'));
+ $admin = get_session('admin_login');
+ $passCookie = get_session('admin_md5');
}
//* DEBUG: */ echo __LINE__."ADMIN:".$admin."/".$passCookie."
";
@@ -438,7 +438,7 @@ function IS_ADMIN($admin="")
}
// Return result of comparision
- /* DEBUG: */ if (!$ret) echo __LINE__."OK!
";
+ //* DEBUG: */ if (!$ret) echo __LINE__."OK!
";
return $ret;
}
//
@@ -551,7 +551,7 @@ function IS_LOGGED_IN()
if ((!empty($GLOBALS['userid'])) && (isSessionVariableSet('u_hash')) && (isSessionVariableSet('lifetime')) && (defined('COOKIE_PATH')))
{
// Cookies are set with values, but are they valid?
- $result = SQL_QUERY_ESC("SELECT password, status, last_module, last_online FROM "._MYSQL_PREFIX."_user_data WHERE userid=%d LIMIT 1",
+ $result = SQL_QUERY_ESC("SELECT password, status, last_module, last_online FROM "._MYSQL_PREFIX."_user_data WHERE userid=%s LIMIT 1",
array($GLOBALS['userid']), __FILE__, __LINE__);
if (SQL_NUMROWS($result) == 1)
{
@@ -572,9 +572,7 @@ function IS_LOGGED_IN()
} else {
// Maybe got locked etc.
//* DEBUG: */ echo __LINE__."!!!
";
- set_session("userid", "");
- set_session("u_hash", "");
- set_session("lifetime", "");
+ destroy_user_session();
// Remove array elements to prevent errors
unset($GLOBALS['userid']);
@@ -582,9 +580,6 @@ function IS_LOGGED_IN()
} else {
// Cookie data is invalid!
//* DEBUG: */ echo __LINE__."***
";
- set_session("userid", "");
- set_session("u_hash", "");
- set_session("lifetime", "");
// Remove array elements to prevent errors
unset($GLOBALS['userid']);
@@ -597,9 +592,7 @@ function IS_LOGGED_IN()
{
// Cookie data is invalid!
//* DEBUG: */ echo __LINE__."///
";
- set_session("userid", "");
- set_session("u_hash", "");
- set_session("lifetime", "");
+ destroy_user_session();
// Remove array elements to prevent errors
unset($GLOBALS['userid']);
@@ -627,7 +620,7 @@ function UPDATE_LOGIN_DATA ($UPDATE=true) {
if (!IS_LOGGED_IN()) return false;
// Load last module and last online time
- $result = SQL_QUERY_ESC("SELECT last_module, last_online FROM "._MYSQL_PREFIX."_user_data WHERE userid=%d LIMIT 1", array($GLOBALS['userid']), __FILE__, __LINE__);
+ $result = SQL_QUERY_ESC("SELECT last_module, last_online FROM "._MYSQL_PREFIX."_user_data WHERE userid=%s LIMIT 1", array($GLOBALS['userid']), __FILE__, __LINE__);
if (SQL_NUMROWS($result) == 1) {
// Load last module and online time
list($mod, $onl) = SQL_FETCHROW($result);
@@ -636,7 +629,7 @@ function UPDATE_LOGIN_DATA ($UPDATE=true) {
// Maybe first login time?
if (empty($mod)) $mod = "login";
- if (set_session("userid", $GLOBALS['userid'], $newl, COOKIE_PATH) && set_session("u_hash", SQL_ESCAPE(get_session('u_hash')), $newl, COOKIE_PATH) && set_session("lifetime", bigintval(get_session('lifetime')), $newl, COOKIE_PATH)) {
+ if (set_session("userid", $GLOBALS['userid'], $newl, COOKIE_PATH) && set_session("u_hash", get_session('u_hash'), $newl, COOKIE_PATH) && set_session("lifetime", bigintval(get_session('lifetime')), $newl, COOKIE_PATH)) {
// This will be displayed on welcome page! :-)
if (empty($LAST['module'])) {
$LAST['module'] = $mod; $LAST['online'] = $onl;
@@ -646,14 +639,12 @@ function UPDATE_LOGIN_DATA ($UPDATE=true) {
}
// Update last module / online time
- $result = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_user_data SET last_module='%s', last_online=UNIX_TIMESTAMP() WHERE userid=%d LIMIT 1",
+ $result = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_user_data SET last_module='%s', last_online=UNIX_TIMESTAMP() WHERE userid=%s LIMIT 1",
array($GLOBALS['what'], $GLOBALS['userid']), __FILE__, __LINE__);
}
} else {
// Destroy session, we cannot update!
- set_session("userid", "");
- set_session("u_hash", "");
- set_session("lifetime", "");
+ destroy_user_session();
}
}
//
@@ -679,7 +670,7 @@ function VALIDATE_MENU_ACTION ($MODE, $act, $wht, $UPDATE=false)
else
{
// Admin login overview
- $SQL = SQL_QUERY_ESC("SELECT id, what FROM "._MYSQL_PREFIX."_%s_menu WHERE action='%s' AND what=''".$ADD." ORDER BY action DESC LIMIT 1",
+ $SQL = SQL_QUERY_ESC("SELECT id, what FROM "._MYSQL_PREFIX."_%s_menu WHERE action='%s' AND (what='' OR what IS NULL)".$ADD." ORDER BY action DESC LIMIT 1",
array($MODE, $act), __FILE__, __LINE__, false);
}
@@ -702,7 +693,8 @@ function VALIDATE_MENU_ACTION ($MODE, $act, $wht, $UPDATE=false)
// Free memory
SQL_FREERESULT($result);
- //* DEBUG: */ var_dump($ret);
+
+ // Return result
return $ret;
}
//
@@ -724,7 +716,7 @@ function SEND_MODE_MAILS($mod, $modes)
global $_CONFIG, $DATA;
// Load hash
- $result_main = SQL_QUERY_ESC("SELECT password FROM "._MYSQL_PREFIX."_user_data WHERE userid=%d AND status='CONFIRMED' LIMIT 1",
+ $result_main = SQL_QUERY_ESC("SELECT password FROM "._MYSQL_PREFIX."_user_data WHERE userid=%s AND status='CONFIRMED' LIMIT 1",
array($GLOBALS['userid']), __FILE__, __LINE__);
if (SQL_NUMROWS($result_main) == 1) {
// Load hash from database
@@ -737,7 +729,7 @@ function SEND_MODE_MAILS($mod, $modes)
$hash = generatePassString($hashDB);
if (($hash == get_session('u_hash')) || ($_POST['pass1'] == $_POST['pass2'])) {
// Load user's data
- $result = SQL_QUERY_ESC("SELECT sex, surname, family, street_nr, country, zip, city, email FROM "._MYSQL_PREFIX."_user_data WHERE userid=%d AND password='%s' LIMIT 1",
+ $result = SQL_QUERY_ESC("SELECT sex, surname, family, street_nr, country, zip, city, email FROM "._MYSQL_PREFIX."_user_data WHERE userid=%s AND password='%s' LIMIT 1",
array($GLOBALS['userid'], $hashDB), __FILE__, __LINE__);
if (SQL_NUMROWS($result) == 1) {
// Load the data
@@ -783,7 +775,7 @@ function SEND_MODE_MAILS($mod, $modes)
// Load template
$msg = LOAD_EMAIL_TEMPLATE("member_mydata_notify", $content, $GLOBALS['userid']);
- if ($_CONFIG['admin_notify'] == 'Y') {
+ if ($_CONFIG['admin_notify'] == "Y") {
// The admin needs to be notified about a profile change
$msg_admin = "admin_mydata_notify";
$sub_adm = ADMIN_CHANGED_DATA;
@@ -827,12 +819,8 @@ function SEND_MODE_MAILS($mod, $modes)
if (empty($content)) {
if ((!empty($sub_adm)) && (!empty($msg_admin))) {
// Send admin mail
- if (GET_EXT_VERSION("admins") >= "0.4.1") {
- SEND_ADMIN_EMAILS_PRO($sub_adm, $msg_admin, $content, $GLOBALS['userid']);
- } else {
- SEND_ADMIN_EMAILS($sub_adm, LOAD_EMAIL_TEMPLATE($msg_admin, $content, $GLOBALS['userid']));
- }
- } elseif ($_CONFIG['admin_notify'] == 'Y') {
+ SEND_ADMIN_NOTIFICATION($sub_adm, $msg_admin, $content, $GLOBALS['userid']);
+ } elseif ($_CONFIG['admin_notify'] == "Y") {
// Cannot send mails to admin!
$content = CANNOT_SEND_ADMIN_MAILS;
} else {
@@ -919,46 +907,55 @@ function GET_ACTION ($MODE, &$wht)
return $ret;
}
//
-function GET_CATEGORY ($cid)
-{
+function GET_CATEGORY ($cid) {
+ // Default is not found
$ret = _CATEGORY_404;
- $result = SQL_QUERY_ESC("SELECT cat FROM "._MYSQL_PREFIX."_cats WHERE id=%d LIMIT 1", array($cid), __FILE__, __LINE__);
- if (SQL_NUMROWS($result) == 1)
- {
+
+ // Lookup the category
+ $result = SQL_QUERY_ESC("SELECT cat FROM "._MYSQL_PREFIX."_cats WHERE id=%s LIMIT 1",
+ array(bigintval($cid)), __FILE__, __LINE__);
+ if (SQL_NUMROWS($result) == 1) {
// Category found... :-)
list($ret) = SQL_FETCHROW($result);
- SQL_FREERESULT($result);
- }
+ } // END - if
+
+ // Free result
+ SQL_FREERESULT($result);
+
+ // Return result
return $ret;
}
//
-function GET_PAYMENT ($pid, $full=false)
-{
+function GET_PAYMENT ($pid, $full=false) {
+ // Default is not found
$ret = _PAYMENT_404;
- $result = SQL_QUERY_ESC("SELECT mail_title, price FROM "._MYSQL_PREFIX."_payments WHERE id=%d LIMIT 1", array($pid), __FILE__, __LINE__);
- if (SQL_NUMROWS($result) == 1)
- {
+
+ // Load payment data
+ $result = SQL_QUERY_ESC("SELECT mail_title, price FROM "._MYSQL_PREFIX."_payments WHERE id=%s LIMIT 1",
+ array(bigintval($pid)), __FILE__, __LINE__);
+ if (SQL_NUMROWS($result) == 1) {
// Payment type found... :-)
- if (!$full)
- {
+ if (!$full) {
// Return only title
list($ret) = SQL_FETCHROW($result);
- SQL_FREERESULT($result);
- }
- else
- {
+ } else {
// Return title and price
list($t, $p) = SQL_FETCHROW($result);
$ret = $t." / ".TRANSLATE_COMMA($p)." ".POINTS;
}
}
+
+ // Free result
+ SQL_FREERESULT($result);
+
+ // Return result
return $ret;
}
//
function GET_PAY_POINTS($pid, $lookFor="price")
{
$ret = "-1";
- $result = SQL_QUERY_ESC("SELECT %s FROM "._MYSQL_PREFIX."_payments WHERE id=%d LIMIT 1",
+ $result = SQL_QUERY_ESC("SELECT %s FROM "._MYSQL_PREFIX."_payments WHERE id=%s LIMIT 1",
array($lookFor, $pid), __FILE__, __LINE__);
if (SQL_NUMROWS($result) == 1)
{
@@ -983,7 +980,7 @@ function REMOVE_RECEIVER(&$ARRAY, $key, $uid, $pool_id, $stats_id="", $bonus=fal
// Only when we got a real stats ID continue searching for the entry
$type = "NORMAL"; $rowName = "stats_id";
if ($bonus) { $type = "BONUS"; $rowName = "bonus_id"; }
- $result = SQL_QUERY_ESC("SELECT id FROM "._MYSQL_PREFIX."_user_links WHERE %s='%s' AND userid=%d AND link_type='%s' LIMIT 1",
+ $result = SQL_QUERY_ESC("SELECT id FROM "._MYSQL_PREFIX."_user_links WHERE %s='%s' AND userid=%s AND link_type='%s' LIMIT 1",
array($rowName, $stats_id, bigintval($uid), $type), __FILE__, __LINE__);
if (SQL_NUMROWS($result) == 0)
{
@@ -1039,7 +1036,7 @@ function GET_TOTAL_DATA($search, $tableName, $lookFor, $whereStatement="userid",
* uid = Referral ID wich should receive...
* points = ... xxx points
* send_notify = shall I send the referral an email or not?
- * refid = inc/modules/guest/what-confirm.php need this
+ * rid = inc/modules/guest/what-confirm.php need this
* locked = Shall I pay it to normal (false) or locked (true) points ammount?
* add_mode = Add points only to $uid or also refs? (WARNING! Changing "ref" to "direct"
* will cause no referral will get points ever!!!)
@@ -1048,6 +1045,9 @@ function ADD_POINTS_REFSYSTEM($uid, $points, $send_notify=false, $rid="0", $lock
{
global $DEPTH, $_CONFIG, $DATA, $link;
+ // Debug message
+ //DEBUG_LOG(__FUNCTION__.": uid={$uid},points={$points}");
+
// When $uid = 0 add points to jackpot
if ($uid == "0") {
// Add points to jackpot
@@ -1064,51 +1064,72 @@ function ADD_POINTS_REFSYSTEM($uid, $points, $send_notify=false, $rid="0", $lock
$DEPTH++;
}
+ // Percents and table
+ $percents = "percents"; if (isset($_CONFIG['db_percents'])) $percents = $_CONFIG['db_percents'];
+ $table = "refdepths"; if (isset($_CONFIG['db_table'])) $table = $_CONFIG['db_table'];
+
// Which points, locked or normal?
$data = "points"; if ($locked) $data = "locked_points";
- $result_user = SQL_QUERY_ESC("SELECT refid, email FROM "._MYSQL_PREFIX."_user_data WHERE userid=%d AND status='CONFIRMED' LIMIT 1",
+ // Check user account
+ $result_user = SQL_QUERY_ESC("SELECT refid, email FROM "._MYSQL_PREFIX."_user_data WHERE userid=%s AND status='CONFIRMED' LIMIT 1",
array(bigintval($uid)), __FILE__, __LINE__);
+
//* DEBUG */ echo "+".SQL_NUMROWS($result_user).":".$points."+
\n";
if (SQL_NUMROWS($result_user) == 1) {
// This is the user and his ref
list ($ref, $email) = SQL_FETCHROW($result_user);
- SQL_FREERESULT($result_user);
- $result = SQL_QUERY_ESC("SELECT percents FROM "._MYSQL_PREFIX."_refdepths WHERE level='%s' LIMIT 1",
- array(bigintval($DEPTH)), __FILE__, __LINE__);
+ // Debug message
+ //DEBUG_LOG(__FUNCTION__.": ref={$ref},email={$email},DEPTH={$DEPTH}");
+
+ // Get referal data
+ $result_lvl = SQL_QUERY_ESC("SELECT %s FROM "._MYSQL_PREFIX."_%s WHERE level='%s' LIMIT 1",
+ array($percents, $table, bigintval($DEPTH)), __FILE__, __LINE__);
//* DEBUG */ echo "DEPTH:".$DEPTH."
\n";
- if (SQL_NUMROWS($result) == 1) {
- list($per) = SQL_FETCHROW($result);
- SQL_FREERESULT($result);
- $P = $points * $per / 100;
- //* DEBUG */ echo "ADD:".$P."
\n";
+ if (SQL_NUMROWS($result_lvl) == 1) {
+ // Get percents
+ list($per) = SQL_FETCHROW($result_lvl);
+
+ // Calculate new points
+ $ref_points = $points * $per / 100;
+
+ // Debug message
+ //DEBUG_LOG(__FUNCTION__.": percent={$per},ref_points={$ref_points}");
// Update points...
- $result = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_user_points SET %s=%s+%s WHERE userid=%d AND ref_depth=%d LIMIT 1",
- array($data, $data, $P, bigintval($uid), bigintval($DEPTH)), __FILE__, __LINE__);
- if (SQL_AFFECTEDROWS($link, __FILE__, __LINE__) == 0) {
+ SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_user_points SET %s=%s+%s WHERE userid=%s AND ref_depth=%d LIMIT 1",
+ array($data, $data, $ref_points, bigintval($uid), bigintval($DEPTH)), __FILE__, __LINE__);
+
+ // Debug log
+ //DEBUG_LOG(__FUNCTION__.": affectedRows=".SQL_AFFECTEDROWS().",DEPTH={$DEPTH}");
+
+ // No entry updated?
+ if (SQL_AFFECTEDROWS() == 0) {
// First ref in this level! :-)
- $result = SQL_QUERY_ESC("INSERT INTO "._MYSQL_PREFIX."_user_points (userid, ref_depth, %s) VALUES (%d, %d, %s)",
- array($data, bigintval($uid), bigintval($DEPTH), $P), __FILE__, __LINE__);
- }
+ $result = SQL_QUERY_ESC("INSERT INTO "._MYSQL_PREFIX."_user_points (userid, ref_depth, %s) VALUES (%s, %d, %s)",
+ array($data, bigintval($uid), bigintval($DEPTH), $ref_points), __FILE__, __LINE__);
+
+ // Debug log
+ //DEBUG_LOG(__FUNCTION__.": insertedRows=".SQL_AFFECTEDROWS()."");
+ } // END - if
// Update mediadata as well
if (GET_EXT_VERSION("mediadata") >= "0.0.4") {
// Update database
- MEDIA_UPDATE_ENTRY(array("total_points"), "add", $P);
- }
+ MEDIA_UPDATE_ENTRY(array("total_points"), "add", $ref_points);
+ } // END - if
// Points updated, maybe I shall send him an email?
if (($send_notify) && ($ref > 0) && (!$locked)) {
// 0 1 2 3
- $DATA = array($per, bigintval($DEPTH), $P, bigintval($ref));
+ $DATA = array($per, bigintval($DEPTH), $ref_points, bigintval($ref));
$msg = LOAD_EMAIL_TEMPLATE("confirm-referral", "", bigintval($uid));
SEND_EMAIL($email, THANX_REFERRAL_ONE, $msg);
} elseif (($send_notify) && ($ref == 0) && (!$locked) && ($add_mode == "direct") && (!defined('__POINTS_VALUE'))) {
// Direct payment shall be notified about
- define('__POINTS_VALUE', $P);
+ define('__POINTS_VALUE', $ref_points);
// Load message
$msg = LOAD_EMAIL_TEMPLATE("add-points", REASON_DIRECT_PAYMENT, $uid);
@@ -1124,7 +1145,13 @@ function ADD_POINTS_REFSYSTEM($uid, $points, $send_notify=false, $rid="0", $lock
ADD_POINTS_REFSYSTEM($ref, $points, $send_notify, $ref, $locked);
}
}
+
+ // Free result
+ SQL_FREERESULT($result_lvl);
}
+
+ // Free result
+ SQL_FREERESULT($result_user);
}
//
function UPDATE_REF_COUNTER($uid)
@@ -1134,7 +1161,7 @@ function UPDATE_REF_COUNTER($uid)
if (empty($REF_LVL)) $REF_LVL = "0";
// Update counter
- $result = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_refsystem SET counter=counter+1 WHERE userid=%d AND level='%s' LIMIT 1",
+ $result = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_refsystem SET counter=counter+1 WHERE userid=%s AND level='%s' LIMIT 1",
array(bigintval($uid), $REF_LVL), __FILE__, __LINE__);
// When no entry was updated then we have to create it here
@@ -1146,7 +1173,7 @@ function UPDATE_REF_COUNTER($uid)
}
// Check for his referral
- $result = SQL_QUERY_ESC("SELECT refid FROM "._MYSQL_PREFIX."_user_data WHERE userid=%d LIMIT 1",
+ $result = SQL_QUERY_ESC("SELECT refid FROM "._MYSQL_PREFIX."_user_data WHERE userid=%s LIMIT 1",
array(bigintval($uid)), __FILE__, __LINE__);
list($ref) = SQL_FETCHROW($result);
@@ -1173,7 +1200,7 @@ function UPDATE_ONLINE_LIST($SID, $mod, $act, $wht)
if (!EXT_IS_ACTIVE("online", true)) return;
// Initialize variables
- $uid = "0"; $rid = "0"; $MEM = 'N'; $ADMIN = 'N';
+ $uid = "0"; $rid = "0"; $MEM = "N"; $ADMIN = "N";
if (!empty($GLOBALS['userid']))
{
// Update member status only when userid is valid
@@ -1181,13 +1208,13 @@ function UPDATE_ONLINE_LIST($SID, $mod, $act, $wht)
{
// Is valid user
$uid = $GLOBALS['userid'];
- $MEM = 'Y';
+ $MEM = "Y";
}
}
if (IS_ADMIN())
{
// Is administrator
- $ADMIN = 'Y';
+ $ADMIN = "Y";
}
if (isSessionVariableSet('refid')) {
// Check cookie
@@ -1206,8 +1233,8 @@ WHERE sid='%s' LIMIT 1",
module='%s',
action='%s',
what='%s',
-userid=%d,
-refid=%d,
+userid=%s,
+refid=%s,
is_member='%s',
is_admin='%s',
timestamp=UNIX_TIMESTAMP()
@@ -1226,46 +1253,46 @@ WHERE sid='%s' LIMIT 1",
else
{
// No entry does exists so we simply add it!
- $result = SQL_QUERY_ESC("INSERT INTO "._MYSQL_PREFIX."_online (module, action, what, userid, refid, is_member, is_admin, timestamp, sid, ip) VALUES ('%s', '%s', '%s', %d, %d, '%s', '%s', UNIX_TIMESTAMP(), '%s', '%s')",
+ $result = SQL_QUERY_ESC("INSERT INTO "._MYSQL_PREFIX."_online (module, action, what, userid, refid, is_member, is_admin, timestamp, sid, ip) VALUES ('%s', '%s', '%s', %s, %s, '%s', '%s', UNIX_TIMESTAMP(), '%s', '%s')",
array($mod, $act, $wht, bigintval($uid), bigintval($rid), $MEM, $ADMIN, $SID, getenv('REMOTE_ADDR')), __FILE__, __LINE__);
}
// Purge old entries
- $result = SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM "._MYSQL_PREFIX."_online WHERE timestamp <= (UNIX_TIMESTAMP() - %d)",
+ $result = SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM "._MYSQL_PREFIX."_online WHERE timestamp <= (UNIX_TIMESTAMP() - %s)",
array($_CONFIG['online_timeout']), __FILE__, __LINE__);
}
// OBSULETE: Sends out mail to all administrators
-function SEND_ADMIN_EMAILS($subj, $msg)
-{
- $result = SQL_QUERY("SELECT email FROM "._MYSQL_PREFIX."_admins ORDER BY id", __FILE__, __LINE__);
- while (list($email) = SQL_FETCHROW($result))
- {
+function SEND_ADMIN_EMAILS($subj, $msg) {
+ // Load all admin email addresses
+ $result = SQL_QUERY("SELECT email FROM "._MYSQL_PREFIX."_admins ORDER BY id ASC", __FILE__, __LINE__);
+ while (list($email) = SQL_FETCHROW($result)) {
+ // Send the email out
SEND_EMAIL($email, $subj, $msg);
- }
- // Really simple... ;-)
+ } // END - if
+
+ // Free result
SQL_FREERESULT($result);
+
+ // Really simple... ;-)
}
// Get ID number from administrator's login name
-function GET_ADMIN_ID($login)
-{
+function GET_ADMIN_ID($login) {
global $cacheArray;
$ret = "-1";
- if (!empty($cacheArray['admins']['aid'][$login]))
- {
+ if (!empty($cacheArray['admins']['aid'][$login])) {
// Check cache
$ret = $cacheArray['admins']['aid'][$login];
if (empty($ret)) $ret = "-1";
- }
- else
- {
+ } else {
// Load from database
$result = SQL_QUERY_ESC("SELECT id FROM "._MYSQL_PREFIX."_admins WHERE login='%s' LIMIT 1",
array($login), __FILE__, __LINE__);
- if (SQL_NUMROWS($result) == 1)
- {
+ if (SQL_NUMROWS($result) == 1) {
list($ret) = SQL_FETCHROW($result);
- SQL_FREERESULT($result);
- }
+ } // END - if
+
+ // Free result
+ SQL_FREERESULT($result);
}
return $ret;
}
@@ -1295,25 +1322,25 @@ function GET_ADMIN_HASH($login)
return $ret;
}
//
-function GET_ADMIN_LOGIN($aid)
-{
+function GET_ADMIN_LOGIN ($aid) {
global $cacheArray;
$ret = "***";
- if (!empty($cacheArray['admins']['login']['aid']))
- {
+ if (!empty($cacheArray['admins']['login'])) {
// Check cache
- if (!empty($cacheArray['admins']['login'][$aid])) $ret = $cacheArray['admins']['login'][$aid];
+ if (!empty($cacheArray['admins']['login'][$aid])) {
+ $ret = $cacheArray['admins']['login'][$aid];
+ } // END - if
if (empty($ret)) $ret = "***";
- }
- else
- {
+ } else {
// Load from database
- $result = SQL_QUERY_ESC("SELECT login FROM "._MYSQL_PREFIX."_admins WHERE id=%d LIMIT 1",
+ $result = SQL_QUERY_ESC("SELECT login FROM "._MYSQL_PREFIX."_admins WHERE id=%s LIMIT 1",
array(bigintval($aid)), __FILE__, __LINE__);
- if (SQL_NUMROWS($result) == 1)
- {
+ if (SQL_NUMROWS($result) == 1) {
// Fetch data
list($ret) = SQL_FETCHROW($result);
+
+ // Set cache
+ $cacheArray['admins']['login'][$aid] = $ret;
}
// Free memory
@@ -1322,25 +1349,19 @@ function GET_ADMIN_LOGIN($aid)
return $ret;
}
//
-function ADD_OPTION_LINES($table, $id, $name, $default="",$special="",$where="")
-{
+function ADD_OPTION_LINES($table, $id, $name, $default="",$special="",$where="") {
$ret = "";
- if ($table == "/ARRAY/")
- {
+ if ($table == "/ARRAY/") {
// Selection from array
- if (is_array($id) && is_array($name) && sizeof($id) == sizeof($name))
- {
+ if (is_array($id) && is_array($name) && sizeof($id) == sizeof($name)) {
// Both are arrays
- foreach ($id as $idx=>$value)
- {
+ foreach ($id as $idx=>$value) {
$ret .= "\n";
}
}
+
// Return - hopefully - the requested data
return $ret;
}
@@ -1389,12 +1407,11 @@ function activateExchange() {
);
// Run SQLs
- foreach ($SQLs as $sql)
- {
+ foreach ($SQLs as $sql) {
$result = SQL_QUERY($sql, __FILE__, __LINE__);
}
- // Destroy cache
+ // @TODO Destroy cache
}
}
//
@@ -1405,19 +1422,17 @@ function DELETE_USER_ACCOUNT($uid, $reason)
FROM "._MYSQL_PREFIX."_user_points AS p
LEFT JOIN "._MYSQL_PREFIX."_user_data AS d
ON p.userid=d.userid
-WHERE p.userid=%d", array(bigintval($uid)), __FILE__, __LINE__);
- if (SQL_NUMROWS($result) == 1)
- {
+WHERE p.userid=%s", array(bigintval($uid)), __FILE__, __LINE__);
+ if (SQL_NUMROWS($result) == 1) {
// Save his points to add them to the jackpot
list($points) = SQL_FETCHROW($result);
SQL_FREERESULT($result);
// Delete points entries as well
- $result = SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM "._MYSQL_PREFIX."_user_points WHERE userid=%d", array(bigintval($uid)), __FILE__, __LINE__);
+ $result = SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM "._MYSQL_PREFIX."_user_points WHERE userid=%s", array(bigintval($uid)), __FILE__, __LINE__);
// Update mediadata as well
- if (GET_EXT_VERSION("mediadata") >= "0.0.4")
- {
+ if (GET_EXT_VERSION("mediadata") >= "0.0.4") {
// Update database
MEDIA_UPDATE_ENTRY(array("total_points"), "sub", $points);
}
@@ -1427,13 +1442,12 @@ WHERE p.userid=%d", array(bigintval($uid)), __FILE__, __LINE__);
}
// Delete category selections as well...
- $result = SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM "._MYSQL_PREFIX."_user_cats WHERE userid=%d",
+ $result = SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM "._MYSQL_PREFIX."_user_cats WHERE userid=%s",
array(bigintval($uid)), __FILE__, __LINE__);
// Remove from rallye if found
- if (EXT_IS_ACTIVE("rallye"))
- {
- $result = SQL_QUERY("DELETE LOW_PRIORITY FROM "._MYSQL_PREFIX."_rallye_users WHERE userid=%d",
+ if (EXT_IS_ACTIVE("rallye")) {
+ $result = SQL_QUERY("DELETE LOW_PRIORITY FROM "._MYSQL_PREFIX."_rallye_users WHERE userid=%s",
array(bigintval($uid)), __FILE__, __LINE__);
}
@@ -1442,7 +1456,7 @@ WHERE p.userid=%d", array(bigintval($uid)), __FILE__, __LINE__);
SEND_EMAIL($uid, ADMIN_DEL_ACCOUNT, $msg);
// Ok, delete the account!
- $result = SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM "._MYSQL_PREFIX."_user_data WHERE userid=%d LIMIT 1", array(bigintval($uid)), __FILE__, __LINE__);
+ $result = SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM "._MYSQL_PREFIX."_user_data WHERE userid=%s LIMIT 1", array(bigintval($uid)), __FILE__, __LINE__);
}
//
function META_DESCRIPTION($mod, $wht)
@@ -1509,8 +1523,7 @@ function IS_DEMO() {
return ((EXT_IS_ACTIVE("demo")) && (get_session('admin_login') == "demo"));
}
//
-function LOAD_CONFIG($no="0")
-{
+function LOAD_CONFIG($no="0") {
global $cacheArray;
$CFG_DUMMY = array();
@@ -1520,7 +1533,7 @@ function LOAD_CONFIG($no="0")
//* DEBUG: */ echo gettype($cacheArray['config'][$no])."
\n";
foreach ($cacheArray['config'][$no] as $key=>$value) {
$CFG_DUMMY[$key] = $value;
- }
+ } // END - foreach
// Count cache hits if exists
if ((isset($CFG_DUMMY['cache_hits'])) && (EXT_IS_ACTIVE("cache"))) {
@@ -1545,8 +1558,7 @@ function LOAD_CONFIG($no="0")
return $CFG_DUMMY;
}
// Gets the matching what name from module
-function GET_WHAT($MOD_CHECK)
-{
+function GET_WHAT($MOD_CHECK) {
$wht = "";
//* DEBUG: */ echo __LINE__."!".$MOD_CHECK."!
\n";
switch ($MOD_CHECK)
@@ -1575,42 +1587,150 @@ function MODULE_HAS_MENU($mod)
// All is false by default
$ret = false;
- if (GET_EXT_VERSION("cache") >= "0.1.2")
- {
+ if (GET_EXT_VERSION("cache") >= "0.1.2") {
if (isset($cacheArray['modules']['has_menu'][$mod]))
{
// Check module cache and count hit
- if ($cacheArray['modules']['has_menu'][$mod] == 'Y') $ret = true;
+ $ret = ($cacheArray['modules']['has_menu'][$mod] == "Y");
$_CONFIG['cache_hits']++;
}
elseif (isset($cacheArray['extensions']['ext_menu'][$mod]))
{
// Check cache and count hit
- if ($cacheArray['extensions']['ext_menu'][$mod] == 'Y') $ret = true;
+ $ret = ($cacheArray['extensions']['ext_menu'][$mod] == "Y");
$_CONFIG['cache_hits']++;
}
- }
- if ((GET_EXT_VERSION("sql_patches") >= "0.3.6") && ($ret === false))
- {
+ } elseif ((GET_EXT_VERSION("sql_patches") >= "0.3.6") && (!EXT_IS_ACTIVE("cache"))) {
// Check database for entry
$result = SQL_QUERY_ESC("SELECT has_menu FROM "._MYSQL_PREFIX."_mod_reg WHERE module='%s' LIMIT 1",
array($mod), __FILE__, __LINE__);
- if (SQL_NUMROWS($result) == 1)
- {
+ if (SQL_NUMROWS($result) == 1) {
list($has_menu) = SQL_FETCHROW($result);
- if ($has_menu == 'Y') $ret = true;
- }
+
+ // Fake cache... ;-)
+ $cacheArray['extensions']['ext_menu'][$mod] = $has_menu;
+
+ // Does it have a menu?
+ $ret = ($has_menu == "Y");
+ } // END - if
// Free memory
SQL_FREERESULT($result);
} elseif (GET_EXT_VERSION("sql_patches") == "") {
// No sql_patches installed, so maybe in admin area?
- if ((IS_ADMIN()) && ($mod == "admin")) return true; // Then there is a menu!
+ $ret = ((IS_ADMIN()) && ($mod == "admin")); // Then there is a menu!
}
// Return status
return $ret;
}
+// Subtract points from database and mediadata cache
+function SUB_POINTS ($uid, $points) {
+ // Add points to used points
+ $result = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_user_data SET used_points=used_points+%s WHERE userid=%s LIMIT 1",
+ array($points, bigintval($uid)), __FILE__, __LINE__);
+
+ // Update mediadata as well
+ if (GET_EXT_VERSION("mediadata") >= "0.0.4") {
+ // Update database
+ MEDIA_UPDATE_ENTRY(array("total_points"), "sub", $points);
+ } // END - if
+}
+// Update config entries
+function UPDATE_CONFIG ($entries, $values, $updateMode="") {
+ // Do we have multiple entries?
+ if (is_array($entries)) {
+ // Walk through all
+ $all = "";
+ foreach ($entries as $idx => $entry) {
+ // Update mode set?
+ if (!empty($updateMode)) {
+ // Update entry
+ $all .= sprintf("%s=%s%s%s,", $entry, $entry, $updateMode, (float)$values[$idx]);
+ } else {
+ // Check if string or number
+ if (($values[$idx] + 0) === $values[$idx]) {
+ // Number detected
+ $all .= sprintf("%s=%s,", $entry, (float)$values[$idx]);
+ } else {
+ // String detected
+ $all .= sprintf("%s='%s',", $entry, SQL_ESCAPE($values[$idx]));
+ }
+ }
+ } // END - foreach
+
+ // Remove last comma
+ $entries = substr($all, 0, -1);
+ } elseif (!empty($updateMode)) {
+ // Update mode set
+ $entries .= sprintf("=%s%s%s", $entries, $updateMode, (float)$value);
+ } else {
+ // Regular entry to update
+ $entries .= sprintf("='%s'", SQL_ESCAPE($values));
+ }
+
+ // Run database update
+ //DEBUG_LOG(__FUNCTION__.":entries={$entries}");
+ SQL_QUERY("UPDATE "._MYSQL_PREFIX."_config SET ".$entries." WHERE config=0 LIMIT 1", __FILE__, __LINE__);
+ // Destroy cache
+ if ((GET_EXT_VERSION("cache") >= "0.1.2") && (SQL_AFFECTEDROWS() == 1)) {
+ global $cacheInstance, $_CONFIG, $CSS;
+ if ($cacheInstance->cache_file("config", true)) $cacheInstance->cache_destroy();
+
+ // Rebuid the cache
+ require(PATH."inc/load_cache-config.php");
+ } // END - if
+}
+// Creates a new task for updated extension
+function CREATE_EXTENSION_UPDATE_TASK ($admin_id, $subject, $notes) {
+ // Check if task is not there
+ $result = SQL_QUERY_ESC("SELECT id FROM "._MYSQL_PREFIX."_task_system WHERE subject='%s' LIMIT 1",
+ array($subject), __FILE__, __LINE__);
+ if (SQL_NUMROWS($result) == 0) {
+ // Task not created so it's a brand-new extension which we need to register and create a task for!
+ $result = SQL_QUERY_ESC("INSERT INTO "._MYSQL_PREFIX."_task_system (assigned_admin, userid, status, task_type, subject, text, task_created) VALUES ('%s', '0', 'NEW', 'EXTENSION_UPDATE', '%s', '%s', UNIX_TIMESTAMP())",
+ array($admin_id, $subject, $notes), __FILE__, __LINE__);
+ } // END - if
+
+ // Free memory
+ SQL_FREERESULT($result);
+}
+// Creates a new task for newly installed extension
+function CREATE_NEW_EXTENSION_TASK ($admin_id, $subject, $ext) {
+ // Not installed and do we have created a task for the admin?
+ $result = SQL_QUERY_ESC("SELECT `id` FROM `"._MYSQL_PREFIX."_task_system` WHERE `subject` LIKE '%s%%' LIMIT 1",
+ array($subject), __FILE__, __LINE__);
+ if ((SQL_NUMROWS($result) == 0) && (GET_EXT_VERSION($ext) == "")) {
+ // Template file
+ $tpl = sprintf("%stemplates/%s/html/ext/ext_%s.tpl",
+ PATH,
+ GET_LANGUAGE(),
+ $ext
+ );
+
+ // Load text for task
+ if ((file_exists($tpl)) && (is_readable($tpl))) {
+ // Load extension's own text template (HTML!)
+ $msg = LOAD_TEMPLATE("ext_".$ext, true);
+ } else {
+ // Load default message
+ $msg = LOAD_EMAIL_TEMPLATE("admin_new_ext","", 0);
+ }
+
+ // Task not created so it's a brand-new extension which we need to register and create a task for!
+ $result_insert = SQL_QUERY_ESC("INSERT INTO "._MYSQL_PREFIX."_task_system (assigned_admin, userid, status, task_type, subject, text, task_created)
+VALUES (%s, 0, 'NEW', 'EXTENSION', '%s', '%s', UNIX_TIMESTAMP())",
+ array(
+ $admin_id,
+ $subject,
+ addslashes($msg),
+ ), __FILE__, __LINE__, true, false
+ );
+ } // END - if
+
+ // Free memory
+ SQL_FREERESULT($result);
+}
//
?>