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" );
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" .
14 "window.open(\"install/step1.php\",\"_self\");".
15 "// -->\n</script>" );
18 $settings = Settings::factory();
20 $DAY_OF_WEEK = array( "(日)","(月)","(火)","(水)","(木)","(金)","(土)" );
24 $program_length = $settings->program_length;
25 if( isset( $_GET['length']) ) $program_length = (int) $_GET['length'];
28 if( isset( $_GET['type'] ) ) $type = $_GET['type'];
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;
38 $last_time = $top_time + 3600 * $program_length;
41 for( $i = 0 ; $i < $program_length; $i++ ) {
42 $tvtimes[$i] = date("H", $top_time + 3600 * $i );
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;
54 $prec = new DBRecord(PROGRAM_TBL);
56 catch( Exception $e ) {
57 exit('プログラムテーブルが存在しないようです。インストールをやり直してください.');
60 foreach( $channel_map as $channel_disc => $channel ) {
61 $prev_end = $top_time;
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);
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 "
76 $programs[$st]['list'] = array();
78 foreach( $reca as $prg ) {
80 $start = toTimestamp( $prg['starttime'] );
81 if( ($start - $prev_end) > 0 ) {
82 $height = ($start-$prev_end) * $settings->height_per_hour / 3600;
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'] = "";
91 $prev_end = toTimestamp( $prg['endtime'] );
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);
98 // $last_time より遅く終わる番組
99 if( toTimestamp($prg['endtime']) > $last_time ) {
100 $height = (($last_time - toTimestamp($prg['starttime'])) * $settings->height_per_hour / 3600);
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']."'" );
118 catch( exception $e ) {
119 // exit( $e->getMessage() );
123 if( ($last_time - $prev_end) > 0 ) {
124 $height = ($last_time - $prev_end) * $settings->height_per_hour / 3600;
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'] = "";
138 $ch_set_width = (int)($settings->ch_set_width);
140 $chs_width = $ch_set_width * $num_ch;
143 $get_param = $_SERVER['SCRIPT_NAME'] . "?type=".$type."&length=".$program_length."";
145 $smarty = new Smarty();
148 $crec = DBRecord::createRecords( CATEGORY_TBL );
151 foreach( $crec as $val ) {
152 $cats[$num]['name_en'] = $val->name_en;
153 $cats[$num]['name_jp'] = $val->name_jp;
156 $smarty->assign( "cats", $cats );
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";
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";
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'] = "地上デジタル";
182 $smarty->assign( "types", $types );
188 $day['link'] = $get_param . "&time=". date( "YmdH", time() - 3600 *24 );
190 $day['selected'] = $top_time < mktime( 0, 0 , 0) ? 'class="selected"' : '';
192 array_push( $days , $day );
194 $day['link'] = $get_param;
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 );
205 $smarty->assign( "days" , $days );
209 for( $i = 0 ; $i < 24; $i+=4 ) {
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 );
215 $smarty->assign( "toptimes" , $toptimes );
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 ) );
226 // date("Y-m-d H:i:s", $timestamp);
228 $sitetitle = date( "Y", $top_time ) . "年" . date( "m", $top_time ) . "月" . date( "d", $top_time ) . "日". date( "H", $top_time ) .
229 "時~".( $type == "GR" ? "地上デジタル" : "BSデジタル" )."番組表";
231 $smarty->assign("sitetitle", $sitetitle );
233 $smarty->assign("top_time", str_replace( "-", "/" ,toDatetime($top_time)) );
234 $smarty->assign("last_time", str_replace( "-", "/" ,toDatetime($last_time)) );
237 $smarty->display("index.html");