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
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"]);
......
......@@ -15,48 +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']));
}
$panelAdmin["context"] = array( "id" => $_POST["id"],
"collection" => $_POST["collection"],
"slug" => $_POST["slug"] );
$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") );
$forms = PHDB::find(Form::COLLECTION, $queryForm , array("name", "mapping") );
$idFs = array();
foreach ($forms as $keyF => $valF) {
$idFs[] = $keyF;
}
$res = Form::getBySourceAndId($controller->costum["slug"]);
$query=array( "form"=>array('$in' => $idFs) );
$searchRegExp = Search::accentToRegex($search);
$querySearch = array();
if(!empty($querySearch))
$query = array('$and' => array( $query , $querySearch ) ) ;
$searchParams = $_POST;
$searchParams["count"] = true;
$answers=Answer::globalAutocomplete($res["form"], $searchParams);
$answerList = Form::listForAdmin($answers["results"]) ;
$answerList = Answer::getDataAnswers($answerList, $res["forms"]);
if(!empty($panelAdmin['filters'])){
$query = Search::searchFilters($panelAdmin['filters'], $query);
}
$panelAdmin["context"] = array( "id" => $_POST["id"],
"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["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";
......@@ -64,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,7 +240,7 @@ class Answer{
$answerList[$key]["todo"] = $todo;
$answerList[$key]["done"] = $done;
$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;
......@@ -265,7 +250,7 @@ class Answer{
public static function csv($elements, $idElt, $valElt, $forms ){
$elements[$idElt]["id"] = $idElt;
$elements[$idElt]["user"] = $valElt["user"];
$elements[$idElt]["created"] = $valElt["created"];
$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"]])){
......
......@@ -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"])){
......
......@@ -166,7 +166,7 @@ if( $mode != "pdf" ){
<?php } ?>
</div>
<?php }
}
?>
<script type="text/javascript">
......@@ -285,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
}
$ct++;
echo "</tr>";
......
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