PageRenderTime 39ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/class.xmodtif.inc

https://github.com/jcplat/console-seolan
PHP | 2176 lines | 1984 code | 79 blank | 113 comment | 402 complexity | eebb76002582b2a3971ed6957c3c1918 MD5 | raw file
Possible License(s): LGPL-2.0, LGPL-2.1, GPL-3.0, Apache-2.0, BSD-3-Clause
  1. <?php
  2. class XModTif extends XModTable{
  3. public $submodmax=20;
  4. public $oiddc; // oid de la ressource en cours
  5. public $NSURI; // NS principal des XML TiF
  6. public $prefixSQL; // Prefix SQL sur les tables du module (TiF1_, TiF2_ ...)
  7. public $alreadyexport=array();
  8. public $structparam=array(); // Paramètres sur la structure des granules => renseigner dans prepareParam
  9. public $idlist=array();
  10. public $acttype=''; // Indique le type d'import en cours (ACVS, GITD...)
  11. public $tzrns='';
  12. private $_cache=array(); // Cache du module
  13. public $TiFTables=array("CAPAGLOB","DMULTIMEDIA","DCONTACT","DADRESSE","DPERSONNE","DMOYENCOM","INFOLEG","DCLASSEMENT","DGEOLOC","ZONES",
  14. "DPOINT","DCOOR","DENV","DCARTE","DACCES","DPERIODE","DDATE","DJOURS","JOURS","HORAIRES","DCLIENTELES","DCLIENT",
  15. "USAGE","DMODERESA","CAPACAPA","CAPASUP","DCAPAPREST","DCAPAUNIT","DDISP","DOFFREPRESTA","DPRESTA","DTARIF",
  16. "DDESCRCOMP","DITI","DPLANNING","DPRESTAPLA","JOURPLA","PRESTLIEE");
  17. public $withCodeAttr=array('table' => array('DC'),
  18. 'target' => array('LS_Communes','LS_ZoneNoms','LS_Pays'));
  19. // Propriétés ACVS
  20. public $ACVSUrl='http://www.acvsnet.net/SI-ACVS/WebServices';
  21. public $ACVSFile='ACVSWebServices.asmx';
  22. public $ACVSFileWSDL='ACVSWebServices.asmx?WSDL';
  23. public $ACVSNSUri='http://www.acvsnet.net/tif3acvs/';
  24. public $ACVSEnvUris='xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"';
  25. public $ACVSLogin;
  26. public $ACVSPwd;
  27. public $ACVSFilter;
  28. // Propriétés GITD
  29. public $GITDUrl='http://extranet.hautes-alpes.net/publication?WSDL';
  30. public $GITDUrlDomain='http://webservice.hautes-alpes.net';
  31. public $GITDLogin;
  32. public $GITDPwd;
  33. public $GITDFilter;
  34. // Propriétés SITRA
  35. public $SITRANSUri='';
  36. public $SITRADirs='';
  37. public $SITRAExportFileRegex='/^\([0-9]+\)_ListeOI_([a-z]+)_([0-9]{8}_[0-9]{6})\.xml$/i';
  38. public $SITRADelFileRegex='/^\([0-9]+\)_DEL_ListeOI_([0-9]{8}_[0-9]{6})\.xml$/i';
  39. public $SITRAImagesFileRegex='/^\([0-9]+\)_ImagesOI_([0-9]{8}_[0-9]{6})\.zip$/i';
  40. public $SITRASelectionsFileRegex='/^\([0-9]+\)_Selections_([0-9]{8}_[0-9]{6})\.xml$/i';
  41. function __construct($ar=NULL){
  42. parent::__construct($ar);
  43. if(in_array('ACVS',$this->type)) $this->TiFTables[]="MODESPAIEMENT";
  44. }
  45. /// securite des fonctions accessibles par le web
  46. function secGroups($function, $group=NULL) {
  47. $g=array();
  48. $g['importNomenclature']=array('admin');
  49. $g['ACVSImport']=array('rwv','admin','none');
  50. $g['GITDImport']=array('rwv','admin','none');
  51. $g['GITDCheckService']=array('none');
  52. $g['SITRAImport']=array('rwv','admin','none');
  53. $g['exportTiF']=array('rwv','admin','none');
  54. if(isset($g[$function])) {
  55. if(!empty($group)) return in_array($group, $g[$function]);
  56. return $g[$function];
  57. }
  58. return parent::secGroups($function,$group);
  59. }
  60. public function initOptions() {
  61. parent::initOptions();
  62. $this->_options->setOpt('Prefix SQL des tables', 'prefixSQL', 'text');
  63. $this->_options->setOpt('Type de la structure', 'type', 'multiplelist', array('values' => array('','ACVS','GITD','SITRA'),
  64. 'labels' => array('---','ACVS','GITD','SITRA')));
  65. $this->_options->setOpt('ACVS : Login', 'ACVSLogin', 'text');
  66. $this->_options->setOpt('ACVS : Password', 'ACVSPwd', 'text');
  67. $this->_options->setOpt('ACVS : Filtre', 'ACVSFilter', 'text', array('rows' => 6,'cols' => 80));
  68. $this->_options->setOpt('GITD : Login', 'GITDLogin', 'text');
  69. $this->_options->setOpt('GITD : Password', 'GITDPwd', 'text');
  70. $this->_options->setOpt('GITD : Filtre', 'GITDFilter', 'text', array('rows' => 6,'cols' => 80));
  71. $this->_options->setOpt('SITRA : Répertoires', 'SITRADirs', 'text', array('rows' => 6,'cols' => 80));
  72. }
  73. protected function _actionlist(&$my) {
  74. parent::_actionlist($my);
  75. $myclass=get_class($this);
  76. $moid=$this->_moid;
  77. $o1=new XModuleAction($this,'deletewithtable',XLabels::getSysLabel('xmodtif','deletewithtable','text'),
  78. 'class='.$myclass.'&moid='.$moid.'&_function=delete&template=proc.html&withtable=1');
  79. $o1->needsconfirm=true;
  80. $my['deletewithtable']=$o1;
  81. }
  82. /// Suppression de tous les modules lié à TiF
  83. function delete($ar){
  84. global $XSHELL;
  85. $p=new XParam($ar,array('tplentry' => ''));
  86. $withtable=$p->get('withtable');
  87. if(!empty($withtable)){
  88. $tplentry=$p->get('tplentry');
  89. $message=parent::delete(array('tplentry' => TZR_RETURN_DATA));
  90. $rs=selectQuery('select MOID from MODULES where MPARAM like "%<field name=\"table\" type=\"%\"><value>'.
  91. '<![CDATA['.$this->prefixSQL.'%]]></value></field>%" order by MOID');
  92. while($rs && ($ors=$rs->fetch())){
  93. $mod=XModule::objectFactory($ors['MOID']);
  94. $message.=$mod->delete(array('tplentry'=>TZR_RETURN_DATA));
  95. }
  96. $rs=selectQuery('select BTAB from BASEBASE where BTAB LIKE "'.$this->prefixSQL.'LS_%"');
  97. while($rs && ($ors=$rs->fetch())){
  98. $xbase=XDataSource::objectFactoryHelper8('BCLASS=XDSTable&SPECS='.$ors['BTAB']);
  99. $ret=$xbase->procDeleteDataSource(array('tplentry' => TZR_RETURN_DATA));
  100. $message.=$ret['message'];
  101. }
  102. return XShell::toScreen2($tplentry,'message',$message);
  103. }else{
  104. return parent::delete($ar);
  105. }
  106. }
  107. /// Efface toutes les fiches liés à la ressource
  108. function del($ar) {
  109. $p=new XParam($ar,array());
  110. $oid=$p->get('_selected');
  111. $selectedok=$p->get('_selectedok');
  112. if(($selectedok!='ok') || empty($oid)) $oid=$p->get('oid');
  113. if(!is_array($oid)) $oid=array($oid => 1);
  114. if(!empty($oid)){
  115. $oid=array_keys($oid);
  116. $oid_list = '"'.implode('","',$oid).'"';
  117. foreach($this->TiFTables as $table) {
  118. updateQuery('delete from '.$this->prefixSQL.$table.' where tzr_dc in ('.$oid_list.')');
  119. }
  120. updateQuery('delete from '.$this->xset->getTable().' where KOID in ('.$oid_list.')');
  121. }
  122. }
  123. /// Prepare les paramètres des différents granules pour l'import/export
  124. function prepareParam(){
  125. if(empty($this->_cache['gparam-'.$this->acttype])){
  126. $gparam=array();
  127. //--- DC
  128. $gparam['dc']=array(
  129. 'DC' => array(
  130. 'balisegroup' => NULL,
  131. 'balises' => array(
  132. 'DublinCore' => array(
  133. 'table' => 'DC','delNS' => false,'oidfield' => 'dc:identifier',
  134. 'updfield' => 'dcterms:modified',
  135. 'ar' => array('tzr_type' => $this->acttype),
  136. 'notexport' => array('ModePaiement','ObservationModePaiement',
  137. 'ObservationModePaiement',
  138. 'CapacitesGlobales')))));
  139. //--- Multimedia
  140. $gparam['mu']=array('MU' => array('balisegroup' => 'Multimedia',
  141. 'balises' => array('DetailMultimedia' => array('table' => 'DMULTIMEDIA','fssm' => 'tzr_lie',
  142. 'notexport' => array('URL_url','URL_img')))));
  143. //--- Contact
  144. $param=array('MC' => array('balisegroup' => 'MoyensCommunications',
  145. 'balises' => array('DetailMoyenCom' => array('table' => 'DMOYENCOM','fssm' => 'tzr_lie'))));
  146. $param=array('PE' => array('balisegroup' => 'Personnes',
  147. 'balises' => array('DetailPersonne' => array('table' => 'DPERSONNE','fssm' => 'tzr_lie','ssm' => $param))));
  148. $param=array('AD' => array('balisegroup' => 'Adresses',
  149. 'balises' => array('DetailAdresse' => array('table' => 'DADRESSE','fssm' => 'tzr_lie','ssm' => $param))));
  150. $gparam['co']=array('CO' => array('balisegroup' => 'Contacts',
  151. 'balises' => array('DetailContact' => array('table' => 'DCONTACT','fssm' => 'tzr_lie','ssm' => $param))));
  152. $param=array('CT' => array('balisegroup' => 'Contact',
  153. 'balises' => array('DetailContact' => array('table' => 'DCONTACT','fssm' => 'tzr_lie','ssm' => $param))));
  154. $gparam['sg']=array('SG' => array('balisegroup' => NULL,
  155. 'balises' => array('StructureGestion' => array('table' => 'STRGESTION','fssm' => 'tzr_lie','ssm' => $param))));
  156. $gparam['si']=array('SI' => array('balisegroup' => NULL,
  157. 'balises' => array('StructureInformation' => array('table' => 'STRINFO','fssm' => 'tzr_lie','ssm' => $param))));
  158. //--- Informations légales
  159. $gparam['il']=array('IL' => array('balisegroup' => NULL,
  160. 'balises' => array('InformationsLegales' => array('table' => 'INFOLEG','fssm' => 'tzr_lie'))));
  161. //--- Classement
  162. $gparam['cl']=array('Classement' => array('balisegroup' => 'Classements',
  163. 'balises' => array('DetailClassement' => array('table' => 'DCLASSEMENT','fssm' => 'tzr_lie'))));
  164. //--- Geoloc
  165. $param=array('CO' => array('balisegroup' => 'Coordonnees',
  166. 'balises' => array('DetailCoordonnees' => array('table' => 'DCOOR','fssm' => 'tzr_lie'))),
  167. 'EN' => array('balisegroup' => 'Environnements',
  168. 'balises' => array('DetailEnvironnement' => array('table' => 'DENV','fssm' => 'tzr_lie'))),
  169. 'CA' => array('balisegroup' => 'Cartes',
  170. 'balises' => array('DetailCarte' => array('table' => 'DCARTE','fssm' => 'tzr_lie'))),
  171. 'AC' => array('balisegroup' => 'Acces',
  172. 'balises' => array('DetailAcces' => array('table' => 'DACCES','fssm' => 'tzr_lie'))),
  173. 'MU' => array('balisegroup' => 'Multimedia',
  174. 'balises' => array('DetailMultimedia' => array('table' => 'DMULTIMEDIA','fssm' => 'tzr_lie',
  175. 'ar' => array('tzr_ispoint' => 1)))));
  176. $param=array('PO' => array('balisegroup' => 'Points',
  177. 'balises' => array('DetailPoint' => array('table' => 'DPOINT','fssm' => 'tzr_lie','ssm' => $param))));
  178. $param=array('ZO' => array('balisegroup' => NULL,
  179. 'balises' => array('Zone' => array('table' => 'ZONES','fssm' => 'tzr_lie','ssm' => $param))));
  180. $gparam['ge']=array('GE' => array('balisegroup' => 'Geolocalisations',
  181. 'balises' => array('DetailGeolocalisation' => array('table' => 'DGEOLOC','fssm' => 'tzr_lie',
  182. 'ssm' => $param))));
  183. //--- Periode
  184. $param=array('HO' => array('balisegroup' => NULL,
  185. 'balises' => array('Horaires' => array('table' => 'HORAIRES','fssm' => 'tzr_lie'))));
  186. $param=array('JO' => array('balisegroup' => NULL,
  187. 'balises' => array('Jour' => array('table' => 'JOURS','fssm' => 'tzr_lie','ssm' => $param))));
  188. $param=array('DJ' => array('balisegroup' => 'Jours',
  189. 'balises' => array('DetailJours' => array('table' => 'DJOURS','fssm' => 'tzr_lie','ssm' => $param))));
  190. $param=array('DA' => array('balisegroup' => 'Dates',
  191. 'balises' => array('DetailDates' => array('table' => 'DDATE','fssm' => 'tzr_lie','ssm' => $param))));
  192. $gparam['pe']=array('PE' => array('balisegroup' => 'Periodes',
  193. 'balises' => array('DetailPeriode' => array('table' => 'DPERIODE','fssm' => 'tzr_lie','ssm' => $param))));
  194. //--- Clientele
  195. $param=array('DC' => array('balisegroup' => NULL,
  196. 'balises' => array('DetailClient' => array('table' => 'DCLIENT','fssm' => 'tzr_lie'))));
  197. $gparam['cli']=array('CL' => array('balisegroup' => 'Clienteles',
  198. 'balises' => array('DetailClienteles' => array('table' => 'DCLIENTELES','fssm' => 'tzr_lie',
  199. 'ssm' => $param))));
  200. //--- Langues
  201. $gparam['la']=array('LA' => array('balisegroup' => 'Langues',
  202. 'balises' => array('Usage' => array('table' => 'USAGE','fssm' => 'tzr_lie'),
  203. 'ListeLangues' => array('table' => 'LISTELANGUES','fssm' => 'tzr_lie'))));
  204. //--- Mode resa
  205. $gparam['mr']=array('MO' => array('balisegroup' => 'ModesReservations',
  206. 'balises' => array('DetailModeReservation' => array('table' => 'DMODERESA','fssm' => 'tzr_lie',
  207. 'ssm' => $gparam['co']))));
  208. //--- Capacité sup
  209. $gparam['cs']=array('CS' => array('balisegroup' => NULL,
  210. 'balises' => array('Capacite' => array('table' => 'CAPACAPA','fssm' => 'tzr_lie','direct' => true),
  211. 'Superficie' => array('table' => 'CAPASUP','fssm' => 'tzr_lie','direct' => true))));
  212. //--- Capacité presta
  213. $gparam['cp']=array('CP' => array('balisegroup' => 'CapacitesPrestations',
  214. 'balises' => array('DetailCapacitePrestation' => array('table' => 'DCAPAPREST','fssm' => 'tzr_lie',
  215. 'ssm' => $gparam['cs']))));
  216. //--- Capacité unité
  217. $param=array('DD' => array('balisegroup' => 'Dispositions',
  218. 'balises' => array('DetailDisposition' => array('table' => 'DDISP','fssm' => 'tzr_lie'))));
  219. $gparam['cu']=array('CU' => array('balisegroup' => 'CapacitesUnites',
  220. 'balises' => array('DetailCapaciteUnite' => array('table' => 'DCAPAUNIT','fssm' => 'tzr_lie',
  221. 'ssm' => $param))));
  222. //--- Offre presta
  223. $oparamcu=$gparam['cu'];
  224. $oparamcp=$gparam['cp'];
  225. $oparamcp['CP']['balisegroup']=$oparamcu['CU']['balisegroup']=NULL;
  226. $oparamcp['CP']['balises']['DetailCapacitePrestation']['ar']=$oparamcu['CU']['balises']['DetailCapaciteUnite']['ar']=
  227. array('tzr_ispresta' => 1);
  228. $param=array('PR' => array('balisegroup' => NULL,
  229. 'balises' => array('DetailPrestation' => array('table' => 'DPRESTA','fssm' => 'tzr_lie','ssm' => $gparam['mr'],
  230. 'linkparam' => array('DetailCapaciteUnite' => $oparamcu,
  231. 'DetailCapacitePrestation' => $oparamcp)))));
  232. $gparam['op']=array('OP' => array('balisegroup' => 'OffresPrestations',
  233. 'balises' => array('DetailOffrePrestation' => array('table' => 'DOFFREPRESTA','fssm' => 'tzr_lie',
  234. 'ssm' => $param))));
  235. //--- Tarif
  236. $oparamcl=$gparam['cli']['CL']['balises']['DetailClienteles']['ssm'];
  237. $oparampr=$gparam['op']['OP']['balises']['DetailOffrePrestation']['ssm'];
  238. $oparampe=$gparam['pe'];
  239. $oparampe['PE']['balisegroup']=$oparampr['PR']['balisegroup']=$oparamcl['DC']['balisegroup']=NULL;
  240. $oparampe['PE']['balises']['DetailPeriode']['ar']=$oparampr['PR']['balises']['DetailPrestation']['ar']=
  241. $oparamcl['DC']['balises']['DetailClient']['ar']=array('tzr_istarif' => 1);
  242. $oparampe['PE']['balises']['DetailPeriode']['fssm']=$oparampr['PR']['balises']['DetailPrestation']['fssm']=
  243. $oparamcl['DC']['balises']['DetailClient']['fssm']=NULL;
  244. $gparam['ta']=array('TA' => array('balisegroup' => 'DetailTarifs',
  245. 'balises' => array('DetailTarif' => array('table' => 'DTARIF','fssm' => 'tzr_lie',
  246. 'linkparam' => array('DetailClient' => $oparamcl,
  247. 'DetailPrestation' => $oparampr,
  248. 'DetailPeriode' => $oparampe)))));
  249. //--- Descr comp
  250. $gparam['desc']=array('DE' => array('balisegroup' => 'DescriptionsComplementaires',
  251. 'balises' => array('DetailDescriptionComplementaire' => array('table' => 'DDESCRCOMP',
  252. 'fssm' => 'tzr_lie'))));
  253. //--- Itinieraire
  254. $oparamzo=$gparam['ge']['GE']['balises']['DetailGeolocalisation']['ssm'];
  255. $oparamzo['ZO']['balisegroup']=NULL;
  256. $oparamzo['ZO']['balises']['Zone']['ar']=array('tzr_isiti' => 1);
  257. $gparam['it']=array('IT' => array('balisegroup' => 'Itineraires',
  258. 'balises' => array('DetailItineraire' => array('table' => 'DITI','fssm' => 'tzr_lie',
  259. 'linkparam' => array('Zone' => $oparamzo)))));;
  260. //--- Planning
  261. $param=array('JP' => array('balisegroup' => NULL,
  262. 'balises' => array('JourPlanning' => array('table' => 'JOURPLA','fssm' => 'tzr_lie'))));
  263. $oparampr['PR']['balises']['DetailPrestation']['ar']=array('tzr_isprestapla' => 1);
  264. $param=array('PP' => array('balisegroup' => 'PrestationsPlanning',
  265. 'balises' => array('DetailPrestationPlanning' => array('table' => 'DPRESTAPLA','fssm' => 'tzr_lie',
  266. 'ssm' => $param,
  267. 'linkparam' => array('DetailPrestation' => $oparampr)))));
  268. $oparampe['PE']['balises']['DetailPeriode']['ar']=array('tzr_ispla' => 1);
  269. $gparam['pla']=array('PL' => array('balisegroup' => 'Plannings',
  270. 'balises' => array('DetailPlanning' => array('table' => 'DPLANNING','fssm' => 'tzr_lie','ssm' => $param,
  271. 'linkparam' => array('DetailPeriode' => $oparampe)))));
  272. //--- Prestations liées
  273. $gparam['pliee']=array('PL' => array('balisegroup' => 'PrestationsLiees',
  274. 'balises' => array('DetailPrestationLiee' => array('table' => 'PRESTLIEE','fssm' => 'tzr_lie'))));
  275. $this->_cache['gparam-'.$this->acttype]=$gparam;
  276. }
  277. $this->structparam=$this->_cache['gparam-'.$this->acttype];
  278. }
  279. /// Importe une chaine/fichier au format TiF
  280. function _import($ar=NULL){
  281. $p=new XParam($ar,NULL);
  282. $file=$p->get('file');
  283. $limit=$p->get('limit');
  284. $xmlstring=$p->get('xmlstring');
  285. if(!empty($xmlstring)) $sxml=$xmlstring;
  286. else $sxml=file_get_contents($file);
  287. $idlist=array();
  288. $dom = new DOMDocument();
  289. $dom->preserveWhiteSpace=false;
  290. $dom->validateOnParse = true;
  291. $dom->loadXML($sxml);
  292. $this->xpath=new DOMXpath($dom);
  293. $this->xpath->registerNamespace('dc','http://purl.org/dc/elements/1.1/');
  294. $this->xpath->registerNamespace('dcterms', 'http://purl.org/dc/terms/');
  295. if(!empty($this->NSURI)){
  296. $this->xpath->registerNamespace('tzrns',$this->NSURI);
  297. $this->tzrns='tzrns:';
  298. }else{
  299. $this->tzrns='';
  300. }
  301. $this->prepareParam();
  302. $ois=$this->xpath->query('/'.$this->tzrns.'OI');
  303. if($ois->length==0)
  304. $ois=$this->xpath->query('/ListeOI/'.$this->tzrns.'OI');
  305. foreach($ois as $i => $oi){
  306. $oiddc=$this->importDC($oi); // DublinCore
  307. XLogs::notice('ModTif::_import', "import $oiddc");
  308. if(!empty($oiddc)){
  309. $this->oiddc=$oiddc;
  310. $this->importMultimedia($oi,$oiddc); // Multimédia
  311. $this->importContacts($oi,$oiddc); // Contacts (Adresses - Personnes - Moyens de communications)
  312. $this->importStructuresGestion($oi,$oiddc); // Structures gestion (Contacts)
  313. $this->importStructuresInformation($oi,$oiddc); // Structures information (Contacts)
  314. $this->importInfosLegales($oi,$oiddc); // Informations légales
  315. $this->importClassements($oi,$oiddc); // Classements
  316. $this->importGeolocs($oi,$oiddc); // Geolocalisation (Zones - Points - Coords - Envs - Cartes - Acces - Multimédia)
  317. $this->importPeriodes($oi,$oiddc); // Periodes (Dates - Details jours - Jours - Horaires)
  318. $this->importClienteles($oi,$oiddc); // Clientèles (Details client)
  319. $this->importUsages($oi,$oiddc); // Usages/Langues
  320. $this->importModesResa($oi,$oiddc); // Modes de réservation
  321. $this->importCapacites($oi,$oiddc); // Capacités
  322. $this->importOffresPresta($oi,$oiddc); // Offres de prestation (Prestations)
  323. $this->importTarifs($oi,$oiddc); // Tarifs et modes de paiement
  324. $this->importDescrComp($oi,$oiddc); // Descriptions complémentaires
  325. $this->importItineraires($oi,$oiddc); // Itinéraires
  326. $this->importPlannings($oi,$oiddc); // Plannings (Presta planning - Jour planning)
  327. $this->importPresationsLiees($oi,$oiddc); // Prestations liées
  328. $this->importOther($oi,$oiddc); // Fonction à personnaliser
  329. if(!empty($limit) && $limit<=$i) break;
  330. }
  331. }
  332. unset($dom,$xmlstring,$sxml,$ois);
  333. }
  334. function importDC($oi){
  335. $this->idlist=array();
  336. $dc=$this->xpath->query($this->tzrns.'DublinCore',$oi);
  337. if($dc->length>0){
  338. $dc=$dc->item(0);
  339. $oiddc=$this->analyseDC($dc,NULL,$this->structparam['dc']['DC']['balises']['DublinCore']);
  340. if(!empty($this->structparam['dc']['DC']['balises']['DublinCore']['ssm'])) $this->analyseQuery($dc,$this->structparam['dc']['DC']['balises']['DublinCore']['ssm'],$oiddc);
  341. }
  342. unset($dc);
  343. return $oiddc;
  344. }
  345. function importMultimedia(&$oi,$oiddc){
  346. $this->analyseQuery($oi,$this->structparam['mu'],$oiddc);
  347. }
  348. function importContacts(&$oi,$oiddc){
  349. $this->analyseQuery($oi,$this->structparam['co'],$oiddc);
  350. }
  351. function importStructuresGestion(&$oi,$oiddc){
  352. $this->analyseQuery($oi,$this->structparam['sg'],$oiddc);
  353. }
  354. function importStructuresInformation(&$oi,$oiddc){
  355. $this->analyseQuery($oi,$this->structparam['si'],$oiddc);
  356. }
  357. function importInfosLegales(&$oi,$oiddc){
  358. $this->analyseQuery($oi,$this->structparam['il'],$oiddc);
  359. }
  360. function importClassements(&$oi,$oiddc){
  361. $this->analyseQuery($oi,$this->structparam['cl'],$oiddc);
  362. }
  363. function importGeolocs(&$oi,$oiddc){
  364. $this->analyseQuery($oi,$this->structparam['ge'],$oiddc);
  365. }
  366. function importPeriodes(&$oi,$oiddc){
  367. $this->analyseQuery($oi,$this->structparam['pe'],$oiddc);
  368. }
  369. function importClienteles(&$oi,$oiddc){
  370. $this->analyseQuery($oi,$this->structparam['cli'],$oiddc);
  371. }
  372. function importUsages(&$oi,$oiddc){
  373. $this->analyseQuery($oi,$this->structparam['la'],$oiddc);
  374. }
  375. function importModesResa(&$oi,$oiddc){
  376. $this->analyseQuery($oi,$this->structparam['mr'],$oiddc);
  377. }
  378. function importCapacites(&$oi,$oiddc){
  379. $capa=$this->xpath->query($this->tzrns.'Capacites',$oi);
  380. if($capa->length>0){
  381. $capa=$capa->item(0);
  382. // Capacité globale
  383. $capaglob=$this->xpath->query($this->tzrns.'CapacitesGlobales',$capa);
  384. if($capaglob->length>0){
  385. $capaglob=$capaglob->item(0);
  386. $param=array('table' => 'CAPAGLOB','fssm' => 'tzr_lie');
  387. $oid=$this->analyseDC($capaglob,$oiddc,$param);
  388. $xset=XDataSource::objectFactoryHelper8('BCLASS=XDSTable&SPECS='.$this->prefixSQL.'DC');
  389. $xset->procEdit(array('oid' => $oiddc,'CapacitesGlobales' => $oid,'_nolog' => true));
  390. $this->analyseQuery($capaglob,$this->structparam['cs'],$oid);
  391. }
  392. // Capacités prestations
  393. $this->analyseQuery($capa,$this->structparam['cp'],$oiddc);
  394. // Capacités unités
  395. $this->analyseQuery($capa,$this->structparam['cu'],$oiddc);
  396. }
  397. }
  398. function importOffresPresta(&$oi,$oiddc){
  399. $this->analyseQuery($oi,$this->structparam['op'],$oiddc);
  400. }
  401. function importTarifs(&$oi,$oiddc){
  402. // Modes de paiement
  403. $mp=$this->xpath->query($this->tzrns.'Tarifs/'.$this->tzrns.'ModesPaiement',$oi);
  404. if($mp->length>0){
  405. $mp=$mp->item(0);
  406. $mdps=$this->xpath->query($this->tzrns.'ModePaiement',$mp);
  407. $xset=XDataSource::objectFactoryHelper8('BCLASS=XDSTable&SPECS='.$this->prefixSQL.'DC');
  408. $xsetmp=XDataSource::objectFactoryHelper8('BCLASS=XDSTable&SPECS='.$xset->desc['ModePaiement']->target);
  409. $ar2=array();
  410. foreach($mdps as $mpd){
  411. $oidmp=$xset->desc['ModePaiement']->target.':'.str_replace('.','-',$mpd->getAttribute('type'));
  412. $xsetmp->procInput(array('newoid' => $oidmp,'_nolog' => true,
  413. 'code' => $mpd->getAttribute('type'),'libelle' => $mpd->textContent));
  414. $ar2['ModePaiement'][]=$oidmp;
  415. }
  416. $obs=$this->xpath->query($this->tzrns.'ObservationModePaiement',$mp);
  417. if($obs->length>0) $ar2['ObservationModePaiement']=$obs->item(0)->textContent;
  418. $ar2['oid']=$oiddc;
  419. $ar2['_nolog']=true;
  420. $xset->procEdit($ar2);
  421. }
  422. unset($mp,$mdps,$mdp,$ar2,$obs);
  423. // Tarifs
  424. $ta=$this->xpath->query($this->tzrns.'Tarifs',$oi);
  425. if($ta->length>0){
  426. $ta=$ta->item(0);
  427. $this->analyseQuery($ta,$this->structparam['ta'],$oiddc);
  428. }
  429. unset($ta);
  430. }
  431. function importDescrComp(&$oi,$oiddc){
  432. $this->analyseQuery($oi,$this->structparam['desc'],$oiddc);
  433. }
  434. function importItineraires(&$oi,$oiddc){
  435. $this->analyseQuery($oi,$this->structparam['it'],$oiddc);
  436. }
  437. function importPlannings(&$oi,$oiddc){
  438. $this->analyseQuery($oi,$this->structparam['pla'],$oiddc);
  439. }
  440. function importPresationsLiees(&$oi,$oiddc){
  441. $this->analyseQuery($oi,$this->structparam['pliee'],$oiddc);
  442. }
  443. function importOther(&$oi,$oiddc){
  444. }
  445. /// Requete un noeud et prepare son analyse
  446. function analyseQuery(&$base,$params,$oidssm){
  447. if(isset($params['balises'])) $params=array($params);
  448. $oids=array();
  449. foreach($params as $param){
  450. $balisegrp=$param['balisegroup'];
  451. $balises=$param['balises'];
  452. if(!empty($balisegrp)){
  453. $dc=$this->xpath->query($this->tzrns.$balisegrp,$base);
  454. if($dc->length>0){
  455. $dc=$dc->item(0);
  456. $idref=$dc->getAttribute('idref');
  457. $id=$dc->getAttribute('id');
  458. if(!empty($idref)){
  459. foreach($this->idlist[$idref]['idlist'] as $i => $myid){
  460. $oids[]=$this->addReference($myid,$oidssm,$this->idlist[$idref]['fssmlist'][$i]);
  461. }
  462. }else{
  463. foreach($balises as $balise => $data){
  464. $details=$this->xpath->query($this->tzrns.$balise,$dc);
  465. foreach($details as $i => $detail){
  466. if(!empty($id)){
  467. $idd=$detail->getAttribute('id');
  468. if(empty($idd)){
  469. $idd=$id.'-tzr'.$i;
  470. $detail->setAttribute('id',$idd);
  471. }
  472. $this->idlist[$id]['idlist'][]=$idd;
  473. $this->idlist[$id]['fssmlist'][]=$data['fssm'];
  474. }
  475. $oid=$this->analyseDC($detail,$oidssm,$data);
  476. $oids[]=$oid;
  477. if(!empty($data['ssm'])) $this->analyseQuery($detail,$data['ssm'],$oid);
  478. }
  479. }
  480. }
  481. }
  482. }else{
  483. foreach($balises as $balise => $data){
  484. $details=$this->xpath->query($this->tzrns.$balise,$base);
  485. foreach($details as $detail){
  486. $oid=$this->analyseDC($detail,$oidssm,$data);
  487. $oids[]=$oid;
  488. if(!empty($data['ssm'])) $this->analyseQuery($detail,$data['ssm'],$oid);
  489. }
  490. }
  491. }
  492. }
  493. unset($dc,$details,$detail,$data);
  494. return $oids;
  495. }
  496. /// Insere les données en base dans le cas d'un objet faisant référence à un autre
  497. private function addReference($idref,$oidssm,$fssm){
  498. if(!empty($idref) && !empty($this->idlist[$idref])){
  499. if(!empty($oidssm) && !empty($fssm)){
  500. $ar=array('oid' => $this->idlist[$idref]['oid']);
  501. $ar[$fssm]=$this->idlist[$idref]['data'][$fssm];
  502. if(is_array($ar[$fssm])){
  503. $ar[$fssm][]=$oidssm;
  504. }else{
  505. $ar[$fssm]=array($ar[$fssm],$oidssm);
  506. }
  507. $table=Kernel::getTable($this->idlist[$idref]['oid']);
  508. if(XSystem::tableExists($table)){
  509. $xset=XDataSource::objectFactoryHelper8('BCLASS=XDSTable&SPECS='.$table);
  510. $ar['_nolog']=true;
  511. $xset->procEdit($ar);
  512. }
  513. }
  514. return $this->idlist[$idref]['oid'];
  515. }
  516. return false;
  517. }
  518. /// Analyse un noeud et insere en base
  519. private function analyseDC(&$dc,$oidssm=NULL,&$param=array()){
  520. $table=$param['table'];
  521. if(empty($table)) return;
  522. $forceedit=false;
  523. $id=$dc->getAttribute('id');
  524. $idref=$dc->getAttribute('idref');
  525. $ar=isset($param['ar'])?$param['ar']:array();
  526. $fssm=isset($param['fssm'])?$param['fssm']:NULL;
  527. $delNS=isset($param['delNS'])?$param['delNS']:true;
  528. $direct=isset($param['direct'])?$param['direct']:false;
  529. $oidfield=isset($param['oidfield'])?$param['oidfield']:NULL;
  530. $updfield=isset($param['updfield'])?$param['updfield']:'';
  531. $linkparam=isset($param['linkparam'])?$param['linkparam']:array();
  532. if($direct) $items=array($dc);
  533. else $items=$dc->childNodes;
  534. // Génération du KOID
  535. if(Kernel::getTable($oidssm)==$this->prefixSQL.$table){
  536. $ar['oid']=$oidssm;
  537. $forceedit=true;
  538. }elseif(!empty($param['oid'])){
  539. $ar['newoid']=$newoid=$param['oid'];
  540. }elseif($oidfield){
  541. if(strpos($this->acttype,'SITRA')===0 && strpos($oidfield,':')){
  542. $oidfield=$this->xpath->query(substr($oidfield,strpos($oidfield,':')+1),$dc);
  543. }else{
  544. $oidfield=$this->xpath->query($oidfield,$dc);
  545. }
  546. if($oidfield->length>0){
  547. $oidfield=$oidfield->item(0)->textContent;
  548. $ar['newoid']=$newoid=$this->prefixSQL.$table.':'.preg_replace('/[^a-z0-9_-]/i','_',$oidfield);
  549. }
  550. }
  551. if(empty($newoid)){
  552. $ar['newoid']=$newoid=XDataSource::getNewBasicOID($this->prefixSQL.$table);
  553. }
  554. XLogs::notice('ModTif::analyseDC', "import oid:{$ar['oid']}, newoid:$newoid");
  555. // Verification du dernier update. Si doit etre mis à jour, on efface pour mieux reinserer
  556. if(!empty($updfield)){
  557. if(strpos($this->acttype,'SITRA')===0 && strpos($updfield,':')){
  558. $updbal=$this->xpath->query(substr($updfield,strpos($updfield,':')+1),$dc);
  559. }else{
  560. $updbal=$this->xpath->query($updfield,$dc);
  561. }
  562. if($updbal->length>0){
  563. $updfield=str_replace(':','__',$updfield);
  564. $updvalue=$this->xset->desc[$updfield]->post_edit($updbal->item(0)->textContent);
  565. $updvalue=$updvalue->raw;
  566. $rs=selectQuery('select '.$updfield.' as UPD from '.$this->prefixSQL.$table.' where KOID="'.$newoid.'"');
  567. $ors=&$rs->fetch();
  568. $rs->CloseCursor();
  569. if(!empty($ors['UPD'])){
  570. if($ors['UPD']>=$updvalue) {
  571. XLogs::notice('ModTif::analyseDC', "import $newoid not imported {$ors['UPD']} >= $updvalue");
  572. return false;
  573. }
  574. elseif($this->prefixSQL.$table==$this->table) {
  575. XLogs::notice('ModTif::analyseDC', "delete $newoid");
  576. $this->del(array('oid' => $newoid,'_nolog' => true));
  577. }
  578. }
  579. }
  580. }
  581. // Dans le cas d'une référence, on recupère les données
  582. if(!empty($idref)){
  583. $ret['oid']=$this->addReference($idref,$oidssm,$fssm);
  584. }else{
  585. if((!$dc->hasChildNodes() && !$dc->hasAttributes() && !$direct) || !XSystem::tableExists($this->prefixSQL.$table)) return false;
  586. $xset=XDataSource::objectFactoryHelper8('BCLASS=XDSTable&SPECS='.$this->prefixSQL.$table);
  587. $hasData=false;
  588. // Traite les eventuels attributs de la balise source à enregistrer
  589. foreach($dc->attributes as $dcatt => $i){
  590. if(isset($xset->desc['att_'.$dcatt])){
  591. $hasData=true;
  592. $att='att_'.$dcatt;
  593. $value=$dc->getAttribute($dcatt);
  594. $ar[$att]=$this->getAttributeValue($xset,$att,$value,$dc);
  595. }
  596. }
  597. // Parcours les enfants
  598. foreach($items as $item){
  599. $hasData=true;
  600. if($delNS){
  601. list($ns,$field)=explode(':',$item->tagName);
  602. if(empty($field)) $field=$ns;
  603. }else{
  604. $field=str_replace(':','__',$item->tagName);
  605. // Patch pour DC de sitra qui n'utilise pas les espaces de noms
  606. if(strpos($this->acttype,'SITRA')===0){
  607. if(!isset($xset->desc[$field])){
  608. if(isset($xset->desc['dc__'.$field])) $field='dc__'.$field;
  609. elseif(isset($xset->desc['dcterms__'.$field])) $field='dcterms__'.$field;
  610. }
  611. }
  612. }
  613. if(isset($xset->desc[$field])){
  614. $xfield=&$xset->desc[$field];
  615. $ftype=$xfield->ftype;
  616. switch($ftype){
  617. case 'XFileDef': // Tente de recupérer le fichier pour le mettre en local, sinon utilise un champ url
  618. $file=TZR_TMP_DIR.'TiF'.uniqid();
  619. $content=file_get_contents($item->textContent);
  620. if(!empty($content)){
  621. file_put_contents($file,$content);
  622. unset($content);
  623. $mimeClasse=XMimeTypes::getInstance();
  624. $mime=$mimeClasse->get_file_type($file);
  625. if($mimeClasse->isImage($mime)){
  626. $ar[$field.'_img']='';
  627. $_FILES[$field.'_img']['tmp_name']=$file;
  628. $_FILES[$field.'_img']['type']=$mime;
  629. $_FILES[$field.'_img']['name']=$item->textContent;
  630. $_FILES[$field.'_img']['size']=filesize($file);
  631. }else{
  632. $ar[$field]='';
  633. $_FILES[$field]['tmp_name']=$file;
  634. $_FILES[$field]['type']=$mime;
  635. $_FILES[$field]['name']=$item->textContent;
  636. $_FILES[$field]['size']=filesize($file);
  637. }
  638. }
  639. $ar[$field.'_url']['url']=$item->textContent;
  640. break;
  641. case 'XUrlDef':
  642. $ar[$field]['url']=$item->textContent;
  643. break;
  644. case 'XLinkDef':
  645. if(strpos($xset->desc[$field]->target,$this->prefixSQL.'LS_')===0){
  646. $code=$item->getAttribute('code');
  647. if(empty($code)) $code=$item->getAttribute('type');
  648. $code=$this->getFormatCode($code);
  649. if(!empty($code)){
  650. $rs=selectQuery('select KOID from '.$xset->desc[$field]->target.' where code="'.$code.'"');
  651. if($rs && $rs->rowCount()==0){
  652. $codeoid=$xset->desc[$field]->target.':'.str_replace('.','-',$code);
  653. $libelle=$item->getAttribute('libelle');
  654. if(empty($libelle)) $libelle=$item->textContent;
  655. $xsettmp=XDataSource::objectFactoryHelper8('BCLASS=XDSTable&SPECS='.$xset->desc[$field]->target);
  656. $xsettmp->procInput(array('newoid' => $codeoid,'code' => $code,'libelle' => $libelle,'_nolog' => true));
  657. }else{
  658. $ors=$rs->fetch();
  659. $codeoid=$ors['KOID'];
  660. }
  661. $rs->CloseCursor();
  662. if($xset->desc[$field]->multivalued) $ar[$field][]=$codeoid;
  663. else $ar[$field]=$codeoid;
  664. }
  665. }elseif(!empty($linkparam[$field])){
  666. $oids=$this->analyseQuery($item->parentNode,$linkparam[$field],$newoid);
  667. if(!$xset->desc[$field]->multivalued) $oids=$oids[0];
  668. $ar[$field]=$oids;
  669. }
  670. break;
  671. case 'XTextDef':
  672. if(!empty($ar[$field])) $ar[$field].="\n\n".$item->textContent;
  673. else $ar[$field]=$item->textContent;
  674. break;
  675. case 'XBoolDef':
  676. if($item->textContent=='O') $ar[$field]=1;
  677. else $ar[$field]=0;
  678. break;
  679. case 'XDateTimeDef':
  680. $parts=preg_split('@[\ ]@',$item->textContent);
  681. if(!empty($parts[1]) && preg_match('@^[0-9]{2}:[0-9]{2}$@',$parts[1]))
  682. $ar[$field]=array('date' => $parts[0],'hour' => $parts[1].":00");
  683. else
  684. $ar[$field]=$item->textContent;
  685. break;
  686. default:
  687. if($xset->desc[$field]->multivalued){
  688. if(empty($ar[$field])) $ar[$field]=$item->textContent;
  689. else $ar[$field].=','.$item->textContent;
  690. }else{
  691. if(!empty($item->textContent)) $ar[$field]=$item->textContent;
  692. }
  693. break;
  694. }
  695. // Traite les eventuels attributs à enregistrer
  696. $ord=$xset->desc[$field]->forder+1;
  697. for($i=$ord;$i<count($xset->desc);$i++){
  698. if(preg_match("/^att_".$field."_(.*)$/",$xset->orddesc[$i],$ret)){
  699. $att=$xset->orddesc[$i];
  700. $atttype=$xset->desc[$att]->ftype;
  701. $value=$item->getAttribute($ret[1]);
  702. $ar[$att]=$this->getAttributeValue($xset,$att,$value,$item);
  703. }else{
  704. break;
  705. }
  706. }
  707. // Boucle pour forcer les champs numériques à NULL s'ils ne sont pas renseignés (car sinon 0, et c'est pas bien)
  708. foreach($xset->desc as $fn => &$f){
  709. if($f->ftype=='XRealDef' && !isset($ar[$fn])) $ar[$fn]='';
  710. }
  711. }
  712. }
  713. if($hasData){
  714. $ar['_nolog']=true;
  715. $ar['tzr_dc']=$this->oiddc;
  716. if($forceedit){
  717. XLogs::notice('ModTif::analyseDC', "update {$ar['oid']}");
  718. $xset->procEdit($ar);
  719. $ret['oid']=$ar['oid'];
  720. }else{
  721. // Renseigne l'oid du module parent si necessaire
  722. if(!empty($oidssm) && !empty($fssm)) $ar[$fssm]=$oidssm;
  723. XLogs::notice('ModTif::analyseDC', "insert $newoid");
  724. $ret=$xset->procInput($ar);
  725. }
  726. }
  727. }
  728. // Enregistre les données si la balise à un identifiant
  729. if(!empty($id)){
  730. $this->idlist[$id]=array('oid' => $ret['oid'],'data' => $ar);
  731. }
  732. unset($ar,$items);
  733. return $ret['oid'];
  734. }
  735. /// Recupere une valeur TZR d'un attribut
  736. function getAttributeValue(&$xset,$att,$value,&$item){
  737. $atttype=$xset->desc[$att]->ftype;
  738. switch($atttype){
  739. case 'XLinkDef':
  740. if(strpos($xset->desc[$att]->target,$this->prefixSQL.'LS_')===0){
  741. if(!empty($value)){
  742. $code=$this->getFormatCode($value);
  743. $rs=selectQuery('select KOID from '.$xset->desc[$att]->target.' where code="'.$code.'"');
  744. if($rs && $rs->rowCount()==0){
  745. $value=$xset->desc[$att]->target.':'.str_replace('.','-',$code);
  746. $libelle=$item->getAttribute('libelle');
  747. if(empty($libelle)) $libelle=$item->textContent;
  748. $libelle=$libelle;
  749. $xsettmp=XDataSource::objectFactoryHelper8('BCLASS=XDSTable&SPECS='.$xset->desc[$att]->target);
  750. $xsettmp->procInput(array('newoid' => $value,'code' => $code,'libelle' => $libelle,'_nolog' => true));
  751. }else{
  752. $ors=$rs->fetch();
  753. $value=$ors['KOID'];
  754. }
  755. $rs->closeCursor();
  756. }
  757. }else{
  758. if(!empty($value)) $value=$xset->desc[$att]->target.':'.preg_replace('/([^a-z0-9_-]+)/','-',$value);
  759. }
  760. break;
  761. case 'XBoolDef':
  762. if(strtolower($value)=='o') $value=1;
  763. else $value=0;
  764. break;
  765. default:
  766. break;
  767. }
  768. return $value;
  769. }
  770. /// Formate un code du thésaurus en xx.xx.xx...
  771. function getFormatCode($code){
  772. $acode=explode('.',$code);
  773. $code=array();
  774. foreach($acode as $tmp) $code[]=sprintf("%02d",$tmp);
  775. return implode('.',$code);
  776. }
  777. /**
  778. Fonction pour retourner un resultat plat sur une ressource
  779. Exemple de $list=array('DCONTACT' => array('filter' => 'RaisonSociale="LES RAILLES"',
  780. 'fields' => array('Sigle' => "Sig",'RaisonSociale' => "RS"),
  781. 'sstables' => array('DADRESSE' => array('fields' => array('Adr1' => 'adr'),'all' => true,
  782. 'order' => 'Adr1 DESC','pagesize' => 5)))
  783. filter : filter sql / fields : liste des champs à recupérer (clé=champ TiF, valeur=champ destination)
  784. order : ordre / pagesize : nombre d'éléments à recuperer
  785. **/
  786. function getFlatEntry($oid,$list,&$targetxset,$alloids=array()){
  787. $lang_data=XShell::getLangData();
  788. $ret=array();
  789. if(!is_array($oid)) $oid=array($oid);
  790. if(empty($alloids)) $alloids=$oid;
  791. foreach($list as $table => $param){
  792. $p=new XParam($param,array('filter' => '','pagesize' => 1,'all' => false,'sstables' => array(),'fields' => array(),'ssmfield' => 'tzr_lie',
  793. 'order' => 'tzr_lie,UPD desc','multivalued' => array(),'format' => array(),'pageseparator' => array(),
  794. 'concatseparator' => array(),'boolcond' => array(),'increment' => array(),'ifempty' => array()));
  795. if(strpos($table,':')!==false) // requête multiple sur la même table
  796. $table = substr($table,strpos($table,':')+1);
  797. $table=$this->prefixSQL.$table;
  798. $all=$p->get('all');
  799. $eval=$p->get('eval');
  800. $order=$p->get('order');
  801. $filter=$p->get('filter');
  802. $fields=$p->get('fields');
  803. $format=$p->get('format');
  804. // Tableau de champs qui ne sont a traiter que si le champ de destination est vide
  805. $ifempty=$p->get('ifempty');
  806. // Champ faisant le lien entre l'objet parent et l'objet fils (tzr_lie par defaut)
  807. $ssmfield=$p->get('ssmfield');
  808. $sstables=$p->get('sstables');
  809. // Nombre d'objet à traier (1 par defaut)
  810. $pagesize=$p->get('pagesize');
  811. $increment=$p->get('increment');
  812. $multivalued=$p->get('multivalued');
  813. // Separateur à utiliser dans le cas ou on concatene plusieurs objets dans le meme champ de destination
  814. $pageseparator=$p->get('pageseparator');
  815. // Separateur à utiliser dans le cas ou on concatene plusieurs champ d'un même objet dans le meme champ de destination
  816. $concatseparator=$p->get('concatseparator');
  817. // Tableau des champs => champs cible dans le cas d'un lien sur un objet
  818. $xlinktargetf=$p->get('xlinktargetf');
  819. $oidlies=array();
  820. $lastpage=array();
  821. if($all) $oid=$alloids;
  822. if($table==$this->table){
  823. $q='select * from '.$table.' where LANG="'.$lang_data.'" AND KOID="'.$oid[0].'"';
  824. $order='';
  825. $ret['oid']=$ret['newoid']=str_replace($this->prefixSQL.'DC',$targetxset->getTable(),$oid[0]);
  826. }else{
  827. $q='select * from '.$table.' where LANG="'.$lang_data.'" AND '.$ssmfield.' IN("'.implode('", "',$oid).'")';
  828. if(!empty($filter)) $q.=' AND '.$filter;
  829. }
  830. $xset=XDataSource::objectFactoryHelper8('BCLASS=XDSTable&SPECS='.$table);
  831. $options=array();
  832. foreach($xlinktargetf as $f=>$targetf){
  833. $options[$f]=array('target_fields' => $targetf, 'nocache' => 1);
  834. }
  835. $br=$xset->browse(array(
  836. 'select' => $q,
  837. 'order' => $order,
  838. 'tplentry' => TZR_RETURN_DATA,
  839. 'selectedfields' => array_keys($fields),
  840. 'options' => $options,
  841. 'nocount' => 1
  842. ));
  843. foreach($br['lines_oid'] as $i => $actoid){
  844. if($i==$pagesize) break;
  845. foreach($fields as $f => $newf){
  846. if(!empty($ret[$newf]) && in_array($f,$ifempty)) continue;
  847. if(in_array($newf,$increment)) $newf=$newf.($i+1);
  848. if($f=='oid')
  849. $value = $br['lines_oid'][$i];
  850. else
  851. $value=$this->getValueForInput($br['lines_o'.$f][$i],$xset->desc[$f],$targetxset->desc[$newf]);
  852. if(is_array($value)){
  853. if(empty($ret[$newf])) $ret[$newf]=array();
  854. $ret[$newf]=array_merge($ret[$newf],$value);
  855. }else{
  856. if(!empty($eval[$f])) $value=eval('return '.$eval[$f]);
  857. if($targetxset->desc[$newf]->ftype=='XBoolDef' && $ret[$newf]!=1) $ret[$newf]=$value;
  858. elseif($targetxset->desc[$newf]->ftype=='XGeodesicCoordinatesDef' && !empty($ret[$newf])) $ret[$newf].=';'.$value;
  859. else{
  860. // Formate la valeur si besoin
  861. if(!empty($format[$f])) $value=sprintf($format[$f],$value);
  862. if(empty($ret[$newf])) $ret[$newf]='';
  863. elseif(!empty($value)){
  864. // Ajoute le separateur suite à un changement d'objet ou pour une simple concat de champ sur un meme objet
  865. if($lastpage[$newf]!=$i){
  866. if(!empty($pageseparator[$newf])) $sep=$pageseparator[$newf];
  867. elseif($targetxset->desc[$newf]->ftype=='XTextDef') $sep="\r\n";
  868. elseif($targetxset->desc[$newf]->ftype=='XShortTextDef') $sep=', ';
  869. else $sep='';
  870. $value=$sep.$value;
  871. }else{
  872. if(!array_key_exists($newf,$concatseparator)) $concatseparator[$newf]=' ';
  873. $value=$concatseparator[$newf].$value;
  874. }
  875. }
  876. $ret[$newf].=$value;
  877. }
  878. }
  879. if(!empty($ret[$newf])) $lastpage[$newf]=$i;
  880. }
  881. $oidlies[]=$actoid;
  882. }
  883. unset($br,$param);
  884. // Recupere les sous tables
  885. if(!empty($sstables)) {
  886. if($table!=$this->table) {
  887. $ssalloids = selectQuery('select KOID from '.$table.' '.
  888. 'where tzr_lie IN("'.implode('","',$alloids).'")')
  889. ->fetchAll(PDO::FETCH_COLUMN);
  890. }
  891. $ret2=$this->getFlatEntry($oidlies,$sstables,$targetxset,$ssalloids);
  892. }
  893. if(!empty($ret2)) $ret=array_merge($ret,$ret2);
  894. }
  895. return $ret;
  896. }
  897. /// Transforme la valeur du champ source en valeur à passer à un procInput pour la champ destination
  898. function getValueForInput($value,$f,$targetf){
  899. global $DATA_DIR;
  900. if($targetf->ftype=='XTextDef' || $targetf->ftype=='XShortTextDef'){
  901. return $value->text;
  902. }
  903. if($targetf->ftype=='XBoolDef' && $f->ftype!='XBoolDef'){
  904. if((empty($targetf->boolcond) && !empty($value->raw)) || (!empty($targetf->boolcond) && in_array($value->raw,$targetf->boolcond)))
  905. return 1;
  906. else
  907. return 2;
  908. }
  909. switch($targetf->ftype){
  910. case 'XGeodesicCoordinatesDef':
  911. return str_replace(',','.',$value->raw);
  912. break;
  913. }
  914. switch($f->ftype){
  915. case 'XLinkDef':
  916. return explode('||',$value->raw);
  917. break;
  918. case 'XImageDef':
  919. $tmp_name=TZR_TMP_DIR.uniqid();
  920. copy($value->filename,$tmp_name);
  921. return $tmp_name;
  922. break;
  923. default:
  924. return $value->raw;
  925. break;
  926. }
  927. }
  928. /// Fonction pour checker l'état du webservice de ACVS
  929. function ACVSCheckService($ar=NULL){
  930. $p=new XParam($ar,NULL);
  931. $filter=$p->get('ACVSFilter');
  932. if(empty($filter)) $filter=$this->ACVSFilter;
  933. $idsql=array();
  934. ini_set('soap.wsdl_cache_enabled', 0);
  935. $soap=new SoapClient($this->ACVSUrl.'/'.$this->ACVSFileWSDL,array('exceptions' => false));
  936. $header=$this->ACVSParamGetHeader();
  937. $params=XSystem::xml2array($filter);
  938. foreach($params as $param){
  939. $param=$this->ACVSParamGetSearchOnlyIdPrestation($param);
  940. $request='<?xml version="1.0" encoding="utf-8"?>';
  941. $request.='<soap:Envelope '.$this->ACVSEnvUris.'>';
  942. $request.=$header.$param;
  943. $request.='</soap:Envelope>';
  944. $xmlidlist=$soap->__doRequest($request,$this->ACVSUrl.'/'.$this->ACVSFile,$this->ACVSUrl.'/SearchOnlyIdPrestation',1);
  945. if(get_class($xmlidlist)=='SoapFault') die('false');
  946. $dom=new DOMDocument();
  947. $dom->loadXML($xmlidlist);
  948. $ids=$dom->getElementsByTagName('idPrestation');
  949. if(empty($ids) || $ids->length==0 || empty($ids->item(0)->textContent)) die('false');
  950. }
  951. die('true');
  952. }
  953. /// Procédure d'import depuis le webservice d'ACVS
  954. function ACVSImport(/*$ar=NULL*/$sched, $o, $more) {
  955. $this->NSURI=$this->ACVSNSUri;
  956. $filter=$this->ACVSFilter;
  957. $message='';
  958. ini_set('soap.wsdl_cache_enabled', 0);
  959. $soap=new SoapClient($this->ACVSUrl.'/'.$this->ACVSFileWSDL,array('exceptions' => false));
  960. $header=$this->ACVSParamGetHeader();
  961. $params=XSystem::xml2array($filter);
  962. foreach($params as $rechname => $tzrparam){
  963. $this->acttype='ACVS ('.$rechname.')';
  964. $param=$this->ACVSParamGetSearchOnlyIdPrestation($tzrparam);
  965. $request='<?xml version="1.0" encoding="utf-8"?>';
  966. $request.='<soap:Envelope '.$this->ACVSEnvUris.'>';
  967. $request.=$header.$param;
  968. $request.='</soap:Envelope>';
  969. $xmlidlist=$soap->__doRequest($request,$this->ACVSUrl.'/'.$this->ACVSFile,$this->ACVSUrl.'/SearchOnlyIdPrestation',1);
  970. $dom=new DOMDocument();
  971. $dom->loadXML($xmlidlist);
  972. $fault=$dom->getElementsByTagName('faultstring');
  973. if($fault->length>0){
  974. if(!empty($this->reportto)){
  975. $GLOBALS['XUSER']->sendMail2User('TiF : Erreur import ACVS',"L'interrogation saop a retourné l'erreur suivante : \n".
  976. $fault->item(0)->textContent,$this->reportto);
  977. }
  978. return "L'interrogation saop a retourné l'erreur suivante : \n".$fault->item(0)->textContent;
  979. }
  980. $ids=$dom->getElementsByTagName('idPrestation');
  981. foreach($ids as $i => $id){
  982. $dom2=new DOMDocument();
  983. $param=$this->ACVSParamGetGetPrestationTIF(array('idPrestation' => $id->textContent));
  984. $request='<?xml version="1.0" encoding="utf-8"?>';
  985. $request.='<soap:Envelope '.$this->ACVSEnvUris.'>';
  986. $request.=$header.$param;
  987. $request.='</soap:Envelope>';
  988. $tif=$soap->__doRequest($request,$this->ACVSUrl.'/'.$this->ACVSFile,$this->ACVSUrl.'/GetPrestationTIF',1);
  989. $dom2->loadXML($tif);
  990. $tif=$dom2->getElementsByTagName('xmlTif');
  991. if($tif->length>0)
  992. $this->_import(array('xmlstring' => '<?xml version="1.0"?>'.$tif->item(0)->textContent));
  993. }
  994. // Suppression des élémenents qui ne sont pas dans l'import
  995. $param=$this->ACVSParamGetSearchOnlyIdPrestation($tzrparam,true);
  996. $request='<?xml version="1.0" encoding="utf-8"?>';
  997. $request.='<soap:Envelope '.$this->ACVSEnvUris.'>';
  998. $request.=$header.$param;
  999. $request.='</soap:Envelope>';
  1000. $xmlidlist=$soap->__doRequest($request,$this->ACVSUrl.'/'.$this->ACVSFile,$this->ACVSUrl.'/SearchOnlyIdPrestation',1);
  1001. $dom=new DOMDocument();
  1002. $dom->loadXML($xmlidlist);
  1003. $ids=$dom->getElementsByTagName('idPrestation');
  1004. $idsql=array();
  1005. foreach($ids as $i => $id)
  1006. $idsql[]='ACVS'.$id->textContent;
  1007. if(empty($idsql)){
  1008. $mail='La requete "'.$rechname.'" n\'a retournée aucun enregistrement.';
  1009. if(!empty($this->reportto))
  1010. $GLOBALS['XUSER']->sendMail2User('TiF : Erreur import ACVS',$mail,$this->reportto);
  1011. $message.=$mail."\n";
  1012. }
  1013. $rs=selectQuery('select KOID from '.$this->table.' where tzr_type="'.$this->acttype.'" and '.
  1014. 'dc__identifier not in ("'.implode('","',$idsql).'")');
  1015. while($rs && ($ors=$rs->fetch()))
  1016. $this->del(array('oid' => $ors['KOID'],'_nolog' => true));
  1017. $rs->CloseCursor();
  1018. }
  1019. return $message;
  1020. }
  1021. /// Prepare l'entete des requètes Soap d'ACVS (identification)
  1022. function ACVSParamGetHeader(){
  1023. $ret='<soap:Header><AuthHeader xmlns="'.$this->ACVSUrl.'">';
  1024. $ret.='<Login>'.$this->ACVSLogin.'</Login><Password>'.$this->ACVSPwd.'</Password>';
  1025. $ret.='</AuthHeader></soap:Header>';
  1026. return $ret;
  1027. }
  1028. /// Prepare le xml pour la fonction SearchOnlyIdPrestation du Soap ACVS
  1029. function ACVSParamGetSearchOnlyIdPrestation($parameters=array(),$nodate=false){
  1030. $ret='<soap:Body><SearchOnlyIdPrestation xmlns="'.$this->ACVSUrl.'">';
  1031. $defaults=array('' => array('libPrestation','criteres','majApresLe'),
  1032. '-1' => array('triEvenement','bMonth1','bMonth2','bMonth3','bMonth4','bMonth5','bMonth6',
  1033. 'bMonth7','bMonth8','bMonth9','bMonth10','bMonth11','bMonth12','bWeekEnd','idAnneeExercice',
  1034. 'dayBorneInfOuverture','dayBorneSupOuverture','bCritereA','bCritereB','bCritereC','bCritereD',
  1035. 'bCritereE','bCritereF','bCritereG','bCritereH'));
  1036. if($nodate) unset($parameters['majApresLe']);
  1037. foreach($defaults as $default => $balises){
  1038. foreach($balises as $balise){
  1039. if(isset($parameters[$balise])){
  1040. if($balise=='majApresLe'){
  1041. if(preg_match("/[0-9]{4}-[0-9]{2}-[0-9]{2}/",$parameters[$balise]))
  1042. $ret.='<'.$balise.'>'.$parameters[$balise].'</'.$balise.'>';
  1043. else
  1044. $ret.='<'.$balise.'>'.date('Y-m-d',strtotime($parameters[$balise])).'</'.$balise.'>';
  1045. }else{
  1046. $ret.='<'.$balise.'>'.$parameters[$balise].'</'.$balise.'>';
  1047. }
  1048. }else{
  1049. $ret.='<'.$balise.'>'.$default.'</'.$balise.'>';
  1050. }
  1051. }
  1052. }
  1053. $ret.='</SearchOnlyIdPrestation></soap:Body>';
  1054. return $ret;
  1055. }
  1056. /// Prepare le xml pour la fonction GetPrestationTIF du Soap ACVS
  1057. function ACVSParamGetGetPrestationTIF($parameters = array()){
  1058. $ret='<soap:Body><GetPrestationTIF xmlns="'.$this->ACVSUrl.'">';
  1059. if(isset($parameters['idPrestation'])) $ret.='<idPrestation>'.$parameters['idPrestation'].'</idPrestation>';
  1060. else $ret.='<idPrestation>-1</idPrestation>';
  1061. $ret.='</GetPrestationTIF></soap:Body>';
  1062. return $ret;
  1063. }
  1064. /// Fonction pour checker l'état du webservice de GITD (avec die pour rq)
  1065. function GITDCheckService($ar=NULL){
  1066. $ret=$this->GITDCheckService2($ar);
  1067. if($ret) die('true');
  1068. else die('false');
  1069. }
  1070. /// Fonction pour checker l'état du webservice de GITD (retourne true ou false)
  1071. function GITDCheckService2($ar=NULL){
  1072. $filter=$this->GITDFilter;
  1073. ini_set('soap.wsdl_cache_enabled', 0);
  1074. $soap=new SoapClient($this->GITDUrl,array('exceptions' => false));
  1075. $params=XSystem::xml2array($filter);
  1076. foreach($params as $param){
  1077. $rep=$soap->executeQueryN(array('arg0' => $this->GITDLogin,'arg1' => $this->GITDPwd,'arg2' => $param['requete'],'arg3' => 1));
  1078. if(get_class($rep)=='SoapFault') return false;
  1079. if(empty($rep)) return false;
  1080. if(empty($rep->return)) return false;
  1081. if(!is_array($rep->return)) $rep1=array($rep->return);
  1082. else $rep1=$rep->return;
  1083. foreach($rep1 as $i => $entry){
  1084. if(empty($entry)) return false;
  1085. if(!isset($entry->id)) return false;
  1086. if(empty($entry->id)) return false;
  1087. }
  1088. }
  1089. return true;
  1090. }
  1091. /// Procédure d'import depuis le webservice de GITD
  1092. function GITDImport(/*$ar=NULL*/$sched, $o, $more) {
  1093. if(!$this->GITDCheckService2($ar)){
  1094. if(!empty($this->reportto)){
  1095. $GLOBALS['XUSER']->sendMail2User('TiF : Erreur import GITD',"Webservice non operationel ou erreur de requete",$this->reportto);
  1096. }
  1097. return "Webservice non operationel ou erreur de requete";
  1098. }
  1099. $filter=$this->GITDFilter;
  1100. ini_set('soap.wsdl_cache_enabled', 0);
  1101. try {
  1102. $soap = new SoapClient($this->GITDUrl, array('exceptions' => true));
  1103. } catch (SoapFault $e) {
  1104. $err_msg = "Soap Error : " . $e->faultcode . ', ' . $e->faultstring ."\n";
  1105. $sched->setStatusJob($o->KOID, 'running', $err_msg);
  1106. return $err_msg;
  1107. }
  1108. $params=XSystem::xml2array($filter);
  1109. foreach($params as $rechname => $param){
  1110. $this->acttype='GITD ('.$rechname.')';
  1111. $rep=$soap->executeQueryN(array('arg0' => $this->GITDLogin,'arg1' => $this->GITDPwd,'arg2' => $param['requete'],'arg3' => $param['limit']));
  1112. if(!is_array($rep->return)) $rep->return=array($rep->return);
  1113. if(strpos($param['princtable'],'Ejb3Asc')===0) $idsql=$this->GITDStructAsc($rep,$soap,$param['princtable']);
  1114. elseif(strpos($param['princtable'],'Ejb3Pcu')===0) $idsql=$this->GITDStructPcu($rep,$soap,$param['princtable']);
  1115. elseif(strpos($param['princtable'],'Ejb3Div')===0) $idsql=$this->GITDStructDiv($rep,$soap,$param['princtable']);
  1116. elseif($param['princtable']=='Ejb3Loi') $idsql=$this->GITDStructLoi($rep,$soap);
  1117. elseif($param['princtable']=='Ejb3Fma') $idsql=$this->GITDStructFma($rep,$soap);
  1118. elseif($param['princtable']=='Ejb3Ski') $idsql=$this->GITDStructSki($rep,$soap);
  1119. elseif($param['princtable']=='Ejb3Pna') $idsql=$this->GITDStructPna($rep,$soap);
  1120. // Suppression des élémenents qui ne sont pas dans l'import
  1121. if(empty($idsql)) return "Webservice non operationel ou erreur de requete";
  1122. $rs=selectQuery('select KOID from '.$this->table.' where tzr_type="'.$this->acttype.'" and '.
  1123. 'dc__identifier not in ("'.implode('","',$idsql).'")');
  1124. while($rs && ($ors=$rs->fetch())){
  1125. $this->del(array('oid' => $ors['KOID'],'_nolog' => true));
  1126. }
  1127. }
  1128. }
  1129. /// Analayse les activités sports/cult de GITD
  1130. function GITDStructAsc(&$rep,&$soap,$type){
  1131. $idsql=array();
  1132. foreach($rep->return as $i => $entry){
  1133. $state=$this->GITDGetEntryState($entry);
  1134. $oiddc=$state['oiddc'];
  1135. if(empty($oiddc)) continue;
  1136. $idsql[]=$entry->id;
  1137. if(!$state['state']) continue;
  1138. $dcparam=array('id' => 'dc__identifier','societe' => 'dc__title','descom' => 'dc__description','modifie' => 'dcterms__modified',
  1139. 'enfan' => 'gitd_enfants','ascTypstruct' => 'gitd_ts','catPrest' => 'gitd_typep','classification' => 'Classification');
  1140. if($type=='Ejb3AscSport'){
  1141. $dcparam['sport']='acvs__ClassificationSousCategorie';
  1142. $entry->classification='02.01.01.02';
  1143. }elseif($type=='Ejb3AscCult'){
  1144. $dcparam['cult']='acvs__ClassificationSousCategorie';
  1145. $entry->classification='02.01.01.01';
  1146. }
  1147. $this->GITDGetDC($oiddc,$entry,$soap,$dcparam);
  1148. $this->GITDGetLang($oiddc,$entry,$soap);
  1149. $this->GITDGetContact($oiddc,$entry,$soap);
  1150. $this->GITDGetOuverture($oiddc,$entry,$soap);
  1151. $this->GITDGetAccessibilite($oiddc,$entry,$soap);
  1152. $this->GITDGetTarif($oiddc,$entry,$soap);
  1153. $this->GITDGetGeoloc($oiddc,$entry,$soap);
  1154. $this->GITDGetMultimedia($oiddc,$entry,$soap);
  1155. $this->GITDGetDescrComp($oiddc,$entry,$soap);
  1156. }
  1157. return $idsql;
  1158. }
  1159. /// Analayse les patrimoines culturels
  1160. function GITDStructPcu(&$rep,&$soap,$type){
  1161. $idsql=array();
  1162. foreach($rep->return as $i => $entry){
  1163. $state=$this->GITDGetEntryState($entry);
  1164. $oiddc=$state['oiddc'];
  1165. if(empty($oiddc)) continue;
  1166. $idsql[]=$entry->id;
  1167. if(!$state['state']) continue;
  1168. $dcparam=array('id' => 'dc__identifier','societe' => 'dc__title','descom' => 'dc__description','modifie' => 'dcterms__modified',
  1169. 'classification' => 'Classification','idTheme' => 'acvs__ClassificationSousCategorie');
  1170. $entry->classification='02.01.11';
  1171. $this->GITDGetDC($oiddc,$entry,$soap,$dcparam);
  1172. $this->GITDGetLang($oiddc,$entry,$soap);
  1173. $this->GITDGetContact($oiddc,$entry,$soap);
  1174. $this->GITDGetOuverture($oiddc,$entry,$soap);
  1175. $this->GITDGetGeoloc($oiddc,$entry,$soap);
  1176. $this->GITDGetMultimedia($oiddc,$entry,$soap);
  1177. $this->GITDGetDescrComp($oiddc,$entry,$soap);
  1178. }
  1179. return $idsql;
  1180. }
  1181. /// Analayse les structures diverses
  1182. function GITDStructDiv(&$rep,&$soap,$type){
  1183. $idsql=array();
  1184. foreach($rep->return as $i => $entry){
  1185. $state=$this->GITDGetEntryState($entry);
  1186. $oiddc=$state['oiddc'];
  1187. if(empty($oiddc)) continue;
  1188. $idsql[]=$entry->id;
  1189. if(!$state['state']) continue;
  1190. $dcparam=array('id' => 'dc__identifier','societe' => 'dc__title','modifie' => 'dcterms__modified',
  1191. 'classification' => 'Classification','idType' => 'acvs__ClassificationSousCategorie');
  1192. $entry->classification='02.01.10';
  1193. $this->GITDGetDC($oiddc,$entry,$soap,$dcparam);
  1194. $this->GITDGetContact($oiddc,$entry,$soap);
  1195. $this->GITDGetGeoloc($oiddc,$entry,$soap);
  1196. $this->GITDGetMultimedia($oiddc,$entry,$soap);
  1197. }
  1198. return $idsql;
  1199. }
  1200. /// Analayse les patrimoines naturels
  1201. function GITDStructPna(&$rep,&$soap,$type){
  1202. $idsql=array();
  1203. foreach($rep->return as $i => $entry){
  1204. $state=$this->GITDGetEntryState($entry);
  1205. $oiddc=$state['oiddc'];
  1206. if(empty($oiddc)) continue;
  1207. $idsql[]=$entry->id;
  1208. if(!$state['state']) continue;
  1209. $dcparam=array('id' => 'dc__identifier','nom' => 'dc__title','descom' => 'dc__description','modifie' => 'dcterms__modified',
  1210. 'classification' => 'Classification','idType' => 'acvs__ClassificationSousCategorie');
  1211. $entry->classification='02.01.12';
  1212. $this->GITDGetDC($oiddc,$entry,$soap,$dcparam);
  1213. $this->GITDGetLang($oiddc,$entry,$soap);
  1214. $this->GITDGetContact($oiddc,$entry,$soap);
  1215. $this->GITDGetOuverture($oiddc,$entry,$soap);
  1216. $this->GITDGetGeoloc($oiddc,$entry,$soap);
  1217. $this->GITDGetMultimedia($oiddc,$entry,$soap);
  1218. $this->GITDGetDescrComp($oiddc,$entry,$soap);
  1219. }
  1220. return $idsql;
  1221. }
  1222. /// Analayse les loisirs de GITD
  1223. function GITDStructLoi(&$rep,&$soap){
  1224. $idsql=array();
  1225. foreach($rep->return as $i => $entry){
  1226. $state=$this->GITDGetEntryState($entry);
  1227. $oiddc=$state['oiddc'];
  1228. if(empty($oiddc)) continue;
  1229. $idsql[]=$entry->id;
  1230. if(!$state['state']) continue;
  1231. $entry->classification='02.01.08';
  1232. $this->GITDGetDC($oiddc,$entry,$soap,array('id' => 'dc__identifier','societe' => 'dc__title','descom' => 'dc__description',
  1233. 'modifie' => 'dcterms__modified','sport' => 'acvs__ClassificationSousCategorie',
  1234. 'idObjet' => 'gitd_typep','classification' => 'Classification'));
  1235. $this->GITDGetLang($oiddc,$entry,$soap);
  1236. $this->GITDGetContact($oiddc,$entry,$soap);
  1237. $this->GITDGetOuverture($oiddc,$entry,$soap);
  1238. $this->GITDGetAccessibilite($oiddc,$entry,$soap);
  1239. $this->GITDGetTarif($oiddc,$entry,$soap);
  1240. $this->GITDGetGeoloc($oiddc,$entry,$soap);
  1241. $this->GITDGetMultimedia($oiddc,$entry,$soap);
  1242. $this->GITDGetDescrComp($oiddc,$entry,$soap);
  1243. }
  1244. return $idsql;
  1245. }
  1246. /// Analyse les evenements/mannifestations de GITD
  1247. function GITDStructFma(&$rep,&$soap){
  1248. $idsql=array();
  1249. foreach($rep->return as $i => $entry){
  1250. $state=$this->GITDGetEntryState($entry);
  1251. $oiddc=$state['oiddc'];
  1252. if(empty($oiddc)) continue;
  1253. $idsql[]=$entry->id;
  1254. if(!$state['state']) continue;
  1255. $entry->classification='02.01.03';
  1256. $this->GITDGetDC($oiddc,$entry,$soap,array('id' => 'dc__identifier','nom' => 'dc__title','descriptif' => 'dc__description',
  1257. 'modifie' => 'dcterms__modified','idType' => 'acvs__ClassificationSousCategorie',
  1258. 'classification' => 'Classification'));
  1259. $this->GITDGetContact($oiddc,$entry,$soap);
  1260. $this->GITDGetOuvertureManif($oiddc,$entry,$soap);
  1261. $this->GITDGetTarif($oiddc,$entry,$soap);
  1262. $this->GITDGetGeoloc($oiddc,$entry,$soap);
  1263. $this->GITDGetMultimedia($oiddc,$entry,$soap);
  1264. if(!empty($entry->lieu)){
  1265. $xset=XDataSource::objectFactoryHelper8('BCLASS=XDSTable&SPECS='.$this->prefixSQL.'DDESCRCOMP');
  1266. $xset->procInput(array('tzr_dc' => $oiddc,'tzr_lie' => $oiddc,'att_type' => $xset->desc['att_type']->target.':16-01-03',
  1267. 'att_Description_type' => $xset->desc['att_Description_type']->target.':16-02-01',
  1268. 'Description' => $entry->lieu));
  1269. }
  1270. }
  1271. return $idsql;
  1272. }
  1273. /// Analyse stations de ski de GITD
  1274. function GITDStructSki(&$rep,&$soap){
  1275. $idsql=array();
  1276. foreach($rep->return as $i => $entry){
  1277. $state=$this->GITDGetEntryState($entry);
  1278. $oiddc=$state['oiddc'];
  1279. if(empty($oiddc)) continue;
  1280. $idsql[]=$entry->id;
  1281. if(!$state['state']) continue;
  1282. $this->GITDGetDC($oiddc,$entry,$soap,array('id' => 'dc__identifier','nom' => 'dc__title','modifie' => 'dcterms__modified',
  1283. 'descom' => 'dc__description'));
  1284. $this->GITDGetContact($oiddc,$entry,$soap);
  1285. $this->GITDGetGeoloc($oiddc,$entry,$soap);
  1286. $this->GITDGetMultimedia($oiddc,$entry,$soap);
  1287. $this->GITDGetPrestaSki($oiddc,$entry,$soap);
  1288. $entry->cueilcompl='Hiver';
  1289. $this->GITDGetOuverture($oiddc,$entry,$soap);
  1290. }
  1291. return $idsql;
  1292. }
  1293. /// Genere l'oid d'une entrée et verifie s'il doit etre importer (efface une eventuelle entrée existante)
  1294. function GITDGetEntryState(&$entry){
  1295. if(empty($entry->id)) return array('oiddc' => '','state' => false);
  1296. $oiddc=$this->table.':'.preg_replace('/[^a-z0-9_-]/i','_',$entry->id);
  1297. $rs=&selectQuery('select KOID,dcterms__modified from '.$this->table.' where KOID="'.$oiddc.'"');
  1298. if($ors=$rs->fetch()) {
  1299. if($this->xset->desc['dcterms__modified']->get_ftype()=='XDateDef') $date=date('Y-m-d',strtotime($entry->modifie));
  1300. else $date=date('Y-m-d H:i:s',strtotime($entry->modifie));
  1301. if($ors['dcterms__modified'] < $date) $this->del(array('oid' => $oiddc));
  1302. else return array('oiddc' => $oiddc,'state' => false);
  1303. }
  1304. $this->recursiveAddslashes($entry);
  1305. return array('oiddc' => $oiddc,'state' => true);
  1306. }
  1307. /// Renseigne le DC avec les données GITD
  1308. function GITDGetDC($oiddc,&$entry,&$soap,$param){
  1309. $ar2=array();
  1310. foreach($param as $ef => $f){
  1311. if(!empty($ar2[$f]) || empty($this->xset->desc[$f])) continue;
  1312. if($this->xset->desc[$f]->isObjectLink()) $ar2[$f]=$this->V2toV3($this->xset->desc[$f]->target,$entry->$ef);
  1313. elseif($this->xset->desc[$f]->get_ftype()=='XBoolDef') $ar2[$f]=!empty($entry->$ef)?1:2;
  1314. else $ar2[$f]=@$entry->$ef;
  1315. }
  1316. $ar2['tzr_type']=$this->acttype;
  1317. $ar2['newoid']=$oiddc;
  1318. $ret=$this->xset->procInput($ar2);
  1319. }
  1320. /// Renseigne les langues avec les données GITD
  1321. function GITDGetLang($oiddc,&$entry,&$soap){
  1322. if(!empty($entry->idParle)){
  1323. if(!is_array($entry->idParle)) $entry->idParle=array($entry->idParle);
  1324. $xset=XDataSource::objectFactoryHelper8('BCLASS=XDSTable&SPECS='.$this->prefixSQL.'USAGE');
  1325. $xset->procInput(array('tzr_dc' => $oiddc,'tzr_lie' => $oiddc,'att_type' => $xset->desc['att_type']->target.':11-01-01',
  1326. 'Langue' => implode(',',$entry->idParle)));;
  1327. }
  1328. }
  1329. /// Renseigne les contacts/moyens de communication avec les données GITD
  1330. function GITDGetContact($oiddc,&$entry,&$soap){
  1331. if(!empty($entry->adresse1) || !empty($entry->adresse2) || !empty($entry->adresse3)|| !empty($entry->codePoste) ||
  1332. !empty($entry->commune) ||
  1333. !empty($entry->coordCom) || !empty($entry->coordCom2) || !empty($entry->coordCom4) || !empty($entry->coordCom5) ||
  1334. !empty($entry->coordCom21) || !empty($entry->coordCom6) || !empty($entry->coordCom7) || !empty($entry->coordCom10) ||
  1335. !empty($entry->coordCom11) || !empty($entry->coordCom20) ||
  1336. !empty($entry->idCiv) || !empty($entry->nomCont) || !empty($entry->prenomCont) || !empty($entry->fonctionCont) ||
  1337. !empty($entry->adr1Cont) || !empty($entry->adr2Cont) || !empty($entry->cpCont) || !empty($entry->communeCont)){
  1338. // Contact
  1339. if(!empty($entry->idCiv) || !empty($entry->nomCont) || !empty($entry->prenomCont) || !empty($entry->fonctionCont) ||
  1340. !empty($entry->adr1Cont) || !empty($entry->adr2Cont) || !empty($entry->cpCont) || !empty($entry->communeCont)){
  1341. $xset=XDataSource::objectFactoryHelper8('BCLASS=XDSTable&SPECS='.$this->prefixSQL.'DCONTACT');
  1342. $ret=$xset->procInput(array('tzr_dc' => $oiddc,'tzr_lie' => $oiddc,'att_type' => $xset->desc['att_type']->target.':04-03-18',
  1343. 'RaisonSociale' => $entry->societe));
  1344. $com=$this->GITDGetCommune($entry->communeCont,$soap);
  1345. $xset=XDataSource::objectFactoryHelper8('BCLASS=XDSTable&SPECS='.$this->prefixSQL.'DADRESSE');
  1346. $ret=$xset->procInput(array('tzr_dc' => $oiddc,'tzr_lie' => $ret['oid'],'Adr1' => $entry->adr1Cont,'Adr2' => $entry->adr2Cont,
  1347. 'CodePostal' => $entry->cpCont,'BureauDistrib' => $com->nom));
  1348. if(!empty($entry->idCiv) || !empty($entry->nomCont) || !empty($entry->prenomCont) || !empty($entry->fonctionCont)){
  1349. $xset=XDataSource::objectFactoryHelper8('BCLASS=XDSTable&SPECS='.$this->prefixSQL.'DPERSONNE');
  1350. $ret=$xset->procInput(array('tzr_dc' => $oiddc,'tzr_lie' => $ret['oid'],
  1351. 'att_type' => $xset->desc['att_type']->target.':04-04-02',
  1352. 'Civilite' => $this->V2toV3($xset->desc['Civilite']->target,$entry->idCiv),
  1353. 'Prenom' => $entry->prenomCont,'Nom' => $entry->nomCont,'Fonction' => $entry->fonctionCont));
  1354. }
  1355. }
  1356. // Adresse-Moyen de com
  1357. if(!empty($entry->adresse1) || !empty($entry->adresse2) || !empty($entry->adresse3) || !empty($entry->codePoste) ||
  1358. !empty($entry->commune) ||
  1359. !empty($entry->coordCom) || !empty($entry->coordCom2) || !empty($entry->coordCom4) || !empty($entry->coordCom5) ||
  1360. !empty($entry->coordCom21) || !empty($entry->coordCom6) || !empty($entry->coordCom7) || !empty($entry->coordCom10) ||
  1361. !empty($entry->coordCom11) || !empty($entry->coordCom20)){
  1362. $xset=XDataSource::objectFactoryHelper8('BCLASS=XDSTable&SPECS='.$this->prefixSQL.'DCONTACT');
  1363. $ret=$xset->procInput(array('tzr_dc' => $oiddc,'tzr_lie' => $oiddc,'att_type' => $xset->desc['att_type']->target.':04-03-13',
  1364. 'RaisonSociale' => $entry->societe,'Sigle' => $entry->sigle));
  1365. $com=$this->GITDGetCommune($entry->commune,$soap);
  1366. $xset=XDataSource::objectFactoryHelper8('BCLASS=XDSTable&SPECS='.$this->prefixSQL.'DADRESSE');
  1367. $ret=$xset->procInput(array('tzr_dc' => $oiddc,'tzr_lie' => $ret['oid'],'Adr1' => $entry->adresse1,'Adr2' => $entry->adresse2,
  1368. 'Adr3' => $entry->adresse3,'CodePostal' => $entry->codePoste,'BureauDistrib' => $com->nom));
  1369. if(!empty($entry->coordCom) || !empty($entry->coordCom2) || !empty($entry->coordCom4) || !empty($entry->coordCom5) ||
  1370. !empty($entry->coordCom21) || !empty($entry->coordCom6) || !empty($entry->coordCom7) || !empty($entry->coordCom10) ||
  1371. !empty($entry->coordCom11) || !empty($entry->coordCom20)){
  1372. $xset=XDataSource::objectFactoryHelper8('BCLASS=XDSTable&SPECS='.$this->prefixSQL.'DPERSONNE');
  1373. $ret=$xset->procInput(array('tzr_dc' => $oiddc,'tzr_lie' => $ret['oid'],
  1374. 'att_type' => $xset->desc['att_type']->target.':04-04-05'));
  1375. $xset=XDataSource::objectFactoryHelper8('BCLASS=XDSTable&SPECS='.$this->prefixSQL.'DMOYENCOM');
  1376. if(!empty($entry->coordCom)){
  1377. $xset->procInput(array('tzr_dc' => $oiddc,'tzr_lie' => $ret['oid'],'att_type' => $xset->desc['att_type']->target.':04-02-01',
  1378. 'Coord' => $entry->coordCom,'ObservationDetailMoyenCom' => 'num1'));
  1379. }
  1380. if(!empty($entry->coordCom2)){
  1381. $xset->procInput(array('tzr_dc' => $oiddc,'tzr_lie' => $ret['oid'],'att_type' => $xset->desc['att_type']->target.':04-02-02',
  1382. 'Coord' => $entry->coordCom2));
  1383. }
  1384. if(!empty($entry->coordCom4)){
  1385. $xset->procInput(array('tzr_dc' => $oiddc,'tzr_lie' => $ret['oid'],'att_type' => $xset->desc['att_type']->target.':04-02-04',
  1386. 'Coord' => $entry->coordCom4));
  1387. }
  1388. if(!empty($entry->coordCom5)){
  1389. $xset->procInput(array('tzr_dc' => $oiddc,'tzr_lie' => $ret['oid'],'att_type' => $xset->desc['att_type']->target.':04-02-05',
  1390. 'Coord' => $entry->coordCom5,'ObservationDetailMoyenCom' => 'num1'));
  1391. }
  1392. if(!empty($entry->coordCom21)){
  1393. $xset->procInput(array('tzr_dc' => $oiddc,'tzr_lie' => $ret['oid'],'att_type' => $xset->desc['att_type']->target.':04-02-05',
  1394. 'Coord' => $entry->coordCom21,'ObservationDetailMoyenCom' => 'num2'));
  1395. }
  1396. if(!empty($entry->coordCom6)){
  1397. $xset->procInput(array('tzr_dc' => $oiddc,'tzr_lie' => $ret['oid'],'att_type' => $xset->desc['att_type']->target.':04-02-01',
  1398. 'Coord' => $entry->coordCom6,'ObservationDetailMoyenCom' => 'num2'));
  1399. }
  1400. if(!empty($entry->coordCom7)){
  1401. $xset->procInput(array('tzr_dc' => $oiddc,'tzr_lie' => $ret['oid'],'att_type' => $xset->desc['att_type']->target.':04-02-01',
  1402. 'Coord' => $entry->coordCom7,'ObservationDetailMoyenCom' => 'num3'));
  1403. }
  1404. if(!empty($entry->coordCom10)){
  1405. $xset->procInput(array('tzr_dc' => $oiddc,'tzr_lie' => $ret['oid'],'att_type' => $xset->desc['att_type']->target.':04-02-05',
  1406. 'Coord' => $entry->coordCom10,'ObservationDetailMoyenCom' => 'coordCom10'));
  1407. }
  1408. if(!empty($entry->coordCom20)){
  1409. $xset->procInput(array('tzr_dc' => $oiddc,'tzr_lie' => $ret['oid'],'att_type' => $xset->desc['att_type']->target.':04-02-05',
  1410. 'Coord' => $entry->coordCom20,'ObservationDetailMoyenCom' => 'coordCom20'));
  1411. }
  1412. if(!empty($entry->coordCom11)){
  1413. $xset->procInput(array('tzr_dc' => $oiddc,'tzr_lie' => $ret['oid'],'att_type' => $xset->desc['att_type']->target.':04-02-05',
  1414. 'Coord' => $entry->coordCom11,'ObservationDetailMoyenCom' => 'coordCom11'));
  1415. }
  1416. }
  1417. }
  1418. }
  1419. }
  1420. /// Renseigne les periodes d'ouvertures avec les données GITD (format loisirs)
  1421. function GITDGetOuverture($oiddc,&$entry,&$soap){
  1422. if(!empty($entry->ouvacPerm)){
  1423. $xset=XDataSource::objectFactoryHelper8('BCLASS=XDSTable&SPECS='.$this->prefixSQL.'DPERIODE');
  1424. $ret=$xset->procInput(array('tzr_dc' => $oiddc,'tzr_lie' => $oiddc,'att_type' => $xset->desc['att_type']->target.':09-01-06'));
  1425. $xset=XDataSource::objectFactoryHelper8('BCLASS=XDSTable&SPECS='.$this->prefixSQL.'DDATE');
  1426. $xset->procInput(array('tzr_dc' => $oiddc,'tzr_lie' => $ret['oid'],'DateDebut' => date('Y').'-01-01','DateFin' => date('Y').'-12-31',
  1427. 'ObservationDates' => 'permanant'));
  1428. }elseif((!empty($entry->datDebutOuvac) && !empty($entry->datFinOuvac)) || (!empty($entry->datDebutOuvac2) && !empty($entry->datFinOuvac2)) || (!empty($entry->datDebutOuvac3) && !empty($entry->datFinOuvac3))){
  1429. $xset=XDataSource::objectFactoryHelper8('BCLASS=XDSTable&SPECS='.$this->prefixSQL.'DPERIODE');
  1430. $ret=$xset->procInput(array('tzr_dc' => $oiddc,'tzr_lie' => $oiddc,'att_type' => $xset->desc['att_type']->target.':09-01-06'));
  1431. if(!empty($entry->datDebutOuvac) && !empty($entry->datFinOuvac)){
  1432. $xset=XDataSource::objectFactoryHelper8('BCLASS=XDSTable&SPECS='.$this->prefixSQL.'DDATE');
  1433. $xset->procInput(array('tzr_dc' => $oiddc,'tzr_lie' => $ret['oid'],'DateDebut' => $entry->datDebutOuvac,
  1434. 'DateFin' => $entry->datFinOuvac,'ObservationDates' => $entry->cueilcompl));
  1435. }
  1436. if(!empty($entry->datDebutOuvac2) && !empty($entry->datFinOuvac2)){
  1437. $xset=XDataSource::objectFactoryHelper8('BCLASS=XDSTable&SPECS='.$this->prefixSQL.'DDATE');
  1438. $xset->procInput(array('tzr_dc' => $oiddc,'tzr_lie' => $ret['oid'],'DateDebut' => $entry->datDebutOuvac2,
  1439. 'DateFin' => $entry->datFinOuvac2,'ObservationDates' => $entry->cueilcompl));
  1440. }
  1441. if(!empty($entry->datDebutOuvac3) && !empty($entry->datFinOuvac3)){
  1442. $xset=XDataSource::objectFactoryHelper8('BCLASS=XDSTable&SPECS='.$this->prefixSQL.'DDATE');
  1443. $xset->procInput(array('tzr_dc' => $oiddc,'tzr_lie' => $ret['oid'],'DateDebut' => $entry->datDebutOuvac3,
  1444. 'DateFin' => $entry->datFinOuvac3,'ObservationDates' => $entry->cueilcompl));
  1445. }
  1446. }
  1447. }
  1448. /// Renseigne les periodes d'ouvertures avec les données GITD (format manif)
  1449. function GITDGetOuvertureManif($oiddc,&$entry,&$soap){
  1450. if(!empty($entry->datDebut) && !empty($entry->datFin)){
  1451. $xset=XDataSource::objectFactoryHelper8('BCLASS=XDSTable&SPECS='.$this->prefixSQL.'DPERIODE');
  1452. $ret=$xset->procInput(array('tzr_dc' => $oiddc,'tzr_lie' => $oiddc,'att_type' => $xset->desc['att_type']->target.':09-01-06'));
  1453. $xset=XDataSource::objectFactoryHelper8('BCLASS=XDSTable&SPECS='.$this->prefixSQL.'DDATE');
  1454. $ret=$xset->procInput(array('tzr_dc' => $oiddc,'tzr_lie' => $ret['oid'],'DateDebut' => $entry->datDebut,'DateFin' => $entry->datFin));
  1455. if(!empty($entry->ouverture1) && !empty($entry->fermeture1)){
  1456. $xset=XDataSource::objectFactoryHelper8('BCLASS=XDSTable&SPECS='.$this->prefixSQL.'DJOURS');
  1457. $ret=$xset->procInput(array('tzr_dc' => $oiddc,'tzr_lie' => $ret['oid'],'att_type' => $xset->desc['att_type']->target.':03-09-02'));
  1458. $xset=XDataSource::objectFactoryHelper8('BCLASS=XDSTable&SPECS='.$this->prefixSQL.'JOURS');
  1459. $ret=$xset->procInput(array('tzr_dc' => $oiddc,'tzr_lie' => $ret['oid'],'att_type' => $xset->desc['att_type']->target.':09-02-08'));
  1460. $xset=XDataSource::objectFactoryHelper8('BCLASS=XDSTable&SPECS='.$this->prefixSQL.'HORAIRES');
  1461. $ret=$xset->procInput(array('tzr_dc' => $oiddc,'tzr_lie' => $ret['oid'],'HoraireDebut' => $entry->ouverture1,
  1462. 'HoraireFin' => $entry->fermeture1));
  1463. }
  1464. }
  1465. }
  1466. /// Renseigne les accessibilités avec les données GITD
  1467. function GITDGetAccessibilite($oiddc,&$entry,&$soap){
  1468. if(!empty($entry->idAcchandi)){
  1469. $handicap=array('AUD' => 'Handicap auditif','MOT' => 'Handicapé moteur','MEN' => 'Handicape mental','VIS' => 'Handicapé visuel');
  1470. $xset=XDataSource::objectFactoryHelper8('BCLASS=XDSTable&SPECS='.$this->prefixSQL.'DOFFREPRESTA');
  1471. $ret=$xset->procInput(array('tzr_dc' => $oiddc,'tzr_lie' => $oiddc,'att_type' => $xset->desc['att_type']->target.':15-01'));
  1472. $xset=XDataSource::objectFactoryHelper8('BCLASS=XDSTable&SPECS='.$this->prefixSQL.'DPRESTA');
  1473. $descrhandicap=array();
  1474. foreach($entry->idAcchandi as $code) $descrhandicap[]=$handicap[$code];
  1475. $xset->procInput(array('tzr_dc' => $oiddc,'tzr_lie' => $ret['oid'],'att_type' => $xset->desc['att_type']->target.':15-01-01',
  1476. 'DescriptionPrestation' => implode('/',$descrhandicap)."\r\n".$entry->deschandi));
  1477. }
  1478. }
  1479. /// Renseigne les tarifs avec les données GITD
  1480. function GITDGetTarif($oiddc,&$entry,&$soap){
  1481. if(!empty($entry->euroTarifs) && empty($entry->gratuit)){
  1482. if(!empty($entry->euroTarifs->debut) && !empty($entry->euroTarifs->fin)){
  1483. $xset=XDataSource::objectFactoryHelper8('BCLASS=XDSTable&SPECS='.$this->prefixSQL.'DPERIODE');
  1484. $ret=$xset->procInput(array('tzr_dc' => $oiddc,'att_type' => $xset->desc['att_type']->target.':09-01-08'));
  1485. $xset=XDataSource::objectFactoryHelper8('BCLASS=XDSTable&SPECS='.$this->prefixSQL.'DDATE');
  1486. $tp=$xset->procInput(array('tzr_dc' => $oiddc,'tzr_lie' => $ret['oid'],'DateDebut' => $entry->euroTarifs->debut,
  1487. 'DateFin' => $entryeuroTarifs->fin));
  1488. }
  1489. if(!empty($entry->euroTarifs->valeurMini) || !empty($entry->euroTarifs->valeurMaxi)){
  1490. $xset=XDataSource::objectFactoryHelper8('BCLASS=XDSTable&SPECS='.$this->prefixSQL.'DTARIF');
  1491. $xset->procInput(array('tzr_dc' => $oiddc,'TarifMax' => $entry->euroTarifs->valeurMaxi,
  1492. 'TarifMin' => $entry->euroTarifs->valeurMini,'att_type' => $xset->desc['att_type']->target.':13-04-01-01',
  1493. 'DetailPeriode' => $tp['oid'],'tzr_lie' => $oiddc));
  1494. }
  1495. }elseif(!empty($entry->gratuit)){
  1496. $xset=XDataSource::objectFactoryHelper8('BCLASS=XDSTable&SPECS='.$this->prefixSQL.'DTARIF');
  1497. $xset->procInput(array('tzr_dc' => $oiddc,'att_type' => $xset->desc['att_type']->target.':13-04-01-34',
  1498. 'DetailPeriode' => $tp['oid'],'tzr_lie' => $oiddc));
  1499. }
  1500. }
  1501. /// Renseigne les geolocalisations avec les données GITD
  1502. function GITDGetGeoloc($oiddc,&$entry,&$soap){
  1503. if(!empty($entry->latitude) || !empty($entry->longitude) || !empty($entry->altitude) || !empty($entry->altMin) || !empty($entry->altMax)){
  1504. $xset=XDataSource::objectFactoryHelper8('BCLASS=XDSTable&SPECS='.$this->prefixSQL.'DGEOLOC');
  1505. $ret=$xset->procInput(array('tzr_dc' => $oiddc,'tzr_lie' => $oiddc,'att_type' => $xset->desc['att_type']->target.':08-01-03'));
  1506. $xset=XDataSource::objectFactoryHelper8('BCLASS=XDSTable&SPECS='.$this->prefixSQL.'ZONES');
  1507. $ret=$xset->procInput(array('tzr_dc' => $oiddc,'tzr_lie' => $ret['oid'],'att_type' => $xset->desc['att_type']->target.':08-02-07-02'));
  1508. $xset=XDataSource::objectFactoryHelper8('BCLASS=XDSTable&SPECS='.$this->prefixSQL.'DPOINT');
  1509. $ret=$xset->procInput(array('tzr_dc' => $oiddc,'tzr_lie' => $ret['oid'],'att_type' => $xset->desc['att_type']->target.':08-02-05-11'));
  1510. $xset=XDataSource::objectFactoryHelper8('BCLASS=XDSTable&SPECS='.$this->prefixSQL.'DCOOR');
  1511. $ret=$xset->procInput(array('tzr_dc' => $oiddc,'tzr_lie' => $ret['oid'],'att_type' => $xset->desc['att_type']->target.':08-02-02-03',
  1512. 'Longitude' => $entry->longitude,'Latitude' => $entry->latitude,'Altitude' => $entry->altitude,
  1513. 'att_Altitude_altitudeMini' => $entry->altMin,'att_Altitude_altitudeMaxi' => $entry->altMax));
  1514. }
  1515. }
  1516. /// Renseigne les medias avec les données GITD
  1517. function GITDGetMultimedia($oiddc,&$entry,&$soap){
  1518. $xset=XDataSource::objectFactoryHelper8('BCLASS=XDSTable&SPECS='.$this->prefixSQL.'DMULTIMEDIA');
  1519. if(!empty($entry->photo)){
  1520. $entry->photoUrl=$this->GITDUrlDomain.$entry->photoUrl;
  1521. $xset->procInput(array('tzr_dc' => $oiddc,'tzr_lie' => $oiddc,'att_type' => $xset->desc['att_type']->target.':03-01-01',
  1522. 'LegendeRessource' => $entry->photoLegende,'URL_img' => $entry->photoUrl,'Nom' => 'Structure'));
  1523. }
  1524. if(!empty($entry->photoenv)){
  1525. $entry->photoenvUrl=$this->GITDUrlDomain.$entry->photoenvUrl;
  1526. $xset->procInput(array('tzr_dc' => $oiddc,'tzr_lie' => $oiddc,'att_type' => $xset->desc['att_type']->target.':03-01-01',
  1527. 'LegendeRessource' => $entry->photoenvLegende,'URL_img' => $entry->photoenvUrl,'Nom' => 'Environnement'));
  1528. }
  1529. if(!empty($entry->photoprest)){
  1530. $entry->photoprestUrl=$this->GITDUrlDomain.$entry->photoprestUrl;
  1531. $xset->procInput(array('tzr_dc' => $oiddc,'tzr_lie' => $oiddc,'att_type' => $xset->desc['att_type']->target.':03-01-01',
  1532. 'LegendeRessource' => $entry->photoprestLegende,'URL_img' => $entry->photoprestUrl,'Nom' => 'Prestataire'));
  1533. }
  1534. if(!empty($entry->photo1)){
  1535. $entry->photo1Url=$this->GITDUrlDomain.$entry->photo1Url;
  1536. $xset->procInput(array('tzr_dc' => $oiddc,'tzr_lie' => $oiddc,'att_type' => $xset->desc['att_type']->target.':03-01-01',
  1537. 'LegendeRessource' => $entry->photo1Legende,'URL_img' => $entry->photo1Url,'Nom' => 'Photo 1'));
  1538. }
  1539. if(!empty($entry->photo2)){
  1540. $entry->photo2Url=$this->GITDUrlDomain.$entry->photo2Url;
  1541. $xset->procInput(array('tzr_dc' => $oiddc,'tzr_lie' => $oiddc,'att_type' => $xset->desc['att_type']->target.':03-01-01',
  1542. 'LegendeRessource' => $entry->photo2Legende,'URL_img' => $entry->photo2Url,'Nom' => 'Photo 2'));
  1543. }
  1544. if(!empty($entry->photo3)){
  1545. $entry->photo3Url=$this->GITDUrlDomain.$entry->photo3Url;
  1546. $xset->procInput(array('tzr_dc' => $oiddc,'tzr_lie' => $oiddc,'att_type' => $xset->desc['att_type']->target.':03-01-01',
  1547. 'LegendeRessource' => $entry->photo3Legende,'URL_img' => $entry->photo3Url,'Nom' => 'Photo 3'));
  1548. }
  1549. if(!empty($entry->photo4)){
  1550. $entry->photo4Url=$this->GITDUrlDomain.$entry->photo4Url;
  1551. $xset->procInput(array('tzr_dc' => $oiddc,'tzr_lie' => $oiddc,'att_type' => $xset->desc['att_type']->target.':03-01-01',
  1552. 'LegendeRessource' => $entry->photo4Legende,'URL_img' => $entry->photo4Url,'Nom' => 'Photo 4'));
  1553. }
  1554. if(!empty($entry->photo5)){
  1555. $entry->photo5Url=$this->GITDUrlDomain.$entry->photo5Url;
  1556. $xset->procInput(array('tzr_dc' => $oiddc,'tzr_lie' => $oiddc,'att_type' => $xset->desc['att_type']->target.':03-01-01',
  1557. 'LegendeRessource' => $entry->photo5Legende,'URL_img' => $entry->photo5Url,'Nom' => 'Photo 5'));
  1558. }
  1559. if(!empty($entry->photoHiver)){
  1560. $entry->photoHiverUrl=$this->GITDUrlDomain.$entry->photoHiverUrl;
  1561. $xset->procInput(array('tzr_dc' => $oiddc,'tzr_lie' => $oiddc,'att_type' => $xset->desc['att_type']->target.':03-01-01',
  1562. 'LegendeRessource' => $entry->legende,'URL_img' => $entry->photoHiverUrl,'Nom' => 'Photo hiver'));
  1563. }
  1564. if(!empty($entry->photoHiver2)){
  1565. $entry->photoHiver2Url=$this->GITDUrlDomain.$entry->photoHiver2Url;
  1566. $xset->procInput(array('tzr_dc' => $oiddc,'tzr_lie' => $oiddc,'att_type' => $xset->desc['att_type']->target.':03-01-01',
  1567. 'LegendeRessource' => $entry->legende2,'URL_img' => $entry->photoHiver2Url,'Nom' => 'Photo été'));
  1568. }
  1569. if(!empty($entry->logo)){
  1570. $entry->logoUrl=$this->GITDUrlDomain.$entry->logoUrl;
  1571. $xset->procInput(array('tzr_dc' => $oiddc,'tzr_lie' => $oiddc,'att_type' => $xset->desc['att_type']->target.':03-01-01',
  1572. 'URL_img' => $entry->logoUrl,'Nom' => 'Logo'));
  1573. }
  1574. if(!empty($entry->document)){
  1575. $entry->documentUrl=$this->GITDUrlDomain.$entry->documentUrl;
  1576. $xset->procInput(array('tzr_dc' => $oiddc,'tzr_lie' => $oiddc,'att_type' => $xset->desc['att_type']->target.':03-01-02',
  1577. 'URL' => $entry->documentUrl,'Nom' => 'Document'));
  1578. }
  1579. if(!empty($entry->documentPdf)){
  1580. $entry->documentPdfUrl=$this->GITDUrlDomain.$entry->documentPdfUrl;
  1581. $xset->procInput(array('tzr_dc' => $oiddc,'tzr_lie' => $oiddc,'att_type' => $xset->desc['att_type']->target.':03-01-02',
  1582. 'URL' => $entry->documentPdfUrl,'Nom' => 'Document PDF'));
  1583. }
  1584. }
  1585. /// Renseigne les descriptions complémentaires avec les données GITD
  1586. function GITDGetDescrComp($oiddc,&$entry,&$soap){
  1587. $xset=XDataSource::objectFactoryHelper8('BCLASS=XDSTable&SPECS='.$this->prefixSQL.'DDESCRCOMP');
  1588. if(!empty($entry->orientation)){
  1589. $xset->procInput(array('tzr_dc' => $oiddc,'tzr_lie' => $oiddc,'att_type' => $xset->desc['att_type']->target.':16-01-03',
  1590. 'att_Description_type' => $xset->desc['att_Description_type']->target.':16-02-101',
  1591. 'Description' => $entry->orientation));
  1592. }
  1593. if(!empty($entry->accescompl)){
  1594. $xset->procInput(array('tzr_dc' => $oiddc,'tzr_lie' => $oiddc,'att_type' => $xset->desc['att_type']->target.':16-01-03',
  1595. 'att_Description_type' => $xset->desc['att_Description_type']->target.':16-02-12',
  1596. 'Description' => $entry->accescompl));
  1597. }
  1598. if(!empty($entry->cueilcompl)){
  1599. $xset->procInput(array('tzr_dc' => $oiddc,'tzr_lie' => $oiddc,'att_type' => $xset->desc['att_type']->target.':16-01-03',
  1600. 'att_Description_type' => $xset->desc['att_Description_type']->target.':16-02-103',
  1601. 'Description' => $entry->cueilcompl));
  1602. }
  1603. if(!empty($entry->descenv)){
  1604. $xset->procInput(array('tzr_dc' => $oiddc,'tzr_lie' => $oiddc,'att_type' => $xset->desc['att_type']->target.':16-01-03',
  1605. 'att_Description_type' => $xset->desc['att_Description_type']->target.':16-02-102',
  1606. 'Description' => $entry->descenv));
  1607. }
  1608. }
  1609. /// Renseigne les prestations en rapport avec le ski
  1610. function GITDGetPrestaSki($oiddc,&$entry,&$soap){
  1611. if(!empty($entry->lgAlpin) || !empty($entry->nbNoir) || !empty($entry->nbRouge) || !empty($entry->nbBleu) || !empty($entry->nbVert) || !empty($entry->nbTelecab) || !empty($entry->nbTelesie) || !empty($entry->nbTeleski) || !empty($entry->lgFond)){
  1612. $xset=XDataSource::objectFactoryHelper8('BCLASS=XDSTable&SPECS='.$this->prefixSQL.'DOFFREPRESTA');
  1613. $ret=$xset->procInput(array('tzr_dc' => $oiddc,'tzr_lie' => $oiddc,'att_type' => $xset->desc['att_type']->target.':15-05'));
  1614. if(!empty($entry->lgAlpin) || !empty($entry->nbNoir) || !empty($entry->nbRouge) || !empty($entry->nbBleu) || !empty($entry->nbVert)){
  1615. $tot=$entry->nbNoir+$entry->nbRouge+$entry->nbBleu+$entry->nbVert;
  1616. $xset=XDataSource::objectFactoryHelper8('BCLASS=XDSTable&SPECS='.$this->prefixSQL.'DPRESTA');
  1617. $xset->procInput(array('tzr_dc' => $oiddc,'tzr_lie' => $ret['oid'],'Prestation' => $xset->desc['Prestation']->target.':15-05-78',
  1618. 'NbPrest' => $tot,'Distance' => $entry->lgAlpin,
  1619. 'att_Distance_unite' => $xset->desc['att_Distance_unite']->target.':01-03-02-01'));
  1620. }
  1621. if(!empty($entry->lgFond)){
  1622. $xset=XDataSource::objectFactoryHelper8('BCLASS=XDSTable&SPECS='.$this->prefixSQL.'DPRESTA');
  1623. $xset->procInput(array('tzr_dc' => $oiddc,'tzr_lie' => $ret['oid'],'Prestation' => $xset->desc['Prestation']->target.':15-05-79',
  1624. 'Distance' => $entry->lgFond,'att_Distance_unite' => $xset->desc['att_Distance_unite']->target.':01-03-02-01'));
  1625. }
  1626. if(!empty($entry->nbTelecab) || !empty($entry->nbTelesie) || !empty($entry->nbTeleski)){
  1627. $tot=$entry->nbTelecab+$entry->nbTelesie+$entry->nbTeleski;
  1628. $xset=XDataSource::objectFactoryHelper8('BCLASS=XDSTable&SPECS='.$this->prefixSQL.'DPRESTA');
  1629. $xset->procInput(array('tzr_dc' => $oiddc,'tzr_lie' => $ret['oid'],'Prestation' => $xset->desc['Prestation']->target.':15-05-194',
  1630. 'NbPrest' => $tot));
  1631. }
  1632. }
  1633. }
  1634. /// Recupere les infos d'une comune via son identifiant
  1635. function GITDGetCommune($id,$soap=NULL){
  1636. if(empty($id)) return (object)array('nom' => '');
  1637. if(empty($soap)) {
  1638. ini_set('soap.wsdl_cache_enabled', 0);
  1639. try {
  1640. $soap = new SoapClient($this->GITDUrl, array('exceptions' => true));
  1641. } catch (SoapFault $e) {
  1642. echo "Soap Error : " . $e->faultcode . ', ' . $e->faultstring ."\n";
  1643. XLogs::critical('ModTif::GITDGetCommune', "Soap Error : " . $e->faultcode . ', ' . $e->faultstring );
  1644. return false;
  1645. }
  1646. }
  1647. $com=$soap->get(array('arg0' => $this->GITDLogin,'arg1' => $this->GITDPwd,'arg2' => "Ejb3Com",'arg3' => $id));
  1648. return $com->return;
  1649. }
  1650. /// Transforme un code V2 en code V3, et le créé s'il n'existe pas
  1651. function V2toV3($table,$value){
  1652. if(empty($value) || empty($table)) return NULL;
  1653. $ret=array();
  1654. $vs=is_array($value)?$value:array($value);
  1655. foreach($vs as $v){
  1656. if(empty($v)){
  1657. $ret[]='';
  1658. continue;
  1659. }
  1660. if(preg_match('/^[A-Z0-9]+$/i',$v)){
  1661. $rs=&selectQuery('select distinct KOID from '.$table.' where codesv2 like "%|'.$v.'|%" or codesv2="'.$v.'"');
  1662. if($ors=$rs->fetch()) {
  1663. $ret[]=$ors['KOID'];
  1664. }else{
  1665. $xset=XDataSource::objectFactoryHelper8('BCLASS=XDSTable&SPECS='.$table);
  1666. $ret2=$xset->procInput(array('code' => $v,'libelle' => $v,'codesv2' => $v,'newoid' => $table.':GITD_'.$v));
  1667. $ret[]=$ret2['oid'];
  1668. }
  1669. }else{
  1670. $ret[]=$table.':'.str_replace('.','-',$v);
  1671. }
  1672. }
  1673. if(is_array($value)) return $ret;
  1674. else return $ret[0];
  1675. }
  1676. /// Fonction d'import SITRA
  1677. function SITRAImport($sched, $o=NULL, $more=NULL) {
  1678. XLogs::notice('ModTif::SITRAImport', 'start import');
  1679. $this->NSURI=$this->SITRANSUri;
  1680. $params=XSystem::xml2array($this->SITRADirs);
  1681. foreach($params as $rechname => $dir){
  1682. $this->acttype='SITRA ('.$rechname.')';
  1683. $list=array();
  1684. $list2=array();
  1685. $fdir=opendir($dir);
  1686. // Liste les fichiers à traiter et les tri par date de création
  1687. while($file=readdir($fdir)) {
  1688. $matches=array();
  1689. if(is_file($dir.$file)){
  1690. if(preg_match($this->SITRAExportFileRegex,$file,$matches) || preg_match($this->SITRADelFileRegex,$file,$matches))
  1691. $list[filemtime($dir.$file)][]=$file;
  1692. elseif(preg_match($this->SITRASelectionsFileRegex,$file,$matches))
  1693. $list2[filemtime($dir.$file)][]=$file;
  1694. elseif(preg_match($this->SITRAImagesFileRegex,$file))
  1695. if ($more->keep_files)
  1696. rename($dir.$file, TZR_VAR2_DIR.'sitra_backup/'.$file);
  1697. else
  1698. unlink($dir.$file);
  1699. }
  1700. }
  1701. ksort($list);
  1702. // Traite les imports et les suppressions
  1703. if ($more->keep_files)
  1704. @mkdir(TZR_VAR2_DIR.'sitra_backup/');
  1705. foreach($list as $mfiles){
  1706. foreach($mfiles as $file){
  1707. XLogs::notice('ModTif::SITRAImport', "processing $file");
  1708. $msg .= "processing $file\n";
  1709. $i++;
  1710. echo $i.' : '.$file.'...';
  1711. if(preg_match($this->SITRAExportFileRegex,$file)){
  1712. $this->_import(array('file' => $dir.$file));
  1713. }elseif(preg_match($this->SITRADelFileRegex,$file)){
  1714. $content=file_get_contents($dir.$file);
  1715. $dom=new DOMDocument();
  1716. $dom->preserveWhiteSpace=false;
  1717. $dom->validateOnParse = true;
  1718. $dom->loadXML($content);
  1719. $xpath=new DOMXpath($dom);
  1720. $todels=$xpath->query('/ListeOI/identifier');
  1721. foreach($todels as $todel){
  1722. $oid=$this->prefixSQL.'DC:'.preg_replace('/[^a-z0-9_-]/i','_',$todel->textContent);
  1723. XLogs::notice('ModTif::SITRAImport', "deleting $oid");
  1724. $this->del(array('oid' => $oid,'_options' => array('local' => true),'_nolog' => true));
  1725. }
  1726. }
  1727. if ($more->keep_files)
  1728. rename($dir.$file, TZR_VAR2_DIR.'sitra_backup/'.$file);
  1729. else
  1730. unlink($dir.$file);
  1731. }
  1732. }
  1733. foreach($list2 as $mfiles2){
  1734. foreach($mfiles2 as $file2){
  1735. XLogs::notice('ModTif::SITRAImport', "processing $file2 for selection");
  1736. $msg .= "processing $file2 for selection\n";
  1737. $xssels = XDataSource::objectFactoryHelper8('BCLASS=XDSTable&SPECS='.$this->prefixSQL.'LS_Selections');
  1738. $content=file_get_contents($dir.$file2);
  1739. $dom=new DOMDocument();
  1740. $dom->preserveWhiteSpace=false;
  1741. $dom->validateOnParse = true;
  1742. $dom->loadXML($content);
  1743. $xpath=new DOMXpath($dom);
  1744. $sels=$xpath->query('/Selections/Selection');
  1745. $selstorec=array();
  1746. foreach($sels as $sel){
  1747. $ar=array();
  1748. $ar['tplentry']=TZR_RETURN_DATA;
  1749. foreach($sel->attributes as $selatt){
  1750. $attname = $selatt->name;
  1751. $attfield = 'att_'.$attname;
  1752. if(isset($xssels->desc[$attfield])){
  1753. $value=$selatt->value;
  1754. $ar[$attfield]=$value;
  1755. if($attname == 'code')
  1756. $oid=$this->prefixSQL.'LS_Selections:'.$value;
  1757. }
  1758. }
  1759. $rcss = countSelectQuery('select count(*) from '.$this->prefixSQL.'LS_Selections where KOID="'.$oid.'" limit 1');
  1760. if($rcss > 0){
  1761. $ar['oid']=$oid;
  1762. $xssels->procEdit($ar);
  1763. }else{
  1764. $ar['newoid']=$oid;
  1765. $xssels->procInput($ar);
  1766. }
  1767. foreach($sel->childNodes as $node){
  1768. $dcoid=$this->prefixSQL.'DC:'.preg_replace('/[^a-z0-9_-]/i','_',$node->nodeValue);
  1769. $selstorec[$dcoid][]=$oid;
  1770. }
  1771. }
  1772. foreach($selstorec as $oiddc => $asels){
  1773. $rcdc = countSelectQuery('select count(*) from '.$this->table.' where KOID="'.$oiddc.'" limit 1');
  1774. if($rcdc){
  1775. $this->procEdit(array('tplentry' => TZR_RETURN_DATA,'oid' => $oiddc,'dc__selection' => implode('||',$asels)));
  1776. }
  1777. }
  1778. if (@$more->keep_files)
  1779. rename($dir.$file2, TZR_VAR2_DIR.'sitra_backup/'.$file2);
  1780. else
  1781. unlink($dir.$file2);
  1782. }
  1783. }
  1784. }
  1785. if (is_object($sched))
  1786. $sched->setStatusJob($o->KOID, 'finished', $msg);
  1787. else
  1788. echo $msg;
  1789. XLogs::notice('ModTif::SITRAImport', 'end import');
  1790. }
  1791. /// Fonction addslashes recurcive
  1792. function recursiveAddslashes(&$obj){
  1793. foreach($obj as &$val){
  1794. if(is_array($val) || is_object($val)) $this->recursiveAddslashes($val);
  1795. else $val=$val;
  1796. }
  1797. }
  1798. /**
  1799. Export au format TiF.
  1800. format : string : retourne la chaine xml (si une ressource) ou tableau de chaine xml (si pls ressources)
  1801. file : fichier xml (si une ressource) ou zip de xml (si pls ressources)
  1802. attachment : true + format file + une ressource => retourne le fichier attaché, sinon ne sert à rien
  1803. **/
  1804. function exportTiF($ar){
  1805. $p=new XParam($ar,array('format' => 'string','attachment' => false));
  1806. $oids=$p->get('_selected');
  1807. $format=$p->get('format');
  1808. $attachment=$p->get('attachment');
  1809. $selectedok=$p->get('_selectedok');
  1810. $oids=array_keys($oids);
  1811. if(($selectedok!='ok') || empty($oids)) $oids=$p->get('oid');
  1812. if(!is_array($oids)) $oids=array($oid);
  1813. $file='<?xml version="1.0" encoding="'.TZR_INTERNAL_CHARSET.'"?>';
  1814. $this->prepareParam();
  1815. $ret=array();
  1816. foreach($oids as $oid){
  1817. $file='<'.$this->makeBaliseName('OI').' xmlns="http://www.xsalto.com" xmlns:dc="http://purl.org/dc/elements/1.1/" '.
  1818. 'xmlns:dcterms="http://purl.org/dc/terms/" xmlns:xsalto="http://www.xsalto.com">';
  1819. $file.=$this->exportDC($oid); // Dublin Core
  1820. $file.=$this->exportMultimedia($oid); // Multimédia
  1821. $file.=$this->exportContacts($oid); // Contacts (Adresses - Personnes - Moyens de communications)
  1822. $file.=$this->exportInfosLegales($oid); // Informations légales
  1823. $file.=$this->exportClassements($oid); // Classements
  1824. $file.=$this->exportGeolocs($oid); // Geolocalisation (Zones - Points - Coords - Envs - Cartes - Acces - Multimédia)
  1825. $file.=$this->exportPeriodes($oid); // Periodes (Dates - Details jours - Jours - Horaires)
  1826. $file.=$this->exportClienteles($oid); // Clientèles (Details client)
  1827. $file.=$this->exportUsages($oid); // Usages/Langues
  1828. $file.=$this->exportModesResa($oid); // Modes de réservation
  1829. $file.=$this->exportCapacites($oid); // Capacités
  1830. $file.=$this->exportOffresPresta($oid); // Offres de prestation (Prestations)
  1831. $file.=$this->exportTarifs($oid); // Tarifs et modes de paiement
  1832. $file.=$this->exportDescrComp($oid); // Descriptions complémentaires
  1833. $file.=$this->exportItineraires($oid); // Itinéraires
  1834. $file.=$this->exportPlannings($oid); // Plannings (Presta planning - Jour planning)
  1835. $file.=$this->exportPresationsLiees($oid); // Prestations liées
  1836. $file.=$this->exportOther($oid); // Fonctions à personnaliser
  1837. $file.='</'.$this->makeBaliseName('OI').'>';
  1838. $ret[$oid]=$file;
  1839. }
  1840. if($format=='string'){
  1841. if(count($ret)<2) return $ret[$oids[0]];
  1842. else return $ret;
  1843. }elseif($format=='file'){
  1844. if(count($ret)<2){
  1845. ob_clean();
  1846. header('Content-Type:text/xml; charset='.TZR_INTERNAL_CHARSET);
  1847. header('Content-Transfer-Encoding:'.TZR_INTERNAL_CHARSET);
  1848. header('Content-Length:'.strlen($ret[$oids[0]]));
  1849. header('Pragma:private');
  1850. header('Cache-Control:no-cache, must-revalidate');
  1851. if($attachment) header('Content-disposition: attachment; filename=exporttif-'.$oids[0].'.xml');
  1852. header('Expires: 0');
  1853. echo $ret[$oids[0]];
  1854. exit(0);
  1855. }else{
  1856. foreach($ret as $oid => $file){
  1857. $dir=TZR_TMP_DIR.'exporttif'.uniqid();
  1858. @mkdir($dir);
  1859. file_put_contents($dir.'/exporttif-'.$oid.'.xml',$file);
  1860. }
  1861. exec('(cd '.$dir.'; zip -r '.$dir.'.zip .)2>&1 > '.TZR_TMP_DIR.'errorlog');
  1862. $size=filesize($dir.'.zip');
  1863. header('Content-type: application/zip');
  1864. header('Content-disposition: attachment; filename=exporttif.zip');
  1865. header('Accept-Ranges: bytes');
  1866. header('Content-Length: '.$size);
  1867. @readfile($dir.'.zip');
  1868. XDir::unlink($dir);
  1869. unlink($dir.'.zip');
  1870. exit(0);
  1871. }
  1872. }
  1873. }
  1874. function exportDC($oid){
  1875. return $this->exportGranule($oid,$this->structparam['dc']);
  1876. }
  1877. function exportMultimedia($oid){
  1878. return $this->exportGranule($oid,$this->structparam['mu']);
  1879. }
  1880. function exportContacts($oid){
  1881. return $this->exportGranule($oid,$this->structparam['co']);
  1882. }
  1883. function exportInfosLegales($oid){
  1884. return $this->exportGranule($oid,$this->structparam['il']);
  1885. }
  1886. function exportClassements($oid){
  1887. return $this->exportGranule($oid,$this->structparam['cl']);
  1888. }
  1889. function exportGeolocs($oid){
  1890. return $this->exportGranule($oid,$this->structparam['ge']);
  1891. }
  1892. function exportPeriodes($oid){
  1893. return $this->exportGranule($oid,$this->structparam['pe']);
  1894. }
  1895. function exportClienteles($oid){
  1896. return $this->exportGranule($oid,$this->structparam['cli']);
  1897. }
  1898. function exportUsages($oid){
  1899. return $this->exportGranule($oid,$this->structparam['la']);
  1900. }
  1901. function exportModesResa($oid){
  1902. return $this->exportGranule($oid,$this->structparam['mr']);
  1903. }
  1904. function exportCapacites($oid){
  1905. $ret='<'.$this->makeBaliseName('Capacites').'>';
  1906. $d=$this->xset->display(array('oid' => $oid,'tplentry' => TZR_RETURN_DATA));
  1907. $ret.=$this->exportGranule($d['oCapacitesGlobales']->raw,array('balisegroup' => NULL,
  1908. 'balises' => array('CapacitesGlobales' => array('table' => 'CAPAGLOB',
  1909. 'fssm' => 'KOID',
  1910. 'ssm' => $this->structparam['cs']))));
  1911. $ret.=$this->exportGranule($oid,$this->structparam['cp']);
  1912. $ret.=$this->exportGranule($oid,$this->structparam['cu']);
  1913. $ret.='</'.$this->makeBaliseName('Capacites').'>';
  1914. return $ret;
  1915. }
  1916. function exportOffresPresta($oid){
  1917. return $this->exportGranule($oid,$this->structparam['op']);
  1918. }
  1919. function exportTarifs($oid){
  1920. $lang=XLang::getLocale();
  1921. $lang=$lang['code'];
  1922. $ret='<'.$this->makeBaliseName('Tarifs').'>';
  1923. $ret.='<'.$this->makeBaliseName('ModesPaiement').'>';
  1924. $d=$this->xset->display(array('oid' => $oid,'tplentry' => TZR_RETURN_DATA));
  1925. $bn=$this->makeBaliseName('ModePaiement');
  1926. foreach($d['oModePaiement']->oidcollection as $i => $oid2){
  1927. $ret.='<'.$bn.' type="'.$d['oModePaiement']->collection[$i]->link['ocode']->raw.'" xml:lang="'.$lang.'">'.
  1928. $d['oModePaiement']->collection[$i]->link['olibelle']->raw.'</'.$bn.'>';
  1929. }
  1930. $bn=$this->makeBaliseName('ObservationModePaiement');
  1931. $ret.='<'.$bn.'>'.$d['oObservationModePaiement']->text.'</'.$bn.'>';
  1932. $ret.='</'.$this->makeBaliseName('ModesPaiement').'>';
  1933. $ret.=$this->exportGranule($oid,$this->structparam['ta']);
  1934. $ret.='</'.$this->makeBaliseName('Tarifs').'>';
  1935. return $ret;
  1936. }
  1937. function exportDescrComp($oid){
  1938. return $this->exportGranule($oid,$this->structparam['desc']);
  1939. }
  1940. function exportItineraires($oid){
  1941. return $this->exportGranule($oid,$this->structparam['it']);
  1942. }
  1943. function exportPlannings($oid){
  1944. return $this->exportGranule($oid,$this->structparam['pla']);
  1945. }
  1946. function exportPresationsLiees($oid){
  1947. return $this->exportGranule($oid,$this->structparam['pliee']);
  1948. }
  1949. function exportOther(&$oi,$oiddc){
  1950. }
  1951. function exportGranule($oidssm,$params){
  1952. if(isset($params['balises'])) $params=array($params);
  1953. $oids=array();
  1954. $ret='';
  1955. $lang=XLang::getLocale();
  1956. $lang=$lang['code'];
  1957. foreach($params as $param){
  1958. $balisegrp=$param['balisegroup'];
  1959. $balises=$param['balises'];
  1960. if(!empty($balisegrp)) $ret.='<'.$this->makeBaliseName($balisegrp).'>';
  1961. foreach($balises as $balise => $data){
  1962. $table=$data['table'];
  1963. $fssm=isset($data['fssm'])?$data['fssm']:'KOID';
  1964. $direct=isset($data['direct'])?$data['direct']:false;
  1965. $delNS=isset($data['delNS'])?$data['delNS']:true;
  1966. $notexport=isset($data['notexport'])?$data['notexport']:array();
  1967. $linkparam=isset($data['linkparam'])?$data['linkparam']:array();
  1968. $xset=XDataSource::objectFactoryHelper8('BCLASS=XDSTable&SPECS='.$this->prefixSQL.$table);
  1969. $cond=isset($data['exportcond'])?$data['exportcond']:array($fssm => array('LIKE',"%$oidssm%"));
  1970. $cond=$xset->select_query(array('cond' => $cond));
  1971. $br=$xset->browse(array('select' => $cond,'tplentry' => TZR_RETURN_DATA,'selectedfields' => 'all'));
  1972. foreach($br['lines_oid'] as $i => $oid){
  1973. if(!isset($this->alreadyexport[$oid])){
  1974. $values=array();
  1975. $att='';
  1976. foreach($xset->desc as $fn => &$fo){
  1977. if(strpos($fn,'tzr_')===0 || strpos($fn,'gitd_')===0 || $fo->sys || in_array($fn,$notexport)) continue;
  1978. $value=$cpltatt='';
  1979. switch($fo->ftype){
  1980. case 'XLinkDef':
  1981. if(strpos($fo->target,$this->prefixSQL.'LS_')===0){
  1982. $tmp=$this->withCodeAttr;
  1983. if(in_array($table,$tmp['table']) || in_array(str_replace($this->prefixSQL,'',$fo->target),$tmp['target']))
  1984. $typename='code';
  1985. else
  1986. $typename='type';
  1987. if(strpos($fn,'att_')!==0){
  1988. $value=trim($br['lines_o'.$fn][$i]->link['libelle']);
  1989. $myatt=trim($br['lines_o'.$fn][$i]->link['code']);
  1990. if(!empty($myatt)) $cpltatt.=' '.$typename.'="'.$myatt.'"';
  1991. }else{
  1992. $value=trim($br['lines_o'.$fn][$i]->link['code']);
  1993. $myatt=trim($br['lines_o'.$fn][$i]->link['libelle']);
  1994. if(!empty($myatt)) $cpltatt.=' libelle="'.$myatt.'"';
  1995. }
  1996. if($br['lines_o'.$fn][$i]->link['olibelle']->fielddef->translatable && strpos($cpltatt,'xml:lang'))
  1997. $cpltatt.=' xml:lang="'.$lang.'"';
  1998. }else{
  1999. if($fo->multivalued){
  2000. $value='';
  2001. foreach($br['lines_o'.$fn][$i]->oidcollection as $loid)
  2002. $value.=$this->exportGranule($loid,$linkparam[$fn]);
  2003. }elseif(!empty($br['lines_o'.$fn][$i]->raw))
  2004. $value=$this->exportGranule($br['lines_o'.$fn][$i]->raw,$linkparam[$fn]);
  2005. }
  2006. break;
  2007. case 'XFileDef':
  2008. $value=trim($br['lines_o'.$fn.'_url'][$i]->text);
  2009. break;
  2010. case 'XBoolDef':
  2011. $value=($br['lines_o'.$fn][$i]->raw==1)?'O':'N';
  2012. break;
  2013. default:
  2014. if($fo->multivalued) $value=explode(',',trim($br['lines_o'.$fn][$i]->text));
  2015. else $value=trim($br['lines_o'.$fn][$i]->text);
  2016. break;
  2017. }
  2018. if(strpos($fn,'att_')!==0){
  2019. $values[$fn]['value']=$value;
  2020. if(empty($values[$fn]['att'])) $values[$fn]['att']=$cpltatt;
  2021. if($fo->translatable && strpos($values[$fn]['att'],'xml:lang')) $values[$fn]['att'].=' xml:lang="'.$lang.'"';
  2022. }else{
  2023. preg_match("/^att_(.+)_(.+)$/",$fn,$matches);
  2024. if(empty($matches[2]) || $fn=='att_lib_jour'){
  2025. preg_match("/^att_(.+)$/",$fn,$matches);
  2026. if(!empty($value)) $att.=' '.$matches[1].'="'.$value.'"'.$cpltatt;
  2027. else $att.=$cpltatt;
  2028. }else{
  2029. if(empty($values[$matches[1]]['att'])) $values[$matches[1]]['att']='';
  2030. if(!empty($value)) $values[$matches[1]]['att'].=' '.$matches[2].'="'.$value.'"'.$cpltatt;
  2031. else $values[$matches[1]]['att'].=$cpltatt;
  2032. }
  2033. }
  2034. }
  2035. $this->alreadyexport[$oid]=$att;
  2036. $att.=' id="'.$oid.'"';
  2037. if(!$direct) $ret.='<'.$this->makeBaliseName($balise).$att.'>';
  2038. foreach($values as $b => $v){
  2039. if(!is_array($v['value'])) $v['value']=array($v['value']);
  2040. foreach($v['value'] as $val){
  2041. $bn=$this->makeBaliseName($b,$delNS);
  2042. if(!isset($linkparam[$b])) $ret.='<'.$bn.$v['att'].'>'.$val.'</'.$bn.'>';
  2043. else $ret.=$val;
  2044. }
  2045. }
  2046. $ret.=$this->exportGranule($oid,$data['ssm']);
  2047. if(!$direct) $ret.='</'.$this->makeBaliseName($balise).'>';
  2048. }else{
  2049. $ret.='<'.$this->makeBaliseName($balise).' idref="'.$oid.'"'.$this->alreadyexport[$oid].'>'.
  2050. '</'.$this->makeBaliseName($balise).'>';
  2051. }
  2052. }
  2053. }
  2054. if(!empty($balisegrp)) $ret.='</'.$this->makeBaliseName($balisegrp).'>';
  2055. }
  2056. return $ret;
  2057. }
  2058. /// Créé un nom de balise avec le namespace pour l'export
  2059. function makeBaliseName($balise,$delNS=true){
  2060. if($delNS) return 'xsalto:'.$balise;
  2061. else return str_replace('__',':',$balise);;
  2062. }
  2063. /// Importe les fichiers de nomenclature
  2064. function importNomenclature($ar=NULL){
  2065. global $LIBTHEZORRO;
  2066. $dir=$LIBTHEZORRO.'contrib/tourinfrance/';
  2067. $dd=opendir($dir.'nomenclatures/');
  2068. while($file=readdir($dd)) {
  2069. if(is_file($dir.'nomenclatures/'.$file) && preg_match("/^nomenclature_([a-zA-Z0-9_]*)\.csv$/",$file,$ret)){
  2070. $lines=file($dir.'nomenclatures/'.$file);
  2071. $xset=XDataSource::objectFactoryHelper8('BCLASS=XDSTable&SPECS='.$this->prefixSQL.$ret[1]);
  2072. foreach($lines as $i => $line){
  2073. $data=explode(';',rtrim($line));
  2074. if(!empty($data[0])) $oid=$this->prefixSQL.$ret[1].':'.str_replace('.','-',$data[0]);
  2075. else $oid=$this->prefixSQL.$ret[1].':GITD_'.$data[2];
  2076. if(isset($xset->desc['codesv2'])){
  2077. updateQuery('insert ignore into '.$this->prefixSQL.$ret[1].' (KOID,LANG,UPD,code,libelle,codesv2) '.
  2078. 'values("'.$oid.'","'.TZR_DEFAULT_LANG.'",NOW(),"'.$data[0].'","'.addslashes($data[1]).'","'.$data[2].'")');
  2079. }else{
  2080. updateQuery('insert ignore into '.$this->prefixSQL.$ret[1].' (KOID,LANG,UPD,code,libelle) '.
  2081. 'values("'.$oid.'","'.TZR_DEFAULT_LANG.'",NOW(),"'.$data[0].'","'.addslashes($data[1]).'")');
  2082. }
  2083. if($xset->getTranslatable() && $xset->getAutoTranslate()) {
  2084. $xk=new Kernel;
  2085. $xk->data_autoTranslate($oid);
  2086. }
  2087. }
  2088. }
  2089. }
  2090. }
  2091. /// Check différents points sur l'ensemble de modules
  2092. function chk($message){
  2093. /// Dans le cas de GITD, la nomenclature doit etre présente
  2094. if(in_array('GITD',$this->type)) $this->importNomenclature();
  2095. }
  2096. }
  2097. ?>