Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function action_personal() {
- $password = Text::random('distinct', mt_rand(6, 8));
- $userdata = array(
- 'email' => 'torname@yandex.ru',
- 'phone' => '+79629397253',
- 'name' => 'Иван Иванов',
- 'subscribed' => '0',
- 'password' => $password,
- );
- $user_id = Model::instance('user') -> add_user_from_order($userdata);
- $price = $this -> request -> param('price');
- $price_config = Kohana::config('global.price');
- if (!Valid::digit($price) || !Valid::range($price, $price_config[0], $price_config[1]))
- $this -> request -> redirect(Route::url('steps', array('action' => NULL)));
- if (empty($this -> post['price']))
- $this -> post['price'] = $price;
- if (HTTP_Request::POST == $this -> request -> method()) {
- $post = $this -> post;
- $post
- -> label('token', 'Ключ запроса')
- -> rule('token', 'not_empty')
- -> rule('token', 'Security::check')
- -> label('price', 'Цена подарка')
- -> rule('price', 'not_empty')
- -> rule('price', 'digit')
- -> rule('price', 'range', array(':value', $price_config[0], $price_config[1]))
- -> label('email', 'Email')
- -> rule('email', 'not_empty')
- -> rule('email', 'email')
- -> label('phone', 'Телефон')
- -> rule('phone', 'not_empty')
- -> rule('phone', 'max_length', array(':value', 32))
- -> label('customer', 'Ваши фамилия и имя')
- -> rule('customer', 'not_empty')
- -> rule('customer', 'max_length', array(':value', 128))
- -> label('lastname', 'Фамилия получателя')
- -> rule('lastname', 'not_empty')
- -> rule('lastname', 'max_length', array(':value', 64))
- -> label('firstname', 'Имя получателя')
- -> rule('firstname', 'not_empty')
- -> rule('firstname', 'max_length', array(':value', 64))
- -> label('index', 'Индекс')
- -> rule('index', 'not_empty')
- -> rule('index', 'digit')
- -> rule('index', 'exact_length', array(':value', 6))
- -> label('region', 'Область, край, район')
- -> rule('region', 'not_empty')
- -> rule('region', 'max_length', array(':value', 64))
- -> label('city', 'Населенный пункт')
- -> rule('city', 'not_empty')
- -> rule('city', 'max_length', array(':value', 64))
- -> label('street', 'Улица')
- -> rule('street', 'not_empty')
- -> rule('street', 'max_length', array(':value', 255))
- -> label('home', 'Номер дома')
- -> rule('home', 'not_empty')
- -> rule('home', 'max_length', array(':value', 16))
- -> label('housing', 'Корпус')
- -> rule('housing', 'max_length', array(':value', 16))
- -> label('apartament', 'Квартира')
- -> rule('apartament', 'not_empty')
- -> rule('apartament', 'max_length', array(':value', 8))
- -> label('more', 'Дополнительная информация')
- -> rule('more', 'max_length', array(':value', 5000))
- -> label('rule', 'Согласие с правилами оплаты и доставки')
- -> rule('rule', 'rule', array(':field', ':value', ':validation', '1'))
- -> label('subscribed', 'Подписка на рассылку об акциях и новостях магазина')
- -> rule('subscribed', 'checkbox', array(':field', ':value', ':validation', '1'));
- if ($post -> check()) {
- $new_user = FALSE;
- // Очищаем пришедшие данные
- foreach ((array)$post as $key => $value)
- $post[$key] = Common::enhtml($value);
- $post['subscribed'] = !empty($post['subscribed']) && $post['subscribed'] == '1' ? '1' : '0';
- $post['name'] = $post['customer'];
- $user_id = Model::instance('user') -> user_from_order($post);
- if (!$user_id) {
- $post['password'] = Text::random('distinct', mt_rand(6, 8));
- $user_id = Model::instance('user') -> add_user_from_order($post);
- if ($user_id)
- $new_user = TRUE;
- }
- $post['user_id'] = $user_id;
- if ($order_id = Model::instance('order') -> new_order($post)) {
- // Отправляем письмо с данными покупки + ссылкой на страницу со статусом покупки
- // Редирект на страницу оплаты
- } else {
- $email = Kohana::config('global.email.support');
- $this -> errors['global'] = 'Ошибка сохранения заказа. Техники уже занимаются' . "<br />\n" .
- '<a href="mailto:' . $email . '">Напишите нам</a> ' .
- 'все данные заказа - мы обработаем его в ручном режиме и ответим Вам.';
- }
- } else
- $this -> errors = $post -> errors();
- }
- $this -> title = 'Заполнение данных для доставки';
- $this -> robots = 'noindex,nofollow';
- $this -> content = View::factory('personal')
- -> bind('min_price', $price_config[0])
- -> bind('max_price', $price_config[1])
- -> bind('price', $price);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement