<?php
define('_IN_JOHNCMS', 1);
require('../incfiles/core.php');
header('Access-Control-Allow-Origin: *');

 if (($user_id == true) && !($user_id == false)) { 

switch($mod)
{
   case 'getchat':
  functions::get_chat(10);
  break;
    case 'sendchat':
  $msg = isset($_POST['msg']) ? $_POST['msg'] : '';
  if(!$user_id) {
      exit();
  }
  if(empty($msg)) {
      exit();
  }
  elseif(mb_strlen($msg) > 150) {
      exit();
  }
  mysql_query("INSERT INTO `chats` SET `user_id` = $user_id, `name` = '" . mysql_real_escape_string($datauser['name']) . "', `message`= '" . mysql_real_escape_string($msg) . "', `date` = '" . time() . "'");
  mysql_query("UPDATE `users` SET `balans` = `balans` +1 WHERE `id` = '".$user_id."';");
  break;
  
  case 'ajaxshx':

$new_sys_mail = mysql_result(mysql_query("SELECT COUNT(*) FROM `cms_mail` WHERE `from_id`='$user_id' AND `read`='0' AND `sys`='1' AND `delete`!='$user_id';"), 0);

$new_mail = mysql_result(mysql_query("SELECT COUNT(*) FROM `cms_mail` LEFT JOIN `cms_contact` ON `cms_mail`.`user_id`=`cms_contact`.`from_id` AND `cms_contact`.`user_id`='$user_id' WHERE `cms_mail`.`from_id`='$user_id' AND `cms_mail`.`sys`='0' AND `cms_mail`.`read`='0' AND `cms_mail`.`delete`!='$user_id' AND `cms_contact`.`ban`!='1' AND `cms_mail`.`spam`='0'"), 0);

if ($new_sys_mail) { ?>
	<a class="w3-bar-item w3-button" href="<?php echo $home; ?>/mail/index.<?php echo $akb_for; ?>?act=systems">Sistema</a> (+<?php echo "$new_sys_mail"; ?>)
<?php } ?>

<?php 
if (($new_mail == true) && !($new_mail == false)) { ?> 
	<div class="w3-dropdown-hover w3-hide-small">
    <button class="w3-button w3-padding-large" title="Notifications"><i class="fa fa-bell"></i>
     <span class="w3-badge w3-right w3-small w3-green">  
      <?php echo $new_mail; ?>
    </span>
  </button>
  <div class="w3-dropdown-content w3-card-4 w3-bar-block" style="width:300px"> <a class="w3-bar-item w3-button" href="<?php echo $home; ?>/mail/index.<?php echo $akb_for; ?>?act=new"><?php echo $lng['mail']; ?> (+<?php echo $new_mail; ?>)</a>
	<audio controls autoplay loop hidden><source src="/sound/notify.mp3" type="audio/mpeg" /><source src="sound/notify.ogg" type="audio/ogg" /><source src="/sound/notify.wav" type="audio/wav" /></audio>
</div> </div>
	<?php } ?>

<?php 
		break;
    default:
    echo 'Salomalekum '.$login.' sizga nima bor bu erda ?. Xabar kelsa men o\'zim sizni ogohlantiraman. Bu yerga vopshe kirishinigizni hojati yo. Agar yomon niyatda kirgan bolsangiz admin akamga xabar jo\'natib yubordim. U bu yerga kirganingizdan xabardor.';
	break;
} } else {
	echo 'Salomalekum mehmon sekin suring baydan. Saytning bu qismi juda klassno ximoya ostida!';
}
?>