* -------------------------------------------------------------------- *
* Kurzbeschreibung : Alle datenbank-relevanten Funktionen *
* -------------------------------------------------------------------- *
- * $Revision:: $ *
- * $Date:: $ *
- * $Tag:: 0.2.1-FINAL $ *
- * $Author:: $ *
- * -------------------------------------------------------------------- *
* Copyright (c) 2003 - 2009 by Roland Haeder *
- * Copyright (c) 2009 - 2013 by Mailer Developer Team *
+ * Copyright (c) 2009 - 2016 by Mailer Developer Team *
* For more information visit: http://mxchange.org *
* *
* This program is free software; you can redistribute it and/or modify *
array($mode), __FUNCTION__, __LINE__);
//* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'main_cnt=' . $main_cnt . ',getWhat()=' . getWhat());
- if (!ifSqlHasZeroNums($result_main)) {
+ if (!ifSqlHasZeroNumRows($result_main)) {
// There are menus available, so we simply display them... :)
$GLOBALS['rows'] = '';
while ($content = sqlFetchArray($result_main)) {
), __FUNCTION__, __LINE__);
// Are there some entries?
- if (!ifSqlHasZeroNums($result_sub)) {
+ if (!ifSqlHasZeroNumRows($result_sub)) {
// Init counter
$count = '0';
// Full file name for checking menu
//* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'sub_what=' . $content['sub_what']);
- $inc = sprintf("inc/modules/%s/what-%s.php", $mode, $content['sub_what']);
+ $inc = sprintf('inc/modules/%s/what-%s.php', $mode, $content['sub_what']);
if (isIncludeReadable($inc)) {
// Mark currently selected menu - open
if ((!empty($what)) && (($what == $content['sub_what']))) {
enableBlockMode();
// Load menu block
- $INC = sprintf("inc/modules/%s/action-%s.php", $mode, $content['action']);
+ $INC = sprintf('inc/modules/%s/action-%s.php', $mode, $content['action']);
if (isFileReadable($INC)) {
// Load include file
if ((!isExtensionActive($content['action'])) || ($content['action'] == 'online')) $GLOBALS['rows'] .= loadTemplate('menu_what_begin', TRUE, $mode);
* login.
*/
function isAdmin () {
+ //* DIE: */ reportBug(__FUNCTION__, __LINE__, 'CALLED!');
+ //* NOISY-DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'CALLED!');
+
// Is there cache?
if (isset($GLOBALS[__FUNCTION__])) {
// Return it
- //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'isAdmin()=' . intval($GLOBALS[__FUNCTION__]));
+ //* NOISY-DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'isAdmin()=' . intval($GLOBALS[__FUNCTION__]) . ' - CACHED!');
return $GLOBALS[__FUNCTION__];
} // END - if
- // No admin in installation phase!
if ((isInstaller()) || (!isAdminRegistered())) {
+ // No admin in installation phase!
$GLOBALS[__FUNCTION__] = FALSE;
+ //* NOISY-DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'isAdmin()=' . intval($GLOBALS[__FUNCTION__]) . ' - INSTALLER!');
return FALSE;
} // END - if
$ret = FALSE;
$adminId = '0';
$passwordFromCookie = '';
- //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, $adminId);
// If admin login is not given take current from cookies...
+ //* NOISY-DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'isSessionVariableSet(admin_id)=' . intval(isSessionVariableSet('admin_id')) . ',isSessionVariableSet(admin_md5)=' . intval(isSessionVariableSet('admin_md5')));
if ((isSessionVariableSet('admin_id')) && (isSessionVariableSet('admin_md5'))) {
+ // Debug message
+ //* NOISY-DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Getting admin data from session ...');
+
// Get admin login and password from session/cookies
$adminId = getCurrentAdminId();
$passwordFromCookie = getAdminMd5();
} // END - if
- //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'adminId=' . $adminId . ',passwordFromCookie=' . $passwordFromCookie);
+ //* NOISY-DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'adminId=' . $adminId . ',passwordFromCookie=' . $passwordFromCookie);
// Abort if admin id is zero
if (($adminId == '0') || (empty($passwordFromCookie))) {
// Search in array for entry
if (isset($GLOBALS['admin_hash'])) {
// Use cached string
- //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Using admin_hash=' . $GLOBALS['admin_hash'] . ' from cache');
+ //* NOISY-DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Using admin_hash=' . $GLOBALS['admin_hash'] . ' from cache');
} elseif ((!empty($adminId)) && (!empty($passwordFromCookie)) && (isAdminHashSet($adminId) === TRUE)) {
// Get admin hash and hash it
$GLOBALS['admin_hash'] = encodeHashForCookie(getAdminHash($adminId));
- //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'valPass=' . $GLOBALS['admin_hash']);
+ //* NOISY-DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'valPass=' . $GLOBALS['admin_hash']);
// Count cache hits
incrementStatsEntry('cache_hits');
} elseif ((!empty($adminId)) && ((!isExtensionActive('cache')) || (isAdminHashSet($adminId) === FALSE))) {
// Get admin hash and hash it
$GLOBALS['admin_hash'] = encodeHashForCookie(getAdminHash($adminId));
- //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'valPass=' . $GLOBALS['admin_hash']);
+ //* NOISY-DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'valPass=' . $GLOBALS['admin_hash']);
}
// Check if password is valid
- //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, '(' . $GLOBALS['admin_hash'] . '==' . $passwordFromCookie . ')='.intval($GLOBALS['admin_hash'] == $passwordFromCookie));
+ //* NOISY-DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, '(' . $GLOBALS['admin_hash'] . '==' . $passwordFromCookie . ')='.intval($GLOBALS['admin_hash'] == $passwordFromCookie));
$GLOBALS[__FUNCTION__] = ((!empty($GLOBALS['admin_hash'])) && ($GLOBALS['admin_hash'] == $passwordFromCookie));
// Return result of comparision
- //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'isAdmin()=' . intval($GLOBALS[__FUNCTION__]));
+ //* NOISY-DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'isAdmin()=' . intval($GLOBALS[__FUNCTION__]));
return $GLOBALS[__FUNCTION__];
}
break;
default: // Invalid!
- logDebugMessage(__FUNCTION__, __LINE__, sprintf("Invalid mode %s detected.", $mode));
+ logDebugMessage(__FUNCTION__, __LINE__, sprintf('Invalid mode %s detected.', $mode));
break;
}
// Some entries are found?
- if (!ifSqlHasZeroNums($result)) {
+ if (!ifSqlHasZeroNumRows($result)) {
$OUT = '';
while ($content = sqlFetchArray($result)) {
$OUT .= ' <option value="' . $content['value'] . '"';
$ret = (!ifSqlHasZeroAffectedRows());
} else {
// Check found rows
- $ret = (!ifSqlHasZeroNums($result));
+ $ret = (!ifSqlHasZeroNumRows($result));
}
// Free memory
// Is the category id set?
if (!isValidId($cid)) {
// No category
- $data['cat'] = '{--_CATEGORY_NONE--}';
- } elseif (isValidId($cid)) {
- // Lookup the category in database
- $result = sqlQueryEscaped('SELECT `cat` FROM `{?_MYSQL_PREFIX?}_cats` WHERE `id`=%s LIMIT 1',
- array(bigintval($cid)), __FUNCTION__, __LINE__);
- if (sqlNumRows($result) == 1) {
- // Category found... :-)
- $data = sqlFetchArray($result);
- } // END - if
+ return '{--_CATEGORY_NONE--}';
+ } // END - if
- // Free result
- sqlFreeResult($result);
+ // Lookup the category in database
+ $result = sqlQueryEscaped('SELECT `cat` FROM `{?_MYSQL_PREFIX?}_cats` WHERE `id`=%s LIMIT 1',
+ array(bigintval($cid)), __FUNCTION__, __LINE__);
+
+ if (sqlNumRows($result) == 1) {
+ // Category found... :-)
+ $data = sqlFetchArray($result);
} // END - if
+ // Free result
+ sqlFreeResult($result);
+
// Return result
return $data['cat'];
}
), __FUNCTION__, __LINE__);
// Was it *not* found?
- if (ifSqlHasZeroNums($result)) {
+ if (ifSqlHasZeroNumRows($result)) {
// So we add one!
sqlQueryEscaped("INSERT INTO `{?_MYSQL_PREFIX?}_user_links` (`%s`, `userid`, `link_type`) VALUES (%s,%s,'%s')",
array(
}
// Generates an option list from various parameters
-function generateOptions ($table, $key, $value, $default = '', $extra = '', $whereStatement = '', $disabled = array(), $callback = '') {
+function generateOptions ($table, $key, $value, $default = '', $extra = '', $whereStatement = '', $disabled = array(), $callback = '', $allowNone = FALSE) {
$ret = '';
+
+ // Allow none?
+ if ($allowNone === TRUE) {
+ // Add option for none
+ $ret .= '<option value="0">{--SELECT_NONE--}</option>';
+ } // END - if
+
if ($table == '/ARRAY/') {
// Selection from array
if ((is_array($key)) && (is_array($value)) && ((count($key)) == (count($value)) || (!empty($callback)))) {
), __FUNCTION__, __LINE__);
// Is there rows?
- if (!ifSqlHasZeroNums($result)) {
+ if (!ifSqlHasZeroNumRows($result)) {
// Found data so add them as OPTION lines
while ($content = sqlFetchArray($result)) {
// Is extra set?
__FUNCTION__, __LINE__);
// Are there entries?
- if (!ifSqlHasZeroNums($result)) {
+ if (!ifSqlHasZeroNumRows($result)) {
// ... and begin loading stuff
while ($content = sqlFetchArray($result)) {
// Transfer some data
if (isValidId($categoryId)) {
// Select category
$extraColumns = "LEFT JOIN `{?_MYSQL_PREFIX?}_user_cats` AS `c` ON `d`.`userid`=`c`.`userid`";
- $addWhere = sprintf(" AND `c`.`cat_id`=%s", $categoryId);
+ $addWhere = sprintf(' AND `c`.`cat_id`=%s', $categoryId);
} // END - if
// Exclude users in holiday?
$addWhere .= " AND `d`.`holiday_active`='N'";
} // END - if
- // Include only HTML recipients?
- if ((isExtensionActive('html_mail')) && ($mode == 'html')) {
- $addWhere .= " AND `d`.`html`='Y'";
- } // END - if
-
// Run query
$result = sqlQueryEscaped("SELECT
`d`.`userid`
);
// Are there entries?
- if (!ifSqlHasZeroNums($result)) {
+ if (!ifSqlHasZeroNumRows($result)) {
// Now load all userids for one big query!
$userids = array();
while ($data = sqlFetchArray($result)) {
$result = sqlQuery($sql, __FUNCTION__, __LINE__);
// Are there some URLs left?
- if (!ifSqlHasZeroNums($result)) {
+ if (!ifSqlHasZeroNumRows($result)) {
// List all URLs
$OUT = '';
while ($row = sqlFetchArray($result)) {
// Call the callback-function
//* NOISY-DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'callbackFunction=' . $callbackName . ',args=<pre>'.print_r($args, TRUE).'</pre>');
- // @TODO If we can rewrite the EL sub-system to support more than one parameter, this call_user_func_array() can be avoided
+ // @TODO If the EL sub-system can support more than one parameter, this call_user_func_array() can be avoided
$row[$columnName] = call_user_func_array($callbackName, $args);
} // END - foreach
$content = array();
// Prepare SQL for this row
- $sql = sprintf("UPDATE `{?_MYSQL_PREFIX?}_%s` SET",
+ $sql = sprintf('UPDATE `{?_MYSQL_PREFIX?}_%s` SET',
sqlEscapeString($tableName[0])
);
return $sql;
}
+// "Getter" for an array from given table and columns
+function getArrayFromTable ($tableName, $columns, $orderBy, $ordered = 'ASC', $whereSql = '') {
+ // The table must exist
+ assert(ifSqlTableExists($tableName));
+
+ // Search for it
+ $result = sqlQueryEscaped('SELECT
+ `' . implode('`, `', $columns) . '`
+FROM
+ `{?_MYSQL_PREFIX?}_%s`
+' . $whereSql . '
+ORDER BY
+ `%s` %S',
+ array(
+ $tableName,
+ $orderBy,
+ $ordered
+ ), __FUNCTION__, __LINE__
+ );
+
+ // Init array
+ $rows = array();
+
+ // Are there entries?
+ if (!ifSqlHasZeroNumRows($result)) {
+ // Load all entries
+ while ($row = sqlFetchArray($result)) {
+ array_push($rows, $row);
+ } // END - while
+ } // END - if
+
+ // Free result
+ sqlFreeResult($result);
+
+ // Return all found rows
+ return $rows;
+}
+
// [EOF]
?>