<?php
	require_once ($_SERVER['DOCUMENT_ROOT']."/inc/mysql.inc");
	require_once ($_SERVER['DOCUMENT_ROOT']."/inc/pgsql.inc");

	$id = $_GET['id'];
	$msg = $_GET['msg'];
	
	// rcid is not RC004 ( thinkware )
	if ($id == "" || $id != "THINKWARE")
		$sid = "ALL";

	if ($id == "THINKWARE") {
		$sid = "BD-RC004";
	} else if ($id == "ADMIN") {
		$sid = "ADMIN";	
	} else if ($id == "AION") {
		$sid = "AION-NC";
	} else if ($id == "WARHAM") {
		$sid = "WARHAM";
	} else if ($id == "WARHAM") {
		$sid = "WARHAM";
	}

	if($sid != "" && $msg != "")
	{
		$dbConnPgSql = new DB_Sql;
		$strSqlpg  = "SELECT group_seq ";
		$strSqlpg .= "FROM t_group ";
		$strSqlpg .= "WHERE group_id = '".$sid."' AND deleted_yn = 'N'";

		$dbConnPgSql->query($strSqlpg);
		
		if($dbConnPgSql->nf() == 1)
		{
			$dbConnPgSql->next_record();
			$group_seq = $dbConnPgSql->f("group_seq");
			
			if($group_seq != "")
			{
				$strSqlpg  = "SELECT member_cellphone ";
				$strSqlpg .= "FROM t_group_member ";
				$strSqlpg .= "WHERE group_seq = ".$group_seq;
		
				$dbConnPgSql->query($strSqlpg);
				if($dbConnPgSql->nf() != 0)
				{
					$tmpSqlmy = "";
					$tmpSqlpg = "";
					
					//$dbConnMySql = new dbconnect('211.39.134.240', 'ktsh', 'ktsh!@#', 'sms', __FILE__, __LINE__);
					$dbConnMySql = new dbconnect('211.39.134.240', 'sms', '', 'sms', __FILE__, __LINE__);
					
					while($dbConnPgSql->next_record())
					{
						$cellphone = $dbConnPgSql->f("member_cellphone");
						$cli_ip = $_SERVER['REMOTE_ADDR'];
						$tmpSqlmy  = "INSERT INTO sms_msg (phone, callback, reqdate, msg,etc1 )  ";
						$tmpSqlmy .= "VALUES ( '$cellphone', '', sysdate(), '$msg', '$cli_ip')";

						$dbConnMySql->query($tmpSqlmy,__FILE__, __LINE__);
						
						$tmpSqlpg .= "INSERT INTO t_sms_log (group_seq, sms_id, sms_cellphone, sms_message, reg_datetime, update_datetime) ";
						$tmpSqlpg .= "VALUES (".$group_seq.", 'SH_".$sid."', '".$cellphone."', '".$msg."', now(), now()); ";
					}
					$dbConnPgSql->query($tmpSqlpg);
				}
			}
		}
	}
?>
