<?

include '../../config.php';
include '../../func.php';
head();

switch ( $_GET['mod'] ) {
    
    default:
    
    echo link2 . 'Ошибочный запрос' . div;
    
    break;
    
    
    case '1':
    
    $result = mysql_query("DELETE FROM `chat_msg`");
    
    if ( $result != NULL ) {
   $result = mysql_query("SELECT * FROM room");
    while($room = mysql_fetch_assoc($result)){
        $msg = 'Комнаты очищены';
        mysql_query("INSERT INTO `chat_msg` SET `msg` = '".$msg."', `ot_user` = '".$bot['system']."', `room` = '".$room['id']."'");        
        header('Location: index.php?mod=1&res=good');
        
 
    }
        
    } else {
        
        header('Location: index.php?mod=1&res=error');
        
    }
    
    break;
    
    
    ####################################################
    
    case '2':
    
    if ( empty ( $_POST['submit'] ) ) {
        
        echo link2 . '<form action="clean.php?mod=2" method="post" name="form">
        <b>Время, через которое произойдет отчистка:</b> [Минуты]<br/>
        <input name="time" type="text" maxlength="25"/><br/>';
        echo '<input name="submit" class="submit" type="submit" value="Чистка" /></form>' . div;
        
    } else {
        
        $time = num($_POST['time']);
        $res = time() + ( $time * 60 );
        $result = mysql_query("UPDATE `config` SET `room_clean` = '".$res."'");
        
        if ( $result != NULL ) {
    $result = mysql_query("SELECT * FROM room");
    while($room = mysql_fetch_assoc($result)){
        $msg = 'Комнаты будут очищены через '.$time.' мин.';
        mysql_query("INSERT INTO `chat_msg` SET `msg` = '".$msg."', `ot_user` = '".$bot['system']."', `room` = '".$room['id']."'");
    }            
            header('Location: index.php?mod=2&res=good');
            

            
        } else {
            
            header('Location: index.php?mod=2&res=error');
            
        }
    }
    
    break;
    
    
}