Example #1
0
} elseif (isset($action) && ($action == 'edit' || $action == 'delete') && $_GET['profile']) {
    $profile = $_GET['profile'];
} elseif (in_array($action, array('edit', 'delete', 'update', 'update-name'))) {
    $messageStack->add_session(ERROR_NO_PROFILE_DEFINED, 'error');
    zen_redirect(zen_href_link(FILENAME_PROFILES));
}
// take appropriate steps depending upon the action requested
switch ($action) {
    case 'add':
        $pagesByMenu = zen_get_admin_pages(FALSE);
        $menuTitles = zen_get_menu_titles();
        break;
    case 'edit':
        $pagesByMenu = zen_get_admin_pages(FALSE);
        $menuTitles = zen_get_menu_titles();
        $profileName = zen_get_profile_name($profile);
        $permittedPages = zen_get_permitted_pages_for_profile($profile);
        break;
    case 'delete':
        $error = zen_delete_profile($profile);
        if ($error != '') {
            $messageStack->add_session($error, 'error');
            zen_redirect(zen_href_link(FILENAME_PROFILES));
        } else {
            $messageStack->add(SUCCESS_PROFILE_DELETED, 'success');
            unset($action);
            $profileList = zen_get_profiles(TRUE);
        }
        break;
    case 'insert':
        $error = zen_create_profile($_POST);
Example #2
0
function zen_update_user($name, $email, $id, $profile)
{
    global $db;
    $errors = array();
    if ($name !== FALSE) {
        if (strlen($name) >= ((int) ADMIN_NAME_MINIMUM_LENGTH < 4 ? 4 : (int) ADMIN_NAME_MINIMUM_LENGTH)) {
            $name = zen_db_prepare_input($name);
        } else {
            $errors[] = sprintf(ERROR_ADMIN_NAME_TOO_SHORT, (int) ADMIN_NAME_MINIMUM_LENGTH < 4 ? 4 : (int) ADMIN_NAME_MINIMUM_LENGTH);
        }
        if (zen_check_for_invalid_admin_chars($name) == FALSE) {
            $errors[] = ERROR_ADMIN_INVALID_CHARS_IN_USERNAME;
        }
    }
    $email = zen_db_prepare_input($email);
    if (zen_validate_email($email) == FALSE) {
        $errors[] = ERROR_ADMIN_INVALID_EMAIL_ADDRESS;
    }
    if (sizeof($errors) == 0) {
        $oldData = zen_read_user(zen_get_admin_name($id));
        $id = (int) $id;
        $sql = "UPDATE " . TABLE_ADMIN . "\n            SET admin_email = :email:, ";
        if (isset($name) && $name !== FALSE && $name != $oldData['admin_name']) {
            $sql .= "admin_name = :name:, ";
        }
        if (isset($profile) && $profile > 0 && $profile != $oldData['admin_profile']) {
            $sql .= "admin_profile = :profile:, ";
        }
        $sql .= "last_modified = NOW()\n             WHERE admin_id=" . $id;
        $sql = $db->bindVars($sql, ':name:', $name, 'string');
        $sql = $db->bindVars($sql, ':email:', $email, 'string');
        $sql = $db->bindVars($sql, ':profile:', $profile, 'integer');
        $db->Execute($sql);
        // Now notify admin and user of changes
        $newData = zen_read_user(zen_get_admin_name($id));
        $admname = preg_replace('/[^\\d\\w._-]/', '*', zen_get_admin_name()) . '[' . (int) $_SESSION['admin_id'] . ']';
        $changes = array();
        if ($oldData['admin_email'] != $newData['admin_email']) {
            $changes['email'] = array('old' => $oldData['admin_email'], 'new' => $newData['admin_email']);
        }
        if ($oldData['admin_name'] != $newData['admin_name']) {
            $changes['name'] = array('old' => $oldData['admin_name'], 'new' => $newData['admin_name']);
        }
        if ($oldData['admin_profile'] != $newData['admin_profile']) {
            $changes['profile'] = array('old' => zen_get_profile_name($oldData['admin_profile']) . '(' . $oldData['admin_profile'] . ')', 'new' => zen_get_profile_name($newData['admin_profile']) . '(' . $newData['admin_profile'] . ')');
        }
        $alertText = '';
        if (isset($changes['email'])) {
            $alertText .= sprintf(TEXT_EMAIL_ALERT_ADM_EMAIL_CHANGED, $oldData['admin_name'], $changes['email']['old'], $changes['email']['new'], $admname) . "\n";
        }
        if (isset($changes['name'])) {
            $alertText .= sprintf(TEXT_EMAIL_ALERT_ADM_NAME_CHANGED, $oldData['admin_name'], $changes['name']['old'], $changes['name']['new'], $admname) . "\n";
        }
        if (isset($changes['profile'])) {
            $alertText .= sprintf(TEXT_EMAIL_ALERT_ADM_PROFILE_CHANGED, $oldData['admin_name'], $changes['profile']['old'], $changes['profile']['new'], $admname) . "\n";
        }
        if ($alertText != '') {
            zen_mail(STORE_OWNER_EMAIL_ADDRESS, STORE_OWNER_EMAIL_ADDRESS, TEXT_EMAIL_SUBJECT_ADMIN_USER_CHANGED, $alertText, STORE_NAME, EMAIL_FROM, array('EMAIL_MESSAGE_HTML' => $alertText, 'EMAIL_SPAM_DISCLAIMER' => ' ', 'EMAIL_DISCLAIMER' => ' '), 'admin_settings_changed');
        }
        if ($alertText != '') {
            zen_mail($oldData['admin_email'], $oldData['admin_email'], TEXT_EMAIL_SUBJECT_ADMIN_USER_CHANGED, $alertText, STORE_NAME, EMAIL_FROM, array('EMAIL_MESSAGE_HTML' => $alertText, 'EMAIL_SPAM_DISCLAIMER' => ' ', 'EMAIL_DISCLAIMER' => ' '), 'admin_settings_changed');
        }
        if ($alertText != '') {
            zen_record_admin_activity(TEXT_EMAIL_SUBJECT_ADMIN_USER_CHANGED . ' ' . $alertText, 'warning');
        }
    }
    return $errors;
}