Example #1
0
 public function save_layout()
 {
     $page_controller = 'pages/content/content';
     $page_key_param = 'content_id';
     //init controller data
     $this->extensions->hk_InitData($this, __FUNCTION__);
     $this->acm = new AContentManager();
     if (!(int) $this->request->get['content_id'] && !(int) $this->request->post['content_id']) {
         $this->redirect($this->html->getSecureURL('design/content'));
     }
     $url = '';
     if (isset($this->request->get['content_id'])) {
         $content_id = (int) $this->request->get['content_id'];
         $url .= '&content_id=' . $this->request->get['content_id'];
     } elseif (isset($this->request->post['content_id'])) {
         $content_id = (int) $this->request->post['content_id'];
         $url .= '&content_id=' . $this->request->post['content_id'];
     }
     if ($this->request->server['REQUEST_METHOD'] == 'POST') {
         $tmpl_id = $this->config->get('config_storefront_template');
         // need to know unique page existing
         $post_data = $this->request->post;
         $layout = new ALayoutManager();
         $pages = $layout->getPages($page_controller, $page_key_param, $content_id);
         if (count($pages)) {
             $page_id = $pages[0]['page_id'];
             $layout_id = $pages[0]['layout_id'];
         } else {
             // create new page record
             $page_info = array('controller' => $page_controller, 'key_param' => $page_key_param, 'key_value' => $content_id);
             $default_language_id = $this->language->getDefaultLanguageID();
             $content_info = $this->acm->getContent($content_id, $default_language_id);
             if ($content_info) {
                 if ($content_info['title']) {
                     $page_info['page_descriptions'][$default_language_id]['name'] = $content_info['title'];
                 } else {
                     $page_info['page_descriptions'][$default_language_id]['name'] = 'Unnamed content page';
                 }
             }
             $page_id = $layout->savePage($page_info);
             $layout_id = '';
             // need to generate layout name
             $post_data['layout_name'] = 'Content: ' . $content_info['title'];
         }
         //create new instance with specific template/page/layout data
         $layout = new ALayoutManager($tmpl_id, $page_id, $layout_id);
         if (has_value($post_data['layout_change'])) {
             //update layout request. Clone source layout
             $layout->clonePageLayout($post_data['layout_change'], $layout_id, $post_data['layout_name']);
         } else {
             //save new layout
             $post_data['controller'] = $page_controller;
             $layout->savePageLayout($post_data);
         }
         $this->session->data['success'] = $this->language->get('text_success_layout');
         $this->redirect($this->html->getSecureURL('design/content/edit_layout', $url));
     }
     $this->redirect($this->html->getSecureURL('design/content/'));
 }