Example #1
0
 public function __construct()
 {
     parent::__construct();
     $id = Register::get('id');
     if (!empty($id)) {
         $user = new User($id);
         $user->setLastVisit();
         $user->writeData(true);
         $this->logout();
     }
     $this->logout();
 }
Example #2
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));
 }
Example #3
0
 private function finalize()
 {
     $user = new User(\Lib\Session::get('id'));
     $name = $user->getFirstName();
     $surname = $user->getSurname();
     $country = $user->getCountry();
     $zipcode = $user->getZipCode();
     $city = $user->getCity();
     $street = $user->getStreet();
     $house = $user->getHousNr();
     $appartment = $user->getAppartmentNr();
     $order_details = new Order_details();
     $order_details->setAddress('Imie: ' . $user->getFirstName() . ' Nazwisko: ' . $user->getSurname() . ' Kraj: ' . $user->getCountry() . ' Kod-Pocztowy: ' . $user->getZipCode() . ' Miasto: ' . $user->getCity() . ' Ulica : ' . $user->getStreet() . ' Nr domu: ' . $user->getHousNr() . ' Nr mieszkania: ' . $user->getAppartmentNr());
     $time = time();
     $id = \Lib\Session::get('id');
     $rand = rand(1, 100);
     $nr = $id . $time . $rand;
     $order_details->setOrderNr($nr);
     $order_details->setDisplaySeller(true);
     $order_details->setDisplayUser(true);
     $sm = $this->http->get('shipping_method');
     if (empty($sm)) {
         Location::To(URL . 'cart/show');
     }
     $order_details->setShippingMethodId($sm);
     $order_details->setDate();
     $order_details->setStatus(1);
     $cart = \Lib\Session::get('cart');
     if (!empty($cart)) {
         $db = Register::get('db');
         $db->query('START TRANSACTION');
         $id = $order_details->writeData();
         foreach ($cart as $product) {
             $order = new Order($product['order_id']);
             $order->setActive(1);
             $order->setOrderDetailsId($id);
             $order->writeData(true);
             if (!$order->writeData(true)) {
                 $db->query('ROLLBACK');
                 return false;
             }
         }
         if ($id) {
             $db->query('COMMIT');
         } else {
             $db->query('ROLLBACK');
             return false;
         }
         $mess = $this->http->get('message');
         if (!empty($mess)) {
             $mesage = new Message();
             $mesage->setUserId(\lib\Register::get('id'));
             $mesage->setReaded(false);
             $mesage->setSeller(false);
             $mesage->setMessage($order_details->getOrderNr() . ': ' . $this->http->get('message'));
             $mesage->setDate();
             $mesage->setDisplayUser(true);
             $mesage->setDisplaySeller(true);
             $mesage->writeData();
         }
         \Lib\Session::delete('cart');
         $this->ActNumberOfProducts();
         return true;
     }
 }
Example #4
0
 private function eraseUser()
 {
     $message_m = new \Models\Messages(\lib\Register::get('id'));
     $messages = $message_m->getMessages();
     if (!empty($messages)) {
         foreach ($messages as $message) {
             $message_m->deleteMessages($message->getId());
         }
     }
     $user_e = new \models\User(\lib\Register::get('id'));
     $user_e->delete();
     $user = new \models\Users(\lib\Register::get('id'));
     $user->delete();
     Location::To(URL . 'logout');
 }