Commit 544ed60f authored by Clément Damiens's avatar Clément Damiens
Browse files

Merge remote-tracking branch 'origin/development' into development

parents 114be7c5 ee45e6cd
......@@ -660,22 +660,25 @@ class Form {
$budgetInputList = [];
$allforms = [];
$stockBudgetInputs = false;
foreach ($params["formList"] as $i => $formId)
{
$f = PHDB::findOne(Form::COLLECTION, ["id"=>$formId]);
$allforms[$formId] = $f;
foreach ($f["inputs"] as $key => $inp)
{
if( in_array($inp["type"], ["tpls.forms.cplx.budget"] ) )
$budgetInputList[$formId.".".$key] = $formId.".".$key;
if( in_array($inp["type"], [
"tpls.forms.cplx.tpls.forms.cplx.financementFromBudget",
"tpls.forms.cplx.tpls.forms.cplx.suiviFromBudget",
"tpls.forms.cplx.tpls.forms.cplx.decideFromBudget"] ) )
$stockBudgetInputs = true;
}
}
if(!empty($params["formList"])){
foreach ($params["formList"] as $i => $formId)
{
$f = PHDB::findOne(Form::COLLECTION, ["id"=>$formId]);
$allforms[$formId] = $f;
foreach ($f["inputs"] as $key => $inp)
{
if( in_array($inp["type"], ["tpls.forms.cplx.budget"] ) )
$budgetInputList[$formId.".".$key] = $formId.".".$key;
if( in_array($inp["type"], [
"tpls.forms.cplx.tpls.forms.cplx.financementFromBudget",
"tpls.forms.cplx.tpls.forms.cplx.suiviFromBudget",
"tpls.forms.cplx.tpls.forms.cplx.decideFromBudget"] ) )
$stockBudgetInputs = true;
}
}
}
if(count($budgetInputList))
Yii::app()->session["budgetInputList"] = $budgetInputList;
//var_dump($budgetInputList);
......@@ -743,91 +746,95 @@ class Form {
$showForm = true;
$myAnswers = self::getListAnswersBy($params["formId"], $params["el"]["slug"], Yii::app()->session["userId"]);
if(!empty($params["formId"])){
$myAnswers = self::getListAnswersBy($params["formId"], $params["el"]["slug"], Yii::app()->session["userId"]);
if(!isset($costum["form"]["oneAnswerPerPerson"]) || count($myAnswers) == 0){
//si ya qu'une réponse et on la charge directe
if(count($myAnswers) == 1 )
$answer = $myAnswers[ array_keys($myAnswers)[0] ];
else {
//sinon on cherche la reponse incomplete
foreach ($myAnswers as $id => $ans)
{
//chercher les reponse incomplete
if(!isset( $ans["answers"]) && $answer == null )
$answer = $ans;
}
}
if( $answer == null && count( $myAnswers ) > 1 && !$params["canEdit"] )
$showForm = false;
//si aucune reponse existe
//et qu'on a des input complexe alors on génere une answer
// if( !isset($_GET['answer']) && $answer == null ){
// if(isset($params["formList"])){
// $generateAnswer = true;
// }
// else if(isset($form["inputs"])){
// foreach ($form["inputs"] as $key => $inp)
// {
// if( stripos( $inp["type"] , "tpls.forms.cplx" ) !== false )
// $generateAnswer = true;
// }
// }
// }
// if( isset($answerId) && $answerId == "new" )
// $generateAnswer = true;
//on pré genere un anwser que quand il n'y en pas
//pour permettre le save onBlur , ou s'il y a des cplx forms
//il ne peut y avoir qu'un seul answer en cours simultanement
//on pré genere un anwser que quand il n'y en pas
//pour permettre le save onBlur , ou s'il y a des cplx forms
//il ne peut y avoir qu'un seul answer en cours simultanement
///TODO purger ANSwers via CRON
// if( $generateAnswer )
// {
// //var_dump("create new" );
// $ans = [
// "formId" => $params["formId"],
// "user" => Yii::app()->session["userId"],
// "parentSlug" => $params["el"]["slug"],
// "links"=>[
// "answered" => [ Yii::app()->session["userId"] ] ,
// //proposed ,particpated,decision,financed,financed,referenced,commented,worked,payed,tested,validated
// //each actor is connectable to his activitystream
// ],
// "created" => time()
// ];
// if(isset($params["formList"]))
// $ans["formList"] = count($params["formList"]);
// PHDB::insert(Form::ANSWER_COLLECTION, $ans);
// $answer = PHDB::findOne( Form::ANSWER_COLLECTION, [ "_id" => new MongoId($ans["_id"]) ] );
// }
// var_dump($params["el"]["slug"] );
// var_dump($params["formId"] );
// var_dump($answer );
// var_dump(Yii::app()->getRequest()->getQuery('answer'));
// exit;
$params["answer"] = $answer;
$params["showForm"] = $showForm;
$params["showAnswerActions"]=(isset($params["showAnswerActions"])) ? $params["showAnswerActions"] : true;
$allAnswers = self::getListAnswersBy($params["formId"], $params["el"]["slug"] ) ;
$params["allAnswers"] = (isset($allAnswers)) ? $allAnswers : [] ;
//var_dump($params["el"]["slug"]);exit;
//var_dump($params["allAnswers"]);exit;
} else {
echo "<h4 class='text-center text-red'><i class='fa fa-warning'></i> Une seul réponse n'est possible.</h4>";
echo "<a class='btn btn-primary' href='/costum/co/index/slug/".$el["slug"]."/answer/".$myAnswers[0]."'>Votre réponse</a>";
if(!isset($costum["form"]["oneAnswerPerPerson"]) || count($myAnswers) == 0){
//si ya qu'une réponse et on la charge directe
if(count($myAnswers) == 1 )
$answer = $myAnswers[ array_keys($myAnswers)[0] ];
else {
//sinon on cherche la reponse incomplete
foreach ($myAnswers as $id => $ans)
{
//chercher les reponse incomplete
if(!isset( $ans["answers"]) && $answer == null )
$answer = $ans;
}
}
if( $answer == null && count( $myAnswers ) > 1 && !$params["canEdit"] )
$showForm = false;
//si aucune reponse existe
//et qu'on a des input complexe alors on génere une answer
// if( !isset($_GET['answer']) && $answer == null ){
// if(isset($params["formList"])){
// $generateAnswer = true;
// }
// else if(isset($form["inputs"])){
// foreach ($form["inputs"] as $key => $inp)
// {
// if( stripos( $inp["type"] , "tpls.forms.cplx" ) !== false )
// $generateAnswer = true;
// }
// }
// }
// if( isset($answerId) && $answerId == "new" )
// $generateAnswer = true;
//on pré genere un anwser que quand il n'y en pas
//pour permettre le save onBlur , ou s'il y a des cplx forms
//il ne peut y avoir qu'un seul answer en cours simultanement
//on pré genere un anwser que quand il n'y en pas
//pour permettre le save onBlur , ou s'il y a des cplx forms
//il ne peut y avoir qu'un seul answer en cours simultanement
///TODO purger ANSwers via CRON
// if( $generateAnswer )
// {
// //var_dump("create new" );
// $ans = [
// "formId" => $params["formId"],
// "user" => Yii::app()->session["userId"],
// "parentSlug" => $params["el"]["slug"],
// "links"=>[
// "answered" => [ Yii::app()->session["userId"] ] ,
// //proposed ,particpated,decision,financed,financed,referenced,commented,worked,payed,tested,validated
// //each actor is connectable to his activitystream
// ],
// "created" => time()
// ];
// if(isset($params["formList"]))
// $ans["formList"] = count($params["formList"]);
// PHDB::insert(Form::ANSWER_COLLECTION, $ans);
// $answer = PHDB::findOne( Form::ANSWER_COLLECTION, [ "_id" => new MongoId($ans["_id"]) ] );
// }
// var_dump($params["el"]["slug"] );
// var_dump($params["formId"] );
// var_dump($answer );
// var_dump(Yii::app()->getRequest()->getQuery('answer'));
// exit;
$params["answer"] = $answer;
$params["showForm"] = $showForm;
$params["showAnswerActions"]=(isset($params["showAnswerActions"])) ? $params["showAnswerActions"] : true;
$allAnswers = self::getListAnswersBy($params["formId"], $params["el"]["slug"] ) ;
$params["allAnswers"] = (isset($allAnswers)) ? $allAnswers : [] ;
//var_dump($params["el"]["slug"]);exit;
//var_dump($params["allAnswers"]);exit;
} else {
echo "<h4 class='text-center text-red'><i class='fa fa-warning'></i> Une seul réponse n'est possible.</h4>";
echo "<a class='btn btn-primary' href='/costum/co/index/slug/".$el["slug"]."/answer/".$myAnswers[0]."'>Votre réponse</a>";
}
}
}
return $params;
}
......
......@@ -6,32 +6,37 @@ else if(!empty($answer) && isset($answer["answers"][$kunik]) && $answer["answers
$value = "checked";
$inpClass = "";
if($saveOneByOne)
$inpClass = " saveOneByOne";
if($mode == "r"){ ?>
if($mode == "r" || $mode == "pdf"){ ?>
<div class="col-xs-12" id="<?php echo $kunik ?>">
<label for="<?php echo $kunik ?>"><h4 style="color:<?php echo ($titleColor) ? $titleColor : "black"; ?>"><?php echo $label ?></h4></label>
<?php
echo @$form["inputs"][$key]["placeholder"]." : ".(!empty($value) ? "Yes" : "No");
?>
<label for="<?php echo $kunik ?>"><h4 style="color:<?php echo ($titleColor) ? $titleColor : "black"; ?>"><?php echo $label ?></h4></label><br/>
<?php echo @$form["inputs"][$key]["placeholder"]." : ".(!empty($value) ? "Yes" : "No"); ?>
</div>
<?php
}else{
?>
<div class="form-check">
<label class="form-check-label" for="<?php echo $kunik ?>"><h4 style="color:<?php echo ($titleColor) ? $titleColor : "black"; ?>"><?php echo $label.$editQuestionBtn ?></h4></label>
<label class="form-check-label" for="<?php echo $kunik ?>"><h4 style="color:<?php echo ($titleColor) ? $titleColor : "black"; ?>"><?php echo $label.$editQuestionBtn ?></h4></label>
<br/>
<input type="checkbox" class="form-check-input <?php echo $inpClass ?>" id="<?php echo $kunik ?>" data-form='<?php echo $form["id"] ?>' <?php echo $value ?> > <?php echo @$form["inputs"][$key]["placeholder"]?>
<?php if(!empty($info)){ ?>
<small id="<?php echo $key ?>Help" class="form-text text-muted"><?php echo $info ?></small>
<?php } ?>
</div>
<script type="text/javascript">
<?php } ?>
<?php if($mode != "pdf"){ ?>
<script type="text/javascript">
jQuery(document).ready(function() {
mylog.log("render form input","/modules/costum/views/tpls/forms/checkbox.php");
});
</script>
</script>
<?php } ?>
\ No newline at end of file
<?php
//check show btn use cases
// role is financer or operater
if( $mode != "pdf" ){
if(Form::canFormAccess( ['roles'=>["Financeur","Opérateur"] ]))
{
if( isset($form['id']) )
{ ?>
if( Form::canFormAccess( ['roles'=>["Financeur","Opérateur"] ]))
{
if( isset($form['id']) )
{ ?>
<table class="table table-bordered table-hover directoryTable" >
<tbody class="directoryLines">
<tr>
<td colspan='2' ><h4 style="color:<?php echo ($titleColor) ? $titleColor : "black"; ?>">Intention Opérateur</h4></td>
</tr>
<?php
$str = "";
$selectedOperator = false;
if(isset($answer["links"]["operators"]))
{
$communityLinks = Element::getCommunityByTypeAndId($this->costum["contextType"],$this->costum["contextId"]);
$persons = Link::groupFindByType( Person::COLLECTION,$communityLinks,["name","links"] );
$organizations = Link::groupFindByType( Organization::COLLECTION,$communityLinks,["name","links"] );
$financers = array_merge( $persons, $organizations );
$orgs = [];
if( !empty($or["links"]["memberOf"][$this->costum["contextId"]]["roles"]) ) {
foreach ($financers as $id => $or) {
$roles = $or["links"]["memberOf"][$this->costum["contextId"]]["roles"];
if( isset($this->costum["form"]["params"]["financement"]["limitRoles"]) && !empty($roles))
{
foreach ($roles as $i => $r) {
if( in_array($r, $this->costum["form"]["params"]["financement"]["limitRoles"]) )
$orgs[$id] = $or["name"];
}
<table class="table table-bordered table-hover directoryTable" >
<tbody class="directoryLines">
<tr>
<td colspan='2' ><h4 style="color:<?php echo ($titleColor) ? $titleColor : "black"; ?>">Intention Opérateur</h4></td>
</tr>
<?php
$str = "";
$selectedOperator = false;
if(isset($answer["links"]["operators"]))
{
$communityLinks = Element::getCommunityByTypeAndId($this->costum["contextType"],$this->costum["contextId"]);
$persons = Link::groupFindByType( Person::COLLECTION,$communityLinks,["name","links"] );
$organizations = Link::groupFindByType( Organization::COLLECTION,$communityLinks,["name","links"] );
$financers = array_merge( $persons, $organizations );
$orgs = [];
if( !empty($or["links"]["memberOf"][$this->costum["contextId"]]["roles"]) ) {
foreach ($financers as $id => $or) {
$roles = $or["links"]["memberOf"][$this->costum["contextId"]]["roles"];
if( isset($this->costum["form"]["params"]["financement"]["limitRoles"]) && !empty($roles))
{
foreach ($roles as $i => $r) {
if( in_array($r, $this->costum["form"]["params"]["financement"]["limitRoles"]) )
$orgs[$id] = $or["name"];
}
}
}
}
}
// var_dump($orgs);exit;
// var_dump($orgs);exit;
foreach ($answer["links"]["operators"] as $oid => $state) {
if($state != "0")
{
$selectedOperator = true;
$str = '<tr>'.
'<td>Opérateur</td>'.
'<td>'.$oid.'</td>'.
'<td><span class="label label-success">Validé</span></td>'.
'</tr>';
}
else if( !$selectedOperator )
{
//if role financeurs
$str .= '<tr>'.
'<td>Opérateur Candidat</td>'.
'<td>'.$oid.'</td>'.
'<td><span class="label label-success"><a href="javascript:;" class="validateOperator" data-id="'.$oid.'">à Valider</a></span></td>'.
'</tr>';
foreach ($answer["links"]["operators"] as $oid => $state) {
if($state != "0")
{
$selectedOperator = true;
$str = '<tr>'.
'<td>Opérateur</td>'.
'<td>'.$oid.'</td>'.
'<td><span class="label label-success">Validé</span></td>'.
'</tr>';
}
else if( !$selectedOperator )
{
//if role financeurs
$str .= '<tr>'.
'<td>Opérateur Candidat</td>'.
'<td>'.$oid.'</td>'.
'<td><span class="label label-success"><a href="javascript:;" class="validateOperator" data-id="'.$oid.'">à Valider</a></span></td>'.
'</tr>';
}
}
}
echo $str;
//if role operateurs
if(!$selectedOperator){
?>
<tr>
<td colspan='2' class="text-center" >
<a href="javascript:;" data-oid="<?php echo Yii::app()->session["userId"] ?>" class="intentOperator btn btn-primary">Opérateur : Demander de prendre en charge</a>
</td>
</tr>
<?php
}
}
echo $str;
//if role operateurs
if(!$selectedOperator){
?>
<tr>
<td colspan='2' class="text-center" >
<a href="javascript:;" data-oid="<?php echo Yii::app()->session["userId"] ?>" class="intentOperator btn btn-primary">Opérateur : Demander de prendre en charge</a>
</td>
</tr>
<?php
}
//if role financeur
if(!$selectedOperator){
?>
<tr>
<td colspan='2' class="text-center" >
<a href="javascript:;" data-oid="<?php echo Yii::app()->session["userId"] ?>" class="validateOperator btn btn-danger">Financeur : Veuillez étudier ce dossier</a>
</td>
</tr>
<?php }?>
</tbody>
</table>
<?php
}} else { ?>
<div class="col-xs-12 text-center margin-top-50 well">
<?php if(@$answer["step"] && $answer["step"]=="deal1"){ ?>
<span style="font-size: 22px;font-weight: 800;">Vous avez soumis votre dossier pour qu'un opérateur se positionne dessus.<br/>Il est en cours de validation.
Cette étape sera validé par un opérateur et les financeurs.</span>
<?php }else{ ?>
<span class="text-center" style="font-size: 22px;font-weight: 800;">
Une fois votre dossier estimé rempli, vous pouvez le valider afin qu'il soit mis sous étude des opérateurs et des financeurs<br/><br/>
<a href="javascript:;" class="validateForSubmit btn btn-success">
Soumettre votre dossier
</a>
</span>
<?php } ?>
</div>
<?php } ?>
<script type="text/javascript">
//if role financeur
if(!$selectedOperator){
?>
<tr>
<td colspan='2' class="text-center" >
<a href="javascript:;" data-oid="<?php echo Yii::app()->session["userId"] ?>" class="validateOperator btn btn-danger">Financeur : Veuillez étudier ce dossier</a>
</td>
</tr>
<?php }?>
</tbody>
</table>
<?php
}
} else { ?>
<div class="col-xs-12 text-center margin-top-50 well">
<?php if(@$answer["step"] && $answer["step"]=="deal1"){ ?>
<span style="font-size: 22px;font-weight: 800;">Vous avez soumis votre dossier pour qu'un opérateur se positionne dessus.<br/>Il est en cours de validation.
Cette étape sera validé par un opérateur et les financeurs.</span>
<?php }else{ ?>
<span class="text-center" style="font-size: 22px;font-weight: 800;">
Une fois votre dossier estimé rempli, vous pouvez le valider afin qu'il soit mis sous étude des opérateurs et des financeurs<br/><br/>
<a href="javascript:;" class="validateForSubmit btn btn-success">
Soumettre votre dossier
</a>
</span>
<?php } ?>
</div>
<?php
} ?>
<script type="text/javascript">
$(document).ready(function() {
$(document).ready(function() {
mylog.log("render","modules/survey/views/tpls/forms/costum/deal/stepOperateur.php");
var today = new Date();
today = today.getDate() + '/' + (today.getMonth()+1) + '/' + today.getFullYear();
$('.validateOperator').off().on("click", function() {
var oid = $(this).data("id");
ctxTpl = {
id : "<?php echo $answer['_id'] ?>",
collection : "answers",
path : "links.operators."+oid,
value : {
date : today,
user : userId
}
};
$(this).fadeOut();
mylog.log("save step save",ctxTpl);
dataHelper.path2Value( ctxTpl, function(params) {
ctxTpl = {
id : "<?php echo $answer['_id'] ?>",
collection : "answers",
path : "step",
value : "deal3" //pourrait etre un parametre element.costum.form.stepOperateur : deal3
};
mylog.log("save step save",ctxTpl);
dataHelper.path2Value( ctxTpl, function(params) {
mylog.log("render","modules/survey/views/tpls/forms/costum/deal/stepOperateur.php");
var today = new Date();
today = today.getDate() + '/' + (today.getMonth()+1) + '/' + today.getFullYear();
$('.validateOperator').off().on("click", function() {
var oid = $(this).data("id");
ctxTpl = {
id : "<?php echo $answer['_id'] ?>",
collection : "answers",
path : "links.operators."+oid,
value : {
date : today,
user : userId
}
};
$(this).fadeOut();
mylog.log("save step save",ctxTpl);
dataHelper.path2Value( ctxTpl, function(params) {
ctxTpl = {
id : "<?php echo $answer['_id'] ?>",
collection : "answers",
path : "step",
value : "deal3" //pourrait etre un parametre element.costum.form.stepOperateur : deal3
};
mylog.log("save step save",ctxTpl);
dataHelper.path2Value( ctxTpl, function(params) {
urlCtrl.loadByHash(location.hash);
} );
} );
});
$('.validateForSubmit').off().on("click", function() {
ctxTpl = {
id : "<?php echo $answer['_id'] ?>",
collection : "answers",
path : "step",
value : "deal1"
};
dataHelper.path2Value( ctxTpl, function(params) {
urlCtrl.loadByHash(location.hash);
});
} );
$('.intentOperator').off().on("click", function() {
var oid = $(this).data("oid");
ctxTpl = {
id : "<?php echo $answer['_id'] ?>",
collection : "answers",
path : "links.operators."+oid,
value : "0"
};
dataHelper.path2Value( ctxTpl, function(params) {
urlCtrl.loadByHash(location.hash);
} );
} );
});
$('.validateForSubmit').off().on("click", function() {
ctxTpl = {
id : "<?php echo $answer['_id'] ?>",
collection : "answers",
path : "step",
value : "deal1"
};
dataHelper.path2Value( ctxTpl, function(params) {
urlCtrl.loadByHash(location.hash);
});
} );
$('.intentOperator').off().on("click", function() {
var oid = $(this).data("oid");
ctxTpl = {
id : "<?php echo $answer['_id'] ?>",
collection : "answers",
path : "links.operators."+oid,
value : "0"
};
dataHelper.path2Value( ctxTpl, function(params) {
urlCtrl.loadByHash(location.hash);
} );
});
</script>
<?php } ?>
});
</script>