Your IP : 216.73.216.79


Current Path : /var/www/html/ekursus/backend/controllers/support/
Upload File :
Current File : /var/www/html/ekursus/backend/controllers/support/SupportHelpdeskController.php

<?php

namespace backend\controllers\support;

use Yii;
use backend\models\support\SupportHelpdesk;
use backend\models\support\SupportHelpdeskSearch;
use backend\models\ReplyEmelAduan;
use common\components\AlertMsg;
use backend\models\StaffAccess;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
use yii\helpers\Url;
use yii\filters\AccessControl;
use common\components\AccessRule;

/**
 * SupportHelpdeskController implements the CRUD actions for SupportHelpdesk model.
 */
class SupportHelpdeskController extends Controller
{
    /**
     * @inheritdoc
     */
    public function behaviors()
    {
        return [
            'access' => [
                'class' => AccessControl::className(),
                'ruleConfig' => [
                    'class' => AccessRule::className(),
                ],
                'rules' => [
                    [
                        'actions' => ['index','index1', 'view', 'view-penerima', 'view-admin', 'reply','create','update','delete1', 'delete'],
                        'allow' => true,
                        'roles' => ['@'],
                    ],
                ],
            ],
            'verbs' => [
                'class' => VerbFilter::className(),
                'actions' => [
                    'delete' => ['POST'],
                ],
            ],
        ];
    }


    /**
     * Lists all SupportHelpdesk models.
     * @return mixed
     */
    public function actionIndex()
    {
        $searchModel = new SupportHelpdeskSearch();
        $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
        $dataProvider2 = $searchModel->searchSelesai(Yii::$app->request->queryParams);

        return $this->render('index', [
            'searchModel' => $searchModel,
            'dataProvider' => $dataProvider,
            'dataProvider2' => $dataProvider2,
        ]);
    }

        public function actionIndex1()
    {
        $searchModel = new SupportHelpdeskSearch();
        $dataProvider = $searchModel->search1(Yii::$app->request->queryParams);

        return $this->render('index1', [
            'searchModel' => $searchModel,
            'dataProvider' => $dataProvider,
        ]);
    }

    /**
     * Displays a single SupportHelpdesk model.
     * @param integer $id
     * @return mixed
     */
    public function actionView($id)
    {
        return $this->render('view', [
            'model' => $this->findModel($id),
        ]);
    }

    public function actionViewPenerima($id)
    {
        return $this->render('view1', [
            'model' => $this->findModel($id),
        ]);
    }

    public function actionViewAdmin($id)
    {
        return $this->render('view2', [
            'model' => $this->findModel($id),
        ]);
    }

    public function actionReply($id) 
    {
       // $this->layout = 'empty';
      //  $model = new ReplyEmelAduan();
        $model = $this->findModel($id);

        $modelemel = new ReplyEmelAduan();
           
        if ($model->load(Yii::$app->request->post())) {

           // $model->support_helpdesk_pegawai_id = Yii::$app->user->identity->username;
            $model->support_helpdesk_status = 1;
            $model->support_helpdesk_reply_at = date('Y-m-d H:i:s');
            $model->support_helpdesk_reply_by = Yii::$app->user->identity->fullname;
          if ($model->save(false)) {

            // ------- email punya bahagian bermula
                    \Yii::$app->mailer->htmlLayout = "@common/mail/layouts/html";

                    $message = \Yii::$app->mailer->compose ( 
                        // templete location.
                        [ 'html' => '@common/mail/views/support_helpdesk_emel' ] ,

                        // detail that want to past to templete email.
                        [
                      //  'imageFileName' => Yii::getAlias('@webroot/images/mygov.png'),
                        'nama' => $model->support_helpdesk_name,
                        'tajuk' => $model->support_helpdesk_title,
                        'keterangan' => $model->support_helpdesk_description,
                        'emel' => $model->support_helpdesk_email,
                        'reply' => $model->support_helpdesk_reply,
                        'tarikhhantar' => $model->support_helpdesk_createdat
                        ]

                     );

                    // email configuration
                    $message->setFrom ( [ 'ekursus@kuskop.gov.my' => 'eKURSUS ADMINISTRATOR' ] );
                    $message->setTo ($model->support_helpdesk_email);
                    $message->setSubject ('Aduan/Pertanyaan Sistem eKursus');

                    if($message->send ()){

            Yii::$app->session->setFlash('success', Yii::t('app', 'Balasan aduan/pertanyaan berjaya dihantar'));
            return $this->redirect('index.php?r=support/support-helpdesk/index');
        }else{
            print_r('email tak jalan');
        }
    }
}
        else {

            return $this->render('reply', [
                        'model' => $model,
            ]);
        }   
}

