public function editAction() { $this->view->title = "Modification d'une galerie"; //if ($this->view->aclIsAllowed('gallery','manage',true)){ // variables $this->view->assign('isXmlHttpRequest', $this->_isXmlHttpRequest); $this->view->assign('success', false); $pageID = $this->_getParam('pageID'); $blockID = $this->_getParam('blockID'); $galleryID = $this->_getParam('galleryID'); $baseDir = $this->view->baseUrl(); $galleryObject = new GalleryObject(); $galleryData = $galleryObject->populate($galleryID, Zend_Registry::get("currentEditLanguage")); $imageObject = new ImageObject(); $imageData = $imageObject->populate($galleryData['G_ImageID'], Zend_Registry::get("currentEditLanguage")); if (!$galleryData) { if ($this->_request->isPost()) { $this->view->assign('success', true); } $this->view->assign('deleted', true); $this->view->assign('galleryID', $galleryID); } else { $this->view->assign('deleted', false); $config = Zend_Registry::get('config')->toArray(); $thumbMaxHeight = $config['gallery']['image']['thumb']['maxHeight']; $thumbMaxWidth = $config['gallery']['image']['thumb']['maxWidth']; $thumbName = str_replace($imageData['ImageSrc'], $thumbMaxWidth . 'x' . $thumbMaxHeight . '_' . $imageData['ImageSrc'], $imageData['ImageSrc']); if ($this->_request->isPost()) { $formData = $this->_request->getPost(); $isNewImage = $formData['isNewImage']; if ($isNewImage == 'true') { $imageSrc = Zend_Registry::get("www_root") . "/data/images/gallery/" . $galleryID . "/tmp/mcith/mcith_" . $formData['ImageSrc']; } else { $imageSrc = Zend_Registry::get("www_root") . "/data/images/gallery/{$galleryID}/" . $galleryData['G_ImageID'] . "/" . $thumbName; } } else { //$imageData['ImageSrc_preview'] = Zend_Registry::get("www_root")."/data/images/gallery/$galleryID/".$galleryData['G_ImageID']."/".$thumbName; $imageSrc = Zend_Registry::get("www_root") . "/data/images/gallery/{$galleryID}/" . $galleryData['G_ImageID'] . "/" . $thumbName; //$this->view->assign('imageUrl', $imageData['ImageSrc_preview']); $this->view->assign('imageUrl', $imageSrc); $isNewImage = 'false'; //$imageSrc = $imageData['ImageSrc_preview']; } // generate the form if ($blockID != '') { $cancelUrl = "{$baseDir}/gallery/index/list/blockID/{$blockID}/pageID/{$pageID}"; } elseif ($this->_categoryID != '') { $cancelUrl = "{$baseDir}/gallery/index/list/catID/{$this->_categoryID}"; } else { $cancelUrl = "{$baseDir}/gallery/index/list/"; } $form = new FormGallery(array('baseDir' => $baseDir, 'cancelUrl' => '', 'galleryID' => $galleryID, 'imageSrc' => $imageSrc, 'isNewImage' => $isNewImage, 'requiredTitle' => true, 'requiredPosition' => false, 'requiredDescription' => false)); if ($this->_request->isPost()) { $formData = $this->_request->getPost(); if ($form->isValid($formData)) { $galleryObject = new GalleryObject(); $formattedName = Cible_FunctionsGeneral::formatValueForUrl($formData['GI_Title']); $formData['GI_ValUrl'] = $formattedName; if ($blockID != '') { $blockParameters = Cible_FunctionsBlocks::getBlockParameters($blockID); $formData['G_CategoryID'] = $blockParameters[0]['P_Value']; } elseif ($this->_categoryID != '') { $formData['G_CategoryID'] = $this->_categoryID; } if ($formData['isNewImage'] == 'true') { // create the image $imageObject = new ImageObject(); $formData['II_Title'] = $formData['GI_Title']; $formData['II_Description'] = $formData['GI_Description']; $imageID = $imageObject->insert($formData, Zend_Registry::get("currentEditLanguage")); // update the galery $formData['G_CreationDate'] = $galleryData['G_CreationDate']; $formData['G_ImageID'] = $imageID; $galleryObject->save($galleryID, $formData, Zend_Registry::get("currentEditLanguage")); $config = Zend_Registry::get('config')->toArray(); $srcOriginal = "../../{$this->_config->document_root}/data/images/gallery/" . $galleryID . "/tmp/" . $form->getValue('ImageSrc'); $originalMaxHeight = $config['gallery']['image']['original']['maxHeight']; $originalMaxWidth = $config['gallery']['image']['original']['maxWidth']; $originalName = str_replace($form->getValue('ImageSrc'), $originalMaxWidth . 'x' . $originalMaxHeight . '_' . $form->getValue('ImageSrc'), $form->getValue('ImageSrc')); $srcThumb = "../../{$this->_config->document_root}/data/images/gallery/" . $galleryID . "/tmp/mcith/mcith_" . $form->getValue('ImageSrc'); $thumbMaxHeight = $config['gallery']['image']['thumb']['maxHeight']; $thumbMaxWidth = $config['gallery']['image']['thumb']['maxWidth']; $thumbName = str_replace($form->getValue('ImageSrc'), $thumbMaxWidth . 'x' . $thumbMaxHeight . '_' . $form->getValue('ImageSrc'), $form->getValue('ImageSrc')); Cible_FunctionsImageResampler::resampled(array('src' => $srcOriginal, 'maxWidth' => $originalMaxWidth, 'maxHeight' => $originalMaxHeight)); Cible_FunctionsImageResampler::resampled(array('src' => $srcThumb, 'maxWidth' => $thumbMaxWidth, 'maxHeight' => $thumbMaxHeight)); // Attempts to create the directory specified by pathname. mkdir("../../{$this->_config->document_root}/data/images/gallery/" . $galleryID . "/" . $imageID) or die("Could not make directory"); // Rename and move the original image to the specific place rename("../../{$this->_config->document_root}/data/images/gallery/" . $galleryID . "/tmp/" . $form->getValue('ImageSrc'), "../../{$this->_config->document_root}/data/images/gallery/" . $galleryID . "/" . $imageID . "/" . $originalName); // Rename and move the thumbnail image to the specific place rename("../../{$this->_config->document_root}/data/images/gallery/" . $galleryID . "/tmp/mcith/mcith_" . $form->getValue('ImageSrc'), "../../{$this->_config->document_root}/data/images/gallery/" . $galleryID . "/" . $imageID . "/" . $thumbName); } else { $formData['G_CreationDate'] = $galleryData['G_CreationDate']; $formData['G_ImageID'] = $galleryData['G_ImageID']; $galleryObject->save($galleryID, $formData, Zend_Registry::get("currentEditLanguage")); } if ($blockID != '') { $indexData['pageID'] = $blockParameters[0]['P_Value']; $indexData['moduleID'] = $this->_moduleID; $indexData['contentID'] = $galleryID; $indexData['languageID'] = Zend_Registry::get("currentEditLanguage"); $indexData['title'] = $formData['GI_Title']; $indexData['text'] = ''; $indexData['link'] = 'gallery'; $indexData['contents'] = $formData['GI_Title'] . " " . $formData['GI_Description']; if ($formData['G_Online'] == 1) { $indexData['action'] = 'update'; } else { $indexData['action'] = 'delete'; } Cible_FunctionsIndexation::indexation($indexData); } $imageSelect = new GalleriesImages(); $select = $imageSelect->select()->setIntegrityCheck(false)->from('Galleries_Images')->where('GI_GalleryID = ?', $galleryID)->join('ImagesIndex', 'II_ImageID = GI_ImageID')->where('II_LanguageID = ?', Zend_Registry::get("currentEditLanguage")); $imageData = $imageSelect->fetchAll($select)->toArray(); $cpt = count($imageData); for ($i = 0; $i < $cpt; $i++) { $indexData['pageID'] = $galleryID; $indexData['moduleID'] = $this->_moduleID; $indexData['contentID'] = $imageData[$i]['II_ImageID']; $indexData['languageID'] = $imageData[$i]['II_LanguageID']; $indexData['title'] = $imageData[$i]['II_Title']; $indexData['text'] = ''; $indexData['link'] = 'image'; $indexData['contents'] = $imageData[$i]['II_Title'] . " " . $imageData[$i]['II_Description']; if ($formData['G_Online'] == 1) { $indexData['action'] = 'update'; if ($imageData[$i]['GI_Online'] == 1) { Cible_FunctionsIndexation::indexation($indexData); } } else { $indexData['action'] = 'delete'; Cible_FunctionsIndexation::indexation($indexData); } } if (!$this->_isXmlHttpRequest) { if ($blockID != '') { $this->_redirect("/gallery/index/list/blockID/{$blockID}/pageID/{$pageID}"); } else { $this->_redirect("/gallery/index/list/catID/{$this->_categoryID}"); } } else { $buttonAction = $formData['buttonAction']; $this->view->assign('buttonAction', $buttonAction); $this->view->assign('success', true); $this->view->assign('galleryID', $galleryID); $this->view->assign('galleryTitle', $form->getValue('GI_Title')); $this->view->assign('galleryDescription', $form->getValue('GI_Description')); $this->view->assign('galleryLanguage', Zend_Registry::get("currentEditLanguage")); } } else { $this->view->form = $form; } } else { $form->populate($galleryData); $form->populate($imageData); $this->view->form = $form; } } //} }
function deleteAction() { $this->view->title = "Suppression d'une image"; //if ($this->view->aclIsAllowed('gallery','manage',true)){ $this->view->assign('isXmlHttpRequest', $this->_isXmlHttpRequest); $this->view->assign('success', false); $pageID = (int) $this->_getParam('pageID'); $blockID = (int) $this->_getParam('blockID'); $galleryID = (int) $this->_getParam('galleryID'); $imageID = (int) $this->_getParam('imageID'); $imageIndexSelect = new ImagesIndex(); $select = $imageIndexSelect->select()->where('II_ImageID = ?', $imageID); $imageIndexData = $imageIndexSelect->fetchRow($select); if (!$imageIndexData) { if ($this->_request->isPost()) { $this->view->assign('success', true); } $this->view->assign('deleted', true); $this->view->assign('imageID', $imageID); } else { $imageObject = new ImageObject(); $imageIndexData = $imageObject->populate($imageID, Zend_Registry::get("languageID")); //$imageIndexData = $imageObject->populate($imageID,$this->_defaultEditLanguage); $this->view->assign('deleted', false); $return = "/gallery/index/list/blockID/{$blockID}/pageID/{$pageID}"; $this->view->return = $this->view->baseUrl() . $return; $this->view->image = $imageIndexData; if ($this->_request->isPost()) { //$del = $this->_request->getPost('delete'); //if ($del && $imageIndexData) { if ($imageIndexData) { $imageSelect = new ImagesIndex(); $select = $imageSelect->select()->where('II_ImageID = ?', $imageID); $imageData = $imageSelect->fetchAll($select)->toArray(); $cpt = count($imageData); for ($i = 0; $i < $cpt; $i++) { $indexData['moduleID'] = $this->_moduleID; $indexData['contentID'] = $imageData[$i]['II_ImageID']; $indexData['languageID'] = $imageData[$i]['II_LanguageID']; $indexData['action'] = 'delete'; Cible_FunctionsIndexation::indexation($indexData); } $imageObject->delete($imageID); $galleryImageDelete = new GalleriesImages(); $where = 'GI_GalleryID = ' . $galleryID . " and GI_ImageID = " . $imageID; $galleryImageDelete->delete($where); //delete the gallery folder Cible_FunctionsGeneral::delFolder("../../{$this->_config->document_root}/data/images/gallery/" . $galleryID . "/" . $imageID); if (!$this->_isXmlHttpRequest) { $this->_redirect("/gallery/index/list/blockID/{$blockID}/pageID/{$pageID}"); } else { $this->view->assign('success', true); $this->view->assign('imageID', $imageID); } } //$this->_redirect($return); } } //} }