]> git.mxchange.org Git - mailer.git/blobdiff - inc/libs/admins_functions.php
Fix for missing array elements
[mailer.git] / inc / libs / admins_functions.php
index 12727422c0e232ec43115564f84d0c15202696fe..3ec0d018869a6c7d6a770bb94d0266f6822b8ad7 100644 (file)
@@ -18,6 +18,7 @@
  * svn:keywords Date Revision" (autoprobset!) at least!!!!!!            *
  * -------------------------------------------------------------------- *
  * Copyright (c) 2003 - 2009 by Roland Haeder                           *
+ * Copyright (c) 2009, 2010 by Mailer Developer Team                    *
  * For more information visit: http://www.mxchange.org                  *
  *                                                                      *
  * This program is free software; you can redistribute it and/or modify *
@@ -419,7 +420,7 @@ function adminsListAdminAccounts() {
 }
 
 // Sends out mail to all administrators
-// IMPORTANT: Please use SEND_ADMIN_NOTIFCATION() for now!
+// IMPORTANT: Please use sendAdminNotification() instead of calling this function directly
 function sendAdminsEmails ($subj, $template, $content, $userid) {
        // Trim template name
        $template = trim($template);
@@ -430,7 +431,7 @@ function sendAdminsEmails ($subj, $template, $content, $userid) {
        // Check which admin shall receive this mail
        $result = SQL_QUERY_ESC("SELECT `admin_id` FROM `{?_MYSQL_PREFIX?}_admins_mails` WHERE `mail_template`='%s' ORDER BY `admin_id` ASC",
                array($template), __FUNCTION__, __LINE__);
-       if (SQL_NUMROWS($result) == '0') {
+       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__);
@@ -462,7 +463,7 @@ function sendAdminsEmails ($subj, $template, $content, $userid) {
                                        $userid
                                ));
                        }
-               } elseif ($adminId == '0') {
+               } elseif (($adminId == '0') || (empty($adminId))) {
                        // Select all email adresses
                        $result = SQL_QUERY("SELECT `email` FROM `{?_MYSQL_PREFIX?}_admins` ORDER BY `id` ASC",
                                __FUNCTION__, __LINE__);
@@ -635,10 +636,10 @@ function getAdminLastFailure ($adminLogin) {
 // Filter for adding extra data to the query
 function FILTER_ADD_EXTRA_SQL_DATA ($add = '') {
        // Is the admins extension updated? (should be!)
-       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`';
+       if (isExtensionInstalledAndNewer('admins', '0.3.0')) $add .= ', `default_acl` AS def_acl';
+       if (isExtensionInstalledAndNewer('admins', '0.6.7')) $add .= ', `la_mode`';
+       if (isExtensionInstalledAndNewer('admins', '0.7.2')) $add .= ', `login_failures`, UNIX_TIMESTAMP(`last_failure`) AS last_failure';
+       if (isExtensionInstalledAndNewer('admins', '0.7.3')) $add .= ', `expert_settings`, `expert_warning`';
 
        // Return it
        return $add;
@@ -647,8 +648,8 @@ function FILTER_ADD_EXTRA_SQL_DATA ($add = '') {
 // Reset the login failures
 function FILTER_RESET_ADMINS_LOGIN_FAILURES ($data) {
        // Store it in session
-       setSession('mxchange_admin_failures'    , getAdminLoginFailures($data['login']));
-       setSession('mxchange_admin_last_failure', getAdminLastFailure($data['login']));
+       setSession('mailer_admin_failures'    , getAdminLoginFailures($data['login']));
+       setSession('mailer_admin_last_failure', getAdminLastFailure($data['login']));
 
        // Prepare update data
        $postData['login'][getCurrentAdminId()]          = $data['login'];
@@ -658,6 +659,9 @@ function FILTER_RESET_ADMINS_LOGIN_FAILURES ($data) {
        // Change it in the admin
        adminsChangeAdminAccount($postData);
 
+       // Always make sure the cache is destroyed
+       rebuildCache('admin');
+
        // Return the data for further processing
        return $data;
 }
@@ -672,6 +676,32 @@ function FILTER_COUNT_ADMINS_LOGIN_FAILURE ($data) {
        // Change it in the admin
        adminsChangeAdminAccount($postData);
 
+       // Always make sure the cache is destroyed
+       rebuildCache('admin');
+
+       // Return the data for further processing
+       return $data;
+}
+
+// Rehashes the given plain admin password and stores it the database
+function FILTER_REHASH_ADMINS_PASSWORD ($data) {
+       // Generate new hash
+       $newHash = generateHash($data['plain_pass']);
+
+       // Prepare update data
+       $postData['login'][getCurrentAdminId()]    = $data['login'];
+       $postData['password'][getCurrentAdminId()] = $newHash;
+
+       // Change it in the admin
+       adminsChangeAdminAccount($postData);
+
+       // Update cookie/session and data array
+       setSession('admin_md5', encodeHashForCookie($newHash));
+       $data['pass_hash'] = $newHash;
+
+       // Always make sure the cache is destroyed
+       rebuildCache('admin');
+
        // Return the data for further processing
        return $data;
 }