]> git.mxchange.org Git - mailer.git/blobdiff - inc/modules/admin/admin-inc.php
Default theme added (opps?)
[mailer.git] / inc / modules / admin / admin-inc.php
index e8778670dd68e3641742ab9eec8a57e2c5b2e8a6..ae4a18e4d655a9b8e40045beeec42e904ea9e3f6 100644 (file)
@@ -39,7 +39,7 @@
 // Some security stuff...
 if (!defined('__SECURITY')) {
        die();
-}
+} // END - if
 
 // Register an administrator account
 function addAdminAccount ($user, $md5, $email) {
@@ -53,8 +53,12 @@ function addAdminAccount ($user, $md5, $email) {
        // Is the entry there?
        if (SQL_NUMROWS($result) == 0) {
                // Ok, let's create the admin login
-               SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_admins` (login, password, email) VALUES ('%s', '%s', '%s')",
-               array($user, $md5, $email), __FUNCTION__, __LINE__);
+               SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_admins` (`login`, `password`, `email`) VALUES ('%s', '%s', '%s')",
+                       array(
+                               $user,
+                               $md5,
+                               $email
+                       ), __FUNCTION__, __LINE__);
                $ret = 'done';
        } // END - if
 
@@ -66,28 +70,28 @@ function addAdminAccount ($user, $md5, $email) {
 }
 
 // Only be executed on login procedure!
-function ifAdminLoginDataIsValid ($admin_login, $password) {
+function ifAdminLoginDataIsValid ($admin, $password) {
        // By default no admin is found
        $ret = '404';
 
        // Get admin id
-       $adminId = getAdminId($admin_login);
+       $adminId = getAdminId($admin);
 
        // Init array with admin id by default
        $data = array('admin_id' => $adminId);
 
        // Is the cache valid?
-       if (isset($GLOBALS['cache_array']['admins']['password'][$adminId])) {
+       if (isAdminHashSet($admin)) {
                // Get password from cache
-               $data['password'] = $GLOBALS['cache_array']['admins']['password'][$adminId];
+               $data['password'] = getAdminHash($admin);
                $ret = 'pass';
                incrementStatsEntry('cache_hits');
 
                // Include more admins data?
-               if (isExtensionInstalledAndNewer('admins', '0.7.2')) {
+               if ((isExtensionInstalledAndNewer('admins', '0.7.2')) && (isset($GLOBALS['cache_array']['admin']['login_failures'][$adminId]))) {
                        // Load them here
-                       $data['login_failures'] = $GLOBALS['cache_array']['admins']['login_failures'][$adminId];
-                       $data['last_failure']   = $GLOBALS['cache_array']['admins']['last_failure'][$adminId];
+                       $data['login_failures'] = $GLOBALS['cache_array']['admin']['login_failures'][$adminId];
+                       $data['last_failure']   = $GLOBALS['cache_array']['admin']['last_failure'][$adminId];
                } // END - if
        } elseif (!isExtensionActive('cache')) {
                // Add extra data via filter now
@@ -136,28 +140,28 @@ function ifAdminLoginDataIsValid ($admin_login, $password) {
 
                // Do we have 0.7.0 of admins or later?
                // Remmeber login failures if available
-               if (isExtensionInstalledAndNewer('admins', '0.7.2')) {
+               if ((isExtensionInstalledAndNewer('admins', '0.7.2')) && (isset($data['login_failures']))) {
                        // Store it in session
                        setSession('mxchange_admin_failures', $data['login_failures']);
                        setSession('mxchange_admin_last_fail', $data['last_failure']);
 
                        // Update password and reset login failures
-                       SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_admins` SET password='%s',login_failures=0,last_failure='0000-00-00 00:00:00' WHERE `id`=%s LIMIT 1",
+                       SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_admins` SET `password`='%s',`login_failures`=0,`last_failure`='0000-00-00 00:00:00' WHERE `id`=%s LIMIT 1",
                                array($data['password'], $adminId), __FUNCTION__, __LINE__);
                } else {
                        // Update password
-                       SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_admins` SET password='%s' WHERE `id`=%s LIMIT 1",
+                       SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_admins` SET `password`='%s' WHERE `id`=%s LIMIT 1",
                                array($data['password'], $adminId), __FUNCTION__, __LINE__);
                }
 
                // Rebuild cache
-               rebuildCacheFile('admins', 'admin');
+               rebuildCacheFile('admin', 'admin');
 
                // Login has failed by default... ;-)
                $ret = 'failed1';
 
                // Password matches so login here
-               if (doAdminLogin($admin_login, $data['password'])) {
+               if (doAdminLogin($admin, $data['password'])) {
                        // All done now
                        $ret = 'done';
                } // END - if
@@ -166,7 +170,7 @@ function ifAdminLoginDataIsValid ($admin_login, $password) {
                $ret = 'failed_salt';
        } elseif ($ret == 'done') {
                // Try to login here if we have the old hashing way (sql_patches not installed?)
-               if (!doAdminLogin($admin_login, $data['password'])) {
+               if (!doAdminLogin($admin, $data['password'])) {
                        // Something went wrong
                        $ret = 'failed2';
                } // END - if
@@ -175,15 +179,15 @@ function ifAdminLoginDataIsValid ($admin_login, $password) {
        // Count login failure if admins extension version is 0.7.0+
        if (($ret == 'pass') && (getExtensionVersion('admins') >= '0.7.0')) {
                // Update counter
-               SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_admins` SET login_failures=login_failures+1,last_failure=NOW() WHERE `id`=%s LIMIT 1",
-               array($adminId), __FUNCTION__, __LINE__);
+               SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_admins` SET login_failures`=`login_failures`+1,`last_failure`=NOW() WHERE `id`=%s LIMIT 1",
+                       array($adminId), __FUNCTION__, __LINE__);
 
                // Rebuild cache
-               rebuildCacheFile('admins', 'admin');
+               rebuildCacheFile('admin', 'admin');
        } // END - if
 
        // Return the result
-       //* DEBUG: */ die("RETURN=".$ret);
+       //* DEBUG: */ die('RETURN=' . $ret);
        return $ret;
 }
 
@@ -196,7 +200,7 @@ function doAdminLogin ($adminLogin, $passHash) {
                        array($adminLogin), __FUNCTION__, __LINE__);
 
                // Rebuild cache
-               rebuildCacheFile('admins', 'admin');
+               rebuildCacheFile('admin', 'admin');
        } // END - if
 
        // Now set all session variables and return the result
@@ -212,13 +216,13 @@ function doAdminLogin ($adminLogin, $passHash) {
 }
 
 // Only be executed on cookie checking
-function ifAdminCookiesAreValid ($admin_login, $password) {
+function ifAdminCookiesAreValid ($admin, $password) {
        // By default no admin cookies are found
        $ret  = '404';
        $pass = '';
 
        // Get hash
-       $pass = getAdminHash(getAdminId($admin_login));
+       $pass = getAdminHash($admin);
        if ($pass != '-1') $ret = 'pass';
 
        //* DEBUG: */ outputHtml(__FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):".generatePassString($pass).'('.strlen($pass).")/".$password.'('.strlen($password).")<br />");
@@ -463,7 +467,7 @@ ORDER BY
 }
 
 // Create member selection box
-function addMemberSelectionBox ($def='0', $add_all=false, $return=false, $none=false, $field='userid') {
+function addMemberSelectionBox ($def=0, $add_all=false, $return=false, $none=false, $field='userid') {
        // Output selection form with all confirmed user accounts listed
        $result = SQL_QUERY("SELECT `userid`, `surname`, `family` FROM `{?_MYSQL_PREFIX?}_user_data` ORDER BY `userid` ASC", __FUNCTION__, __LINE__);
 
@@ -507,7 +511,7 @@ function adminMenuSelectionBox_DEPRECATED ($mode, $default = '', $defid = '') {
        if (SQL_NUMROWS($result) > 0) {
                // Load menu as selection
                $OUT = "<select name=\"".$mode."_menu";
-               if ((!empty($defid)) || ($defid == '0')) $OUT .= "[".$defid."]";
+               if ((!empty($defid)) || ($defid == 0)) $OUT .= "[".$defid."]";
                $OUT .= "\" size=\"1\" class=\"admin_select\">
        <option value=\"\">{--SELECT_NONE--}</option>\n";
                // @TODO Try to rewrite this to $content = SQL_FETCHARRAY(). Please look some lines above for the dynamic query
@@ -590,7 +594,7 @@ function adminSaveSettings (&$postData, $tableName = "_config", $whereStatement
 
        if (SQL_NUMROWS($result) == 1) {
                // "Implode" all data to single string
-               $DATA_UPDATE = implode(", ", $DATA);
+               $DATA_UPDATE = implode(', ', $DATA);
 
                // Generate SQL string
                $sql = sprintf("UPDATE `{?_MYSQL_PREFIX?}%s` SET %s WHERE %s LIMIT 1",
@@ -608,8 +612,8 @@ function adminSaveSettings (&$postData, $tableName = "_config", $whereStatement
                } // END - foreach
 
                // Add both in one line
-               $KEYs = implode(", ", $KEYs);
-               $values = implode(", ", $values);
+               $KEYs = implode(', ', $KEYs);
+               $values = implode(', ', $values);
 
                // Generate SQL string
                $sql = sprintf("INSERT INTO {?_MYSQL_PREFIX?}%s (%s) VALUES (%s)",
@@ -673,18 +677,23 @@ function adminAddMenuSelectionBox ($menu, $type, $name, $default = '') {
 
 // Creates a user-profile link for the admin. This function can also be used for many other purposes
 function generateUserProfileLink ($userid, $title = '', $what = 'list_user') {
-       if (($title == '') && ($title != '0')) {
+       if (($title == '') && ($userid > 0)) {
                // Set userid as title
                $title = $userid;
        } // END - if
 
-       if (($title == '0') && ($what == 'list_refs')) {
+       if (($title == 0) && ($what == 'list_refs')) {
                // Return title again
                return $title;
-       } // END - if
+       } elseif (isExtensionActive('nickname')) {
+               // Get nickname
+               $nick = getNickname($userid);
+
+               // Is it not empty, use it as title else the userid
+               if (!empty($nick)) $title = $nick . '(' . $userid . ')'; else $title = $userid;
+       }
 
        // Return link
-       //* DEBUG: */ outputHtml("a:".$title."<br />");
        return '[<a href="{?URL?}/modules.php?module=admin&amp;what=' . $what . '&amp;userid=' . $userid . '" title="{--ADMIN_USER_PROFILE_TITLE--}">' . $title . '</a>]';
 }
 
@@ -698,9 +707,9 @@ function adminGetMenuMode () {
        $adminId = getCurrentAdminId();
 
        // Check individual settings of current admin
-       if (isset($GLOBALS['cache_array']['admins']['la_mode'][$adminId])) {
+       if (isset($GLOBALS['cache_array']['admin']['la_mode'][$adminId])) {
                // Load from cache
-               $ADMIN = $GLOBALS['cache_array']['admins']['la_mode'][$adminId];
+               $ADMIN = $GLOBALS['cache_array']['admin']['la_mode'][$adminId];
                incrementStatsEntry('cache_hits');
        } elseif (isExtensionInstalledAndNewer('admins', '0.6.7')) {
                // Load from database when version of 'admins' is enough
@@ -1207,7 +1216,7 @@ function doResetAdminPassword ($login, $password) {
        $passHash = '';
 
        // Now check if we have sql_patches installed
-       if (getExtensionVersion('sql_patches') >= '0.3.6') {
+       if (isExtensionInstalledAndNewer('sql_patches', '0.3.6')) {
                // Use new way of hashing
                $passHash = generateHash($password);
        } else {