generează-prima-pagină.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <?php
  2. /**
  3. * File name:
  4. *
  5. *
  6. * (C) Copyright 2013 Friedrich-Ebert-Stiftung (http://fes.ro)
  7. * Author: Tiberiu C. Turbureanu (tct@ceata.org)
  8. *
  9. * This file is part of the project funded by FES
  10. *
  11. * This is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU Affero General Public License as published by
  13. * the Free Software Foundation; either version 3 of the License, or
  14. * (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU Affero General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU Affero General Public License
  22. * along with this program; if not, write to the Free Software
  23. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  24. */
  25. require_once 'utile.php';
  26. // Load the list of persons
  27. $xml = new DOMDocument();
  28. $xml->load('../20131013-consilieri.xml');
  29. $xpath = new DOMXpath($xml);
  30. $persons = $xpath->query("/xml/person");
  31. // Load template for profiles
  32. $tpl = file_get_contents('../șabloane/prima.tpl');
  33. $psd = $pdl = $ppdd = $pc = $pnl = "";
  34. $fem = "";
  35. $psdN = $pdlN = $ppddN = $pcN = $pnlN = 0;
  36. $femN = 0;
  37. foreach($persons as $person)
  38. {
  39. $comname = $xpath->query("comname", $person)->item(0)->nodeValue;
  40. $surname = $xpath->query("surname", $person)->item(0)->nodeValue;
  41. $iname = $comname.'-'.$surname;
  42. $comnamep = $xpath->query("comnamep", $person)->item(0)->nodeValue;
  43. $surnamep = $xpath->query("surnamep", $person)->item(0)->nodeValue;
  44. $shortname = $comnamep.' '.$surnamep;
  45. $xmla = new DOMDocument();
  46. $xmla->load('../profile/'.$iname.'.xml');
  47. $xpatha = new DOMXpath($xmla);
  48. $party = $xpatha->query("/xml/party")->item(0)->nodeValue;
  49. $sex = $xpatha->query("/xml/sex")->item(0)->nodeValue;
  50. $image = '/imagini/01-embleme/'.$iname.'.jpg';
  51. $placeholder = '/imagini/naught101-ProfilePlaceholderSuit-emblema.png';
  52. if (!file_exists('..'.$image))
  53. $image = $placeholder;
  54. $img = '<img class="emblemă" src="'.$image.'" />';
  55. $ftag = $tag = $img.'<a href="/consilieri/'.$iname.'.html">'.$shortname.'</a>';
  56. $ftag .= ' ('.$party.')';
  57. $ftag = cuEtichetă("li", $ftag);
  58. $tag = cuEtichetă("li", $tag);
  59. if ($party == "PSD")
  60. {
  61. $psd .= $tag;
  62. $psdN++;
  63. }
  64. else if ($party == "PNL")
  65. {
  66. $pnl .= $tag;
  67. $pnlN++;
  68. }
  69. else if ($party == "PDL")
  70. {
  71. $pdl .= $tag;
  72. $pdlN++;
  73. }
  74. else if ($party == "PPDD")
  75. {
  76. $ppdd .= $tag;
  77. $ppddN++;
  78. }
  79. else if ($party == "PC")
  80. {
  81. $pc .= $tag;
  82. $pcN++;
  83. }
  84. if ($sex == "F")
  85. {
  86. $fem .= $ftag;
  87. $femN++;
  88. }
  89. }
  90. // Load template for main page
  91. $tpl = file_get_contents("../șabloane/prima.tpl");
  92. $tpl = str_replace("<!-- psd -->", $psd, $tpl);
  93. $tpl = str_replace("<!-- pdl -->", $pdl, $tpl);
  94. $tpl = str_replace("<!-- ppdd -->", $ppdd, $tpl);
  95. $tpl = str_replace("<!-- pc -->", $pc, $tpl);
  96. $tpl = str_replace("<!-- pnl -->", $pnl, $tpl);
  97. $tpl = str_replace("<!-- fem -->", $fem, $tpl);
  98. $tpl = str_replace("<!-- psdN -->", $psdN, $tpl);
  99. $tpl = str_replace("<!-- pdlN -->", $pdlN, $tpl);
  100. $tpl = str_replace("<!-- ppddN -->", $ppddN, $tpl);
  101. $tpl = str_replace("<!-- pcN -->", $pcN, $tpl);
  102. $tpl = str_replace("<!-- pnlN -->", $pnlN, $tpl);
  103. $tpl = str_replace("<!-- femN -->", $femN, $tpl);
  104. $file = fopen("../consilieri/prima.html", "w");
  105. fwrite($file, $tpl);
  106. fclose($file);
  107. ?>