Mercurial > epgrec.yaz
comparison index.php @ 34:18df04305501
modified: index.php
author | Sushi-k <epgrec@park.mda.or.jp> |
---|---|
date | Mon, 27 Jul 2009 19:43:45 +0900 |
parents | 19cd7816b2c1 |
children | 7d1f7e4cac82 |
comparison
equal
deleted
inserted
replaced
33:1fc71046946c | 34:18df04305501 |
---|---|
2 | 2 |
3 include_once("config.php"); | 3 include_once("config.php"); |
4 include_once( INSTALL_PATH . "/DBRecord.class.php" ); | 4 include_once( INSTALL_PATH . "/DBRecord.class.php" ); |
5 include_once( INSTALL_PATH . "/Smarty/Smarty.class.php" ); | 5 include_once( INSTALL_PATH . "/Smarty/Smarty.class.php" ); |
6 include_once( INSTALL_PATH . "/reclib.php" ); | 6 include_once( INSTALL_PATH . "/reclib.php" ); |
7 include_once( INSTALL_PATH . "/Settings.class.php" ); | |
8 | |
9 // 設定ファイルの有無を検査する | |
10 if( ! file_exists( INSTALL_PATH."/settings/config.xml") ) { | |
11 header( "Content-Type: text/html;charset=utf-8" ); | |
12 exit( "<script type=\"text/javascript\">\n" . | |
13 "<!--\n". | |
14 "window.open(\"".$url."\",\"_self\");". | |
15 "// -->\n</script>" ); | |
16 } | |
17 | |
18 $settings = Settings::factory(); | |
7 | 19 |
8 $DAY_OF_WEEK = array( "(日)","(月)","(火)","(水)","(木)","(金)","(土)" ); | 20 $DAY_OF_WEEK = array( "(日)","(月)","(火)","(水)","(木)","(金)","(土)" ); |
9 | 21 |
10 // パラメータの処理 | 22 // パラメータの処理 |
11 // 表示する長さ(時間) | 23 // 表示する長さ(時間) |
12 $program_length = 8; | 24 $program_length = $settings->program_length; |
13 if( isset( $_GET['length']) ) $program_length = (int) $_GET['length']; | 25 if( isset( $_GET['length']) ) $program_length = (int) $_GET['length']; |
14 // 地上=GR/BS=BS | 26 // 地上=GR/BS=BS |
15 $type = "GR"; | 27 $type = "GR"; |
16 if( isset( $_GET['type'] ) ) $type = $_GET['type']; | 28 if( isset( $_GET['type'] ) ) $type = $_GET['type']; |
17 // 現在の時間 | 29 // 現在の時間 |
34 // 番組表 | 46 // 番組表 |
35 $programs = array(); | 47 $programs = array(); |
36 if( $type == "BS" ) $channel_map = $BS_CHANNEL_MAP; | 48 if( $type == "BS" ) $channel_map = $BS_CHANNEL_MAP; |
37 else if( $type == "GR" ) $channel_map = $GR_CHANNEL_MAP; | 49 else if( $type == "GR" ) $channel_map = $GR_CHANNEL_MAP; |
38 $st = 0; | 50 $st = 0; |
39 $prec = new DBRecord(TBL_PREFIX.PROGRAM_TBL); | 51 $prec = new DBRecord($settings->tbl_prefix.PROGRAM_TBL); |
40 foreach( $channel_map as $channel_disc => $channel ) { | 52 foreach( $channel_map as $channel_disc => $channel ) { |
41 $prev_end = $top_time; | 53 $prev_end = $top_time; |
42 try { | 54 try { |
43 $crec = new DBRecord( TBL_PREFIX . CHANNEL_TBL, "channel_disc", $channel_disc ); | 55 $crec = new DBRecord( $settings->tbl_prefix . CHANNEL_TBL, "channel_disc", $channel_disc ); |
44 $programs[$st]["station_name"] = $crec->name; | 56 $programs[$st]["station_name"] = $crec->name; |
45 | 57 |
46 $reca = $prec->fetch_array( "channel_disc", $channel_disc, | 58 $reca = $prec->fetch_array( "channel_disc", $channel_disc, |
47 "endtime > '".toDatetime($top_time)."' ". | 59 "endtime > '".toDatetime($top_time)."' ". |
48 "AND starttime < '". toDatetime($last_time)."' ". | 60 "AND starttime < '". toDatetime($last_time)."' ". |
52 $num = 0; | 64 $num = 0; |
53 foreach( $reca as $prg ) { | 65 foreach( $reca as $prg ) { |
54 // 前プログラムとの空きを調べる | 66 // 前プログラムとの空きを調べる |
55 $start = toTimestamp( $prg['starttime'] ); | 67 $start = toTimestamp( $prg['starttime'] ); |
56 if( $start - $prev_end ) { | 68 if( $start - $prev_end ) { |
57 $height = ($start-$prev_end) / 60; | 69 $height = ($start-$prev_end) * $settings->height_per_hour / 3600; |
58 if( $height > 0.5 ) { | 70 if( $height > 0.5 ) { |
59 $height = (int)($height * 2); | 71 $height = (int)$height; |
60 $programs[$st]['list'][$num]['category_none'] = "none"; | 72 $programs[$st]['list'][$num]['category_none'] = "none"; |
61 $programs[$st]['list'][$num]['height'] = $height; | 73 $programs[$st]['list'][$num]['height'] = $height; |
62 $programs[$st]['list'][$num]['title'] = ""; | 74 $programs[$st]['list'][$num]['title'] = ""; |
63 $programs[$st]['list'][$num]['starttime'] = ""; | 75 $programs[$st]['list'][$num]['starttime'] = ""; |
64 $programs[$st]['list'][$num]['description'] = ""; | 76 $programs[$st]['list'][$num]['description'] = ""; |
65 $num++; | 77 $num++; |
66 } | 78 } |
67 } | 79 } |
68 $prev_end = toTimestamp( $prg['endtime'] ); | 80 $prev_end = toTimestamp( $prg['endtime'] ); |
69 | 81 |
70 $height = (int)((toTimestamp($prg['endtime']) - toTimestamp($prg['starttime'])) / 30); | 82 $height = (int)((toTimestamp($prg['endtime']) - toTimestamp($prg['starttime'])) * $settings->height_per_hour / 3600); |
71 // $top_time より早く始まっている番組 | 83 // $top_time より早く始まっている番組 |
72 if( toTimestamp($prg['starttime']) <$top_time ) { | 84 if( toTimestamp($prg['starttime']) <$top_time ) { |
73 $height = (int)((toTimestamp($prg['endtime']) - $top_time ) / 30); | 85 $height = (int)((toTimestamp($prg['endtime']) - $top_time ) * $settings->height_per_hour / 3600); |
74 } | 86 } |
75 // $last_time より遅く終わる番組 | 87 // $last_time より遅く終わる番組 |
76 if( toTimestamp($prg['endtime']) > $last_time ) { | 88 if( toTimestamp($prg['endtime']) > $last_time ) { |
77 $height = (int)(($last_time - toTimestamp($prg['starttime'])) / 30); | 89 $height = (int)(($last_time - toTimestamp($prg['starttime'])) * $settings->height_per_hour / 3600); |
78 } | 90 } |
79 | 91 |
80 // プログラムを埋める | 92 // プログラムを埋める |
81 $cat = new DBRecord( TBL_PREFIX . CATEGORY_TBL, "id", $prg['category_id'] ); | 93 $cat = new DBRecord( $settings->tbl_prefix . CATEGORY_TBL, "id", $prg['category_id'] ); |
82 $programs[$st]['list'][$num]['category_name'] = $cat->name_en; | 94 $programs[$st]['list'][$num]['category_name'] = $cat->name_en; |
83 $programs[$st]['list'][$num]['height'] = $height; | 95 $programs[$st]['list'][$num]['height'] = $height; |
84 $programs[$st]['list'][$num]['title'] = $prg['title']; | 96 $programs[$st]['list'][$num]['title'] = $prg['title']; |
85 $programs[$st]['list'][$num]['starttime'] = date("H:i", $start )."" ; | 97 $programs[$st]['list'][$num]['starttime'] = date("H:i", $start )."" ; |
86 $programs[$st]['list'][$num]['description'] = $prg['description']; | 98 $programs[$st]['list'][$num]['description'] = $prg['description']; |
87 $programs[$st]['list'][$num]['prg_start'] = str_replace( "-", "/", $prg['starttime']); | 99 $programs[$st]['list'][$num]['prg_start'] = str_replace( "-", "/", $prg['starttime']); |
88 $programs[$st]['list'][$num]['duration'] = "" . (toTimestamp($prg['endtime']) - toTimestamp($prg['starttime'])); | 100 $programs[$st]['list'][$num]['duration'] = "" . (toTimestamp($prg['endtime']) - toTimestamp($prg['starttime'])); |
89 $programs[$st]['list'][$num]['channel'] = ($prg['type'] == "GR" ? "地上D" : "BS" ) . ":". $prg['channel'] . "ch"; | 101 $programs[$st]['list'][$num]['channel'] = ($prg['type'] == "GR" ? "地上D" : "BS" ) . ":". $prg['channel'] . "ch"; |
90 $programs[$st]['list'][$num]['id'] = "" . ($prg['id']); | 102 $programs[$st]['list'][$num]['id'] = "" . ($prg['id']); |
91 $programs[$st]['list'][$num]['rec'] = DBRecord::countRecords( TBL_PREFIX.RESERVE_TBL, "WHERE complete = '0' AND program_id = '".$prg['id']."'" ); | 103 $programs[$st]['list'][$num]['rec'] = DBRecord::countRecords( $settings->tbl_prefix.RESERVE_TBL, "WHERE complete = '0' AND program_id = '".$prg['id']."'" ); |
92 $num++; | 104 $num++; |
93 } | 105 } |
94 } | 106 } |
95 catch( exception $e ) { | 107 catch( exception $e ) { |
96 exit( $e->getMessage() ); | 108 exit( $e->getMessage() ); |
97 } | 109 } |
98 // 空きを埋める | 110 // 空きを埋める |
99 if( $last_time - $prev_end ) { | 111 if( $last_time - $prev_end ) { |
100 $height = ($last_time - $prev_end) / 60; | 112 $height = ($last_time - $prev_end) * $settings->height_per_hour / 3600; |
101 if( $height > 0.5 ) { | 113 if( $height > 0.5 ) { |
102 $height = (int)($height * 2); | 114 $height = (int)$height; |
103 $programs[$st]['list'][$num]['category_name'] = "none"; | 115 $programs[$st]['list'][$num]['category_name'] = "none"; |
104 $programs[$st]['list'][$num]['height'] = $height; | 116 $programs[$st]['list'][$num]['height'] = $height; |
105 $programs[$st]['list'][$num]['title'] = ""; | 117 $programs[$st]['list'][$num]['title'] = ""; |
106 $programs[$st]['list'][$num]['starttime'] = ""; | 118 $programs[$st]['list'][$num]['starttime'] = ""; |
107 $programs[$st]['list'][$num]['description'] = ""; | 119 $programs[$st]['list'][$num]['description'] = ""; |
111 $st++; | 123 $st++; |
112 } | 124 } |
113 $prec = null; | 125 $prec = null; |
114 | 126 |
115 // 局の幅 | 127 // 局の幅 |
116 $ch_set_width = 150; | 128 $ch_set_width = $settings->ch_set_width; |
117 // 全体の幅 | 129 // 全体の幅 |
118 $chs_width = $ch_set_width * count( $channel_map ); | 130 $chs_width = $ch_set_width * count( $channel_map ); |
119 | 131 |
120 // GETパラメタ | 132 // GETパラメタ |
121 $get_param = $_SERVER['SCRIPT_NAME'] . "?type=".$type."&length=".$program_length.""; | 133 $get_param = $_SERVER['SCRIPT_NAME'] . "?type=".$type."&length=".$program_length.""; |
122 | 134 |
123 $smarty = new Smarty(); | 135 $smarty = new Smarty(); |
124 | 136 |
125 // カテゴリ一覧 | 137 // カテゴリ一覧 |
126 $crec = DBRecord::createRecords( TBL_PREFIX . CATEGORY_TBL ); | 138 $crec = DBRecord::createRecords( $settings->tbl_prefix . CATEGORY_TBL ); |
127 $cats = array(); | 139 $cats = array(); |
128 $num = 0; | 140 $num = 0; |
129 foreach( $crec as $val ) { | 141 foreach( $crec as $val ) { |
130 $cats[$num]['name_en'] = $val->name_en; | 142 $cats[$num]['name_en'] = $val->name_en; |
131 $cats[$num]['name_jp'] = $val->name_jp; | 143 $cats[$num]['name_jp'] = $val->name_jp; |
136 | 148 |
137 | 149 |
138 // タイプ選択 | 150 // タイプ選択 |
139 $types = array(); | 151 $types = array(); |
140 $i = 0; | 152 $i = 0; |
141 if( BS_TUNERS ) { | 153 if( $settings->bs_tuners ) { |
142 $types[$i]['selected'] = $type == "BS" ? 'class="selected"' : ""; | 154 $types[$i]['selected'] = $type == "BS" ? 'class="selected"' : ""; |
143 $types[$i]['link'] = $_SERVER['SCRIPT_NAME'] . "?type=BS&length=".$program_length."&time=".date( "YmdH", $top_time); | 155 $types[$i]['link'] = $_SERVER['SCRIPT_NAME'] . "?type=BS&length=".$program_length."&time=".date( "YmdH", $top_time); |
144 $types[$i]['name'] = "BS"; | 156 $types[$i]['name'] = "BS"; |
145 $i++; | 157 $i++; |
146 } | 158 } |
147 if( GR_TUNERS ) { | 159 if( $settings->gr_tuers ) { |
148 $types[$i]['selected'] = $type == "GR" ? 'class="selected"' : ""; | 160 $types[$i]['selected'] = $type == "GR" ? 'class="selected"' : ""; |
149 $types[$i]['link'] = $_SERVER['SCRIPT_NAME'] . "?type=GR&length=".$program_length."&time=".date( "YmdH", $top_time); | 161 $types[$i]['link'] = $_SERVER['SCRIPT_NAME'] . "?type=GR&length=".$program_length."&time=".date( "YmdH", $top_time); |
150 $types[$i]['name'] = "地上デジタル"; | 162 $types[$i]['name'] = "地上デジタル"; |
151 $i++; | 163 $i++; |
152 } | 164 } |
185 } | 197 } |
186 $smarty->assign( "toptimes" , $toptimes ); | 198 $smarty->assign( "toptimes" , $toptimes ); |
187 | 199 |
188 $smarty->assign( "tvtimes", $tvtimes ); | 200 $smarty->assign( "tvtimes", $tvtimes ); |
189 $smarty->assign( "programs", $programs ); | 201 $smarty->assign( "programs", $programs ); |
190 $smarty->assign( "ch_set_width", $ch_set_width ); | 202 $smarty->assign( "ch_set_width", $settings->ch_set_width ); |
191 $smarty->assign( "chs_width", $chs_width ); | 203 $smarty->assign( "chs_width", $chs_width ); |
204 $smarty->assign( "height_per_hour", $settings->height_per_hour ); | |
192 | 205 |
193 // date("Y-m-d H:i:s", $timestamp); | 206 // date("Y-m-d H:i:s", $timestamp); |
194 | 207 |
195 $sitetitle = date( "Y", $top_time ) . "年" . date( "m", $top_time ) . "月" . date( "d", $top_time ) . "日". date( "H", $top_time ) . | 208 $sitetitle = date( "Y", $top_time ) . "年" . date( "m", $top_time ) . "月" . date( "d", $top_time ) . "日". date( "H", $top_time ) . |
196 "時~".( $type == "GR" ? "地上デジタル" : "BSデジタル" )."番組表"; | 209 "時~".( $type == "GR" ? "地上デジタル" : "BSデジタル" )."番組表"; |