<?php
	require_once ($_SERVER['DOCUMENT_ROOT']."/inc/mysql.inc");
	require_once ($_SERVER['DOCUMENT_ROOT']."/inc/pgsql.inc");
	$id = $_GET['id'];
	$msg = $_GET['msg'];
	
    $id = "ALL";
	
	$dbConnPgSql = new DB_Sql;

	$strSqlpg  = "SELECT group_seq ";
	$strSqlpg .= "FROM t_group ";
	$strSqlpg .= "WHERE group_id = '$id' 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 = "";
				$user_count =0;
			    $cellphone_list = "";
				
				$dbConnMySql = new dbconnect('222.122.18.22', 'smsuser', 'sms5emffld)', 'sms', __FILE__, __LINE__);

				while($dbConnPgSql->next_record())
				{						
					$cellphone = $dbConnPgSql->f("member_cellphone");

					if( strlen($cellphone_list) > 0 )
					{
						$cellphone_list .= "|ktics1^" . $cellphone;
					}
					else
					{
						$cellphone_list = "ktics1^" . $cellphone;
					}

					$user_count ++;

					$tmpSqlpg .= "INSERT INTO t_sms_log (group_seq, sms_id, sms_cellphone, sms_message, reg_datetime, update_datetime) ";
					$tmpSqlpg .= "VALUES (".$group_seq.", 'SH_".$id."', '".$cellphone."', '".$msg."', now(), now()); ";						
					
					
				}


				$tmpSqlmy  = "INSERT INTO SDK_SMS_SEND ( USER_ID, SCHEDULE_TYPE, SUBJECT, NOW_DATE,SEND_DATE, CALLBACK, DEST_COUNT, DEST_INFO, SMS_MSG) ";
				$tmpSqlmy .= "VALUES ('ktics1', 0,'ktics1',DATE_FORMAT(now(),'%Y%m%d%H%i%s'),DATE_FORMAT(now(),'%Y%m%d%H%i%s'),'0317810344',$user_count,'$cellphone_list','$msg')";

				
				$res = $dbConnMySql->query($tmpSqlmy,__FILE__, __LINE__);
				if( !$res->result )
				{
					echo "fail to send SMS ";  echo "<br><br>";
				}

				$dbConnMySql->close();
					
				$dbConnPgSql->query($tmpSqlpg);
				
			}					
		}
	}		
?>
