New functions introduced, several rewrites:
[mailer.git] / inc / libs / admins_functions.php
index 60a9d02731580fa7ce22c4984e9801c76427e021..6a1116e65e23958ab90059b480896ceacbeb6b47 100644 (file)
@@ -154,7 +154,7 @@ LIMIT 1",
 }
 
 // Change a lot admin account
-function adminsChangeAdminAccount ($postData) {
+function adminsChangeAdminAccount ($postData, $element = '') {
        // Begin the update
        $cache_update = '0';
        foreach ($postData['login'] as $id => $login) {
@@ -162,7 +162,14 @@ function adminsChangeAdminAccount ($postData) {
                $id = bigintval($id);
 
                // When both passwords match update admin account
-               if ($postData['pass1'][$id] == $postData['pass2'][$id]) {
+               if ((!empty($element)) && (isset($postData[$element]))) {
+                       // Save this setting
+                       SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_admins` SET `%s`='%s' WHERE `id`=%s LIMIT 1",
+                               array($element, $postData[$element][$id], $id), __FILE__, __LINE__);
+
+                       // Admin account saved
+                       $message = getMessage('ADMIN_ACCOUNT_SAVED');
+               } elseif ($postData['pass1'][$id] == $postData['pass2'][$id]) {
                        // Save only when both passwords are the same (also when they are empty)
                        $add = ''; $cache_update = 1;
 
@@ -241,12 +248,12 @@ LIMIT 1",
                        // Passwords did not match
                        $message = getMessage('ADMINS_ERROR_PASS_MISMATCH');
                }
+       } // END - foreach
 
-               // Display message
-               if (!empty($message)) {
-                       loadTemplate('admin_settings_saved', false, $message);
-               }
-       }
+       // Display message
+       if (!empty($message)) {
+               loadTemplate('admin_settings_saved', false, $message);
+       } // END - if
 
        // Remove cache file
        runFilterChain('post_admin_edited', postRequestArray());
@@ -310,7 +317,7 @@ function adminsDeleteAdminAccount ($postData) {
 
                        // Get the admin's data
                        $result = SQL_QUERY_ESC("SELECT login, email, default_acl AS mode, la_mode FROM `{?_MYSQL_PREFIX?}_admins` WHERE `id`=%s LIMIT 1",
-                       array($id), __FUNCTION__, __LINE__);
+                               array($id), __FUNCTION__, __LINE__);
                        if (SQL_NUMROWS($result) == 1) {
                                // Entry found
                                $content = SQL_FETCHARRAY($result);
@@ -392,6 +399,7 @@ function FILTER_ADD_EXTRA_SQL_DATA ($add = '') {
        if (getExtensionVersion('admins') >= '0.3.0') $add .= ', `default_acl` AS def_acl';
        if (getExtensionVersion('admins') >= '0.6.7') $add .= ', `la_mode`';
        if (getExtensionVersion('admins') >= '0.7.2') $add .= ', `login_failures`, UNIX_TIMESTAMP(`last_failure`) AS last_failure';
+       if (getExtensionVersion('admins') >= '0.7.3') $add .= ', `expert_settings`, `expert_warning`';
 
        // Return it
        return $add;
@@ -461,5 +469,79 @@ function sendAdminsEmails ($subj, $template, $content, $userid) {
        SQL_FREERESULT($result);
 }
 
+// "Getter" for current admin's expert settings
+function getAminsExpertSettings () {
+       // Default is has not the right
+       $data['expert_settings'] = 'N';
+
+       // Get current admin login
+       $admin = getAdminLogin(getCurrentAdminId());
+
+       // Lookup settings in cache
+       if (isset($GLOBALS['cache_array']['admin']['expert_settings'][$admin])) {
+               // Use cache
+               $data['expert_settings'] = $GLOBALS['cache_array']['admin']['expert_settings'][$admin];
+
+               // Update cache hits
+               incrementStatsEntry('cache_hits');
+       } elseif (!isExtensionInstalled('cache')) {
+               // Load from database
+               $result = SQL_QUERY_ESC("SELECT `expert_settings` FROM `{?_MYSQL_PREFIX?}_admins` WHERE `login`='%s' LIMIT 1",
+                       array($admin), __FUNCTION__, __LINE__);
+
+               // Entry found?
+               if (SQL_NUMROWS($result) == 1) {
+                       // Fetch data
+                       $data = SQL_FETCHARRAY($result);
+
+                       // Set cache
+                       $GLOBALS['cache_array']['admin']['expert_settings'][$admin] = $data['expert_settings'];
+               } // END - if
+
+               // Free memory
+               SQL_FREERESULT($result);
+       }
+
+       // Return the result
+       return $data['expert_settings'];
+}
+
+// "Getter" for current admin's expert warning (if he wants to see them or not
+function getAminsExpertWarning () {
+       // Default is has not the right
+       $data['expert_warning'] = 'N';
+
+       // Get current admin login
+       $admin = getAdminLogin(getCurrentAdminId());
+
+       // Lookup warning in cache
+       if (isset($GLOBALS['cache_array']['admin']['expert_warning'][$admin])) {
+               // Use cache
+               $data['expert_warning'] = $GLOBALS['cache_array']['admin']['expert_warning'][$admin];
+
+               // Update cache hits
+               incrementStatsEntry('cache_hits');
+       } elseif (!isExtensionInstalled('cache')) {
+               // Load from database
+               $result = SQL_QUERY_ESC("SELECT `expert_warning` FROM `{?_MYSQL_PREFIX?}_admins` WHERE `login`='%s' LIMIT 1",
+                       array($admin), __FUNCTION__, __LINE__);
+
+               // Entry found?
+               if (SQL_NUMROWS($result) == 1) {
+                       // Fetch data
+                       $data = SQL_FETCHARRAY($result);
+
+                       // Set cache
+                       $GLOBALS['cache_array']['admin']['expert_warning'][$admin] = $data['expert_warning'];
+               } // END - if
+
+               // Free memory
+               SQL_FREERESULT($result);
+       }
+
+       // Return the result
+       return $data['expert_warning'];
+}
+
 // [EOF]
 ?>