Advertisement
mamptecnocrata

registrar.php

Mar 25th, 2017
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 21.55 KB | None | 0 0
  1. <?php
  2.     session_start();
  3.     include("conexion.php");
  4.     if (isset($_SESSION["usuario"]))
  5.     {
  6. ?>
  7.  
  8. <!DOCTYPE html>
  9. <!--[if IE 8]> <html lang="en" class="ie8 no-js"> <![endif]-->
  10. <!--[if IE 9]> <html lang="en" class="ie9 no-js"> <![endif]-->
  11. <!--[if !IE]><!-->
  12. <html lang="es">
  13. <head>
  14.     <meta charset="UTF-8">
  15.     <meta http-equiv="X-UA-Compatible" content="IE=edge">
  16.     <meta name="viewport" content="width=device-width, initial-scale=1">
  17.     <meta name="robots" content="noindex,nofollow" />
  18.     <meta name="description" content="Un sistema informático realizado por la Gerencia de Tecnología e Información de VyCSucre para el departamento de obras públicas, para agregar los datos de las plantas de asfalto y concreto."/>
  19.     <meta name="keywords" content="ficha, tecnica, planta, asfalto, obras, públicas, vycsucre, mppttop, mpptt, programacion, php, sql, tren, trituración">
  20.     <link rel="stylesheet" href="font-awesome/css/font-awesome.min.css">
  21.     <link rel="stylesheet" href="estilos.css">
  22.     <link rel="shorcut icon" href="imagenes/bookmark.png">
  23.     <title>Ficha Técnica</title>
  24.     <script>
  25.         //<!-- <![CDATA[
  26.         function msgbox(mensaje) {
  27.                 alert(mensaje);
  28.         };
  29.         // ]]> -->
  30.     </script>
  31. </head>
  32. <body>
  33. <?php
  34.         include("header.php");
  35.         #$produccion_nominal="";
  36. ?>
  37.  
  38. <?php
  39.    
  40.     /* Declaración de variables */
  41.     $nombre = $ubicacion = $recurso_humano = $tipo_mezcla = $especificacion_planta = $tipo_planta = $produccion_nominal = $produccion_efectiva = $especificacion_tren = $tipo_tren = $capacidad_tren = $caracteristica_1 = $caracteristica_2 = $caracteristica_3 = $imagen_1 = $imagen_2 = $imagen_3 = $produccion_maxima = $precio = '';
  42.    
  43.     if (isset($_POST["enviar"]))
  44.     {
  45.         $nombre = $_POST["nombre"];
  46.         $ubicacion = $_POST["ubicacion"];
  47.         $recurso_humano = $_POST["recurso_humano"];
  48.         $tipo_mezcla = $_POST["tipo_mezcla"];
  49.         $especificacion_planta = $_POST["especificacion_planta"];
  50.         $tipo_planta = $_POST["tipo_planta"];
  51.         $produccion_nominal = $_POST["produccion_nominal"];
  52.         $produccion_efectiva = $_POST["produccion_efectiva"];
  53.         $especificacion_tren = $_POST["especificacion_tren"];
  54.         $tipo_tren = $_POST["tipo_tren"];
  55.         $capacidad_tren = $_POST["capacidad_tren"];
  56.         $caracteristica_1 = $_POST["caracteristica_1"];
  57.         $caracteristica_2 = $_POST["caracteristica_2"];
  58.         $caracteristica_3 = $_POST["caracteristica_3"];
  59.         $imagen_1 = $_FILES["imagen_1"]["tmp_name"];
  60.         $imagen_2 = $_FILES["imagen_2"]["tmp_name"];
  61.         $imagen_3 = $_FILES["imagen_3"]["tmp_name"];
  62.         $produccion_maxima = $_POST["produccion_maxima"];
  63.         $precio = $_POST["precio"];
  64.         # Realizar la comprobación de los campos del formulario
  65.         //1. Validar que los campos no estén vacíos
  66.         if($_POST["nombre"] == "" || $_POST["ubicacion"] == "" || $_POST["recurso_humano"] == "" || $_POST["tipo_mezcla"] == ""  || $_POST["especificacion_planta"] == "" || $_POST["produccion_nominal"] == "" || $_POST["produccion_efectiva"] == "" || $_POST["especificacion_tren"] == "" || $_POST["capacidad_tren"] == "" || $_POST["caracteristica_1"] == "" || $_POST["caracteristica_2"] == "" || $_POST["caracteristica_3"] == "" || $_POST["produccion_maxima"] == "" ||  $_POST["precio"] == "" )
  67.         {
  68.             echo '<script>msgbox("Los datos no pueden estar vacíos, intente nuevamente");</script>';
  69.  
  70.         }
  71.         //2. Validar que los campos numéricos contenga sólo números
  72.         else if ((strcmp($_POST["recurso_humano"], strval(intval($_POST["recurso_humano"])))) || (strcmp($_POST["produccion_nominal"], strval(intval($_POST["produccion_nominal"])))) || (strcmp($_POST["produccion_efectiva"], strval(intval($_POST["produccion_efectiva"])))) || (strcmp($_POST["capacidad_tren"], strval(intval($_POST["capacidad_tren"])))) || (strcmp($_POST["produccion_maxima"], strval(intval($_POST["produccion_maxima"])))) || (strcmp($_POST["precio"], strval(floatval($_POST["precio"])))))
  73.         {
  74.             echo '<script>msgbox("Ha escrito números donde debe escribir valores numéricos, intente nuevamente");</script>';
  75.         }
  76.         //3. Comprobar que el campo de selección no esté vacío
  77.         else if ($_POST["tipo_planta"] == '1' && $_POST["tipo_tren"] == '1')
  78.         {
  79.             echo '<script>msgbox("Los campos de selección no pueden estar vacíos, intente nuevamente")</script>';
  80.         }
  81.         //4. Comprobar que se se han agregado correctamente todas las imágenes
  82.         else if ($_FILES['imagen_1']['tmp_name'] == "" && $_FILES['imagen_2']['tmp_name'] == "" && $_FILES['imagen_3']['tmp_name'] == "")
  83.         {
  84.             echo '<script>msgbox("No se ha seleccionado ninguna imagen, intente nuevamente")</script>';
  85.         }
  86.         //5. Cuando se hayan pasado todas las validaciones, se pueden agregar los campos a la base de datos
  87.         else
  88.         {
  89.             # Almacenar las imágenes en las carpetas requeridas
  90.             $archivo = 'imagenes/' .$_FILES["imagen_1"]['name'];
  91.             $destino_1 = $archivo;
  92.             copy($_FILES['imagen_1']['tmp_name'],$destino_1);
  93.  
  94.             $archivo = 'imagenes/' .$_FILES["imagen_2"]['name'];
  95.             $destino_2 = $archivo;
  96.             copy($_FILES['imagen_2']['tmp_name'],$destino_2);
  97.  
  98.             $archivo = 'imagenes/' .$_FILES["imagen_3"]['name'];
  99.             $destino_3 = $archivo;
  100.             copy($_FILES['imagen_3']['tmp_name'],$destino_3);
  101.  
  102.             # Insertar los campos en la base de datos
  103.             $guardarDatos = 'INSERT INTO planta_fisica(nombre, recurso_humano, ubicacion, tipo_mezcla, especificacion_planta, produccion_nominal, produccion_efectiva, especificacion_tren, capacidad_tren, produccion_maxima, precio, caracteristica_materia_1, caracteristica_materia_2, caracteristica_materia_3, imagen_1, imagen_2, imagen_3, fk_tipo_planta, fk_tipo_tren) VALUES ("'.$nombre.'", '.$recurso_humano.', "'.$ubicacion.'", "'.$tipo_mezcla.'", "'.$especificacion_planta.'", '.$produccion_nominal.', '.$produccion_efectiva.', "'.$especificacion_tren.'", '.$capacidad_tren.', '.$produccion_maxima.', '.$precio.', "'.$caracteristica_1.'", "'.$caracteristica_2.'", "'.$caracteristica_3.'", "'.$destino_1.'", "'.$destino_2.'", "'.$destino_3.'", '.$tipo_planta.', '.$tipo_tren.')';
  104.  
  105.             # Comprobar si se pueden ejecutar las consultas, e informar de los posibles fallos
  106.             if (!mysql_query($guardarDatos))
  107.             {
  108.                 die('<script>msgbox("Los datos de la ficha no se han podido guardar");</script>');
  109.             }
  110.             else
  111.             { // Guardamos los datos, y salimos del formulario
  112.                 echo '<script>msgbox("Los datos han sido guardados en la base de datos");</script>';
  113.             }
  114.         }
  115.         $nombre = $_POST["nombre"];
  116.         $ubicacion = $_POST["ubicacion"];
  117.         $recurso_humano = $_POST["recurso_humano"];
  118.         $tipo_mezcla = $_POST["tipo_mezcla"];
  119.         $especificacion_planta = $_POST["especificacion_planta"];
  120.         $tipo_planta = $_POST["tipo_planta"];
  121.         $produccion_nominal = $_POST["produccion_nominal"];
  122.         $produccion_efectiva = $_POST["produccion_efectiva"];
  123.         $especificacion_tren = $_POST["especificacion_tren"];
  124.         $tipo_tren = $_POST["tipo_tren"];
  125.         $capacidad_tren = $_POST["capacidad_tren"];
  126.         $caracteristica_1 = $_POST["caracteristica_1"];
  127.         $caracteristica_2 = $_POST["caracteristica_2"];
  128.         $caracteristica_3 = $_POST["caracteristica_3"];
  129.         $imagen_1 = $_FILES["imagen_1"]["tmp_name"];
  130.         $imagen_2 = $_FILES["imagen_2"]["tmp_name"];
  131.         $imagen_3 = $_FILES["imagen_3"]["tmp_name"];
  132.         $produccion_maxima = $_POST["produccion_maxima"];
  133.         $precio = $_POST["precio"];
  134.     }
  135. ?>
  136.    
  137.     <main class="principal">
  138.  
  139.         <div class="formulario">
  140. <!-- agregarDatos.php -->
  141.             <form action="" method="post" enctype="multipart/form-data">
  142.                 <!-- <table align="center" cellpadding="3"> -->
  143.                 <table>
  144.                     <tr>
  145.                         <td colspan="6"><h3>DATOS DE PLANTA</h3></td>
  146.                     </tr>
  147.                     <tr>
  148.                         <td>
  149.                             <label>
  150.                                 <strong>Planta:</strong>
  151.                             </label>
  152.                         </td>
  153.                         <td colspan="5">
  154.                             <input type="text" name="nombre" value="<?php echo (isset($nombre)?$nombre:""); ?>" maxlength="100" placeholder="Nombre de planta">
  155.                         </td>
  156.                     </tr>
  157.                     <tr>
  158.                         <td>
  159.                             <label>
  160.                                 <strong>Ubicación</strong>
  161.                             </label>
  162.                         </td>
  163.                         <td colspan="5">
  164.                             <input type="text" name="ubicacion" value="<?php echo (isset($ubicacion)?$ubicacion:""); ?>" maxlength="128" placeholder="Ubicación de planta">
  165.                         </td>
  166.                     </tr>
  167.                     <tr>
  168.                         <td>
  169.                             <label>
  170.                                 <strong>Recurso Humano:</strong>
  171.                             </label>
  172.                         </td>
  173.                         <td colspan="2">
  174.                             <input type="text" name="recurso_humano" value="<?php echo (isset($recurso_humano)?$recurso_humano:""); ?>" maxlength="10" placeholder="Cantidad">
  175.                         </td>
  176.                         <td>
  177.                             <label>
  178.                                 <strong>Tipo de Mezcla que Produce:</strong>
  179.                             </label>
  180.                         </td>
  181.                         <td colspan="2">
  182.                             <input type="text" name="tipo_mezcla" value="<?php echo (isset($tipo_mezcla)?$tipo_mezcla:""); ?>" maxlength="30" placeholder="Tipo de mezcla">
  183.                         </td>
  184.                     </tr>
  185.                     <tr>
  186.                         <td>
  187.                             <label>
  188.                                 <strong>Modelo y especificaciones de la planta de Asfalto:</strong>
  189.                             </label>
  190.                         </td>
  191.                         <td colspan="5">
  192.                             <input type="text" name="especificacion_planta" value="<?php echo (isset($especificacion_planta)?$especificacion_planta:""); ?>" maxlength="120" placeholder="Modelo/especificacion">
  193.                         </td>
  194.                     </tr>
  195.                     <tr>
  196.                         <td>
  197.                             <label>
  198.                                 <strong>Tipo de Planta:</strong>
  199.                             </label>
  200.                         </td>
  201.                         <td>
  202.                             <select name="tipo_planta" id="tipo_planta">
  203.                                 <option value="1" selected>Seleccione un valor</option>
  204.                                 <?php
  205.                                     $plantafisica = mysql_query("SELECT * FROM tipo_planta") or die ('No se ejecutó la consulta: '.mysql_error());
  206.                                     while ($tipo_planta = mysql_fetch_array($plantafisica)){
  207.                                         if (empty($_POST['id_tipo_planta'])){
  208.                                             $_POST['id_tipo_planta'] = '1';
  209.                                         } elseif ($_POST['id_tipo_planta'] == $tipo_planta['id_tipo_planta']) {
  210.                                             echo '<option value="'.$tipo_planta["id_tipo_planta"].' selected">'.$tipo_planta["tipo_planta"].'</option>';
  211.                                         } else {
  212.                                             echo '<option value="'.$tipo_planta["id_tipo_planta"].'">'.$tipo_planta["tipo_planta"].'</option>';
  213.                                         }
  214.                                     }
  215.                                     mysql_free_result($plantafisica);
  216.                                     ?>
  217.                             </select>
  218.                         </td>
  219.                         <td>
  220.                             <label>
  221.                                 <strong>Capacidad de Producción NOMINAL TON/H:</strong>
  222.                             </label>
  223.                         </td>
  224.                         <td>
  225.                             <input type="text" name="produccion_nominal" value="<?php echo (isset($produccion_nominal)?$produccion_nominal:""); ?>" maxlength="30" placeholder="NOMINAL">
  226.                         </td>
  227.                         <td>
  228.                             <label>
  229.                                 <strong>Capacidad de Producción EFECTIVA TON/H:</strong>
  230.                             </label>
  231.                         </td>
  232.                         <td>
  233.                             <input type="text" name="produccion_efectiva" value="<?php echo (isset($produccion_efectiva)?$produccion_efectiva:""); ?>" maxlength="30" placeholder="EFECTIVA">
  234.                         </td>
  235.                     </tr>
  236.                     <tr>
  237.                         <td>
  238.                             <label>
  239.                                 <strong>Modelo y especificaciones del Tren de Trituración:</strong>
  240.                             </label>
  241.                         </td>
  242.                         <td colspan="5">
  243.                             <input type="text" name="especificacion_tren" value="<?php echo (isset($especificacion_tren)?$especificacion_tren:""); ?>" maxlength="100" placeholder="Modelo/especificacion">
  244.                         </td>
  245.                     </tr>
  246.                     <tr>
  247.                         <td>
  248.                             <label>
  249.                                 <strong>Tipo de Tren de Trituración:</strong>
  250.                             </label>
  251.                         </td>
  252.                         <td>
  253.                             <select name="tipo_tren" id="tipo_tren">
  254.                                 <option value="1" selected>Seleccione un valor</option>
  255.                                 <?php
  256.                                     $trentrituracion = mysql_query("SELECT * FROM tipo_tren") or die ('No se pudo ejecutar la consulta: '.mysql_error());
  257.                                     while ($tipo_tren = mysql_fetch_array($trentrituracion)){
  258.                                         if (empty($_POST['id_tipo_tren'])){
  259.                                             $_POST['id_tipo_tren'] = '1';
  260.                                         } elseif ($_POST['id_tipo_tren'] == $tipo_tren['id_tipo_tren']) {
  261.                                             echo '<option value="'.$tipo_tren["id_tipo_tren"].' selected">'.$tipo_tren["tipo_tren"].'</option>';
  262.                                             } else {
  263.                                             echo '<option value="'.$tipo_tren["id_tipo_tren"].'">'.$tipo_tren["tipo_tren"].'</option>';
  264.                                         }
  265.                                     }
  266.                                     mysql_free_result($trentrituracion);
  267.                                 ?>
  268.                             </select>
  269.                         </td>
  270.                         <td>
  271.                             <label>
  272.                                 <strong>Capacidad Nominal TON/H:</strong>
  273.                             </label>
  274.                         </td>
  275.                         <td colspan="3">
  276.                             <input type="text" name="capacidad_tren" value="<?php echo (isset($capacidad_tren)?$capacidad_tren:""); ?>" maxlength="20" placeholder="Capacidad Nominal">
  277.                         </td>
  278.                     </tr>
  279.                     <tr>
  280.                         <td colspan="6"><h3>MATERIA PRIMA</h3></td>
  281.                     </tr>
  282.                     <tr>
  283.                         <td>
  284.                             <label>
  285.                                 <strong>Agregado:</strong>
  286.                             </label>
  287.                         </td>
  288.                         <td colspan="5"><textarea name="caracteristica_1" rows="3" cols="100" placeholder="Características"><?php echo (isset($caracteristica_1)?$caracteristica_1:""); ?></textarea>
  289.                         </td>
  290.                     </tr>
  291.                     <tr>
  292.                         <td>
  293.                             <label>
  294.                                 <strong>Arrocillo, Polvillo y Piedra:</strong>
  295.                             </label>
  296.  
  297.                         </td>
  298.                         <td colspan="5"><textarea name="caracteristica_2" rows="3" cols="100" placeholder="Características"><?php echo (isset($caracteristica_2)?$caracteristica_2:""); ?></textarea>
  299.                         </td>
  300.                     </tr>
  301.                     <tr>
  302.                         <td>
  303.                             <label>
  304.                                 <strong>Arena:</strong>
  305.                             </label>
  306.                         </td>
  307.                         <td colspan="5"><textarea name="caracteristica_3" rows="3" cols="100" placeholder="Características"><?php echo (isset($caracteristica_3)?$caracteristica_3:""); ?></textarea>
  308.                         </td>
  309.                     </tr>
  310.                     <tr>
  311.                         <td colspan="6"><h3>REGISTRO FOTOGRAFICO</h3></td>
  312.                     </tr>
  313.                     <tr>
  314.                         <td colspan="2">
  315.                             <label>
  316.                                 <strong>Imagen 1: </strong>
  317.                             </label>
  318.                         <input type="file" name="imagen_1" id="imagen_1">
  319.                         </td>
  320.                         <td colspan="2">
  321.                             <label>
  322.                                 <strong>Imagen 2: </strong>
  323.                             </label>
  324.                         <input type="file" name="imagen_2" id="imagen_2">
  325.                         </td>
  326.                         <td colspan="2">
  327.                             <label>
  328.                                 <strong>Imagen 3: </strong>
  329.                             </label>
  330.                         <input type="file" name="imagen_3" id="imagen_3">
  331.                         </td>
  332.                     </tr>
  333.                     <tr>
  334.                         <td colspan="2">
  335.                           <output id="list_1"></output>
  336.                           <script>
  337.                               function archivo(evt) {
  338.                                   var files = evt.target.files; // FileList object
  339.  
  340.                                   // Obtenemos la imagen del campo "file".
  341.                                   for (var i = 0, f; f = files[i]; i++) {
  342.                                     //Solo admitimos im&aacute;genes.
  343.                                     if (!f.type.match('image.*')) {
  344.                                         continue;
  345.                                     }
  346.  
  347.                                     var reader = new FileReader();
  348.  
  349.                                     reader.onload = (function(theFile) {
  350.                                         return function(e) {
  351.                                           // Insertamos la imagen
  352.                                          document.getElementById("list_1").innerHTML = ['<img class="thumb" widht="250" height="250" src="', e.target.result,'" title="', escape(theFile.name), '"/>'].join('');
  353.                                         };
  354.                                     })(f);
  355.  
  356.                                     reader.readAsDataURL(f);
  357.                                   }
  358.                               }
  359.  
  360.                               document.getElementById('imagen_1').addEventListener('change', archivo, false);
  361.                           </script>
  362.                         </td>
  363.                         <td colspan="2">
  364.                           <output id="list_2"></output>
  365.                           <script>
  366.                               function archivo(evt) {
  367.                                   var files = evt.target.files; // FileList object
  368.  
  369.                                   // Obtenemos la imagen del campo "file".
  370.                                   for (var i = 0, f; f = files[i]; i++) {
  371.                                     //Solo admitimos im&aacute;genes.
  372.                                     if (!f.type.match('image.*')) {
  373.                                         continue;
  374.                                     }
  375.  
  376.                                     var reader = new FileReader();
  377.  
  378.                                     reader.onload = (function(theFile) {
  379.                                         return function(e) {
  380.                                           // Insertamos la imagen
  381.                                          document.getElementById("list_2").innerHTML = ['<img class="thumb" widht="250" height="250" src="', e.target.result,'" title="', escape(theFile.name), '"/>'].join('');
  382.                                         };
  383.                                     })(f);
  384.  
  385.                                     reader.readAsDataURL(f);
  386.                                   }
  387.                               }
  388.  
  389.                               document.getElementById('imagen_2').addEventListener('change', archivo, false);
  390.                           </script>
  391.                         </td>
  392.                         <td colspan="2">
  393.                           <output id="list_3"></output>
  394.                           <script>
  395.                               function archivo(evt) {
  396.                                   var files = evt.target.files; // FileList object
  397.  
  398.                                   // Obtenemos la imagen del campo "file".
  399.                                   for (var i = 0, f; f = files[i]; i++) {
  400.                                     //Solo admitimos im&aacute;genes.
  401.                                     if (!f.type.match('image.*')) {
  402.                                         continue;
  403.                                     }
  404.  
  405.                                     var reader = new FileReader();
  406.  
  407.                                     reader.onload = (function(theFile) {
  408.                                         return function(e) {
  409.                                           // Insertamos la imagen
  410.                                          document.getElementById("list_3").innerHTML = ['<img class="thumb" widht="250" height="250" src="', e.target.result,'" title="', escape(theFile.name), '"/>'].join('');
  411.                                         };
  412.                                     })(f);
  413.  
  414.                                     reader.readAsDataURL(f);
  415.                                   }
  416.                               }
  417.  
  418.                               document.getElementById('imagen_3').addEventListener('change', archivo, false);
  419.                           </script>
  420.                         </td>
  421.                     </tr>
  422.                     <tr>
  423.                         <td>
  424.                             <label>
  425.                                 <strong>Capacidad Máxima productiva día (TON)::</strong>
  426.                             </label>
  427.  
  428.                         </td>
  429.                         <td colspan="2">
  430.                             <input type="text" name="produccion_maxima" value="<?php echo (isset($produccion_maxima)?$produccion_maxima:""); ?>" maxlength="20" placeholder="Capacidad máxima">
  431.                         </td>
  432.                         <td>
  433.                             <label>
  434.                                 <strong>Precio de la Mezcla asfáltica (TON) Bs.:</strong>
  435.                             </label>
  436.                         </td>
  437.                         <td colspan="2">
  438.                             <input type="text" name="precio" value="<?php echo (isset($precio)?$precio:""); ?>" maxlength="20" placeholder="Precio (usar . para los decimales)" pattern="^\d+(\.\d{1,4})?$">
  439.                         </td>
  440.                     </tr>
  441.                     <tr>
  442.                         <td colspan="6" align="center">
  443.                             <input type="submit" name="enviar" value="Guardar datos">
  444.                         </td>
  445.                     </tr>
  446.                 </table>
  447.             </form>
  448.  
  449.         </div>
  450.     </main>
  451.  
  452. <?php
  453.     include("footer.php");
  454.     } else
  455.     {
  456.         header("Location: ingreso.php");
  457.     }
  458. ?>
  459.  
  460. </body>
  461. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement