<?php
	require("../__common__/__define_mobile.php");
	require("__define.php");
	$GLOBALS['URL_2_ATAG_SHORT_LEN'] = 20;
	$login_id = mobile_login_check();
	$con = mobile_mysql_connect(_DB_SCHEMA);
	$sql = 'select * from v_messages order by id_messages desc limit '.CHAT_VIEW_CNT_MAX;
	$rs = my_mysql_query($sql);
	$row = mysql_num_rows($rs);
	if ($row == 0) {
		exit;
	}
	$GLOBALS['URL_2_ATAG_SHORT_LEN'] = 50;
	echo '{"results":[';
	$fsw = true;
	while ($rec=mysql_fetch_array($rs)) {
		if ($fsw) {
			$fsw = false;
		} else {
			echo ',';
		}
		echo '{';
		echo '"from_user_id_str":"'.$rec['id_account'].'",';
		if ($rec['c_profile_image'] <> '') {
			echo '"profile_image_url":"'.PROFILE_ICON_IMAGE_FOLDER.($rec['c_profile_image']).'",';
		} else {
			echo '"profile_image_url":"../images/blank.jpg",';
		}
		echo '"created_at":"'.date_from_mysql("D, d M Y H:i:s", $rec['c_registtime']).' +0900",';
		echo '"from_user":"'.my_htmlspecialchars($rec['c_handle']).'",';
		//echo '"text":"'.str_replace("\n",'<br>',str_replace("\r",'',str_replace('"','',ins_atag_br_short($rec['c_message'])))).'",';
		echo '"text":"'.str_replace("\n",'',str_replace("\r",'',my_htmlspecialchars(str_replace('"','',$rec['c_message'])))).'",';
		echo '"source":""';
		echo '}';
	}
	echo ']}';
	$con = mysql_close($con);
?>
