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