IndexAction.php 3.77 KB
Newer Older
Clément Damiens's avatar
 
Clément Damiens committed
1 2 3
 <?php
class IndexAction extends CAction
{
Tibor Katelbach's avatar
Tibor Katelbach committed
4
    public function run($id=null, $answer=null, $mode=null)
Clément Damiens's avatar
 
Clément Damiens committed
5 6
    {
    	$this->getController()->layout = "//layouts/empty";
7
        $params = array();
Clément Damiens's avatar
 
Clément Damiens committed
8
        if(!empty($id)){
Raph El's avatar
Hotfix  
Raph El committed
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
            if($id == "new"){
                if(!empty(Yii::app()->session["userId"])){
 					$answer = Answer::generateAnswer();
 					$params["answerId"] = $answer["_id"];
 					$mode = "w" ;
				} 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"));

		            exit;
				}
                
            } else {
                $params["answerId"]=$id;
                $answer = PHDB::findOne( Form::ANSWER_COLLECTION, array("_id"=>new MongoId($id)));
            }
Raph El's avatar
Raph El committed
27

Raph El's avatar
Raph El committed
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68

            //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"));
	        }
Raph El's avatar
Raph El committed
69
        } else {
70 71 72 73
            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"));
Raph El's avatar
Raph El committed
74 75
        }
        
Raph El's avatar
Raph El committed
76
        
Clément Damiens's avatar
 
Clément Damiens committed
77
    }
Raph El's avatar
Modif  
Raph El committed
78
}