Ver Mensaje Individual
  #3 (permalink)  
Antiguo 07/12/2008, 16:58
Avatar de pato12
pato12
 
Fecha de Ingreso: septiembre-2007
Ubicación: Salta
Mensajes: 1.620
Antigüedad: 16 años, 6 meses
Puntos: 101
Respuesta: [APORTE]Crear un chat con php+ajax, (con salas y muestra los usuarios onli

chat.js (continuación)
Código HTML:
	flag=0;
function addTex(let){
	var forms="mensaje";
	var story = $(forms).value;
	if(let=="BACK"){
		story=story.substring(0, story.length-1);
		$(forms).value=story;
		$(forms).focus();
	}else if(flag==1){
		story+=let.toUpperCase();
		flag=0;
		$(forms).value=story;
		$(forms).focus();
	}else{
story+=let;
flag=0;
$(forms).value=story;
$(forms).focus();
}
}
function capIt(){
flag=1;
}
// BBcodes
function escribir_web(){
title = prompt('Titulo:',"");
if(title!=null){
web = prompt('Direcion web:',"http://");
if(web=="http://" || web==null){
alert('No as escrito una direccion valida.');
}else{
addTex('[url='+web+']'+title+'[/url]');
}
}
}
function b(){
texto = prompt('Texto en negritas:',"");
if(texto==null || texto==""){
		alert("Nada");
		}
else{
addTex('[b]'+texto+'[/b]');
}
}
function it(){
texto = prompt('Texto:',"");
if(texto==null || texto==""){
		alert("Nada");
		}
else{
addTex('[i]'+texto+'[/i]');
}
}
function u(){
texto = prompt('Texto subrayado:',"");
if(texto==null || texto==""){
		alert("Nada");
		}
else{
addTex('[u]'+texto+'[/u]');
}
}
function imagen(){
image = prompt('Direcion de la imagen:',"http://");
if(image==null || image==""){
		alert("Nada");
		}
else{
addTex('[img]'+image+'[/img]');
}
}
function colo(){
	texto = prompt('Texto:',"");
		if(texto==null || texto==""){
		alert("Nada");
		}
else{
color = prompt('Color:  (Ej.: red,blue o puede ser html)',"");
if(color==null || color==""){
}else{
addTex('[color='+color+']'+texto+'[/color]');
}
}
}
/////////////////////////////////////////////////
function html(d,t){
	$(d).innerHTML=t;
}
function restartClass(){
var lis = document.getElementById("sala").getElementsByTagName("div");
		for (i=0; i<lis.length; i++) {
			lis[i].className = "sala";
		}
}
function selecSala(){
	var lis = document.getElementById("sala").getElementsByTagName("div");
	for (i=0; i<lis.length; i++) {
		lis[i].onclick=function() {
			restartClass();
			this.className="sala_ac";
			sala=this.getAttribute('sala');
			verGET('cargando');
			ir('inter.php','r='+Math.random()+'&t=ver&sala='+sala,'coment_tr','POST',false,null,true,'cargando',true,actualizarList());
			ir('inter.php','r='+Math.random()+'&t=user&sala='+sala,'usuarios','POST',false,null,true,'cargando');
			ir('inter.php','r='+Math.random()+'&t=conectar&name='+user+'&sala='+sala,null,'POST',false,null,true,'cargando',false,null,true);
			html('salaET',sala);
		}
	}
}
function envAUT(e) { 
tecla = (document.all) ? e.keyCode :e.which; 
	if(tecla==13 && !e.shiftKey){
	enviarGET($('mensaje'));
	return false;
	}
return true;
}
function verSalGET(){
	$('users').className="tabs";
	$('salas').className="tabs_ac";
	$('sala').style.display="block";
	$('usuarios').style.display="none";
}
function verUGET(){
	$('users').className="tabs_ac";
	$('salas').className="tabs";
	$('usuarios').style.display="block";
	$('sala').style.display="none";
}
window.onload=function(){
makeDraggable('bbcode'); 
makeDraggable('config'); 
$('mensaje').disabled = !this.checked;
$('enviar').disabled = !this.checked;
$('nik').innerHTML=" <strong>Nick: </strong>"+user;
addEvent($('users'),'click',verUGET,false);
addEvent($('salas'),'click',verSalGET,false);
selecSala();
verGET('box');
cerrarGET('cargando');
}
config.php
Código PHP:
<?php
$seg_inac
=50;// Segundos que si el usuario no hace nada, se lo considera incativo
$bd_servidor "localhost";
$bd_usuario "root";
$bd_contrasenya "clave";
$bd_bdname "BD";
$con = @mysql_connect($bd_servidor,$bd_usuario,$bd_contrasenya);
$bd_conect=@mysql_select_db($bd_bdname,$con);
if(!
$con || !$bd_conect){
exit(
'Servidor no disponible, disculpe las molestias.');
}
?>
Tablas:
Código:
CREATE TABLE `contenido` (
  `id` int(10) NOT NULL AUTO_INCREMENT,
  `name` varchar(100) NOT NULL,
  `cont` longtext NOT NULL,
  `fecha` varchar(100) NOT NULL,
  `sala` varchar(100) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=136 ;


CREATE TABLE `online` (
  `id` int(10) NOT NULL AUTO_INCREMENT,
  `time` varchar(100) NOT NULL,
  `user` varchar(100) NOT NULL,
  `sala` varchar(100) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=173 ;
Continua...
__________________
Half Music - www.halfmusic.com