Commit dd0b403c authored by Clément Damiens's avatar Clément Damiens
Browse files

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

parents 6bddbaaf 977736c9
......@@ -64,11 +64,14 @@ var formObj = {
history.replaceState(location.hash, "", hashUrlPage+".view.forms.dir.form."+id);
},"html");
},
answer : function(fObj, id, form){
answer : function(fObj, id, form, mode){
mylog.log("fObj.urls.answer", fObj, id, form);
var url = '/survey/answer/index/id/'+id;
if(typeof form != "undefined" && form != null)
url += '/form/'+form;
if(typeof mode != "undefined" && mode != null)
url += '/mode/'+mode;
ajaxPost(fObj.container, baseUrl+url,
null,
function(){
......@@ -202,7 +205,6 @@ var formObj = {
'</div>'+
'</div>';
return str ;
},
answers : function(fObj, answers){
//mylog.log("formProfil.views.answers");
......@@ -290,10 +292,16 @@ var formObj = {
}
}
str += '<div class="col-xs-12 no-padding">'+
'<a href="javascript:;" data-id="'+id+'" class="btnAnswer lbh margin-top-5 btn btn-open-answer">'+
'<i class="fa fa-sign-in"></i> Ouvrir'+
'</a>'+
'</div>'+
'<a href="javascript:;" data-id="'+id+'" data-mode="r" class="btnAnswer lbh margin-top-5 btn btn-open-answer">'+
'<i class="fa fa-sign-in"></i> Lire'+
'</a>';
if(typeof ans.canEdit == "boolean" && ans.canEdit === true){
str += '<a href="javascript:;" data-id="'+id+'" data-mode="w" class="btnAnswer lbh margin-top-5 btn btn-open-answer">'+
'<i class="fa fa-sign-in"></i> Modifer'+
'</a>';
}
str += '</div>'+
'</div>'+
'</div>';
});
......@@ -311,7 +319,7 @@ var formObj = {
},
answers : function(fObj){
$(fObj.container+' .btnAnswer').off().on("click",function(){
fObj.urls.answer(fObj, $(this).data("id"));
fObj.urls.answer(fObj, $(this).data("id"), null, $(this).data("mode"));
});
},
......
......@@ -12,7 +12,6 @@ class DirectoryAction extends CAction
$res=array();
$searchParams = $_POST;
$res = Form::getBySourceAndId($source, $form);
//var_dump($params["form"]);exit;
$answers=Answer::globalAutocomplete($res["form"], $searchParams);
$answerList = Form::listForAdmin($answers["results"]) ;
$answerList = Answer::getDataAnswers($answerList, $res["forms"]);
......@@ -20,22 +19,16 @@ class DirectoryAction extends CAction
if(isset($answers["count"]))
$res["count"]=$answers["count"];
$res["results"] = $answerList ;
$res["what"] = (isset($params["form"]["what"])) ? $params["form"]["what"] : "réponses";
//$res["what"] = (isset($params["form"]["what"])) ? $params["form"]["what"] : "réponses";
//$el = Slug::getElementBySlug( $res["form"]["parentSlug"] );
//$el=Form::getFirstParentForm($res["form"]);
$res['el'] = Form::getFirstParentForm($res["form"]);
//$res['el'] = Form::getFirstParentForm($res["form"]);
//ce code ne marchera pas pour deux formulaire identaique , d'un meme slug
//TODO utiliser le parntForm Id en plus
$res['canEdit'] = ( isset(Yii::app()->session["userId"]) && isset($el["type"]) && isset($el["id"]) ) ?
Authorisation::canEditItem(Yii::app()->session["userId"],$el["type"], $el["id"])
: false ;
// if($tpl=="json")
Rest::json( $res );
//else if(Yii::app()->request->isAjaxRequest)
// echo $controller->renderPartial("costum.views.custom.default.".$page,$params,true);
}
}
......@@ -15,42 +15,28 @@ class DirectoryAction extends CAction
if(@$_POST["page"]){
$limitMin=$limitMin+(100*($_POST["page"]-1));
}
$search="";
if(!empty($_POST["name"])){
$search = trim(urldecode($_POST['name']));
$queryForm = array("parent.".$_POST["id"] => array('$exists' => 1 ) );
if(!empty($controller->costum) && !empty($controller->costum["slug"]))
$queryForm = array('$and' => array( $queryForm , array("source.key" => $controller->costum["slug"]) ) ) ;
$forms = PHDB::find(Form::COLLECTION, $queryForm , array("name", "mapping") );
$idFs = array();
foreach ($forms as $keyF => $valF) {
$idFs[] = $keyF;
}
$res = Form::getBySourceAndId($controller->costum["slug"]);
$searchParams = $_POST;
$searchParams["count"] = true;
$answers=Answer::globalAutocomplete($res["form"], $searchParams);
$answerList = Form::listForAdmin($answers["results"]) ;
$answerList = Answer::getDataAnswers($answerList, $res["forms"]);
$panelAdmin["context"] = array( "id" => $_POST["id"],
"collection" => $_POST["collection"],
"slug" => $_POST["slug"] );
$searchRegExp = Search::accentToRegex($search);
//$query=array("parentSlug"=>$slug);
$forms = PHDB::find(Form::COLLECTION, array("parent.".$_POST["id"] => array('$exists' => 1 ) ) , array("name") );
$idFs = array();
foreach ($forms as $keyF => $valF) {
$idFs[] = $keyF;
}
$query=array( "form"=>array('$in' => $idFs) );
//Rest::json($query); exit;
$querySearch = array();
if(!empty($querySearch))
$query = array('$and' => array( $query , $querySearch ) ) ;
if(!empty($panelAdmin['filters'])){
$query = Search::searchFilters($panelAdmin['filters'], $query);
}
$params["typeDirectory"]=[ Answer::COLLECTION ];
$params["results"] = array();
$answers = PHDB::findAndLimitAndIndex ( Answer::COLLECTION , $query, $stepLim, $limitMin);
$answerList = Form::listForAdmin($answers) ;
foreach ($answerList as $key => $value) {
$answerList[$key]["countComment"] = PHDB::count(Comment::COLLECTION, array("contextId"=>$key,"contextType"=>Answer::COLLECTION));
}
$params["results"]["count"][Answer::COLLECTION] = PHDB::count( Answer::COLLECTION , $query);
$params["results"]["count"] = $answers["count"];
$params["results"][Answer::COLLECTION] = $answerList ;
$params["panelAdmin"] = $panelAdmin;
$page = "groupAdmin";
......@@ -58,7 +44,5 @@ class DirectoryAction extends CAction
Rest::json( $params );
else if(Yii::app()->request->isAjaxRequest)
echo $controller->renderPartial("costum.views.custom.default.".$page,$params,true);
}
}
......@@ -172,13 +172,11 @@ class Answer{
}
$answerList[$key]["countComment"] = PHDB::count(Comment::COLLECTION, array("contextId"=>$key,"contextType"=>Form::ANSWER_COLLECTION));
$localLinks = [];
$uids = [];
$todo = 0;
$done = 0;
$tasksPerson = [];
// $imgAnsw=(isset($ans["profilMediumImageUrl"])) ? Yii::app()->createUrl($ans["profilMediumImageUrl"]) : Yii::app()->getModule( Yii::app()->params["module"]["parent"] )->getAssetsUrl()."/images/thumbnail-default.jpg";
if(!isset($ans["answers"])) {
$percent = 0;
} else {
......@@ -186,10 +184,8 @@ class Answer{
$answeredInputs = 0;
foreach ($forms as $fid => $f){
$totalInputs += count($f["inputs"]);
//echo "|".$f['id']."-fi=".count($f["inputs"]);
if( isset( $ans["answers"][$fid] ) ){
$answeredInputs += count( $ans["answers"][$fid] );
//echo "|".$f['id']."-ai=".count( $ans["answers"][$f['id']] )."<br/>";
}
//todo lists are on depense for the moment
......@@ -211,7 +207,6 @@ class Answer{
$done++;
}
}
}
}
}
......@@ -223,16 +218,6 @@ class Answer{
if(!isset($globalLinks[$type]))
$globalLinks[$type] = [];
// if($type == "operators"){
// $lblstate = "Opérateur à valider";
// $statecol = "warning";
// foreach ($ls as $oid => $ov) {
// if($ov != "0"){
// $lblstate = "Opérateur OK";
// $statecol = "primary";
// }
// }
// }
foreach ($ls as $uid => $time) {
if(is_string($uid) && strlen($uid) == 24 && ctype_xdigit($uid)){
if(!in_array($uid, $localLinks[$type] ))
......@@ -255,10 +240,30 @@ class Answer{
$answerList[$key]["todo"] = $todo;
$answerList[$key]["done"] = $done;
$answerList[$key]["tasksPerson"] = $tasksPerson;
$answerList[$key]["canEdit"] = self::canEdit( $ans, null, Yii::app()->session["userId"]) ;
}
}
return $answerList;
}
public static function csv($elements, $idElt, $valElt, $forms ){
$elements[$idElt]["id"] = $idElt;
$elements[$idElt]["user"] = $valElt["user"];
$elements[$idElt]["created"] = date("d/m/Y", $valElt["created"]);
if(!empty($valElt["answers"])){
foreach ($forms as $keyF => $valF) {
if(!empty($valF["id"]) && !empty($valElt["answers"][$valF["id"]])){
foreach ($valElt["answers"][$valF["id"]] as $keyAns => $valAns) {
if(!empty($valF["inputs"]) && !empty($valF["inputs"][$keyAns]) && !empty($valF["inputs"][$keyAns]["label"])){
$elements[$idElt][$valF["inputs"][$keyAns]["label"]] = $valAns;
}
}
}
}
}
return $elements;
}
}
?>
\ No newline at end of file
......@@ -663,6 +663,7 @@ class Form {
$form = $params["form"] ;
else
$form = PHDB::findOneById( Form::COLLECTION, $_GET["form"] );
$params["parentForm"] = $form;
$communityLinks = array();
if(!empty($form["parent"])){
......
......@@ -24,6 +24,7 @@ if( $mode != "pdf" ){
<table class="table table-bordered table-hover directoryTable" >
<tbody class="directoryLines">
<tr>
<?php $label=(@$answer["step"]=="deal12") ? "Opérateur sélectionner par le ménage" : "Intention opérateur"; ?>
<td colspan='2' ><h4 style="color:<?php echo ($titleColor) ? $titleColor : "black"; ?>"><?php echo $label ?></h4></td>
</tr>
......@@ -165,7 +166,7 @@ if( $mode != "pdf" ){
<?php } ?>
</div>
<?php }
}
?>
<script type="text/javascript">
......@@ -284,3 +285,6 @@ if( $mode != "pdf" ){
</script>
<?php
}
?>
\ No newline at end of file
<?php
$styleT = ( ($mode == "pdf") ? " border : 1px solid black ;" : "");
//$styleT = ( ($mode == "pdf") ? " border : 1px solid black ;" : "");
//var_dump($styleT);
$colspanplus = (($mode == "r" || $mode == "pdf") ? 0 : 2);
?>
......@@ -16,125 +16,118 @@ $colspanplus = (($mode == "r" || $mode == "pdf") ? 0 : 2);
<?php echo $info ?>
<?php
} ?>
<table class="table table-bordered table-hover directoryTable" id="<?php echo $kunik ; ?>"
>
<table class="table table-bordered table-hover directoryTable" id="<?php echo $kunik ; ?>" >
<thead>
<?php
if( count($answers)>0 ){ ?>
<tr>
<?php
foreach ($properties as $i => $inp) {
echo "<th>".$inp["placeholder"]."</th>";
} ?>
<?php
if($mode != "r" && $mode != "pdf"){ ?>
<th></th>
<?php } ?>
</tr>
<?php } ?>
</thead>
<tbody class="directoryLines">
<?php
$ct = 0;
if(isset($answers)){
foreach ($answers as $q => $a) {
$tds = "";
<thead>
<?php
if( count($answers)>0 ){ ?>
<tr>
<?php
foreach ($properties as $i => $inp) {
$tds .= "<td>";
echo "<th>".$inp["placeholder"]."</th>";
} ?>
if( $i == "price" ) {
if(!empty($a["price"]))
$tds .= "<span id='price".$q."'>".$a["price"]."€</span>";
if( $paramsData["estimate"] )
{
$tds .= "<a href='javascript:;' data-id='".$answer["_id"]."' data-key='".$key."' data-form='".$form["id"]."' data-pos='".$q."' class='btn btn-xs btn-primary btnEstimate margin-left-5 padding-10'><i class='fa fa-plus'></i></a>";
if( isset($a["estimates"] ))
{
foreach ( $a["estimates"] as $uid => $esti )
<?php
if($mode != "r" && $mode != "pdf"){ ?>
<th></th>
<?php } ?>
</tr>
<?php } ?>
</thead>
<tbody class="directoryLines">
<?php
$ct = 0;
if(isset($answers)){
foreach ($answers as $q => $a) {
$tds = "";
foreach ($properties as $i => $inp) {
$tds .= "<td>";
if( $i == "price" ) {
if(!empty($a["price"]))
$tds .= "<span id='price".$q."'>".$a["price"]."€</span>";
if( $paramsData["estimate"] )
{
$tds .= "<a href='javascript:;' data-id='".$answer["_id"]."' data-key='".$key."' data-form='".$form["id"]."' data-pos='".$q."' class='btn btn-xs btn-primary btnEstimate margin-left-5 padding-10'><i class='fa fa-plus'></i></a>";
if( isset($a["estimates"] ))
{
$selected = ( isset($esti["selected"]) ) ? "success" : "default";
$tds .= "<br/><a href='javascript:;' data-id='".$answer["_id"]."' data-uid='".$uid."' data-price='".$esti["price"]."' data-key='".$key."' data-form='".$form["id"]."' data-pos='".$q."' class='btn btn-xs btn-".$selected." btnEstimateSelected margin-left-5 padding-10'>".$esti["price"]."€ | ".$esti["days"]."j | ".$esti["name"]."</a>";
foreach ( $a["estimates"] as $uid => $esti )
{
$selected = ( isset($esti["selected"]) ) ? "success" : "default";
$tds .= "<br/><a href='javascript:;' data-id='".$answer["_id"]."' data-uid='".$uid."' data-price='".$esti["price"]."' data-key='".$key."' data-form='".$form["id"]."' data-pos='".$q."' class='btn btn-xs btn-".$selected." btnEstimateSelected margin-left-5 padding-10'>".$esti["price"]."€ | ".$esti["days"]."j | ".$esti["name"]."</a>";
}
}
}
}
}
}
else if(isset($a[$i]))
$tds .= $a[$i];
$tds .= "</td>";
}
else if(isset($a[$i]))
$tds .= $a[$i];
echo "<tr id='".$kunik.$q."' class='".$kunik."Line'>";
echo $tds;
if($mode != "r" && $mode != "pdf"){
?>
<td>
<?php
//echo $answerPath.$q;
$this->renderPartial( "survey.views.tpls.forms.cplx.editDeleteLineBtn" , [
"canEdit"=>($canEdit||Yii::app()->session["userId"] == $answer["user"]),
"id" => $answer["_id"],
"collection" => Form::ANSWER_COLLECTION,
"q" => $q,
"path" => $answerPath.$q,
"kunik"=>$kunik ] ); ?>
<a href="javascript:;" class="btn btn-xs btn-primary openAnswersComment" onclick="commentObj.openPreview('answers','<?php echo $answer["_id"]?>','<?php echo $answer["_id"].$key.$q ?>', '<?php echo @$a['step'] ?>')"><?php echo PHDB::count(Comment::COLLECTION, array("contextId"=>$answer["_id"],"contextType"=>"answers", "path"=>$answer["_id"].$key.$q))?> <i class='fa fa-commenting'></i></a>
</td>
<?php
}
$ct++;
echo "</tr>";
$tds .= "</td>";
}
echo "<tr id='".$kunik.$q."' class='".$kunik."Line'>";
echo $tds;
if($mode != "r" && $mode != "pdf"){
?>
<td>
<?php
//echo $answerPath.$q;
$this->renderPartial( "survey.views.tpls.forms.cplx.editDeleteLineBtn" , [
"canEdit"=>($canEdit||Yii::app()->session["userId"] == $answer["user"]),
"id" => $answer["_id"],
"collection" => Form::ANSWER_COLLECTION,
"q" => $q,
"path" => $answerPath.$q,
"kunik"=>$kunik ] ); ?>
<a href="javascript:;" class="btn btn-xs btn-primary openAnswersComment" onclick="commentObj.openPreview('answers','<?php echo $answer["_id"]?>','<?php echo $answer["_id"].$key.$q ?>', '<?php echo @$a['step'] ?>')"><?php echo PHDB::count(Comment::COLLECTION, array("contextId"=>$answer["_id"],"contextType"=>"answers", "path"=>$answer["_id"].$key.$q))?> <i class='fa fa-commenting'></i></a>
</td>
<?php
}
$ct++;
echo "</tr>";
}
}
$totalMap = [];
foreach ( $properties as $i => $inp ) {
if( isset($inp["propType"]) && $inp["propType"] == "amount" )
$totalMap[$i] = 0;
}
if(isset($answers)){
foreach ( $answers as $q => $a ) {
foreach ($totalMap as $i => $tot) {
if(isset($a[$i]))
$totalMap[$i] = $tot + $a[$i];
}
}
}
$total = 0;
foreach ( $totalMap as $i => $tot ) {
if( $tot != 0 )
$total = $total + $tot ;
}
if($total > 0){
$totalMap = [];
foreach ( $properties as $i => $inp ) {
if( isset($inp["propType"]) && $inp["propType"] == "amount" )
$totalMap[$i] = 0;
}
echo "<tr class='bold'>";
echo "<td colspan=".(count( $paramsData["amounts"] )+2)." style='text-align:right'> TOTAL : </td>";
if($mode != "r" && $mode != "pdf")
echo "<td colspan='".$colspanplus."''>".trim(strrev(chunk_split(strrev($total),3, ' ')))." €</td>";
else
echo "<td>".trim(strrev(chunk_split(strrev($total),3, ' ')))." €</td>";
echo "</tr>";
if(isset($answers)){
foreach ( $answers as $q => $a ) {
foreach ($totalMap as $i => $tot) {
if(isset($a[$i]))
$totalMap[$i] = $tot + $a[$i];
}
}
}
//Yii::app()->session["totalBudget"] = $total;
$total = 0;
foreach ( $totalMap as $i => $tot ) {
if( $tot != 0 )
$total = $total + $tot ;
}
}
if($total > 0){
echo "<tr class='bold'>";
echo '<td colspan="'.(count( $paramsData["amounts"] )+2).'" style="text-align:right"> TOTAL : </td>';
if($mode != "r" && $mode != "pdf")
echo "<td colspan='".$colspanplus."'>".trim(strrev(chunk_split(strrev($total),3, ' ')))." €</td>";
else
echo "<td>".trim(strrev(chunk_split(strrev($total),3, ' ')))." €</td>";
echo "</tr>";
}
?>
?>
</tbody>
</table>
</div>
\ No newline at end of file
<?php
$styleT = ( ($mode == "pdf") ? " border : 1px solid black ;" : "");
$colspanplus = (($mode == "r" || $mode == "pdf") ? 0 : 2);
?>
<div class="form-group">
<?php
if($mode == "r" || $mode == "pdf"){ ?>
......@@ -31,6 +26,8 @@ $colspanplus = (($mode == "r" || $mode == "pdf") ? 0 : 2);
<?php
if($mode != "r" && $mode != "pdf"){ ?>
<th></th>
<?php } else { ?>
<th>State</th>
<?php } ?>
</tr>
<?php } ?>
......@@ -153,40 +150,47 @@ $colspanplus = (($mode == "r" || $mode == "pdf") ? 0 : 2);
echo "<tr id='".$kunik.$q."' class='".$kunik."Line text-center' style='".$trStyle."'>";
echo $tds;
if($mode != "r" && $mode != "pdf"){ ?>
<td>
<?php
$color = "default";
$valbl = "?";
$tool= "En attente de validation";
if( isset($a["validFinal"]["valid"]) ){
if( $a["validFinal"]["valid"] == "validated" ){
$color = "success";
$valbl = "V";
$tool="Validé sans réserve";
} else if( $a["validFinal"]["valid"] == "reserved" ){
$color = "warning";
$valbl = "R";
$tool="Validé avec réserves";
} else if( $a["validFinal"]["valid"] == "refused" ){
$color = "danger";
$valbl = "NV";
$tool="Non validé";
echo "<tr id='".$kunik.$q."' class='".$kunik."Line text-center' style='".$trStyle."'>";
echo $tds;
if($mode != "r" && $mode != "pdf"){ ?>
<td>
<?php
$color = "default";
$valbl = "?";
$tool= "En attente de validation";
if( isset($a["validFinal"]["valid"]) ){
if( $a["validFinal"]["valid"] == "validated" ){
$color = "success";
$valbl = "V";
$tool="Validé sans réserve";
} else if( $a["validFinal"]["valid"] == "reserved" ){
$color = "warning";
$valbl = "R";
$tool="Validé avec réserves";
} else if( $a["validFinal"]["valid"] == "refused" ){
$color = "danger";
$valbl = "NV";
$tool="Non validé";
}
}
}
echo "<a href='javascript:;' data-id='".$answer["_id"]."' data-budgetpath='".$copy."' data-form='".$copyF."' data-pos='".$q."' class='btnValidFinance btn btn-xs btn-".$color." margin-left-5 padding-10 tooltips' data-toggle='tooltip' data-placement='left' data-original-title='".$tool."'>".$valbl."</a>";
echo "<a href='javascript:;' data-id='".$answer["_id"]."' data-budgetpath='".$copy."' data-form='".$copyF."' data-pos='".$q."' class='btnValidFinance btn btn-xs btn-".$color." margin-left-5 padding-10 tooltips' data-toggle='tooltip' data-placement='left' data-original-title='".$tool."'>".$valbl."</a>";
?>
<a href="javascript:;" class="btn btn-xs btn-primary openAnswersComment" onclick="commentObj.openPreview('answers','<?php echo $answer["_id"]?>','<?php echo $answer["_id"].$key.$q ?>', '<?php echo @$a['step'] ?>')"><?php echo PHDB::count(Comment::COLLECTION, array("contextId"=>$answer["_id"],"contextType"=>"answers", "path"=>$answer["_id"].$key.$q))?> <i class='fa fa-commenting'></i></a>
</td>
<?php
}else{ ?>
<td>
<?php
if(!empty($a["validFinal"]["valid"]))
echo $a["validFinal"]["valid"];
?>
<a href="javascript:;" class="btn btn-xs btn-primary openAnswersComment" onclick="commentObj.openPreview('answers','<?php echo $answer["_id"]?>','<?php echo $answer["_id"].$key.$q ?>', '<?php echo @$a['step'] ?>')"><?php echo PHDB::count(Comment::COLLECTION, array("contextId"=>$answer["_id"],"contextType"=>"answers", "path"=>$answer["_id"].$key.$q))?> <i class='fa fa-commenting'></i></a>
</td>
<?php
</td>
<?php
}