Advertisement
Guest User

Untitled

a guest
May 14th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 11.91 KB | None | 0 0
  1. <?php
  2. $lineaPar=1;
  3.  
  4. function pegaform() {
  5. echo "<form action=\"insertar.php\" method=\"POST\">
  6. <TABLE border=\"0\">
  7. <TR>
  8.   <TD>host:</TD>
  9.   <TD><INPUT TYPE=\"password\" value=\"sql104.zobyhost.com\" NAME=\"host\" SIZE=\"20\" MAXLENGTH=\"30\"></TD>
  10. </TR>
  11. <TR>
  12.   <TD>userid:</TD>
  13.   <TD><INPUT TYPE=\"password\" value=\"zoby_5231271\" NAME=\"user\" SIZE=\"20\" MAXLENGTH=\"30\"></TD>
  14. </TR>
  15. <TR>
  16.   <TD>password:</TD>
  17.   <TD><INPUT TYPE=\"password\" NAME=\"pass\" SIZE=\"20\" MAXLENGTH=\"30\"></TD>
  18. </TR>
  19. </TABLE>
  20.     <INPUT TYPE=\"submit\" NAME=\"accion\" VALUE=\"conectar\">
  21. </FORM>";
  22. }
  23.  
  24. function conectar($host, $user, $pass) {
  25.     $conex = mysql_connect($host, $user, $pass);
  26.     /*if (mysql_select_db($db, $conex)) {
  27.         return $conex; 
  28.     } else {
  29.         print (mysql_error());
  30.     }*/
  31.     return $conex; 
  32. }
  33.  
  34. function desconectar($conex) {
  35.     mysql_close($conex);
  36. }
  37.  
  38. function insertar($host, $user, $pass) {
  39.     if(isset($_COOKIE["PHPSESSID"]) && isset($_SESSION["pass"])) {
  40. //      echo 'if(isset($_COOKIE["PHPSESSID"]) && isset($_SESSION["pass"])) { $pass'.$pass.' $_SESSION["pass"]'.$_SESSION["pass"];
  41.         if ($load=0) {
  42.             if (isset($_POST["nombre"])) {
  43.                 if (isset($_SESSION['host']) && isset($_SESSION['user']) && isset($_SESSION['pass'])) {
  44.                     $conex=conectar($_SESSION['host'], $_SESSION['user'], $_SESSION['pass']);
  45.                     if (mysql_select_db("zoby_5231271_lj", $conex)) {
  46.                         if ($result=mysql_query("INSERT INTO juegos VALUES ('".$_POST["nombre"]."',".$_POST["discos"].",'".$_POST["reg"]."',".$_POST["w"].",".$_POST["ss"].",".$_POST["st"].",'".$_POST["audio"]."','".$_POST["text"]."') ",$conex)) {
  47.                                 echo $result.' <table border=0><tr><td>'.$_POST["nombre"].'</td><td>'.$_POST["discos"].'</td><td>'.$_POST["reg"].'</td><td>'.$_POST["w"].'</td><td>'.$_POST["ss"].'</td><td>'.$_POST["st"].'</td><td>'.$_POST["audio"].'</td><td>'.$_POST["text"].'</td><td>'.$conex.'</td></tr></table>';
  48.                             } else {
  49.                                 print (mysql_error());
  50.                             }
  51.                     } else {
  52.                         print (mysql_error());
  53.                     }
  54.                     desconectar($conex);       
  55.                 } else {
  56.                     echo "Faltan datos de loggeo<br> Redireccionando<br><meta http-equiv=\"refresh\" content=\"5;URL=admin.php\">";
  57.                 }
  58.             }
  59.         } elseif ($load=1) {
  60.             $tablaHtml=$_POST['tablahtml'];
  61.             if (isset($tablaHtml)) {
  62.                 tablaHtml($tablaHtml);
  63.             }
  64.         }
  65.        
  66.         echo"<form name=\"form1\" method=\"post\" action=\"insertar.php?load=0\">
  67.           <table>
  68.           <tr>
  69.             <td>Juego</td><td>DVDs</td><td>Region</td><td>Wave</td><td>SSv</td><td>Stealth</td><td>Audio</td><td>Textos, Subs.</td>
  70.           </tr>
  71.           <tr>
  72.             <td><input type=\"text\" name=\"nombre\"></td><td><input type=\"text\" name=\"discos\"></td><td><input type=\"text\" name=\"reg\"></td><td><input type=\"text\" name=\"w\"></td><td><input type=\"text\" name=\"ss\"></td><td><input type=\"text\" name=\"st\"></td><td><input type=\"text\" name=\"audio\"></td><td><input type=\"text\" name=\"text\"></td>
  73.           </tr>
  74.           <tr>
  75.             <td><input type=\"submit\" name=\"Submit\" value=\"Insertar datos\"></td>
  76.           </tr>
  77.           </table>
  78.         </form><br>
  79.        
  80.         <form name=\"form2\" method=\"post\" action=\"insertar.php?load=1\">
  81.           <table>
  82.           <tr>
  83.             <td>cargar desde tabla html</td>
  84.           </tr>
  85.           <tr>
  86.             <td><textarea name=\"tablahtml\" cols=\"80\" rows=\"20\"></textarea></td>
  87.           </tr>
  88.           <tr>
  89.             <td><input type=\"submit\" name=\"Submit\" value=\"Cargar Tabla\"></td>
  90.           </tr>
  91.           </table>
  92.         </form>";
  93.        
  94.     } else {
  95. //      echo 'ELSEif(isset($_COOKIE["PHPSESSID"]) && isset($_SESSION["pass"])) { $pass'.$pass.' $_SESSION["pass"]'.$_SESSION["pass"];
  96.         if (isset($host, $user, $pass)) {
  97. //          echo 'ELSEif(isset($_COOKIE["PHPSESSID"]) && isset($_SESSION["pass"])) {<br>if (isset($host, $user, $pass)) { $pass'.$pass.' $_SESSION["pass"]'.$_SESSION["pass"];           
  98.             $_SESSION['host']=$host;
  99.             $_SESSION['user']=$user;
  100.             $_SESSION['pass']=$pass;
  101.         } else {
  102.             echo "Faltan datos de loggeo<br> Redireccionando<br><meta http-equiv=\"refresh\" content=\"5;URL=admin.php\">";        
  103.         }
  104.     }
  105.    
  106. }
  107.  
  108. function mostrar() {
  109.     $conex=conectar("sql104.zobyhost.com", "zoby_5231271", "m4Sj0D10");
  110.     mysql_select_db("zoby_5231271_lj", $conex);
  111.     $result=mysql_query("SELECT * FROM juegos ORDER BY Juego",$conex);
  112.     echo"<table width=\"100%\" border=\"1\" cellpadding=\"0\" cellspacing=\"0\" bordercolor=\"#999999\">
  113.       <tr bgcolor=\"#FFFF66\">
  114.         <td width=\"35%\"> <div align=\"left\"><font face=\"MS Serif\">Juego</font></div></td>
  115.         <td width=\"5%\"> <div align=\"center\"><font face=\"MS Serif\">DVDs</font></div></td>
  116.         <td width=\"20%\"> <div align=\"center\"><font face=\"MS Serif\">Region</font></div></td>
  117.         <td width=\"5%\"> <div align=\"center\"><font face=\"MS Serif\">Wave</font></div></td>
  118.         <td width=\"5%\"> <div align=\"center\"><font face=\"MS Serif\">SSv</font></div></td>
  119.         <td width=\"5%\"> <div align=\"center\"><font face=\"MS Serif\">Stealth</font></div></td>
  120.         <td width=\"15%\"> <div align=\"center\"><font face=\"MS Serif\">Audio</font></div></td>
  121.         <td width=\"15%\"> <div align=\"center\"><font face=\"MS Serif\">Textos, Subs.</font></div></td>
  122.       </tr>
  123.     ";
  124.     while($row=mysql_fetch_row($result)){
  125.         if (!is_odd($lineaPar)) {
  126.             echo"<tr>
  127.             <td width=\"35%\"><div align=\"left\"><font face=\"MS Serif\">$row[0]</font></div></td>
  128.             <td width=\"5%\"><div align=\"center\"><font face=\"MS Serif\">$row[1]</font></div></td>
  129.             <td width=\"20%\"> <div align=\"center\"><font face=\"MS Serif\">$row[2]</font></div></td>
  130.             <td width=\"5%\"> <div align=\"center\"><font face=\"MS Serif\">$row[3]</font></div></td>
  131.             <td width=\"5%\"> <div align=\"center\"><font face=\"MS Serif\">$row[4]</font></div></td>
  132.             <td width=\"5%\"> <div align=\"center\"><font face=\"MS Serif\">$row[5]</font></div></td>
  133.             <td width=\"15%\"> <div align=\"center\"><font face=\"MS Serif\">$row[6]</font></div></td>
  134.             <td width=\"15%\"> <div align=\"center\"><font face=\"MS Serif\">$row[7]</font></div></td>
  135.             </tr>";
  136.             $lineaPar++;
  137.         } else  if (is_odd($lineaPar)) {
  138.             echo"<tr bgcolor=\"#99CCCC\">
  139.             <td width=\"35%\"><div align=\"left\"><font face=\"MS Serif\">$row[0]</font></div></td>
  140.             <td width=\"5%\"><div align=\"center\"><font face=\"MS Serif\">$row[1]</font></div></td>
  141.             <td width=\"20%\"> <div align=\"center\"><font face=\"MS Serif\">$row[2]</font></div></td>
  142.             <td width=\"5%\"> <div align=\"center\"><font face=\"MS Serif\">$row[3]</font></div></td>
  143.             <td width=\"5%\"> <div align=\"center\"><font face=\"MS Serif\">$row[4]</font></div></td>
  144.             <td width=\"5%\"> <div align=\"center\"><font face=\"MS Serif\">$row[5]</font></div></td>
  145.             <td width=\"15%\"> <div align=\"center\"><font face=\"MS Serif\">$row[6]</font></div></td>
  146.             <td width=\"15%\"> <div align=\"center\"><font face=\"MS Serif\">$row[7]</font></div></td>
  147.             </tr>";
  148.             $lineaPar++;
  149.         }
  150.        
  151.     }   /* else {
  152.                print (mysql_error());
  153.             }*/
  154.     echo"</table>";
  155.    
  156.     desconectar($conex);
  157. }
  158.  
  159. function is_odd($number) {
  160.  return $number & 1; // 0 = par, 1 = impar
  161. }
  162.  
  163. function tablaHtml($tablaHtml) {
  164.     $ElCualo = array("<TR VALIGN=TOP>
  165.         <TD WIDTH=40%>
  166.             <P STYLE=\"font-weight: normal\"><FONT COLOR=\"#000000\"><FONT FACE=\"Arial, sans-serif\"><FONT SIZE=2>",
  167.    
  168.                 "</FONT></FONT></FONT></P>
  169.         </TD>
  170.         <TD WIDTH=6% SDVAL=\"1\" SDNUM=\"3082;\">
  171.             <P ALIGN=CENTER STYLE=\"font-weight: normal\"><FONT COLOR=\"#000000\"><FONT FACE=\"Arial, sans-serif\"><FONT SIZE=2>",
  172.    
  173.                 "</FONT></FONT></FONT></P>
  174.         </TD>
  175.         <TD WIDTH=15%>
  176.             <P ALIGN=CENTER STYLE=\"font-weight: normal\"><FONT COLOR=\"#000000\"><FONT FACE=\"Arial, sans-serif\"><FONT SIZE=2>",
  177.    
  178.                 "</FONT></FONT></FONT></P>
  179.         </TD>
  180.         <TD WIDTH=6% SDVAL=\"4\" SDNUM=\"3082;\">
  181.             <P ALIGN=CENTER STYLE=\"font-weight: normal\"><FONT COLOR=\"#000000\"><FONT FACE=\"Arial, sans-serif\"><FONT SIZE=2>",
  182.    
  183.                 "</FONT></FONT></FONT></P>
  184.         </TD>
  185.         <TD WIDTH=5% SDVAL=\"1\" SDNUM=\"3082;\">
  186.             <P ALIGN=CENTER STYLE=\"font-weight: normal\"><FONT COLOR=\"#000000\"><FONT FACE=\"Arial, sans-serif\"><FONT SIZE=2>",
  187.    
  188.                 "</FONT></FONT></FONT></P>
  189.         </TD>
  190.         <TD WIDTH=7%>
  191.             <P ALIGN=CENTER STYLE=\"font-weight: normal\"><FONT COLOR=\"#000000\"><FONT FACE=\"Arial, sans-serif\"><FONT SIZE=2>",
  192.    
  193.                 "</FONT></FONT></FONT></P>
  194.         </TD>
  195.         <TD WIDTH=9%>
  196.             <P ALIGN=CENTER STYLE=\"font-weight: normal\"><FONT COLOR=\"#000000\"><FONT FACE=\"Arial, sans-serif\"><FONT SIZE=2><SPAN STYLE=\"background: transparent\">",
  197.    
  198.                 "</SPAN></FONT></FONT></FONT></P>
  199.         </TD>
  200.         <TD WIDTH=13%>
  201.             <P ALIGN=CENTER STYLE=\"font-weight: normal\"><FONT COLOR=\"#000000\"><FONT FACE=\"Arial, sans-serif\"><FONT SIZE=2><SPAN STYLE=\"background: transparent\">",
  202.    
  203.                 "</SPAN></FONT></FONT></FONT></P>
  204.         </TD>
  205.     </TR>");
  206.     $PorElCualo=array("", "&nbsp;", "&nbsp;", "&nbsp;", "&nbsp;", "&nbsp;", "&nbsp;", "&nbsp;", "");
  207.    
  208.     $a = htmlentities($tablaHtml); // usar $a con str_replace <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  209.     $lineas=substr_count($a, htmlentities("<TR VALIGN=TOP>"));
  210.  
  211.     for ( $k = 1 ; $k <= $lineas ; $k++) {
  212.         $posS=strpos($a, htmlentities("<TR VALIGN=TOP>"), $k);
  213.         $posE=strpos($a, htmlentities("</TR>"), $k)+11;
  214.  
  215.         if ($k>1) {
  216.             //y tu dirás, esto para que? rectifica los cuelgues del strpos()
  217.             $g=$k;
  218.             while ($posS<=$overS) {
  219.                 $g++;
  220.                 $posS=strpos($a, htmlentities("<TR VALIGN=TOP>"), $g);
  221.             }
  222.         }
  223.         //lo mismo q lo de arriba
  224.         $f=$k;
  225.         while ($posE<$posS) {
  226.             $f++;
  227.             $posE=strpos($a, htmlentities("</TR>"), $f)+11;
  228.         }
  229.         //no se porque, pero substr también se cuelga a partir de la 2º vuelta
  230.         if ($k>1) {
  231.             $posE=$posE+2;
  232.         }
  233.         /* esto solventa un fallo gordo que tenia, le daba $posE como
  234.          * final y eso hace que pilla ese parametro como caracteres a contar
  235.          * hasta el final y no la posicion del caracter final, hago la resta
  236.          * y listo
  237.          */
  238.         $posEnd=$posE-$posS;
  239.  
  240. //      echo '$posStart['.$k.'] '.$posS.' ';
  241. //      echo '- $posEnd['.$k.'] '.$posE.' = '.$posEnd.'<br>';
  242.  
  243.         $lineaHtml=substr($a, $posS, $posEnd);
  244.         $aBece = str_replace($ElCualo, $PorElCualo, $lineaHtml);
  245. //      echo '$aBece['.$k.'] '.html_entity_decode($aBece).'<br>';
  246.         $overS=$posS; //variables de override, para que no se atasque strpos()
  247.         $overE=$posE; //variables de override, para que no se atasque strpos()
  248.             $datosMySQL = explode("&nbsp;", $aBece); // cortamos el string por el punto
  249. /*          for ( $j = 0 ; $j <= count($datosMySQL) ; $j ++) {
  250.                 echo '$datosMySQL['.$j.'] '.html_entity_decode($datosMySQL[$j]).'<br>';
  251.             }*/
  252.             $datosMySQL[6]=html_entity_decode($datosMySQL[6]);
  253.             $datosMySQL[7]=html_entity_decode($datosMySQL[7]);
  254.             //echo '$k'.$k.' $posS'.$posS.' $posE'.$posE.' $datosMySQL '.html_entity_decode($datosMySQL[0]).' '.html_entity_decode($datosMySQL[1]).' '.html_entity_decode($datosMySQL[2]).' '.html_entity_decode($datosMySQL[3]).' '.html_entity_decode($datosMySQL[4]).' '.html_entity_decode($datosMySQL[5]).' '.$datosMySQL[6].' '.$datosMySQL[7].'<br>';
  255.            
  256. //          echo $datosMySQL[6].' '.$datosMySQL[7].'<br>';
  257.            
  258.         if (isset($_SESSION['host']) && isset($_SESSION['user']) && isset($_SESSION['pass'])) {
  259.             $conex=conectar($_SESSION['host'], $_SESSION['user'], $_SESSION['pass']);
  260.             if (mysql_select_db("zoby_5231271_lj", $conex)) {
  261.                 if ($result=mysql_query("INSERT INTO juegos VALUES ('".$datosMySQL[0]."',".$datosMySQL[1].",'".$datosMySQL[2]."',".$datosMySQL[3].",".$datosMySQL[4].",".$datosMySQL[5].",'".html_entity_decode($datosMySQL[6],ENT_QUOTES)."','".html_entity_decode($datosMySQL[7],ENT_QUOTES)."') ",$conex)) {
  262.                         echo $result.' <table border=0><tr><td>'.$datosMySQL[0].'</td><td>'.$datosMySQL[1].'</td><td>'.$datosMySQL[2].'</td><td>'.$datosMySQL[3].'</td><td>'.$datosMySQL[4].'</td><td>'.$datosMySQL[5].'</td><td>'.$datosMySQL[6].'</td><td>'.$datosMySQL[7].'</td><td>'.$conex.'</td></tr></table>';
  263.                     } else {
  264.                         print (mysql_error());
  265.                     }
  266.             } else {
  267.                 print (mysql_error());
  268.             }
  269.             desconectar($conex);       
  270.         } else {
  271.             echo "faltan datos para conectar a MySQL. host=".$_SESSION['host']." user=".$_SESSION['user']." pass=".$_SESSION['pass'];
  272.         }      
  273.     }
  274. }
  275.  
  276. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement