<?php
class main extends CI_Controller {

	public function index()
	{
		$this->load->view("login");
	}
	public function login_check(){
		$username = $this->input->post('username');
		$password = $this->input->post('password');
		$this->load->model('users_model');
		$this->load->model("telegram_model");
		$query = $this->users_model->check_users($username,md5($password));
		if($query == "not_find"){
			$this->session->set_flashdata("error","userwrong");
			redirect('./');
		}else{
			//check expire
			if($this->persiandate->jdate("Ymd","","",'Asia/Tehran',"en") >= $query["expire"]){
			$this->session->set_flashdata("error","expiretime");
			redirect('./');
			}else{
				$this->session->set_userdata(array("canlogin"=>"yes","browser"=>$this->agent->browser(),"version"=>$this->agent->version(),"ip"=>$this->input->ip_address()));
				$this->session->set_userdata($query);
				if($query["per"] == "5"){
			redirect('./admin');		
				}elseif($query["per"] == "4" || $query["per"] == "3"){
			redirect('./panel');		
				}elseif($query["per"] == "2"){
					$group_id = $this->telegram_model->get_group_byuid($query["id"]);
					$menulinks = $this->telegram_model->get_telegram_bd_dymanic("telebot_".$group_id);
					$this->session->set_userdata("tellinks",$menulinks);
			redirect('./botuser');
				}elseif($query["per"] == "1"){
					redirect('./panel');	
				}
			
			}
			//end check expire
		}
		
	}
	public function logout(){
		$this->session->sess_destroy();
		redirect('./panel');
	}
}
?>