<?php

require_once 'classes/ImportPlugin.php';
require_once dirname(__FILE__).'/importer.php';

class PluginWhmcs extends ImportPlugin
{
    var $name = /*T*/'Imports Data from WHMCS'/*/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"));
    }
}
?>
