mirror of
https://github.com/RaspbianFrance/raspisms.git
synced 2025-04-20 16:37:48 +02:00
mise à jour d'un contact avec infos étendues
This commit is contained in:
parent
edf544b276
commit
17789f5b27
3 changed files with 106 additions and 21 deletions
|
@ -182,13 +182,42 @@
|
||||||
|
|
||||||
foreach ($_POST['contacts'] as $id => $contact)
|
foreach ($_POST['contacts'] as $id => $contact)
|
||||||
{
|
{
|
||||||
if (!$number = internalTools::parsePhone($contact['phone']))
|
if (!isset($contact['name']) || !isset($contact['phone']) || (RASPISMS_SETTINGS_EXTENDED_CONTACTS_INFOS && !isset($contact['civility'])))
|
||||||
{
|
{
|
||||||
$errors[] = $contact['id'];
|
$errors[] = $id;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
$db->updateTableWhere('contacts', ['name' => $contact['name'], 'number' => $number], ['id' => $id]);
|
$nom = $contact['name'];
|
||||||
|
$phone = $contact['phone'];
|
||||||
|
// on enregistre les infos si elles ont été saisies par l'utilisateur
|
||||||
|
$civility = isset($contact['civility']) ? $contact['civility'] : null;
|
||||||
|
$prenom = isset($contact['first_name']) ? $contact['first_name'] : null;
|
||||||
|
$birthday = isset($contact['birthday']) ? $contact['birthday'] : null;
|
||||||
|
$loveSituation = isset($contact['love_situation']) ? $contact['love_situation'] : null;
|
||||||
|
$nomComplet = $prenom ? $prenom.' '.$nom : $nom;
|
||||||
|
|
||||||
|
if (!$number = internalTools::parsePhone($contact['phone']))
|
||||||
|
{
|
||||||
|
$errors[] = $id;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$db->updateTableWhere('contacts', ['name' => $nomComplet, 'number' => $number], ['id' => $id]);
|
||||||
|
|
||||||
|
if (!isset($contact['contacts_infos_id'])) {
|
||||||
|
if (!$db->insertIntoTable('contacts_infos', ['id_contact' => $id, 'civility' => $civility, 'first_name' => $prenom, 'last_name' => $nom, 'birthday' => $birthday, 'love_situation' => $loveSituation]))
|
||||||
|
{
|
||||||
|
$errors[] = $id;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$db->updateTableWhere('contacts_infos', ['id_contact' => $id, 'civility' => $civility, 'first_name' => $prenom, 'last_name' => $nom, 'birthday' => $birthday, 'love_situation' => $loveSituation], ['id' => $contact['contacts_infos_id']]))
|
||||||
|
{
|
||||||
|
$errors[] = $id;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//Si on a eu des erreurs
|
//Si on a eu des erreurs
|
||||||
|
|
|
@ -249,18 +249,27 @@
|
||||||
{
|
{
|
||||||
if (RASPISMS_SETTINGS_EXTENDED_CONTACTS_INFOS) {
|
if (RASPISMS_SETTINGS_EXTENDED_CONTACTS_INFOS) {
|
||||||
$extended_contact_join = '
|
$extended_contact_join = '
|
||||||
LEFT JOIN contacts_infos as inf
|
LEFT JOIN contacts_infos
|
||||||
ON (inf.id_contact = contacts.id)
|
ON (contacts_infos.id_contact = contacts.id)
|
||||||
';
|
';
|
||||||
|
$tableToDescribe = "contacts,contacts_infos";
|
||||||
} else {
|
} else {
|
||||||
$extended_contact_join = '';
|
$extended_contact_join = '';
|
||||||
|
$tableToDescribe = "contacts";
|
||||||
}
|
}
|
||||||
|
|
||||||
$query = "
|
$fields = $this->describeTable($tableToDescribe);
|
||||||
SELECT *
|
|
||||||
|
// liste les champs disponibles pour ajouter des alias et éviter des problèmes en cas de colonnes avec le même nom
|
||||||
|
$fieldNames = array_keys($fields);
|
||||||
|
foreach ($fieldNames as $key => $fieldName) {
|
||||||
|
$fieldNames[$key] = $fieldName . " AS '" . $fieldName . "'";
|
||||||
|
}
|
||||||
|
|
||||||
|
$query = "SELECT " . implode(', ', $fieldNames) . "
|
||||||
FROM contacts
|
FROM contacts
|
||||||
".$extended_contact_join."
|
".$extended_contact_join."
|
||||||
WHERE id ";
|
WHERE contacts.id ";
|
||||||
|
|
||||||
//On génère la clause IN et les paramètres adaptés depuis le tableau des id
|
//On génère la clause IN et les paramètres adaptés depuis le tableau des id
|
||||||
$generted_in = $this->generateInFromArray($contacts_ids);
|
$generted_in = $this->generateInFromArray($contacts_ids);
|
||||||
|
|
|
@ -41,21 +41,59 @@
|
||||||
<?php
|
<?php
|
||||||
foreach ($contacts as $contact)
|
foreach ($contacts as $contact)
|
||||||
{
|
{
|
||||||
?>
|
if (RASPISMS_SETTINGS_EXTENDED_CONTACTS_INFOS) { ?>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label>Nom contact</label>
|
<label>Civilité du contact</label>
|
||||||
<div class="form-group input-group">
|
<div class="form-group">
|
||||||
<span class="input-group-addon"><span class="fa fa-user"></span></span>
|
<input name="contacts[<?php secho($contact['contacts.id']); ?>][civility]" type="radio" value="1" required <?php echo ($contact['contacts_infos.civility']==='1' ? 'checked' : ''); ?>/> Monsieur
|
||||||
<input name="contacts[<?php secho($contact['id']); ?>][name]" class="form-control" type="text" placeholder="Nom contact" autofocus required value="<?php secho($contact['name']); ?>">
|
<input name="contacts[<?php secho($contact['contacts.id']); ?>][civility]" type="radio" value="0" required <?php echo ($contact['contacts_infos.civility']==='0' ? 'checked' : ''); ?>/> Madame
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<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="contacts[<?php secho($contact['contacts.id']); ?>][first_name]" class="form-control" type="text" placeholder="Prénom du contact (facultatif)" value="<?php secho($contact['contacts_infos.first_name']); ?>">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<?php } ?>
|
||||||
|
<?php
|
||||||
|
if (RASPISMS_SETTINGS_EXTENDED_CONTACTS_INFOS) {
|
||||||
|
$name = ($contact['contacts_infos.last_name'] != '') ? $contact['contacts_infos.last_name'] : $contact['contacts.name'];
|
||||||
|
$tableAlias = "contacts.";
|
||||||
|
} else {
|
||||||
|
$name = $contact['name'];
|
||||||
|
$tableAlias = '';
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
<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="contacts[<?php secho($contact[$tableAlias.'id']); ?>][name]" class="form-control" type="text" placeholder="Nom du contact" required value="<?php secho($name); ?>">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
<label>Numéro de téléphone du contact</label>
|
<label>Numéro de téléphone du contact</label>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<input name="" class="form-control phone-international-input" type="tel" contact-id="<?php secho($contact['id']); ?>" value="<?php secho($contact['number']); ?>">
|
<input name="" class="form-control phone-international-input" type="tel" contact-id="<?php secho($contact[$tableAlias.'id']); ?>" value="<?php secho($contact[$tableAlias.'number']); ?>">
|
||||||
<input name="contacts[<?php secho($contact['id']); ?>][phone]" type="hidden" id="phone-hidden-input-<?php secho($contact['id']); ?>" required>
|
<input name="contacts[<?php secho($contact[$tableAlias.'id']); ?>][phone]" type="hidden" id="phone-hidden-input-<?php secho($contact[$tableAlias.'id']); ?>" required>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<?php if (RASPISMS_SETTINGS_EXTENDED_CONTACTS_INFOS) { ?>
|
||||||
|
<input name="contacts[<?php secho($contact['contacts.id']); ?>][contacts_infos_id]" type="hidden" value="<?php secho($contact['contacts_infos.id']); ?>">
|
||||||
|
<div class="form-group">
|
||||||
|
<label>Date de naissance du contact (facultatif)</label>
|
||||||
|
<input name="contacts[<?php secho($contact['contacts.id']); ?>][birthday]" class="form-control form-date" type="text" readonly value="<?php secho($contact['contacts_infos.birthday']); ?>">
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label>Situation amoureuse du contact (facultatif)</label>
|
||||||
|
<div class="form-group">
|
||||||
|
<input name="contacts[<?php secho($contact['contacts.id']); ?>][love_situation]" type="radio" value="0" <?php echo ($contact['contacts_infos.love_situation']==='0' ? 'checked' : ''); ?>/> Célibataire
|
||||||
|
<input name="contacts[<?php secho($contact['contacts.id']); ?>][love_situation]" type="radio" value="1" <?php echo ($contact['contacts_infos.love_situation']==='1' ? 'checked' : ''); ?>/> En couple
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<?php } ?>
|
||||||
<hr/>
|
<hr/>
|
||||||
<?php
|
<?php
|
||||||
}
|
}
|
||||||
|
@ -80,6 +118,15 @@
|
||||||
utilsScript: '<?php echo HTTP_PWD; ?>/js/intlTelInput/lib/libphonenumber/utils.js'
|
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)
|
jQuery('form').on('submit', function(e)
|
||||||
{
|
{
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue