Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $dbserver = "localhost";
- $dbuser = "kamileqp_divek";
- $dbpass = "xlayx512";
- $dbname = "kamileqp_lex";
- $id = $_GET["id"];
- if ($id<=0) {
- echo "Error: no id";
- die();
- }
- $file = "/home/kamileqp/public_html/techbird.pl/parser/eksport" . $id . ".xml";
- function FullModeProcessing($value)
- {
- // if ($value=="true") {
- // tutaj może znajdować się kod czyszczacy baze danych
- // dla eksportu calosciowego
- // }
- }
- function ProcessOferta($oferta)
- {
- // tutaj powinien znalezc się kod dodajacy bądź usuwajacy oferte z bazy danych
- echo "Oferta nr: ". $oferta["IDOFERTA"] . "<br>";
- $wynik = mysql_query("SELECT nroferty FROM ogloszenia WHERE nroferty = " . $oferta["IDOFERTA"] . ";");
- echo mysql_error(); $row=mysql_fetch_row($wynik); echo "Takich ofert w bazie:" . count($row[0])."<br>";
- if ( count($row[0])>0 )
- { // jest taka oferta, wiec ja usuwamy
- $wynik = mysql_query("select zdjecie from foto where ogl = " . $oferta["IDOFERTA"]);
- while ($listap = mysql_fetch_row($wynik))
- { // kasowanie zdjec plików
- unlink("foto/" . $listap[0] );
- unlink("foto/min" . $listap[0] );
- }
- mysql_query("delete from foto where ogl = " . $oferta["IDOFERTA"]);
- mysql_query("delete from ogloszenia where nroferty = " . $oferta["IDOFERTA"]);
- }
- if ($oferta["ACTION"] == "delete") return; // oferta zostala skasowana
- if ($oferta["TRANSAKCJA"]>3) return;
- if ($oferta["TRANSAKCJA"]==3) $oferta["TRANSAKCJA"]=1;
- if ($oferta["TYP"]<3) $oferta["TYP"]++;
- else if ($oferta["TYP"]==5) $oferta["TYP"]=7;
- else if ($oferta["TYP"]==3) $oferta["TYP"]=5;
- $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:', ";
- $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"] . "'";
- $insertsql.=");";
- echo $insertsql;
- $wynik = mysql_query($insertsql);
- if(!$wynik)
- echo mysql_error ();
- $ofid = $oferta["IDOFERTA"];
- if ($oferta["COUNT"]>0)
- { // zdjecia
- for ($i = 1; $i <= $oferta["COUNT"]; $i++)
- {
- $lok = 'P_' . $i; //echo $lok;
- $lokm = 'PM_' . $i; //echo $lok;
- rename("/home/kamileqp/public_html/techbird.pl/parser/" . $oferta[$lok] , "/home/kamileqp/public_html/techbird.pl/lex/foto/" . $oferta[$lok] );
- rename("/home/kamileqp/public_html/techbird.pl/parser/" . $oferta[$lokm] , "/home/kamileqp/public_html/techbird.pl/lex/foto/min/" . $oferta[$lok] );
- $insertsql = "insert into foto (zdjecie, ogl) values ('$oferta[$lok]', $ofid)";
- echo $insertsql;
- $wynik = mysql_query($insertsql);
- if(!$wynik)
- echo mysql_error ();
- }
- }
- }
- // ********************** PARSER PLIKU XML Z OFERTAMI ***********************
- function contents($parser, $data){
- global $act_tag, $inoferta, $oferta;
- if ($inoferta)
- {
- if (isset($oferta[$act_tag])) $oferta[$act_tag] .= $data;
- else $oferta[$act_tag] = $data;
- } else if ($act_tag=="FULL_MODE") FullModeProcessing($data);
- }
- function startTag($parser, $data){
- global $act_tag, $inoferta, $oferta;
- if ($data=="RECORD") {
- $inoferta = true;
- $oferta = array();
- }
- $act_tag = $data;
- }
- function endTag($parser, $data){
- global $act_tag, $inoferta, $oferta;
- if ($data == "RECORD") {
- $inoferta = false;
- ProcessOferta($oferta);
- }
- $act_tag = "";
- }
- mysql_connect($dbserver, $dbuser, $dbpass);
- mysql_select_db($dbname);
- $xml_parser = xml_parser_create('');
- xml_parser_set_option($xml_parser, XML_OPTION_TARGET_ENCODING, 'UTF-8');
- xml_set_element_handler($xml_parser, "startTag", "endTag");
- xml_set_character_data_handler($xml_parser, "contents");
- $fp = fopen($file, "r");
- if (!$fp) { echo "Error"; die(); }
- $data = fread($fp, 1000000);
- if(!(xml_parse($xml_parser, $data, feof($fp)))){
- die("Error on line " . xml_get_current_line_number($xml_parser));
- }
- echo "OK";
- xml_parser_free($xml_parser);
- fclose($fp);
- unlink($file);
- mysql_close();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement