]> git.mxchange.org Git - mailer.git/blobdiff - inc/libs/admins_functions.php
More usage of padLeftZero() instead of prependZeros() but use prependZeros() as a...
[mailer.git] / inc / libs / admins_functions.php
index c1851a0cfe8e7815b3af6e60591b45197100e9d5..10fa2ec88a66436a5846f55ec37d50cedc23e582 100644 (file)
@@ -38,7 +38,7 @@
 // Some security stuff...
 if (!defined('__SECURITY')) {
        die();
-}
+} // END - if
 
 // Check ACL for menu combination
 function isAdminsAllowedByAcl ($action, $what) {
@@ -47,15 +47,12 @@ function isAdminsAllowedByAcl ($action, $what) {
 
        if (($action == 'login') || ($action == 'logout')) {
                // If action is login or logout allow allways!
-               return true;
+               return TRUE;
        } elseif (isset($GLOBALS[__FUNCTION__][$adminId][$action][$what])) {
                // If we have cache, use it
                return $GLOBALS[__FUNCTION__][$adminId][$action][$what];
        }
 
-       // But default result is failed
-       $GLOBALS[__FUNCTION__][$action][$what] = false;
-
        // Get admin's defult access right
        $default = getAdminDefaultAcl($adminId);
 
@@ -68,7 +65,7 @@ function isAdminsAllowedByAcl ($action, $what) {
                $parent = isAdminsAllowedByAcl($parent_action, '');
        } else {
                // Anything else is true!
-               $parent = false;
+               $parent = FALSE;
        }
 
        // Shall I test for a main or sub menu? (action or what?)
@@ -102,7 +99,7 @@ function isAdminsAllowedByAcl ($action, $what) {
                }
        } elseif (!isExtensionActive('cache')) {
                // Extension ext-cache is absent, so load it from database
-               $result = false;
+               $result = FALSE;
                if (!empty($action)) {
                        // Main menu
                        $result = SQL_QUERY_ESC("SELECT `access_mode` FROM `{?_MYSQL_PREFIX?}_admins_acls` WHERE `admin_id`=%s AND `action_menu`='%s' LIMIT 1",
@@ -123,11 +120,14 @@ function isAdminsAllowedByAcl ($action, $what) {
                SQL_FREERESULT($result);
        }
 
+       // But default result is failed
+       $GLOBALS[__FUNCTION__][$adminId][$action][$what] = FALSE;
+
        // Check ACL and (maybe) allow
        //* DEBUG: */ debugOutput('default='.$default.',acl_mode='.$aclMode.',parent='.intval($parent));
-       if ((($default == 'allow') && ($aclMode != 'deny')) || (($default == 'deny') && ($aclMode == 'allow')) || ($parent === true) || (($default == 'NO-ACL') && ($aclMode == 'failed') && ($parent === false))) {
+       if ((($default == 'allow') && ($aclMode != 'deny')) || (($default == 'deny') && ($aclMode == 'allow')) || ($parent === TRUE) || (($default == 'NO-ACL') && ($aclMode == 'failed') && ($parent === FALSE))) {
                // Access is granted
-               $GLOBALS[__FUNCTION__][$adminId][$action][$what] = true;
+               $GLOBALS[__FUNCTION__][$adminId][$action][$what] = TRUE;
        } // END - if
 
        // Return value
@@ -159,7 +159,7 @@ LIMIT 1",
 
                // Free memory
                SQL_FREERESULT($result);
-       } elseif (isValidUserId($email)) {
+       } elseif (isValidId($email)) {
                // Direct id given
                $email = '{%url=modules.php?module=' . $mod . '&what=admins_contct&id=' . bigintval($email) . '%}';
        } else {
@@ -172,7 +172,7 @@ LIMIT 1",
 }
 
 // Change a lot admin account
-function adminsChangeAdminAccount ($postData, $element = '', $displayMessage = true) {
+function adminsChangeAdminAccount ($postData, $element = '', $displayMessage = TRUE) {
        // Begin the update
        $cache_update = '0';
        $message = '';
@@ -194,17 +194,17 @@ function adminsChangeAdminAccount ($postData, $element = '', $displayMessage = t
 
                        // Admin account saved
                        $message = '{--ADMIN_ACCOUNT_SAVED--}';
-               } elseif ((!empty($postData['pass1'])) && (!empty($postData['pass2']))) {
+               } elseif ((!empty($postData['password1'])) && (!empty($postData['password2']))) {
                        // Update only if both passwords match
-                       if (($postData['pass1'][$id] == $postData['pass2'][$id])) {
+                       if (($postData['password1'][$id] == $postData['password2'][$id])) {
                                // Save only when both passwords are the same (also when they are empty)
                                $add = ''; $cache_update = 1;
 
                                // Generate hash
-                               $hash = generateHash($postData['pass1'][$id]);
+                               $hash = generateHash($postData['password1'][$id]);
 
                                // Save password when set
-                               if (!empty($postData['pass1'][$id])) {
+                               if (!empty($postData['password1'][$id])) {
                                        $add = sprintf(",`password`='%s'", SQL_ESCAPE($hash));
                                } // END - if
 
@@ -225,7 +225,7 @@ function adminsChangeAdminAccount ($postData, $element = '', $displayMessage = t
                                                if (!empty($add)) {
                                                        setAdminMd5($hash);
                                                } // END - if
-                                       } elseif (generateHash($postData['pass1'][$id], $salt) != getAdminMd5()) {
+                                       } elseif (generateHash($postData['password1'][$id], $salt) != getAdminMd5()) {
                                                // Update password cookie
                                                setAdminMd5($hash);
                                        }
@@ -298,7 +298,7 @@ LIMIT 1",
        } // END - foreach
 
        // Display message if not empty and allowed
-       if ((!empty($message)) && ($displayMessage === true)) {
+       if ((!empty($message)) && ($displayMessage === TRUE)) {
                // Display it
                displayMessage($message);
        } // END - if
@@ -322,7 +322,7 @@ function adminsEditAdminAccount ($postData) {
                $id = bigintval($id);
 
                // Get the admin's data
-               $result = SQL_QUERY_ESC("SELECT `login`,`email` FROM `{?_MYSQL_PREFIX?}_admins` WHERE `id`=%s LIMIT 1",
+               $result = SQL_QUERY_ESC('SELECT `login`, `email` FROM `{?_MYSQL_PREFIX?}_admins` WHERE `id`=%s LIMIT 1',
                        array($id), __FUNCTION__, __LINE__);
                if ((SQL_NUMROWS($result) == 1) && ($selected == 1)) {
                        // Entry found
@@ -341,7 +341,7 @@ function adminsEditAdminAccount ($postData) {
                        }
 
                        // Load row template and switch color
-                       $OUT .= loadTemplate('admin_edit_admins_row', true, $content);
+                       $OUT .= loadTemplate('admin_edit_admins_row', TRUE, $content);
                } // END - if
 
                // Free result
@@ -349,7 +349,7 @@ function adminsEditAdminAccount ($postData) {
        } // END - foreach
 
        // Load template
-       loadTemplate('admin_edit_admins', false, $OUT);
+       loadTemplate('admin_edit_admins', FALSE, $OUT);
 }
 
 // Generate access mode selection box for given admin id
@@ -407,7 +407,7 @@ function generateAdminMenuModeSelectionBox ($adminId = NULL) {
 // Delete given admin accounts
 function adminsDeleteAdminAccount ($postData) {
        // Check if this account is the last one which cannot be deleted...
-       if (countSumTotalData('', 'admins', 'id', '', true) > 1) {
+       if (countSumTotalData('', 'admins', 'id', '', TRUE) > 1) {
                // Delete accounts
                $OUT = '';
                foreach ($postData['sel'] as $id => $selected) {
@@ -415,7 +415,16 @@ function adminsDeleteAdminAccount ($postData) {
                        $id = bigintval($id);
 
                        // Get the admin's data
-                       $result = SQL_QUERY_ESC("SELECT `login`,`email`,`default_acl` AS `access_mode`,`la_mode` FROM `{?_MYSQL_PREFIX?}_admins` WHERE `id`=%s LIMIT 1",
+                       $result = SQL_QUERY_ESC('SELECT
+       `login`,
+       `email`,
+       `default_acl` AS `access_mode`,
+       `la_mode`
+FROM
+       `{?_MYSQL_PREFIX?}_admins`
+WHERE
+       `id`=%s
+LIMIT 1',
                                array($id), __FUNCTION__, __LINE__);
 
                        // Is there an entry?
@@ -429,7 +438,7 @@ function adminsDeleteAdminAccount ($postData) {
                                $content['id'] = $id;
 
                                // Load row template and switch color
-                               $OUT .= loadTemplate('admin_delete_admins_row', true, $content);
+                               $OUT .= loadTemplate('admin_delete_admins_row', TRUE, $content);
                        } // END - if
 
                        // Free result
@@ -437,7 +446,7 @@ function adminsDeleteAdminAccount ($postData) {
                } // END - foreach
 
                // Load template
-               loadTemplate('admin_delete_admins', false, $OUT);
+               loadTemplate('admin_delete_admins', FALSE, $OUT);
        } else {
                // Cannot delete last account!
                displayMessage('{--ADMIN_ADMINS_CANNOT_DELETE_LAST--}');
@@ -455,11 +464,11 @@ function adminsRemoveAdminAccount ($postData) {
                // Delete only when it's not your own account!
                if (($del == 1) && (getCurrentAdminId() != $id)) {
                        // Rewrite his tasks to all admins
-                       SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_task_system` SET `assigned_admin`=NULL WHERE `assigned_admin`=%s",
+                       SQL_QUERY_ESC('UPDATE `{?_MYSQL_PREFIX?}_task_system` SET `assigned_admin`=NULL WHERE `assigned_admin`=%s',
                                array($id), __FUNCTION__, __LINE__);
 
                        // Remove account
-                       SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_admins` WHERE `id`=%s LIMIT 1",
+                       SQL_QUERY_ESC('DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_admins` WHERE `id`=%s LIMIT 1',
                                array($id), __FUNCTION__, __LINE__);
                }
        }
@@ -488,14 +497,14 @@ ORDER BY
                $content['la_mode']     = '{--ADMIN_ADMINS_LA_MODE_' . strtoupper($content['la_mode']) . '--}';
 
                // Load row template and switch color
-               $OUT .= loadTemplate('admin_list_admins_row', true, $content);
+               $OUT .= loadTemplate('admin_list_admins_row', TRUE, $content);
        } // END - while
 
        // Free memory
        SQL_FREERESULT($result);
 
        // Load template
-       loadTemplate('admin_list_admins', false, $OUT);
+       loadTemplate('admin_list_admins', FALSE, $OUT);
 }
 
 // Sends out mail to all administrators
@@ -513,9 +522,12 @@ function sendAdminsEmails ($subject, $template, $content, $userid) {
 
        // No entries found?
        if (SQL_HASZERONUMS($result)) {
-               // Create new entry (to all admins)
-               SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_admins_mails` (`admin_id`,`mail_template`) VALUES (0, '%s')",
-                       array($template), __FUNCTION__, __LINE__);
+               // Is ext-admins' version at least 0.7.9?
+               if (isExtensionInstalledAndNewer('admins', '0.7.9')) {
+                       // Create new entry (to all admins)
+                       SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_admins_mails` (`admin_id`, `mail_template`) VALUES (NULL, '%s')",
+                               array($template), __FUNCTION__, __LINE__);
+               } // END - if
 
                // Select all email adresses (default)
                $result = SQL_QUERY('SELECT `email` FROM `{?_MYSQL_PREFIX?}_admins` ORDER BY `id` ASC',
@@ -532,7 +544,7 @@ function sendAdminsEmails ($subject, $template, $content, $userid) {
                SQL_FREERESULT($result);
 
                // Init result
-               $result = false;
+               $result = FALSE;
 
                // "implode" ids and query string
                $adminId = implode(',', $adminIds);
@@ -551,13 +563,16 @@ function sendAdminsEmails ($subject, $template, $content, $userid) {
                                        $userid
                                ));
                        }
+
+                       // Abort here as below while() loop will cause problems
+                       return;
                } elseif (($adminId == '0') || (empty($adminId))) {
                        // Select all email adresses
                        $result = SQL_QUERY('SELECT `email` FROM `{?_MYSQL_PREFIX?}_admins` ORDER BY `id` ASC',
                                __FUNCTION__, __LINE__);
                } else {
                        // If Admin-Id is not "to-all" select
-                       $result = SQL_QUERY_ESC("SELECT `email` FROM `{?_MYSQL_PREFIX?}_admins` WHERE `id` IN (%s) ORDER BY `id` ASC",
+                       $result = SQL_QUERY_ESC('SELECT `email` FROM `{?_MYSQL_PREFIX?}_admins` WHERE `id` IN (%s) ORDER BY `id` ASC',
                                array($adminId), __FUNCTION__, __LINE__);
                }
        }
@@ -568,7 +583,7 @@ function sendAdminsEmails ($subject, $template, $content, $userid) {
        // Is the template a bug report?
        if ($template == 'admin_report_bug') {
                // Then set 'Reply-To:' again
-               $mailHeader = 'Reply-To: webmaster@mxchange.org' . chr(10);
+               $mailHeader = 'Reply-To: webmaster@mxchange.org' . PHP_EOL;
        } // END - if
 
        // Load email addresses and send away
@@ -597,7 +612,7 @@ function getAminsExpertSettings () {
                incrementStatsEntry('cache_hits');
        } elseif (!isExtensionInstalled('cache')) {
                // Load from database
-               $result = SQL_QUERY_ESC("SELECT `expert_settings` FROM `{?_MYSQL_PREFIX?}_admins` WHERE `id`=%s LIMIT 1",
+               $result = SQL_QUERY_ESC('SELECT `expert_settings` FROM `{?_MYSQL_PREFIX?}_admins` WHERE `id`=%s LIMIT 1',
                        array($adminId), __FUNCTION__, __LINE__);
 
                // Entry found?
@@ -634,7 +649,7 @@ function getAminsExpertWarning () {
                incrementStatsEntry('cache_hits');
        } elseif (!isExtensionInstalled('cache')) {
                // Load from database
-               $result = SQL_QUERY_ESC("SELECT `expert_warning` FROM `{?_MYSQL_PREFIX?}_admins` WHERE `id`=%s LIMIT 1",
+               $result = SQL_QUERY_ESC('SELECT `expert_warning` FROM `{?_MYSQL_PREFIX?}_admins` WHERE `id`=%s LIMIT 1',
                        array($adminId), __FUNCTION__, __LINE__);
 
                // Entry found?
@@ -673,7 +688,7 @@ function getAdminLoginFailures ($adminId) {
                incrementStatsEntry('cache_hits');
        } elseif (!isExtensionActive('cache')) {
                // Load from database
-               $result = SQL_QUERY_ESC("SELECT `login_failures` FROM `{?_MYSQL_PREFIX?}_admins` WHERE `id`=%s LIMIT 1",
+               $result = SQL_QUERY_ESC('SELECT `login_failures` FROM `{?_MYSQL_PREFIX?}_admins` WHERE `id`=%s LIMIT 1',
                        array($adminId), __FUNCTION__, __LINE__);
 
                // Is there an entry?
@@ -709,7 +724,7 @@ function getAdminLastFailure ($adminId) {
                incrementStatsEntry('cache_hits');
        } elseif (!isExtensionActive('cache')) {
                // Load from database
-               $result = SQL_QUERY_ESC("SELECT UNIX_TIMESTAMP(`last_failure`) AS `last_failure` FROM `{?_MYSQL_PREFIX?}_admins` WHERE `id`=%s LIMIT 1",
+               $result = SQL_QUERY_ESC('SELECT UNIX_TIMESTAMP(`last_failure`) AS `last_failure` FROM `{?_MYSQL_PREFIX?}_admins` WHERE `id`=%s LIMIT 1',
                        array($adminId), __FUNCTION__, __LINE__);
 
                // Is there an entry?
@@ -735,5 +750,10 @@ function isAdminsExpertWarningEnabled () {
        return (getAminsExpertWarning() == 'Y');
 }
 
+// Wrapper function to check whether expert setting is enabled
+function isAdminsExpertSettingEnabled () {
+       return (getAminsExpertSettings() == 'Y');
+}
+
 // [EOF]
 ?>