<?php defined('BASEPATH') OR exit('No direct script access allowed');

/* ----------------------------------------------------------------------------
 * Easy!Appointments - Open Source Web Scheduler
 *
 * @package     EasyAppointments
 * @author      A.Tselegidis <alextselegidis@gmail.com>
 * @copyright   Copyright (c) 2013 - 2018, Alex Tselegidis
 * @license     http://opensource.org/licenses/GPL-3.0 - GPLv3
 * @link        http://easyappointments.org
 * @since       v1.1.0
 * ---------------------------------------------------------------------------- */

/**
 * Installation Controller
 *
 * This controller will handle the installation procedure of Easy!Appointments
 *
 * @package Controllers
 */
class Installation extends CI_Controller {
    /**
     * Class Constructor
     */
    public function __construct()
    {
        parent::__construct();
        $this->load->helper('installation');
        $this->load->library('session');

        // Set user's selected language.
        if ($this->session->userdata('language'))
        {
            $this->config->set_item('language', $this->session->userdata('language'));
            $this->lang->load('translations', $this->session->userdata('language'));
        }
        else
        {
            $this->lang->load('translations', $this->config->item('language')); // default
        }
    }

    /**
     * Display the installation page.
     */
    public function index()
    {
        if (is_ea_installed())
        {
            redirect('appointments/index');
            return;
        }

        $this->load->view('general/installation', [
            'base_url' => $this->config->item('base_url')
        ]);
    }

