Exemple #1
0
 public function nr($id = null)
 {
     $is_loged = LoginVal::isLogged();
     $http = new Http();
     $this->product_m = new \models\Product($id[0]);
     $name = $this->product_m->getName();
     if (empty($name)) {
         Location::To(URL . 'error');
     }
     $available = $this->product_m->getQuantity();
     $promotions = new Promotions($id[0]);
     $pro = $promotions->getPromotion();
     if (!empty($pro)) {
         $old_price = $this->product_m->getOldPrice($pro->getPercent());
         $discount = $pro->getPercent() * 100;
     }
     $additionals = $this->product_m->getAdditionals();
     $a_images = $this->product_m->getAdditionalImages();
     $comments_m = new Comments($id[0]);
     $pagination = new Pagination(2, $comments_m->getNumberOfComments());
     $avg_rating = $comments_m->getAverageRating();
     $comments = $comments_m->getComments(2, $pagination->page($id[1]));
     $next = $pagination->next();
     $prev = $pagination->prev();
     $num_pages = $pagination->getPages();
     $selected = $pagination->getSelected();
     $comment = $http->post('comment');
     if (!empty($comment) && $is_loged && $http->isActive('send') && !empty($this->product_m)) {
         $comment = new Comment();
         $comment->setComment($http->post('comment'));
         $comment->setDate();
         $comment->setProductId($this->product_m->getId());
         $comment->setUserId(Register::get('id'));
         $comment->setRate($http->post('star'));
         $comment->writeData();
         Location::To(URL . 'product/nr/' . $id[0]);
     }
     $comment_tab = array();
     if (!empty($comments)) {
         foreach ($comments as $key => $comment) {
             if (!empty($comment)) {
                 $comment_tab[$key]['comment'] = $comment->getComment();
                 $comment_tab[$key]['date'] = $comment->getDate();
                 $comment_tab[$key]['rate'] = $comment->getRate();
                 $user = new \models\Users($comment->getUserId());
                 $login = $user->getLogin();
                 $comment_tab[$key]['login'] = empty($login) ? 'anonimowy' : $login;
             }
         }
     }
     $this->render('product', array('categories' => $this->categories, 'd_product' => $this->d_product, 'category' => $this->product_m->getCategory(), 'name' => $this->product_m->getName(), 'description' => $this->product_m->getDescription(), 'image' => $this->product_m->getImage(), 'quantity' => $this->product_m->getQuantity(), 'price' => $this->product_m->getPrice(), 'additionals' => $additionals, 'images' => $a_images, 'comments' => $comment_tab, 'product_nr' => $id[0], 'next' => $next, 'prev' => $prev, 'num_pages' => $num_pages, 'selected' => $selected, 'is_loged' => $is_loged, 'avg_rating' => $avg_rating, 'discount' => $discount, 'old_price' => $old_price, 'available' => $available));
 }
    public function __construct()
    {
        if (\Lib\LoginVal::isLogged()) {
            Location::To(URL . 'user');
        }
        parent::__construct();
        $http = new Http();
        $this->categories_m = new \models\Categories();
        $this->categories = $this->categories_m->getCategories();
        $this->products_m = new \models\Products();
        $this->d_product = $this->products_m->getDayProduct();
        $this->category_ids = $this->categories_m->getCategoriesIds();
        if (!$http->isActive('login')) {
            $this->render('register', array('categories' => $this->categories, 'd_product' => $this->d_product, 'ids' => $this->category_ids));
        } else {
            $passVal = new \lib\PassVal("Nieprawidłowe hasło", "Hasła nie są takie same.", 5, 15);
            $validator = new Validator(array('login' => new \lib\LoginVal("Podana nazwa użytkownika jest zajęta.", "Nieprawidłowa nazaw użytkownika.", 5, 15), 'email' => new \lib\EmailVal("Nieprawidłowy email."), 'password' => $passVal, 'password_2' => $passVal, 'accept' => new \lib\CheckBoxVal("Nie zaznaczono pola z akceptacją regulaminu.")));
            if ($validator->validate($http->post())) {
                $this->register($http->post());
                $user = new \models\User($this->id);
                $date = $user->getRegistrationDate();
                $subject = 'Aktywacja Konta';
                $message = 'W celu aktywowania Konta kliknij 
						<a href="' . URL . 'activation/activate?id=' . $this->id . '&register=' . $date . '">Tutaj</a>';
                $altmessage = 'W celu aktywacji konta odwiedź podany adres:' . URL . 'activation/activate?id=' . $id . '&register=' . $date;
                $email = new Email();
                if ($email->send($http->post('email'), $subject, $message, $altmessage)) {
                    Location::To(URL . 'success/success/Sprawdź email w celu aktywacji konta.');
                } else {
                    Location::To(URL . 'error');
                }
            } else {
                $this->errors = $validator->getErrors();
                $this->render('register', array('categories' => $this->categories, 'd_product' => $this->d_product, 'ids' => $this->category_ids, 'errors' => $this->errors));
            }
        }
    }
Exemple #3
0
 public function purchuase()
 {
     if (LoginVal::isLogged()) {
         $this->confirm();
     } else {
         \Lib\Session::set('intended', URL . 'cart/purchuase');
         Location::To(URL . 'login');
     }
 }