';
exit;
}
}
}
}else{
// Si pas de start_date, on prend le mois courant
$start_date = new DateTime('first day of this month');
$end_date = new DateTime('last day of this month');
}
$start_date->setTime(0,0,0);
if (isset($end_date)){
$nb_col = 4;
if ($end_date < $today){
$days_left = 0;
}else{
$dteDiff = $end_date->diff($today);
$days_left = $dteDiff->format('%a');
}
}
$col_width = $bar_width/$nb_col;
$icon_x = $col_width/2-$icon_size/2;
// Vérification du format de la pubkey
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&comment=don&redirect_url=https%3A%252F%252F' . $api_node . '&cancel_url=https%3A%252F%252F' . $api_node;
$display_pubkey = (!empty($_GET['display_pubkey']));
if ($display_pubkey){
$svg_height += $whitespace;
}
// Génération du QRcode
if ($display_qrcode){
$qrcode_path = 'img/qrcodes/' . $pubkey . '.svg';
if (!file_exists($qrcode_path)){
QRcode::svg($pubkey, $qrcode_path);
}
$qrcode_width = 111;
$svg_width += $qrcode_width + $whitespace;
}
}
else {
echo '
'.tr('error_pubkey_invalid').'
';
exit;
}
}else{
echo '
'.tr('error_pubkey_missing').'
';
exit;
}
// Vérification du format de la valeur cible à atteindre
if (!empty($_GET['target'])){
$target = (int)$_GET['target'];
if (!is_int($target)){
echo '
'.tr('error_target_not_int').'
';
exit;
}elseif ($target<=0){
echo '
'.tr('error_target_negative').'
';
exit;
}
}else{
echo '
'.tr('error_target_missing').'
';
exit;
}
// Récupération des transactions entrantes entre la date de début et la date du jour
$start_timestamp = $start_date->getTimestamp();
$today_timestamp = $today->getTimestamp();
$url_json = 'https://' . $node . '/tx/history/' . $pubkey . '/times/' . $start_timestamp . '/' . $today_timestamp;
$json = @file_get_contents($url_json);
if ($json === false){
echo '
'.tr('error_connect_node').'
';
exit;
}
$json = json_decode($json);
$transactions = $json->history->received;
$total = 0;
$donneurs = [];
$tmp_timestamp = $start_timestamp;
$array_final = [];
foreach ($transactions as $transaction){
$donneur = $transaction->issuers[0];
if ($donneur != $pubkey){
if(!in_array($donneur, $donneurs)){
array_push($donneurs, $donneur);
}
$outputs = $transaction->outputs;
foreach ($outputs as $output){
if (strstr($output,$pubkey)){
$timestamp = $transaction->blockstampTime;
$output = explode(':', $output);
$montant_transaction = $output[0]/100;
if ($timestamp != $tmp_timestamp){
array_push($array_final, ['t'=>$tmp_timestamp*1000, 'y'=>(string) $total]);
}
$total += $montant_transaction;
$tmp_timestamp = $timestamp;
}
}
}
}
$donors = count($donneurs);
// Vérification de l'unité
$unit = (!empty($_GET['unit']))
? ((!in_array($_GET['unit'], $units)) ? 'quantitative' : $_GET['unit'])
: 'quantitative';
// Si l'unité est relative
if ($unit == 'relative'){
// On récupère le dernier block qui contient le DU
$url_json = 'https://' . $node . '/blockchain/with/ud';
$json = file_get_contents($url_json);
$json = json_decode($json);
$last_block_with_ud = end($json->result->blocks);
// Puis on récupère le montant du DU pour mettre à jour les données
$url_json = 'https://' . $node . '/blockchain/block/' . $last_block_with_ud;
$json = file_get_contents($url_json);
$json = json_decode($json);
$ud = $json->dividend/100;
$total = round($total/$ud);
}
$percentage = round($total/$target,2);
$percentage_bar = ($percentage>1) ? 1 : $percentage;
$bar_innerfill = $percentage_bar*($bar_width - 2*$bar_border);
?>