<?php
/************************************************************************
- * MXChange v0.2.1 Start: 06/30/2003 *
- * =============== Last change: 11/27/2004 *
+ * Mailer v0.2.1-FINAL Start: 06/30/2003 *
+ * =================== Last change: 11/27/2004 *
* *
* -------------------------------------------------------------------- *
* File : admins_functions.php *
// Default is deny
$ret = false;
- // Get admin's ID
+ // Get admin's id
$adminId = getCurrentAdminId();
// Get admin's defult access right
// Shall I test for a main or sub menu? (action or what?)
$acl_mode = 'failed';
- if ((getExtensionVersion('cache') >= '0.1.2') && (count($GLOBALS['cache_array']['admin_acls']) > 0)) {
+ if ((isExtensionInstalledAndNewer('cache', '0.1.2')) && (isset($GLOBALS['cache_array']['admin_acls'])) && (count($GLOBALS['cache_array']['admin_acls']) > 0)) {
// Lookup in cache
if ((!empty($action)) && (isset($GLOBALS['cache_array']['admin_acls']['action_menu'][$adminId])) & ($GLOBALS['cache_array']['admin_acls']['action_menu'][$adminId] == $action)) {
// Main menu line found
list($adminId) = SQL_FETCHROW($result);
// Rewrite email address to contact link
- $email = "{?URL?}/modules.php?module=".$mod."&what=admins_contct&admin=".bigintval($adminId);
+ $email = '{%url=modules.php?module=' . $mod . '&what=admins_contct&admin=' . bigintval($adminId) . '%}';
} // END - if
// Free memory
SQL_FREERESULT($result);
} elseif ((is_int($email)) && ($email > 0)) {
- // Direct ID given
- $email = "{?URL?}/modules.php?module=".$mod."&what=admins_contct&admin=".bigintval($email);
+ // Direct id given
+ $email = '{%url=modules.php?module=' . $mod . '&what=admins_contct&admin=' . bigintval($email) . '%}';
}
// Return rewritten (?) email address
}
// Change a lot admin account
-function adminsChangeAdminAccount ($postData) {
+function adminsChangeAdminAccount ($postData, $element = '') {
// Begin the update
- $cache_update = 0;
+ $cache_update = '0';
foreach ($postData['login'] as $id => $login) {
- // Secure ID number
+ // Secure id number
$id = bigintval($id);
// When both passwords match update admin account
- if ($postData['pass1'][$id] == $postData['pass2'][$id]) {
+ if ((!empty($element)) && (isset($postData[$element]))) {
+ // Save this setting
+ SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_admins` SET `%s`='%s' WHERE `id`=%s LIMIT 1",
+ array($element, $postData[$element][$id], $id), __FILE__, __LINE__);
+
+ // Admin account saved
+ $message = getMessage('ADMIN_ACCOUNT_SAVED');
+ } elseif ($postData['pass1'][$id] == $postData['pass2'][$id]) {
// Save only when both passwords are the same (also when they are empty)
- $add = ''; $cache_update = '1';
+ $add = ''; $cache_update = 1;
// Generate hash
$hash = generateHash($postData['pass1'][$id]);
// Save password when set
- if (!empty($postData['pass1'][$id])) $add = sprintf(", password='%s'", SQL_ESCAPE($hash));
+ if (!empty($postData['pass1'][$id])) $add = sprintf(", `password`='%s'", SQL_ESCAPE($hash));
- // Get admin's ID
+ // Get admin's id
$adminId = getCurrentAdminId();
- $salt = substr(getAdminHash($adminId), 0, -40);
+ $salt = substr(getAdminHash(getAdminLogin($adminId)), 0, -40);
// Rewrite cookie when it's own account
if ($adminId == $id) {
// Passwords did not match
$message = getMessage('ADMINS_ERROR_PASS_MISMATCH');
}
+ } // END - foreach
- // Display message
- if (!empty($message)) {
- loadTemplate('admin_settings_saved', false, $message);
- }
- }
+ // Display message
+ if (!empty($message)) {
+ loadTemplate('admin_settings_saved', false, $message);
+ } // END - if
// Remove cache file
runFilterChain('post_admin_edited', postRequestArray());
// Begin the edit loop
$OUT = ''; $SW = 2;
foreach ($postData['sel'] as $id => $selected) {
- // Secure ID number
+ // Secure id number
$id = bigintval($id);
// Get the admin's data
// Delete accounts
$OUT = ''; $SW = 2;
foreach ($postData['sel'] as $id => $selected) {
- // Secure ID number
+ // Secure id number
$id = bigintval($id);
// Get the admin's data
$result = SQL_QUERY_ESC("SELECT login, email, default_acl AS mode, la_mode FROM `{?_MYSQL_PREFIX?}_admins` WHERE `id`=%s LIMIT 1",
- array($id), __FUNCTION__, __LINE__);
+ array($id), __FUNCTION__, __LINE__);
if (SQL_NUMROWS($result) == 1) {
// Entry found
$content = SQL_FETCHARRAY($result);
// Remove the given accounts
function adminsRemoveAdminAccount ($postData) {
// Begin removal
- $cache_update = 0;
+ $cache_update = '0';
foreach ($postData['sel'] as $id => $del) {
- // Secure ID number
+ // Secure id number
$id = bigintval($id);
// Delete only when it's not your own account!
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`';
// Return it
return $add;
// Sends out mail to all administrators
// IMPORTANT: Please use SEND_ADMIN_NOTIFCATION() for now!
-function sendAdminsEmails ($subj, $template, $content, $UID) {
+function sendAdminsEmails ($subj, $template, $content, $userid) {
// Trim template name
$template = trim($template);
// Load email template
- $message = loadEmailTemplate($template, $content, $UID);
+ $message = loadEmailTemplate($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_NUMROWS($result) == '0') {
// 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__);
} else {
- // Load admin IDs...
+ // Load admin ids...
// @TODO This can be, somehow, rewritten
$adminIds = array();
while ($content = SQL_FETCHARRAY($result)) {
// Init result
$result = false;
- // "implode" IDs and query string
+ // "implode" ids and query string
$adminId = implode(',', $adminIds);
if ($adminId == '-1') {
if (isExtensionActive('events')) {
// Add line to user events
- EVENTS_ADD_LINE($subj, $message, $UID);
+ EVENTS_ADD_LINE($subj, $message, $userid);
} else {
// Log error for debug
- logDebugMessage(__FUNCTION__, __LINE__, sprintf("Extension 'events' missing: tpl=%s,subj=%s,UID=%s",
+ logDebugMessage(__FUNCTION__, __LINE__, sprintf("Extension 'events' missing: tpl=%s,subj=%s,userid=%s",
$template,
$subj,
- $UID
+ $userid
));
}
} elseif ($adminId == '0') {
$result = SQL_QUERY("SELECT `email` FROM `{?_MYSQL_PREFIX?}_admins` ORDER BY `id` ASC",
__FUNCTION__, __LINE__);
} else {
- // If Admin-ID is not "to-all" select
+ // If Admin-Id is not "to-all" select
$result = SQL_QUERY_ESC("SELECT `email` FROM `{?_MYSQL_PREFIX?}_admins` WHERE `id` IN (%s) ORDER BY `id` ASC",
array($adminId), __FUNCTION__, __LINE__);
}
SQL_FREERESULT($result);
}
+// "Getter" for current admin's expert settings
+function getAminsExpertSettings () {
+ // Default is has not the right
+ $data['expert_settings'] = 'N';
+
+ // Get current admin login
+ $admin = getAdminLogin(getCurrentAdminId());
+
+ // Lookup settings in cache
+ if (isset($GLOBALS['cache_array']['admin']['expert_settings'][$admin])) {
+ // Use cache
+ $data['expert_settings'] = $GLOBALS['cache_array']['admin']['expert_settings'][$admin];
+
+ // Update cache hits
+ incrementStatsEntry('cache_hits');
+ } elseif (!isExtensionInstalled('cache')) {
+ // Load from database
+ $result = SQL_QUERY_ESC("SELECT `expert_settings` FROM `{?_MYSQL_PREFIX?}_admins` WHERE `login`='%s' LIMIT 1",
+ array($admin), __FUNCTION__, __LINE__);
+
+ // Entry found?
+ if (SQL_NUMROWS($result) == 1) {
+ // Fetch data
+ $data = SQL_FETCHARRAY($result);
+
+ // Set cache
+ $GLOBALS['cache_array']['admin']['expert_settings'][$admin] = $data['expert_settings'];
+ } // END - if
+
+ // Free memory
+ SQL_FREERESULT($result);
+ }
+
+ // Return the result
+ return $data['expert_settings'];
+}
+
+// "Getter" for current admin's expert warning (if he wants to see them or not
+function getAminsExpertWarning () {
+ // Default is has not the right
+ $data['expert_warning'] = 'N';
+
+ // Get current admin login
+ $admin = getAdminLogin(getCurrentAdminId());
+
+ // Lookup warning in cache
+ if (isset($GLOBALS['cache_array']['admin']['expert_warning'][$admin])) {
+ // Use cache
+ $data['expert_warning'] = $GLOBALS['cache_array']['admin']['expert_warning'][$admin];
+
+ // Update cache hits
+ incrementStatsEntry('cache_hits');
+ } elseif (!isExtensionInstalled('cache')) {
+ // Load from database
+ $result = SQL_QUERY_ESC("SELECT `expert_warning` FROM `{?_MYSQL_PREFIX?}_admins` WHERE `login`='%s' LIMIT 1",
+ array($admin), __FUNCTION__, __LINE__);
+
+ // Entry found?
+ if (SQL_NUMROWS($result) == 1) {
+ // Fetch data
+ $data = SQL_FETCHARRAY($result);
+
+ // Set cache
+ $GLOBALS['cache_array']['admin']['expert_warning'][$admin] = $data['expert_warning'];
+ } // END - if
+
+ // Free memory
+ SQL_FREERESULT($result);
+ }
+
+ // Return the result
+ return $data['expert_warning'];
+}
+
// [EOF]
?>