Esempio n. 1
0
 function indexAction()
 {
     // retrieve the ID of the requested page
     $pageID = $this->view->pageID = $this->_getParam('ID');
     $pageDetails = new PagesIndex();
     $pageDetailsSelect = $pageDetails->select();
     $pageDetailsSelect->where('PI_PageID = ?', $pageID)->where('PI_LanguageID = ?', $this->_defaultEditLanguage);
     $pageDetailsData = $pageDetails->fetchRow($pageDetailsSelect)->toArray();
     $this->view->assign("pageTitle", $pageDetailsData["PI_PageTitle"]);
     $authData = $this->view->user;
     $authID = $authData['EU_ID'];
     if (Cible_FunctionsAdministrators::checkAdministratorPageAccess($authID, $pageID, "data")) {
         $authData = $this->view->user;
         $authID = $authData['EU_ID'];
         if (Cible_FunctionsAdministrators::checkAdministratorPageAccess($authID, $pageID, "structure")) {
             $this->view->assign('hasAccessToStructure', true);
         }
         // Retrieve the page view layout
         $page = new Pages();
         $page_select = $page->select()->setIntegrityCheck(false);
         $page_select->from('Pages')->join('Views', 'Pages.P_ViewID = Views.V_ID')->where('P_ID = ?', $pageID);
         $page_info = Cible_FunctionsPages::getPageViewDetails($pageID);
         $template_file = 'index/' . $page_info['V_Path'];
         $_zone_count = $page_info['V_ZoneCount'];
         // make a request to get all the blocks to be displayed
         $blocks = new Blocks();
         $select = $blocks->select()->setIntegrityCheck(false);
         $select->from('Blocks')->join('Modules', 'Modules.M_ID = Blocks.B_ModuleID')->join('Pages', 'Blocks.B_PageID = P_ID')->join('BlocksIndex', 'Blocks.B_ID = BlocksIndex.BI_BlockID')->where('Blocks.B_PageID = ?', $pageID)->where('BlocksIndex.BI_LanguageID = ?', Zend_Registry::get('languageID'))->order('Blocks.B_Position ASC');
         //Send the results to the view
         $rows = $blocks->fetchAll($select);
         $_blocks = array();
         foreach ($rows as $row) {
             // create the placeholder object if not already defined
             if (!isset($_blocks[$row['B_ZoneID']])) {
                 $_blocks[$row['B_ZoneID']] = array();
             }
             $_blocks[$row['B_ZoneID']][] = $row->toArray();
         }
         $this->view->assign('template_file', $template_file);
         $this->view->assign('zone_count', $_zone_count);
         $this->view->assign('blocks', $_blocks);
         // Load the modules in the view
         $Modules = new Modules();
         $modules = $Modules->fetchAll();
         $this->view->assign('modules', $modules->toArray());
     } else {
         $this->view->assign('template_file', "");
         $this->view->assign('error_message_permission', $this->view->getCibleText('error_message_permission'));
     }
 }
Esempio n. 2
0
 function editAction()
 {
     $this->view->assign('isXmlHttpRequest', $this->_isXmlHttpRequest);
     $this->view->assign('success', false);
     $this->view->title = "Modification de la page";
     // retrieve the ID of the requested page
     $PageID = (int) $this->_getParam('ID');
     if (Cible_ACL::hasAccess($PageID)) {
         // get page informations
         $Page = Cible_FunctionsPages::getPageDetails($PageID, $this->_currentEditLanguage);
         $page_info = $Page->toArray();
         $this->view->home = $page_info['P_Home'];
         $this->view->pageTitle = isset($page_info['PI_PageTitle']) ? $page_info['PI_PageTitle'] : '';
         $imageHeaderArray = $this->_findImagesFiles();
         $form = new FormPage(array('baseDir' => $this->view->baseUrl(), 'pageID' => $PageID, 'imageHeaderArray' => $imageHeaderArray));
         $layouts = Cible_FunctionsPages::getAvailableLayouts();
         $templates = Cible_FunctionsPages::getAvailableTemplates();
         $form = Cible_FunctionsPages::fillSelectLayouts($form, $layouts);
         $form = Cible_FunctionsPages::fillSelectTemplates($form, $templates);
         $this->view->form = $form;
         if ($this->_request->isPost()) {
             $formData = $this->_request->getPost();
             $PageIndex = $formData['PI_PageIndex'];
             // replace all double underscore by simple underscore
             while (substr_count($PageIndex, "__") > 0) {
                 $PageIndex = str_replace("__", "_", $PageIndex);
             }
             if (isset($page_info['PI_PageIndex']) && $page_info['PI_PageIndex'] == $formData['PI_PageIndex']) {
                 $form->getElement('PI_PageIndex')->clearValidators();
             }
             if ($form->isValid($formData)) {
                 $db = $this->_db;
                 // update the P_LayoutID for the current Page
                 $db->update('Pages', array('P_LayoutID' => $formData['P_LayoutID'], 'P_ShowTitle' => $formData['P_ShowTitle']), 'P_ID = ' . $PageID);
                 // check to update P_ViewID
                 if ($formData['P_ViewID'] != $page_info['P_ViewID']) {
                     //get current number of zones
                     $previous_zone_count = $page_info['V_ZoneCount'];
                     // update the P_ViewID for the current Page
                     $db->update('Pages', array('P_ViewID' => $formData['P_ViewID']), 'P_ID = ' . $PageID);
                     // Fetch the new selected view details
                     $new_view_details = Cible_FunctionsPages::getPageViewDetails($PageID);
                     $new_zone_count = $new_view_details['V_ZoneCount'];
                     // if our new zone count is smaller then our previous zone count, we need to move our deleted zone blocks to zone 1
                     if ($new_zone_count < $previous_zone_count) {
                         //reset where just in case
                         $where = array();
                         $where[] = $db->quoteInto('B_PageID = ?', $PageID);
                         $where[] = $db->quoteInto('B_ZoneID > ?', $new_zone_count);
                         $db->update('Blocks', array('B_ZoneID' => '-1'), $where);
                     }
                 }
                 //$Page['PI_LanguageID'] = $this->_currentEditLanguage;
                 if (isset($Page['PI_PageTitle'])) {
                     $Page['PI_PageTitle'] = $formData['PI_PageTitle'];
                     $Page['PI_PageIndex'] = $PageIndex;
                     $Page['PI_Status'] = $formData['PI_Status'];
                     $Page['PI_MetaTitle'] = $formData['PI_MetaTitle'];
                     $Page['PI_MetaDescription'] = $formData['PI_MetaDescription'];
                     $Page['PI_MetaKeywords'] = $formData['PI_MetaKeywords'];
                     $Page['PI_MetaOther'] = $formData['PI_MetaOther'];
                     if (!empty($formData['PI_TitleImageSrc'])) {
                         $Page['PI_TitleImageSrc'] = $formData['PI_TitleImageSrc'];
                     }
                     if (!empty($formData['PI_AltPremiereImage'])) {
                         $Page['PI_AltPremiereImage'] = $formData['PI_AltPremiereImage'];
                     }
                     $Page->save();
                 } else {
                     $data = array('PI_PageID' => $PageID, 'PI_LanguageID' => $this->_currentEditLanguage, 'PI_PageTitle' => $formData['PI_PageTitle'], 'PI_PageIndex' => $PageIndex, 'PI_Status' => $formData['PI_Status'], 'PI_MetaTitle' => $formData['PI_MetaTitle'], 'PI_MetaDescription' => $formData['PI_MetaDescription'], 'PI_MetaKeywords' => $formData['PI_MetaKeywords'], 'PI_MetaOther' => $formData['PI_MetaOther'], 'PI_TitleImageSrc' => $formData['PI_TitleImageSrc'], 'PI_AltPremiereImage' => $formData['PI_AltPremiereImage']);
                     $this->_db->insert('PagesIndex', $data);
                 }
                 $indexData['pageID'] = $PageID;
                 $indexData['moduleID'] = 0;
                 $indexData['contentID'] = $PageID;
                 $indexData['languageID'] = Zend_Registry::get("currentEditLanguage");
                 $indexData['title'] = $formData['PI_PageTitle'];
                 $indexData['text'] = '';
                 $indexData['link'] = '';
                 $indexData['contents'] = $formData['PI_PageTitle'];
                 if ($formData['PI_Status'] == 1) {
                     $indexData['action'] = 'update';
                 } else {
                     $indexData['action'] = 'delete';
                 }
                 Cible_FunctionsIndexation::indexation($indexData);
                 // if not and ajax request, redirect else simply return as json success code and page details
                 if (!$this->_isXmlHttpRequest) {
                     $this->_redirect('/');
                 } else {
                     $buttonAction = $formData['buttonAction'];
                     $this->view->assign('buttonAction', $buttonAction);
                     $this->view->assign('success', true);
                     $this->view->assign('pageID', $PageID);
                     $this->view->assign('pageTitle', $formData['PI_PageTitle']);
                     $this->view->assign('currentEditLanguage', $this->_currentEditLanguage);
                 }
             } else {
                 $form->getElement('PI_MetaOther')->clearFilters();
                 $form->populate($formData);
             }
         } else {
             if ($PageID > 0) {
                 $form->getElement('PI_MetaOther')->clearFilters();
                 $form->populate($Page->toArray());
             }
         }
     }
 }