Пример #1
0
function main()
{
    $product = array();
    $errors = empty_errors();
    if (is_postback()) {
        // подключаемся к базе данных
        $dbh = db_connect();
        $post_result = add_product($dbh, $product, $errors);
        db_close($dbh);
        if ($post_result) {
            // перенаправляем на список товаров
            render('sucsess_register', array());
        } else {
            render('BD_ProductInsert_T', array('form' => $_POST, 'file' => $_FILES, 'errors' => $errors));
        }
    } else {
        // отправляем пользователю чистую форму для входа
        render('BD_ProductInsert_T', array('form' => array(), 'errors' => array()));
    }
}
Пример #2
0
function show_error($error, $extra = NULL)
{
    // show error-message
    $msg = $error;
    if ($extra != NULL) {
        $msg .= " - " . $extra;
    }
    add_error($msg);
    if (empty($_GET['error'])) {
        session_write_close();
        mosRedirect(make_link("show_error", $GLOBALS["dir"]) . '&error=1&extra=' . urlencode($extra));
    } else {
        show_header($GLOBALS["error_msg"]["error"]);
        $errors = count_errors();
        $messages = count_messages();
        echo '<div class="quote">';
        if ($errors) {
            echo '<a href="#errors">' . $errors . ' ' . $GLOBALS["error_msg"]["error"] . '</a><br />';
        }
        if ($messages) {
            echo '<a href="#messages">' . $messages . ' ' . $GLOBALS["error_msg"]["message"] . '</a><br />';
        }
        echo "</div>\n";
        if (!empty($_SESSION['jx_message'])) {
            echo "<a href=\"" . str_replace('&dir=', '&ignore=', make_link("list", '')) . "\">[ " . $GLOBALS["error_msg"]["back"] . " ]</a>";
            echo "<div class=\"jx_message\"><a name=\"messages\"></a>\n\t\t\t\t\t<h3>" . $GLOBALS["error_msg"]["message"] . ":</strong>" . "</h3>\n";
            foreach ($_SESSION['jx_message'] as $msgtype) {
                foreach ($msgtype as $message) {
                    echo $message . "\n<br/>";
                }
                echo '<br /><hr /><br />';
            }
            empty_messages();
            if (!empty($_REQUEST['extra'])) {
                echo " - " . htmlspecialchars(urldecode($_REQUEST['extra']), ENT_QUOTES);
            }
            echo "</div>\n";
        }
        if (!empty($_SESSION['jx_error'])) {
            echo "<div class=\"jx_error\"><a name=\"errors\"></a>\n\t\t\t\t<h3>" . $GLOBALS["error_msg"]["error"] . ":</strong>" . "</h3>\n";
            foreach ($_SESSION['jx_error'] as $errortype) {
                foreach ($errortype as $error) {
                    echo $error . "\n<br/>";
                }
                echo '<br /><hr /><br />';
            }
            empty_errors();
        }
        echo "<a href=\"" . str_replace('&dir=', '&ignore=', make_link("list", '')) . "\">" . $GLOBALS["error_msg"]["back"] . "</a>";
        if (!empty($_REQUEST['extra'])) {
            echo " - " . htmlspecialchars(urldecode($_REQUEST['extra']), ENT_QUOTES);
        }
        echo "</div>\n";
        defined('JXPLORER_NOEXEC') or define('JXPLORER_NOEXEC', 1);
    }
}
Пример #3
0
function add_product($dbh, &$product, &$errors)
{
    $product = array();
    $errors = empty_errors();
    // считываем строки из запроса
    read_string($_POST, 'title', $product, $errors, 2, 60, false);
    read_integer($_POST, 'category_id', $product, $errors, 1, null, true);
    read_decimal($_POST, 'price', $product, $errors, '0.0', null, true);
    read_integer($_POST, 'stock', $product, $errors, 1, null, true);
    read_string($_POST, 'description', $product, $errors, 1, 10000, false, null, false);
    read_img($_FILES, 'img', $product, $errors, 0, 204800, true);
    if (has_errors($errors)) {
        return false;
    }
    // форма передана правильно, сохраняем пользователя в базу данных
    $db_product = db_product_insert($dbh, $product);
    return true;
}
Пример #4
0
function register_user($dbh, &$user, &$errors)
{
    $user = array();
    $errors = empty_errors();
    // считываем строки из запроса
    read_string($_POST, 'nickname', $user, $errors, 2, 64, true);
    read_email($_POST, 'email', $user, $errors, 2, 64, true);
    read_string($_POST, 'password', $user, $errors, 6, 24, true);
    read_string($_POST, 'password_confirmation', $user, $errors, 6, 24, true);
    read_string($_POST, 'fullname', $user, $errors, 1, 80, true);
    read_list($_POST, 'gender', $user, $errors, array('M', 'F'), false);
    read_bool($_POST, 'newsletter', $user, $errors, '1', false, false);
    // пароль и подтверждение пароля должны совпадать
    if (!is_error($errors, 'password') && !is_error($errors, 'password_confirmation') && $user['password'] != $user['password_confirmation']) {
        $errors['fields'][] = 'password';
        add_error($errors, 'password_confirmation', 'dont-match');
    }
    if (has_errors($errors)) {
        return false;
    }
    // защищаем пароль пользователя
    $user['password'] = crypt($user['password']);
    unset($user['password_confirmation']);
    // форма передана правильно, сохраняем пользователя в базу данных
    $db_user = db_user_insert($dbh, $user);
    // автоматически логиним пользователя после регистрации, запоминая его в сессии
    store_current_user_id($db_user['id']);
    return true;
}