Commit 8d546635 authored by FloBen's avatar FloBen
Browse files

amelio et fix deal
parent a3135740
<?php
$nbAnswer = (isset($answer["answers"][$form["id"]]["deal404"])) ? count($answer["answers"][$form["id"]]["deal404"]) : 0 ;
$nbAns=(isset($answer["answers"]["deal3"]["deal36"])) ? count($answer["answers"]["deal3"]["deal36"]) : 0;
$refused=null;
if(isset($answer["answers"][$form["id"]]["deal404"])){
$refused = 0;
foreach ($answer["answers"][$form["id"]]["deal404"] as $fin => $ans) {
if(in_array("refused", $ans)){
$refused ++;
}
}
}
$reloadIn = "";
foreach ($form["inputs"] as $keyfI => $valuefI) {
if ($valuefI["type"] == "tpls.forms.costum.deal.validateStep") {
$reloadIn = $keyfI;
}
}
?>
<script type="text/javascript">
$("form :input").on('blur', function() {
mylog.log("aaaaaaaa");
reloadInput("<?php echo $key ?>", "<?php echo (string)$form["_id"] ?>");
});
$(document).ready(function() {
var tplCtx = {};
<?php
if(empty($answers && isset($refused))){ ?>
// alert("pas vide");
<?php if ($nbAnswer==$nbAns && $refused==0) {
?> // alert("égale");
tplCtx.value = "validée";
$.when(validateNumberInput<?php echo $kunik ?>()).then(
reloadInput("<?php echo $reloadIn ?>", "<?php echo (string)$form["_id"] ?>")
);
<?php
} else if($refused>0){ ?>
alert("Un financeur a refusé l'attribution d'une subvention. Le dossier est donc pour le moment en suspens.");
<?php } ?>
// }
// else{
// alert("pas égale");
// tplCtx.value = "";
// $.when(validateNumberInput<?php echo $kunik ?>()).then(
// reloadInput("<?php echo $reloadIn ?>", "<?php echo (string)$form["_id"] ?>")
// );
<?php
// }
}
?>
function validateNumberInput<?php echo $kunik ?>() {
tplCtx.id = "<?php echo $answer["_id"] ?>";
tplCtx.path = "<?php echo "answers.".$form["id"].".".$key ?>";
tplCtx.collection = "<?php echo Form::ANSWER_COLLECTION ?>";
mylog.log("validateNumberdeal4",tplCtx);
dataHelper.path2Value( tplCtx, function(params) {
reloadInput("<?php echo $key ?>", "<?php echo (string)$form["_id"] ?>");
} );
};
});
</script>
\ No newline at end of file
<?php
$nbAnswer = (isset($answer["answers"][$form["id"]]["deal404"])) ? count($answer["answers"][$form["id"]]["deal404"]) : 0 ;
$nbAns=(isset($answer["answers"]["deal3"]["deal36"])) ? count($answer["answers"]["deal3"]["deal36"]) : 0;
$refused=null;
if(isset($answer["answers"][$form["id"]]["deal404"])){
$refused = 0;
foreach ($answer["answers"][$form["id"]]["deal404"] as $fin => $ans) {
if(in_array("refused", $ans)){
$refused ++;
}
}
$formList = [];
$paramsData = [
"sign" => "",
"one" => "",
"two" => "",
"oneValue" => "",
"twoValue" => ""
];
$sign = [
"more" => "N1 > N2",
"moreEqual" => "N1 >= N2",
"less" => "N1 < N2",
"lessEqual" => "N1 <= N2",
"equal" => "N1 = N2"
];
$editParamsBtn = ($canEditForm and $mode != "r" || $mode != "pdf") ? "Comparateur <a href='javascript:;' data-id='".$parentForm["_id"]."' data-collection='".Form::COLLECTION."' data-path='params.".$kunik."' class='previewTpl edit".$kunik."Params btn btn-xs btn-danger'><i class='fa fa-cog'></i> </a>" : "";
if( isset($parentForm["params"][$kunik]["sign"]) ){
$paramsData["sign"] = $parentForm["params"][$kunik]["sign"];
}
if( isset($parentForm["params"][$kunik]["one"]) ){
$paramsData["one"] = $parentForm["params"][$kunik]["one"];
if (isset($answer["answers"][$form["id"]])) {
foreach ($answer["answers"][$form["id"]] as $kAns => $vAns) {
// var_dump("(",$kAns,")");
// var_dump(is_numeric($vAns));
if(strpos($kAns, $parentForm["params"][$kunik]["one"]) !== false && is_numeric($vAns) ){
$paramsData["oneValue"] = (int)$vAns;
}
}
}
}
if( isset($parentForm["params"][$kunik]["two"]) ){
$paramsData["two"] = $parentForm["params"][$kunik]["two"];
if (isset($answer["answers"][$form["id"]])) {
foreach ($answer["answers"][$form["id"]] as $kAns => $vAns) {
if(strpos($kAns, $parentForm["params"][$kunik]["two"]) !== false && is_numeric($vAns) ){
$paramsData["twoValue"] = (int)$vAns;
}
}
}
}
if (isset($form)) {
foreach ($form["inputs"] as $fid => $fvalue) {
if ($fid != $key) {
$formList[$fid] = $fvalue["label"];
}
}
}
function isValid($sign,$oneV,$twoV){
if ($sign == "more" && $oneV > $twoV) {
return true;
} elseif ($sign == "moreEqual" && $oneV >= $twoV) {
return true;
} elseif ($sign == "less" && $oneV < $twoV) {
return true;
} elseif ($sign == "lessEqual" && $oneV <= $twoV) {
return true;
}
return false;
}
echo $editParamsBtn;
$reloadIn = "";
foreach ($form["inputs"] as $keyfI => $valuefI) {
if ($valuefI["type"] == "tpls.forms.cplx.validateStep") {
if ($valuefI["type"] == "tpls.forms.costum.deal.validateStep") {
$reloadIn = $keyfI;
}
}
?>
<script type="text/javascript">
<script type="text/javascript">
var <?php echo $kunik ?>Data = <?php echo json_encode( (isset($answers)) ? $answers : null ); ?>;
sectionDyf.<?php echo $kunik ?>ParamsData = <?php echo json_encode( $paramsData ); ?>;
$("form :input").on('blur', function() {
mylog.log("aaaaaaaa");
reloadInput("<?php echo $key ?>", "<?php echo (string)$form["_id"] ?>");
......@@ -31,45 +97,85 @@ $refused=null;
$(document).ready(function() {
var tplCtx = {};
<?php
if(empty($answers && isset($refused))){ ?>
// alert("pas vide");
<?php if ($nbAnswer==$nbAns && $refused==0) {
?> // alert("égale");
tplCtx.value = "validée";
<?php
if ($paramsData["sign"] != "" && $paramsData["one"] != "" && $paramsData["two"] != "" && $paramsData["oneValue"] != "" && $paramsData["twoValue"] != "" && $answers == null && isValid($paramsData["sign"], $paramsData["oneValue"],$paramsData["twoValue"]) && $reloadIn != "") {
?>
$.when(validateNumberInput<?php echo $kunik ?>()).then(
reloadInput("<?php echo $reloadIn ?>", "<?php echo (string)$form["_id"] ?>")
);
<?php
} else if($refused>0){ ?>
alert("Un financeur a refusé l'attribution d'une subvention. Le dossier est donc pour le moment en suspens.");
<?php } ?>
// }
// else{
}
?>
// alert("pas égale");
// tplCtx.value = "";
// $.when(validateNumberInput<?php echo $kunik ?>()).then(
// reloadInput("<?php echo $reloadIn ?>", "<?php echo (string)$form["_id"] ?>")
// );
<?php
// }
}
?>
sectionDyf.<?php echo $kunik ?>Params = {
"jsonSchema" : {
"title" : "<?php echo $kunik ?> config",
"description" : "Liste de question possible",
"icon" : "fa-cog",
"properties" : {
sign : {
inputType : "select",
label : "Fonction",
options : <?php echo json_encode($sign) ?>,
values : sectionDyf.<?php echo $kunik ?>ParamsData.sign
},
one : {
inputType : "select",
label : "N1",
options : <?php echo json_encode($formList) ?>,
values : sectionDyf.<?php echo $kunik ?>ParamsData.one
},
two : {
inputType : "select",
label : "N2",
options : <?php echo json_encode($formList) ?>,
values : sectionDyf.<?php echo $kunik ?>ParamsData.two
}
},
save : function () {
tplCtx.value = {};
$.each( sectionDyf.<?php echo $kunik ?>Params.jsonSchema.properties , function(k,val) {
if(val.inputType == "properties")
tplCtx.value[k] = getPairsObj('.'+k+val.inputType);
else if(val.inputType == "array")
tplCtx.value[k] = getArray('.'+k+val.inputType);
else
tplCtx.value[k] = $("#"+k).val();
mylog.log("value",'.'+k+val.inputType,tplCtx.value[k]);
});
mylog.log("save tplCtx",tplCtx);
if(typeof tplCtx.value == "undefined"){
toastr.error('value cannot be empty!');
}
else {
dataHelper.path2Value( tplCtx, function(params) {
dyFObj.closeForm();
urlCtrl.loadByHash(location.hash);
} );
}
}
}
};
$(".edit<?php echo $kunik ?>Params").off().on("click",function() {
tplCtx.id = $(this).data("id");
tplCtx.collection = $(this).data("collection");
tplCtx.path = $(this).data("path");
dyFObj.openForm( sectionDyf.<?php echo $kunik ?>Params,null, sectionDyf.<?php echo $kunik ?>ParamsData);
});
function validateNumberInput<?php echo $kunik ?>() {
tplCtx.id = "<?php echo $answer["_id"] ?>";
tplCtx.path = "<?php echo "answers.".$form["id"].".".$key ?>";
tplCtx.collection = "<?php echo Form::ANSWER_COLLECTION ?>";
mylog.log("validateNumberdeal4",tplCtx);
tplCtx = {};
tplCtx.id = "<?php echo $answer["_id"] ?>",
tplCtx.path = "<?php echo "answers.".$form["id"].".".$key ?>",
tplCtx.collection = "<?php echo Form::ANSWER_COLLECTION ?>";
tplCtx.value = "validée";
dataHelper.path2Value( tplCtx, function(params) {
reloadInput("<?php echo $key ?>", "<?php echo (string)$form["_id"] ?>");
} );
......
<style type="text/css">
.checkedvalue{
color: #00C851;
}
.timesvalue{
color: #ff4444;
}
.tovalidatelist{
list-style: none;
}
.gotoinput-btn{
border: 2px solid #0099CC;
border-radius: 5px;
font-size: 15px;
background-color: transparent;
cursor: pointer;
padding: 2px;
margin: 2px;
}
.inputList{
display: flow-root;
}
</style>
<?php
$isValidate = false;
$formList = [];
$stepList = [];
$lastForm = false;
$ischecked= [];
if (isset($parentForm["subForms"])) {
foreach ($parentForm["subForms"] as $keysF => $valuesF) {
$stepList[$valuesF] = $valuesF;
$lastSubForm = $valuesF;
}
}else{
$lastForm = true;
}
if ($form["id"] == $lastSubForm) {
$lastForm = true;
}
if (isset($form)) {
foreach ($form["inputs"] as $fid => $fvalue) {
if ($fid != $key) {
$formList[$fid] = $fvalue["label"];
}
}
}
if (isset($answers) && !is_null($answers) && !empty($answers)) {
$isValidate = true;
}
$canValidate = false;
$alreadyChecked = 0;
$inputListOptions = [];
$comV = [];
//var_dump($canEditForm);
$editParamsBtn = ($canEditForm=="true" && ($mode != "r" || $mode != "pdf")) ? " <a href='javascript:;' data-id='".$parentForm["_id"]."' data-collection='".Form::COLLECTION."' data-path='params.".$kunik."' class='previewTpl edit".$kunik."Params btn btn-xs btn-danger'><i class='fa fa-cog'></i> </a>" : "";
$contactType = [
"Partenaire"=>"Partenaire",
"Financeur" => "Financeur",
"Opérateur"=>"Opérateur",
"Répondant"=>"Répondant",
"OpérateurValidated"=>"Opérateur validé",
"customInput" => "Réponse d'une question"
];
foreach ($form["inputs"] as $forminputskey => $forminputsvalue) {
if (isset($forminputsvalue["label"])) {
$inputListOptions[$forminputskey] = $forminputsvalue["label"];
}
}
if (isset($answer["links"]["operators"])) {
$operateurVid = $answer["links"]["operators"];
foreach ($operateurVid as $vkey => $vvalue) {
$comV = Element::getCommunityByTypeAndId("organizations", $vkey);
}
}
$selectedContact = array("roles"=>array());
if( isset($parentForm["params"][$kunik]["contact"]) ){
if (is_array($parentForm["params"][$kunik]["contact"]) && in_array("Financeur", $parentForm["params"][$kunik]["contact"]) ) {
array_push($selectedContact["roles"], "Financeur");
}
if (is_array($parentForm["params"][$kunik]["contact"]) && in_array("Opérateur", $parentForm["params"][$kunik]["contact"])) {
array_push($selectedContact["roles"], "Opérateur");
}
}
$paramsData = [
"inputList" => [],
"step" => "",
"contact" => [],
"object" => "",
"msg" => "",
"msgbox" => "",
"notif" => "",
"urlRedirect" => ""
];
if( isset($parentForm["params"][$kunik]["inputList"]) && !empty($parentForm["params"][$kunik]["inputList"])){
$paramsData["inputList"] = $parentForm["params"][$kunik]["inputList"];
}
if( isset($parentForm["params"][$kunik]["step"]) ){
$paramsData["step"] = $parentForm["params"][$kunik]["step"];
}
if( isset($parentForm["params"][$kunik]["object"]) ){
$paramsData["object"] = $parentForm["params"][$kunik]["object"];
}
if( isset($parentForm["params"][$kunik]["msg"]) ){
$paramsData["msg"] = $parentForm["params"][$kunik]["msg"];
}
if( isset($parentForm["params"][$kunik]["msgbox"]) ){
$paramsData["msgbox"] = $parentForm["params"][$kunik]["msgbox"];
}
if( isset($parentForm["params"][$kunik]["notif"]) ){
$paramsData["notif"] = $parentForm["params"][$kunik]["notif"];
}
if( isset($parentForm["params"][$kunik]["contact"]) ){
$paramsData["contact"] = $parentForm["params"][$kunik]["contact"];
}
if( isset($parentForm["params"][$kunik]["urlRedirect"]) ){
$paramsData["urlRedirect"] = $parentForm["params"][$kunik]["urlRedirect"];
}
$totalToChecked = sizeof($paramsData["inputList"]);
// var_dump($totalToChecked);
// var_dump($paramsData["inputList"]);exit;
if($totalToChecked > 0){
// var_dump($paramsData["inputList"]);exit;
foreach ($paramsData["inputList"] as $inid => $invalue) {
if ($alreadyChecked < $totalToChecked && isset($answer["answers"][$form["id"]])) {
foreach ($answer["answers"][$form["id"]] as $kAns => $vAns) {
if(strpos($kAns, $invalue) !== false){
$alreadyChecked++;
array_push($ischecked, $invalue);
}
}
}
}
}
$message = "Veuillez remplir les champs obligatoires pour passer à l'etape suivante";
$message .= "<div class='tovalidatelist'>";
if (!empty($parentForm["params"][$kunik]["inputList"])) {
foreach ($parentForm["params"][$kunik]["inputList"] as $keysF => $valuesF) {
$message .="<div class='inputList'>";
if (in_array($valuesF, $ischecked)) {
$message .= "<span class='checkedvalue'>";
} else {
$message .= "<span class='timesvalue'>";
}
$message .= $formList[$valuesF];
if (in_array($valuesF, $ischecked)) {
$message .= '</span><i class="fa fa-check-circle checkedvalue pull-left success" aria-hidden="true"></i>';
} else {
$message .= '</span><i class="fa fa-times-circle timesvalue pull-left" aria-hidden="true"></i>';
}
$message .='<a data-path="question'.$valuesF.'" class="gotoinput-btn pull-right">s\'y rendre</a></div>';
}
}
$message .= "</div>";
if ($paramsData['step'] == "") {
$paramsData['step'] = $form['id'];
}
if (($totalToChecked == $alreadyChecked) || (!isset($parentForm["params"][$kunik]["inputList"]) or (isset($parentForm["params"][$kunik]["inputList"]) && sizeof($parentForm["params"][$kunik]["inputList"]) == 0)) || (isset($answers) && $answers == "canValidate")) {
$canValidate = true;
}
if ($isValidate) {
$canValidate = false;
$message = (isset($parentForm["params"][$kunik]["msgbox"]) && $parentForm["params"][$kunik]["msgbox"] != "") ? $parentForm["params"][$kunik]["msgbox"] : "Cette étape a été validée le ".$answers;
}
$hasUserEmail = false;
$userEmail = "";
$costum = CacheHelper::getCostum();
if(in_array("Financeur",Yii::app()->session["costum"][$costum["slug"]]["hasRoles"]) || in_array("Opérateur",Yii::app()->session["costum"][$costum["slug"]]["hasRoles"])){
$userEmail = (isset($answer["answers"]["deal1"]["deal125"])) ? $answer["answers"]["deal1"]["deal125"] : "" ;
}else if(isset(Yii::app()->session["userEmail"])){
$hasUserEmail = true;
$userEmail = Yii::app()->session["userEmail"];
}
?>
<?php if(!$lastForm){?>
<div style="border: 2px solid darkgrey;padding: 20px;border-radius: 20px; overflow-x: auto; text-align: center" class="step-vld">
<?php if(!$isValidate && $canValidate){
?>
<button type="button" class="btn validate<?php echo $kunik ?>Params" >Passer à l'étape suivante</button>
<?php } else { echo $message; } echo $editParamsBtn?>
</div>
<?php } elseif ($lastForm) { ?>
<div style="border: 2px solid darkgrey;padding: 20px;border-radius: 20px; overflow-x: auto; text-align: center" class="step-vld">
<?php if(!$isValidate && $canValidate){ ?>
<button type="button" class="btn validate<?php echo $kunik ?>Params" >Terminer</button>
<?php } else { echo $message; } echo $editParamsBtn?>
</div>
<?php }
$mustSendMail = [];
$mailList =[];
if (isset($parentForm["params"][$kunik]["contact"]) && is_array($parentForm["params"][$kunik]["contact"])) {
if (is_array($parentForm["params"][$kunik]["contact"]) && !empty($parentForm["params"][$kunik]["contact"])) {
if(in_array("Répondant", $parentForm["params"][$kunik]["contact"])){
array_push($mailList, $userEmail);
}
}
if(in_array("OpérateurValidated", $parentForm["params"][$kunik]["contact"]) && isset($comV)){
foreach ($comV as $keypers => $valuepers) {
if ($valuepers["type"] == "citoyens") {
array_push($mustSendMail, $keypers);
}
}
}
if(in_array("Opérateur", $parentForm["params"][$kunik]["contact"]) || in_array("Financeur", $parentForm["params"][$kunik]["contact"])){
foreach ($this->costum["communityLinks"] as $comkey => $comvalue) {
foreach ($comvalue as $ke => $valu) {
if (isset($valu["roles"])) {
if (in_array("Opérateur", $parentForm["params"][$kunik]["contact"]) && in_array("Opérateur", $valu["roles"])) {
array_push($mustSendMail, $ke);
}
if (in_array("Financeur", $parentForm["params"][$kunik]["contact"]) && in_array("Financeur", $valu["roles"])) {
array_push($mustSendMail, $ke);
}
}
}
}
}
if(in_array("customInput", $parentForm["params"][$kunik]["contact"]) && isset($parentForm["params"][$kunik]["inputscontact"])){
foreach ($parentForm["params"][$kunik]["inputscontact"] as $inputscontactkey => $inputscontactvalue) {
if (isset($answer["answers"][$form["id"]][$inputscontactvalue])) {
array_push($mailList, $answer["answers"][$form["id"]][$inputscontactvalue]);
}
}
}