Installation improved, first login:
[mailer.git] / inc / modules / admin / admin-inc.php
index 66a7223bd4abd1192e01dc9b0a51f277f56943e7..2f2d9bb0fc3bb9b1f4de3e7aea4385ae4aab0017 100644 (file)
@@ -51,7 +51,7 @@ function addAdminAccount ($user, $md5, $email) {
                array($user), __FUNCTION__, __LINE__);
 
        // Is the entry there?
-       if (SQL_NUMROWS($result) == 0) {
+       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(
@@ -59,6 +59,8 @@ function addAdminAccount ($user, $md5, $email) {
                                $md5,
                                $email
                        ), __FUNCTION__, __LINE__);
+
+               // All done
                $ret = 'done';
        } // END - if
 
@@ -210,8 +212,6 @@ function doAdminLogin ($adminLogin, $passHash) {
                setSession('admin_login', $adminLogin)
        ) && (
                setSession('admin_last', time())
-       ) && (
-               setSession('admin_to', bigintval(postRequestElement('timeout')))
        ));
 }
 
@@ -249,14 +249,14 @@ function doAdminAction () {
                // Default admin action is the overview page
                $what = 'overview';
        } else {
-               // Compile out some chars
-               $what = compileCode($what, false, false, false);
+               // Secure it
+               $what = secureString($what);
        }
 
        // Get action value
        $action = getModeAction(getModule(), $what);
 
-       // Define admin login name and ID number
+       // Define admin login name and id number
        $content['login'] = getSession('admin_login');
        $content['id']    = getCurrentAdminId();
 
@@ -272,12 +272,6 @@ function doAdminAction () {
        // Tableset header
        loadTemplate('admin_main_header', false, $content);
 
-       // Is sql_patches not yet installed?
-       if (!isExtensionInstalled('sql_patches')) {
-               // Output warning
-               loadTemplate('admin_settings_saved', false, getMessage('ADMIN_WARNING_SQL_PATCHES_MISSING'));
-       } // END - if
-
        // Check if action/what pair is valid
        $result_action = SQL_QUERY_ESC("SELECT
        `id`
@@ -297,7 +291,13 @@ WHERE
                )
        )
 LIMIT 1",
