Your IP : 216.73.216.79


Current Path : /var/www/html/brspace/frontend/controllers/
Upload File :
Current File : /var/www/html/brspace/frontend/controllers/SiteController-bak.php

<?php

namespace frontend\controllers;

use Yii;
use yii\filters\AccessControl;
use yii\filters\VerbFilter;
use yii\web\Controller;
use kartik\mpdf\Pdf;
use yii\helpers\ArrayHelper;
use backend\modules\contentDownloads\models\ContentDownloads;
use backend\modules\contentDownloads\models\ContentDownloadsAppendix;
use yii\helpers\Html;
use backend\modules\fruserdynav2\models\FrontendUser;

class SiteController extends Controller {

    public $DYNAWEB_DEFAULT_ROUTE_PAGE;
    public $DYNAWEB_DEFAULT_ROUTE_PARAMS;

    public function beforeAction($action) {
        return parent::beforeAction($action);
    }

    public function behaviors() {
        return [
            'access' => [
                'class' => AccessControl::className(),
                'only' => ['logout', 'signup', 'error', 'stub'],
                'rules' => [
                    [
                        'actions' => ['signup', 'error', 'stub'],
                        'allow' => true,
                        'roles' => ['?'],
                    ],
                    [
                        'actions' => ['logout', 'error'],
                        'allow' => true,
                        'roles' => ['@'],
                    ],
                ],
            ],
            'verbs' => [
                'class' => VerbFilter::className(),
            ],
        ];
    }

    public function actions() {
        return [
            'error' => [
                'class' => 'yii\web\ErrorAction',
            ],
            'captcha' => [
                'class' => 'yii\captcha\CaptchaAction',
                'fixedVerifyCode' => YII_ENV_TEST ? 'testme' : null,
            ],
        ];
    }

    public function actionIndex($frontendpage = null, $params = null) {
        $this->DYNAWEB_DEFAULT_ROUTE_PAGE = $frontendpage;
        $this->DYNAWEB_DEFAULT_ROUTE_PARAMS = $params;

        return $this->render('index');
    }

    public function actionPage() {
        return $this->render('page'); // placeholder
    }

    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($code) {
        $parent_id = \backend\modules\refdynawebv2\models\Ref::getparentid($code, 'DOWNLOAD_CATEGORY');
        $output = Html::dropDownList('upload-subcategory', null,
                        ArrayHelper::map((new \yii\db\Query())
                                        ->from('ref')
                                        ->where(['=', 'cat', 'DOWNLOAD_CATEGORY'])
                                        ->andwhere(['=', 'param1', $parent_id])
                                        ->orderBy(['descr' => SORT_ASC])
                                        ->all(), 'code', 'descr'), ['prompt' => '-- Please choose --', 'class' => 'form-select']);
        return $output;
    }

    public function actionGetoperationalprocedureadmin($cat) {
        $content = '';
        $parent_id = \backend\modules\refdynawebv2\models\Ref::getparentid($cat, 'DOWNLOAD_CATEGORY');
        $cat_arr = ArrayHelper::map(\backend\modules\refdynawebv2\models\Ref::find()
                                ->where(['cat' => 'DOWNLOAD_CATEGORY'])
                                ->andwhere(['=', 'param1', $parent_id])
                                ->orderBy(['sort' => SORT_ASC])->all(), 'code', 'descr');
        if (!empty($cat_arr)) {
            foreach ($cat_arr as $cat_code => $cat_label) {

                $query = new \yii\db\Query();
                $query->from('content_downloads')
                        ->where(['=', 'download_status', 'active'])
                        ->andwhere(['=', 'download_category', $cat_code]);
                $total = $query->count();

                $content .= '<p style="padding-left:20px;">
                    <a href="#" onclick="opencontentadmin2(\'' . $cat_code . '\')" style="color:black;">
                        Sub-Category : <b>' . strtoupper($cat_label) . '</b>
                    </a> (' . $total . ')
                </p>
                <div class="content content-' . $cat_code . '"></div>';
            }
        }
        return $content;
    }

    public function actionGetoperationalprocedureapproval($cat) {
        $content = '';
        $parent_id = \backend\modules\refdynawebv2\models\Ref::getparentid($cat, 'DOWNLOAD_CATEGORY');
        $cat_arr = ArrayHelper::map(\backend\modules\refdynawebv2\models\Ref::find()
                                ->where(['cat' => 'DOWNLOAD_CATEGORY'])
                                ->andwhere(['=', 'param1', $parent_id])
                                ->orderBy(['sort' => SORT_ASC])->all(), 'code', 'descr');
        if (!empty($cat_arr)) {
            foreach ($cat_arr as $cat_code => $cat_label) {

                $query = new \yii\db\Query();
                $query->from('upload')
                        ->where(['=', 'upload_type', 'operational-procedure'])
                        ->andwhere(['=', 'upload_subcategory', $cat_code]);
                $total = $query->count();

                $content .= '<p style="padding-left:20px;">
                    <a href="#" onclick="opencontent2(\'' . $cat_code . '\')" style="color:black;">
                        Sub-Category : <b>' . strtoupper($cat_label) . '</b>
                    </a> (' . $total . ')
                </p>
                <div class="content content-' . $cat_code . '"></div>';
            }
        }
        return $content;
    }

    public function actionGetoperationalprocedureadmin2($cat) {
        $content = '<table border="0" cellpadding="5" cellspacing="0" width="97%">';
        $query = new \yii\db\Query();
        $query->from('content_downloads')
                ->where(['=', 'download_status', 'active'])
                ->andwhere(['=', 'download_category', $cat])
                ->orderby(['download_version' => SORT_ASC]);
        $model = $query->all();
        if (!empty($model)) {
            foreach ($model as $row) {
                $content .= '<tr>
    		    <td width="2%" style="vertical-align:top;"></td>
    		    <td width="7%" style="vertical-align:top;">' . strtoupper($row['download_version']) . '</td>
    		    <td width="2%" style="vertical-align:top;"><img src="/portalassets/icon/pdf.png"></td>
    		    <td width="10%" style="vertical-align:top;">' . strtoupper(\backend\modules\refdynawebv2\models\Ref::getDesc('DOWNLOAD_CATEGORY', $row['download_category'])) . '</td>
    		    <td width="10%" style="vertical-align:top;">' . strtoupper($row['download_descr']) . '</td>
    		    <td style="vertical-align:top;"><a href="/' . $row['download_file'] . '" target="_blank">' . strtoupper($row['download_title']) . '</a></td>
    		    <td width="2%" style="vertical-align:top;"><img src="/portalassets/icon/more.png"></td>
    		    <td width="10%" style="vertical-align:top;">Approved</td>
    		    <td width="10%" style="vertical-align:top;">' . date("d F, Y", strtotime($row['updated_at'])) . '</td>
    		    <td width="10%" style="vertical-align:top;">Administrator</td>
    		    <td width="10%" style="vertical-align:top;">Administrator</td>
    		    <td width="10%" style="vertical-align:top;"><a href="#" onclick="displayappendix(' . $row['download_id'] . ')">' . strtoupper($row['download_version']) . '</a></td>
    		</tr>';
            }
        }

        $content .= '</table>';
        return $content;
    }

    public function actionGetoperationalprocedureapproval2($cat) {
        $content = '<table border="0" cellpadding="5" cellspacing="0" width="97%">';
        $query = new \yii\db\Query();
        $query->from('upload')
                ->where(['=', 'upload_type', 'operational-procedure'])
                ->andwhere(['=', 'upload_subcategory', $cat])
                ->orderby(['upload_id' => SORT_DESC]);
        $model = $query->all();
        if (!empty($model)) {
            foreach ($model as $row) {
                $content .= '<tr>
    		    <td width="2%" style="vertical-align:top;"></td>
    		    <td width="7%" style="vertical-align:top;"></td>
    		    <td width="2%" style="vertical-align:top;"><img src="/portalassets/icon/pdf.png"></td>
    		    <td width="10%" style="vertical-align:top;">' . strtoupper(\backend\modules\refdynawebv2\models\Ref::getDesc('DOWNLOAD_CATEGORY', $row['upload_subcategory'])) . '</td>
    		    <td width="10%" style="vertical-align:top;">' . strtoupper($row['upload_former']) . '</td>
    		    <td width="17%" style="vertical-align:top;"><a href="/' . $row['upload_file'] . '" target="_blank">' . strtoupper($row['upload_title']) . '</a></td>
    		    <td width="2%" style="vertical-align:top;"><img src="/portalassets/icon/more.png"></td>
    		    <td width="10%" style="vertical-align:top;">' . strtoupper($row['upload_status']) . '</td>
    		    <td width="10%" style="vertical-align:top;">' . date("d F, Y", strtotime($row['created_at'])) . '</td>
    		    <td width="10%" style="vertical-align:top;">' . strtoupper(FrontendUser::getname($row['created_by'])) . '</td>
    		    <td width="10%" style="vertical-align:top;">' . strtoupper(FrontendUser::getname($row['upload_approver'])) . '</td>
    		    <td width="10%" style="vertical-align:top;">' . strtoupper($row['upload_appendix']) . '</td>
    		</tr>';
            }
        }

        $content .= '</table>';
        return $content;
    }

    public function actionGetoperationalprocedure($cat) {
        $content = '';
        $parent_id = \backend\modules\refdynawebv2\models\Ref::getparentid($cat, 'DOWNLOAD_CATEGORY');
        $cat_arr = ArrayHelper::map(\backend\modules\refdynawebv2\models\Ref::find()
                                ->where(['cat' => 'DOWNLOAD_CATEGORY'])
                                ->andwhere(['=', 'param1', $parent_id])
                                ->orderBy(['sort' => SORT_ASC])->all(), 'code', 'descr');
        if (!empty($cat_arr)) {
            foreach ($cat_arr as $cat_code => $cat_label) {

                $query = new \yii\db\Query();
                $query->from('content_downloads')
                        ->where(['=', 'download_status', 'active'])
                        ->andwhere(['=', 'download_category', $cat_code]);
                $total = $query->count();

                $content .= '<p style="padding-left:20px;">
                    <a href="#" onclick="opencontent2(\'' . $cat_code . '\')" style="color:black;">
                        Sub-Category : <b>' . strtoupper($cat_label) . '</b>
                    </a> (' . $total . ')
                </p>
                <div class="content content-' . $cat_code . '"></div>';
            }
        }
        return $content;
    }

    public function actionGetoperationalprocedure2($cat) {
        $content = '<table border="0" cellpadding="5" cellspacing="0" width="100%">';
        $query = new \yii\db\Query();
        $query->from('content_downloads')
                ->where(['=', 'download_status', 'active'])
                ->andwhere(['=', 'download_category', $cat])
                ->orderby(['download_version' => SORT_ASC]);
        $model = $query->all();
        if (!empty($model)) {
            foreach ($model as $row) {
                $content .= '<tr>
                    <td width="5%" style="vertical-align:top;"></td>
                    <td width="10%" style="vertical-align:top;">' . strtoupper($row['download_version']) . '</td>
                    <td style="vertical-align:top;"><a href="/' . $row['download_file'] . '" target="_blank">' . strtoupper($row['download_title']) . '</a></td>
                    <td width="20%" style="vertical-align:top;">' . strtoupper($row['download_descr']) . '</td>
                </tr>';
            }
        }

        $content .= '</table>';
        return $content;
    }

