| Current Path : /var/www/html/slaas/frontend/controllers/ |
| Current File : /var/www/html/slaas/frontend/controllers/SiteController.php |
<?php
namespace frontend\controllers;
use Yii;
use yii\filters\AccessControl;
use yii\filters\VerbFilter;
use yii\web\Controller;
use kartik\mpdf\Pdf;
use backend\modules\school\models\School;
use backend\modules\refdynawebv2\models\Ref;
use backend\modules\participation\models\Participation;
/**
* Site controller
*/
class SiteController extends Controller {
/**
* {@inheritDoc}
* @see \yii\web\Controller::beforeAction()
*/
public function beforeAction($action) {
// $this->layout = 'main_default';
// TODO Auto-generated method stub
if ($action->id == 'upload') {
$this->enableCsrfValidation = false;
}
return parent::beforeAction($action);
}
/**
* @inheritdoc
*/
public function behaviors() {
return [
'access' => [
'class' => AccessControl::className(),
'only' => ['logout', 'signup', 'error', 'stub'],
'rules' => [
[
'actions' => ['signup', 'error', 'stub'],
'allow' => true,
'roles' => ['?'],
],
[
'actions' => ['logout', 'error', 'searchschool'],
'allow' => true,
'roles' => ['@'],
],
],
],
'verbs' => [
'class' => VerbFilter::className(),
],
];
}
/**
* @inheritdoc
*/
public function actions() {
return [
'error' => [
'class' => 'yii\web\ErrorAction',
],
'captcha' => [
'class' => 'yii\captcha\CaptchaAction',
'fixedVerifyCode' => YII_ENV_TEST ? 'testme' : null,
],
];
}
/**
* Displays homepage.
*
* @return mixed
*/
public function actionSearchschooldetails($code) {
$output = '';
$model = School::find()->where(['=', 'school_code', $code])->one();
if (!empty($model)) {
$output = $model->school_name . '<->' .
$model->school_address1 . '<->' .
$model->school_address2 . '<->' .
$model->school_address3 . '<->' .
$model->school_postcode . '<->' .
$model->school_city . '<->' .
$model->school_state . '<->' .
$model->school_district . '<->' .
$model->school_ppd . '<->' .
$model->school_email . '<->' .
$model->school_phone . '<->' .
$model->school_fax . '<->'.
$model->school_parlimen . '<->'.
$model->school_dun . '<->';
}
return $output;
}
public function actionSearchschool($keyword = '', $search_state = '', $search_cat = '') {
$output = '<table class="table table-bordered table-striped">
<thead>
<tr>
<th width="1%">NO.</th>
<th width="1%">KOD</th>
<th>NAMA SEKOLAH</th>
<th>JENIS SEKOLAH</th>
<th>NEGERI</th>
<th width="1%"></th>
</tr>
</thead>
<tbody>';
$model = School::find()
->where(['LIKE', 'school_name', $keyword])
->andfilterwhere(['=', 'school_state', $search_state])
->andfilterwhere(['=', 'school_cat', $search_cat])
->limit(20)->all();
if (!empty($model)) {
$count = 0;
foreach ($model as $row) {
$count++;
$output .= '<tr>
<td>' . $count . '</td>
<td>' . strtoupper($row->school_code) . '</td>
<td>' . strtoupper($row->school_name) . '</td>
<td>' . strtoupper(\backend\modules\refdynawebv2\models\Ref::getDesc('SCHOOLCAT', $row->school_cat)) . '</td>
<td>' . strtoupper(\backend\modules\refdynawebv2\models\Ref::getDesc('STATE', $row->school_state)) . '</td>
<td><button type="button" class="btn btn-primary btn-sm" onclick="selectschool(\'' . $row->school_code . '\')">Pilih</button></td>
</tr>';
}
} else {
$output .= '<tr><td colspan="5">Rekod tidak dijumpai</td></tr>';
}
$output .= '</tbody></table>';
return $output;
}
public function actionIndex() {
return $this->render('index');
}
/**
* use slug
* */
public function actionPage() {
return $this->render('page'); // placeholder
}
/**
* Logs out the current user.
*
* @return mixed
*/
public function actionLogout() {
Yii::$app->user->logout();
return $this->goHome();
}
public function actionError() {
$exception = Yii::$app->errorHandler->exception;
if ($exception !== null) {
return $exception->getMessage();
}
}
public function actionViewpdf($doc_id) {
if (($model = \common\models\CourseDocument::findOne($doc_id)) !== null) {
$pdf = new Pdf([
'mode' => Pdf::MODE_BLANK,
'filename' => $model->doc_title . '.pdf',
'format' => Pdf::FORMAT_A4,
'orientation' => Pdf::ORIENT_PORTRAIT,
'destination' => Pdf::DEST_DOWNLOAD,
'content' => $model->doc_content,
]);
return $pdf->render();
}
}
public function actionTranslate($language) {
$cookies = Yii::$app->response->cookies;
Yii::$app->language = $language;
$cookies->add(new \yii\web\Cookie([
'name' => 'language',
'value' => $language
]));
return $this->redirect(Yii::$app->request->referrer ?: Yii::$app->homeUrl);
}
public function actionGetsubcategory($cat = '') {
$output = '<option value="">-- Sila pilih --</option>';
if (!empty($cat)) {
$ch_subcat = curl_init();
curl_setopt($ch_subcat, CURLOPT_FAILONERROR, true);
curl_setopt($ch_subcat, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch_subcat, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch_subcat, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch_subcat, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch_subcat, CURLOPT_URL, Yii::$app->params['erosesApi'] . "ref_category?cat=" . $cat);
curl_setopt($ch_subcat, CURLOPT_RETURNTRANSFER, true);
$server_output_subcat = curl_exec($ch_subcat);
curl_close($ch_subcat);
$output_subcat = json_decode($server_output_subcat, true);
if (!empty($output_subcat['subcategory'])) {
foreach ($output_subcat['subcategory'] as $sub_code => $sub_label) {
$output .= '<option value="' . $sub_code . '">' . $sub_label . '</option>';
}
}
}
return $output;
}
public function actionGetparlimen($parent_code = '') {
$output = '<option value="">-- Sila pilih --</option>';
if (($model2 = Ref::findOne(['code' => $parent_code, 'cat' => 'STATE'])) !== null) {
$model = Ref::find()->where(['param1' => $model2->id, 'cat' => 'PARLIMEN'])->orderBy(['descr_en' => SORT_ASC])->all();
if (!empty($model)) {
foreach ($model as $row) {
$output .= '<option value="' . $row->code . '">' . $row->descr_en . '</option>';
}
}
}
return $output;
}
public function actionGetdun($parent_code = '') {
$output = '<option value="">-- Sila pilih --</option>';
if (($model2 = Ref::findOne(['code' => $parent_code, 'cat' => 'STATE'])) !== null) {
$model = Ref::find()->where(['param1' => $model2->id, 'cat' => 'DUN'])->orderBy(['descr_en' => SORT_ASC])->all();
if (!empty($model)) {
foreach ($model as $row) {
$output .= '<option value="' . $row->code . '">' . $row->descr_en . '</option>';
}
}
}
return $output;
}
public function actionGetdistrict($parent_code = '') {
$output = '<option value="">-- Sila pilih --</option>';
if (($model2 = Ref::findOne(['code' => $parent_code, 'cat' => 'STATE'])) !== null) {
$model = Ref::find()->where(['param1' => $model2->id, 'cat' => 'DAERAH'])->orderBy(['descr_en' => SORT_ASC])->all();
if (!empty($model)) {
foreach ($model as $row) {
$output .= '<option value="' . $row->code . '">' . $row->descr_en . '</option>';
}
}
}
return $output;
}
public function actionUpload($participation_id) {
if (!empty($_FILES)) {
$uploadDir = "uploads/video/";
$fileName = date("YmdHis") . '.mp4';
$uploadFilePath = $uploadDir . $fileName;
if (move_uploaded_file($_FILES['file']['tmp_name'], $uploadFilePath)) {
if (($model = \backend\modules\participation\models\Participation::findOne($participation_id)) !== null) {
$model->updated_at = date("Y-m-d H:i:s");
$model->updated_by = Yii::$app->user->identity->id;
$model->updated_user_type = 'frontend_user';
$model->participation_video = $fileName;
$model->save(false);
//$modelCheck = new Participation();
//$modelCheck->checkvideo($model->participation_id);
}
}
}
}
public function actionParticipationpdf($id) {
$pdf_content = '';
$pdf_title = '';
$model = Participation::findOne($id);
if (!empty($model)) {
$modelSchool = \backend\modules\fruserdynav2\models\FrontendUser::find()->where(['=', 'school_id', $model->participation_school_id])->one();
if (!empty($modelSchool)) {
$address = $modelSchool->school_address1;
if (!empty($modelSchool->school_address2))
$address .= ' ' . $modelSchool->school_address2;
if (!empty($modelSchool->school_address3))
$address .= ' ' . $modelSchool->school_address3;
if (!empty($modelSchool->school_postcode))
$address .= ' ' . $modelSchool->school_postcode;
if (!empty($modelSchool->school_city))
$address .= ' ' . $modelSchool->school_city;
if (!empty($modelSchool->school))
$address .= ' ' . \backend\modules\refdynawebv2\models\Ref::getDesc('STATE', $modelSchool->school_state);
$pdf_content = '<table width="100%" border="0" cellpadding="10" cellspacing="0" style="border:1px solid black;">
<tr><td style="text-align:right;"><h4>SLAAS SESI ' . $model->cycle->cycle_start_year . ' / ' . $model->cycle->cycle_end_year . '</h4></td></tr>
<tr><td style="text-align:right;"><h4>KATEGORI ' . strtoupper(\backend\modules\refdynawebv2\models\Ref::getDesc('SCHOOLTYPE', $model->school->school_type)) . '</h4></td></tr>
<tr><td> </td></tr>
<tr><td> </td></tr>
<tr><td style="text-align:center;"><img src="/assets/img/Logo-SLAAS.png"></td></tr>
<tr><td> </td></tr>
<tr><td> </td></tr>
<tr><td style="text-align:center;"><h3><b>Laporan Sekolah Lestari Anugerah Alam Sekitar (SLAAS)</b></h3></td></tr>
<tr><td style="text-align:center;"><h3><b>Sesi ' . $model->cycle->cycle_start_year . ' / ' . $model->cycle->cycle_end_year . '</b></h3></td></tr>
<tr><td> </td></tr>
<tr><td> </td></tr>
<tr>
<td>
<table width="100%" border="0" cellpadding="10" cellspacing="0" style="border:1px solid black;">
<tr>
<td style="width:40%;text-align:right;vertical-align:top;"><h4>Nama Sekolah</h4></td>
<td style="width:5%;text-align:center;">:</td>
<td style="width:55%"><h4>' . $modelSchool->school_name . '</h4></td>
</tr>
<tr>
<td style="width:40%;text-align:right;vertical-align:top;"><h4>Alamat</h4></td>
<td style="width:5%;text-align:center;">:</td>
<td style="width:55%"><h4>' . $address . '</h4></td>
</tr>
<tr>
<td style="width:40%;text-align:right;vertical-align:top;"><h4>Nama Guru Penyelia</h4></td>
<td style="width:5%;text-align:center;">:</td>
<td style="width:55%"><h4>' . $modelSchool->pic_name1 . '</h4></td>
</tr>
<tr>
<td style="width:40%;text-align:right;vertical-align:top;"><h4>Nombor Telefon</h4></td>
<td style="width:5%;text-align:center;">:</td>
<td style="width:55%"><h4>' . $modelSchool->school_phone . '</h4></td>
</tr>
<tr>
<td style="width:40%;text-align:right;vertical-align:top;"><h4>Nombor Faks</h4></td>
<td style="width:5%;text-align:center;">:</td>
<td style="width:55%"><h4>' . $modelSchool->school_fax . '</h4></td>
</tr>
<tr>
<td style="width:40%;text-align:right;vertical-align:top;"><h4>Email</h4></td>
<td style="width:5%;text-align:center;">:</td>
<td style="width:55%"><h4>' . $modelSchool->school_email . '</h4></td>
</tr>
</table>
</td>
</tr>
</table>';
}
if ($model->cycle->cycle_component_status1 == 1) {
$pdf_content .= '<pagebreak>' . Participation::getplanningpdf($model->participation_id);
}
if ($model->cycle->cycle_component_status2 == 1) {
$pdf_content .= '<pagebreak>' . Participation::getcuriculumpdf($model->participation_id);
}
if ($model->cycle->cycle_component_status3 == 1) {
$pdf_content .= '<pagebreak>' . Participation::getcocuriculumpdf($model->participation_id);
}
if ($model->cycle->cycle_component_status4 == 1) {
$pdf_content .= '<pagebreak>' . Participation::getgreeningpdf($model->participation_id);
}
if ($model->cycle->cycle_component_status5 == 1) {
$pdf_content .= '<pagebreak>' . Participation::getspecialelementpdf($model->participation_id);
}
if ($model->cycle->cycle_component_status6 == 1) {
$pdf_content .= '<pagebreak>' . Participation::getotherspdf($model->participation_id);
}
$pdf_title = $model->school->school_name;
}
$pdf = new Pdf([
'mode' => Pdf::MODE_BLANK,
'filename' => urlencode($pdf_title) . '.pdf',
'format' => Pdf::FORMAT_A4,
'orientation' => Pdf::ORIENT_PORTRAIT,
'destination' => Pdf::DEST_BROWSER,
'content' => $pdf_content,
]);
return $pdf->render();
}
}