Commit fff33c76 authored by Raph El's avatar Raph El

Form : amélioration validation form

parent 6b9474f3
......@@ -40,7 +40,10 @@ class IndexAction extends CAction
$canEditAnswer = 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";
if(!empty(Yii::app()->session['userId'])){
......
<?php
class ValidateAction extends CAction
{
public function run($id=null, $type=null , $tpl=null)
public function run()
{
$res = Answer::validate($_POST);
Rest::json($_POST);
//$controller = $this->getController();
$params = $_POST;
$params["controller"] = $this->getController();
$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{
public static function validate($params){
$costum = CacheHelper::getCostum();
$set = array();
if(!empty($params["validated"]) && $params["validated"] === true)
$set["validated"] = true;
$res = array('result' => false, "msg" => "Erreur");
if(!empty($params["answerId"]))
$answer = PHDB::findOneById(Answer::COLLECTION, $params["answerId"]);
if(!empty($params["input"]["generateElement"])){
$mapping = array();
$import = array(
'file' => array(json_encode(array($params["answer"]))),
'nameFile' => "test",
'typeFile' => 'json',
"warnings" => "false"
);
foreach ($params["input"]["generateElement"] as $type => $map) {
if(!empty($answer)){
if(!empty($params["input"]["validated"]) && ( $params["input"]["validated"] === true || $params["input"]["validated"] === "true" ) )
$set["validated"] = true;
if(!empty($params["input"]["generateElement"])){
$mapping = array();
foreach ($map as $k => $v) {
$mapping[] =array(
'idHeadCSV' => $v["from"],
'valueAttributeElt' => $v["to"]
);
$import = array(
'file' => array(json_encode(array($params["answer"]))),
'nameFile' => "test",
'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")){
$paramBeforeValidate = Costum::sameFunction("answerValidate", $params);
}
if(Costum::isSameFunction("answerValidate")){
$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)){
PHDB::update(Answer::COLLECTION,
array( "_id" => new MongoId((string)$params["answerId"])),
array( '$set' => $set ) );
$res = array('result' => true, "msg" => "Valider");
}
$res = array('result' => true, "msg" => "Valider");
if($res["result"] === true){
$res["html"] = $params["controller"]->renderPartial('survey.views.tpls.forms.finish', $res, true);
}
}
return $res;
......
<?php
if($mode != "pdf"){
var_dump($input);
//var_dump($input);
?>
<div class="">
<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"){
$("#question<?php echo $key ?> #validation<?php echo $kunik ?>").off().click(function(){
var paramsValidate = {
answerId : answerId,
answer : answerObj.answers,
input : paramsInput
};
......@@ -26,7 +25,9 @@ if($mode != "pdf"){
baseUrl+"/survey/answer/validate",
paramsValidate,
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){
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"]))
<div class="col-xs-12 margin-top-20">
<?php
$wizardUid = (String) $form["_id"];
if($canEdit === true && $mode != "fa"){
if($canEdit === true && $mode != "fa" && empty($answer["validated"]) ){
$nameMode = "mode read";
if($mode == "w")
$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