Mercurial > epgrec.yaz
comparison index.php @ 1:f5a9f0eb4858
deleted: LICENSE.ja
author | Sushi-k <epgrec@park.mda.or.jp> |
---|---|
date | Wed, 08 Jul 2009 11:44:50 +0900 |
parents | |
children | 19cd7816b2c1 |
comparison
equal
deleted
inserted
replaced
0:96312e6ab8d4 | 1:f5a9f0eb4858 |
---|---|
1 <?php | |
2 | |
3 include_once("config.php"); | |
4 include_once( INSTALL_PATH . "/DBRecord.class.php" ); | |
5 include_once( INSTALL_PATH . "/Smarty/Smarty.class.php" ); | |
6 include_once( INSTALL_PATH . "/reclib.php" ); | |
7 | |
8 $DAY_OF_WEEK = array( "(日)","(月)","(火)","(水)","(木)","(金)","(土)" ); | |
9 | |
10 // パラメータの処理 | |
11 // 表示する長さ(時間) | |
12 $program_length = 8; | |
13 if( isset( $_GET['length']) ) $program_length = (int) $_GET['length']; | |
14 // 地上=GR/BS=BS | |
15 $type = "GR"; | |
16 if( isset( $_GET['type'] ) ) $type = $_GET['type']; | |
17 // 現在の時間 | |
18 $top_time = mktime( date("H"), 0 , 0 ); | |
19 if( isset( $_GET['time'] ) ) { | |
20 if( sscanf( $_GET['time'] , "%04d%2d%2d%2d", $y, $mon, $day, $h ) == 4 ) { | |
21 $tmp_time = mktime( $h, 0, 0, $mon, $day, $y ); | |
22 if( ($tmp_time < ($top_time + 3600 * 24 * 8)) && ($tmp_time > ($top_time - 3600 * 24 * 8)) ) | |
23 $top_time = $tmp_time; | |
24 } | |
25 } | |
26 $last_time = $top_time + 3600 * $program_length; | |
27 | |
28 // 時刻欄 | |
29 for( $i = 0 ; $i < $program_length; $i++ ) { | |
30 $tvtimes[$i] = date("H", $top_time + 3600 * $i ); | |
31 } | |
32 | |
33 | |
34 // 番組表 | |
35 $programs = array(); | |
36 if( $type == "BS" ) $channel_map = $BS_CHANNEL_MAP; | |
37 else if( $type == "GR" ) $channel_map = $GR_CHANNEL_MAP; | |
38 $st = 0; | |
39 foreach( $channel_map as $channel_disc => $channel ) { | |
40 $prev_end = $top_time; | |
41 try { | |
42 $crec = new DBRecord( TBL_PREFIX . CHANNEL_TBL, "channel_disc", $channel_disc ); | |
43 $programs[$st]["station_name"] = $crec->name; | |
44 $prec = DBRecord::createRecords( TBL_PREFIX . PROGRAM_TBL, "". | |
45 "WHERE channel_disc = '".$channel_disc."' ". | |
46 "AND endtime > '".toDatetime($top_time)."' ". | |
47 "AND starttime < '". toDatetime($last_time)."' ". | |
48 "ORDER BY starttime ASC " | |
49 ); | |
50 $programs[$st]['list'] = array(); | |
51 $num = 0; | |
52 foreach( $prec as $prg ) { | |
53 // 前プログラムとの空きを調べる | |
54 $start = toTimestamp( $prg->starttime ); | |
55 if( $start - $prev_end ) { | |
56 $height = ($start-$prev_end) / 60; | |
57 if( $height > 0.5 ) { | |
58 $height = (int)($height * 2); | |
59 $programs[$st]['list'][$num]['category_none'] = "none"; | |
60 $programs[$st]['list'][$num]['height'] = $height; | |
61 $programs[$st]['list'][$num]['title'] = ""; | |
62 $programs[$st]['list'][$num]['starttime'] = ""; | |
63 $programs[$st]['list'][$num]['description'] = ""; | |
64 $num++; | |
65 } | |
66 } | |
67 $prev_end = toTimestamp( $prg->endtime ); | |
68 | |
69 $height = (int)((toTimestamp($prg->endtime) - toTimestamp($prg->starttime)) / 30); | |
70 // $top_time より早く始まっている番組 | |
71 if( toTimestamp($prg->starttime) <$top_time ) { | |
72 $height = (int)((toTimestamp($prg->endtime) - $top_time ) / 30); | |
73 } | |
74 // $last_time より遅く終わる番組 | |
75 if( toTimestamp($prg->endtime) > $last_time ) { | |
76 $height = (int)(($last_time - toTimestamp($prg->starttime)) / 30); | |
77 } | |
78 | |
79 // プログラムを埋める | |
80 $cat = new DBRecord( TBL_PREFIX . CATEGORY_TBL, "id", $prg->category_id ); | |
81 $programs[$st]['list'][$num]['category_name'] = $cat->name_en; | |
82 $programs[$st]['list'][$num]['height'] = $height; | |
83 $programs[$st]['list'][$num]['title'] = $prg->title; | |
84 $programs[$st]['list'][$num]['starttime'] = date("H:i", $start )."" ; | |
85 $programs[$st]['list'][$num]['description'] = $prg->description; | |
86 $programs[$st]['list'][$num]['prg_start'] = str_replace( "-", "/", $prg->starttime); | |
87 $programs[$st]['list'][$num]['duration'] = "" . (toTimestamp($prg->endtime) - toTimestamp($prg->starttime)); | |
88 $programs[$st]['list'][$num]['channel'] = ($prg->type == "GR" ? "地上D" : "BS" ) . ":". $prg->channel . "ch"; | |
89 $programs[$st]['list'][$num]['id'] = "" . ($prg->id); | |
90 $programs[$st]['list'][$num]['rec'] = DBRecord::countRecords( TBL_PREFIX.RESERVE_TBL, "WHERE complete = '0' AND program_id = '".$prg->id."'" ); | |
91 $num++; | |
92 } | |
93 } | |
94 catch( exception $e ) { | |
95 exit( $e->getMessage() ); | |
96 } | |
97 // 空きを埋める | |
98 if( $last_time - $prev_end ) { | |
99 $height = ($last_time - $prev_end) / 60; | |
100 if( $height > 0.5 ) { | |
101 $height = (int)($height * 2); | |
102 $programs[$st]['list'][$num]['category_name'] = "none"; | |
103 $programs[$st]['list'][$num]['height'] = $height; | |
104 $programs[$st]['list'][$num]['title'] = ""; | |
105 $programs[$st]['list'][$num]['starttime'] = ""; | |
106 $programs[$st]['list'][$num]['description'] = ""; | |
107 $num++; | |
108 } | |
109 } | |
110 $st++; | |
111 } | |
112 | |
113 // 局の幅 | |
114 $ch_set_width = 150; | |
115 // 全体の幅 | |
116 $chs_width = $ch_set_width * count( $channel_map ); | |
117 | |
118 // GETパラメタ | |
119 $get_param = $_SERVER['SCRIPT_NAME'] . "?type=".$type."&length=".$program_length.""; | |
120 | |
121 $smarty = new Smarty(); | |
122 | |
123 // カテゴリ一覧 | |
124 $crec = DBRecord::createRecords( TBL_PREFIX . CATEGORY_TBL ); | |
125 $cats = array(); | |
126 $num = 0; | |
127 foreach( $crec as $val ) { | |
128 $cats[$num]['name_en'] = $val->name_en; | |
129 $cats[$num]['name_jp'] = $val->name_jp; | |
130 $num++; | |
131 } | |
132 $smarty->assign( "cats", $cats ); | |
133 | |
134 | |
135 | |
136 // タイプ選択 | |
137 $types = array(); | |
138 $i = 0; | |
139 if( BS_TUNERS ) { | |
140 $types[$i]['selected'] = $type == "BS" ? 'class="selected"' : ""; | |
141 $types[$i]['link'] = $_SERVER['SCRIPT_NAME'] . "?type=BS&length=".$program_length."&time=".date( "YmdH", $top_time); | |
142 $types[$i]['name'] = "BS"; | |
143 $i++; | |
144 } | |
145 if( GR_TUNERS ) { | |
146 $types[$i]['selected'] = $type == "GR" ? 'class="selected"' : ""; | |
147 $types[$i]['link'] = $_SERVER['SCRIPT_NAME'] . "?type=GR&length=".$program_length."&time=".date( "YmdH", $top_time); | |
148 $types[$i]['name'] = "地上デジタル"; | |
149 $i++; | |
150 } | |
151 $smarty->assign( "types", $types ); | |
152 | |
153 // 日付選択 | |
154 $days = array(); | |
155 $day = array(); | |
156 $day['d'] = "昨日"; | |
157 $day['link'] = $get_param . "&time=". date( "YmdH", time() - 3600 *24 ); | |
158 $day['ofweek'] = ""; | |
159 $day['selected'] = $top_time < mktime( 0, 0 , 0) ? 'class="selected"' : ''; | |
160 | |
161 array_push( $days , $day ); | |
162 $day['d'] = "現在"; | |
163 $day['link'] = $get_param; | |
164 $day['ofweek'] = ""; | |
165 $day['selected'] = ""; | |
166 array_push( $days, $day ); | |
167 for( $i = 0 ; $i < 8 ; $i++ ) { | |
168 $day['d'] = "".date("d", time() + 24 * 3600 * $i ) . "日"; | |
169 $day['link'] = $get_param . "&time=".date( "Ymd", time() + 24 * 3600 * $i) . date("H" , $top_time ); | |
170 $day['ofweek'] = $DAY_OF_WEEK[(int)date( "w", time() + 24 * 3600 * $i )]; | |
171 $day['selected'] = date("d", $top_time) == date("d", time() + 24 * 3600 * $i ) ? 'class="selected"' : ''; | |
172 array_push( $days, $day ); | |
173 } | |
174 $smarty->assign( "days" , $days ); | |
175 | |
176 // 時間選択 | |
177 $toptimes = array(); | |
178 for( $i = 0 ; $i < 24; $i+=4 ) { | |
179 $tmp = array(); | |
180 $tmp['hour'] = sprintf( "%02d:00", $i ); | |
181 $tmp['link'] = $get_param . "&time=".date("Ymd", $top_time ) . sprintf("%02d", $i ); | |
182 array_push( $toptimes, $tmp ); | |
183 } | |
184 $smarty->assign( "toptimes" , $toptimes ); | |
185 | |
186 $smarty->assign( "tvtimes", $tvtimes ); | |
187 $smarty->assign( "programs", $programs ); | |
188 $smarty->assign( "ch_set_width", $ch_set_width ); | |
189 $smarty->assign( "chs_width", $chs_width ); | |
190 | |
191 // date("Y-m-d H:i:s", $timestamp); | |
192 | |
193 $sitetitle = date( "Y", $top_time ) . "年" . date( "m", $top_time ) . "月" . date( "d", $top_time ) . "日". date( "H", $top_time ) . | |
194 "時~".( $type == "GR" ? "地上デジタル" : "BSデジタル" )."番組表"; | |
195 | |
196 $smarty->assign("sitetitle", $sitetitle ); | |
197 | |
198 $smarty->assign("top_time", str_replace( "-", "/" ,toDatetime($top_time)) ); | |
199 $smarty->assign("last_time", str_replace( "-", "/" ,toDatetime($last_time)) ); | |
200 | |
201 | |
202 $smarty->display("index.html"); | |
203 ?> |