| Current Path : /var/www/html/sprm/backend/controllers/program/ |
| Current File : /var/www/html/sprm/backend/controllers/program/ProgramEducationApplicationController.php |
<?php
namespace backend\controllers\program;
use Yii;
use backend\models\program\ProgramEducationApplication;
use backend\models\program\ProgramEducationApplicationSearch;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
use yii\filters\AccessControl;
use common\components\AccessRule;
use yii\helpers\FileHelper;
use yii\web\UploadedFile;
use kartik\mpdf\Pdf;
/**
* ProgramEducationApplicationController implements the CRUD actions for ProgramEducationApplication model.
*/
class ProgramEducationApplicationController extends Controller {
/**
* {@inheritdoc}
*/
public function behaviors() {
return [
'access' => [
'class' => AccessControl::className(),
'ruleConfig' => [
'class' => AccessRule::className(),
],
'rules' => [
[
'actions' => ['index', 'create', 'update', 'view', 'delete', 'updatenotes','download'],
'allow' => true,
'roles' => ['@'],
],
],
],
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'delete' => ['POST'],
],
],
];
}
/**
* Lists all ProgramEducationApplication models.
* @return mixed
*/
public function actionIndex() {
$searchModel = new ProgramEducationApplicationSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
return $this->render('index', ['searchModel' => $searchModel, 'dataProvider' => $dataProvider,]);
}
/**
* Displays a single ProgramEducationApplication model.
* @param integer $id
* @return mixed
* @throws NotFoundHttpException if the model cannot be found
*/
public function actionView($id) {
return $this->render('view', ['model' => $this->findModel($id),]);
}
/**
* Creates a new ProgramEducationApplication model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate() {
$model = new ProgramEducationApplication();
$model->created_at = date("Y-m-d H:i:s");
$model->created_by = 'admin:' . Yii::$app->user->identity->id;
$model->updated_at = date("Y-m-d H:i:s");
$model->updated_by = 'admin:' . Yii::$app->user->identity->id;
$model->status = 'approve';
if ($model->load(Yii::$app->request->post())) {
$model->file_upload = UploadedFile::getInstance($model, 'file_upload');
if (!empty($model->file_upload)) {
$file_upload = 'uploads/' . date("YmdHis") . '.' . $model->file_upload->extension;
if ($model->file_upload->saveAs($file_upload))
$model->file_upload = $file_upload;
}
if ($model->save())
return $this->redirect(['index']);
}
return $this->render('create', ['model' => $model,]);
}
/**
* Updates an existing ProgramEducationApplication model.
* If update is successful, the browser will be redirected to the 'view' page.
* @param integer $id
* @return mixed
* @throws NotFoundHttpException if the model cannot be found
*/
public function actionUpdate($id) {
$model = $this->findModel($id);
$file_original = $model->file_upload;
$model->updated_at = date("Y-m-d H:i:s");
$model->updated_by = 'admin:' . Yii::$app->user->identity->id;
if ($model->load(Yii::$app->request->post())) {
$model->file_upload = UploadedFile::getInstance($model, 'file_upload');
if (!empty($model->file_upload)) {
$file_upload = 'uploads/' . date("YmdHis") . '.' . $model->file_upload->extension;
if ($model->file_upload->saveAs($file_upload))
$model->file_upload = $file_upload;
} else
$model->file_upload = $file_original;
if ($model->save())
return $this->redirect(['index']);
}
return $this->render('update', ['model' => $model,]);
}
public function actionUpdatenotes($id) {
$model = $this->findModel($id);
$model->updated_at = date("Y-m-d H:i:s");
$model->updated_by = 'admin:' . Yii::$app->user->identity->id;
if ($model->load(Yii::$app->request->post()) && $model->save()) {
if ($model->status == 'approve' && !empty($model->applicant_email)) {
$emailFrom = 'noreply.testemailweb@gmail.com';
$emailSubject = 'Permohonan Program / Ceramah / Taklimat di SPRM';
$emailContent = '<p>Salam Sejahtera ' . $model->applicant_name . ',</p>
<p>Permohonan anda untuk Program / Ceramah / Taklimat di SPRM pada ' . date("d-m-Y", strtotime($model->program_start_date)) . ' telah diluluskan.</p>
<p>Catatan : ' . $model->notes . '</p>
<p>Terima kasih</p>';
Yii::$app->mailer->compose()->setFrom($emailFrom)->setTo($model->applicant_email)
->setSubject($emailSubject)->setHtmlBody($emailContent)->send();
} else if ($model->status == 'reject' && !empty($model->applicant_email)) {
$emailFrom = 'noreply.testemailweb@gmail.com';
$emailSubject = 'Permohonan Program / Ceramah / Taklimat di SPRM';
$emailContent = '<p>Salam Sejahtera ' . $model->applicant_name . ',</p>
<p>Permohonan anda untuk Program / Ceramah / Taklimat di SPRM pada ' . date("d-m-Y", strtotime($model->program_start_date)) . ' telah ditolak.</p>
<p>Catatan : ' . $model->notes . '</p>
<p>Untuk maklumat lanjut, sila hubungi pegawai :</p>
<p> En Zamani Othman melalui zamaniothman@sprm.gov.my</p>
<p>Terima kasih</p>';
Yii::$app->mailer->compose()->setFrom($emailFrom)->setTo($model->applicant_email)
->setSubject($emailSubject)->setHtmlBody($emailContent)->send();
}
return $this->redirect(['index']);
}
return $this->render('updatenotes', ['model' => $model,]);
}
/**
* Deletes an existing ProgramEducationApplication model.
* If deletion is successful, the browser will be redirected to the 'index' page.
* @param integer $id
* @return mixed
* @throws NotFoundHttpException if the model cannot be found
*/
public function actionDelete($id) {
$this->findModel($id)->delete();
return $this->redirect(['index']);
}
/**
* Finds the ProgramEducationApplication model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown.
* @param integer $id
* @return ProgramEducationApplication the loaded model
* @throws NotFoundHttpException if the model cannot be found
*/
protected function findModel($id) {
if (($model = ProgramEducationApplication::findOne($id)) !== null) {
return $model;
}
throw new NotFoundHttpException('The requested page does not exist.');
}
public function actionDownload($id) {
$model = $this->findModel($id);
if(!empty($model)){
$header = '<table id="table-header" border="0" width="100%" cellpadding="0" cellspacing="0">
<tr>
<td><img src="https://www.sprm.gov.my/admin/files/sprm/assets/images/sprm/favicon.png" height="50"></td>
<td align="right"><b>Permohonan Program / Ceramah / Taklimat </b><br/>PENDIDIKAN</td>
</tr>
</table>';
$audience1 = ($model->status_audience1 == 1 && !empty($model->no_audience1)) ? number_format($model->no_audience1) : 0;
$audience2 = ($model->status_audience2 == 1 && !empty($model->no_audience2)) ? number_format($model->no_audience2) : 0;
$audience3 = ($model->status_audience3 == 1 && !empty($model->no_audience3)) ? number_format($model->no_audience3) : 0;
$audience4 = ($model->status_audience4 == 1 && !empty($model->no_audience4)) ? number_format($model->no_audience4) : 0;
$audience5 = ($model->status_audience5 == 1 && !empty($model->no_audience5)) ? number_format($model->no_audience5) : 0;
$audience6 = ($model->status_audience6 == 1 && !empty($model->no_audience6)) ? number_format($model->no_audience6) : 0;
$audience7 = ($model->status_audience7 == 1 && !empty($model->no_audience7)) ? number_format($model->no_audience7) : 0;
$audience8 = ($model->status_audience8 == 1 && !empty($model->no_audience8)) ? number_format($model->no_audience8) : 0;
$audience9 = ($model->status_audience9 == 1 && !empty($model->no_audience9)) ? number_format($model->no_audience9) : 0;
$audience10 = ($model->status_audience10 == 1 && !empty($model->no_audience10)) ? number_format($model->no_audience10) : 0;
$audience11 = ($model->status_audience11 == 1 && !empty($model->no_audience11)) ? number_format($model->no_audience11) : 0;
$audience12 = ($model->status_audience12 == 1 && !empty($model->no_audience12)) ? number_format($model->no_audience12) : 0;
$audience13 = ($model->status_audience13 == 1 && !empty($model->no_audience13)) ? number_format($model->no_audience13) : 0;
$audience14 = ($model->status_audience14 == 1 && !empty($model->no_audience14)) ? number_format($model->no_audience14) : 0;
$audience15 = ($model->status_audience15 == 1 && !empty($model->no_audience15)) ? number_format($model->no_audience15) : 0;
$audience16 = ($model->status_audience16 == 1 && !empty($model->no_audience16)) ? number_format($model->no_audience16) : 0;
switch ($model->status){
case 'approve':
$status = 'Lulus';
break;
case 'reject':
$status = 'Tidak Lulus';
break;
default:
$status = 'Sedang Diproses';
break;
}
$content = '<br><br><table border="0" width="100%" cellpadding="5" cellspacing="0">
<tr>
<td valign="top" colspan="3" style="text-align:center;color:white;font-weight:bold;background-color:black;">Maklumat Agensi / Organisasi </td>
</tr>
<tr>
<td valign="top">Nama Agensi / Organisasi</td>
<td valign="top"> : </td>
<td valign="top">' . strtoupper($model->agency_name) . '</td>
</tr>
<tr>
<td valign="top">No. Telefon Pejabat</td>
<td valign="top"> : </td>
<td valign="top">' . $model->agency_phone . '</td>
</tr>
<tr>
<td valign="top">Alamat Agensi/Organisasi</td>
<td valign="top"> : </td>
<td valign="top">' . strtoupper($model->agency_address) . '</td>
</tr>
<tr>
<td valign="top" colspan="3" style="text-align:center;color:white;font-weight:bold;background-color:black;"> Maklumat Pemohon </td>
</tr>
<tr>
<td valign="top">Nama Pemohon</td>
<td valign="top"> : </td>
<td valign="top">'. \backend\models\Ref::getDesc('PROGRAM_APPTITLE', $model->applicant_title) .' '.strtoupper($model->applicant_name) . '</td>
</tr>
<tr>
<td valign="top">No. Telefon Pemohon</td>
<td valign="top"> : </td>
<td valign="top">' . $model->applicant_phone . '</td>
</tr>
<tr>
<td valign="top">Emel Pemohon</td>
<td valign="top"> : </td>
<td valign="top">' . $model->applicant_email . '</td>
</tr>
<tr>
<td valign="top" colspan="3" style="text-align:center;color:white;font-weight:bold;background-color:black;"> Maklumat Program </td>
</tr>
<tr>
<td valign="top">Jenis Program</td>
<td valign="top"> : </td>
<td valign="top">' . strtoupper(\backend\models\Ref::getDesc('PROGRAM_TYPE2', $model->program_type)) . '</td>
</tr>
<tr>
<td valign="top">Lokasi Program</td>
<td valign="top"> : </td>
<td valign="top">' . strtoupper($model->program_location) . '</td>
</tr>
<tr>
<td valign="top">Tarikh & Masa Mula Program</td>
<td valign="top"> : </td>
<td valign="top">'. $model->program_start_date .' ['. strtoupper($model->program_start_time) . '] </td>
</tr>
<tr>
<td valign="top">Tarikh & Masa Akhir Program</td>
<td valign="top"> : </td>
<td valign="top">'. $model->program_end_date .' ['. strtoupper($model->program_end_time) . '] </td>
</tr>
<tr>
<td valign="top">Maklumat Tambahan</td>
<td valign="top"> : </td>
<td valign="top">' . strtoupper($model->extra_info) . '</td>
</tr>
<tr>
<td valign="top" colspan="3" style="text-align:center;color:white;font-weight:bold;background-color:black;"> Maklumat Audien </td>
</tr>
<tr>
<td valign="top">Anggaran Bil. Audien</td>
<td valign="top"> : </td>
<td valign="top">' . number_format($model->total_audience) . '</td>
</tr>
<tr>
<td td valign="top">Kerajaan</td>
<td valign="top"> : </td>
<td>
Pengurusan Tertinggi [ '. $audience1 .' ]<br>
Pengurusan & Profesional [ '. $audience2 .' ]<br>
Kumpulan Sokongan [ '. $audience3 .' ]<br>
</td>
</tr>
<tr>
<td td valign="top">Swasta</td>
<td valign="top"> : </td>
<td>
Pengurusan Tertinggi [ '. $audience4 .' ]<br>
Eksekutif [ '. $audience5 .' ]<br>
Bukan Eksekutif [ '. $audience6 .' ]<br>
</td>
</tr>
<tr>
<td td valign="top">GLC</td>
<td valign="top"> : </td>
<td>
Pengurusan Tertinggi [ '. $audience7 .' ]<br>
Eksekutif [ '. $audience8 .' ]<br>
Bukan Eksekutif [ '. $audience9 .' ]<br>
</td>
</tr>
<tr>
<td td valign="top">Pelajar</td>
<td valign="top"> : </td>
<td>
Rendah [ '. $audience10 .' ]<br>
Menengah [ '. $audience11 .' ]<br>
Pengajian Tinggi [ '. $audience12 .' ]<br>
</td>
</tr>
<tr>
<td td valign="top">Lain-Lain</td>
<td valign="top"> : </td>
<td>
Pengurusan Tertinggi [ '. $audience13 .' ]<br>
Pengurusan & Profesional [ '. $audience14 .' ]<br>
Kumpulan Sokongan [ '. $audience15 .' ]<br>
Kumpulan Sokongan [ '. $audience15 .' ]<br>
</td>
</tr>
<tr>
<td valign="top" colspan="3" style="text-align:center;color:white;font-weight:bold;background-color:black;"> Status Permohonan </td>
</tr>
<tr>
<td valign="top">Status</td>
<td valign="top"> : </td>
<td valign="top">'. strtoupper($status) . ' </td>
</tr>
<tr>
<td valign="top">Catatan</td>
<td valign="top"> : </td>
<td valign="top">'. strtoupper($model->notes) . ' </td>
</tr>
</table>';
$footer = '<table id="table-footer" border="0" width="100%" cellpadding="0" cellspacing="0">
<tr><td align="center">Suruhanjaya Pencegahan Rasuah Malaysia (SPRM), ' .
' No. 2, Lebuh Wawasan, Presint 7, 62250 Putrajaya. </td>
</tr>
</table>';
// setup kartik\mpdf\Pdf component
$pdf = new Pdf([
'mode' => Pdf::MODE_CORE,
'filename' => 'Permohonan Program / Ceramah / Taklimat oleh ' . $model->agency_name . '.pdf',
'format' => Pdf::FORMAT_A4,
'orientation' => Pdf::ORIENT_PORTRAIT,
'destination' => Pdf::DEST_BROWSER,
'cssFile' => '@vendor/kartik-v/yii2-mpdf/src/assets/kv-mpdf-bootstrap.min.css',
'cssInline' => 'body,table td{font-size:11px;Arial, Helvetica, sans-serif;line-height:1.7em;}
#table-header{padding-bottom:10px;}
#table-footer{padding-top:10px;}
#table-product th{background-color:black;color:white;text-align:center;}
#table-product tr:nth-child(odd) td{background-color:white;}
#table-product tr:nth-child(even) td{background-color:whitesmoke;}',
'methods' => ['SetHeader' => [$header], 'SetFooter' => $footer],
'content' => $content,
'options' => ['setAutoTopMargin' => 'stretch'],
]);
return $pdf->render();
}
}
}