<?php

require_once __DIR__ . '/lib/Classes/PHPExcel.php';
// UI
$GLOBALS['navBar']['appMenu'][] = array('url' => 'extensions/ExcelImport/ui/views/MenuItem.html');
AngularApp::addCSS('extensions/ExcelImport/ui/css/style.css');
AngularApp::addJS('extensions/ExcelImport/ui/js/ExcelImport.js');
// Config
Config::set('allowedMimeTypes', 'excelImport', array('application/vnd.ms-excel', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'application/excel'));
class ImportExcel
{
    public $file;
    private $db;
    function __construct($filename)
    {
        $this->file = $filename;
        $this->db = Database::singleton();
    }
    public function ParseFile()
    {
        Notifications::addLog('------------------------- EXCEL IMPORT STARTED -------------------------', 'ExcelImport');
        $this->ProcessFileContent();
        Notifications::addLog('------------------------- END OF EXCEL IMPORT -------------------------', 'ExcelImport');
        // Close transaction => ROLLBACK or COMMIT.
        $this->db->closeTransaction('File uploaded', false, true, false);
        return Notifications::getAll();
    }
    public function ProcessFileContent()
    {
        $objPHPExcel = PHPExcel_IOFactory::load($this->file);
        // Format is as follows: