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