Commit 67b825f0 authored by Chancellier Pierre-Jean's avatar Chancellier Pierre-Jean
Browse files

Correction de bugs et amélioration du graphique

parent 86bb16f8
......@@ -45,7 +45,7 @@
echo '<div>'.tr('error_date_end_invalid').'</div>';
exit;
}elseif ($end_date < $start_date) {
echo '<div>'.tr('error_date_end_missing').'</div>';
echo '<div>'.tr('error_date_end_invalid').'</div>';
exit;
}elseif ($end_date < $today){
$days_left = 0;
......@@ -60,6 +60,7 @@
if (!empty($_GET['pubkey'])){
if (preg_match($format_pubkey, $_GET['pubkey'])){
$pubkey = $_GET['pubkey'];
$contribution_url = 'https://' . $api_node . '/api/#/v1/payment/' . $pubkey . '?amount=10|20|50|100|1000&amp;comment=don&amp;redirect_url=https%3A%252F%252F' . $api_node . '&amp;cancel_url=https%3A%252F%252F' . $api_node;
$display_pubkey = (!empty($_GET['display_pubkey']));
$display_button = (!empty($_GET['display_button']));
$display_graph = (!empty($_GET['display_graph']));
......@@ -96,14 +97,17 @@
// Récupération des transactions entrantes entre la date de début et la date du jour
$url_json = 'https://' . $node . '/tx/history/' . $pubkey . '/times/' . $start_date->getTimestamp() . '/' . $today->getTimestamp();
$json = file_get_contents($url_json);
$json = @file_get_contents($url_json);
if ($json === false){
echo '<div>'.tr('error_connect_node').'</div>';
exit;
}
$json = json_decode($json);
$transactions = $json->history->received;
$total = 0;
$donneurs = [];
$current_date = $start_date->format($format);
$array_dates = [$current_date];
$array_montants = [];
$current_date = DateTime::createFromFormat($format, $_GET['start_date']);
$array_montants = [0];
foreach ($transactions as $transaction){
$donneur = $transaction->issuers[0];
if ($donneur != $pubkey){
......@@ -114,22 +118,35 @@
foreach ($outputs as $output){
if (strstr($output,$pubkey)){
$timestamp = $transaction->blockstampTime;
$date_transaction = date('d/m/Y', $timestamp);
if ($date_transaction != $current_date){
array_push($array_dates, $date_transaction);
array_push($array_montants, $total);
$current_date = $date_transaction;
}
$date_transaction = new DateTime();
$date_transaction->setTimestamp($timestamp);
$output = explode(':', $output);
$montant = $output[0]/100;
$total += $montant;
$montant_transaction = $output[0]/100;
if ($display_graph){
if ($date_transaction->format($format) != $current_date->format($format)){
// On remplit les éventuels jours manquants depuis le jour de la dernière transaction
while ($current_date->format($format) < $date_transaction->format($format)){
array_push($array_montants, $total);
$current_date->add(new DateInterval('P1D'));
}
$current_date = clone $date_transaction;
}
}
$total += $montant_transaction;
}
}
}
}
array_push($array_montants, $total);
$donors = count($donneurs);
if ($display_graph){
// On complète le tableau des montants jusqu'à aujourd'hui
while ($current_date <= $today){
array_push($array_montants, $total);
$current_date->add(new DateInterval('P1D'));
}
}
// Vérification de l'unité
$unit = (!empty($_GET['unit']))
? ((!in_array($_GET['unit'], $units)) ? 'quantitative' : $_GET['unit'])
......@@ -152,7 +169,6 @@
}
$percentage = round($total/$target*100);
$contribution_url = 'https://' . $api_node . '/api/#/v1/payment/' . $pubkey . '?amount=10|20|50|100|1000&amp;comment=don&amp;redirect_url=https%3A%252F%252F' . $api_node . '&amp;cancel_url=https%3A%252F%252F' . $api_node;
?>
<!DOCTYPE html>
<html lang="<?php echo $lang; ?>">
......@@ -202,14 +218,23 @@
<div class="row">
<div class="col">
<a class="btn btn-success" href="<?php echo $contribution_url; ?>" target="_blank" role="button" style="width: 100%;">
<i class="fas fa-check"></i><span>&nbsp;<?php echo tr('contribute'); ?></span>
<i class="fas fa-check"></i><span>&nbsp;<?php echo tr('label_contribute'); ?></span>
</a>
</div>
</div>
<?php } ?>
</div>
</section>
<?php if ($display_graph){ ?>
<?php
if ($display_graph){
// Boucle pour avoir toutes les dates, du début du financement jusqu'à aujourd'hui, en abscisse du graph
$array_dates = [];
$tmp_date = clone $start_date;
while ($tmp_date <= $today){
array_push($array_dates, $tmp_date->format($format));
$tmp_date->add(new DateInterval('P1D'));
}
?>
<script src="lib/js/chart.min.js"></script>
<script>
window.onload = function() {
......@@ -226,18 +251,17 @@
labels: <?php echo json_encode($array_dates); ?>,
datasets: [{
label: "<?php echo tr('graph_title'); ?>",
steppedLine: false,
data: data,
borderColor: '#0099FF',
fill: false,
lineTension: 0
},
{
label: "<?php echo tr('graph_target'); ?>",
steppedLine: false,
data: Array.apply(null, new Array(<?php echo count($array_dates); ?>)).map(Number.prototype.valueOf, <?php echo $target; ?>),
borderColor: 'rgb(255, 99, 132)',
radius: 0,
fill: false,
fill: false
}]
},
options: {
......
<?php
$ttr = array(
'error_connect_node' => 'The connection to the duniter node failed. Change the used node.',
'error_date_start_invalid' => 'Invalid start date. Please check your syntax.',
'error_date_start_missing' => 'Missing start date. Please check your syntax.',
'error_date_end_invalid' => 'Invalid end date. Please check your syntax.',
......@@ -17,7 +18,7 @@ $ttr = array(
'ud' => 'UD',
'label_ontotal' => 'Over a total of {{total}} {{unit}}',
'label_remaining_d' => 'days remaining',
'label_contribute' => 'Contribute now',
'label_contribute' => 'Contribute now !',
'graph_title' => 'Evolution of the funding',
'graph_target' => 'Target'
);
......
<?php
$ttr = array(
'error_connect_node' => 'La rilato al la nodo Duniter malsukcesis. Modifu la uzatan nodon.',
'error_date_start_invalid' => 'Erara dato de komenciĝo. Kontrolu vian sintakson.',
'error_date_start_missing' => 'Mankanta dato de komenciĝo. Kontrolu vian sintakson.',
'error_date_end_invalid' => 'Erara fin-dato. Kontrolu vian sintakson.',
......@@ -17,7 +18,7 @@ $ttr = array(
'ud' => 'UD',
'label_ontotal' => 'Celo: {{total}} {{unit}}',
'label_remaining_d' => 'tagoj restas',
'label_contribute' => 'Kontribuu nun',
'label_contribute' => 'Kontribuu nun !',
'graph_title' => 'Evoluo de la financado',
'graph_target' => 'Celo'
);
......
<?php
$ttr = array(
'error_connect_node' => 'La connexion au noeud duniter a échoué. Modifiez le noeud utilisé.',
'error_date_start_invalid' => 'La date de début est incorrecte. Vérifiez votre syntaxe.',
'error_date_start_missing' => 'Il manque la date de début. Vérifiez votre syntaxe.',
'error_date_end_invalid' => 'La date de fin est incorrecte. Vérifiez votre syntaxe.',
......@@ -17,7 +18,7 @@ $ttr = array(
'ud' => 'DU',
'label_ontotal' => 'Sur un total de {{total}} {{unit}}',
'label_remaining_d' => 'jours restants',
'label_contribute' => 'Contribuez maintenant',
'label_contribute' => 'Contribuez maintenant !',
'graph_title' => 'Évolution du financement',
'graph_target' => 'Objectif'
);
......
......@@ -3,7 +3,7 @@
body{margin: 0;line-height: 1.5;font-weight:400;font-family: -apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,"Helvetica Neue",Arial,"Noto Sans",sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol","Noto Color Emoji";}
a{color: #007bff;text-decoration: none; background-color: transparent;}
p{margin-top: 0;margin-bottom: 1rem;}
img{vertical-align: middle;border-style: none;}
img{vertical-align: middle;border-style: none;margin-bottom: 20px;}
.container{padding: 0 15px;margin: 0 auto;}
.row{display: -ms-flexbox;display: flex;-ms-flex-wrap: wrap;flex-wrap: wrap;margin: 0 -15px;}
.col{-ms-flex-preferred-size: 0;flex-basis: 0;-ms-flex-positive: 1;flex-grow: 1;max-width: 100%;}
......@@ -44,6 +44,7 @@ img{vertical-align: middle;border-style: none;}
.fa-user::before{content: "\f007";}
.fa-money-bill-alt::before{content: "\f3d1";}
.fa-calendar-alt::before {content: "\f073";}
.fa-check::before {content: "\f00c";}
/* CSS PERSO */
.wrapper-numbers {padding: 60px 0 45px;text-align: center;font-size: 16px;overflow: hidden;}
......
Supports Markdown
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