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

Form : add function Answer::canAdmin for operator + change mode read or write

parent 977736c9
......@@ -35,43 +35,34 @@ class IndexAction extends CAction
$params = Form::getDataForm($params);
$params["answer"] = $answer;
// TODO améliorer getdataForAnser pour soit viré la création de lanswers soit charger la bonne answer
//$parentForm = Slug::getElementBySlug($form["id"]);
$canEditForm = false;
$canAdminAnswer = false;
$canEditAnswer = false;
$canSeeAnswer = false;
if(empty($mode) || ( $mode != "w" && $mode != "r" ) )
$mode = "r";
if(!empty(Yii::app()->session['userId'])){
if($mode == "fa"){
$canEditForm = Form::canAdmin(Yii::app()->session['userId'], $form);
if(empty($canEditForm))
$mode = "w";
}
if( $mode == "w" || $mode == "fa" ){
$canEditAnswer = Answer::canEdit($params["answer"], $form, Yii::app()->session['userId'], @$parentForm);
if(empty($canEditAnswer))
$mode = "r";
else
$canSeeAnswer = true;
}
$canEditAnswer = Answer::canEdit($params["answer"], $form, Yii::app()->session['userId'], @$parentForm);
$canAdminAnswer = Answer::canAdmin($params["answer"], $form);
if(empty($canEditAnswer) && empty($canSeeAnswer)){
$canSeeAnswer = Answer::canAccess($params["answer"], $form, Yii::app()->session['userId'], @$parentForm);
if($canSeeAnswer === true && !empty($mode) && ($mode == "w" || $mode == "fa") )
$mode = "r";
}
if($canEditAnswer === false && $canAdminAnswer === false)
$canSeeAnswer = Answer::canAccess($params["answer"], $form, Yii::app()->session['userId'], @$parentForm);
else
$canSeeAnswer = true;
}
if($canEditAnswer === true || $canSeeAnswer === true){
if( $mode == "w" && $canEditAnswer === false && $canAdminAnswer === false )
$mode = "r";
if($canSeeAnswer === true){
$params["canEditForm"] = $canEditForm;
$params["canAdminAnswer"] = $canAdminAnswer;
$params["canEdit"] = $canEditAnswer;
$params["canSee"] = $canSeeAnswer;
$params["mode"] = (!empty($mode) ? $mode : "r");
$tpl=(!empty($form["tpl"])) ? $form["tpl"] : "survey.views.tpls.forms.formWizard";
//Rest::json($tpl); exit;
echo $this->getController()->renderPartial($tpl,$params );
} else {
if(Yii::app()->request->isAjaxRequest)
......
......@@ -23,6 +23,7 @@ class EditAction extends CAction
$params = Form::getDataForm($params);
$params["answer"] = $answer;
$params["canEditForm"] = $canEditForm;
$params["canAdminAnswer"] = true;
$params["canEdit"] = true;
$params["canSee"] = true;
$params["showForm"] = true;
......
......@@ -51,6 +51,16 @@ class Answer{
return $answer;
}
public static function canAdmin($ans, $form=null){
if(Form::canAdmin((string)$form["_id"], $form))
return true;
else if(Costum::isSameFunction("canAdminAnswer", array("answer"=>$ans)))
return Costum::sameFunction("canAdminAnswer", array("answer"=>$ans));
return false;
}
public static function canEdit($ans, $form=null, $userId=null, $parent=null){
if(ctype_xdigit($ans)){
$ans=self::getById($ans);
......
......@@ -14,7 +14,7 @@
"canEditForm"=>false,
"controller" => $controller);
$params = Form::getDataForm($params);
$params["mode"]=(isset($_GET["mode"])) ? $_GET["mode"] : "rplus";
$params["mode"]=(isset($_GET["mode"])) ? $_GET["mode"] : "r";
echo $this->renderPartial('survey.views.tpls.forms.formWizard', $params );
?>
......
<?php if($answer){
<?php if($answer){
//var_dump($mode); exit;
$debug = false;
$editBtnL = (Yii::app()->session["userId"] == $answer["user"]) ? " <a href='javascript:;' data-id='".$answer["_id"]."' data-collection='".Form::ANSWER_COLLECTION."' data-path='".$answerPath."' class='add".$kunik." btn btn-default'><i class='fa fa-plus'></i> Ajouter une ligne </a>" : "";
$editBtnL = ( $canEdit === true && ( $mode == "w" || $mode == "fa") ) ? " <a href='javascript:;' data-id='".$answer["_id"]."' data-collection='".Form::ANSWER_COLLECTION."' data-path='".$answerPath."' class='add".$kunik." btn btn-default'><i class='fa fa-plus'></i> Ajouter une ligne </a>" : "";
$editParamsBtn = ($canEditForm) ? " <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>" : "";
......@@ -72,6 +73,7 @@ $properties = [
?>
<?php
echo $this->renderPartial("survey.views.tpls.forms.cplx.budgetTable",
[
"form" => $form,
......@@ -84,8 +86,7 @@ echo $this->renderPartial("survey.views.tpls.forms.cplx.budgetTable",
"key" => $key,
"titleColor" => $titleColor,
"properties" => $properties,
"canAdminAnswer" => $canAdminAnswer,
"label" => $label,
"editQuestionBtn" => $editQuestionBtn,
"editParamsBtn" => $editParamsBtn,
......
<?php
//$styleT = ( ($mode == "pdf") ? " border : 1px solid black ;" : "");
//var_dump($styleT);
$colspanplus = (($mode == "r" || $mode == "pdf") ? 0 : 2);
$colspanplus = 0 ;
if( $mode != "pdf" && ( $canAdminAnswer === true || $canEdit === true ) )
$colspanplus = 2;
?>
<div class="form-group">
......@@ -29,7 +32,8 @@ $colspanplus = (($mode == "r" || $mode == "pdf") ? 0 : 2);
} ?>
<?php
if($mode != "r" && $mode != "pdf"){ ?>
if( $mode != "pdf" && !empty($canAdminAnswer) && $canAdminAnswer === true ){?>
<th></th>
<?php } ?>
</tr>
......@@ -71,20 +75,26 @@ $colspanplus = (($mode == "r" || $mode == "pdf") ? 0 : 2);
echo "<tr id='".$kunik.$q."' class='".$kunik."Line'>";
echo $tds;
if($mode != "r" && $mode != "pdf"){
if( $mode != "pdf" &&
( $canAdminAnswer === true ||
$canEdit === true ) ) {
?>
<td>
<?php
//echo $answerPath.$q;
<?php
if($mode == "w" && ( $canAdminAnswer === true || $canEdit === true ) ){
$this->renderPartial( "survey.views.tpls.forms.cplx.editDeleteLineBtn" , [
"canEdit"=>($canEdit||Yii::app()->session["userId"] == $answer["user"]),
"id" => $answer["_id"],
"collection" => Form::ANSWER_COLLECTION,
"q" => $q,
"path" => $answerPath.$q,
"kunik"=>$kunik ] ); ?>
"kunik"=>$kunik ] );
} ?>
<a href="javascript:;" class="btn btn-xs btn-primary openAnswersComment" onclick="commentObj.openPreview('answers','<?php echo $answer["_id"]?>','<?php echo $answer["_id"].$key.$q ?>', '<?php echo @$a['step'] ?>')"><?php echo PHDB::count(Comment::COLLECTION, array("contextId"=>$answer["_id"],"contextType"=>"answers", "path"=>$answer["_id"].$key.$q))?> <i class='fa fa-commenting'></i></a>
<a href="javascript:;" class="btn btn-xs btn-primary openAnswersComment" onclick="commentObj.openPreview('answers','<?php echo $answer["_id"]?>','<?php echo $answer["_id"].$key.$q ?>', '<?php echo @$a['step'] ?>')">
<?php
echo PHDB::count(Comment::COLLECTION, array("contextId"=>$answer["_id"],"contextType"=>"answers", "path"=>$answer["_id"].$key.$q)); ?>
<i class='fa fa-commenting'></i></a>
</td>
<?php
}
......@@ -118,10 +128,10 @@ $colspanplus = (($mode == "r" || $mode == "pdf") ? 0 : 2);
if($total > 0){
echo "<tr class='bold'>";
echo '<td colspan="'.(count( $paramsData["amounts"] )+2).'" style="text-align:right"> TOTAL : </td>';
if($mode != "r" && $mode != "pdf")
//if($mode != "r" && $mode != "pdf")
echo "<td colspan='".$colspanplus."'>".trim(strrev(chunk_split(strrev($total),3, ' ')))." €</td>";
else
echo "<td>".trim(strrev(chunk_split(strrev($total),3, ' ')))." €</td>";
//else
//echo "<td>".trim(strrev(chunk_split(strrev($total),3, ' ')))." €</td>";
echo "</tr>";
}
......
......@@ -137,7 +137,8 @@ echo $this->renderPartial("survey.views.tpls.forms.cplx.financementFromBudgetTab
"info" => $info,
//"showForm" => $showForm,
"paramsData" => $paramsData,
"canEdit" => $canEdit,
"canEdit" => $canEdit,
"canAdminAnswer" => $canAdminAnswer,
//"el" => $el
] ,true );
......
......@@ -153,7 +153,8 @@
echo "<tr id='".$kunik.$q."' class='".$kunik."Line text-center' style='".$trStyle."'>";
echo $tds;
if($mode != "r" && $mode != "pdf"){ ?>
if($mode != "r" && $mode != "pdf" &&
!empty($canAdminAnswer) && $canAdminAnswer === true ){ ?>
<td>
<?php
$color = "default";
......
<?php
if( $mode != "pdf" ){
if( Form::canFormAccess( ['roles'=>["Financeur"] ], @$parentForm["parent"]) )
{
//if( Form::canFormAccess( ['roles'=>["Financeur"] ], @$parentForm["parent"]) ){
if( !empty($canAdminAnswer) && $canAdminAnswer === true ){
if( isset($form['id']) )
{
$editParamsBtn = ($canEdit) ? " <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>" : "";
......@@ -17,30 +17,29 @@ if( $mode != "pdf" ){
?>
<div id="copyEquilibreBudgetaire"></div>
<div id="copyEquilibreBudgetaire"></div>
<table class="table table-bordered table-hover directoryTable" >
<tbody class="directoryLines">
<tr>
<td colspan='2' ><h4 style="color:<?php echo ($titleColor) ? $titleColor : "black"; ?>">Validation</h4>
</td>
</tr>
<table class="table table-bordered table-hover directoryTable" >
<tbody class="directoryLines">
<tr>
<td colspan='2' ><h4 style="color:<?php echo ($titleColor) ? $titleColor : "black"; ?>">Validation</h4>
</td>
</tr>
<?php
if( isset( $answer["validation"][ $form['id'] ] ) )
{ ?>
<tr>
<td colspan='2' align="center">
<button id="generateCopil2" class="generateCopil btn btn-primary" data-id="<?php echo (string)$answer["_id"] ?>" data-date="<?php echo date("Y-m-d") ?>" data-title="Compte Rendu de la réunion de finalisation" data-key="copilReunionFinalisation">Générer le dossier validé</button>
<?php $pdf=Document::getListDocumentsWhere([ "id"=>(string)$answer["_id"], "type"=>Form::ANSWER_COLLECTION, "doctype"=>"file", "subKey"=>"pdf".$form['id'] ] ,"file");
?>
</td>
</tr>
<?php }
if( isset( $answer["validation"][ $form['id'] ] ) ){ ?>
<tr>
<td colspan='2' align="center">
<button id="generateCopil2" class="generateCopil btn btn-primary" data-id="<?php echo (string)$answer["_id"] ?>" data-date="<?php echo date("Y-m-d") ?>" data-title="Compte Rendu de la réunion de finalisation" data-key="copilReunionFinalisation">Générer le dossier validé</button>
<?php $pdf=Document::getListDocumentsWhere([ "id"=>(string)$answer["_id"], "type"=>Form::ANSWER_COLLECTION, "doctype"=>"file", "subKey"=>"pdf".$form['id'] ] ,"file");
?>
</td>
</tr>
<?php
}
if(isset($answer["validation"][$form['id']]))
{
if(isset($answer["validation"][$form['id']])){
$color = "danger";
$lbl = "Non validé";
if(isset($answer["validation"][$form['id']]["valid"])){
......@@ -68,33 +67,33 @@ if( $mode != "pdf" ){
<td><?php if( isset($answer["validation"][$form['id']]["date"] ) ) echo $answer["validation"][$form['id']]["date"]; ?></td>
</tr>
<?php
if(!empty($ficheAction))
{
//$ficheAction = array_splice($ficheAction, count($ficheAction)-1);
$histo = 0;
foreach($ficheAction as $k => $v){
if($histo < 1){?>
<tr>
<td>Fiche Action Finale</td>
<td><a href='<?php echo $v["docPath"] ?>' target='_blank' class="link-files"><i class="fa fa-file-pdf-o text-red"></i> <?php echo $v["name"] ?></a></td>
</tr>
<?php $histo++; }
}
} ?>
if(!empty($ficheAction)){
//$ficheAction = array_splice($ficheAction, count($ficheAction)-1);
$histo = 0;
foreach($ficheAction as $k => $v){
if($histo < 1){?>
<tr>
<td>Fiche Action Finale</td>
<td><a href='<?php echo $v["docPath"] ?>' target='_blank' class="link-files"><i class="fa fa-file-pdf-o text-red"></i> <?php echo $v["name"] ?></a></td>
</tr>
<?php $histo++; }
}
} ?>
<?php } ?>
<tr>
<td colspan='2' class="text-center" >
<a href="javascript:;" data-type="<?php echo $form['id'] ?>" class="validEdit btn btn-primary">Valider cette action</a>
</td>
</tr>
</tbody>
</table>
<?php
} ?>
<tr>
<td colspan='2' class="text-center" >
<a href="javascript:;" data-type="<?php echo $form['id'] ?>" class="validEdit btn btn-primary">Valider cette action</a>
</td>
</tr>
</tbody>
</table>
<?php
} ?>
} ?>
......@@ -105,7 +104,7 @@ if( $mode != "pdf" ){
$(document).ready(function() {
mylog.log("render","/modules/costum/views/tpls/forms/cplx/stepValidation.php");
mylog.log("render","/modules/survey/views/tpls/forms/cplx/stepValidation.php");
sectionDyf.<?php echo $kunik ?>Params = {
"jsonSchema" : {
......@@ -251,7 +250,8 @@ if( $mode != "pdf" ){
});
</script>
<?php } else {?>
<?php
} else { ?>
<div class="col-xs-12">
Seuls les référents du territoire, le porteur de l’action et l’équipe nationale ont accès à cette étape.
</div>
......
......@@ -165,7 +165,8 @@ echo $this->renderPartial("survey.views.tpls.forms.cplx.suiviFromBudgetTable",
"info" => $info,
//"showForm" => $showForm,
"paramsData" => $paramsData,
"canEdit" => $canEdit,
"canEdit" => $canEdit,
"canAdminAnswer" => $canAdminAnswer,
//"el" => $el
] ,true );
......
......@@ -188,7 +188,8 @@
$ct++;
echo "<tr id='".$kunik.$q."' class='".$kunik."Line text-center' style='".$trStyle."'>";
echo $tds;
if($mode != "r" && $mode != "pdf"){ ?>
if($mode != "r" && $mode != "pdf" &&
!empty($canAdminAnswer) && $canAdminAnswer === true ){ ?>
<td>
<a href="javascript:;" class="btn btn-xs btn-primary openAnswersComment" onclick="commentObj.openPreview('answers','<?php echo $answer["_id"]?>','<?php echo $answer["_id"].$key.$q ?>', '<?php echo @$a['step'] ?>')"><?php echo PHDB::count(Comment::COLLECTION, array("contextId"=>$answer["_id"],"contextType"=>"answers", "path"=>$answer["_id"].$key.$q))?> <i class='fa fa-commenting'></i></a>
</td>
......
......@@ -18,7 +18,7 @@ if( !isset($parentForm["startDate"]) ||
if($showForm)
{
$params =[
$params =[
"parentForm"=>$parentForm,
"formId" => $formId,
"form" => $form,
......@@ -26,6 +26,7 @@ if( !isset($parentForm["startDate"]) ||
"mode" => $mode,
"canEdit" => $canEdit,
"canEditForm" => $canEditForm,
"canAdminAnswer" => $canAdminAnswer,
"el" => $el ];
if( isset($wizard) ){
$params["saveOneByOne"] = true;
......
......@@ -146,49 +146,69 @@ if(isset($this->costum["cms"]["color1"]))
<div class="col-xs-12 margin-top-20">
<?php
$wizardUid = (String) $form["_id"];
if($mode != "fa"){
$params = [
"parentForm"=>$parentForm,
"el" => $el,
"color1" => $color1,
"canEdit" => $canEdit,
"answer"=>$answer,
"forms"=>$forms,
"allAnswers"=>@$allAnswers,
"what" => "dossiers",
"wizid"=> $wizardUid
];
echo $this->renderPartial($parentForm["answersTpl"],$params);
}
if( $mode == "fa" && $canEditForm === true ){
$params = [
"canEditForm"=>$canEditForm,
"mode" => $mode,
"form" => $form,
"el" => $el
];
echo $this->renderPartial("survey.views.tpls.forms.config",$params);
}
if( isset($answer) && !empty($showForm) && $showForm === true ) {
$params = [
"parentForm"=>$parentForm,
"form" => $form,
"forms"=>$forms,
"el" => $el,
"active" => "all",
"color1" => $this->costum["colors"]["dark"],
"color2" => $this->costum["colors"]["pink"],
"canEdit" => $canEdit,
"canEditForm" => $canEditForm,
"answer"=>$answer,
"showForm" => $showForm,
"mode" => $mode,
"wizid"=> $wizardUid
];
echo $this->renderPartial("survey.views.tpls.forms.wizard",$params);
}
if($canEdit === true && $mode != "fa"){
$nameMode = "mode read";
if($mode == "w")
$nameMode = "mode write";
echo '<div class="col-xs-12">'.
'<div class="col-xs-4 col-xs-offset-4 dropdown">'.
'<button class="btn btn-default dropdown-toggle col-xs-12" type="button" id="dropdown'.$wizardUid.'" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">'.
ucfirst (Yii::t('survey',$nameMode) ).' <span class="caret"></span>'.
'</button>'.
'<ul class="dropdown-menu col-xs-12" aria-labelledby="dropdown'.$wizardUid.'">'.
'<li><a href="#answer.index.id.'.(String)$answer['_id'].'.mode.r" class="lbh">'.ucfirst (Yii::t('survey',"read")).'</a></li>'.
'<li><a href="#answer.index.id.'.(String)$answer['_id'].'.mode.w" class="lbh">'.ucfirst (Yii::t('survey',"write")).'</a></li>'.
'</ul>'.
'</div>'.
'</div>';
}
if($mode != "fa" && !empty($parentForm["answersTpl"])){
$params = [
"parentForm"=>$parentForm,
"el" => $el,
"color1" => $color1,
"canEdit" => $canEdit,
"answer"=>$answer,
"forms"=>$forms,
"allAnswers"=>@$allAnswers,
"what" => "dossiers",
"wizid"=> $wizardUid
];
echo $this->renderPartial($parentForm["answersTpl"],$params);
}
if( $mode == "fa" && $canEditForm === true ){
$params = [
"canEditForm"=>$canEditForm,
"mode" => $mode,
"form" => $form,
"el" => $el
];
echo $this->renderPartial("survey.views.tpls.forms.config",$params);
}
if( isset($answer) && !empty($showForm) && $showForm === true ) {
$params = [
"parentForm"=>$parentForm,
"form" => $form,
"forms"=>$forms,
"el" => $el,
"active" => "all",
"color1" => $this->costum["colors"]["dark"],
"color2" => $this->costum["colors"]["pink"],
"canEdit" => $canEdit,
"canEditForm" => $canEditForm,
"canAdminAnswer" => $canAdminAnswer,
"answer"=>$answer,
"showForm" => $showForm,
"mode" => $mode,
"wizid"=> $wizardUid
];
echo $this->renderPartial("survey.views.tpls.forms.wizard",$params);
}
?>
</div>
......
......@@ -92,6 +92,7 @@ if( isset( $form["inputs"] ) ){ ?>
// var_dump($answerPath);
// var_dump($answers);
//var_dump($mode); exit;
$p = [
"el" => $el,
"parentForm"=> $parentForm,
......@@ -110,6 +111,7 @@ if( isset( $form["inputs"] ) ){ ?>
"mode" => $mode,
"canEdit" => $canEdit,
"canEditForm" => @$canEditForm,
"canAdminAnswer" => $canAdminAnswer,
"canAnswer" => $canAnswer,
"editQuestionBtn" => @$editQuestionBtn,
"saveOneByOne" => $saveOneByOne,
......
......@@ -118,11 +118,12 @@ if( isset($parentForm["subForms"]) && count($parentForm["subForms"]) > 1 ) {
</script>
<?php
if( !empty($forms[$v]) )
{
echo '<h1 class="text-center" style="color:'.$color1.'" >'.@$forms[$v]["name"].'</h1>';
//echo "<div class='markdown'>";
echo "<div class=''>";
echo $this->renderPartial("survey.views.tpls.forms.formSection",
......@@ -135,6 +136,7 @@ if( isset($parentForm["subForms"]) && count($parentForm["subForms"]) > 1 ) {
"showForm" => $showForm,
"canEdit" => $canEdit,
"canEditForm" => @$canEditForm,
"canAdminAnswer" => @$canAdminAnswer,
"el" => $el ] ,true );
echo "</div>";
}
......
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