contact.php 17 KB
Newer Older
1
<?php
root's avatar
root committed
2 3 4 5 6 7 8


/*
Template Name: Formulaire d'adhésion
*/


9 10 11 12 13 14
$errors = array(

    //Liste des éléments pouvant avoir une erreur

    "first selection" => "",
    "second Selection" => "",
N. Peraldi's avatar
N. Peraldi committed
15 16
    "EPCI com" => "",
    "EPCI hab" => "",
17 18 19 20 21 22 23 24 25 26 27 28
    "nom" => "",
    "adresse" => "",
    "CP" => "",
    "ville" => "",
    "tel" => "",
    "site" => "",
    "periode" => "",
    "siret" => "",
    "numeroEngagement" => "",
    "code" => ""
);

root's avatar
root committed
29 30

//le dossier où se trouvent les fichiers
N. Peraldi's avatar
N. Peraldi committed
31
$workingDirectory = $_SERVER["CONTEXT_DOCUMENT_ROOT"] . '/wp-content/themes/theme-wordpress-adullact-org/';
root's avatar
root committed
32 33
$grillePath = $workingDirectory . 'grille.csv';
$periodSelectionPath = $workingDirectory . "periodSelection.php";
N. Peraldi's avatar
N. Peraldi committed
34
$JSPath = '/wp-content/themes/theme-wordpress-adullact-org/adhesionForm.js';
root's avatar
root committed
35 36


37
$debug_mode = false;
N. Peraldi's avatar
N. Peraldi committed
38

39 40
$resultat = false;

N. Peraldi's avatar
N. Peraldi committed
41 42 43
function tryToEcho($var)
{
    if (isset($_POST[$var])) {
N. Peraldi's avatar
N. Peraldi committed
44 45 46 47
        echo $_POST[$var];
    }
}

N. Peraldi's avatar
N. Peraldi committed
48 49
function tryToSetInputSelect($key, $value)
{
50
    //fonction utilisée pour définir l'option sélectionnée lorsque l'envoi du formulaire a échoué.
N. Peraldi's avatar
N. Peraldi committed
51
    if (isset($_POST[$key])) {
52

N. Peraldi's avatar
N. Peraldi committed
53
        if ($_POST[$key] == $value) {
54 55 56 57 58 59 60 61
            echo "selected";
        }


    }

}

N. Peraldi's avatar
N. Peraldi committed
62 63
function tryToShowError($var)
{
N. Peraldi's avatar
N. Peraldi committed
64
    global $errors;
N. Peraldi's avatar
N. Peraldi committed
65
    if (strlen($errors[$var]) > 0) {
N. Peraldi's avatar
N. Peraldi committed
66 67 68 69
        echo "<p class='error'> " . $errors[$var] . "</p>";
    }
}

70 71
$numberOfErrors = 0;

N. Peraldi's avatar
N. Peraldi committed
72 73
if (isset($_POST)) {
    if (isset($_POST["firstSelection"])) {
74

75
        include "traitementAdhesion.php";
N. Peraldi's avatar
N. Peraldi committed
76
        if ($debug_mode) {
N. Peraldi's avatar
N. Peraldi committed
77 78 79 80
            echo "<br> début du traitement <br>";
        }


N. Peraldi's avatar
N. Peraldi committed
81
        $errors = traitement($_POST, $errors);
82

N. Peraldi's avatar
N. Peraldi committed
83
        if ($debug_mode) {
N. Peraldi's avatar
N. Peraldi committed
84 85 86
            echo "<br> fin du traitement <br>";
        }

87

N. Peraldi's avatar
N. Peraldi committed
88
        foreach ($errors as $key => $value) {
N. Peraldi's avatar
N. Peraldi committed
89

N. Peraldi's avatar
N. Peraldi committed
90
            if ($debug_mode) {
N. Peraldi's avatar
N. Peraldi committed
91 92 93
                echo $key . " : " . $value . "<br>";
            }

N. Peraldi's avatar
N. Peraldi committed
94 95
            if (strlen($value) > 0) {
                $numberOfErrors += 1;
96
            }
97 98
        }

N. Peraldi's avatar
N. Peraldi committed
99
        if ($debug_mode) {
N. Peraldi's avatar
N. Peraldi committed
100
            echo "<br> nombre d'erreurs : " . $numberOfErrors . " <br>";
101

N. Peraldi's avatar
N. Peraldi committed
102 103
            var_dump($errors);
        }
N. Peraldi's avatar
N. Peraldi committed
104
        if ($numberOfErrors == 0) {
105 106 107
            sendAdhesionMail($_POST);


N. Peraldi's avatar
N. Peraldi committed
108 109 110 111
            header("Location:");
        }


112 113
    }
}
114 115


N. Peraldi's avatar
N. Peraldi committed
116 117
get_header();

118 119
?>

N. Peraldi's avatar
N. Peraldi committed
120 121 122
<div class="wrap">
    <div id="primary" class="content-area">
        <main id="main" class="site-main" role="main">
123

N. Peraldi's avatar
N. Peraldi committed
124
            <?php
root's avatar
root committed
125

126

N. Peraldi's avatar
N. Peraldi committed
127
            include_once $periodSelectionPath;
root's avatar
root committed
128

N. Peraldi's avatar
N. Peraldi committed
129

N. Peraldi's avatar
N. Peraldi committed
130 131
            $fichier = fopen($grillePath, 'r');
            $ligne = fgetcsv($fichier, 1024, ";");
N. Peraldi's avatar
N. Peraldi committed
132

N. Peraldi's avatar
N. Peraldi committed
133 134
            //on effectue de nouveau cette instruction pour sauter les titres du tableau
            $ligne = fgetcsv($fichier, 1024, ";");
N. Peraldi's avatar
N. Peraldi committed
135

N. Peraldi's avatar
N. Peraldi committed
136
            //------------------------Variables-------------------
N. Peraldi's avatar
N. Peraldi committed
137

N. Peraldi's avatar
N. Peraldi committed
138 139 140
            $listeGrilleEntiere = [];       //contiendra l'intégralité des données dans grille.csv
            $textsSelectMenu = [];         //contiendra les textes du premier select option gérés automatiquement
            $textsSelectMenuExtended = []; //même rôle qu'au dessus mais en ajoutant les options gérées automatiquement + manuellement
root's avatar
root committed
141

N. Peraldi's avatar
N. Peraldi committed
142 143
            $classSelectMenu = [];           //contiendra les classes des option menu gérés automatiquement
            $classSelectMenuExtended = [];   //contiendra les classes des option menu gérés automatiquement + manuellement
N. Peraldi's avatar
N. Peraldi committed
144 145


N. Peraldi's avatar
N. Peraldi committed
146 147 148 149 150 151
            function createFirstSelectionList($liste)
            {
                //fonction qui crée la première liste de sélection sans modifier les textes
                $listeTempo = [];
                for ($a = 0; $a < count($liste); $a++) {
                    $mot = $liste[$a][0];
152

N. Peraldi's avatar
N. Peraldi committed
153

N. Peraldi's avatar
N. Peraldi committed
154 155 156 157
                    if (!isWordIn($mot, $listeTempo)) {
                        $listeTempo[] = $mot;
                    }
                }
158

N. Peraldi's avatar
N. Peraldi committed
159 160
                return $listeTempo;
            }
161

N. Peraldi's avatar
N. Peraldi committed
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201
            function createNameClass($variable)
            {
                //fonction qui nettoie la chaine pour pouvoir l'utiliser en tant que nom de classe

                $chars = array(
                    //tous les caractères susceptibles d'être remplacés
                    "é" => "e",
                    "è" => "e",
                    "ê" => "e",
                    "ë" => "e",
                    "à" => "a",
                    "â" => "a",
                    "ù" => "u",
                    "û" => "u",
                    "î" => "i",
                    "ï" => "i",
                    "ç" => "c",


                    "É" => "e",
                    "È" => "e",
                    "Ê" => "e",
                    "Ë" => "e",
                    "À" => "a",
                    "Â" => "a",
                    "Ù" => "u",
                    "Û" => "u",
                    "Î" => "i",
                    "Ï" => "i",
                    "Ç" => "c",

                    " " => "_"


                );

                $variable = strtr($variable, $chars);

                return $variable;
            }
root's avatar
root committed
202

N. Peraldi's avatar
N. Peraldi committed
203 204 205 206 207 208
            function createSizeSelectList($liste)
            {
                //fonction qui crée la liste des classes qui sert pour le 2e select
                $resultList = [];
                for ($a = 0; $a < count($liste); $a++) {
                    $mot = createNameClass($liste[$a][0]);
209 210


N. Peraldi's avatar
N. Peraldi committed
211 212 213
                    if (!isWordIn($mot, $resultList)) {
                        $resultList[] = $mot;
                    }
N. Peraldi's avatar
N. Peraldi committed
214

N. Peraldi's avatar
N. Peraldi committed
215
                }
N. Peraldi's avatar
N. Peraldi committed
216

N. Peraldi's avatar
N. Peraldi committed
217
                return $resultList;
N. Peraldi's avatar
N. Peraldi committed
218

N. Peraldi's avatar
N. Peraldi committed
219
            }
220

N. Peraldi's avatar
N. Peraldi committed
221 222 223 224 225 226 227 228
            function isWordIn($word, $list)
            {
                //on vérifie si word est contenu dans list
                for ($a = 0; $a < count($list); $a++) {
                    if ($word == $list[$a]) {
                        return true;
                    }
                }
N. Peraldi's avatar
N. Peraldi committed
229

N. Peraldi's avatar
N. Peraldi committed
230 231
                return false;
            }
N. Peraldi's avatar
N. Peraldi committed
232

N. Peraldi's avatar
N. Peraldi committed
233 234 235 236 237
            while ($ligne) {
                //boucle qui va récupérer tout le contenu du fichier pour le stocker dans listeGrilleEntiere
                $listeGrilleEntiere[] = ($ligne);
                $ligne = fgetcsv($fichier, 1024, ";");
            }
N. Peraldi's avatar
N. Peraldi committed
238 239


N. Peraldi's avatar
N. Peraldi committed
240
            fclose($fichier);
N. Peraldi's avatar
N. Peraldi committed
241

N. Peraldi's avatar
N. Peraldi committed
242 243
            //on crée la première liste qui gère les textes de la première liste, avec accents et espaces
            $textsSelectMenu = createFirstSelectionList($listeGrilleEntiere);
244

N. Peraldi's avatar
N. Peraldi committed
245 246 247 248 249
            //on ajoute "association", epci mutualisant et "individu" qui possèdent un traitement différent
            $textsSelectMenuExtended = $textsSelectMenu;
            $textsSelectMenuExtended[] = ("Association");
            $textsSelectMenuExtended[] = ("Individu");
            $textsSelectMenuExtended[] = ("EPCI Mutualisant");
250

N. Peraldi's avatar
N. Peraldi committed
251 252
            //on crée la liste pour le 2e select qui contient le nom des classes gérés automatiquement
            $classSelectMenu = createSizeSelectList($listeGrilleEntiere);
N. Peraldi's avatar
N. Peraldi committed
253

N. Peraldi's avatar
N. Peraldi committed
254 255
            //classes gérées automatiquement + manuellement
            $classSelectMenuExtended = $classSelectMenu;
256

N. Peraldi's avatar
N. Peraldi committed
257 258 259
            $classSelectMenuExtended[] = ("Association");
            $classSelectMenuExtended[] = ("Individu");
            $classSelectMenuExtended[] = ("EPCIMutualisant");
N. Peraldi's avatar
N. Peraldi committed
260

N. Peraldi's avatar
N. Peraldi committed
261 262 263 264 265
            //on trie par ordre alphabétique
            sort($textsSelectMenu);
            sort($textsSelectMenuExtended);
            sort($classSelectMenu);
            sort($classSelectMenuExtended);
266 267


N. Peraldi's avatar
N. Peraldi committed
268
            ?>
269 270


N. Peraldi's avatar
N. Peraldi committed
271 272 273 274 275 276 277 278
            <h1>Formulaire de renouvellement d'adhésion</h1>
            <p>
                <?php
                if ($numberOfErrors == 1) {
                    echo "Une erreur est survenue lors de l'envoi du formulaire. Veuillez vérifier vos informations";
                } elseif ($numberOfErrors > 1) {
                    echo "Plusieurs erreurs sont survenues lors de l'envoi du formulaire. Veuillez vérifier vos informations";
                }
279

280

N. Peraldi's avatar
N. Peraldi committed
281
                ?>
282

N. Peraldi's avatar
N. Peraldi committed
283 284 285 286 287 288 289 290 291
            </p>
            <form action="" method="post">
                <p>
                    <input id="ancienSelectType" type="hidden" name="ancienSelectType"
                           value="<?php tryToEcho("firstSelection") ?>">
                    <input id="ancienSelectSize" type="hidden" name="ancienSelectSize"
                           value="<?php tryToEcho("secondSelection") ?>">
                    <input id="ancienSelectPeriod" type="hidden" name="ancienSelectPeriod"
                           value="<?php tryToEcho("periodeAdhesionCollectivite") ?>">
292

N. Peraldi's avatar
N. Peraldi committed
293
                    <label for="firstSelect">Veuillez sélectionner le type de collectivité :</label>
294

N. Peraldi's avatar
N. Peraldi committed
295 296
                    <select id="firstSelect" required="" name="firstSelection">
                        <option value="none">---</option>
N. Peraldi's avatar
N. Peraldi committed
297

N. Peraldi's avatar
N. Peraldi committed
298 299 300 301 302 303 304 305
                        <?php
                        //on génère les options en fonction du fichier et des valeurs par défaut.
                        for ($i = 0; $i < count($textsSelectMenuExtended); $i++) {
                            ?>
                            <option class="optionFirstSelect"
                                    value="<?php echo $classSelectMenuExtended[$i] ?>"><?php echo $textsSelectMenuExtended[$i] ?></option>
                            <?php
                        }
N. Peraldi's avatar
N. Peraldi committed
306

N. Peraldi's avatar
N. Peraldi committed
307
                        ?>
308

309

N. Peraldi's avatar
N. Peraldi committed
310 311 312
                    </select>
                    <?php tryToShowError("first selection"); ?>
                </p>
313

N. Peraldi's avatar
N. Peraldi committed
314 315 316
                <div id="link">
                    <a href="contact.php" id="linkRedirection" title="Page par défaut">Valider</a>
                </div>
317

N. Peraldi's avatar
N. Peraldi committed
318 319 320 321 322
                <div id="formulaireEPCIMutualisant">
                    <label for="nombreHabitantsEPCI">Nombre d'habitants de l'EPCI :</label>
                    <input type="number" name="nombreHabitantsEPCI" id="nombreHabitantsEPCI"
                           value="<?php tryToEcho("nombreHabitantsEPCI"); ?>"><br>
                    <?php tryToShowError("EPCI com"); ?>
323

N. Peraldi's avatar
N. Peraldi committed
324 325 326 327
                    <label for="nombreCommunesMembresEPCI">Nombre de communes membres :</label>
                    <input type="number" name="nombreCommunesMembresEPCI" id="nombreCommunesMembresEPCI"
                           value="<?php tryToEcho("nombreCommunesMembresEPCI"); ?>"><br>
                    <?php tryToShowError("EPCI hab"); ?>
328

N. Peraldi's avatar
N. Peraldi committed
329
                    <input type="button" value="Valider" id="boutonValiderNombresEPCI">
330 331


N. Peraldi's avatar
N. Peraldi committed
332
                </div>
333

N. Peraldi's avatar
N. Peraldi committed
334 335
                <p id="paraSecondSelection">
                    <label for="secondSelection">Veuillez sélectionner la taille :</label>
336

N. Peraldi's avatar
N. Peraldi committed
337
                    <select id="secondSelection" name="secondSelection">
338

N. Peraldi's avatar
N. Peraldi committed
339 340 341
                        <?php
                        $classInTreatment = "";
                        $counter = 1;
342

