Example #1
0
 public function update_field()
 {
     //init controller data
     $this->extensions->hk_InitData($this, __FUNCTION__);
     if (!$this->user->canModify('listing_grid/blocks_grid')) {
         $error = new AError('');
         return $error->toJSONResponse('NO_PERMISSIONS_402', array('error_text' => sprintf($this->language->get('error_permission_modify'), 'listing_grid/blocks_grid'), 'reset_value' => true));
     }
     $this->loadLanguage('design/blocks');
     $custom_block_id = (int) $this->request->get['custom_block_id'];
     $layout = new ALayoutManager();
     if ($this->request->is_POST()) {
         $tmp = array();
         if (isset($this->request->post['block_status'])) {
             $tmp['status'] = (int) $this->request->post['block_status'];
         }
         if (isset($this->request->post['block_name'])) {
             $tmp['name'] = $this->request->post['block_name'];
         }
         if (isset($this->request->post['block_title'])) {
             $tmp['title'] = $this->request->post['block_title'];
         }
         if (isset($this->request->post['block_description'])) {
             $tmp['description'] = $this->request->post['block_description'];
         }
         if (isset($this->request->post['block_content'])) {
             $tmp['content'] = $this->request->post['block_content'];
         }
         if (isset($this->request->post['block_wrapper'])) {
             $tmp['block_wrapper'] = $this->request->post['block_wrapper'];
         }
         if (isset($this->request->post['block_framed'])) {
             $tmp['block_framed'] = (int) $this->request->post['block_framed'];
         }
         if (isset($this->request->post['selected']) && is_array($this->request->post['selected'])) {
             //updating custom list of selected items
             $listing_manager = new AListingManager($custom_block_id);
             $listing_manager->deleteCustomListing();
             $k = 0;
             foreach ($this->request->post['selected'] as $id) {
                 $listing_manager->saveCustomListItem(array('id' => $id, 'sort_order' => (int) $k));
                 $k++;
             }
         }
         $tmp['language_id'] = $this->language->getContentLanguageID();
         $layout->saveBlockDescription((int) $this->request->post['block_id'], $custom_block_id, $tmp);
         if (isset($tmp['status'])) {
             $layout->editBlockStatus($tmp['status'], (int) $this->request->post['block_id'], $custom_block_id);
             $info = $layout->getBlockDescriptions($custom_block_id);
             if ($info[$tmp['language_id']]['status'] != $tmp['status']) {
                 $error = new AError('');
                 return $error->toJSONResponse('NO_PERMISSIONS_406', array('error_text' => $this->language->get('error_text_status'), 'reset_value' => true));
             }
         }
     }
     //update controller data
     $this->extensions->hk_UpdateData($this, __FUNCTION__);
 }
 public function edit_block()
 {
     //init controller data
     $this->extensions->hk_InitData($this, __FUNCTION__);
     $this->loadLanguage('banner_manager/banner_manager');
     $this->loadLanguage('design/blocks');
     $this->document->setTitle($this->language->get('banner_manager_name'));
     $this->data['heading_title'] = $this->language->get('text_banner_block');
     $lm = new ALayoutManager();
     $block = $lm->getBlockByTxtId('banner_block');
     $this->data['block_id'] = $block['block_id'];
     $custom_block_id = (int) $this->request->get['custom_block_id'];
     if (!$custom_block_id) {
         $this->redirect($this->html->getSecureURL('extension/banner_manager/insert_block'));
     }
     $layout = new ALayoutManager();
     if ($this->request->is_POST() && $this->_validateBlockForm()) {
         $content = '';
         if ($this->request->post['banner_group_name']) {
             $content = serialize(array('banner_group_name' => $this->request->post['banner_group_name']));
         }
         // saving
         $layout->saveBlockDescription($this->data['block_id'], $custom_block_id, array('name' => $this->request->post['block_name'], 'title' => $this->request->post['block_title'], 'description' => $this->request->post['block_description'], 'content' => $content, 'status' => (int) $this->request->post['block_status'], 'block_wrapper' => $this->request->post['block_wrapper'], 'block_framed' => $this->request->post['block_framed'], 'language_id' => $this->session->data['content_language_id']));
         // save list if it is custom
         if ($this->request->post['block_banners']) {
             $listing_manager = new AListingManager($custom_block_id);
             $listing_manager->deleteCustomListing();
             $k = 0;
             foreach ($this->request->post['block_banners'] as $id) {
                 $listing_manager->saveCustomListItem(array('data_type' => 'banner_id', 'id' => $id, 'sort_order' => (int) $k));
                 $k++;
             }
         } else {
             //delete the list as nothing provided
             $listing_manager = new AListingManager($custom_block_id);
             $listing_manager->deleteCustomListing();
         }
         $this->session->data['success'] = $this->language->get('text_banner_success');
         $this->redirect($this->html->getSecureURL('extension/banner_manager/edit_block', '&custom_block_id=' . $custom_block_id));
     }
     $this->data['tabs'][0] = array('href' => $this->html->getSecureURL('extension/banner_manager/insert_block', '&block_id=' . $this->data['block_id']), 'text' => $this->language->get('text_banner_block'), 'active' => true);
     $this->_getBlockForm();
     //update controller data
     $this->extensions->hk_UpdateData($this, __FUNCTION__);
 }
 public function edit()
 {
     //init controller data
     $this->extensions->hk_InitData($this, __FUNCTION__);
     $this->document->setTitle($this->language->get('heading_title'));
     if (is_int(strpos($this->request->get['custom_block_id'], '_'))) {
         $t = explode('_', $this->request->get['custom_block_id']);
         $custom_block_id = $t[1];
     } else {
         $custom_block_id = (int) $this->request->get['custom_block_id'];
     }
     // now need to know what custom block is this
     $lm = new ALayoutManager();
     $blocks = $lm->getAllBlocks();
     foreach ($blocks as $block) {
         if ($block['custom_block_id'] == $custom_block_id) {
             $block_txt_id = $block['block_txt_id'];
             break;
         }
     }
     $layout = new ALayoutManager();
     // saving
     if ($this->request->is_POST() && $this->_validateForm()) {
         switch ($block_txt_id) {
             case 'listing_block':
                 $content = array('listing_datasource' => $this->request->post['listing_datasource']);
                 $listing_manager = new AListingManager($custom_block_id);
                 // need to check previous listing_datasource of that block
                 $block_info = $lm->getBlockDescriptions($custom_block_id);
                 $block_info = current($block_info);
                 $block_info['content'] = unserialize($block_info['content']);
                 // if datasource changed - drop custom list
                 if ($block_info['content']['listing_datasource'] != $content['listing_datasource']) {
                     $listing_manager->deleteCustomListing();
                 }
                 if (strpos($content['listing_datasource'], 'custom_') !== FALSE) {
                     if ($this->request->post['selected']) {
                         $listing_manager->deleteCustomListing();
                         $k = 0;
                         foreach ($this->request->post['selected'] as $id) {
                             $listing_manager->saveCustomListItem(array('listing_datasource' => $content['listing_datasource'], 'id' => $id, 'limit' => $this->request->post['limit'], 'sort_order' => $k));
                             $k++;
                         }
                     }
                 } else {
                     if ($content['listing_datasource'] == 'media') {
                         $content['resource_type'] = $this->request->post['resource_type'];
                     }
                     $content['limit'] = $this->request->post['limit'];
                 }
                 $content = serialize($content);
                 break;
             case 'html_block':
                 $content = $this->request->post['block_content'];
                 break;
             default:
                 $this->redirect($this->html->getSecureURL('design/blocks'));
                 break;
         }
         $layout->saveBlockDescription(0, $custom_block_id, array('name' => $this->request->post['block_name'], 'title' => $this->request->post['block_title'], 'description' => $this->request->post['block_description'], 'content' => $content, 'block_wrapper' => $this->request->post['block_wrapper'], 'block_framed' => (int) $this->request->post['block_framed'], 'language_id' => $this->session->data['content_language_id']));
         $layout->editBlockStatus((int) $this->request->post['block_status'], 0, $custom_block_id);
         $this->session->data['success'] = $this->language->get('text_success');
         $this->redirect($this->html->getSecureURL('design/blocks/edit', '&custom_block_id=' . $custom_block_id));
     }
     // end of saving
     $info = $layout->getBlockDescriptions($custom_block_id);
     if (isset($info[$this->session->data['content_language_id']])) {
         $info = $info[$this->session->data['content_language_id']];
     } else {
         $info = current($info);
         unset($info['name'], $info['title'], $info['description']);
     }
     foreach ($info as $k => $v) {
         $this->data[$k] = $v;
     }
     $this->data['tabs'][0] = array('href' => '', 'text' => $this->language->get('text_' . $block_txt_id), 'active' => true);
     switch ($block_txt_id) {
         case 'listing_block':
             $this->_getListingForm();
             break;
         case 'html_block':
         default:
             $this->_getHTMLForm();
     }
     //update controller data
     $this->extensions->hk_UpdateData($this, __FUNCTION__);
 }