<?php

class panel extends CI_Controller {

	public function index()
	{
		if($this->session->userdata("canlogin") == "yes"){
			if($this->session->userdata("browser") == $this->agent->browser() && $this->session->userdata("version") == $this->agent->version() && $this->session->userdata("ip") == $this->input->ip_address() && ($this->session->userdata("per") == 4 || $this->session->userdata("per") == 1)){
			$query = $this->db->query('SELECT * FROM users');
			$this->load->model("nobat_model");
			$this->load->model("pationt_model");
			$this->load->model('general_model');
			$this->load->model('telegram_model');
			$year = $this->persiandate->jdate("Y","","",'Asia/Tehran',"en");
			$a = $this->nobat_model->get_nobat_bytime($this->session->userdata("id"),(int)($year."01"."01"),(int)($year."01"."31"));
			$b = $this->nobat_model->get_nobat_bytime($this->session->userdata("id"),$year."02"."01",$year."02"."31");
			$c = $this->nobat_model->get_nobat_bytime($this->session->userdata("id"),$year."03"."01",$year."03"."31");
			$d = $this->nobat_model->get_nobat_bytime($this->session->userdata("id"),$year."04"."01",$year."04"."31");
			$e = $this->nobat_model->get_nobat_bytime($this->session->userdata("id"),$year."05"."01",$year."05"."31");
			$f = $this->nobat_model->get_nobat_bytime($this->session->userdata("id"),$year."06"."01",$year."06"."31");
			$g = $this->nobat_model->get_nobat_bytime($this->session->userdata("id"),(int)($year."07"."01"),(int)($year."07"."30"));
			$h = $this->nobat_model->get_nobat_bytime($this->session->userdata("id"),$year."08"."01",$year."08"."30");
			$i = $this->nobat_model->get_nobat_bytime($this->session->userdata("id"),$year."09"."01",$year."09"."30");
			$j = $this->nobat_model->get_nobat_bytime($this->session->userdata("id"),$year."10"."01",$year."10"."30");
			$k = $this->nobat_model->get_nobat_bytime($this->session->userdata("id"),$year."11"."01",$year."11"."30");
			$l = $this->nobat_model->get_nobat_bytime($this->session->userdata("id"),$year."12"."01",$year."12"."30");
			$nobatcounter = count($this->nobat_model->get_nobat_all($this->session->userdata("id")));
			$telegram_message = $this->telegram_model->get_telegram_message($this->session->userdata("id"));
			$days = $this->general_model->get_setting($this->session->userdata("id"));
			@$days = $days[0]->day_work; 
			$nobatdehi = $this->nobat_model->get_nobat_all($this->session->userdata("id"));
			$sevenlastnobat = $this->nobat_model->get_nobat_byorder($this->session->userdata("id"),$this->persiandate->jdate("Ymd","","",'Asia/Tehran',"en"));
			if(count($sevenlastnobat)>0){
				foreach($sevenlastnobat as $value){
			$docpation = $this->pationt_model->get_pationt_byname($value->po_name);
			if(count($docpation)>0){
				$value->isdoc = true;
				$value->docurl =  base_url()."panel/Patient_document?id=".$docpation[0]->id."&root=yes";
			}else{
				$value->isdoc = false;
				$value->docurl = base_url()."panel/confirm_Patient?name=".$value->po_name;
			}
			}
			}
			$this->load->view('index',array("username" =>$this->session->userdata("username"),"fullname"=>$this->session->userdata("fullname"),
											"calender_item"=>$nobatdehi,"day_work"=>$days,"telegram_message"=>$telegram_message,"lastsnobats"=>$sevenlastnobat,"nobat_count"=>$nobatcounter,
											"count_of_customers"=>array($a,$b,$c,$d,$e,$f,$g,$h,$i,$j,$k,$l)
											));	
			}else{
				$this->session->sess_destroy();
				redirect("./");
			}
			
		}else{
			$this->session->sess_destroy();
			redirect("./");
		}
		
		//$query = $this->db->query('SELECT * FROM users');
		//$this->load->view('index',array("username" =>$this->session->userdata("username"),"fullname"=>$this->session->userdata("fullname")));
		$this->agent->browser();
	}

	public function confirm_Patient(){
		if($this->session->userdata("canlogin") == "yes"){
			if($this->session->userdata("browser") == $this->agent->browser() && $this->session->userdata("version") == $this->agent->version() && $this->session->userdata("ip") == $this->input->ip_address() && ($this->session->userdata("per") == 4 || $this->session->userdata("per") == 1)){
			$query = $this->db->query('SELECT * FROM users');
			$this->load->view('add_bimar',array("username" =>$this->session->userdata("username"),"fullname"=>$this->session->userdata("fullname")
											,"today"=>$this->persiandate->jdate("Y/m/d","","",'Asia/Tehran',"en")	
												
												));	
			}else{
				$this->session->sess_destroy();
				redirect("./");
			}
			
		}else{
			$this->session->sess_destroy();
			redirect("./");
		}
		
	}
	public function confirm_Patient_control(){
		if($this->session->userdata("canlogin") == "yes"){
			if($this->session->userdata("browser") == $this->agent->browser() && $this->session->userdata("version") == $this->agent->version() && $this->session->userdata("ip") == $this->input->ip_address() && ($this->session->userdata("per") == 4 || $this->session->userdata("per") == 1)){
			$this->load->model('pationt_model');
			
		$imgData = $this->input->post('image');
		if($this->input->post('image') != ""){
		$type = explode(";",$imgData);
		$type = explode("/",$type[0]);
		$type = $type[1];
		$imgData=base64_decode(preg_replace('#^data:image/\w+;base64,#i', '', $imgData));
		$imagename = rand(11111, 99999) . time();
		$fullimage_name = $imagename. "." .$type;
			if ( ! write_file('./assets/data_images/drs/Patient_profile_pictures/'. $imagename. "." .$type, $imgData))
{
		$this->session->set_flashdata(array("error"=>"imageproblem"));
}
		}else{
			$fullimage_name = "null";
		}
$data = array("shomare_parvandeh" =>$this->input->post("shomareh_parvandeh"),"full_name"=>$this->input->post("name")." ".$this->input->post("lname"),
				"title"=>$this->input->post("title"),"important_phone"=>$this->input->post("emphone"),"home_phone"=>$this->input->post("homephone"),"email"=>$this->input->post("email"),
				"home_address"=>$this->input->post("home_address"),"work_address"=>$this->input->post("work_address"),"group_by"=>$this->input->post("group"),
				"father_name"=>$this->input->post("fathername"),"no_shenasnameh"=>$this->input->post("shensnameh"),"meli_code"=>$this->input->post("melicode"),
				"work_phone"=>$this->input->post("phonework"),"cell_phone"=>$this->input->post("cellphone"),"age"=>$this->input->post("age"),"tavaload_place"=>$this->input->post("placeofb"),
				"submit_date"=>$this->input->post("submitdate"),"sex"=>$this->input->post("sex"),"image_name"=>$fullimage_name,"uid"=>$this->session->userdata("id"),
				
			);
$this->pationt_model->add_pationt($data);
$id = $this->pationt_model->getLastInserted();
mkdir("assets/data_images/drs/pationt_doc/".$id);
		$this->session->set_flashdata('datbasetype', 'succ');
		redirect("./panel/confirm_Patient");
			}else{
				$this->session->sess_destroy();
				redirect("./");
			}
			
		}else{
			$this->session->sess_destroy();
			redirect("./");
		}
	}
public function list_Patient(){
	if($this->session->userdata("canlogin") == "yes"){
			if($this->session->userdata("browser") == $this->agent->browser() && $this->session->userdata("version") == $this->agent->version() && $this->session->userdata("ip") == $this->input->ip_address() && ($this->session->userdata("per") == 4 || $this->session->userdata("per") == 1)){
			$this->load->model('pationt_model');
			//for paginig
			
			if($this->input->get("page") && $this->input->get("limit")){
			$page = $this->input->get("page");
			$limit = $this->input->get("limit");
			}else{
				$page = 1;
				$limit = 10;
			}
			$offset = ($limit * ($page-1));
			if($this->input->get("search")){
			$data = $this->pationt_model->list_pationt($this->session->userdata("id"),$limit,$offset,$this->input->get("search"));	
			}else{
			$data = $this->pationt_model->list_pationt($this->session->userdata("id"),$limit,$offset);	
			}
			
			$count = $this->pationt_model->count_pationt($this->session->userdata("id"));
			//for caraneh payiineh tedad
			$minrec = ($page-1)*$limit+1;
			//for karaneh bala tadad
			if($count <= ($page * $limit)){
				$maxrec = $count;
			}else{
				$maxrec = $page * $limit;
			}
			//for pages number
			$pages_numbers = ceil($count/$limit);
			//print_r($data);
			$this->load->view('list_bimar',array("username" =>$this->session->userdata("username"),"countof"=>$count,"fullname"=>$this->session->userdata("fullname"),
												"numberofpage"=>$pages_numbers,"datalist"=>$data,"last"=>$maxrec,"first"=>$minrec));	
			}else{
				$this->session->sess_destroy();
				redirect("./");
			}
			
		}else{
			$this->session->sess_destroy();
			redirect("./");
		}
}
public function delete_Patient_control(){
	if($this->session->userdata("canlogin") == "yes"){
			if($this->session->userdata("browser") == $this->agent->browser() && $this->session->userdata("version") == $this->agent->version() && $this->session->userdata("ip") == $this->input->ip_address() && ($this->session->userdata("per") == 4 || $this->session->userdata("per") == 1)){
			$this->load->model('pationt_model');
			if($this->input->post("getid")){
			$this->pationt_model->delete_pationt($this->input->post("getid"));
			echo "done";
			}else{
				echo "notdone";
			}
			}else{
				$this->session->sess_destroy();
				redirect("./");
			}
			
		}else{
			redirect("./");
			$this->session->sess_destroy();
		}
}
public function Patient_document(){
	if($this->session->userdata("canlogin") == "yes"){
			if($this->session->userdata("browser") == $this->agent->browser() && $this->session->userdata("version") == $this->agent->version() && $this->session->userdata("ip") == $this->input->ip_address() && ($this->session->userdata("per") == 4 || $this->session->userdata("per") == 1)){
			$this->load->model('pationt_model');
			$this->load->model('folder_model');
			$this->load->model('bimeh_model');
			$this->load->model("record_model");
			$this->load->model("finance_model");;
			$record_data = $this->record_model->get_record($this->input->get("id"));
			if($this->input->get("root") == "yes"){
				$this->session->set_userdata(array("isroot" => "yes"));
			}
			if($this->session->userdata("isroot") == "no" && $this->session->userdata("pid")){
			$map = $this->folder_model->get_folder_bypid($this->session->userdata("pid"),$this->input->get('id'));
			}else{
				$map = $this->folder_model->get_folder_byuid($this->input->get('id'),'bimaran');
				
			}
			
			 $pdata = $this->pationt_model->get_pationt($this->session->userdata("id"),$this->input->get('id'));
			 $pname = $pdata[0]->full_name;
			 $finace_data = $this->finance_model->get_finance_byname($this->session->userdata("id"),$pname);
			 $fresuns = $this->finance_model->get_khadamat($this->session->userdata("id"));
			$this->load->view('doc_bimar',array("username" =>$this->session->userdata("username"),"fullname"=>$this->session->userdata("fullname"),
												"data"=>$pdata,"dmap"=>$map,"whattype"=>$this->input->get('whattype'),"bimeh"=>$this->bimeh_model->get_bimehs($this->session->userdata("id")),"today"=>$this->persiandate->jdate("Y/m/d","","",'Asia/Tehran',"en")
												,"record_data"=>$record_data,"f_data"=>$finace_data,"fresun"=>$fresuns
												));	
			}else{
				$this->session->sess_destroy();
				redirect("./");
			}
			
		}else{
			$this->session->sess_destroy();
			redirect("./");
		}
}
public function add_folder_control_bimaran(){
	if($this->session->userdata("canlogin") == "yes"){
			if($this->session->userdata("browser") == $this->agent->browser() && $this->session->userdata("version") == $this->agent->version() && $this->session->userdata("ip") == $this->input->ip_address() && ($this->session->userdata("per") == 4 || $this->session->userdata("per") == 1)){
	$this->load->model('folder_model');
	$uid = $this->input->post("bid");
	if($this->input->post("parent") == "root" || !$this->session->userdata("pid")){
	$parent = "root";
	}else{
	$parent =	$this->session->userdata("pid");
	}
	if($this->input->post("optionsRadios") == "option1"){
		$type="folder";
		$name = $this->input->post("foldername");
		
			$foldername = rand(11111, 99999) . time();
		$real_name = $foldername;
		
	}else{
			$imagename = rand(11111, 99999) . time();
		 $config['upload_path'] ="./assets/data_images/drs/pationt_doc/".$this->input->post("bid");
		

		$config['file_name'] = $imagename;
        $config['allowed_types'] = 'gif|jpg|png|jpeg';
		$type="image";
		  $this->load->library('upload', $config);

                if ( ! $this->upload->do_upload('uploadfile'))
                {
                   echo "not done";     
                }
                else
                {
                  $real_name = $imagename .$this->upload->data('file_ext');
                }
		$name = $this->input->post("filename");
	}
	$data = array("userid"=>$uid,"name"=>$name,"real_name"=>$real_name,"parent"=>$parent,"type"=>$type,"usefor"=>"bimaran");
	$this->folder_model->add_folder($data);
	redirect("./panel/Patient_document?id=".$uid."&whattype=documents");
	}else{
				$this->session->sess_destroy();
				redirect("./");
			}
			
		}else{
			$this->session->sess_destroy();
			redirect("./");
		}
}
public function check_folder_control(){
	if($this->session->userdata("canlogin") == "yes"){
			if($this->session->userdata("browser") == $this->agent->browser() && $this->session->userdata("version") == $this->agent->version() && $this->session->userdata("ip") == $this->input->ip_address() && ($this->session->userdata("per") == 4 || $this->session->userdata("per") == 1)){
	$this->load->model('folder_model');
	$pid = $this->input->post("id");
	$parent = $this->input->post("lastparent");
	if($parent == "root"){
		$this->session->unset_userdata("real_name");
	}
	$realname = $this->session->userdata("real_name")."/".$this->input->post("realname");
	$array = array("lastparent"=>$parent,"pid"=>$pid,"real_name"=>$realname,"isroot"=>"no");
	$this->session->set_userdata($array);
	 $result = $this->folder_model->get_folder_bypid($pid,$this->input->post("uid"));
	echo  json_encode($result);
	}else{
				$this->session->sess_destroy();
				redirect("./");
			}

		}else{
			$this->session->sess_destroy();
			redirect("./");
		}
}
public function check_folder_control_back(){
	if($this->session->userdata("canlogin") == "yes"){
			if($this->session->userdata("browser") == $this->agent->browser() && $this->session->userdata("version") == $this->agent->version() && $this->session->userdata("ip") == $this->input->ip_address() && ($this->session->userdata("per") == 4 || $this->session->userdata("per") == 1)){
	try{
	$this->load->model('folder_model');
	$pid = $this->session->userdata("pid");
	$uid = $this->input->post("uid");
	
	 $pid = $this->folder_model->get_parent($this->session->userdata("pid"));
	 $result = $this->folder_model->get_folder_bypid($pid,$uid);
	$this->session->set_userdata(array("pid"=>$pid));
	echo  json_encode($result);
	}catch(Exeption $e){
		
	}
	}else{
				$this->session->sess_destroy();
				redirect("./");
			}

		}else{
			$this->session->sess_destroy();
			redirect("./");
		}
	
}
public function check_folder_control_delete(){
	if($this->session->userdata("canlogin") == "yes"){
			if($this->session->userdata("browser") == $this->agent->browser() && $this->session->userdata("version") == $this->agent->version() && $this->session->userdata("ip") == $this->input->ip_address() && ($this->session->userdata("per") == 4 || $this->session->userdata("per") == 1)){
	$this->load->model('folder_model');
	$result = $this->folder_model->get_delete_folder($this->input->post("id"));
	$this->folder_model->delete_folder($this->input->post("id"));
	foreach($result as $value){
		if($value->type == "image"){
			$path = "./assets/data_images/drs/pationt_doc/".$this->input->post("bid")."/".$value->real_name ;
			@unlink($path);
		}
	}
	echo "done";
	}else{
				$this->session->sess_destroy();
				redirect("./");
			}

		}else{
			$this->session->sess_destroy();
			redirect("./");
		}
}
public function check_folder_control_editname(){
	if($this->session->userdata("canlogin") == "yes"){
			if($this->session->userdata("browser") == $this->agent->browser() && $this->session->userdata("version") == $this->agent->version() && $this->session->userdata("ip") == $this->input->ip_address() && ($this->session->userdata("per") == 4 || $this->session->userdata("per") == 1)){
	$this->load->model('folder_model');
	$this->folder_model->rename_folder($this->input->post("id"),$this->input->post("value"));
	echo "done";
	}else{
				$this->session->sess_destroy();
				redirect("./");
			}

		}else{
			$this->session->sess_destroy();
			redirect("./");
		}
}
public function add_noskheh_control_bimaran(){
	if($this->session->userdata("canlogin") == "yes"){
			if($this->session->userdata("browser") == $this->agent->browser() && $this->session->userdata("version") == $this->agent->version() && $this->session->userdata("ip") == $this->input->ip_address() && ($this->session->userdata("per") == 4 || $this->session->userdata("per") == 1)){
	$this->load->model('finance_model');
	$cuntable_date = $this->input->post("visitd");
	$cuntable_date = explode("/",$cuntable_date);
	$cuntable_date = $cuntable_date[0].$cuntable_date[1].$cuntable_date[2];
	$data = array("uid"=>$this->session->userdata("id"),"visit_date"=>$this->input->post("visitd"),
				"visit_pay"=>$this->input->post("visitp"),"surgery_pay"=>$this->input->post("segp"),
				"other_pay"=>$this->input->post("otherp"),"insure_type"=>$this->input->post("insurename"),
				"insure_pay"=>$this->input->post("peybyinsure"),"client_pay"=>$this->input->post("peybycustomer"),
				"client_name"=>$this->input->post("bimarname"),"submit_date"=>$cuntable_date,"morage_res"=>$this->input->post("visitresun")
				);
	$this->finance_model->add_finance($data);
	redirect("./panel/Patient_document?id=".$this->input->post("bimarid")."&whattype=finance");
	}else{
				$this->session->sess_destroy();
				redirect("./");
			}

		}else{
			$this->session->sess_destroy();
			redirect("./");
		}
}
public function add_history_control_bimaran(){
	if($this->session->userdata("canlogin") == "yes"){
			if($this->session->userdata("browser") == $this->agent->browser() && $this->session->userdata("version") == $this->agent->version() && $this->session->userdata("ip") == $this->input->ip_address() && ($this->session->userdata("per") == 4 || $this->session->userdata("per") == 1)){
	$this->load->model('record_model');
	$data = array("dalileh_moragee"=>$this->input->post("visitresun"),
				"sharh"=>$this->input->post("discriptiontype"),"date"=>$this->input->post("date"),
				"code_bimar"=>$this->input->post("pationtid")
				);
	$this->record_model->add_record($data);
	redirect("./panel/Patient_document?id=".$this->input->post("pationtid")."&whattype=recordhistori");
	}else{
				$this->session->sess_destroy();
				redirect("./");
			}

		}else{
			$this->session->sess_destroy();
			redirect("./");
		}
}
public function data_edit_information_control(){
	if($this->session->userdata("canlogin") == "yes"){
			if($this->session->userdata("browser") == $this->agent->browser() && $this->session->userdata("version") == $this->agent->version() && $this->session->userdata("ip") == $this->input->ip_address() && ($this->session->userdata("per") == 4 || $this->session->userdata("per") == 1)){
			$this->load->model('pationt_model');
			
		$imgData = $this->input->post('image');
		if($this->input->post('image') != ""){
		$type = explode(";",$imgData);
		$type = explode("/",$type[0]);
		$type = $type[1];
		$imgData=base64_decode(preg_replace('#^data:image/\w+;base64,#i', '', $imgData));
		$imagename = rand(11111, 99999) . time();
		$fullimage_name = $imagename. "." .$type;
			if ( ! write_file('./assets/data_images/drs/Patient_profile_pictures/'. $imagename. "." .$type, $imgData))
{
		$this->session->set_flashdata(array("error"=>"imageproblem"));
}
		}else{
			$fullimage_name = "null";
		}
		if($fullimage_name == "null"){
			$data = array("shomare_parvandeh" =>$this->input->post("shomareh_parvandeh"),"full_name"=>$this->input->post("name")." ".$this->input->post("lname"),
				"title"=>$this->input->post("title"),"important_phone"=>$this->input->post("emphone"),"home_phone"=>$this->input->post("homephone"),"email"=>$this->input->post("email"),
				"home_address"=>$this->input->post("home_address"),"work_address"=>$this->input->post("work_address"),"group_by"=>$this->input->post("group"),
				"father_name"=>$this->input->post("fathername"),"no_shenasnameh"=>$this->input->post("shensnameh"),"meli_code"=>$this->input->post("melicode"),
				"work_phone"=>$this->input->post("phonework"),"cell_phone"=>$this->input->post("cellphone"),"age"=>$this->input->post("age"),"tavaload_place"=>$this->input->post("placeofb"),
				"submit_date"=>$this->input->post("submitdate"),"sex"=>$this->input->post("sex"),"uid"=>$this->session->userdata("id"),
				
			);
			}else{
			$data = array("shomare_parvandeh" =>$this->input->post("shomareh_parvandeh"),"full_name"=>$this->input->post("name")." ".$this->input->post("lname"),
				"title"=>$this->input->post("title"),"important_phone"=>$this->input->post("emphone"),"home_phone"=>$this->input->post("homephone"),"email"=>$this->input->post("email"),
				"home_address"=>$this->input->post("home_address"),"work_address"=>$this->input->post("work_address"),"group_by"=>$this->input->post("group"),
				"father_name"=>$this->input->post("fathername"),"no_shenasnameh"=>$this->input->post("shensnameh"),"meli_code"=>$this->input->post("melicode"),
				"work_phone"=>$this->input->post("phonework"),"cell_phone"=>$this->input->post("cellphone"),"age"=>$this->input->post("age"),"tavaload_place"=>$this->input->post("placeofb"),
				"submit_date"=>$this->input->post("submitdate"),"sex"=>$this->input->post("sex"),"image_name"=>$fullimage_name,"uid"=>$this->session->userdata("id"),
				
			);
		}

$this->pationt_model->update_pationt($this->input->post("id"),$data);
$this->session->set_flashdata('datbasetype', 'succ');
		redirect("./panel/Patient_document?id=".$this->input->post("id")."&whattype=edit");
		}else{
				$this->session->sess_destroy();
				redirect("./");
			}

		}else{
			$this->session->sess_destroy();
			redirect("./");
		}
}
public function set_insure(){
	if($this->session->userdata("canlogin") == "yes"){
			if($this->session->userdata("browser") == $this->agent->browser() && $this->session->userdata("version") == $this->agent->version() && $this->session->userdata("ip") == $this->input->ip_address() && ($this->session->userdata("per") == 4 || $this->session->userdata("per") == 1)){
	$this->load->model('bimeh_model');
	$bimeh = $this->bimeh_model->get_bimehs($this->session->userdata("id"));
	$this->load->view('set_bimeh',array("username" =>$this->session->userdata("username"),"fullname"=>$this->session->userdata("fullname"),
											"bimeh"=>$bimeh	));
	}else{
				$this->session->sess_destroy();
				redirect("./");
			}

		}else{
			$this->session->sess_destroy();
			redirect("./");
		}
}
public function set_insure_control(){
	if($this->session->userdata("canlogin") == "yes"){
			if($this->session->userdata("browser") == $this->agent->browser() && $this->session->userdata("version") == $this->agent->version() && $this->session->userdata("ip") == $this->input->ip_address() && ($this->session->userdata("per") == 4 || $this->session->userdata("per") == 1)){
	$this->load->model('bimeh_model');
	$this->bimeh_model->delete_bimehs($this->session->userdata("id"));
	for($i=1; $i <= $this->input->post("number");$i++ ){
		if($this->input->post("insurename".$i) !="" && $this->input->post("insurepercent".$i) !=""){
			$data = array("uid"=>$this->session->userdata("id"),"name"=>$this->input->post("insurename".$i),"percent"=>$this->input->post("insurepercent".$i));
			$this->bimeh_model->add_bimeh($data);
		}
	}
	redirect("./panel/set_insure");
	}else{
				$this->session->sess_destroy();
				redirect("./");
			}

		}else{
			$this->session->sess_destroy();
			redirect("./");
		}
}
public function Articles(){
	if($this->session->userdata("canlogin") == "yes"){
			if($this->session->userdata("browser") == $this->agent->browser() && $this->session->userdata("version") == $this->agent->version() && $this->session->userdata("ip") == $this->input->ip_address() && ($this->session->userdata("per") == 4 || $this->session->userdata("per") == 1)){
	$this->load->view('maghalat',array("username" =>$this->session->userdata("username"),"fullname"=>$this->session->userdata("fullname"),
									   "today"=>$this->persiandate->jdate("Y/m/d","","",'Asia/Tehran',"en")
												));
		}else{
				$this->session->sess_destroy();
				redirect("./");
			}

		}else{
			$this->session->sess_destroy();
			redirect("./");
		}
}
public function set_articles_control(){
	if($this->session->userdata("canlogin") == "yes"){
			if($this->session->userdata("browser") == $this->agent->browser() && $this->session->userdata("version") == $this->agent->version() && $this->session->userdata("ip") == $this->input->ip_address() && ($this->session->userdata("per") == 4 || $this->session->userdata("per") == 1)){
	$this->load->model('articles_model');
	$data = array("uid"=>$this->session->userdata("id"),"date"=>$this->input->post("date"),"title"=>$this->input->post("title"),"content"=>$this->input->post("contant"));
	$this->articles_model->add_article($data);
	$this->session->set_flashdata('type', 'succ');
	redirect("./panel/Articles");
	}else{
				$this->session->sess_destroy();
				redirect("./");
			}

		}else{
			$this->session->sess_destroy();
			redirect("./");
		}
}
public function list_articles(){
	if($this->session->userdata("canlogin") == "yes"){
			if($this->session->userdata("browser") == $this->agent->browser() && $this->session->userdata("version") == $this->agent->version() && $this->session->userdata("ip") == $this->input->ip_address() && ($this->session->userdata("per") == 4 || $this->session->userdata("per") == 1)){
	$this->load->model('articles_model');
	$result = $this->articles_model->get_articles($this->session->userdata("id"));
	$this->load->view('list_maghalat',array("username" =>$this->session->userdata("username"),"fullname"=>$this->session->userdata("fullname"),
									   "result"=>$result
												));
	}else{
				$this->session->sess_destroy();
				redirect("./");
			}

		}else{
			$this->session->sess_destroy();
			redirect("./");
		}
}
public function edit_articles(){
	if($this->session->userdata("canlogin") == "yes"){
			if($this->session->userdata("browser") == $this->agent->browser() && $this->session->userdata("version") == $this->agent->version() && $this->session->userdata("ip") == $this->input->ip_address() && ($this->session->userdata("per") == 4 || $this->session->userdata("per") == 1)){
	$this->load->model('articles_model');
	$result = $this->articles_model->get_article_one($this->input->get("id"),$this->session->userdata("id"));
	if(count($result) == 0){
		$this->load->view('errors/html/404',array("heading"=>"صفحه ی مورد نظر یافت نشد","message"=>'<a href="'.base_url().'panel/list_articles">برای بازگشت کلیک کنید.</a>'));
	}else{
	$this->load->view('edit_maghalat',array("username" =>$this->session->userdata("username"),"fullname"=>$this->session->userdata("fullname"),
									   "result"=>$result
												));
	}
	}else{
				$this->session->sess_destroy();
				redirect("./");
			}

		}else{
			$this->session->sess_destroy();
			redirect("./");
		}
}
public function delete_article_control(){
	if($this->session->userdata("canlogin") == "yes"){
			if($this->session->userdata("browser") == $this->agent->browser() && $this->session->userdata("version") == $this->agent->version() && $this->session->userdata("ip") == $this->input->ip_address() && ($this->session->userdata("per") == 4 || $this->session->userdata("per") == 1)){
	$this->load->model("articles_model");
		$this->articles_model->delete_article($this->input->post("id"));
		echo "done";
		}else{
				$this->session->sess_destroy();
				redirect("./");
			}

		}else{
			$this->session->sess_destroy();
			redirect("./");
		}
}
public function edit_articles_control(){
	if($this->session->userdata("canlogin") == "yes"){
			if($this->session->userdata("browser") == $this->agent->browser() && $this->session->userdata("version") == $this->agent->version() && $this->session->userdata("ip") == $this->input->ip_address() && ($this->session->userdata("per") == 4 || $this->session->userdata("per") == 1)){
	$this->load->model('articles_model');
	$data = array("date"=>$this->input->post("date"),"title"=>$this->input->post("title"),"content"=>$this->input->post("contant"));
	$result = $this->articles_model-> update_article($this->input->post("id"),$this->session->userdata("id"),$data);
	$this->session->set_flashdata('type', 'succ');
	redirect("./panel/edit_articles?id=".$this->input->post("id"));
	}else{
				$this->session->sess_destroy();
				redirect("./");
			}

		}else{
			$this->session->sess_destroy();
			redirect("./");
		}
}
public function galery(){
	if($this->session->userdata("canlogin") == "yes"){
			if($this->session->userdata("browser") == $this->agent->browser() && $this->session->userdata("version") == $this->agent->version() && $this->session->userdata("ip") == $this->input->ip_address() && ($this->session->userdata("per") == 4 || $this->session->userdata("per") == 1)){
	$this->load->helper('directory');
	$map = directory_map("./assets/data_images/drs/dr_galery/".$this->session->userdata("id"));
	$this->load->view('picture_galery',array("username" =>$this->session->userdata("username"),"fullname"=>$this->session->userdata("fullname"),
					"directory"=>$map
												));
	}else{
				$this->session->sess_destroy();
				redirect("./");
			}

		}else{
			$this->session->sess_destroy();
			redirect("./");
		}
}
public function set_galery_control(){
	if($this->session->userdata("canlogin") == "yes"){
			if($this->session->userdata("browser") == $this->agent->browser() && $this->session->userdata("version") == $this->agent->version() && $this->session->userdata("ip") == $this->input->ip_address() && ($this->session->userdata("per") == 4 || $this->session->userdata("per") == 1)){
	$imagename = rand(11111, 99999) . time();
		 $config['upload_path'] ="./assets/data_images/drs/dr_galery/".$this->session->userdata("id");
		

		$config['file_name'] = $imagename;
        $config['allowed_types'] = 'gif|jpg|png|jpeg';
		$type="image";
		  $this->load->library('upload', $config);

                if ( ! $this->upload->do_upload('uploadfile'))
                {
                   echo "not done";     
                }
                else
                {
                  $real_name = $imagename .$this->upload->data('file_ext');
                }
				redirect("./panel/galery");
				}else{
				$this->session->sess_destroy();
				redirect("./");
			}

		}else{
			$this->session->sess_destroy();
			redirect("./");
		}
}
public function delete_galery_control(){
	if($this->session->userdata("canlogin") == "yes"){
			if($this->session->userdata("browser") == $this->agent->browser() && $this->session->userdata("version") == $this->agent->version() && $this->session->userdata("ip") == $this->input->ip_address() && ($this->session->userdata("per") == 4 || $this->session->userdata("per") == 1)){
	$path = "./assets/data_images/drs/dr_galery/".$this->session->userdata("id")."/".$this->input->post("filename");
	unlink($path);
	echo "done";
	}else{
				$this->session->sess_destroy();
				redirect("./");
			}

		}else{
			$this->session->sess_destroy();
			redirect("./");
		}
}
public function appointment(){
	if($this->session->userdata("canlogin") == "yes"){
			if($this->session->userdata("browser") == $this->agent->browser() && $this->session->userdata("version") == $this->agent->version() && $this->session->userdata("ip") == $this->input->ip_address() && ($this->session->userdata("per") == 4 || $this->session->userdata("per") == 1)){
	$this->load->model("nobat_model");
	if($this->input->get("date")){
		$result = $this->nobat_model->get_nobat($this->session->userdata("id"),$this->input->get("date"));
	}else{
	$result = $this->nobat_model->get_nobat($this->session->userdata("id"),$this->persiandate->jdate("Ymd","","",'Asia/Tehran',"en"));
	}
	//die($result);
	$this->load->view('nobatdehi',array("username" =>$this->session->userdata("username"),"fullname"=>$this->session->userdata("fullname"),
							"data"=>$result,"today"=>$this->persiandate->jdate("d/m/Y","","",'Asia/Tehran',"en")));
	}else{
				$this->session->sess_destroy();
				redirect("./");
			}

		}else{
			$this->session->sess_destroy();
			redirect("./");
		}
}
public function set_appointment_control(){
	if($this->session->userdata("canlogin") == "yes"){
			if($this->session->userdata("browser") == $this->agent->browser() && $this->session->userdata("version") == $this->agent->version() && $this->session->userdata("ip") == $this->input->ip_address() && ($this->session->userdata("per") == 4 || $this->session->userdata("per") == 1)){
	$date = $this->input->post("date");
	$time = $this->input->post("time");
	$name = $this->input->post("name");
	$date_year = $date[6].$date[7].$date[8].$date[9];
	$date_mon = $date[3].$date[4];
	$date_day = $date[0].$date[1];
	$hour = $time[0].$time[1];
	$min = $time[3].$time[4];
	$day = $this->persiandate->jalali_to_gregorian($date_year,$date_mon,$date_day);
	if($day[1] < 10){
		$day[1] = "0" . $day[1];
	}
	if($day[2] < 10){
		$day[2] = "0" . $day[2];
	}
	$convert_day = $day[0]."-".$day[1]."-".$day[2]."T".$hour.":".$min.":00";
	$normal_date =$date_year . $date_mon . $date_day;
	$this->load->model("nobat_model");
	$data = array("uid"=>$this->session->userdata("id"),"po_name"=>$name,"po_date_ISO8601"=>$convert_day,"po_date"=>$normal_date,"po_status"=>2,"po_time"=>$time);
	$this->nobat_model->set_nobat($data);
	echo "done";
	}else{
				$this->session->sess_destroy();
				redirect("./");
			}

		}else{
			$this->session->sess_destroy();
			redirect("./");
		}
}
public function set_appointment_control_ajax(){
	if($this->session->userdata("canlogin") == "yes"){
			if($this->session->userdata("browser") == $this->agent->browser() && $this->session->userdata("version") == $this->agent->version() && $this->session->userdata("ip") == $this->input->ip_address() && ($this->session->userdata("per") == 4 || $this->session->userdata("per") == 1)){
	$date = $this->input->post("date");
	$time = $this->input->post("time");
	$name = $this->input->post("name");
	$this->load->model("nobat_model");
	$hour = $time[0].$time[1];
	$min = $time[3].$time[4];
	$date_year = $date[0].$date[1].$date[2].$date[3];
	$date_mon = $date[4].$date[5];
	$date_day = $date[6].$date[7];
	$day = $this->persiandate->gregorian_to_jalali($date_year,$date_mon,$date_day);
	if($day[1] < 10){
		$day[1] = "0" . $day[1];
	}
	if($day[2] < 10){
		$day[2] = "0" . $day[2];
	}
	$normal_date = $day[0].$day[1].$day[2];
	$convert_day = $date_year."-".$date_mon."-".$date_day."T".$hour.":".$min.":00";
	$data = array("uid"=>$this->session->userdata("id"),"po_name"=>$name,"po_date_ISO8601"=>$convert_day,"po_date"=>$normal_date,"po_status"=>2,"po_time"=>$time);
	$this->nobat_model->set_nobat($data);
	echo "done";
	}else{
				$this->session->sess_destroy();
				redirect("./");
			}

		}else{
			$this->session->sess_destroy();
			redirect("./");
		}
}
public function update_appointment_date_ajax(){
	if($this->session->userdata("canlogin") == "yes"){
			if($this->session->userdata("browser") == $this->agent->browser() && $this->session->userdata("version") == $this->agent->version() && $this->session->userdata("ip") == $this->input->ip_address() && ($this->session->userdata("per") == 4 || $this->session->userdata("per") == 1)){
	$this->load->model("nobat_model");
	$date = $this->input->post("date");
	$id = $this->input->post("id");
	$po_date_ISO8601 = $date;
	$date_year = $date[0].$date[1].$date[2].$date[3];
	$date_mon = $date[5].$date[6];
	$date_day = $date[8].$date[9];
	$day = $this->persiandate->gregorian_to_jalali($date_year,$date_mon,$date_day);
	if($day[1] < 10){
		$day[1] = "0" . $day[1];
	}
	if($day[2] < 10){
		$day[2] = "0" . $day[2];
	}
	$po_date = $day[0].$day[1].$day[2];
	$data = array("po_date_ISO8601"=>$po_date_ISO8601,"po_date"=>$po_date);
	$this->nobat_model->update_nobat($id,$data);
	}else{
				$this->session->sess_destroy();
				redirect("./");
			}

		}else{
			$this->session->sess_destroy();
			redirect("./");
		}
}
public function delete_appointment(){
	if($this->session->userdata("canlogin") == "yes"){
			if($this->session->userdata("browser") == $this->agent->browser() && $this->session->userdata("version") == $this->agent->version() && $this->session->userdata("ip") == $this->input->ip_address() && ($this->session->userdata("per") == 4 || $this->session->userdata("per") == 1)){
	$this->load->model("nobat_model");
	 $id = $this->input->post("id");
	 $this->nobat_model->delete_nobat($id);
	 echo "done";
	 }else{
				$this->session->sess_destroy();
				redirect("./");
			}

		}else{
			$this->session->sess_destroy();
			redirect("./");
		}
}
public function update_appointment(){
	if($this->session->userdata("canlogin") == "yes"){
			if($this->session->userdata("browser") == $this->agent->browser() && $this->session->userdata("version") == $this->agent->version() && $this->session->userdata("ip") == $this->input->ip_address() && ($this->session->userdata("per") == 4 || $this->session->userdata("per") == 1)){
	$this->load->model("nobat_model");
	 $id = $this->input->post("id");
	 $date = $this->input->post("date");
	 $time = $this->input->post("time");
	$date_year = $date[6].$date[7].$date[8].$date[9];
	$date_mon = $date[3].$date[4];
	$date_day = $date[0].$date[1];
	$date = $date_year.$date_mon.$date_day;
	$day = $this->persiandate->jalali_to_gregorian($date_year,$date_mon,$date_day);
	if($day[1] < 10){
		$day[1] = "0" . $day[1];
	}
	if($day[2] < 10){
		$day[2] = "0" . $day[2];
	}
	$po_date_ISO8601 = $day[0]."-".$day[1]."-".$day[2]."T".$time.":00";
	 $data = array("po_date"=>$date,"po_time"=>$time,"po_date_ISO8601"=>$po_date_ISO8601);
	 $this->nobat_model-> update_nobat($id,$data);
	 echo "done";
	 }else{
				$this->session->sess_destroy();
				redirect("./");
			}

		}else{
			$this->session->sess_destroy();
			redirect("./");
		}
}
public function general_setting(){
	if($this->session->userdata("canlogin") == "yes"){
			if($this->session->userdata("browser") == $this->agent->browser() && $this->session->userdata("version") == $this->agent->version() && $this->session->userdata("ip") == $this->input->ip_address() && ($this->session->userdata("per") == 4 || $this->session->userdata("per") == 1)){
	$this->load->model('general_model');
	$data = $this->general_model->get_setting($this->session->userdata("id"));
	$this->load->view('general_setting',array("username" =>$this->session->userdata("username"),"fullname"=>$this->session->userdata("fullname")
							,"today"=>$this->persiandate->jdate("d/m/Y","","",'Asia/Tehran',"en"),"info"=>$data ));
	}else{
				$this->session->sess_destroy();
				redirect("./");
			}

		}else{
			$this->session->sess_destroy();
			redirect("./");
		}
}
public function control_setting(){
	if($this->session->userdata("canlogin") == "yes"){
			if($this->session->userdata("browser") == $this->agent->browser() && $this->session->userdata("version") == $this->agent->version() && $this->session->userdata("ip") == $this->input->ip_address() && ($this->session->userdata("per") == 4 || $this->session->userdata("per") == 1)){
	$this->load->model('general_model');
	if($this->input->post("start_time")){
		$start_time = $this->input->post("start_time");
	}else{
		$start_time = "";
	}
	if($this->input->post("end_time")){
		$end_time = $this->input->post("end_time");
	}else{
		$end_time = "";
	}
	if($this->input->post("visitavg_time")){
		$visitavg_time = $this->input->post("visitavg_time");
	}else{
		$visitavg_time = "";
	}
	if($this->input->post("doc_number")){
		$doc_number = $this->input->post("doc_number");
	}else{
		$doc_number = "";
	}
	if($this->input->post("day_add")){
		$day_add = rtrim($this->input->post("day_add"),",");
	}else{
		$day_add = "";
	}
	$data = array("uid"=>$this->session->userdata("id"),"day_work"=>$day_add,"time_work_s"=>$start_time,"time_work_e"=>$end_time,"time_visit_avg"=>$visitavg_time,"doc_number_s"=>$doc_number);
	$this->general_model->delete_setting($this->session->userdata("id"));
	$this->general_model->insert_setting($data);
	redirect("./panel/general_setting");
	}else{
				$this->session->sess_destroy();
				redirect("./");
			}

		}else{
			$this->session->sess_destroy();
			redirect("./");
		}
}
public function control_robat_program(){
	if($this->session->userdata("canlogin") == "yes"){
			if($this->session->userdata("browser") == $this->agent->browser() && $this->session->userdata("version") == $this->agent->version() && $this->session->userdata("ip") == $this->input->ip_address() && ($this->session->userdata("per") == 4 || $this->session->userdata("per") == 1)){
	$this->load->model('telegram_model');
	$this->load->model('nobat_model');
	$id = $this->input->post("id");
	$token = $this->telegram_model->get_token_buid($this->session->userdata("id"));
	$time = $this->input->post("time");
	$message = $this->input->post("message");
	$date = $this->input->post("date");
	$date = explode("-",$date);
	$date = $this->persiandate->gregorian_to_jalali($date[2],$date[0],$date[1]);
	$date = $date[0]. "/" . $date[1] . "/" . $date[2];
	$status = $this->input->post("status");
	$telegram_id = $this->nobat_model->telegram_infonobatdehi_get($id);
	$telegram_id = $telegram_id[0]->telegramid;
	$data = array("po_status"=>$status,"po_time"=>$time);
	$this->nobat_model->update_nobat($id,$data);
	if($status == "3"){
		$this->telegram_model->send_message_only($token,$telegram_id," نوبت شما برای روز".$date." و ساعت ".$time. "تایید شد.");
	}else{
		$this->telegram_model->send_message_only($token,$telegram_id,"نوبت شما رد شد.");
	}
	$this->telegram_model->send_message_only($token,$telegram_id,$message);
	echo "done";
	}else{
				$this->session->sess_destroy();
				redirect("./");
			}

		}else{
			$this->session->sess_destroy();
			redirect("./");
		}
}
public function send_message(){
	if($this->session->userdata("canlogin") == "yes"){
			if($this->session->userdata("browser") == $this->agent->browser() && $this->session->userdata("version") == $this->agent->version() && $this->session->userdata("ip") == $this->input->ip_address() && ($this->session->userdata("per") == 4 || $this->session->userdata("per") == 1)){
	$this->load->model('telegram_model');
	$tellid = $this->input->post("tellid");
	$message = $this->input->post("message");
	$token = $this->telegram_model->get_token_buid($this->session->userdata("id"));
	$this->telegram_model->send_message_only($token,$tellid,$message);
	echo "done";
	}else{
				$this->session->sess_destroy();
				redirect("./");
			}

		}else{
			$this->session->sess_destroy();
			redirect("./");
		}
}
public function nobatdehi_status_controls(){
	if($this->session->userdata("canlogin") == "yes"){
			if($this->session->userdata("browser") == $this->agent->browser() && $this->session->userdata("version") == $this->agent->version() && $this->session->userdata("ip") == $this->input->ip_address() && ($this->session->userdata("per") == 4 || $this->session->userdata("per") == 1)){
	$this->load->model('nobat_model');
	if($this->input->post("type") == "done"){
		$data = array("visit_status"=>3);
		$id = $this->input->post("id");
		$this->nobat_model->update_nobat($id,$data);
		$result = $this->nobat_model->get_nobat_byorder($this->session->userdata("id"),$this->persiandate->jdate("Ymd","","",'Asia/Tehran',"en"));
		 echo json_encode($result);
	}else if($this->input->post("type") == "resume"){
		echo "okeyeh baba";
		$data = array("visit_status"=>1);
		$id = $this->input->post("id");
		$this->nobat_model->update_nobat($id,$data);
		echo "done";
	}else if($this->input->post("type") == "play"){
		$data = array("visit_status"=>0);
		$id = $this->input->post("id");
		$this->nobat_model->update_nobat($id,$data);
		echo "done";
	}
	}else{
				$this->session->sess_destroy();
				redirect("./");
			}

		}else{
			$this->session->sess_destroy();
			redirect("./");
		}
}
public function checkajaxnobat(){
	if($this->session->userdata("canlogin") == "yes"){
			if($this->session->userdata("browser") == $this->agent->browser() && $this->session->userdata("version") == $this->agent->version() && $this->session->userdata("ip") == $this->input->ip_address() && ($this->session->userdata("per") == 4 || $this->session->userdata("per") == 1)){
	$this->load->model('nobat_model');
	$nobatcounter = count($this->nobat_model->get_nobat_all($this->session->userdata("id")));
	if($nobatcounter > $this->input->post("nobat_count")){
		echo "update";
	}else{
		echo "null";
	}
	}else{
				$this->session->sess_destroy();
				redirect("./");
			}

		}else{
			$this->session->sess_destroy();
			redirect("./");
		}
}
public function contact(){
	if($this->session->userdata("canlogin") == "yes"){
			if($this->session->userdata("browser") == $this->agent->browser() && $this->session->userdata("version") == $this->agent->version() && $this->session->userdata("ip") == $this->input->ip_address() && ($this->session->userdata("per") == 4 || $this->session->userdata("per") == 1)){
	$this->load->model("contact_model");
	$contact_result = $this->contact_model->get_contact($this->session->userdata("id"));
	$this->load->view('contact_setting',array("username" =>$this->session->userdata("username"),"fullname"=>$this->session->userdata("fullname")
							,"today"=>$this->persiandate->jdate("d/m/Y","","",'Asia/Tehran',"en"), "contact"=>$contact_result )) ;
}else{
				$this->session->sess_destroy();
				redirect("./");
			}

		}else{
			$this->session->sess_destroy();
			redirect("./");
		}
}
public function set_contact(){
	if($this->session->userdata("canlogin") == "yes"){
			if($this->session->userdata("browser") == $this->agent->browser() && $this->session->userdata("version") == $this->agent->version() && $this->session->userdata("ip") == $this->input->ip_address() && ($this->session->userdata("per") == 4 || $this->session->userdata("per") == 1)){
	$this->load->model("contact_model");
	
	if($this->contact_model->is_contact($this->session->userdata("id"))){
	$data = array("phone"=>$this->input->post("phone"),"address"=>$this->input->post("address"),"discription"=>$this->input->post("discription"));
		$this->contact_model->update_contact($this->session->userdata("id"),$data);
	}else{
		$data = array("uid"=>$this->session->userdata("id"),"phone"=>$this->input->post("phone"),"address"=>$this->input->post("address"),"discription"=>$this->input->post("discription"));
		$this->contact_model->set_contact($data);
	}
	redirect("./panel/contact");
	}else{
				$this->session->sess_destroy();
				redirect("./");
			}

		}else{
			$this->session->sess_destroy();
			redirect("./");
		}
}
public function set_khadamat(){
	if($this->session->userdata("canlogin") == "yes"){
			if($this->session->userdata("browser") == $this->agent->browser() && $this->session->userdata("version") == $this->agent->version() && $this->session->userdata("ip") == $this->input->ip_address() && ($this->session->userdata("per") == 4 || $this->session->userdata("per") == 1)){
	$this->load->model('finance_model');
	$khadamat = $this->finance_model->get_khadamat($this->session->userdata("id"));
	$this->load->view('set_khadamat',array("username" =>$this->session->userdata("username"),"fullname"=>$this->session->userdata("fullname"),
											"khadamat"=>$khadamat	));
	}else{
				$this->session->sess_destroy();
				redirect("./");
			}

		}else{
			$this->session->sess_destroy();
			redirect("./");
		}
}
public function set_khadamat_control(){
	if($this->session->userdata("canlogin") == "yes"){
			if($this->session->userdata("browser") == $this->agent->browser() && $this->session->userdata("version") == $this->agent->version() && $this->session->userdata("ip") == $this->input->ip_address() && ($this->session->userdata("per") == 4 || $this->session->userdata("per") == 1)){
	$this->load->model('finance_model');
	$this->finance_model->delete_khadamat($this->session->userdata("id"));
	for($i=1; $i <= $this->input->post("number");$i++ ){
		if($this->input->post("insurename".$i) !=""){
			$data = array("uid"=>$this->session->userdata("id"),"khdamat_name"=>$this->input->post("insurename".$i));
			$this->finance_model->set_khadamat($data);
		}
	}
	redirect("./panel/set_khadamat");
	}else{
				$this->session->sess_destroy();
				redirect("./");
			}

		}else{
			$this->session->sess_destroy();
			redirect("./");
		}
}
public function comesoon(){
	if($this->session->userdata("canlogin") == "yes"){
			if($this->session->userdata("browser") == $this->agent->browser() && $this->session->userdata("version") == $this->agent->version() && $this->session->userdata("ip") == $this->input->ip_address() && ($this->session->userdata("per") == 4 || $this->session->userdata("per") == 1)){
		$this->load->view('plugins/cunstroct',array("from"=>"panel"));
		}else{
				$this->session->sess_destroy();
				redirect("./");
			}

		}else{
			$this->session->sess_destroy();
			redirect("./");
		}
	}
public function messages(){
	if($this->session->userdata("canlogin") == "yes"){
			if($this->session->userdata("browser") == $this->agent->browser() && $this->session->userdata("version") == $this->agent->version() && $this->session->userdata("ip") == $this->input->ip_address() && ($this->session->userdata("per") == 4 || $this->session->userdata("per") == 1)){
	$this->load->model("telegram_model");
	$telegram_message = $this->telegram_model->get_telegram_message($this->session->userdata("id"));
	$this->load->view('moshavereh_payam',array("username" =>$this->session->userdata("username"),"fullname"=>$this->session->userdata("fullname"),
											   "messages"=>$telegram_message
												));
	}else{
				$this->session->sess_destroy();
				redirect("./");
			}

		}else{
			$this->session->sess_destroy();
			redirect("./");
		}
}
public function delete_messages(){
	if($this->session->userdata("canlogin") == "yes"){
			if($this->session->userdata("browser") == $this->agent->browser() && $this->session->userdata("version") == $this->agent->version() && $this->session->userdata("ip") == $this->input->ip_address() && ($this->session->userdata("per") == 4 || $this->session->userdata("per") == 1)){
	$this->load->model("telegram_model");
	$id = $this->input->post("id");
	$this->telegram_model->delete_telegram_message($id);
	echo "done";
	}else{
				$this->session->sess_destroy();
				redirect("./");
			}

		}else{
			$this->session->sess_destroy();
			redirect("./");
		}
}
public function finance_manager(){
	if($this->session->userdata("canlogin") == "yes"){
			if($this->session->userdata("browser") == $this->agent->browser() && $this->session->userdata("version") == $this->agent->version() && $this->session->userdata("ip") == $this->input->ip_address() && ($this->session->userdata("per") == 4 || $this->session->userdata("per") == 1)){
	$this->load->model("finance_model");
	$results = $this->finance_model->get_finance($this->session->userdata("id"));
	
	$this->load->view('finance_kol',array("username" =>$this->session->userdata("username"),"fullname"=>$this->session->userdata("fullname"),
										  "results"=>$results
												));
	}else{
				$this->session->sess_destroy();
				redirect("./");
			}

		}else{
			$this->session->sess_destroy();
			redirect("./");
		}
	
}
public function finance_update(){
	if($this->session->userdata("canlogin") == "yes"){
			if($this->session->userdata("browser") == $this->agent->browser() && $this->session->userdata("version") == $this->agent->version() && $this->session->userdata("ip") == $this->input->ip_address() && ($this->session->userdata("per") == 4 || $this->session->userdata("per") == 1)){
	$this->load->model("finance_model");
	$data = $this->input->post("data");
	$type = $this->input->post("type");
	if($type == "date"){
		$data = explode(",",$data);
		 $result = $this->finance_model->get_finance_bdate($this->session->userdata("id"),$data[0],$data[1]);
	}else{
		$result = $this->finance_model->search_finance($this->session->userdata("id"),$data);
	}
	echo json_encode($result);
	}else{
				$this->session->sess_destroy();
				redirect("./");
			}

		}else{
			$this->session->sess_destroy();
			redirect("./");
		}
}
}
?>