mirror of
https://github.com/RaspbianFrance/raspisms.git
synced 2025-04-20 16:37:48 +02:00
add contact with extended infos
This commit is contained in:
parent
ace38aa8bb
commit
edf544b276
2 changed files with 88 additions and 26 deletions
|
@ -105,7 +105,7 @@
|
|||
|
||||
global $db;
|
||||
|
||||
if (empty($_POST['name']) || empty($_POST['phone']))
|
||||
if (empty($_POST['name']) || empty($_POST['phone']) || (RASPISMS_SETTINGS_EXTENDED_CONTACTS_INFOS && empty($_POST['civility'])))
|
||||
{
|
||||
$_SESSION['errormessage'] = 'Des champs sont manquants.';
|
||||
header('Location: ' . $this->generateUrl('contacts', 'add'));
|
||||
|
@ -114,6 +114,12 @@
|
|||
|
||||
$nom = $_POST['name'];
|
||||
$phone = $_POST['phone'];
|
||||
// on enregistre les infos si elles ont été saisies par l'utilisateur
|
||||
$civility = isset($_POST['civility']) ? $_POST['civility'] : null;
|
||||
$prenom = isset($_POST['firstName']) ? $_POST['firstName'] : null;
|
||||
$birthday = isset($_POST['birthday']) ? $_POST['birthday'] : null;
|
||||
$loveSituation = isset($_POST['loveSituation']) ? $_POST['loveSituation'] : null;
|
||||
$nomComplet = $prenom ? $prenom.' '.$nom : $nom;
|
||||
|
||||
if (!$phone = internalTools::parsePhone($phone))
|
||||
{
|
||||
|
@ -122,14 +128,32 @@
|
|||
return false;
|
||||
}
|
||||
|
||||
if (!$db->insertIntoTable('contacts', ['name' => $nom, 'number' => $phone]))
|
||||
if (!$db->insertIntoTable('contacts', ['name' => $nomComplet, 'number' => $phone]))
|
||||
{
|
||||
$_SESSION['errormessage'] = 'Impossible créer ce contact.';
|
||||
header('Location: ' . $this->generateUrl('contacts', 'add'));
|
||||
return false;
|
||||
}
|
||||
|
||||
$db->insertIntoTable('events', ['type' => 'CONTACT_ADD', 'text' => 'Ajout contact : ' . $nom . ' (' . internalTools::phoneAddSpace($phone) . ')']);
|
||||
$db->insertIntoTable('events', ['type' => 'CONTACT_ADD', 'text' => 'Ajout contact : ' . $nomComplet . ' (' . internalTools::phoneAddSpace($phone) . ')']);
|
||||
|
||||
if (!RASPISMS_SETTINGS_EXTENDED_CONTACTS_INFOS)
|
||||
{
|
||||
$_SESSION['successmessage'] = 'Le contact a bien été créé.';
|
||||
header('Location: ' . $this->generateUrl('contacts'));
|
||||
return true;
|
||||
}
|
||||
|
||||
$id_contact = $db->lastId();
|
||||
|
||||
if (!$db->insertIntoTable('contacts_infos', ['id_contact' => $id_contact, 'civility' => $civility, 'first_name' => $prenom, 'last_name' => $nom, 'birthday' => $birthday, 'love_situation' => $loveSituation]))
|
||||
{
|
||||
$_SESSION['errormessage'] = "Le contact a bien été créé, mais certaines informations n'ont pas pu être enregistrées.";
|
||||
header('Location: ' . $this->generateUrl('contacts', 'add'));
|
||||
return false;
|
||||
}
|
||||
|
||||
$db->insertIntoTable('events', ['type' => 'CONTACT_EXTENTED_ADD', 'text' => 'Ajout infos pour le contact : ' . $nomComplet . ' (' . internalTools::phoneAddSpace($phone) . ')']);
|
||||
|
||||
$_SESSION['successmessage'] = 'Le contact a bien été créé.';
|
||||
header('Location: ' . $this->generateUrl('contacts'));
|
||||
|
|
|
@ -38,11 +38,27 @@
|
|||
</div>
|
||||
<div class="panel-body">
|
||||
<form action="<?php echo $this->generateUrl('contacts', 'create', [$_SESSION['csrf']]);?>" method="POST">
|
||||
<?php if (RASPISMS_SETTINGS_EXTENDED_CONTACTS_INFOS) { ?>
|
||||
<div class="form-group">
|
||||
<label>Nom contact</label>
|
||||
<label>Civilité du contact</label>
|
||||
<div class="form-group">
|
||||
<input name="civility" type="radio" value="1" required/> Monsieur
|
||||
<input name="civility" type="radio" value="0" required/> Madame
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>Prénom du contact (facultatif)</label>
|
||||
<div class="form-group input-group">
|
||||
<span class="input-group-addon"><span class="fa fa-user"></span></span>
|
||||
<input name="name" class="form-control" type="text" placeholder="Nom contact" autofocus required>
|
||||
<input name="firstName" class="form-control" type="text" placeholder="Prénom du contact (facultatif)">
|
||||
</div>
|
||||
</div>
|
||||
<?php } ?>
|
||||
<div class="form-group">
|
||||
<label>Nom du contact</label>
|
||||
<div class="form-group input-group">
|
||||
<span class="input-group-addon"><span class="fa fa-user"></span></span>
|
||||
<input name="name" class="form-control" type="text" placeholder="Nom du contact" required>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
|
@ -52,6 +68,19 @@
|
|||
<input name="phone" type="hidden" id="phone-hidden-input" required>
|
||||
</div>
|
||||
</div>
|
||||
<?php if (RASPISMS_SETTINGS_EXTENDED_CONTACTS_INFOS) { ?>
|
||||
<div class="form-group">
|
||||
<label>Date de naissance du contact (facultatif)</label>
|
||||
<input name="birthday" class="form-control form-date" type="text" readonly>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>Situation amoureuse du contact (facultatif)</label>
|
||||
<div class="form-group">
|
||||
<input name="loveSituation" type="radio" value="0" /> Célibataire
|
||||
<input name="loveSituation" type="radio" value="1" /> En couple
|
||||
</div>
|
||||
</div>
|
||||
<?php } ?>
|
||||
<a class="btn btn-danger" href="<?php echo $this->generateUrl('contacts'); ?>">Annuler</a>
|
||||
<input type="submit" class="btn btn-success" value="Enregistrer le contact" />
|
||||
</form>
|
||||
|
@ -72,6 +101,15 @@
|
|||
utilsScript: '<?php echo HTTP_PWD; ?>/js/intlTelInput/lib/libphonenumber/utils.js'
|
||||
});
|
||||
|
||||
jQuery('.form-date').datepicker(
|
||||
{
|
||||
format: 'yyyy-mm-dd',
|
||||
autoclose: true,
|
||||
minuteStep: 1,
|
||||
startView: 3,
|
||||
language: 'fr'
|
||||
});
|
||||
|
||||
jQuery('form').on('submit', function(e)
|
||||
{
|
||||
e.preventDefault();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue