<?php

class LanguageLoader
{
    function initialize() {
        $ci =& get_instance();
        $ci->load->helper('language');
        
        // http redirect
//        $ci->config->config['base_url'] = str_replace('http://', 'https://', $ci->config->config['base_url']);
//        if ($_SERVER['SERVER_PORT'] != 443) redirect($ci->uri->uri_string());
        
        if($ci->uri->segment(1) == 'admin') {
            $language = 'english';
        } else {
            if ($ci->db->table_exists('languages')) {
                $language = objToArr($ci->AdminLanguageModel->getSelected());    
            } else {
                $language = 'english';
            }
        }
        $ci->session->set_userdata(array('selected_language' => $language));
        $ci->config->set_item('language', $language);

        $ci->lang->load('message',$language);
        $ci->lang->load('form_validation',$language);
    }
}