$entry) { if ($index > 0) { $placeholders[] = "( :id_$index, :exe_ref_$index, :prest_id_$index, :prest_lib_$index, :prest_lib2_$index, :catprest_id_$index, :catprest_lib_$index, :prest_period_$index, :prest_closed_$index, :doss_id_$index, :doss_lib_$index, :etdoss_id_$index, :etdoss_lib_$index, :doss_nb_inscrit_$index, :od_meyclub_subv_$index, :doss_partce_$index, :doss_partod_$index, :doss_montant_total_$index, :comm_ref_$index, :od_matricule_$index, :od_nom_$index, :od_prenom_$index, :hismo_date_crea_$index)"; $params[":id_$index"] = $entry[1] . $entry[8]; if (preg_match('/\b(\d{4})\b/', $entry[0], $match)) { $params[":exe_ref_$index"] = (int)$match[1]; } else { $params[":exe_ref_$index"] = null; } $params[":prest_id_$index"] = !empty($entry[1]) ? (int)$entry[1] : null; $params[":prest_lib_$index"] = $entry[2]; $params[":prest_lib2_$index"] = $entry[3]; $params[":catprest_id_$index"] = !empty($entry[4]) ? (int)$entry[4] : null; $params[":catprest_lib_$index"] = $entry[5]; $params[":prest_period_$index"] = $entry[6]; $params[":prest_closed_$index"] = $entry[7]; $params[":doss_id_$index"] = $entry[8]; $params[":doss_lib_$index"] = $entry[9]; $params[":etdoss_id_$index"] = $entry[10]; $params[":etdoss_lib_$index"] = $entry[11]; $params[":doss_nb_inscrit_$index"] = is_numeric($entry[12]) ? (int)$entry[12] : null; $params[":od_meyclub_subv_$index"] = $entry[13]; $params[":doss_partce_$index"] = $entry[14]; $params[":doss_partod_$index"] = $entry[15]; $params[":doss_montant_total_$index"] = $entry[16]; $params[":comm_ref_$index"] = $entry[17]; $params[":od_matricule_$index"] = $entry[18]; $params[":od_nom_$index"] = $entry[19]; $params[":od_prenom_$index"] = $entry[20]; $params[":hismo_date_crea_$index"] = $entry[21]; } } $sql = "INSERT INTO " . DB_T_DOSSIERS_PROWEB . " ( id, exe_ref, prest_id, prest_lib, prest_lib2, catprest_id, catprest_lib, prest_period, prest_closed, doss_id, doss_lib, etdoss_id, etdoss_lib, doss_nb_inscrit, od_meyclub_subv, doss_partce, doss_partod, doss_montant_total, comm_ref, od_matricule, od_nom, od_prenom, hismo_date_crea ) VALUES " . implode(", ", $placeholders) . " ON DUPLICATE KEY UPDATE exe_ref = VALUES(exe_ref), prest_id = VALUES(prest_id), prest_lib = VALUES(prest_lib), prest_lib2 = VALUES(prest_lib2), catprest_id = VALUES(catprest_id), catprest_lib = VALUES(catprest_lib), prest_period = VALUES(prest_period), prest_closed = VALUES(prest_closed), doss_id = VALUES(doss_id), doss_lib = VALUES(doss_lib), etdoss_id = VALUES(etdoss_id), etdoss_lib = VALUES(etdoss_lib), doss_nb_inscrit = VALUES(doss_nb_inscrit), od_meyclub_subv = VALUES(od_meyclub_subv), doss_partce = VALUES(doss_partce), doss_partod = VALUES(doss_partod), doss_montant_total = VALUES(doss_montant_total), comm_ref = VALUES(comm_ref), od_matricule = VALUES(od_matricule), od_nom = VALUES(od_nom), od_prenom = VALUES(od_prenom), hismo_date_crea = VALUES(hismo_date_crea)"; db::query($sql); foreach ($params as $key => $value) { db::bind($key, $value); } try { db::execute(); return TRUE; } catch (Exception $ex) { alert::recError("Erreur lors de l'importation des données : " . $ex->getMessage()); if (debug::isFile("debug")) { alert::recError("Stack : " . $ex); } return FALSE; } } /** * Récupère les informations du dernier fichier Excel. * * @return array Informations du dernier fichier Excel. */ public static function getExcel() { db::query("SELECT * FROM " . DB_T_EXCEL . " ORDER BY id DESC LIMIT 0, 1"); return db::single(); } /** * Télécharge un fichier Excel Proweb par son identifiant. * * @param int $_id Identifiant du fichier Excel. * @param string $_file Nom du fichier temporaire. * @return string Chemin du fichier téléchargé. */ public static function downloadExcel(int $_id, string $_file) { $data = base64_decode(self::getExcelById($_id)["file"]); $fileTemp = fopen(DIR_TEMP . $_file, "w"); file_put_contents(DIR_TEMP . $_file, $data); fclose($fileTemp); return DIR_TEMP . $_file; } /** * Génère un lien vers les dossiers Proweb avec une date formatée. * * @return string Lien formaté vers les dossiers Proweb. */ public static function getLinkProweb() { $date = new DateTime(); $date->modify('-12 months'); $dateFormatee = $date->format('d-m-Y'); return str_replace('##DD-MM-YYYY##', $dateFormatee, PROWEB_DOSSIERS); } }