<?php
function turkceYap($s) {
    $tr = array('ş','Ş','ı','I','İ','ğ','Ğ','ü','Ü','ö','Ö','Ç','ç','(',')','/',':',',','?','&');
    $eng = array('s','s','i','i','i','g','g','u','u','o','o','c','c','','','-','-','','-','-');
    $s = str_replace($tr,$eng,$s);
    $s = strtolower($s);
    $s = preg_replace('/&amp;amp;amp;amp;amp;amp;amp;amp;amp;.+?;/', '', $s);
    $s = preg_replace('/\s+/', '-', $s);
    $s = preg_replace('|-+|', '-', $s);
    $s = preg_replace('/#/', '', $s);
    $s = str_replace('.', '', $s);
    $s = trim($s, '-');
    return $s;
}



function get_full_name($tablo,$veriid, $alan,$veriadi)
{
    $ci=&get_instance();
    $ci->load->database();
    $ci->db->select('*');
    $ci->db->where($alan, $veriid);
    $row = $ci->db->get($tablo)->row();
    $fullName = $row->$veriadi;
    return $fullName;
}


function get_active_user() {
    $t=&get_instance();

    $user = $t->session->userdata("user");
    if ($user)
    {
        return $user;
    }
    else {
        return false;
    }
}



function tarihcevir($OrjinalTarih) {
    $CevrilenTarih = explode("-",$OrjinalTarih);
    $degistirLg1  = array("01"=>"Ocak","02"=>"Şubat","03"=>"Mart","04"=>"Nisan","05"=>"Mayıs","06"=>"Haziran","07"=>"Temmuz","08"=>"Ağustos","09"=>"Eylül","10"=>"Ekim","11"=>"Kasım","12"=>"Aralık");
    $Yeniay = strtr($CevrilenTarih[1], $degistirLg1);
    return $CevrilenTarih[2].'.'.$CevrilenTarih[1].'.'.$CevrilenTarih[0];
    //TarihCevir ($YeniTarih,$VTCtarih);
}


function sifre_uretici($kacbasamak)
{
    $alphabet = '1234567890ABCDEFGHXYZQLPUMNCVabcdefghxyzqlpumncv';
    $password = array();
    $alpha_length = strlen($alphabet) - 1;
    for ($i = 0; $i < $kacbasamak; $i++)
    {
        $n = rand(0, $alpha_length);
        $password[] = $alphabet[$n];
    }
    return implode($password);
}




function mail_send ($toEmail = "", $subject = "", $message = "") 
{
    $t =&get_instance();

    $t->load->model("emailsettings_model");
               

    $emailinfo = $t->emailsettings_model->get(
        array
        (
            "isactive" => 1
        ),  "id DESC","LIMIT 0,1"
    );


    $config = array
    (
        "protocol"  => $emailinfo->protocol,
        "smtp_host" => $emailinfo->host,
        "smtp_port" => $emailinfo->port,
        "smtp_user" => $emailinfo->user,
        "smtp_pass" => $emailinfo->password,
        "starttls"  => true,
        "charset"   => "utf-8",
        "mailtype"  => "html",
        "wordwrap"  => true,
        "newline"   => "\r\n"
    );


    $t->load->library("email", $config);
    $t->email->from($emailinfo->fromm, $emailinfo->username);
    $t->email->to($toEmail);
    $t->email->subject($subject);
    $t->email->message($message);

    return $t->email->send();
}



function get_settings()
{
    $t = &get_instance();
    $t->load->model("ayarlar_model");
    $ayar = $t->ayarlar_model->get();
    return $ayar;
}





function get_category($parent_id = 0, $str = 0)
{
    $t = &get_instance(); 

    $t->load->database();

    $t->db->select('*');
    $t->db->from('kategori');
    $t->db->where('ustid', $parent_id);
    $result = $t->db->get()->result();

    if ($result)
    {
        foreach ($result as $mainCategory)
        {
            if ($mainCategory->ustid == 0) {$color = "red";} else {$color = "black";}
            echo "<option style='color:{$color}; font-size:13pt;' value=".$mainCategory->id.">".str_repeat('>',$str).$mainCategory->baslik_tr."</option>";
            get_category($mainCategory->id,$str+2);
        }
    }
}



function get_settings_front()
{
    $t = &get_instance();

    $ayarlar = $t->session->userdata('item');
    if (empty($ayarlar))
    {
        $t->load->model('ayarlar_model');
        $ayarlar = $t->ayarlar_model->get();
        $t->session->set_userdata('ayarlar', $ayarlar);
    }
    return $ayarlar;
}





function get_image_cover($urunid,$kind)
{
    $t = &get_instance();
    
    $t->load->model('imageupload_model');

    $kapak_resmi = $t->imageupload_model->get(
        array 
        (
            "isCover" => 1,
            "urunid"  => $urunid,
            "kind"    => $kind      
        )
    );

    if (empty($kapak_resmi))
    {
        $kapak_resmi = $t->imageupload_model->get
        (
            array 
            (
                "urunid"  => $urunid,
                "kind"    => $kind      
            )  
        );
    }
    return !empty($kapak_resmi) ? $kapak_resmi->resim : "";

}


?>
