Mercurial > epgrec.yaz
annotate index.php @ 100:6619fefc7056
make config.xml writable by anyone if it exists.
author | Yoshiki Yazawa <yaz@honeyplanet.jp> |
---|---|
date | Thu, 04 Mar 2010 17:11:02 +0900 |
parents | cb7da56c4198 |
children | cb04c9ca1cb0 |
rev | line source |
---|---|
50 | 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 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(\"install/step1.php\",\"_self\");". | |
15 "// -->\n</script>" ); | |
16 } | |
17 | |
18 $settings = Settings::factory(); | |
19 | |
20 $DAY_OF_WEEK = array( "(日)","(月)","(火)","(水)","(木)","(金)","(土)" ); | |
21 | |
22 // パラメータの処理 | |
23 // 表示する長さ(時間) | |
24 $program_length = $settings->program_length; | |
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; | |
67
a2c4665b310c
add: CS support (thanks to dakku)
Sushi-k <epgrec@park.mda.or.jp>
parents:
58
diff
changeset
|
50 else if( $type == "CS" ) $channel_map = $CS_CHANNEL_MAP; |
50 | 51 $st = 0; |
76
69e0dabc765a
fixed: Reservation.class.php
Sushi-k <epgrec@park.mda.or.jp>
parents:
67
diff
changeset
|
52 $prec = null; |
69e0dabc765a
fixed: Reservation.class.php
Sushi-k <epgrec@park.mda.or.jp>
parents:
67
diff
changeset
|
53 try { |
69e0dabc765a
fixed: Reservation.class.php
Sushi-k <epgrec@park.mda.or.jp>
parents:
67
diff
changeset
|
54 $prec = new DBRecord(PROGRAM_TBL); |
69e0dabc765a
fixed: Reservation.class.php
Sushi-k <epgrec@park.mda.or.jp>
parents:
67
diff
changeset
|
55 } |
69e0dabc765a
fixed: Reservation.class.php
Sushi-k <epgrec@park.mda.or.jp>
parents:
67
diff
changeset
|
56 catch( Exception $e ) { |
69e0dabc765a
fixed: Reservation.class.php
Sushi-k <epgrec@park.mda.or.jp>
parents:
67
diff
changeset
|
57 exit('プログラムテーブルが存在しないようです。インストールをやり直してください.'); |
69e0dabc765a
fixed: Reservation.class.php
Sushi-k <epgrec@park.mda.or.jp>
parents:
67
diff
changeset
|
58 } |
50 | 59 foreach( $channel_map as $channel_disc => $channel ) { |
60 $prev_end = $top_time; | |
61 try { | |
62 $crec = new DBRecord( CHANNEL_TBL, "channel_disc", $channel_disc ); | |
63 $programs[$st]["station_name"] = $crec->name; | |
77 | 64 $programs[$st]["channel_disc"] = $crec->channel_disc; |
50 | 65 |
66 $reca = $prec->fetch_array( "channel_disc", $channel_disc, | |
67 "endtime > '".toDatetime($top_time)."' ". | |
68 "AND starttime < '". toDatetime($last_time)."' ". | |
69 "ORDER BY starttime ASC " | |
70 ); | |
71 $programs[$st]['list'] = array(); | |
72 $num = 0; | |
73 foreach( $reca as $prg ) { | |
74 // 前プログラムとの空きを調べる | |
75 $start = toTimestamp( $prg['starttime'] ); | |
51 | 76 if( ($start - $prev_end) > 0 ) { |
50 | 77 $height = ($start-$prev_end) * $settings->height_per_hour / 3600; |
78 $height = $height; | |
79 $programs[$st]['list'][$num]['category_none'] = "none"; | |
80 $programs[$st]['list'][$num]['height'] = $height; | |
81 $programs[$st]['list'][$num]['title'] = ""; | |
82 $programs[$st]['list'][$num]['starttime'] = ""; | |
83 $programs[$st]['list'][$num]['description'] = ""; | |
84 $num++; | |
85 } | |
86 $prev_end = toTimestamp( $prg['endtime'] ); | |
87 | |
88 $height = ((toTimestamp($prg['endtime']) - toTimestamp($prg['starttime'])) * $settings->height_per_hour / 3600); | |
89 // $top_time より早く始まっている番組 | |
90 if( toTimestamp($prg['starttime']) <$top_time ) { | |
91 $height = ((toTimestamp($prg['endtime']) - $top_time ) * $settings->height_per_hour / 3600); | |
92 } | |
93 // $last_time より遅く終わる番組 | |
94 if( toTimestamp($prg['endtime']) > $last_time ) { | |
95 $height = (($last_time - toTimestamp($prg['starttime'])) * $settings->height_per_hour / 3600); | |
96 } | |
97 | |
98 // プログラムを埋める | |
99 $cat = new DBRecord( CATEGORY_TBL, "id", $prg['category_id'] ); | |
100 $programs[$st]['list'][$num]['category_name'] = $cat->name_en; | |
101 $programs[$st]['list'][$num]['height'] = $height; | |
102 $programs[$st]['list'][$num]['title'] = $prg['title']; | |
103 $programs[$st]['list'][$num]['starttime'] = date("H:i", $start )."" ; | |
104 $programs[$st]['list'][$num]['description'] = $prg['description']; | |
105 $programs[$st]['list'][$num]['prg_start'] = str_replace( "-", "/", $prg['starttime']); | |
106 $programs[$st]['list'][$num]['duration'] = "" . (toTimestamp($prg['endtime']) - toTimestamp($prg['starttime'])); | |
107 $programs[$st]['list'][$num]['channel'] = ($prg['type'] == "GR" ? "地上D" : "BS" ) . ":". $prg['channel'] . "ch"; | |
108 $programs[$st]['list'][$num]['id'] = "" . ($prg['id']); | |
109 $programs[$st]['list'][$num]['rec'] = DBRecord::countRecords(RESERVE_TBL, "WHERE complete = '0' AND program_id = '".$prg['id']."'" ); | |
110 $num++; | |
111 } | |
112 } | |
113 catch( exception $e ) { | |
76
69e0dabc765a
fixed: Reservation.class.php
Sushi-k <epgrec@park.mda.or.jp>
parents:
67
diff
changeset
|
114 // exit( $e->getMessage() ); |
69e0dabc765a
fixed: Reservation.class.php
Sushi-k <epgrec@park.mda.or.jp>
parents:
67
diff
changeset
|
115 // 何もしない |
50 | 116 } |
117 // 空きを埋める | |
51 | 118 if( ($last_time - $prev_end) > 0 ) { |
50 | 119 $height = ($last_time - $prev_end) * $settings->height_per_hour / 3600; |
120 $height = $height; | |
121 $programs[$st]['list'][$num]['category_name'] = "none"; | |
122 $programs[$st]['list'][$num]['height'] = $height; | |
123 $programs[$st]['list'][$num]['title'] = ""; | |
124 $programs[$st]['list'][$num]['starttime'] = ""; | |
125 $programs[$st]['list'][$num]['description'] = ""; | |
126 $num++; | |
127 } | |
128 $st++; | |
129 } | |
130 $prec = null; | |
131 | |
132 // 局の幅 | |
133 $ch_set_width = $settings->ch_set_width; | |
134 // 全体の幅 | |
135 $chs_width = $ch_set_width * count( $channel_map ); | |
136 | |
137 // GETパラメタ | |
138 $get_param = $_SERVER['SCRIPT_NAME'] . "?type=".$type."&length=".$program_length.""; | |
139 | |
140 $smarty = new Smarty(); | |
141 | |
142 // カテゴリ一覧 | |
143 $crec = DBRecord::createRecords( CATEGORY_TBL ); | |
144 $cats = array(); | |
145 $num = 0; | |
146 foreach( $crec as $val ) { | |
147 $cats[$num]['name_en'] = $val->name_en; | |
148 $cats[$num]['name_jp'] = $val->name_jp; | |
149 $num++; | |
150 } | |
151 $smarty->assign( "cats", $cats ); | |
152 | |
153 | |
154 | |
155 // タイプ選択 | |
156 $types = array(); | |
157 $i = 0; | |
57 | 158 if( $settings->bs_tuners != 0 ) { |
50 | 159 $types[$i]['selected'] = $type == "BS" ? 'class="selected"' : ""; |
160 $types[$i]['link'] = $_SERVER['SCRIPT_NAME'] . "?type=BS&length=".$program_length."&time=".date( "YmdH", $top_time); | |
161 $types[$i]['name'] = "BS"; | |
162 $i++; | |
67
a2c4665b310c
add: CS support (thanks to dakku)
Sushi-k <epgrec@park.mda.or.jp>
parents:
58
diff
changeset
|
163 |
a2c4665b310c
add: CS support (thanks to dakku)
Sushi-k <epgrec@park.mda.or.jp>
parents:
58
diff
changeset
|
164 // CS |
a2c4665b310c
add: CS support (thanks to dakku)
Sushi-k <epgrec@park.mda.or.jp>
parents:
58
diff
changeset
|
165 if ($settings->cs_rec_flg != 0) { |
a2c4665b310c
add: CS support (thanks to dakku)
Sushi-k <epgrec@park.mda.or.jp>
parents:
58
diff
changeset
|
166 $types[$i]['selected'] = $type == "CS" ? 'class="selected"' : ""; |
a2c4665b310c
add: CS support (thanks to dakku)
Sushi-k <epgrec@park.mda.or.jp>
parents:
58
diff
changeset
|
167 $types[$i]['link'] = $_SERVER['SCRIPT_NAME'] . "?type=CS&length=".$program_length."&time=".date( "YmdH", $top_time); |
a2c4665b310c
add: CS support (thanks to dakku)
Sushi-k <epgrec@park.mda.or.jp>
parents:
58
diff
changeset
|
168 $types[$i]['name'] = "CS"; |
a2c4665b310c
add: CS support (thanks to dakku)
Sushi-k <epgrec@park.mda.or.jp>
parents:
58
diff
changeset
|
169 $i++; |
a2c4665b310c
add: CS support (thanks to dakku)
Sushi-k <epgrec@park.mda.or.jp>
parents:
58
diff
changeset
|
170 } |
50 | 171 } |
57 | 172 if( $settings->gr_tuners != 0 ) { |
50 | 173 $types[$i]['selected'] = $type == "GR" ? 'class="selected"' : ""; |
174 $types[$i]['link'] = $_SERVER['SCRIPT_NAME'] . "?type=GR&length=".$program_length."&time=".date( "YmdH", $top_time); | |
175 $types[$i]['name'] = "地上デジタル"; | |
176 $i++; | |
177 } | |
178 $smarty->assign( "types", $types ); | |
179 | |
180 // 日付選択 | |
181 $days = array(); | |
182 $day = array(); | |
183 $day['d'] = "昨日"; | |
184 $day['link'] = $get_param . "&time=". date( "YmdH", time() - 3600 *24 ); | |
185 $day['ofweek'] = ""; | |
186 $day['selected'] = $top_time < mktime( 0, 0 , 0) ? 'class="selected"' : ''; | |
187 | |
188 array_push( $days , $day ); | |
189 $day['d'] = "現在"; | |
190 $day['link'] = $get_param; | |
191 $day['ofweek'] = ""; | |
192 $day['selected'] = ""; | |
193 array_push( $days, $day ); | |
194 for( $i = 0 ; $i < 8 ; $i++ ) { | |
195 $day['d'] = "".date("d", time() + 24 * 3600 * $i ) . "日"; | |
196 $day['link'] = $get_param . "&time=".date( "Ymd", time() + 24 * 3600 * $i) . date("H" , $top_time ); | |
197 $day['ofweek'] = $DAY_OF_WEEK[(int)date( "w", time() + 24 * 3600 * $i )]; | |
198 $day['selected'] = date("d", $top_time) == date("d", time() + 24 * 3600 * $i ) ? 'class="selected"' : ''; | |
199 array_push( $days, $day ); | |
200 } | |
201 $smarty->assign( "days" , $days ); | |
202 | |
203 // 時間選択 | |
204 $toptimes = array(); | |
205 for( $i = 0 ; $i < 24; $i+=4 ) { | |
206 $tmp = array(); | |
207 $tmp['hour'] = sprintf( "%02d:00", $i ); | |
208 $tmp['link'] = $get_param . "&time=".date("Ymd", $top_time ) . sprintf("%02d", $i ); | |
209 array_push( $toptimes, $tmp ); | |
210 } | |
211 $smarty->assign( "toptimes" , $toptimes ); | |
212 | |
213 $smarty->assign( "tvtimes", $tvtimes ); | |
214 $smarty->assign( "programs", $programs ); | |
215 $smarty->assign( "ch_set_width", $settings->ch_set_width ); | |
216 $smarty->assign( "chs_width", $chs_width ); | |
217 $smarty->assign( "height_per_hour", $settings->height_per_hour ); | |
58
80dc62c94185
add: height_per_minite at index.html
Sushi-k <epgrec@park.mda.or.jp>
parents:
57
diff
changeset
|
218 $smarty->assign( "height_per_min", $settings->height_per_hour / 60 ); |
50 | 219 |
220 // date("Y-m-d H:i:s", $timestamp); | |
221 | |
222 $sitetitle = date( "Y", $top_time ) . "年" . date( "m", $top_time ) . "月" . date( "d", $top_time ) . "日". date( "H", $top_time ) . | |
223 "時~".( $type == "GR" ? "地上デジタル" : "BSデジタル" )."番組表"; | |
224 | |
225 $smarty->assign("sitetitle", $sitetitle ); | |
226 | |
227 $smarty->assign("top_time", str_replace( "-", "/" ,toDatetime($top_time)) ); | |
228 $smarty->assign("last_time", str_replace( "-", "/" ,toDatetime($last_time)) ); | |
229 | |
230 | |
231 $smarty->display("index.html"); | |
76
69e0dabc765a
fixed: Reservation.class.php
Sushi-k <epgrec@park.mda.or.jp>
parents:
67
diff
changeset
|
232 ?> |