public function sendMessage() { $http = new Http(); $to_user = $http->post('message_to_user'); $message = $http->post('message'); if (!empty($to_user) && !empty($message)) { $message_m = new Message(); $message_m->setUserId($to_user); $message_m->setSeller(true); $message_m->setMessage($message); $message_m->setReaded(false); $message_m->setDate(); $message_m->setDisplayUser(true); $message_m->setDisplaySeller(true); $message_m->writeData(); echo "Wiadomość została wysłana."; } else { echo "Wiadomość nie została wysłana."; } }
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; } }
public function message($arg = null) { $http = new Http(); if ($http->isActive('del')) { $message_m = new \Models\Messages(\lib\Register::get('id')); $to_delete = $http->post('delete'); if (!empty($to_delete) && is_array($to_delete)) { foreach ($to_delete as $nr) { $message_m->deleteMessages($nr); } } Location::To(URL . 'user/message'); } if ($http->isActive('send')) { $mesage = new Message(); $mesage->setUserId(\lib\Register::get('id')); $mesage->setReaded(false); $mesage->setSeller(false); $mesage->setMessage($http->post('message')); $mesage->setDate(); $mesage->setDisplayUser(true); $mesage->setDisplaySeller(true); $mesage->writeData(); Location::To(URL . 'user/message'); } $message_m = new \Models\Messages(\lib\Register::get('id')); $pag = new \lib\Pagination(10, $message_m->getNumberOfMessages()); $messages = $message_m->getMessages(10, $pag->page($arg[0])); $messages_array = array(); $next = $pag->next(); $prev = $pag->prev(); $num_pages = $pag->getPages(); $selected = $pag->getSelected(); if (!empty($messages)) { foreach ($messages as $key => $m) { if ($m->getDisplayUser()) { $messages_array[$key]['message'] = $m->getMessage(); $messages_array[$key]['date'] = $m->getDate(); $messages_array[$key]['seller'] = $m->getSeller(); $messages_array[$key]['readed'] = $m->getReaded(); $messages_array[$key]['id'] = $m->getId(); } } } $this->render('message', array('categories' => $this->categories, 'd_product' => $this->d_product, 'messages' => $messages_array, 'login' => \lib\Register::get('login'), 'ids' => $this->category_ids, 'next' => $next, 'prev' => $prev, 'num_pages' => $num_pages, 'selected' => $selected)); }