<?php
/**
 * PluginModernbill File
 *
 * @category Import
 * @package  Plugins
 * @author   Alberto Vasquez <alberto@clientexec.com>
 * @license  ClientExec License
 * @version  [someversion]
 * @link     http://www.clientexec.com
 */

require_once 'modules/admin/models/ImportPlugin.php';

/**
 * PluginModernbill Import Class
 *
 * @category Import
 * @package  Plugins
 * @author   Alberto Vasquez <alberto@clientexec.com>
 * @license  ClientExec License
 * @version  [someversion]
 * @link     http://www.clientexec.com
 */

class PluginModernbill extends ImportPlugin
{
    var $_title = /*T*/'Modernbill 4.x'/*/T*/;  
    var $description = /*T*/"This import plugin imports customers, packages, and invoices from a Modernbill 4.x installation."/*/T*/;

    /**
     * Gets form to begin import
     * 
     * @return html
     */
    function getForm()
    {   
        $this->tpl->define(array('view' => '../../plugins/import/modernbill/PluginModernbill.tpl'));
        return $this->tpl->subst('PluginModernbill_out', 'view');
    }

    /**
     * Process import function
     *
     * @return redirects
     */
    function process()
    {
        include_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"));
    }
}
?>