Advertisement
Guest User

Untitled

a guest
Sep 17th, 2017
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.11 KB | None | 0 0
  1.     public function action_personal() {
  2.         $password = Text::random('distinct', mt_rand(6, 8));
  3.         $userdata = array(
  4.             'email'       => 'torname@yandex.ru',
  5.             'phone'       => '+79629397253',
  6.             'name'        => 'Иван Иванов',
  7.             'subscribed'  => '0',
  8.             'password'    => $password,
  9.         );
  10.         $user_id = Model::instance('user') -> add_user_from_order($userdata);
  11.        
  12.         $price = $this -> request -> param('price');
  13.         $price_config = Kohana::config('global.price');
  14.         if (!Valid::digit($price) || !Valid::range($price, $price_config[0], $price_config[1]))
  15.             $this -> request -> redirect(Route::url('steps', array('action' => NULL)));
  16.        
  17.         if (empty($this -> post['price']))
  18.             $this -> post['price'] = $price;
  19.        
  20.         if (HTTP_Request::POST == $this -> request -> method()) {
  21.             $post = $this -> post;
  22.            
  23.             $post
  24.                 -> label('token', 'Ключ запроса')
  25.                 -> rule('token', 'not_empty')
  26.                 -> rule('token', 'Security::check')
  27.                
  28.                 -> label('price', 'Цена подарка')
  29.                 -> rule('price', 'not_empty')
  30.                 -> rule('price', 'digit')
  31.                 -> rule('price', 'range', array(':value', $price_config[0], $price_config[1]))
  32.                
  33.                 -> label('email', 'Email')
  34.                 -> rule('email', 'not_empty')
  35.                 -> rule('email', 'email')
  36.                
  37.                 -> label('phone', 'Телефон')
  38.                 -> rule('phone', 'not_empty')
  39.                 -> rule('phone', 'max_length', array(':value', 32))
  40.                
  41.                 -> label('customer', 'Ваши фамилия и имя')
  42.                 -> rule('customer', 'not_empty')
  43.                 -> rule('customer', 'max_length', array(':value', 128))
  44.                
  45.                 -> label('lastname', 'Фамилия получателя')
  46.                 -> rule('lastname', 'not_empty')
  47.                 -> rule('lastname', 'max_length', array(':value', 64))
  48.                
  49.                 -> label('firstname', 'Имя получателя')
  50.                 -> rule('firstname', 'not_empty')
  51.                 -> rule('firstname', 'max_length', array(':value', 64))
  52.                
  53.                 -> label('index', 'Индекс')
  54.                 -> rule('index', 'not_empty')
  55.                 -> rule('index', 'digit')
  56.                 -> rule('index', 'exact_length', array(':value', 6))
  57.                
  58.                 -> label('region', 'Область, край, район')
  59.                 -> rule('region', 'not_empty')
  60.                 -> rule('region', 'max_length', array(':value', 64))
  61.                
  62.                 -> label('city', 'Населенный пункт')
  63.                 -> rule('city', 'not_empty')
  64.                 -> rule('city', 'max_length', array(':value', 64))
  65.                
  66.                 -> label('street', 'Улица')
  67.                 -> rule('street', 'not_empty')
  68.                 -> rule('street', 'max_length', array(':value', 255))
  69.                
  70.                 -> label('home', 'Номер дома')
  71.                 -> rule('home', 'not_empty')
  72.                 -> rule('home', 'max_length', array(':value', 16))
  73.                
  74.                 -> label('housing', 'Корпус')
  75.                 -> rule('housing', 'max_length', array(':value', 16))
  76.                
  77.                 -> label('apartament', 'Квартира')
  78.                 -> rule('apartament', 'not_empty')
  79.                 -> rule('apartament', 'max_length', array(':value', 8))
  80.                
  81.                 -> label('more', 'Дополнительная информация')
  82.                 -> rule('more', 'max_length', array(':value', 5000))
  83.                
  84.                 -> label('rule', 'Согласие с правилами оплаты и доставки')
  85.                 -> rule('rule', 'rule', array(':field', ':value', ':validation', '1'))
  86.                
  87.                 -> label('subscribed', 'Подписка на рассылку об акциях и новостях магазина')
  88.                 -> rule('subscribed', 'checkbox', array(':field', ':value', ':validation', '1'));
  89.            
  90.             if ($post -> check()) {
  91.                 $new_user = FALSE;
  92.                
  93.                 // Очищаем пришедшие данные
  94.                 foreach ((array)$post as $key => $value)
  95.                     $post[$key] = Common::enhtml($value);
  96.                
  97.                 $post['subscribed'] = !empty($post['subscribed']) && $post['subscribed'] == '1' ? '1' : '0';
  98.                 $post['name'] = $post['customer'];
  99.                
  100.                 $user_id = Model::instance('user') -> user_from_order($post);
  101.                 if (!$user_id) {
  102.                     $post['password'] = Text::random('distinct', mt_rand(6, 8));
  103.                     $user_id = Model::instance('user') -> add_user_from_order($post);
  104.                     if ($user_id)
  105.                         $new_user = TRUE;
  106.                 }
  107.                
  108.                 $post['user_id'] = $user_id;
  109.                 if ($order_id = Model::instance('order') -> new_order($post)) {
  110.                     // Отправляем письмо с данными покупки + ссылкой на страницу со статусом покупки
  111.                    
  112.                     // Редирект на страницу оплаты
  113.                    
  114.                 } else {
  115.                     $email = Kohana::config('global.email.support');
  116.                     $this -> errors['global'] = 'Ошибка сохранения заказа. Техники уже занимаются' . "<br />\n" .
  117.                         '<a href="mailto:' . $email . '">Напишите нам</a> '  .          
  118.                         'все данные заказа - мы обработаем его в ручном режиме и ответим Вам.';
  119.                 }
  120.             } else
  121.                 $this -> errors = $post -> errors();
  122.         }
  123.        
  124.         $this -> title = 'Заполнение данных для доставки';
  125.         $this -> robots = 'noindex,nofollow';
  126.        
  127.         $this -> content = View::factory('personal')
  128.             -> bind('min_price', $price_config[0])
  129.             -> bind('max_price', $price_config[1])
  130.             -> bind('price', $price);
  131.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement