<?php
/**
 * @version		$Id: contacto.php 20196 2011-03-19 02:40:25Z pol $
 * @package		Joomla.Site
 * @subpackage	Contact
 * @copyright	Copyright (C) 2005 - 2011 Open Source Matters, Inc. All rights reserved.
 * @license		GNU General Public License version 2 or later; see LICENSE.txt
 */

// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );

require_once( JApplicationHelper::getPath( 'toolbar_html' ) );
require_once( JApplicationHelper::getPath( 'admin_html' ) );

$option = JRequest::getVar( 'option', '' );
$contacto = JRequest::getVar( 'contacto', array(0), 'post', 'array' );
$diremail = JRequest::getVar( 'diremail', '' );
$mensaje = JRequest::getVar( 'mensaje', '', 'post', 'STRING',JREQUEST_NOTRIM );
//$address = JRequest::getVar('address', 'default value goes here', 'post','variable type');
$id = JRequest::getVar( 'id', '' );

switch ($task) {

	case "save":
		save( "save",$diremail,$mensaje);
		break;

	case "apply":
		save( "apply",$diremail,$mensaje);
		break;

	case "cancel":
		$app = &JFactory::getApplication();
		$app->redirect( 'index.php' );
		break;

	case "bajacoment":
		bajacoment($id);
		break;

	default:
        TOOLBAR_contacto::_DEFAULT();
		show( $option );
		break;
}


############################################################################
############################################################################

function show( $option ) {
	// Display configuration tables
	HTML_contacto::show( );

}

function save( $option,$diremail,$mensaje ) {

$db =& JFactory::getDBO();
$query = "UPDATE #__contacto_form SET diremail='{$diremail}',mensaje='{$mensaje}' WHERE id='1'";
$db->setQuery( $query );
$db->query();

if ($option=="apply"){
$app = &JFactory::getApplication();
$app->redirect( 'index.php?option=com_contacto' );
}elseif($option=="save"){
$app = &JFactory::getApplication();
$app->redirect( 'index.php' );
}
}



function bajacoment( $id ) {
	// DELETE FROM tabla_relacionada WHERE id=nro id
$db =& JFactory::getDBO();
$query = "DELETE FROM #__contacto_historia WHERE id=".$id;
$db->setQuery( $query );
$db->query();

$app = &JFactory::getApplication();
$app->redirect( 'index.php?option=com_contacto' );
}



?>