]> git.mxchange.org Git - mailer.git/blobdiff - inc/modules/admin/admin-inc.php
Surfbar continued (unfinished) and some updates:
[mailer.git] / inc / modules / admin / admin-inc.php
index ebf2b0e3caba251d4c141eed40166ac957c60b57..2c3dffea5de11a272b5ec64479ecffef55512608 100644 (file)
@@ -107,8 +107,8 @@ function CHECK_ADMIN_LOGIN ($admin_login, $password)
                $data['password'] = generateHash($password);
 
                // Is the sql_patches not installed, than we cannot have a valid hashed password here!
-               if (($ret == "pass") && ((GET_EXT_VERSION("sql_patches") < "0.3.6") || (GET_EXT_VERSION("sql_patches") == ""))) $ret = "done";
-       } elseif ((GET_EXT_VERSION("sql_patches") < "0.3.6") || (GET_EXT_VERSION("sql_patches") == "")) {
+               if (($ret == "pass") && ((EXT_VERSION_IS_OLDER("sql_patches", "0.3.6")) || (GET_EXT_VERSION("sql_patches") == ""))) $ret = "done";
+       } elseif ((EXT_VERSION_IS_OLDER("sql_patches", "0.3.6")) || (GET_EXT_VERSION("sql_patches") == "")) {
                // Old hashing way
                return $ret;
        } elseif (!isset($data['password'])) {
@@ -132,11 +132,15 @@ function CHECK_ADMIN_LOGIN ($admin_login, $password)
                        // Store it in session
                        set_session('mxchange_admin_failtures', $data['login_failtures']);
                        set_session('mxchange_admin_last_fail', $data['last_failture']);
-               } // END - if
 
-               // Update password
-               $result = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_admins SET password='%s',login_failtures=0,last_failture='0000-00-00 00:00:00' WHERE login='%s' LIMIT 1",
-                array($data['password'], $admin_login), __FILE__, __LINE__);
+                       // Update password and reset login failtures
+                       $result = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_admins SET password='%s',login_failtures=0,last_failture='0000-00-00 00:00:00' WHERE login='%s' LIMIT 1",
+                               array($data['password'], $admin_login), __FILE__, __LINE__);
+               } else {
+                       // Update password
+                       $result = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_admins SET password='%s' WHERE login='%s' LIMIT 1",
+                               array($data['password'], $admin_login), __FILE__, __LINE__);
+               }
 
                // Rebuild cache
                REBUILD_CACHE("admins", "admin");
@@ -180,7 +184,7 @@ function LOGIN_ADMIN ($adminLogin, $passHash) {
        global $cacheInstance;
 
        // Reset failture counter on matching admins version
-       if ((GET_EXT_VERSION("admins") >= "0.7.0") && ((GET_EXT_VERSION("sql_patches") < "0.3.6") || (GET_EXT_VERSION("sql_patches") == ""))) {
+       if ((GET_EXT_VERSION("admins") >= "0.7.0") && ((EXT_VERSION_IS_OLDER("sql_patches", "0.3.6")) || (GET_EXT_VERSION("sql_patches") == ""))) {
                // Reset counter on out-dated sql_patches version
                SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_admins SET login_failtures=0,last_failture='0000-00-00 00:00:00' WHERE login='%s' LIMIT 1",
                        array($adminLogin), __FILE__, __LINE__);
@@ -228,7 +232,7 @@ function CHECK_ADMIN_COOKIES ($admin_login, $password) {
                SQL_FREERESULT($result);
        }
 
-       //* DEBUG: */ echo __FUNCTION__.":".$pass."(".strlen($pass).")/".$password."(".strlen($password).")<br />\n";
+       //* DEBUG: */ echo __FUNCTION__.":".generatePassString($pass)."(".strlen($pass).")/".$password."(".strlen($password).")<br />\n";
 
        // Check if password matches
        if (($ret == "pass") && ((generatePassString($pass) == $password) || ($pass == $password) || ((strlen($pass) == 32) && (md5($password) == $pass)))) {
@@ -581,7 +585,7 @@ function ADD_ADMIN_MENU($act, $wht, $return=false) {
        }
 }
 //
-function ADD_MEMBER_SELECTION_BOX ($def="0", $add_all=false, $return=false, $none=false)
+function ADD_MEMBER_SELECTION_BOX ($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", __FILE__, __LINE__);
@@ -610,8 +614,8 @@ function ADD_MEMBER_SELECTION_BOX ($def="0", $add_all=false, $return=false, $non
                // Load template
                LOAD_TEMPLATE("admin_member_selection_box", false, $GLOBALS['what']);
        } else {
-               // Return content
-               return "<select name=\"userid\" size=\"1\">\n".$OUT."</select>\n";
+               // Return content in selection frame
+               return "<select class=\"admin_select\" name=\"".$field."\" size=\"1\">\n".$OUT."</select>\n";
        }
 }
 //
@@ -903,7 +907,7 @@ function ADMIN_BUILD_LIST ($listType, $IDs, $table, $columns, $filterFunctions,
                $id = bigintval($id);
 
                // Get result from a given column array and table name
-               $result = SQL_RESULT_FROM_ARRAY($table, $columns, $idColumn, $id);
+               $result = SQL_RESULT_FROM_ARRAY($table, $columns, $idColumn, $id, __FILE__, __LINE__);
 
                // Is there one entry?
                if (SQL_NUMROWS($result) == 1) {
@@ -942,14 +946,90 @@ function ADMIN_BUILD_LIST ($listType, $IDs, $table, $columns, $filterFunctions,
        // Load master template
        LOAD_TEMPLATE("admin_".$listType."_".$table."", false, $OUT);
 }
+// Change status of "build" list
+function ADMIN_BUILD_STATUS_HANDLER ($mode, $IDs, $table, $columns, $filterFunctions, $extraValues, $idColumn, $userIdColumn, $statusArray) {
+       // All valid entries? (We hope so here!)
+       if ((is_array($IDs)) && (count($IDs) > 0) && (count($columns) == count($filterFunctions)) && (count($columns) == count($extraValues)) && (count($statusArray) > 0)) {
+               // "Walk" through all entries
+               foreach ($IDs as $id => $sel) {
+                       // Construct SQL query
+                       $SQL = "UPDATE "._MYSQL_PREFIX."_".$table." SET";
+
+                       // Load data of entry
+                       $result = SQL_QUERY_ESC("SELECT * FROM "._MYSQL_PREFIX."_%s WHERE %s=%s LIMIT 1",
+                               array($table, $idColumn, $id), __FILE__, __LINE__);
+
+                       // Fetch the data
+                       $content = SQL_FETCHARRAY($result);
+
+                       // Free the result
+                       SQL_FREERESULT($result);
+
+                       // Add all status entries (e.g. status column last_updated or so)
+                       $newStatus = "UNKNOWN";
+                       $oldStatus = "UNKNOWN";
+                       $statusColumn = "unknown";
+                       foreach ($statusArray as $column => $statusInfo) {
+                               // Does the entry exist?
+                               if ((isset($content[$column])) && (isset($statusInfo[$content[$column]]))) {
+                                       // Add these entries for update
+                                       $SQL .= sprintf(" %s='%s',", SQL_ESCAPE($column), SQL_ESCAPE($statusInfo[$content[$column]]));
+
+                                       // Remember status
+                                       if ($statusColumn == "unknown") {
+                                               // Always (!!!) change status column first!
+                                               $oldStatus = $content[$column];
+                                               $newStatus = $statusInfo[$oldStatus];
+                                               $statusColumn = $column;
+                                       } // END - if
+                               } elseif (isset($content[$column])) {
+                                       // Unfinished!
+                                       mxchange_die("{--".__FUNCTION__."--}:UNFINISHED: id={$id}/{$column}[".gettype($statusInfo)."] = {$content[$column]}");
+                               }
+                       } // END - foreach
+
+                       // Add other columns as well
+                       foreach ($_POST as $key => $entries) {
+                               // Skip id, raw userid and 'do_lock'
+                               if (!in_array($key, array($idColumn, 'uid_raw', 'do_lock'))) {
+                                       // Are there brackets () at the end?
+                                       if (substr($entries[$id], -2, 2) == "()") {
+                                               // Direct SQL command found
+                                               $SQL .= sprintf(" %s=%s,", SQL_ESCAPE($key), SQL_ESCAPE($entries[$id]));
+                                       } else {
+                                               // Add regular entry
+                                               $SQL .= sprintf(" %s='%s',", SQL_ESCAPE($key), SQL_ESCAPE($entries[$id]));
+                                       }
+                               } // END - if
+                       } // END - if
+
+                       // Finish SQL statement
+                       $SQL = substr($SQL, 0, -1) . " WHERE ".$idColumn."=".bigintval($id)." AND ".$statusColumn."='".$oldStatus."' LIMIT 1";
+
+                       // Run the SQL
+                       SQL_QUERY($SQL, __FILE__, __LINE__);
+
+                       // Do we have an URL?
+                       if (isset($content['url'])) {
+                               // Then add a framekiller test as well
+                               $content['frametester'] = FRAMETESTER($content['url']);
+                       } // END - if
+
+                       // Send "build mails" out
+                       ADMIN_SEND_BUILD_MAILS($mode, $table, $content, $id, $statusInfo[$content[$column]]);
+               } // END - foreach
+       } // END - if
+}
 // Delete rows by given ID numbers
 function ADMIN_DELETE_ENTRIES_CONFIRM ($IDs, $table, $columns=array(), $filterFunctions=array(), $extraValues=array(), $deleteNow=false, $idColumn="id", $userIdColumn="userid") {
        // All valid entries? (We hope so here!)
        if ((is_array($IDs)) && (count($IDs) > 0) && (count($columns) == count($filterFunctions)) && (count($columns) == count($extraValues))) {
                // Shall we delete here or list for deletion?
                if ($deleteNow) {
-                       // Delete them
+                       // The base SQL command:
                        $SQL = "DELETE LOW_PRIORITY FROM "._MYSQL_PREFIX."_%s WHERE %s IN (%s)";
+
+                       // Delete them all
                        $idList = "";
                        foreach ($IDs as $id => $sel) {
                                // Is there a userid?
@@ -970,7 +1050,7 @@ function ADMIN_DELETE_ENTRIES_CONFIRM ($IDs, $table, $columns=array(), $filterFu
 
                                // Add id number
                                $idList .= $id.",";
-                       } // END - if
+                       } // END - foreach
 
                        // Run the query
                        SQL_QUERY($SQL, array($table, $idColumn, substr($idList, 0, -1)), __FILE__, __LINE__);
@@ -1036,7 +1116,9 @@ function ADMIN_EDIT_ENTRIES_CONFIRM ($IDs, $table, $columns=array(), $filterFunc
                                                // Then add a framekiller test as well
                                                $content['frametester'] = FRAMETESTER($content[$key]);
                                        } // END - if
-                               }
+                               } // END - foreach
+
+                               // Finish SQL command
                                $SQL = substr($SQL, 0, -1) . " WHERE ".$idColumn."=".bigintval($id)." LIMIT 1";
 
                                // Run this query
@@ -1081,79 +1163,27 @@ function ADMIN_LOCK_ENTRIES_CONFIRM ($IDs, $table, $columns=array(), $filterFunc
                // Shall we un-/lock here or list for locking?
                if ($lockNow) {
                        // Un-/lock entries
-                       foreach ($IDs as $id => $sel) {
-                               // Construct SQL query
-                               $SQL = "UPDATE "._MYSQL_PREFIX."_".$table." SET";
-
-                               // Load data of entry
-                               $result = SQL_QUERY_ESC("SELECT * FROM "._MYSQL_PREFIX."_%s WHERE %s=%s LIMIT 1",
-                                       array($table, $idColumn, $id), __FILE__, __LINE__);
-
-                               // Fetch the data
-                               $content = SQL_FETCHARRAY($result);
-
-                               // Free the result
-                               SQL_FREERESULT($result);
-
-                               // Add all status entries (e.g. status column last_updated or so)
-                               $newStatus = "UNKNOWN";
-                               $oldStatus = "UNKNOWN";
-                               $statusColumn = "unknown";
-                               foreach ($statusArray as $column => $statusInfo) {
-                                       // Does the entry exist?
-                                       if ((isset($content[$column])) && (isset($statusInfo[$content[$column]]))) {
-                                               // Add these entries for update
-                                               $SQL .= sprintf(" %s='%s',", SQL_ESCAPE($column), SQL_ESCAPE($statusInfo[$content[$column]]));
-
-                                               // Remember status
-                                               if ($statusColumn == "unknown") {
-                                                       // Always (!!!) change status column first!
-                                                       $oldStatus = $content[$column];
-                                                       $newStatus = $statusInfo[$oldStatus];
-                                                       $statusColumn = $column;
-                                               } // END - if
-                                       } elseif (isset($content[$column])) {
-                                               // Unfinished!
-                                               die("UNFINISHED: {$column}[".gettype($statusInfo)."] = {$content[$column]}");
-                                       }
-                               } // END - foreach
-
-                               // Add other columns as well
-                               foreach ($_POST as $key => $entries) {
-                                       // Skip id, raw userid and 'do_lock'
-                                       if (!in_array($key, array($idColumn, 'uid_raw', 'do_lock'))) {
-                                               // Are there brackets () at the end?
-                                               if (substr($entries[$id], -2, 2) == "()") {
-                                                       // Direct SQL command found
-                                                       $SQL .= sprintf(" %s=%s,", SQL_ESCAPE($key), SQL_ESCAPE($entries[$id]));
-                                               } else {
-                                                       // Add regular entry
-                                                       $SQL .= sprintf(" %s='%s',", SQL_ESCAPE($key), SQL_ESCAPE($entries[$id]));
-                                               }
-                                       } // END - if
-                               } // END - if
-
-                               // Finish SQL statement
-                               $SQL = substr($SQL, 0, -1) . " WHERE ".$idColumn."=".bigintval($id)." AND ".$statusColumn."='".$oldStatus."' LIMIT 1";
-
-                               // Run the SQL
-                               SQL_QUERY($SQL, __FILE__, __LINE__);
-
-                               // Do we have an URL?
-                               if (isset($content['url'])) {
-                                       // Then add a framekiller test as well
-                                       $content['frametester'] = FRAMETESTER($content['url']);
-                               } // END - if
-
-                               // Send "build mails" out
-                               ADMIN_SEND_BUILD_MAILS("lock", $table, $content, $id, $statusInfo[$content[$column]]);
-                       } // END - if
+                       ADMIN_BUILD_STATUS_HANDLER("lock", $IDs, $table, $columns, $filterFunctions, $extraValues, $idColumn, $userIdColumn);
                } else {
                        // List for editing
                        ADMIN_BUILD_LIST("lock", $IDs, $table, $columns, $filterFunctions, $extraValues, $idColumn, $userIdColumn);
                }
        } // END - if
 }
+// Undelete rows by given ID numbers
+function ADMIN_UNDELETE_ENTRIES_CONFIRM ($IDs, $table, $columns=array(), $filterFunctions=array(), $extraValues=array(), $statusArray=array(), $lockNow=false, $idColumn="id", $userIdColumn="userid") {
+       // All valid entries? (We hope so here!)
+       if ((is_array($IDs)) && (count($IDs) > 0) && (count($columns) == count($filterFunctions)) && (count($columns) == count($extraValues)) && ((!$lockNow) || (count($statusArray) == 1))) {
+               // Shall we un-/lock here or list for locking?
+               if ($lockNow) {
+                       // Undelete entries
+                       ADMIN_BUILD_STATUS_HANDLER("undelete", $IDs, $table, $columns, $filterFunctions, $extraValues, $idColumn, $userIdColumn, $statusArray);
+               } else {
+                       // List for editing
+                       ADMIN_BUILD_LIST("undelete", $IDs, $table, $columns, $filterFunctions, $extraValues, $idColumn, $userIdColumn);
+               }
+       } // END - if
+}
 // Checks proxy settins by fetching check-updates3.php from www.mxchange.org
 function ADMIN_TEST_PROXY_SETTINGS ($settingsArray) {
        global $_CONFIG;