<?php

require_once 'classes/ImportPlugin.php';

class PluginModernbill extends ImportPlugin
{
    var $name = /*T*/'Imports Data from Modernbill 4.x'/*/T*/;  
    
    function getForm()
    {   
        $this->tpl->define(array('view' => '../../plugins/import/modernbill/PluginModernbill.tpl'));
        return $this->tpl->subst('PluginModernbill_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();
            NE_Lib::addMessage( $numAdded. " ".$this->user->lang("accounts added from Modernbill."));
            NE_Lib::addMessage( $packAdded. " ".$this->user->lang("packages added from Modernbill."));
            NE_Lib::addMessage( $invoicesAdded. " ".$this->user->lang("invoices added from Modernbill."));
            NE_Lib::redirectPage('index.php?fuse=admin&view=ViewImportPlugins');
        }
        NE_Lib::redirectPage('index.php?fuse=admin&view=ViewImportPlugins', $this->user->lang("File upload failed"));
    }
}
?>
