LIST0000.php 6.11 KB
<?PHP 
//*****************************************************************************
//* 
//* プログラム名:め〜るNiポン!V2
//* プログラムID:LIST0000.php
//* 機能				:配信した情報の一覧を表示する
//* 
//*****************************************************************************
header("Content-type: text/html; charset=EUC-JP");

//***************************
//* インクルードファイル
//***************************
include("./include/smarty.conf");
include("./include/jcode.phps");
include("./include/session_start.inc");
include("./include/SessionChk.inc");

//********** ヘッダー処理 **********//
include("./include/headr_data.inc");

//********** カレンダー処理 **********//
include("./include/dbcon.inc");

//*** メールデータ取得 ***//
$strSQL  = "SELECT ";
$strSQL .= "  mail_data.mail_id     , ";
$strSQL .= "  mail_data.message_date, ";
$strSQL .= "  mail_data.message_time, ";
$strSQL .= "  mail_data.subject_name, ";
$strSQL .= "  mail_data.contents    , ";
$strSQL .= "  mail_data.send_date   , ";
$strSQL .= "  mail_data.send_alarm  , ";
$strSQL .= "  mail_data.reserva_flg , ";
$strSQL .= "  mail_data.reserva_date, ";
$strSQL .= "  mail_data.reserva_time, ";
$strSQL .= "  syain_tbl.name_kj_sei , ";
$strSQL .= "  syain_tbl.name_kj_mei , ";
$strSQL .= "  answer_data.name50_nm   ";
$strSQL .= "FROM ";
$strSQL .= " (";
$strSQL .= "  mail_data ";
$strSQL .= "    LEFT JOIN syain_tbl ON mail_data.admin_cd = syain_tbl.syain_cd ";
$strSQL .= " )";
$strSQL .= "  LEFT JOIN answer_data ON mail_data.mail_id = answer_data.mail_id ";
//$strSQL .= "WHERE ";
//$strSQL .= " mail_data.admin_cd = syain_tbl.syain_cd AND";
//$strSQL .= " mail_data.mail_id = answer_data.mail_id ";
$strSQL .= "ORDER BY ";
$strSQL .= " mail_data.Mail_id DESC";
$objRec = pg_exec($strSQL);
if($objRec==false){
		echo("SQL実行に失敗しました(SELECT)");
		exit;
}

for ($intI = 0; $intI < pg_numrows($objRec); $intI++) {
		$obData = pg_fetch_object($objRec, $intI);

		$MailData[$intI][0]  = $obData->mail_id;
		$MailData[$intI][1]  = intval(substr($obData->send_date,0,4))."年";
		$MailData[$intI][1] .= str_replace("*","&nbsp;",sprintf("%'*2s",intval(substr($obData->send_date,4,2))))."月";
		$MailData[$intI][1] .= str_replace("*","&nbsp;",sprintf("%'*2s",intval(substr($obData->send_date,6,2))))."日";
		$MailData[$intI][1] .= "&nbsp;";
		$MailData[$intI][1] .= str_replace("*","&nbsp;",sprintf("%'*2s",intval(substr($obData->send_date,8,2))))."時";
		$MailData[$intI][1] .= str_replace("*","&nbsp;",sprintf("%'*2s",intval(substr($obData->send_date,10,2))))."分";
		$MailData[$intI][1] .= str_replace("*","&nbsp;",sprintf("%'*2s",intval(substr($obData->send_date,12,2))))."秒";
		$MailData[$intI][2]  = $obData->subject_name;
		
		switch ($obData->name50_nm) {
			case "SC":
					$DataSC[$intI][0] = "#DEFFD1";
					$DataSC[$intI][1] = "<br>(スケジュール調整)";
					$DataSC[$intI][2] = "LIST2000.php";
					break;
			case "QU":
					$DataSC[$intI][0] = "#FFFF66";
					$DataSC[$intI][1] = "<br>(アンケート)";
					$DataSC[$intI][2] = "LIST3000.php";
					break;
			case "DM":
					$DataSC[$intI][0] = "#E6E6FA";
					$DataSC[$intI][1] = "<br>(お知らせ配信)";
					$DataSC[$intI][2] = "LIST1000.php";
					break;
			default:
				$DataSC[$intI][0] = "#FFFFFF";
				$DataSC[$intI][1] = "";
				$DataSC[$intI][2] = "LIST1000.php";
		}

		//***** 閲覧情報取得 *****//
		$strSQL  = "SELECT ";
		$strSQL .= " (SELECT COUNT(*) FROM mail_info AS chk1 WHERE chk1.mail_id=M.mail_id)                                                AS all_cnt   ,";
		$strSQL .= " (SELECT COUNT(*) FROM mail_info AS chk1 WHERE chk1.mail_id=M.mail_id AND chk1.check_flg =0)                          AS n_read_cnt,";
		$strSQL .= " (SELECT COUNT(*) FROM mail_info AS chk1 WHERE chk1.mail_id=M.mail_id AND chk1.check_flg<>0)                          AS read_cnt  ,";
		$strSQL .= " (SELECT COUNT(*) FROM mail_info AS chk1 WHERE chk1.mail_id=M.mail_id AND (chk1.check_flg<>0 AND chk1.check_flg<>99)) AS ans_cnt   ,";
		$strSQL .= " (SELECT COUNT(*) FROM mail_info AS chk1 WHERE chk1.mail_id=M.mail_id AND chk1.check_flg =100)                        AS not_cnt    ";
		$strSQL .= "FROM ";
		$strSQL .= " mail_info AS M ";
		$strSQL .= "WHERE";
		$strSQL .= " M.mail_id=".$obData->mail_id;
		$strSQL .= "GROUP BY ";
		$strSQL .= " M.mail_id";
		//echo $strSQL."<hr>";
		$objCntRec = pg_exec($strSQL);
		if($objCntRec==false){
				echo("SQL実行に失敗しました(SELECT)");
				exit;
		}
		if(pg_numrows($objCntRec)>0){
				$objCntData = pg_fetch_object($objCntRec, 0);
				$ALL_CNT    = $objCntData->all_cnt;
				$N_READ_CNT = $objCntData->n_read_cnt;
				$READ_CNT   = $objCntData->read_cnt;
				$ANS_CNT    = $objCntData->ans_cnt;
				$NOT_CNT    = $objCntData->not_cnt;
		}else{
				$ALL_CNT    = 0;
				$N_READ_CNT = 0;
				$READ_CNT   = 0;
				$ANS_CNT    = 0;
				$NOT_CNT    = 0;
		}

		if ($obData->name50_nm=="DM"){
				$MailData[$intI][3] = "配信済み";
		}else{
				if ($ALL_CNT==($READ_CNT+$NOT_CNT)){
						$MailData[$intI][3] = "○全既読済";
				}elseif ($ALL_CNT==($READ_CNT+$ANS_CNT+$NOT_CNT)){
						$MailData[$intI][3] = "◇既読・回答済";
				}elseif ($ALL_CNT==($ANS_CNT+$NOT_CNT)){
						$MailData[$intI][3] = "☆全回答済";
				}else{
						$MailData[$intI][3] = "&nbsp;";
				}
				if ($NOT_CNT!=0){
						$MailData[$intI][3] .= "<br />アドレス無し";
				}
		}
		//***** アラーム情報取得 *****//
		if ($obData->mail_id==1){
				$strSQL  = "SELECT ";
				$strSQL .= " * ";
				$strSQL .= "FROM ";
				$strSQL .= " alarm_data ";
				$strSQL .= "WHERE";
				$strSQL .= " mail_id=".$obData->mail_id;
				$objALRec = pg_exec($strSQL);
				if($objALRec==false){
						echo("SQL実行に失敗しました(SELECT)");
						exit;
				}
				if(pg_numrows($objALRec)>0){
						$objALData = pg_fetch_object($objALRec, 0);
						if ($objALData->send_flg==1){
								$MailData[$intI][4] = "送信済";
						}else{
								$MailData[$intI][4] = "設定済";
						}
				}else{
						$MailData[$intI][4] = "";
				}
		}else{
						$MailData[$intI][4] = "";
		}
}

$MailCnt=count($MailData);

$o_smarty->assign('N_READ_CNT' , $N_READ_CNT);

$o_smarty->assign('MailData' , $MailData);
$o_smarty->assign('MailCnt'  , $MailCnt);
$o_smarty->assign('DataSC'   , $DataSC);

$o_smarty->display('LIST0000.tpl');

?>