<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
namespace App\Controllers;
use App\Views;
use App\Models\CommonModel;
class LanguageSwitcher extends CI_Controller
{
    public function __construct() {
        parent::__construct();     
        $CommonModel = model('CommonModel');
    }
 
    function switchLang() {
        
        $language = ($this->request->uri->getSegment(2)) ? $this->request->uri->getSegment(2) : "english";
        $condition = "language_name = '".$language."'";
        $act_lang_data = $CommonModel->GetRow("language_controls",$condition);

        if($act_lang_data) {
	        $this->session->set_userdata('site_lang', $act_lang_data->language_name);
	        $this->session->set_userdata('langid', $act_lang_data->language_id);
	    }
        
        redirect($_SERVER['HTTP_REFERER']);
        
    }

    function switchLangs() {
        
        $language = ($this->request->uri->getSegment(2)) ? $this->request->uri->getSegment(2) : "english";
        $condition = "language_name = '".$language."'";
        $act_lang_data = $CommonModel->GetRow("language_controls",$condition);

        if($act_lang_data) {
            $this->session->set_userdata('user_lang', $act_lang_data->language_name);
            $this->session->set_userdata('user_langid', $act_lang_data->language_id);
        }
        
        redirect($_SERVER['HTTP_REFERER']);
        
    }
}