public function RightColumnContent()
 {
     if (in_array($this->Action, array('add', 'view', 'edit'))) {
         $languages = Db_Language::getLanguageWithKey();
         $this->TPL->assign('languages', $languages);
         $options = Db_Options::getFulLDetails();
         $product_options = Db_ProductOptions::getOptionsByProductId($this->Id);
         $this->TPL->assign('options', $options);
         $this->TPL->assign('product_options', $product_options);
     }
     if (in_array($this->Action, array('view', 'edit'))) {
         $product = Db_Products::getDetailsById($this->Id);
         $product_trans = Db_ProductTrans::getDetailsById($this->Id);
         $this->TPL->assign('product', $product);
         $this->TPL->assign('product_trans', $product_trans);
     }
     switch ($this->Action) {
         case 'delete':
             if ($this->Id == 0) {
                 break;
             }
             Db_Products::deleteByField('id', $this->Id);
             Db_ProductTrans::deleteAllByField('pt_product_id', $this->Id);
             Db_ProductOptions::deleteAllByField('po_product_id', $this->Id);
             Upload::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':
             $p_model = getPost('p_model');
             $p_url = getPost('p_url');
             $p_published = isset($_POST['p_published']) ? 1 : 0;
             $p_price = getPost('p_price');
             $p_discount = getPost('p_discount');
             $p_discount_status = isset($_POST['p_discount_status']) ? 1 : 0;
             $pt_title = getPost('pt_title');
             $pt_description = getPost('pt_description');
             $options = getPost('options');
             $product = new Db_Products($this->DB, $this->Id, 'id');
             $product->p_model = $p_model;
             $product->p_url = $p_url;
             $product->p_published = $p_published;
             $product->p_price = $p_price;
             $product->p_discount = $p_discount;
             $product->p_discount_status = $p_discount_status;
             $product->p_type = $this->productType;
             $product->save();
             foreach ($pt_title as $lang => $item) {
                 $product_trans = new Db_ProductTrans();
                 $product_trans->findByFields(array('pt_product_id' => $product->id, 'pt_lang_id' => $lang));
                 $product_trans->pt_title = $pt_title[$lang];
                 $product_trans->pt_description = $pt_description[$lang];
                 $product_trans->pt_lang_id = $lang;
                 $product_trans->pt_product_id = $product->id;
                 $product_trans->save();
             }
             if (!empty($_FILES['p_image']) && $_FILES['p_image']['error'] == 0) {
                 $image = Db_Products::getImageById($product->id);
                 $path = BASE_PATH . 'files' . $this->img_path . $product->id . '/';
                 if (is_dir($path)) {
                     Upload::deleteImage($path, $image, $this->img_sizes);
                 }
                 if ($filename = Upload::uploadImage($path, $_FILES['p_image'], 'product', $this->img_sizes, 'crop')) {
                     $product->p_image = $filename;
                     $product->save();
                 }
             }
             if (!empty($options)) {
                 foreach ($options as $option_id => $option_value) {
                     if (empty($option_value) || empty($option_id)) {
                         continue;
                     }
                     $product_option = new Db_ProductOptions();
                     $product_option->findByFields(array('po_option_id' => $option_id, 'po_product_id' => $product->id));
                     $product_option->po_option_id = $option_id;
                     $product_option->po_product_id = $product->id;
                     $product_option->po_value = $option_value;
                     $product_option->save();
                 }
             }
             $this->Msg->SetMsg($this->_T('success_item_saved'));
             $this->Redirect($this->PageUrl . '?action=view&id=' . $product->id);
             break;
         default:
             $Objects = Db_Products::getObjects($this->productType);
             $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('Title'), $this->_T('Url'), $this->_T('Enabled'), $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_TR->Add($Grid_TD);
                     $Grid_TD = new TGrid_TTD($Object['title']);
                     $Grid_TR->Add($Grid_TD);
                     $Grid_TD = new TGrid_TTD($Object['url']);
                     $Grid_TR->Add($Grid_TD);
                     $Grid_TD = new TGrid_TTD($Object['enabled'] == 1 ? $this->_T('yes') : $this->_T('no'));
                     $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'));
                     $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;
 }
 public function RightColumnContent()
 {
     if (in_array($this->Action, array('add', 'view', 'edit'))) {
         $languages = Db_Language::getLanguageWithKey();
         $this->TPL->assign('languages', $languages);
     }
     if (in_array($this->Action, array('view', 'edit'))) {
         $option = Db_Options::getDetailsById($this->Id);
         $option_trans = Db_OptionTrans::getDetailsById($this->Id);
         $this->TPL->assign('option', $option);
         $this->TPL->assign('option_trans', $option_trans);
     }
     switch ($this->Action) {
         case 'delete':
             if ($this->Id == 0) {
                 return false;
             }
             Db_Options::deleteByField('id', $this->Id);
             Db_OptionTrans::deleteAllByField('ot_option_id', $this->Id);
             Db_ProductOptions::deleteAllByField('po_option_id', $this->Id);
             $this->Msg->SetMsg($this->_T('success_item_deleted'));
             $this->Redirect($this->PageUrl);
             break;
         case 'save':
             $o_key = getPost('o_key');
             $o_priority = getPost('o_priority');
             $o_enabled = isset($_POST['o_enabled']) ? 1 : 0;
             $ot_title = getPost('ot_title');
             $option = new Db_Options($this->DB, $this->Id, 'id');
             $option->o_key = $o_key;
             $option->o_enabled = $o_enabled;
             $option->o_priority = $o_priority;
             $option->save();
             foreach ($ot_title as $lang => $title) {
                 $option_trans = new Db_OptionTrans();
                 $option_trans->findByFields(array('ot_option_id' => $option->id, 'ot_lang_id' => $lang));
                 $option_trans->ot_title = $title;
                 $option_trans->ot_lang_id = $lang;
                 $option_trans->ot_option_id = $option->id;
                 $option_trans->save();
             }
             $this->Msg->SetMsg($this->_T('success_item_saved'));
             $this->Redirect($this->PageUrl . '?action=view&id=' . $option->id);
             break;
         default:
             $Objects = Db_Options::getFulLDetails();
             $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('Title'), $this->_T('Enabled'), $this->_T('Priority'), $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($Object['option_key']);
                     $Grid_TR->Add($Grid_TD);
                     $Grid_TD = new TGrid_TTD($Object['title']);
                     $Grid_TR->Add($Grid_TD);
                     $Grid_TD = new TGrid_TTD($Object['enabled']);
                     $Grid_TD->AddAttr(new TAttr('class', 'col-md-1'));
                     $Grid_TR->Add($Grid_TD);
                     $Grid_TD = new TGrid_TTD($Object['priority']);
                     $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;
 }