Files
simpro-rssa/app/inbox/undangan.php
T
2024-08-13 05:44:19 +00:00

149 lines
4.9 KiB
PHP

<?php
include('../koneksi.php');
//echo "Hari ini adalah ". hari_ini();
$riwayat_peserta_id=$_POST['id'];
$ket=pg_query("SELECT t.id,
k.tgl_und,
k.no_und,
p.nama,
r.nama,
k.tanggal_mulai,
k.waktu_mulai,
k.waktu_selesai,
k.tempat,
(SELECT u.nama FROM sebagai u WHERE u.id=t.sebagai_id),
l.nama,
k.nama_pelatihan
FROM riwayat_peserta t
INNER JOIN data_pegawai p ON (p.id=t.data_pegawai_id)
INNER JOIN riwayat_kegiatan k ON (k.id=t.riwayat_kegiatan_id)
INNER JOIN satuan_kerja r ON (r.id=p.satuan_kerja)
INNER JOIN jenis_pelatihan l ON (l.id=k.jenis_pelatihan_id)
WHERE t.id='$riwayat_peserta_id'
ORDER BY t.id DESC
");
while($rket=pg_fetch_array($ket)) {
$id=$rket[0];
$tgl_und=$rket[1];
$no_und=$rket[2];
$nama_und=$rket[3];
$satker_und=str_replace("&","dan",$rket[4]);
$tgl_acara_und=$rket[5];
$waktu_mulai=$rket[6];
$waktu_selesai=$rket[7];
$tempat_und=$rket[8];
$sebagai_und=$rket[9];
$jenis_pel=ucwords(strtolower($rket[10]));
$nama_pel=ucwords(strtolower($rket[11]));
}
$kpl=pg_query("SELECT p.nama,p.nipb,k.pangkat
FROM data_kepala k
INNER JOIN data_pegawai p ON (p.id=k.data_pegawai_id) WHERE k.aktif='t' AND jenis='Wadir'");
while($rkpl=pg_fetch_array($kpl)) {
$wadir_und=$rkpl[0];
$pangkat_und=$rkpl[2];
$nip_und=$rkpl[1];
}
$thn_und=date('Y');
$array_hari = array(1=>"Senin","Selasa","Rabu","Kamis","Jumat", "Sabtu","Minggu");
$hari = $array_hari[date("N",strtotime($tgl_acara_und))];
$bulan = array(
'01' => 'Januari',
'02' => 'Februari',
'03' => 'Maret',
'04' => 'April',
'05' => 'Mei',
'06' => 'Juni',
'07' => 'Juli',
'08' => 'Agustus',
'09' => 'September',
'10' => 'Oktober',
'11' => 'November',
'12' => 'Desember',
);
$bulan[date('m')];
$template_file_name = 'undangan.docx';
$rand_no = rand(111111, 999999);
$fileName = "UNDANGAN_".$nama_und.'_'.date('d',strtotime($tgl_und)).''.(date('m',strtotime($tgl_und))).''.date('Y',strtotime($tgl_und)).".docx";
$folder = $id;
$full_path = $folder . '/' . $fileName;
try
{
if (!file_exists($folder))
{
mkdir($folder);
}
//Copy the Template file to the Result Directory
copy($template_file_name, $full_path);
// add calss Zip Archive
$zip_val = new ZipArchive;
//Docx file is nothing but a zip file. Open this Zip File
if($zip_val->open($full_path) == true)
{
// In the Open XML Wordprocessing format content is stored.
// In the document.xml file located in the word directory.
$key_file_name = 'word/document.xml';
$message = $zip_val->getFromName($key_file_name);
$timestamp = date('d-M-Y H:i:s');
// this data Replace the placeholders with actual values
$message = str_replace("tgl_und", date('d',strtotime($tgl_und)).' '.($bulan[date('m',strtotime($tgl_und))]).' '.date('Y',strtotime($tgl_und)), $message);
$message = str_replace("no_und", $no_und, $message);
$message = str_replace("thn_und", $thn_und, $message);
$message = str_replace("nama_und", $nama_und, $message);
$message = str_replace("satker_und", $satker_und, $message);
$message = str_replace("tgl_acara_und", date('d',strtotime($tgl_acara_und)).' '.($bulan[date('m',strtotime($tgl_acara_und))]).' '.date('Y',strtotime($tgl_acara_und)), $message);
if (date('H:i',strtotime($waktu_selesai))=='00:00') {
$message = str_replace("waktu_acara_und", date('H:i',strtotime($waktu_mulai)).' s/d Selesai', $message);
} else {
$message = str_replace("waktu_acara_und", date('H:i',strtotime($waktu_mulai)).' s/d '.date('H:i',strtotime($waktu_selesai)), $message);
}
$message = str_replace("tempat_und", $tempat_und, $message);
$message = str_replace("sebagai_und", $sebagai_und, $message);
$message = str_replace("jenis_pel", $jenis_pel, $message);
$message = str_replace("nama_pel", $nama_pel, $message);
$message = str_replace("wadir_und", $wadir_und, $message);
$message = str_replace("pangkat_und", $pangkat_und, $message);
$message = str_replace("nip_und", $nip_und, $message);
/* $message = str_replace("2020", $thn, $message);
$message = str_replace("hd", $head, $message);
$message = str_replace("isi_catatan", $isi_catatan, $message); */
//Replace the content with the new content created above.
$zip_val->addFromString($key_file_name, $message);
$zip_val->close();
}
}
catch (Exception $exc)
{
$error_message = "Error creating the Word Document";
var_dump($exc);
}
echo $fileName;
?>