N. Peraldi's avatar
N. Peraldi committed
343 344
                        for ($a = 0; $a < count($listeGrilleEntiere); $a++) {
                            //boucle qui génère les options du second select
345

N. Peraldi's avatar
N. Peraldi committed
346 347 348
                            //on récupère la ligne
                            $actualLine = $listeGrilleEntiere[$a];
                            $actualClass = createNameClass($actualLine[0]);
349

N. Peraldi's avatar
N. Peraldi committed
350 351
                            //on vérifie si on change de classe ou non pour remettre le compteur à 1
                            if ($classInTreatment != $actualClass) {
352

N. Peraldi's avatar
N. Peraldi committed
353 354
                                $counter = 1;
                                $classInTreatment = $actualClass;
355

N. Peraldi's avatar
N. Peraldi committed
356 357 358 359 360
                                ?>
                                <option class="<?php echo $classInTreatment ?>" value="none" name="optionSelect2">---
                                </option>
                                <?php
                            }
361

N. Peraldi's avatar
N. Peraldi committed
362 363
                            //la tranche pour la cotisation
                            $tranch = $classInTreatment . "-T" . $counter;
364

N. Peraldi's avatar
N. Peraldi committed
365 366 367 368 369
                            ?>
                            <option class="<?php echo $classInTreatment ?>" id="<?php echo $tranch ?>"
                                    value="<?php echo $actualLine[1] ?>"
                                    name="optionSelect2"><?php echo $actualLine[1] ?></option>
                            <?php
370 371


N. Peraldi's avatar
N. Peraldi committed
372
                            $counter += 1;
373 374


N. Peraldi's avatar
N. Peraldi committed
375
                        }
376

N. Peraldi's avatar
N. Peraldi committed
377
                        ?>
378 379


N. Peraldi's avatar
N. Peraldi committed
380 381 382
                    </select>
                    <?php tryToShowError("second Selection"); ?>
                </p>
383

N. Peraldi's avatar
N. Peraldi committed
384
                <div id="cotisation">
385

N. Peraldi's avatar
N. Peraldi committed
386 387 388
                    <?php
                    $classInTreatment = "";
                    $counter = 1;
389

N. Peraldi's avatar
N. Peraldi committed
390 391
                    for ($a = 0; $a < count($listeGrilleEntiere); $a++) {
                        //boucle qui génère les montants des cotisations
392

N. Peraldi's avatar
N. Peraldi committed
393 394 395
                        //on récupère la ligne
                        $actualLine = $listeGrilleEntiere[$a];
                        $actualClass = createNameClass($actualLine[0]);
396

N. Peraldi's avatar
N. Peraldi committed
397 398
                        //on vérifie si on change de classe ou non pour remettre le compteur à 1
                        if ($classInTreatment != $actualClass) {
399

N. Peraldi's avatar
N. Peraldi committed
400 401 402
                            $counter = 1;
                            $classInTreatment = $actualClass;
                        }
403

N. Peraldi's avatar
N. Peraldi committed
404 405
                        //la tranche pour la cotisation
                        $id = "PCOT-" . $classInTreatment . "-T" . $counter;
406

N. Peraldi's avatar
N. Peraldi committed
407 408 409 410
                        ?>
                        <p id="<?php echo $id ?>" class="PCOT">Montant de la cotisation : <?php echo $actualLine[2] ?>
</p>
                        <?php
411

N. Peraldi's avatar
N. Peraldi committed
412
                        $counter += 1;
413 414


N. Peraldi's avatar
N. Peraldi committed
415
                    }
416

N. Peraldi's avatar
N. Peraldi committed
417
                    ?>
418

N. Peraldi's avatar
N. Peraldi committed
419 420 421
                    <p id="PCOT-EPCIMutualisant" class="PCOT">Montant de la cotisation : <span
                                id="montantCotisation"></span></p>
                    <p id="PCOT-Association" class="PCOT">Montant de la cotisation : 15€</p>
422

N. Peraldi's avatar
N. Peraldi committed
423
                </div>
424 425


N. Peraldi's avatar
N. Peraldi committed
426 427
                <div id="informationsCollectivite">
                    <h3>Informations obligatoires :</h3>
428

N. Peraldi's avatar
N. Peraldi committed
429 430 431 432
                    <label for="nomCollectivite">Nom de la collectivité :</label>
                    <input type="text" name="nomCollectivite" id="nomCollectivite" required=""
                           value="<?php tryToEcho("nomCollectivite"); ?>"><br>
                    <?php tryToShowError("nom"); ?>
433