-               array($action, $what, $what), __FUNCTION__, __LINE__);
+               array(
+                       $action,
+                       $what,
+                       $what
+               ), __FUNCTION__, __LINE__);
+
+       // Do we have an entry?
        if (SQL_NUMROWS($result_action) == 1) {
                // Is valid but does the inlcude file exists?
                $inc = sprintf("inc/modules/admin/action-%s.php", $action);
@@ -343,6 +343,8 @@ WHERE
 ORDER BY
        `sort` ASC,
        `id` DESC", __FUNCTION__, __LINE__);
+
+       // Do we have entries?
        if (SQL_NUMROWS($result_main) > 0) {
                $OUT = "<div style=\"height:7px\" class=\"seperator\">&nbsp;</div>\n";
                $OUT .= "<ul class=\"admin_menu_main\">\n";
@@ -355,6 +357,12 @@ ORDER BY
                                $ACL = true;
                        }
 
+                       // Filename
+                       $inc = sprintf("inc/modules/admin/action-%s.php", $menu);
+
+                       // Is the file readable?
+                       $readable = isIncludeReadable($inc);
+
                        if ($ACL === true) {
                                if ($SUB === false) {
                                        // Insert compiled menu title and description
@@ -364,18 +372,26 @@ ORDER BY
                                $OUT .= "<li class=\"admin_menu\">
 <div class=\"nobr\"><strong>&middot;</strong>&nbsp;";
 
-                               if (($menu == $action) && (empty($what))) {
-                                       $OUT .= "<strong>";
+                               if ($readable === true) {
+                                       if (($menu == $action) && (empty($what))) {
+                                               $OUT .= "<strong>";
+                                       } else {
+                                               $OUT .= "[<a href=\"{?URL?}/modules.php?module=admin&amp;action=".$menu."\">";
+                                       }
                                } else {
-                                       $OUT .= "[<a href=\"{?URL?}/modules.php?module=admin&amp;action=".$menu."\">";
+                                       $OUT .= "<em style=\"cursor:help\" class=\"admin_note\" title=\"{--MENU_ACTION_404--}\">";
                                }
 
                                $OUT .= $title;
 
-                               if (($menu == $action) && (empty($what))) {
-                                       $OUT .= "</strong>";
+                               if ($readable === true) {
+                                       if (($menu == $action) && (empty($what))) {
+                                               $OUT .= "</strong>";
+                                       } else {
+                                               $OUT .= "</a>]";
+                                       }
                                } else {
-                                       $OUT .= "</a>]";
+                                       $OUT .= "</em>";
                                }
 
                                $OUT .= "</div>
@@ -521,7 +537,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
@@ -565,11 +581,8 @@ function adminSaveSettings (&$postData, $tableName = '_config', $whereStatement
                        // Do not save the ok value
                        convertSelectionsToTimestamp($postData, $DATA, $id, $skip);
 
-                       // Shall we process this ID? It muss not be empty, of course
+                       // Shall we process this id? It muss not be empty, of course
                        if (($skip === false) && (!empty($id)) && (!isset($GLOBALS['skip_config'][$id]))) {
-                               // Save this entry
-                               $val = compileCode($val);
-
                                // Translate the value? (comma to dot!)
                                if ((is_array($translateComma)) && (in_array($id, $translateComma))) {
                                        // Then do it here... :)
@@ -695,7 +708,7 @@ function generateUserProfileLink ($userid, $title = '', $what = 'list_user') {
                $title = $userid;
        } // END - if
 
-       if (($title == 0) && ($what == 'list_refs')) {
+       if (($title == '0') && ($what == 'list_refs')) {
                // Return title again
                return $title;
        } elseif (isExtensionActive('nickname')) {
@@ -746,11 +759,11 @@ function adminGetMenuMode () {
 
 // Change activation status
 function adminChangeActivationStatus ($IDs, $table, $row, $idRow = 'id') {
-       $cnt = 0; $newStatus = 'Y';
+       $cnt = '0'; $newStatus = 'Y';
        if ((is_array($IDs)) && (count($IDs) > 0)) {
                // "Walk" all through and count them
                foreach ($IDs as $id => $selected) {
-                       // Secure the ID number
+                       // Secure the id number
                        $id = bigintval($id);
 
                        // Should always be set... ;-)
@@ -832,7 +845,7 @@ function adminListBuilder ($listType, $IDs, $table, $columns, $filterFunctions,
 
        // "Walk" through all entries
        foreach ($IDs as $id => $selected) {
-               // Secure ID number
+               // Secure id number
                $id = bigintval($id);
 
                // Get result from a given column array and table name
@@ -967,7 +980,7 @@ function adminBuilderStatusHandler ($mode, $IDs, $table, $columns, $filterFuncti
        } // END - if
 }
 
-// Delete rows by given ID numbers
+// Delete rows by given id numbers
 function adminDeleteEntriesConfirm ($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))) {
@@ -1017,14 +1030,14 @@ function adminDeleteEntriesConfirm ($IDs, $table, $columns=array(), $filterFunct
        } // END - if
 }
 
-// Edit rows by given ID numbers
+// Edit rows by given id numbers
 function adminEditEntriesConfirm ($IDs, $table, $columns=array(), $filterFunctions=array(), $extraValues=array(), $editNow=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 change here or list for editing?
                if ($editNow === true) {
                        // Change them all
-                       $affected = 0;
+                       $affected = '0';
                        foreach ($IDs as $id => $sel) {
                                // Prepare content array (new values)
                                $content = array();
@@ -1106,7 +1119,7 @@ function adminEditEntriesConfirm ($IDs, $table, $columns=array(), $filterFunctio
        } // END - if
 }
 
-// Un-/lock rows by given ID numbers
+// Un-/lock rows by given id numbers
 function adminLockEntriesConfirm ($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 === false) || (count($statusArray) == 1))) {
@@ -1121,7 +1134,7 @@ function adminLockEntriesConfirm ($IDs, $table, $columns=array(), $filterFunctio
        } // END - if
 }
 
-// Undelete rows by given ID numbers
+// Undelete rows by given id numbers
 function adminUndeleteEntriesConfirm ($IDs, $table, $columns=array(), $filterFunctions=array(), $extraValues=array(), $statusArray=array(), $undeleteNow=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)) && (($undeleteNow === false) || (count($statusArray) == 1))) {
@@ -1156,15 +1169,12 @@ function sendAdminPasswordResetLink ($email) {
        // Init output
        $OUT = '';
 
-       // Compile out security characters (must be for looking up!)
-       $email = compileCode($email);
-
        // Look up administator login
        $result = SQL_QUERY_ESC("SELECT `id`, `login`, `password` FROM `{?_MYSQL_PREFIX?}_admins` WHERE `email`='%s' LIMIT 1",
                array($email), __FUNCTION__, __LINE__);
 
        // Is there an account?
-       if (SQL_NUMROWS($result) == 0) {
+       if (SQL_NUMROWS($result) == '0') {
                // No account found!
                return getMessage('ADMIN_NO_LOGIN_WITH_EMAIL');
        } // END - if
@@ -1197,12 +1207,9 @@ function adminResetValidateHashLogin ($hash, $login) {
        // By default nothing validates... ;)
        $valid = false;
 
-       // Compile the login for lookup
-       $login = compileCode($login);
-
        // Then try to find that user
        $result = SQL_QUERY_ESC("SELECT `id`, `password`, `email` FROM `{?_MYSQL_PREFIX?}_admins` WHERE `login`='%s' LIMIT 1",
-       array($login), __FUNCTION__, __LINE__);
+               array($login), __FUNCTION__, __LINE__);
 
        // Is an account here?
        if (SQL_NUMROWS($result) == 1) {
@@ -1210,7 +1217,7 @@ function adminResetValidateHashLogin ($hash, $login) {
                $content = SQL_FETCHARRAY($result);
 
                // Generate hash again
-               $hashFromData = generateHash(getConfig('URL').':'.$content['id'].':'.$login.':'.$content['password'], substr($content['password'], 10));
+               $hashFromData = generateHash(getConfig('URL') . ':' . $content['id'] . ':' . $login . ':' . $content['password'], substr($content['password'], 10));
 
                // Does both match?
                $valid = ($hash == $hashFromData);
@@ -1313,5 +1320,35 @@ function adminCreateUserLink ($userid) {
        return '{?URL?}/modules.php?module=admin&amp;what=list_user';
 }
 
+// Generate a "link" for the given admin id (admin_id)
+function generateAdminLink ($adminId) {
+       // No assigned admin is default
+       $adminLink = "<span class=\"admin_note\">{--ADMIN_NO_ADMIN_ASSIGNED--}</span>";
+
+       // Zero? = Not assigned
+       if (bigintval($adminId) > 0) {
+               // Load admin's login
+               $login = getAdminLogin($adminId);
+
+               // Is the login valid?
+               if ($login != '***') {
+                       // Is the extension there?
+                       if (isExtensionActive('admins')) {
+                               // Admin found
+                               $adminLink = "<a href=\"".generateEmailLink(getAdminEmail($adminId), 'admins')."\">" . $login."</a>";
+                       } else {
+                               // Extension not found
+                               $adminLink = sprintf(getMessage('EXTENSION_PROBLEM_NOT_INSTALLED'), 'admins');
+                       }
+               } else {
+                       // Maybe deleted?
+                       $adminLink = "<div class=\"admin_note\">".sprintf(getMessage('ADMIN_ID_404'), $adminId)."</div>";
+               }
+       } // END - if
+
+       // Return result
+       return $adminLink;
+}
+
 // [EOF]
 ?>