<?
include '../config.php';
include '../func.php';

head();
aut();
ban();

echo head . 'Рассылка' . div . katalog;

if ( isset($_POST['submit']) ) {
    
    $msg = html($_POST['msg']);
    
    
if ( $_POST['po'] == 0 ) { 
$result = mysql_query("SELECT * FROM room");
while($room = mysql_fetch_assoc($result)){
    
    mysql_query("INSERT INTO `chat_msg` SET `msg` = '".$msg."', `ot_user` = '".$id_session."', `room` = '".$room['id']."', `date` = '".time()."'");
    echo katalog . 'Рассылка прошла успешно' . div;
}

} else {
    $res = mysql_query("SELECT * FROM profile");
    while($user = mysql_fetch_assoc($res)){
    mysql_query("INSERT INTO `mail` SET `to_user` = '".$user['id']."', `ot_user` = '".$id_session."', `msg` = '".$msg."', `status` = 0, `date` = '".(time() + 120)."'");
    }
    echo katalog . 'Рассылка прошла успешно' . div;
}


}

echo '<form action="send.php" method="post" name="form">';
echo '<textarea id="tarea" name="msg" cols="30" rows="5" style="width: 99%;"></textarea><br/>';

echo '<b>По:</b><br/><select name="po">
<option value="0">Комнатам</option>
<option value="1">Личке</option>
</select><br/ >';
    
echo '<input name="submit" type="submit" class="button" value="Разослать" /></form>';

navig();
foot();
?>

