<?php
/**
* @package css2switch
* @author Dominik Gorczyca - mediahof
* 
* --------------------------------------------------------------------------------
* All rights reserved.  css2switch Component for Joomla! 1.5
*
**/
defined( '_JEXEC' ) or die( 'Restricted access' );

function com_install()
{
	global $mainframe;
	$db =& JFactory::getDBO();
	$locale = $mainframe->getCfg( 'language' );
	$adminPath = JPATH_SITE.DS.'administrator';
	$css2switchPath = $adminPath.DS.'components'.DS.'com_css2switch'.DS;
	$pluginVon = $css2switchPath.'plugin'.DS;
	$pluginNach = JPATH_SITE.DS.'plugins'.DS.'system'.DS;
	$pluginPHP = 'css2switch.php';
	$pluginXML = 'css2switch.xml';
	$langFile = file_get_contents($adminPath.DS.'language'.DS.$locale.DS.$locale.'.com_css2switch.ini');
	preg_match('/C2S_INSTALL_DESCRIPTION=(.*?)C2S_/is', $langFile, $descriptInstall);
	
	if ( @ rename($pluginVon.$pluginPHP, $pluginNach.$pluginPHP) == false || @ rename($pluginVon.$pluginXML, $pluginNach.$pluginXML) == false)
	{
		echo JText::_('Plugin install error, please install the plugin!');
	}
	else
	{
		@ rmdir(JPATH_SITE.DS.'administrator'.DS.'components'.DS.'com_css2switch'.DS.'plugin');
		$db->setQuery ( "SELECT ordering FROM #__plugins WHERE folder='system' ORDER BY ordering DESC LIMIT 1" );
		$lastpluginOrder = $db->loadResult() + 1;
		$db->setQuery( 
									 "INSERT INTO #__plugins ("
									." id, name, element, folder, access, ordering, published, iscore, client_id, checked_out, checked_out_time, params)"
									." VALUES ("
									." '', 'css2switch', 'css2switch', 'system', 0, ".intval($lastpluginOrder).", 1, 0, 0, 0, '0000-00-00 00:00:00', '' "
									.")"
								);
		$db->query();
	}
	echo $descriptInstall[1];
}
?>
