Переделать модуль случайной даты под PHP 7
berch 07.08.2018 Стол заказов 880 3 комментария
Здравствуйте! Кто может переделать модуль случайной даты под PHP 7. Вот код:
<?php
set_time_limit(0);
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.2/themes/smoothness/jquery-ui.css" />
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.2/jquery-ui.js"></script>
<link rel="stylesheet" href="/resources/demos/style.css" />
<script>
$(function() {
$( "#start" ).datepicker();
$( "#finish" ).datepicker();
});
</script>
</head>
<body>
<form action="" method="post">
<p>Начальная дата: <input type="text" name="start" id="start" /> Конечная дата: <input type="text" name="finish" id="finish" /> <input type="submit" name="submit" value=" Сгенерировать " /></p>
</form>
<?php
if (isset($_POST['submit']) && $_POST['start'] != '' && $_POST['finish'] != '')
{
$start_array = explode('/', $_POST['start']);
$start = array();
$start['day'] = $start_array[1];
$start['month'] = $start_array[0];
$start['year'] = $start_array[2];
$start_time = strtotime("{$start['year']}-{$start['month']}-{$start['day']}");
$finish_array = explode('/', $_POST['finish']);
$finish = array();
$finish['day'] = $finish_array[1];
$finish['month'] = $finish_array[0];
$finish['year'] = $finish_array[2];
$finish_time = strtotime("{$finish['year']}-{$finish['month']}-{$finish['day']}");
class db {}
require_once('engine/data/dbconfig.php');
if (!mysql_connect(DBHOST,DBUSER, DBPASS) || !mysql_select_db(DBNAME)) trigger_error('Can not connect to database',E_USER_ERROR);
$query = "SELECT * FROM `" . PREFIX . "_post`";
$result = mysql_query($query) or trigger_error('SQL: Query error at line '.__LINE__, E_USER_ERROR);
if (mysql_num_rows($result) > 0)
{
while ($row = mysql_fetch_assoc($result))
{
if (file_exists('stop.txt'))
die('Cancel by the user!');
$post_time = date("Y-m-d H:i:s", rand($start_time, $finish_time));
$query = "UPDATE `" . PREFIX . "_post` SET `date`= '$post_time' WHERE `id`= ". intval($row['id']);
mysql_query($query) or trigger_error('SQL: Query error at line '.__LINE__,E_USER_ERROR);
}
}
echo '<h3>Готово!</h3>';
}
?>
</body>
</html>