    public function actionGetappendixop($id) {
        $title = '';
        $modelMain = ContentDownloads::findOne($id);
        if (!empty($modelMain)) {
            $title = $modelMain->download_version;
        }
        $output = '<table cellpadding="5">
            <tr>
                <td>Title</td>
                <td>' . $title . '</td>
            </tr>
            <tr>
                <td style="vertical-align:top;">Attachment</td>
                <td>';
        $modelAppendix = ContentDownloadsAppendix::find()->where(['=', 'parent_id', $id])->orderby(['id' => SORT_ASC])->all();
        if (!empty($modelAppendix)) {
            foreach ($modelAppendix as $row) {
                $output .= '<div style="margin-bottom:5px;"><a href="/' . $row->file_url . '" target="_blank">' . $row->name . '</a></div>';
            }
        }
        echo '</td>
            </tr>
        </table>';
        return $output;
    }

    public function actionGetappendixpg($id) {
        $title = '';
        $modelMain = ContentDownloads::findOne($id);
        if (!empty($modelMain)) {
            $title = $modelMain->download_version;
        }
        $output = '<table cellpadding="5">
            <tr>
                <td>Title</td>
                <td>' . $title . '</td>
            </tr>
            <tr>
                <td style="vertical-align:top;">Attachment</td>
                <td>';
        $modelAppendix = ContentDownloadsAppendix::find()->where(['=', 'parent_id', $id])->orderby(['id' => SORT_ASC])->all();
        if (!empty($modelAppendix)) {
            foreach ($modelAppendix as $row) {
                $output .= '<div style="margin-bottom:5px;"><a href="/' . $row->file_url . '" target="_blank">' . $row->name . '</a></div>';
            }
        }
        echo '</td>
            </tr>
        </table>';
        return $output;
    }

    public function actionGetappendixgpa($id) {
        $title = '';
        $modelMain = ContentDownloads::findOne($id);
        if (!empty($modelMain)) {
            $title = $modelMain->download_descr;
        }
        $output = '<table cellpadding="5">
            <tr>
                <td>Title</td>
                <td>' . $title . '</td>
            </tr>
            <tr>
                <td style="vertical-align:top;">Attachment</td>
                <td>';
        $modelAppendix = ContentDownloadsAppendix::find()->where(['=', 'parent_id', $id])->orderby(['id' => SORT_ASC])->all();
        if (!empty($modelAppendix)) {
            foreach ($modelAppendix as $row) {
                $output .= '<div style="margin-bottom:5px;"><a href="/' . $row->file_url . '" target="_blank">' . $row->name . '</a></div>';
            }
        }
        echo '</td>
            </tr>
        </table>';
        return $output;
    }

    public function actionGetdepartmentmanual($code,$sortdepartment) {
        $content = '<table border="0" cellpadding="5" cellspacing="0" width="100%">';

        if ($sortdepartment == 'up') {
        $model = \backend\modules\departmentManual\models\DepartmentManual::find()
                ->where(['=', 'dm_year', $code])
                ->andwhere(['=', 'dm_approval_status', 'approved'])
                ->orderby(['dm_department' => SORT_DESC])
                ->all();
        } else {
            $model = \backend\modules\departmentManual\models\DepartmentManual::find()
                ->where(['=', 'dm_year', $code])
                ->andwhere(['=', 'dm_approval_status', 'approved'])
                ->orderby(['dm_department' => SORT_ASC])
                ->all();
        }
                
            

        if (!empty($model)) {
            foreach ($model as $row) {
                $content .= '<tr>
		    <td width="5%">&nbsp;</td>
		    <td width="30%" style="vertical-align:top;"><a href="/web/department-manual-details?id=' . $row->dm_id . '">' . \backend\modules\refdynawebv2\models\Ref::getDesc('DEPT', $row->dm_department) . '</a></td>
		    <td width="20%" style="vertical-align:top;"><a href="/web/department-manual-details?id=' . $row->dm_id . '">' . \backend\modules\refdynawebv2\models\Ref::getDesc('SECTOR', $row->dm_sector) . '<a></td>
		    <td width="15%" style="vertical-align:top;"><a href="/web/department-manual-details?id=' . $row->dm_id . '">' . \backend\modules\refdynawebv2\models\Ref::getDesc('DM_DOCUMENT_TYPE', $row->dm_type) . '</a></td>
		    <td width="10%" style="vertical-align:top;text-align:center;">' . $row->dm_count_sop . '</td>
		</tr>';
            }
        }
        $content .= '</table>';
        return $content;
    }

    public function actionGetdepartmentmanualadmin($code,$sortdepartment,$sortsector) {
        $content = '<table border="0" cellpadding="5" cellspacing="0" width="100%">';

        $deptarray = SORT_ASC;
        if ($sortdepartment == 'up') {
            $deptarray = SORT_DESC;
        }

        $sectorarray = SORT_ASC;
        if ($sortsector == 'up') {
            $sectorarray = SORT_DESC;
        }


            $model = \backend\modules\departmentManual\models\DepartmentManual::find()
                ->where(['=', 'dm_year', $code])
                ->orderby(['dm_department' => $deptarray,'dm_sector' => $sectorarray])
                ->all();
        


        if (!empty($model)) {
            foreach ($model as $row) {
                $content .= '<tr>
		    <td width="5%">&nbsp;</td>
		    <td width="30%" style="vertical-align:top;"><a href="/web/department-manual-details?id=' . $row->dm_id . '">' . \backend\modules\refdynawebv2\models\Ref::getDesc('DEPT', $row->dm_department) . '</a></td>
		    <td width="20%" style="vertical-align:top;"><a href="/web/department-manual-details?id=' . $row->dm_id . '">' . \backend\modules\refdynawebv2\models\Ref::getDesc('SECTOR', $row->dm_sector) . '<a></td>
		    <td width="15%" style="vertical-align:top;"><a href="/web/department-manual-details?id=' . $row->dm_id . '">' . \backend\modules\refdynawebv2\models\Ref::getDesc('DM_DOCUMENT_TYPE', $row->dm_type) . '</a></td>
		    <td width="10%" style="vertical-align:top;text-align:center;">' . $row->dm_count_sop . '</td>
		    <td width="10%" style="vertical-align:top;">' . \backend\modules\refdynawebv2\models\Ref::getDesc('APPROVAL_STATUS', $row->dm_approval_status) . '</td>
		    <td width="10%" style="vertical-align:top;">' . date("d F, Y", strtotime($row->created_at)) . '</td>
		</tr>';
            }
        }
        $content .= '</table>';
        return $content;
    }

    public function actionCompliancebulletin($code, $no) {
        $no++;
        $padding = $no * 10;
        $content = '';
        $parent_id = \backend\modules\refdynawebv2\models\Ref::getparentid($code, 'DOWNLOAD_CATEGORY');
        $cat_arr = ArrayHelper::map(\backend\modules\refdynawebv2\models\Ref::find()
                                ->where(['cat' => 'DOWNLOAD_CATEGORY'])
                                ->andwhere(['=', 'param1', $parent_id])
                                ->orderBy(['sort' => SORT_ASC])->all(), 'code', 'descr');
        if (!empty($cat_arr)) {
            //get submenu
            foreach ($cat_arr as $cat_code => $cat_label) {
                $content .= '<div style="padding-left:' . $padding . 'px;"><p>
                    <a href="#" onclick="opencontent(\'' . $cat_code . '\',' . $no . ')" style="color:black;">
                        <b>' . $cat_label . '</b>
                    </a>
                </p>
                <div class="content content-' . $cat_code . '"></div></div>';
            }
        } else {
            //get content

            $query = new \yii\db\Query();
            $query->from('content_downloads')
                    ->where(['=', 'download_status', 'active'])
                    ->andwhere(['=', 'download_category', $code])
                    ->orderby(['download_title' => SORT_ASC]);
            $model = $query->all();
            if (!empty($model)) {
                foreach ($model as $row) {
                    $content .= '<p style="padding-left:10px;"><img src="/assets/img/pdf.png" style="margin-right:10px;"><a href="/' . $row['download_file'] . '" target="_blank">' . $row['download_title'] . '</a></p>';
                }
            }
        }
        return $content;
    }
}