<?php

function lokasi_url($nomor)
{
	if($nomor==1)
	return url_1;
	
	if($nomor==2)
	return url_2;
	
	if($nomor==4)
	return url_4;
	
	if($nomor==5)
	return url_5;
	
	if($nomor==10)
	return url_10;
	
	if($nomor==14)
	return url_14;
	
}

function lokasi_berita($nomor)
{
	if($nomor==1)
	return lokasi_berita_1;
	
	if($nomor==2)
	return lokasi_berita_2;
	
	if($nomor==4)
	return lokasi_berita_4;
	
	if($nomor==5)
	return lokasi_berita_5;
	
	if($nomor==10)
	return lokasi_berita_10;
	
	if($nomor==14)
	return lokasi_berita_14;
	
}

function lokasi_gal($nomor)
{
	if($nomor==1)
	return lokasi_gal_1;
	
	if($nomor==2)
	return lokasi_gal_2;
	
	if($nomor==4)
	return lokasi_gal_4;
	
	if($nomor==5)
	return lokasi_gal_5;
	
	if($nomor==10)
	return lokasi_gal_10;
	
	if($nomor==14)
	return lokasi_gal_14;
	
}

function lokasi_down($nomor)
{
	if($nomor==1)
	return lokasi_down_1;
	
	if($nomor==2)
	return lokasi_down_2;
	
	if($nomor==4)
	return lokasi_down_4;
	
	if($nomor==5)
	return lokasi_down_5;
	
	if($nomor==10)
	return lokasi_down_10;
	
	if($nomor==14)
	return lokasi_down_14;
	
}


function konten_tengah($nomor, $jenis, $hal)
{
	$ci =&get_instance();
	$d_pas = $ci->load->database('default', TRUE);
    $a=$d_pas->query("SELECT * FROM gen_konten2 where nomor='$nomor' and hal='$hal' and jenis_id='$jenis'");

	
	return $a->result();
	
}


