Пример #1
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());
             }
         }
     }
 }