    /**
     * Creates a new SupportHelpdesk model.
     * If creation is successful, the browser will be redirected to the 'view' page.
     * @return mixed
     */
    public function actionCreate()
    {
        $model = new SupportHelpdesk();

        if ($model->load(Yii::$app->request->post())) {

            $staffaccess = StaffAccess::find()->where(['role_code'=>'HQ'])->one();

            $model->support_helpdesk_pegawai_id = $staffaccess->staff_info_id;
            $model->support_helpdesk_role = 'HQ';
            $model->support_helpdesk_username = Yii::$app->user->identity->username;
            $model->support_helpdesk_status = 0;
            $model->support_helpdesk_createdat = date('Y-m-d H:i:s');
            $model->support_helpdesk_createdby = Yii::$app->user->identity->username;

            // echo '<pre>';
            // print_r($model);
            // echo '</pre>';
            // exit();
            if ($model->save(false)) {
                // $msg = 'Mesej telah diterima';
                // AlertMsg::alertByRole($msg, AlertMsg::PENTADBIR_SISTEM);

                        // ------- email punya bahagian bermula
                    \Yii::$app->mailer->htmlLayout = "@common/mail/layouts/html";

                    $message = \Yii::$app->mailer->compose ( 
                        // templete location.
                        [ 'html' => '@common/mail/views/support_helpdesk_emel_admin' ] ,

                        // detail that want to past to templete email.
                        [
                      //  'imageFileName' => Yii::getAlias('@webroot/images/mygov.png'),
                        'nama' => $model->support_helpdesk_name,
                        'no_spkk' => Yii::$app->user->identity->username,
                        'tajuk' => $model->support_helpdesk_title,
                        'keterangan' => $model->support_helpdesk_description,
                        'emel' => $model->support_helpdesk_email,
                        'reply' => $model->support_helpdesk_reply,
                        'tarikhhantar' => $model->support_helpdesk_createdat,
                        ]

                     );

                    // email configuration
                    $message->setFrom ('notify.ekursus@kuskop.gov.my');
                    $message->setCc ($model->support_helpdesk_email);
                    $message->setTo ('ekursus@kuskop.gov.my');
                    $message->setSubject ($model->support_helpdesk_title);

                    if($message->send()){

            Yii::$app->session->setFlash('success', Yii::t('app', 'TERIMA KASIH... Aduan Anda Telah Di Hantar'));
            return $this->redirect(['index1']);
        }else{
            print_r('email tak jalan');
        }
    }
}


            // yii::$app->session->setFlash('success','Aduan Anda Telah Di Hantar');
            // return $this->redirect(['index1']);
         else {
            return $this->render('create', [
                'model' => $model,
            ]);
        }
    }

    /**
     * Updates an existing SupportHelpdesk model.
     * If update is successful, the browser will be redirected to the 'view' page.
     * @param integer $id
     * @return mixed
     */
    public function actionUpdate($id)
    {
        $model = $this->findModel($id);

        if ($model->load(Yii::$app->request->post()) && $model->save()) {
            return $this->redirect(['view', 'id' => $model->support_helpdesk_id]);
        } else {
            return $this->render('update', [
                'model' => $model,
            ]);
        }
    }

    /**
     * Deletes an existing SupportHelpdesk model.
     * If deletion is successful, the browser will be redirected to the 'index' page.
     * @param integer $id
     * @return mixed
     */
    public function actionDelete($id)
    {
        $this->findModel($id)->delete();

        return $this->redirect(['index']);
    }

        public function actionDelete1($id)
    {   
        yii::$app->session->setFlash('success','Aduan Anda Telah Dihapuskan');
        $this->findModel($id)->delete();

        return $this->redirect(['index1']);
    }

    /**
     * Finds the SupportHelpdesk model based on its primary key value.
     * If the model is not found, a 404 HTTP exception will be thrown.
     * @param integer $id
     * @return SupportHelpdesk the loaded model
     * @throws NotFoundHttpException if the model cannot be found
     */
    protected function findModel($id)
    {
        if (($model = SupportHelpdesk::findOne($id)) !== null) {
            return $model;
        } else {
            throw new NotFoundHttpException('The requested page does not exist.');
        }
    }
}