<?php

/*
 * Copyright (c) 2019 Earworks.
 * Codeigniter Project Template Modification
 * Please contact our email for more information :
 *  contact@earworks.co.id
 */
defined('BASEPATH') OR exit('No direct script access allowed');
include_once APPPATH . '/third_party/phpexcel/PHPExcel.php';

/**
 * Description of Import
 *
 * @author Andhy Taslin <andhy@earworks.co.id>
 * @since 1.0
 */
class Import extends Base_controller {

    public function index() {
        // slient is golden
    }

    public function company() {
        $user = $this->session->userdata(CI_NAME .'log');
        $this->load->library('excel_lib');
        $data = $this->excel_lib->readexcel($_FILES['files']['tmp_name']);
        if (!$data) {
            redirect('backoffice/register/lists');
        }
        $sql = 'INSERT INTO `company` (`name`, `created`, `modified`, `createdby`, `modifiedby`) VALUES ';
        foreach($data as $res){
            if($res['A']){
            $sql .= '("'.$res['A'].'", "'.time().'", "'.time().'", '.$user['userid'].', '.$user['userid'].'), ';
            }
        }
        $this->db->query(rtrim($sql, ', ').';');
        redirect('backoffice/register/lists');
    }
    public function visitor(){
        $user = $this->session->userdata(CI_NAME .'log');
        $this->load->library('excel_lib');
        $data = $this->excel_lib->readexcel($_FILES['files']['tmp_name']);
        if (!$data) {
            redirect('backoffice/register/lists');
        }
        $sql = 'INSERT INTO `visitor` (`name`, `created`, `modified`, `createdby`, `modifiedby`) VALUES ';
        foreach($data as $res){
            if($res['B']){
            $sql .= '("'.$res['B'].'", "'.time().'", "'.time().'", '.$user['userid'].', '.$user['userid'].'), ';
            }
        }
        $this->db->query(rtrim($sql, ', ').';');
        redirect('backoffice/register/lists');
    }

}
