Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $this->pageTitle = Yii::app()->name;
- $this->titulo = "Lista Arquivo CSV";
- $this->barraSuperior = true;
- ?>
- <div class="row-fluid">
- <div class="offset-campanha">
- <div class="white-box">
- <div class="white-box-title">
- <h3>Relatório</h3>
- <h5></h5>
- </div>
- <div class="white-box-content" style="display: inline-block;
- float: right;
- width: 660px;">
- <?php
- Yii::import('ext.GUtils.GUtils');
- $connection = Yii::app()->db;
- ini_set("max_execution_time", 60);
- // Define uma função que poderá ser usada para validar e-mails usando regexp
- function validaEmail($mail) {
- if (preg_match("/^([[:alnum:]_.-]){3,}@([[:lower:][:digit:]_.-]{3,})(\.[[:lower:]]{2,3})(\.[[:lower:]]{2})?$/", $mail)) {
- return true;
- } else {
- return false;
- }
- }
- $clienteList = array();
- $blackList = array();
- $duplicadosList = array();
- $csv_line = array();
- $ic = 0;
- $id = 0;
- $ie = 0;
- $index = 0;
- $index2 = 0;
- $count = 0;
- $erros = 0;
- $corretos = 0;
- $duplicados = 0;
- $fp = fopen(Yii::getPathOfAlias('webroot') . '/csvUpload/' . $caminho, 'r') or die("Não foi possível abrir o arquivo.");
- while ($csv_line1 = fgetcsv($fp, 1024, ';')) {
- $csv_line[$index][1] = trim($csv_line1[1]);
- $csv_line[$index][0] = $csv_line1[0];
- $index = $index + 1;
- }
- while ($index2 < $index) {
- //$csv_line[$index2][0] = trim($csv_line1[$index2][0]);
- //$csv_line[$index2][1] = $csv_line1[$index2][1];
- if ($csv_line[$index2][1] == validaEmail(trim($csv_line[$index2][1]))) {
- if (!(strstr(trim($csv_line[$index2][1]), "@gmail.com.br")) && !(strstr(trim($csv_line[$index2][1]), "@hotmail.com.br"))) {
- $csv_line[$index2][0] = GUtils::normalizarNome($csv_line[$index2][0]);
- if (preg_match("/^[_a-zA-Z0-9-.áàâãÁÀÂÃéêÉÊíÍóôöÖÓÔúüÚÜçÇ\s]*$/i", $csv_line[$index2][0])) {
- $results = Listabranca::model()->findAll(array(
- 'condition' => 'email=:email',
- 'params' => array(':email' => $csv_line[$index2][1]),
- ));
- $count = count($results);
- if ($count > 0) {
- $duplicadosList[$id]['id'] = $id;
- $duplicadosList[$id]['email'] = $csv_line[$index2][1];
- $duplicadosList[$id]['nome'] = $csv_line[$index2][0];
- $duplicados = $duplicados + 1;
- $query = $connection->createCommand("insert into DUPLICADOS (nome, email) values ('" . $duplicadosList[$id]['nome'] . '\',\'' . $duplicadosList[$id]['email'] . "');")->query();
- $id = $id + 1;
- } else {
- $clienteList[$ic]['id'] = $ic;
- $clienteList[$ic]['email'] = $csv_line[$index2][1];
- $clienteList[$ic]['nome'] = $csv_line[$index2][0];
- $corretos = $corretos + 1;
- $query = $connection->createCommand("insert into LISTABRANCA (nome, email) values ('" . $clienteList[$ic]['nome'] . '\',\'' . $clienteList[$ic]['email'] . "');")->query();
- $ic = $ic + 1;
- }
- } else {
- $results = Listanegra::model()->findAll(array(
- 'condition' => 'email=:email',
- 'params' => array(':email' => $csv_line[$index2][1]),
- ));
- $count = count($results);
- if ($count > 0) {
- $duplicadosList[$id]['id'] = $id;
- $duplicadosList[$id]['email'] = $csv_line[$index2][1];
- $duplicadosList[$id]['nome'] = $csv_line[$index2][0];
- $duplicados = $duplicados + 1;
- $query = $connection->createCommand("insert into DUPLICADOS (nome, email) values ('" . $duplicadosList[$id]['nome'] . '\',\'' . $duplicadosList[$id]['email'] . "');")->query();
- $id = $id + 1;
- } else {
- $blackList[$ie]['id'] = $ie;
- $blackList[$ie]['email'] = $csv_line[$index2][1];
- $blackList[$ie]['nome'] = $csv_line[$index2][0];
- $erros = $erros + 1;
- $query = $connection->createCommand("insert into LISTANEGRA (nome, email) values ('" . $blackList[$ie]['nome'] . '\',\'' . $blackList[$ie]['email'] . "');")->query();
- $ie = $ie + 1;
- }
- }
- } else {
- $results = Listanegra::model()->findAll(array(
- 'condition' => 'email=:email',
- 'params' => array(':email' => $csv_line[$index2][1]),
- ));
- $count = count($results);
- if ($count > 0) {
- $duplicadosList[$id]['id'] = $id;
- $duplicadosList[$id]['email'] = $csv_line[$index2][1];
- $duplicadosList[$id]['nome'] = $csv_line[$index2][0];
- $duplicados = $duplicados + 1;
- $query = $connection->createCommand("insert into DUPLICADOS (nome, email) values ('" . $duplicadosList[$id]['nome'] . '\',\'' . $duplicadosList[$id]['email'] . "');")->query();
- $id = $id + 1;
- } else {
- $blackList[$ie]['id'] = $ie;
- $blackList[$ie]['email'] = $csv_line[$index2][1];
- $blackList[$ie]['nome'] = $csv_line[$index2][0];
- $erros = $erros + 1;
- $query = $connection->createCommand("insert into LISTANEGRA (nome, email) values ('" . $blackList[$ie]['nome'] . '\',\'' . $blackList[$ie]['email'] . "');")->query();
- $ie = $ie + 1;
- }
- }
- } else {
- $results = Listanegra::model()->findAll(array(
- 'condition' => 'email=:email',
- 'params' => array(':email' => $csv_line[$index2][1]),
- ));
- $count = count($results);
- if ($count > 0) {
- $duplicadosList[$id]['id'] = $id;
- $duplicadosList[$id]['email'] = $csv_line[$index2][1];
- $duplicadosList[$id]['nome'] = $csv_line[$index2][0];
- $duplicados = $duplicados + 1;
- $query = $connection->createCommand("insert into DUPLICADOS (nome, email) values ('" . $duplicadosList[$id]['nome'] . '\',\'' . $duplicadosList[$id]['email'] . "');")->query();
- $id = $id + 1;
- } else {
- $blackList[$ie]['id'] = $ie;
- $blackList[$ie]['email'] = $csv_line[$index2][1];
- $blackList[$ie]['nome'] = $csv_line[$index2][0];
- $erros = $erros + 1;
- $query = $connection->createCommand("insert into LISTANEGRA (nome, email) values ('" . $blackList[$ie]['nome'] . '\',\'' . $blackList[$ie]['email'] . "');")->query();
- $ie = $ie + 1;
- }
- }
- $index2 = $index2 + 1;
- }
- $corretosProvider = new CArrayDataProvider($clienteList, array(
- 'pagination' => array(
- 'pageSize' => 20,
- ),
- ));
- // $blackListProvider = new CArrayDataProvider($blackList, array(
- // 'pagination' => array(
- // 'pageSize' => 20,
- // ),
- // ));
- //
- // $duplicadosProvider = new CArrayDataProvider($duplicadosList, array(
- // 'pagination' => array(
- // 'pageSize' => 20,
- // ),
- // ));
- // print"<h3>Lista de clientes duplicados</h3>";
- $this->widget('ext.Ts.TsGridView', array(
- 'id' => 'gridCorretos',
- 'type' => ' bordered condensed',
- 'dataProvider' => $corretosProvider,
- 'pager' => array(
- 'class' => 'bootstrap.widgets.TbPager',
- 'alignment' => 'right',
- 'displayFirstAndLast' => true,
- 'firstPageLabel' => 'Primeira',
- 'lastPageLabel' => 'Última',
- ),
- 'template' => "{summary}\n{exportbuttons}\n{items}\n{pager}",
- 'htmlOptions' => array('style' => 'font-size: 11px; margin-top: -20px;'),
- 'columns' => array(
- array('name' => 'nome', 'header' => 'Nome', 'htmlOptions' => array('width' => '35%'),),
- array('name' => 'email', 'header' => 'Email'),
- // array('name' => 'email', 'header' => 'E-mail', 'htmlOptions' => array('width' => '90px'),),
- // array('name' => 'notaNPS', 'header' => 'Nota NPS', 'htmlOptions' => array('width' => '50px', 'text-align' => 'center'),
- // 'cssClassExpression' => '$data[\'corNPS\']'),
- // array('name' => 'comentario', 'header' => 'Comentário', 'htmlOptions' => array('width' => '450px'),),
- ),
- ));
- print"<h3>Lista de clientes duplicados</h3>";
- $this->widget('ext.Ts.TsGridView', array(
- 'id' => 'gridDuplicados',
- 'type' => ' bordered condensed',
- 'dataProvider' => $duplicadosProvider,
- 'pager' => array(
- 'class' => 'bootstrap.widgets.TbPager',
- 'alignment' => 'right',
- 'displayFirstAndLast' => true,
- 'firstPageLabel' => 'Primeira',
- 'lastPageLabel' => 'Última',
- ),
- 'template' => "{summary}\n{exportbuttons}\n{items}\n{pager}",
- 'htmlOptions' => array('style' => 'font-size: 11px; margin-top: -20px;'),
- 'columns' => array(
- array('name' => 'nome', 'header' => 'Nome', 'htmlOptions' => array('width' => '35%'),),
- array('name' => 'email', 'header' => 'Email'),
- // array('name' => 'email', 'header' => 'E-mail', 'htmlOptions' => array('width' => '90px'),),
- // array('name' => 'notaNPS', 'header' => 'Nota NPS', 'htmlOptions' => array('width' => '50px', 'text-align' => 'center'),
- // 'cssClassExpression' => '$data[\'corNPS\']'),
- // array('name' => 'comentario', 'header' => 'Comentário', 'htmlOptions' => array('width' => '450px'),),
- ),
- ));
- ////
- // print"<h3>Lista de clientes ignorados/com erro</h3>";
- // $this->widget('ext.Ts.TsGridView', array(
- // 'id' => 'gridIgnorados',
- // 'type' => 'bordered condensed',
- // 'dataProvider' => $blackListProvider,
- // 'pager' => array(
- // 'class' => 'bootstrap.widgets.TbPager',
- // 'alignment' => 'right',
- // 'displayFirstAndLast' => true,
- // 'firstPageLabel' => 'Primeira',
- // 'lastPageLabel' => 'Última',
- // ),
- // 'template' => "{summary}\n{exportbuttons}\n{items}\n{pager}",
- // 'htmlOptions' => array('style' => 'font-size: 11px; margin-top: -20px;'),
- // 'columns' => array(
- // array('name' => 'nome', 'header' => 'Nome', 'htmlOptions' => array('width' => '35%'),),
- // array('name' => 'email', 'header' => 'Email'),
- //// array('name' => 'email', 'header' => 'E-mail', 'htmlOptions' => array('width' => '90px'),),
- //// array('name' => 'notaNPS', 'header' => 'Nota NPS', 'htmlOptions' => array('width' => '50px', 'text-align' => 'center'),
- //// 'cssClassExpression' => '$data[\'corNPS\']'),
- //// array('name' => 'comentario', 'header' => 'Comentário', 'htmlOptions' => array('width' => '450px'),),
- // ),
- // ));
- // foreach ($clienteList as $key => $value) {
- //
- // $results = Listabranca::model()->findAll(array(
- // 'condition' => 'email=:email',
- // 'params' => array(':email' => $value['email']),
- // ));
- //
- // $count = count($results);
- //
- // if ($count > 0) {
- // $query = $connection->createCommand("insert into DUPLICADOS (nome, email) values ('" . $value['nome'] . '\',\'' . $value['email'] . "');")->query();
- // } else {
- // $query = $connection->createCommand("insert into LISTABRANCA (nome, email) values ('" . $value['nome'] . '\',\'' . $value['email'] . "');")->query();
- // }
- // }
- //
- // foreach ($blackList as $key => $value) {
- //
- // $query = $connection->createCommand("insert into LISTANEGRA (nome, email) values ('" . $value['nome'] . '\',\'' . $value['email'] . "');")->query();
- // }
- fclose($fp) or die("can't close file");
- // echo CHtml::submitButton('Salvar Lista', array('class' => 'btn btn-success', 'style' => 'margin-top: 10px;'));
- ?>
- </div><!--fim da div content-->
- <div style="margin-bottom: 10px;
- margin-top: 20px;
- display: inline-block;
- width: 176px;">
- <h5 style="color:#008945;">Cadastros Corretos: </h5><?php echo $corretos; ?>
- <h5 style="color:#ffc818;"><?php echo CHtml::Link('Cadastros Duplicados', array('gestor/FiltragemDuplicados', 'caminho' => $caminho)); ?></h5><?php echo $duplicados; ?>
- <h5 style="color:#e03e00;"><?php echo CHtml::link('Cadastros Ignorados', array('gestor/FiltragemIgnorados', 'caminho' => $caminho)); ?></h5><?php echo $erros; ?>
- <br>
- </div>
- </div>
- </div>
- </div>
Add Comment
Please, Sign In to add comment