Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ikhwan 2
- $app->post('/submit_weekly_report', function(Request $request, Response $response) {
- $parsedparam = $request->getParsedBody();
- $detail = json_decode($parsedparam['description'], true);
- $id_siswa = sanitizeInput($detail['id_siswa']);
- $id_guru = sanitizeInput($detail['id_guru']);
- $nama_guru = sanitizeInput($detail['nama_guru']);
- $jabatan = sanitizeInput($detail['jabatan']);
- $id_kelas = sanitizeInput($detail['id_kelas']);
- $id_tahun = sanitizeInput($detail['id_tahun']);
- $bulan = sanitizeInput($detail['bulan']);
- $draft = sanitizeInput($detail['draft']); //1 atau 0
- $nama_bulan = date('F', mktime(0, 0, 0, $bulan, 10));
- // $nama_bulan = 'agustus';
- $judul = sanitizeInput($detail['judul']);
- $isi = sanitizeInput($detail['isi']);
- $directory = $this->get('settings')['upload_directory_weekly_report'];
- $uploadedFiles = $request->getUploadedFiles();
- $filenames = array(); // gambars
- $filepdfs = array(); // pdfs
- $responseRes = array();
- $tanggal = date('Y-m-d h:i', time());
- $lastID = null;
- // insert new weekly_report
- $queryInput = "INSERT INTO raport_weekly(id_siswa, id_guru, nama_guru, jabatan, id_kelas, id_tahun, bulan, nama_bulan, flag, draft, date_submit_by_guru, submit, judul, isi) VALUES (:id_siswa, :id_guru, :nama_guru, :jabatan, :id_kelas, :id_tahun, :bulan, :nama_bulan, '0', :draft, now(), '0', :judul, :isi)";
- $stmt = $this->db->prepare($queryInput);
- $stmt->bindParam(':id_siswa', $id_siswa, PDO::PARAM_STR);
- $stmt->bindParam(':id_guru', $id_guru, PDO::PARAM_STR);
- $stmt->bindParam(':nama_guru', $nama_guru, PDO::PARAM_STR);
- $stmt->bindParam(':jabatan', $jabatan, PDO::PARAM_STR);
- $stmt->bindParam(':id_kelas', $id_kelas, PDO::PARAM_STR);
- $stmt->bindParam(':id_tahun', $id_tahun, PDO::PARAM_STR);
- $stmt->bindParam(':bulan', $bulan, PDO::PARAM_STR);
- $stmt->bindParam(':nama_bulan', $nama_bulan, PDO::PARAM_STR);
- // $stmt->bindParam(':flag', 0, PDO::PARAM_STR);
- $stmt->bindParam(':draft', $draft, PDO::PARAM_STR);
- // $stmt->bindParam(':submit', 0, PDO::PARAM_STR);
- $stmt->bindParam(':judul', $judul, PDO::PARAM_STR);
- $stmt->bindParam(':isi', $isi, PDO::PARAM_STR);
- // $stmt->execute();
- // $lastID = $db->insert_id;
- if($stmt->execute()){
- $lastID = $this->db->lastInsertId();
- } else {
- $responseRes = array(
- 'status' => 'failed',
- 'message' => 'Failed adding weekly report!'
- );
- return $response->withJson($responseRes, 200);
- }
- if($lastID != null){
- // input gambars
- foreach ($uploadedFiles['gambars'] as $uploadedFile) {
- if ($uploadedFile->getError() === UPLOAD_ERR_OK) {
- $filename = moveUploadedFile($directory, $uploadedFile);
- // $filenames[] = $filename;
- if($filename){
- $query = "INSERT INTO raport_weekly_file(id_weekly_report, tipe, source, thumbnail) VALUES (:id, 'Gambar', :source, :thumbnail)";
- $stmt = $this->db->prepare($query);
- $stmt->bindParam(':id', $lastID, PDO::PARAM_STR);
- $stmt->bindParam(':source', $filename, PDO::PARAM_STR);
- $stmt->bindParam(':thumbnail', $filename, PDO::PARAM_STR);
- $stmt->execute();
- }
- } else {
- $responseRes = array(
- 'status' => 'failed',
- 'message' => 'Error while uploading image!'
- );
- }
- }
- // input pdf
- foreach ($uploadedFiles['pdfs'] as $uploadedFile) {
- if ($uploadedFile->getError() === UPLOAD_ERR_OK) {
- $filename = moveUploadedFile($directory, $uploadedFile);
- // $filepdfs[] = $filename;
- if($filename){
- $query = "INSERT INTO raport_weekly_file(id_weekly_report, tipe, source, thumbnail) VALUES (:id, 'Pdf', :source, :thumbnail)";
- $stmt = $this->db->prepare($query);
- $stmt->bindParam(':id', $lastID, PDO::PARAM_STR);
- $stmt->bindParam(':source', $filename, PDO::PARAM_STR);
- $stmt->bindParam(':thumbnail', $filename, PDO::PARAM_STR);
- $stmt->execute();
- }
- } else {
- $responseRes = array(
- 'status' => 'failed',
- 'message' => 'Error while uploading pdf!'
- );
- }
- }
- // if(count($filenames) > 0 ){
- // foreach ($filenames as $f) {
- // $query = "INSERT INTO raport_weekly_file(id_weekly_report, tipe, source, thumbnail) VALUES (:id, :tipe, :source, :thumbnail)";
- // $stmt = $this->db->prepare($query);
- // $stmt->bindParam(':id', $lastID, PDO::PARAM_STR);
- // $stmt->bindParam(':tipe', 'Gambar', PDO::PARAM_STR);
- // $stmt->bindParam(':source', $f, PDO::PARAM_STR);
- // $stmt->bindParam(':thumbnail', $f, PDO::PARAM_STR);
- // $stmt->execute();
- // }
- // }
- // if(count($filepdfs) > 0){
- // foreach ($filepdfs as $f) {
- // $query = "INSERT INTO raport_weekly_file(id_weekly_report, tipe, source) VALUES (:id, :tipe, :source)";
- // $stmt = $this->db->prepare($query);
- // $stmt->bindParam(':id', $lastID, PDO::PARAM_STR);
- // $stmt->bindParam(':tipe', 'Pdf', PDO::PARAM_STR);
- // $stmt->bindParam(':source', $f, PDO::PARAM_STR);
- // $stmt->execute();
- // }
- // }
- $responseRes = array(
- 'status' => 'Success',
- 'message' => 'Success creating new weekly report!'
- );
- return $response->withJson($responseRes, 200);
- } else {
- $responseRes = array(
- 'status' => 'Error',
- 'message' => 'Last id null!'
- );
- return $response->withJson($responseRes, 200);
- }
- $responseRes = array(
- 'status' => 'Success',
- 'message' => $parsedparam
- );
- return $response->withJson($responseRes, 200);
- });
- $app->post('/list_weekly_report_adm', function (Request $request, Response $response) {
- $parsedparam = $request->getParsedBody();
- $id_kelas = sanitizeInput($parsedparam['id_kelas']);
- $id_tahun = sanitizeInput($parsedparam['id_tahun']);
- $bulan = sanitizeInput($parsedparam['bulan']);
- $query = "SELECT a.id, a.id_siswa, a.nama_guru, a.jabatan, a.id_kelas, a.id_tahun, a.bulan, a.nama_bulan, a.date_submit_by_guru, a.judul, b.source FROM raport_weekly a INNER JOIN raport_weekly_file b ON a.id = b.id_weekly_report WHERE a.id_kelas = $id_kelas AND a.id_tahun = $id_tahun AND a.bulan = $bulan GROUP BY a.id ORDER BY a.id desc";
- // $weekly = ambilData($this->db, $query);
- return $response->withJson(ambilData($this->db, $query, true), 200);
- });
- $app->post('/detail_weekly_report_adm', function (Request $request, Response $response) {
- $parsedparam = $request->getParsedBody();
- $id = sanitizeInput($parsedparam['id']);
- $query = "SELECT * FROM raport_weekly WHERE id = $id";
- $weeklyReport = ambilDataSingle($this->db, $query);
- // source
- $qSource = "SELECT * FROM raport_weekly_file WHERE id_weekly_report = $id";
- $weeklyReport->assets = ambilDataSingle($this->db, $qSource, true);
- return $response->withJson(["status" => "success", "data" => $weeklyReport], 200);
- });
- $app->post('/update_weekly_report', function (Request $request, Response $response) {
- $parsedparam = $request->getParsedBody();
- $id = sanitizeInput($parsedparam['id']); // id weekly peroprt
- $id_siswa = sanitizeInput($parsedparam['id_siswa']);
- $id_guru = sanitizeInput($parsedparam['id_guru']);
- $nama_guru = sanitizeInput($parsedparam['nama_guru']);
- $jabatan = sanitizeInput($parsedparam['jabatan']);
- $id_kelas = sanitizeInput($parsedparam['id_kelas']);
- $id_tahun = sanitizeInput($parsedparam['id_tahun']);
- $bulan = sanitizeInput($parsedparam['bulan']);
- $draft = sanitizeInput($parsedparam['draft']); //1 atau 0
- $nama_bulan = date('F', mktime(0, 0, 0, $bulan, 10));
- $judul = sanitizeInput($parsedparam['judul']);
- $isi = sanitizeInput($parsedparam['isi']);
- $responseRes = array();
- $tanggal = date('Y-m-d h:i', time());
- // insert new weekly_report
- $queryInput = "UPDATE raport_weekly SET id_siswa=:id_siswa, id_guru=:id_guru, nama_guru=:nama_guru, jabatan=:jabatan, id_kelas=:id_kelas, id_tahun=:id_tahun, bulan=:bulan, nama_bulan=:nama_bulan, judul=:judul, isi=:isi, draft=:draft WHERE id = :id";
- $stmt = $this->db->prepare($queryInput);
- $stmt->bindParam(':id_siswa', $id_siswa, PDO::PARAM_STR);
- $stmt->bindParam(':id_guru', $id_guru, PDO::PARAM_STR);
- $stmt->bindParam(':nama_guru', $nama_guru, PDO::PARAM_STR);
- $stmt->bindParam(':jabatan', $jabatan, PDO::PARAM_STR);
- $stmt->bindParam(':id_kelas', $id_kelas, PDO::PARAM_STR);
- $stmt->bindParam(':id_tahun', $id_tahun, PDO::PARAM_STR);
- $stmt->bindParam(':bulan', $bulan, PDO::PARAM_STR);
- $stmt->bindParam(':nama_bulan', $nama_bulan, PDO::PARAM_STR);
- $stmt->bindParam(':judul', $judul, PDO::PARAM_STR);
- $stmt->bindParam(':isi', $isi, PDO::PARAM_STR);
- $stmt->bindParam(':id', $id, PDO::PARAM_STR);
- $stmt->bindParam(':draft', $draft, PDO::PARAM_STR);
- if($stmt->execute()){
- $responseRes = array(
- 'status' => 'Success',
- 'message' => 'Weekly report successfully updated!'
- );
- } else {
- $responseRes = array(
- 'status' => 'failed',
- 'message' => 'something went wrong while updating weekly report!'
- );
- }
- return $response->withJson($responseRes, 200);
- });
- $app->post('/delete_img_weekly', function (Request $request, Response $response) {
- $parsedparam = $request->getParsedBody();
- $id = sanitizeInput($parsedparam['id']);
- $directory = $this->get('settings')['upload_directory_weekly_report'];
- // select img detail
- $query = "SELECT * FROM raport_weekly_file WHERE id = $id";
- $image = ambilDataSingle($this->db, $query);
- if(unlink($directory.'/'.$image->source)){
- $query = "DELETE FROM raport_weekly_file WHERE id = :id";
- $stmt = $this->db->prepare($query);
- $stmt->bindParam(':id', $id, PDO::PARAM_STR);
- $stmt->execute();
- return $response->withJson(["status" => "success", "message" => "File successfully deleted!"], 200);
- } else {
- return $response->withJson(["status" => "failed", "message" => "An error occured!"], 200);
- }
- });
- $app->post('/upload_img_weekly', function (Request $request, Response $response) {
- $parsedparam = $request->getParsedBody();
- $id = sanitizeInput($parsedparam['id']);
- $directory = $this->get('settings')['upload_directory_weekly_report'];
- $uploadedFiles = $request->getUploadedFiles();
- $uploadedFile = $uploadedFiles['file'];
- if ($uploadedFile->getError() === UPLOAD_ERR_OK) {
- $filename = moveUploadedFile($directory, $uploadedFile);
- if($filename){ // kalau berhasil upload hapus file yg ada
- // select img detail
- $query = "SELECT * FROM raport_weekly_file WHERE id = $id";
- $image = ambilDataSingle($this->db, $query);
- if(unlink($directory.'/'.$image->source)){
- $query = "UPDATE raport_weekly_file SET source = :filename, thumbnail = :filename WHERE id = :id";
- $stmt = $this->db->prepare($query);
- $stmt->bindParam(':filename', $filename, PDO::PARAM_STR);
- $stmt->bindParam(':id', $id, PDO::PARAM_STR);
- if($stmt->execute()){
- return $response->withJson(["status" => "success", "message" => "File successfully uploaded!"], 200);
- } else {
- return $response->withJson(["status" => "failed", "message" => "An error occured!"], 200);
- }
- } else {
- return $response->withJson(["status" => "failed", "message" => "Something wrong with directory!"], 200);
- }
- }
- }
- });
- $app->post('/approve_weekly_report', function (Request $request, Response $response) {
- $parsedparam = $request->getParsedBody();
- $id = sanitizeInput($parsedparam['id']);
- $query = "UPDATE raport_weekly SET submit=1, date_submit_by_admin=NOW() WHERE id=:id";
- $stmt = $this->db->prepare($query);
- $stmt->bindParam(':id', $id, PDO::PARAM_STR);
- if($stmt->execute()){
- return $response->withJson(["status" => "success", "message" => "Weekly report successfully approved!"], 200);
- } else {
- return $response->withJson(["status" => "success", "message" => "Weekly report successfully approved!"], 200);
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement