Your IP : 216.73.216.79


Current Path : /var/www/html/donate/frontend/controllers/
Upload File :
Current File : /var/www/html/donate/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\events\models\EventsRegistration;
use backend\modules\subscription\models\Subscription;

/**
 * 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', 'stub'],
                        'allow' => true,
                        'roles' => ['?'],
                    ],
                    [
                        'actions' => ['logout', 'error'],
                        '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 actionCertificate($registration_id) {
        $output = '';
        if (($model = EventsRegistration::findOne($registration_id)) !== null) {
            $output = $model->certificate;
        }

        $pdf = new Pdf([
            'mode' => Pdf::MODE_BLANK,
            'filename' => 'Certificate.pdf',
            'format' => Pdf::FORMAT_A4,
            'orientation' => Pdf::ORIENT_PORTRAIT,
            'destination' => Pdf::DEST_BROWSER,
            'content' => $output,
            'marginLeft' => '0',
            'marginRight' => '0',
            'marginTop' => '0',
            'marginBottom' => '0',
                //'cssFile' => '@vendor/kartik-v/yii2-mpdf/src/assets/kv-mpdf-bootstrap.min.css',
                //'cssInline' => 'table td{line-height:150%} table{border-collapse: collapse;} table thead th{background-color:#ccc;}',
        ]);
        return $pdf->render();
    }
    
    public function actionViewmembercertificate($subscription_id) {
        $output = '';
        if (($model = Subscription::findOne($subscription_id)) !== null) {
            $output = $model->subscription_cert;
        }

        $pdf = new Pdf([
            'mode' => Pdf::MODE_BLANK,
            'filename' => 'Certificate.pdf',
            'format' => Pdf::FORMAT_A4,
            'orientation' => Pdf::ORIENT_PORTRAIT,
            'destination' => Pdf::DEST_BROWSER,
            'content' => $output,
            'marginLeft' => '0',
            'marginRight' => '0',
            'marginTop' => '0',
            'marginBottom' => '0',
                //'cssFile' => '@vendor/kartik-v/yii2-mpdf/src/assets/kv-mpdf-bootstrap.min.css',
                //'cssInline' => 'table td{line-height:150%} table{border-collapse: collapse;} table thead th{background-color:#ccc;}',
        ]);
        return $pdf->render();
    }

}