Commit dd83cad2 authored by Tibor Katelbach's avatar Tibor Katelbach
Browse files

Merge remote-tracking branch 'origin/development' into development

parents cdb967e2 48f1fe1d
......@@ -21,8 +21,8 @@ class AnswerAction extends CAction
if ( ! Person::logguedAndValid() )
$ctrl->render("co2.views.default.unTpl",array("msg"=>Yii::t("common","Please Login First"),"icon"=>"fa-sign-in"));
else if( Form::canSeeAnswer(Yii::app()->session["userId"], $answer, $form, $parent) ) {
$canAdmin=Form::canEditAnswer(Yii::app()->session["userId"], $answer, $form, $parent);
else if( Answer::canAccess($answer, $form, Yii::app()->session["userId"], $parent) ) {
$canAdmin=Answer::canEdit($answer, $form, Yii::app()->session["userId"], $parent);
if(!@$form["session"][ $answer["session"] ]){
$ctrl->render("co2.views.default.unTpl",array("msg"=>"Session introuvable sur ".$answer["formId"]."<br/><br/> Généré l'AAP pour afficher la candidature","icon"=>"fa-search"));
} else {
......
......@@ -25,7 +25,30 @@ class NewAction extends CAction
"email"=>Yii::app()->session["userEmail"],
"session" => $session
);
$res = Form::newAnswer( $new );
try{
$answer = array(
"formId"=>$new["id"],
"user"=>$new["user"],
"session"=>$new["session"],
"name"=>$new["name"],
"email"=>$new["email"],
"step" => "dossier",
"created"=>time()
);
$costum = CacheHelper::getCostum();
if( isset($costum) &&
isset($costum["slug"]) ){
$answer["source"] = array( "key" => $costum["slug"],
"keys" => array($costum["slug"]),
"insertOrign" => "costum") ;
}
PHDB::insert( self::ANSWER_COLLECTION, $answer);
$res = array( "result" => true,
"answer" => $answer );
} catch (CTKException $e){
return $e->getMessage();
}
if( $form["surveyType"] == "surveyList" ){
$firstId = (@$form["scenario"]) ? array_keys($form["scenario"])[0] : $form["id"];
$ctrl->redirect(Yii::app()->createUrl("/survey/co/index/id/".$firstId."/session/".$session."/answer/".(string)$res["answer"]['_id']));
......
......@@ -50,7 +50,7 @@ class IndexAction extends CAction
$mode = "w";
}
if( $mode == "w" || $mode == "fa" ){
$canEditAnswer = Form::canEditAnswer(Yii::app()->session['userId'], $params["answer"], $form, @$parentForm);
$canEditAnswer = Answer::canEdit($params["answer"], $form, Yii::app()->session['userId'], @$parentForm);
if(empty($canEditAnswer))
$mode = "r";
else
......@@ -58,7 +58,7 @@ class IndexAction extends CAction
}
if(empty($canEditAnswer) && empty($canSeeAnswer)){
$canSeeAnswer = Form::canSeeAnswer(Yii::app()->session['userId'], $params["answer"], $form, @$parentForm);
$canSeeAnswer = Answer::canAccess($params["answer"], $form, Yii::app()->session['userId'], @$parentForm);
if($canSeeAnswer === true && !empty($mode) && ($mode == "w" || $mode == "fa") )
$mode = "r";
}
......
......@@ -51,6 +51,51 @@ class Answer{
return $answer;
}
public static function canEdit($ans, $form=null, $userId=null, $parent=null){
if(ctype_xdigit($ans)){
$ans=self::getById($ans);
$form = Form::getByIdMongo($ans["form"]);
$parent = Slug::getElementBySlug($form["id"]);
$userId=Yii::app()->session["userId"];
}
if($ans["user"] == $userId)
return true;
else if(Form::canAdmin((string)$form["_id"], $form))
return true;
else if(Costum::isSameFunction("canEditAnswer", array("answer"=>$ans)))
return Costum::sameFunction("canEditAnswer", array("answer"=>$ans));
return false;
}
public static function canAccess($answer, $form=null, $userId=null, $parentForm=null){
if(ctype_xdigit($answer)){
$answer=self::getById($answer);
$form = Form::getByIdMongo($answer["form"]);
$parent = Slug::getElementBySlug($form["id"]);
}
if(self::canEdit( $answer, $form, $userId, $parentForm))
return true;
else if(Costum::isSameFunction("canAccessAnswer", array("answer"=>$answer)))
return Costum::sameFunction("canAccessAnswer", array("answer"=>$answer));
return false;
}
public static function getListBy($form=null, $costum=null, $userId=null, $cond=null){
$where = array();
$lists = array();
if(!empty($form))
$where["form"]=$form;
if(!empty($costum))
$where["source.keys"]=array('$in' => array($costum) );
if(!empty($userId))
$where["user"]=$userId;
if(!empty($cond)){
$where=array('$and'=> array($where, $cond));
}
if(!empty($where))
$lists=PHDB::find( Answer::COLLECTION, $where);
return $lists;
}
public static function globalAutocomplete($form, $searchParams){
$searchParams["indexMin"] = (isset($searchParams["indexMin"])) ? $searchParams["indexMin"] : 0;
$searchParams["indexStep"] = (isset($searchParams["indexStep"])) ? $searchParams["indexStep"] : 100;
......
......@@ -100,33 +100,6 @@ class Form {
[ ] array
[ ] properties
*/
public static function newAnswer($data)
{
try{
$answer = array(
"formId"=>$data["id"],
"user"=>$data["user"],
"session"=>$data["session"],
"name"=>$data["name"],
"email"=>$data["email"],
"step" => "dossier",
"created"=>time()
);
$costum = CacheHelper::getCostum();
if( isset($costum) &&
isset($costum["slug"]) ){
$answer["source"] = array( "key" => $costum["slug"],
"keys" => array($costum["slug"]),
"insertOrign" => "costum") ;
}
PHDB::insert( self::ANSWER_COLLECTION, $answer);
return array( "result" => true,
"answer" => $answer );
} catch (CTKException $e){
return $e->getMessage();
}
}
public static function save($id,$data)
{
......@@ -182,12 +155,7 @@ class Form {
return PHDB::findOneById(self::COLLECTION,$id, $fields);
}
public static function canEditAnswerById($id){
$ans=self::getAnswerById($id);
$form = PHDB::findOne( Form::COLLECTION , array("id"=>$ans["formId"]));
$parent = Slug::getElementBySlug($form["id"]);
return self::canEditAnswer(Yii::app()->session["userId"], $ans, $form, $parent);
}
public static function getAnswerById($id,$fields=array()){
return PHDB::findOneById(self::ANSWER_COLLECTION,$id, $fields);
}
......@@ -236,8 +204,8 @@ class Form {
}
return $res;
}
public static function listForAdminNews($form, $answers = array() ){
// TODO OCEATOON : DEPRACTED !?
/* public static function listForAdminNews($form, $answers = array() ){
$results = array();
$uniq = array();
$uniqO = array();
......@@ -390,7 +358,7 @@ class Form {
// exit;
// Rest::json($results);exit ;
return $results ;
}
}*/
//rebuild answerList
// by adding organizing organization (id,type) and project (id,type)
......@@ -429,30 +397,6 @@ class Form {
}
public static function canSeeAnswer($userId, $answer, $form, $parentForm){
if(self::canEditAnswer($userId, $answer, $form, $parentForm))
return true;
else if(Costum::isSameFunction("canSeeAnswer", array("answer"=>$answer)))
return Costum::sameFunction("canSeeAnswer", array("answer"=>$answer));
return false;
}
public static function canEditAnswer($userId, $answer, $form, $parentForm = null){
if(self::canAdmin((string)$form["_id"], $form))
return true;
else if($answer["user"] == $userId)
return true;
else if ( self::canAdmin((string)$form["_id"], $form) )
return true;
// else if(Authorisation::canEditItem(Yii::app()->session["userId"], $parentForm["type"], $answer["_id"] ))
// return true;
// else if(Costum::sameFunction("canEditAnswer", array("answer"=>$answer)))
// return true;
else if(Costum::isSameFunction("canEditAnswer", array("answer"=>$answer)))
return Costum::sameFunction("canEditAnswer", array("answer"=>$answer));
return false;
}
public static function canAdmin($id, $form = array()){
if(empty($form) && @$id)
......@@ -670,33 +614,7 @@ class Form {
}
return false;
}
// public static function getListAnswersBy($formId, $parent, $userId=null, $cond=null){
// $where=array("formId"=> $formId, "parentSlug" => $parent);
// if(!empty($userId)){
// $where["user"]=$userId;
// }
// if(!empty($cond))
// $where=array('$and'=> array($where, $cond));
// $lists=PHDB::find( Form::ANSWER_COLLECTION, $where);
// return $lists;
// }
public static function getListAnswersBy($form=null, $costum=null, $userId=null, $cond=null){
$where = array();
$lists = array();
if(!empty($form))
$where["form"]=$form;
if(!empty($costum))
$where["source.keys"]=array('$in' => array($costum) );
if(!empty($userId))
$where["user"]=$userId;
if(!empty($cond)){
$where=array('$and'=> array($where, $cond));
}
if(!empty($where))
$lists=PHDB::find( Answer::COLLECTION, $where);
return $lists;
}
public static function getDataForAnswer($params){
if(isset($_GET["form"]) || !empty($params["form"])){
......
......@@ -52,7 +52,6 @@ if( $this->layout != "//layouts/empty"){
$this->renderPartial($layoutPath.'header',array("page"=>"ressource","layoutPath"=>$layoutPath));
}
//$canAdmin = Form::canEditAnswer( Form::canAdmin((string)$form["_id"]) || Authorisation::isElementAdmin( $parent["id"] , $parent["type"], Yii::app()->session["userId"] ) );
$canSuperAdmin = Form::canSuperAdmin($form["id"],$session, $form, $adminForm);
$showStyle = ( $canAdmin ) ? "display:none; " : "";
......
......@@ -111,6 +111,67 @@ if( $mode != "pdf" ){
<?php }
} ?>
<script type="text/javascript">
$(document).ready(function() {
mylog.log("render","modules/survey/views/tpls/forms/costum/deal/stepOperateur.php");
var today = new Date();
today = today.getDate() + '/' + (today.getMonth()+1) + '/' + today.getFullYear();
$('.validateOperator').off().on("click", function() {
var oid = $(this).data("id");
ctxTpl = {
id : "<?php echo $answer['_id'] ?>",
collection : "answers",
path : "links.operators."+oid,
value : {
date : today,
user : userId
}
};
$(this).fadeOut();
mylog.log("save step save",ctxTpl);
dataHelper.path2Value( ctxTpl, function(params) {
ctxTpl = {
id : "<?php echo $answer['_id'] ?>",
collection : "answers",
path : "step",
value : "deal3" //pourrait etre un parametre element.costum.form.stepOperateur : deal3
};
mylog.log("save step save",ctxTpl);
dataHelper.path2Value( ctxTpl, function(params) {
urlCtrl.loadByHash(location.hash);
} );
} );
});
$('.validateForSubmit').off().on("click", function() {
ctxTpl = {
id : "<?php echo $answer['_id'] ?>",
collection : "answers",
path : "step",
value : "deal1"
};
dataHelper.path2Value( ctxTpl, function(params) {
urlCtrl.loadByHash(location.hash);
});
} );
$('.intentOperator').off().on("click", function() {
var oid = $(this).data("oid");
ctxTpl = {
id : "<?php echo $answer['_id'] ?>",
collection : "answers",
path : "links.operators."+oid,
value : "0"
};
dataHelper.path2Value( ctxTpl, function(params) {
urlCtrl.loadByHash(location.hash);
} );
});
});
</script>
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