/class.xmoditea.inc
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
- <?php
- class XModItea extends XModTable {
- private $_cache;
- public $submodmax = 12;
- public $directsubdata;
- public $descrType;
- public $animauxok;
- public $restook;
- public $delparam = array(); // Parametres à passer au del sur import (pour empecher suppression des photo par ex) : cle => dpt, val => param
- public $prefix = 'ITEA_';
- public $exercice; // Exercice en cours d'import
- function __construct($ar = NULL) {
- parent::__construct($ar);
- $this->directsubdata = array(
- $this->prefix.'DETAILSOFREF' => array('situation', 'tourismeEtHandicap'),
- $this->prefix.'CONTACT' => array('siteWeb', 'languesParlees'),
- $this->prefix.'CHAMBRE' => array('description'),
- $this->prefix.'SUPPLEMENT' => array('description'));
- $this->directuniquesubdata=array(
- $this->prefix.'DETAILSOFREF' => array('descriptif' => 'description', 'descriptifTechnique' => 'description', 'descriptifCommercial' => 'description'));
- $this->descrType = array(
- 'link' => array('INFO_TOUR', 'INFO_TOUR_ACTIV_OT', 'THEME', 'RUBRIQUE', 'RUBRIQUE_GENE'),
- //'no' => array('INFO_TOUR'),
- 'tables' => array($this->prefix.'INFOTOUR', $this->prefix.'THEME', $this->prefix.'RUBRIQUE'),
- 'fields' => array('theme' => 'theme', 'rubrique' => 'rubrique', 'rubrique_gene' => 'rubrique',
- 'info_tour_activ_ot' => 'info_tour_activ_ot', 'info_tour' => 'info_tour_activ_ot'),
- // champ => valeurs passées a analyseObject
- 'cplt' => array('rubrique_gene' => array('general' => 1)),
- 'notlink' => array(/*'rubrique_gene'*/)
- );
- $this->animauxok = $this->prefix.'CARACTERISTIQUE:O-40-';
- $this->restook = $this->prefix.'CARACTERISTIQUE:O-46-';
- XLabels::loadLabels('xmoditea');
- }
- public function initOptions() {
- parent::initOptions();
- $this->_options->setOpt('Prefix', 'prefix', 'text');
- $this->_options->setOpt('Liste des départements (séparateur ,)', 'dpts', 'text');
- $p1 = XModule::findParam($this->_moid);
- $dpts = explode(', ', $p1['MPARAM']['dpts']);
- $conf = $GLOBALS['ITEACONF'][$p1['MPARAM']['table']];
- $this->_options->setOpt('Consolidation des caractéristiques','needconscaract','boolean',false,NULL);
- foreach ($dpts as $dpt) {
- if (!empty($dpt)) {
- $this->_options->setOpt($dpt.' : Adresse service SOAP',$dpt.'soap','text',NULL,$conf[$dpt]['soap']);
- $this->_options->setOpt($dpt.' : Adresse service SOAP XS (xsalto)',$dpt.'soap_xs','text',NULL,$conf[$dpt]['soap_xs']);
- $this->_options->setOpt($dpt.' : Environnement', $dpt.'env', 'text', NULL, $conf[$dpt]['env']);
- $this->_options->setOpt($dpt.' : Login', $dpt.'login', 'text', NULL, $conf[$dpt]['login']);
- $this->_options->setOpt($dpt.' : Password', $dpt.'pass', 'text', NULL, $conf[$dpt]['pass']);
- $this->_options->setOpt($dpt.' : Langues (tzr=>itea, séparateur ,)', $dpt.'langs', 'text', NULL, 'FR=>FRANCAIS');
- }
- }
- }
- /// securite des fonctions accessibles par le web
- function secGroups($function, $group = NULL) {
- $g = array();
- $g['manuelImportFromITEA'] = array('admin');
- $g['importFromITEA'] = array('admin');
- $g['importDispoFromITEA'] = array('admin');
- $g['executeAllConsolidation'] = array('admin');
- $g['duplicateRubToRubGlob'] = array('admin');
- $g['importFromOtherBase'] = array('admin');
- $g['importDispoFromOtherBase'] = array('admin');
- if (isset($g[$function])) {
- if (!empty($group)) return in_array($group, $g[$function]);
- return $g[$function];
- }
- return parent::secGroups($function, $group);
- }
- function _daemon($period = 'any') {
- // Vide le cache des requetes de dispo datant de plus de 2 heures
- updateQuery('delete from '.$this->prefix.'DISPOREQ where UPD<date_add(now(), interval -2 hour)');
- /// TODO: disparition des options
- // $dir=$GLOBALS['LIBTHEZORRO'].'contrib/itea/';
- // if ($period == 'daily') {
- // // Importe les champs afin de maintenir à jour le format des tables
- // $mod_ds = new XModDataSource();
- // $mod_ds->importFields(array('file'=>$dir.'fields.csv','prefixSQL'=>$this->prefix,'endofline'=>"\n"));
- // $mod_ds->importFields(array('file'=>$dir.'nomenclature_fields.csv','prefixSQL'=>$this->prefix,'endofline'=>"\n"));
- // }
- }
- function insert($ar) {
- // En saisie manuelle, on fixe une date itea vieille pour ne pas gener un eventuel import
- $ar['options']['upditea']['value'] = '2000-01-01';
- return parent::insert($ar);
- }
- function procInsert($ar = NULL) {
- // L'oid est forcé
- $p = new XParam($ar, NULL);
- $ref = $p->get('reference');
- $dpt = $p->get('dpt');
- $ar['newoid'] = $this->getOid($dpt, $ref);
- return parent::procInsert($ar);
- }
- /// Retourne l'oid d'une reference dans un departement (le departement peut etre son numero ou son oid)
- function getOid($dpt, $ref) {
- $dpt = substr($dpt, -2);
- if (substr($ref, 0, 3) != $dpt.'_')
- return $this->table.':'.$dpt.'_'.rewriteToAscii(trim($ref), false);
- else
- return $this->table.':'.rewriteToAscii(trim($ref), false);
- }
- /// Rend vrai si la table en question est utilisée dans le module en question
- public function usesTable($table) {
- return in_array($table, $this->allTables());
- }
- /// Tables de nomenclature/communes
- public function nomenclatureTables() {
- return array(
- $this->prefix.'CHOIX_ON', $this->prefix.'TYPEPRODUIT', $this->prefix.'TYPEPIECE',
- $this->prefix.'TYPEGESTION', $this->prefix.'TYPELANGUE', $this->prefix.'TYPELIT',
- $this->prefix.'TYPECONTACT', $this->prefix.'TYPEURL', $this->prefix.'TYPEPARAMETRE',
- $this->prefix.'TYPECARACTERISTIQUE', $this->prefix.'TYPETARIF', $this->prefix.'TYPEDUREETARIF',
- $this->prefix.'TYPECHAMBRE', $this->prefix.'TYPECHARGE', $this->prefix.'TYPEDESCRIPTION',
- $this->prefix.'DPT', $this->prefix.'INSEE', $this->prefix.'CONSLOISIRS',
- $this->prefix.'CARACTERISTIQUE', $this->prefix.'RUBRIQUE', $this->prefix.'RUBRIQUE2',
- $this->prefix.'THEME', $this->prefix.'THEME2',
- $this->prefix.'INFOTOUR', $this->prefix.'INFOTOUR2', $this->prefix.'PL');
- }
- /// Tables de nomenclature/communes
- public function nomenclatureTablesDpt() {
- return array(
- 'INFOTOUR', $this->prefix.'INSEE',
- $this->prefix.'RUBRIQUE', $this->prefix.'RUBRIQUE2', $this->prefix.'THEME',
- $this->prefix.'THEME2', $this->prefix.'INFOTOUR', $this->prefix.'INFOTOUR2');
- }
- /// Tables objet
- function objectTables() {
- return array(
- $this->prefix.'ADR', $this->prefix.'ALBPHOTOINT', $this->prefix.'CHAMBRE',
- $this->prefix.'CONTACT', $this->prefix.'DESCRIPTION', $this->prefix.'DETAILSOFREF',
- $this->prefix.'LOISIRS', $this->prefix.'PARAMETRE', $this->prefix.'PERIOD',
- $this->prefix.'PERIODPROMO', $this->prefix.'PIECE', $this->prefix.'PROMO',
- $this->prefix.'SUPPLEMENT', $this->prefix.'TARIF', $this->prefix.'AGREMENT');
- }
- /// Tables de consolidation
- function consolidateTables() {
- return array($this->prefix.'CONSCARAC', $this->prefix.'CONSDISTLOISIRS');
- }
- /// Tables contenant les dispo
- function dispoTables() {
- return array($this->prefix.'DISPOGEN', $this->prefix.'DISPOREQ');
- }
- /// Toutes les tables
- public function allTables() {
- return array_merge($this->nomenclatureTables(), $this->objectTables(), $this->consolidateTables(), $this->dispoTables());
- }
- /// Supprime une fiche et tout ce qui lui est directement rattachée
- /// nodel : liste des tables à ne pas effacer
- function del($ar) {
- $p = new XParam($ar, array('nodel' => array()));
- $nodel = $p->get('nodel');
- $oid = $p->get('_selected');
- $selectedok = $p->get('_selectedok');
- if (($selectedok != 'ok') || empty($oid))
- $oid = $p->get('oid');
- if (!is_array($oid))
- $oid = array($oid);
- if (empty($oid))
- return;
- foreach ($this->objectTables() as $table) {
- if (!in_array($table, $nodel) && $table != $this->table) {
- if ($table == $this->prefix.'ALBPHOTOINT')
- updateQuery('delete from '.$table.' where lie in ("'.implode('", "', $oid).'")');
- elseif ($table == $this->prefix.'TARIF')
- updateQuery('delete from '.$table.' where lie_ref in ("'.implode('", "', $oid).'") and exercice="'.$this->exercice.'"');
- else
- updateQuery('delete from '.$table.' where lie_ref in ("'.implode('", "', $oid).'")');
- }
- }
- updateQuery('delete from '.$this->table.' where KOID in ("'.implode('", "', $oid).'")');
- }
- /// Lance manuellement un import ITEA sur une liste de référence (séparées par des ,)
- function manuelImportFromITEA($ar = NULL) {
- $p = new XParam($ar, NULL);
- $dpt = $p->get('dpt');
- $refs = $p->get('refs');
- if (empty($dpt)) die('No dpt');
- if (empty($refs)) die('No reference');
- $o['uid'] = getSessionVar('UID');
- $o['function'] = 'importFromITEA';
- $o['dpt'] = $dpt;
- $o['refs'] = $refs;
- $o['forceall'] = 1;
- $o['post_import'] = $p->get('post_import');
- $date = date('Y-m-d H:i:s');
- $scheduler= new XModScheduler();
- $roid = $scheduler->createJob($this->_moid, $date, 'Test ITEA', $o, '');
- $scheduler->executeJob($roid['oid'], false);
- die('finnish');
- }
- /// Importe les données depuis ITEA via tache scheduler
- /// Parametres : clearall => vide toutes les tables objets
- /// forceall => force l'import des fiches deja à jour (donc importe tout)
- /// dpt => liste des departement à importer (séparer par des , )
- function importFromITEA(XModScheduler& $sched, $o, $more) {
- if (empty($GLOBALS['ITEACONF'][$this->table]))
- return 'Error : no ITEACONF in local.inc';
- XDbIni::set('disable_xlinkclean', true);
- // Effacement de toutes les tables non nomenclature/consolidation
- if (!empty($more->clearall)) {
- foreach ($this->objectTables() as $table)
- updateQuery('delete from '.$table);
- }
- // les départements
- if ($more->dpt && is_string($more->dpt))
- $dpt_select = explode(', ', $more->dpt);
- else
- $dpt_select = explode(', ', $this->dpts);
- echo 'Fonction importFromITEA:'.implode(', ', $dpt_select)."\n";
- // Initialisation des variables et recupération des champs spécifiques à la console (commencent par tzr_)
- $tzrfields = $del = $error = $new = $maj = $no = $retry = $log_retry = $error2 = array();
- foreach ($this->xset->orddesc as $k) {
- if (strpos($k, 'tzr_') === 0)
- $tzrfields[] = $k;
- }
- if (!empty($tzrfields))
- $sqltzrfields = ', '.implode(', ', $tzrfields);
- else
- $sqltzrfields = '';
- ini_set('soap.wsdl_cache_enabled', 0);
- foreach ($dpt_select as $dpt) {
- $dptsoap = $dpt.'soap';
- $dptsoap_xs = $dpt.'soap_xs';
- $soap = new SoapClient($this->$dptsoap, array('exceptions'=>false, 'features'=>SOAP_SINGLE_ELEMENT_ARRAYS));
- if ($this->$dptsoap_xs)
- $soap_xs = new SoapClient($this->$dptsoap_xs, array('exceptions'=>false, 'features'=>SOAP_SINGLE_ELEMENT_ARRAYS));
-
- $env = $dpt.'env';
- $login = $dpt.'login';
- $pass = $dpt.'pass';
- $identification = array('env' => $this->$env, 'login' => $this->$login, 'pass' => $this->$pass);
- $timebefore = time();
- $oids = $oidsmaj = array();
- $manual = false;
- // les langues pour ce département
- $langs = $dpt.'langs';
- $langs = $this->$langs;
- $langs = explode(',', $langs);
- unset($langues);
- foreach ($langs as $lang) {
- list($tzr_lang, $itea_lang) = explode('=>', trim($lang));
- $langues[$tzr_lang] = $itea_lang;
- if ($tzr_lang != TZR_DEFAULT_LANG)
- $otherlangues[$tzr_lang] = $itea_lang;
- }
- // Recherche des références à importer
- $refs = array();
- $to_import = array();
- // sur import manuel, les refs sont spécifiées
- if(!empty($more->refs)) {
- $manual=true;
- $mrefs = explode(',',$more->refs);
- foreach ($mrefs as $i => $ref) {
- // l'exercice en cours uniquement
- $exercice = date('Y');
- $refs[$ref]->$exercice = true;
- $to_import[$exercice][$ref] = (object)array('reference'=>$ref,'type'=>'tzr','date_maj'=>date('d/m/Y'));
- $to_import[$exercice+1][$ref] = $to_import[$exercice][$ref];
- }
- }
- // sinon import de toutes les refs mises à jour
- else {
- // pour l'exercice en cours et le suivant
- foreach (array(0, 1) as $i) {
- $exercice = date('Y') + $i;
- // récupération de la liste
- if ($this->$dptsoap_xs)
- $lstRef = $this->getXSLstRef($sched, $soap_xs, $o, $identification, $exercice);
- else
- $lstRef = $this->getLstRef($sched, $soap, $o, $identification, $exercice);
- if ($lstRef->produit)
- $to_import[$exercice] = array();
- elseif ($i == 0) {
- // suppression de l'exercice
- updateQuery('delete from '.$this->prefix.'TARIF where exercice="'.$exercice.'"');
- continue;
- } else // exercice +1 vide
- break;
- // correspondance refs/UPD en base (upditea different selon exercice)
- $refs_upd = selectQuery(
- 'select reference, UPD from '.$this->prefix.'DETAILSOFREF
- where lang="'.TZR_DEFAULT_LANG.'" and dpt="'.$this->prefix.'DPT:'.$dpt.'"')
- ->fetchAll(PDO::FETCH_GROUP|PDO::FETCH_UNIQUE|PDO::FETCH_COLUMN);
- // vérification date maj
- foreach ($lstRef->produit as $i => $infos) {
- // ce test est-il vraiment nécessaire ?
- if (empty($infos->reference) || empty($infos->type))
- continue;
- $oids[] = $this->getOid($dpt, $infos->reference);
- $infos->date_maj = $this->convertDate($infos->date_maj);
- if ($infos->date_maj > $refs_upd[$infos->reference] || $more->forceall) {
- $to_import[$exercice][$infos->reference] = $infos;
- }
- }
- }
- }
- $oids = array_values(array_unique($oids));
- if (empty($to_import)) {
- XLogs::critical("ITEA : importFromITEA error: dpt $dpt, nothing to do");
- continue;
- }
- unset($lstRef, $imported);
- // Import des produits
- foreach ($to_import as $exercice => $liste_refs) {
- foreach ($liste_refs as $ref => $infos) {
- XLogs::notice("ITEA Import $ref for $exercice");
- $refoid = $this->getOid($dpt, $ref);
- unset($infosForRef);
- // pour appel recursif à analyseObject
- $this->exercice = $exercice;
- // si la ref n'est pas déjà importée
- if (!isset($imported[$ref])) {
- $imported[$ref] = 1; // même si l'import échoue, ne pas importer dans l'exercice suivant (caract !=)
- $ors = selectQuery('select KOID, UPD, conspromo' . $sqltzrfields .
- ' from ' . $this->table .
- ' where KOID = "'.$refoid.'" limit 1')->fetch();
- echo ' - Post get 1 '.date('H:i:s') . "\n";
- foreach ($langues as $tzr_lang => $itea_lang) {
- $retry = 0;
- do {
- sleep($retry);
- if ($this->$dptsoap_xs)
- $infosForRef[$tzr_lang] = $soap_xs->getInfosForRef($identification, array('exercice' => $exercice, 'reference' => $ref, 'langue' => $itea_lang));
- else
- $infosForRef[$tzr_lang] = $soap->getInfosForRef($identification, array('exercice' => $exercice, 'reference' => $ref, 'langue' => $itea_lang));
- $retry++;
- } while (empty($infosForRef[$tzr_lang]) && $retry < 5);
- }
- // Pas de réponse correcte
- if(empty($infosForRef[TZR_DEFAULT_LANG]->reference)) {
- $error2[$dpt] .= $ref." (".TZR_DEFAULT_LANG.")\n";
- continue;
- }
- $ovalues = array('upditea' => $infos->date_maj);
- echo ' - Post get 2 '.date('H:i:s') . "\n";
- // suppression de la fiche
- if ($ors) {
- $maj[$dpt]++;
- $delar = $this->delparam[$dpt];
- $delar['oid'] = $refoid;
- $delar['_nolog'] = true;
- $this->del($delar);
- // Reprise des champs tzr
- foreach ($tzrfields as $field)
- $ovalues[$field] = $ors[$field];
- } else
- $new[$dpt]++;
- $this->analyseObject($infosForRef, $this->table, $refoid, $refoid, NULL, $dpt, $ovalues);
- echo ' - Post analyse '.date('H:i:s') . "\n";
- }
- // si la ref est déjà importée (dans un autre exercice)
- // on écrase pas les infos de l'exercice en cours par celles du suivant
- // Tarifs et promo de l'année uniquement
- else {
- updateQuery('delete from '.$this->prefix.'TARIF where exercice="'.$exercice.'" and lie_ref="'.$refoid.'"');
- foreach ($langues as $tzr_lang => $itea_lang)
- $infosForRef[$tzr_lang] = $soap->getInfosForRef($identification, array('exercice' => $exercice, 'reference' => $ref, 'langue' => $itea_lang));
- // Tarifs de la reference
- foreach ($infosForRef[TZR_DEFAULT_LANG]->tarifs->tarif as $i => $tarif) {
- $tarifs[TZR_DEFAULT_LANG] = $tarif;
- foreach ($otherlangues as $tzr_lang => $itea_lang)
- $tarifs[$tzr_lang] = $infosForRef[$tzr_lang]->tarifs->tarif[$i];
- $this->analyseObject($tarifs, $this->prefix.'TARIF', $refoid, NULL, $refoid, $dpt);
- }
- // Promos de la reference
- foreach ($infosForRef[TZR_DEFAULT_LANG]->promos->promo as $i => $promo){
- $promos[TZR_DEFAULT_LANG] = $promo;
- foreach ($otherlangues as $tzr_lang => $itea_lang)
- $promos[$tzr_lang] = $infosForRef[$tzr_lang]->promos->promo[$i];
- $this->analyseObject($promos, $this->prefix.'PROMO', $refoid, NULL, $refoid, $dpt);
- }
- // Tarifs des suppléments de la référence
- // correspondance libelle -> oid
- $suppl_libelle_oid = selectQuery(
- 'select libelle, koid from '.$this->prefix.'SUPPLEMENT
- where lie="'.$refoid.'" and lang="'.TZR_DEFAULT_LANG.'"')
- ->fetchAll(PDO::FETCH_GROUP|PDO::FETCH_UNIQUE|PDO::FETCH_COLUMN);
- foreach ($infosForRef[TZR_DEFAULT_LANG]->supplements->supplement as $i => $suppl) {
- $oid_suppl = $suppl_libelle_oid[$suppl->libelle];
- foreach ($suppl->prix->tarif as $j => $tarif) {
- $suppls[TZR_DEFAULT_LANG] = $suppl;
- $tarifs[TZR_DEFAULT_LANG] = $tarif;
- foreach ($otherlangues as $tzr_lang => $itea_lang) {
- $tarifs[$tzr_lang] = $infosForRef[$tzr_lang]->supplements->supplement[$i]->prix->tarif[$j];
- }
- $this->analyseObject($tarifs, $this->prefix.'TARIF', $refoid, NULL, $oid_suppl, $dpt);
- }
- }
- // Tarifs des chambres et des suppléments des chambres
- // correspondance num -> oid
- $chambre_num_oid = selectQuery(
- 'select numeroChambre, KOID from '.$this->prefix.'CHAMBRE
- where lie="'.$refoid.'" and lang="'.TZR_DEFAULT_LANG.'"')
- ->fetchAll(PDO::FETCH_GROUP|PDO::FETCH_UNIQUE|PDO::FETCH_COLUMN);
- foreach ($infosForRef[TZR_DEFAULT_LANG]->chambres->chambre as $i => $chambre) {
- $oid_chambre = $chambre_num_oid[$chambre->numeroChambre];
- foreach ($chambre->tarifs->tarif as $j => $tarif) {
- $tarifs[TZR_DEFAULT_LANG] = $tarif;
- foreach ($otherlangues as $tzr_lang => $itea_lang) {
- $tarifs[$tzr_lang] = $infosForRef[$tzr_lang]->chambres->chambre[$i]->tarifs->tarif[$j];
- }
- $this->analyseObject($tarifs, $this->prefix.'TARIF', $refoid, NULL, $oid_chambre, $dpt);
- }
- // les suppléments de la chambre
- foreach ($chambre->supplements->supplement as $j => $suppl){
- // correspondance libelle -> oid
- $suppl_libelle_oid = selectQuery(
- 'select libelle, KOID from '.$this->prefix.'SUPPLEMENT
- where lie="'.$oid_chambre.'" and lang="'.TZR_DEFAULT_LANG.'"')
- ->fetchAll(PDO::FETCH_GROUP|PDO::FETCH_UNIQUE|PDO::FETCH_COLUMN);
- if ($oid_suppl = $suppl_libelle_oid[$suppl->libelle]) {
- foreach ($suppl->prix->tarif as $k => $tarif) {
- $tarifs[TZR_DEFAULT_LANG] = $tarif;
- foreach ($otherlangues as $tzr_lang => $itea_lang)
- $tarifs[$tzr_lang] = $infosForRef[$tzr_lang]->chambres->chambre[$i]->supplements->supplement[$j]->prix->tarif[$k];
- $this->analyseObject($tarifs, $this->prefix.'TARIF', $refoid, NULL, $oid_suppl, $dpt);
- }
- }
- }
- }
- } // import Y+1
- // Consolidation
- $this->consolidateRef($refoid);
- $oidsmaj[] = $refoid;
- XLogs::notice("ITEA Import $ref for $exercice ok");
- } // foreach liste_refs
- } // foreach to_import
- // Supression des produit non vus dans cet import pour le departement en cours
- if (!$manual && !empty($oids)) {
- $oids_todel = selectQuery('select distinct KOID from '.$this->table.
- ' where KOID NOT IN("'.implode('", "', $oids).'") and '.
- ' dpt = "'.$this->prefix.'DPT:'.$dpt.'"')
- ->fetchAll(PDO::FETCH_COLUMN);
- XLogs::critical('ITEA import '.count($oids_todel).' à effacer');
- foreach ($oids_todel as $oid) {
- $this->del(array('oid' => $oid, '_nolog' => true));
- $del[$dpt]++;
- }
- }
- // Création des rubriques, info tour et themes globaux + consolidation finale
- if (!empty($oidsmaj)) {
- $this->duplicateRubToRubGlob(array('table' => $this->prefix.'RUBRIQUE', 'dpt' => $dpt));
- $this->duplicateRubToRubGlob(array('table' => $this->prefix.'INFOTOUR', 'dpt' => $dpt));
- $this->duplicateRubToRubGlob(array('table' => $this->prefix.'THEME', 'dpt' => $dpt));
- $this->consolidateRefs($oidsmaj, $dpt);
- }
- // Rapport dur le departement
- $timing = time()-$timebefore;
- $ret .= 'Département : '.$dpt."\n";
- $ret .= 'Heure début : '.date("c", $timebefore)."\n";
- $ret .= 'Heure fin : '.date("c", time())."\n";
- $ret .= 'Timing : '.$timing." sec.\n";
- $ret .= 'Total : '.count($refs)."\n";
- $ret .= 'A jour : '.$no[$dpt]."\n";
- $ret .= 'Nouveaux : '.$new[$dpt]."\n";
- $ret .= 'Mis à jour : '.$maj[$dpt]."\n";
- $ret .= 'Erreur : '.$error[$dpt]."\n";
- $ret .= 'Erreur getInfosForRef vide : '.$error2[$dpt]."\n";
- $ret .= 'Nb itérations sur err : '.$log_retry[$dpt]."\n";
- $ret .= 'Total traités : '.($no[$dpt]+$maj[$dpt]+$new[$dpt]+$error[$dpt])."\n";
- $ret .= 'Supprimé : '.$del[$dpt]."\n";
- echo str_replace("\n", '<br>', $ret);
- }
- $sched->setStatusJob($o->KOID, 'running', $ret);
- // execution traitements supplémentaires
- if (method_exists($this, 'postImport') && (!$manual || $o->post_import == 1)) {
- $sched->setStatusJob($o->KOID, 'running', 'calling postImport');
- $this->postImport($sched, $o, $more, $oidsmaj);
- }
- $sched->setStatusJob($o->KOID, 'finished', 'done');
- XDbIni::clear('disable_xlinkclean');
- return $ret;
- }
- /// Recupere la liste des references pour un exercice
- /// utilise la version améliorée xs_getLstRef
- function getXSLstRef(&$sched, &$soap_xs, $o, $identification, $exercice) {
- $retry=0;
- do {
- $sched->setStatusJob($o->KOID, 'running', "Fonction getXSLstRef $exercice : Try $retry\n");
- $lstref->exercice = $exercice;
- $rep = $soap_xs->xs_getLstRef($identification, $lstref);
- $retry++;
- } while (empty($rep->produit) && $retry < 2);
- if (empty($rep->produit) || $retry == 2){
- $sched->setStatusJob($o->KOID, 'running','Fonction getXSLstRef : Echec - '.$retry." retries\n");
- return false;
- }
- return $rep;
- }
- /// Recupere la liste des references pour un exercice
- /// utilise la version itea getLstRef
- function getLstRef(&$sched, &$soap, $o, $identification, $exercice) {
- $retry=0;
- do {
- $sched->setStatusJob($o->KOID, 'running', "Fonction getLstRef $exercice : Try $retry\n");
- $lstref->exercice = $exercice;
- $rep = $soap->getLstRef($identification, $lstref);
- $retry++;
- } while (empty($rep->produit) && $retry < 2);
- if (empty($rep->produit) || $retry == 2){
- $sched->setStatusJob($o->KOID, 'running','Fonction getLstRef : Echec - '.$retry." retries\n");
- return false;
- }
- return $rep;
- }
- /// Analyse un objet XML
- /// rep => tableau avec obj xml par langue
- /// table => table de destination de l'objet
- /// refoid => oid du produit de reference
- /// oid => oid de la fiche a creer
- /// parent => oid du parent
- /// dpt => departement
- /// values => valeurs à passer au procInput/procEdit
- function analyseObject(&$rep, $table, $refoid, $oid = NULL, $parent = NULL, $dpt = NULL, $values = array()) {
- global $TZR_DB;
- $repbase = &$rep[TZR_DEFAULT_LANG];
- $forceedit = false;
- if (!XSystem::tableExists($table)) return;
- $oxset = XDataSource::objectFactoryHelper8('BCLASS=XDSTable&SPECS='.$table);
- // Génération de l'oid si pas passé en parametre
- if (empty($oid)) {
- if ($table == $this->prefix.'CARACTERISTIQUE')
- $oid = substr($table.':'.str_replace('?', '-', $repbase->valeur).'-'.$repbase->id . '-' .$dpt.'_'. md5($repbase->libelleLong), 0, 40);
- elseif ($table == $this->prefix.'TYPELANGUE')
- $oid = $table.':'.rewriteToAscii($repbase->code);
- // // les promos sont identiques pour tout les hébergements mais elles sont en sf
- // elseif ($table == $this->prefix.'PROMO')
- // $oid = $table.':'.$dpt.'_'.$repbase->id;
- elseif (in_array($table, $this->descrType['tables'])) {
- $code = $this->convertText($repbase->code);
- // Inversion code/description de INFOTOUR pour NOM_INFO_TOURISTIQUE
- if ($code == 'NOM_INFO_TOURISTIQUE') {
- foreach ($rep as $lang => &$replang) {
- $replang->code = $replang->description;
- $replang->description = '';
- }
- unset($replang);
- $code = $this->convertText($repbase->code);
- }
- $descr = $this->convertText($repbase->description);
- $oid = selectQuery('select KOID from '.$table.' where code = "'.addslashes($code).'" '.
- 'and description = "'.addslashes($descr).'" '.
- 'and dpt = "'.$this->prefix.'DPT:'.$dpt.'" and LANG = "'.TZR_DEFAULT_LANG.'" limit 1')
- ->fetch(PDO::FETCH_COLUMN);
- }
- }
- if (empty($oid)) {
- $oid = $oxset->getNewOID();
- }
- $objexist = selectQuery('select count(KOID) from '.$table.' where KOID = "'.$oid.'" and LANG = "'.TZR_DEFAULT_LANG.'"')
- ->fetch(PDO::FETCH_COLUMN);
- if (($table == $this->prefix.'TYPELANGUE' || $table == $this->prefix.'CARACTERISTIQUE') && $objexist)
- return $oid;
- if (!empty($parent))
- $values['lie'] = $parent;
- $values['newoid'] = $oid;
- $values['lie_ref'] = $refoid;
- $values['_nolog'] = true;
- $values['LANG_DATA'] = TZR_DEFAULT_LANG;
- $values['exercice'] = $this->exercice;
- foreach ($repbase as $field => &$value) {
- // Valeur classique (string, int, nomenclature...)
- if (!is_object($value) && !($field == 'caracteristiques' && is_array($value))) {
- $ftype = $oxset->desc[$field]->ftype;
- switch($ftype) {
- case 'XDateDef':
- $values[$field] = $this->convertDate($value);
- break;
- case 'XUrlDef':
- $this->prepareImage('img', $value, $values);
- $values[$field]['url'] = $value;
- break;
- case 'XStringSetDef':
- $soid = selectQuery('select SOID from SETS where STXT = "'.$value.'" and SLANG = "'.TZR_DEFAULT_LANG.'" and FIELD = "'.$field.'" '.
- 'and STAB = "'.$table.'" limit 1')->fetch(PDO::FETCH_COLUMN);
- if (empty($soid)) {
- $soid = selectQuery('select max(SOID)+1 as SOID from SETS')->fetch(PDO::FETCH_COLUMN);
- $order = selectQuery('select max(SORDER)+1 as max from SETS where STAB = "'.$table.'" and FIELD = "'.$field.'"')->fetch(PDO::FETCH_COLUMN);
- if (!empty($order))
- $order = 1;
- foreach ($rep as $lang => $replang) {
- updateQuery('insert into SETS (SOID, FIELD, STAB, SLANG, STXT, SORDER) values ("'.$soid.'", "'.$field.'", "'.$table.'", '.
- '"'.$lang.'", "'.$value.'", "'.$order.'")');
- }
- }
- $values[$field] = $soid;
- break;
- case 'XLinkDef':
- $target = $oxset->desc[$field]->target;
- if (!is_array($value))
- $value = array($value);
- foreach ($value as $v) {
- if (!empty($v)) {
- // suppression traitement des pictos loisirs
- // on doir récupérer les libellés dans toutes les langues
- // le champ picto devient le lien sur ITEA_PL
- // !!! changement fonctionnalité v7
- if ($field == 'languesParlees') {
- $rs = selectQuery('select KOID from '.$target.' where code = "'.$v->code.'" limit 1');
- if ($rs->rowCount() == 0) {
- $xset = XDataSource::objectFactoryHelper8('BCLASS=XDSTable&SPECS='.$target);
- $loid = $target.':'.$v->code;
- $xset->procInput(array('newoid' => $loid, 'code' => $v->code, 'libelle' => $v->libelle, '_nolog' => true));
- $values[$field][] = $loid;
- } else {
- $values[$field][] = $rs->fetch(PDO::FETCH_COLUMN);
- }
- } else {
- $rs = selectQuery('select KOID from '.$target.' where code = "'.$v.'" limit 1');
- if ($rs->rowCount() == 0) {
- $xset = XDataSource::objectFactoryHelper8('BCLASS=XDSTable&SPECS='.$target);
- $loid = $target.':'.rewriteToAscii(str_replace('?', '-', $v));
- $xset->procInput(array('newoid' => $loid, 'code' => $v, 'libelle' => $v, '_nolog' => true));
- $values[$field][] = $loid;
- } else {
- $values[$field][] = $rs->fetch(PDO::FETCH_COLUMN);
- }
- }
- }
- }
- break;
- default:
- if ($field == 'id') $field = 'refid';
- if ($field == 'classementLabel' and $value == '9') $value = '0';
- // traitement des pictos loisirs
- if ($table == $this->prefix.'LOISIRS' && $field == 'libelleLong') {
- $picto = $this->getDistinctLoisir($value);
- $picto_table = $this->prefix.'PL';
- $loid = $picto_table.':'.md5($value);
- $rs = selectQuery('select KOID from '.$picto_table.' where KOID = "'.$loid.'" limit 1');
- if ($rs->rowCount() == 0) {
- $xset = XDataSource::objectFactoryHelper8('BCLASS=XDSTable&SPECS='.$picto_table);
- $xset->procInput(array('newoid' => $loid, 'code' => $value, '_nolog' => true));
- $values['picto'][] = $loid;
- } else {
- $values['picto'][] = $rs->fetch(PDO::FETCH_COLUMN);
- }
- }
- $values[$field] = $this->convertText($value);
- if ($oxset->desc[$field]->translatable) {
- foreach ($rep as $lang => $replang) {
- $tradvalues[$lang][$field] = $this->convertText($replang->$field);
- }
- }
- break;
- }
- } else {
- // On veut recuperer un sous objet pour le mettre directement dans la fiche en cours
- if (in_array($field, $this->directsubdata[$table])) {
- $obj = array();
- foreach ($rep as $lang => $replang) {
- $obj[$lang] = $replang->$field;
- }
- $foid = $this->analyseObject($obj, $table, $refoid, $oid, NULL, $dpt);
- $forceedit = true;
- } elseif ($subfield = $this->directuniquesubdata[$table][$field]) {
- $values[$field] = $this->convertText($value->$subfield);
- if ($oxset->desc[$field]->translatable) {
- foreach ($rep as $lang => $replang) {
- $replang->$field->$subfield = $this->convertText($replang->$field->$subfield);
- $tradvalues[$lang][$field] = addslashes($replang->$field->$subfield);
- }
- }
- // Lien vers un objet complexe unique (donc en lien dans la table) (id loisir)
- } elseif (isset($oxset->desc[$field]) && !$oxset->desc[$field]->multivalued) {
- $obj = array();
- foreach ($rep as $lang => $replang)
- $obj[$lang] = $replang->$field;
- $foid = $this->analyseObject($obj, $oxset->desc[$field]->target, $refoid, NULL, NULL, $dpt);
- $values[$field] = $foid;
- // Lien vers un objet complexe multiple en lien multiple ou en sous fiches
- } else {
- // Cas particulier des caractéristiques toutes foireuses dans pieces et chambres
- if ($field == 'caracteristiques' && is_array($value)) {
- foreach ($rep as $lang => &$replang) {
- foreach ($replang->$field as &$tmp)
- $tmp = (object)$tmp;
- $replang->$field = (object)array('carateristique' => $replang->$field);
- }
- $value = $rep[TZR_DEFAULT_LANG]->$field;
- }
- foreach ($value as $t => $objs) {
- foreach ($rep as $lang => &$replang) {
- if (!is_array($replang->$field->$t))
- $replang->$field->$t = array($replang->$field->$t);
- }
- unset($replang);
- foreach ($rep[TZR_DEFAULT_LANG]->$field->$t as $i => $object_deflang) {
- $obj = array();
- // les descriptifsComp ne sont pas les mêmes dans les différentes langues
- // recherche de correspondance sur type et code
- if ($field == 'descriptifsComp') {
- $obj[TZR_DEFAULT_LANG] = $object_deflang;
- foreach ($rep as $lang => $replang) {
- if ($lang == TZR_DEFAULT_LANG)
- continue;
- foreach ($replang->$field->$t as $j => $object_other_lang) {
- if ($object_other_lang->type == $object_deflang->type
- && $object_other_lang->code == $object_deflang->code) {
- $obj[$lang] = $object_other_lang;
- }
- }
- }
- }
- // sinon, on prend dans les objects dans l'ordre de l'index
- else
- foreach ($rep as $lang => $replang) {
- $objlist = $replang->$field->$t;
- $obj[$lang] = $objlist[$i];
- }
- $isok = false;
- if ($field == 'descriptifsComp' && $table == $this->prefix.'DETAILSOFREF') {
- if (in_array($obj[TZR_DEFAULT_LANG]->type, $this->descrType['link'])) {
- $lower = strtolower($obj[TZR_DEFAULT_LANG]->type);
- $newf = $this->descrType['fields'][$lower];
- if (!in_array($lower, $this->descrType['notlink'])) {
- $values[$newf][] = $this->analyseObject($obj, $oxset->desc[$newf]->target, $refoid, NULL, NULL, $dpt, $this->descrType['cplt'][$lower]);
- }
- $isok = true;
- } elseif (in_array($obj[TZR_DEFAULT_LANG]->type, $this->descrType['no'])) {
- continue;
- }
- } elseif ($field == 'urls' && $table == $this->prefix.'DETAILSOFREF') {
- // Gestion de la photo principale + vignette
- if (isset($oxset->desc[strtolower($obj[TZR_DEFAULT_LANG]->type)])) {
- $isok = true;
- $newf = strtolower($obj[TZR_DEFAULT_LANG]->type);
- if ($oxset->desc[$newf]->ftype == 'XImageDef') {
- $this->prepareImage($newf, $obj[TZR_DEFAULT_LANG]->url, $values);
- $values[$newf] = $obj[TZR_DEFAULT_LANG]->url;
- } else
- $values[$newf]['url'] = $obj[TZR_DEFAULT_LANG]->url;
- // Gestion de l'album photo
- } elseif (substr(strtolower($obj[TZR_DEFAULT_LANG]->type), 0, 5) == 'photo' && strtolower($obj[TZR_DEFAULT_LANG]->type) != 'photo') {
- $isok = true;
- $this->analyseObject($obj, $this->prefix.'ALBPHOTOINT', $refoid, NULL, $oid, $dpt);
- }
- } elseif ($field == 'telephones' && $table == $this->prefix.'CONTACT') {
- $isok = true;
- if (isset($oxset->desc[strtolower($obj[TZR_DEFAULT_LANG]->type)])) {
- $newf = strtolower($obj[TZR_DEFAULT_LANG]->type);
- if (empty($values[$newf]))
- $values[$newf] = $obj[TZR_DEFAULT_LANG]->numero;
- else
- $values[$newf] .= ', '.$obj[TZR_DEFAULT_LANG]->numero;
- }
- } elseif ($table == $this->prefix.'PERIODPROMO') {
- $isok = true;
- // Consolidation des champs période directement dans la table ITEA_PERIODPROMO
- if (!isset($oxset->desc[$field])) {
- $values[$t.$field] = $this->convertDate($obj[TZR_DEFAULT_LANG]);
- }
- }
- if (!$isok) {
- if (isset($oxset->desc[$field]) && $oxset->desc[$field]->multivalued) {
- $values[$field][] = $this->analyseObject($obj, $oxset->desc[$field]->target, $refoid, NULL, NULL, $dpt);
- } else {
- $values[$field][] = $this->analyseObject($obj, strtoupper($this->prefix.''.$t), $refoid, NULL, $oid, $dpt);
- }
- }
- }
- }
- }
- }
- }
- if ($table == $this->prefix.'DETAILSOFREF') {
- // Coordonnées TZR
- if (!empty($values['latitude']) && !empty($values['longitude'])) {
- $values['coordx'] = $values['latitude'].';'.$values['longitude'].';M;N/A;'.date('Y-m-d H:i:s');
- }
- // Caractéristiques consolidées
- if ($this->needconscaract && is_object($repbase->caracteristiques)) {
- foreach ($repbase->caracteristiques->caracteristique as $c) {
- if ($c->valeur == 'O') {
- $value = $this->getConsCarac($c->id, $values['type'], $dpt);
- if (!empty($value)) $values['conscarac'][] = $value;
- }
- }
- }
- }
- if ($dpt) $values['dpt'] = $this->prefix.'DPT:'.$dpt;
- // Insere ou edite l'entrée
- if (empty($objexist) && !$forceedit) {
- // Boucle pour forcer les champs numériques à NULL s'ils ne sont pas renseignés (car sinon 0, et c'est pas bien)
- foreach ($oxset->desc as $fn => &$fo) {
- if ($fo->ftype == 'XRealDef' && !isset($values[$fn])) $values[$fn] = '';
- }
- $values['_nolog'] = true;
- $ret = $oxset->procInput($values);
- } else {
- $ret['oid'] = $values['oid'] = $oid;
- $values['_nolog'] = true;
- $oxset->procEdit($values);
- }
- // Traduction
- if ($oxset->getTranslatable()) {
- foreach ($tradvalues as $lang => $values) {
- if ($lang != TZR_DEFAULT_LANG) {
- $q = array();
- foreach ($values as $f => $v) {
- if (!empty($v)) $q[] = $f.' = '.$TZR_DB->quote($v);
- }
- if (!empty($q))
- updateQuery('update '.$table.' set '.implode(', ', $q).' where KOID = "'.$ret['oid'].'" and LANG = "'.$lang.'"');
- }
- }
- }
- return $ret['oid'];
- }
- /// Import les disponibilité depuis ITEA via tache scheduler
- function importDispoFromITEA(XModScheduler& $sched, $o, $more) {
- if (empty($GLOBALS['ITEACONF'][$this->table]))
- return 'Error : no ITEACONF in local.inc';
- // Si des imports de ressources sont en cours, on reporte l'import des dispo d'une heure pour ne pas trop ralentir la recuperation
- $nb = countSelectQuery('select count(KOID) from TASKS where title like "Import ITEA%" and status = "running"');
- if ($nb > 0) {
- updateQuery('UPDATE TASKS SET status = "scheduled", rem = "'.date('Y-m-d H:i:s').' : Reporté car import ITEA en cours", '.
- 'ptime = "'.date('Y-m-d H:i:s', strtotime('+1 hour')).'" WHERE KOID = "'.$o->KOID.'"', false);
- return;
- }
- // Paramètre des recup : clé => numero du jour dans la semaine
- // valeur => tableau : cle => duree
- // valeur => tableau des types
- // donner une chance à la class d'implémentation de personnaliser la conf
- if (method_exists($this, 'getDispoConf'))
- $torecup = $this->getDispoConf();
- else {
- if ($more->dtype == 'other') {
- $types = selectQuery('select distinct KOID from '.$this->prefix.'TYPEPRODUIT '.
- 'where KOID not in("'.$this->prefix.'TYPEPRODUIT:g", "'.$this->prefix.'TYPEPRODUIT:h)"')
- ->fetchAll(PDO::FETCH_COLUMN);
- $torecup = array('5' => array('2' => $types, '7' => $types, '14' => $types, '21' => $types));
- } else {
- $torecup = array(
- '5' => array('2' => array($this->prefix.'TYPEPRODUIT:g', $this->prefix.'TYPEPRODUIT:h'),
- '7' => array($this->prefix.'TYPEPRODUIT:g', $this->prefix.'TYPEPRODUIT:h'),
- '8' => array($this->prefix.'TYPEPRODUIT:h'),
- '14' => array($this->prefix.'TYPEPRODUIT:g', $this->prefix.'TYPEPRODUIT:h'),
- '15' => array($this->prefix.'TYPEPRODUIT:h'),
- '21' => array($this->prefix.'TYPEPRODUIT:g', $this->prefix.'TYPEPRODUIT:h')
- ),
- '6' => array('7' => array($this->prefix.'TYPEPRODUIT:g', $this->prefix.'TYPEPRODUIT:h'),
- '8' => array($this->prefix.'TYPEPRODUIT:h'),
- '14' => array($this->prefix.'TYPEPRODUIT:g', $this->prefix.'TYPEPRODUIT:h'),
- '15' => array($this->prefix.'TYPEPRODUIT:h'),
- '21' => array($this->prefix.'TYPEPRODUIT:g', $this->prefix.'TYPEPRODUIT:h')
- )
- );
- }
- }
- $ts = time();
- $end = date('Y-m-d',strtotime('+12 month'));
- $liste = array();
- if (!empty($more->dpts))
- $dpts = $more->dpts;
- else
- $dpts = $this->dpts;
- if (empty($dpts))
- return 'Erreur : aucun département spécifié';
- $dpts = explode(',', $dpts);
- foreach ($dpts as $dpt){
- $liste[trim($dpt)] = array();
- }
- $ds_dispogen = XDataSource::objectFactoryHelper8('BCLASS=XDSTable&SPECS='.$this->prefix.'DISPOGEN');
- updateQuery('delete from '.$this->prefix.'DISPOGEN where deb < curDate()');
- do {
- $isodate = date('Y-m-d', $ts);
- $date = date('d/m/Y', $ts);
- $dayinweek = date('N', $ts);
- foreach ($torecup[$dayinweek] as $duree => $types) {
- foreach ($types as $type) {
- echo date('H:i:s').' => ';
- $refs = $this->xset->getDispoFromITEA($liste, $date, $duree, $type);
- echo $date.' - '.$duree.' - '.$type.' - '.(strpos($refs, 'soaperrorcode:') !== false? $refs: count(explode(';', $refs)))."\n";
- updateQuery('delete from '.$this->prefix.'DISPOGEN where deb = "'.$isodate.'" and duree = "'.$duree.'" and type = "'.$type.'"');
- if (strpos($refs, 'soaperrorcode:') === false) {
- $ds_dispogen->procInput(array('type' => $type, 'duree' => $duree, 'deb' => $isodate, 'refs' => $refs, '_nolog' => true));
- }
- }
- if (is_object($sched)) {
- $ns = $sched->setStatusJob($o->KOID, 'running', $isodate.'-'.$duree);
- if ($ns===false) return; // ns = false si la tache n'existe plus
- }
- }
- $ts = strtotime($isodate.' +1 day');
- } while ($isodate<=$end);
- // suppression des dispos dépassées
- updateQuery('delete from '.$this->prefix.'DISPOGEN where date_add(deb, interval duree day) < now()');
- // execution traitements supplémentaires
- if (method_exists($this, 'postImportDispo')) {
- $sched->setStatusJob($o->KOID, 'running', 'calling postImportDispo');
- $this->postImportDispo($sched, $o, $more);
- }
- $sched->setStatusJob($o->KOID, 'finished', 'done');
- }
- /// Prepare un fichier image à partir d'une url
- function prepareImage($field, $url, &$values) {
- $file = TZR_TMP_DIR.'ITEA'.uniqid();
- $retry = 0;
- do {
- $content = file_get_contents($url);
- $retry++;
- } while(!$content && $retry < 3);
- if (empty($content)) {
- XLogs::notice('xmoditea::prepareImage cannot fetch '.$url);
- } else {
- file_put_contents($file, $content);
- $mimeClasse = XMimeTypes::getInstance();
- $mime = $mimeClasse->get_file_type($file);
- if ($mimeClasse->isImage($mime)) {
- $values[$field.'_title'] = '';
- $values[$field.'_HID'] = array('old' => 'N%3B');
- $values[$field] = 1;
- $_FILES[$field]['tmp_name'] = $file;
- $_FILES[$field]['type'] = $mime;
- $_FILES[$field]['name'] = $url;
- $_FILES[$field]['size'] = filesize($file);
- }
- }
- }
- /// Convertion de texte ITEA en texte normal
- function convertText($text) {
- $from = array("\xc2\x92", "\xc2\x9C", "\xc2\x80");
- $to = array("'", "oe", "€");
- $text = str_replace($from, $to, $text);
- convert_charset($text, 'UTF-8', 'ISO-8859-15');
- cp1252_replace($text);
- convert_charset($text, 'ISO-8859-15', 'UTF-8');
- return $text;
- }
- /// Convertit une date ITEA au format international
- function convertDate($date) {
- if (!preg_match('/^([0-9]{2})\/?([0-9]{2})\/?([0-9]{4}|[0-9]{2})$/', $date, $matches))
- return $date;
- if (strlen($matches[3]) == 2)
- if ($matches[3] >= 50)
- $matches[3] = '19'.$matches[3];
- else
- $matches[3] = '20'.$matches[3];
- return $matches[3] . '-' . $matches[2] . '-' . $matches[1];
- }
- /// Recupere une caracteristique consolidée à partir de son id, de son type et de son departement
- function getConsCarac($id, $type, $dpt) {
- if (is_array($type))
- $type = $type[0];
- $type = str_replace($this->prefix.'TYPEPRODUIT:', '', $type);
- if (empty($this->_cache->conscarac)) {
- $rs = &selectQuery('select * from '.$this->prefix.'CONSCARAC');
- while($ors = $rs->fetch()) {
- foreach ($ors as $f => $v) {
- if (strpos($f, 'c')!==0 || empty($v)) continue;
- $lid = explode(', ', $v);
- foreach ($lid as $fooid) {
- $this->_cache->conscarac[$f][$fooid] = $ors['KOID'];
- }
- }
- }
- }
- return $this->_cache->conscarac['c'.$type.$dpt][$id];
- }
- /// Recupere un libelle Loisir unique
- function getDistinctLoisir($lib) {
- if (empty($this->_cache->consloisirs)) {
- $this->_cache->consloisirs = selectQuery('select src, dest from '.$this->prefix.'CONSLOISIRS')
- ->fetchAll(PDO::FETCH_COLUMN|PDO::FETCH_UNIQUE);
- }
- if (!empty($this->_cache->consloisirs[$lib]))
- return $this->_cache->consloisirs[$lib];
- else
- return $lib;
- }
- /// Execute toutes les consolidations d'un departement (utilisé pour une consolidation globale manuelle)
- function executeAllConsolidation($ar = NULL) {
- ini_set('max_execution_time', 3600);
- $p = new XParam($ar, array('dpt' => '04'));
- $dpt = $p->get('dpt');
- if (empty($dpt)) return 'no dpt';
- $oids = selectQuery('select KOID from '.$this->table.
- ' where dpt = "'.$this->prefix.'DPT:'.$dpt.'" and LANG = "'.TZR_DEFAULT_LANG.'"')
- ->fetchAll(PDO::FETCH_COLUMN);
- foreach ($oids as $oid)
- $this->consolidateRef($oid);
- $this->duplicateRubToRubGlob(array('table' => $this->prefix.'RUBRIQUE', 'dpt' => $dpt));
- $this->duplicateRubToRubGlob(array('table' => $this->prefix.'INFOTOUR', 'dpt' => $dpt));
- $this->duplicateRubToRubGlob(array('table' => $this->prefix.'THEME', 'dpt' => $dpt));
- $this->consolidateRefs($oids, $dpt);
- echo 'ok';
- }
- /// Consolide une fiche (appelé pour chaque fiche)
- /// (pour une consolidation complete, consolidateRefs doit etre aussi appelée)
- /// Retourne l'ors de la fiche pour un enrichissement eventuel de la fonction
- function consolidateRef($oid, $edit = true) {
- if (empty($oid)) return;
- echo ' - Debut consolidation '.date('H:i:s') . "\n";
- $orsref = selectQuery('select * from '.$this->table.
- ' where KOID = "'.$oid.'" and LANG = "'.TZR_DEFAULT_LANG.'" limit 1')
- ->fetch();
- if (!$orsref)
- return;
- $ar = array();
- // Tarif min max
- if (!empty($this->xset->desc['constarifmin']) && !empty($this->xset->desc['constarifmax'])) {
- if ($orsref['type'] == $this->prefix.'TYPEPRODUIT:h')
- $ors = selectQuery('select min(montant) as min, max(montant) as max '.
- 'from '.$this->prefix.'TARIF where lie_ref = "'.$orsref['KOID'].'"'.
- 'and duree = "'.$this->prefix.'TYPEDUREETARIF:1" '.
- 'and lie like "'.$this->prefix.'CHAMBRE%" and lang="'.TZR_DEFAULT_LANG.'" '.
- 'and libelle not like "%suppl%" and libelle not like "%P.SUP%"')
- ->fetch();
- elseif ($orsref['type'] == $this->prefix.'TYPEPRODUIT:se' || $orsref['type'] == $this->prefix.'TYPEPRODUIT:gs' || $orsref['type'] == $this->prefix.'TYPEPRODUIT:ge')
- $ors = selectQuery('select montant as min, montant_maxi as max '.
- 'from '.$this->prefix.'TARIF where lie_ref = "'.$orsref['KOID'].'"'.
- 'and libelle = "PERS.NUIT"')
- ->fetch();
- else // lie évite suppl
- $ors = selectQuery('select min(montant) as min, max(montant) as max '.
- 'from '.$this->prefix.'TARIF where lie = "'.$orsref['KOID'].'"'.
- 'and duree = "'.$this->prefix.'TYPEDUREETARIF:7"')
- ->fetch();
- $ar['constarifmin'] = $ors['min'];
- $ar['constarifmax'] = $ors['max'];
- }
- // Animaux
- if (!empty($this->xset->desc['consani'])) {
- if (strpos($orsref['caracteristiques'], $this->animauxok)!==false) $ar['consani'] = 1;
- else $ar['consani'] = 2;
- }
- // Table d'hote
- if (!empty($this->xset->desc['constho'])) {
- if (strpos($orsref['caracteristiques'], $this->restook)!==false) $ar['constho'] = 1;
- else $ar['constho'] = 2;
- }
- // Album pho…
Large files files are truncated, but you can click here to view the full file