Exemplo n.º 1
0
 public function RightColumnContent()
 {
     if (in_array($this->Action, array('view', 'edit', 'add'))) {
         $languages = Db_Language::getLanguageWithKey();
         $this->TPL->assign('languages', $languages);
     }
     if (in_array($this->Action, array('view', 'edit'))) {
         $banner = Db_Banners::getObjectById($this->Id);
         $banner_trans = Db_BannerTrans::getTransById($this->Id);
         $this->TPL->assign('banner', $banner);
         $this->TPL->assign('banner_trans', $banner_trans);
     }
     switch ($this->Action) {
         case 'delete':
             if ($this->Id != 0) {
                 Db_Banners::deleteByField('id', $this->Id);
                 Db_BannerTrans::deleteByField('bt_banner_id', $this->Id, 0);
                 $this->rrmdir(BASE_PATH . 'files/' . $this->img_path . $this->Id, true);
                 $this->Msg->SetMsg($this->_T('success_item_deleted'));
                 $this->Redirect($this->PageUrl);
             }
             break;
         case 'save':
             $banner = new Db_Banners($this->DB, $this->Id, 'id');
             $banner->b_published = isset($_POST['b_published']) ? 1 : 0;
             $banner->b_url = getPost('b_url');
             $banner->b_key = getPost('b_key');
             $banner->save();
             $bt_h1 = getPost('bt_h1');
             $bt_h2 = getPost('bt_h3');
             $bt_h3 = getPost('bt_h3');
             foreach ($bt_h1 as $lang => $title) {
                 $banner_trans = new Db_BannerTrans();
                 $banner_trans->findByFields(array('bt_banner_id' => $banner->id, 'bt_lang_id' => $lang));
                 $banner_trans->bt_banner_id = $banner->id;
                 $banner_trans->bt_lang_id = $lang;
                 $banner_trans->bt_h1 = $bt_h1[$lang];
                 $banner_trans->bt_h2 = $bt_h2[$lang];
                 $banner_trans->bt_h3 = $bt_h3[$lang];
                 $banner_trans->save();
             }
             if (!empty($_FILES['b_image']) && $_FILES['b_image']['error'] == 0) {
                 $image = Db_Banners::getImageById($banner->id);
                 $path = BASE_PATH . 'files' . $this->img_path . $banner->id . DS;
                 if (is_dir($path)) {
                     Upload::deleteImage($path, $image, $this->img_sizes);
                 }
                 if ($image = Upload::uploadImage($path, $_FILES['b_image'], 'image', $this->img_sizes, 'crop')) {
                     $banner->b_image = $image;
                     $banner->save();
                 }
             }
             $this->Msg->SetMsg($this->_T('success_item_saved'));
             $this->Redirect($this->PageUrl . '?action=view&id=' . $banner->id);
             break;
         default:
             $Objects = Db_Banners::getObjects();
             $ObjectsTrans = Db_BannerTrans::getTransByLang($this->LangId);
             $ListGrid = false;
             if ($Objects) {
                 $ListGrid = new TGrid();
                 $ListGrid->Spacing = 0;
                 $ListGrid->Width = '100%';
                 $ListGrid->SetClass('table table-bordered table-highlight-head');
                 $ListGrid->AddHeaderRow($this->_T('id'), $this->_T('Key'), $this->_T('H1'), $this->_T('H2'), $this->_T('H3'), $this->_T('Published'), $this->_T('actions'));
                 $ListGrid->BeginBody();
                 foreach ($Objects as $Object) {
                     $Grid_TR = new TGrid_TTR();
                     $Grid_TD = new TGrid_TTD($Object['id'] . getButton('view', $this->PageUrl, 'view', $Object['id']));
                     $Grid_TD->AddAttr(new TAttr('class', 'col-md-1'));
                     $Grid_TR->Add($Grid_TD);
                     $Grid_TD = new TGrid_TTD($this->_T($Object['b_key']));
                     $Grid_TR->Add($Grid_TD);
                     $Grid_TD = new TGrid_TTD($ObjectsTrans[$Object['id']]['bt_h1']);
                     $Grid_TR->Add($Grid_TD);
                     $Grid_TD = new TGrid_TTD($ObjectsTrans[$Object['id']]['bt_h2']);
                     $Grid_TR->Add($Grid_TD);
                     $Grid_TD = new TGrid_TTD($ObjectsTrans[$Object['id']]['bt_h3']);
                     $Grid_TR->Add($Grid_TD);
                     $Grid_TD = new TGrid_TTD($Object['b_published'] == 1 ? $this->_T('yes') : $this->_T('no'));
                     $Grid_TD->AddAttr(new TAttr('class', 'col-md-1'));
                     $Grid_TR->Add($Grid_TD);
                     $Grid_TD = new TGrid_TTD(getButton('edit', $this->PageUrl, 'edit', $Object['id']) . getButton('delete', $this->PageUrl, 'delete', $Object['id']));
                     $Grid_TD->AddAttr(new TAttr('class', 'align-center col-md-1'));
                     $Grid_TR->Add($Grid_TD);
                     $ListGrid->AddTR($Grid_TR);
                 }
                 $ListGrid->EndBody();
                 $ListGrid = $ListGrid->Html();
             }
             $this->TPL->assign('ListGrid', $ListGrid);
             break;
     }
     $msg = $this->Msg->Html();
     $this->TPL->assign('msg', $msg);
     $this->TPL->assign('Action', $this->Action);
     $result = $this->TPL->display(null, true);
     $this->Msg->Clear();
     return $result;
 }