N. Peraldi's avatar
N. Peraldi committed
434 435 436 437
                    <label for="adresseCollectivite">Adresse :</label>
                    <input type="text" name="adresseCollectivite" id="adresseCollectivite" required=""
                           value="<?php tryToEcho("adresseCollectivite"); ?>"><br>
                    <?php tryToShowError("adresse"); ?>
438

N. Peraldi's avatar
N. Peraldi committed
439 440 441 442
                    <label for="codePostalCollectivite">Code postal :</label>
                    <input type="text" name="codePostalCollectivite" id="codePostalCollectivite" required=""
                           value="<?php tryToEcho("codePostalCollectivite"); ?>"><br>
                    <?php tryToShowError("CP"); ?>
443

N. Peraldi's avatar
N. Peraldi committed
444 445 446 447
                    <label for="villeCollectivite">Ville :</label>
                    <input type="text" name="villeCollectivite" id="villeCollectivite" required=""
                           value="<?php tryToEcho("villeCollectivite"); ?>"><br>
                    <?php tryToShowError("ville"); ?>
448

N. Peraldi's avatar
N. Peraldi committed
449 450 451 452
                    <label for="telCollectivite">Téléphone :</label>
                    <input type="tel" name="telCollectivite" id="telCollectivite" required=""
                           value="<?php tryToEcho("telCollectivite"); ?>"><br>
                    <?php tryToShowError("tel"); ?>
453 454


N. Peraldi's avatar
N. Peraldi committed
455 456 457 458
                    <label for="siteCollectivite">Site internet :</label>
                    <input type="url" name="siteCollectivite" id="siteCollectivite" required=""
                           value="<?php tryToEcho("siteCollectivite"); ?>"><br>
                    <?php tryToShowError("site"); ?>
459

N. Peraldi's avatar
N. Peraldi committed
460 461 462 463
                    <label for="periodeAdhesionCollectivite">Période d'adhésion :</label>
                    <select name="periodeAdhesionCollectivite" id="periodeAdhesionCollectivite" required="">
                        <option class="optionPeriod" value="" selected>---</option>
                        <?php generateDates(); ?>
464

N. Peraldi's avatar
N. Peraldi committed
465
                    </select>
466

N. Peraldi's avatar
N. Peraldi committed
467
                    <h3>Informations relatives à Chorus Pro</h3>
N. Peraldi's avatar
N. Peraldi committed
468

N. Peraldi's avatar
N. Peraldi committed
469 470 471 472
                    <label for="siretCollectivite">SIRET :</label>
                    <input type="number" name="siretCollectivite" id="siretCollectivite" required=""
                           value="<?php tryToEcho("siretCollectivite"); ?>"><br>
                    <?php tryToShowError("siret"); ?>
473 474


N. Peraldi's avatar
N. Peraldi committed
475 476 477 478
                    <label for="numeroEngagementCollectivite">N° d'engagement :</label>
                    <input type="text" name="numeroEngagementCollectivite" id="numeroEngagementCollectivite" required=""
                           value="<?php tryToEcho("numeroEngagementCollectivite"); ?>"><br>
                    <?php tryToShowError("numeroEngagement"); ?>
root's avatar
root committed
479

N. Peraldi's avatar
N. Peraldi committed
480 481 482 483
                    <label for="codeCollectivite">Code :</label>
                    <input type="text" name="codeCollectivite" id="codeCollectivite" required=""
                           value="<?php tryToEcho("codeCollectivite"); ?>"><br>
                    <?php tryToShowError("code"); ?>
root's avatar
root committed
484

485

N. Peraldi's avatar
N. Peraldi committed
486
                </div>
N. Peraldi's avatar
N. Peraldi committed
487

488

N. Peraldi's avatar
N. Peraldi committed
489 490
                <input type="submit" id="boutonEnvoyer">
            </form>
491 492


N. Peraldi's avatar
N. Peraldi committed
493
            <script type="text/javascript" src="<?php echo $JSPath ?>"></script>
494

N. Peraldi's avatar
N. Peraldi committed
495 496 497 498
            <script>
                prepareDocument();
            </script>
        </main>
499
    </div>
N. Peraldi's avatar
N. Peraldi committed
500
</div>
N. Peraldi's avatar
N. Peraldi committed
501

502 503 504 505 506
<?php

get_footer();

?>