fxGetVar($sqlCheck); if ($intCheck < 1) { $sqlCreate = "CREATE TABLE " . $strReportTableName . " (row_id int(10) unsigned AUTO_INCREMENT"; foreach ($tabFields as $field) { if (array_key_exists(substr($field, 4), $tabInfoFields)) $sqlCreate .= ", " . $field . " " . $tabInfoFields[substr($field, 4)]['COLUMN_TYPE']; else $sqlCreate .= ", " . $field . " varchar(50)"; } $sqlCreate .= ",PRIMARY KEY (row_id)) ENGINE=MyISAM;"; $qryCreate = $GLOBALS['db']->fxQuery($sqlCreate); } // vider la table $sqlTruncate = "TRUNCATE TABLE " . $strReportTableName; $qryTruncate = $GLOBALS['db']->fxQuery($sqlTruncate); return true; } function fxCreateSet($strReportTableName, $tabData) { $tabOutput = array(); $tabInfoFields = $GLOBALS['db']->fxGetInfoFields($strReportTableName); $tabKeys = array_keys($tabData); foreach ($tabKeys as $key) { switch ($tabInfoFields[$key]['DATA_TYPE']) { case 'tinyint': case 'int': case 'smallint': case 'mediumint': case 'bigint': $tabOutput[] = $key . " = " . intval($tabData[$key]); break; case 'double': case 'float': $tabOutput[] = $key . " = " . floatval($tabData[$key]); break; default: $tabOutput[] = $key . " = '" . $GLOBALS['db']->fxEscape($tabData[$key]) . "'"; } } return $tabOutput; } $tabOutput = $tabFields = array(); $strReportTableName = "rapport_pnq_" . session_id() . "_" . str_replace('-', '', fxGetDate()); $_SESSION['rapports'][$intMenu] = $strReportTableName; // Trouver les commandes de l'�v�nement 102 $sqlCommandes = "SELECT 'ACHETEUR' AS info_ligne, a.no_commande AS ach_no_commande, a.no_panier AS ach_no_panier, a.TransactionID AS ach_TransactionID, a.ach_maj AS ach_ach_maj, e.eve_nom_fr AS ach_eve_nom_fr, a.com_id AS ach_com_id, a.com_nom AS ach_com_nom, a.com_prenom AS ach_com_prenom, a.com_adresse AS ach_com_adresse, a.com_ville AS ach_com_ville, p.pro_nom_fr AS ach_pro_nom_fr, c.pay_nom_fr AS ach_pay_nom_fr, a.com_codepostal AS ach_com_codepostal, a.com_telephone1 as ach_com_telephone1, a.com_telephone2 AS ach_com_telephone2, a.ach_total AS ach_ach_total, (a.ach_total - a.fra_total) AS ach_montant_promoteur, a.fra_total AS ach_fra_total, a.fra_avant_tx AS ach_fra_avant_tx, a.fra_taxe1 AS ach_fra_taxe1, a.fra_taxe2 AS ach_fra_taxe2, a.rabais_total AS ach_rabais_total FROM inscriptions_panier_acheteurs a, inscriptions_provinces p, inscriptions_pays c, inscriptions_panier_evenements e WHERE a.pro_id = p.pro_id AND a.pay_id = c.pay_id AND a.eve_id = e.eve_id AND a.eve_id = 102 AND a.sta_id = 3 ORDER BY no_commande DESC, ach_maj DESC"; $tabCommandes = $GLOBALS['db']->fxGetResults($sqlCommandes); if ($tabCommandes != null) { for ($intCtr = 1; $intCtr <= count($tabCommandes); $intCtr++) { $strNoPanier = $tabCommandes[$intCtr]['ach_no_panier']; $strNoCommande = $tabCommandes[$intCtr]['ach_no_commande']; $strDateAchat = $tabCommandes[$intCtr]['ach_ach_maj']; $strTransactionID = $tabCommandes[$intCtr]['ach_TransactionID']; $strEvenement = $tabCommandes[$intCtr]['ach_eve_nom_fr']; $tabOutput[] = $tabCommandes[$intCtr]; if ($intCtr == 1) $tabFields = array_keys($tabCommandes[1]); // info rabais $sqlRabais = "SELECT 'RABAIS' AS info_ligne, '$strNoCommande' AS ach_no_commande, '$strDateAchat' AS ach_ach_maj, '$strTransactionID' AS ach_TransactionID, '$strEvenement' AS ach_eve_nom_fr, a.no_panier AS ach_no_panier, r.pra_id AS rab_pra_id, a.prac_id AS rab_prac_id, r.rab_description_fr AS rab_rab_description_fr , r.rab_code AS rab_rab_code, a.rab_montant AS rab_rab_montant FROM inscriptions_panier_rabais r, inscriptions_panier_rabais_acheteurs a WHERE a.pra_id = r.pra_id AND r.pra_depot = 0 AND a.no_panier = '" . $GLOBALS['db']->fxEscape($strNoPanier) . "' ORDER BY r.rab_priorite, r.rab_code, r.pra_maj"; $tabRabais = $GLOBALS['db']->fxGetResults($sqlRabais); if ($tabRabais != null) { $tabKeys = array_keys($tabRabais[1]); $tabFields = array_merge($tabFields, $tabKeys); foreach ($tabRabais as $rabais) { $tabOutput[] = $rabais; } } // info �preuves $sqlEpreuves = "SELECT '�PREUVE' AS info_ligne, r.no_commande AS ach_no_commande, '$strDateAchat' AS ach_ach_maj, '$strTransactionID' AS ach_TransactionID, '$strEvenement' AS ach_eve_nom_fr, c.no_panier AS ach_no_panier, c.pec_id AS epr_pec_id, e.epr_type_fr AS epr_epr_type_fr, e.epr_nom_fr AS epr_epr_nom_fr, c.pec_nom_equipe AS epr_pec_nom_equipe, c.pec_prix AS epr_pec_prix FROM inscriptions_panier_epreuves e, inscriptions_panier_epreuves_commandees c, resultats_epreuves_commandees r WHERE e.epr_id = c.epr_id AND c.pec_id = r.pec_id_original AND c.no_panier = '" . $GLOBALS['db']->fxEscape($strNoPanier) . "' ORDER BY e.epr_date, e.epr_heure"; $tabEpreuves = $GLOBALS['db']->fxGetResults($sqlEpreuves); if ($tabEpreuves != null) { for ($intCtr2 = 1; $intCtr2 <= count($tabEpreuves); $intCtr2++) { $intEpreuveCommandee = $tabEpreuves[$intCtr2]['epr_pec_id']; $tabOutput[] = $tabEpreuves[$intCtr2]; if ($intCtr2 == 1) { $tabKeys = array_keys($tabEpreuves[1]); $tabFields = array_merge($tabFields, $tabKeys); } // info questions �preuves $sqlQuestionsEpreuves = "SELECT 'QUESTION �PREUVE' AS info_ligne, no_commande AS ach_no_commande, '$strDateAchat' AS ach_ach_maj, '$strTransactionID' AS ach_TransactionID, '$strEvenement' AS ach_eve_nom_fr, no_panier AS ach_no_panier, pqu_id_original AS qep_pqu_id, pec_id AS epr_pec_id, que_question_fr AS qep_que_question_fr, que_choix_fr AS qep_que_choix_fr FROM resultats_questions WHERE pec_id = " . intval($intEpreuveCommandee); $tabQuestionsEpreuves = $GLOBALS['db']->fxGetResults($sqlQuestionsEpreuves); if ($tabQuestionsEpreuves != null) { $tabKeys = array_keys($tabQuestionsEpreuves[1]); $tabFields = array_merge($tabFields, $tabKeys); foreach ($tabQuestionsEpreuves as $question) { $tabOutput[] = $question; } } // info participants $sqlParticipants = "SELECT 'PARTICIPANT' AS info_ligne, p.no_commande AS ach_no_commande, '$strDateAchat' AS ach_ach_maj, '$strTransactionID' AS ach_TransactionID, '$strEvenement' AS ach_eve_nom_fr, p.no_panier AS ach_no_panier, p.par_id_original AS par_par_id, p.pec_id AS epr_pec_id, r.rol_nom_fr AS par_rol_nom_fr, p.par_prenom AS par_par_prenom, p.par_nom AS par_par_nom, p.par_naissance AS par_par_naissance, p.par_age AS par_par_age, p.par_sexe AS par_par_sexe, p.par_adresse AS par_par_adresse, p.par_ville AS par_par_ville, (SELECT pro_nom_fr FROM inscriptions_provinces WHERE pro_id = p.pro_id) AS par_pro_nom_fr, p.par_codepostal AS par_par_codepostal, (SELECT pay_nom_fr FROM inscriptions_pays WHERE pay_id = p.pay_id) AS par_pay_nom_fr, p.par_telephone1 AS par_par_telephone1, p.par_telephone2 AS par_par_telephone2, p.par_courriel AS par_par_courriel, p.par_no_equipe AS par_par_no_equipe FROM resultats_participants p, inscriptions_roles r WHERE p.rol_id = r.rol_id AND p.pec_id = " . intval($intEpreuveCommandee) . " ORDER BY p.par_id_original"; $tabParticipants = $GLOBALS['db']->fxGetResults($sqlParticipants); if ($tabParticipants != null) { for ($intCtr3 = 1; $intCtr3 <= count($tabParticipants); $intCtr3++) { $intParticipant = $tabParticipants[$intCtr3]['par_par_id']; $tabOutput[] = $tabParticipants[$intCtr3]; if ($intCtr3 == 1) { $tabKeys = array_keys($tabParticipants[1]); $tabFields = array_merge($tabFields, $tabKeys); } // info questions participant $sqlQuestionsParticipant = "SELECT 'QUESTION PARTICIPANT' AS info_ligne, no_commande AS ach_no_commande, '$strDateAchat' AS ach_ach_maj, '$strTransactionID' AS ach_TransactionID, '$strEvenement' AS ach_eve_nom_fr, no_panier AS ach_no_panier, pqu_id_original AS qpa_pqu_id, par_id AS par_par_id, que_question_fr AS qpa_que_question_fr, que_choix_fr AS qpa_que_choix_fr FROM resultats_questions WHERE par_id = " . intval($intParticipant); $tabQuestionsParticipant = $GLOBALS['db']->fxGetResults($sqlQuestionsParticipant); if ($tabQuestionsParticipant != null) { $tabKeys = array_keys($tabQuestionsParticipant[1]); $tabFields = array_merge($tabFields, $tabKeys); foreach ($tabQuestionsParticipant as $question) { $tabOutput[] = $question; } } } } // info produits $sqlProduits = "SELECT 'PRODUIT' AS info_ligne, r.no_commande AS ach_no_commande, '$strDateAchat' AS ach_ach_maj, '$strTransactionID' AS ach_TransactionID, '$strEvenement' AS ach_eve_nom_fr, p.no_panier AS ach_no_panier, p.pec_id AS epr_pec_id, p.par_id AS par_par_id, t.pt_nom_fr AS pro_pt_nom_fr, p.pro_nom_fr AS pro_pro_nom_fr, p.pro_prix AS pro_pro_prix FROM inscriptions_panier_produits_new p, inscriptions_produits_types t, resultats_produits_new r WHERE p.pt_id = t.pt_id AND p.ppn_id = r.ppn_id_original AND p.pec_id = " . intval($intEpreuveCommandee); $tabProduits = $GLOBALS['db']->fxGetResults($sqlProduits); if ($tabProduits != null) { $tabKeys = array_keys($tabProduits[1]); $tabFields = array_merge($tabFields, $tabKeys); foreach ($tabProduits as $produit) { $tabOutput[] = $produit; } } } } } } // ajouter les champs au tableau $tabInfoFields = $GLOBALS['db']->fxGetInfoFields('inscriptions_panier_acheteurs,inscriptions_provinces,inscriptions_pays,inscriptions_panier_evenements,inscriptions_panier_rabais,inscriptions_panier_rabais_acheteurs,inscriptions_panier_epreuves,inscriptions_panier_epreuves_commandees,resultats_epreuves_commandees,resultats_questions,resultats_participants,inscriptions_roles,inscriptions_panier_produits_new,resultats_produits_new,inscriptions_produits_types'); $tabFields = array_unique($tabFields); // cr�er et vider la table fxGetCreateTable($strReportTableName, $tabFields, $tabInfoFields); // ins�rer les valeurs foreach ($tabOutput as $row) { // cr�er le tableau des champs/valeurs $tabFieldsValues = fxCreateSet($strReportTableName, $row); $sqlInsert = "INSERT INTO " . $strReportTableName . " SET " . implode(', ', $tabFieldsValues); $qryInsert = $GLOBALS['db']->fxQuery($sqlInsert); }