<?php
require_once 'modules/admin/models/ImportPlugin.php';
require_once dirname(__FILE__).'/importer.php';

class PluginWhmcs extends ImportPlugin
{
    var $name = 'WHMCS 3.8.x';  
    var $description = /*T*/"This import plugin imports customers, packages, and invoices from a WHMCS 3.8.x installation."/*/T*/;
    
    function getForm()
    {    
        $this->tpl->define(array('view' => '../../plugins/import/whmcs/PluginWhmcs.tpl'));
        return $this->tpl->subst('PluginWhmcs_out', 'view');
    }
    
    function process()
    {
        require_once dirname(__FILE__).'/importer.php';
        if (isset($_FILES['importfile']) && $_FILES['importfile']['size'] > 0) {
            $importer = new Importer($_FILES['importfile']['tmp_name']);
            $numAdded = $importer->addUsers();
            $packAdded = $importer->addPackages();	
            $invoicesAdded = $importer->addInvoices();
			$hostingAdded = $importer->addHosting();
            NE_Lib::addMessage( $numAdded. " ".$this->user->lang("accounts added from WHMCS."));
            NE_Lib::addMessage( $packAdded. " ".$this->user->lang("packages added from WHMCS."));
            NE_Lib::addMessage( $invoicesAdded. " ".$this->user->lang("invoices added from WHMCS."));
            NE_Lib::addMessage( $hostingAdded. " ".$this->user->lang("client packages added from WHMCS."));
            NE_Lib::redirectPage('index.php?fuse=admin&view=ViewImportPlugins');
        }
        NE_Lib::redirectPage('index.php?fuse=admin&view=ViewImportPlugins', $this->user->lang("File upload failed"));
    }
}
?>
