/**
  * Reademails
  * @return type
  */
 public function readmails(Emails $emails, Email $settings_email, System $system)
 {
     $path_url = $system->first()->url;
     if ($settings_email->first()->email_fetching == 1) {
         if ($settings_email->first()->all_emails == 1) {
             $helptopic = $this->TicketController->default_helptopic();
             $sla = $this->TicketController->default_sla();
             $email = $emails->get();
             foreach ($email as $e_mail) {
                 $dept = $e_mail->department;
                 $host = $e_mail->fetching_host;
                 $port = $e_mail->fetching_port;
                 $protocol = $e_mail->mailbox_protocol;
                 $imap_config = '{' . $host . ':' . $port . $protocol . '}INBOX';
                 $password = Crypt::decrypt($e_mail->password);
                 $mailbox = new ImapMailbox($imap_config, $e_mail->user_name, $password, __DIR__);
                 $mails = array();
                 $mailsIds = $mailbox->searchMailBox('SINCE ' . date('d-M-Y', strtotime("-1 day")));
                 if (!$mailsIds) {
                     die('Mailbox is empty');
                 }
                 // dd($mailsIds);
                 foreach ($mailsIds as $mailId) {
                     $overview = $mailbox->get_overview($mailId);
                     $var = $overview[0]->seen ? 'read' : 'unread';
                     if ($var == 'unread') {
                         $mail = $mailbox->getMail($mailId);
                         if ($settings_email->email_collaborator == 1) {
                             $collaborator = $mail->cc;
                         } else {
                             $collaborator = null;
                         }
                         $body = $mail->textHtml;
                         // dd($mailId);
                         if ($body == null) {
                             $body = $mailbox->backup_getmail($mailId);
                             $body = str_replace('\\r\\n', '<br/>', $body);
                             // var_dump($body);
                         }
                         // dd($body);
                         $date = $mail->date;
                         $datetime = $overview[0]->date;
                         $date_time = explode(" ", $datetime);
                         $date = $date_time[1] . "-" . $date_time[2] . "-" . $date_time[3] . " " . $date_time[4];
                         $date = date('Y-m-d H:i:s', strtotime($date));
                         if (isset($mail->subject)) {
                             $subject = $mail->subject;
                         } else {
                             $subject = "No Subject";
                         }
                         $fromname = $mail->fromName;
                         $fromaddress = $mail->fromAddress;
                         $source = "2";
                         $phone = "";
                         $priority = '1';
                         $assign = "";
                         $form_data = null;
                         if ($this->TicketController->create_user($fromaddress, $fromname, $subject, $body, $phone, $helptopic, $sla, $priority, $source, $collaborator, $dept, $assign, $form_data) == true) {
                             $thread_id = Ticket_Thread::whereRaw('id = (select max(`id`) from ticket_thread)')->first();
                             $thread_id = $thread_id->id;
                             foreach ($mail->getAttachments() as $attachment) {
                                 $support = "support";
                                 // echo $_SERVER['DOCUMENT_ROOT'];
                                 $dir_img_paths = __DIR__;
                                 $dir_img_path = explode('/code', $dir_img_paths);
                                 $filepath = explode('../../../../../../public/', $attachment->filePath);
                                 // dd($filepath);
                                 // $path = $dir_img_path[0]."/public/".$filepath[1];
                                 $path = public_path() . '/' . $filepath[1];
                                 // dd($path);
                                 $filesize = filesize($path);
                                 $file_data = file_get_contents($path);
                                 $ext = pathinfo($attachment->filePath, PATHINFO_EXTENSION);
                                 $imageid = $attachment->id;
                                 $string = str_replace('-', '', $attachment->name);
                                 $filename = explode('src', $attachment->filePath);
                                 $filename = str_replace('\\', '', $filename);
                                 $body = str_replace("cid:" . $imageid, $filepath[1], $body);
                                 $pos = strpos($body, $filepath[1]);
                                 if ($pos == false) {
                                     if ($settings_email->first()->attachment == 1) {
                                         $upload = new Ticket_attachments();
                                         $upload->file = $file_data;
                                         $upload->thread_id = $thread_id;
                                         $upload->name = $filepath[1];
                                         $upload->type = $ext;
                                         $upload->size = $filesize;
                                         $upload->poster = "ATTACHMENT";
                                         $upload->save();
                                     }
                                 } else {
                                     $upload = new Ticket_attachments();
                                     $upload->file = $file_data;
                                     $upload->thread_id = $thread_id;
                                     $upload->name = $filepath[1];
                                     $upload->type = $ext;
                                     $upload->size = $filesize;
                                     $upload->poster = "INLINE";
                                     $upload->save();
                                 }
                                 unlink($path);
                             }
                             $body = Encoding::fixUTF8($body);
                             $thread = Ticket_Thread::where('id', '=', $thread_id)->first();
                             $thread->body = $this->separate_reply($body);
                             $thread->save();
                         }
                     }
                 }
             }
         }
     }
 }
 /**
  * Display a listing of the resource.
  *
  * @return Response
  */
 public function get(System $note)
 {
     if (Config::get('database.install') == '%0%') {
         return Redirect::route('licence');
     }
     $notes = $note->get();
     foreach ($notes as $note) {
         $content = $note->content;
     }
     return view('themes.default1.client.guest-user.guest', compact('heading', 'content'));
 }
 /**
  * user time zone
  * @param type $utc 
  * @return type date
  */
 public static function usertimezone($utc)
 {
     $set = System::whereId('1')->first();
     $timezone = Timezones::whereId($set->time_zone)->first();
     $tz = $timezone->name;
     $format = $set->date_time_format;
     date_default_timezone_set($tz);
     $offset = date('Z', strtotime($utc));
     $format = Date_time_format::whereId($format)->first()->format;
     $date = date($format, strtotime($utc) + $offset);
     return $date;
 }
 /**
  * Post accountcheck
  * checking prerequisites
  * @param type InstallerRequest $request 
  * @return type view
  */
 public function accountcheck(InstallerRequest $request)
 {
     // migrate database
     Artisan::call('migrate', array('--force' => true));
     Artisan::call('db:seed', array('--force' => true));
     // create user
     $firstname = $request->input('firstname');
     $lastname = $request->input('Lastname');
     $email = $request->input('email');
     $username = $request->input('username');
     $password = $request->input('password');
     $language = $request->input('language');
     $timezone = $request->input('timezone');
     $date = $request->input('date');
     $datetime = $request->input('datetime');
     // $system = System::where('id','=','1')->first();
     // $system->time_zone = $timezone;
     // $system->date_time_format = $datetime;
     // $system->save();
     // checking requested timezone for the admin and system
     $timezones = Timezones::where('name', '=', $timezone)->first();
     if ($timezones->id == null) {
         return ['response' => 'fail', 'reason' => 'Invalid time-zone', 'status' => '0'];
     }
     // var_dump($datetime);
     // checking requested date time format for the admin and system
     $date_time_format = Date_time_format::where('format', '=', $datetime)->first();
     // dd($date_time_format);
     if ($date_time_format->id == null) {
         return ['response' => 'fail', 'reason' => 'invalid date-time format', 'status' => '0'];
     }
     // Creating minum settings for system
     $system = new System();
     $system->status = 1;
     $system->department = 1;
     $system->date_time_format = $date_time_format->id;
     $system->time_zone = $timezones->id;
     $system->save();
     // creating an user
     $user = User::create(array('first_name' => $firstname, 'last_name' => $lastname, 'email' => $email, 'user_name' => $username, 'password' => Hash::make($password), 'assign_group' => 1, 'primary_dpt' => 1, 'active' => 1, 'role' => 'admin'));
     // checking if the user have been created
     if ($user) {
         Session::put('step6', 'step6');
         return Redirect::route('final');
     }
 }
 /**
  * getform
  * @param type Help_topic $topic 
  * @return type
  */
 public function getForm(Help_topic $topic)
 {
     if (\Config::get('database.install') == '%0%') {
         return \Redirect::route('license');
     }
     if (System::first()->status == 1) {
         $topics = $topic->get();
         return view('themes.default1.client.helpdesk.form', compact('topics'));
     } else {
         return \Redirect::route('home');
     }
 }
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     /* Date time format */
     $date_time_formats = ['d/m/Y  H:i:s', 'd.m.Y  H:i:s', 'd-m-Y  H:i:s', 'm/d/Y  H:i:s', 'm.d.Y  H:i:s', 'm-d-Y  H:i:s', 'Y/m/d  H:i:s', 'Y.m.d  H:i:s', 'Y-m-d  H:i:s'];
     foreach ($date_time_formats as $date_time_format) {
         Date_time_format::create(['format' => $date_time_format]);
     }
     /* Date format */
     $date_formats = ['dd/mm/yyyy', 'dd-mm-yyyy', 'dd.mm.yyyy', 'mm/dd/yyyy', 'mm:dd:yyyy', 'mm-dd-yyyy', 'yyyy/mm/dd', 'yyyy.mm.dd', 'yyyy-mm-dd'];
     foreach ($date_formats as $date_format) {
         Date_format::create(['format' => $date_format]);
     }
     /* Time format */
     Time_format::create(array('format' => 'H:i:s'));
     Time_format::create(array('format' => 'H.i.s'));
     /* Timezone */
     $timezone = ['Pacific/Midway' => '(GMT-11:00) Midway Island', 'US/Samoa' => '(GMT-11:00) Samoa', 'US/Hawaii' => '(GMT-10:00) Hawaii', 'US/Alaska' => '(GMT-09:00) Alaska', 'US/Pacific' => '(GMT-08:00) Pacific Time (US &amp; Canada)', 'America/Tijuana' => '(GMT-08:00) Tijuana', 'US/Arizona' => '(GMT-07:00) Arizona', 'US/Mountain' => '(GMT-07:00) Mountain Time (US &amp; Canada)', 'America/Chihuahua' => '(GMT-07:00) Chihuahua', 'America/Mazatlan' => '(GMT-07:00) Mazatlan', 'America/Mexico_City' => '(GMT-06:00) Mexico City', 'America/Monterrey' => '(GMT-06:00) Monterrey', 'Canada/Saskatchewan' => '(GMT-06:00) Saskatchewan', 'US/Central' => '(GMT-06:00) Central Time (US &amp; Canada)', 'US/Eastern' => '(GMT-05:00) Eastern Time (US &amp; Canada)', 'US/East-Indiana' => '(GMT-05:00) Indiana (East)', 'America/Bogota' => '(GMT-05:00) Bogota', 'America/Lima' => '(GMT-05:00) Lima', 'America/Caracas' => '(GMT-04:30) Caracas', 'Canada/Atlantic' => '(GMT-04:00) Atlantic Time (Canada)', 'America/La_Paz' => '(GMT-04:00) La Paz', 'America/Santiago' => '(GMT-04:00) Santiago', 'Canada/Newfoundland' => '(GMT-03:30) Newfoundland', 'America/Buenos_Aires' => '(GMT-03:00) Buenos Aires', 'Greenland' => '(GMT-03:00) Greenland', 'Atlantic/Stanley' => '(GMT-02:00) Stanley', 'Atlantic/Azores' => '(GMT-01:00) Azores', 'Atlantic/Cape_Verde' => '(GMT-01:00) Cape Verde Is.', 'Africa/Casablanca' => '(GMT) Casablanca', 'Europe/Dublin' => '(GMT) Dublin', 'Europe/Lisbon' => '(GMT) Lisbon', 'Europe/London' => '(GMT) London', 'Africa/Monrovia' => '(GMT) Monrovia', 'Europe/Amsterdam' => '(GMT+01:00) Amsterdam', 'Europe/Belgrade' => '(GMT+01:00) Belgrade', 'Europe/Berlin' => '(GMT+01:00) Berlin', 'Europe/Bratislava' => '(GMT+01:00) Bratislava', 'Europe/Brussels' => '(GMT+01:00) Brussels', 'Europe/Budapest' => '(GMT+01:00) Budapest', 'Europe/Copenhagen' => '(GMT+01:00) Copenhagen', 'Europe/Ljubljana' => '(GMT+01:00) Ljubljana', 'Europe/Madrid' => '(GMT+01:00) Madrid', 'Europe/Paris' => '(GMT+01:00) Paris', 'Europe/Prague' => '(GMT+01:00) Prague', 'Europe/Rome' => '(GMT+01:00) Rome', 'Europe/Sarajevo' => '(GMT+01:00) Sarajevo', 'Europe/Skopje' => '(GMT+01:00) Skopje', 'Europe/Stockholm' => '(GMT+01:00) Stockholm', 'Europe/Vienna' => '(GMT+01:00) Vienna', 'Europe/Warsaw' => '(GMT+01:00) Warsaw', 'Europe/Zagreb' => '(GMT+01:00) Zagreb', 'Europe/Athens' => '(GMT+02:00) Athens', 'Europe/Bucharest' => '(GMT+02:00) Bucharest', 'Africa/Cairo' => '(GMT+02:00) Cairo', 'Africa/Harare' => '(GMT+02:00) Harare', 'Europe/Helsinki' => '(GMT+02:00) Helsinki', 'Europe/Istanbul' => '(GMT+02:00) Istanbul', 'Asia/Jerusalem' => '(GMT+02:00) Jerusalem', 'Europe/Kiev' => '(GMT+02:00) Kyiv', 'Europe/Minsk' => '(GMT+02:00) Minsk', 'Europe/Riga' => '(GMT+02:00) Riga', 'Europe/Sofia' => '(GMT+02:00) Sofia', 'Europe/Tallinn' => '(GMT+02:00) Tallinn', 'Europe/Vilnius' => '(GMT+02:00) Vilnius', 'Asia/Baghdad' => '(GMT+03:00) Baghdad', 'Asia/Kuwait' => '(GMT+03:00) Kuwait', 'Africa/Nairobi' => '(GMT+03:00) Nairobi', 'Asia/Riyadh' => '(GMT+03:00) Riyadh', 'Asia/Tehran' => '(GMT+03:30) Tehran', 'Europe/Moscow' => '(GMT+04:00) Moscow', 'Asia/Baku' => '(GMT+04:00) Baku', 'Europe/Volgograd' => '(GMT+04:00) Volgograd', 'Asia/Muscat' => '(GMT+04:00) Muscat', 'Asia/Tbilisi' => '(GMT+04:00) Tbilisi', 'Asia/Yerevan' => '(GMT+04:00) Yerevan', 'Asia/Kabul' => '(GMT+04:30) Kabul', 'Asia/Karachi' => '(GMT+05:00) Karachi', 'Asia/Tashkent' => '(GMT+05:00) Tashkent', 'Asia/Kolkata' => '(GMT+05:30) Kolkata', 'Asia/Kathmandu' => '(GMT+05:45) Kathmandu', 'Asia/Yekaterinburg' => '(GMT+06:00) Ekaterinburg', 'Asia/Almaty' => '(GMT+06:00) Almaty', 'Asia/Dhaka' => '(GMT+06:00) Dhaka', 'Asia/Novosibirsk' => '(GMT+07:00) Novosibirsk', 'Asia/Bangkok' => '(GMT+07:00) Bangkok', 'Asia/Ho_Chi_Minh' => '(GMT+07.00) Ho Chi Minh', 'Asia/Jakarta' => '(GMT+07:00) Jakarta', 'Asia/Krasnoyarsk' => '(GMT+08:00) Krasnoyarsk', 'Asia/Chongqing' => '(GMT+08:00) Chongqing', 'Asia/Hong_Kong' => '(GMT+08:00) Hong Kong', 'Asia/Kuala_Lumpur' => '(GMT+08:00) Kuala Lumpur', 'Australia/Perth' => '(GMT+08:00) Perth', 'Asia/Singapore' => '(GMT+08:00) Singapore', 'Asia/Taipei' => '(GMT+08:00) Taipei', 'Asia/Ulaanbaatar' => '(GMT+08:00) Ulaan Bataar', 'Asia/Urumqi' => '(GMT+08:00) Urumqi', 'Asia/Irkutsk' => '(GMT+09:00) Irkutsk', 'Asia/Seoul' => '(GMT+09:00) Seoul', 'Asia/Tokyo' => '(GMT+09:00) Tokyo', 'Australia/Adelaide' => '(GMT+09:30) Adelaide', 'Australia/Darwin' => '(GMT+09:30) Darwin', 'Asia/Yakutsk' => '(GMT+10:00) Yakutsk', 'Australia/Brisbane' => '(GMT+10:00) Brisbane', 'Australia/Canberra' => '(GMT+10:00) Canberra', 'Pacific/Guam' => '(GMT+10:00) Guam', 'Australia/Hobart' => '(GMT+10:00) Hobart', 'Australia/Melbourne' => '(GMT+10:00) Melbourne', 'Pacific/Port_Moresby' => '(GMT+10:00) Port Moresby', 'Australia/Sydney' => '(GMT+10:00) Sydney', 'Asia/Vladivostok' => '(GMT+11:00) Vladivostok', 'Asia/Magadan' => '(GMT+12:00) Magadan', 'Pacific/Auckland' => '(GMT+12:00) Auckland', 'Pacific/Fiji' => '(GMT+12:00) Fiji'];
     foreach ($timezone as $name => $location) {
         Timezones::create(array('name' => $name, 'location' => $location));
     }
     /* Ticket status */
     Ticket_status::create(array('name' => 'Open', 'state' => 'open', 'mode' => '3', 'message' => 'Ticket have been Reopened by', 'flags' => '0', 'sort' => '1', 'properties' => 'Open tickets.'));
     Ticket_status::create(array('name' => 'Resolved', 'state' => 'closed', 'mode' => '1', 'message' => 'Ticket have been Resolved by', 'flags' => '0', 'sort' => '2', 'properties' => 'Resolved tickets.'));
     Ticket_status::create(array('name' => 'Closed', 'state' => 'closed', 'mode' => '3', 'message' => 'Ticket have been Closed by', 'flags' => '0', 'sort' => '3', 'properties' => 'Closed tickets. Tickets will still be accessible on client and staff panels.'));
     Ticket_status::create(array('name' => 'Archived', 'state' => 'archived', 'mode' => '3', 'message' => 'Ticket have been Archived by', 'flags' => '0', 'sort' => '4', 'properties' => 'Tickets only adminstratively available but no longer accessible on ticket queues and client panel.'));
     Ticket_status::create(array('name' => 'Deleted', 'state' => 'deleted', 'mode' => '3', 'message' => 'Ticket have been Deleted by', 'flags' => '0', 'sort' => '5', 'properties' => 'Tickets queued for deletion. Not accessible on ticket queues.'));
     /* Ticket priority */
     Ticket_priority::create(array('priority' => 'low', 'priority_desc' => 'Low', 'priority_color' => 'info', 'priority_urgency' => '4', 'ispublic' => '1'));
     Ticket_priority::create(array('priority' => 'normal', 'priority_desc' => 'Normal', 'priority_color' => 'info', 'priority_urgency' => '3', 'ispublic' => '1'));
     Ticket_priority::create(array('priority' => 'high', 'priority_desc' => 'High', 'priority_color' => 'warning', 'priority_urgency' => '2', 'ispublic' => '1'));
     Ticket_priority::create(array('priority' => 'emergency', 'priority_desc' => 'Emergency', 'priority_color' => 'danger', 'priority_urgency' => '1', 'ispublic' => '1'));
     /* SLA Plans */
     Sla_plan::create(array('name' => 'Sla 1', 'grace_period' => '6 Hours', 'status' => '1'));
     Sla_plan::create(array('name' => 'Sla 2', 'grace_period' => '12 Hours', 'status' => '1'));
     Sla_plan::create(array('name' => 'Sla 3', 'grace_period' => '24 Hours', 'status' => '1'));
     /* Mailbox protocol */
     $mailbox = ['IMAP' => '/imap', 'IMAP+SSL' => '/imap/ssl', 'IMAP+TLS' => '/imap/tls', 'IMAP+SSL/No-validate' => '/imap/ssl/novalidate-cert'];
     foreach ($mailbox as $name => $value) {
         MailboxProtocol::create(['name' => $name, 'value' => $value]);
     }
     /* Languages */
     $languages = ['English' => 'en', 'Italian' => 'it', 'German' => 'de', 'French' => 'fr', 'Brazilian Portuguese' => 'pt_BR', 'Dutch' => 'nl', 'Spanish' => 'es', 'Norwegian' => 'nb_NO', 'Danish' => 'da'];
     foreach ($languages as $language => $locale) {
         Languages::create(['name' => $language, 'locale' => $locale]);
     }
     /* Teams */
     Teams::create(array('name' => 'Level 1 Support', 'status' => '1'));
     Teams::create(array('name' => 'Level 2 Support'));
     Teams::create(array('name' => 'Developer'));
     /* Groups */
     Groups::create(array('name' => 'Group A', 'group_status' => '1', 'can_create_ticket' => '1', 'can_edit_ticket' => '1', 'can_post_ticket' => '1', 'can_close_ticket' => '1', 'can_assign_ticket' => '1', 'can_transfer_ticket' => '1', 'can_delete_ticket' => '1', 'can_ban_email' => '1', 'can_manage_canned' => '1', 'can_view_agent_stats' => '1', 'department_access' => '1'));
     Groups::create(array('name' => 'Group B', 'group_status' => '1', 'can_create_ticket' => '1', 'can_edit_ticket' => '0', 'can_post_ticket' => '0', 'can_close_ticket' => '1', 'can_assign_ticket' => '1', 'can_transfer_ticket' => '1', 'can_delete_ticket' => '1', 'can_ban_email' => '1', 'can_manage_canned' => '1', 'can_view_agent_stats' => '1', 'department_access' => '1'));
     Groups::create(array('name' => 'Group C', 'group_status' => '1', 'can_create_ticket' => '0', 'can_edit_ticket' => '0', 'can_post_ticket' => '0', 'can_close_ticket' => '1', 'can_assign_ticket' => '0', 'can_transfer_ticket' => '0', 'can_delete_ticket' => '0', 'can_ban_email' => '0', 'can_manage_canned' => '0', 'can_view_agent_stats' => '0', 'department_access' => '0'));
     /* Department */
     Department::create(array('name' => 'Support', 'sla' => '1'));
     Department::create(array('name' => 'Sales', 'sla' => '1'));
     Department::create(array('name' => 'Operation', 'sla' => '1'));
     /* Helptopic */
     help_topic::create(array('topic' => 'Support query', 'department' => '1', 'ticket_status' => '1', 'priority' => '2', 'sla_plan' => '1', 'ticket_num_format' => '1', 'status' => '1', 'type' => '1', 'auto_response' => '0'));
     help_topic::create(array('topic' => 'Sales query', 'department' => '2', 'ticket_status' => '1', 'priority' => '2', 'sla_plan' => '1', 'ticket_num_format' => '1', 'status' => '0', 'type' => '1', 'auto_response' => '0'));
     help_topic::create(array('topic' => 'Operational query', 'department' => '3', 'ticket_status' => '1', 'priority' => '2', 'sla_plan' => '1', 'ticket_num_format' => '1', 'status' => '0', 'type' => '1', 'auto_response' => '0'));
     /* Daily notification log */
     Log_notification::create(['log' => 'NOT-1']);
     /* System complete settings */
     Alert::create(['id' => '1', 'ticket_status' => '1', 'ticket_admin_email' => '1', 'assignment_status' => '1', 'assignment_assigned_status' => '1', 'assignment_assigned_agent' => '1']);
     Company::create(array('id' => '1'));
     Email::create(array('id' => '1', 'email_fetching' => '1', 'notification_cron' => '1', 'all_emails' => '1', 'email_collaborator' => '1', 'attachment' => '1'));
     Responder::create(array('id' => '1', 'new_ticket' => '1', 'agent_new_ticket' => '1'));
     System::create(array('id' => '1', 'status' => '1', 'department' => '1', 'date_time_format' => '1', 'time_zone' => '32'));
     Ticket::create(array('num_format' => '#ABCD 1234 1234567', 'num_sequence' => '0', 'priority' => '1', 'sla' => '2', 'help_topic' => '1', 'status' => '1'));
     /* Ticket source */
     Ticket_source::create(array('name' => 'web', 'value' => 'Web'));
     Ticket_source::create(array('name' => 'email', 'value' => 'E-mail'));
     Ticket_source::create(array('name' => 'agent', 'value' => 'Agent Panel'));
     /* Mail configuration */
     Smtp::create(array('id' => '1'));
     /* Version check */
     Version_Check::create(['id' => '1']);
     /* System widgets */
     Widgets::create(['id' => '1', 'name' => 'footer1']);
     Widgets::create(['id' => '2', 'name' => 'footer2']);
     Widgets::create(['id' => '3', 'name' => 'footer3']);
     Widgets::create(['id' => '4', 'name' => 'footer4']);
     Widgets::create(['id' => '5', 'name' => 'side1']);
     Widgets::create(['id' => '6', 'name' => 'side2']);
     Widgets::create(['id' => '7', 'name' => 'linkedin']);
     Widgets::create(['id' => '8', 'name' => 'stumble']);
     Widgets::create(['id' => '9', 'name' => 'google']);
     Widgets::create(['id' => '10', 'name' => 'deviantart']);
     Widgets::create(['id' => '11', 'name' => 'flickr']);
     Widgets::create(['id' => '12', 'name' => 'skype']);
     Widgets::create(['id' => '13', 'name' => 'rss']);
     Widgets::create(['id' => '14', 'name' => 'twitter']);
     Widgets::create(['id' => '15', 'name' => 'facebook']);
     Widgets::create(['id' => '16', 'name' => 'youtube']);
     Widgets::create(['id' => '17', 'name' => 'vimeo']);
     Widgets::create(['id' => '18', 'name' => 'pinterest']);
     Widgets::create(['id' => '19', 'name' => 'dribbble']);
     Widgets::create(['id' => '20', 'name' => 'instagram']);
     /* Knowledge base setting */
     Settings::create(['id' => 'id', 'pagination' => '10']);
 }
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     Time_format::create(array('format' => 'H:i:s'));
     Time_format::create(array('format' => 'H.i.s'));
     $timezone = ['Pacific/Midway' => '(GMT-11:00) Midway Island', 'US/Samoa' => '(GMT-11:00) Samoa', 'US/Hawaii' => '(GMT-10:00) Hawaii', 'US/Alaska' => '(GMT-09:00) Alaska', 'US/Pacific' => '(GMT-08:00) Pacific Time (US &amp; Canada)', 'America/Tijuana' => '(GMT-08:00) Tijuana', 'US/Arizona' => '(GMT-07:00) Arizona', 'US/Mountain' => '(GMT-07:00) Mountain Time (US &amp; Canada)', 'America/Chihuahua' => '(GMT-07:00) Chihuahua', 'America/Mazatlan' => '(GMT-07:00) Mazatlan', 'America/Mexico_City' => '(GMT-06:00) Mexico City', 'America/Monterrey' => '(GMT-06:00) Monterrey', 'Canada/Saskatchewan' => '(GMT-06:00) Saskatchewan', 'US/Central' => '(GMT-06:00) Central Time (US &amp; Canada)', 'US/Eastern' => '(GMT-05:00) Eastern Time (US &amp; Canada)', 'US/East-Indiana' => '(GMT-05:00) Indiana (East)', 'America/Bogota' => '(GMT-05:00) Bogota', 'America/Lima' => '(GMT-05:00) Lima', 'America/Caracas' => '(GMT-04:30) Caracas', 'Canada/Atlantic' => '(GMT-04:00) Atlantic Time (Canada)', 'America/La_Paz' => '(GMT-04:00) La Paz', 'America/Santiago' => '(GMT-04:00) Santiago', 'Canada/Newfoundland' => '(GMT-03:30) Newfoundland', 'America/Buenos_Aires' => '(GMT-03:00) Buenos Aires', 'Greenland' => '(GMT-03:00) Greenland', 'Atlantic/Stanley' => '(GMT-02:00) Stanley', 'Atlantic/Azores' => '(GMT-01:00) Azores', 'Atlantic/Cape_Verde' => '(GMT-01:00) Cape Verde Is.', 'Africa/Casablanca' => '(GMT) Casablanca', 'Europe/Dublin' => '(GMT) Dublin', 'Europe/Lisbon' => '(GMT) Lisbon', 'Europe/London' => '(GMT) London', 'Africa/Monrovia' => '(GMT) Monrovia', 'Europe/Amsterdam' => '(GMT+01:00) Amsterdam', 'Europe/Belgrade' => '(GMT+01:00) Belgrade', 'Europe/Berlin' => '(GMT+01:00) Berlin', 'Europe/Bratislava' => '(GMT+01:00) Bratislava', 'Europe/Brussels' => '(GMT+01:00) Brussels', 'Europe/Budapest' => '(GMT+01:00) Budapest', 'Europe/Copenhagen' => '(GMT+01:00) Copenhagen', 'Europe/Ljubljana' => '(GMT+01:00) Ljubljana', 'Europe/Madrid' => '(GMT+01:00) Madrid', 'Europe/Paris' => '(GMT+01:00) Paris', 'Europe/Prague' => '(GMT+01:00) Prague', 'Europe/Rome' => '(GMT+01:00) Rome', 'Europe/Sarajevo' => '(GMT+01:00) Sarajevo', 'Europe/Skopje' => '(GMT+01:00) Skopje', 'Europe/Stockholm' => '(GMT+01:00) Stockholm', 'Europe/Vienna' => '(GMT+01:00) Vienna', 'Europe/Warsaw' => '(GMT+01:00) Warsaw', 'Europe/Zagreb' => '(GMT+01:00) Zagreb', 'Europe/Athens' => '(GMT+02:00) Athens', 'Europe/Bucharest' => '(GMT+02:00) Bucharest', 'Africa/Cairo' => '(GMT+02:00) Cairo', 'Africa/Harare' => '(GMT+02:00) Harare', 'Europe/Helsinki' => '(GMT+02:00) Helsinki', 'Europe/Istanbul' => '(GMT+02:00) Istanbul', 'Asia/Jerusalem' => '(GMT+02:00) Jerusalem', 'Europe/Kiev' => '(GMT+02:00) Kyiv', 'Europe/Minsk' => '(GMT+02:00) Minsk', 'Europe/Riga' => '(GMT+02:00) Riga', 'Europe/Sofia' => '(GMT+02:00) Sofia', 'Europe/Tallinn' => '(GMT+02:00) Tallinn', 'Europe/Vilnius' => '(GMT+02:00) Vilnius', 'Asia/Baghdad' => '(GMT+03:00) Baghdad', 'Asia/Kuwait' => '(GMT+03:00) Kuwait', 'Africa/Nairobi' => '(GMT+03:00) Nairobi', 'Asia/Riyadh' => '(GMT+03:00) Riyadh', 'Asia/Tehran' => '(GMT+03:30) Tehran', 'Europe/Moscow' => '(GMT+04:00) Moscow', 'Asia/Baku' => '(GMT+04:00) Baku', 'Europe/Volgograd' => '(GMT+04:00) Volgograd', 'Asia/Muscat' => '(GMT+04:00) Muscat', 'Asia/Tbilisi' => '(GMT+04:00) Tbilisi', 'Asia/Yerevan' => '(GMT+04:00) Yerevan', 'Asia/Kabul' => '(GMT+04:30) Kabul', 'Asia/Karachi' => '(GMT+05:00) Karachi', 'Asia/Tashkent' => '(GMT+05:00) Tashkent', 'Asia/Kolkata' => '(GMT+05:30) Kolkata', 'Asia/Kathmandu' => '(GMT+05:45) Kathmandu', 'Asia/Yekaterinburg' => '(GMT+06:00) Ekaterinburg', 'Asia/Almaty' => '(GMT+06:00) Almaty', 'Asia/Dhaka' => '(GMT+06:00) Dhaka', 'Asia/Novosibirsk' => '(GMT+07:00) Novosibirsk', 'Asia/Bangkok' => '(GMT+07:00) Bangkok', 'Asia/Ho_Chi_Minh' => '(GMT+07.00) Ho Chi Minh', 'Asia/Jakarta' => '(GMT+07:00) Jakarta', 'Asia/Krasnoyarsk' => '(GMT+08:00) Krasnoyarsk', 'Asia/Chongqing' => '(GMT+08:00) Chongqing', 'Asia/Hong_Kong' => '(GMT+08:00) Hong Kong', 'Asia/Kuala_Lumpur' => '(GMT+08:00) Kuala Lumpur', 'Australia/Perth' => '(GMT+08:00) Perth', 'Asia/Singapore' => '(GMT+08:00) Singapore', 'Asia/Taipei' => '(GMT+08:00) Taipei', 'Asia/Ulaanbaatar' => '(GMT+08:00) Ulaan Bataar', 'Asia/Urumqi' => '(GMT+08:00) Urumqi', 'Asia/Irkutsk' => '(GMT+09:00) Irkutsk', 'Asia/Seoul' => '(GMT+09:00) Seoul', 'Asia/Tokyo' => '(GMT+09:00) Tokyo', 'Australia/Adelaide' => '(GMT+09:30) Adelaide', 'Australia/Darwin' => '(GMT+09:30) Darwin', 'Asia/Yakutsk' => '(GMT+10:00) Yakutsk', 'Australia/Brisbane' => '(GMT+10:00) Brisbane', 'Australia/Canberra' => '(GMT+10:00) Canberra', 'Pacific/Guam' => '(GMT+10:00) Guam', 'Australia/Hobart' => '(GMT+10:00) Hobart', 'Australia/Melbourne' => '(GMT+10:00) Melbourne', 'Pacific/Port_Moresby' => '(GMT+10:00) Port Moresby', 'Australia/Sydney' => '(GMT+10:00) Sydney', 'Asia/Vladivostok' => '(GMT+11:00) Vladivostok', 'Asia/Magadan' => '(GMT+12:00) Magadan', 'Pacific/Auckland' => '(GMT+12:00) Auckland', 'Pacific/Fiji' => '(GMT+12:00) Fiji'];
     foreach ($timezone as $name => $location) {
         Timezones::create(array('name' => $name, 'location' => $location));
     }
     Ticket_status::create(array('name' => 'Open', 'state' => 'open', 'mode' => '3', 'message' => 'Ticket have been Reopened by', 'flags' => '0', 'sort' => '1', 'properties' => 'Open tickets.'));
     Ticket_status::create(array('name' => 'Resolved', 'state' => 'closed', 'mode' => '1', 'message' => 'Ticket have been Resolved by', 'flags' => '0', 'sort' => '2', 'properties' => 'Resolved tickets.'));
     Ticket_status::create(array('name' => 'Closed', 'state' => 'closed', 'mode' => '3', 'message' => 'Ticket have been Closed by', 'flags' => '0', 'sort' => '3', 'properties' => 'Closed tickets. Tickets will still be accessible on client and staff panels.'));
     Ticket_status::create(array('name' => 'Archived', 'state' => 'archived', 'mode' => '3', 'message' => 'Ticket have been Archived by', 'flags' => '0', 'sort' => '4', 'properties' => 'Tickets only adminstratively available but no longer accessible on ticket queues and client panel.'));
     Ticket_status::create(array('name' => 'Deleted', 'state' => 'deleted', 'mode' => '3', 'message' => 'Ticket have been Deleted by', 'flags' => '0', 'sort' => '5', 'properties' => 'Tickets queued for deletion. Not accessible on ticket queues.'));
     Ticket::create(array('num_format' => '#ABCD 1234 1234567', 'num_sequence' => '0', 'priority' => 'low', 'sla' => '12 Hours', 'help_topic' => 'support query'));
     Ticket_priority::create(array('priority' => 'low', 'priority_desc' => 'Low', 'priority_color' => 'info', 'priority_urgency' => '4', 'ispublic' => '1'));
     Ticket_priority::create(array('priority' => 'normal', 'priority_desc' => 'Normal', 'priority_color' => 'info', 'priority_urgency' => '3', 'ispublic' => '1'));
     Ticket_priority::create(array('priority' => 'high', 'priority_desc' => 'High', 'priority_color' => 'warning', 'priority_urgency' => '2', 'ispublic' => '1'));
     Ticket_priority::create(array('priority' => 'emergency', 'priority_desc' => 'Emergency', 'priority_color' => 'danger', 'priority_urgency' => '1', 'ispublic' => '1'));
     Sla_plan::create(array('name' => 'Sla 1', 'grace_period' => '6 Hours', 'status' => '1'));
     Sla_plan::create(array('name' => 'Sla 2', 'grace_period' => '12 Hours', 'status' => '1'));
     Sla_plan::create(array('name' => 'Sla 3', 'grace_period' => '24 Hours', 'status' => '1'));
     $mailbox = ['IMAP+SSl', 'IMAP', 'POP+SSL', 'POP'];
     foreach ($mailbox as $protocol) {
         MailboxProtocol::create(array('name' => $protocol));
     }
     $logs = ['WARN', 'DEBUG', 'ERROR'];
     foreach ($logs as $log) {
         Logs::create(['level' => $log]);
     }
     $languages = ['English' => 'en', 'Italian' => 'it', 'German' => 'de', 'French' => 'fr', 'Brazilian Portuguese' => 'pt_BR', 'Dutch' => 'nl', 'Spanish' => 'es', 'Norwegian' => 'nb_NO', 'Danish' => 'da'];
     foreach ($languages as $language => $locale) {
         Languages::create(['name' => $language, 'locale' => $locale]);
     }
     Guest_note::create(['heading' => 'Welcome to the Support Center', 'content' => 'Hello this is a new helpdesk support system ans it is in the development phase.']);
     Form_name::create(['name' => 'form', 'status' => '1', 'no_of_fields' => '5']);
     $date_time_formats = ['d/m/Y  H:i:s', 'd.m.Y  H:i:s', 'd-m-Y  H:i:s', 'm/d/Y  H:i:s', 'm.d.Y  H:i:s', 'm-d-Y  H:i:s', 'Y/m/d  H:i:s', 'Y.m.d  H:i:s', 'Y-m-d  H:i:s'];
     foreach ($date_time_formats as $date_time_format) {
         Date_time_format::create(['format' => $date_time_format]);
     }
     $date_formats = ['dd/mm/yyyy', 'dd-mm-yyyy', 'dd.mm.yyyy', 'mm/dd/yyyy', 'mm:dd:yyyy', 'mm-dd-yyyy', 'dd-mm-yyyy', 'yyyy/mm/dd', 'yyyy.mm.dd', 'yyyy-mm-dd'];
     foreach ($date_formats as $date_format) {
         Date_format::create(['format' => $date_format]);
     }
     Teams::create(array('name' => 'Level 1 Support'));
     Teams::create(array('name' => 'Level 2 Support'));
     Teams::create(array('name' => 'Developer'));
     Groups::create(array('name' => 'Group A', 'group_status' => '1', 'can_create_ticket' => '1', 'can_edit_ticket' => '1', 'can_post_ticket' => '1', 'can_close_ticket' => '1', 'can_assign_ticket' => '1', 'can_transfer_ticket' => '1', 'can_delete_ticket' => '1', 'can_ban_email' => '1', 'can_manage_canned' => '1', 'can_manage_faq' => '1', 'can_view_agent_stats' => '1', 'department_access' => '1'));
     Groups::create(array('name' => 'Group B', 'group_status' => '1', 'can_create_ticket' => '1', 'can_edit_ticket' => '0', 'can_post_ticket' => '0', 'can_close_ticket' => '1', 'can_assign_ticket' => '1', 'can_transfer_ticket' => '1', 'can_delete_ticket' => '1', 'can_ban_email' => '1', 'can_manage_canned' => '1', 'can_manage_faq' => '1', 'can_view_agent_stats' => '1', 'department_access' => '1'));
     Groups::create(array('name' => 'Group C', 'group_status' => '1', 'can_create_ticket' => '0', 'can_edit_ticket' => '0', 'can_post_ticket' => '0', 'can_close_ticket' => '1', 'can_assign_ticket' => '0', 'can_transfer_ticket' => '0', 'can_delete_ticket' => '0', 'can_ban_email' => '0', 'can_manage_canned' => '0', 'can_manage_faq' => '0', 'can_view_agent_stats' => '0', 'department_access' => '0'));
     Department::create(array('name' => 'Support'));
     Department::create(array('name' => 'Sales'));
     Department::create(array('name' => 'Operation'));
     // Access::create(array('password_expire' => '1 Months', 'reg_method' => 'disable'));
     // Access::create(array('password_expire' => '2 Months', 'reg_method' => 'private'));
     // Access::create(array('password_expire' => '6 Months', 'reg_method' => 'public'));
     // Company::create(array('company_name' => 'D company', 'website' => 'dcompany.org', 'phone' => '8606574126'));
     // Emails::create(array('email_address' => '*****@*****.**', 'email_name' => 'maintain', 'department' => 'maintanance', 'priority' => 'low', 'help_topic' => 'maintanance query', 'user_name' => 'maintanance'));
     help_topic::create(array('topic' => 'Support query', 'parent_topic' => 'Support query', 'custom_form' => '1', 'department' => '1', 'ticket_status' => '1', 'priority' => '2', 'sla_plan' => '1', 'ticket_num_format' => '1', 'status' => '1', 'type' => '1', 'auto_response' => '0'));
     help_topic::create(array('topic' => 'Sales query', 'parent_topic' => 'Sale query', 'custom_form' => '1', 'department' => '2', 'ticket_status' => '1', 'priority' => '2', 'sla_plan' => '1', 'ticket_num_format' => '1', 'status' => '1', 'type' => '1', 'auto_response' => '0'));
     help_topic::create(array('topic' => 'Operational query', 'parent_topic' => 'Operational query', 'custom_form' => '1', 'department' => '3', 'ticket_status' => '1', 'priority' => '2', 'sla_plan' => '1', 'ticket_num_format' => '1', 'status' => '1', 'type' => '1', 'auto_response' => '0'));
     Priority::create(array('name' => 'low'));
     Priority::create(array('name' => 'high'));
     Log_notification::create(['log' => 'NOT-1']);
     Access::create(array('id' => '1'));
     Alert::create(array('id' => '1'));
     Company::create(array('id' => '1'));
     Email::create(array('id' => '1'));
     Responder::create(array('id' => '1'));
     System::create(array('id' => '1'));
     Footer::create(array('id' => '1'));
     Footer2::create(array('id' => '1'));
     Footer3::create(array('id' => '1'));
     Footer4::create(array('id' => '1'));
     // Ticket::create(array('id' => '1'));
     Ticket_source::create(array('name' => 'web', 'value' => 'Web'));
     Ticket_source::create(array('name' => 'email', 'value' => 'E-mail'));
     Ticket_source::create(array('name' => 'agent', 'value' => 'Agent Panel'));
     Smtp::create(array('id' => '1'));
     Version_Check::create(['id' => '1']);
     $option = array('gmt_offset', 'date_format', 'time_format', 'date_time_format', 'sitename', 'sitedescription', 'admin_email', 'template', 'upload_url_path', 'timezone_string', 'siteurl', 'home', 'start_of_week', 'language', 'port', 'host', 'encryption', 'username', 'password', 'footer', 'uselogo', 'logo');
     foreach ($option as $name) {
         Options::create(array('option_name' => $name));
     }
     Social::create(['id' => '1']);
     Side1::create(['id' => '1']);
     Side2::create(['id' => '1']);
     Settings::create(['id' => 'id', 'paagination' => '10']);
 }
 /**
  * Post accountcheck
  * checking prerequisites
  * @param type InstallerRequest $request 
  * @return type view
  */
 public function accountcheck(InstallerRequest $request)
 {
     // dd($request);
     // config/database.php management
     $default = $request->input('default');
     $host = $request->input('host');
     $database = $request->input('databasename');
     $dbusername = $request->input('dbusername');
     $dbpassword = $request->input('dbpassword');
     // migrate database
     Artisan::call('migrate', array('--force' => true));
     Artisan::call('db:seed', array('--force' => true));
     // create user
     $firstname = $request->input('firstname');
     $lastname = $request->input('Lastname');
     $email = $request->input('email');
     $username = $request->input('username');
     $password = $request->input('password');
     $language = $request->input('language');
     $timezone = $request->input('timezone');
     $date = $request->input('date');
     $datetime = $request->input('datetime');
     $system = System::where('id', '=', '1')->first();
     $system->time_zone = $timezone;
     $system->date_time_format = $datetime;
     $system->save();
     $form1 = new Form_details();
     $form1->label = 'Name';
     $form1->type = 'text';
     $form1->form_name_id = '1';
     $form1->save();
     $form2 = new Form_details();
     $form2->label = 'Phone';
     $form2->type = 'number';
     $form2->form_name_id = '1';
     $form2->save();
     $form3 = new Form_details();
     $form3->label = 'Email';
     $form3->type = 'text';
     $form3->form_name_id = '1';
     $form3->save();
     $form4 = new Form_details();
     $form4->label = 'Subject';
     $form4->type = 'text';
     $form4->form_name_id = '1';
     $form4->save();
     $form5 = new Form_details();
     $form5->label = 'Details';
     $form5->type = 'textarea';
     $form5->form_name_id = '1';
     $form5->save();
     $user = User::create(array('first_name' => $firstname, 'last_name' => $lastname, 'email' => $email, 'user_name' => $username, 'password' => Hash::make($password), 'active' => 1, 'role' => 'admin', 'assign_group' => 'group A', 'primary_dpt' => 'support'));
     if ($user) {
         Session::put('step6', 'step6');
         return Redirect::route('final');
     }
 }
 /**
  * Update the specified resource in storage.
  * @param type int  $id
  * @param type System $system
  * @param type SystemRequest $request
  * @return type Response
  */
 public function postsystem($id, System $system, SystemRequest $request)
 {
     try {
         /* fetch the values of system request  */
         $systems = $system->whereId('1')->first();
         /* fill the values to coompany table */
         /* Check whether function success or not */
         if ($systems->fill($request->input())->save() == true) {
             /* redirect to Index page with Success Message */
             return redirect('getsystem')->with('success', 'System Updated Successfully');
         } else {
             /* redirect to Index page with Fails Message */
             return redirect('getsystem')->with('fails', 'System can not Updated');
         }
     } catch (Exception $e) {
         /* redirect to Index page with Fails Message */
         return redirect('getsystem')->with('fails', 'System can not Updated');
     }
 }
 /**
  * config_database
  * This function is to configure the database and install the application via API call.
  * @return type Json
  */
 public function config_system(Request $request)
 {
     // Check for pre install
     if (\Config::get('database.install') == '%0%') {
         $firstname = $request->firstname;
         $lastname = $request->lastname;
         $email = $request->email;
         $username = $request->username;
         $password = $request->password;
         $timezone = $request->timezone;
         $datetime = $request->datetime;
         // Migrate database
         Artisan::call('migrate', array('--force' => true));
         Artisan::call('db:seed', array('--force' => true));
         // var_dump($datetime);
         // $date_time_format = Date_time_format::where('format','=',$datetime)->first();
         // // dd($date_time_format->id);
         // if($date_time_format->id){
         // $date_time = 1;
         // } else {
         // 	return 'date time format not supported';
         // }
         // Creating minum settings
         $system = System::where('id', '=', '1')->first();
         $system->time_zone = 1;
         $system->date_time_format = 1;
         $system->save();
         // Creating user
         $user = User::create(array('first_name' => $firstname, 'last_name' => $lastname, 'email' => $email, 'user_name' => $username, 'password' => Hash::make($password), 'active' => 1, 'role' => 'admin', 'assign_group' => 1, 'primary_dpt' => 1));
         // Setting database installed status
         $value = '1';
         $install = app_path('../config/database.php');
         $datacontent = File::get($install);
         $datacontent = str_replace('%0%', $value, $datacontent);
         File::put($install, $datacontent);
         // Applying email configuration on route
         $smtpfilepath = "\\App\\Http\\Controllers\\Common\\SettingsController::smtp()";
         $path22 = app_path('Http/routes.php');
         $content23 = File::get($path22);
         $content23 = str_replace('"%smtplink%"', $smtpfilepath, $content23);
         File::put($path22, $content23);
         // If user created return success
         if ($user) {
             return ['response' => 'success', 'status' => '1'];
         }
     } else {
         return ['response' => 'fail', 'reason' => 'this system is already installed', 'status' => '0'];
     }
 }
 /**
  * config_database
  * This function is to configure the database and install the application via API call.
  * @return type Json
  */
 public function config_system(Request $request)
 {
     error_reporting(E_ALL & ~E_NOTICE);
     try {
         \DB::connection()->getDatabaseName();
         // check for database connection
         if (\DB::connection()->getDatabaseName()) {
             echo "Connected sucessfully to database " . \DB::connection()->getDatabaseName() . ".";
         }
         // Check for pre install
         if (\Config::get('database.install') == '%0%') {
             $firstname = $request->firstname;
             $lastname = $request->lastname;
             $email = $request->email;
             $username = $request->username;
             $password = $request->password;
             $timezone = $request->timezone;
             $datetime = $request->datetime;
             // Migrate database
             Artisan::call('migrate', array('--force' => true));
             Artisan::call('db:seed', array('--force' => true));
             // Creating minum settings
             $system = System::where('id', '=', '1')->first();
             $system->time_zone = $timezone;
             $system->date_time_format = $datetime;
             $system->save();
             // Creating default form field
             $form1 = new Form_details();
             $form1->label = 'Name';
             $form1->type = 'text';
             $form1->form_name_id = '1';
             $form1->save();
             $form2 = new Form_details();
             $form2->label = 'Phone';
             $form2->type = 'number';
             $form2->form_name_id = '1';
             $form2->save();
             $form3 = new Form_details();
             $form3->label = 'Email';
             $form3->type = 'text';
             $form3->form_name_id = '1';
             $form3->save();
             $form4 = new Form_details();
             $form4->label = 'Subject';
             $form4->type = 'text';
             $form4->form_name_id = '1';
             $form4->save();
             $form5 = new Form_details();
             $form5->label = 'Details';
             $form5->type = 'textarea';
             $form5->form_name_id = '1';
             $form5->save();
             // Creating user
             $user = User::create(array('first_name' => $firstname, 'last_name' => $lastname, 'email' => $email, 'user_name' => $username, 'password' => Hash::make($password), 'active' => 1, 'role' => 'admin', 'assign_group' => 'group A', 'primary_dpt' => 'support'));
             // Setting database installed status
             $value = '1';
             $install = app_path('../config/database.php');
             $datacontent = File::get($install);
             $datacontent = str_replace('%0%', $value, $datacontent);
             File::put($install, $datacontent);
             // Applying email configuration on route
             $smtpfilepath = "\\App\\Http\\Controllers\\Common\\SettingsController::smtp()";
             $path22 = app_path('Http/routes.php');
             $content23 = File::get($path22);
             $content23 = str_replace('"%smtplink%"', $smtpfilepath, $content23);
             File::put($path22, $content23);
             // If user created return success
             if ($user) {
                 return ['response' => 'success', 'status' => '1'];
             }
         } else {
             return ['response' => 'fail', 'reason' => 'this system is already installed', 'status' => '0'];
         }
     } catch (\Exception $e) {
         return $e->getMessage();
     }
 }
 /**
  * system
  * @return type
  */
 public function system()
 {
     try {
         $system = System::Where('id', '=', '1')->first();
         if ($system->name == null) {
             $system = "Support Center";
         } else {
             $system = $system->name;
         }
         return $system;
     } catch (\Exception $e) {
         return $e->getMessage();
     }
 }
 /**
  * Posted form
  * @param type Request $request
  * @param type User $user
  */
 public function postedForm(User $user, ClientRequest $request, Ticket $ticket_settings, Ticket_source $ticket_source)
 {
     $form_extras = $request->except('Name', 'Phone', 'Email', 'Subject', 'Details', 'helptopic', '_wysihtml5_mode', '_token');
     $name = $request->input('Name');
     $phone = $request->input('Phone');
     $email = $request->input('Email');
     $subject = $request->input('Subject');
     $details = $request->input('Details');
     $System = System::where('id', '=', 1)->first();
     $departments = Department::where('id', '=', $System->department)->first();
     $department = $departments->id;
     $status = $ticket_settings->first()->status;
     $helptopic = $ticket_settings->first()->help_topic;
     $sla = $ticket_settings->first()->sla;
     $priority = $ticket_settings->first()->priority;
     $source = $ticket_source->where('name', '=', 'web')->first();
     $collaborator = null;
     $assignto = null;
     if ($this->TicketController->create_user($email, $name, $subject, $details, $phone, $helptopic, $sla, $priority, $source->id, $collaborator, $department, $assignto, $form_extras)) {
         return Redirect::route('guest.getform')->with('success', 'Ticket Created Successfully');
     }
 }