<?php
$template = <<<END
<!-- travel_news:お知らせ -->
<section class="bg3 blur travel_news">
<h2 class="w1"><span class="fade-in-text">News</span><span class="small">お知らせ</span></h2>
<dl class="new">
<!--{each item/newinfo}-->
<dt>{val item/newinfo/news_date}<!--{def item/newinfo/kind}--><span<!--{def item/newinfo/color}--> class="{val item/newinfo/color}"<!--{/def}-->>{val item/newinfo/kind}</span><!--{/def}--></dt>
<!--{def item/newinfo/link}-->
<dd><a href="{val item/newinfo/link}">{val item/newinfo/title}</a></dd>
<!--{/def}-->
<!--{ndef item/newinfo/link}-->
<dd>{val item/newinfo/title}</dd>
<!--{/ndef}-->
<!--{/each}-->
</dl>
</section>
END;

$travel_news = array(
		"title" => "travel お知らせ一覧",
		"name" => "travel_news",			// 名称、重複すると正しく動作しません
		"template" => $template,		// ブロックのテンプレート
		"input" => array(
		"help" => array(
			"title" => "使い方",
			"type" => "comment",
			"link" => DOCUMENT1 . "/?act=travel_news",
			"class" => "notice",
		),
			"notice1" => array(
				"title" => "このブロックは1ページに1つしか使えません",
				"type" => "comment",
				"class"=> "notice",
			),
			"info_num" => array(
				"title" => "表示数",
				"type" => "text",
			),
/*
			"comment1" => array(
				"title" => "お知らせ種別",
				"type" => "comment",
			),
			"kind1" => array(
				"title" => "種類1",
				"type" => "text",
			),
			"kind2" => array(
				"title" => "種類2",
				"type" => "text",
			),
			"kind3" => array(
				"title" => "種類3",
				"type" => "text",
			),
			"kind4" => array(
				"title" => "種類4",
				"type" => "text",
			),
			"kind5" => array(
				"title" => "種類5",
				"type" => "text",
			),
*/
		),
		"func" => "func_travel_news",		// 処理プログラム（指定がない物は標準処理）
	);

block_add($travel_news);

// お知らせの取得
function func_travel_news($def, $info)
{
	$login = get_setup();
	$kiji_list = array("" => "");
	$kiji_color = array("" => "");
	for ($i = 1; $i <= 10; $i++) {
		if (trim($login["news" . $i])) {
			$ary = explode("|", trim($login["news" . $i]));
			$kiji_list[$i] = $ary[0];
			$kiji_color[$i] = $ary[1];
		}
	}
	$num = intval($info["info_num"]);
	if ($num) {
		$info["newinfo"] = get_newinfo(($setup["info_max"] == "")?$num:$setup["info_max"]);
	}
	if (is_array($info["newinfo"])) {
		foreach ($info["newinfo"] as $key => $val) {
			$info["newinfo"][$key]["kind"] = $kiji_list[$val["kind"]];
			$info["newinfo"][$key]["color"] = "bgcolor-" . $kiji_color[$val["kind"]] . "-maru";
		}
	}
	return $info;
}
