OSDN Git Service

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