<?php
/* $Id: uninstall.anjel.php 34 2005-11-21 05:42:47Z schmalls $ */
/**
* uninstall.anjel.php
*
* <p>Uninstall file for ANJEL.</p>
*
* @package ANJEL
* @subpackage backend
* @copyright © 2004-2005 Schmalls / Joshua Thompson / All Rights Reserved
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
* @author Schmalls / Joshua Thompson <hide@address.com>
* @version 0.6.1
* @since 0.4.3
* @link http://www.schmalls.com
*/
/**
* Ensures this file is being included by a parent file
*/
defined('_VALID_MOS') or die('Direct Access to this location is not allowed.');
/**
* Joomla uninstall function
*
* <p>Either removes ANJEL tables or does nothing depending on the
* configuration. Returns a success or failure message.</p>
*
* @version 0.6.1
* @since 0.4.3
* @return string success or failure message
*/
function com_uninstall() {
// remove tables
$return = '';
$check = anjel_remove_tables();
if ($check) {
$return .= '<p>Tables removed successfully.</p>';
} else {
$return .= '<p>There was an error removing tables. Some may be left behind.</p>';
} // end if
// remove bots
$return .= anjel_remove_bots();
return $return;
} // end function
/**
* Remove table function
*
* <p>Removes all ANJEL database tables from the database.</p>
*
* @version 0.6.1
* @since 0.4.3
* @global class access to the database
* @return boolean whether it was successful or not
*/
function anjel_remove_tables() {
global $database;
// create query array
$queries = array();
$queries[] = 'DROP TABLE `#__anjel_letters`';
$queries[] = 'DROP TABLE `#__anjel_subscribers`';
$queries[] = 'DROP TABLE `#__anjel_mailing`';
$queries[] = 'DROP TABLE `#__anjel_stats_overall`';
$queries[] = 'DROP TABLE `#__anjel_stats_detailed`';
$queries[] = 'DROP TABLE `#__anjel_stats_detailed_unregistered`';
$queries[] = 'DROP TABLE `#__anjel_unregistered`';
// perform queries
$error = '';
foreach ($queries as $query) {
$database->setQuery($query);
$database->query();
$error .= $database->getErrorMsg();
}
// check for errors
if (!empty($error)) {
return '<p><b>Error (unistall.anjel.php-> line ' . __LINE__ . '):</b> Error removing database tables. Database error(s): <br />' . $error . '</p>';
} else {
return '';
} // end if
} // end function
/**
* Removes the bots included with ANJEL
*
* <p>Deletes the bot files from the bot directory. Then deletes the bot
* information from the database.</p>
*
* @version 0.6.1
* @since 0.6.1
* @global string filesystem path to main site directory
* @global class access to the database
*/
function anjel_remove_bots() {
global $mosConfig_absolute_path, $database;
$return = true;
// copy files
$bot_files = array('bot_anjel_content.php', 'bot_anjel_content.xml', 'index.html');
foreach ($bot_files as $bot_file) {
if (!unlink($mosConfig_absolute_path . '/mambots/anjel/' . $bot_file)) {
echo '<p><b>Error (uninstall.anjel.php-> line ' . __LINE__ . '):</b> Error deleting bot file ' . $bot_file . ' from bot directory.</p>';
$return = false;
} // end if
} // end foreach
// update database
$bot_infos = array('bot_anjel_content');
foreach ($bot_infos as $bot_info) {
$query = 'DELETE FROM `#__mambots` WHERE element = \'' . $bot_info . '\'';
$database->setQuery($query);
$database->query();
$error = $database->getErrorMsg();
if (!empty($error)) {
echo '<p><b>Error (uninstall.anjel.php-> line ' . __LINE__ . '):</b> Error deleting bot information from bot table for "' . $bot_info . '". Database error: <br />' . $error . '</p>';
$return = false;
} // end if
} // end foreach
return $return;
} // end function
?>