Advertisement
Guest User

Untitled

a guest
Sep 19th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.58 KB | None | 0 0
  1. $(document).ready(function() {
  2.  
  3.  
  4. //-----------Cargar la lista de usuarios dependiendo del perfil----------
  5.  
  6. $("#id_tip").change(function() {
  7.  
  8. $("#id_tip option:selected").each(function() {
  9.  
  10. id_tip = $('#id_tip').val();
  11.  
  12. $.post("<?php echo base_url();?>cHorarios/cargar_usuarios", {
  13.  
  14. id_tip : id_tip
  15.  
  16. },
  17.  
  18. function(data) {
  19.  
  20. $("#rut_usu").html(data);
  21.  
  22. });
  23. });
  24. });
  25.  
  26. //---------------------fin de la funcion----------------------------------
  27.  
  28. //-------Enviamos los datos por Ajax -------------------------------------
  29.  
  30.  
  31. $(function(){
  32.  
  33. $('#subida').submit(function(){
  34.  
  35. var comprobar = $('#file').val().length;
  36.  
  37. if(comprobar>0){
  38.  
  39. var formulario = $('#subida');
  40. var rut_usu;
  41. var fecha_ini;
  42. var fecha_ter;
  43. var archivos = new FormData();
  44.  
  45. archivos.append('rut_usu',rut_usu);
  46. archivos.append('fecha_ini',fecha_ini);
  47. archivos.append('fecha_ter',fecha_ter);
  48.  
  49.  
  50. var url = '<?php echo base_url();?>cHorarios/guardar_horario';
  51.  
  52. for (var i = 0; i < (formulario.find('input[type=file]').length); i++) {
  53.  
  54. archivos.append((formulario.find('input[type="file"]:eq('+i+')').attr("name")),((formulario.find('input[type="file"]:eq('+i+')')[0]).files[0]));
  55.  
  56. }
  57.  
  58. $.ajax({
  59.  
  60.  
  61. url: url,
  62. type: 'POST',
  63. contentType: false,
  64. data: archivos,
  65. processData:false,
  66.  
  67.  
  68. success: function(data){
  69.  
  70. if(data == 'OK'){
  71.  
  72. $('#respuesta').html('<label style="padding-top:10px; color:green;">Importacion de xlsx exitosa</label>');
  73. return false;
  74.  
  75. }else{
  76.  
  77. $('#respuesta').html('<label style="padding-top:10px; color:red;">Error en la importacion del xlsx</label>');
  78. return false;
  79.  
  80. }
  81.  
  82.  
  83. }
  84.  
  85. });
  86.  
  87. return false;
  88.  
  89. }else{
  90.  
  91. alert('Selecciona un archivo para importar');
  92.  
  93. return false;
  94.  
  95. }
  96. });
  97. });
  98.  
  99.  
  100. //-------Fin de el envio de datos-----------------------------------------
  101. });
  102.  
  103. public function guardar_horario(){
  104.  
  105.  
  106. if (!empty($_FILES['file']['name'])) {
  107.  
  108.  
  109. $pathinfo = pathinfo($_FILES["file"]["name"]);
  110.  
  111.  
  112. if (($pathinfo['extension'] == 'xlsx' || $pathinfo['extension'] == 'xls')
  113. && $_FILES['file']['size'] > 0 ) {
  114.  
  115. // Nombre Temporal del Archivo
  116. $inputFileName = $_FILES['file']['tmp_name'];
  117.  
  118. //Lee el Archivo usando ReaderFactory
  119. $reader = ReaderFactory::create(Type::XLSX);
  120.  
  121. //var_dump($reader);
  122.  
  123. $reader->setShouldFormatDates(true);
  124.  
  125. // Abrimos el archivo
  126. $reader->open($inputFileName);
  127. $count = 1;
  128.  
  129. //Numero de Hojas en el Archivo
  130. foreach ($reader->getSheetIterator() as $sheet) {
  131.  
  132. // Numero de filas en el documento EXCEL
  133. foreach ($sheet->getRowIterator() as $row) {
  134.  
  135. // Lee los Datos despues del encabezado
  136. // El encabezado se encuentra en la primera fila
  137. if($count > 1) {
  138.  
  139.  
  140. $data = array(
  141.  
  142.  
  143. 'rut_usu' => $this->input->post('rut_usu'),
  144. 'hrs_ini' => $row[0],
  145. 'hrs_ter' => $row[1],
  146. 'lunes' => $row[2],
  147. 'martes' => $row[3],
  148. 'miercoles' => $row[4],
  149. 'jueves' => $row[5],
  150. 'viernes' => $row[6],
  151. 'sabado' => $row[7],
  152. 'fecha_ini' => $this->input->post('fecha_ini'),
  153. 'fecha_ter' => $this->input->post('fecha_ter')
  154.  
  155. );
  156.  
  157.  
  158. $this->db->insert('horario',$data);
  159.  
  160. }
  161. $count++;
  162. }
  163. }
  164.  
  165. // cerramos el archivo EXCEL
  166. $reader->close();
  167.  
  168. } else {
  169.  
  170. echo "Seleccione un tipo de Archivo Valido";
  171. }
  172.  
  173. } else {
  174.  
  175. echo "Seleccione un Archivo EXCEL";
  176.  
  177. }
  178. }
  179. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement