184 lines
8.6 KiB
PHP
184 lines
8.6 KiB
PHP
<?php
|
|
/**
|
|
* Modal personnalisé pour l'édition/création de crédits
|
|
* Intégré via shortcode WordPress
|
|
*/
|
|
|
|
// Vérification de sécurité
|
|
if (!defined('ABSPATH')) {
|
|
exit;
|
|
}
|
|
|
|
// Récupération des données si en mode édition
|
|
$credit_id = isset($_GET['credit_id']) ? intval($_GET['credit_id']) : 0;
|
|
$credit_data = null;
|
|
$is_edit_mode = $credit_id > 0;
|
|
|
|
if ($is_edit_mode) {
|
|
// Récupérer les données du crédit depuis la base de données
|
|
$credit_manager = new credit_manager();
|
|
$credit_data = $credit_manager->get_credit_by_id($credit_id);
|
|
|
|
// Si pas de données trouvées, initialiser avec des valeurs vides
|
|
if (!$credit_data) {
|
|
$credit_data = (object) array(
|
|
'title' => '',
|
|
'nom' => '',
|
|
'prenom' => '',
|
|
'adresse' => '',
|
|
'localite' => '',
|
|
'email' => '',
|
|
'telephone' => '',
|
|
'gsm' => '',
|
|
'societe_credit' => '',
|
|
'montant' => '',
|
|
'date' => '',
|
|
'signature' => '',
|
|
'numero_dossier' => '',
|
|
'code' => '',
|
|
'remarques' => ''
|
|
);
|
|
}
|
|
}
|
|
?>
|
|
|
|
<!-- Modal Container -->
|
|
<div id="credit-manager-modal" class="credit-modal" style="display: none;">
|
|
<div class="credit-modal-overlay"></div>
|
|
<div class="credit-modal-content">
|
|
<div class="credit-modal-header">
|
|
<h2 id="modal-title"><?php echo $is_edit_mode ? 'Modifier le crédit' : 'Nouveau crédit'; ?></h2>
|
|
<button type="button" class="credit-modal-close" onclick="closeCreditModal()">×</button>
|
|
</div>
|
|
|
|
<div class="credit-modal-body">
|
|
<form id="credit-manager-form" method="post" action="">
|
|
<?php wp_nonce_field('credit_manager_action', 'credit_manager_nonce'); ?>
|
|
<input type="hidden" name="action" value="<?php echo $is_edit_mode ? 'update_credit' : 'create_credit'; ?>">
|
|
<input type="hidden" name="credit_id" value="<?php echo $credit_id; ?>">
|
|
|
|
<div class="form-grid">
|
|
<!-- Titre -->
|
|
<div class="form-group">
|
|
<label for="title">Titre *</label>
|
|
<input type="text" id="title" name="title" value="<?php echo esc_attr($credit_data['title'] ?? ''); ?>" required>
|
|
</div>
|
|
|
|
<!-- Nom -->
|
|
<div class="form-group">
|
|
<label for="nom">Nom *</label>
|
|
<input type="text" id="nom" name="nom" value="<?php echo esc_attr($credit_data['nom'] ?? ''); ?>" required>
|
|
</div>
|
|
|
|
<!-- Prénom -->
|
|
<div class="form-group">
|
|
<label for="prenom">Prénom *</label>
|
|
<input type="text" id="prenom" name="prenom" value="<?php echo esc_attr($credit_data['prenom'] ?? ''); ?>" required>
|
|
</div>
|
|
|
|
<!-- Adresse -->
|
|
<div class="form-group form-group-full">
|
|
<label for="adresse">Adresse *</label>
|
|
<textarea id="adresse" name="adresse" rows="3" required><?php echo esc_textarea($credit_data['adresse'] ?? ''); ?></textarea>
|
|
</div>
|
|
|
|
<!-- Localité -->
|
|
<div class="form-group">
|
|
<label for="localite">Localité *</label>
|
|
<input type="text" id="localite" name="localite" value="<?php echo esc_attr($credit_data['localite'] ?? ''); ?>" required>
|
|
</div>
|
|
|
|
<!-- E-mail -->
|
|
<div class="form-group">
|
|
<label for="email">E-mail *</label>
|
|
<input type="email" id="email" name="email" value="<?php echo esc_attr($credit_data['email'] ?? ''); ?>" required>
|
|
</div>
|
|
|
|
<!-- Téléphone -->
|
|
<div class="form-group">
|
|
<label for="telephone">Téléphone</label>
|
|
<input type="tel" id="telephone" name="telephone" value="<?php echo esc_attr($credit_data['telephone'] ?? ''); ?>">
|
|
</div>
|
|
|
|
<!-- GSM -->
|
|
<div class="form-group">
|
|
<label for="gsm">GSM *</label>
|
|
<input type="tel" id="gsm" name="gsm" value="<?php echo esc_attr($credit_data['gsm'] ?? ''); ?>" required>
|
|
</div>
|
|
|
|
<!-- Société de crédit -->
|
|
<div class="form-group">
|
|
<label for="societe_credit">Société de crédit *</label>
|
|
<select id="societe_credit" name="societe_credit" required>
|
|
<option value="">Sélectionner une société</option>
|
|
<?php
|
|
// Récupérer les agences depuis la base de données
|
|
$credit_manager = new credit_manager();
|
|
$agences = $credit_manager->get_agences();
|
|
foreach ($agences as $agence) : ?>
|
|
<option value="<?php echo esc_attr($agence->id); ?>" <?php selected($credit_data['societe_credit'] ?? '', $agence->id); ?>>
|
|
<?php echo esc_html($agence->nom); ?>
|
|
</option>
|
|
<?php endforeach; ?>
|
|
</select>
|
|
</div>
|
|
|
|
<!-- Montant -->
|
|
<div class="form-group">
|
|
<label for="montant">Montant (€) *</label>
|
|
<input type="number" id="montant" name="montant" step="0.01" min="0" value="<?php echo esc_attr($credit_data['montant'] ?? ''); ?>" required>
|
|
</div>
|
|
|
|
<!-- Date -->
|
|
<div class="form-group">
|
|
<label for="date">Date *</label>
|
|
<input type="date" id="date" name="date" value="<?php echo esc_attr($credit_data['date'] ?? date('Y-m-d')); ?>" required>
|
|
</div>
|
|
|
|
<!-- Signature -->
|
|
<div class="form-group">
|
|
<label for="signature">Signature</label>
|
|
<input type="text" id="signature" name="signature" value="<?php echo esc_attr($credit_data['signature'] ?? ''); ?>">
|
|
</div>
|
|
|
|
<!-- N° de dossier / compte remboursement -->
|
|
<div class="form-group">
|
|
<label for="numero_dossier">N° de dossier / compte remboursement</label>
|
|
<input type="text" id="numero_dossier" name="numero_dossier" value="<?php echo esc_attr($credit_data['numero_dossier'] ?? ''); ?>">
|
|
</div>
|
|
|
|
<!-- Code -->
|
|
<div class="form-group">
|
|
<label for="code">Code</label>
|
|
<input type="text" id="code" name="code" value="<?php echo esc_attr($credit_data['code'] ?? ''); ?>">
|
|
</div>
|
|
|
|
<!-- Remarques -->
|
|
<div class="form-group form-group-full">
|
|
<label for="remarques">Remarques</label>
|
|
<textarea id="remarques" name="remarques" rows="4"><?php echo esc_textarea($credit_data['remarques'] ?? ''); ?></textarea>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="form-actions">
|
|
<button type="button" class="button button-secondary" onclick="closeCreditModal()">Annuler</button>
|
|
<button type="submit" class="button button-primary"><?php echo $is_edit_mode ? 'Mettre à jour' : 'Créer'; ?></button>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<?php
|
|
// Enqueue CSS et JS pour le modal
|
|
wp_enqueue_style('credit-manager-css', plugin_dir_url(__FILE__) . '../../assets/css/credit-manager.css', array(), '1.0.0');
|
|
wp_enqueue_script('credit-manager-js', plugin_dir_url(__FILE__) . '../../assets/js/credit-manager.js', array('jquery'), '1.0.0', true);
|
|
|
|
// Localiser les variables JavaScript
|
|
wp_localize_script('credit-manager-js', 'creditManagerAjax', array(
|
|
'ajaxurl' => admin_url('admin-ajax.php'),
|
|
'nonce' => wp_create_nonce('credit_manager_action')
|
|
));
|
|
?>
|
|
|