function main() { session_start(); // обрабатываем отправленную форму //Если передан гет запрос, то открыть запрашиваемую страницу, //иначе открыть категорию catgory_id=1 $dbh = db_connect(); if (is_current_user()) { $count_in_car = product_count_in_car($dbh); } else { $count_in_car = array(); } if (is_postbuy()) { if (is_current_user()) { $product = array('count' => 1, 'user_id' => $_SESSION['user_id'], 'product_id' => $_POST['buy_product_id']); db_product_incar_insert($dbh, $product); } else { redirect('login.php'); } } /*Если передан поисковой запрос и он не пустой, то находим товар по введенному поисковому запросу */ if (is_getfind()) { $items_result = db_product_find_like_title($dbh, $_GET['search_text']); $search_text = $_GET['search_text']; if ($items_result == null) { $items_result = 'products_not_found'; } } else { $items_result = null; $search_text = null; } $category_items = db_product_find_category_all($dbh); db_close($dbh); render('Find_Template', array('items' => $items_result, 'category' => $category_items, 'count_in_car' => $count_in_car, 'search_text' => $search_text)); }
function main() { // создаем сессию session_start(); if (is_current_user()) { // если пользователь уже залогинен, то отправляем его на глапную redirect('./'); } if (is_postback()) { // обрабатываем отправленную форму $dbh = db_connect(); $post_result = register_user($dbh, $user, $errors); db_close($dbh); if ($post_result) { // перенаправляем на главную redirect('./'); } else { // информация о пользователе заполнена неправильно, выведем страницу с ошибками render('register_form', array('form' => $_POST, 'errors' => $errors)); } } else { // отправляем пользователю чистую форму для регистрации render('register_form', array('form' => array(), 'errors' => array())); } }
function main() { session_start(); /* Если была выполнена отправка формы, то открыть запрашиваемую страницу, * иначе открыть главную страницу */ $dbh = db_connect(); if (is_postbuy()) { if (is_current_user()) { $product = array('count' => 1, 'user_id' => $_SESSION['user_id'], 'product_id' => $_POST['buy_product_id']); db_product_incar_insert($dbh, $product); } else { redirect('login.php'); } } if (is_postback() || is_postbuy()) { // обрабатываем отправленную форму if (is_current_user()) { $count_in_car = product_count_in_car($dbh); $car_items = db_get_product_in_car_by_user($dbh); /*Добавлен ли продукт в корзин пользователя? */ /* Если корзина пустая, то в массиве хранится значение Array ( [0] => Array ( [total] => 0 ) ), отсюда получается следующий оператор) исправлю потом */ if ($car_items[0]['total'] !== 0) { foreach ($car_items as $car_item) { $car_productid[] = $car_item[0]['id']; } } else { $car_productid[] = null; } } else { $count_in_car = array(); $car_productid[] = null; } /*Вывести на страницу товар id которго передан либо гетом(Когда нажали на ссылку товара из других страниц), либо постом(Когда товар купили) */ if (is_postback()) { $items_result = db_product_find_by_product_id($dbh, $_GET['product_id']); } elseif (is_postbuy()) { $items_result = db_product_find_by_product_id($dbh, $_POST['buy_product_id']); } $category_items = db_product_find_category_all($dbh); db_close($dbh); render('Product_Page_Template', array('items' => $items_result, 'category' => $category_items, 'count_in_car' => $count_in_car, 'car_productid' => $car_productid)); } else { redirect('index.php'); } }
function main() { session_start(); // обрабатываем отправленную форму //Если передан гет запрос, то открыть запрашиваемую страницу, //иначе открыть категорию catgory_id=1 $dbh = db_connect(); if (is_postbuy()) { if (is_current_user()) { $product = array('count' => 1, 'user_id' => $_SESSION['user_id'], 'product_id' => $_POST['buy_product_id']); db_product_incar_insert($dbh, $product); } else { redirect('login.php'); } } if (is_current_user()) { $count_in_car = product_count_in_car($dbh); $car_items = db_get_product_in_car_by_user($dbh); /*Добавлен ли продукт в корзин пользователя? */ /* Если корзина пустая, то в массиве хранится значение Array ( [0] => Array ( [total] => 0 ) ), отсюда получается следующий оператор) исправлю потом */ if ($car_items[0]['total'] !== 0) { foreach ($car_items as $car_item) { $car_productid[] = $car_item[0]['id']; } } else { $car_productid[] = null; } } else { $count_in_car = array(); $car_productid[] = null; } /* показать выбранную категорию*/ if (is_postback() || is_postbuy()) { if (is_postback()) { $items_result = db_product_find_by_category_id($dbh, $_GET['catgory_id']); } else { $items_result = db_product_find_by_category_id($dbh, $_POST['get_category_id']); $_GET['catgory_id'] = $_POST['get_category_id']; } } else { $items_result = db_product_find_by_category_id($dbh, 1); } $category_items = db_product_find_category_all($dbh); db_close($dbh); render('Category_Page_Template', array('items' => $items_result, 'category' => $category_items, 'count_in_car' => $count_in_car, 'car_productid' => $car_productid)); }
/** * Shows user profile */ public function profile($login = '') { if (empty($login)) { set_flash_error('Пустой ник пользователя, нам нечего вам показать'); redirect(); } // find user with this login $this->data['user'] = $this->user->where('login', $login)->find(NULL, 1); if (empty($this->data['user'])) { set_flash_error('У нас нет человека с таким ником, возможно вы ошиблись'); redirect(); } $this->load->library('form_validation'); if ($_POST) { $config = array(array('field' => 'email', 'label' => 'E-mail', 'rules' => 'required|max_length[128]|valid_email|trim')); $this->form_validation->set_rules($config); if ($this->form_validation->run($this) === FALSE) { $this->profile_form(); } else { if (!(is_current_user($this->data['user']) or user_is('admin'))) { show_error('Проблемы с доступом?', 500); return; } $new_user = array('id' => $this->data['user']['id'], 'email' => param('email'), 'new_password' => param('new_password')); if (!empty($_FILES['avatar']['name'])) { try { if (!empty($this->data['user']['avatar'])) { $this->user->delete_file('avatar', $this->data['user']['id']); } $this->user->upload('avatar')->resize_image(array('width' => $this->settings['avatar_width'], 'height' => $this->settings['avatar_height'], 'adaptive' => TRUE)); $new_user['avatar'] = $this->user->file_name; } catch (Exception $e) { set_flash_error($e->getMessage()); redirect_path('user/profile/' . $this->data['user']['login']); return; } } $this->user->save($new_user); set_flash_ok('Ваши изменения в профиле сохранены'); redirect('user/profile/' . $this->data['user']['login']); } } else { $this->profile_form(); } $this->draw(); }
function main() { // создаем сессию session_start(); if (!is_current_user()) { // отправляем пользователя на страницу входа в систему redirect('login.php'); } // у нас есть пользователь, считываем список пользователей из БД, и отображаем его // подключаемся к базе данных $dbh = db_connect(); // считываем список пользователей и текущего пользователя $user_list = db_user_find_all($dbh); $current_user = db_user_find_by_id($dbh, get_current_user_id()); // выводим результирующую страницу render('user_list', array('user_list' => $user_list, 'current_user' => $current_user)); // закрываем соединение с базой данных db_close($dbh); }
function main() { // создаем сессию session_start(); /************************************************************************** * Вывод "Популярное" на страницу и меню */ $dbh = db_connect(); if (is_postbuy()) { if (is_current_user()) { $product = array('count' => 1, 'user_id' => $_SESSION['user_id'], 'product_id' => $_POST['buy_product_id']); db_product_incar_insert($dbh, $product); } else { redirect('login.php'); } } $items_result = get_popular_products($dbh); $category_items = db_product_find_category_all($dbh); db_close($dbh); /************************************************************************** * Регистрация */ if (is_current_user()) { // если пользователь уже залогинен, то отправляем его на глапную redirect('./'); } if (is_postback()) { // обрабатываем отправленную форму $dbh = db_connect(); $post_result = register_user($dbh, $user, $errors); db_close($dbh); if ($post_result) { // перенаправляем на главную render('sucsess_register', array()); } else { // информация о пользователе заполнена неправильно, выведем страницу с ошибками render('register_form', array('form' => $_POST, 'errors' => $errors, 'items' => $items_result, 'category' => $category_items)); } } else { // отправляем пользователю чистую форму для регистрации render('register_form', array('form' => array(), 'errors' => array(), 'items' => $items_result, 'category' => $category_items)); } }
function main() { session_start(); // обрабатываем отправленную форму $dbh = db_connect(); if (is_postbuy()) { if (is_current_user()) { $product = array('count' => 1, 'user_id' => $_SESSION['user_id'], 'product_id' => $_POST['buy_product_id']); db_product_incar_insert($dbh, $product); } else { redirect('login.php'); } } if (isset($_POST['product_decrement'])) { if (is_current_user()) { $product = array('count' => 1, 'user_id' => $_SESSION['user_id'], 'product_id' => $_POST['product_decrement']); $result = db_product_incar_decrement($dbh, $product); if ($result == null || $result == array()) { } } else { redirect('login.php'); } } if (isset($_POST['product_delete'])) { if (is_current_user()) { $product = array('user_id' => $_SESSION['user_id'], 'product_id' => $_POST['product_delete']); db_product_incar_delete($dbh, $product); } else { redirect('login.php'); } } $count_in_car = product_count_in_car($dbh); $items_result = get_popular_products($dbh); $car_items = db_get_product_in_car_by_user($dbh); $res = db_car_find_by_user_id_and_product_id($dbh, $_SESSION['user_id'], 42); db_close($dbh); render('Car_Page_Template', array('items' => $items_result, 'car_items' => $car_items, 'count_in_car' => $count_in_car, 'res' => $res)); }
function main() { session_start(); // обрабатываем отправленную форму $dbh = db_connect(); if (is_postbuy()) { if (is_current_user()) { $product = array('count' => 1, 'user_id' => $_SESSION['user_id'], 'product_id' => $_POST['buy_product_id']); db_product_incar_insert($dbh, $product); } else { redirect('login.php'); } } if (is_current_user()) { $car_items = db_get_product_in_car_by_user($dbh); $count_in_car = product_count_in_car($dbh); /*Добавлен ли продукт в корзин пользователя? */ /* Если корзина пустая, то в массиве хранится значение Array ( [0] => Array ( [total] => 0 ) ), отсюда получается следующий оператор) исправлю потом */ if ($car_items[0]['total'] !== 0) { foreach ($car_items as $car_item) { $car_productid[] = $car_item[0]['id']; } } else { $car_productid[] = null; } } else { $count_in_car = array(); $car_productid[] = null; } //извлекаем массив популярных товаров $items_result = get_popular_products($dbh); $category_items = db_product_find_category_all($dbh); db_close($dbh); render('Main_Page_Template', array('items' => $items_result, 'category' => $category_items, 'post' => $_POST, 'count_in_car' => $count_in_car, 'car_productid' => $car_productid)); }
"> <div class="ToCar headCar">В корзину <?php if ($count_in_car && is_current_user()) { ?> <div class="count_in_car"><?php echo $count_in_car; ?> </div> <?php } ?> </div> </a> <?php if (is_current_user()) { ?> <div class="login_positioner"> Вы вошли в систему как: <br><div class="user"><?php echo $_SESSION['username']; ?> </div> <a href="logout.php"><div class="logout_button login_cell">Выход</div></a> </div> <?php } else { ?> <div class="login_positioner entry-positioner"> <a href="login.php"><div class="entry_button login_cell">Вход</div></a> <a href="register.php"><div class="registration_button login_cell">Регистрация</div></a> </div>
<input type="submit" value="Сохранить" class="button" /> </form> <script language="JavaScript" type="text/javascript"> $(document).ready(function() { $('#showcharacters').click(function() { if ($(this).attr('checked')) { $('#new_password').replaceWith('<input id="new_password" name="new_password" class="input" style="width:120px" type="text" value="' + $('#new_password').attr('value') + '" />'); } else { $('#new_password').replaceWith('<input id="new_password" name="new_password" class="input" style="width:120px" type="password" value="' + $('#new_password').attr('value') + '" />'); } }); }); </script> <?php } if (user_is('admin') and !is_current_user($user)) { if ($user['banned'] == 0) { ?> <br/><form method="POST" action="<?php echo site_url('user/ban'); ?> "> <input type="hidden" name="user_id" value="<?php echo form_prep($user['id']); ?> " /> <input type="submit" value="Забанить пользователя" class="button danger" /> </form> <?php } elseif ($user['banned'] == 1) { ?>
/** * @param $idnumber ccid of the user that we retrieve. */ function get_user($idnumber) { global $app, $USER, $cm; if (is_current_user($idnumber)) { if (!has_capability('mod/iclickerregistration:viewown', context_module::instance($cm->id))) { trigger_access_denied_event(); echo json_encode(array("status" => "access denied")); return; } $idnumber = $USER->idnumber; } else { if ($idnumber === "") { // The idnumber (aka ccid) is what identifies students in this institution. Thus, this case is ignored. echo "No idnumber provided."; return; } else { // Only admins can edit iclicker that is not their own. if (!has_capability('mod/iclickerregistration:viewenrolled', context_module::instance($cm->id))) { echo json_encode(array("status" => "access denied")); return; } } } try { echo json_encode(get_user_by_idnumber($idnumber)); } catch (Exception $e) { echo $e->getMessage(); return; } }
<div class="main-part"> <h1>Вы успешно зарегистрировались!</h1> <div class="category_name popular">Популярное</div> <div class="main-window"> <?php for ($i = 0; $i < 6; $i++) { ?> <a href="product.php"> <div class="item"> <div class="main-image"> <img alt="Notebook" src="Images/30023889m.jpg"> </div> <div class="product-name">15.6" Ноутбук Asus X553MA 90NB04X1-M25360 черный</div> <div class="Price">21990р.</div> <a href="<?php echo is_current_user() ? 'car.php' : 'login.php'; ?> "> <div class="ToCar">+Купить</div> </a> </div> </a> <?php } ?> </div> </div> </div> </div> <!-- Footer -->