root/trunk/install/php/viewepg.php

リビジョン 111, 11.5 kB (コミッタ: sorshi, コミット時期: 9 年 前)

・放送波からのEPG番組表取得に対応。
・foltia_epgテーブル構成変更
・folcast.phpがSQLiteでまったく動作していなかったのを修正

Line 
1 <?php
2 /*
3  Anime recording system foltia
4  http://www.dcc-jpl.com/soft/foltia/
5
6 viewepg.php
7
8 目的
9 番組録画予約ページを表示します。
10
11 オプション
12 start:表示タイムスタンプ(Ex.200512281558)
13  省略時、現在時刻。
14
15  DCC-JPL Japan/foltia project
16
17 */
18
19 include("./foltialib.php");
20 $con = m_connect();
21
22 if ($useenvironmentpolicy == 1){
23     if (!isset($_SERVER['PHP_AUTH_USER'])) {
24         header("WWW-Authenticate: Basic realm=\"foltia\"");
25         header("HTTP/1.0 401 Unauthorized");
26         redirectlogin();
27         exit;
28     } else {
29     login($con,$_SERVER['PHP_AUTH_USER'],$_SERVER['PHP_AUTH_PW']);
30     }
31 }//end if login
32 ?>
33 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
34 <html lang="ja">
35 <head>
36 <meta http-equiv="Content-Type" content="text/html; charset=EUC-JP">
37 <meta http-equiv="Content-Style-Type" content="text/css">
38 <link rel="stylesheet" type="text/css" href="graytable.css">
39 <title>foltia:EPG番組表</title>
40 </head>
41 <?php
42 $start = getgetnumform("start");
43
44 if ($start == ""){
45     $start date("YmdHi");
46 }else{
47   $start = ereg_replace( "[^0-9]", "", $start);
48 }
49 ?>
50 <body BGCOLOR="#ffffff" TEXT="#494949" LINK="#0047ff" VLINK="#000000" ALINK="#c6edff" >
51 <div align="center">
52 <?php
53 printhtmlpageheader();
54 ?>
55 <p align="left"><font color="#494949" size="6">EPG番組表</font></p>
56 <p align="left"><a href="./m.php">番組手動予約</a ></p>
57 <hr size="4">
58 <p align="left">EPG番組表を表示します。
59 <?php
60
61 $startyear =   substr($start,0,4);
62 $startmonth =   substr($start,4,2);
63 $startday =   substr($start,6,2);
64 $starthour =   substr($start,8,2);
65 $startmin =   substr($start,10,2);
66 print "($startyear/$startmonth/$startday $starthour:$startmin-)<BR>\n";
67
68 $yesterday = date ("YmdHi",mktime($starthour , 0 , 0, $startmonth , $startday -1 , $startyear));
69 $dayyesterday = date ("m/d(D)",mktime($starthour , 0 , 0, $startmonth , $startday -1 , $startyear));
70 $today0400 = date ("YmdHi",mktime(4 , 0 , 0, $startmonth , $startday  , $startyear));
71 $today0800 = date ("YmdHi",mktime(8 , 0 , 0, $startmonth , $startday  , $startyear));
72 $today1200 = date ("YmdHi",mktime(12 , 0 , 0, $startmonth , $startday , $startyear));
73 $today1600 = date ("YmdHi",mktime(16 , 0 , 0, $startmonth , $startday , $startyear));
74 $today2000 = date ("YmdHi",mktime(20 , 0 , 0, $startmonth , $startday , $startyear));
75 $today2359 = date ("YmdHi",mktime(23 , 59 , 0, $startmonth , $startday , $startyear));
76 $day1after = date ("YmdHi",mktime($starthour , 0 , 0, $startmonth , $startday +1 , $startyear));
77 $day1 = date ("m/d(D)",mktime($starthour , 0 , 0, $startmonth , $startday +1 , $startyear));
78 $day2after = date ("YmdHi",mktime($starthour , 0 , 0, $startmonth , $startday +2 , $startyear));
79 $day2 = date ("m/d(D)",mktime($starthour , 0 , 0, $startmonth , $startday +2 , $startyear));
80 $day3after = date ("YmdHi",mktime($starthour , 0 , 0, $startmonth , $startday +3 , $startyear));
81 $day3 = date ("m/d(D)",mktime($starthour , 0 , 0, $startmonth , $startday +3 , $startyear));
82 $day4after = date ("YmdHi",mktime($starthour , 0 , 0, $startmonth , $startday +4 , $startyear));
83 $day4 = date ("m/d(D)",mktime($starthour , 0 , 0, $startmonth , $startday +4 , $startyear));
84 $day5after = date ("YmdHi",mktime($starthour , 0 , 0, $startmonth , $startday +5 , $startyear));
85 $day5 = date ("m/d(D)",mktime($starthour , 0 , 0, $startmonth , $startday +5 , $startyear));
86 $day6after = date ("YmdHi",mktime($starthour , 0 , 0, $startmonth , $startday +6 , $startyear));
87 $day6 = date ("m/d(D)",mktime($starthour , 0 , 0, $startmonth , $startday +6 , $startyear));
88 $day7after = date ("YmdHi",mktime($starthour , 0 , 0, $startmonth , $startday +7 , $startyear));
89 $day7 = date ("m/d(D)",mktime($starthour , 0 , 0, $startmonth , $startday +7 , $startyear));
90
91
92
93 //表示局選定
94 // $page = 1 ~
95 $maxdisplay = 8;
96
97 $query = "SELECT count(*) FROM foltia_station WHERE \"ontvcode\" LIKE '%ontvjapan%'";
98 //$rs = m_query($con, $query, "DBクエリに失敗しました");
99 $rs = sql_query($con, $query, "DBクエリに失敗しました");
100 $maxrows = $rs->fetchColumn(0);
101 if ($maxrows > $maxdisplay){
102     $pages = ceil($maxrows / $maxdisplay) ;
103 }
104
105 $page = getgetnumform("p");
106
107 if (($page == "")|| ($page <= 0) ){
108     $page = 1 ;
109     $offset = ;
110 }else{
111   $page = ereg_replace( "[^0-9]", "", $page);
112   if ($page > $pages){
113       $page = $pages ;
114   }elseif ($page <= 0) {
115   $page = 1 ;
116   }
117   $offset = ($page * $maxdisplay ) - $maxdisplay;
118 }
119
120
121 print "←<A HREF=\"./viewepg.php?p=$page&start=$yesterday\">$dayyesterday(前日)</A> <A HREF=\"./viewepg.php\">現在</A> 当日(<A HREF=\"./viewepg.php?p=$page&start=$today0400\">4:00</A> <A HREF=\"./viewepg.php?p=$page&start=$today0800\">8:00</A> <A HREF=\"./viewepg.php?p=$page&start=$today1200\">12:00</A> <A HREF=\"./viewepg.php?p=$page&start=$today1600\">16:00</A> <A HREF=\"./viewepg.php?p=$page&start=$today2000\">20:00</A> <A HREF=\"./viewepg.php?p=$page&start=$today2359\">24:00</A>) <A HREF=\"./viewepg.php?p=$page&start=$day1after\">$day1(翌日)</A> <A HREF=\"./viewepg.php?p=$page&start=$day2after\">$day2</A> <A HREF=\"./viewepg.php?p=$page&start=$day3after\">$day3</A> <A HREF=\"./viewepg.php?p=$page&start=$day4after\">$day4</A> <A HREF=\"./viewepg.php?p=$page&start=$day5after\">$day5</A> <A HREF=\"./viewepg.php?p=$page&start=$day6after\">$day6</A> <A HREF=\"./viewepg.php?p=$page&start=$day7after\">$day7</A>→<BR>\n";
122
123
124 if ($maxrows > $maxdisplay){
125 //複数ページ
126 //$pages = ceil($maxrows / $maxdisplay) ;
127 if ($page > 1){
128     $beforepage = $page - 1;
129     print "<a href = \"./viewepg.php?p=$beforepage&start=$start\">←</A>";
130 }
131
132 print " $page / $pages (放送局) ";
133 for ($i=1;$i<=$pages;$i++){
134     print "<a href = \"./viewepg.php?p=$i&start=$start\">$i</a>・";
135 }
136
137
138 if ($page < $pages){
139     $nextpage = $page + 1;
140     print "<a href = \"./viewepg.php?p=$nextpage&start=$start\">→</a>";
141 }
142 }
143 //ココから新コード
144 //・局リスト
145 $query = "SELECT stationid, stationname, stationrecch, ontvcode
146 FROM foltia_station
147 WHERE \"ontvcode\" LIKE '%ontvjapan%' 
148 ORDER BY stationid ASC , stationrecch
149 LIMIT ? OFFSET ?
150 ";
151
152 //$slistrs = m_query($con, $query, "DBクエリに失敗しました");
153 $slistrs = sql_query($con, $query, "DBクエリに失敗しました",array($maxdisplay,$offset));
154 while ($rowdata = $slistrs->fetch()) {
155     $stationhash[] = $rowdata[3];
156     $snames[] = $rowdata[1]; // headder
157 }
158
159 //・時間と全順番のハッシュ作る
160 $epgstart = $start ;
161 $epgend = calcendtime($start , (8*60));
162
163 $query = "SELECT DISTINCT startdatetime   
164 FROM foltia_epg
165 WHERE foltia_epg.ontvchannel in (
166     SELECT ontvcode
167     FROM foltia_station
168     WHERE \"ontvcode\" LIKE '%ontvjapan%'
169     ORDER BY stationid ASC , stationrecch
170     LIMIT ? OFFSET ?
171     )
172 AND startdatetime  >= ?
173 AND startdatetime  < ?
174 ORDER BY foltia_epg.startdatetime  ASC    ";
175
176 //$rs = m_query($con, $query, "DBクエリに失敗しました");
177 $rs = sql_query($con, $query, "DBクエリに失敗しました",array($maxdisplay,$offset,$start,$epgend));
178
179 //print "$query<br>\n";
180
181 $rowdata = $rs->fetch();
182 if (! $rowdata) {
183 //番組データがない
184 $colmnums = 2;
185 }else{
186     $colmnums = 0;
187     do {
188         $colmnums++;
189         $timetablehash[$rowdata[0]] = $colmnums;
190 //        print "$rowdata[0]:$i+1 <br>\n";
191     } while ($rowdata = $rs->fetch());
192 }
193 //print "colmnums $colmnums <br>\n";
194
195 //・局ごとに縦に配列入れていく
196 foreach ($stationhash as $stationname) {
197 $epgstart = $start ;
198 $epgend = calcendtime($start , (8*60));
199 $query = "
200 SELECT startdatetime , enddatetime , lengthmin , epgtitle , epgdesc , epgcategory  ,ontvchannel  ,epgid ,    epgcategory
201 FROM foltia_epg
202 WHERE foltia_epg.ontvchannel = ? AND
203 enddatetime  > ?  AND
204 startdatetime  < ? 
205 ORDER BY foltia_epg.startdatetime  ASC
206     ";
207
208 //    $statiodh = m_query($con, $query, "DBクエリに失敗しました");
209     $statiodh = sql_query($con, $query, "DBクエリに失敗しました",array($stationname,$epgstart,$epgend));
210     $stationrowdata = $statiodh->fetch();
211     if (! $stationrowdata) {
212         //print("番組データがありません<BR>");
213         $item[0]["$stationname"] =  ">番組データがありません";
214 }else{
215         do {
216 $printstarttime = substr($stationrowdata[0],8,2) . ":" substr($stationrowdata[0],10,2);
217 $tdclass = "t".substr($stationrowdata[0],8,2) .  substr($stationrowdata[0],10,2);
218 $title = $stationrowdata[3];
219 $title = htmlspecialchars(z2h($title));
220 $desc = $stationrowdata[4];
221 $desc = htmlspecialchars(z2h($desc));
222 $height htmlspecialchars($stationrowdata[2]) * 3;
223 $epgid htmlspecialchars($stationrowdata[7]);
224 $epgcategory = htmlspecialchars($stationrowdata[8]);
225
226 if (isset($timetablehash["$stationrowdata[0]"])){
227     $number = $timetablehash["$stationrowdata[0]"];
228 //print "$stationname $stationrowdata[0] [$number] $printstarttime $title $desc<br>\n";
229 }else{
230     $number = 0;
231 //print "$stationname $stationrowdata[0] 現在番組 $printstarttime $title $desc<br>\n";
232 }
233 if ($epgcategory == ""){
234 $item["$number"]["$stationname"] =  " onClick=\"location = './reserveepg.php?epgid=$epgid'\"><span id=\"epgstarttime\">$printstarttime</span> <A HREF=\"./reserveepg.php?epgid=$epgid\"><span id=\"epgtitle\">$title</span></A> <span id=\"epgdesc\">$desc</span>";
235 }else{
236 $item["$number"]["$stationname"] =  " id=\"$epgcategory\" onClick=\"location = './reserveepg.php?epgid=$epgid'\"><span id=\"epgstarttime\">$printstarttime</span> <A HREF=\"./reserveepg.php?epgid=$epgid\"><span id=\"epgtitle\">$title</span></A> <span id=\"epgdesc\">$desc</span></span>";
237 }//if
238
239         } while ($stationrowdata = $statiodh->fetch());
240 }//if
241
242 //・局ごとに間隔決定
243 //$item[$i][NHK] はヌルかどうか判定
244 $dataplace = 0 ; //初期化
245 $rowspan = 0;
246
247 for ($i=1; $i <= $colmnums ; $i++){
248     if ($i === ($colmnums )){//最終行
249         $rowspan = $i - $dataplace ;
250         //そして自分自身にタグを
251             //if ((!isset($item[$i][$stationname])) && ($item[$i][$stationname] == "")){
252             if (!isset($item[$i][$stationname])){
253             $item[$i][$stationname]  = null ;
254             }else{
255             $item[$i][$stationname]  = "<td ". $item[$i][$stationname] . "</td>";
256             $rowspan--;
257             }
258             //ROWSPAN
259             if ($rowspan === 1 ){
260             $item[$dataplace][$stationname]  = "<td ". $item[$dataplace][$stationname] . "</td>";
261             }else{
262             $item[$dataplace][$stationname]  = "<td  rowspan = $rowspan ". $item[$dataplace][$stationname] . "</td>";
263 //            $item[$dataplace][$stationname]  = "<td ". $item[$dataplace][$stationname] . "$rowspan </td>";
264             }
265
266 //    }elseif ((!isset($item[$i][$stationname]))&&($item[$i][$stationname] == "")){
267     }elseif (!isset($item[$i][$stationname])){
268     //ヌルなら
269         //$item[$i][$stationname]  =  $item[$i][$stationname] ;
270         $item[$i][$stationname]  =  null ;
271 //        $item[$i][$stationname]  =  "<td><br></td>" ;
272     }else{
273     //なんか入ってるなら
274         $rowspan = $i - $dataplace;
275         $itemDataplaceStationname = null;
276         if (isset($item[$dataplace][$stationname])){
277         $itemDataplaceStationname = $item[$dataplace][$stationname];
278         }
279             if ($rowspan === 1 ){
280             $item[$dataplace][$stationname]  = "<td ". $itemDataplaceStationname . "</td>";
281             }else{
282             $item[$dataplace][$stationname]  = "<td rowspan = $rowspan ". $itemDataplaceStationname . "</td>";
283 //            $item[$dataplace][$stationname]  = "<td ". $item[$dataplace][$stationname] . "$rowspan </td>";
284             }
285         $dataplace = $i;
286         
287     }
288 }//for
289 }// end of for://・局ごとに縦に配列入れていく
290
291 //・テーブルレンダリング
292 print "<table>\n<tr>";
293
294 //ヘッダ
295 foreach ($snames as $s) {
296     print "<th>".htmlspecialchars($s)."</th>" ;
297 }
298 //本体
299 for ($l = 0 ;$l $colmnums; $l++){
300     print "<tr>";
301     foreach ($stationhash as $stationname) {
302         print_r($item[$l]["$stationname"]);
303     }
304     print "</tr>\n";
305 }
306 print "</table>\n";
307  ?>
308
309 <hr>
310 凡例
311 <table>
312 <tr>
313 <td id="information">情報</td>
314 <td id="anime">アニメ・特撮</td>
315 <td id="news">ニュース・報道</td>
316 <td id="drama">ドラマ</td>
317 <td id="variety">バラエティ</td>
318 <td id="documentary">ドキュメンタリー・教養</td>
319 <td id="education">教育</td>
320 <td id="music">音楽</td>
321 <td id="cinema">映画</td>
322 <td id="hobby">趣味・実用</td>
323 <td id="kids">キッズ</td>
324 <td id="sports">スポーツ</td>
325 <td id="etc">その他</td>
326 <td id="stage">演劇</td>
327
328 </tr>
329 </table>
330 </body>
331 </html>
332
333
334
Note: リポジトリブラウザについてのヘルプは TracBrowser を参照してください。
track feed