Exemplo n.º 1
0
    public function RightColumnContent()
    {
        switch ($this->Action) {
            case 'view':
                $this->CheckIdExist();
                $Object = Db_Product::getObjectById($this->Id);
                $this->TPL->assign('Object', $Object);
                $ObjectTrans = Db_ProductTrans::getTransByObjectId($this->Id);
                $this->TPL->assign('ObjectTrans', $ObjectTrans);
                $LanguageModel = Db_Language::getLanguageWithKey();
                $this->TPL->assign('LanguageModel', $LanguageModel);
                $ObjectImages = Db_ProductImages::getImagesByObjectId($this->Id);
                $this->TPL->assign('ObjectImages', $ObjectImages);
                break;
            case 'edit':
                $this->CheckIdExist();
                $Object = Db_Product::getObjectById($this->Id);
                $this->TPL->assign('Object', $Object);
                $ObjectTrans = Db_ProductTrans::getTransByObjectId($this->Id);
                $this->TPL->assign('ObjectTrans', $ObjectTrans);
                $LanguageModel = Db_Language::getLanguageWithKey();
                $this->TPL->assign('LanguageModel', $LanguageModel);
                $types = Db_Type::getSelect($this->LangId, $this->Id);
                $this->TPL->assign('types', $types);
                $Color = Db_Color::getSelect($this->LangId, $this->Id);
                $this->TPL->assign('Color', $Color);
                $categories = Db_Category::getSelect($this->Id);
                $this->TPL->assign('categories', $categories);
                $Brand = Db_Brand::getSelect($this->LangId);
                $this->TPL->assign('Brand', $Brand);
                $ObjectImages = Db_ProductImages::getImagesByObjectId($this->Id);
                $this->TPL->assign('ObjectImages', $ObjectImages);
                break;
            case 'delete':
                if ($this->Id != 0) {
                    Db_Product::deleteByField('id', $this->Id);
                    Db_ProductTrans::deleteByField('pt_product_id', $this->Id, 0);
                    if (is_dir(BASE_PATH . 'files/' . $this->object_path . $this->Id)) {
                        removeDir(BASE_PATH . 'files/' . $this->object_path . $this->Id);
                    }
                    $this->Msg->SetMsg($this->_T('success_item_deleted'));
                    $this->Redirect($this->PageUrl);
                }
                break;
            case 'add':
                $types = Db_Type::getSelect($this->LangId, $this->Id);
                $this->TPL->assign('types', $types);
                $LanguageModel = Db_Language::getLanguageWithKey();
                $this->TPL->assign('LanguageModel', $LanguageModel);
                //                $Feature = Db_Feature::getSelect($this->LangId);
                //                $this->TPL->assign('Feature', $Feature);
                $Color = Db_Color::getSelect($this->LangId);
                $this->TPL->assign('Color', $Color);
                $types = Db_Type::getSelect($this->LangId);
                $this->TPL->assign('types', $types);
                //                $Style = Db_Style::getSelect($this->LangId);
                //                $this->TPL->assign('Style', $Style);
                //                $Brand = Db_Brand::getSelect($this->LangId);
                //                $this->TPL->assign('Brand', $Brand);
                break;
            case 'deleteimages':
                // Db_{database_name_images}
                $ObjectImage = Db_ProductImages::getObjectDetails($this->Id);
                // $ObjectImage['{image_field}']
                if (!empty($ObjectImage) && !empty($ObjectImage['pi_image'])) {
                    // $ObjectImage['{object_id}']
                    Upload::deleteImage(BASE_PATH . '/files' . $this->object_path . $ObjectImage['pi_product_id'] . '/images/', $ObjectImage['pi_image'], $this->imageSizes);
                    $result = Db_ProductImages::deleteByField('id', $this->Id, 1);
                }
                if (isset($result)) {
                    die((string) $this->Id);
                } else {
                    die('error');
                }
                break;
            case 'save':
                if ($this->Id != 0) {
                    $this->CheckIdExist();
                }
                //                dump($_FILES); die;
                $p_new = isset($_POST['p_new']) ? 1 : 0;
                $p_published = isset($_POST['p_published']) ? 1 : 0;
                $p_price = getPost('p_price');
                $p_priority = getPost('p_priority');
                $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');
                $p_brand_id = isset($_POST['p_brand_id']) ? getPost('p_brand_id') : '';
                $p_category_id = getPost('p_category_id');
                $p_color = getPost('p_color');
                $p_style = isset($_POST['p_style']) ? getPost('p_style') : '';
                $p_type_id = getPost('p_type_id');
                //                Save data into OBJECT
                $Object = new Db_Product($this->DB, $this->Id, 'id');
                $Object->p_new = $p_new;
                $Object->p_published = $p_published;
                $Object->p_price = $p_price;
                $Object->p_priority = $p_priority;
                $Object->p_discount = $p_discount;
                $Object->p_discount_status = $p_discount_status;
                $Object->p_brand_id = $p_brand_id;
                $Object->p_category_id = !empty($p_category_id) ? implode(',', $p_category_id) : '0';
                $Object->p_color = !empty($p_color) ? implode(',', $p_color) : 0;
                $Object->p_style = $p_style;
                $Object->p_type_id = $p_type_id;
                $Object->save();
                $id = $Object->id;
                $url = Utils::FilterDotURL($pt_title[1]) . '-' . $Object->id;
                $Object->p_url = $url;
                $Object->save();
                //                Save trans values into $ObjectTrans
                foreach ($pt_title as $lang => $title) {
                    $ObjectTrans = new Db_ProductTrans();
                    $ObjectTrans->findByFields(array('pt_product_id' => $id, 'pt_lang_id' => $lang));
                    $ObjectTrans->pt_title = $pt_title[$lang];
                    $ObjectTrans->pt_description = $pt_description[$lang];
                    $ObjectTrans->pt_lang_id = $lang;
                    $ObjectTrans->pt_product_id = $id;
                    $ObjectTrans->save();
                }
                if (!empty($_FILES['p_image']) && $_FILES['p_image']['error'] == 0) {
                    $image = Db_Product::getObjectById($id);
                    if (!empty($image['p_image']) && is_dir(BASE_PATH . 'files/' . $this->object_path . $this->Id)) {
                        removeDir(BASE_PATH . 'files/' . $this->object_path . $this->Id);
                    }
                    $path = BASE_PATH . 'files/' . $this->object_path . '/' . $id . '/';
                    if ($filename = Upload::uploadImageWorkshop($path, $_FILES['p_image'], $this->imageSizes)) {
                        $Object = new Db_Product($this->DB, $id, 'id');
                        $Object->p_image = $filename;
                        $Object->save();
                    }
                }
                $pi_priority = $this->getPost('pi_priority');
                $i_priority = $this->getPost('i_priority');
                if (!empty($_FILES['li_image']) && !empty($_FILES['li_image']['name'])) {
                    $path = BASE_PATH . 'files/' . $this->object_path . '/' . $id . '/images/';
                    $files = fixFilesArray($_FILES['li_image']);
                    $imageNames = array();
                    foreach ($files as $index => $value) {
                        $imageNames[$index] = Upload::uploadImageWorkshop($path, $files[$index], $this->imageSizes);
                    }
                    foreach ($imageNames as $index => $value) {
                        if (!empty($value)) {
                            $ObjectImages = new Db_ProductImages();
                            $ObjectImages->pi_product_id = $id;
                            $ObjectImages->pi_image = $value;
                            $ObjectImages->pi_priority = $pi_priority[$index];
                            $ObjectImages->save();
                        }
                    }
                }
                if ($i_priority) {
                    foreach ($i_priority as $index => $value) {
                        $OldImages = new Db_ProductImages();
                        $OldImages->findByFields(array('id' => $index));
                        $OldImages->pi_priority = $value;
                        $OldImages->save();
                    }
                }
                $this->Msg->SetMsg($this->_T('success_item_saved'));
                $this->Redirect($this->PageUrl . '?action=view&id=' . $id);
                break;
            default:
                $Objects = Db_Product::getObjects();
                $ObjectsTrans = Db_ProductTrans::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('Title'), $this->_T('Price'), $this->_T('New'), $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']]['pt_title']);
                        $Grid_TR->Add($Grid_TD);
                        $Grid_TD = new TGrid_TTD($Object['p_price']);
                        $Grid_TR->Add($Grid_TD);
                        $Grid_TD = new TGrid_TTD($Object['p_new'] == 1 ? $this->_T('yes') : $this->_T('no'));
                        $Grid_TR->Add($Grid_TD);
                        $Grid_TD = new TGrid_TTD($Object['p_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;
    }