예제 #1
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;
    }