    /**
     * [AJAX] Installs Easy!Appointments on the server.
     *
     * Required POST Parameters
     *
     * - array $_POST['admin'] Contains the initial admin user data. The App needs at least one admin user to work.
     * - array $_POST['company'] Contains the basic company data.
     */
    public function ajax_install()
    {
        try
        {
            if (is_ea_installed())
            {
                return;
            }

            // Create E!A database structure.
            $file_contents = file_get_contents(dirname(BASEPATH) . '/assets/sql/structure.sql');
            $sql_queries = explode(';', $file_contents);
            array_pop($sql_queries);
            foreach ($sql_queries as $query)
            {
                $this->db->query($query);
            }

            // Insert default E!A entries into the database.
            $file_contents = file_get_contents(dirname(BASEPATH) . '/assets/sql/data.sql');
            $sql_queries = explode(';', $file_contents);
            array_pop($sql_queries);
            foreach ($sql_queries as $query)
            {
                $this->db->query($query);
            }
require(dirname(BASEPATH) . "/application/language/english/translations_lang.php");
$filename = dirname(BASEPATH) . "/application/language/english/translations_lang.php";
$millie ="<?php"." ".

"millie['page_title']  =". "'". $lang['page_title']."'".';'." ".
"millie['step_one_title'] =". "'".$lang['step_one_title']."'".';'." ".
"millie['select_service'] =". "'".$lang['select_service']."'".';'." ".
"millie['select_provider'] ="."'".$lang['select_provider']."'".';'." ".
"millie['duration'] =". "'".$lang['duration']."'".';'." ".
"millie['minutes'] =". "'".$lang['minutes']."'".';'." ".
"millie['price'] ="."'".$lang['price']."'".';'." ".
"millie['back'] =". "'".$lang['back']."'".';'." ".
"millie['step_two_title'] ="."'".$lang['step_two_title']."'".';'." ".
"millie['no_available_hours'] =". "'".$lang['no_available_hours']."'".';'." ".
"millie['appointment_hour_missing'] =" . "'".$lang['appointment_hour_missing']."'".';'." ".
"millie['step_three_title'] =". "'".$lang['step_three_title']."'".';'." ".
"millie['first_name'] =". "'".'First Name*'."'".';'." ".
"millie['first_name_required'] =". "'".'required form-control'."'".';'." ".
"millie['first_name_onoff'] =". "'".'on'."'".';'." ".
"millie['last_name'] ="."'".'Last Name*'."'".';'." ".
"millie['last_name_required'] ="."'".'required form-control'."'".';'." ".
"millie['last_name_onoff'] ="."'".'on'."'".';'." ".
"millie['birth_date'] ="."'".'Birthdate*'."'".';'." ".
"millie['birth_date_required'] ="."'".'required form-control'."'".';'." ".
"millie['birth_date_onoff'] ="."'".'on'."'".';'." ".
"millie['email'] ="."'".'Email'."'".';'." ". 
"millie['email_required'] ="."'".'form-control'."'".';'." ". 
"millie['email_onoff'] ="."'".'on'."'".';'." ". 
"millie['phone_number'] ="."'".'Phone Number'."'".';'." ".
"millie['phone_number_required'] ="."'".'form-control'."'".';'." ".
"millie['phone_number_onoff'] ="."'".'on'."'".';'." ".
"millie['address'] ="."'".'Address'."'".';'." ".
"millie['address_required'] ="."'".'form-control'."'".';'." ".
"millie['address_onoff'] ="."'".'on'."'".';'." ".
"millie['city'] =" ."'".'City'."'".';'." ".
"millie['city_required'] =" ."'".'form-control'."'".';'." ".
"millie['city_onoff'] =" ."'".'on'."'".';'." ".
"millie['zip_code'] = "."'".'Postal Code'."'".';'." ".
"millie['zip_code_required'] = "."'".'form-control'."'".';'." ".
"millie['zip_code_onoff'] = "."'".'on'."'".';'." ".
"millie['notes'] =" ."'".'Notes'."'".';'." ".
"millie['notes_required'] =" ."'".'form-control'."'".';'." ".
"millie['notes_onoff'] =" ."'".'off'."'".';'." ".
"millie['fields_are_required'] =" ."'".$lang['fields_are_required']."'".';'." ".
"millie['step_four_title'] =" ."'".$lang['step_four_title']."'".';'." ".
"millie['confirm'] =" ."'".$lang['confirm']."'".';'." ".
"millie['update'] =" ."'".$lang['update']."'".';'." ".
"millie['cancel_appointment_hint'] =" ."'".$lang['cancel_appointment_hint']."'".';'." ".
"millie['cancel'] =" ."'".$lang['cancel']."'".';'." ".
"millie['appointment_registered'] =" ."'".$lang['appointment_registered']."'".';'." ".
"millie['cancel_appointment_title'] =" ."'".$lang['cancel_appointment_title']."'".';'." ".
"millie['appointment_cancelled'] ="."'".$lang['appointment_cancelled']."'".';'." ".
"millie['appointment_cancelled_title'] ="."'".'Appointment Cancelled'."'".";".
"millie['reason'] =" ."'".$lang['reason']."'".';'." ".
"millie['appointment_removed_from_schedule'] ="."'".'The following appointment was removed from the companys schedule.'."'".";".
"millie['appointment_details_was_sent_to_you'] =" ."'".$lang['appointment_details_was_sent_to_you']."'".';'." ".
"millie['add_to_google_calendar'] ="."'".$lang['add_to_google_calendar']."'".';'." ".
"millie['appointment_booked'] ="."'".'Your appointment has been successfully booked!'."'".";".
"millie['thank_you_for_appointment'] ="."'".'Thank you for arranging an appointment with us. Below you can see the appointment details. Make changes by clicking the appointment link.'."'".";".
"millie['appointment_details_title'] ="."'".$lang['appointment_details_title']."'".';'." ".
"millie['customer_details_title'] =" ."'".$lang['customer_details_title']."'".';'." ".
"millie['service'] =" ."'".$lang['service']."'".';'." ".
"millie['provider'] =" ."'".$lang['provider']."'".';'." ".
"millie['customer'] =" ."'".$lang['customer']."'".';'." ".
"millie['start'] =" ."'".$lang['start']."'".';'." ".
"millie['end'] ="."'".$lang['end']."'".';'." ".
"millie['name'] =" ."'".$lang['name']."'".';'." ".
"millie['phone'] =" ."'".$lang['phone']."'".';'." ".
"millie['address'] =" ."'".$lang['address']."'".';'." ".
"millie['appointment_link_title'] =" ."'".$lang['appointment_link_title']."'".';'." ".
"millie['success'] =" ."'".$lang['success']."'".';'." ".
"millie['appointment_added_to_google_calendar'] =" ."'".$lang['appointment_added_to_google_calendar']."'".';'." ".
"millie['view_appointment_in_google_calendar'] =" ."'".$lang['view_appointment_in_google_calendar']."'".';'." ".
"millie['appointment_added_to_your_plan'] ="."'". 'A new appointment has been added to your plan.'."'".";".
"millie['appointment_link_description'] =". "'".$lang['appointment_link_description']."'".';'." ".
"millie['appointment_not_found'] =" ."'".$lang['appointment_not_found']."'".';'." ".
"millie['appointment_does_not_exist_in_db'] =" ."'".$lang['appointment_does_not_exist_in_db']."'".';'." ".
"millie['display_calendar'] =" ."'".$lang['display_calendar']."'".';'." ".
"millie['calendar'] =" ."'".$lang['calendar']."'".';'." ".
"millie['users'] =". "'".$lang['users']."'".';'." ".
"millie['settings'] =". "'".$lang['settings']."'".';'." ". 
"millie['log_out'] =".  "'".$lang['log_out']."'".';'." ".
"millie['synchronize'] =". "'".$lang['synchronize']."'".';'." ". 
"millie['enable_sync'] =".  "'".$lang['enable_sync']."'".';'." ".
"millie['disable_sync'] =". "'".$lang['disable_sync']."'".';'." ". 
"millie['reload'] =".  "'".$lang['reload']."'".';'." ".
"millie['appointment'] =". "'".$lang['appointment']."'".';'." ".
"millie['unavailable'] =".  "'".$lang['unavailable']."'".';'." ".
"millie['week'] =". "'".$lang['week']."'".';'." ". 
"millie['month'] =".  "'".$lang['month']."'".';'." ".
"millie['today'] =". "'".$lang['today']."'".';'." ". 
"millie['not_working'] =".  "'".$lang['not_working']."'".';'." ".
"millie['break'] =". "'".$lang['break']."'".';'." ". 
"millie['add'] =".  "'".$lang['add']."'".';'." ".
"millie['edit'] =". "'".$lang['edit']."'".';'." ". 
"millie['hello'] =".  "'".$lang['hello']."'".';'." ".
"millie['all_day'] =". "'".$lang['all_day']."'".';'." ". 
"millie['manage_appointment_record_hint'] =".  "'".$lang['manage_appointment_record_hint']."'".';'." ".
"millie['select_filter_item_hint'] =". "'".$lang['select_filter_item_hint']."'".';'." ". 
"millie['enable_appointment_sync_hint'] =".  "'".$lang['enable_appointment_sync_hint']."'".';'." ".
"millie['manage_customers_hint'] ="."'".$lang['manage_customers_hint']."'".';'." ". 
"millie['manage_services_hint'] =".  "'".$lang['manage_services_hint']."'".';'." ".
"millie['manage_users_hint'] =". "'".$lang['manage_users_hint']."'".';'." ". 
"millie['settings_hint'] =".  "'".$lang['settings_hint']."'".';'." ".
"millie['log_out_hint'] =". "'".$lang['log_out_hint']."'".';'." ". 
"millie['unavailable_periods_hint'] =".  "'".$lang['unavailable_periods_hint']."'".';'." ".
"millie['new_appointment_hint'] =". "'".$lang['new_appointment_hint']."'".';'." ". 
"millie['reload_appointments_hint'] =".  "'".$lang['reload_appointments_hint']."'".';'." ".
"millie['trigger_google_sync_hint'] =". "'".$lang['trigger_google_sync_hint']."'".';'." ". 
"millie['appointment_updated'] =".  "'".$lang['appointment_updated']."'".';'." ".
"millie['undo'] =". "'".$lang['undo']."'".';'." ".
"millie['appointment_details_changed'] ="."'".$lang['appointment_details_changed']."'".";".
"millie['appointment_changes_saved'] =". "'".'Appointment changes have been successfully saved!'."'".";".
"millie['save'] =".  "'".$lang['save']."'".';'." ".
"millie['new'] =". "'".$lang['new']."'".';'." ". 
"millie['select'] =".  "'".$lang['select']."'".';'." ".
"millie['hide'] =". "'".$lang['hide']."'".';'." ". 
"millie['type_to_filter_customers'] =".  "'".$lang['type_to_filter_customers']."'".';'." ".
"millie['clear_fields_add_existing_customer_hint'] =". "'".$lang['clear_fields_add_existing_customer_hint']."'".';'." ". 
"millie['pick_existing_customer_hint'] =".  "'".$lang['pick_existing_customer_hint']."'".';'." ".
"millie['new_appointment_title'] =". "'".$lang['new_appointment_title']."'".';'." ". 
"millie['edit_appointment_title'] =".  "'".$lang['edit_appointment_title']."'".';'." ".
"millie['delete_appointment_title'] =". "'".$lang['delete_appointment_title']."'".';'." ". 
"millie['write_appointment_removal_reason'] =".  "'".$lang['write_appointment_removal_reason']."'".';'." ".
"millie['appointment_saved'] =". "'".$lang['appointment_saved']."'".';'." ".
"millie['new_unavailable_title'] =".  "'".$lang['new_unavailable_title']."'".';'." ".
"millie['edit_unavailable_title'] =". "'".$lang['edit_unavailable_title']."'".';'." ". 
"millie['unavailable_saved'] =".  "'".$lang['unavailable_saved']."'".';'." ".
"millie['start_date_before_end_error'] =". "'".$lang['start_date_before_end_error']."'".';'." ".
"millie['invalid_email'] =".  "'".$lang['invalid_email']."'".';'." ".
"millie['customers'] =". "'".$lang['customers']."'".';'." ". 
"millie['details'] =".  "'".$lang['details']."'".';'." ".
"millie['no_records_found'] =". "'".$lang['no_records_found']."'".';'." ". 
"millie['services'] =".  "'".$lang['services']."'".';'." ".
"millie['duration_minutes'] =". "'".$lang['duration_minutes']."'".';'." ". 
"millie['currency'] =".  "'".$lang['currency']."'".';'." ".
"millie['category'] =". "'".$lang['category']."'".';'." ". 
"millie['no_category'] =".  "'".$lang['no_category']."'".';'." ".
"millie['description'] =". "'".$lang['description']."'".';'." ". 
"millie['categories'] =".  "'".$lang['categories']."'".';'." ".
"millie['admins'] =". "'".$lang['admins']."'".';'." ". 
"millie['providers'] =".  "'".$lang['providers']."'".';'." ".
"millie['secretaries'] =". "'".$lang['secretaries']."'".';'." ". 
"millie['mobile_number'] =".  "'".$lang['mobile_number']."'".';'." ".
"millie['state'] =". "'".$lang['state']."'".';'." ". 
"millie['username'] =".  "'".$lang['username']."'".';'." ".
"millie['password'] =". "'".$lang['password']."'".';'." ". 
"millie['retype_password'] =".  "'".$lang['retype_password']."'".';'." ".
"millie['receive_notifications'] =". "'".$lang['receive_notifications']."'".';'." ". 
"millie['passwords_mismatch'] =".  "'".$lang['passwords_mismatch']."'".';'." ".
"millie['admin_saved'] =". "'".$lang['admin_saved']."'".';'." ". 
"millie['provider_saved'] =".  "'".$lang['provider_saved']."'".';'." ".
"millie['secretary_saved'] =". "'".$lang['secretary_saved']."'".';'." ". 
"millie['admin_deleted'] =".  "'".$lang['admin_deleted']."'".';'." ".
"millie['provider_deleted'] =". "'".$lang['provider_deleted']."'".';'." ".
"millie['secretary_deleted'] =".  "'".$lang['secretary_deleted']."'".';'." ".
"millie['service_saved'] =". "'".$lang['service_saved']."'".';'." ". 
"millie['service_category_saved'] =".  "'".$lang['service_category_saved']."'".';'." ".
"millie['service_deleted'] =". "'".$lang['service_deleted']."'".';'." ".
"millie['service_category_deleted'] =".  "'".$lang['service_category_deleted']."'".';'." ".
"millie['customer_saved'] =". "'".$lang['customer_saved']."'".';'." ". 
"millie['customer_deleted'] =".  "'".$lang['customer_deleted']."'".';'." ".
"millie['current_view'] =". "'".$lang['current_view']."'".';'." ". 
"millie['working_plan'] =".  "'".$lang['working_plan']."'".';'." ".
"millie['reset_plan'] =". "'".$lang['reset_plan']."'".';'." ". 
"millie['monday'] =".  "'".$lang['monday']."'".';'." ".
"millie['tuesday'] =". "'".$lang['tuesday']."'".';'." ". 
"millie['wednesday'] =".  "'".$lang['wednesday']."'".';'." ".
"millie['thursday'] =". "'".$lang['thursday']."'".';'." ". 
"millie['friday'] =".  "'".$lang['friday']."'".';'." ".
"millie['saturday'] =". "'".$lang['saturday']."'".';'." ". 
"millie['sunday'] =".  "'".$lang['sunday']."'".';'." ".
"millie['breaks'] =". "'".$lang['breaks']."'".';'." ".
"millie['add_breaks_during_each_day'] =".  "'".$lang['add_breaks_during_each_day']."'".';'." ".
"millie['day'] =". "'".$lang['day']."'".';'." ".
"millie['days'] =".  "'".$lang['days']."'".';'." ".
"millie['actions'] =". "'".$lang['actions']."'".';'." ". 
"millie['reset_working_plan_hint'] =".  "'".$lang['reset_working_plan_hint']."'".';'." ".
"millie['company_name'] =". "'".$lang['company_name']."'".';'." ". 
"millie['company_name_hint'] =".  "'".$lang['company_name_hint']."'".';'." ".
"millie['company_email'] =". "'".$lang['company_email']."'".';'." ". 
"millie['company_email_hint'] =".  "'".$lang['company_email_hint']."'".';'." ".
"millie['company_link'] =". "'".$lang['company_link']."'".';'." ". 
"millie['company_link_hint'] =".  "'".$lang['company_link_hint']."'".';'." ".
"millie['go_to_booking_page'] =". "'".$lang['go_to_booking_page']."'".';'." ". 
"millie['settings_saved'] =".  "'".$lang['settings_saved']."'".';'." ".
"millie['general'] =". "'".$lang['general']."'".';'." ".
"millie['business_logic'] =".  "'".$lang['business_logic']."'".';'." ".
"millie['current_user'] =". "'".$lang['current_user']."'".';'." ".
"millie['about_app'] =".  "'".$lang['about_app']."'".';'." ".
"millie['edit_working_plan_hint'] =". "'".$lang['edit_working_plan_hint']."'".';'." ". 
"millie['edit_breaks_hint'] =".  "'".$lang['edit_breaks_hint']."'".';'." ".
"millie['book_advance_timeout'] =". "'".$lang['book_advance_timeout']."'".';'." ". 
"millie['book_advance_timeout_hint'] =".  "'".$lang['book_advance_timeout_hint']."'".';'." ".
"millie['timeout_minutes'] =". "'".$lang['timeout_minutes']."'".';'." ".
"millie['about_app_info'] =".  "'".$lang['about_app_info']."'".';'." ".
"millie['current_version'] =". "'".$lang['current_version']."'".';'." ".
"millie['support'] =".  "'".$lang['support']."'".';'." ".
"millie['about_app_support'] =". "'".$lang['about_app_support']."'".';'." ".
"millie['official_website'] =".  "'".$lang['official_website']."'".';'." ".
"millie['google_plus_community'] =". "'".$lang['google_plus_community']."'".';'." ".
"millie['support_group'] =".  "'".$lang['support_group']."'".';'." ".
"millie['project_issues'] =". "'".$lang['project_issues']."'".';'." ".
"millie['license'] =".  "'".$lang['license']."'".';'." ".
"millie['about_app_license'] =". "'".$lang['about_app_license']."'".';'." ".
"millie['logout_success'] =".  "'".$lang['logout_success']."'".';'." ".
"millie['book_appointment_title'] =". "'".$lang['book_appointment_title']."'".';'." ".
"millie['backend_section'] =".  "'".$lang['backend_section']."'".';'." ".
"millie['you_need_to_login'] =". "'".$lang['you_need_to_login']."'".';'." ".
"millie['enter_username_here'] =".  "'".$lang['enter_username_here']."'".';'." ".
"millie['enter_password_here'] =". "'".$lang['enter_password_here']."'".';'." ".
"millie['login'] =".  "'".$lang['login']."'".';'." ".
"millie['forgot_your_password'] =". "'".$lang['forgot_your_password']."'".';'." ".
"millie['login_failed'] =".  "'".$lang['login_failed']."'".';'." ".
"millie['type_username_and_email_for_new_password'] =". "'".$lang['type_username_and_email_for_new_password']."'".';'." ".
"millie['enter_email_here'] =".  "'".$lang['enter_email_here']."'".';'." ".
"millie['regenerate_password'] =". "'".$lang['regenerate_password']."'".';'." ".
"millie['go_to_login'] =".  "'".$lang['go_to_login']."'".';'." ".
"millie['new_password_sent_with_email'] =". "'".$lang['new_password_sent_with_email']."'".';'." ".
"millie['new_account_password'] =".  "'".$lang['new_account_password']."'".';'." ".
"millie['new_password_is'] =". "'".$lang['new_password_is']."'".';'." ".
"millie['delete_record_prompt'] =".  "'".$lang['delete_record_prompt']."'".';'." ".
"millie['delete_admin'] =". "'".$lang['delete_admin']."'".';'." ".
"millie['delete_customer'] =".  "'".$lang['delete_customer']."'".';'." ".
"millie['delete_service'] =". "'".$lang['delete_service']."'".';'." ".
"millie['delete_category'] =".  "'".$lang['delete_category']."'".';'." ".
"millie['delete_provider'] =". "'".$lang['delete_provider']."'".';'." ".
"millie['delete_secretary'] =".  "'".$lang['delete_secretary']."'".';'." ".
"millie['delete_appointment'] =". "'".$lang['delete_appointment']."'".';'." ".
"millie['delete_unavailable'] =".  "'".$lang['delete_unavailable']."'".';'." ".
"millie['delete'] =". "'".$lang['delete']."'".';'." ".
"millie['unexpected_issues'] =".  "'".$lang['unexpected_issues']."'".';'." ".
"millie['unexpected_issues_message'] =". "'".$lang['unexpected_issues_message']."'".';'." ".
"millie['close'] =".  "'".$lang['close']."'".';'." ".
"millie['page_not_found'] =". "'".$lang['page_not_found']."'".';'." ".
"millie['page_not_found_message'] =".  "'".$lang['page_not_found_message']."'".';'." ".
"millie['error'] =". "'".$lang['error']."'".';'." ".
"millie['no_privileges'] =".  "'".$lang['no_privileges']."'".';'." ".
"millie['no_privileges_message'] =". "'".$lang['no_privileges_message']."'".';'." ".
"millie['backend_calendar'] =".  "'".$lang['backend_calendar']."'".';'." ".
"millie['start_date_time'] =". "'".$lang['start_date_time']."'".';'." ".
"millie['end_date_time'] =".  "'".$lang['end_date_time']."'".';'." ".
"millie['licensed_under'] =". "'".$lang['licensed_under']."'".';'." ".
"millie['unexpected_issues_occurred'] =".  "'".$lang['unexpected_issues_occurred']."'".';'." ".
"millie['service_communication_error'] =". "'".$lang['service_communication_error']."'".';'." ".
"millie['no_privileges_edit_appointments'] =".  "'".$lang['no_privileges_edit_appointments']."'".';'." ".
"millie['unavailable_updated'] =". "'".$lang['unavailable_updated']."'".';'." ".
"millie['appointments'] =".  "'".$lang['appointments']."'".';'." ".
"millie['unexpected_warnings'] =". "'".$lang['unexpected_warnings']."'".';'." ".
"millie['unexpected_warnings_message'] =".  "'".$lang['unexpected_warnings_message']."'".';'." ".
"millie['filter'] =". "'".$lang['filter']."'".';'." ".
"millie['clear'] =".  "'".$lang['clear']."'".';'." ".
"millie['uncategorized'] =". "'".$lang['uncategorized']."'".';'." ".
"millie['username_already_exists'] =".  "'".$lang['username_already_exists']."'".';'." ".
"millie['password_length_notice'] =". "'".$lang['password_length_notice']."'".';'." ".
"millie['general_settings'] =".  "'".$lang['general_settings']."'".';'." ".
"millie['personal_information'] =". "'".$lang['personal_information']."'".';'." ".
"millie['system_login'] =".  "'".$lang['system_login']."'".';'." ".
"millie['user_settings_are_invalid'] =". "'".$lang['user_settings_are_invalid']."'".';'." ".
"millie['add_break'] =".  "'".$lang['add_break']."'".';'." ".
"millie['january'] =". "'".$lang['january']."'".';'." ".
"millie['february'] =".  "'".$lang['february']."'".';'." ".
"millie['march'] =". "'".$lang['march']."'".';'." ".
"millie['april'] =".  "'".$lang['april']."'".';'." ".
"millie['may'] =". "'".$lang['may']."'".';'." ".
"millie['june'] =".  "'".$lang['june']."'".';'." ".
"millie['july'] =". "'".$lang['july']."'".';'." ".
"millie['august'] =".  "'".$lang['august']."'".';'." ".
"millie['september'] =". "'".$lang['september']."'".';'." ".
"millie['october'] =".  "'".$lang['october']."'".';'." ".
"millie['november'] =". "'".$lang['november']."'".';'." ".
"millie['december'] =".  "'".$lang['december']."'".';'." ".
"millie['previous'] =". "'".$lang['previous']."'".';'." ".
"millie['next'] =".  "'".$lang['next']."'".';'." ".
"millie['now'] =". "'".$lang['now']."'".';'." ".
"millie['select_time'] =".  "'".$lang['select_time']."'".';'." ".
"millie['time'] =". "'".$lang['time']."'".';'." ".
"millie['hour'] =".  "'".$lang['hour']."'".';'." ".
"millie['minute'] =". "'".$lang['minute']."'".';'." ".
"millie['google_sync_completed'] =".  "'".$lang['google_sync_completed']."'".';'." ".
"millie['google_sync_failed'] =". "'".$lang['google_sync_failed']."'".';'." ".
"millie['select_google_calendar'] =".  "'".$lang['select_google_calendar']."'".';'." ".
"millie['select_google_calendar_prompt'] =". "'".$lang['select_google_calendar_prompt']."'".';'." ".
"millie['google_calendar_selected'] =".  "'".$lang['google_calendar_selected']."'".';'." ".
"millie['oops_something_went_wrong'] =". "'".$lang['oops_something_went_wrong']."'".';'." ".
"millie['could_not_add_to_google_calendar'] =".  "'".$lang['could_not_add_to_google_calendar']."'".';'." ".
"millie['ea_update_success'] =". "'".$lang['ea_update_success']."'".';'." ".
"millie['require_captcha'] =".  "'".$lang['require_captcha']."'".';'." ".
"millie['require_captcha_hint'] =". "'".$lang['require_captcha_hint']."'".';'." ".
"millie['captcha_is_wrong'] =".  "'".$lang['captcha_is_wrong']."'".';'." ".
"millie['any_provider'] =". "'".$lang['any_provider']."'".';'." ".
"millie['requested_hour_is_unavailable'] =".  "'".$lang['requested_hour_is_unavailable']."'".';'." ".
"millie['customer_notifications'] =". "'".$lang['customer_notifications']."'".';'." ".
"millie['customer_notifications_hint'] =".  "'".$lang['customer_notifications_hint']."'".';'." ".
"millie['date_format'] =". "'".$lang['date_format']."'".';'." ".
"millie['date_format_hint'] =".  "'".$lang['date_format_hint']."'".';'." ".
"millie['time_format'] =". "'".$lang['time_format']."'".';'." ".
"millie['time_format_hint'] =".  "'".$lang['time_format_hint']."'".';'." ".
"millie['google_analytics_code_hint'] =". "'".$lang['google_analytics_code_hint']."'".';'." ".
"millie['availabilities_type'] =".  "'".$lang['availabilities_type']."'".';'." ".
"millie['flexible'] =". "'".$lang['flexible']."'".';'." ".
"millie['fixed'] =".  "'".$lang['fixed']."'".';'." ".
"millie['attendants_number'] =". "'".$lang['attendants_number']."'".';'." ".
"millie['reset_working_plan'] =".  "'".$lang['reset_working_plan']."'".';'." ".
"millie['legal_contents'] =". "'".$lang['legal_contents']."'".';'." ".
"millie['cookie_notice'] =".  "'".$lang['cookie_notice']."'".';'." ".
"millie['display_cookie_notice'] =". "'".$lang['display_cookie_notice']."'".';'." ".
"millie['cookie_notice_content'] =".  "'".$lang['cookie_notice_content']."'".';'." ".
"millie['terms_and_conditions'] =". "'".$lang['terms_and_conditions']."'".';'." ".
"millie['display_terms_and_conditions'] =".  "'".$lang['display_terms_and_conditions']."'".';'." ".
"millie['terms_and_conditions_content'] =". "'".$lang['terms_and_conditions_content']."'".';'." ".
"millie['privacy_policy'] =".  "'".$lang['privacy_policy']."'".';'." ".
"millie['display_privacy_policy'] =". "'".$lang['display_privacy_policy']."'".';'." ".
"millie['privacy_policy_content'] =".  "'".$lang['privacy_policy_content']."'".';'." ".
"millie['website_using_cookies_to_ensure_best_experience'] =". "'".$lang['website_using_cookies_to_ensure_best_experience']."'".';'." ".
"millie['read_and_agree_to_terms_and_conditions'] =".  "'".$lang['read_and_agree_to_terms_and_conditions']."'".';'." ".
"millie['read_and_agree_to_privacy_policy'] =". "'".$lang['read_and_agree_to_privacy_policy']."'".';'." ".
"millie['delete_personal_information_hint'] =".  "'".$lang['delete_personal_information_hint']."'".';'." ".
"millie['delete_personal_information'] =". "'".$lang['delete_personal_information']."'".';'." ".
"millie['delete_personal_information_prompt'] =".  "'".$lang['delete_personal_information_prompt']."'".';'." ".
"millie['smsdeletemessage'] ="."'".'to inquire call us at  1234567890 or visit our website mytestwebsite.ca'."'".';'." ".
"millie['smsconfirmmessage'] ="."'".'to inquire call us at 1234567890 or visit our website mytestwebsite.ca'."'".';'.
"millie['smsonoff'] ="."'".Config::SMS_ON_OFF."'".';';

$millie1 = str_replace('millie', '$lang', $millie);
$millie2 = str_replace('|', '$', $millie1);
file_put_contents($filename, $millie2);

            // Insert admin
            $this->load->model('admins_model');
            $admin = $this->input->post('admin');
            $admin['settings']['username'] = $admin['username'];
            $admin['settings']['password'] = $admin['password'];
            $admin['settings']['calendar_view'] = CALENDAR_VIEW_DEFAULT;
            unset($admin['username'], $admin['password']);
            $admin['id'] = $this->admins_model->add($admin);

            $this->load->library('session');
            $this->session->set_userdata('user_id', $admin['id']);
            $this->session->set_userdata('user_email', $admin['email']);
            $this->session->set_userdata('role_slug', DB_SLUG_ADMIN);
            $this->session->set_userdata('username', $admin['settings']['username']);

            // Save company settings
            $this->load->model('settings_model');
            $company = $this->input->post('company');
            $this->settings_model->set_setting('company_name', $company['company_name']);
            $this->settings_model->set_setting('company_email', $company['company_email']);
            $this->settings_model->set_setting('company_link', $company['company_link']);

            // Create sample records.
            $this->load->model('services_model');
            $this->load->model('providers_model');

            $sample_service = get_sample_service();
            $sample_service['id'] = $this->services_model->add($sample_service);
            $sample_provider = get_sample_provider();
            $sample_provider['services'][] = $sample_service['id'];
            $this->providers_model->add($sample_provider);

            $this->output
                ->set_content_type('application/json')
                ->set_output(json_encode(AJAX_SUCCESS));

        }
        catch (Exception $exc)
        {
            $this->output
                ->set_content_type('application/json')
                ->set_output(json_encode(['exceptions' => [exceptionToJavaScript($exc)]]));
        }
    }
}
