<?
session_start();
include"../plg/ses.php";

$namax = $_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,smt)values('$kpikar','$namax','$nip','$unit','$jab','$loka','$selkpi')";
  $res = $conn->query($sql);

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

    $sql3 = "insert into kpiuser (idkar,kode,kpi,pola,des,sat,kua,smt,fok,foktan,nol)values
    ('$kpikar','$kode','$kpi','$pola','$des','$sat','100','$selkpi','$fok','$foktan','$nol')";
    $res3 = $conn->query($sql3);

    echo "<script>location.href='formuserkpiver2.php?idkar=$kpikar';</script>";
  }
}




?>
