Ver Mensaje Individual
  #8 (permalink)  
Antiguo 25/03/2013, 08:37
Avatar de tquezada
tquezada
 
Fecha de Ingreso: febrero-2013
Ubicación: Santiago
Mensajes: 196
Antigüedad: 11 años, 2 meses
Puntos: 8
Respuesta: guardar checkbox al recargar un formulario

y este es el codigo php
Código PHP:
Ver original
  1. <?
  2. include("../inc/funciones.php");
  3. include("../inc/oConn.php");
  4. $_SESSION['rut']    =16222215;
  5. $_SESSION['ccosto'] =9210;
  6. if($_SESSION['rut']==""){
  7.   echo "Inicie sesión nuevamente.";
  8.   exit;
  9. }
  10.  
  11. $ccosto          = $_SESSION['ccosto'];
  12. $rut_colaborador = $_SESSION['rut'];
  13.  
  14.      $strSQL = " SELECT * FROM RRHH_ENCUESTA_USUARIO where CCOSTO=".$ccosto;
  15.      $rsConn = $db->Execute($strSQL) or die("Error");
  16.      if(!$rsConn->EOF)
  17.      {
  18.      
  19.        echo "<table width='543' height='154' border='1' align='center' cellpadding='2' cellspacing='0' bordercolor='E6E6E6'>
  20.                 <tr>
  21.                     <td>
  22.                         <p class=txt9pt>                           
  23.                             <div align='center' class='txt9pt'><font color='#FF0000'>Usted ya contesto, la encuesta</font></div>
  24.                         </p>
  25.                     </td>
  26.                </tr>
  27.             </table>";
  28.        exit;
  29.      } 
  30.  
  31. ?>
  32. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  33. <html xmlns="http://www.w3.org/1999/xhtml">
  34. <head>
  35. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  36. <title>Encuesta consultas cotidianas</title>
  37. <link rel="stylesheet" href="css/cssnew.css" />
  38. </head>
  39.  
  40. <?
  41.      $strSQL3 = " select InitCap(a.emp_a_nombre||' '||a.emp_a_apellpater||' '||a.emp_a_apellmater),
  42.                          a.uni_k_codunidad,
  43.                          initCap(b.uni_a_nombunidad)
  44.                   from mae_empleado a,
  45.                        mae_unidades b
  46.                  where a.emp_k_rutemplead = ".$rut_colaborador."
  47.                    and a.uni_k_codunidad  = b.uni_k_codunidad
  48.                    and a.cia_k_empresa    = b.cia_k_empresa";
  49.      $rsconn=$db->Execute($strSQL3) or die (" No se conecto(0)");
  50.      if($rsconn->EOF)
  51.      {
  52.         echo "Colaborador no existe en nuestros registros";
  53.         exit();  
  54.      }else{
  55.          $nombre = $rsconn->fields[0];
  56.          $unidad = $rsconn->fields[1]." - ".$rsconn->fields[2];
  57.          $ccosto = $rsconn->fields[1];
  58.      }
  59.      
  60.         $observacion = $_POST["observacion"];
  61.  
  62.       if(isset ($enviar)){
  63.          
  64.          
  65.          if (strlen($observacion) > 1000){
  66.             $textarea = "No Puede Execeder el Limite de 1.000 Caracteres";
  67.          }
  68.             $checkbox_recibidos = count($_POST['opcion']);
  69.  
  70.         if($checkbox_recibidos < 1  || $checkbox_recibidos > 5){
  71.           $mensaje1 = "Debe Seleccionar un Maximo de 5 Opciones";
  72.           /*echo "<script languaje='javascript'>alert('Item II, Debe Seleccionar un Maximo de 5 Opciones'); location.href = 'encuesta.php';</script>";*/
  73.          
  74.         }
  75.         //if($checkbox_recibidos <=0){
  76.             //$mensaje2 = "Debe Escoger Almenos una Opción";
  77.             /*echo "<script languaje='javascript'>alert('Item II, Debe Escoger Almenos una Opción'); location.href = 'encuesta.php';</script>";*/
  78.         //}
  79.        
  80.         $item1 = count($_POST['opc']);     
  81.            
  82.         if($item1 == 0){
  83.             $mensaje3 = "Debe Escoger Almenos una Opción";
  84.             /*echo "<script languaje='javascript'>alert('Item I, Debe Escoger Almenos una Opción'); location.href = 'encuesta.php';</script>";*/
  85.         }
  86.        
  87.         if($textarea == "" and $mensaje1 == "" and $mensaje3 == ""){
  88.        
  89.            $strSQL = "INSERT INTO RRHH_ENCUESTA_USUARIO (ID_USUARIO,
  90.                                                           RUT,
  91.                                                           CCOSTO,
  92.                                                           FECHA,
  93.                                                           OBSERVACION)
  94.                                                           VALUES
  95.                                                           (get_nextval_SEQ_USUARIO,
  96.                                                            '".$rut_colaborador."',
  97.                                                            '".$ccosto."',
  98.                                                            sysdate,
  99.                                                            '".chao_tilde(limpiarCaracteres($observacion))."')";
  100.                                                          
  101.           $rsConn = $db->Execute($strSQL) or die("Error12");
  102.            if($rsConn){
  103.  
  104.                 $item1 = $_POST['opc'];
  105.                
  106.                 for($t=0;$t<count($item1);$t++){
  107.                     $strSQL1 = "insert into RRHH_ENCUESTA_RESPUESTA (ID_RESPUESTA,
  108.                                                                      CCOSTO,
  109.                                                                      ITEM,
  110.                                                                      ID_PREGUNTA,
  111.                                                                      rut) values
  112.                                                                     (get_nextval_SEQ_RESPUESTA,
  113.                                                                      '".$ccosto."',
  114.                                                                      '1',
  115.                                                                      '$item1[$t]',
  116.                                                                      '".$rut_colaborador."')";
  117.                     $rsConn = $db->Execute($strSQL1) or die("Error1");
  118.                       if($rsConn){
  119.                           $suma1 = $suma1 + 1;
  120.                       }            
  121.              }
  122.  
  123.             if($suma1==$t){
  124.                 $item2 = $_POST['opcion'];
  125.                        
  126.                 for($i=0;$i<count($item2);$i++){
  127.                     $strSQL2 = "insert into RRHH_ENCUESTA_RESPUESTA (ID_RESPUESTA,
  128.                                                                  CCOSTO,
  129.                                                                  ITEM,
  130.                                                                  ID_PREGUNTA,
  131.                                                                  rut) values
  132.                                                                 (get_nextval_SEQ_RESPUESTA,
  133.                                                                  '".$ccosto."',
  134.                                                                  '2',
  135.                                                                  '$item2[$i]',
  136.                                                                  '".$rut_colaborador."')";
  137.                    $rsConn = $db->Execute($strSQL2) or die("Error12");
  138.                       if($rsConn){
  139.                           $suma = $suma + 1;
  140.                       }
  141.                 }
  142.  
  143.                     if($suma == $i){
  144.                            echo "<table width='543' height='154' border='1' align='center' cellpadding='2' cellspacing='0' bordercolor='E6E6E6'>
  145.                                     <tr>
  146.                                         <td>
  147.                                             <p class=txt9pt>                           
  148.                                                 <div align='center' class='txt9pt'><font color='#FF0000'>Muchas gracias, su encuesta fue guardada correctamente.</font></div>
  149.                                             </p>
  150.                                         </td>
  151.                                    </tr>
  152.                                 </table>";
  153.                            exit;
  154.                     }else{
  155.                        echo "<table width='543' height='154' border='1' align='center' cellpadding='2' cellspacing='0' bordercolor='E6E6E6'>
  156.                                 <tr>
  157.                                     <td>
  158.                                         <p class=txt9pt>                           
  159.                                             <div align='center' class='txt9pt'><font color='#FF0000'>1111Ocurrio un error, por favor comunicar con Intranet.</font></div>
  160.                                         </p>
  161.                                     </td>
  162.                                </tr>
  163.                             </table>";
  164.                        exit;
  165.                 }
  166.                
  167.             }else{
  168.                echo "<table width='543' height='154' border='1' align='center' cellpadding='2' cellspacing='0' bordercolor='E6E6E6'>
  169.                         <tr>
  170.                             <td>
  171.                                 <p class=txt9pt>                           
  172.                                     <div align='center' class='txt9pt'><font color='#FF0000'>2222Ocurrio un error, por favor comunicar con Intranet.</font></div>
  173.                                 </p>
  174.                             </td>
  175.                        </tr>
  176.                     </table>";
  177.                exit;
  178.             }
  179.                
  180.            
  181.            }else{
  182.                echo "<table width='543' height='154' border='1' align='center' cellpadding='2' cellspacing='0' bordercolor='E6E6E6'>
  183.                         <tr>
  184.                             <td>
  185.                                 <p class=txt9pt>                           
  186.                                     <div align='center' class='txt9pt'><font color='#FF0000'>333Ocurrio un error, por favor comunicar con Intranet.</font></div>
  187.                                 </p>
  188.                             </td>
  189.                        </tr>
  190.                     </table>";
  191.                exit;
  192.            }
  193.         }//if preguntar si los campos son vacios
  194.     }//if guardar
  195. ?>

ahora si espero me ayuden
__________________
¿Sabes cuántos programadores hacen falta para cambiar una bombilla? - no, no ¿Cuántos? - Ninguno... es un problema de hardware.