<?php
/**
 * Addon Module Sample File
 *
 * This example addon module demonstrates all the functions an addon module can contain.
 * Please refer to the full documentation @ http://docs.whmcs.com/Addon_Modules for more details.
 *
 * @package    WHMCS
 * @author     WHMCS Limited <development@whmcs.com>
 * @copyright  Copyright (c) WHMCS Limited 2005-2013
 * @license    http://www.whmcs.com/license/ WHMCS Eula
 * @version    $Id$
 * @link       http://www.whmcs.com/
 */

if (!defined("WHMCS"))
	die("This file cannot be accessed directly");

function siteautobackup_config() {

$get_whmcs_url ="select value from tblconfiguration where setting = 'SystemURL'";
$rs_whmcs_url = mysql_query($get_whmcs_url);

 while ($row = mysql_fetch_array($rs_whmcs_url)) 
    {
		$whmcsurl = $row['value'];
	}
$whmcsurl = str_replace("https:","",$whmcsurl);
$whmcsurl = str_replace("http:","",$whmcsurl);

    $configarray = array(
    "name" => "SiteAutoBackup",
    "description" => "This is a SiteAutoBackup AddOn Module allowing SiteAutoBackup resellers to add backup hosting service as AddOn in WHMCS.",
    "version" => "1.0",
    "author" => "SiteAutoBackup.Com",
    "language" => "english",
    "fields" => array(
        "option1" => array ("FriendlyName" => "SiteAutoBackup AddOn", "Type" => "hidden", "Size" => "0", "Description" => "
<iframe width=\"100%\" height=\"200\" noresize=\"noresize\" frameborder=\"0\" border=\"0\" cellspacing=\"0\" scrolling=\"auto\" marginwidth=\"0\" marginheight=\"0\" src=\"$whmcsurl/modules/addons/siteautobackup/sab_addon.php\"></iframe>		
		", "Default" => "Example", ),
    ));
    return $configarray;
}

function siteautobackup_activate() {

/////// Checking if table sabreseller exist //////
$ctbl = "show tables like 'sabreseller'";
$rs_ctbl = mysql_query($ctbl);
$tblexist = mysql_num_rows($rs_ctbl);

if(!$tblexist){

$install_sql1 = "

CREATE TABLE IF NOT EXISTS `sabreseller` (
  `addon_id` int(11) NOT NULL,
  `product_id` int(11) NOT NULL,
  UNIQUE KEY `addon_id` (`addon_id`,`product_id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

";
$rs_install_sql1 = mysql_query($install_sql1);  

}	

/////// Checking if table sabreseller exist //////
$ctbl = "show tables like 'sabreseller_rel'";
$rs_ctbl = mysql_query($ctbl);
$tblexist = mysql_num_rows($rs_ctbl);

if(!$tblexist){

$install_sql2 = "

CREATE TABLE IF NOT EXISTS `sabreseller_rel` (
  `hostingid` int(11) NOT NULL,
  `accountid` int(11) NOT NULL,
  `addonid` int(11) NOT NULL,
  `status` varchar(16)
  UNIQUE KEY `accountid` (`hostingid`,`accountid`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

";
$rs_install_sql2 = mysql_query($install_sql2);  

}

$result=1;	

    # Return Result
    return array('status'=>'success','description'=>'MySql table sabreseller and sabreseller_rel were successfully created in your existing WHMCS database.');
    return array('status'=>'error','description'=>'You can use the error status return to indicate there was a problem activating the module');
    return array('status'=>'info','description'=>'You can use the info status return to display a message to the user');

}

function siteautobackup_deactivate() {

    # Remove Custom DB Table
    $query = "DROP TABLE `mod_addonexample`";
	$result = mysql_query($query);

    # Return Result
    return array('status'=>'success','description'=>'If successful, you can return a message to show the user here');
    return array('status'=>'error','description'=>'If an error occurs you can return an error message for display here');
    return array('status'=>'info','description'=>'If you want to give an info message to a user you can return it here');

}

function siteautobackup_upgrade($vars) {

    $version = $vars['version'];

    # Run SQL Updates for V1.0 to V1.1
    if ($version < 1.1) {
        $query = "ALTER `mod_addonexample` ADD `demo2` TEXT NOT NULL ";
    	$result = mysql_query($query);
    }

    # Run SQL Updates for V1.1 to V1.2
    if ($version < 1.2) {
        $query = "ALTER `mod_addonexample` ADD `demo3` TEXT NOT NULL ";
    	$result = mysql_query($query);
    }

}

function siteautobackup_output($vars) {

    $modulelink = $vars['modulelink'];
    $version = $vars['version'];
    $option1 = $vars['option1'];
    $option2 = $vars['option2'];
    $option3 = $vars['option3'];
    $option4 = $vars['option4'];
    $option5 = $vars['option5'];
    $LANG = $vars['_lang'];

    echo '<p>'.$LANG['intro'].'</p>
<p>'.$LANG['description'].'</p>
<p>'.$LANG['documentation'].'</p>';

}

function siteautobackup_sidebar($vars) {

    $modulelink = $vars['modulelink'];
    $version = $vars['version'];
    $option1 = $vars['option1'];
    $option2 = $vars['option2'];
    $option3 = $vars['option3'];
    $option4 = $vars['option4'];
    $option5 = $vars['option5'];
    $LANG = $vars['_lang'];

    $sidebar = '<span class="header"><img src="images/icons/addonmodules.png" class="absmiddle" width="16" height="16" /> Example</span>
<ul class="menu">
        <li><a href="#">Demo Sidebar Content</a></li>
        <li><a href="#">Version: '.$version.'</a></li>
    </ul>';
    return $sidebar;

}