Your IP : 216.73.216.79


Current Path : /var/www/html/dosm/backend/modules/feedback/controllers/
Upload File :
Current File : /var/www/html/dosm/backend/modules/feedback/controllers/FeedbackController.php

<?php

namespace backend\modules\feedback\controllers;

use Yii;
use backend\modules\feedback\models\Feedback;
use backend\modules\feedback\models\FeedbackSearch;
use backend\modules\feedback\models\FeedbackMessages;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
use yii\filters\AccessControl;
use yii\web\UploadedFile;

/**
 * FeedbackController implements the CRUD actions for Feedback model.
 */
class FeedbackController extends Controller
{

    /**
     * {@inheritdoc}
     */
    public function behaviors()
    {
        return [
            'access' => [
                'class' => AccessControl::className(),
                'rules' => [
                    [
                        'allow' => true,
                        'roles' => ['@'],
                    ],
                ],
            ],
            'verbs' => [
                'class' => VerbFilter::className(),
                'actions' => [
                    'delete' => ['post'],
                ],
            ],
        ];
    }

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

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

    /**
     * Displays a single Feedback model.
     * @param integer $id
     * @return mixed
     * @throws NotFoundHttpException if the model cannot be found
     */
    public function actionView($id)
    {
        $model = $this->findModel($id);
        $model->scenario = 'reply';
        if ($model->load(Yii::$app->request->post())) {

            $model->myfile2 = UploadedFile::getInstance($model, 'myfile2');
            
            // nisya comment 13112024
            // $path_gambar = 'images/feedback/_' . $model->name . '_' . date("YmdHis") . '.' . $model->myfile2->extension;

            // $model->myfile2->saveAs($path_gambar);

            // $model->myfile2 = 'admin/' . $path_gambar;
            
            // nisya add 13112024
            // Check if file is uploaded
            if ($model->myfile2) {
                $path_gambar = 'images/feedback/_' . $model->name . '_' . date("YmdHis") . '.' . $model->myfile2->extension;
    
                if ($model->myfile2->saveAs($path_gambar)) {
                    // Set file path only if upload was successful
                    $model->myfile2 = 'admin/' . $path_gambar;
                }
            }
            
            //add to message
            $modelMsg = new FeedbackMessages();
            $modelMsg->feedback_id = $model->id;
            $modelMsg->user_type = 'admin';
            $modelMsg->message = $model->message;
            $modelMsg->submit_at = date("Y-m-d H:i:s");
            $modelMsg->save(false);
            $model->save(false);

            //submit email to user submit form
            $to_mail2 = $model->emel;
            $subject_mail2 = "New message for feedback from DOSM Portal #" . $model->ticket_no;
            $content_mail2 = "<p>Hi " . $model->name . ",</p>
                    <p>Admin has send new message to you for your feedback at DOSM Portal (#" . $model->ticket_no . ")</p>
                    <p><b><i>" . $model->message . "</i></b></p>
                    <p><a href='" . $_SERVER['SERVER_NAME'] . "/portal-main/feedback-view?search_email=" . urlencode($model->emel) . "&search_ticketno=" . $model->ticket_no . "'>Click here to view your feedback</a></p>
                    <p>Thank you.</p>
                    <p>Strategic Communication and International Statistics Division<br>Department of Statistics Malaysia</p>";
            Yii::$app->emailModule->sendemail($to_mail2, $subject_mail2, $content_mail2);

            //submit email to all superadmin & admin feedback
            $queryAdmin = new \yii\db\Query();
            $queryAdmin->select(['dmg_user.*'])->from('dmg_user')
                ->innerJoin('auth_assignment', 'dmg_user.id=auth_assignment.user_id')
                ->where(['IN', 'auth_assignment.item_name', ['super-admin', 'admin-feedback']])
                ->andwhere(['=', 'dmg_user.status', '10']);
            $modelAdmin = $queryAdmin->all();
            if (!empty($modelAdmin)) {
                foreach ($modelAdmin as $rowAdmin) {
                    $to_mail = $rowAdmin['email'];
                    $subject_mail = "New message - DOSM Portal Feedback #" . $model->ticket_no;
                    $content_mail = "<p>Hi " . $rowAdmin['fullname'] . ",</p>
                    <p>Admin has send new message for feedback #" . $model->ticket_no . "</p>
                    <p><b><i>" . $model->message . "</i></b></p>
                    <p>Strategic Communication and International Statistics Division<br>Department of Statistics Malaysia</p>";
                    Yii::$app->emailModule->sendemail($to_mail, $subject_mail, $content_mail);
                }
            }
            return $this->redirect(['view', 'id' => $model->id]);
        }
        return $this->render('view', ['model' => $model]);
    }

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

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

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

    /**
     * Updates an existing Feedback 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);

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

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

    /**
     * Deletes an existing Feedback 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 Feedback model based on its primary key value.
     * If the model is not found, a 404 HTTP exception will be thrown.
     * @param integer $id
     * @return Feedback the loaded model
     * @throws NotFoundHttpException if the model cannot be found
     */
    protected function findModel($id)
    {
        if (($model = Feedback::findOne($id)) !== null) {
            return $model;
        }

        throw new NotFoundHttpException('The requested page does not exist.');
    }

    public function actionCloseticket($id)
    {
        $model = $this->findModel($id);
        $model->status = 'closed';
        if ($model->save()) {

            //submit email to all superadmin & admin feedback
            $queryAdmin = new \yii\db\Query();
            $queryAdmin->select(['dmg_user.*'])->from('dmg_user')
                ->innerJoin('auth_assignment', 'dmg_user.id=auth_assignment.user_id')
                ->where(['IN', 'auth_assignment.item_name', ['super-admin', 'admin-feedback']])
                ->andwhere(['=', 'dmg_user.status', '10']);
            $modelAdmin = $queryAdmin->all();
            if (!empty($modelAdmin)) {
                foreach ($modelAdmin as $rowAdmin) {
                    $to_mail = $rowAdmin['email'];
                    $subject_mail = "Closed - DOSM Portal Feedback #" . $model->ticket_no;
                    $content_mail = "<p>Hi " . $rowAdmin['fullname'] . ",</p>
                    <p>Feedback has been closed from CMS DOSM Portal as below:</p>
                    <table cellpadding='0' cellspacing='0' border='0'>
                        <tr>
                            <td style='padding-right:2em;'>Ticket No.</td>
                            <td>" . $model->ticket_no . "</td>
                        </tr>
                        <tr>
                            <td style='padding-right:2em;'>Type</td>
                            <td>" . \backend\modules\refdynawebv2\models\Ref::getDesc('FEEDBACKTYPE', $model->feedback_type, 'descr_en') . "</td>
                        </tr>
                        <tr>
                            <td style='padding-right:2em;'>Name</td>
                            <td>" . $model->name . "</td>
                        </tr>
                        <tr>
                            <td style='padding-right:2em;'>Email Address</td>
                            <td>" . $model->emel . "</td>
                        </tr>
                        <tr>
                            <td style='padding-right:2em;'>Feedback</td>
                            <td>" . $model->details . "</td>
                        </tr>
                    </table>
                    <p>Thank you.</p><p>Strategic Communication and International Statistics Division<br>Department of Statistics Malaysia</p>";
                    Yii::$app->emailModule->sendemail($to_mail, $subject_mail, $content_mail);
                }
            }

            //submit email to user submit form
            $to_mail2 = $model->emel;
            $subject_mail2 = "Feedback from DOSM Portal closed #" . $model->ticket_no;
            $content_mail2 = "<p>Hi " . $model->name . ",</p>
                    <p>Admin has closed your feedback that you have submitted at DOSM Portal as below:</p>
                    <table cellpadding='0' cellspacing='0' border='0'>
                        <tr>
                            <td style='padding-right:2em;'>Ticket No.</td>
                            <td>" . $model->ticket_no . "</td>
                        </tr>
                        <tr>
                            <td style='padding-right:2em;'>Type</td>
                            <td>" . \backend\modules\refdynawebv2\models\Ref::getDesc('FEEDBACKTYPE', $model->feedback_type, 'descr_en') . "</td>
                        </tr>
                        <tr>
                            <td style='padding-right:2em;'>Name</td>
                            <td>" . $model->name . "</td>
                        </tr>
                        <tr>
                            <td style='padding-right:2em;'>Email Address</td>
                            <td>" . $model->emel . "</td>
                        </tr>
                        <tr>
                            <td style='padding-right:2em;'>Feedback</td>
                            <td>" . $model->details . "</td>
                        </tr>
                    </table>
                    <p><a href='" . $_SERVER['SERVER_NAME'] . "/portal-main/feedback-view?search_email=" . urlencode($model->emel) . "&search_ticketno=" . $model->ticket_no . "'>Click here to view your feedback</a></p>
                    <p>Thank you.</p><p>Strategic Communication and International Statistics Division<br>Department of Statistics Malaysia</p>";
            Yii::$app->emailModule->sendemail($to_mail2, $subject_mail2, $content_mail2);

            return $this->redirect(['view', 'id' => $model->id]);
        }
    }

    public function actionReopenticket($id)
    {
        $model = $this->findModel($id);
        $model->status = 'open';
        if ($model->save()) {
            return $this->redirect(['view', 'id' => $model->id]);
        }
    }
}