Commit 34c77f12 authored by tguillon's avatar tguillon
Browse files

Correction : règle de validation

Correction : bdd
Correction : jquery
Ajout : calcul de l'obligation d'un AIPD coté serveur
parent 62752bbf
......@@ -106,9 +106,9 @@ ALTER TABLE fiches
DROP CONSTRAINT fiches_form_id_fkey,
ADD CONSTRAINT fiches_form_id_fkey FOREIGN KEY (form_id) REFERENCES formulaires (id) ON DELETE CASCADE ON UPDATE CASCADE;
ALTER TABLE fiches ADD COLUMN obligation_pia BOOL;
ALTER TABLE fiches ADD COLUMN realisation_pia BOOL NOT NULL DEFAULT FALSE;
ALTER TABLE fiches ADD COLUMN depot_pia BOOL NOT NULL DEFAULT FALSE;
ALTER TABLE fiches ADD COLUMN obligation_pia BOOL DEFAULT NULL;
ALTER TABLE fiches ADD COLUMN realisation_pia BOOL DEFAULT NULL;
ALTER TABLE fiches ADD COLUMN depot_pia BOOL DEFAULT NULL;
--
-- on passe le champ concernant la soutraitance à true en fonction si la fiche à un soustraitant
......
......@@ -269,6 +269,10 @@ class FichesController extends AppController
]
]);
if ($formulaireOptions['Formulaire']['usepia'] == true) {
$data['Fiche']['obligation_pia'] = $this->deductValueFieldObligationPia($data);
}
$success = $this->WebdpoFiche->saveWithVirtualFields($data, $formulaireFields, $formulaireOptions, false, true);
if ($success == true) {
......@@ -583,6 +587,20 @@ class FichesController extends AppController
]
]);
$formulaireOptions = $this->Formulaire->find('first', [
'conditions' => [
'id' => $form_id['Fiche']['form_id']
],
'fields' => [
'usesousfinalite',
'usebaselegale',
'usedecisionautomatisee',
'usetransferthorsue',
'usedonneessensible',
'usepia'
]
]);
$formulaireOLD = $this->Formulaire->find('first', [
'conditions' => [
'id' => $form_id['Fiche']['form_id']
......@@ -592,7 +610,13 @@ class FichesController extends AppController
]
]);
$success = $this->WebdpoFiche->saveWithVirtualFields($data, $formulaireFields, $formulaireOLD['Formulaire']['oldformulaire']);
if ($formulaireOLD['Formulaire']['oldformulaire'] === false) {
if ($formulaireOptions['Formulaire']['usepia'] == true) {
$data['Fiche']['obligation_pia'] = $this->deductValueFieldObligationPia($data);
}
}
$success = $this->WebdpoFiche->saveWithVirtualFields($data, $formulaireFields, $formulaireOptions, $formulaireOLD['Formulaire']['oldformulaire']);
if ($success == true) {
$this->Fiche->commit();
......@@ -1977,4 +2001,61 @@ class FichesController extends AppController
}
}
private function deductValueFieldObligationPia($data)
{
foreach (Fiche::LISTING_FIELDS_TRAITEMENT_NO_REQUIRED_PIA as $listingFieldsPiaNoRequired) {
if (!empty($data['WebdpoFiche'][$listingFieldsPiaNoRequired])) {
if ($data['WebdpoFiche'][$listingFieldsPiaNoRequired] == 'Oui') {
return false;
}
} else {
return null;
}
}
foreach (Fiche::LISTING_FIELDS_TRAITEMENT_REQUIRED_PIA as $listingFieldsPiaRequired) {
if (!empty($data['WebdpoFiche'][$listingFieldsPiaRequired])) {
if ($data['WebdpoFiche'][$listingFieldsPiaRequired] == 'Oui') {
return true;
}
} else {
return null;
}
}
foreach (Fiche::LISTING_FIELDS_TRAITEMENT_REQUIRED_PIA as $listingFieldsPiaRequired) {
if (!empty($data['WebdpoFiche'][$listingFieldsPiaRequired])) {
if ($data['WebdpoFiche'][$listingFieldsPiaRequired] == 'Oui') {
return true;
}
} else {
return null;
}
}
if (empty($data['WebdpoFiche']['criteres'])) {
return null;
}
$countOptionsChecked = count($data['WebdpoFiche']['criteres']);
if ($countOptionsChecked >= 2) {
return true;
}
if (empty($data['WebdpoFiche']['traitement_considere_risque'])) {
return null;
}
if ($countOptionsChecked == 1) {
if ($data['WebdpoFiche']['traitement_considere_risque'] == 'Oui') {
return true;
}
if ($data['WebdpoFiche']['traitement_considere_risque'] == 'Non') {
return false;
}
}
return null;
}
}
......@@ -287,6 +287,38 @@ class Fiche extends AppModel {
"Exclusion du bénéfice d’un droit/contrat" => "Exclusion du bénéfice d’un droit/contrat"
];
const LISTING_FIELDS_TRAITEMENT_NO_REQUIRED_PIA = [
'ressources_humaines',
'relation_fournisseurs',
'gestion_electoral',
'comites_entreprise',
'association',
'sante_prise_patient',
'avocats',
'greffiers',
'notaires',
'collectivites_affaires_scolaires',
'controles_acces',
'ethylotests'
];
const LISTING_FIELDS_TRAITEMENT_REQUIRED_PIA = [
'sante_medicosociaux',
'donnees_genetiques',
'profils_personnes_gestion_rh',
'surveiller_constante_employes',
'gestion_alertes_sociale_sanitaire',
'gestion_alertes_professionnelle',
'donnees_sante_registre',
'profilage_rupture_contrat',
'mutualises_manquements_rupture_contrat',
'profilage_donnees_externes',
'biometriques',
'gestion_logements_sociaux',
'accompagnement_social',
'localisation_large_echelle'
];
public $validate = [
'organisation_id' => [
'areUnique' => [
......@@ -302,16 +334,34 @@ class Fiche extends AppModel {
'message' => '... est déjà utilisée.'
]
],
// 'realisation_pia' => [
// 'notBlank' => [
// 'rule' => ['notBlank']
// ]
// ],
// 'depot_pia' => [
// 'obligation_pia' => [
// 'checkNotBlankIf' => [
// 'rule' => ['checkNotBlankIf', 'realisation_pia', true, ['1']]
// 'rule' => ['checkNotBlankIf', 'usepia', true, [true]]
// ]
// ],
'realisation_pia' => [
'checkNotBlankIf' => [
'rule' => ['checkNotBlankIf', 'formulaireOLD', true, [false]]
],
],
'depot_pia' => [
'checkNotBlankIf' => [
'rule' => ['checkNotBlankIf', 'realisation_pia', true, ['1']]
],
'checkBlankIf' => [
'rule' => ['checkBlankIf', 'realisation_pia', true, ['0']]
]
],
'coresponsable' => [
'notBlank' => [
'rule' => ['notBlank']
]
],
'soustraitance' => [
'notBlank' => [
'rule' => ['notBlank']
]
],
];
/**
......
......@@ -70,33 +70,6 @@ class WebdpoFiche extends AppModel {
]
],
// ---------------------------------------------------------------------
// ------------------INFORMATION TRAITEMENT-----------------------------
'realisation_pia' => [
'notBlank' => [
'rule' => ['notBlank']
]
],
'depot_pia' => [
'checkNotBlankIf' => [
'rule' => ['checkNotBlankIf', 'realisation_pia', true, ['1']]
]
],
'coresponsable' => [
'notBlank' => [
'rule' => ['notBlank']
]
],
'soustraitance' => [
'notBlank' => [
'rule' => ['notBlank']
]
],
// 'obligation_pia' => [
// 'checkNotBlankIf' => [
// 'rule' => ['checkNotBlankIf', 'usepia', true, [true]]
// ]
// ],
// ---------------------------------------------------------------------
// 'declarantraisonsociale' => [
// 'notBlank' => [
// 'rule' => ['notBlank']
......@@ -499,6 +472,11 @@ class WebdpoFiche extends AppModel {
unset($data['Fiche']['soustraitant']);
// champ virtuel pour la régle de validation
$data['Fiche']['usepia'] = $formulaireOptions['Formulaire']['usepia'];
$data['Fiche']['formulaireOLD'] = $formulaireOLD;
// Sauvegarde BDD Fiches
$Fiche->create($data['Fiche']);
$success = false !== $Fiche->save(null, ['atomic' => false]) && $success;
......@@ -763,14 +741,16 @@ class WebdpoFiche extends AppModel {
$referenceValue = Hash::get($this->data, "{$this->alias}.{$reference}");
if (!empty($checks)) {
if(empty($referenceValue)) {
if (empty($referenceValue)) {
$countOptionsChecked = 0;
} else {
$countOptionsChecked = count($referenceValue);
}
if ($countOptionsChecked == $nbOptionsChecked) {
$success = Validation::notBlank($checks) && $success;
foreach ($checks as $value) {
$success = Validation::notBlank($value) && $success;
}
}
}
......@@ -787,10 +767,16 @@ class WebdpoFiche extends AppModel {
$referenceValue = Hash::get($this->data, "{$this->alias}.{$reference}");
if (!empty($checks)) {
$countOptionsChecked = count($referenceValue);
if (empty($referenceValue)) {
$countOptionsChecked = 0;
} else {
$countOptionsChecked = count($referenceValue);
}
if ($countOptionsChecked >= $nbOptionsChecked) {
$success = Validation::blank($checks) && $success;
foreach ($checks as $value) {
$success = Validation::blank($value) && $success;
}
}
}
......
......@@ -309,30 +309,62 @@ if (in_array($this->request->params['action'], ['edit', 'show']) === true) {
</div>
</div>
<div class="col-md-12">
<span class='labelFormulaire'>
<?php
echo __d('fiche', 'fiche.textInfoPia');
<?php
if ($formulaireOLD['Formulaire']['oldformulaire'] === false) {
if (isset($usePIA) && $usePIA['Formulaire']['usepia'] === true) {
?>
</span>
<div class="row row35"></div>
</div>
<div class="col-md-12">
<span class='labelFormulaire'>
<?php
echo __d('fiche', 'fiche.textInfoPia');
?>
</span>
<div class="row row35"></div>
</div>
<?php
if($usePIA['Formulaire']['usepia'] === true) {
<div class="row">
<div class="col-md-6">
<?php
echo $this->WebcilForm->input('obligation_pia', [
'id' => 'obligation_pia',
// 'id' => 'obligation_pia_displayed',
'options' => [
true => 'Oui',
false => 'Non'
],
'class' => 'transformSelect form-control',
'required' => true,
'readonly' => true,
'disabled' => true,
'empty' => true,
'placeholder' => false,
'data-placeholder' => ' '
]);
?>
</div>
<div class="col-md-6"></div>
</div>
<?php
} else {
echo $this->WebcilForm->hidden('obligation_pia', [
'id' => 'obligation_pia',
'value' => null
]);
}
?>
<div class="row">
<div class="col-md-6">
<?php
echo $this->WebcilForm->input('obligation_pia', [
'id' => 'obligation_pia',
echo $this->WebcilForm->input('realisation_pia', [
'id' => 'realisation_pia',
'options' => [
true => 'Oui',
false => 'Non'
],
'class' => 'transformSelect form-control',
'required' => true,
'readonly' => true,
'empty' => $empty,
'placeholder' => false,
'data-placeholder' => ' '
......@@ -340,51 +372,26 @@ if (in_array($this->request->params['action'], ['edit', 'show']) === true) {
?>
</div>
<div class="col-md-6"></div>
<div class="col-md-6">
<?php
echo $this->WebcilForm->input('depot_pia', [
'id' => 'depot_pia',
'options' => [
true => 'Oui',
false => 'Non'
],
'class' => 'transformSelect form-control',
'required' => true,
'empty' => $empty,
'placeholder' => false,
'data-placeholder' => ' '
]);
?>
</div>
</div>
<?php
} else {
echo $this->WebcilForm->hidden('obligation_pia', ['value' => null]);
}
?>
<div class="row">
<div class="col-md-6">
<?php
echo $this->WebcilForm->input('realisation_pia', [
'id' => 'realisation_pia',
'options' => [
true => 'Oui',
false => 'Non'
],
'class' => 'transformSelect form-control',
'required' => true,
'empty' => $empty,
'placeholder' => false,
'data-placeholder' => ' '
]);
?>
</div>
<div class="col-md-6">
<?php
echo $this->WebcilForm->input('depot_pia', [
'id' => 'depot_pia',
'options' => [
true => 'Oui',
false => 'Non'
],
'class' => 'transformSelect form-control',
'required' => true,
'empty' => $empty,
'placeholder' => false,
'data-placeholder' => ' '
]);
?>
</div>
</div>
<?php
$showCoresponsable = true;
if ($formulaireOLD['Formulaire']['oldformulaire'] === true) {
if (empty($responsables)) {
......@@ -510,11 +517,6 @@ if (in_array($this->request->params['action'], ['edit', 'show']) === true) {
$("#descriptionNorme").val(str);
});
var usePIA = <?php echo json_encode($usePIA['Formulaire']['usepia']); ?>;
if (usePIA == true) {
$('#obligation_pia').prop("disabled", true);
}
displayFieldDepotPIA($('#realisation_pia').val());
$('#realisation_pia').change(function () {
var val = $(this).val();
......@@ -527,6 +529,7 @@ if (in_array($this->request->params['action'], ['edit', 'show']) === true) {
if (val == true) {
$('#depot_pia').parent().parent().show();
} else {
$('#depot_pia').val('');
$('#depot_pia').parent().parent().hide();
}
}
......
This diff is collapsed.
<?php
echo $this->Html->script('jquery-mask-plugin/dist/jquery.mask.min.js');
debug($this->validationErrors);
if (isset($this->validationErrors['WebdpoFiche']) && !empty($this->validationErrors['WebdpoFiche'])) {
?>
<div class="alert alert-danger" role="alert">
......
......@@ -145,7 +145,9 @@ $(document).ready(function () {
if ($(this).val() == 'Oui') {
// alert('PIA OBLIGATOIRE');
$('#obligation_pia').val('1');
} else {
}
if ($(this).val() == 'Non') {
// alert('PIA NON OBLIGATOIRE');
$('#obligation_pia').val('0');
}
......@@ -158,12 +160,14 @@ function displayFieldRisque()
if (nbChecked >= 2 ){
$('#traitement_considere_risque').parent().parent().hide();
$('#traitement_considere_risque').val('');
// alert("PIA OBLIGATOIRE");
$('#obligation_pia').val('1');
} else if (nbChecked == 1) {
$('#traitement_considere_risque').parent().parent().show();
} else if (nbChecked == 0) {
$('#traitement_considere_risque').parent().parent().hide();
$('#traitement_considere_risque').val('');
}
}
......@@ -180,14 +184,21 @@ function displayFieldPiaListNotRequired(id, val) {
if (!$('#'+id).parent().parent().next('div').length) {
showListeObligatoire();
}
} else {
// if (val == 'Oui') {
$('#'+id).parent().parent().nextAll('div').hide();
$('#'+id).parent().parent().nextAll('div').children().children().prop('selectedIndex',0);
// On cache
$('#liste_obligatoire').hide();
$('#liste_criteres').hide();
// On reset les valeurs caché
$('.fieldRequiredPia').val('');
$('.fieldListeRequiredPia').val('');
$('input:checkbox[type=checkbox]').attr('checked',false);
$('#traitement_considere_risque').val('');
// alert('PIA non obligatoire');
$('#obligation_pia').val('0');
}
......@@ -209,13 +220,17 @@ function displayFieldPiaListRequired(id, val)
}
} else {
// alert("PIA OBILGATOIRE");
$('#obligation_pia').val('1');
$('#'+id).parent().parent().nextAll('div').hide();
$('#'+id).parent().parent().nextAll('div').children().children().prop('selectedIndex',0);
$('#liste_criteres').hide();
$('.fieldListeRequiredPia').val('');
// alert("PIA OBILGATOIRE");
$('#obligation_pia').val('1');
$('input:checkbox[type=checkbox]').attr('checked',false);
$('#traitement_considere_risque').val('');
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment