<?php
/**
* Upgrade controller for Forms Component
*
* @version		$Id: controller.php 179 2009-08-18 01:33:14Z dr_drsh $
* @package		Joomla
* @subpackage	JForms
* @copyright	Copyright (C) 2008 Mostafa Muhammad. All rights reserved.
* @license		GNU/GPL
*/

jimport('joomla.application.component.controller');

/**
 * Main backend Controller
 *
 * @package    Joomla
 * @subpackage JForms
 */
 
 
class PluginsController extends JController{

	/**
	 * constructor (registers additional tasks to methods)
	 *
	 * @return void
	 */
	function __construct(){
		parent::__construct();
		$this->registerTask( 'invoke'  , 'invoke');
	}
	
	function invoke(){
		
		JRequest::checkToken('get') or jexit( 'Invalid Token' );
		
		$pManager =& JFormsGetPluginManager();
		
		require_once JFORMS_BACKEND_PATH.DS.'libraries'.DS.'Services_JSON'.DS.'Services_JSON.php';
	
		//Decode JSON value
		
		$json = new Services_JSON();
		
		$method = JRequest::getVar( 'method' , '', 'get' );
		list($pluginType, $pluginName) = explode('.',JRequest::getVar( 'plugin' , '', 'get' ));
		$parameters = $json->decode(JRequest::getVar( 'parameter'   , '', 'get' ));
		
		$pManager->loadPlugins( $pluginType );
		$output = $pManager->invokeMethod($pluginType, $method, array($pluginName), array( $parameters ) );
		jexit( $output );
	}
}