noalyss Version-10
NOALYSS : serveur de comptabilité et ERP (2002)
Loading...
Searching...
No Matches
ajax_search_peppol.php
Go to the documentation of this file.
1<?php
2/*
3 * This file is part of NOALYSS.
4 *
5 * PhpCompta is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * NOALYSS is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with PhpCompta; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19// Copyright (2016) Author Dany De Bontridder <dany@alchimerys.be>
20
21if (!defined('ALLOWED'))
22 die('Appel direct ne sont pas permis');
23
24/**
25 * @file
26 * @brief search Peppol ID.
27 *
28 * Parameters :
29 * - query : string to search
30 * - ctl : DOMID to udpate (useless)
31 * - filter: query on name , VAT id or Enterprise ID
32 */
34try {
35 /* @var $query (string) string to search */
36 $query = $http->request('query', 'string', '');
37
38 /* @$ctl_id (string) DOM ID of the element to update */
39 $ctl_id = $http->request('ctl', 'string');
40
41 /* @filter (string) search on name, VAT ID or enterprise ID */
42 $filter = $http->request('filter', 'string', '');
43} catch (Exception $e) {
44 echo $e->getMessage();
45 return;
46}
47
48/**
49 * @class
50 * @brief Found PEPPOL Elements, inner class
51 */
53{
54
56 var array $docTypeID;
58}
59
70 var $type;
71 var $name;
72 var $phone;
73 var $email;
74
75}
76$msg = _("La recherche par nom et numéro de TVA sont limitées à la Belgique");
77
78echo \HtmlInput::title_box(_("Recherche PEPPOL Directory"), 'peppol_id_search_div');
79?>
80<div class="content">
81<form method="GET" id="peppol_id_search_div_frm" onsubmit="category_card.display_search_peppol('<?= $ctl_id ?>');return false;">
82 <p class="text-muted">
83 <?= $msg ?>
84 </p>
85 <?php
86 echo \HtmlInput::hidden("op", "search_peppol");
87 echo \HtmlInput::hidden("ctl_id", $ctl_id);
88
89 $input_query = new IText("query", $query);
90 $select_filter = new ISelect("filter");
91 $select_filter->transform(["vatid" => _("Numéro de TVA")
92 , "entid" => _("Numéro entreprise")
93 , "peppolid" => _("Endpoint (PEPPOL ID)")
94 , "name" => _("Nom")
95 ]);
97 ?>
98<?= $select_filter->input() ?>
99 <?= $input_query->input() ?>
100 <ul class="aligned-block">
101 <li>
102 <?php
103 echo \HtmlInput::submit("search", _("Chercher"));
104 ?>
105 </li>
106 <li>
107 <?php
108 echo \HtmlInput::button_close('peppol_id_search_div');
109 ?>
110 </li>
111 </ul>
112</form>
113<?php
114if (trim($query) == '' || $filter=='')
115{
116 echo '</div>'; // div class content
117 return;
118}
119//------------------------------------------------
120// if a query has been submitted, show the result
121//------------------------------------------------
122$search = null;
123switch ($filter)
124{
125 case 'name':
126 $search = http_build_query(["name" => $query, 'countryCode' => 'BE']);
127 break;
128 case "vatid":
129 if (stripos("x" . $query, "BE") == 0)
130 {
131 print _("Numéro de TVA invalide: doit commencer par BE");
132 break;
133 }
134 $search = http_build_query(["participant" => 'iso6523-actorid-upis::9925:' . $query]);
135 break;
136 case 'entid':
137 if (strlen(trim($query ?? "")) != 10)
138 {
139 print _("Numéro entreprise belge valide: 10 chiffres");
140 break;
141 }
142 $search = http_build_query(["participant" => 'iso6523-actorid-upis::0208:' . $query]);
143 break;
144 case 'peppolid':
145 $search = http_build_query(["participant" => 'iso6523-actorid-upis::' . $query]);
146 break;
147 default:
148 throw new \Exception("ASP129 unknown filter",129);
149}
150try {
151 $curl = curl_init("https://directory.peppol.eu/search/1.0/xml?{$search}");
152 curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
153
154 $str = curl_exec($curl);
155 if ( curl_errno($curl) != 0 ) {
156 $info = "AJX147 connexion fails";
157 if ($curl != null)
158 {
159 $info = curl_error($curl) . "\n----\n";
160 $info .= var_export(curl_getinfo($curl), true);
161 }
162 throw new \Exception($info,147);
163 }
164
165 curl_close($curl);
166} catch (\Exception $e) {
168 echo p(_("Vérification impossible"));
169 return;
170}
171
173$xml->loadXML($str);
174file_put_contents("/tmp/alchimerys.xml",$xml->saveXML());
175$root = $xml->getElementsByTagName("resultlist");
176if (count($root) == 0)
177{
178 echo span(_("Aucun résultat"),' class="notice" ');
179 echo '</div>'; // div class content
180 return ;
181} else
182{
183 printf(_("Résultat %d"), $root[0]->getAttribute("total-result-count"));
184}
185
186$a_match = $xml->getElementsByTagName("match");
188
189$result=array();
190for ($i = 0; $i < $nb_match; $i++)
191{
192 $node = $a_match->item($i);
194 for ($e = 0; $e < $node->childElementCount; $e++)
195 {
196 if ($node->childNodes->item($e)->nodeType != XML_ELEMENT_NODE)
197 {
198 continue;
199 }
200 if ($node->childNodes->item($e)->tagName == 'participantID')
201 {
202 $obj->participantID = $node->childNodes->item($e)->textContent;
203 } elseif ($node->childNodes->item($e)->tagName == 'docTypeID')
204 {
205 $obj->docTypeID[] = $node->childNodes->item($e)->textContent;
206 } elseif ($node->childNodes->item($e)->tagName == 'entity')
207 {
208 $obj->entity = new PEPPOL_Entity_Record();
209 $obj->entity->contact=array();
210 $obj->entity->website=array();
211 for ($f=0;$f< $node->childNodes->item($e)->childElementCount;$f++)
212 {
213 if ( $node->childNodes->item($e)->childNodes->item($f)->tagName == 'name')
214 $obj->entity->name=$node->childNodes->item($e)->childNodes->item($f)->textContent;
215 if ($node->childNodes->item($e)->childNodes->item($f)->tagName=='countryCode')
216 $obj->entity->countryCode=$node->childNodes->item($e)->childNodes->item($f)->textContent;
217 if ($node->childNodes->item($e)->childNodes->item($f)->tagName=='regDate')
218 $obj->entity->regDate=$node->childNodes->item($e)->childNodes->item($f)->textContent;
219 if ($node->childNodes->item($e)->childNodes->item($f)->tagName=='additionalInfo')
220 $obj->entity->additionalInfo=$node->childNodes->item($e)->childNodes->item($f)->textContent;
221 if ($node->childNodes->item($e)->childNodes->item($f)->tagName=='additionalInfo')
222 $obj->entity->additionalInfo=$node->childNodes->item($e)->childNodes->item($f)->textContent;
223 if ($node->childNodes->item($e)->childNodes->item($f)->tagName=='website')
224 $obj->entity->website[]=$node->childNodes->item($e)->childNodes->item($f)->textContent;
225 if ($node->childNodes->item($e)->childNodes->item($f)->tagName=='contact')
226 { $a=array();
227 $a['type']=$node->childNodes->item($e)->childNodes->item($f)->getAttribute("type");
228 $a['name']=$node->childNodes->item($e)->childNodes->item($f)->getAttribute("name");
229 $a['phone']=$node->childNodes->item($e)->childNodes->item($f)->getAttribute("phone");
230 $a['email']=$node->childNodes->item($e)->childNodes->item($f)->getAttribute("email");
231
232 $obj->entity->contact[]=$a;
233 }
234 }
235
236 }
237 }
238 if ($obj->participantID != null) $result[]=clone $obj;
239
240}
241if (empty($result))
242{
243 echo span(_("Aucun résultat"),' class="notice" ');
244 return;
245}
246
247//------------------------------------------------
248// display result
249//------------------------------------------------
251?>
252
253<?php
254for ($i=0;$i < $nb_result;$i++)
255{
256 $str_url="";
257 $nb_website=count ($result[$i]->entity->website);
258
259 ($result[$i]->entity->website != "") ? :"";
260?>
261<div style="display:flex;align-content: space-evenly">
262<div style="width:20rem;">
263 <a href="javascript:void(0)" onclick="$('<?=$ctl?>').value='<?=$result[$i]->participantID?>';removeDiv('peppol_id_search_div')">
264 <?=$result[$i]->participantID?>
265 </a>
266</div>
267<div>
268 <?=$result[$i]->entity->name?>
269 (<?=$result[$i]->entity->countryCode?>)
270</div>
271
272
273</div>
274 <div style="display:flex;align-content: space-evenly;gap:1rem">
275 <div style="display:flex;flex-direction:column">
276 <b> website :</b>
277 <?php if ( $nb_website != 0)
278 {
279 for ($x=0;$x < $nb_website;$x++ ) {
280 $str_url.=sprintf('<div><a href="%s" target="_blank" class="line">%s</a></div>',$result[$i]->entity->website[$x],$result[$i]->entity->website[$x]);
281 }
282 }
283 ?>
284 <?=$str_url?>
285</div>
286<div style="display:flex;flex-direction:column">
287 <b>contact : </b>
288 <?php
289 $nb_contact=count($result[$i]->entity->contact);
290 for ($h=0;$h< $nb_contact;$h++) {
291 $email=mailTo($result[$i]->entity->contact[$h]['email']);
292 ?>
293 <div>
294 <?=$result[$i]->entity->contact[$h]['type']?>
295 <?=$result[$i]->entity->contact[$h]['name']?>
296 <?=$result[$i]->entity->contact[$h]['phone']?>
297 <?=$email?>
298 </div>
299 <?php
300 } // LOOP h : for ($h=0;$h< $nb_contact;$h++) {
301 ?>
302</div>
303<div>
304 <b>Info:</b>
305 <?=$result[$i]->entity->additionalInfo?>
306</div>
307 </div>
308<?php
309} // end for ($i)
310echo '</div>'; // div class content
311?>
312
mailTo($p_email)
compose a HTML string with email
span($p_string, $p_extra='')
Definition ac_common.php:43
p($p_string, $p_extra='')
Definition ac_common.php:39
record_log($p_message)
Record an error message into the log file of the server or in the log folder of NOALYSS Record also t...
switch($op2) $xml
catch(Exception $e) $obj
$opd_description style
for( $i=0;$i< $nb_match;$i++) if(empty($result)) $nb_result
if(trim($query)==''|| $filter=='') $search
_("actif, passif,charge,...")
manage the http input (get , post, request) and extract from an array
Html Input , create a tag <SELECT> ... </SELECT> if readonly == true then display the label correspon...
Html Input Text member :
Found PEPPOL Elements, inner class.
Class contact (customer, supplier...)
print
Type of printing.
if( $delta< 0) elseif( $delta==0)
$str_url