<?PHP
$tipo_local = 1;
include("../../secure/secure.php");
include ('../../conf/configuracao.php');

$pergs_por_pagina = 10;

echo "<html>";
echo "<head><title>Lista - Perguntas Pesquisa</title>
</head>";

echo "<body bgcolor='#FFFFFF' link=\"660000\" vlink=\"660000\" alink=\"660000\" topmargin=\"14\">";

if (!$num_total_pergs) {
   $query = "select * from perguntas_pesquisa";
     
   $resultado = mysql_query($query) or
                   die(mysql_error());
   $num_total_pergs = mysql_num_rows($resultado);
}

if ( $num_total_pergs != 0 ) {

  if ( !$lim_inicial)
     $lim_inicial = 0;

 $pg_anterior = ($lim_inicial - $pergs_por_pagina) - 1;

  if ( $pg_anterior < 0 )
   $pg_anterior = 0;

 $pg_proxima = $lim_inicial + $pergs_por_pagina;
  if ( $pg_proxima > $num_total_pergs)
    $pg_proxima = $num_total_pergs;
  
  $query_1 = "select * from perguntas_pesquisa Order By codigo ASC LIMIT $lim_inicial,$pergs_por_pagina;";

  $resultado = mysql_query($query_1) or
             die(mysql_error());

  $result = mysql_fetch_array($resultado);

 echo "<br>&nbsp&nbsp <font face=\"Verdana\" color=\"#006B9F\" size=\"3\">Número total de perguntas cadastradas: $num_total_pergs<p><br>";

     $bgcolor_td = "#B0B0B0";
     $bgcolor_flag = 1;

     echo "<table border='1' cellspacing='0' cellpadding='0' align='center' width='96%'>";

     echo "<tr>";
       echo "<td width=\"60%\"><font face=\"Verdana\" color=\"#006B9F\" size=\"3\">Pergunta</font></td>";
         echo "<td width=\"15%\"><font face=\"Verdana\" color=\"#006B9F\" size=\"3\">Add Resposta</font></td>            
           </tr>";

           do {
               $perg = $result["pergunta"];
               $cod_perg = $result["codigo"];

               echo "<tr>";
                 echo "<td bgcolor='$bgcolor_td'><font face=\"Verdana\" color=\"black\" size=\"2\">$perg</font></td>";
               
                  echo "<td bgcolor='$bgcolor_td' align='center'><a href='add_resp.php?cod_perg=$cod_perg'>X</a></td>                         
                    </tr>";

               if ($bgcolor_flag) {
                 $bgcolor_td = "#FFFFFF";
                 $bgcolor_flag = !$bgcolor_flag;
               }
               else {
                 $bgcolor_td = "#B0B0B0";
                 $bgcolor_flag = !$bgcolor_flag;
               }

           } while ($result = mysql_fetch_array($resultado));

     echo "</table><p><center>";

     if ( $lim_inicial > 0 ) {
      echo "<a href='resp_pergs.php?lim_inicial=$pg_anterior&num_total_pergs=$num_total_pergs'>Ver $pergs_por_pagina perguntas anteriores</a> &nbsp ";
     }

     if ( $pg_proxima < $num_total_pergs ) {

         if ($pg_proxima == ($num_total_pergs-1) ) {
           echo "<a href='resp_pergs.php?lim_inicial=$pg_proxima&num_total_pergs=$num_total_pergs'>Ver última pergunta cadastrada</a>";
         }
         else if ( $pg_proxima <= ($num_total_pergs-$pergs_por_pagina) ){
           echo "<a href='resp_pergs.php?lim_inicial=$pg_proxima&num_total_pergs=$num_total_pergs'>Ver $pergs_por_pagina próximas perguntas</a>";
         }
         else {
           $num_pergs_restantes = $num_total_pergs - $pg_proxima;
           echo "<a href='resp_pergs.php?lim_inicial=$pg_proxima&num_total_pergs=$num_total_pergs'>Ver $num_pergs_restantes próximas perguntas</a>";
         }
     }

  echo "</center></body></html>";

} // Fim do if ( $num_total_pergs != 0 )
else {
 echo "<p><br><p>";
 echo "<center><font face=\"Verdana\" color=\"#006B9F\" size=\"3\">Não existem perguntas cadastradas</font><p><br><br></center>";       
}

echo "</body>";
echo "</html>";

?>