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



class Genel extends CI_Model
{

    private static $db;

    function __construct(){
        parent::__construct();
        self::$db = &get_instance()->db;

    }

static function token_uret($str = 8){
$karakterler = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
$sifre = substr( str_shuffle( $karakterler ), 0, $str );
return $sifre;
}
static function get_main_menu($start=0,$limit=100){
self::$db->where("onay",1);
self::$db->where("site_id",config_item("site_id"));
self::$db->order_by("siralama","ASC");
self::$db->limit($limit,$start);
return self::$db->select(self::site_dili()."_menu AS menu,link")->get("website_mice_menus")->result();
}

static function mice_gruplar(){

self::$db->where("mices_groups.site_id",config_item("site_id"));
self::$db->where("mices_groups.status",1);
self::$db->where("mices_groups.show_on_site",1);
self::$db->where("mices_groups.deleted",NULL);
self::$db->join("mices_groups_packages","mices_groups_packages.group_id=mices_groups.group_id");
self::$db->group_by("mices_groups_packages.package_id");
return self::$db->get("mices_groups")->result();
}

static function sistem_ayarlari($setting_id=0){
self::$db->where('setting_id',$setting_id);    
self::$db->select("setting_id,setting_name,value");
$sonuclarmain=self::$db->get("system_settings")->result();
$sonuclar_array=array();
foreach ($sonuclarmain as $sonuclar) {
$sonuclar_array[$sonuclar->setting_id]=$sonuclar->value;
}

if(isset($sonuclar_array[$setting_id])){
return $sonuclar_array[$setting_id];
}else{
return  false;  
}
}


static function site_bilgi(){
self::$db->where("site_id",config_item("site_id"));
return self::$db->get("website_mice")->row();
}

static function get_apikey(){
$kullanici_id=self::site_bilgi()->user_id;

self::$db->where("id",$kullanici_id);
$sonuc=self::$db->select("apikey")->get("system_users")->row();

if(is_null($sonuc)){
return "";	
}else{
return $sonuc->apikey;	
}
}


static function grup_detay($paket_id){

self::$db->where("mices_groups.site_id",config_item("site_id"));
self::$db->where("mices_groups.status",1);
self::$db->where("mices_groups.show_on_site",1);
self::$db->where("mices_groups.sealing",0);

self::$db->where("mices_groups_packages.package_id",$paket_id);

self::$db->join("mices_groups_packages","mices_groups_packages.group_id=mices_groups.group_id");
self::$db->group_by("mices_groups_packages.package_id");
$sonuc=self::$db->get("mices_groups")->row();
//print_r($sonuc);
if(is_null($sonuc)){
redirect("/");	
}
return $sonuc;
}


static function site_dili(){
 $ci =& get_instance();    
return $ci->lang->line('lang_code');
}

static function dil_ceviri($line=NULL){
 $ci =& get_instance();     
return $ci->lang->line($line);
}

static function get_company_info(){
return self::$db->where("site_id",config_item("site_id"))->get("website_mice")->row();
}

static function otel_detay($otel_id){
//

self::$db->where("hotels.hotel_id",$otel_id);	
self::$db->where("hotels_translation.lang",strtolower(self::site_dili()));  
 self::$db->join('hotels_translation','hotels_translation.hotel_id=hotels.hotel_id');
return self::$db->get("hotels")->row();
}

static function otel_fotolari($otel_id){
self::$db->where("hotel_id",$otel_id);	
return self::$db->get("hotels_photos")->result();	
}

static function otel_bilgileri($otel_id){
self::$db->where("hotel_id",$otel_id);	
return self::$db->get("hotels_details")->result();	
}
static function tesisler($otel_id){



self::$db->where("oteller_otel_listesi.otel_id",$otel_id);
return self::$db->select("oteller_otel_listesi.otel_id,oteller_otel_listesi.seo,oteller_otel_listesi.otel_adi,oteller_otel_listesi.vitrin_resmi")->get("oteller_otel_listesi")->result();
}




static function fiyat_listesi($paket_id=0){
self::$db->Where("package_id", $paket_id);
$query=self::$db->get("mices_groups_packages_prices");
$fiyatlar=$query->result();

//print_r($fiyatlar);
$fiyatlar_array=array();
foreach ($fiyatlar as $fiyatlar) {



self::$db->from("mices_groups_packages_prices_child_discounts");
self::$db->Where("group_id", $fiyatlar->group_id);
self::$db->Where("sort",1);
$query=self::$db->get();
$birincicocuk=$query->result();
$birincicocuk_array=array();
foreach ($birincicocuk as $birincicocuk) {
$birincicocuk_array[]=array("yas1"=>$birincicocuk->age_1,
							"yas2"=>$birincicocuk->age_2,
							"ucret"=>$birincicocuk->price);
}



self::$db->from("mices_groups_packages_prices_child_discounts");
self::$db->Where("group_id", $fiyatlar->group_id);
self::$db->Where("sort",2);
$query=self::$db->get();
$birincicocuk=$query->result();
$ikincicocuk_array=array();
foreach ($birincicocuk as $birincicocuk) {
$ikincicocuk_array[]=array("yas1"=>$birincicocuk->age_1,
							"yas2"=>$birincicocuk->age_2,
							"ucret"=>$birincicocuk->price);
}


$fiyatlar_array[]=array("giris_tarihi"=>date("d-m-Y",strtotime($fiyatlar->checkin_date)),
						
						"geceleme"=>$fiyatlar->night,
						"kisi_basi"=>$fiyatlar->double_room,
						"tek_kisi"=>$fiyatlar->single_room,
						"ek_yatak"=>$fiyatlar->triple_room,
						"paylasimli_oda"=>$fiyatlar->shared_room,
						"kur"=>$fiyatlar->currency,
						"birinci_cocuk"=>$birincicocuk_array,
						"ikinci_cocuk"=>$ikincicocuk_array

	);

}


//print_r($fiyatlar_array);

return $fiyatlar_array;

}


static function paketler($paket_id){
self::$db->where("mices_groups_packages_prices.sales_start<=",date("Y-m-d"));
self::$db->where("mices_groups_packages_prices.sales_end>=",date("Y-m-d"));
self::$db->where("mices_groups_packages_prices.package_id",$paket_id);
   self::$db->where("mices_groups_packages_prices.deleted",null);
self::$db->group_by("mices_groups_packages_prices.price_id");
return self::$db->select("*")->get("mices_groups_packages_prices")->result();


}


static function kontenjanlar($grup_id){
self::$db->where("mice_mice_gruplar_paketler.durum",1);
self::$db->where("mice_mice_gruplar_paketler.grup_id",$grup_id);
$paketler=self::$db->get("mice_mice_gruplar_paketler")->result();

return $paketler;
}

static function kullanilan_kontenjanlar($grupum_id,$kategori_id){

self::$db->where('reservations.reservation_type>',0);
self::$db->where('reservations.process_step>',5);
self::$db->where('reservations.process_step<',8);
self::$db->where('reservations.isbasket',0);
self::$db->where('reservations.ispassive',0);
self::$db->where('reservations.deleted',NULL);


self::$db->where('reservations_products_mice.category_id',config_item("site_id"));
self::$db->where('reservations_products_mice.group_id',$grupum_id);

self::$db->join('reservations_products_mice',"reservations_products_mice.token=reservations.token");
self::$db->join('reservations_products_mice_paxes',"reservations_products_mice_paxes.token=reservations_products_mice.token and reservations_products_mice_paxes.mice_token=reservations_products_mice.mice_token");
self::$db->group_by("reservations_products_mice_paxes.Id");
return  self::$db->select("count(reservations_products_mice_paxes.Id) AS total")->get('reservations')->row();




}



static function tckontrol_degistir($deger){

$search  = array('a', 'b', 'c', 'ç', 'd','e','f','g','ğ','h','ı','i','j','k','l','m','n','o','ö','p','r','s','ş','t','u','ü','v','y','z');
$replace  = array('A', 'B', 'C', 'Ç', 'D','E','F','G','Ğ','H','I','İ','J','K','L','M','N','O','Ö','P','R','S','Ş','T','U','Ü','V','Y','Z');
$sonuc=str_replace($search, $replace, $deger);
return $sonuc; 
}



static function tcno_dogrula($bilgiler){


    
        $gonder = '<?xml version="1.0" encoding="utf-8"?>
        <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
        <soap:Body>
        <TCKimlikNoDogrula xmlns="http://tckimlik.nvi.gov.tr/WS">
        <TCKimlikNo>'.$bilgiler["tcno"].'</TCKimlikNo>
        <Ad>'.$bilgiler["isim"].'</Ad>
        <Soyad>'.$bilgiler["soyisim"].'</Soyad>
        <DogumYili>'.$bilgiler["dogumyili"].'</DogumYili>
        </TCKimlikNoDogrula>
        </soap:Body>
        </soap:Envelope>';
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL,            "https://tckimlik.nvi.gov.tr/Service/KPSPublic.asmx" );
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true );
        curl_setopt($ch, CURLOPT_POST,           true );
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_HEADER, FALSE);
        curl_setopt($ch, CURLOPT_POSTFIELDS,    $gonder);
        curl_setopt($ch, CURLOPT_HTTPHEADER,     array(
        'POST /Service/KPSPublic.asmx HTTP/1.1',
        'Host: tckimlik.nvi.gov.tr',
        'Content-Type: text/xml; charset=utf-8',
        'SOAPAction: "http://tckimlik.nvi.gov.tr/WS/TCKimlikNoDogrula"',
        'Content-Length: '.strlen($gonder)
        ));
        $gelen = curl_exec($ch);
        curl_close($ch);
        return strip_tags($gelen);
    }


static function kullanilan_kontenjan($grup_id,$kategori_id){

self::$db->where("rezervasyonlar_urunler_mice.islem_basamagi>",5);
self::$db->where("rezervasyonlar_urunler_mice.islem_basamagi<",8);
self::$db->where("rezervasyonlar_urunler_mice.kategori_id",$kategori_id);
self::$db->where("rezervasyonlar_urunler_mice.grup_id",$grup_id);
self::$db->join("reservations_products_mice_paxes","reservations_products_mice_paxes.token=rezervasyonlar_urunler_mice.token and rezervasyonlar_urunler_mice.mice_token=reservations_products_mice_paxes.mice_token");
$sonuc=self::$db->select("count(reservations_products_mice_paxes.kisi_token) AS toplam")->get("rezervasyonlar_urunler_mice")->row();

//print_r($sonuc);
return $sonuc->toplam;
}


}

/* End of file model.php */
