<?
session_start();
include"../plg/ses.php";
$nama = $_POST['nama2'];
$nip = $_POST['nip'];
$unit = $_POST['unit'];
$jab = $_POST['jab'];
$loka = $_POST['loka'];
$selkpi = $_POST['selkpi'];
$kpikar = $selkpi."-".$nip;
$kodejab = $_POST['kodejab'];

include"../plg/kon.php";

$sql1 = "select * from kpikar where idkar='$kpikar'";
$res1 = $conn->query($sql1);
while($a = $res1->fetch_assoc()){
  $hasil = $a['idkar'];
}

if($hasil == $kpikar){
  echo "<script>alert('DATA SUDAH ADA !...')</script>";
  echo "<script>location.href='baru2.php';</script>";
}
else{
  $sql = "insert into kpikar (idkar,nama,nip,unit,jab,lok)values('$kpikar','$nama','$nip','$unit','$jab','$loka')";
  $res = $conn->query($sql);

  $sql2 = "select * from masterkpi where del='0' and kodejab like'%$kodejab%'";
  $res2 = $conn->query($sql2);
  while($b = $res2->fetch_assoc()){
    echo $kode = $b['kode'];
    echo $kpi = $b['kpi'];
    echo $pola = $b['pola'];
    echo $des = $b['des'];
    echo $sat = $b['sat'];
    //echo $kua = $b['fok'];

    $sql3 = "insert into kpiuser (idkar,kode,kpi,pola,des,sat,kua)values('$kpikar','$kode','$kpi','$pola','$des','$sat','100')";
    $res3 = $conn->query($sql3);
  }
  echo "<script>location.href='formuserkpi.php?idkar=$kpikar';</script>";
}




?>
