Commit c232077e authored by Raph El's avatar Raph El
Browse files

Form : Hotfix pdf + Hotfix csv + Refactor admin/directory answer/directory and csv

parent 805283e7
...@@ -19,7 +19,7 @@ class DirectoryAction extends CAction ...@@ -19,7 +19,7 @@ class DirectoryAction extends CAction
if(isset($answers["count"])) if(isset($answers["count"]))
$res["count"]=$answers["count"]; $res["count"]=$answers["count"];
$res["results"] = $answerList ; $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 = Slug::getElementBySlug( $res["form"]["parentSlug"] );
//$el=Form::getFirstParentForm($res["form"]); //$el=Form::getFirstParentForm($res["form"]);
//$res['el'] = Form::getFirstParentForm($res["form"]); //$res['el'] = Form::getFirstParentForm($res["form"]);
......
...@@ -15,48 +15,28 @@ class DirectoryAction extends CAction ...@@ -15,48 +15,28 @@ class DirectoryAction extends CAction
if(@$_POST["page"]){ if(@$_POST["page"]){
$limitMin=$limitMin+(100*($_POST["page"]-1)); $limitMin=$limitMin+(100*($_POST["page"]-1));
} }
$search="";
if(!empty($_POST["name"])){
$search = trim(urldecode($_POST['name']));
}
$panelAdmin["context"] = array( "id" => $_POST["id"],
"collection" => $_POST["collection"],
"slug" => $_POST["slug"] );
$queryForm = array("parent.".$_POST["id"] => array('$exists' => 1 ) ); $queryForm = array("parent.".$_POST["id"] => array('$exists' => 1 ) );
if(!empty($controller->costum) && !empty($controller->costum["slug"])) if(!empty($controller->costum) && !empty($controller->costum["slug"]))
$queryForm = array('$and' => array( $queryForm , array("source.key" => $controller->costum["slug"]) ) ) ; $queryForm = array('$and' => array( $queryForm , array("source.key" => $controller->costum["slug"]) ) ) ;
$forms = PHDB::find(Form::COLLECTION, $queryForm , array("name", "mapping") );
$forms = PHDB::find(Form::COLLECTION, $queryForm , array("name") );
$idFs = array(); $idFs = array();
foreach ($forms as $keyF => $valF) { foreach ($forms as $keyF => $valF) {
$idFs[] = $keyF; $idFs[] = $keyF;
} }
$res = Form::getBySourceAndId($controller->costum["slug"]);
$query=array( "form"=>array('$in' => $idFs) ); $searchParams = $_POST;
$searchRegExp = Search::accentToRegex($search); $searchParams["count"] = true;
$querySearch = array(); $answers=Answer::globalAutocomplete($res["form"], $searchParams);
if(!empty($querySearch)) $answerList = Form::listForAdmin($answers["results"]) ;
$query = array('$and' => array( $query , $querySearch ) ) ; $answerList = Answer::getDataAnswers($answerList, $res["forms"]);
if(!empty($panelAdmin['filters'])){ $panelAdmin["context"] = array( "id" => $_POST["id"],
$query = Search::searchFilters($panelAdmin['filters'], $query); "collection" => $_POST["collection"],
} "slug" => $_POST["slug"] );
if(!empty($controller->costum) && !empty($controller->costum["slug"]))
$query = array('$and' => array( $query , array("source.key" => $controller->costum["slug"]) ) ) ;
//Rest::json($query); exit;
$params["typeDirectory"]=[ Answer::COLLECTION ]; $params["typeDirectory"]=[ Answer::COLLECTION ];
$params["results"] = array(); $params["results"]["count"] = $answers["count"];
$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"][Answer::COLLECTION] = $answerList ; $params["results"][Answer::COLLECTION] = $answerList ;
$params["panelAdmin"] = $panelAdmin; $params["panelAdmin"] = $panelAdmin;
$page = "groupAdmin"; $page = "groupAdmin";
...@@ -64,7 +44,5 @@ class DirectoryAction extends CAction ...@@ -64,7 +44,5 @@ class DirectoryAction extends CAction
Rest::json( $params ); Rest::json( $params );
else if(Yii::app()->request->isAjaxRequest) else if(Yii::app()->request->isAjaxRequest)
echo $controller->renderPartial("costum.views.custom.default.".$page,$params,true); echo $controller->renderPartial("costum.views.custom.default.".$page,$params,true);
} }
} }
...@@ -172,13 +172,11 @@ class Answer{ ...@@ -172,13 +172,11 @@ class Answer{
} }
$answerList[$key]["countComment"] = PHDB::count(Comment::COLLECTION, array("contextId"=>$key,"contextType"=>Form::ANSWER_COLLECTION)); $answerList[$key]["countComment"] = PHDB::count(Comment::COLLECTION, array("contextId"=>$key,"contextType"=>Form::ANSWER_COLLECTION));
$localLinks = []; $localLinks = [];
$uids = []; $uids = [];
$todo = 0; $todo = 0;
$done = 0; $done = 0;
$tasksPerson = []; $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"])) { if(!isset($ans["answers"])) {
$percent = 0; $percent = 0;
} else { } else {
...@@ -186,10 +184,8 @@ class Answer{ ...@@ -186,10 +184,8 @@ class Answer{
$answeredInputs = 0; $answeredInputs = 0;
foreach ($forms as $fid => $f){ foreach ($forms as $fid => $f){
$totalInputs += count($f["inputs"]); $totalInputs += count($f["inputs"]);
//echo "|".$f['id']."-fi=".count($f["inputs"]);
if( isset( $ans["answers"][$fid] ) ){ if( isset( $ans["answers"][$fid] ) ){
$answeredInputs += count( $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 //todo lists are on depense for the moment
...@@ -211,7 +207,6 @@ class Answer{ ...@@ -211,7 +207,6 @@ class Answer{
$done++; $done++;
} }
} }
} }
} }
} }
...@@ -223,16 +218,6 @@ class Answer{ ...@@ -223,16 +218,6 @@ class Answer{
if(!isset($globalLinks[$type])) if(!isset($globalLinks[$type]))
$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) { foreach ($ls as $uid => $time) {
if(is_string($uid) && strlen($uid) == 24 && ctype_xdigit($uid)){ if(is_string($uid) && strlen($uid) == 24 && ctype_xdigit($uid)){
if(!in_array($uid, $localLinks[$type] )) if(!in_array($uid, $localLinks[$type] ))
...@@ -255,7 +240,7 @@ class Answer{ ...@@ -255,7 +240,7 @@ class Answer{
$answerList[$key]["todo"] = $todo; $answerList[$key]["todo"] = $todo;
$answerList[$key]["done"] = $done; $answerList[$key]["done"] = $done;
$answerList[$key]["tasksPerson"] = $tasksPerson; $answerList[$key]["tasksPerson"] = $tasksPerson;
$answerList[$key]["canEdit"] = self::canEdit( $ans, $ans["form"], Yii::app()->session["userId"]) ; $answerList[$key]["canEdit"] = self::canEdit( $ans, null, Yii::app()->session["userId"]) ;
} }
} }
return $answerList; return $answerList;
...@@ -265,7 +250,7 @@ class Answer{ ...@@ -265,7 +250,7 @@ class Answer{
public static function csv($elements, $idElt, $valElt, $forms ){ public static function csv($elements, $idElt, $valElt, $forms ){
$elements[$idElt]["id"] = $idElt; $elements[$idElt]["id"] = $idElt;
$elements[$idElt]["user"] = $valElt["user"]; $elements[$idElt]["user"] = $valElt["user"];
$elements[$idElt]["created"] = $valElt["created"]; $elements[$idElt]["created"] = date("d/m/Y", $valElt["created"]);
if(!empty($valElt["answers"])){ if(!empty($valElt["answers"])){
foreach ($forms as $keyF => $valF) { foreach ($forms as $keyF => $valF) {
if(!empty($valF["id"]) && !empty($valElt["answers"][$valF["id"]])){ if(!empty($valF["id"]) && !empty($valElt["answers"][$valF["id"]])){
......
...@@ -663,6 +663,7 @@ class Form { ...@@ -663,6 +663,7 @@ class Form {
$form = $params["form"] ; $form = $params["form"] ;
else else
$form = PHDB::findOneById( Form::COLLECTION, $_GET["form"] ); $form = PHDB::findOneById( Form::COLLECTION, $_GET["form"] );
$params["parentForm"] = $form; $params["parentForm"] = $form;
$communityLinks = array(); $communityLinks = array();
if(!empty($form["parent"])){ if(!empty($form["parent"])){
......
...@@ -166,7 +166,7 @@ if( $mode != "pdf" ){ ...@@ -166,7 +166,7 @@ if( $mode != "pdf" ){
<?php } ?> <?php } ?>
</div> </div>
<?php } <?php }
}
?> ?>
<script type="text/javascript"> <script type="text/javascript">
...@@ -285,3 +285,6 @@ if( $mode != "pdf" ){ ...@@ -285,3 +285,6 @@ if( $mode != "pdf" ){
</script> </script>
<?php
}
?>
\ No newline at end of file
<?php <?php
$styleT = ( ($mode == "pdf") ? " border : 1px solid black ;" : ""); //$styleT = ( ($mode == "pdf") ? " border : 1px solid black ;" : "");
//var_dump($styleT); //var_dump($styleT);
$colspanplus = (($mode == "r" || $mode == "pdf") ? 0 : 2); $colspanplus = (($mode == "r" || $mode == "pdf") ? 0 : 2);
?> ?>
...@@ -16,125 +16,118 @@ $colspanplus = (($mode == "r" || $mode == "pdf") ? 0 : 2); ...@@ -16,125 +16,118 @@ $colspanplus = (($mode == "r" || $mode == "pdf") ? 0 : 2);
<?php echo $info ?> <?php echo $info ?>
<?php <?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> <thead>
<?php <?php
if( count($answers)>0 ){ ?> if( count($answers)>0 ){ ?>
<tr> <tr>
<?php <?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 = "";
foreach ($properties as $i => $inp) { foreach ($properties as $i => $inp) {
$tds .= "<td>"; echo "<th>".$inp["placeholder"]."</th>";
} ?>
if( $i == "price" ) { <?php
if(!empty($a["price"])) if($mode != "r" && $mode != "pdf"){ ?>
$tds .= "<span id='price".$q."'>".$a["price"]."€</span>"; <th></th>
if( $paramsData["estimate"] ) <?php } ?>
{ </tr>
$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>"; <?php } ?>
if( isset($a["estimates"] )) </thead>
{ <tbody class="directoryLines">
foreach ( $a["estimates"] as $uid => $esti ) <?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"; foreach ( $a["estimates"] as $uid => $esti )
$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>"; {
$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'>"; if(isset($answers)){
echo "<td colspan=".(count( $paramsData["amounts"] )+2)." style='text-align:right'> TOTAL : </td>"; foreach ( $answers as $q => $a ) {
if($mode != "r" && $mode != "pdf") foreach ($totalMap as $i => $tot) {
echo "<td colspan='".$colspanplus."''>".trim(strrev(chunk_split(strrev($total),3, ' ')))." €</td>"; if(isset($a[$i]))
else $totalMap[$i] = $tot + $a[$i];
echo "<td>".trim(strrev(chunk_split(strrev($total),3, ' ')))." €</td>"; }
echo "</tr>"; }
}
//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> </tbody>
</table> </table>
</div> </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"> <div class="form-group">
<?php <?php
if($mode == "r" || $mode == "pdf"){ ?> if($mode == "r" || $mode == "pdf"){ ?>
...@@ -31,6 +26,8 @@ $colspanplus = (($mode == "r" || $mode == "pdf") ? 0 : 2); ...@@ -31,6 +26,8 @@ $colspanplus = (($mode == "r" || $mode == "pdf") ? 0 : 2);
<?php <?php
if($mode != "r" && $mode != "pdf"){ ?> if($mode != "r" && $mode != "pdf"){ ?>
<th></th> <th></th>
<?php } else { ?>
<th>State</th>
<?php } ?> <?php } ?>
</tr> </tr>
<?php } ?> <?php } ?>
...@@ -153,40 +150,47 @@ $colspanplus = (($mode == "r" || $mode == "pdf") ? 0 : 2); ...@@ -153,40 +150,47 @@ $colspanplus = (($mode == "r" || $mode == "pdf") ? 0 : 2);
echo "<tr id='".$kunik.$q."' class='".$kunik."Line text-center' style='".$trStyle."'>"; echo "<tr id='".$kunik.$q."' class='".$kunik."Line text-center' style='".$trStyle."'>";
echo $tds; echo $tds;
if($mode != "r" && $mode != "pdf"){ ?> if($mode != "r" && $mode != "pdf"){ ?>
<td>
<td> <?php
<?php $color = "default";
$color = "default"; $valbl = "?";
$valbl = "?"; $tool= "En attente de validation";
$tool= "En attente de validation"; if( isset($a["validFinal"]["valid"]) ){
if( isset($a["validFinal"]["valid"]) ){ if( $a["validFinal"]["valid"] == "validated" ){
if( $a["validFinal"]["valid"] == "validated" ){ $color = "success";
$color = "success"; $valbl = "V";
$valbl = "V"; $tool="Validé sans réserve";
$tool="Validé sans réserve"; } else if( $a["validFinal"]["valid"] == "reserved" ){
} else if( $a["validFinal"]["valid"] == "reserved" ){ $color = "warning";
$color = "warning"; $valbl = "R";
$valbl = "R"; $tool="Validé avec réserves";
$tool="Validé avec réserves"; } else if( $a["validFinal"]["valid"] == "refused" ){
} else if( $a["validFinal"]["valid"] == "refused" ){ $color = "danger";
$color = "danger"; $valbl = "NV";
$valbl = "NV"; $tool="Non validé";
$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>
</td> <?php
<?php
} }
$ct++; $ct++;
echo "</tr>"; echo "</tr>";