public function sendMessage() { $encoded_values = Settings::where('key', 'chat')->first(); $decoded_values = json_decode($encoded_values->value); $v_data = ["thread_id" => Input::get('thread_id'), "user_id" => Input::get('user_id'), "message" => Input::get('message'), "attachment" => Input::hasFile('attachment') ? \Str::lower(Input::file('attachment')->getClientOriginalExtension()) : ""]; $v_rules = ["thread_id" => 'required', "user_id" => 'required', "message" => 'required', "attachment" => 'in:' . $decoded_values->chat_file_types]; $v = Validator::make($v_data, $v_rules); if ($v->passes() && Input::get("user_id") > 0 && Input::get("thread_id") > 0) { $thread_message = new ThreadMessages(); $thread_message->thread_id = Input::get('thread_id'); $thread_message->sender_id = Input::get('user_id'); $thread_message->message = Input::get('message'); $thread_message->save(); if (Input::hasFile('attachment') && Input::file('attachment')->getSize() <= $decoded_values->max_file_size * 1024 * 1024) { $ticket_attachment = new TicketAttachments(); $ticket_attachment->thread_id = Input::get('thread_id'); $ticket_attachment->message_id = $thread_message->id; $ticket_attachment->has_attachment = Input::hasFile('attachment'); $ticket_attachment->attachment_path = Input::hasFile('attachment') ? Utils::fileUpload(Input::file('attachment'), 'attachments') : ''; $ticket_attachment->save(); } return json_encode(["result" => 1]); } else { return json_encode(["result" => 0]); } }
public function update() { $v = Validator::make(["thread_id" => Input::get('thread_id'), "user_id" => Input::get('user_id'), "message" => Input::get('message'), "status" => Input::get('status'), 'attachment' => Input::get('attachment')], ["thread_id" => 'required', "user_id" => 'required', "message" => 'required', "status" => 'required', "attachment" => 'mimes:rar,zip|size:10000']); if ($v->passes()) { $ticket = Tickets::where('thread_id', Input::get('thread_id'))->first(); $ticket->thread_id = Input::get('thread_id'); $ticket->status = Input::get('status'); $ticket->save(); $thread_message = new ThreadMessages(); $thread_message->thread_id = Input::get('thread_id'); $thread_message->sender_id = Input::get('user_id'); $thread_message->message = Input::get('message'); $thread_message->save(); $ticket_attachment = new TicketAttachments(); $ticket_attachment->thread_id = Input::get('thread_id'); $ticket_attachment->message_id = $thread_message->id; $ticket_attachment->has_attachment = Input::hasFile('attachment'); $ticket_attachment->attachment_path = Input::hasFile('attachment') ? Utils::fileUpload(Input::file('attachment'), 'attachments') : ''; $ticket_attachment->save(); if (!Utils::isBackendUser(Input::get('user_id'))) { $country = DB::table('countries')->where('countryCode', Input::get('country'))->first(); $geo_info = ThreadGeoInfo::where('thread_id', Input::get('thread_id'))->first(); $geo_info->ip_address = Input::get('ip', $geo_info->ip_address); $geo_info->country_code = Input::get('country', $geo_info->country_code); $geo_info->country = !empty($country) ? $country->countryName : ""; $geo_info->provider = Input::get('provider'); $geo_info->current_page = ""; $geo_info->all_pages = ""; $geo_info->save(); } $customer = User::find($ticket->customer_id); $raw_settings = Settings::where('key', 'tickets')->pluck('value'); $decode_settings = json_decode($raw_settings); if ($decode_settings->should_send_email_ticket_reply) { if (!$customer->is_online) { $mailer_extra = ['ticket' => $ticket, 'has_attachment' => $ticket_attachment->has_attachment, 'attachment_path' => $ticket_attachment->attachment_path, 'operator_message' => $thread_message]; $this->ticketMailer->updated($customer->email, $customer->name, $mailer_extra); } } else { $mailer_extra = ['ticket' => $ticket, 'has_attachment' => $ticket_attachment->has_attachment, 'attachment_path' => $ticket_attachment->attachment_path, 'operator_message' => $thread_message]; $this->ticketMailer->updated($customer->email, $customer->name, $mailer_extra); } return json_encode(['result' => 1, 'errors' => trans('msgs.ticket_updated_success')]); } else { return json_encode(['result' => 0, 'errors' => \KodeInfo\Utilities\Utils::buildMessages($v->messages()->all())]); } }