<?php
//_________________________________________________________________________________
//Zone de récupération des données
$formId = encrypt_decrypt("decrypt", rawurldecode($_GET['element']), $key_user, $iv_user);
$reqForm = getQueries('api_forms', array('idForm' => $formId));
//Avons-nous le formulaire ?
if(!$reqForm['count']) {
//Le formulaire n'existe pas, on le recréer
//Données du formulaire
$form = array('idForm' => $formId,
'form_uniqid' => uniqid(),
'form_name' => "Formulaire automatique",
'application_uniqid' => $_SESSION['current_application_uniqid'],
'user_id' => $user -> getUserId());
$flag = dbRowInsert2("api_forms", $form);
if($flag) {
itsLog(array('log_table' => "api_forms",
'log_operation' => "Re-création d'un formulaire",
'log_request' => json_encode($form),
'log_response' => json_encode($flag),
'log_color' => "success",
'log_display' => 1,
'log_timeout' => 5000,
'id_log' => getLastId("api_forms", 'idForm'),
'user_id' => $user -> getUserId()
));
//Refresh
redirect($_SERVER['REQUEST_URI']);
} else {
itsLog(array('log_table' => "api_forms",
'log_operation' => "Erreur durant la re-création du formulaire",
'log_request' => json_encode($form),
'log_response' => json_encode($flag),
'log_color' => "danger",
'log_display' => 1,
'log_timeout' => 5000,
'user_id' => $user -> getUserId()
));
}
}
$form = $reqForm['result'][0];
//
//Commande
if(!empty($form['command_id']) && !empty($form['command_id']) != null) {
$reqCommand = getQueries('api_commands', array('idCommand' => $form['command_id']));
$command = $reqCommand['result'][0];
//PARAMETRES
$reqParameters = getQueries('api_commands_parameters LEFT JOIN api_parameters ON api_commands_parameters.parameter_id = api_parameters.idParameter', array('api_commands_parameters.command_id' => $command['idCommand']));
$parameters = $reqParameters['result'];
}
//Champs
$reqFields = getQueries('api_fields', array('form_uniqid' => $form['form_uniqid'], 'ORDER BY' => 'field_order'));
$fields = $reqFields['result'];
//_________________________________________________________________________________
//_________________________________________________________________________________
//Récupération des attributs par défaut
$reqSetting = getQueries("nx_settings", array('setting_uniqid' => "6253e2a6e43a7"));
$settingJson = $reqSetting['result'][0];
$settings = json_decode($settingJson['setting_json'], true);
//_________________________________________________________________________________
//_________________________________________________________________________________
//Récupération des réglages
$reqSettings = getQueries("nx_settings", array('application_uniqid' => $_SESSION['current_application_uniqid']));
$allSettings = $reqSettings['result'];
//_________________________________________________________________________________
//Récupération des commandes API
$reqCommands = getQueries("api_commands", array('application_uniqid' => $_SESSION['current_application_uniqid']));
$commands = $reqCommands['result'];
//_________________________________________________________________________________
//_________________________________________________________________________________
//Création d'un champ
if(isset($_POST['add-field'])) {
//Données du formulaire
$data = array('field_uniqid' => uniqid(),
'field_label' => htmlspecialchars($_POST['field_label']),
'field_placeholder' => htmlspecialchars($_POST['field_placeholder']),
'field_prefix' => htmlspecialchars($_POST['field_prefix']),
'field_name' => htmlspecialchars($_POST['field_name']),
'field_type' => htmlspecialchars($_POST['field_type']),
'field_source' => htmlspecialchars($_POST['field_source']),
'field_readonly' => $_POST['field_readonly'] == "1" ? 1 : 0,
'form_uniqid' => $form['form_uniqid'],
'application_uniqid' => $_SESSION['current_application_uniqid'],
'setting_uniqid' => htmlspecialchars($_POST['setting_uniqid']),
'entite_id' => $idEntite,
'user_id' => $user -> getUserId());
//Ajout des options aux select / multiselect
if($_POST['field_type'] == 'select' || $_POST['field_type'] == 'multiselect') {
//Récupérer les options ou un profil de réglage ?
if($_POST['field_source'] == 'options') {
$selectOptsArray = explode(",", $_POST['field_select']);
$structure = array();
foreach($selectOptsArray as $selectOption) {
if (strpos($selectOption, '|') !== false) {
$item = explode("|", $selectOption);
$array = array('value' => ( (!empty($item[0])) ? $item[0] : ($item[0] == 0 ? "0" : "") ),
'option' => ( (!empty($item[1])) ? $item[1] : ($item[1] == 0 ? "0" : "") ) );
} else {
$array = array('value' => ( (!empty($selectOption)) ? $selectOption : "" ),
'option' => ( (!empty($selectOption)) ? $selectOption : "" ) );
}
array_push($structure, $array);
}
$data['field_select'] = json_encode($structure);
}
}
//Si fonction de calcul activé
if($form['form_calculation'] == 1) {
$data['field_formula'] = htmlspecialchars($_POST['field_formula']);
}
$flag = createField($data);
if($flag) {
itsLog(array('log_table' => "api_fields",
'log_operation' => "Ajout d'un champ",
'log_request' => json_encode($data),
'log_response' => json_encode($flag),
'log_color' => "success",
'log_display' => 1,
'log_timeout' => 5000,
'id_log' => getLastId("api_fields", 'idField'),
'user_id' => $user -> getUserId()
));
} else {
itsLog(array('log_table' => "api_fields",
'log_operation' => "Erreur durant l'ajout d'un champ",
'log_request' => json_encode($data),
'log_response' => json_encode($flag),
'log_color' => "danger",
'log_display' => 1,
'log_timeout' => 5000,
'user_id' => $user -> getUserId()
));
}
//Refresh
redirect($_SERVER['REQUEST_URI']);
}
//_________________________________________________________________________________
//_________________________________________________________________________________
//Mise à jour de l'ordre des champs
if(isset($_POST['update-fields'])) {
//Commence l'ordre à 10
$order = 10;
//Parcours du POST
foreach ($_POST as $key => $value) {
if(strpos($key, "field_") !== false) {
//Pour chaque champ, on récupère son id
$idField = substr($key, strpos($key, "_") + 1);
//Données du formulaire
$form = array('field_order' => $order,
'user_id' => $user -> getUserId());
$selector = array('idField' => $idField);
$flag = dbRowUpdate2("api_fields", $form, $selector);
//Incrémentation de 10 de l'ordre
$order = $order + 10;
}
}
//Refresh
redirect($_SERVER['REQUEST_URI']);
}
//_________________________________________________________________________________
//_________________________________________________________________________________
//Mise à jour d'un champ
if(isset($_POST['update-field'])) {
//ID du champ
$idField = htmlspecialchars($_POST['idfield']);
$selector = array('idField' => $idField);
//Récupère le champ
$reqItem = getQueries('api_fields', $selector);
$field = $reqItem['result'][0];
$field_settings = json_decode($field['field_settings'], true);
$field_settings['post_label'] = htmlspecialchars($_POST['post_label']);
$field_settings['post_command'] = htmlspecialchars($_POST['post_command']);
$field_settings['post_id'] = htmlspecialchars($_POST['post_id']);
//Données du formulaire
$data = array('field_label' => htmlspecialchars($_POST['field_label']),
'field_placeholder' => htmlspecialchars($_POST['field_placeholder']),
'field_text' => $_POST['field_text'],
'field_name' => htmlspecialchars($_POST['field_name']),
'field_id' => htmlspecialchars($_POST['field_id']),
'field_type' => htmlspecialchars($_POST['field_type']),
'field_source' => htmlspecialchars($_POST['field_source']),
'field_foreign_column_uniqid' => htmlspecialchars($_POST['field_foreign_column_uniqid']),
'field_multiple' => htmlspecialchars($_POST['field_multiple']),
'field_readonly' => $_POST['field_readonly'] == "1" ? 1 : 0,
'field_mandatory' => $_POST['field_mandatory'] == "1" ? 1 : 0,
'field_settings' => json_encode($field_settings),
'setting_uniqid' => htmlspecialchars($_POST['setting_uniqid']),
'user_id' => $user -> getUserId());
//Ajout des options aux select / multiselect
if($_POST['field_type'] == 'select' || $_POST['field_type'] == 'multiselect') {
//Récupérer les options ou un profil de réglage ?
if($_POST['field_source'] == 'options') {
$selectOptsArray = explode(",", $_POST['field_select']);
$structure = array();
foreach($selectOptsArray as $selectOption) {
if (strpos($selectOption, '|') !== false) {
$item = explode("|", $selectOption);
$array = array('value' => ( (!empty($item[0])) ? $item[0] : ($item[0] == 0 ? "0" : "") ),
'option' => ( (!empty($item[1])) ? $item[1] : ($item[1] == 0 ? "0" : "") ) );
} else {
$array = array('value' => ( (!empty($selectOption)) ? $selectOption : "" ),
'option' => ( (!empty($selectOption)) ? $selectOption : "" ) );
}
array_push($structure, $array);
}
$data['field_select'] = json_encode($structure);
}
}
//Si fonction de calcul activé
if($form['form_calculation'] == 1) {
$data['field_formula'] = htmlspecialchars($_POST['field_formula']);
}
$flag = dbRowUpdate2("api_fields", $data, $selector);
if($flag) {
itsLog(array('log_table' => "api_fields",
'log_operation' => "Mise à jour d'un champ",
'log_request' => json_encode($data),
'log_response' => json_encode($flag),
'log_selector' => json_encode($selector),
'log_color' => "success",
'log_display' => 1,
'log_timeout' => 5000,
'id_log' => $idField,
'user_id' => $user -> getUserId()
));
} else {
itsLog(array('log_table' => "api_fields",
'log_operation' => "Erreur durant la mise à jour d'un champ",
'log_request' => json_encode($data),
'log_response' => json_encode($flag),
'log_selector' => json_encode($selector),
'log_color' => "danger",
'log_display' => 1,
'log_timeout' => 5000,
'id_log' => $idField,
'user_id' => $user -> getUserId()
));
}
//Refresh
redirect($_SERVER['REQUEST_URI']);
}
//_________________________________________________________________________________
//_________________________________________________________________________________
//Mise à jour du formulaire
if(isset($_POST['update-form'])) {
//Données du formulaire
$form = array('form_name' => htmlspecialchars($_POST['form_name']),
'form_calculation' => $_POST['form_calculation'] == "1" ? 1 : 0,
'user_id' => $user -> getUserId());
$selector = array('idForm' => $formId);
$flag = dbRowUpdate2("api_forms", $form, $selector);
if($flag) {
itsLog(array('log_table' => "api_forms",
'log_operation' => "Mise à jour du formulaire",
'log_request' => json_encode($form),
'log_response' => json_encode($flag),
'log_selector' => json_encode($selector),
'log_color' => "success",
'log_display' => 1,
'log_timeout' => 5000,
'id_log' => $idField,
'user_id' => $user -> getUserId()
));
} else {
itsLog(array('log_table' => "api_forms",
'log_operation' => "Erreur durant la mise à jour du formulaire",
'log_request' => json_encode($form),
'log_response' => json_encode($flag),
'log_selector' => json_encode($selector),
'log_color' => "danger",
'log_display' => 1,
'log_timeout' => 5000,
'id_log' => $idField,
'user_id' => $user -> getUserId()
));
}
//Refresh
redirect($_SERVER['REQUEST_URI']);
}
//_________________________________________________________________________________
?>
<div class="content d-flex flex-column flex-column-fluid" id="kt_content">
<!--begin::Container-->
<div class="container-xxl" id="kt_content_container">
<!--begin::Card-->
<div class="card pt-4 mb-6 mb-xl-9">
<!--begin::Card header-->
<div class="card-header border-0">
<!--begin::Card title-->
<div class="card-title">
<h2>Modification du formulaire <?= $form['form_name']?></h2>
</div>
<!--end::Card title-->
</div>
<!--end::Card header-->
<!--begin::Card body-->
<div class="card-body pt-0 pb-5">
<!--begin::Row-->
<div class="row">
<!--begin::Col-->
<div class="col-lg-4">
<form method="post" action="">
<!--begin::Card-->
<div class="card card-bordered">
<!--begin::Card header-->
<div class="card-header">
<div class="card-title">
<h3 class="card-label">Options</h3>
</div>
</div>
<!--end::Card header-->
<!--begin::Card body-->
<div class="card-body">
<!--begin::Input group-->
<div class="fv-row mb-7">
<!--begin::Label-->
<label class="required fw-bold fs-6 mb-2">Nom formulaire</label>
<!--end::Label-->
<!--begin::Input-->
<input type="text" name="form_name" class="form-control form-control-solid mb-3 mb-lg-0" placeholder="Ex: Nouveau contact" value="<?= $form['form_name']?>"/>
<!--end::Input-->
</div>
<!--end::Input group-->
<!--begin::Input group-->
<div class="form-check form-switch form-check-custom form-check-solid">
<input class="form-check-input" type="checkbox" value="1" id="form_calculation" name="form_calculation" <?= ($form['form_calculation'] == 1 ? "checked" : "") ?>/>
<label class="form-check-label" for="form_calculation">
Formules de calcul
</label>
</div>
<!--end::Input group-->
</div>
<!--end::Card body-->
<!--begin::Card footer-->
<div class="card-footer d-flex justify-content-end py-6 px-9">
<button type="submit" class="btn btn-primary" name="update-form">Enregistrer</button>
</div>
<!--end::Card footer-->
</div>
<!--end::Card-->
</form>
<br>
<!--begin::Card-->
<div class="card card-bordered">
<!--begin::Card header-->
<div class="card-header">
<div class="card-title">
<h3 class="card-label">Champs</h3>
</div>
</div>
<!--end::Card header-->
<!--begin::Card body-->
<div class="card-body">
<!--begin::Row-->
<!--end::Row-->
</div>
<!--end::Card body-->
<!--begin::Card footer-->
<div class="card-footer border-0 d-flex justify-content-center pt-0">
<a href="#" class="btn btn-sm btn-light-primary" data-bs-toggle="modal" data-bs-target="#add-item">Ajouter un champ</a><br>
</div>
<!--end::Card footer-->
</div>
<!--end::Card-->
</div>
<!--end::Col-->
<!--begin::Col-->
<div class="col-lg-8">
<form method="post" action="">
<!--begin::Card-->
<div class="card card-bordered">
<!--begin::Card header-->
<div class="card-header">
<div class="card-title">
<h3 class="card-label">Formulaire</h3>
</div>
</div>
<!--end::Card header-->
<!--begin::Card body-->
<div class="card-body">
<!--begin::Row-->
<div class="row row-cols-1 g-10 min-h-100px draggable-zone">
<?php
foreach($fields as $field) {?>
<div class="col draggable">
<div class="table-responsive">
<input type="number" name="field_<?= $field['idField']?>" style="display: none;">
<!--begin::Table-->
<table class="table align-middle gs-0 gy-5">
<!--begin::Table head-->
<thead>
<tr>
<th class="p-0 w-50px"></th>
<th class="p-0 min-w-300px"></th>
<th class="p-0 min-w-40px"></th>
</tr>
</thead>
<!--end::Table head-->
<!--begin::Table body-->
<tbody>
<tr data-id="<?= encrypt_decrypt("encrypt", $field['idField'], $key_user, $iv_user)?>" data-method="custom" data-element="<?= encrypt_decrypt("encrypt", "field", $key_user, $iv_user)?>" class="rounded py-5 px-5 bg-light-primary">
<th>
<a href="#" class="btn btn-icon btn-hover-light-primary draggable-handle">
<!--begin::Svg Icon | path: icons/duotune/abstract/abs015.svg-->
<span class="svg-icon svg-icon-2x">
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none">
<path d="M21 7H3C2.4 7 2 6.6 2 6V4C2 3.4 2.4 3 3 3H21C21.6 3 22 3.4 22 4V6C22 6.6 21.6 7 21 7Z" fill="black" />
<path opacity="0.3" d="M21 14H3C2.4 14 2 13.6 2 13V11C2 10.4 2.4 10 3 10H21C21.6 10 22 10.4 22 11V13C22 13.6 21.6 14 21 14ZM22 20V18C22 17.4 21.6 17 21 17H3C2.4 17 2 17.4 2 18V20C2 20.6 2.4 21 3 21H21C21.6 21 22 20.6 22 20Z" fill="black" />
</svg>
</span>
<!--end::Svg Icon-->
</a>
</th>
<td>
<label class="<?= ($field['field_mandatory'] ? 'required' : '')?>"><?= $field['field_label']?></label>
<span class="text-muted fw-bold d-block fs-7"><?= $settings['field_type'][$field['field_type']]?><?= ( ($form['form_calculation'] == 1) ? ( !empty($field['field_formula']) ? " / f(x): " . $field['field_formula']: " / Aucune formule") : "" ) ?></span>
</td>
<!--begin::Action=-->
<td class="text-end">
<a href="#" class="btn btn-sm btn-icon btn-bg-light btn-active-color-primary" data-bs-toggle="modal" data-bs-target="#update-item_<?= $field['idField']?>">
<!--begin::Svg Icon | path: assets/media/icons/duotune/general/gen055.svg-->
<span class="svg-icon svg-icon-muted svg-icon-2hx"><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none">
<path opacity="0.3" fill-rule="evenodd" clip-rule="evenodd" d="M2 4.63158C2 3.1782 3.1782 2 4.63158 2H13.47C14.0155 2 14.278 2.66919 13.8778 3.04006L12.4556 4.35821C11.9009 4.87228 11.1726 5.15789 10.4163 5.15789H7.1579C6.05333 5.15789 5.15789 6.05333 5.15789 7.1579V16.8421C5.15789 17.9467 6.05333 18.8421 7.1579 18.8421H16.8421C17.9467 18.8421 18.8421 17.9467 18.8421 16.8421V13.7518C18.8421 12.927 19.1817 12.1387 19.7809 11.572L20.9878 10.4308C21.3703 10.0691 22 10.3403 22 10.8668V19.3684C22 20.8218 20.8218 22 19.3684 22H4.63158C3.1782 22 2 20.8218 2 19.3684V4.63158Z" fill="black"/>
<path d="M10.9256 11.1882C10.5351 10.7977 10.5351 10.1645 10.9256 9.77397L18.0669 2.6327C18.8479 1.85165 20.1143 1.85165 20.8953 2.6327L21.3665 3.10391C22.1476 3.88496 22.1476 5.15129 21.3665 5.93234L14.2252 13.0736C13.8347 13.4641 13.2016 13.4641 12.811 13.0736L10.9256 11.1882Z" fill="black"/>
<path d="M8.82343 12.0064L8.08852 14.3348C7.8655 15.0414 8.46151 15.7366 9.19388 15.6242L11.8974 15.2092C12.4642 15.1222 12.6916 14.4278 12.2861 14.0223L9.98595 11.7221C9.61452 11.3507 8.98154 11.5055 8.82343 12.0064Z" fill="black"/>
</svg></span>
<!--end::Svg Icon-->
</a>
<a href="#" class="btn btn-sm btn-icon btn-bg-light btn-active-color-primary" data-action="delete">
<!--begin::Svg Icon | path: assets/media/icons/duotune/general/gen027.svg-->
<span class="svg-icon svg-icon-muted svg-icon-2hx"><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none">
<path d="M5 9C5 8.44772 5.44772 8 6 8H18C18.5523 8 19 8.44772 19 9V18C19 19.6569 17.6569 21 16 21H8C6.34315 21 5 19.6569 5 18V9Z" fill="black"/>
<path opacity="0.5" d="M5 5C5 4.44772 5.44772 4 6 4H18C18.5523 4 19 4.44772 19 5V5C19 5.55228 18.5523 6 18 6H6C5.44772 6 5 5.55228 5 5V5Z" fill="black"/>
<path opacity="0.5" d="M9 4C9 3.44772 9.44772 3 10 3H14C14.5523 3 15 3.44772 15 4V4H9V4Z" fill="black"/>
</svg></span>
<!--end::Svg Icon-->
</a>
</td>
<!--end::Action=-->
</tr>
</tbody>
<!--end::Table body-->
</table>
<!--end::Table-->
</div>
</div>
<?php
}
?>
</div>
<!--end::Row-->
</div>
<!--end::Card body-->
<!--begin::Actions-->
<div class="card-footer d-flex justify-content-end py-6 px-9">
<button type="submit" class="btn btn-primary" name="update-fields">Enregistrer</button>
</div>
<!--end::Actions-->
</div>
<!--end::Card-->
</form>
</div>
<!--end::Col-->
</div>
</div>
<!--end::Card body-->
</div>
<!--end::Card-->
</div>
<!--end::Container-->
</div>
<!--begin::Modal - Ajouter champs-->
<div class="modal fade" id="add-item" tabindex="-1" aria-hidden="true">
<!--begin::Modal dialog-->
<div class="modal-dialog modal-dialog-centered mw-650px">
<!--begin::Modal content-->
<div class="modal-content">
<!--begin::Modal header-->
<div class="modal-header" id="kt_modal_add_user_header">
<!--begin::Modal title-->
<h2 class="fw-bolder">Ajouter un champ</h2>
<!--end::Modal title-->
<!--begin::Close-->
<div class="btn btn-icon btn-sm btn-active-icon-primary" data-bs-dismiss="modal">
<!--begin::Svg Icon | path: icons/duotune/arrows/arr061.svg-->
<span class="svg-icon svg-icon-1">
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none">
<rect opacity="0.5" x="6" y="17.3137" width="16" height="2" rx="1" transform="rotate(-45 6 17.3137)" fill="black" />
<rect x="7.41422" y="6" width="16" height="2" rx="1" transform="rotate(45 7.41422 6)" fill="black" />
</svg>
</span>
<!--end::Svg Icon-->
</div>
<!--end::Close-->
</div>
<!--end::Modal header-->
<!--begin::Modal body-->
<div class="modal-body scroll-y mx-5 mx-xl-15 my-7">
<!--begin::Form-->
<form class="form" action="" method="post">
<!--begin::Scroll-->
<div class="d-flex flex-column scroll-y me-n7 pe-7" id="kt_modal_add_user_scroll" data-kt-scroll="true" data-kt-scroll-activate="{default: false, lg: true}" data-kt-scroll-max-height="auto" data-kt-scroll-dependencies="#kt_modal_add_user_header" data-kt-scroll-wrappers="#kt_modal_add_user_scroll" data-kt-scroll-offset="300px">
<!--begin::Input group-->
<div class="fv-row mb-7">
<!--begin::Label-->
<label class="required fw-bold fs-6 mb-2">Libellé</label>
<!--end::Label-->
<!--begin::Input-->
<input type="text" name="field_label" class="form-control form-control-solid mb-3 mb-lg-0" placeholder="Ex: Nom du client" />
<!--end::Input-->
</div>
<!--end::Input group-->
<!--begin::Input group-->
<div class="fv-row mb-7">
<!--begin::Label-->
<label class="required fw-bold fs-6 mb-2">Placeholder</label>
<!--end::Label-->
<!--begin::Input-->
<input type="text" name="field_placeholder" class="form-control form-control-solid mb-3 mb-lg-0" placeholder="Ex: John Doe" />
<!--end::Input-->
</div>
<!--end::Input group-->
<!--begin::Input group-->
<div class="fv-row mb-7">
<!--begin::Label-->
<label class="required fw-bold fs-6 mb-2">Type de champ</label>
<!--end::Label-->
<!--begin::Input-->
<select data-control="select2" data-placeholder="Choisir un type..." class="form-select form-select-solid form-select-lg fw-bold" name="field_type" id="field_type" data-dropdown-parent="#add-item">
<?php
foreach($settings['field_type'] as $value => $option) {
echo '<option value="'.$value.'">'.$option.'</option>';
}
?>
</select>
<!--end::Input-->
</div>
<!--end::Input group-->
<!--begin::Input group-->
<div class="fv-row mb-7" id="section_prefix">
<!--begin::Label-->
<label class="required fw-bold fs-6 mb-2">Préfixe</label>
<!--end::Label-->
<!--begin::Input-->
<input type="text" name="field_prefix" id="field_prefix" class="form-control form-control-solid mb-3 mb-lg-0" placeholder="Ex: CHF" />
<!--end::Input-->
</div>
<!--end::Input group-->
<!--begin::Input group-->
<div class="fv-row mb-7" id="section_source">
<!--begin::Radio group-->
<div data-kt-buttons="true">
<!--begin::Radio button-->
<label class="btn btn-outline btn-outline-dashed d-flex flex-stack text-start p-6 mb-5">
<!--end::Description-->
<div class="d-flex align-items-center me-2">
<!--begin::Radio-->
<div class="form-check form-check-custom form-check-solid form-check-primary me-6">
<input class="form-check-input" type="radio" name="field_source" checked="checked" value="options"/>
</div>
<!--end::Radio-->
<!--begin::Info-->
<div class="flex-grow-1">
<h2 class="d-flex align-items-center fs-3 fw-bolder flex-wrap">
Saisie manuelle
</h2>
<div class="fw-bold opacity-50">
Saisissez les options de votre liste déroulante
</div>
</div>
<!--end::Info-->
</div>
<!--end::Description-->
</label>
<!--end::Radio button-->
<!--begin::Radio button-->
<label class="btn btn-outline btn-outline-dashed d-flex flex-stack text-start p-6 mb-5 active">
<!--end::Description-->
<div class="d-flex align-items-center me-2">
<!--begin::Radio-->
<div class="form-check form-check-custom form-check-solid form-check-primary me-6">
<input class="form-check-input" type="radio" name="field_source" value="settings"/>
</div>
<!--end::Radio-->
<!--begin::Info-->
<div class="flex-grow-1">
<h2 class="d-flex align-items-center fs-3 fw-bolder flex-wrap">
Profil de réglage
</h2>
<div class="fw-bold opacity-50">
Utilisez une liste de valeur défini dans un profil de réglage
</div>
</div>
<!--end::Info-->
</div>
<!--end::Description-->
</label>
<!--end::Radio button-->
<!--begin::Radio button-->
<label class="btn btn-outline btn-outline-dashed d-flex flex-stack text-start p-6 mb-5 active">
<!--end::Description-->
<div class="d-flex align-items-center me-2">
<!--begin::Radio-->
<div class="form-check form-check-custom form-check-solid form-check-primary me-6">
<input class="form-check-input" type="radio" name="field_source" value="posts"/>
</div>
<!--end::Radio-->
<!--begin::Info-->
<div class="flex-grow-1">
<h2 class="d-flex align-items-center fs-3 fw-bolder flex-wrap">
Posts
</h2>
<div class="fw-bold opacity-50">
Utilisez les posts du contexte
</div>
</div>
<!--end::Info-->
</div>
<!--end::Description-->
</label>
<!--end::Radio button-->
</div>
<!--end::Radio group-->
</div>
<!--end::Input group-->
<!--begin::Input group-->
<div class="fv-row mb-7" id="section_select_options">
<!--begin::Label-->
<label class="required fw-bold fs-6 mb-2">Options</label>
<!--end::Label-->
<!--begin::Input-->
<textarea name="field_select" class="form-control form-control-solid mb-3 mb-lg-0">option1,option2,option3</textarea>
<div class="form-text">Séparez les options par une virgule et les valeurs des libellés par une barre oblique, exemple:<code>7.7|TVA Normal, 2.5|TVA réduit</code></div>
<!--end::Input-->
</div>
<!--end::Input group-->
<!--begin::Input group-->
<div class="fv-row mb-7" id="section_select_setting">
<!--begin::Label-->
<label class="required fw-bold fs-6 mb-2">Profil de réglage</label>
<!--end::Label-->
<!--begin::Input-->
<select data-control="select2" data-placeholder="Choisir un profil..." class="form-select form-select-solid form-select-lg fw-bold" name="setting_uniqid" data-dropdown-parent="#add-item">
<?php
foreach($allSettings as $setting) {
echo '<option value="'.$setting['setting_uniqid'].'">'.$setting['setting_name'].'</option>';
}
?>
</select>
<!--end::Input-->
</div>
<!--end::Input group-->
<!--begin::Input group-->
<div class="fv-row mb-7 form-check form-switch form-check-custom form-check-solid">
<!--begin::Label-->
<label class="required fw-bold fs-6 mb-2 form-check-label">Lecture uniquement</label>
<!--end::Label-->
<!--begin::Input-->
<input class="orm-control form-control-solid mb-3 mb-lg-0 form-check-input" type="checkbox" value="1" id="field_readonly" name="field_readonly"/>
<!--end::Input-->
</div>
<!--end::Input group-->
<!--begin::Input group-->
<div class="fv-row mb-7">
<!--begin::Label-->
<label class="required fw-bold fs-6 mb-2">Nom API</label>
<!--end::Label-->
<!--begin::Input-->
<input type="text" name="field_name" class="form-control form-control-solid mb-3 mb-lg-0" placeholder="Ex: customer_name" />
<?php
if(isset($command)) {?>
<div class="form-text">Paramètre(s):
<?php
foreach($parameters as $parameter)
echo '<code>['.$parameter['parameter_name'].']</code>'
?>
</div>
<?php
}
?>
<!--end::Input-->
</div>
<!--end::Input group-->
<?php
if($form['form_calculation'] == 1) {?>
<!--begin::Input group-->
<div class="fv-row mb-7">
<!--begin::Label-->
<label class="required fw-bold fs-6 mb-2">Formule</label>
<!--end::Label-->
<!--begin::Input-->
<input type="text" name="field_formula" class="form-control form-control-solid mb-3 mb-lg-0" />
<div class="form-text">Exemple:
<code>[product_price] * [product_units] + [product_marge]</code>
</div>
<!--end::Input-->
</div>
<!--end::Input group-->
<?php
}
?>
</div>
<!--end::Scroll-->
<!--begin::Actions-->
<div class="text-center pt-15">
<button type="reset" class="btn btn-light me-3" data-bs-dismiss="modal">Annuler</button>
<button type="submit" class="btn btn-primary" name="add-field">
<span class="indicator-label">Ajouter</span>
<span class="indicator-progress">2 secondes...
<span class="spinner-border spinner-border-sm align-middle ms-2"></span></span>
</button>
</div>
<!--end::Actions-->
</form>
<!--end::Form-->
</div>
<!--end::Modal body-->
</div>
<!--end::Modal content-->
</div>
<!--end::Modal dialog-->
</div>
<!--end::Modal - Ajouter champs-->
<!--begin::Modal - Modifier les champs-->
<?php
foreach($fields as $field) {
$field_settings = json_decode($field['field_settings'], true);
$field_settings = is_array($field_settings) ? $field_settings : array();
?>
<div class="modal fade" id="update-item_<?= $field['idField']?>" tabindex="-1" aria-hidden="true">
<!--begin::Modal dialog-->
<div class="modal-dialog modal-dialog-centered mw-650px">
<!--begin::Modal content-->
<div class="modal-content">
<!--begin::Modal header-->
<div class="modal-header">
<!--begin::Modal title-->
<h2 class="fw-bolder">Modifier le champ <?= $field['field_label']?></h2>
<!--end::Modal title-->
<!--begin::Close-->
<div class="btn btn-icon btn-sm btn-active-icon-primary" data-bs-dismiss="modal">
<!--begin::Svg Icon | path: icons/duotune/arrows/arr061.svg-->
<span class="svg-icon svg-icon-1">
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none">
<rect opacity="0.5" x="6" y="17.3137" width="16" height="2" rx="1" transform="rotate(-45 6 17.3137)" fill="black" />
<rect x="7.41422" y="6" width="16" height="2" rx="1" transform="rotate(45 7.41422 6)" fill="black" />
</svg>
</span>
<!--end::Svg Icon-->
</div>
<!--end::Close-->
</div>
<!--end::Modal header-->
<!--begin::Modal body-->
<div class="modal-body scroll-y mx-5 mx-xl-15 my-7">
<!--begin::Form-->
<form class="form" action="" method="post">
<!--begin::Scroll-->
<div class="d-flex flex-column scroll-y me-n7 pe-7" id="kt_modal_add_user_scroll" data-kt-scroll="true" data-kt-scroll-activate="{default: false, lg: true}" data-kt-scroll-max-height="auto" data-kt-scroll-dependencies="#kt_modal_add_user_header" data-kt-scroll-wrappers="#kt_modal_add_user_scroll" data-kt-scroll-offset="300px">
<!--begin::Input group-->
<div class="fv-row mb-7" style="display:none;">
<!--begin::Label-->
<label class="required fw-bold fs-6 mb-2">ID</label>
<!--end::Label-->
<!--begin::Input-->
<input type="text" name="idfield" class="form-control form-control-solid mb-3 mb-lg-0" value="<?= $field['idField']?>" />
<!--end::Input-->
</div>
<!--end::Input group-->
<!--begin::Input group-->
<div class="fv-row mb-7">
<!--begin::Label-->
<label class="required fw-bold fs-6 mb-2">Libellé</label>
<!--end::Label-->
<!--begin::Input-->
<input type="text" name="field_label" class="form-control form-control-solid mb-3 mb-lg-0" placeholder="Nom du client" value="<?= $field['field_label']?>" />
<!--end::Input-->
</div>
<!--end::Input group-->
<!--begin::Input group-->
<div class="fv-row mb-7">
<!--begin::Label-->
<label class="required fw-bold fs-6 mb-2">Placeholder</label>
<!--end::Label-->
<!--begin::Input-->
<input type="text" name="field_placeholder" class="form-control form-control-solid mb-3 mb-lg-0" placeholder="Ex: John Doe" value="<?= $field['field_placeholder']?>"/>
<!--end::Input-->
</div>
<!--end::Input group-->
<!--begin::Input group-->
<div class="fv-row mb-7">
<!--begin::Label-->
<label class="required fw-bold fs-6 mb-2">Type de champ</label>
<!--end::Label-->
<!--begin::Input-->
<select data-control="select2" data-placeholder="Choisir un type..." class="form-select form-select-solid form-select-lg fw-bold" name="field_type" data-dropdown-parent="#update-item_<?= $field['idField']?>">
<?php
foreach($settings['field_type'] as $value => $option) {
$selected = $field['field_type'] == $value ? "selected" : "";
echo '<option value="'.$value.'" '.$selected.'>'.$option.'</option>';
}
?>
</select>
<!--end::Input-->
</div>
<!--end::Input group-->
<?php
if($field['field_type'] == 'select' || $field['field_type'] == 'multiselect') {?>
<!--begin::Input group-->
<div class="fv-row mb-7">
<!--begin::Radio group-->
<div data-kt-buttons="true">
<!--begin::Radio button-->
<label class="btn btn-outline btn-outline-dashed d-flex flex-stack text-start p-6 mb-5">
<!--end::Description-->
<div class="d-flex align-items-center me-2">
<!--begin::Radio-->
<div class="form-check form-check-custom form-check-solid form-check-primary me-6">
<input class="form-check-input" type="radio" name="field_source" <?= ($field['field_source'] == 'options' ? 'checked="checked"' : '')?> value="options"/>
</div>
<!--end::Radio-->
<!--begin::Info-->
<div class="flex-grow-1">
<h2 class="d-flex align-items-center fs-3 fw-bolder flex-wrap">
Saisie manuelle
</h2>
<div class="fw-bold opacity-50">
Saisissez les options de votre liste déroulante
</div>
</div>
<!--end::Info-->
</div>
<!--end::Description-->
</label>
<!--end::Radio button-->
<!--begin::Radio button-->
<label class="btn btn-outline btn-outline-dashed d-flex flex-stack text-start p-6 mb-5 active">
<!--end::Description-->
<div class="d-flex align-items-center me-2">
<!--begin::Radio-->
<div class="form-check form-check-custom form-check-solid form-check-primary me-6">
<input class="form-check-input" type="radio" name="field_source" <?= ($field['field_source'] == 'settings' ? 'checked="checked"' : '')?> value="settings"/>
</div>
<!--end::Radio-->
<!--begin::Info-->
<div class="flex-grow-1">
<h2 class="d-flex align-items-center fs-3 fw-bolder flex-wrap">
Profil de réglage
</h2>
<div class="fw-bold opacity-50">
Utilisez une liste de valeur défini dans un profil de réglage
</div>
</div>
<!--end::Info-->
</div>
<!--end::Description-->
</label>
<!--end::Radio button-->
<!--begin::Radio button-->
<label class="btn btn-outline btn-outline-dashed d-flex flex-stack text-start p-6 mb-5 active">
<!--end::Description-->
<div class="d-flex align-items-center me-2">
<!--begin::Radio-->
<div class="form-check form-check-custom form-check-solid form-check-primary me-6">
<input class="form-check-input" type="radio" name="field_source" <?= ($field['field_source'] == 'posts' ? 'checked="checked"' : '')?> value="posts"/>
</div>
<!--end::Radio-->
<!--begin::Info-->
<div class="flex-grow-1">
<h2 class="d-flex align-items-center fs-3 fw-bolder flex-wrap">
Posts
</h2>
<div class="fw-bold opacity-50">
Utilisez les posts du contexte
</div>
</div>
<!--end::Info-->
</div>
<!--end::Description-->
</label>
<!--end::Radio button-->
</div>
<!--end::Radio group-->
</div>
<!--end::Input group-->
<?php
}
if($field['field_source'] == 'options') {
$allOpts = json_decode($field['field_select'], true);
$optsString = "";
foreach($allOpts as $opts) {
if(!empty($opts['value']))
$optsString .= $opts['value'] . "|";
$optsString .= $opts['option'] . ",";
}
$optsString = substr_replace($optsString ,"", -1);
?>
<!--begin::Input group-->
<div class="fv-row mb-7">
<!--begin::Label-->
<label class="required fw-bold fs-6 mb-2">Options</label>
<!--end::Label-->
<!--begin::Input-->
<textarea name="field_select" class="form-control form-control-solid mb-3 mb-lg-0"><?= $optsString?></textarea>
<div class="form-text">Séparez les options par une virgule et les valeurs des libellés par une barre oblique, exemple:<code>7.7|TVA Normal, 2.5|TVA réduit</code></div>
<!--end::Input-->
</div>
<!--end::Input group-->
<?php
}
if($field['field_source'] == 'settings') {?>
<!--begin::Input group-->
<div class="fv-row mb-7">
<!--begin::Label-->
<label class="required fw-bold fs-6 mb-2">Profil de réglage</label>
<!--end::Label-->
<!--begin::Input-->
<select data-control="select2" data-placeholder="Choisir un profil..." class="form-select form-select-solid form-select-lg fw-bold" name="setting_uniqid" data-dropdown-parent="#update-item_<?= $field['idField']?>">
<?php
foreach($allSettings as $setting) {
$selected = $setting['setting_uniqid'] == $field['setting_uniqid'] ? "selected" : "";
echo '<option value="'.$setting['setting_uniqid'].'" '.$selected.'>'.$setting['setting_name'].'</option>';
}
?>
</select>
<!--end::Input-->
</div>
<!--end::Input group-->
<?php
}
if($field['field_source'] == 'posts') {
$post_label = key_exists('post_label', $field_settings) ? $field_settings['post_label'] : '';
?>
<!--begin::Input group-->
<div class="fv-row mb-7">
<!--begin::Label-->
<label class="required fw-bold fs-6 mb-2">Colonne du post</label>
<!--end::Label-->
<!--begin::Input-->
<textarea name="post_label" class="form-control form-control-solid mb-3 mb-lg-0"><?= $post_label?></textarea>
<div class="form-text">Saisissez la valeur à afficher dans la liste déroulante en se basant sur les colonnes du post, exemple:<code>[user_firstname] [user_lastname]</code></div>
<!--end::Input-->
</div>
<!--end::Input group-->
<?php
}
if($field['field_source'] == 'posts') {
$post_id = key_exists('post_id', $field_settings) ? $field_settings['post_id'] : '';
?>
<!--begin::Input group-->
<div class="fv-row mb-7">
<!--begin::Label-->
<label class="required fw-bold fs-6 mb-2">Colonne de l'Id du post</label>
<!--end::Label-->
<!--begin::Input-->
<input name="post_id" class="form-control form-control-solid mb-3 mb-lg-0" value="<?= $post_id?>">
<div class="form-text">Saisissez le nom de la colonne du post qui contient l'ID, exemple:<code>idUser</code></div>
<!--end::Input-->
</div>
<!--end::Input group-->
<?php
}
if($field['field_source'] == 'posts') {
$post_command = key_exists('post_command', $field_settings) ? $field_settings['post_command'] : '';
?>
<!--begin::Input group-->
<div class="fv-row mb-7">
<!--begin::Label-->
<label class="required fw-bold fs-6 mb-2">Commande API</label>
<!--end::Label-->
<!--begin::Input-->
<select data-control="select2" data-placeholder="Choisir une commande..." class="form-select form-select-solid form-select-lg fw-bold" name="post_command" data-dropdown-parent="#update-item_<?= $field['idField']?>">
<?php
foreach($commands as $command) {
$selected = $command['command_uniqid'] == $post_command ? "selected" : "";
echo '<option value="'.$command['command_uniqid'].'" '.$selected.'>'.$command['command_name'].'</option>';
}
?>
</select>
<div class="form-text">Choisissez la commande API qui alimentera le contexte des postes désirés.</div>
<!--end::Input-->
</div>
<!--end::Input group-->
<?php
}
if($field['field_type'] == 'foreignkey') {
//Avons-nous une table API pour cette clé étrangère ?
$reqTable = getQueries("api_infos_tables", array('info_table_foreignkey' => $field['field_name']));
if($reqTable['count']) {
$table = $reqTable['result'][0];
//Récupère les colonnes de cette table
$reqColumns = getQueries("api_infos_tables_columns", array('table_uniqid' => $table['info_table_uniqid']));
$columns = $reqColumns['result'];
?>
<!--begin::Input group-->
<div class="fv-row mb-7">
<!--begin::Label-->
<label class="required fw-bold fs-6 mb-2">Nom de la colonne</label>
<!--end::Label-->
<!--begin::Input-->
<select data-control="select2" data-placeholder="Choisir une colonne..." class="form-select form-select-solid form-select-lg fw-bold" name="field_foreign_column_uniqid" data-dropdown-parent="#update-item_<?= $field['idField']?>">
<?php
foreach($columns as $column) {
$selected = $field['field_foreign_column_uniqid'] == $column['info_table_column_uniqid'] ? "selected" : "";
echo '<option value="'.$column['info_table_column_uniqid'].'" '.$selected.'>'.$column['info_table_column_name'].'</option>';
}
?>
</select>
<!--end::Input-->
</div>
<!--end::Input group-->
<?php
}
}
if($field['field_type'] == 'foreignkey') {?>
<!--begin::Input group-->
<div class="fv-row mb-7">
<!--begin::Label-->
<label class="required fw-bold fs-6 mb-2">Liste déroulante</label>
<!--end::Label-->
<!--begin::Input-->
<select data-control="select2" data-placeholder="Choisir un type..." class="form-select form-select-solid form-select-lg fw-bold" name="field_multiple" data-dropdown-parent="#update-item_<?= $field['idField']?>">
<option value="0" <?= ($field['field_multiple'] == 0 ? "selected" : "")?>>Choix unique</option>
<option value="1" <?= ($field['field_multiple'] == 1 ? "selected" : "")?>>Choix mulitple</option>
</select>
<!--end::Input-->
</div>
<!--end::Input group-->
<?php
}
?>
<!--begin::Input group-->
<div class="fv-row mb-7 form-check form-switch form-check-custom form-check-solid">
<!--begin::Label-->
<label class="fw-bold fs-6 mb-2 form-check-label">Obligatoire</label>
<!--end::Label-->
<!--begin::Input-->
<input class="orm-control form-control-solid mb-3 mb-lg-0 form-check-input" type="checkbox" value="1" id="field_mandatory" name="field_mandatory" <?= ($field['field_mandatory'] == 1 ? "checked" : "") ?> />
<!--end::Input-->
</div>
<!--end::Input group-->
<!--begin::Input group-->
<div class="fv-row mb-7 form-check form-switch form-check-custom form-check-solid">
<!--begin::Label-->
<label class="fw-bold fs-6 mb-2 form-check-label">Lecture uniquement</label>
<!--end::Label-->
<!--begin::Input-->
<input class="orm-control form-control-solid mb-3 mb-lg-0 form-check-input" type="checkbox" value="1" id="field_readonly" name="field_readonly" <?= ($field['field_readonly'] == 1 ? "checked" : "") ?> />
<!--end::Input-->
</div>
<!--end::Input group-->
<!--begin::Input group-->
<div class="fv-row mb-7">
<!--begin::Label-->
<label class="required fw-bold fs-6 mb-2">Nom API</label>
<!--end::Label-->
<!--begin::Input-->
<input type="text" name="field_name" class="form-control form-control-solid mb-3 mb-lg-0" value="<?= $field['field_name']?>"/>
<?php
if(isset($command)) {?>
<div class="form-text">Paramètre(s):
<?php
foreach($parameters as $parameter)
echo '<code>['.$parameter['parameter_name'].']</code>'
?>
</div>
<?php
}
?>
<!--end::Input-->
</div>
<!--end::Input group-->
<!--begin::Input group-->
<div class="fv-row mb-7">
<!--begin::Label-->
<label class="required fw-bold fs-6 mb-2">Id HTML</label>
<!--end::Label-->
<!--begin::Input-->
<input type="text" name="field_id" class="form-control form-control-solid mb-3 mb-lg-0" value="<?= $field['field_id']?>"/>
<!--end::Input-->
</div>
<!--end::Input group-->
<!--begin::Input group-->
<div class="fv-row mb-7">
<!--begin::Label-->
<label class="required fw-bold fs-6 mb-2">Consigne</label>
<!--end::Label-->
<!--begin::Input-->
<textarea type="text" name="field_text" class="form-control form-control-solid mb-3 mb-lg-0"><?= $field['field_text']?></textarea>
<!--end::Input-->
</div>
<?php
if($form['form_calculation'] == 1) {?>
<!--begin::Input group-->
<div class="fv-row mb-7">
<!--begin::Label-->
<label class="required fw-bold fs-6 mb-2">Formule</label>
<!--end::Label-->
<!--begin::Input-->
<input type="text" name="field_formula" class="form-control form-control-solid mb-3 mb-lg-0" value="<?= $field['field_formula']?>" />
<div class="form-text">Exemple:
<code>[product_price] * [product_units] + [product_marge]</code>
</div>
<!--end::Input-->
</div>
<!--end::Input group-->
<?php
}
?>
</div>
<!--end::Scroll-->
<!--begin::Actions-->
<div class="text-center pt-15">
<button type="reset" class="btn btn-light me-3" data-bs-dismiss="modal">Annuler</button>
<button type="submit" class="btn btn-primary" name="update-field">
<span class="indicator-label">Enregistrer</span>
<span class="indicator-progress">2 secondes...
<span class="spinner-border spinner-border-sm align-middle ms-2"></span></span>
</button>
</div>
<!--end::Actions-->
</form>
<!--end::Form-->
</div>
<!--end::Modal body-->
</div>
<!--end::Modal content-->
</div>
<!--end::Modal dialog-->
</div>
<?php
}
?>
<!--end::Modal - Modifier les champs-->