| Current Path : /var/www/html/intranetdbklv2/frontend/controllers/ |
| Current File : /var/www/html/intranetdbklv2/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;
/**
* 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
return parent::beforeAction($action);
}
/**
* @inheritdoc
*/
public function behaviors() {
return [
'access' => [
'class' => AccessControl::className(),
'only' => ['logout', 'signup', 'error', 'stub'],
'rules' => [
[
'actions' => ['signup', 'error'],
'allow' => true,
'roles' => ['?'],
],
[
'actions' => ['logout', 'error', 'stub'],
'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 actionIndex() {
return $this->render('index');
}
public function stub() {
return '1231';
}
/**
* 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 actionDownloademailapplication($id) {
$content = '';
if (($model = \frontend\models\EmailApplication::findOne($id)) !== null) {
$content = '
<div style="text-align:center;">
<img src="/assets/dbkl/images/preloader-logo.png" height="100">
<h5>Jabatan Pengurusan Maklumat</h5>
<h5>Dewan Bandaraya Kuala Lumpur</h5>
<h5>Tingkat 11, Menara DBKL 2, Jalan Raja Laut</h5>
<h5>50350 Kuala Lumpur</h5>
<h5>(Tel : 03 - 2028 2078 Faks : 03 - 2693 6649)</h5>
<h5>Permohonan Email DBKL</h5>
</div><br>
<table class="table table-borderless">
<tbody>
<tr>
<td width="50%" class="text-right">' . $model->getAttributeLabel('application_icno') . '</td>
<th>' . $model->application_icno . '</th>
</tr>
<tr>
<td class="text-right">' . $model->getAttributeLabel('application_name') . '</td>
<th>' . $model->application_name . '</th>
</tr>';
if (!empty($model->application_staff_no)) {
$content .= '<tr>
<td class="text-right">' . $model->getAttributeLabel('application_staff_no') . '</td>
<th>' . $model->application_staff_no . '</th>
</tr>';
}
$content .= '
<tr>
<td class="text-right">' . $model->getAttributeLabel('application_dept') . '</td>
<th>' . \backend\modules\refdynawebv2\models\Ref::getDesc('CONTENT_SOURCE', $model->application_dept, 'descr_en') . '</th>
</tr>
<tr>
<td class="text-right">' . $model->getAttributeLabel('application_unit') . '</td>
<th>' . $model->application_unit . '</th>
</tr>
<tr>
<td class="text-right">' . $model->getAttributeLabel('application_level') . '</td>
<th>' . $model->application_level . '</th>
</tr>
<tr>
<td class="text-right">' . $model->getAttributeLabel('application_location') . '</td>
<th>' . \backend\modules\refdynawebv2\models\Ref::getDesc('REQUESTLOCATION', $model->application_location, 'descr_en') . '</th>
</tr>
<tr>
<td class="text-right">' . $model->getAttributeLabel('application_grade') . '</td>
<th>' . \backend\modules\refdynawebv2\models\Ref::getDesc('GRADE', $model->application_grade, 'descr_en') . '</th>
</tr>
<tr>
<td class="text-right">' . $model->getAttributeLabel('application_phone') . '</td>
<th>' . $model->application_phone . '</th>
</tr>
<tr>
<td class="text-right">' . $model->getAttributeLabel('application_ip') . '</td>
<th>' . $model->application_ip . '</th>
</tr>
<tr>
<td class="text-right">' . $model->getAttributeLabel('application_os') . '</td>
<th>' . \backend\modules\refdynawebv2\models\Ref::getDesc('OPERATINGSYSTEM', $model->application_os, 'descr') . '</th>
</tr>
<tr>
<td class="text-right">' . $model->getAttributeLabel('application_network') . '</td>
<th>' . \backend\modules\refdynawebv2\models\Ref::getDesc('REQUESTNETWORK', $model->application_network, 'descr') . '</th>
</tr>
<tr>
<td class="text-right">' . $model->getAttributeLabel('application_requirement') . '</td>
<th>' . \backend\modules\refdynawebv2\models\Ref::getDesc('REQUESTREQUIREMENT', $model->application_requirement, 'descr') . '</th>
</tr>';
if ($model->application_requirement == 'EMAIL03') {
$content .= '<tr>
<td style="text-align:right;">' . $model->getAttributeLabel('event_name') . '</td>
<th style="text-align:left;">' . $model->event_name . '</th>
</tr>
<tr>
<td style="text-align:right;">' . $model->getAttributeLabel('event_start_date') . '</td>
<th style="text-align:left;">' . $model->event_start_date . '</th>
</tr>
<tr>
<td style="text-align:right;">' . $model->getAttributeLabel('event_end_date') . '</td>
<th style="text-align:left;">' . $model->event_end_date . '</th>
</tr>';
}
$content .= '<tr>
<td class="text-right">' . $model->getAttributeLabel('created_at') . '</td>
<th>' . date("d/m/Y", strtotime($model->created_at)) . '</th>
</tr>
</tbody>
</table>';
}
$pdf = new Pdf([
'mode' => Pdf::MODE_BLANK,
'filename' => 'Permohonan Emel & Internet DBKL.pdf',
'format' => Pdf::FORMAT_A4,
'orientation' => Pdf::ORIENT_PORTRAIT,
'destination' => Pdf::DEST_BROWSER,
'content' => $content,
]);
return $pdf->render();
}
/**
* set up first time user detail
* */
public function actionFirstTimeSetup() {
try {
$model = \backend\modules\fruserdynav2\models\FrontendUser::findOne(Yii::$app->user->id);
if ($model->load(Yii::$app->request->post())) {
$model->password_hash = Yii::$app->security->generatePasswordHash($model->new_password);
$model->first_time_setup = 1;
if (!$model->save()) {
if(is_countable($model->errors) && count($model->errors) > 0) {
Yii::$app->session->setFlash('form-error', $model->errors);
}
}
if(empty($model->errors)) {
Yii::$app->session->setFlash('success', 'Kata Laluan Berjaya Di Simpan');
}
}
} catch (\Throwable $t) {
var_dump($t->getMessage());die;
// ErrorHandler::handle($t, Yii::$app->controller->id, Yii::$app->controller->action->id, Url::to());
}
return $this->redirect(['/portal-main/dashboard']);
}
public function actionStub() {
// $this->sendEmailApplication(['12']);
}
}