X-Git-Url: https://git.mxchange.org/?p=mailer.git;a=blobdiff_plain;f=inc%2Fmodules%2Fadmin%2Fadmin-inc.php;h=5d655b2f74b4fac3935630f250db0f6b54d4a08f;hp=86de3a3778c29ecdcacbe632f61b7b4bd6cc7116;hb=8da353fa4bb729bb3299d247803c23833a52a327;hpb=a18efdcd57ba91893f0958a457b5c58639b135c3 diff --git a/inc/modules/admin/admin-inc.php b/inc/modules/admin/admin-inc.php index 86de3a3778..5d655b2f74 100644 --- a/inc/modules/admin/admin-inc.php +++ b/inc/modules/admin/admin-inc.php @@ -16,7 +16,7 @@ * $Author:: $ * * -------------------------------------------------------------------- * * Copyright (c) 2003 - 2009 by Roland Haeder * - * Copyright (c) 2009 - 2011 by Mailer Developer Team * + * Copyright (c) 2009 - 2012 by Mailer Developer Team * * For more information visit: http://mxchange.org * * * * This program is free software; you can redistribute it and/or modify * @@ -41,7 +41,7 @@ if (!defined('__SECURITY')) { } // END - if // Register an administrator account -function addAdminAccount ($adminLogin, $passHash, $adminEmail) { +function addAdminAccount ($adminLogin, $passHash, $adminEmail, $accessLevel = 'deny') { // Login does already exist $ret = 'already'; @@ -51,13 +51,25 @@ function addAdminAccount ($adminLogin, $passHash, $adminEmail) { // Is the entry there? if (SQL_HASZERONUMS($result)) { - // Ok, let's create the admin login - SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_admins` (`login`,`password`,`email`) VALUES ('%s', '%s', '%s')", - array( - $adminLogin, - $passHash, - $adminEmail - ), __FUNCTION__, __LINE__); + // Is ext-admins installed and version at least 0.3.0? + if (isExtensionInstalledAndNewer('admins', '0.3.0')) { + // Ok, let's create the admin login + SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_admins` (`login`, `password`, `email`, `default_acl`) VALUES ('%s', '%s', '%s', '%s')", + array( + $adminLogin, + $passHash, + $adminEmail, + $accessLevel + ), __FUNCTION__, __LINE__); + } else { + // Ok, let's create the admin login + SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_admins` (`login`, `password`, `email`) VALUES ('%s', '%s', '%s')", + array( + $adminLogin, + $passHash, + $adminEmail + ), __FUNCTION__, __LINE__); + } // All done $ret = 'done'; @@ -80,7 +92,7 @@ function ifAdminLoginDataIsValid ($adminLogin, $adminPassword) { $adminId = getAdminId($adminLogin); // Continue only with found admin ids - if ($adminId > 0) { + if (isValidId($adminId)) { // Then we need to lookup the login name by getting the admin hash $adminHash = getAdminHash($adminId); @@ -130,38 +142,30 @@ function ifAdminCookiesAreValid ($adminLogin, $passHash) { if ($adminHash != '-1') { // Now, we need to encode the password in the same way the one is encoded in database $testHash = encodeHashForCookie($adminHash); - //* DEBUG: */ debugOutput('adminLogin=' . $adminLogin . ',passHash='.$passHash.',adminHash='.$adminHash.',testHash='.$testHash); + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'adminLogin=' . $adminLogin . ',passHash='.$passHash.',adminHash='.$adminHash.',testHash='.$testHash); // If they both match, the login data is valid - if ($testHash == $passHash) { + if ($testHash != $passHash) { + // Passwords don't match + $ret = 'password'; + } elseif (!isAdmin()) { + // Is not valid session + $ret = 'session'; + } else { // All fine $ret = 'done'; - } else { - // Set status - $ret = 'password'; } } // END - if // Return status - //* DEBUG: */ debugOutput('ret='.$ret); + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ret='.$ret); return $ret; } // Do an admin action function doAdminAction () { - // Get default what - $what = getWhat(); - - //* DEBUG: */ debugOutput(__LINE__.'*'.$what.'/'.getModule().'/'.getAction().'/'.getWhat().'*'); - - // Remove any spaces from variable - if (empty($what)) { - // Default admin action is the overview page - $what = 'overview'; - } else { - // Secure it - $what = secureString($what); - } + // Determine correct 'what' value + $what = determineWhat(); // Get action value $action = getActionFromModuleWhat(getModule(), $what); @@ -169,18 +173,18 @@ function doAdminAction () { // Load welcome template if (isExtensionActive('admins')) { // @TODO This and the next getCurrentAdminId() call might be moved into the templates? - $content['welcome'] = loadTemplate('admin_welcome_admins', true, getCurrentAdminId()); + $content['welcome'] = loadTemplate('admin_welcome_admins', TRUE, getCurrentAdminId()); } else { - $content['welcome'] = loadTemplate('admin_welcome', true, getCurrentAdminId()); + $content['welcome'] = loadTemplate('admin_welcome', TRUE, getCurrentAdminId()); } // Load header, footer, render menu - $content['header'] = loadTemplate('admin_header' , true, $content); - $content['footer'] = loadTemplate('admin_footer' , true, $content); - $content['menu'] = addAdminMenu($action, $what, true); + $content['header'] = loadTemplate('admin_header' , TRUE, $content); + $content['footer'] = loadTemplate('admin_footer' , TRUE, $content); + $content['menu'] = addAdminMenu($action, $what); - // Tableset header - loadTemplate('admin_main_header', false, $content); + // Load main template + loadTemplate('admin_main', FALSE, $content); // Check if action/what pair is valid $result_action = SQL_QUERY_ESC("SELECT @@ -191,12 +195,12 @@ WHERE `action`='%s' AND ( ( - `what`='%s' AND `what` != 'overview' + `what`='%s' AND `what` != 'welcome' ) OR ( ( `what`='' OR `what` IS NULL ) AND ( - '%s'='overview' + '%s'='welcome' ) ) ) @@ -207,40 +211,42 @@ LIMIT 1", $what ), __FUNCTION__, __LINE__); - // Do we have an entry? + // Is there 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); - if ((isIncludeReadable($inc)) && (isMenuActionValid('admin', $action, $what)) && ($GLOBALS['acl_allow'] === true)) { + if ((isIncludeReadable($inc)) && (isMenuActionValid('admin', $action, $what)) && ($GLOBALS['acl_allow'] === TRUE)) { // Ok, we finally load the admin action module loadInclude($inc); - } elseif ($GLOBALS['acl_allow'] === false) { + } elseif ($GLOBALS['acl_allow'] === FALSE) { // Access denied - loadTemplate('admin_menu_failed', false, '{%message,ADMIN_ACCESS_DENIED=' . $what . '%}'); + loadTemplate('admin_menu_failed', FALSE, '{%message,ADMIN_ACCESS_DENIED=' . $what . '%}'); } else { // Include file not found :-( - loadTemplate('admin_menu_failed', false, '{%message,ADMIN_ACTION_404=' . $action . '%}'); + loadTemplate('admin_menu_failed', FALSE, '{%message,ADMIN_ACTION_404=' . $action . '%}'); } } else { // Invalid action/what pair found - loadTemplate('admin_menu_failed', false, '{%message,ADMIN_ACTION_INVALID=' . $action . '/' . $what . '%}'); + loadTemplate('admin_menu_failed', FALSE, '{%message,ADMIN_ACTION_INVALID=' . $action . '/' . $what . '%}'); } // Free memory SQL_FREERESULT($result_action); // Tableset footer - loadTemplate('admin_main_footer', false, $content); + loadTemplate('admin_main_footer', FALSE, $content); } -// Checks wether current admin is allowed to access given action/what combination -// (only one is allowed to be null!) +/** + * Checks whether current admin is allowed to access given action/what + * combination (only one is allowed to be null!). + */ function isAdminAllowedAccessMenu ($action, $what = NULL) { - // Do we have cache? + // Is there cache? if (!isset($GLOBALS[__FUNCTION__][$action][$what])) { // ACL is always 'allow' when no ext-admins is installed // @TODO This can be rewritten into a filter - $GLOBALS[__FUNCTION__][$action][$what] = ((!isExtensionInstalledAndNewer('admins', '0.2.0')) || (isAdminsAllowedByAcl($action, $what))); + $GLOBALS[__FUNCTION__][$action][$what] = ((!isExtensionInstalledAndNewer('admins', '0.2.0')) || ((isExtensionActive('admins')) && (isAdminsAllowedByAcl($action, $what)))); } // END - if // Return the cached value @@ -248,18 +254,20 @@ function isAdminAllowedAccessMenu ($action, $what = NULL) { } // Adds an admin menu -function addAdminMenu ($action, $what, $return = false) { +function addAdminMenu ($action, $what) { // Init variables - $SUB = false; + $SUB = FALSE; $OUT = ''; // Menu descriptions $GLOBALS['menu']['description'] = array(); - $GLOBALS['menu']['title'] = array(); + $GLOBALS['menu']['title'] = array(); // Build main menu $result_main = SQL_QUERY("SELECT - `action`,`title`,`descr` + `action` AS `main_action`, + `title` AS `main_title`, + `descr` AS `main_descr` FROM `{?_MYSQL_PREFIX?}_admin_menu` WHERE @@ -268,55 +276,78 @@ ORDER BY `sort` ASC, `id` DESC", __FUNCTION__, __LINE__); - // Do we have entries? + // Are there entries? if (!SQL_HASZERONUMS($result_main)) { $OUT .= ''; + + // Free memory + SQL_FREERESULT($result_main); + } // END - if + + // Return content + return $OUT; +} + +// Add admin sub menu +function addAdminSubMenu ($mainContent, $action, $what) { + // Init content + $OUT = ''; + + // Check for menu entries + $result_what = SQL_QUERY_ESC("SELECT + `what` AS `sub_what`, + `title` AS `sub_title`, + `descr` AS `sub_descr` FROM `{?_MYSQL_PREFIX?}_admin_menu` WHERE @@ -326,78 +357,78 @@ WHERE ORDER BY `sort` ASC, `id` DESC", - array($menu), __FUNCTION__, __LINE__); - - // Remember the count for later checks - setAdminMenuHasEntries($menu, ((!SQL_HASZERONUMS($result_what)) && ($action == $menu))); - - // Do we have entries? - if ((ifAdminMenuHasEntries($menu)) && (!SQL_HASZERONUMS($result_what))) { - $GLOBALS['menu']['description'] = array(); - $GLOBALS['menu']['title'] = array(); - $SUB = true; - $OUT .= '
  • '; + } // END - if // Free memory - SQL_FREERESULT($result_main); - $OUT .= ''; + SQL_FREERESULT($result_what); } // END - if - // Is there a cache instance again? - // Return or output content? - if ($return === true) { - return $OUT; - } else { - outputHtml($OUT); - } + // Close li-tag + $OUT .= '
  • '; + + // Return content + return $OUT; } // Create an admin selection box form @@ -413,7 +444,9 @@ function addAdminSelectionBox ($adminId = NULL, $special = '') { // Query all entries $result = SQL_QUERY('SELECT - `id`,`login`' . $ADD . ' + `id`, + `login` + ' . $ADD . ' FROM `{?_MYSQL_PREFIX?}_admins` ORDER BY @@ -424,8 +457,17 @@ ORDER BY // Load all entries while ($content = SQL_FETCHARRAY($result)) { + // Default is none + $content['default'] = ''; + + // Is the id the same? + if ($content['id'] == $adminId) { + // Set this as default + $content['default'] = ' selected="selected"'; + } // END - if + // Add the entry - $OUT .= loadTemplate('select_admins_option', true, $content); + $OUT .= loadTemplate('select_admins_option', TRUE, $content); } // END - if // Free memory @@ -435,16 +477,19 @@ ORDER BY $content['form_selection'] = $OUT; // Output form - loadTemplate('select_admins_box', false, $content); + loadTemplate('select_admins_box', FALSE, $content); } // Create a member selection box -function addMemberSelectionBox ($userid = NULL, $add_all = false, $return = false, $none = false, $field = 'userid') { +function addMemberSelectionBox ($userid = NULL, $add_all = FALSE, $return = FALSE, $none = FALSE, $field = 'userid', $whereStatement = " WHERE `surname` NOT LIKE '{?tester_user_surname_prefix?}%'") { // Output selection form with all confirmed user accounts listed $result = SQL_QUERY('SELECT - `userid`,`surname`,`family` + `userid`, + `surname`, + `family` FROM `{?_MYSQL_PREFIX?}_user_data` +' . $whereStatement . ' ORDER BY `userid` ASC', __FUNCTION__, __LINE__); @@ -452,29 +497,32 @@ ORDER BY $OUT = ''; // USe this only for adding points (e.g. adding refs really makes no sence ;-) ) - if ($add_all === true) { + if ($add_all === TRUE) { $OUT = ' '; - } elseif ($none === true) { + } elseif ($none === TRUE) { $OUT = ' '; } // Load all entries while ($content = SQL_FETCHARRAY($result)) { + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . intval($userid) . '/' . $content['userid']); $OUT .= ''; @@ -652,9 +714,11 @@ function adminAddMenuSelectionBox ($menu, $type, $name, $default = '') { $part = substr($part, 0, -4); // Is that part different from the overview? - if ($part != 'overview') { + if ($part != 'welcome') { $OUT .= '