JavaScript
1
Вклад в тег
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,'https://api.direct.yandex.ru/live/v4/json/');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,'{
"method": "AccountManagement",
"token": "AQAAAAAW-*******************************",
"param": {"SelectionCriteria": {}, "Action": "Get"}}'); //Post Fields
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$headers = [
'POST /json/v5/ads/ HTTP/1.1',
'Host: api.direct.yandex.com',
'Authorization: Bearer AQAAAAAW-**********************************',
'Accept-Language: ru',
'Client-Login: *************@yandex.ru',
'Content-Type: application/json; charset=utf-8',
];
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$server_output = curl_exec ($ch);
curl_close ($ch);
$balance_direct_miramall = json_decode($server_output,true);
<div class="calculator_table">
<select id="calc-month">
<option value="0">January</option>
<option value="1">February</option>
<option value="2">March</option>
<option value="3">April</option>
<option value="4">May</option>
<option value="5">June</option>
<option value="6">July</option>
<option value="7">August</option>
<option value="8">September</option>
<option value="9">October</option>
<option value="10">November</option>
<option value="11">December</option>
</select>
<select id="calc-day"></select>
<select id="calc-year"></select>
<p align="center"><button onclick="calculate();return false;">Calculate</button></p>
<div id="results"></div>
</div>
<script>
window.onload = function()
{
var npw = new Date();
var g = npw.getFullYear();
var m = npw.getMonth();
var da = npw.getDate();
for (var y = 2014; y < 2050; y++ )
{
document.getElementById('calc-year').innerHTML += '<option value="'+y+'">' + y +'</option>';
}
for (var d = 1; d <= 31; d++ )
{
document.getElementById('calc-day').innerHTML += '<option value="'+d+'">' + d +'</option>';
}
document.getElementById('calc-year').value=g;
document.getElementById('calc-month').value=m;
document.getElementById('calc-day').value=da;
}
function calculate()
{
var monthNames = new Array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');
var day = Number(document.getElementById('calc-day').value);
var month = Number(document.getElementById('calc-month').value);
var year = Number(document.getElementById('calc-year').value);
var nextday = day + 280;
var initial = new Date(Date.UTC( year, month, day, 0, 0, 0));
var predicted = new Date(Date.UTC( year, month, nextday, 0, 0, 0));
var now = new Date();
var formated = monthNames[predicted.getMonth()] + ' ' + predicted.getDate() + ', ' + predicted.getFullYear();
var leftDays = ( predicted.getTime() - now.getTime() ) / (24*3600*1000);
var currentWeeks = (now.getTime() - initial.getTime()) / (7*24*3600*1000)
document.getElementById('results').innerHTML = '<p>Your estimated due date is ' + formated + '</p><p>Days left to your date: '+ parseInt(leftDays) +'</p><p>Weeks of pregnancy: '+ Math.round(currentWeeks) +'</p>';
}
</script>