<?php
include ('koneksi.php');

function level($id_dep,$jab)
{
	$pr=mysql_query("SELECT COUNT(parrent_departemen),parrent_departemen FROM departemen WHERE id_departemen='$id_dep'");
	$r=mysql_fetch_array($pr);
	if ($r[0]==0)
	{
		$level = 1;
	}
	else if($id_dep==2)
	{	
		$level = 2;
	}
	else
	{
		$a=mysql_query("SELECT COUNT(parrent_departemen), parrent_departemen, nama_departemen FROM departemen WHERE id_departemen = '$r[1]'");
		$c=mysql_fetch_array($a);
		
		if($c[2]=='Sekretaris')
		{
			$level = 3;
		}
		else if ($r[1]==3 || $r[1]==4 || $r[1]==5 || $r[1]==6)
		{
			$level = 5;
		}
		else if ($r[0]==1)
		{
			$level = 4;
		}
	}
	return $level;
}

function cari_id_dep($nama_dep)
{
	$pr=mysql_query("SELECT id_departemen FROM departemen WHERE nama_departemen='$nama_dep'");
	$r=mysql_fetch_array($pr);
	
	$id_dep = $r[0];
	return $id_dep;
}


function cari_nama_dep($id_dep)
{
	$pr=mysql_query("SELECT nama_departemen FROM departemen WHERE id_departemen='$id_dep'");
	$r=mysql_fetch_array($pr);
	
	$nm_dep = $r[0];
	return $nm_dep;
}

function cari_parr_dep($id_dep)
{
	$pr=mysql_query("SELECT parrent_departemen FROM departemen WHERE id_departemen='$id_dep'");
	$r=mysql_fetch_array($pr);
	
	$pr_dep = $r[0];
	return $pr_dep;
}

function bagan($level)
{
	if ($level==4)
	{
		$bagan='kiri';
	}
	else if ($parrent_level==3)
	{
		$bagan='kanan';
	}
	return $bagan;
}

function cari_no_hp($nip)
{
	$pr=mysql_query("SELECT TELP FROM pegawai WHERE NIP='$nip'");
	$r=mysql_fetch_array($pr);
	
	$pr_no = $r[0];
	return $pr_no;
}

function generateRandomString($length = 10) {
    $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
    $charactersLength = strlen($characters);
    $randomString = '';
    for ($i = 0; $i < $length; $i++) {
        $randomString .= $characters[rand(0, $charactersLength - 1)];
    }
    return $randomString;
}
function cari_nama_pegawai($nip)
{
	$pr=mysql_query("SELECT p.NAMA, d.nama_departemen FROM pegawai p, departemen d WHERE NIP='$nip' AND p.id_departemen = d.id_departemen");
	$r=mysql_fetch_array($pr);
	
	$nm_peg = $r[0];
	return $nm_peg;
}
function cari_nama_pegawai_dep($nip)
{
	$pr=mysql_query("SELECT p.NAMA, d.nama_departemen FROM pegawai p, departemen d WHERE NIP='$nip' AND p.id_departemen = d.id_departemen");
	$r=mysql_fetch_array($pr);
	
	$nm_peg = $r[0];
	return $nm_peg;
}
function kop($id_surat)
{
	$pr=mysql_query("SELECT tujuan_surat FROM surat_masuk WHERE id_surat_masuk='$id_surat'");
	$r=mysql_fetch_array($pr);
	
	$tujuan = $r[0];
	if ($tujuan==1)
	{
		$kop = "Kepala Dinas";
	}
	else
	{
		$kop = "Sekretaris";
	}
	return $kop;
}
function urgensi($id_surat)
{
	$pr=mysql_query("SELECT urgensi FROM surat_masuk WHERE id_surat_masuk='$id_surat'");
	$r=mysql_fetch_array($pr);
	
	$urg = $r[0];
	if ($urg=="Biasa")
	{
		$kop = "<span class=\"label label-info\">Biasa</span>";
	}
	else if ($urg=="Penting")
	{
		$kop = "<span class=\"label label-success\">Penting</span>";
	}
	else if ($urg=="Segera")
	{
		$kop = "<span class=\"label label-waring\">Segera</span>";
	}
	else if ($urg=="Amat Segera")
	{
		$kop = "<span class=\"label label-important\">Amat Segera</span>";
	}
	return $kop;
}
?>