PageRenderTime 55ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 1ms

/class.xmoditea.inc

https://github.com/jcplat/console-seolan
PHP | 1551 lines | 1347 code | 61 blank | 143 comment | 255 complexity | 4f5a627689d8246c038f5d1a4935c678 MD5 | raw file
Possible License(s): LGPL-2.0, LGPL-2.1, GPL-3.0, Apache-2.0, BSD-3-Clause

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. class XModItea extends XModTable {
  3. private $_cache;
  4. public $submodmax = 12;
  5. public $directsubdata;
  6. public $descrType;
  7. public $animauxok;
  8. public $restook;
  9. public $delparam = array(); // Parametres à passer au del sur import (pour empecher suppression des photo par ex) : cle => dpt, val => param
  10. public $prefix = 'ITEA_';
  11. public $exercice; // Exercice en cours d'import
  12. function __construct($ar = NULL) {
  13. parent::__construct($ar);
  14. $this->directsubdata = array(
  15. $this->prefix.'DETAILSOFREF' => array('situation', 'tourismeEtHandicap'),
  16. $this->prefix.'CONTACT' => array('siteWeb', 'languesParlees'),
  17. $this->prefix.'CHAMBRE' => array('description'),
  18. $this->prefix.'SUPPLEMENT' => array('description'));
  19. $this->directuniquesubdata=array(
  20. $this->prefix.'DETAILSOFREF' => array('descriptif' => 'description', 'descriptifTechnique' => 'description', 'descriptifCommercial' => 'description'));
  21. $this->descrType = array(
  22. 'link' => array('INFO_TOUR', 'INFO_TOUR_ACTIV_OT', 'THEME', 'RUBRIQUE', 'RUBRIQUE_GENE'),
  23. //'no' => array('INFO_TOUR'),
  24. 'tables' => array($this->prefix.'INFOTOUR', $this->prefix.'THEME', $this->prefix.'RUBRIQUE'),
  25. 'fields' => array('theme' => 'theme', 'rubrique' => 'rubrique', 'rubrique_gene' => 'rubrique',
  26. 'info_tour_activ_ot' => 'info_tour_activ_ot', 'info_tour' => 'info_tour_activ_ot'),
  27. // champ => valeurs passées a analyseObject
  28. 'cplt' => array('rubrique_gene' => array('general' => 1)),
  29. 'notlink' => array(/*'rubrique_gene'*/)
  30. );
  31. $this->animauxok = $this->prefix.'CARACTERISTIQUE:O-40-';
  32. $this->restook = $this->prefix.'CARACTERISTIQUE:O-46-';
  33. XLabels::loadLabels('xmoditea');
  34. }
  35. public function initOptions() {
  36. parent::initOptions();
  37. $this->_options->setOpt('Prefix', 'prefix', 'text');
  38. $this->_options->setOpt('Liste des départements (séparateur ,)', 'dpts', 'text');
  39. $p1 = XModule::findParam($this->_moid);
  40. $dpts = explode(', ', $p1['MPARAM']['dpts']);
  41. $conf = $GLOBALS['ITEACONF'][$p1['MPARAM']['table']];
  42. $this->_options->setOpt('Consolidation des caractéristiques','needconscaract','boolean',false,NULL);
  43. foreach ($dpts as $dpt) {
  44. if (!empty($dpt)) {
  45. $this->_options->setOpt($dpt.' : Adresse service SOAP',$dpt.'soap','text',NULL,$conf[$dpt]['soap']);
  46. $this->_options->setOpt($dpt.' : Adresse service SOAP XS (xsalto)',$dpt.'soap_xs','text',NULL,$conf[$dpt]['soap_xs']);
  47. $this->_options->setOpt($dpt.' : Environnement', $dpt.'env', 'text', NULL, $conf[$dpt]['env']);
  48. $this->_options->setOpt($dpt.' : Login', $dpt.'login', 'text', NULL, $conf[$dpt]['login']);
  49. $this->_options->setOpt($dpt.' : Password', $dpt.'pass', 'text', NULL, $conf[$dpt]['pass']);
  50. $this->_options->setOpt($dpt.' : Langues (tzr=>itea, séparateur ,)', $dpt.'langs', 'text', NULL, 'FR=>FRANCAIS');
  51. }
  52. }
  53. }
  54. /// securite des fonctions accessibles par le web
  55. function secGroups($function, $group = NULL) {
  56. $g = array();
  57. $g['manuelImportFromITEA'] = array('admin');
  58. $g['importFromITEA'] = array('admin');
  59. $g['importDispoFromITEA'] = array('admin');
  60. $g['executeAllConsolidation'] = array('admin');
  61. $g['duplicateRubToRubGlob'] = array('admin');
  62. $g['importFromOtherBase'] = array('admin');
  63. $g['importDispoFromOtherBase'] = array('admin');
  64. if (isset($g[$function])) {
  65. if (!empty($group)) return in_array($group, $g[$function]);
  66. return $g[$function];
  67. }
  68. return parent::secGroups($function, $group);
  69. }
  70. function _daemon($period = 'any') {
  71. // Vide le cache des requetes de dispo datant de plus de 2 heures
  72. updateQuery('delete from '.$this->prefix.'DISPOREQ where UPD<date_add(now(), interval -2 hour)');
  73. /// TODO: disparition des options
  74. // $dir=$GLOBALS['LIBTHEZORRO'].'contrib/itea/';
  75. // if ($period == 'daily') {
  76. // // Importe les champs afin de maintenir à jour le format des tables
  77. // $mod_ds = new XModDataSource();
  78. // $mod_ds->importFields(array('file'=>$dir.'fields.csv','prefixSQL'=>$this->prefix,'endofline'=>"\n"));
  79. // $mod_ds->importFields(array('file'=>$dir.'nomenclature_fields.csv','prefixSQL'=>$this->prefix,'endofline'=>"\n"));
  80. // }
  81. }
  82. function insert($ar) {
  83. // En saisie manuelle, on fixe une date itea vieille pour ne pas gener un eventuel import
  84. $ar['options']['upditea']['value'] = '2000-01-01';
  85. return parent::insert($ar);
  86. }
  87. function procInsert($ar = NULL) {
  88. // L'oid est forcé
  89. $p = new XParam($ar, NULL);
  90. $ref = $p->get('reference');
  91. $dpt = $p->get('dpt');
  92. $ar['newoid'] = $this->getOid($dpt, $ref);
  93. return parent::procInsert($ar);
  94. }
  95. /// Retourne l'oid d'une reference dans un departement (le departement peut etre son numero ou son oid)
  96. function getOid($dpt, $ref) {
  97. $dpt = substr($dpt, -2);
  98. if (substr($ref, 0, 3) != $dpt.'_')
  99. return $this->table.':'.$dpt.'_'.rewriteToAscii(trim($ref), false);
  100. else
  101. return $this->table.':'.rewriteToAscii(trim($ref), false);
  102. }
  103. /// Rend vrai si la table en question est utilisée dans le module en question
  104. public function usesTable($table) {
  105. return in_array($table, $this->allTables());
  106. }
  107. /// Tables de nomenclature/communes
  108. public function nomenclatureTables() {
  109. return array(
  110. $this->prefix.'CHOIX_ON', $this->prefix.'TYPEPRODUIT', $this->prefix.'TYPEPIECE',
  111. $this->prefix.'TYPEGESTION', $this->prefix.'TYPELANGUE', $this->prefix.'TYPELIT',
  112. $this->prefix.'TYPECONTACT', $this->prefix.'TYPEURL', $this->prefix.'TYPEPARAMETRE',
  113. $this->prefix.'TYPECARACTERISTIQUE', $this->prefix.'TYPETARIF', $this->prefix.'TYPEDUREETARIF',
  114. $this->prefix.'TYPECHAMBRE', $this->prefix.'TYPECHARGE', $this->prefix.'TYPEDESCRIPTION',
  115. $this->prefix.'DPT', $this->prefix.'INSEE', $this->prefix.'CONSLOISIRS',
  116. $this->prefix.'CARACTERISTIQUE', $this->prefix.'RUBRIQUE', $this->prefix.'RUBRIQUE2',
  117. $this->prefix.'THEME', $this->prefix.'THEME2',
  118. $this->prefix.'INFOTOUR', $this->prefix.'INFOTOUR2', $this->prefix.'PL');
  119. }
  120. /// Tables de nomenclature/communes
  121. public function nomenclatureTablesDpt() {
  122. return array(
  123. 'INFOTOUR', $this->prefix.'INSEE',
  124. $this->prefix.'RUBRIQUE', $this->prefix.'RUBRIQUE2', $this->prefix.'THEME',
  125. $this->prefix.'THEME2', $this->prefix.'INFOTOUR', $this->prefix.'INFOTOUR2');
  126. }
  127. /// Tables objet
  128. function objectTables() {
  129. return array(
  130. $this->prefix.'ADR', $this->prefix.'ALBPHOTOINT', $this->prefix.'CHAMBRE',
  131. $this->prefix.'CONTACT', $this->prefix.'DESCRIPTION', $this->prefix.'DETAILSOFREF',
  132. $this->prefix.'LOISIRS', $this->prefix.'PARAMETRE', $this->prefix.'PERIOD',
  133. $this->prefix.'PERIODPROMO', $this->prefix.'PIECE', $this->prefix.'PROMO',
  134. $this->prefix.'SUPPLEMENT', $this->prefix.'TARIF', $this->prefix.'AGREMENT');
  135. }
  136. /// Tables de consolidation
  137. function consolidateTables() {
  138. return array($this->prefix.'CONSCARAC', $this->prefix.'CONSDISTLOISIRS');
  139. }
  140. /// Tables contenant les dispo
  141. function dispoTables() {
  142. return array($this->prefix.'DISPOGEN', $this->prefix.'DISPOREQ');
  143. }
  144. /// Toutes les tables
  145. public function allTables() {
  146. return array_merge($this->nomenclatureTables(), $this->objectTables(), $this->consolidateTables(), $this->dispoTables());
  147. }
  148. /// Supprime une fiche et tout ce qui lui est directement rattachée
  149. /// nodel : liste des tables à ne pas effacer
  150. function del($ar) {
  151. $p = new XParam($ar, array('nodel' => array()));
  152. $nodel = $p->get('nodel');
  153. $oid = $p->get('_selected');
  154. $selectedok = $p->get('_selectedok');
  155. if (($selectedok != 'ok') || empty($oid))
  156. $oid = $p->get('oid');
  157. if (!is_array($oid))
  158. $oid = array($oid);
  159. if (empty($oid))
  160. return;
  161. foreach ($this->objectTables() as $table) {
  162. if (!in_array($table, $nodel) && $table != $this->table) {
  163. if ($table == $this->prefix.'ALBPHOTOINT')
  164. updateQuery('delete from '.$table.' where lie in ("'.implode('", "', $oid).'")');
  165. elseif ($table == $this->prefix.'TARIF')
  166. updateQuery('delete from '.$table.' where lie_ref in ("'.implode('", "', $oid).'") and exercice="'.$this->exercice.'"');
  167. else
  168. updateQuery('delete from '.$table.' where lie_ref in ("'.implode('", "', $oid).'")');
  169. }
  170. }
  171. updateQuery('delete from '.$this->table.' where KOID in ("'.implode('", "', $oid).'")');
  172. }
  173. /// Lance manuellement un import ITEA sur une liste de référence (séparées par des ,)
  174. function manuelImportFromITEA($ar = NULL) {
  175. $p = new XParam($ar, NULL);
  176. $dpt = $p->get('dpt');
  177. $refs = $p->get('refs');
  178. if (empty($dpt)) die('No dpt');
  179. if (empty($refs)) die('No reference');
  180. $o['uid'] = getSessionVar('UID');
  181. $o['function'] = 'importFromITEA';
  182. $o['dpt'] = $dpt;
  183. $o['refs'] = $refs;
  184. $o['forceall'] = 1;
  185. $o['post_import'] = $p->get('post_import');
  186. $date = date('Y-m-d H:i:s');
  187. $scheduler= new XModScheduler();
  188. $roid = $scheduler->createJob($this->_moid, $date, 'Test ITEA', $o, '');
  189. $scheduler->executeJob($roid['oid'], false);
  190. die('finnish');
  191. }
  192. /// Importe les données depuis ITEA via tache scheduler
  193. /// Parametres : clearall => vide toutes les tables objets
  194. /// forceall => force l'import des fiches deja à jour (donc importe tout)
  195. /// dpt => liste des departement à importer (séparer par des , )
  196. function importFromITEA(XModScheduler& $sched, $o, $more) {
  197. if (empty($GLOBALS['ITEACONF'][$this->table]))
  198. return 'Error : no ITEACONF in local.inc';
  199. XDbIni::set('disable_xlinkclean', true);
  200. // Effacement de toutes les tables non nomenclature/consolidation
  201. if (!empty($more->clearall)) {
  202. foreach ($this->objectTables() as $table)
  203. updateQuery('delete from '.$table);
  204. }
  205. // les départements
  206. if ($more->dpt && is_string($more->dpt))
  207. $dpt_select = explode(', ', $more->dpt);
  208. else
  209. $dpt_select = explode(', ', $this->dpts);
  210. echo 'Fonction importFromITEA:'.implode(', ', $dpt_select)."\n";
  211. // Initialisation des variables et recupération des champs spécifiques à la console (commencent par tzr_)
  212. $tzrfields = $del = $error = $new = $maj = $no = $retry = $log_retry = $error2 = array();
  213. foreach ($this->xset->orddesc as $k) {
  214. if (strpos($k, 'tzr_') === 0)
  215. $tzrfields[] = $k;
  216. }
  217. if (!empty($tzrfields))
  218. $sqltzrfields = ', '.implode(', ', $tzrfields);
  219. else
  220. $sqltzrfields = '';
  221. ini_set('soap.wsdl_cache_enabled', 0);
  222. foreach ($dpt_select as $dpt) {
  223. $dptsoap = $dpt.'soap';
  224. $dptsoap_xs = $dpt.'soap_xs';
  225. $soap = new SoapClient($this->$dptsoap, array('exceptions'=>false, 'features'=>SOAP_SINGLE_ELEMENT_ARRAYS));
  226. if ($this->$dptsoap_xs)
  227. $soap_xs = new SoapClient($this->$dptsoap_xs, array('exceptions'=>false, 'features'=>SOAP_SINGLE_ELEMENT_ARRAYS));
  228. $env = $dpt.'env';
  229. $login = $dpt.'login';
  230. $pass = $dpt.'pass';
  231. $identification = array('env' => $this->$env, 'login' => $this->$login, 'pass' => $this->$pass);
  232. $timebefore = time();
  233. $oids = $oidsmaj = array();
  234. $manual = false;
  235. // les langues pour ce département
  236. $langs = $dpt.'langs';
  237. $langs = $this->$langs;
  238. $langs = explode(',', $langs);
  239. unset($langues);
  240. foreach ($langs as $lang) {
  241. list($tzr_lang, $itea_lang) = explode('=>', trim($lang));
  242. $langues[$tzr_lang] = $itea_lang;
  243. if ($tzr_lang != TZR_DEFAULT_LANG)
  244. $otherlangues[$tzr_lang] = $itea_lang;
  245. }
  246. // Recherche des références à importer
  247. $refs = array();
  248. $to_import = array();
  249. // sur import manuel, les refs sont spécifiées
  250. if(!empty($more->refs)) {
  251. $manual=true;
  252. $mrefs = explode(',',$more->refs);
  253. foreach ($mrefs as $i => $ref) {
  254. // l'exercice en cours uniquement
  255. $exercice = date('Y');
  256. $refs[$ref]->$exercice = true;
  257. $to_import[$exercice][$ref] = (object)array('reference'=>$ref,'type'=>'tzr','date_maj'=>date('d/m/Y'));
  258. $to_import[$exercice+1][$ref] = $to_import[$exercice][$ref];
  259. }
  260. }
  261. // sinon import de toutes les refs mises à jour
  262. else {
  263. // pour l'exercice en cours et le suivant
  264. foreach (array(0, 1) as $i) {
  265. $exercice = date('Y') + $i;
  266. // récupération de la liste
  267. if ($this->$dptsoap_xs)
  268. $lstRef = $this->getXSLstRef($sched, $soap_xs, $o, $identification, $exercice);
  269. else
  270. $lstRef = $this->getLstRef($sched, $soap, $o, $identification, $exercice);
  271. if ($lstRef->produit)
  272. $to_import[$exercice] = array();
  273. elseif ($i == 0) {
  274. // suppression de l'exercice
  275. updateQuery('delete from '.$this->prefix.'TARIF where exercice="'.$exercice.'"');
  276. continue;
  277. } else // exercice +1 vide
  278. break;
  279. // correspondance refs/UPD en base (upditea different selon exercice)
  280. $refs_upd = selectQuery(
  281. 'select reference, UPD from '.$this->prefix.'DETAILSOFREF
  282. where lang="'.TZR_DEFAULT_LANG.'" and dpt="'.$this->prefix.'DPT:'.$dpt.'"')
  283. ->fetchAll(PDO::FETCH_GROUP|PDO::FETCH_UNIQUE|PDO::FETCH_COLUMN);
  284. // vérification date maj
  285. foreach ($lstRef->produit as $i => $infos) {
  286. // ce test est-il vraiment nécessaire ?
  287. if (empty($infos->reference) || empty($infos->type))
  288. continue;
  289. $oids[] = $this->getOid($dpt, $infos->reference);
  290. $infos->date_maj = $this->convertDate($infos->date_maj);
  291. if ($infos->date_maj > $refs_upd[$infos->reference] || $more->forceall) {
  292. $to_import[$exercice][$infos->reference] = $infos;
  293. }
  294. }
  295. }
  296. }
  297. $oids = array_values(array_unique($oids));
  298. if (empty($to_import)) {
  299. XLogs::critical("ITEA : importFromITEA error: dpt $dpt, nothing to do");
  300. continue;
  301. }
  302. unset($lstRef, $imported);
  303. // Import des produits
  304. foreach ($to_import as $exercice => $liste_refs) {
  305. foreach ($liste_refs as $ref => $infos) {
  306. XLogs::notice("ITEA Import $ref for $exercice");
  307. $refoid = $this->getOid($dpt, $ref);
  308. unset($infosForRef);
  309. // pour appel recursif à analyseObject
  310. $this->exercice = $exercice;
  311. // si la ref n'est pas déjà importée
  312. if (!isset($imported[$ref])) {
  313. $imported[$ref] = 1; // même si l'import échoue, ne pas importer dans l'exercice suivant (caract !=)
  314. $ors = selectQuery('select KOID, UPD, conspromo' . $sqltzrfields .
  315. ' from ' . $this->table .
  316. ' where KOID = "'.$refoid.'" limit 1')->fetch();
  317. echo ' - Post get 1 '.date('H:i:s') . "\n";
  318. foreach ($langues as $tzr_lang => $itea_lang) {
  319. $retry = 0;
  320. do {
  321. sleep($retry);
  322. if ($this->$dptsoap_xs)
  323. $infosForRef[$tzr_lang] = $soap_xs->getInfosForRef($identification, array('exercice' => $exercice, 'reference' => $ref, 'langue' => $itea_lang));
  324. else
  325. $infosForRef[$tzr_lang] = $soap->getInfosForRef($identification, array('exercice' => $exercice, 'reference' => $ref, 'langue' => $itea_lang));
  326. $retry++;
  327. } while (empty($infosForRef[$tzr_lang]) && $retry < 5);
  328. }
  329. // Pas de réponse correcte
  330. if(empty($infosForRef[TZR_DEFAULT_LANG]->reference)) {
  331. $error2[$dpt] .= $ref." (".TZR_DEFAULT_LANG.")\n";
  332. continue;
  333. }
  334. $ovalues = array('upditea' => $infos->date_maj);
  335. echo ' - Post get 2 '.date('H:i:s') . "\n";
  336. // suppression de la fiche
  337. if ($ors) {
  338. $maj[$dpt]++;
  339. $delar = $this->delparam[$dpt];
  340. $delar['oid'] = $refoid;
  341. $delar['_nolog'] = true;
  342. $this->del($delar);
  343. // Reprise des champs tzr
  344. foreach ($tzrfields as $field)
  345. $ovalues[$field] = $ors[$field];
  346. } else
  347. $new[$dpt]++;
  348. $this->analyseObject($infosForRef, $this->table, $refoid, $refoid, NULL, $dpt, $ovalues);
  349. echo ' - Post analyse '.date('H:i:s') . "\n";
  350. }
  351. // si la ref est déjà importée (dans un autre exercice)
  352. // on écrase pas les infos de l'exercice en cours par celles du suivant
  353. // Tarifs et promo de l'année uniquement
  354. else {
  355. updateQuery('delete from '.$this->prefix.'TARIF where exercice="'.$exercice.'" and lie_ref="'.$refoid.'"');
  356. foreach ($langues as $tzr_lang => $itea_lang)
  357. $infosForRef[$tzr_lang] = $soap->getInfosForRef($identification, array('exercice' => $exercice, 'reference' => $ref, 'langue' => $itea_lang));
  358. // Tarifs de la reference
  359. foreach ($infosForRef[TZR_DEFAULT_LANG]->tarifs->tarif as $i => $tarif) {
  360. $tarifs[TZR_DEFAULT_LANG] = $tarif;
  361. foreach ($otherlangues as $tzr_lang => $itea_lang)
  362. $tarifs[$tzr_lang] = $infosForRef[$tzr_lang]->tarifs->tarif[$i];
  363. $this->analyseObject($tarifs, $this->prefix.'TARIF', $refoid, NULL, $refoid, $dpt);
  364. }
  365. // Promos de la reference
  366. foreach ($infosForRef[TZR_DEFAULT_LANG]->promos->promo as $i => $promo){
  367. $promos[TZR_DEFAULT_LANG] = $promo;
  368. foreach ($otherlangues as $tzr_lang => $itea_lang)
  369. $promos[$tzr_lang] = $infosForRef[$tzr_lang]->promos->promo[$i];
  370. $this->analyseObject($promos, $this->prefix.'PROMO', $refoid, NULL, $refoid, $dpt);
  371. }
  372. // Tarifs des suppléments de la référence
  373. // correspondance libelle -> oid
  374. $suppl_libelle_oid = selectQuery(
  375. 'select libelle, koid from '.$this->prefix.'SUPPLEMENT
  376. where lie="'.$refoid.'" and lang="'.TZR_DEFAULT_LANG.'"')
  377. ->fetchAll(PDO::FETCH_GROUP|PDO::FETCH_UNIQUE|PDO::FETCH_COLUMN);
  378. foreach ($infosForRef[TZR_DEFAULT_LANG]->supplements->supplement as $i => $suppl) {
  379. $oid_suppl = $suppl_libelle_oid[$suppl->libelle];
  380. foreach ($suppl->prix->tarif as $j => $tarif) {
  381. $suppls[TZR_DEFAULT_LANG] = $suppl;
  382. $tarifs[TZR_DEFAULT_LANG] = $tarif;
  383. foreach ($otherlangues as $tzr_lang => $itea_lang) {
  384. $tarifs[$tzr_lang] = $infosForRef[$tzr_lang]->supplements->supplement[$i]->prix->tarif[$j];
  385. }
  386. $this->analyseObject($tarifs, $this->prefix.'TARIF', $refoid, NULL, $oid_suppl, $dpt);
  387. }
  388. }
  389. // Tarifs des chambres et des suppléments des chambres
  390. // correspondance num -> oid
  391. $chambre_num_oid = selectQuery(
  392. 'select numeroChambre, KOID from '.$this->prefix.'CHAMBRE
  393. where lie="'.$refoid.'" and lang="'.TZR_DEFAULT_LANG.'"')
  394. ->fetchAll(PDO::FETCH_GROUP|PDO::FETCH_UNIQUE|PDO::FETCH_COLUMN);
  395. foreach ($infosForRef[TZR_DEFAULT_LANG]->chambres->chambre as $i => $chambre) {
  396. $oid_chambre = $chambre_num_oid[$chambre->numeroChambre];
  397. foreach ($chambre->tarifs->tarif as $j => $tarif) {
  398. $tarifs[TZR_DEFAULT_LANG] = $tarif;
  399. foreach ($otherlangues as $tzr_lang => $itea_lang) {
  400. $tarifs[$tzr_lang] = $infosForRef[$tzr_lang]->chambres->chambre[$i]->tarifs->tarif[$j];
  401. }
  402. $this->analyseObject($tarifs, $this->prefix.'TARIF', $refoid, NULL, $oid_chambre, $dpt);
  403. }
  404. // les suppléments de la chambre
  405. foreach ($chambre->supplements->supplement as $j => $suppl){
  406. // correspondance libelle -> oid
  407. $suppl_libelle_oid = selectQuery(
  408. 'select libelle, KOID from '.$this->prefix.'SUPPLEMENT
  409. where lie="'.$oid_chambre.'" and lang="'.TZR_DEFAULT_LANG.'"')
  410. ->fetchAll(PDO::FETCH_GROUP|PDO::FETCH_UNIQUE|PDO::FETCH_COLUMN);
  411. if ($oid_suppl = $suppl_libelle_oid[$suppl->libelle]) {
  412. foreach ($suppl->prix->tarif as $k => $tarif) {
  413. $tarifs[TZR_DEFAULT_LANG] = $tarif;
  414. foreach ($otherlangues as $tzr_lang => $itea_lang)
  415. $tarifs[$tzr_lang] = $infosForRef[$tzr_lang]->chambres->chambre[$i]->supplements->supplement[$j]->prix->tarif[$k];
  416. $this->analyseObject($tarifs, $this->prefix.'TARIF', $refoid, NULL, $oid_suppl, $dpt);
  417. }
  418. }
  419. }
  420. }
  421. } // import Y+1
  422. // Consolidation
  423. $this->consolidateRef($refoid);
  424. $oidsmaj[] = $refoid;
  425. XLogs::notice("ITEA Import $ref for $exercice ok");
  426. } // foreach liste_refs
  427. } // foreach to_import
  428. // Supression des produit non vus dans cet import pour le departement en cours
  429. if (!$manual && !empty($oids)) {
  430. $oids_todel = selectQuery('select distinct KOID from '.$this->table.
  431. ' where KOID NOT IN("'.implode('", "', $oids).'") and '.
  432. ' dpt = "'.$this->prefix.'DPT:'.$dpt.'"')
  433. ->fetchAll(PDO::FETCH_COLUMN);
  434. XLogs::critical('ITEA import '.count($oids_todel).' à effacer');
  435. foreach ($oids_todel as $oid) {
  436. $this->del(array('oid' => $oid, '_nolog' => true));
  437. $del[$dpt]++;
  438. }
  439. }
  440. // Création des rubriques, info tour et themes globaux + consolidation finale
  441. if (!empty($oidsmaj)) {
  442. $this->duplicateRubToRubGlob(array('table' => $this->prefix.'RUBRIQUE', 'dpt' => $dpt));
  443. $this->duplicateRubToRubGlob(array('table' => $this->prefix.'INFOTOUR', 'dpt' => $dpt));
  444. $this->duplicateRubToRubGlob(array('table' => $this->prefix.'THEME', 'dpt' => $dpt));
  445. $this->consolidateRefs($oidsmaj, $dpt);
  446. }
  447. // Rapport dur le departement
  448. $timing = time()-$timebefore;
  449. $ret .= 'Département : '.$dpt."\n";
  450. $ret .= 'Heure début : '.date("c", $timebefore)."\n";
  451. $ret .= 'Heure fin : '.date("c", time())."\n";
  452. $ret .= 'Timing : '.$timing." sec.\n";
  453. $ret .= 'Total : '.count($refs)."\n";
  454. $ret .= 'A jour : '.$no[$dpt]."\n";
  455. $ret .= 'Nouveaux : '.$new[$dpt]."\n";
  456. $ret .= 'Mis à jour : '.$maj[$dpt]."\n";
  457. $ret .= 'Erreur : '.$error[$dpt]."\n";
  458. $ret .= 'Erreur getInfosForRef vide : '.$error2[$dpt]."\n";
  459. $ret .= 'Nb itérations sur err : '.$log_retry[$dpt]."\n";
  460. $ret .= 'Total traités : '.($no[$dpt]+$maj[$dpt]+$new[$dpt]+$error[$dpt])."\n";
  461. $ret .= 'Supprimé : '.$del[$dpt]."\n";
  462. echo str_replace("\n", '<br>', $ret);
  463. }
  464. $sched->setStatusJob($o->KOID, 'running', $ret);
  465. // execution traitements supplémentaires
  466. if (method_exists($this, 'postImport') && (!$manual || $o->post_import == 1)) {
  467. $sched->setStatusJob($o->KOID, 'running', 'calling postImport');
  468. $this->postImport($sched, $o, $more, $oidsmaj);
  469. }
  470. $sched->setStatusJob($o->KOID, 'finished', 'done');
  471. XDbIni::clear('disable_xlinkclean');
  472. return $ret;
  473. }
  474. /// Recupere la liste des references pour un exercice
  475. /// utilise la version améliorée xs_getLstRef
  476. function getXSLstRef(&$sched, &$soap_xs, $o, $identification, $exercice) {
  477. $retry=0;
  478. do {
  479. $sched->setStatusJob($o->KOID, 'running', "Fonction getXSLstRef $exercice : Try $retry\n");
  480. $lstref->exercice = $exercice;
  481. $rep = $soap_xs->xs_getLstRef($identification, $lstref);
  482. $retry++;
  483. } while (empty($rep->produit) && $retry < 2);
  484. if (empty($rep->produit) || $retry == 2){
  485. $sched->setStatusJob($o->KOID, 'running','Fonction getXSLstRef : Echec - '.$retry." retries\n");
  486. return false;
  487. }
  488. return $rep;
  489. }
  490. /// Recupere la liste des references pour un exercice
  491. /// utilise la version itea getLstRef
  492. function getLstRef(&$sched, &$soap, $o, $identification, $exercice) {
  493. $retry=0;
  494. do {
  495. $sched->setStatusJob($o->KOID, 'running', "Fonction getLstRef $exercice : Try $retry\n");
  496. $lstref->exercice = $exercice;
  497. $rep = $soap->getLstRef($identification, $lstref);
  498. $retry++;
  499. } while (empty($rep->produit) && $retry < 2);
  500. if (empty($rep->produit) || $retry == 2){
  501. $sched->setStatusJob($o->KOID, 'running','Fonction getLstRef : Echec - '.$retry." retries\n");
  502. return false;
  503. }
  504. return $rep;
  505. }
  506. /// Analyse un objet XML
  507. /// rep => tableau avec obj xml par langue
  508. /// table => table de destination de l'objet
  509. /// refoid => oid du produit de reference
  510. /// oid => oid de la fiche a creer
  511. /// parent => oid du parent
  512. /// dpt => departement
  513. /// values => valeurs à passer au procInput/procEdit
  514. function analyseObject(&$rep, $table, $refoid, $oid = NULL, $parent = NULL, $dpt = NULL, $values = array()) {
  515. global $TZR_DB;
  516. $repbase = &$rep[TZR_DEFAULT_LANG];
  517. $forceedit = false;
  518. if (!XSystem::tableExists($table)) return;
  519. $oxset = XDataSource::objectFactoryHelper8('BCLASS=XDSTable&SPECS='.$table);
  520. // Génération de l'oid si pas passé en parametre
  521. if (empty($oid)) {
  522. if ($table == $this->prefix.'CARACTERISTIQUE')
  523. $oid = substr($table.':'.str_replace('?', '-', $repbase->valeur).'-'.$repbase->id . '-' .$dpt.'_'. md5($repbase->libelleLong), 0, 40);
  524. elseif ($table == $this->prefix.'TYPELANGUE')
  525. $oid = $table.':'.rewriteToAscii($repbase->code);
  526. // // les promos sont identiques pour tout les hébergements mais elles sont en sf
  527. // elseif ($table == $this->prefix.'PROMO')
  528. // $oid = $table.':'.$dpt.'_'.$repbase->id;
  529. elseif (in_array($table, $this->descrType['tables'])) {
  530. $code = $this->convertText($repbase->code);
  531. // Inversion code/description de INFOTOUR pour NOM_INFO_TOURISTIQUE
  532. if ($code == 'NOM_INFO_TOURISTIQUE') {
  533. foreach ($rep as $lang => &$replang) {
  534. $replang->code = $replang->description;
  535. $replang->description = '';
  536. }
  537. unset($replang);
  538. $code = $this->convertText($repbase->code);
  539. }
  540. $descr = $this->convertText($repbase->description);
  541. $oid = selectQuery('select KOID from '.$table.' where code = "'.addslashes($code).'" '.
  542. 'and description = "'.addslashes($descr).'" '.
  543. 'and dpt = "'.$this->prefix.'DPT:'.$dpt.'" and LANG = "'.TZR_DEFAULT_LANG.'" limit 1')
  544. ->fetch(PDO::FETCH_COLUMN);
  545. }
  546. }
  547. if (empty($oid)) {
  548. $oid = $oxset->getNewOID();
  549. }
  550. $objexist = selectQuery('select count(KOID) from '.$table.' where KOID = "'.$oid.'" and LANG = "'.TZR_DEFAULT_LANG.'"')
  551. ->fetch(PDO::FETCH_COLUMN);
  552. if (($table == $this->prefix.'TYPELANGUE' || $table == $this->prefix.'CARACTERISTIQUE') && $objexist)
  553. return $oid;
  554. if (!empty($parent))
  555. $values['lie'] = $parent;
  556. $values['newoid'] = $oid;
  557. $values['lie_ref'] = $refoid;
  558. $values['_nolog'] = true;
  559. $values['LANG_DATA'] = TZR_DEFAULT_LANG;
  560. $values['exercice'] = $this->exercice;
  561. foreach ($repbase as $field => &$value) {
  562. // Valeur classique (string, int, nomenclature...)
  563. if (!is_object($value) && !($field == 'caracteristiques' && is_array($value))) {
  564. $ftype = $oxset->desc[$field]->ftype;
  565. switch($ftype) {
  566. case 'XDateDef':
  567. $values[$field] = $this->convertDate($value);
  568. break;
  569. case 'XUrlDef':
  570. $this->prepareImage('img', $value, $values);
  571. $values[$field]['url'] = $value;
  572. break;
  573. case 'XStringSetDef':
  574. $soid = selectQuery('select SOID from SETS where STXT = "'.$value.'" and SLANG = "'.TZR_DEFAULT_LANG.'" and FIELD = "'.$field.'" '.
  575. 'and STAB = "'.$table.'" limit 1')->fetch(PDO::FETCH_COLUMN);
  576. if (empty($soid)) {
  577. $soid = selectQuery('select max(SOID)+1 as SOID from SETS')->fetch(PDO::FETCH_COLUMN);
  578. $order = selectQuery('select max(SORDER)+1 as max from SETS where STAB = "'.$table.'" and FIELD = "'.$field.'"')->fetch(PDO::FETCH_COLUMN);
  579. if (!empty($order))
  580. $order = 1;
  581. foreach ($rep as $lang => $replang) {
  582. updateQuery('insert into SETS (SOID, FIELD, STAB, SLANG, STXT, SORDER) values ("'.$soid.'", "'.$field.'", "'.$table.'", '.
  583. '"'.$lang.'", "'.$value.'", "'.$order.'")');
  584. }
  585. }
  586. $values[$field] = $soid;
  587. break;
  588. case 'XLinkDef':
  589. $target = $oxset->desc[$field]->target;
  590. if (!is_array($value))
  591. $value = array($value);
  592. foreach ($value as $v) {
  593. if (!empty($v)) {
  594. // suppression traitement des pictos loisirs
  595. // on doir récupérer les libellés dans toutes les langues
  596. // le champ picto devient le lien sur ITEA_PL
  597. // !!! changement fonctionnalité v7
  598. if ($field == 'languesParlees') {
  599. $rs = selectQuery('select KOID from '.$target.' where code = "'.$v->code.'" limit 1');
  600. if ($rs->rowCount() == 0) {
  601. $xset = XDataSource::objectFactoryHelper8('BCLASS=XDSTable&SPECS='.$target);
  602. $loid = $target.':'.$v->code;
  603. $xset->procInput(array('newoid' => $loid, 'code' => $v->code, 'libelle' => $v->libelle, '_nolog' => true));
  604. $values[$field][] = $loid;
  605. } else {
  606. $values[$field][] = $rs->fetch(PDO::FETCH_COLUMN);
  607. }
  608. } else {
  609. $rs = selectQuery('select KOID from '.$target.' where code = "'.$v.'" limit 1');
  610. if ($rs->rowCount() == 0) {
  611. $xset = XDataSource::objectFactoryHelper8('BCLASS=XDSTable&SPECS='.$target);
  612. $loid = $target.':'.rewriteToAscii(str_replace('?', '-', $v));
  613. $xset->procInput(array('newoid' => $loid, 'code' => $v, 'libelle' => $v, '_nolog' => true));
  614. $values[$field][] = $loid;
  615. } else {
  616. $values[$field][] = $rs->fetch(PDO::FETCH_COLUMN);
  617. }
  618. }
  619. }
  620. }
  621. break;
  622. default:
  623. if ($field == 'id') $field = 'refid';
  624. if ($field == 'classementLabel' and $value == '9') $value = '0';
  625. // traitement des pictos loisirs
  626. if ($table == $this->prefix.'LOISIRS' && $field == 'libelleLong') {
  627. $picto = $this->getDistinctLoisir($value);
  628. $picto_table = $this->prefix.'PL';
  629. $loid = $picto_table.':'.md5($value);
  630. $rs = selectQuery('select KOID from '.$picto_table.' where KOID = "'.$loid.'" limit 1');
  631. if ($rs->rowCount() == 0) {
  632. $xset = XDataSource::objectFactoryHelper8('BCLASS=XDSTable&SPECS='.$picto_table);
  633. $xset->procInput(array('newoid' => $loid, 'code' => $value, '_nolog' => true));
  634. $values['picto'][] = $loid;
  635. } else {
  636. $values['picto'][] = $rs->fetch(PDO::FETCH_COLUMN);
  637. }
  638. }
  639. $values[$field] = $this->convertText($value);
  640. if ($oxset->desc[$field]->translatable) {
  641. foreach ($rep as $lang => $replang) {
  642. $tradvalues[$lang][$field] = $this->convertText($replang->$field);
  643. }
  644. }
  645. break;
  646. }
  647. } else {
  648. // On veut recuperer un sous objet pour le mettre directement dans la fiche en cours
  649. if (in_array($field, $this->directsubdata[$table])) {
  650. $obj = array();
  651. foreach ($rep as $lang => $replang) {
  652. $obj[$lang] = $replang->$field;
  653. }
  654. $foid = $this->analyseObject($obj, $table, $refoid, $oid, NULL, $dpt);
  655. $forceedit = true;
  656. } elseif ($subfield = $this->directuniquesubdata[$table][$field]) {
  657. $values[$field] = $this->convertText($value->$subfield);
  658. if ($oxset->desc[$field]->translatable) {
  659. foreach ($rep as $lang => $replang) {
  660. $replang->$field->$subfield = $this->convertText($replang->$field->$subfield);
  661. $tradvalues[$lang][$field] = addslashes($replang->$field->$subfield);
  662. }
  663. }
  664. // Lien vers un objet complexe unique (donc en lien dans la table) (id loisir)
  665. } elseif (isset($oxset->desc[$field]) && !$oxset->desc[$field]->multivalued) {
  666. $obj = array();
  667. foreach ($rep as $lang => $replang)
  668. $obj[$lang] = $replang->$field;
  669. $foid = $this->analyseObject($obj, $oxset->desc[$field]->target, $refoid, NULL, NULL, $dpt);
  670. $values[$field] = $foid;
  671. // Lien vers un objet complexe multiple en lien multiple ou en sous fiches
  672. } else {
  673. // Cas particulier des caractéristiques toutes foireuses dans pieces et chambres
  674. if ($field == 'caracteristiques' && is_array($value)) {
  675. foreach ($rep as $lang => &$replang) {
  676. foreach ($replang->$field as &$tmp)
  677. $tmp = (object)$tmp;
  678. $replang->$field = (object)array('carateristique' => $replang->$field);
  679. }
  680. $value = $rep[TZR_DEFAULT_LANG]->$field;
  681. }
  682. foreach ($value as $t => $objs) {
  683. foreach ($rep as $lang => &$replang) {
  684. if (!is_array($replang->$field->$t))
  685. $replang->$field->$t = array($replang->$field->$t);
  686. }
  687. unset($replang);
  688. foreach ($rep[TZR_DEFAULT_LANG]->$field->$t as $i => $object_deflang) {
  689. $obj = array();
  690. // les descriptifsComp ne sont pas les mêmes dans les différentes langues
  691. // recherche de correspondance sur type et code
  692. if ($field == 'descriptifsComp') {
  693. $obj[TZR_DEFAULT_LANG] = $object_deflang;
  694. foreach ($rep as $lang => $replang) {
  695. if ($lang == TZR_DEFAULT_LANG)
  696. continue;
  697. foreach ($replang->$field->$t as $j => $object_other_lang) {
  698. if ($object_other_lang->type == $object_deflang->type
  699. && $object_other_lang->code == $object_deflang->code) {
  700. $obj[$lang] = $object_other_lang;
  701. }
  702. }
  703. }
  704. }
  705. // sinon, on prend dans les objects dans l'ordre de l'index
  706. else
  707. foreach ($rep as $lang => $replang) {
  708. $objlist = $replang->$field->$t;
  709. $obj[$lang] = $objlist[$i];
  710. }
  711. $isok = false;
  712. if ($field == 'descriptifsComp' && $table == $this->prefix.'DETAILSOFREF') {
  713. if (in_array($obj[TZR_DEFAULT_LANG]->type, $this->descrType['link'])) {
  714. $lower = strtolower($obj[TZR_DEFAULT_LANG]->type);
  715. $newf = $this->descrType['fields'][$lower];
  716. if (!in_array($lower, $this->descrType['notlink'])) {
  717. $values[$newf][] = $this->analyseObject($obj, $oxset->desc[$newf]->target, $refoid, NULL, NULL, $dpt, $this->descrType['cplt'][$lower]);
  718. }
  719. $isok = true;
  720. } elseif (in_array($obj[TZR_DEFAULT_LANG]->type, $this->descrType['no'])) {
  721. continue;
  722. }
  723. } elseif ($field == 'urls' && $table == $this->prefix.'DETAILSOFREF') {
  724. // Gestion de la photo principale + vignette
  725. if (isset($oxset->desc[strtolower($obj[TZR_DEFAULT_LANG]->type)])) {
  726. $isok = true;
  727. $newf = strtolower($obj[TZR_DEFAULT_LANG]->type);
  728. if ($oxset->desc[$newf]->ftype == 'XImageDef') {
  729. $this->prepareImage($newf, $obj[TZR_DEFAULT_LANG]->url, $values);
  730. $values[$newf] = $obj[TZR_DEFAULT_LANG]->url;
  731. } else
  732. $values[$newf]['url'] = $obj[TZR_DEFAULT_LANG]->url;
  733. // Gestion de l'album photo
  734. } elseif (substr(strtolower($obj[TZR_DEFAULT_LANG]->type), 0, 5) == 'photo' && strtolower($obj[TZR_DEFAULT_LANG]->type) != 'photo') {
  735. $isok = true;
  736. $this->analyseObject($obj, $this->prefix.'ALBPHOTOINT', $refoid, NULL, $oid, $dpt);
  737. }
  738. } elseif ($field == 'telephones' && $table == $this->prefix.'CONTACT') {
  739. $isok = true;
  740. if (isset($oxset->desc[strtolower($obj[TZR_DEFAULT_LANG]->type)])) {
  741. $newf = strtolower($obj[TZR_DEFAULT_LANG]->type);
  742. if (empty($values[$newf]))
  743. $values[$newf] = $obj[TZR_DEFAULT_LANG]->numero;
  744. else
  745. $values[$newf] .= ', '.$obj[TZR_DEFAULT_LANG]->numero;
  746. }
  747. } elseif ($table == $this->prefix.'PERIODPROMO') {
  748. $isok = true;
  749. // Consolidation des champs période directement dans la table ITEA_PERIODPROMO
  750. if (!isset($oxset->desc[$field])) {
  751. $values[$t.$field] = $this->convertDate($obj[TZR_DEFAULT_LANG]);
  752. }
  753. }
  754. if (!$isok) {
  755. if (isset($oxset->desc[$field]) && $oxset->desc[$field]->multivalued) {
  756. $values[$field][] = $this->analyseObject($obj, $oxset->desc[$field]->target, $refoid, NULL, NULL, $dpt);
  757. } else {
  758. $values[$field][] = $this->analyseObject($obj, strtoupper($this->prefix.''.$t), $refoid, NULL, $oid, $dpt);
  759. }
  760. }
  761. }
  762. }
  763. }
  764. }
  765. }
  766. if ($table == $this->prefix.'DETAILSOFREF') {
  767. // Coordonnées TZR
  768. if (!empty($values['latitude']) && !empty($values['longitude'])) {
  769. $values['coordx'] = $values['latitude'].';'.$values['longitude'].';M;N/A;'.date('Y-m-d H:i:s');
  770. }
  771. // Caractéristiques consolidées
  772. if ($this->needconscaract && is_object($repbase->caracteristiques)) {
  773. foreach ($repbase->caracteristiques->caracteristique as $c) {
  774. if ($c->valeur == 'O') {
  775. $value = $this->getConsCarac($c->id, $values['type'], $dpt);
  776. if (!empty($value)) $values['conscarac'][] = $value;
  777. }
  778. }
  779. }
  780. }
  781. if ($dpt) $values['dpt'] = $this->prefix.'DPT:'.$dpt;
  782. // Insere ou edite l'entrée
  783. if (empty($objexist) && !$forceedit) {
  784. // Boucle pour forcer les champs numériques à NULL s'ils ne sont pas renseignés (car sinon 0, et c'est pas bien)
  785. foreach ($oxset->desc as $fn => &$fo) {
  786. if ($fo->ftype == 'XRealDef' && !isset($values[$fn])) $values[$fn] = '';
  787. }
  788. $values['_nolog'] = true;
  789. $ret = $oxset->procInput($values);
  790. } else {
  791. $ret['oid'] = $values['oid'] = $oid;
  792. $values['_nolog'] = true;
  793. $oxset->procEdit($values);
  794. }
  795. // Traduction
  796. if ($oxset->getTranslatable()) {
  797. foreach ($tradvalues as $lang => $values) {
  798. if ($lang != TZR_DEFAULT_LANG) {
  799. $q = array();
  800. foreach ($values as $f => $v) {
  801. if (!empty($v)) $q[] = $f.' = '.$TZR_DB->quote($v);
  802. }
  803. if (!empty($q))
  804. updateQuery('update '.$table.' set '.implode(', ', $q).' where KOID = "'.$ret['oid'].'" and LANG = "'.$lang.'"');
  805. }
  806. }
  807. }
  808. return $ret['oid'];
  809. }
  810. /// Import les disponibilité depuis ITEA via tache scheduler
  811. function importDispoFromITEA(XModScheduler& $sched, $o, $more) {
  812. if (empty($GLOBALS['ITEACONF'][$this->table]))
  813. return 'Error : no ITEACONF in local.inc';
  814. // Si des imports de ressources sont en cours, on reporte l'import des dispo d'une heure pour ne pas trop ralentir la recuperation
  815. $nb = countSelectQuery('select count(KOID) from TASKS where title like "Import ITEA%" and status = "running"');
  816. if ($nb > 0) {
  817. updateQuery('UPDATE TASKS SET status = "scheduled", rem = "'.date('Y-m-d H:i:s').' : Reporté car import ITEA en cours", '.
  818. 'ptime = "'.date('Y-m-d H:i:s', strtotime('+1 hour')).'" WHERE KOID = "'.$o->KOID.'"', false);
  819. return;
  820. }
  821. // Paramètre des recup : clé => numero du jour dans la semaine
  822. // valeur => tableau : cle => duree
  823. // valeur => tableau des types
  824. // donner une chance à la class d'implémentation de personnaliser la conf
  825. if (method_exists($this, 'getDispoConf'))
  826. $torecup = $this->getDispoConf();
  827. else {
  828. if ($more->dtype == 'other') {
  829. $types = selectQuery('select distinct KOID from '.$this->prefix.'TYPEPRODUIT '.
  830. 'where KOID not in("'.$this->prefix.'TYPEPRODUIT:g", "'.$this->prefix.'TYPEPRODUIT:h)"')
  831. ->fetchAll(PDO::FETCH_COLUMN);
  832. $torecup = array('5' => array('2' => $types, '7' => $types, '14' => $types, '21' => $types));
  833. } else {
  834. $torecup = array(
  835. '5' => array('2' => array($this->prefix.'TYPEPRODUIT:g', $this->prefix.'TYPEPRODUIT:h'),
  836. '7' => array($this->prefix.'TYPEPRODUIT:g', $this->prefix.'TYPEPRODUIT:h'),
  837. '8' => array($this->prefix.'TYPEPRODUIT:h'),
  838. '14' => array($this->prefix.'TYPEPRODUIT:g', $this->prefix.'TYPEPRODUIT:h'),
  839. '15' => array($this->prefix.'TYPEPRODUIT:h'),
  840. '21' => array($this->prefix.'TYPEPRODUIT:g', $this->prefix.'TYPEPRODUIT:h')
  841. ),
  842. '6' => array('7' => array($this->prefix.'TYPEPRODUIT:g', $this->prefix.'TYPEPRODUIT:h'),
  843. '8' => array($this->prefix.'TYPEPRODUIT:h'),
  844. '14' => array($this->prefix.'TYPEPRODUIT:g', $this->prefix.'TYPEPRODUIT:h'),
  845. '15' => array($this->prefix.'TYPEPRODUIT:h'),
  846. '21' => array($this->prefix.'TYPEPRODUIT:g', $this->prefix.'TYPEPRODUIT:h')
  847. )
  848. );
  849. }
  850. }
  851. $ts = time();
  852. $end = date('Y-m-d',strtotime('+12 month'));
  853. $liste = array();
  854. if (!empty($more->dpts))
  855. $dpts = $more->dpts;
  856. else
  857. $dpts = $this->dpts;
  858. if (empty($dpts))
  859. return 'Erreur : aucun département spécifié';
  860. $dpts = explode(',', $dpts);
  861. foreach ($dpts as $dpt){
  862. $liste[trim($dpt)] = array();
  863. }
  864. $ds_dispogen = XDataSource::objectFactoryHelper8('BCLASS=XDSTable&SPECS='.$this->prefix.'DISPOGEN');
  865. updateQuery('delete from '.$this->prefix.'DISPOGEN where deb < curDate()');
  866. do {
  867. $isodate = date('Y-m-d', $ts);
  868. $date = date('d/m/Y', $ts);
  869. $dayinweek = date('N', $ts);
  870. foreach ($torecup[$dayinweek] as $duree => $types) {
  871. foreach ($types as $type) {
  872. echo date('H:i:s').' => ';
  873. $refs = $this->xset->getDispoFromITEA($liste, $date, $duree, $type);
  874. echo $date.' - '.$duree.' - '.$type.' - '.(strpos($refs, 'soaperrorcode:') !== false? $refs: count(explode(';', $refs)))."\n";
  875. updateQuery('delete from '.$this->prefix.'DISPOGEN where deb = "'.$isodate.'" and duree = "'.$duree.'" and type = "'.$type.'"');
  876. if (strpos($refs, 'soaperrorcode:') === false) {
  877. $ds_dispogen->procInput(array('type' => $type, 'duree' => $duree, 'deb' => $isodate, 'refs' => $refs, '_nolog' => true));
  878. }
  879. }
  880. if (is_object($sched)) {
  881. $ns = $sched->setStatusJob($o->KOID, 'running', $isodate.'-'.$duree);
  882. if ($ns===false) return; // ns = false si la tache n'existe plus
  883. }
  884. }
  885. $ts = strtotime($isodate.' +1 day');
  886. } while ($isodate<=$end);
  887. // suppression des dispos dépassées
  888. updateQuery('delete from '.$this->prefix.'DISPOGEN where date_add(deb, interval duree day) < now()');
  889. // execution traitements supplémentaires
  890. if (method_exists($this, 'postImportDispo')) {
  891. $sched->setStatusJob($o->KOID, 'running', 'calling postImportDispo');
  892. $this->postImportDispo($sched, $o, $more);
  893. }
  894. $sched->setStatusJob($o->KOID, 'finished', 'done');
  895. }
  896. /// Prepare un fichier image à partir d'une url
  897. function prepareImage($field, $url, &$values) {
  898. $file = TZR_TMP_DIR.'ITEA'.uniqid();
  899. $retry = 0;
  900. do {
  901. $content = file_get_contents($url);
  902. $retry++;
  903. } while(!$content && $retry < 3);
  904. if (empty($content)) {
  905. XLogs::notice('xmoditea::prepareImage cannot fetch '.$url);
  906. } else {
  907. file_put_contents($file, $content);
  908. $mimeClasse = XMimeTypes::getInstance();
  909. $mime = $mimeClasse->get_file_type($file);
  910. if ($mimeClasse->isImage($mime)) {
  911. $values[$field.'_title'] = '';
  912. $values[$field.'_HID'] = array('old' => 'N%3B');
  913. $values[$field] = 1;
  914. $_FILES[$field]['tmp_name'] = $file;
  915. $_FILES[$field]['type'] = $mime;
  916. $_FILES[$field]['name'] = $url;
  917. $_FILES[$field]['size'] = filesize($file);
  918. }
  919. }
  920. }
  921. /// Convertion de texte ITEA en texte normal
  922. function convertText($text) {
  923. $from = array("\xc2\x92", "\xc2\x9C", "\xc2\x80");
  924. $to = array("'", "oe", "€");
  925. $text = str_replace($from, $to, $text);
  926. convert_charset($text, 'UTF-8', 'ISO-8859-15');
  927. cp1252_replace($text);
  928. convert_charset($text, 'ISO-8859-15', 'UTF-8');
  929. return $text;
  930. }
  931. /// Convertit une date ITEA au format international
  932. function convertDate($date) {
  933. if (!preg_match('/^([0-9]{2})\/?([0-9]{2})\/?([0-9]{4}|[0-9]{2})$/', $date, $matches))
  934. return $date;
  935. if (strlen($matches[3]) == 2)
  936. if ($matches[3] >= 50)
  937. $matches[3] = '19'.$matches[3];
  938. else
  939. $matches[3] = '20'.$matches[3];
  940. return $matches[3] . '-' . $matches[2] . '-' . $matches[1];
  941. }
  942. /// Recupere une caracteristique consolidée à partir de son id, de son type et de son departement
  943. function getConsCarac($id, $type, $dpt) {
  944. if (is_array($type))
  945. $type = $type[0];
  946. $type = str_replace($this->prefix.'TYPEPRODUIT:', '', $type);
  947. if (empty($this->_cache->conscarac)) {
  948. $rs = &selectQuery('select * from '.$this->prefix.'CONSCARAC');
  949. while($ors = $rs->fetch()) {
  950. foreach ($ors as $f => $v) {
  951. if (strpos($f, 'c')!==0 || empty($v)) continue;
  952. $lid = explode(', ', $v);
  953. foreach ($lid as $fooid) {
  954. $this->_cache->conscarac[$f][$fooid] = $ors['KOID'];
  955. }
  956. }
  957. }
  958. }
  959. return $this->_cache->conscarac['c'.$type.$dpt][$id];
  960. }
  961. /// Recupere un libelle Loisir unique
  962. function getDistinctLoisir($lib) {
  963. if (empty($this->_cache->consloisirs)) {
  964. $this->_cache->consloisirs = selectQuery('select src, dest from '.$this->prefix.'CONSLOISIRS')
  965. ->fetchAll(PDO::FETCH_COLUMN|PDO::FETCH_UNIQUE);
  966. }
  967. if (!empty($this->_cache->consloisirs[$lib]))
  968. return $this->_cache->consloisirs[$lib];
  969. else
  970. return $lib;
  971. }
  972. /// Execute toutes les consolidations d'un departement (utilisé pour une consolidation globale manuelle)
  973. function executeAllConsolidation($ar = NULL) {
  974. ini_set('max_execution_time', 3600);
  975. $p = new XParam($ar, array('dpt' => '04'));
  976. $dpt = $p->get('dpt');
  977. if (empty($dpt)) return 'no dpt';
  978. $oids = selectQuery('select KOID from '.$this->table.
  979. ' where dpt = "'.$this->prefix.'DPT:'.$dpt.'" and LANG = "'.TZR_DEFAULT_LANG.'"')
  980. ->fetchAll(PDO::FETCH_COLUMN);
  981. foreach ($oids as $oid)
  982. $this->consolidateRef($oid);
  983. $this->duplicateRubToRubGlob(array('table' => $this->prefix.'RUBRIQUE', 'dpt' => $dpt));
  984. $this->duplicateRubToRubGlob(array('table' => $this->prefix.'INFOTOUR', 'dpt' => $dpt));
  985. $this->duplicateRubToRubGlob(array('table' => $this->prefix.'THEME', 'dpt' => $dpt));
  986. $this->consolidateRefs($oids, $dpt);
  987. echo 'ok';
  988. }
  989. /// Consolide une fiche (appelé pour chaque fiche)
  990. /// (pour une consolidation complete, consolidateRefs doit etre aussi appelée)
  991. /// Retourne l'ors de la fiche pour un enrichissement eventuel de la fonction
  992. function consolidateRef($oid, $edit = true) {
  993. if (empty($oid)) return;
  994. echo ' - Debut consolidation '.date('H:i:s') . "\n";
  995. $orsref = selectQuery('select * from '.$this->table.
  996. ' where KOID = "'.$oid.'" and LANG = "'.TZR_DEFAULT_LANG.'" limit 1')
  997. ->fetch();
  998. if (!$orsref)
  999. return;
  1000. $ar = array();
  1001. // Tarif min max
  1002. if (!empty($this->xset->desc['constarifmin']) && !empty($this->xset->desc['constarifmax'])) {
  1003. if ($orsref['type'] == $this->prefix.'TYPEPRODUIT:h')
  1004. $ors = selectQuery('select min(montant) as min, max(montant) as max '.
  1005. 'from '.$this->prefix.'TARIF where lie_ref = "'.$orsref['KOID'].'"'.
  1006. 'and duree = "'.$this->prefix.'TYPEDUREETARIF:1" '.
  1007. 'and lie like "'.$this->prefix.'CHAMBRE%" and lang="'.TZR_DEFAULT_LANG.'" '.
  1008. 'and libelle not like "%suppl%" and libelle not like "%P.SUP%"')
  1009. ->fetch();
  1010. elseif ($orsref['type'] == $this->prefix.'TYPEPRODUIT:se' || $orsref['type'] == $this->prefix.'TYPEPRODUIT:gs' || $orsref['type'] == $this->prefix.'TYPEPRODUIT:ge')
  1011. $ors = selectQuery('select montant as min, montant_maxi as max '.
  1012. 'from '.$this->prefix.'TARIF where lie_ref = "'.$orsref['KOID'].'"'.
  1013. 'and libelle = "PERS.NUIT"')
  1014. ->fetch();
  1015. else // lie évite suppl
  1016. $ors = selectQuery('select min(montant) as min, max(montant) as max '.
  1017. 'from '.$this->prefix.'TARIF where lie = "'.$orsref['KOID'].'"'.
  1018. 'and duree = "'.$this->prefix.'TYPEDUREETARIF:7"')
  1019. ->fetch();
  1020. $ar['constarifmin'] = $ors['min'];
  1021. $ar['constarifmax'] = $ors['max'];
  1022. }
  1023. // Animaux
  1024. if (!empty($this->xset->desc['consani'])) {
  1025. if (strpos($orsref['caracteristiques'], $this->animauxok)!==false) $ar['consani'] = 1;
  1026. else $ar['consani'] = 2;
  1027. }
  1028. // Table d'hote
  1029. if (!empty($this->xset->desc['constho'])) {
  1030. if (strpos($orsref['caracteristiques'], $this->restook)!==false) $ar['constho'] = 1;
  1031. else $ar['constho'] = 2;
  1032. }
  1033. // Album pho…

Large files files are truncated, but you can click here to view the full file