Commit fff33c76 authored by Raph El's avatar Raph El
Browse files

Form : amélioration validation form

parent 6b9474f3
...@@ -40,7 +40,10 @@ class IndexAction extends CAction ...@@ -40,7 +40,10 @@ class IndexAction extends CAction
$canEditAnswer = false; $canEditAnswer = false;
$canSeeAnswer = false; $canSeeAnswer = false;
if(empty($mode) || ( $mode != "w" && $mode != "r" ) )
if( empty($mode) || ( $mode != "w" && $mode != "r" ) ||
( !empty($answer["validated"]) && $answer["validated"] == true) )
$mode = "r"; $mode = "r";
if(!empty(Yii::app()->session['userId'])){ if(!empty(Yii::app()->session['userId'])){
......
<?php <?php
class ValidateAction extends CAction class ValidateAction extends CAction
{ {
public function run($id=null, $type=null , $tpl=null) public function run()
{ {
//$controller = $this->getController();
$params = $_POST;
$res = Answer::validate($_POST); $params["controller"] = $this->getController();
Rest::json($_POST); $res = Answer::validate($params);
Rest::json($res);
} }
} }
"organizations" : [
{
"from" : "aressForm1.multitextvalidationaressForm110",
"to" : "name"
},
{
"from" : "aressForm1.multitextvalidationaressForm111",
"to" : "sigle"
},
{
"from" : "aressForm1.multitextvalidationaressForm112",
"to" : "siren"
},
{
"from" : "aressForm1.multitextvalidationaressForm19",
"to" : "email"
},
{
"from" : "aressForm1.multitextvalidationaressForm113",
"to" : "WALDEC_RNA
"
},
{
"from" : "aressForm1.multitextvalidationaressForm113",
"to" : "siren"
}
]
\ No newline at end of file
...@@ -368,45 +368,73 @@ class Answer{ ...@@ -368,45 +368,73 @@ class Answer{
public static function validate($params){ public static function validate($params){
$costum = CacheHelper::getCostum(); $costum = CacheHelper::getCostum();
$set = array(); $set = array();
$res = array('result' => false, "msg" => "Erreur");
if(!empty($params["validated"]) && $params["validated"] === true) if(!empty($params["answerId"]))
$set["validated"] = true; $answer = PHDB::findOneById(Answer::COLLECTION, $params["answerId"]);
if(!empty($params["input"]["generateElement"])){ if(!empty($answer)){
$mapping = array(); if(!empty($params["input"]["validated"]) && ( $params["input"]["validated"] === true || $params["input"]["validated"] === "true" ) )
$import = array( $set["validated"] = true;
'file' => array(json_encode(array($params["answer"]))),
'nameFile' => "test", if(!empty($params["input"]["generateElement"])){
'typeFile' => 'json',
"warnings" => "false"
);
foreach ($params["input"]["generateElement"] as $type => $map) {
$mapping = array(); $mapping = array();
foreach ($map as $k => $v) { $import = array(
$mapping[] =array( 'file' => array(json_encode(array($params["answer"]))),
'idHeadCSV' => $v["from"], 'nameFile' => "test",
'valueAttributeElt' => $v["to"] 'typeFile' => 'json',
); "warnings" => "false"
);
foreach ($params["input"]["generateElement"] as $type => $map) {
$mapping = array();
foreach ($map as $k => $v) {
$mapping[] =array(
'idHeadCSV' => $v["from"],
'valueAttributeElt' => $v["to"]
);
}
$import['infoCreateData'] = $mapping;
$import['typeElement'] = $type;
//Rest::json($import); exit;
$resImport = Import::previewData($import, true, true, true);
//Rest::json($resImport); exit;
foreach ($resImport["elementsObj"] as $keyElt => $elt) {
$elt = Import::checkElement($elt, $type);
if(!empty($elt["msgError"]))
unset($elt["msgError"]);
$elt["collection"] = $type;
$elt["key"] = $type;
if(Costum::isSameFunction("generateElementBeforeSave")){
$elt = Costum::sameFunction("generateElementBeforeSave", $elt);
}
$save = Element::save($elt);
//Rest::json($save); exit;
Link::connect($save["id"], $type, $params["answerId"], Answer::COLLECTION, Yii::app()->session["userId"], "answers",false,false,false,false);
Link::connect($params["answerId"], Answer::COLLECTION, $save["id"], $type, Yii::app()->session["userId"], $type,false,false,false,false);
}
$res = array('result' => true, "msg" => "Valider");
//Rest::json($resImport); exit;
} }
$import['infoCreateData'] = $mapping;
$import['typeElement'] = $type;
$resImport = Import::previewData($import, true, true, true);
Rest::json($resImport); exit;
} }
}
if(Costum::isSameFunction("answerValidate")){ if(Costum::isSameFunction("answerValidate")){
$paramBeforeValidate = Costum::sameFunction("answerValidate", $params); $paramBeforeValidate = Costum::sameFunction("answerValidate", $params);
} }
if(!empty($set)){
PHDB::update(Answer::COLLECTION,
array( "_id" => new MongoId((string)$params["answerId"])),
array( '$set' => $set ) );
if(!empty($set)){ $res = array('result' => true, "msg" => "Valider");
PHDB::update(Answer::COLLECTION, }
array( "_id" => new MongoId((string)$params["answerId"])),
array( '$set' => $set ) );
$res = array('result' => true, "msg" => "Valider"); if($res["result"] === true){
$res["html"] = $params["controller"]->renderPartial('survey.views.tpls.forms.finish', $res, true);
}
} }
return $res; return $res;
......
<?php <?php
if($mode != "pdf"){ if($mode != "pdf"){
var_dump($input); //var_dump($input);
?> ?>
<div class=""> <div class="">
<label for="validation<?php echo $kunik ?>"><h4 style="color:<?php echo ($titleColor) ? $titleColor : "black"; ?>"><?php echo $label.$editQuestionBtn ?></h4></label> <label for="validation<?php echo $kunik ?>"><h4 style="color:<?php echo ($titleColor) ? $titleColor : "black"; ?>"><?php echo $label.$editQuestionBtn ?></h4></label>
...@@ -17,7 +17,6 @@ if($mode != "pdf"){ ...@@ -17,7 +17,6 @@ if($mode != "pdf"){
$("#question<?php echo $key ?> #validation<?php echo $kunik ?>").off().click(function(){ $("#question<?php echo $key ?> #validation<?php echo $kunik ?>").off().click(function(){
var paramsValidate = { var paramsValidate = {
answerId : answerId, answerId : answerId,
answer : answerObj.answers,
input : paramsInput input : paramsInput
}; };
...@@ -26,7 +25,9 @@ if($mode != "pdf"){ ...@@ -26,7 +25,9 @@ if($mode != "pdf"){
baseUrl+"/survey/answer/validate", baseUrl+"/survey/answer/validate",
paramsValidate, paramsValidate,
function(data){ function(data){
toastr.success("Le formulaire à été soumis"); toastr.success("Le formulaire à été soumis");
if(typeof data.html != "undefined")
$("#customHeader").html(data.html);
}, },
function(data){ function(data){
toastr.error("Un soucis est apparue. Contacter l'administrateur"); toastr.error("Un soucis est apparue. Contacter l'administrateur");
......
<div class="col-xs-12 text-center padding-20 margin-top-10">
<h4>Félicitation!!! Vous avez terminé le formulaire.</h4>
<br/>
<h4>Celui-ci sera traité dans les plus bref délai.</h4>
</div>
\ No newline at end of file
...@@ -145,7 +145,7 @@ if(isset($this->costum["cms"]["color1"])) ...@@ -145,7 +145,7 @@ if(isset($this->costum["cms"]["color1"]))
<div class="col-xs-12 margin-top-20"> <div class="col-xs-12 margin-top-20">
<?php <?php
$wizardUid = (String) $form["_id"]; $wizardUid = (String) $form["_id"];
if($canEdit === true && $mode != "fa"){ if($canEdit === true && $mode != "fa" && empty($answer["validated"]) ){
$nameMode = "mode read"; $nameMode = "mode read";
if($mode == "w") if($mode == "w")
$nameMode = "mode write"; $nameMode = "mode write";
......
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