permission()->check(['global', 'support-all', 'support-view', 'support-crud'])) { header('HTTP/1.1 401 Unauthorized'); exit; } $ticket = Support::o(c::getPagePiece(2)); if (!$ticket->id_support) { header('HTTP/1.0 404 Not Found'); exit; } if (get_class($ticket) != 'Crunchbutton_Support') { $ticket = $ticket->get(0); } if ($this->method() == 'get') { echo $ticket->json(); exit; } if (c::getPagePiece(3) == 'open-close' && $this->method() == 'post') { if( $ticket->status == Crunchbutton_Support::STATUS_OPEN ){ $ticket->status = Crunchbutton_Support::STATUS_CLOSED; $ticket->save(); $ticket->addSystemMessage( c::admin()->name . ' closed this ticket '); } else { $ticket->status = Crunchbutton_Support::STATUS_OPEN; $ticket->save(); $ticket->addSystemMessage( c::admin()->name . ' open this ticket '); } echo $ticket->json(); exit; } if (c::getPagePiece(3) == 'message' && $this->method() == 'post') { $note = $this->request()[ 'note' ]; if( $note ){ $message = $ticket->addNote($this->request()['body']); } else { $message = $ticket->addAdminReply($this->request()['body'], $this->request()['guid']); if ($message->id_support_message) { Message_Incoming_Support::notifyReps($message->admin()->firstName() . ' replied to #' . $message->id_support . ': ' . $message->body, $message->support()); } } if( $message ){ echo $message->json(); exit; } } header('HTTP/1.0 409 Conflict'); exit; } }