public function index()
 {
     $history = new History();
     $histories = $history->all();
     $customer = new Customer();
     $product = new Product();
     view('dashboard.index', compact('history', 'histories', 'product', 'customer'));
 }
 /**
  * Processing of the form
  *
  * @Privilege("create", "edit")
  *
  * @param \Nette\Application\UI\Form $form
  */
 public function historyFormSucceded(\Nette\Application\UI\Form $form)
 {
     $values = $form->getValues(TRUE);
     unset($values['send']);
     //handle file upload
     $file = $values['file'];
     unset($values['file']);
     $params = $this->context->parameters;
     $path = $params['wwwDir'] . $params['historyPhotosStorage'];
     if ($file->isOk()) {
         if ($file->isImage()) {
             //make sure the file will be JPEG
             $image = $file->toImage();
             $filename = '/' . $values['year'] . '.jpg';
             $image->save($path . $filename, 100, \Nette\Image::JPEG);
         }
     }
     $item = $this->histories->get($values['year']);
     if ($item) {
         //do an update
         $item->update($values);
         $this->flashMessage('Historie oddílu pro rok ' . $values['year'] . ' byla změněna.');
     } else {
         //do an insert
         $this->histories->insert($values);
         $this->flashMessage('Historie oddílu pro rok ' . $values['year'] . ' byla přidána.');
     }
     $this->redirect('default');
 }
예제 #3
0
 public function store()
 {
     if (empty($_SESSION)) {
         session_start();
     }
     empty($_SESSION['old']) ?: ($_SESSION['old'] = []);
     empty($_SESSION['error']) ?: ($_SESSION['error'] = []);
     $rules = ['email' => FILTER_VALIDATE_EMAIL, 'number' => ['filter' => FILTER_CALLBACK, 'options' => function ($nb) {
         if (preg_match('/[0-9]{16}/', $nb)) {
             return (int) $nb;
         }
         return false;
     }], 'address' => FILTER_SANITIZE_STRING];
     $sanitize = filter_input_array(INPUT_POST, $rules);
     var_dump($sanitize);
     $error = false;
     if (!$sanitize['email']) {
         $error = true;
         $_SESSION['error']['email'] = "Email Invalid";
     }
     if (!$sanitize['number']) {
         $error = true;
         $_SESSION['error']['number'] = "Blue Card number Invalid";
     }
     if (!$sanitize['address']) {
         $error = true;
         $_SESSION['error']['address'] = "You must give your address";
     }
     if ($error) {
         $_SESSION['old']['email'] = $sanitize['email'];
         $_SESSION['old']['address'] = $sanitize['address'];
         $this->redirect(url('cart'));
     }
     try {
         \Connect::$pdo->beginTransaction();
         $history = new History();
         $customer = new Customer();
         $customer->create(['email' => $sanitize['email'], 'number' => $sanitize['number'], 'addess' => $sanitize['address']]);
         $customerId = \Connect::$pdo->LastInsertID;
         $storage = $this->cart->all();
         $products = [];
         foreach ($storage as $id => $total) {
             $p = new Product();
             $stmt = $p->find($id);
             $history->create(['product_id' => $id, 'price' => (double) $stmt->price, 'total' => $total, 'quantity' => $total / $stmt->price, 'commandet_at' => date('Y-m-d h:i:s')]);
             $this->cart->reset();
             $this->redirect(url());
         }
         \Connect::$pdo->commit();
     } catch (\PDOException $e) {
         \Connect::$pdo->rollback();
     }
 }
