public function previewPair($pair_id)
 {
     $paired = PairedTemplates::find($pair_id);
     $data = [];
     $template = $this->mailchimp->getTemplate($paired->template_id);
     $file_path = app_path() . "/views/emails/users/mailchimp_view.blade.php";
     \File::put($file_path, $template['preview']);
     $send_mail = Input::get('send_mail') == "true" ? true : false;
     if ($paired->view == "emails.users.activate") {
         $user_mailer = new \KodeInfo\Mailers\UsersMailer();
         $mailer_extra = User::getActivateFields(true);
         $data = $user_mailer->activate(Auth::user()->email, Auth::user()->name, $mailer_extra, true, $send_mail);
     }
     if ($paired->view == "emails.users.password_changed") {
         $user_mailer = new \KodeInfo\Mailers\UsersMailer();
         $mailer_extra = User::getPasswordChangedFields(true);
         $data = $user_mailer->password_changed(Auth::user()->email, Auth::user()->name, $mailer_extra, true, $send_mail);
     }
     if ($paired->view == "emails.users.reset_password") {
         $user_mailer = new \KodeInfo\Mailers\UsersMailer();
         $mailer_extra = User::getResetPasswordFields(true);
         $data = $user_mailer->reset_password(Auth::user()->email, Auth::user()->name, $mailer_extra, true, $send_mail);
     }
     if ($paired->view == "emails.users.welcome") {
         $user_mailer = new \KodeInfo\Mailers\UsersMailer();
         $mailer_extra = User::getWelcomeFields(true);
         $data = $user_mailer->welcome(Auth::user()->email, Auth::user()->name, $mailer_extra, true, $send_mail);
     }
     if ($paired->view == "emails.tickets.ticket_created") {
         $user_mailer = new \KodeInfo\Mailers\TicketsMailer();
         $mailer_extra = Tickets::getCreatedFields(true);
         $data = $user_mailer->created(Auth::user()->email, Auth::user()->name, $mailer_extra, true, $send_mail);
     }
     if ($paired->view == "emails.tickets.ticket_updated") {
         $user_mailer = new \KodeInfo\Mailers\TicketsMailer();
         $mailer_extra = Tickets::getUpdatedFields(true);
         $data = $user_mailer->updated(Auth::user()->email, Auth::user()->name, $mailer_extra, true, $send_mail);
     }
     if ($send_mail) {
         Session::flash('success_msg', trans('msgs.mail_sent_success'));
         return Redirect::to('/templates/pair/all');
     } else {
         return View::make('emails.users.mailchimp_view', $data);
     }
 }
 public function convertToTicket($thread_id, $msg_id, $user, $subject, $message, $department_id, $company_id)
 {
     $ticket = new Tickets();
     $ticket->thread_id = $thread_id;
     $ticket->customer_id = $user->id;
     $ticket->priority = Tickets::PRIORITY_MEDIUM;
     $ticket->company_id = $company_id;
     $ticket->department_id = $department_id;
     $ticket->subject = $subject;
     $ticket->description = $message;
     $ticket->status = Tickets::TICKET_NEW;
     $ticket->requested_on = \Carbon\Carbon::now();
     $ticket->save();
     $ticket_attachment = new TicketAttachments();
     $ticket_attachment->thread_id = $thread_id;
     $ticket_attachment->message_id = $msg_id;
     $ticket_attachment->has_attachment = Input::hasFile('attachment');
     $ticket_attachment->attachment_path = Input::hasFile('attachment') ? Utils::fileUpload(Input::file('attachment'), 'attachments') : '';
     $ticket_attachment->save();
     $customer = User::find($ticket->customer_id);
     $ticketMailer = new \KodeInfo\Mailers\TicketsMailer();
     $mailer_extra = Tickets::getCreatedFields(false, $ticket->id, $msg_id);
     $ticketMailer->created($customer->email, $customer->name, $mailer_extra);
 }