public function postAdd(MessageBindingModel $message)
 {
     $validator = $this->validateMessage(new Validation(), $message);
     if (!$validator->validate()) {
         Session::setError($validator->getErrors());
         Redirect::back();
     }
     $this->message->add($message->first_name, $message->last_name, $message->email, $message->phone, $message->content, $message->about, date("Y-m-d H:i:s"), false);
     Session::setMessage('Message is sent successfully');
     Redirect::to('');
 }
Esempio n. 2
0
 /**
  * Renders form for sending messages.
  * Sends message content to selected user.
  * If message is sent, user is notified.
  */
 public function action()
 {
     checkUnauthorizedAccess();
     $main = new Main();
     $body = new \templates\SendMessage();
     echo $main->setPageTitle("Send Message")->setBody($body);
     if (post('send')) {
         $senderID = UserRepository::getIdByUsername($_SESSION['username']);
         $recipientID = getIdFromURL();
         $content = htmlentities(trim(post('content')));
         //stvaranje poruke
         $message = new Message();
         $message->setSenderID($senderID);
         $message->setRecipientID($recipientID);
         $message->setContent($content);
         $message->setCreated(date('Y-m-d H:i:s'));
         try {
             //slanje poruke
             MessageRepository::sendMessage($message);
             ?>
             <script src="/TwitterApp/assets/js/messageSent.js"></script>
             <?php 
         } catch (\PDOException $e) {
             $e->getMessage();
         }
     }
 }
 public static function sendMessage(Message $message)
 {
     $db = Database::getInstance();
     $query = $db->prepare('INSERT INTO messages (senderid, recipientid, content, created) VALUES (?, ?, ?, ?)');
     $query->execute([$message->getSenderID(), $message->getRecipientID(), $message->getContent(), $message->getCreated()]);
 }
Esempio n. 4
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;
     }
 }
Esempio n. 5
0
 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.";
     }
 }
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function storeMessage($conversation)
 {
     $message = Message::create(['conversation_id' => $conversation, 'user_id' => $this->auth->user()->id, 'body' => $this->input->input('message')]);
     return Redirect::route('conversations.show', $conversation);
 }
Esempio n. 7
0
 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));
 }
Esempio n. 8
0
 public function POSTlogin($request)
 {
     $pin = $request->post('pin') ?: 0;
     $uid = $request->post('uid') ?: false;
     try {
         if ($uid && $pin) {
             // authenticate user based on password
             (new \models\instructor(\models\Data::ID($uid)))->authenticate($pin);
             \bloc\Application::instance()->session('COLUM', ['id' => $uid]);
             \bloc\router::redirect('/records/courses');
         } else {
             // user must be in database based on oasis id, find them: ;
             $user = \models\Data::ID(\models\Student::BLEAR($pin));
             // if found, generate token with sha1 of $email address and token
             $token = \bloc\types\token::generate($user['@email'], getenv('EMAIL_TOKEN'));
             // set the token on the user field
             if ($user->hasAttribute('token') && $user->getAttribute('token') === $token) {
                 throw new \InvalidArgumentException("Token Already Requested", 2);
             } else {
                 $user->setAttribute('token', $token);
                 \models\Data::instance()->storage->save();
                 // email the user a link.
                 $template = new \bloc\View('views/layouts/email.html');
                 $template->content = 'views/layouts/forms/transaction.html';
                 $output = ['link' => DOMAIN . "/records/token/{$user['@id']}/{$token}", 'title' => $user['@name'], 'message' => 'login to course site'];
                 \models\Message::TRANSACTION('login', $user['@email'], (string) $template->render($output));
             }
         }
     } catch (\InvalidArgumentException $e) {
         $type = $e->getCode() == 1 ? 'invalid' : 'duplicate';
         $path = sprintf('/%s/login/%s/', $this->template, $type);
         \bloc\router::redirect($path);
     }
     $view = new \bloc\View(self::layout);
     $view->content = 'views/layouts/forms/transaction.html';
     return $view->render(['link' => 'http://www.colum.edu/loopmail', 'title' => 'Email Sent', 'message' => 'check your email']);
 }
Esempio n. 9
0
 public function update($request)
 {
     $validate = $this->validate($request, $this->rules);
     if ($validate->errors() == 0 && Auth::get()) {
         $conversation = new Conversation();
         $conversation = $conversation->find((int) $request->id);
         if ($conversation) {
             if ($conversation->hasAccess()) {
                 $conversation->updated_at = date('Y-m-d H:i:s');
                 $conversation->update();
                 $message = new Message();
                 $message->conversation_id = $conversation->id;
                 $message->sender_id = Auth::get()->id;
                 $message->text = nl2br(htmlspecialchars($request->text));
                 $message->save();
                 $notification = new Notification();
                 $notification->text = 'Používateľ ' . Auth::get()->nick . ' vám poslal novú správu!';
                 $notification->user_id = $conversation->getUserId();
                 $notification->link = 'sprava/' . $conversation->id;
                 $notification->save();
                 return json_encode(['success' => 'Správa bola úspešne odoslaná!']);
             } else {
                 return json_encode(['errors' => ['Nemáte prístup!']]);
             }
         }
     } else {
         return json_encode(['errors' => $validate->getErrors()]);
     }
 }