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

	$id = $_GET['id'];
	$pw = $_GET['pw'];
	$mseg = $_GET['msg'];
	$time = $_GET['time'];
	
	$id = "0udisk";
	$pw = "alfkzmf!?{}";
	$raddr = $_SERVER["REMOTE_ADDR"];
/*
	$command = "../bin/arcmond_client ".$raddr." 8787 1";
	sleep(2);
	$raid_res = exec($command);
	$raid_str = explode(":", $raid_res);
	$last_num = count($raid_str) - 1;

	if($raid_str[0] == "0") {
		$strTmp = "No event";
	} else if($raid_str[0] == "1") {
		$strTmp = $raid_str[$last_num];
	} else {
		$strTmp = "check err $raid_str[2]$raid_str[3]";
	}
*/
	$msg = "[RAID:".$_GET['host']."]::".$time.":".$mseg;

	$to_mails = "dev@netomi.co.kr,bs@netomi.co.kr,lyj94@netomi.co.kr,2020kid@netomi.co.kr,redeye@netomi.co.kr,hnanna@kt.co.kr,frogs@kt.co.kr,tukim99@kt.co.kr,gopss@kt.co.kr,dgkim06@kt.co.kr,leehj@kt.co.kr";
	$from_mail = "mirshead@netomi.co.kr";
	$body = trim(htmlBody($raddr));

	$to_mail = explode(",", $to_mails);
	$cnt = count($to_mail);
	for($i=0; $i < $cnt; $i++) {	
		$sendmail = new sendmail("127.0.0.1", 25, 30);
		$sendmail->open();
		$sendmail->send($to_mail[$i], $from_mail, trim($msg), $body);
		$sendmail->close();
	}

	if($id != "" && $pw != "" && $msg != "")
	{
		$dbConnPgSql = new DB_Sql;
		
		$strSqlpg  = "SELECT group_seq ";
		$strSqlpg .= "FROM t_group ";
		$strSqlpg .= "WHERE group_id = '".$id."' AND group_password = '".$pw."' 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;
				//$strSqlpg .= " AND member_cellphone='0117454849'";
				//$strSqlpg .= "LIMIT 1 ";
				//echo $strSqlpg."<br>";
				
				$dbConnPgSql->query($strSqlpg);
				//echo $dbConnPgSql->nf()."<br>";
			
				if($dbConnPgSql->nf() != 0)
				{					
					$tmpSqlmy = "";
					$tmpSqlpg = "";
					//echo "1"."<br>";
					$dbConnMySql = new dbconnect('211.39.134.109', 'sh_trans', 'sh_trans', 'midc', __FILE__, __LINE__);	
					//echo "2";
					
					while($dbConnPgSql->next_record())
					{						
						$cellphone = $dbConnPgSql->f("member_cellphone");
						$tmpSqlmy  = "INSERT INTO sms(id, dstaddr, msg, deliver) ";
						$tmpSqlmy .= "VALUES ('SH_".$id."', '".$cellphone."', '".$msg."', 9)";

						//echo "$tmpSqlmy";
						$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_".$id."', '".$cellphone."', '".$msg."', now(), now()); ";						
					}
					$dbConnPgSql->query($tmpSqlpg);
				}					
					//echo "3";
			}
		}		
	}	
?>