Exemplo n.º 2
0
    public function RightColumnContent()
    {
        switch ($this->Action) {
            case 'view':
                $this->CheckIdExist();
                $Object = Db_Banners::getObjectById($this->Id);
                $this->TPL->assign('Object', $Object);
                $ObjectTrans = Db_BannerTrans::getTransByObjectId($this->Id);
                $this->TPL->assign('ObjectTrans', $ObjectTrans);
                $LanguageModel = Db_Language::getLanguageWithKey();
                $this->TPL->assign('LanguageModel', $LanguageModel);
                break;
            case 'edit':
                $this->CheckIdExist();
                $Object = Db_Banners::getObjectById($this->Id);
                $this->TPL->assign('Object', $Object);
                $ObjectTrans = Db_BannerTrans::getTransByObjectId($this->Id);
                $this->TPL->assign('ObjectTrans', $ObjectTrans);
                $LanguageModel = Db_Language::getLanguageWithKey();
                $this->TPL->assign('LanguageModel', $LanguageModel);
                break;
            case 'delete':
                if ($this->Id != 0) {
                    Db_Banners::deleteByField('id', $this->Id);
                    Db_BannerTrans::deleteByField('bt_banner_id', $this->Id, 0);
                    $this->rrmdir(BASE_PATH . 'files/' . $this->object_path . $this->Id, true);
                    $this->Msg->SetMsg($this->_T('success_item_deleted'));
                    $this->Redirect($this->PageUrl);
                }
                break;
            case 'add':
                $LanguageModel = Db_Language::getLanguageWithKey();
                $this->TPL->assign('LanguageModel', $LanguageModel);
                break;
            case 'save':
                if ($this->Id != 0) {
                    $this->CheckIdExist();
                }
                $b_priority = getPost('b_priority');
                $b_published = isset($_POST['b_published']) ? 1 : 0;
                $b_size = getPost('b_size');
                $b_url = getPost('b_url');
                $bt_maintitle = getPost('bt_maintitle');
                $bt_subtitle = getPost('bt_subtitle');
                //                Save data into OBJECT
                $Object = new Db_Banners($this->DB, $this->Id, 'id');
                $Object->b_priority = $b_priority;
                $Object->b_published = $b_published;
                $Object->b_size = $b_size;
                $Object->b_url = $b_url;
                $Object->save();
                //                Take id of $Object
                $id = $Object->id;
                //                Save trans values into $ObjectTrans
                foreach ($bt_maintitle as $lang => $title) {
                    $ObjectTrans = new Db_BannerTrans();
                    $ObjectTrans->findByFields(array('bt_banner_id' => $id, 'bt_lang_id' => $lang));
                    $ObjectTrans->bt_banner_id = $id;
                    $ObjectTrans->bt_lang_id = $lang;
                    $ObjectTrans->bt_maintitle = $bt_maintitle[$lang];
                    $ObjectTrans->bt_subtitle = $bt_subtitle[$lang];
                    $ObjectTrans->save();
                }
                if (!empty($_FILES['b_image']) && $_FILES['b_image']['error'] == 0) {
                    $image = Db_Banners::getObjectById($id);
                    $path = BASE_PATH . 'files/' . $this->object_path . '/' . $id . '/';
                    if (!empty($image['b_image']) && is_dir(BASE_PATH . 'files/' . $this->object_path . $this->Id)) {
                        removeDir(BASE_PATH . 'files/' . $this->object_path . $this->Id);
                    }
                    if ($filename = Upload::uploadImageWorkshop($path, $_FILES['b_image'], $this->imageSizes)) {
                        $Object = new Db_Banners($this->DB, $id, 'id');
                        $Object->b_image = $filename;
                        $Object->save();
                    }
                }
                $this->Msg->SetMsg($this->_T('success_item_saved'));
                $this->Redirect($this->PageUrl . '?action=view&id=' . $id);
                break;
            default:
                $Objects = Db_Banners::getObjects();
                $ObjectsTrans = Db_BannerTrans::getTransByLang($this->LangId);
                $ListGrid = false;
                if ($Objects) {
                    $ListGrid = new TGrid();
                    $ListGrid->Spacing = 0;
                    $ListGrid->Width = '100%';
                    $ListGrid->SetClass('table table-bordered table-highlight-head');
                    $ListGrid->AddHeaderRow($this->_T('id'), $this->_T('Main title'), $this->_T('Subtitle'), $this->_T('Size'), $this->_T('Priority'), $this->_T('Published'), $this->_T('actions'));
                    $ListGrid->BeginBody();
                    foreach ($Objects as $Object) {
                        $Grid_TR = new TGrid_TTR();
                        $Grid_TD = new TGrid_TTD($Object['id'] . ' (&nbsp;<a href="' . $this->PageUrl . '?action=view&id=' . $Object['id'] . '">' . $this->_T('see') . '</a>&nbsp;)');
                        $Grid_TR->Add($Grid_TD);
                        $Grid_TD = new TGrid_TTD($ObjectsTrans[$Object['id']]['bt_maintitle']);
                        $Grid_TR->Add($Grid_TD);
                        $Grid_TD = new TGrid_TTD($ObjectsTrans[$Object['id']]['bt_subtitle']);
                        $Grid_TR->Add($Grid_TD);
                        $Grid_TD = new TGrid_TTD($Object['b_size']);
                        $Grid_TR->Add($Grid_TD);
                        $Grid_TD = new TGrid_TTD($Object['b_priority']);
                        $Grid_TR->Add($Grid_TD);
                        $Grid_TD = new TGrid_TTD($Object['b_published'] == 1 ? $this->_T('yes') : $this->_T('no'));
                        $Grid_TR->Add($Grid_TD);
                        $Grid_TD = new TGrid_TTD('
								<a class="bs-tooltip" title="" href="' . $this->PageUrl . '?action=edit&id=' . $Object['id'] . '" data-original-title="' . $this->_T('edit') . '"><i class="icon-pencil"></i></a>
								<a class="bs-tooltip confirm-dialog" data-text="' . _T('sure_you_want_to_delete') . '" title="" href="' . $this->PageUrl . '?action=delete&id=' . $Object['id'] . '" data-original-title="' . $this->_T('delete') . '"><i class="icon-trash"></i></a>
							');
                        $Grid_TD->AddAttr(new TAttr('class', 'align-center'));
                        $Grid_TR->Add($Grid_TD);
                        $ListGrid->AddTR($Grid_TR);
                    }
                    $ListGrid->EndBody();
                    $ListGrid = $ListGrid->Html();
                }
                $this->TPL->assign('ListGrid', $ListGrid);
                break;
        }
        $msg = $this->Msg->Html();
        $this->TPL->assign('msg', $msg);
        $this->TPL->assign('Action', $this->Action);
        $result = $this->TPL->display(null, true);
        $this->Msg->Clear();
        return $result;
    }