/** * Confirm if image should be deleted and delete image * * @return void */ function deleteAction() { $id = (int) $this->_request->getParam('id', 0); $image_class = new Images(); if ($this->_request->isPost()) { $image = $image_class->fetchRow('id = ' . $id); $album_id = $image->album_id; // decerement viewer_order on all the images that have a higher // viewer_order than the deleted image $select = $image_class->select(); $select->where('album_id = ' . $image->album_id)->where('viewer_order > ' . $image->viewer_order); $statement = $select->__toString(); $this->logger->info($statement); $images = $image_class->fetchAll($select); foreach ($images as $image) { $image->viewer_order--; $this->logger->info("image {$image->id} now has index of {$image->viewer_order}"); $image->save(); } $del = $this->_request->getPost('confirm'); if ($del == 'Confirm' && $id > 0) { $image_class->delete('id=' . $id); } if ($this->_request->getParam('from', 0) == 'viewImage' && $del != 'Confirm') { $this->_redirect('/image/view/id/' . $id); } else { $this->_redirect('/album/view/id/' . $album_id); } } else { if ($id > 0) { $this->view->title = 'Confirm Deletion'; $image = $image_class->fetchRow('id=' . $id); $this->view->image_title = $image->title; $form = new ImageDeleteForm(); $form->confirm->setLabel('Confirm'); $form->cancel->setLabel('Cancel'); $this->view->form = $form; $form->populate($image->toArray()); } } }
/** * delete all images for a given anchor * * @param the anchor to check * * @see shared/anchors.php */ public static function delete_for_anchor($anchor) { global $context; // seek all records attached to this anchor $query = "SELECT id FROM " . SQL::table_name('images') . " AS images " . " WHERE images.anchor LIKE '" . SQL::escape($anchor) . "'"; if (!($result = SQL::query($query))) { return; } // delete silently all matching images while ($row = SQL::fetch($result)) { Images::delete($row['id']); } }
public function deleteAction() { // web page title $this->view->title = "Suppression d'une galerie"; //if ($this->view->aclIsAllowed('gallery','manage',true)){ // variables $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'); if ($blockID != '') { $return = "/gallery/index/list/blockID/{$blockID}/pageID/{$pageID}"; } elseif ($this->_categoryID) { $return = "/gallery/index/list/catID/{$this->_categoryID}"; } else { $return = "/gallery/index/list/"; } $this->view->return = $this->view->baseUrl() . $return; $galleryObject = new GalleryObject(); $galleryDataIndex = $galleryObject->populate($galleryID, $this->_defaultEditLanguage); if (!$galleryDataIndex) { 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); $this->view->gallery = $galleryDataIndex; if ($this->_request->isPost()) { $formData = $this->_request->getPost(); if ($galleryDataIndex) { $gallerySelect = new GalleriesIndex(); $select = $gallerySelect->select()->where('GI_GalleryID = ?', $galleryID); $galleryData = $gallerySelect->fetchAll($select); foreach ($galleryData as $gallery) { $indexData['moduleID'] = $this->_moduleID; $indexData['contentID'] = $galleryID; $indexData['languageID'] = $gallery['GI_LanguageID']; $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 = ?', $gallery['GI_LanguageID']); $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); } } //delete all images associated with the gallery $galleryImagesSelect = new GalleriesImages(); $select = $galleryImagesSelect->select()->where('GI_GalleryID = ?', $galleryID); $galleryImagesData = $galleryImagesSelect->fetchAll($select); foreach ($galleryImagesData as $galleryImages) { $imageDelete = new Images(); $where = "I_ID = " . $galleryImages['GI_ImageID']; $imageDelete->delete($where); $imageIndexDelete = new ImagesIndex(); $where = "II_ImageID = " . $galleryImages['GI_ImageID']; $imageIndexDelete->delete($where); } $galleryImagesDelete = new GalleriesImages(); $where = "GI_GalleryID = " . $galleryID; $galleryImagesDelete->delete($where); $galleryObject->delete($galleryID); /* //delete the gallery $galleryDelete = new Galleries(); $where = 'G_ID = ' . $galleryID; $galleryDelete->delete($where); $galleryIndexDelete = new GalleriesIndex(); $where = 'GI_GalleryID = ' . $galleryID; $galleryIndexDelete->delete($where); */ //delete the gallery folder Cible_FunctionsGeneral::delFolder("../../{$this->_config->document_root}/data/images/gallery/" . $galleryID); if (!$this->_isXmlHttpRequest) { if ($blockID != '') { $this->_redirect("/gallery/index/list/blockID/{$blockID}/pageID/{$pageID}"); } elseif ($this->_categoryID) { $this->_redirect("/gallery/index/list/catID/{$this->_categoryID}"); } else { $this->_redirect("/gallery/index/list/"); } } else { $buttonAction = $formData['buttonAction']; $this->view->assign('success', true); $this->view->assign('buttonAction', $buttonAction); $this->view->assign('galleryID', $galleryID); $this->view->assign('deleted', true); } } } } //} }
global $render_overlaid; // not found if (!isset($item['id'])) { include '../error.php'; // permission denied } elseif (!$permitted) { Safe::header('Status: 401 Unauthorized', TRUE, 401); Logger::error(i18n::s('You are not allowed to perform this operation.')); // deletion is confirmed } elseif (isset($_REQUEST['confirm']) && $_REQUEST['confirm'] == 'yes') { // touch the related anchor before actual deletion, since the image has to be accessible at that time if (is_object($anchor)) { $anchor->touch('image:delete', $item['id']); } // if no error, back to the anchor or to the index page if (Images::delete($item['id'])) { Images::clear($item); if (isset($_REQUEST['strait'])) { $output['success'] = true; // provide a new field if required if (isset($_REQUEST['newfield'])) { $indice = $_REQUEST['newfield'] ? $_REQUEST['newfield'] : ''; $output['replace'] = Skin::build_input_file('upload' . $indice); } } elseif (isset($_REQUEST['follow_up'])) { Safe::redirect($_REQUEST['follow_up']); } elseif (is_object($anchor)) { Safe::redirect($anchor->get_url()); } else { Safe::redirect($context['url_to_home'] . $context['url_to_root'] . 'images/'); }