Commit d2e3f182 authored by Raph El's avatar Raph El

add canEditForm

parent 495f1c84
......@@ -24,37 +24,48 @@ class IndexAction extends CAction
$params["answerId"]=$id;
$answer = PHDB::findOne( Form::ANSWER_COLLECTION, array("_id"=>new MongoId($id)));
}
}
//Rest::json($params); exit;
$params = Form::getDataForAnswer($params);
$params["answer"] = $answer;
// TODO améliorer getdataForAnser pour soit viré la création de lanswers soit charger la bonne answer
$form = PHDB::findOne( Form::COLLECTION , array("id"=>$answer["formId"]));
$parentForm = Slug::getElementBySlug($form["id"]);
$canEditAnswer = false;
$canSeeAnswer = false;
if(!empty(Yii::app()->session['userId'])){
$canEditAnswer = Form::canEditAnswer(Yii::app()->session['userId'], $params["answer"], $form, $parentForm);
if(empty($canEditAnswer)){
$canSeeAnswer = Form::canSeeAnswer(Yii::app()->session['userId'], $params["answer"], $form, $parentForm);
if($canSeeAnswer === true && !empty($mode) && ($mode == "w" || $mode == "rplus") )
$mode = "r";
}else{
$canSeeAnswer = true;
}
}
// var_dump($canEditAnswer);
// var_dump($canSeeAnswer);
if($canEditAnswer === true || $canSeeAnswer === true){
$params["canEdit"] = $canEditAnswer;
$params["canSee"] = $canSeeAnswer;
$params["mode"] = (!empty($mode) ? $mode : "r");
//$tpl=(!empty($tpl)) ? $tpl : "survey.views.tpls.forms.formWizard";
$tpl=(!empty($this->getController()->costum["form"]["tpl"])) ? $this->getController()->costum["form"]["tpl"] : "survey.views.tpls.forms.formWizard";
echo $this->getController()->renderPartial($tpl,$params );
//Rest::json($params); exit;
$params = Form::getDataForAnswer($params);
$params["answer"] = $answer;
// TODO améliorer getdataForAnser pour soit viré la création de lanswers soit charger la bonne answer
$form = PHDB::findOne( Form::COLLECTION , array("id"=>$answer["formId"]));
$parentForm = Slug::getElementBySlug($form["id"]);
$canEditForm = false;
$canEditAnswer = false;
$canSeeAnswer = false;
if(!empty(Yii::app()->session['userId'])){
$canEditForm = Form::canAdmin(Yii::app()->session['userId'], $form);
if(empty($canEditForm) && $mode == "fa")
$mode = "w";
$canEditAnswer = Form::canEditAnswer(Yii::app()->session['userId'], $params["answer"], $form, $parentForm);
if(empty($canEditAnswer)){
$canSeeAnswer = Form::canSeeAnswer(Yii::app()->session['userId'], $params["answer"], $form, $parentForm);
if($canSeeAnswer === true && !empty($mode) && ($mode == "w" || $mode == "fa") )
$mode = "r";
}else{
$canSeeAnswer = true;
}
}
// var_dump($canEditAnswer);
// var_dump($canSeeAnswer);
if($canEditAnswer === true || $canSeeAnswer === true){
$params["canEditForm"] = $canEditForm;
$params["canEdit"] = $canEditAnswer;
$params["canSee"] = $canSeeAnswer;
$params["mode"] = (!empty($mode) ? $mode : "r");
//$tpl=(!empty($tpl)) ? $tpl : "survey.views.tpls.forms.formWizard";
$tpl=(!empty($this->getController()->costum["form"]["tpl"])) ? $this->getController()->costum["form"]["tpl"] : "survey.views.tpls.forms.formWizard";
echo $this->getController()->renderPartial($tpl,$params );
} else {
if(Yii::app()->request->isAjaxRequest)
echo $this->getController()->renderPartial("co2.views.default.unTpl",array("msg"=>Yii::t("common", "You are not allow to access to this answer"),"icon"=>"fa-lock"));
else
$this->getController()->render("co2.views.default.unTpl",array("msg"=>Yii::t("common", "You are not allow to access to this answer"),"icon"=>"fa-lock"));
}
} else {
if(Yii::app()->request->isAjaxRequest)
echo $this->getController()->renderPartial("co2.views.default.unTpl",array("msg"=>Yii::t("common", "You are not allow to access to this answer"),"icon"=>"fa-lock"));
......@@ -62,5 +73,6 @@ class IndexAction extends CAction
$this->getController()->render("co2.views.default.unTpl",array("msg"=>Yii::t("common", "You are not allow to access to this answer"),"icon"=>"fa-lock"));
}
}
}
\ No newline at end of file
......@@ -22,7 +22,8 @@ if( !isset($this->costum["form"]["startDate"]) ||
"form" => $form,
"answer" => $answer,
"mode" => $mode,
"canEdit" => $canEdit,
"canEdit" => $canEdit,
"canEditForm" => $canEditForm,
"el" => $el ];
if( isset($wizard) ){
$params["saveOneByOne"] = true;
......
......@@ -55,9 +55,11 @@ if( isset( $form["inputs"] ) ){ ?>
echo "<ul class='questionList'>";
foreach ( $form["inputs"] as $key => $input) {
$editQuestionBtn = ($canEdit) ? " <a class='btn btn-xs btn-danger editQuestion' href='javascript:;' data-form='".$form["id"]."' data-id='".$form["_id"]."' data-collection='".Form::COLLECTION."' data-key='".$key."' data-path='inputs.".$key."'><i class='fa fa-pencil'></i></a>".
$editQuestionBtn = ($canEditForm) ? " <a class='btn btn-xs btn-danger editQuestion' href='javascript:;' data-form='".$form["id"]."' data-id='".$form["_id"]."' data-collection='".Form::COLLECTION."' data-key='".$key."' data-path='inputs.".$key."'><i class='fa fa-pencil'></i></a>".
" <a class='btn btn-xs btn-danger deleteLine' href='javascript:;' data-id='".$form["_id"]."' data-collection='".Form::COLLECTION."' data-key='question".$key."' data-path='inputs.".$key."'><i class='fa fa-trash'></i></a>" : "";
var_dump($canEditForm);
$tpl = $input["type"];
if(in_array($tpl, ["textarea","markdown","wysiwyg"]))
$tpl = "tpls.forms.textarea";
......
......@@ -105,7 +105,7 @@ var formInputsHere = formInputs;
echo htmlentities($this->costum["cms"][$form["id"]."desc"]);
else
echo "<span style='color:#aaa'>* section description</span>";
if($canEdit)
if($canEditForm)
echo "<a class='btn btn-xs btn-danger editBtn' href='javascript:;' data-key='".@$form["id"]."desc' data-type='textarea' data-markdown='1' data-path='costum.cms.".@$form["id"]."desc' data-label='Expliquez les objectifs de cette étape ? '> <i class='fa fa-pencil'></i></a>";
echo "</div>";
......@@ -118,7 +118,8 @@ var formInputsHere = formInputs;
"answer"=>$answer,
"mode" => $mode,
"showForm" => $showForm,
"canEdit" => $canEdit,
"canEdit" => $canEdit,
"canEditForm" => $canEditForm,
"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