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

33
            $params["form"] = $form ;
Raph El's avatar
Raph El committed
34
            //Rest::json($params); exit;
35
	        $params = Form::getDataForm($params);
36
      		
Raph El's avatar
Raph El committed
37 38
	        $params["answer"] = $answer;
	        $canEditForm = false;
39
	        $canAdminAnswer = false;
Raph El's avatar
Raph El committed
40 41
	        $canEditAnswer = false;
	        $canSeeAnswer = false;
42 43 44 45

	        if(empty($mode) || ( $mode != "w" && $mode != "r" ) )
	        	$mode = "r";

Raph El's avatar
Raph El committed
46
	        if(!empty(Yii::app()->session['userId'])){
47 48
	        	$canEditAnswer = Answer::canEdit($params["answer"], $form, Yii::app()->session['userId'], @$parentForm);
				$canAdminAnswer = Answer::canAdmin($params["answer"], $form);
Raph El's avatar
Test  
Raph El committed
49

50 51 52 53
				if($canEditAnswer === false && $canAdminAnswer === false)
					$canSeeAnswer = Answer::canAccess($params["answer"], $form, Yii::app()->session['userId'], @$parentForm);
				else
					$canSeeAnswer = true;
Raph El's avatar
Raph El committed
54
	        }
Raph El's avatar
Raph El committed
55

56 57 58 59
	        if( $mode == "w" && $canEditAnswer === false && $canAdminAnswer === false )
	        	$mode = "r";

	        if($canSeeAnswer === true){
Raph El's avatar
Raph El committed
60
	        	$params["canEditForm"] = $canEditForm;
61
	        	$params["canAdminAnswer"] = $canAdminAnswer;
Raph El's avatar
Raph El committed
62 63 64
	            $params["canEdit"] = $canEditAnswer;
	            $params["canSee"] = $canSeeAnswer;
	            $params["mode"] = (!empty($mode) ? $mode : "r");
Raph El's avatar
Raph El committed
65
	            $tpl=(!empty($form["tpl"])) ? $form["tpl"] : "survey.views.tpls.forms.formWizard";
Raph El's avatar
Raph El committed
66 67 68 69 70 71 72
	            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
73
        } else {
74 75 76 77
            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
78 79
        }
        
Raph El's avatar
Raph El committed
80
        
Clément Damiens's avatar
 
Clément Damiens committed
81
    }
Raph El's avatar
Modif  
Raph El committed
82
}