Advertisement
Guest User

Untitled

a guest
Sep 18th, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.79 KB | None | 0 0
  1. <?php
  2. $dbserver = "localhost";
  3. $dbuser = "kamileqp_divek";
  4. $dbpass = "xlayx512";
  5. $dbname   = "kamileqp_lex";
  6.  
  7. $id = $_GET["id"];
  8. if ($id<=0) {
  9.     echo "Error: no id";
  10.     die();
  11. }
  12. $file = "/home/kamileqp/public_html/techbird.pl/parser/eksport" . $id . ".xml";
  13.  
  14. function FullModeProcessing($value)
  15. {
  16.     //  if ($value=="true") {
  17.     // tutaj może znajdować się kod czyszczacy baze danych
  18.     // dla eksportu calosciowego
  19.     // }
  20. }
  21.  
  22. function ProcessOferta($oferta)
  23. {
  24.     // tutaj powinien znalezc się kod dodajacy bądź usuwajacy oferte z bazy danych
  25.     echo "Oferta nr: ". $oferta["IDOFERTA"] . "<br>";
  26.     $wynik = mysql_query("SELECT  nroferty FROM ogloszenia WHERE nroferty = " . $oferta["IDOFERTA"] . ";");
  27.     echo mysql_error(); $row=mysql_fetch_row($wynik); echo "Takich ofert w bazie:" . count($row[0])."<br>";
  28.         if ( count($row[0])>0 )
  29.     {   // jest taka oferta, wiec ja usuwamy
  30.        $wynik = mysql_query("select zdjecie from foto where ogl = " . $oferta["IDOFERTA"]);
  31.         while ($listap = mysql_fetch_row($wynik))
  32.         {  // kasowanie zdjec plików
  33.             unlink("foto/" . $listap[0] );
  34.             unlink("foto/min" . $listap[0] );
  35.         }
  36.          
  37.           mysql_query("delete from foto where ogl = " . $oferta["IDOFERTA"]);
  38.           mysql_query("delete from ogloszenia where nroferty = " . $oferta["IDOFERTA"]);
  39.            
  40.     }
  41.  
  42.    
  43.     if ($oferta["ACTION"] == "delete") return;   // oferta zostala skasowana
  44.     if ($oferta["TRANSAKCJA"]>3) return;
  45.        
  46.     if ($oferta["TRANSAKCJA"]==3) $oferta["TRANSAKCJA"]=1;
  47.    
  48.     if ($oferta["TYP"]<3) $oferta["TYP"]++;
  49.     else if ($oferta["TYP"]==5) $oferta["TYP"]=7;
  50.     else if ($oferta["TYP"]==3) $oferta["TYP"]=5;
  51.    
  52.  
  53.     $insertsql = "insert into ogloszenia (co, nroferty, miasto, ulica, pow, dzielnica, pokoje, spec, pietro, pieter, cena, opis, transakcja, typ, rok, zabudowa, media, powdz, dlugosc, szerokosc) values ('Cena:', ";
  54.     $insertsql.=$oferta["IDOFERTA"] . ", '" . $oferta["MIASTO"] . "', '" . $oferta["ULICA"] . "', " . ereg_replace(",", ".", $oferta["POWIERZCHNIA_OD"]) . ", '" . $oferta["DZIELNICA"] . "', '" . $oferta["POKOJE"] . "', " . $oferta["PROMOTED"] . ", '" . $oferta["PIETRO"] . "', '" . $oferta["L_PIETER"] . "', " . ereg_replace(",", ".", $oferta["CENA_DO"]) . ", '" . addslashes($oferta["OPIS_PUBLICZNY"]) . "', " . $oferta["TRANSAKCJA"] . ", " . $oferta["TYP"] . ", '" . $oferta["ROK_BUDOWY"] . "', '" . $oferta["TYP_ZABUDOWY"] . "', '" . $oferta["MEDIA"] . "', '" . $oferta["POW_DZIALKI"] . "', '" . $oferta["DLUGOSC"] . "', '" . $oferta["SZEROKOSC"] . "'";
  55.     $insertsql.=");";
  56.    
  57.         echo $insertsql;
  58.     $wynik = mysql_query($insertsql);
  59.         if(!$wynik)
  60.             echo mysql_error ();
  61.        
  62.     $ofid = $oferta["IDOFERTA"];
  63.    
  64.     if ($oferta["COUNT"]>0)
  65.     {   // zdjecia
  66.         for ($i = 1; $i <= $oferta["COUNT"]; $i++)
  67.         {
  68.                    $lok = 'P_' . $i; //echo $lok;
  69.                    $lokm = 'PM_' . $i; //echo $lok;
  70.            rename("/home/kamileqp/public_html/techbird.pl/parser/" . $oferta[$lok] ,  "/home/kamileqp/public_html/techbird.pl/lex/foto/" . $oferta[$lok] );
  71.            rename("/home/kamileqp/public_html/techbird.pl/parser/" . $oferta[$lokm] ,  "/home/kamileqp/public_html/techbird.pl/lex/foto/min/" . $oferta[$lok] );
  72.                    
  73.                     $insertsql = "insert into foto (zdjecie, ogl) values ('$oferta[$lok]', $ofid)";
  74.                     echo $insertsql;
  75.                     $wynik = mysql_query($insertsql);
  76.                     if(!$wynik)
  77.                         echo mysql_error ();
  78.         }
  79.     }
  80.    
  81.    
  82. }
  83.  
  84. // ********************** PARSER PLIKU XML Z OFERTAMI ***********************
  85.  
  86.  
  87. function contents($parser, $data){
  88.     global $act_tag, $inoferta, $oferta;
  89.     if ($inoferta)
  90.     {
  91.         if (isset($oferta[$act_tag])) $oferta[$act_tag] .= $data;
  92.     else $oferta[$act_tag] = $data;    
  93.     } else if ($act_tag=="FULL_MODE") FullModeProcessing($data);
  94. }
  95.  
  96. function startTag($parser, $data){
  97.      global $act_tag, $inoferta, $oferta;
  98.      if ($data=="RECORD") {
  99.         $inoferta = true;
  100.         $oferta = array();
  101.      }
  102.      $act_tag = $data;
  103. }
  104.  
  105. function endTag($parser, $data){
  106.     global $act_tag, $inoferta, $oferta;
  107.     if ($data == "RECORD") {
  108.         $inoferta = false;
  109.         ProcessOferta($oferta);
  110.     }
  111.      $act_tag = "";
  112. }
  113.  
  114. mysql_connect($dbserver, $dbuser, $dbpass);
  115. mysql_select_db($dbname);
  116.  
  117. $xml_parser = xml_parser_create('');
  118. xml_parser_set_option($xml_parser, XML_OPTION_TARGET_ENCODING, 'UTF-8');
  119. xml_set_element_handler($xml_parser, "startTag", "endTag");
  120. xml_set_character_data_handler($xml_parser, "contents");
  121.  
  122. $fp = fopen($file, "r");
  123. if (!$fp) { echo "Error"; die(); }
  124.  
  125.  
  126. $data = fread($fp, 1000000);
  127.  
  128. if(!(xml_parse($xml_parser, $data, feof($fp)))){
  129.     die("Error on line " . xml_get_current_line_number($xml_parser));
  130. }
  131.  
  132. echo "OK";
  133.  
  134. xml_parser_free($xml_parser);
  135.  
  136. fclose($fp);
  137.  
  138. unlink($file);
  139.  
  140. mysql_close();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement