<?php

use PhpOffice\PhpWord\PhpWord;

include APPPATH . '/third_party/vendor/autoload.php';
// include APPPATH . '/third_party/phpword/bootstrap.php';

function imprimir($data)
{
  //  $CI = &get_instance();
//    $CI->load->database();
    // Creating the new document...
    $templateProcessor = new \PhpOffice\PhpWord\TemplateProcessor('assets/plantillas/formato_registro.docx');
    // Saving the document as OOXML file...
     /*   $CI->db->select('*')->from('apoyos');
        $post = $CI->db->get()->row_array();

    if($tipo == 'curp'){
        $CI->db->select('*')->from('apoyos')->where('curp =', $data['curp']);
    $post = $CI->db->get()->row_array();
    }else if ($tipo == 'curp'){
        $CI->db->select('*')->from('apoyos')->where('idapoyo =', $data);
        $post = $CI->db->get()->row_array();
    }
    else{
        $CI->db->select('*')->from('apoyos')->where('idapoyo =', $data);
        $post = $CI->db->get()->row_array();
    }
    
    $CI->db->select('*')->from('escuelas2')->where('idescuela =', $post['idescuela']);
    $escuela2 = $CI->db->get()->row_array();

    $CI->db->select('*')->from('escuelas')->where('idescuela =', $post['idescuela']);
    $escuela = $CI->db->get()->row_array();

    if($post['escuela'] != $escuela2['escuela']){
        $templateProcessor->setValue('escuela',     $post['escuela']);
        
    }else{
        $templateProcessor->setValue('escuela',     $escuela2['escuela']);
        
    }

    $CI->db->select('*')->from('niveles')->where('idnivel =', $post['idnivel']);
    $nivel = $CI->db->get()->row_array();
    
    $CI->db->select('*')->from('colonias')->where('idcolonia =', $post['idcolonia']);
    $colonia = $CI->db->get()->row_array();

    $CI->db->select('*')->from('colonias')->where('idcolonia =', $post['idcolonia_escuela']);
    $colonia_escuela = $CI->db->get()->row_array();

    
    if($post['idapoyo'] >= 1000){
        $folio = $post['idapoyo'];
    }else if($post['idapoyo'] >= 100){
        $folio = "0".$post['idapoyo'];
    }else if($post['idapoyo'] >= 10){
        $folio = "00".$post['idapoyo'];
    }else{
        $folio = "000".$post['idapoyo'];
    }
    
    */
    $folio='123';
    $templateProcessor->setValue('id', $folio);
   


    header("Content-Type: application/vnd.openxmlformats-officedocument.wordprocessingml.document");
    header("Content-Disposition: attachment; filename=myFile.docx");
    $templateProcessor->saveAs('php://output');
    // capacitacionvirtual_ws\plantillas\reglamentos . docx
    // Creating the new document...
  
}