예제 #4
0
 public function store()
 {
     $this->validToken('_token');
     if (empty($_SESSION)) {
         session_start();
     }
     empty($_SESSION['old']) ?: ($_SESSION['old'] = []);
     empty($_SESSION['error']) ?: ($_SESSION['error'] = []);
     $rules = ['email' => FILTER_VALIDATE_EMAIL, 'number' => ['filter' => FILTER_CALLBACK, 'options' => function ($nb) {
         if (iconv_strlen($nb) == 16 && (int) $nb != 0) {
             return (int) $nb;
         }
         return false;
     }], 'address' => FILTER_SANITIZE_STRING];
     $sanitize = filter_input_array(INPUT_POST, $rules);
     $error = false;
     $_SESSION['old']['email'] = $sanitize['email'];
     $_SESSION['old']['address'] = $sanitize['address'];
     if (!$sanitize['email']) {
         $_SESSION['error']['email'] = 'your email is invalid';
         $error = true;
     }
     if (!$sanitize['number']) {
         $_SESSION['error']['number'] = 'your number blue card is invalid';
         $error = true;
     }
     if (!$sanitize['address']) {
         $_SESSION['error']['address'] = 'you must given your address';
         $error = true;
     }
     if ($error) {
         $_SESSION['flashMessage'] = 'there was a problem';
         $this->redirect(url('cart'));
     }
     try {
         \Connect::$pdo->beginTransaction();
         $history = new History();
         $customer = new Customer();
         if ($c = $customer->where('number_card', '=', (string) $sanitize['number'])->get()->fetch()) {
             $customer->update($c->id, ['number_command' => 'number_command+1']);
             $customerId = $c->id;
         } else {
             $customer->create(['email' => $sanitize['email'], 'number_card' => $sanitize['number'], 'address' => $sanitize['address'], 'number_command' => 1]);
             $customerId = \Connect::$pdo->lastInsertId();
         }
         $products = $this->storage();
         foreach ($products as $name => $p) {
             $p['commanded_at'] = date('Y-m-d h:i:s');
             $p['customer_id'] = $customerId;
             $history->create($p);
         }
         \Connect::$pdo->commit();
         $_SESSION['flashMessage'] = 'thank you for your purchase, the team of Star Wars';
         $this->cart->reset();
         $this->redirect(url());
     } catch (\PDOException $e) {
         \Connect::$pdo->rollBack();
         $_SESSION['flashMessage'] = 'there has been a problem for your order, so sorry';
         $this->redirect(url('cart'));
     }
 }
예제 #5
0
 public function dashboard()
 {
     $history = new History();
     $histories = $history->getHistories();
     view('front.dashboard', compact('histories'));
 }
 /**
  * Sets variables for view of "Historie oddílu" page
  */
 public function renderHistory()
 {
     $template = $this->template;
     $template->title = "Historie oddílu";
     $this->template->histories = $this->histories->getOrderedHistories();
 }
 public function store()
 {
     if (!checked_token($_POST['_token'])) {
         $this->redirect(url('cart'));
     }
     //if(empty($_SESSION)) session_start();
     if (!empty($_SESSION['old'])) {
         $_SESSION['old'] = [];
     }
     if (!empty($_SESSION['error'])) {
         $_SESSION['error'] = [];
     }
     $rules = ['email' => FILTER_VALIDATE_EMAIL, 'number' => ['filter' => FILTER_CALLBACK, 'options' => function ($nb) {
         if (preg_match('/[0-9]{16}/', $nb)) {
             return $nb;
         }
         return false;
     }], 'adresse' => FILTER_SANITIZE_STRING];
     $sanitize = filter_input_array(INPUT_POST, $rules);
     //var_dump($sanitize);
     $error = false;
     if (!$sanitize['email']) {
         $error = true;
         $_SESSION['error']['email'] = 'your email is invalid';
     }
     if (!$sanitize['number']) {
         $error = true;
         $_SESSION['error']['number'] = 'your blue card number is invalid';
     }
     if (!empty($sanitize['adresse'])) {
         $error = true;
         $_SESSION['error']['adresse'] = 'you must give your address';
     }
     if ($error) {
         $_SESSION['old']['email'] = $sanitize['email'];
         $_SESSION['old']['adresse'] = $sanitize['adresse'];
         $this->redirect(url('cart'));
     }
     //transactionnelle PDO
     try {
         \Connect::$pdo->beginTransaction();
         $history = new History();
         $customer = new Customer();
         $customer->create(['email' => $sanitize['email'], 'number' => $sanitize['number'], 'adresse' => $sanitize['adresse']]);
         $customer_id = \Connect::$pdo->lastInsertId();
         $storage = $this->cart->all();
         foreach ($storage as $id => $total) {
             $p = new Product();
             // product du Model pas du Cart
             $stmt = $p->find($id);
             $history->create(['product_id' => $id, 'customer_id' => $customer_id, 'price' => (double) $stmt->price, 'total' => $total, 'quantity' => $total / $stmt->price, 'commanded_at' => date('Y-m-d h:i:s')]);
         }
         \Connect::$pdo->commit();
         $this->cart->reset();
         $this->redirect(url());
     } catch (\PDOException $e) {
         \Connect::$pdo->rollBack();
     }
 }