/** * Put up a dialog to double-check before deleting an attachment */ public function delete_warning() { // Access check. if (!(JFactory::getUser()->authorise('core.delete', 'com_attachments') or JFactory::getUser()->authorise('attachments.delete.own', 'com_attachments'))) { return JError::raiseError(403, JText::_('JERROR_ALERTNOAUTHOR') . ' (ERR 144)'); } // Make sure we have a valid attachment ID $attachment_id = JRequest::getInt('id', null); if (is_numeric($attachment_id)) { $attachment_id = (int) $attachment_id; } else { $errmsg = JText::sprintf('ATTACH_ERROR_CANNOT_DELETE_INVALID_ATTACHMENT_ID_N', $attachment_id) . ' (ERR 145)'; JError::raiseError(500, $errmsg); } // Load the attachment $model = $this->getModel(); $attachment = $model->getTable(); // Make sure the article ID is valid $attachment_id = JRequest::getInt('id'); if (!$attachment->load($attachment_id)) { $errmsg = JText::sprintf('ATTACH_ERROR_CANNOT_DELETE_INVALID_ATTACHMENT_ID_N', $attachment_id) . ' (ERR 146)'; JError::raiseError(500, $errmsg); } // Set up the view require_once JPATH_COMPONENT_ADMINISTRATOR . '/views/warning/view.html.php'; $view = new AttachmentsViewWarning(); $view->parent_id = $attachment_id; $view->option = JRequest::getCmd('option'); $view->from = JRequest::getWord('from'); $view->tmpl = JRequest::getWord('tmpl'); // Prepare for the query $view->warning_title = JText::_('ATTACH_WARNING'); if ($attachment->uri_type == 'file') { $msg = "( {$attachment->filename} )"; } else { $msg = "( {$attachment->url} )"; } $view->warning_question = JText::_('ATTACH_REALLY_DELETE_ATTACHMENT') . '<br/>' . $msg; $view->action_button_label = JText::_('ATTACH_DELETE'); $view->action_url = "index.php?option=com_attachments&task=attachments.delete&cid[]=" . (int) $attachment_id; $view->action_url .= "&from=" . $view->from; $view->display(); }
/** * Show the warning for deleting an attachment */ public function delete_warning() { // Make sure we have a valid attachment ID $attachment_id = JRequest::getInt('id'); if (is_numeric($attachment_id)) { $attachment_id = (int) $attachment_id; } else { $errmsg = JText::sprintf('ATTACH_ERROR_CANNOT_DELETE_INVALID_ATTACHMENT_ID_N', $attachment_id) . ' (ERR 20)'; JError::raiseError(500, $errmsg); } // Get the attachment record JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_attachments/tables'); $attachment = JTable::getInstance('Attachment', 'AttachmentsTable'); if (!$attachment->load($attachment_id)) { $errmsg = JText::sprintf('ATTACH_ERROR_CANNOT_DELETE_INVALID_ATTACHMENT_ID_N', $attachment_id) . ' (ERR 21)'; JError::raiseError(500, $errmsg); } // Get the parent object $parent_type = $attachment->parent_type; JPluginHelper::importPlugin('attachments'); $apm = getAttachmentsPluginManager(); if (!$apm->attachmentsPluginInstalled($parent_type)) { $errmsg = JText::sprintf('ATTACH_ERROR_INVALID_PARENT_TYPE_S', $parent_type) . ' (ERR 22)'; JError::raiseError(500, $errmsg); } $parent = $apm->getAttachmentsPlugin($parent_type); // Check to make sure we can edit it $parent_id = $attachment->parent_id; if (!$parent->userMayDeleteAttachment($attachment)) { $errmsg = JText::_('ATTACH_ERROR_NO_PERMISSION_TO_DELETE_ATTACHMENT') . ' (ERR 23)'; JError::raiseError(500, $errmsg); } // Set up the view require_once JPATH_COMPONENT . '/views/warning/view.html.php'; $view = new AttachmentsViewWarning(); $view->parent_id = $parent_id; $view->option = JRequest::getCmd('option'); $view->from = JRequest::getWord('from', 'closeme'); $view->tmpl = JRequest::getWord('tmpl'); // Prepare for the query $view->warning_title = JText::_('ATTACH_WARNING'); if ($attachment->uri_type == 'file') { $fname = "( {$attachment->filename} )"; } else { $fname = "( {$attachment->url} )"; } $view->warning_question = JText::_('ATTACH_REALLY_DELETE_ATTACHMENT') . '<br/>' . $fname; $delete_url = "index.php?option=com_attachments&task=delete&id={$attachment_id}"; $delete_url = JRoute::_($delete_url); $view->action_url = $delete_url; $view->action_button_label = JText::_('ATTACH_DELETE'); $view->display(); }