initialise(); $db =& JFactory::getDBO(); if (file_exists(JPATH_SITE.'/modules/mod_achat/languages/russian.php')) { include_once(JPATH_SITE.'/modules/mod_achat/languages/russian.php'); } else { include_once(JPATH_SITE.'/modules/mod_achat/languages/english.php'); } $limit = intval(JArrayHelper::getValue($_GET, 'limit')); $myid = intval(JArrayHelper::getValue($_GET, 'userid')); $aid = intval(JArrayHelper::getValue($_GET, 'aid')); $msgid = intval(JArrayHelper::getValue($_GET, 'msgid')); $lastid = intval(JArrayHelper::getValue($_GET, 'lastid')); $word = intval(JArrayHelper::getValue($_GET, 'word')); $nick = JArrayHelper::getValue($_GET, 'nick'); $msg = JArrayHelper::getValue($_GET, 'msg'); $act = JArrayHelper::getValue($_GET, 'act'); $psw = JArrayHelper::getValue($_GET, 'psw'); //echo 'ACT='.$act; //die; switch($act){ case 'read': echo read_msg($limit,$myid,$lastid,$aid); break; case "write": if($myid == $aid && $myid !=0) echo write_msg($nick,$msg,$limit,$myid,$lastid,$word,$aid); break; case "delall": if($myid == $aid && $myid !=0) { echo delete_all($limit,$myid,$psw); } break; case "delmsg": if($myid == $aid && $myid !=0) { echo delete_msg($limit,$myid,$msgid,$aid); } break; default: echo read_msg($limit,$myid,$lastid,$aid); break; } function delete_msg($limit,$myid,$msgid,$aid) { $db = & JFactory::getDBO(); $db->setQuery("DELETE FROM #__achat WHERE msg_id=".$msgid); $db->Query(); $html = read_msg($limit,$myid,$msgid,$aid); return $html; } function delete_all($limit,$myid,$psw) { $db = & JFactory::getDBO(); $db->setQuery("SELECT params FROM #__modules WHERE module = 'mod_achat'"); $res = $db->loadResult(); $params = new JParameter($res); $stored_psw = $params->getValue('psw'); if($stored_psw == $psw) { $db->setQuery("TRUNCATE TABLE #__achat"); $db->Query(); $html = read_msg($limit,$myid,0); return $html; } else { return '

'._ACHAT_PSW_NOTOK.'
'; } } function read_msg($limit,$myid,$lastid,$aid) { global $mainframe; $live_site = $mainframe->getCfg('live_site'); $db = & JFactory::getDBO(); $config =& JFactory::getConfig(); //$live_site = $config->getValue('config.live_site'); //echo JURI::base(); $path = JURI::base(); $imgpath = $path.'images'; $smilespath = $path.'smiles'; $sndpath = $path.'js/'; //$db->setQuery("SELECT * FROM #__achat WHERE msgtime=NOW() ORDER BY msg_id DESC LIMIT ".$limit); //$db->setQuery("SELECT * FROM #__achat ORDER BY msg_id DESC LIMIT ".$limit); $db->setQuery("SELECT * FROM #__achat ORDER BY msg_id DESC"); $messages = $db->loadObjectList(); $smiles = array(':)',':(',':D',':|'); $html = ''; if(count($messages) > 0) { $html .= ''; foreach ($messages as $msg) { $now = date('d.m.Y'); if(substr($msg->msgtime,0,10) == $now) { for($i=0;$i<4;$i++) { $smile_img = ''; $msg->msg = str_replace($smiles[$i],$smile_img,$msg->msg); } $html .= ''; } } $html .= '
'; $html .= $msg->msgtime.' |'; $html .= ''; //$html .= ''.$msg->nick.''; $html .= $msg->nick; $html .= '
'; if($myid == $aid && $myid !=0) { $html .= ''._ACHAT_DELMSG.' '; $html .= ''; } $html .= $msg->msg; if($myid == $aid && $myid !=0) { $html .= ''; $html .= ''; } $html .= '
'; $maxid = $messages[0]->msg_id; $html .= ''; if($maxid > $lastid) $html .= ''; } else { $html .= ''; $html .= ''; $html .= '
'; $html .= _ACHAT_NOMSG; $html .= '
'; } return $html; } function write_msg($nick,$msg,$limit,$myid,$lastid,$word,$aid) { $db = & JFactory::getDBO(); if ($myid == $aid) { $bads = explode(',',_ACHAT_BADWORDS); foreach ($bads as $bad) { $msg = str_replace($bad,'[...]',$msg); } if($word != NULL) $msg = chunk_split($msg,$word); $now = date('d.m.Y H:i'); //$now = date(); $db->setQuery("INSERT INTO #__achat (nick,msg,msgtime) VALUES ('".$nick."','".$msg."','".$now."')"); $db->Query(); if(mysql_error()) { return _ACHAT_ERROR.mysql_error(); } else { $html = ''; $html .= read_msg($limit,$myid,$lastid); return $html; } } else { $html = '
'._ACHAT_ERR.'
'; return $html; } } ?>