123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223 |
- <?php
- /**
- * File name:
- *
- *
- * (C) Copyright 2013 Friedrich-Ebert-Stiftung (http://fes.ro)
- * Author: Tiberiu C. Turbureanu (tct@ceata.org)
- *
- * This file is part of the project funded by FES
- *
- * This is free software; you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
- require_once 'utile.php';
- $names = array();
- // Load the list of persons
- $xml = new DOMDocument();
- $xml->load('../20131013-consilieri.xml');
- $xpath = new DOMXpath($xml);
- $persons = $xpath->query("/xml/person");
- foreach($persons as $person)
- {
- $dataset = array();
- $dataset[] = $xpath->query("comname", $person)->item(0)->nodeValue;
- $dataset[] = $xpath->query("surname", $person)->item(0)->nodeValue;
- $names[] = $dataset;
- }
- $profiles = array();
- $html = file_get_contents('http://www.pmb.ro/institutii/cgmb/componenta/consilieri/consilieri.php');
- $doc = new DOMDocument();
- $doc->loadHTML($html);
- $xpath = new DOMXpath($doc);
-
- $elements = $xpath->query("//table[@id='tabel']/tbody/tr[@class='table_row0']");
- foreach ($elements as $e)
- {
- $dataset = array();
- $iname = "";
- // Get row from person table
- $row = $xpath->query("td", $e);
- $name = $row->item(1)->nodeValue;
- $dataset['name'] = substr($name, 2);
- $surname = fărăDiacritice(lcfirst(strtok($dataset['name'], "– ")));
- if ($surname == 'alexandre') $surname = 'fontoura';
- if ($surname == 'boaja')
- {
- $dataset['name'] = utf8_encode("Boajă Minică");
- }
- if ($surname == 'popescu')
- {
- $comname = "";
- while ($r = strtok("– "))
- {
- $comname = lcfirst($r);
- }
- $iname = $comname.'-'.$surname;
- }
- else
- {
- foreach ($names as $name)
- if ($name[1] == $surname)
- $iname = $name[0].'-'.$name[1];
- }
- $dataset['name'] = cuLiniuță(trim(cuDiacriticeCorecte($dataset['name'])));
- $birth = $row->item(2)->nodeValue;
- $dataset['date'] = substr(strtok($birth, ", "), 2);
- $dataset['place'] = trim(cuDiacriticeCorecte(substr($birth, 14)));
- if ($iname == 'violeta-popescu')
- {
- $dataset['place'] = "Târgu Jiu, Jud. Gorj";
- }
- else if ($surname == 'pieptea')
- {
- $dataset['place'] = "Com. Văleni, Jud. Olt";
- }
- $occup = $row->item(3)->nodeValue;
- $dataset['occup'] = trim(cuDiacriticeCorecte(substr($occup, 2)));
- if ($surname == 'nicolescu')
- {
- $dataset['occup'] = "Cadru universitar";
- }
- else if ($surname == 'pieptea')
- {
- $dataset['occup'] = "Consilier C.G.M.B.";
- }
- $prof = $row->item(4)->nodeValue;
- $dataset['prof'] = trim(cuDiacriticeCorecte(substr($prof, 2)));
- $affil = $row->item(5)->nodeValue;
- $dataset['affil'] = fărăPunctuație(trim(cuDiacriticeCorecte(substr($affil, 2))));
- $profiles[$iname] = $dataset;
- }
- $declarations = array();
- $html = file_get_contents('http://www.pmb.ro/institutii/declaratii_avere/d_avere_12_16_cgmb.php');
- $doc = new DOMDocument();
- $doc->loadHTML($html);
- $xpath = new DOMXpath($doc);
-
- $elements = $xpath->query("//table[@class='tabel']/tbody/tr[not(@class)]");
- foreach ($elements as $e)
- {
- $dataset = array();
- $iname = "";
- // Get row from person table
- $row = $xpath->query("td", $e);
- $res = $xpath->query("p", $row->item(0));
- if ($res->length)
- $name = $res->item(0)->nodeValue;
- else
- $name = $row->item(0)->nodeValue;
- $surname = fărăDiacritice(lcfirst(strtok($name, "– ")));
- if ($surname == 'alexandre') $surname = 'fontoura';
- if ($surname == 'popescu')
- {
- $comname = "";
- while ($r = strtok("– "))
- {
- $comname = lcfirst($r);
- }
- $iname = $comname.'-'.$surname;
- }
- else
- {
- foreach ($names as $name)
- if ($name[1] == $surname)
- $iname = $name[0].'-'.$name[1];
- if ($iname == "")
- continue;
- }
- // Start wealth
- $wstart = "";
- $res = $xpath->query("a", $row->item(1));
- if ($res->length)
- $wstart = $res->item(0)->getAttribute('href');
- $dataset['wstart'] = $wstart;
- // Start interests
- $istart = "";
- $res = $xpath->query("a", $row->item(2));
- if ($res->length)
- $istart = $res->item(0)->getAttribute('href');
- $dataset['istart'] = $istart;
- // 2012 wealth
- $w2012 = "";
- $res = $xpath->query("a", $row->item(3));
- if ($res->length)
- $w2012 = $res->item(0)->getAttribute('href');
- $dataset['w2012'] = $w2012;
- // 2012 interests
- $i2012 = "";
- $res = $xpath->query("a", $row->item(4));
- if ($res->length)
- $i2012 = $res->item(0)->getAttribute('href');
- $dataset['i2012'] = $i2012;
- $declarations[$iname] = $dataset;
- }
- foreach ($names as $n)
- {
- $in = $n[0].'-'.$n[1];
- $xml = '<?xml version="1.0" encoding="UTF-8"?>'.PHP_EOL;
- $xml .= '<xml>'.PHP_EOL;
- $xml .= cuEtichetă("comname", extragePrenumele($profiles[$in]['name']));
- $xml .= cuEtichetă("surname", extrageNumele($profiles[$in]['name']));
- $xml .= cuEtichetă("fullname", inverseazăNumele($profiles[$in]['name']));
- $xml .= cuEtichetă("birthdate", $profiles[$in]['date']);
- $xml .= cuEtichetă("birthplace", $profiles[$in]['place']);
- $xml .= cuEtichetă("occupation", $profiles[$in]['occup']);
- $xml .= cuEtichetă("profession", $profiles[$in]['prof']);
- $xml .= cuEtichetă("affiliation", $profiles[$in]['affil']);
- $xml .= '<declarations>'.PHP_EOL;
- $xml .= "<declaration type='wealth' year='2012' file='".$declarations[$in]['wstart']."' />".PHP_EOL;
- $xml .= "<declaration type='wealth' year='2013' file='".$declarations[$in]['w2012']."' />".PHP_EOL;
- $xml .= "<declaration type='interest' year='2012' file='".$declarations[$in]['istart']."' />".PHP_EOL;
- $xml .= "<declaration type='interest' year='2013' file='".$declarations[$in]['i2012']."' />".PHP_EOL;
- $xml .= '</declarations>'.PHP_EOL;
- $xml .= '</xml>'.PHP_EOL;
- $file = fopen('../profile/00-pmb/'.$n[0].'-'.$n[1].'.xml', "w");
- fwrite($file, $xml);
- fclose($file);
- }
- ?>
|