94 lines
2.2 KiB
PHP
94 lines
2.2 KiB
PHP
<?php
|
|
|
|
function maintenanceActive()
|
|
{
|
|
if (!maintenanceMode()){
|
|
$link = mysql_connect(MYSQL_HOST, MYSQL_USER, MYSQL_PASS);
|
|
if (!$link) {
|
|
return false;
|
|
}
|
|
$sql = "INSERT INTO sdv1.maintenance (mode, countMaintenance, dateEven) ".
|
|
"VALUES (1, 0, '".date('Y-m-d H:i:s')."')";
|
|
if (mysql_query($sql, $link)){
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
function maintenanceDesactive()
|
|
{
|
|
if(maintenanceMode()){
|
|
$link = mysql_connect(MYSQL_HOST, MYSQL_USER, MYSQL_PASS);
|
|
if (!$link) {
|
|
return false;
|
|
}
|
|
$sql = "INSERT INTO sdv1.maintenance (mode, countMaintenance, dateEven) ".
|
|
"VALUES (0, 0, '".date('Y-m-d H:i:s')."')";
|
|
if (mysql_query($sql, $link)){
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
function maintenanceMode($error = false)
|
|
{
|
|
$countEvenMax = 70;
|
|
$link = mysql_connect(MYSQL_HOST, MYSQL_USER, MYSQL_PASS);
|
|
if (!$link) {
|
|
return false;
|
|
}
|
|
$sql = 'SELECT * FROM sdv1.maintenance ORDER BY dateEven DESC, LIMIT 1';
|
|
$result = mysql_query($sql, $link);
|
|
if (!$result) {
|
|
return false;
|
|
}
|
|
if (mysql_num_rows($result) == 0){
|
|
return false;
|
|
}
|
|
$info = mysql_fetch_assoc($result);
|
|
if ($info[0]['countMaintenance']>=$countEventMax || $info[0]['mode']==1){
|
|
if ($error &&
|
|
$info[0]['countMaintenance']>=$countEventMax && $info[0]['mode']==0)
|
|
{
|
|
$sql = "UPDATE sdv1.maintenance SET mode=1, ".
|
|
"dateEven=".date('Y-m-d H:i:s').
|
|
" WHERE ".$info[0]['id'];
|
|
if (mysql_query($sql, $link)){
|
|
return true;
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
function maintenanceIncrement()
|
|
{
|
|
$link = mysql_connect(MYSQL_HOST, MYSQL_USER, MYSQL_PASS);
|
|
if (!$link) {
|
|
return false;
|
|
}
|
|
$sql = 'SELECT id FROM sdv1.maintenance ORDER BY dateEven DESC, LIMIT 1';
|
|
$result = mysql_query($sql, $link);
|
|
if (!$result) {
|
|
return false;
|
|
}
|
|
if (mysql_num_rows($result)==0){
|
|
$sql = "INSERT INTO sdv1.maintenance (mode, countMaintenance, dateEven) ".
|
|
"VALUES (0, 0, '".date('Y-m-d H:i:s')."')";
|
|
$result = mysql_query($sql, $link);
|
|
}
|
|
$info = mysql_fetch_assoc($result);
|
|
$sql = "UPDATE sdv1.maintenance SET countMaintenance=countMaintenance+1, ".
|
|
"dateEven=".date('Y-m-d H:i:s');
|
|
" WHERE ".$info[0]['id'];
|
|
if (mysql_query($sql, $link)){
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
|