Renamed ifSqlHasZeroNums() to ifSqlHasZeroNumRows() and improved some queries.
[mailer.git] / inc / modules / admin / admin-inc.php
index 9360b73c8ae581708cb69e5f1327a36f3c1fa0d0..6eee1eddf6e93996b89532899bfbb5c77fb54678 100644 (file)
@@ -16,7 +16,7 @@
  * $Author::                                                          $ *
  * -------------------------------------------------------------------- *
  * Copyright (c) 2003 - 2009 by Roland Haeder                           *
- * Copyright (c) 2009 - 2013 by Mailer Developer Team                   *
+ * 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 *
@@ -53,7 +53,7 @@ function addAdminAccount ($adminLogin, $passHash, $adminEmail, $accessLevel = 'd
                array($adminLogin), __FUNCTION__, __LINE__);
 
        // Is the entry there?
-       if (ifSqlHasZeroNums($result)) {
+       if (ifSqlHasZeroNumRows($result)) {
                // Is ext-admins installed and version at least 0.3.0?
                if (isExtensionInstalledAndNewer('admins', '0.3.0')) {
                        // Ok, let's create the admin login
@@ -135,6 +135,8 @@ function ifAdminLoginDataIsValid ($adminLogin, $adminPassword) {
 
 // Only be executed on cookie checking
 function ifAdminCookiesAreValid ($adminLogin, $passHash) {
+       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'adminLogin=' . $adminLogin . ',passHash=' . $passHash . ' - CALLED!');
+
        // First of all, no admin login is found
        $ret = '404';
 
@@ -161,7 +163,7 @@ function ifAdminCookiesAreValid ($adminLogin, $passHash) {
        } // END - if
 
        // Return status
-       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ret='.$ret);
+       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ret=' . $ret . ' - EXIT!');
        return $ret;
 }
 
@@ -217,7 +219,7 @@ LIMIT 1",
        // Is there an entry?
        if (sqlNumRows($result_action) == 1) {
                // Is valid but does the inlcude file exists?
-               $inc = sprintf("inc/modules/admin/action-%s.php", $action);
+               $inc = sprintf('inc/modules/admin/action-%s.php', $action);
                if ((isIncludeReadable($inc)) && (isMenuActionValid('admin', $action, $what)) && ($GLOBALS['acl_allow'] === TRUE)) {
                        // Ok, we finally load the admin action module
                        loadInclude($inc);
@@ -280,13 +282,13 @@ ORDER BY
        `id` DESC", __FUNCTION__, __LINE__);
 
        // Are there entries?
-       if (!ifSqlHasZeroNums($result_main)) {
+       if (!ifSqlHasZeroNumRows($result_main)) {
                $OUT .= '<ul class="admin_menu_main">';
 
                // Load all 'action' menus
                while ($mainContent = sqlFetchArray($result_main)) {
                        // Filename
-                       $inc = sprintf("inc/modules/admin/action-%s.php", $mainContent['main_action']);
+                       $inc = sprintf('inc/modules/admin/action-%s.php', $mainContent['main_action']);
 
                        // Is the current admin allowed to access this 'action' menu?
                        if (isAdminAllowedAccessMenu($mainContent['main_action'])) {
@@ -363,7 +365,7 @@ ORDER BY
                array($mainContent['main_action']), __FUNCTION__, __LINE__);
 
        // Remember the count for later checks
-       setAdminMenuHasEntries($mainContent['main_action'], ((!ifSqlHasZeroNums($result_what)) && (($action == $mainContent['main_action']) || (isAdminMenuJavascriptEnabled()))));
+       setAdminMenuHasEntries($mainContent['main_action'], ((!ifSqlHasZeroNumRows($result_what)) && (($action == $mainContent['main_action']) || (isAdminMenuJavascriptEnabled()))));
 
        // Start li-tag for sub menu content
        $OUT .= '<li class="admin_menu_sub" id="action_menu_' . $mainContent['main_action'] . '"' . addStyleMenuContent('admin', $mainContent['main_action'], $action) . '>';
@@ -374,14 +376,14 @@ ORDER BY
                $SUB = TRUE;
 
                // Are there entries?
-               if (!ifSqlHasZeroNums($result_what)) {
+               if (!ifSqlHasZeroNumRows($result_what)) {
                        // Start HTML code
                        $OUT .= '<ul class="admin_menu_sub">';
 
                        // Load all entries
                        while ($subContent = sqlFetchArray($result_what)) {
                                // Filename
-                               $inc = sprintf("inc/modules/admin/what-%s.php", $subContent['sub_what']);
+                               $inc = sprintf('inc/modules/admin/what-%s.php', $subContent['sub_what']);
 
                                // Is the current admin allowed to access this 'what' menu?
                                if (isAdminAllowedAccessMenu(NULL, $subContent['sub_what'])) {
@@ -541,7 +543,7 @@ function adminMenuSelectionBox_DEPRECATED ($mode, $default = '', $defid = '') {
 
        $result = sqlQueryEscaped("SELECT `%s` AS `menu`, `title` FROM `{?_MYSQL_PREFIX?}_admin_menu` WHERE ".$what." ORDER BY `sort` ASC",
                array($mode), __FUNCTION__, __LINE__);
-       if (!ifSqlHasZeroNums($result)) {
+       if (!ifSqlHasZeroNumRows($result)) {
                // Load menu as selection
                $OUT = '<select name="' . $mode . '_menu';
                if (!isValidId($defid)) $OUT .= '[' . intval($defid) . ']';
@@ -614,10 +616,10 @@ function adminSaveSettings (&$postData, $tableName = '_config', $whereStatement
                        // Shall we add numbers or strings?
                        if ('' . $val . '' == '' . $test . '') {
                                // Add numbers
-                               array_push($tableData, sprintf("`%s`=%s", $id, $test));
+                               array_push($tableData, sprintf('`%s`=%s', $id, $test));
                        } elseif (is_null($val)) {
                                // Add NULL
-                               array_push($tableData, sprintf("`%s`=NULL", $id));
+                               array_push($tableData, sprintf('`%s`=NULL', $id));
                        } else {
                                // Add strings
                                array_push($tableData, sprintf("`%s`='%s'", $id, trim($val)));
@@ -635,9 +637,9 @@ function adminSaveSettings (&$postData, $tableName = '_config', $whereStatement
        $result = FALSE;
        if ($alwaysAdd === FALSE) {
                if (!empty($whereStatement)) {
-                       $result = sqlQuery("SELECT * FROM `{?_MYSQL_PREFIX?}" . $tableName . "` WHERE " . $whereStatement . " LIMIT 1", __FUNCTION__, __LINE__);
+                       $result = sqlQuery('SELECT * FROM `{?_MYSQL_PREFIX?}' . $tableName . '` WHERE ' . $whereStatement . ' LIMIT 1', __FUNCTION__, __LINE__);
                } else {
-                       $result = sqlQuery("SELECT * FROM `{?_MYSQL_PREFIX?}" . $tableName . "` LIMIT 1", __FUNCTION__, __LINE__);
+                       $result = sqlQuery('SELECT * FROM `{?_MYSQL_PREFIX?}' . $tableName . '` LIMIT 1', __FUNCTION__, __LINE__);
                }
        } // END - if
 
@@ -646,7 +648,7 @@ function adminSaveSettings (&$postData, $tableName = '_config', $whereStatement
                $updatedData = implode(', ', $tableData);
 
                // Generate SQL string
-               $sql = sprintf("UPDATE `{?_MYSQL_PREFIX?}%s` SET %s WHERE %s LIMIT 1",
+               $sql = sprintf('UPDATE `{?_MYSQL_PREFIX?}%s` SET %s WHERE %s LIMIT 1',
                        $tableName,
                        $updatedData,
                        $whereStatement
@@ -666,7 +668,7 @@ function adminSaveSettings (&$postData, $tableName = '_config', $whereStatement
                $values = implode(', '  , $values);
 
                // Generate SQL string
-               $sql = sprintf("INSERT INTO `{?_MYSQL_PREFIX?}%s` (%s) VALUES (%s)",
+               $sql = sprintf('INSERT INTO `{?_MYSQL_PREFIX?}%s` (%s) VALUES (%s)',
                        $tableName,
                        $keys,
                        $values
@@ -698,7 +700,7 @@ function adminSaveSettings (&$postData, $tableName = '_config', $whereStatement
 // Generate a selection box
 function adminAddMenuSelectionBox ($menu, $type, $name, $default = '') {
        // Open the requested menu directory
-       $menuArray = getArrayFromDirectory(sprintf("inc/modules/%s/", $menu), $type . '-', FALSE, FALSE);
+       $menuArray = getArrayFromDirectory(sprintf('inc/modules/%s/', $menu), $type . '-', FALSE, FALSE);
 
        // Init the selection box
        $OUT = '<select name="' . $name . '" class="form_select" size="1"><option value="">{--ADMIN_IS_TOP_MENU--}</option>';
@@ -708,7 +710,7 @@ function adminAddMenuSelectionBox ($menu, $type, $name, $default = '') {
                // Is this a PHP script?
                if ((!isDirectory($file)) && (isInString('' . $type . '-', $file)) && (isInString('.php', $file))) {
                        // Then test if the file is readable
-                       $test = sprintf("inc/modules/%s/%s", $menu, $file);
+                       $test = sprintf('inc/modules/%s/%s', $menu, $file);
 
                        // Is the file there?
                        if (isIncludeReadable($test)) {
@@ -802,7 +804,7 @@ function adminGetMenuMode () {
                incrementStatsEntry('cache_hits');
        } elseif (isExtensionInstalledAndNewer('admins', '0.6.7')) {
                // Load from database when version of 'admins' is enough
-               $result = sqlQueryEscaped("SELECT `la_mode` FROM `{?_MYSQL_PREFIX?}_admins` WHERE `id`=%s LIMIT 1",
+               $result = sqlQueryEscaped('SELECT `la_mode` FROM `{?_MYSQL_PREFIX?}_admins` WHERE `id`=%s LIMIT 1',
                        array($adminId), __FUNCTION__, __LINE__);
 
                // Is there an entry?
@@ -836,7 +838,7 @@ function adminChangeActivationStatus ($IDs, $table, $row, $idRow = 'id') {
                        // Should always be set... ;-)
                        if (!empty($selected)) {
                                // Determine new status
-                               $result = sqlQueryEscaped("SELECT %s FROM `{?_MYSQL_PREFIX?}_%s` WHERE %s=%s LIMIT 1",
+                               $result = sqlQueryEscaped('SELECT %s FROM `{?_MYSQL_PREFIX?}_%s` WHERE `%s`=%s LIMIT 1',
                                        array(
                                                $row,
                                                $table,
@@ -853,7 +855,7 @@ function adminChangeActivationStatus ($IDs, $table, $row, $idRow = 'id') {
                                        $newStatus = convertBooleanToYesNo(!($currStatus == 'Y'));
 
                                        // Change this status
-                                       sqlQueryEscaped("UPDATE `{?_MYSQL_PREFIX?}_%s` SET %s='%s' WHERE %s=%s LIMIT 1",
+                                       sqlQueryEscaped("UPDATE `{?_MYSQL_PREFIX?}_%s` SET `%s`='%s' WHERE `%s`=%s LIMIT 1",
                                                array(
                                                        $table,
                                                        $row,
@@ -903,10 +905,10 @@ function adminBuilderStatusHandler ($mode, $tableName, $columns, $filterFunction
        // "Walk" through all entries
        foreach (postRequestElement($idColumn[0]) as $id => $sel) {
                // Construct SQL query
-               $sql = sprintf("UPDATE `{?_MYSQL_PREFIX?}_%s` SET", sqlEscapeString($tableName[0]));
+               $sql = sprintf('UPDATE `{?_MYSQL_PREFIX?}_%s` SET', sqlEscapeString($tableName[0]));
 
                // Load data of entry
-               $result = sqlQueryEscaped("SELECT * FROM `{?_MYSQL_PREFIX?}_%s` WHERE `%s`=%s LIMIT 1",
+               $result = sqlQueryEscaped('SELECT * FROM `{?_MYSQL_PREFIX?}_%s` WHERE `%s`=%s LIMIT 1',
                        array(
                                $tableName[0],
                                $idColumn[0],
@@ -952,7 +954,7 @@ function adminBuilderStatusHandler ($mode, $tableName, $columns, $filterFunction
                                // Are there brackets () at the end?
                                if (substr($entries[$id], -2, 2) == '()') {
                                        // Direct SQL command found
-                                       $sql .= sprintf(" `%s`=%s,", sqlEscapeString($key), sqlEscapeString($entries[$id]));
+                                       $sql .= sprintf(' `%s`=%s,', sqlEscapeString($key), sqlEscapeString($entries[$id]));
                                } else {
                                        // Add regular entry
                                        $sql .= sprintf(" `%s`='%s',", sqlEscapeString($key), sqlEscapeString($entries[$id]));
@@ -1150,7 +1152,7 @@ function sendAdminPasswordResetLink ($email) {
                array($email), __FUNCTION__, __LINE__);
 
        // Is there an account?
-       if (ifSqlHasZeroNums($result)) {
+       if (ifSqlHasZeroNumRows($result)) {
                // No account found
                return '{--ADMIN_NO_LOGIN_WITH_EMAIL--}';
        } // END - if
@@ -1247,7 +1249,7 @@ function adminUpdateTaskData ($id, $row, $data) {
                reportBug(__FUNCTION__, __LINE__, 'id=' . $id . ',row=' . $row . ',data=' . $data . ' - isAdmin()=false');
        } elseif ($id <= 0) {
                // Initiate backtrace
-               reportBug(__FUNCTION__, __LINE__, sprintf("id is invalid: %s. row=%s, data=%s",
+               reportBug(__FUNCTION__, __LINE__, sprintf('id is invalid: %s. row=%s, data=%s',
                        $id,
                        $row,
                        $data
@@ -1531,7 +1533,7 @@ function adminProcessMenuEditForm ($type, $subMenu) {
                                break;
 
                        default: // Unexpected action
-                               logDebugMessage(__FUNCTION__, __LINE__, sprintf("Unsupported action %s detected.", postRequestElement('ok')));
+                               logDebugMessage(__FUNCTION__, __LINE__, sprintf('Unsupported action %s detected.', postRequestElement('ok')));
                                displayMessage('{%message,ADMIN_UNKNOWN_OKAY=' . postRequestElement('ok') . '%}');
                                break;
                } // END - switch
@@ -1663,7 +1665,7 @@ function registerFirstAdmin () {
 
                        default:
                                // Any other kind will be logged
-                               $errorMessage = sprintf("Unknown return code %s from ifAdminLoginDataIsValid().", $ret);
+                               $errorMessage = sprintf('Unknown return code %s from ifAdminLoginDataIsValid().', $ret);
                                logDebugMessage(__FUNCTION__, __LINE__, $errorMessage);
 
                                // Set this to have our error message displayed