Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, "https://apimws.bkn.go.id:8243/apisiasn/1.0/pns/rw-diklat/" . $nip);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($ch, CURLOPT_HEADER, false);
- curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
- curl_setopt($ch, CURLOPT_POSTFIELDS, "client_id=197906242006041006&grant_type=client_credentials");
- curl_setopt($ch, CURLOPT_HTTPHEADER, array(
- "Content-Type: application/x-www-form-urlencoded",
- "Auth: bearer $tokensso",
- "Authorization: Bearer $tokenapim",
- ));
- $response = curl_exec($ch);
- curl_close($ch);
- $data = json_decode($response);
- $message = $data->code;
- if ($message == 1) {
- $jmlData = count($data->data);
- if ($jmlData > 0) {
- foreach ($data->data as $item) {
- $id = trim($item->id);
- $idPns = trim($item->idPns);
- $nipBaru = trim($item->nipBaru);
- $nipLama = trim($item->nipLama);
- $latihanStrukturalId = trim($item->latihanStrukturalId);
- $latihanStrukturalNama = trim($item->latihanStrukturalNama);
- $nomor = trim($item->nomor);
- $tanggal = ($item->tanggal == '' ? '' : date('Y-m-d', strtotime($item->tanggal)));
- $tanggal_selesai = ($item->tanggalSelesai == '' ? '' : date('Y-m-d', strtotime($item->tanggalSelesai)));
- $jumlahJam = trim($item->jumlahJam);
- $institusiPenyelenggara = trim($item->institusiPenyelenggara);
- // Insert ke Tabel
- $checkPegawai = $this->db->get_where('simpeg_pegawai', array('pegawai_nip_baru' => $nip))->row();
- if (count($checkPegawai) > 0) {
- $pegawai_id = $checkPegawai->pegawai_id;
- $dataDiklat = $this->db->get_where('simpeg_diklat', array('diklat_id_sapk' => $latihanStrukturalId))->row();
- if (count($dataDiklat) > 0) {
- $diklat_id = $dataDiklat->diklat_id;
- } else {
- $diklat_id = 0;
- }
- $checkData = $this->db->get_where('simpeg_diklat_pegawai', array('diklat_pegawai_id_sapk' => $id))->row();
- if (count($checkData) == 0) {
- // Download Dokumen
- if ($item->path == null) {
- $statusFile = 'kosong';
- } else {
- if ($item->path && isset($item->path->{'0'})) {
- $statusFile = 'kosong';
- } else if ($item->path && isset($item->path->{'874'})) {
- $jam = time();
- $file = $item->path->{'874'}->dok_uri;
- $url = "https://apimws.bkn.go.id:8243/apisiasn/1.0/download-dok?filePath=" . $file;
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_HTTPHEADER, array(
- "Auth: bearer $tokensso",
- "Authorization: Bearer $tokenapim",
- ));
- $namaFile = 'Berkas_' . $nipBaru . '_' . $jam . '.pdf';
- $filename = './dokumen/diklat/' . $namaFile;
- $fp = fopen($filename, 'wb');
- curl_setopt($ch, CURLOPT_FILE, $fp);
- curl_exec($ch);
- curl_close($ch);
- fclose($fp);
- $statusFile = 'ada';
- } else {
- $statusFile = 'kosong';
- }
- }
- // Insert ke Tabel Diklat SIMPEG
- if ($statusFile == 'ada') {
- $data = array(
- 'pegawai_id' => $pegawai_id,
- 'diklat_pegawai_id_sapk' => $id,
- 'jenis_kompetensi_id' => 4,
- 'diklat_id' => $diklat_id,
- 'diklat_pegawai_tanggal' => date('Y-m-d'),
- 'diklat_pegawai_nama' => '',
- 'diklat_pegawai_tgl_mulai' => $tanggal,
- 'diklat_pegawai_tgl_selesai' => $tanggal_selesai,
- 'diklat_pegawai_penyelenggara' => $institusiPenyelenggara,
- 'diklat_pegawai_no_sertifikat' => $nomor,
- 'diklat_pegawai_jp' => $jumlahJam,
- 'diklat_pegawai_tahun' => $tahun,
- 'diklat_pegawai_berkas' => $namaFile,
- 'diklat_pegawai_verif' => 3,
- 'diklat_pegawai_update' => date('Y-m-d H:i:s'),
- );
- } else {
- $data = array(
- 'pegawai_id' => $pegawai_id,
- 'diklat_pegawai_id_sapk' => $id,
- 'jenis_kompetensi_id' => 4,
- 'diklat_id' => $diklat_id,
- 'diklat_pegawai_tanggal' => date('Y-m-d'),
- 'diklat_pegawai_nama' => '',
- 'diklat_pegawai_tgl_mulai' => $tanggal,
- 'diklat_pegawai_tgl_selesai' => $tanggal_selesai,
- 'diklat_pegawai_penyelenggara' => $institusiPenyelenggara,
- 'diklat_pegawai_no_sertifikat' => $nomor,
- 'diklat_pegawai_jp' => $jumlahJam,
- 'diklat_pegawai_tahun' => $tahun,
- 'diklat_pegawai_verif' => 3,
- 'diklat_pegawai_update' => date('Y-m-d H:i:s'),
- );
- }
- $this->db->insert('simpeg_diklat_pegawai', $data);
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement