My class :
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class PersonneAdd extends CI_Controller {
function __construct()
{
parent::__construct();
$this->load->database();
$this->load->helper('url');
$this->load->helper('download');
/* ------------------ */
$this->load->library('grocery_CRUD');
$this->load->model('personne');
}
public function index()
{
}
public function personneBlocAdd()
{
$this->personne->empty_temppersonne();
$this->grocery_crud->set_table('temppersonne');
$this->grocery_crud->set_relation('idGroupe','groupe','nomGroupe');
$this->grocery_crud->columns('idGroupe','file_url ','upload');
$this->grocery_crud->display_as('idGroupe','Groupe');
$this->grocery_crud->display_as('file_url','Chargement du fichier de données');
$this->grocery_crud->display_as('upload','Téléchargement d’un fichier type');
$this->grocery_crud->fields('idGroupe','cin','prenom','nom','numTel','dateNaissance','email','Sexe','file_url','upload');
/*********************** Default Values ***************************/
/*************************************************/
$this->grocery_crud->field_type('cin', 'hidden', '0000000');
$this->grocery_crud->field_type('prenom', 'hidden','Test');
$this->grocery_crud->field_type('nom', 'hidden','Test');
$this->grocery_crud->field_type('numTel', 'hidden','00000000');
$this->grocery_crud->field_type('dateNaissance', 'hidden','01/01/2000');
$this->grocery_crud->field_type('email', 'hidden','Test@test.test');
$this->grocery_crud->field_type('Sexe', 'hidden','Masculin');
/*****************************************************/
$this->grocery_crud->set_field_upload('file_url','application/controllers/xlsupload');
$this->grocery_crud->callback_after_upload(array($this,'example_callback_after_upload'));
$this->grocery_crud->callback_add_field('upload',array($this,'add_field_callback_upload'));
$this->grocery_crud->set_theme('datatables');
$this->grocery_crud->unset_back_to_list();
/*************************/
try{
$output =$this->grocery_crud->render();
} catch(Exception $e)
{
if($e->getCode() == 14)
{
redirect(strtolower(__CLASS__).'/'.strtolower(__FUNCTION__).'/add');
}
else
{
show_error($e->getMessage());
}
}
$this->_example_output($output);
}
function add_field_callback_upload()
{
return '<a href="'.realpath('null').'/Tempxlsx/personne.xlsx'.'" title="News title">Fichier Exemple</a>';
}
function example_callback_after_upload($files_to_upload,$field_info)
{
$this->xlsfullarray();
}
public function xlsfullarray()
{
$this->load->helper('url');
$ctrl=0;
require_once '/ex/Classes/PHPExcel/IOFactory.php';
$objReader = new PHPExcel_Reader_Excel2007();
$objReader->setReadDataOnly(true);
$objPHPExcel = $objReader->load(dirname(__FILE__) . '/xlsupload/e9b50-personne.xlsx' );
$rowIterator = $objPHPExcel->getActiveSheet()->getRowIterator();
$array_data = array();
foreach($rowIterator as $row)
{
$cellIterator = $row->getCellIterator();
$cellIterator->setIterateOnlyExistingCells(false);
if(1 == $row->getRowIndex ()) continue;
$rowIndex = $row->getRowIndex ();
$array_data[$rowIndex] = array('A'=>'', 'B'=>'','C'=>'','D'=>'','E'=>'','F'=>'','G'=>'');
foreach ($cellIterator as $cell) {
if('A' == $cell->getColumn()){
$array_data[$rowIndex][$cell->getColumn()] = $cell->getCalculatedValue();
} else if('B' == $cell->getColumn()){
$array_data[$rowIndex][$cell->getColumn()] = $cell->getCalculatedValue();
} else if('C' == $cell->getColumn()){
$array_data[$rowIndex][$cell->getColumn()] = $cell->getCalculatedValue();
} else if('D' == $cell->getColumn()){
$array_data[$rowIndex][$cell->getColumn()] = $cell->getCalculatedValue();
} else if('E' == $cell->getColumn()){
$array_data[$rowIndex][$cell->getColumn()] = PHPExcel_Style_NumberFormat::toFormattedString($cell->getCalculatedValue(), 'YYYY-MM-DD');
}else if('F' == $cell->getColumn()){
$array_data[$rowIndex][$cell->getColumn()] = $cell->getCalculatedValue();
}else if('G' == $cell->getColumn()){
$array_data[$rowIndex][$cell->getColumn()] = $cell->getCalculatedValue();
}
}
}
foreach ($array_data as $cel)
{
echo $cel['C'].'<br/>';
if (($this->nomcheck($cel['A'])==1)) $ctrl=1;
if (($this->prenomcheck($cel['B'])==1)) $ctrl=1;
if (($this->cincheck($cel['C'])==1)) $ctrl=1;
if (($this->numtelcheck($cel['D'])==1)) $ctrl=1;
if (($this->is_date($cel['E'])==1)) $ctrl=1;
if (($this->VerifierAdresseMail($cel['F'])==1)) $ctrl=1;
if (($this->is_sexe($cel['G'])==1)) $ctrl=1;
}
$ctrl=1; // just to force a redidrection -------->testing purpose
if ($ctrl==1)
{
redirect("/PersonneAdd/personneblocadd"); // bug at this line
}
}
function _example_output($output = null)
{
$this->load->view('our_template.php',$output);
}
}