Advertisement
wrsi

Modulo

Jun 15th, 2013
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 17.03 KB | None | 0 0
  1. <?php
  2. require('includes/application_top.php');
  3.  
  4.   error_reporting(0);
  5.     function calcula_frete_correios($cep_origem, $cep_destino, $peso, $valordeclarado, $servico, $trys) {
  6.             $chances = 1;
  7.             $conexao = fsockopen("www.correios.com.br", 80, $errno, $errstr, 2);
  8.  
  9.             if (!$conexao) {
  10.                 if ($trys < $chances) {
  11.                     calcula_frete_correios($ceporigem, $cepdestino, $peso, $valordeclarado, $servico, ++$trys);
  12.                 } else
  13.                     return 0;
  14.             } else {
  15.                 $saida  = "GET /encomendas/precos/calculo.cfm?servico=$servico&CepOrigem=$cep_origem&CepDestino=$
  16. cep_destino&Peso=$peso&ValorDeclarado=$valordeclarado HTTP/1.1\r\n";
  17.                 $saida .= "Host: www.correios.com.br\r\n";
  18.                 $saida .= "Connection: Close\r\n\r\n";
  19.    
  20.                 fwrite($conexao, $saida);
  21.                 stream_set_timeout($conexao, 10000);                
  22.                 $resposta = "";
  23.                            
  24.                 while (!feof($conexao))      
  25.                     $resposta .= fgets($conexao, 128);
  26.                
  27.                 fclose($conexao);
  28.        
  29.                 ereg ("&Tarifa=([0-9]+\.[0-9]+)", $resposta, $reg);
  30.            
  31.                 if (!$reg[1])
  32.                     ereg ("&Tarifa=([0-9]+)", $resposta, $reg);
  33.                 $resultado = $reg[1];
  34.                
  35.                 if ($resultado == 0 && $trys < $chances) {
  36.                     calcula_frete_correios($ceporigem, $cepdestino, $peso, $valordeclarado, $servico, ++$trys);
  37.                 } else
  38.                     return $resultado;
  39.                
  40.             }
  41.     //    } catch(Exception $e) {   // PHP5
  42.     //        return 0;
  43.     //    }
  44.   }
  45.  
  46.  // $idml = $_GET["idml"];
  47.    
  48. //  $idproduto = mysql_query("select * from products where  products_ml = '".$idml."'");
  49. //  $idx = mysql_fetch_array($idproduto);
  50. //  $products_idml = $idx['products_id'];// Isto traz o ID do produto
  51.     $products_idml = $_GET["idml"];// Isto traz o ID do produto
  52.        
  53.     $pesop=tep_db_query("SELECT products_weight FROM `products` WHERE `products_id` = '".$products_idml."'");
  54.     $pesop = tep_db_fetch_array($pesop);    
  55.     $pesop = $pesop["products_weight"];
  56.     $pesoa = str_replace(".", ",", $pesop);
  57.  
  58.  
  59.     $cep_origem=tep_db_query("SELECT configuration_value FROM `configuration` WHERE `configuration_key` = 'SHIPPING_ORIGIN_ZIP'");
  60.     $cep = tep_db_fetch_array($cep_origem);    
  61.     $cep_origem = $cep["configuration_value"];
  62.    
  63.     $preco = tep_db_query("SELECT products_price FROM `products` WHERE `products_id` = '".$products_idml."'");
  64.     $preco = tep_db_fetch_array($preco);    
  65.     $preco = $preco["products_price"];
  66.    
  67.     $nomeprodutoml = mysql_query("select * from products_description where products_id = '".$products_idml."'");
  68.     $nomeprodutoml = mysql_fetch_array($nomeprodutoml);
  69.     $nomeprodutoml = $nomeprodutoml['products_name'];//Istro traz o nome do Produto
  70.    
  71.     $imagemproduto = mysql_query("select * from products where products_id = '".$products_idml."'");
  72.     $imagemproduto = mysql_fetch_array($imagemproduto);
  73.     $imagemproduto = $imagemproduto['products_image'];//Istro traz o nome do Produto
  74.    
  75.    
  76.    
  77.     $ceporigem = $_GET["ceporigem"];
  78.     $cep1 = $_GET["cepdestino1"];
  79.     $cep2 = $_GET["cepdestino2"];
  80.    
  81.     $cepdestino = $cep1.$cep2;
  82.     $cepdestino = str_replace("-", "", $cepdestino);
  83.     $cepdestino = str_replace(".", "", $cepdestino);   
  84.     $mult = $_GET["multiplicador"];  
  85.     $peso = $_GET["peso"];
  86.     $peso = bcmul($peso, $mult, 2);
  87.     $pesototal = $peso;
  88.     $valordeclarado = $_GET["valordeclarado"];
  89.     $servico = $_GET["servico"];
  90.    
  91.     $valorfrete = calcula_frete_correios($ceporigem, $cepdestino, $peso, $valordeclarado, $servico, 1);
  92.     $valorfrete = str_replace(".", ",", $valorfrete);
  93.    
  94.     $sedex = $servico;
  95. if ($sedex == '40010') {
  96.     $sedex = 'SEDEX'; }
  97. if ($sedex == '40045') {
  98.     $sedex = 'SEDEX A COBRAR'; }
  99. if ($sedex == '41106') {
  100.     $sedex = 'PAC'; }
  101. if ($sedex == '41017') {
  102.     $sedex = 'ENCOMENDA NORMAL'; }
  103.    
  104. if ($multiplicador == '1') {
  105.     $unidplural = 'unidade'; } else {
  106.     $unidplural = 'unidades'; }
  107.    
  108. ?>
  109. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  110. <html><head><title>Calculo de Frete Mercado Livre</title>  
  111.  
  112.  
  113.  
  114. <link rel="stylesheet" type="text/css" href="frete_stylesheet.css">
  115. <script>
  116. function verifica_cep(theform) {
  117.  
  118.     if  (isNaN(frete.cep1.value)) {
  119.         alert( 'O campo CEP deve ser numérico');
  120.         frete.cep1.focus();
  121.         return( false );
  122.         }
  123.  
  124.      if  (isNaN(frete.cep2.value)) {
  125.         alert( 'O campo CEP deve ser numérico');
  126.         frete.cep2.focus();
  127.         return( false );
  128.         }
  129.        
  130.     if (frete.cep1.value == '') {
  131.         alert( 'Você deve informar seu CEP.');
  132.         frete.cep1.focus();
  133.         return( false );
  134.     }
  135.    
  136.     if (frete.cep2.value == '') {
  137.         alert( 'Você deve informar seu CEP.');
  138.         frete.cep2.focus();
  139.         return( false );
  140.     }
  141.    
  142. if (frete.cep1.value.length != 5){
  143.         alert( 'O campo de CEP deve ter 8 digitos.');
  144.         frete.cep1.focus();
  145.         return( false );
  146.     }
  147.  
  148. if (frete.cep2.value.length != 3){
  149.         alert( 'O campo de CEP deve ter 8 digitos.');
  150.         frete.cep2.focus();
  151.         return( false );
  152.     }  
  153.    
  154. document.form.submit();
  155.    return(true);
  156.    
  157. }
  158.  
  159. //self.window.toolbar.visible=false;
  160. //self.window.locationbar.visible false;
  161.  
  162. window.resizeTo(screen.width, screen.height - 30);
  163. window.moveTo( 0 ,0 );
  164. </script>
  165. <style type="text/css">
  166. <!--
  167. .style1 {
  168.     font-family: Arial, Helvetica, sans-serif;
  169.     font-size: x-small;
  170. }
  171. .style2 {
  172.     font-family: Arial, Helvetica, sans-serif;
  173.     font-size: small;
  174. }
  175. .style3 {
  176.     font-size: x-large;
  177.     font-family: Arial, Helvetica, sans-serif;
  178.     font-weight: bold;
  179.     color: #0000FF;
  180. }
  181. .style4 {
  182.     font-family: Arial, Helvetica, sans-serif;
  183.     font-size: xx-small;
  184. }
  185. .style5 {font-size: x-small}
  186. .style6 {font-family: Arial, Helvetica, sans-serif}
  187. -->
  188. </style>
  189. </head><body topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0" marginheight="0" marginwidth="0">
  190. <? if ($valorfrete == '0') { ?>
  191. <!-- body //-->
  192. <table align="center" border="0" cellpadding="0" cellspacing="0" width="752">
  193.   <tbody>
  194.     <tr>
  195.       <td width="225">
  196.         <p align="center"><img src="images/<? echo STORE_LOGO; ?>"></p>
  197.       </td>
  198.       <td width="523">
  199.         <p align="center"><b><font face="Verdana" size="5">Cálculo de Frete</font></b></p></td>
  200.     </tr>
  201.     <tr>
  202.       <td colspan="2" width="750">&nbsp;</td>
  203.     </tr>
  204.   </tbody>
  205. </table>
  206. <table align="center" border="0" cellpadding="0" cellspacing="0" width="750">
  207.   <tbody>
  208.     <tr>
  209.       <td><table border="0" cellpadding="0" cellspacing="0" width="750">
  210.         <tbody>
  211.           <tr>
  212.             <td> <form action="" method="get">
  213.             <input type="hidden" name="ceporigem" id="ceporigem" value="<? echo $cep_origem; ?>" />
  214.                 <input type="hidden" name="peso" id="peso" value="<? echo $pesop; ?>" />
  215.                 <input type="hidden" name="maoPropria" id="maoPropria" value="N" />
  216.                 <input type="hidden" name="valordeclarado" id="valordeclarado" value="<? echo $preco; ?>"/>
  217.                 <input type="hidden" name="avisarRecebimento" id="avisarRecebimento" value="N" />
  218.                 <input type="hidden" name="idml" id="idml" value="<? echo $idml; ?>" />
  219.                              
  220.                   <tbody>
  221.             <tr>
  222.             <td align="right" valign="top" width="28%">&nbsp;</td>
  223.               <td valign="top" width="2%">&nbsp;</td>
  224.               <td valign="top" width="70%"><font color="#000000" face="Arial" size="2">Prezado cliente, nesta
  225.                 página você poderá fazer o cálculo de frete para o
  226.                 envio do produto&nbsp; abaixo. Informe o seu CEP,
  227.                 a quantidade desejada, escolha o tipo de serviço e depois clique no botão </font><b><font color="#4a766e" face="Arial" size="2">Calcular Frete.</font></b></td>
  228.             </tr>
  229.         <tr height="30">
  230.             <td align="right" height="15">&nbsp;</td>
  231.           <td height="15">&nbsp;</td>
  232.           <td height="15">&nbsp;</td>
  233.         </tr>
  234.         <tr height="30">
  235.           <td align="right" height="10" valign="top"><div align="center"><img src="images/<? echo $imagemproduto; ?>" name="imgp1" border="0" width="150"> </div></td>
  236.           <td height="10" valign="top">&nbsp;</td>
  237.           <td height="10" valign="top"><table border="0" cellpadding="5" cellspacing="0" width="479">
  238.             <tbody>
  239.               <tr bgcolor="#efefef">
  240.                 <td style="border-top: 1px solid silver;" width="116"><font face="Arial" size="2"><b>Produto:</b></font></td>
  241.                 <td style="border-top: 1px solid silver;" width="343"><b><font color="#000080" face="Arial" size="2"><? echo $nomeprodutoml; ?></font></b></td>
  242.               </tr>
  243.               <tr bgcolor="#f5f5f5">
  244.                 <td style="border-top: 1px solid silver;" width="116"><font face="Arial" size="2"><b>CEP de Origem:</b></font></td>
  245.                 <td style="border-top: 1px solid silver;" width="343"><b><font color="#000080" face="Arial" size="2"><? echo $cep_origem; ?></font></b></td>
  246.               </tr>
  247.               <tr bgcolor="#efefef">
  248.                 <td style="border-top: 1px solid silver;" width="116"><font face="Arial" size="2"><b>Peso aproximado (c/ embalagem):</b></font></td>
  249.                 <td style="border-top: 1px solid silver;" width="343"><b><font color="#000080" face="Arial" size="2"><? echo $pesoa; ?> Kg</font></b></td>
  250.               </tr>
  251.               <tr bgcolor="#f5f5f5">
  252.                 <td style="border-top: 1px solid silver;" width="116"><font face="Arial" size="2"><b>Quantidade:</b></font></td>
  253.                 <td style="border-top: 1px solid silver;" width="343"><select class="input" style="width: 40px;" name="multiplicador">
  254.                   <option value="1" selected="selected">1</option>
  255.                   <option value="2">2</option>
  256.                   <option value="3">3</option>
  257.                   <option value="4">4</option>
  258.                   <option value="5">5</option>
  259.                   <option value="6">6</option>
  260.                   <option value="7">7</option>
  261.                   <option value="8">8</option>
  262.                   <option value="9">9</option>
  263.                   <option value="10">10</option>
  264.                 </select></td>
  265.               </tr>
  266.               <tr bgcolor="#efefef">
  267.                 <td style="border-top: 1px solid silver;" width="116"><font face="Arial" size="2"><b>Tipo de Serviço:</b></font></td>
  268.                 <td style="border-top: 1px solid silver;" width="343"><select class="input" name="servico" id="servico" >
  269.                   <option value="40010" selected>SEDEX</option>
  270.                   <option value="41106">PAC</option>
  271.                   <option value="40045">SEDEX A COBRAR</option>
  272.                   <option value="41017">NORMAL</option>
  273.                 </select></td>
  274.               </tr>
  275.               <tr bgcolor="#f5f5f5">
  276.                 <td style="border-top: 1px solid silver; border-bottom: 1px solid silver;" width="116"><font face="Arial" size="2"><b>Informe
  277.                   seu CEP:</b></font></td>
  278.                 <td style="border-top: 1px solid silver; border-bottom: 1px solid silver;" width="343"><table border="0" cellpadding="0" cellspacing="0" width="100%">
  279.                   <tbody>
  280.                     <tr>
  281.                       <td width="29%"><div align="left">
  282.                        <input class="input" style="font-weight: bold; width: 50px;" onkeypress="if (event.keyCode < 48 || event.keyCode > 57) event.returnValue = false; if(event.keyCode == 13)event.returnValue=false;" maxlength="5" size="20" name="cepdestino1" size="7" type="text">
  283.                         -
  284.                         <input class="input" style="font-weight: bold; width: 30px;" onkeypress="if (event.keyCode < 48 || event.keyCode > 57) event.returnValue = false; if(event.keyCode == 13)event.returnValue=false;" maxlength="3" size="20" name="cepdestino2" size="7" type="text">
  285.                       </div></td>
  286.                       <td width="65%"><p align="left" class="style6"><font size="2">Não sabe seu CEP ?<br>
  287.                         Então
  288.                         clique <a href="http://www.correios.com.br/servicos/cep/cep_loc_log.cfm" target="_blank"><b><font color="#0000ff">AQUI</font></b></a></font> </p></td>
  289.                     </tr>
  290.                   </tbody>
  291.                 </table></td>
  292.               </tr>
  293.             </tbody>
  294.           </table></td>
  295.         </tr>
  296.         <tr height="30">
  297.           <td align="right" height="10" valign="top">&nbsp;</td>
  298.           <td height="10" valign="top">&nbsp;</td>
  299.           <td height="10" valign="top"><p style="line-height: 100%; margin-top: 0pt; margin-bottom: 0pt;">&nbsp;</p></td>
  300.         </tr>
  301.         <tr height="30">
  302.           <td align="right" height="30" valign="top">&nbsp;</td>
  303.           <td height="30" valign="top">&nbsp;</td>
  304.           <td height="30" valign="top"><input style="width: 180px; height: 24px; color: rgb(255, 255, 255); background-color: rgb(0, 255, 0); font-weight: bold;" onclick="return verifica_cep(this);" value="Calcular Frete" type="submit">
  305.           <input style="width: 180px; height: 24px; color: rgb(255, 255, 255); background-color: rgb(255, 0, 0); font-weight: bold;" value="Limpar" type="reset">          </td>
  306.         </tr>
  307.         </tbody>
  308.   <tbody>
  309.     <tr>
  310.       <td>
  311.       </form>
  312.       </table></td>
  313.     </tr>
  314.             </tbody>
  315.           </table>
  316.         </td>
  317.       </tr>
  318.     </tbody>
  319.   </table>
  320. <table align="center" border="0" cellpadding="0" cellspacing="0" width="750">
  321.     <tbody>
  322.       <tr>
  323.         <td><div align="center">
  324.           <p class="style5 style4 style1">&nbsp;</p>
  325.           <p class="style5 style4 style1"><a href="http://www.lgz.com.br" class="style7">Cálculo de Frete pelo Sistema LegalLojaML - Lojas Integradas com o Mercado Livre</a></p>
  326.         </div></td>
  327.       </tr>
  328.     </tbody>
  329.   </table>
  330.  
  331. <?  } else { ?>
  332. <table align="center" border="0" cellpadding="0" cellspacing="0" width="752">
  333.   <tbody>
  334.     <tr>
  335.       <td width="225">
  336.         <p align="center"><img src="images/<? echo STORE_LOGO; ?>"></p>
  337.       </td>
  338.       <td width="523">
  339.         <p align="center"><b><font face="Verdana" size="5">Valor do Frete</font></b></p></td>
  340.     </tr>
  341.     <tr>
  342.       <td colspan="2" width="750">&nbsp;</td>
  343.     </tr>
  344.   </tbody>
  345. </table>
  346. <table align="center" border="0" cellpadding="0" cellspacing="0" width="750">
  347.   <tbody>
  348.     <tr>
  349.       <td><table border="0" cellpadding="0" cellspacing="0" width="750">
  350.         <tbody>
  351.           <tr>
  352.             <td>
  353.                   <tbody>
  354.                        
  355.             <tr>
  356.             <td align="right" valign="top" width="28%">&nbsp;</td>
  357.               <td valign="top" width="2%">&nbsp;</td>
  358.               <td valign="top" width="70%"><font face="Arial" size="2"><span class="style1">ATEN&Ccedil;&Atilde;O:</span></font><font color="#000000" face="Arial" size="2"> Esta p&aacute;gina exibe uma SIMULA&Ccedil;&Atilde;O do valor do frete, portanto seu resultado pode ocasionalmente n&atilde;o ser o valor real do frete. Nos reservamos o direito de corrigir eventuais diferen&ccedil;as no c&aacute;lculo.</font></td>
  359.             </tr>
  360.         <tr height="30">
  361.             <td align="right" height="15">&nbsp;</td>
  362.           <td height="15">&nbsp;</td>
  363.           <td height="15">&nbsp;</td>
  364.         </tr>
  365.         <tr height="30">
  366.           <td align="right" height="10" valign="top"><div align="center"><img src="images/<? echo $imagemproduto; ?>" name="imgp1" border="0" width="150"> </div></td>
  367.           <td height="10" valign="top">&nbsp;</td>
  368.           <td height="10" valign="top"><p class="infoBoxHeading style2">O valor do frete para <strong> <? echo $multiplicador; ?> </strong><? echo $unidplural; ?> do produto <strong><? echo $nomeprodutoml; ?></strong> com entrega atrav&eacute;s do servi&ccedil;o de <strong><? echo $sedex; ?></strong> no C.E.P. <strong><? echo $cepdestino; ?></strong> &eacute;:</p>
  369.             <p align="center" class="style3">R$ <? echo $valorfrete; ?></p>
  370.             <p align="center" class="style3">&nbsp;</p>
  371.             <p align="center" class="style3">
  372.               <input style="width: 180px; height: 24px; color: rgb(255, 255, 255); background-color: rgb(0, 0, 255); font-weight: bold;" onclick="history.back()" value="Novo Cálculo" type="submit">
  373.             </p></td>
  374.         </tr>
  375.         <tr height="30">        </tr>
  376.         </tbody>
  377.   <tbody>
  378.     <tr>
  379.      </table></td>
  380.     </tr>
  381.             </tbody>
  382.           </table>
  383.         </td>
  384.       </tr>
  385.     </tbody>
  386.   </table>
  387. <table align="center" border="0" cellpadding="0" cellspacing="0" width="750">
  388.     <tbody>
  389.       <tr>
  390.         <td><div align="center"><span class="style5 style4"><a href="http://www.lgz.com.br" class="style7">Cálculo de Frete pelo Sistema LegalLojaML - Lojas Integradas com o Mercado Livre</a></span></div></td>
  391.       </tr>
  392.     </tbody>
  393.   </table><? } ?>
  394.   </body></html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement