<?php
require_once('config.php');

function insert_notification_log($site_cd, $assign_from, $assign_to, $doc_no, $title, $body, $message, $module, $dvc_id, $audit_user){
	global $conn;
	
	$insert_ntf = true;
	
	
	$sql_insert_ntf_log = "	INSERT ntf_log (	site_cd,				ntf_log_from,			ntf_log_to,				ntf_log_doc_no,			ntf_log_title,			
												ntf_log_body, 			ntf_log_msg,			ntf_log_priority,		ntf_log_icon,			ntf_log_sound,			
												ntf_log_event,			ntf_log_module,			ntf_log_send, 			ntf_log_send_date,		ntf_log_rcv,		
												ntf_log_rcv_dvc_id,		ntf_log_rcv_date,		audit_user,				audit_date,				column1,				
												column2,				column3,				column4,				column5 )

							VALUES 
											(	?,						?,						?,						?,						?,						
												?,						?,						?,						?,						?,	
												?,						?,						?,						getdate(),				?,	
												?,						getdate(),				?,						getdate(),				?,	
												?,						?,						?,						?) SELECT SCOPE_IDENTITY() as rowid";

	$params_insert_ntf_log = array(				$site_cd,				$assign_from,			$assign_to,				$doc_no,				$title,
												$body,					$message,				"",						"",						"",	
												"",						$module,				"0",											"",
												$dvc_id,										$audit_user,									NUll,
												NUll,					NUll,					NUll,					NUll);
									
	$stmt_insert_ntf_log = sqlsrv_query( $conn, $sql_insert_ntf_log, $params_insert_ntf_log);

	$json = array();

	do {
		 while ($row = sqlsrv_fetch_array($stmt_insert_ntf_log, SQLSRV_FETCH_ASSOC)) {
		 $json = $row;
		 
		 $a1[]=array("row"=>$row['rowid'],"insert_ntf"=>$insert_ntf);
		 
		 //echo '<pre>'; print_r($a1); echo '</pre>';
		 }
	} while ( sqlsrv_next_result($stmt_insert_ntf_log) );



	
	if( !$stmt_insert_ntf_log ) {
	$error_message = "Error (INSERT Table ntf_log)";
	returnError($error_message);
	die( print_r( sqlsrv_errors(), true));
	
	$insert_ntf = false;
		
	}
	
	
	sqlsrv_free_stmt( $stmt_insert_ntf_log);
	
	
	return $a1;
}


?>