Add consultation module assets and libraries
This commit is contained in:
94
konsultasi/robot/robotDataDosen.php
Normal file
94
konsultasi/robot/robotDataDosen.php
Normal file
@@ -0,0 +1,94 @@
|
||||
<?php
|
||||
error_reporting(E_ALL);
|
||||
ini_set('display_errors', '1');
|
||||
include '../conf/koneksiPDO.php';
|
||||
include '../conf/function.php';
|
||||
|
||||
header('Content-Type: application/json');
|
||||
$conn = new createCon();
|
||||
$dbh = $conn->connect();
|
||||
$dbhSpota = $conn->connectSpota();
|
||||
|
||||
$sql = 'SELECT idDosen FROM dosen';
|
||||
$stmt = $dbh->prepare($sql);
|
||||
$stmt->execute();
|
||||
|
||||
$listDosenDb = [];
|
||||
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
|
||||
$idDosenDb = $row['idDosen'];
|
||||
$listDosenDb[$idDosenDb] = true;
|
||||
}
|
||||
|
||||
//$data = file_get_contents('http://spota.untan.ac.id/steven/API/getListDosen.php?secret=in14d4lahP4ssWordSP0TA!12!');
|
||||
//$url = 'http://spota.untan.ac.id/steven/API/getListDosen.php?secret=in14d4lahP4ssWordSP0TA!12!';
|
||||
/**
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL, $url);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||
$data = curl_exec($ch);
|
||||
curl_close($ch);
|
||||
*/
|
||||
|
||||
//$data = file_get_contents($url);
|
||||
|
||||
$sql = 'SELECT * FROM tbdosen';
|
||||
$stmt = $dbhSpota->prepare($sql);
|
||||
$stmt->execute();
|
||||
|
||||
$data = array();
|
||||
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
|
||||
$id = $row['iddosen'];
|
||||
$nip = $row['nip'];
|
||||
$nama = $row['nmLengkap'];
|
||||
$email = $row['email'];
|
||||
$hp = $row['nohp'];
|
||||
$foto = $row['foto'];
|
||||
$urlFoto = "http://spota.untan.ac.id/img/$foto";
|
||||
|
||||
array_push($data, array(
|
||||
'id' => $id,
|
||||
'nip' => $nip,
|
||||
'nama' => $nama,
|
||||
'email' => $email,
|
||||
'hp' => $hp,
|
||||
'urlFoto' => $urlFoto,
|
||||
));
|
||||
}
|
||||
|
||||
$decoded = ['data' => $data];
|
||||
//$decoded = json_decode($data, 1);
|
||||
$banyakData = sizeof($decoded['data']);
|
||||
|
||||
for ($i = 0; $i < $banyakData; ++$i) {
|
||||
$dataDosen = $decoded['data'][$i];
|
||||
$id = $dataDosen['id'];
|
||||
$nip = $dataDosen['nip'];
|
||||
$nama = $dataDosen['nama'];
|
||||
$email = $dataDosen['email'];
|
||||
$hp = $dataDosen['hp'];
|
||||
$urlFoto = $dataDosen['urlFoto'];
|
||||
|
||||
if (!isset($listDosenDb[$id])) {
|
||||
$sql = 'INSERT INTO dosen(idDosen, nip, namaDosen, email, hp, urlFoto) VALUES (:id, :nip, :nama, :email, :hp, :urlFoto)';
|
||||
$stmt = $dbh->prepare($sql);
|
||||
$stmt->bindParam(':id', $id);
|
||||
$stmt->bindParam(':nip', $nip);
|
||||
$stmt->bindParam(':nama', $nama);
|
||||
$stmt->bindParam(':email', $email);
|
||||
$stmt->bindParam(':hp', $hp);
|
||||
$stmt->bindParam(':urlFoto', $urlFoto);
|
||||
$stmt->execute();
|
||||
} else {
|
||||
$sql = 'UPDATE dosen SET nip = :nip, namaDosen = :nama, email = :email, hp = :hp, urlFoto = :urlFoto WHERE idDosen = :id';
|
||||
$stmt = $dbh->prepare($sql);
|
||||
$stmt->bindParam(':id', $id);
|
||||
$stmt->bindParam(':nip', $nip);
|
||||
$stmt->bindParam(':nama', $nama);
|
||||
$stmt->bindParam(':email', $email);
|
||||
$stmt->bindParam(':hp', $hp);
|
||||
$stmt->bindParam(':urlFoto', $urlFoto);
|
||||
$stmt->execute();
|
||||
}
|
||||
}
|
||||
|
||||
echo json_encode(['status' => 1, 'msg' => 'ok']);
|
||||
Reference in New Issue
Block a user