daily pastebin goal
8%
SHARE
TWEET

Untitled

a guest May 31st, 2017 90 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     public function setOgloszenia($ogloszenia){
  2.         logger("setOgloszenia();\n".$ogloszenia);
  3.         $host = 'db1.blue.pl';
  4.         $port = '5432';
  5.         $dbname = 'hestia_cms';
  6.         $user = 'hestia_cms';
  7.         $password = '4P0TdCiC';
  8.         $connection_string = 'host='.$host.' port='.$port.' dbname='.$dbname.' user='.$user.' password='.$password;
  9.         $conn = pg_connect($connection_string) or die("Brak połączenia");
  10.         if(!$conn){
  11.             return '<?xml version="1.0" encoding="utf-8"?><ROOT><STATUS>-1</STATUS><ERROR>Brak połączenia z bazą.</ERROR></ROOT>';
  12.         }
  13.  
  14.         $query = "DELETE FROM kallisto._ogloszenia";
  15.         pg_query($query);
  16.         $count = substr_count(preg_replace('/<TAGI>.*?<\/TAGI>/', '', str_replace("\t", "", str_replace("\n", "", str_replace("\r", "", str_replace("\0", "", $ogloszenia))))), '<ITEM>');
  17.         if($count == 0){
  18.             return '<?xml version="1.0" encoding="utf-8"?><ROOT><STATUS>-2</STATUS><ERROR>Brak danych.</ERROR></ROOT>';
  19.         }
  20.         $ogloszenia = xml2array($ogloszenia);
  21.         if($count == 1){
  22.             $query = "INSERT INTO kallisto._ogloszenia (nrref, nstanow, miasto, wojew, o_oczekiw, o_zakresodp, o_coofer) VALUES ('".
  23.             trim($ogloszenia['ROOT']['_c']['ITEM']['_c']['NRREF']['_v'])."', '".
  24.             trim($ogloszenia['ROOT']['_c']['ITEM']['_c']['NSTANOW']['_v'])."', '".
  25.             trim($ogloszenia['ROOT']['_c']['ITEM']['_c']['MIASTO']['_v'])."', '".
  26.             trim($ogloszenia['ROOT']['_c']['ITEM']['_c']['WOJEW']['_v'])."', '".
  27.             trim($ogloszenia['ROOT']['_c']['ITEM']['_c']['OGLOSZENIE']['_c']['OCZEKIW']['_v'])."', '".
  28.             trim($ogloszenia['ROOT']['_c']['ITEM']['_c']['OGLOSZENIE']['_c']['ZAKRESODP']['_v'])."', '".
  29.             trim($ogloszenia['ROOT']['_c']['ITEM']['_c']['OGLOSZENIE']['_c']['COOFER']['_v'])."')";
  30.             pg_query($query);
  31.         }else{
  32.             foreach($ogloszenia['ROOT']['_c']['ITEM'] as $ogloszenie){
  33.                 $query = "INSERT INTO kallisto._ogloszenia (nrref, nstanow, miasto, wojew, o_oczekiw, o_zakresodp, o_coofer) VALUES ('".
  34.                 trim($ogloszenie['_c']['NRREF']['_v'])."', '".
  35.                 trim($ogloszenie['_c']['NSTANOW']['_v'])."', '".
  36.                 trim($ogloszenie['_c']['MIASTO']['_v'])."', '".
  37.                 trim($ogloszenie['_c']['WOJEW']['_v'])."', '".
  38.                 trim($ogloszenie['_c']['OGLOSZENIE']['_c']['OCZEKIW']['_v'])."', '".
  39.                 trim($ogloszenie['_c']['OGLOSZENIE']['_c']['ZAKRESODP']['_v'])."', '".
  40.                 trim($ogloszenie['_c']['OGLOSZENIE']['_c']['COOFER']['_v'])."')";
  41.                 pg_query($query);
  42.             }
  43.         }
  44.         pg_close($conn);
  45.        
  46.         return '<?xml version="1.0" encoding="utf-8"?><ROOT><STATUS>0</STATUS></ROOT>';
  47.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top