Ejemplo n.º 1
0
 public function viewpost()
 {
     $f3 = \Base::instance();
     $this->_requireLogin();
     $user = $f3->get('user');
     $user_obj = $f3->get('user_obj');
     $user_org_links = $f3->get('user_org_links');
     $db = $f3->get('db.instance');
     $ticketId = $f3->get('PARAMS.id');
     $ticket = new Ticket();
     $ticket->load($ticketId);
     if ($ticket->loaded() and $ticket->memberId == $user['id']) {
         $text = $f3->get('POST.text');
         $text = $f3->clean($text);
         if (strlen($text) > 10) {
             // Add response and redirect
             $ticketmsg = new TicketMessage();
             $ticketmsg->ticketId = $ticket->id;
             $ticketmsg->text = $text;
             $ticketmsg->senderId = $user['id'];
             $ticketmsg->sendTime = date("Y-m-d H:i:s");
             $ticketmsg->save();
             // Set ticket to active if closed
             if ($ticket->status == 'closed') {
                 $ticket->status = 'active';
                 $ticket->save();
             }
             // Sending a mail to admins
             $admins = \Helpers\User::getUsersRankedHigherThen(1);
             $adminEmails = [];
             foreach ($admins as $admin) {
                 $adminEmails[] = $admin['email'];
             }
             $f3->set('ticket_id', $ticket->id);
             $f3->set('ticket_text', $text);
             $f3->set('ticket_priority', $ticket->priority);
             SendingAPI::send(['mailTo' => $adminEmails, 'mailSubject' => 'An answer has been made to a ticket', 'mailContents' => ['html' => \Template::instance()->render('mails/ticketAnswer.html'), 'text' => "An answer has been made to a ticket. \n\n" . "From: " . $user['name'] . "\n" . "Priority: " . $ticket->priority . "\n" . "URL: " . 'https://squarems.net/dashboard/admin/support/ticket/' . $ticket->id . "\n\n" . $text . "\n\n" . "You can unsubscribe in your user settings: 'Notifications'."]]);
             $f3->reroute($f3->get('PATH'));
         } else {
             new Notification('Text must be at least 10 characters long.', 'danger', true);
             $f3->reroute($f3->get('PATH') . '?content=' . urlencode($text));
         }
     } else {
         $f3->set('target', 'support/unauthorized.html');
     }
 }
Ejemplo n.º 2
0
 public function createpost()
 {
     $f3 = \Base::instance();
     $this->_requireLogin();
     $user = $f3->get('user');
     $user_obj = $f3->get('user_obj');
     $user_org_links = $f3->get('user_org_links');
     $db = $f3->get('db.instance');
     $name = $f3->get('POST.name');
     $priority = $f3->get('POST.priority');
     $text = $f3->get('POST.content');
     $errors = [];
     if (!empty($name)) {
         $name = $f3->clean($name);
         if (strlen($name) < 7) {
             $errors[] = 'Ticket name must be at least 8 characters long';
         }
     } else {
         $errors[] = 'Ticket name cannot be empty';
     }
     $priority = (int) $priority;
     if ($priority > 4 or $priority < 1) {
         $errors[] = 'Priority is 4 max, 1 min.';
     }
     if (!empty($text)) {
         $text = $f3->clean($text);
         if (strlen($text) < 30) {
             $errors[] = 'Ticket content must be at least 30 characters long.';
         }
     } else {
         $errors[] = 'Ticket text cannot be empty';
     }
     if (empty($errors)) {
         // No errors, create ticket
         // Ticket
         $ticket = new Ticket();
         $ticket->memberId = $user['id'];
         $ticket->status = 'active';
         $ticket->statusColor = 'red';
         $ticket->assignedUserId = 0;
         $ticket->title = $name;
         $ticket->create_time = date("Y-m-d H:i:s");
         $ticket->priority = $priority;
         $ticket->save();
         // First ticket message
         $ticketmsg = new TicketMessage();
         $ticketmsg->ticketId = $ticket->id;
         $ticketmsg->text = $text;
         $ticketmsg->senderId = $user['id'];
         $ticketmsg->sendTime = date("Y-m-d H:i:s");
         $ticketmsg->save();
         // Sending a mail to admins
         $admins = User::getUsersRankedHigherThen(1);
         $adminEmails = [];
         foreach ($admins as $admin) {
             $adminEmails[] = $admin['email'];
         }
         $f3->set('ticket_id', $ticket->id);
         $f3->set('ticket_text', $text);
         $f3->set('ticket_priority', $priority);
         SendingAPI::send(['mailTo' => $adminEmails, 'mailSubject' => 'New support ticket opened', 'mailContents' => ['html' => \Template::instance()->render('mails/newTicket.html'), 'text' => "A new ticket has just been opened. \n\n" . "From: " . $user['name'] . "\n" . "Priority: " . $priority . "\n" . "URL: " . 'https://squarems.net/dashboard/admin/support/ticket/' . $ticket->id . "\n\n" . $text . "\n\n" . "You can unsubscribe in your user settings: 'Notifications'."]]);
         // Redirect to ticket
         $f3->reroute('/support/ticket/' . $ticket->id);
     } else {
         // Show him his errors
         $f3->set('errors', $errors);
     }
     $f3->set('target', 'support/new.html');
     $this->_render('base.html');
 }