<?php
/**
* @version $Id: application.php 13243 2009-10-20 04:01:04Z ian $
* @package Joomla
* @subpackage Config
* @copyright Copyright (C) 2005 - 2008 Open Source Matters. All rights reserved.
* @license GNU/GPL, see LICENSE.php
* Joomla! is free software. This version may have been modified pursuant to the
* GNU General Public License, and as distributed it includes or is derivative
* of works licensed under the GNU General Public License or other free or open
* source software licenses. See COPYRIGHT.php for copyright notices and
* details.
*/
// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );
require_once( JPATH_COMPONENT.DS.'views'.DS.'chalangeadmin'.DS.'view.html.php' );
/**
* @package Joomla
* @subpackage Config
*/
class ChalangeAdminControllerChalange extends ChalangeAdminController
{
//Guardamos y nos quedamos en la pantalla actual
function apply(){
//recuperamos los valores y los guardamos en la tabla
JTable::addIncludePath(JPATH_COMPONENT.DS.'tables');
$row=& JTable::getInstance('Chalanges','Table');
if(!$row->bindU(JRequest::get('post'),JRequest::getVar('raceResults', null, 'files', 'array'))){
echo "<script>alert('".$row->getError()."');
window.history.go(-1);</script>\n";
exit();
}
if(!$row->store()){
echo "<script>alert('".$row->getError()."');
window.history.go(-1);</script>\n";
exit();
}
$this->setRedirect('index.php?option=com_chalange&view=chalangeAdmin&task=edit&cid[]='.(JRequest::getCmd('id'))); //recargamos la página
$this->setMessage(JText::_('LA CHALANGE HA SIDO CORRECTAMENTE MODIFICADA')); //mostramos mensaje de confirmación.
}
//guardamos y salimos al listado general
function save(){
//recuperamos los valores y los guardamos en la tabla
JTable::addIncludePath(JPATH_COMPONENT.DS.'tables');
$row=& JTable::getInstance('Chalanges','Table');
if(!$row->bindU(JRequest::get('post'),JRequest::getVar('raceResults', null, 'files', 'array'))){
echo "<script>alert('".$row->getError()."');
window.history.go(-1);</script>\n";
exit();
}
if(!$row->store()){
echo "<script>alert('".$row->getError()."');
window.history.go(-1);</script>\n";
exit();
}
$this->setRedirect('index.php?option=com_chalange&view=chalangesAdmin'); //volvemos al listado
}
function cancel(){
JRequest::setVar('view','chalangesAdmin');
parent::display();
}
/**
* Goto form raceAdmin to create new race asigned to the chalange
*/
function addNewRace(){
JRequest::setVar('view','raceAdmin');
JRequest::setVar('chalangeId',JRequest::getCmd('id'));
parent::display();
}
/**
* Catch the event fron the addRaceToChalangeAdmin window and add every selected race to this chalange
*/
function addRacesToChalange(){
$idChalange=JRequest::getCmd('id');
$cid = JRequest::getVar('cid',array(),'','array');
$db =& JFactory::getDBO();
if (count($cid)){
$idChalange=JRequest::getCmd('chalangeId');
foreach ($cid as $race){
$query="INSERT INTO #__gcd_carrerasChalange (idCarrera, idChalange) VALUES ($race,$idChalange)";
//echo $race;
$db->setQuery($query);
if (!$db->query()){
echo "<script>alert('".$db->getErrorMsg()."');
window.history.go(-1);</script>\n";
break;
}
}
}
$this->setRedirect('index.php?option=com_chalange&view=chalangeAdmin&task=edit&cid[]='.(JRequest::getCmd('chalangeId'))); //recargamos la página
}
/**
* Vamos al formulario con el listado de carreras para la búsqueda de carreras y asociar las deseadas a la chalange
*/
function addRace(){
JRequest::setVar('view','addRaceToChalangeAdmin');
JRequest::setVar('chalangeId',JRequest::getCmd('id'));
parent::display();
}
/**
*Desasociamos las carreras seleccionadoas de esta chalange
*/
function delRace(){
$idChalange=JRequest::getCmd('id');
$cid = JRequest::getVar('cid',array(),'','array');
$db =& JFactory::getDBO();
if (count($cid)){
$cids= implode(',',$cid);
$query="DELETE FROM #__gcd_carrerasChalange WHERE idCarrera IN ($cids) AND idChalange=$idChalange";
$db->setQuery($query);
if (!$db->query()){
echo "<script>alert('".$db->getErrorMsg()."');
window.history.go(-1);</script>\n";
}
}
$this->setRedirect('index.php?option=com_chalange&view=chalangeAdmin&task=edit&cid[]='.(JRequest::getCmd('id'))); //recargamos la página
}
}