Esempio n. 1
0
 function delete()
 {
     global $option;
     $db =& JFactory::getDBO();
     // Verify the user is logged in
     $user =& JFactory::getUser();
     if ($user->get('username') == '') {
         $errmsg = JText::_('ERROR MUST BE LOGGED IN TO DELETE ATTACHMENT');
         JError::raiseError(500, $errmsg);
         exit;
     }
     // Make sure we have a valid article ID
     $article_id = JRequest::getVar('artid');
     if (is_numeric($article_id)) {
         $article_id = intval($article_id);
     } else {
         $errmsg = JText::_('ERROR BAD ARTICLE ID');
         JError::raiseError(500, $errmsg);
         exit;
     }
     $query = "SELECT title FROM #__content WHERE id='{$article_id}'";
     $db->setQuery($query);
     $rows = $db->loadObjectList();
     if (count($rows) <= 0) {
         $errmsg = JText::_('ERROR CANNOT DELETE INVALID ARTICLE ID') . "  ({$article_id})";
         JError::raiseError(500, $errmsg);
         exit;
     }
     $article_title = $rows[0]->title;
     // Make sure we have a valid attachment ID
     $id = JRequest::getVar('id');
     if (is_numeric($id)) {
         $id = intval($id);
     } else {
         $errmsg = JText::_('ERROR CANNOT DELETE INVALID ATTACHMENT ID') . " ({$id})";
         JError::raiseError(500, $errmsg);
         exit;
     }
     $query = "SELECT * FROM #__attachments WHERE id='{$id}'";
     $db->setQuery($query);
     $rows = $db->loadObjectList();
     if (count($rows) != 1) {
         $errmsg = JText::_('ERROR CANNOT DELETE INVALID ATTACHMENT ID') . "  ({$id})";
         JError::raiseError(500, $errmsg);
         exit;
     }
     $filename_sys = $rows[0]->filename_sys;
     $filename = $rows[0]->filename;
     // Get the component parameters
     jimport('joomla.application.component.helper');
     $params = JComponentHelper::getParams('com_attachments');
     // See if this user can modify (delete) the attachment
     require_once JPATH_COMPONENT_SITE . DS . 'permissions.php';
     if (!AttachmentsPermissions::user_may_modify_attachment($user, $rows[0], $article_id, $params)) {
         $errmsg = JText::_('ERROR NO PERMISSION TO DELETE');
         JError::raiseError(500, $errmsg);
     }
     // First delete the actual attachment files
     jimport('joomla.filesystem.file');
     JFile::delete($filename_sys);
     // Delete the entries in the attachments table
     $query = "DELETE FROM #__attachments WHERE id='{$id}' LIMIT 1";
     $db->setQuery($query);
     if (!$db->query()) {
         JError::raiseError(500, $db->getErrorMsg());
     }
     // Get the Itemid
     $Itemid = JRequest::getVar('Itemid', false);
     if (is_numeric($Itemid)) {
         $Itemid = intval($Itemid);
     } else {
         $Itemid = 1;
     }
     $msg = JText::_('DELETED ATTACHMENT') . " '{$filename}'";
     // How to redirect?
     $from = JRequest::getVar('from', false);
     if ($from) {
         if ($from == 'frontpage') {
             $redirect_to = JURI::base();
         } elseif ($from == 'article') {
             $redirect_to = JRoute::_("index.php?option=com_content&view=article&id={$article_id}", False);
         } elseif ($from == 'closeme') {
             // If we are supposed to close this iframe, do it now.
             // Queue the message
             require_once JPATH_COMPONENT_SITE . DS . 'helper.php';
             AttachmentsHelper::enqueueSystemMessage($msg);
             // Now do the Javascript to close this pop-up window and reload the parent
             echo "<script language=\"javascript\" type=\"text/javascript\">\r\n                window.parent.document.getElementById('sbox-window').close();\r\n                window.parent.location.reload();\r\n                </script>";
             exit;
         } else {
             $redirect_to = JURI::base();
         }
     } else {
         $redirect_to = JURI::Base();
     }
     $this->setRedirect($redirect_to, $msg);
 }
Esempio n. 2
0
 function regenerate_system_filenames()
 {
     require_once JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_attachments' . DS . 'update.php';
     $close = JRequest::getVar('close', false);
     $msg = AttachmentsUpdate::regenerate_system_filenames();
     if ($close) {
         require_once JPATH_SITE . DS . 'components' . DS . 'com_attachments' . DS . 'helper.php';
         AttachmentsHelper::enqueueSystemMessage($msg);
         echo "<script>window.parent.document.getElementById('sbox-window').close();\n                  window.parent.location.reload();</script>";
     } else {
         global $option;
         $this->setRedirect('index.php?option=' . $option, $msg);
     }
 }