test /script/create_xml_3.11.php

Language PHP Lines 211
MD5 Hash 87f5b898d2f50119c5c48a63aae78b13
Repository https://github.com/lufyx/test.git View Raw File
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
<?php

include "fonctions.php";

// Date du jour
$laDate = date("ymd");

$loginDB = "apmobile";
$mdpDB = "ap2012";

$tabBases = file('mesBases_3.11.txt');
	
foreach ($tabBases as $lineNumber => $lineContent)
{
	$infoBase = explode("#", $lineContent);
	$nomDB = $infoBase[0];
	if ($nomDB != "grandparis")
	{
		if ($nomDB == "u2n")
		{
			$nomDB = $nomDB. "prod";
		}
		else
		{
			$nomDB = $nomDB. "dbprod";
		}
	}
	
	mysql_connect("192.168.3.11",$loginDB,$mdpDB) or die("Connexion impossible ŕ ".$nomDB);
	mysql_select_db($nomDB) or die("Echec de sélection de la base ".$nomDB);
	
	$reqRDP = mysql_query("SELECT DISTINCT entry_text_more FROM mt_entry WHERE entry_text_more LIKE '%" .$laDate. "'");
	
	while($ligneRDP = mysql_fetch_array($reqRDP))
	{
		$nbArticlesAll = 0;
		$nbArticlesAll2 = 0;
				
		$leFlux = new DOMDocument('1.0','UTF-8');
		$leFlux->formatOutput = true;
		
		$unEntryTextMore = $ligneRDP["entry_text_more"];
		$unRDP = utf8_encode(nomOnglet($nomDB, $unEntryTextMore));
		
		$noeudRdp = $leFlux->createElement('RDP');
		$noeudRdp = $leFlux->appendChild($noeudRdp);
		
		$reqCat = mysql_query("SELECT DISTINCT category_id, category_label FROM mt_entry JOIN mt_category ON entry_category_id = category_id WHERE entry_text_more = '" .$unEntryTextMore. "' ORDER BY category_description");
		
		$leFluxAll = new DOMDocument('1.0','UTF-8'); // Tous les articles
		$leFluxAll->formatOutput = true;
		
		$mesArticles = $leFluxAll->createElement('listeArticle');
		$mesArticles = $leFluxAll->appendChild($mesArticles);
		
		while($ligneCat = mysql_fetch_array($reqCat))
		{
			$nbArticles = 0;
			
			// XML des RDP
			$unIdCat = $ligneCat["category_id"];
			$uneCat = $ligneCat["category_label"];
			$typeCat = catAdmin($uneCat);
			
			$noeudCat = $leFlux->createElement('Category');
			$noeudCat = $noeudRdp->appendChild($noeudCat);
			$noeudCat->setAttribute("idCat",$unIdCat);
			$noeudCat->setAttribute("typeCat",$typeCat);
				$text = $leFlux->createTextNode(utf8_encode($uneCat));
				$text = $noeudCat->appendChild($text);
				
			$mesArts = $leFluxAll->createElement('Category');
			$mesArts = $mesArticles->appendChild($mesArts);
			$mesArts->setAttribute("nomCate",utf8_encode($uneCat));
			$mesArts->setAttribute("typeCat",$typeCat);
			$mesArts->setAttribute("idCat",$unIdCat);
			
			// XML des Cat
			$fluxCat = new DOMDocument('1.0','UTF-8');
			$fluxCat->formatOutput = true;
			$mesArt = $fluxCat->createElement('mesArt');
			$mesArt = $fluxCat->appendChild($mesArt);
				$mesArt->setAttribute("nomCate",utf8_encode($uneCat));
			
			$reqInfoArticle = mysql_query("SELECT * FROM mt_entry JOIN mt_author ON entry_author_id = author_id JOIN mt_placement ON entry_id = placement_entry_id WHERE entry_text_more = '" .$unEntryTextMore. "' AND entry_category_id = '" .$unIdCat. "' ORDER BY placement_norder");
			
			while($ligneInfoArticle = mysql_fetch_array($reqInfoArticle))
			{
				// XML d'un article
				$fluxArt = new DOMDocument('1.0','UTF-8');
				$fluxArt->formatOutput = true;
				
				$nbArticles = $nbArticles + 1;
				
				//On récup les infos
				$unIdArticle = $ligneInfoArticle["entry_id"];
				$uneDateArticle = $ligneInfoArticle["entry_modified_on"];
				$tabDate = explode(' ',$uneDateArticle);
				$unTitreArticle = utf8_encode($ligneInfoArticle["entry_title"]);
					$unTitreArticle = str_replace(chr(34),"",$unTitreArticle);
					$unTitreArticle = str_replace(chr(38),"",$unTitreArticle);
				$uneDescriptionArticle = utf8_encode($ligneInfoArticle["entry_text"]);
					$uneDescriptionArticle = str_replace(chr(23),"",$uneDescriptionArticle);
					$uneDescriptionArticle = str_replace(chr(13),"",$uneDescriptionArticle);
					$uneDescriptionArticle = str_replace(chr(38),"",$uneDescriptionArticle);
					$uneDescriptionArticle = str_replace(chr(60),"",$uneDescriptionArticle);
					$uneDescriptionArticle = str_replace(chr(62),"",$uneDescriptionArticle);
					$uneDescriptionArticle = str_replace(chr(31),"",$uneDescriptionArticle);
				$uneSourceArticle = utf8_encode($ligneInfoArticle["author_name"]);
					$uneSourceArticle = str_replace(chr(60),"",$uneSourceArticle);
					$uneSourceArticle = str_replace(chr(62),"",$uneSourceArticle);
				
				
				//XML Cat ALL
				$unArticle = $leFluxAll->createElement('Article');
				$unArticle = $mesArts->appendChild($unArticle);
				$unArticle->setAttribute("idArt",$unIdArticle);
				if ($uneDescriptionArticle != "")
				{
					$unArticle->setAttribute("typeArt","texte");
				}
				else
				{
					$unArticle->setAttribute("typeArt","pdf");
				}
				
				$unTitre = $leFluxAll->createElement("Titre");
				$unTitre = $unArticle->appendChild($unTitre);
					$text = $leFluxAll->createTextNode($unTitreArticle);
					$text = $unTitre->appendChild($text);
					
					$uneSource = $leFluxAll->createElement("Source");
					$uneSource = $unArticle->appendChild($uneSource);
					$text = $leFluxAll->createTextNode($uneSourceArticle);
					$text = $uneSource->appendChild($text);
					
					$uneDate = $leFluxAll->createElement("Date");
					$uneDate = $unArticle->appendChild($uneDate);
					$text = $leFluxAll->createTextNode($tabDate[0]);
					$text = $uneDate->appendChild($text);
					
				
				//XML des Cat
				$noeudCat2 = $fluxCat->createElement('Article');
				$noeudCat2 = $mesArt->appendChild($noeudCat2);
				$noeudCat2->setAttribute("idArt",$unIdArticle);
				if ($uneDescriptionArticle != "")
				{
					$noeudCat2->setAttribute("typeArt","texte");
				}
				else
				{
					$noeudCat2->setAttribute("typeArt","pdf");
				}
					
					$noeudCatTitre = $fluxCat->createElement('Titre');
					$noeudCatTitre = $noeudCat2->appendChild($noeudCatTitre);
						$text = $fluxCat->createTextNode($unTitreArticle);
						$text = $noeudCatTitre->appendChild($text);
						
					$noeudCatSrc = $fluxCat->createElement('Source');
					$noeudCatSrc = $noeudCat2->appendChild($noeudCatSrc);
						$text = $fluxCat->createTextNode($uneSourceArticle);
						$text = $noeudCatSrc->appendChild($text);
					
					$noeudCatDate = $fluxCat->createElement('Date');
					$noeudCatDate = $noeudCat2->appendChild($noeudCatDate);
						$text = $fluxCat->createTextNode($tabDate[0]);
						$text = $noeudCatDate->appendChild($text);
				
				if ($uneDescriptionArticle != "")
				{
					$noeudArt = $fluxArt->createElement('Article');
					$noeudArt = $fluxArt->appendChild($noeudArt);
					$noeudArt->setAttribute("idArt",$unIdArticle);
					
						$noeudArtTitre = $fluxArt->createElement('Titre');
						$noeudArtTitre = $noeudArt->appendChild($noeudArtTitre);
							$text = $fluxArt->createTextNode($unTitreArticle);
							$text = $noeudArtTitre->appendChild($text);
							
							$noeudArtDesc = $fluxArt->createElement('Description');
							$noeudArtDesc = $noeudArt->appendChild($noeudArtDesc);
								$text = $fluxArt->createTextNode($uneDescriptionArticle);
								$text = $noeudArtDesc->appendChild($text);
							
								$noeudArtSrc = $fluxArt->createElement('Source');
								$noeudArtSrc = $noeudArt->appendChild($noeudArtSrc);
									$text = $fluxArt->createTextNode($uneSourceArticle);
									$text = $noeudArtSrc->appendChild($text);
							
					$fluxArt->save("../data/" .$nomDB. "_" .$unRDP. "_" .$unIdCat. "_" .$unIdArticle. ".xml");
				}
			}
			
			$noeudCat->setAttribute("nbArt",$nbArticles);
			$mesArts->setAttribute("nbArt",$nbArticles);
			$mesArt->setAttribute("nbArt",$nbArticles);
			
			$fluxCat->save("../data/" .$nomDB. "_" .$unRDP. "_" .$unIdCat. ".xml");
			echo "../data/" .$nomDB. "_" .$unRDP. "_" .$unIdCat. ".xml";
		}
		
		$leFluxAll->save("../data/".$nomDB."_".$unRDP."_all.xml");
		$leFlux->save("../data/".$nomDB. "_" .$unRDP. ".xml");
	}
}

mysql_close();
?>
Back to Top