<?php
function alamat($text)
{
	$text=str_replace(" ", "-", $text);
	$text=str_replace("?", "-", $text);
	$text=str_replace("!", "-", $text);
	$text=str_replace(",", "-", $text);
	$text=str_replace("'", "-", $text);
	$text=str_replace("$", "-", $text);
	$text=str_replace("=", "-", $text);
	$text=str_replace("/", "-", $text);
	$text=str_replace("@", "-", $text);
	
	return $text;
}

function total($tabel)
{
	$ci =&get_instance();
	$d_pas = $ci->load->database('default', TRUE);
    $a=$d_pas->query("SELECT sum(nominal) as tot FROM $tabel where v='1'");
    
	if($a -> num_rows() >0){
	$row=$a->row();
	$b=$row->tot;
	}
	else{
		$b="0";
	}
	
	return $b;
	
}

function siswa($tapel, $kelkd)
{
	$ci =&get_instance();
	$d_pas = $ci->load->database('sim', TRUE);
    $a=$d_pas->query("SELECT m_siswa.*, m_siswa_tmp_tinggal.* ".
			"FROM m_siswa, siswa_kelas, m_siswa_tmp_tinggal ".
			"WHERE siswa_kelas.kd_siswa = m_siswa.kd ".
			"AND m_siswa_tmp_tinggal.kd_siswa = m_siswa.kd ".
			"AND siswa_kelas.kd_tapel = '$tapel' ".
			"AND siswa_kelas.kd_kelas = '$kelkd' ".
			"ORDER BY round(siswa_kelas.no_absen) ASC, m_siswa.nama asc");
    
	return $a->result();
	
}

function guru()
{
	$ci =&get_instance();
	$d_pas = $ci->load->database('sim', TRUE);
    $a=$d_pas->query("SELECT * from m_guru, m_pegawai where m_pegawai.kd=m_guru.kd_pegawai group by kd_pegawai order by nama");
    
	return $a->result();
	
}

function tapel()
{
	$ci =&get_instance();
	$d_pas = $ci->load->database('sim', TRUE);
    $a=$d_pas->query("SELECT m_tapel.* from m_tapel, siswa_kelas where siswa_kelas.kd_tapel=m_tapel.kd group by kd_tapel order by tahun1 asc");
    
	return $a->result();
	
}

function kelas()
{
	$ci =&get_instance();
	$d_pas = $ci->load->database('sim', TRUE);
    $a=$d_pas->query("SELECT m_kelas.* from m_kelas, siswa_kelas where siswa_kelas.kd_kelas=m_kelas.kd group by kd_kelas order by kelas asc");
    
	return $a->result();
	
}

function bukutamu()
{
	$ci =&get_instance();
	$d_pas = $ci->load->database('default', TRUE);
    $a=$d_pas->query("SELECT * from at_bukutamu where balas!='' order by waktu desc");
    
	return $a->result();
	
}

function balik($tabel, $tampil, $kunci, $harus)
{
	$ci =&get_instance();
	$d_pas = $ci->load->database('default', TRUE);
    $a=$d_pas->query("SELECT $tampil FROM $tabel where $kunci='$harus'");
    
	if($a -> num_rows() >0){
	$row=$a->row();
	$b=$row->$tampil;
	}
	else{
		$b="";
	}
	
	return $b;
	
}


function berita($kode, $jum)
{
	$ci =&get_instance();
	$d_pas = $ci->load->database('default', TRUE);
    $a=$d_pas->query("select * from at_berita where tipe='$kode' order by urut asc, tanggal desc limit $jum");
    
	return $a->result();
	
}

function loncat()
{
	$ci =&get_instance();
	$d_pas = $ci->load->database('default', TRUE);
    $a=$d_pas->query("select * from at_loncat");
    
	return $a->result();
	
}

function berita_depan($kode)
{
	$ci =&get_instance();
	$d_pas = $ci->load->database('default', TRUE);
    $a=$d_pas->query("select * from at_berita where tipe='$kode' and depan='1' order by tanggal desc");
    
	return $a->result();
	
}

function promo($kode, $jum)
{
	$ci =&get_instance();
	$d_pas = $ci->load->database('default', TRUE);
    $a=$d_pas->query("select * from at_promo where tipe='$kode' order by tanggal desc limit $jum");
    
	return $a->result();
	
}

function testimoni_s($cari, $tipe, $limit)
    {
		$ci =&get_instance();
		$d_pas = $ci->load->database('default', TRUE);
        $a=$d_pas->query("SELECT * FROM at_testimoni where tipe='$tipe' $limit");
        return $a->result();
    }


function gambar($produk_id)
{
	$ci =&get_instance();
	$d_pas = $ci->load->database('default', TRUE);
    $a=$d_pas->query("SELECT gambar FROM at_gambar where id_produk='$produk_id' order by id desc limit 1");
    
	if($a -> num_rows() >0){
	$row=$a->row();
	$b=$row->gambar;
	}
	else{
		$b="none.jpg";
	}
	
	return $b;
	
}

function gambar_al($produk_id)
{
	$ci =&get_instance();
	$d_pas = $ci->load->database('default', TRUE);
    $a=$d_pas->query("SELECT gambar FROM at_galeri where galeri_id='$produk_id' order by id desc limit 1");
    
	if($a -> num_rows() >0){
	$row=$a->row();
	$b=$row->gambar;
	}
	else{
		$b="none.jpg";
	}
	
	return $b;
	
}


function folder_galeri($kode)
{
	$ci =&get_instance();
	$d_pas = $ci->load->database('default', TRUE);
    $a=$d_pas->query("SELECT * from at_galeri_id where tenan_id=$kode");
    
	return $a->result();
	
}

function cek_kelas($teks)
{
   if(eregi($cari,$kalimat)){ 	   
  	$hasil=1;
  }
	else{
		$hasil=1;
	}
	
	return $hasil;
}

?>