Commit c3c53690 authored by Anatole Rakotoson's avatar Anatole Rakotoson
Browse files

stepValidate and Oceco access permission Fix

parent e6c746f1
......@@ -108,8 +108,7 @@ var formObj = {
addHash += ".mode."+mode;
}
if(typeof contextId != "undefined" && contextId != null &&
typeof contextType != "undefined" && contextType != null){
if(typeof contextId != "undefined" && contextType != "undefined" ){
url += '/contextId/'+contextId+'/contextType/'+contextType;
addHash += '.contextId.'+contextId+'.contextType.'+contextType;
}
......@@ -202,7 +201,7 @@ var formObj = {
// str += '<a href="javascript:;" class="createForm btn btn-sm btn-link bg-green-k pull-right "><i class="fa fa-plus"></i> Nouveau Formulaire</a>'+
// '<a href="javascript:;" class="addOpenForm btn btn-sm btn-link bg-green-k pull-right "><i class="fa fa-plus"></i>Ajouter Formulaire</a>'+
str += '<div class="dropdown pull-right"> <button class="addformdropdown dropdown-toggle" type="button" data-toggle="dropdown"> Ajouter <span class="caret"></span> </button> <ul class="dropdown-menu"> <li><a href="javascript:;" class="createForm btn btn-sm btn-link bg-green-k pull-right "><i class="fa fa-plus"></i> Nouveau Formulaire</a></li><li><a href="javascript:;" class="addOpenForm btn btn-sm btn-link bg-green-k pull-right "><i class="fa fa-plus"></i>Ajouter Formulaire</a></li></ul> </div>';
str += '<div class="dropdown pull-right"> <button class="addformdropdown dropdown-toggle" type="button" data-toggle="dropdown"> Ajouter <span class="caret"></span> </button> <ul class="dropdown-menu"> <li><a href="javascript:;" class="createForm bg-green-k "><i class="fa fa-plus"></i> Nouveau Formulaire</a></li><li><a href="javascript:;" class="addOpenForm "><i class="fa fa-plus"></i>Ajouter Formulaire</a></li></ul> </div>';
str += ' </div>';
str += '<div class="page__items" role="row">';
$.each(forms, function(idF, valForm){
......@@ -576,13 +575,23 @@ var formObj = {
$(".addAnswer").on('click', function() {
coInterface.showLoader("#mainDash");
ajaxPost("#mainDash", baseUrl+'/survey/answer/index/id/new/form/'+$(this).data("parentformid")+'/contextId/'+$(this).data("contextid")+'/contextType/'+$(this).data("contexttype"),
null,
function(){
if (typeof hashUrlPage != "undefined") {
// history.replaceState(location.hash, "", hashUrlPage+".view.forms.dir.graphbuilder."+$(this).data("parentformid"));
}
},"html");
if (typeof $(this).data("contextid") !== "undefined" && typeof $(this).data("contexttype") !== "undefined") {
ajaxPost("#mainDash", baseUrl+'/survey/answer/index/id/new/form/'+$(this).data("parentformid")+'/contextId/'+$(this).data("contextid")+'/contextType/'+$(this).data("contexttype"),
null,
function(){
if (typeof hashUrlPage != "undefined") {
// history.replaceState(location.hash, "", hashUrlPage+".view.forms.dir.graphbuilder."+$(this).data("parentformid"));
}
},"html");
} else {
ajaxPost("#mainDash", baseUrl+'/survey/answer/index/id/new/form/'+$(this).data("parentformid"),
null,
function(){
if (typeof hashUrlPage != "undefined") {
// history.replaceState(location.hash, "", hashUrlPage+".view.forms.dir.graphbuilder."+$(this).data("parentformid"));
}
},"html");
}
});
// $(fObj.container+' .application').off().on("click",function(){
......
......@@ -10,7 +10,7 @@ class DashboardAction extends CAction
public function run($id=null, $answer=null, $form=null, $title = "", $contextId = null, $contextType = null)
{
$controller = $this->getController();
$myanswer = PHDB::find( Form::ANSWER_COLLECTION, array("form"=>$answer));
$formanswers = PHDB::find( Form::ANSWER_COLLECTION, array("form"=>$answer));
$prntForm = PHDB::findOneById(Form::COLLECTION, $answer );
......@@ -18,14 +18,149 @@ class DashboardAction extends CAction
$tittleList = [];
$adminRight = false;
$active = true;
$canModify = true;
$canReadOtherAnswers = false;
$oneAnswerPerPers = false;
$private = true;
$showAnswers = true;
//permission to all Dashboard
$canAddAnswer = false;
$canEditEachotherAnswer = false;
$canReadEachOtherAnswer = false;
$titletype = [
$myanswers = PHDB::find( Form::ANSWER_COLLECTION, array("form"=>$answer, "user" => Yii::app()->session["userId"]));
if ($contextId != null || $contextType != null) {
$itemId = $contextId;
$itemType = $contextType;
} else {
foreach ($prntForm["parent"] as $prntFormkey => $prntFormvalue) {
$itemId = $prntFormkey;
$itemType = $prntFormvalue["type"];
}
}
// var_dump($itemId, $itemType, Yii::app()->session["userId"]);exit();
if
(
(
//is form active
isset($prntForm["active"]) &&
$prntForm["active"] == "true"
)
&&
(
//is form between start and end date
!isset($prntForm["startDate"]) ||
( time() > strtotime(str_replace("/","-",$prntForm["startDate"])) &&
( !isset($prntForm["endDate"]) || time() <= strtotime(str_replace("/","-",$prntForm["endDate"])))) ||
(isset($prntForm["endDate"]) && $prntForm["endDate"] == "")
)
&&
(
// is one answer per person
!isset($prntForm["oneAnswerPerPers"]) ||
(
isset($prntForm["oneAnswerPerPers"]) &&
$prntForm["oneAnswerPerPers"] == "false"
)||
(
isset($prntForm["oneAnswerPerPers"]) &&
$prntForm["oneAnswerPerPers"] == "true" && empty($myanswers)
)
)
&&
(
//private
!isset($prntForm["private"]) ||
(
isset($prntForm["private"]) &&
$prntForm["private"] == "false"
)
||
(
isset($prntForm["private"]) &&
$prntForm["private"] == "true" && Link::isLinked($itemId, $itemType, Yii::app()->session["userId"])
)
)
&&
!empty(Yii::app()->session["userId"])
)
{
$canAddAnswer = true;
}
if
(
(
//is form active
isset($prntForm["active"]) &&
$prntForm["active"] == "true"
)
&&
(
//is form between start and end date
!isset($prntForm["startDate"]) ||
( time() > strtotime(str_replace("/","-",$prntForm["startDate"])) &&
( !isset($prntForm["endDate"]) || time() <= strtotime(str_replace("/","-",$prntForm["endDate"])))) ||
(isset($prntForm["endDate"]) && $prntForm["endDate"] == "")
)
&&
(
//private
!isset($prntForm["private"]) ||
(
isset($prntForm["private"]) &&
$prntForm["private"] == "false"
)
||
(
isset($prntForm["private"]) &&
$prntForm["private"] == "true" && Link::isLinked($itemId, $itemType, Yii::app()->session["userId"])
)
)
)
{
$canEditEachotherAnswer = true;
}
if
(
(
//is form active
isset($prntForm["active"]) &&
$prntForm["active"] == "true"
)
&&
(
//private
!isset($prntForm["private"]) ||
(
isset($prntForm["private"]) &&
$prntForm["private"] == "false"
)
||
(
isset($prntForm["private"]) &&
$prntForm["private"] == "true" && Link::isLinked($itemId, $itemType, Yii::app()->session["userId"] )
)
)
&&
(
//private
!isset($prntForm["canReadOtherAnswers"]) ||
(
isset($prntForm["canReadOtherAnswers"]) &&
$prntForm["canReadOtherAnswers"] == "true"
)
)
)
{
$canReadEachOtherAnswer = true;
}
$titletype = [
"text",
"select",
"tpls.forms.cplx.multitextvalidation",
......@@ -33,6 +168,7 @@ class DashboardAction extends CAction
"tpls.forms.cplx.multiRadio"
];
if(isset($prntForm["active"]) ){
$active = filter_var($prntForm["active"], FILTER_VALIDATE_BOOLEAN);
}
......@@ -54,11 +190,16 @@ class DashboardAction extends CAction
foreach ($prntForm["parent"] as $ip => $vp) {
$communityLinks = Element::getCommunityByTypeAndId($vp["type"],$ip);
foreach ($communityLinks as $cmid => $cmvalue) {
if ($cmid == Yii::app()->session["userId"] && isset($cmvalue["isAdmin"]) && $cmvalue["isAdmin"] == true) {
$adminRight = true;
}
}
if (Authorisation::isUserSuperAdmin(Yii::app()->session["userId"])) {
$adminRight = true;
}
}
if (isset($prntForm["subForms"])) {
......@@ -121,8 +262,8 @@ class DashboardAction extends CAction
$responsetitle = [];
$right = [];
foreach ($myanswer as $idAns => $valueAns) {
if(isset($valueAns["answers"])){
foreach ($formanswers as $idAns => $valueAns) {
if(isset($valueAns["answers"]) || $valueAns["user"] == Yii::app()->session["userId"]){
if(isset($valueAns["answers"][$title[0]][$title[1]])){
array_push($responsetitle , $valueAns["answers"][$title[0]][$title[1]]);
......@@ -147,6 +288,9 @@ class DashboardAction extends CAction
$countrsp = 0;
$percntrsp = 0;
if (empty($valueAns["answers"])) {
$valueAns["answers"] = [];
}
foreach ($valueAns["answers"] as $formName => $formAns) {
$countrsp += sizeof($formAns);
}
......@@ -167,7 +311,11 @@ class DashboardAction extends CAction
array_push($users, $us);
array_push($index, $idAns);
array_push($updatedate, date("d-m-Y", $valueAns["updated"])) ;
if (isset($valueAns["updated"])) {
array_push($updatedate, date("d-m-Y", $valueAns["updated"])) ;
}else{
array_push($updatedate, "") ;
}
array_push($countAns, $countrsp);
array_push($percentage, $percntrsp);
......@@ -202,11 +350,14 @@ class DashboardAction extends CAction
"allanswers" => $allfields,
"adminRight" => $adminRight,
"p_active" => $active,
"p_canModify" => $canModify,
"p_canReadOtherAnswers" => $canReadOtherAnswers,
"p_oneAnswerPerPers " => $oneAnswerPerPers ,
"p_private " => $private ,
"p_showAnswers" => $showAnswers,
"p_canModify" => @$canModify,
"p_canReadOtherAnswers" => @$canReadOtherAnswers,
"p_oneAnswerPerPers " => @$oneAnswerPerPers ,
"p_private " => @$private ,
"p_showAnswers" => @$showAnswers,
"canAddAnswer" => $canAddAnswer,
"canEditEachotherAnswer" => $canEditEachotherAnswer,
"canReadEachOtherAnswer" => $canReadEachOtherAnswer,
"contextId" => $contextId,
"contextType" => $contextType
];
......
......@@ -50,15 +50,16 @@ echo $this->renderPartial("survey.views.tpls.answers.header",["parentFormId" =>
<div class="btn-group pull-right">
<?php if ($adminRight) { ?>
<button class="btn btn-outline-dark titleparams"><i class="fa fa-cog"></i> Paramètre </button>
<?php }
if ($p_active && isset(Yii::app()->session["userId"])){
<?php
}
if ($canAddAnswer || $adminRight){
if ($contextId != null && $contextType != null) {
$btndatacontext= " data-contextid='".$contextId."' data-contexttype='".$contextType."'";
}else{
$btndatacontext= "";
}
$btndatacontext= " data-contextid='".$contextId."' data-contexttype='".$contextType."' data-type='openform'";
}else{
$btndatacontext= "";
}
?>
<button class="btn btn-outline-dark application addAnswer" data-type="openform" data-id='<?php echo $allanswers['parentFormId'] ?>' data-parentformid='<?php echo $allanswers['parentFormId'] ?>' <?php echo $btndatacontext ?>><i class="fa fa-plus"></i> Ajouter </button>
<button class="btn btn-outline-dark application addAnswer" data-id='<?php echo $allanswers['parentFormId'] ?>' data-parentformid='<?php echo $allanswers['parentFormId'] ?>' <?php echo $btndatacontext ?>><i class="fa fa-plus"></i> Ajouter </button>
<?php } ?>
</div>
</div>
......@@ -219,6 +220,13 @@ echo $this->renderPartial("survey.views.tpls.answers.header",["parentFormId" =>
<?php
for ($i = 0; $i < count($allanswers["index"]) ; $i++)
{
$useranswer = false;
foreach ($allanswers["users"][$i] as $ukey => $uvalue) {
if (Yii::app()->session["userId"] == (string)$uvalue["_id"]) {
$useranswer = true;
}
}
if ($adminRight || $p_showAnswers || (!$p_showAnswers && $useranswer)) {
?>
<li class="survey-item">
<span class="survey-country list-only">
......@@ -316,18 +324,30 @@ echo $this->renderPartial("survey.views.tpls.answers.header",["parentFormId" =>
?>
<div class='social-links'>
<?php
if ($adminRight || $canEditEachotherAnswer || (!$canEditEachotherAnswer && $useranswer)) {
?>
<div class='social-btn flex-center <?php echo $btnclass ?> ' <?php echo $btndataw.$btndatatype ?>>
<i class="fa fa-pencil-square-o editdeleteicon"></i><span style="font-size: 14px;">Editer</span>
</div>
<?php
}
if ($adminRight || $canReadEachOtherAnswer || (!$canReadEachOtherAnswer && $useranswer)) {
?>
<div class='social-btn flex-center <?php echo $btnclass ?>' <?php echo $btndatar ?>>
<i class="fa fa-sticky-note-o editdeleteicon"></i><span style="font-size: 14px;">Lire</span>
</div>
<div class='social-btn flex-center <?php echo $btnpdfclass ?>' <?php echo $btndataw ?>>
<?php
}
?>
<!-- <div class='social-btn flex-center <?php echo $btnpdfclass ?>' <?php echo $btndataw ?>>
<i class="fa fa-file-pdf-o editdeleteicon"></i><span style="font-size: 14px;">pdf</span>
</div>
</div> -->
<?php if ($adminRight) { ?>
<div class='social-btn flex-center <?php echo $btndeleteclass ?>' <?php echo $btndataw ?>>
<i class="fa fa-trash-o editdeleteicon" style="color: #e6e6e6"></i><span style="font-size: 14px;">supprimer</span>
......@@ -339,6 +359,7 @@ echo $this->renderPartial("survey.views.tpls.answers.header",["parentFormId" =>
</li>
<?php
}
}
?>
</ul>
......
......@@ -55,9 +55,10 @@
}
}
}
// if (isset($answers) && !is_null($answers)) {
// $isValidate = true;
// }
if (isset($answers) && !is_null($answers) && !empty($answers)) {
$isValidate = true;
var_dump($answers);
}
$canValidate = false;
......@@ -209,7 +210,7 @@
$canValidate = true;
}
if (isset($answers) && $answers != null && $answers != "canValidate") {
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;
......@@ -227,16 +228,17 @@
?>
<?php if(!$isValidate && !$lastForm){?>
<?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($canValidate){ ?>
<?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 (!$isValidate && $lastForm) { ?>
<?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(!$canValidate){ ?>
<?php if(!$isValidate && $canValidate){ ?>
<button type="button" class="btn validate<?php echo $kunik ?>Params" >Terminer</button>
<?php } else { echo $message; } echo $editParamsBtn?>
......@@ -295,6 +297,8 @@ foreach ($mustSendMail as $persk => $persid) {
$mailList = array_unique($mailList);
var_dump($canValidate);
var_dump($isValidate);
?>
<script>
......@@ -323,6 +327,10 @@ $mailList = array_unique($mailList);
var <?php echo $kunik ?>Data = <?php echo json_encode( (isset($answers)) ? $answers : null ); ?>;
sectionDyf.<?php echo $kunik ?>ParamsData = <?php echo json_encode( $paramsData ); ?>;
function stepValidationReload<?php echo $form["id"]?>(){
reloadInput("<?php echo $key ?>", "<?php echo (string)$form["_id"] ?>");
}
$(document).ready(function() {
$(".gotoinput-btn").click( function() {
......
......@@ -260,6 +260,9 @@ jQuery(document).ready(function() {
dataHelper.path2Value( answer , function(params) {
toastr.success('Mise à jour enregistrée');
saveLinks(answerObj._id.$id,"updated",userId);
if (typeof stepValidationReload<?php echo $form["id"]?> !== "undefined") {
stepValidationReload<?php echo $form["id"]?>();
}
} );
} else {
toastr.error('answer cannot be empty, on saveOneByOne!');
......
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