<?php
/**
* Smart Former - Joomla Form manager
* @version 2.4.0
* @package Smart Former
* @copyright (C) 2007-2009 by IToris Inc.
* @license Released under the terms of Commercial License
**/

function com_install_outputErrors( $errors ) {
    if( $errors ) {
        echo '<p style="color: red;"><b>The component was not fully uninstalled. Some files remain in the following directories</b>:</p>';
        foreach( $errors as $error ) {
            echo '<p>'.$error."</p>";
        }
    }
}

// no direct access
if (!defined( '_VALID_MOS' ) && !defined( '_JEXEC' )) die( 'Restricted access' );
function com_uninstall() {
	global $database;
	if (defined( '_JEXEC' )) {
		$database=& JFactory::getDBO();
		$GLOBALS['DOCUMENT_ROOT']=$_SERVER['DOCUMENT_ROOT'];
		$GLOBALS['mosConfig_live_site']=substr(JURI::root(),0,strlen(JURI::root())-1);
		$mosConfig_live_site=$GLOBALS['mosConfig_live_site'];
		$GLOBALS['mosConfig_absolute_path']=substr(__FILE__,0,strpos(strtolower(__FILE__),'administrator')-1);
        $errors = array();
		/*
		if (!@unlink ($GLOBALS['mosConfig_absolute_path'].'/plugins/content/smartformer.php')) {
            $errors['plugin.content'] = '/plugins/content/';
		}
		if (!@unlink ($GLOBALS['mosConfig_absolute_path'].'/plugins/content/smartformer.xml')) {
			$errors['plugin.content'] = '/plugins/content/';
		}
		if (!@unlink ($GLOBALS['mosConfig_absolute_path'].'/modules/mod_smartformer/mod_smartformer.php')){
			$errors['modules'] = '/modules/';
		}
		if (!@unlink ($GLOBALS['mosConfig_absolute_path'].'/modules/mod_smartformer/mod_smartformer.xml')) {
			$errors['modules'] = '/modules/';
		}
		if (!@rmdir($GLOBALS['mosConfig_absolute_path'].'/modules/mod_smartformer')) {
			$errors['modules'] = '/modules/';
		}
		*/
        com_install_outputErrors($errors);
		$database->setQuery( 'delete from `#__plugins` where `element`="smartformer"' );
		$database->query();
	} else {
		$GLOBALS['mosConfig_absolute_path']=substr(__FILE__,0,strpos(strtolower(__FILE__),'administrator')-1);
        $errors = array();
		/*
		if (!@unlink ($GLOBALS['mosConfig_absolute_path'].'/mambots/content/smartformer.php')) {
			$errors['mambots.content'] = '/mambots/content/';
		}
		if (!@unlink ($GLOBALS['mosConfig_absolute_path'].'/mambots/content/smartformer.xml')) {
			$errors['mambots.content'] = '/mambots/content/';
		}
		if (!@unlink ($GLOBALS['mosConfig_absolute_path'].'/modules/mod_smartformer.php')) {
			$errors['modules'] = '/modules/';
		}
		if (!@unlink ($GLOBALS['mosConfig_absolute_path'].'/modules/mod_smartformer.xml')) {
			$errors['modules'] = '/modules/';
		}*/
        com_install_outputErrors($errors);
		$database->setQuery( 'delete from `#__mambots` where `element`="smartformer"' );
		$database->query();
		$database->setQuery( 'delete from `#__modules` where `module`="mod_smartformer"' );
		$database->query();

	}
}

?>