function kelas_intake($lembaga, $intake)
{
	$ci =&get_instance();
	$d_pas = $ci->load->database('cms', TRUE);
    $a=$d_pas->query("SELECT * FROM  
cms_classes, cms_academic_periods, cms_learningcenter_branch_courses, cms_learningcenter_branches, cms_learningcenters, cms_courses  
where 
cms_academic_periods.prdLcbrcId = cms_learningcenter_branch_courses.lcbrcId 
and cms_learningcenter_branches.lcbranchId=cms_learningcenter_branch_courses.lcbrcLcbranchId
and cms_academic_periods.prdLcbrcId = cms_learningcenter_branch_courses.lcbrcId 
and cms_learningcenters.lcId=cms_learningcenter_branches.lcbranchLcId 
and cms_courses.courseId=cms_learningcenter_branch_courses.lcbrcLcbranchIdCourseId
and cms_academic_periods.prdId=cms_classes.classPrdId 
and 1 = 1 AND
    cms_learningcenters.lcId = '".$lembaga."'
and prdName='$intake' order by className asc");

	
	return $a->result();
	
}

function ijin($kelas, $jenis){
	$ci =&get_instance();
	$d_pas = $ci->load->database('default', TRUE);
	 $a=$d_pas->query("SELECT ijin FROM  gen_ijin where kelas_id='$kelas' and jenis_id='$jenis' ");
    
	if($a -> num_rows() >0){
	$row=$a->row();
	$b=$row->ijin;
	}
	else{
		$b="Tidak Aktif";
	}
	
	if($b=="1"){
		$b="Aktif";
	}
	if($b=="0"){
		$b="Tidak Aktif";
	}
	
	
	
	return $b;
	
}

function hit_ijin($d, $e){
	$ci =&get_instance();
	$d_pas = $ci->load->database('default', TRUE);
	 $a=$d_pas->query("SELECT ijin FROM  gen_ijin where kelas_id='$d' and jenis_id='$e'");
	
	return $a -> num_rows();
}

function hit_cms_ijin($d){
	$ci =&get_instance();
	$d_pas = $ci->load->database('cms', TRUE);
	 $a=$d_pas->query("SELECT * FROM cms_examinations where examScheduleId='$d'");
	
	return $a -> num_rows();
}

function hit_isi($a, $b, $c, $d){
	
	$ci =&get_instance();
	$d_pas = $ci->load->database('default', TRUE);
	$d_pas->query("INSERT INTO gen_ijin (`kelas_id`, `ijin`, jenis_id, jadwal_id) VALUES ('$a', '$b', '$c', '$d')");
}

function hit_cms_isi($a, $b, $c){
	
	$ci =&get_instance();
	$d_pas = $ci->load->database('cms', TRUE);
	$d_pas->query("INSERT INTO cms_examinations(`examScheduleId`, `examName`, examDescription) VALUES ('$a', '$b', '$c')");
}

function hit_ubah($a, $b, $c, $d){
	
	$ci =&get_instance();
	$d_pas = $ci->load->database('default', TRUE);
	$d_pas->query("UPDATE gen_ijin SET `ijin`='$b', jadwal_id='$d' WHERE kelas_id='$a' and jenis_id='$c' LIMIT 1");
}

function hit_cms_ubah($a, $b, $c){
	
	$ci =&get_instance();
	$d_pas = $ci->load->database('cms', TRUE);
	$d_pas->query("UPDATE cms_examinations SET `examName`='$b', examDescription='$c' WHERE examScheduleId='$a' LIMIT 1");
}

function encode_ganti($a)
{

	$a=str_replace("/","agung", $a);
	$a=str_replace("=","yappi", $a);
	$a=str_replace("+","cakep", $a);
	return $a;
}

function decode_ganti($a)
{
	$a=str_replace("cakep","+", $a);
	$a=str_replace("yappi","=", $a);
	$a=str_replace("agung","/", $a);
	return $a;
}

function kuis_ijin($id, $jenis)
{
	$ci =&get_instance();
	$d_pas = $ci->load->database('default', TRUE);
    $a=$d_pas->query("select * from gen_ijin where kelas_id='$id and jenis_id='$jenis'");
    
	if($a -> num_rows() >0){
	$row=$a->row();
	$b=$row->ijin;
	}
	else{
		$b="0";
	}
	
	return $b;
	
}

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 balik2($tabel, $tampil, $kunci, $harus, $kunci2, $harus2)
{
	$ci =&get_instance();
	$d_pas = $ci->load->database('default', TRUE);
    $a=$d_pas->query("SELECT $tampil FROM $tabel where $kunci='$harus' and $kunci2='$harus2'");
    
	if($a -> num_rows() >0){
	$row=$a->row();
	$b=$row->$tampil;
	}
	else{
		$b="";
	}
	
	return $b;
	
}

function balik_cms($tabel, $tampil, $kunci, $harus)
{
	$ci =&get_instance();
	$d_pas = $ci->load->database('cms', 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 balik_user($id)
{
	$ci =&get_instance();
	$d_pas = $ci->load->database('cms', TRUE);
    $a=$d_pas->query("select studentId from gtfw_user as gu, cms_students as cs, cms_applicants as ca, pub_ref_sekolah as prs where gu.UserId=cs.studentGtfwUserId and gu.UserName='$id' and ca.applicantId=cs.studentApplicantId and prs.sekolah_id=ca.sekolah_id");
    
	if($a -> num_rows() >0){
	$row=$a->row();
	$b=$row->studentId;
	}
	else{
		$b="";
	}
	
	return $b;
	
}

function nilai($peserta_id, $jenis_id, $kolom)
{
	$ci =&get_instance();
	$d_pas = $ci->load->database('default', TRUE);
    $a=$d_pas->query("SELECT p.id FROM gen_soal as s, gen_jawaban as j, gen_peserta as p 
					WHERE p.id=j.peserta_id and j.peserta_id=p.id and j.soal_id=s.id and s.kolom='$kolom'
					and p.id='$peserta_id' and s.jenis_id='$jenis_id' and j.jawaban=s.jawaban
								   ");
    
	$b=$a -> num_rows();
	
	return $b;
	
}

function nilai2($peserta_id, $jenis_id, $kolom)
{
	$ci =&get_instance();
	$d_pas = $ci->load->database('default', TRUE);
    $a=$d_pas->query("SELECT p.id FROM gen_soal as s, gen_jawaban as j, gen_peserta as p 
					WHERE p.id=j.peserta_id and j.peserta_id=p.id and j.soal_id=s.id and s.kolom='$kolom'
					and p.id='$peserta_id' and s.jenis_id='$jenis_id' and j.jawaban != s.jawaban
								   ");
    
	$b=$a -> num_rows();
	
	return $b;
	
}

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

function lihat_jawaban($peserta_id, $soal_id, $jenis_id)
{
	$ci =&get_instance();
	$d_pas = $ci->load->database('default', TRUE);
    $a=$d_pas->query("SELECT * FROM gen_jawaban where peserta_id='$peserta_id' and soal_id='$soal_id' and jenis_id='$jenis_id'");
    if($a -> num_rows() >0){
	$row=$a->row();
	$b=$row->jawaban;
	}
	else { $b=""; }
	return $b;
	
	
}

function cek_level($peserta_id, $kelas_id)
{
	$ci =&get_instance();
	$d_pas = $ci->load->database('cms', TRUE);
    $a=$d_pas->query("SELECT studentlevelId FROM cms_student_levels, cms_student_courses where 
	studentlevelClassId='$kelas_id' and studentcourseStudentId='$peserta_id' and studentcourseId=studentlevelStudentcourseId");
    
	$row=$a->row();
	$b=$row->studentlevelId;
	
	return $b;
	
	
}

function cek_jadwal($jenis, $kelas)
{
	$ci =&get_instance();
	$d_pas = $ci->load->database('default', TRUE);
    $a=$d_pas->query("SELECT jadwal_id FROM gen_ijin where 
	jenis_id='$jenis' and kelas_id='$kelas'");
    
	$row=$a->row();
	$b=$row->jadwal_id;
	
	return $b;
	
	
}

function cek_exs($ex, $materi)
{
	$ci =&get_instance();
	$d_pas = $ci->load->database('cms', TRUE);
    $a=$d_pas->query("SELECT examsbjId FROM cms_examination_subjects where 
	examsbjExamId='$ex' and examsbjLabel='$materi'");
    
	$row=$a->row();
	$b=$row->examsbjId;
	
	return $b;
	
	
}


function hal($jenis)
{
	$ci =&get_instance();
	$d_pas = $ci->load->database('default', TRUE);
    $a=$d_pas->query("SELECT hal, id FROM gen_soal where jenis_id=$jenis group by hal");
  	return $a->result();
}

function materi($jenis)
{
	$ci =&get_instance();
	$d_pas = $ci->load->database('default', TRUE);
    $a=$d_pas->query("SELECT * FROM gen_materi where jenis_id=$jenis");
  	return $a->result();
}

function jawaban($peserta_id, $soal_id, $jenis, $jawaban)
{
	$ci =&get_instance();
	$d_pas = $ci->load->database('default', TRUE);
    $a=$d_pas->query("SELECT * FROM gen_jawaban where peserta_id='$peserta_id' and soal_id='$soal_id' and jenis_id='$jenis'");
    
	if($a -> num_rows() >0){
		if($jawaban !="undefined"){
			mysql_query("UPDATE  gen_jawaban SET  `jawaban` =  '$jawaban' where peserta_id='$peserta_id' and soal_id='$soal_id' and jenis_id='$jenis'");
		}
	}
	else{
	mysql_query("INSERT INTO  gen_jawaban (peserta_id , soal_id, `jawaban`, jenis_id) VALUES ('$peserta_id',  '$soal_id',  '$jawaban', '$jenis')");
	}
	
	
}

function sinkron($jenis, $kelas){
	$ci =&get_instance();
	$d_pas = $ci->load->database('default', TRUE);
	 $a=$d_pas->query("SELECT jadwal_id FROM  gen_ijin where kelas_id='$kelas' and jenis_id='$jenis' ");
    
	if($a -> num_rows() >0){
	$row=$a->row();
	$b=$row->jadwal_id;
	}
	else{
		$b="0";
	}
	
	return $b;
	
}

function jadwal_cms($kelas){
	$ci =&get_instance();
	$d_pas = $ci->load->database('cms', TRUE);
	 $a=$d_pas->query("SELECT * FROM  cms_schedules where scheduleClassId='$kelas'");

	
	return $a->result();
	
}

function hapus_cms_isi($d){
	$ci =&get_instance();
	$d_pas = $ci->load->database('cms', TRUE);
	$d_pas->query("DELETE FROM cms_examinations where examScheduleId='$d'");
}

function hapus_isi($d){
	$ci =&get_instance();
	$d_pas = $ci->load->database('default', TRUE);
	$d_pas->query("UPDATE `gen_ijin` SET `jadwal_id`='0' WHERE `jadwal_id`='$d' ");
}



function materi_tambah($a, $b){
	$ci =&get_instance();
	$d_pas = $ci->load->database('cms', TRUE);
	$d_pas->query("INSERT INTO  cms_examination_subjects (examsbjExamId, examsbjLabel) VALUES ('$a',  '$b')");
}

function hapus_materi($d){
	$ci =&get_instance();
	$d_pas = $ci->load->database('cms', TRUE);
	$d_pas->query("DELETE FROM cms_examination_subjects where examsbjExamId='$d'");
}

function nilai_isi($materi_id, $peserta_id, $total, $b, $s, $k){
	$ci =&get_instance();
	$d_pas = $ci->load->database('default', TRUE);
	$d_pas->query("INSERT INTO gen_nilai(materi_id, peserta_id, total, b, s, k) VALUES ('$materi_id',  '$peserta_id', '$total', '$b', '$s', '$k')");
}

function nilai_ubah($materi_id, $peserta_id, $total, $b, $s, $k){
	$ci =&get_instance();
	$d_pas = $ci->load->database('default', TRUE);
	$d_pas->query("UPDATE `gen_nilai` SET `total`='$total',`b`='$b',`s`='$s',`k`='$k' WHERE peserta_id='$peserta_id' and materi_id='$materi_id'");
}

function nilai_isi_cms($level, $exs, $total){
	$ci =&get_instance();
	$d_pas = $ci->load->database('cms', TRUE);
	$d_pas->query("INSERT INTO cms_student_exam_scores(studentscoreStudentlevelId, studentscoreExamsbjId, studentscoreValue) VALUES ('$level',  '$exs', '$total')");
}

function nilai_ubah_cms($level, $exs, $total){
	$ci =&get_instance();
	$d_pas = $ci->load->database('cms', TRUE);
	$d_pas->query("UPDATE `cms_student_exam_scores` SET `studentscoreValue`='$total' WHERE studentscoreStudentlevelId='$level' and studentscoreExamsbjId='$exs'");
}


function cek_maks($m){
	$ci =&get_instance();
	$d_pas = $ci->load->database('default', TRUE);
	 $a=$d_pas->query("select sum(benar) as benar from gen_soal where materi_id='$m'");
    
	if($a -> num_rows() >0){
	$row=$a->row();
	$b=$row->benar;
	}
	else{
		$b="0";
	}
	
	return $b;
	
}

function nilai_materi($m, $p){
	$ci =&get_instance();
	$d_pas = $ci->load->database('default', TRUE);
	 $a=$d_pas->query("SELECT total FROM gen_nilai where materi_id='$m' and peserta_id='$p'");
    
	if($a -> num_rows() >0){
	$row=$a->row();
	$b=$row->total;
	}
	else{
		$b="0";
	}
	
	return $b;
	
}


function cek_nilai($materi, $peserta)
{
	$ci =&get_instance();
	$d_pas = $ci->load->database('default', TRUE);
    $a=$d_pas->query("SELECT * FROM gen_nilai where materi_id='$materi' and peserta_id='$peserta'
								   ");
    
	$b=$a -> num_rows();
	
	return $b;
	
}

function cek_nilai_cms($level, $exs)
{
	$ci =&get_instance();
	$d_pas = $ci->load->database('cms', TRUE);
    $a=$d_pas->query("SELECT * FROM cms_student_exam_scores where studentscoreStudentlevelId='$level' and studentscoreExamsbjId='$exs'
								   ");
    
	$b=$a -> num_rows();
	
	return $b;
	
}

function pernah($peserta, $jenis){
	$ci =&get_instance();
	$d_pas = $ci->load->database('default', TRUE);
	 $a=$d_pas->query("SELECT total FROM  gen_nilai, gen_soal where peserta_id='$peserta' and gen_soal.jenis_id='$jenis' and gen_soal.materi_id=gen_nilai.materi_id group by gen_soal.materi_id");
    
	if($a -> num_rows() >0){
	$b="Sudah Pernah";
	}
	else{
		$b="Belum Pernah";
	}
	
	return $b;
	
}

function materi_jenis($id)
    {
		$ci =&get_instance();
		$d_pas = $ci->load->database('default', TRUE);
		$query = $d_pas->query("SELECT * FROM gen_materi where jenis_id=$id");
        $b=$query->result();
		return $b;
    }

function jenis_soal()
    {
		$ci =&get_instance();
		$d_pas = $ci->load->database('default', TRUE);
		$query = $d_pas->query("SELECT * FROM gen_jenis");
        $b=$query->result();
		return $b;
    }

function materi_soal()
    {
		$ci =&get_instance();
		$d_pas = $ci->load->database('default', TRUE);
		$query = $d_pas->query("SELECT * FROM gen_materi");
        $b=$query->result();
		return $b;
    }




?>