|
|
@@ -0,0 +1,186 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+class prowebDossiers
|
|
|
+{
|
|
|
+
|
|
|
+ public static function getExcelById(int $_id)
|
|
|
+ {
|
|
|
+ db::query("SELECT * FROM " . DB_T_EXCEL_PROWEB_DOSSIERS . " WHERE id = :id");
|
|
|
+ db::bind(':id', $_id);
|
|
|
+ return db::single();
|
|
|
+ }
|
|
|
+
|
|
|
+ public static function all()
|
|
|
+ {
|
|
|
+ db::query("SELECT * FROM " . DB_T_DOSSIERS_PROWEB);
|
|
|
+ return db::resultset();
|
|
|
+ }
|
|
|
+
|
|
|
+ public static function deleteExcel(int $_id)
|
|
|
+ {
|
|
|
+
|
|
|
+ $tmp = self::getExcelById($_id);
|
|
|
+ file::delete($tmp["md5"]);
|
|
|
+
|
|
|
+ db::query("DELETE FROM " . DB_T_EXCEL_PROWEB_DOSSIERS . " WHERE id = :id");
|
|
|
+ db::bind(':id', $_id);
|
|
|
+ try {
|
|
|
+ db::execute();
|
|
|
+ return TRUE;
|
|
|
+ } catch (Exception $ex) {
|
|
|
+ return FALSE;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public static function checkExcel(array $_array)
|
|
|
+ {
|
|
|
+
|
|
|
+ $expectedValues = [
|
|
|
+ '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'
|
|
|
+ ];
|
|
|
+
|
|
|
+ $firstEntry = $_array[0] ?? [];
|
|
|
+
|
|
|
+ $missingValues = array_diff($expectedValues, $firstEntry);
|
|
|
+ $extraValues = array_diff($firstEntry, $expectedValues);
|
|
|
+
|
|
|
+
|
|
|
+ if (empty($missingValues) && empty($extraValues)) {
|
|
|
+ return TRUE;
|
|
|
+ } else {
|
|
|
+ alert::recError("Les données présentes dans ce fichier ne correspondent pas avec l'attendu");
|
|
|
+ if (!empty($missingValues)) {
|
|
|
+ alert::recError("Clés manquantes : " . implode(', ', $missingValues) . "\n");
|
|
|
+ }
|
|
|
+ if (!empty($extraValues)) {
|
|
|
+ alert::recError("Clés supplémentaires : " . implode(', ', $extraValues) . "\n");
|
|
|
+ }
|
|
|
+ return FALSE;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public static function add(array $_array)
|
|
|
+ {
|
|
|
+ if (empty($_array)) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ $placeholders = [];
|
|
|
+ $params = [];
|
|
|
+
|
|
|
+ foreach ($_array as $index => $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)";
|
|
|
+
|
|
|
+ $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];
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ $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
|
|
|
+ ) 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)";
|
|
|
+
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public static function getExcel()
|
|
|
+ {
|
|
|
+ db::query("SELECT * FROM " . DB_T_EXCEL . " ORDER BY id DESC LIMIT 0, 1");
|
|
|
+ return db::single();
|
|
|
+ }
|
|
|
+
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+}
|