function save() { // Check for request forgeries JRequest::checkToken() or die('Invalid Token'); global $option; $row =& JTable::getInstance('Attachments', 'Table'); if (!$row->bind(JRequest::get('post'))) { JError::raiseError(500, $errmsg); } // See if the article has been changed, rename files if necessary $old_article_id = JRequest::getVar('old_article_id', false); if ($old_article_id && is_numeric($old_article_id)) { $old_article_id = intval($old_article_id); } $article_id = intval($row->article_id); if ($old_article_id && $article_id != $old_article_id) { require_once JPATH_BASE . DS . '..' . DS . 'components' . DS . 'com_attachments' . DS . 'helper.php'; $error_msg = AttachmentsHelper::switch_article($row, $old_article_id, $article_id); if ($error_msg != '') { $warning = JText::_($error_msg); JError::raiseError(500, $warning); } } // Compute the update time jimport('joomla.utilities.date'); $now = new JDate(); $row->modification_date = $now->toMySQL(); // Update the record $update_file = JRequest::getVar('update_file', False); $msg = ""; if ($update_file && ($_FILES['upload']['size'] > 0 || $_FILES['upload']['tmp_name'] != '')) { // Process the uploaded file (if one was uploaded) // (Note that this also save the record) require_once JPATH_BASE . DS . '..' . DS . 'components' . DS . 'com_attachments' . DS . 'helper.php'; $msg = AttachmentsHelper::upload_file($row, $article_id, true); } else { // Save the updated attachment if (!$row->store()) { JError::raiseError(500, $row->getError()); } } switch ($this->_task) { case 'apply': $msg = JText::_('CHANGES TO ATTACHMENT SAVED'); $link = 'index.php?option=' . $option . '&task=edit&cid[]=' . $row->id; break; case 'save': default: $msg = JText::_('ATTACHMENT SAVED'); $link = 'index.php?option=' . $option; break; } $this->setRedirect($link, $msg); }