%PDF- %PDF-
Direktori : /home/tjamichg/portal.tjamich.gob.mx/infofi/modules/forms/ |
Current File : /home/tjamichg/portal.tjamich.gob.mx/infofi/modules/forms/upload.php |
<?php require("conn.php"); $token = $_GET['token']; if(isset($_FILES['archivo'])){ $dir = "uploads/"; $file_up = $dir . basename($_FILES['archivo']['name']); if(move_uploaded_file($_FILES['archivo']['tmp_name'], $file_up)){ require("Classes/PHPExcel/IOFactory.php"); $ntable = $_POST['nform']; $nombre = $file_up; $objPHPExcel = PHPEXCEL_IOFactory::load($nombre); $objPHPExcel->setActiveSheetIndex(0); $numRows = $objPHPExcel->setActiveSheetIndex(0)->getHighestRow(); $LetCols = $objPHPExcel->setActiveSheetIndex(0)->getHighestColumn(); $sentr = mysqli_query($db, "SHOW COLUMNS FROM $ntable"); $CuentaCols = mysqli_query($db, "SELECT * FROM $ntable"); $NumCols = mysqli_num_fields($CuentaCols); $nCols = array( "1" => "A", "2" => "B", "3" => "C", "4" => "D", "5" => "E", "6" => "F", "7" => "G", "8" => "H", "9" => "I", "10" => "J", "11" => "K", "12" => "L", "13" => "M", "14" => "N", "15" => "O", "16" => "P", "17" => "Q", "18" => "R", "19" => "S", "20" => "T", "21" => "U", "22" => "V", "23" => "W", "24" => "X", "25" => "Y", "26" => "Z", "27" => "AA", "28" => "AB", "29" => "AC", "30" => "AD", "31" => "AE", "32" => "AF", "33" => "AG", "34" => "AH", "35" => "AI", "36" => "AJ", "37" => "AK", "38" => "AL", "39" => "AM", "40" => "AN", "41" => "AO", "42" => "AP", "43" => "AQ", "44" => "AR", "45" => "AS", "46" => "AT", "47" => "AU", "48" => "AV", "49" => "AW", "50" => "AX", "51" => "AY", "52" => "AZ", "53" => "BA", "54" => "BB", "55" => "BC", "56" => "BD", "57" => "BE", "58" => "BF", "59" => "BG", "60" => "BH", "61" => "BI", "62" => "BJ", "63" => "BK", "64" => "BL", "65" => "BM", "66" => "BN", "67" => "BO", "68" => "BP", "69" => "BQ", "70" => "BR", "71" => "BS", "72" => "BT", "73" => "BU", "74" => "BV", "75" => "BW", "76" => "BX", "77" => "BY", "78" => "BZ", ); if(mysqli_num_rows($sentr) >= 0){ $ncols = 0; while($fila = mysqli_fetch_array($sentr)){ $ncols++; if(!isset($vars)){ $vars = $fila['Field'].", "; } elseif($ncols < $NumCols){ $vars .= $fila['Field'].", "; } else { $vars .= $fila['Field']; } } } $year = $_POST['year']; $senFolio = mysqli_query($db, "SELECT * FROM nfolios WHERE year = '$year' ORDER BY id DESC"); $oldFolio = mysqli_fetch_row($senFolio); $newNumb = $oldFolio['1']; $newNumb++; $nNum = str_pad($newNumb,5,0,STR_PAD_LEFT); $rest = substr($year, -2); //$nFolio = "SISOFI".$nNum.date('y'); $nFolio = "INFOFI".$nNum.$rest; $tempo = $_POST['tempo']; $noForm = $_POST['nform']; $art = substr($noForm, 2, 2); $idUS = $_SESSION['idus']; $fecha = date('Y-m-d'); if($_SESSION['rol'] == 1){ $apro = "Y"; } else { $apro = "N"; if($art == 99){ $apro = "Y"; } else { $apro = "N"; } } mysqli_query($db, "SET NAMES 'utf8'"); mysqli_query($db, "INSERT INTO nfolios (numero, folio, year, idus, tabla, tempo, fecha, apro) VALUES ('$newNumb','$nFolio','$year','$idUS','$noForm','$tempo','$fecha','$apro')"); $NumCols--; $param = 0; $i = 8; //while($i <= $numRows){ while($param == 0) { for($letCols=1;$letCols<=$NumCols;$letCols++){ if(!isset($rCols)){ $rCols = "'".$objPHPExcel->getActiveSheet()->getCell($nCols[$letCols].$i)->getValue()."',"; } elseif ($letCols < $NumCols) { //$rCols .= "'".$objPHPExcel->getActiveSheet()->getCell($nCols[$letCols].$i)->getFormattedValue()."',"; $resultado = strpos($objPHPExcel->getActiveSheet()->getCell($nCols[$letCols]."7")->getValue(), "Fecha"); if($resultado !== FALSE) $rCols .= "'".PHPExcel_Style_NumberFormat::toFormattedString($objPHPExcel->getActiveSheet()->getCell($nCols[$letCols].$i)->getCalculatedValue(), 'DD/MM/YYYY')."',"; else $rCols .= "'".$objPHPExcel->getActiveSheet()->getCell($nCols[$letCols].$i)->getValue()."',"; } else { $rCols .= "'".$nFolio."'"; } } $sen = "INSERT INTO $ntable ($vars) VALUES (NUll,$rCols)"; mysqli_query($db, $sen) or die(mysql_error()); /*************************************************************************************************/ $result = mysqli_query($db, "select * from nformatos where tabla='$ntable'"); if($row = mysqli_fetch_row($result)) { $idformato = $row[6]; } $result2 = mysqli_query($db, "select distinct idcampo as idcampo from ncat_campos_formatos where idformato=".$idformato); while($row2 = mysqli_fetch_array($result2)) { $idcampo= $row2["idcampo"]; mysqli_query($db, "update ncat_campos_formatos as c inner join $ntable as f on c.idformato=$idformato and id_$idcampo=descripcion and f.folio='$nFolio' set f.id_$idcampo=c.indice"); } /*************************************************************************************************/ unset($rCols); $j = $i+1; if($objPHPExcel->getActiveSheet()->getCell('A'.$j)->getCalculatedValue()==NULL) { $param=1; } $i++; } $result3 = mysqli_query($db, "SELECT distinct idtabla as idtabla FROM ncat_formatos_tablas_campos WHERE idformato='$idformato' ORDER BY id"); while($row3 = mysqli_fetch_array($result3)) { /*$objPHPExcel->setActiveSheetIndex($l); $numRow = $objPHPExcel->setActiveSheetIndex($l)->getHighestRow(); $LetCol = $objPHPExcel->setActiveSheetIndex($l)->getHighestColumn(); */ $objPHPExcel->setActiveSheetIndexByName("Tabla_".$row3["idtabla"]); $numRow = $objPHPExcel->setActiveSheetIndexByName("Tabla_".$row3["idtabla"])->getHighestRow(); $LetCol = $objPHPExcel->setActiveSheetIndexByName("Tabla_".$row3["idtabla"])->getHighestColumn(); $nuCol = 1; while($nCols[$nuCol] <= $LetCol){ $nuCol++; } for($ncolum=1;$ncolum<=$nuCol;$ncolum++){ if(!isset($val)){ $val = "val".$ncolum.", "; } elseif ($ncolum < $nuCol) { $val .= "val".$ncolum.", "; } else { //$val .= "tipo, "; $val .= "Folio"; } } $line = 4; while($line <= $numRow){ for($nmCol=1;$nmCol<=$nuCol;$nmCol++){ if(!isset($vrow)){ $vrow = "'".$objPHPExcel->getActiveSheet()->getCell($nCols[$nmCol].$line)->getValue()."',"; } elseif ($nmCol < $nuCol) { $vrow .= "'".$objPHPExcel->getActiveSheet()->getCell($nCols[$nmCol].$line)->getFormattedValue()."',"; } else { //$vrow .= "'".$l."',"; $vrow .= "'".$nFolio."'"; } } mysqli_query($db, "INSERT INTO nlistas (idformato,idtabla,$val) VALUES ('$idformato','".$row3["idtabla"]."',$vrow)") or die(mysqli_error()); unset($vrow); $line++; } //$l++; unset($val); } $sqlF = mysqli_query($db, "INSERT INTO bitacora (fecha, folio, year, tabla, fechafolio, tempo, apro, accion, idus) VALUES (NOW(), '$nFolio', '$year', '$noForm', '$fecha', '$tempo', '$apro', 'Cargar Informacion', '$idUS')"); echo "<div class='bmsg'><b>Su información ha sido publicada satisfactoriamente<br />Tu folio es: ".$nFolio."</b></div>"; unlink($file_up); } else { echo "error"; } } ?> <br /> <div class="content"> <div class="titulo">Cargar Información</div><br /> <div> <form name="carga" method="post" action="" enctype="multipart/form-data"> <div class="fcampo"> <select name="nform" onchange="location = 'index.php?token=<?php echo $_GET['token'] ?>&mod=upload&tab=' + this.options[this.selectedIndex].value" required> <option value="">- SELECCIONA EL FORMATO -</option> <?php mysqli_query($db, "SET NAMES 'utf8'"); $exFormat = mysqli_query($db, "SELECT * FROM nas_forms ORDER BY idform ASC"); while($f = mysqli_fetch_array($exFormat)){ if($f['idus'] == $_SESSION['idus']){ if($_GET['tab'] == $f['tabla']){ echo "<option value='".$f['tabla']."' selected>".$f['nform']."</option>"; } else { echo "<option value='".$f['tabla']."'>".$f['nform']."</option>"; } } } ?> </select> </div> <?php if(isset($_GET['tab'])){ ?> <div class="fcampo"> <select name="tempo" required> <option value="">- SELECCIONA UNA TEMPORALIDAD -</option> <?php $tab = $_GET['tab']; $senForm = mysqli_query($db, "SELECT * FROM nformatos WHERE tabla='$tab'"); if($atab = mysqli_fetch_row($senForm)){ if($atab['8'] == 1){ $nomT = $atab['5']; } else { $nomT = $atab['4']; } } else { echo "Problemon"; } $exTempo = mysqli_query($db, "SELECT * FROM na_temp WHERE idtmp='$nomT'"); while($t = mysqli_fetch_array($exTempo)){ echo "<option value='".$t['id']."'>".$t['clas']."</option>"; } ?> </select> </div> <div class="fcampo"> <select name="year" required> <option value="">- SELECCIONA EL AÑO -</option> <?php $exYear = mysqli_query($db, "SELECT * FROM nyears ORDER BY id ASC"); while($y = mysqli_fetch_array($exYear)){ if($atab[8] == 1){ if($y['year'] >= 2021){ echo "<option value='".$y['year']."'>".$y['year']."</option>"; } } else { echo "<option value='".$y['year']."'>".$y['year']."</option>"; } } ?> </select> </div> <div class="fcampo"><input type="file" name="archivo" required /></div> <div><input type="submit" value="Subir" /></div> <?php } ?> </form> </div> </div>