root/trunk/install/php/foltialib.php

リビジョン 46, 13.6 kB (コミッタ: sorshi, コミット時期: 17 年 前)

開始時刻、録画時間、録画局を個別に指定する手動番組予約機能追加。

Line 
1 <?php
2         
3 include("./foltia_config2.php");
4
5 /*
6 こちらのモジュールは
7 Apache + PHP + PostgreSQL 実験室
8 http://www.hizlab.net/app/
9 のサンプルを使わせていただいております。
10 ありがとうございます。
11 */
12
13     /* エラー表示の抑制 */
14     //error_reporting(0);
15
16     
17     //GET用フォームデコード
18       function getgetform($key) {
19     if ($_GET["{$key}"] != "") {
20         $value = $_GET["{$key}"];
21                    escape_string($value);
22                    htmlspecialchars($value);
23     return ($value);
24     }
25   }
26     //GET用数字フォームデコード
27       function getgetnumform($key) {
28     if ($_GET["{$key}"] != "") {
29         $value = $_GET["{$key}"];
30         escape_string($value);
31         htmlspecialchars($value);
32         $value = ereg_replace("[^0-9]", "", $value);
33         $value = escape_numeric($value);
34     return ($value);
35     }
36   }
37     
38     //フォームデコード
39       function getform($key) {
40             //    global $where;
41     if ($_POST["{$key}"] != "") {
42         $value = $_POST["{$key}"];
43                    escape_string($value);
44                    htmlspecialchars($value);
45     return ($value);
46     }
47   }
48     //数字専用フォームデコード
49       function getnumform($key) {
50     if ($_POST["{$key}"] != "") {
51         $value = $_POST["{$key}"];
52                    escape_string($value);
53                    htmlspecialchars($value);
54                    $value = ereg_replace("[^0-9]", "", $value);
55         $value = escape_numeric($value);
56     return ($value);
57     }
58   }
59
60     /* 全角カタカナ化してスペースを削除してインデックス用にする */
61     function name2read($name) {
62     $name = mb_convert_kana($name, "KVC", "EUC-JP");
63     $name = mb_convert_kana($name, "s", "EUC-JP");
64     $name = ereg_replace(" ", "", $name);
65
66         return $name;
67     }
68
69     /* 数字を半角化して数字化してインデックス用にする */
70     function pnum2dnum($num) {
71     $num = mb_convert_kana($num, "a", "EUC-JP");
72     $num = ereg_replace("[^0-9]", "", $num);
73
74         return $num;
75     }
76     
77     /* 終了関数の定義 */
78     function die_exit($message) {
79         ?>
80         <p class="error"><?= $message ?></p>
81         <div class="index"><a href="./">トップ</a></div>
82     </body>
83 </html><?
84         exit;
85     }
86     
87     /* 入力した値のサイズをチェック */
88     function check_length($str, $maxlen, $must, $name) {
89         $len = strlen($str);
90         if ($must && $len == 0) {
91             die_exit("$name が入力されてません。必須項目です。");
92         }
93         if ($len > $maxlen) {
94             die_exit("$name は $len 文字以下で入力して下さい。全角文字は、一文字で二文字分と計算されます。");
95         }
96     }
97     
98     /* LIKE 用の文字列のエスケープ */
99     function escape_like($sql, $quote = TRUE) {
100         return ($quote ? "'" : "") .
101                str_replace(array("\\\\",     "%"    , "_"    ),
102                            array("\\\\\\\\", "\\\\%", "\\\\_"),
103                            pg_escape_string($sql)) .
104                ($quote ? "'" : "");
105     }
106     
107     /* SQL 文字列のエスケープ */
108     function escape_string($sql, $quote = TRUE) {
109         if ($quote && strlen($sql) == 0) {
110             return "null";
111         }
112         return ($quote ? "'" : "") .
113                pg_escape_string($sql) .
114                ($quote ? "'" : "");
115     }
116     
117     /* SQL 数値のエスケープ */
118     function escape_numeric($sql) {
119         if (strlen($sql) == 0) {
120             return "null";
121         }
122         if (!is_numeric($sql)) {
123             die_exit("$sql は数値ではありません。");
124         }
125         return $sql;
126     }
127     
128     /* PostgreSQL サーバに接続 */
129     function m_connect() {
130 /*        $con = @pg_connect("host=".DBHOST ." dbname=".DATABASE_NAME .
131                            " user=".USER_NAME .
132                            " password=".USER_PASSWORD);
133 */
134         $con = @pg_pconnect("host=".DBHOST ." dbname=".DATABASE_NAME .
135                            " user=".USER_NAME .
136                            " password=".USER_PASSWORD);
137
138
139         if (!$con) {
140             die_exit("データベースに接続出来ませんでした。");
141         }
142         /* データベースと、PHP の内部文字コードが違う場合 */
143         return($con);
144     }
145
146     /* データベースとの接続を切り離す */
147     function m_close($con) {
148         return @pg_close($con);
149     }
150
151     /* SQL 文を実行 */
152     function m_query($con, $query, $errmessage) {
153         $rtn = @pg_query($con, $query);
154         if (!$rtn) {
155             /* エラーメッセージに SQL 文を出すのはセキュリティ上良くない!! */
156             $msg = $errmessage . "<br>\n" .
157                    @pg_last_error($con) . "<br>\n" .
158                    "<small><code>" . htmlspecialchars($query) .
159                    "</code></small>\n";
160                    $rtn = @pg_query($con, "rollback");//04.4.8
161             m_close($con);
162             die_exit($msg);
163         }
164         return($rtn);
165     }
166
167     /* select した結果をテーブルで表示 */
168     function m_showtable($rs) {
169         /* 検索件数 */
170         $maxrows = pg_num_rows($rs);
171         
172         if ($maxrows == 0) {
173             echo("<p class=\"msg\">データが存在しません</p>\n");
174             return 0;
175         }
176         
177         /* フィールド数 */
178         $maxcols = pg_num_fields($rs);
179         ?>
180 <table class="list" summary="データ検索結果を表示" border="1">
181     <thead>
182         <tr>
183             <?php
184                 /* テーブルのヘッダーを出力 */
185                 for ($col = 1; $col < $maxcols; $col++) {
186                     /* pg_field_name() はフィールド名を返す */
187                     $f_name = htmlspecialchars(pg_field_name($rs, $col));
188                     echo("<th abbr=\"$f_name\">$f_name</th>\n");
189                 }
190             ?>
191         </tr>
192     </thead>
193     <tbody>
194         <?php
195             /* テーブルのデータを出力 */
196             for ($row = 0; $row < $maxrows; $row++) { /* 行に対応 */
197                 echo("<tr>\n");
198                 /* pg_fetch_row で一行取り出す */
199                 $rowdata = pg_fetch_row($rs, $row);
200                 /* 1列目にリンクを張る */
201                 echo("<td><a href=\"edit.php?q_code=" .
202                      urlencode($rowdata[0]) . "\">" .
203                      htmlspecialchars($rowdata[1]) . "</a></td>\n");
204                 for ($col = 2; $col < $maxcols; $col++) { /* 列に対応 */
205                     echo("<td>".htmlspecialchars($rowdata[$col])."<br></td>\n");
206                 }
207                 echo("</tr>\n");
208             }
209         ?>
210     </tbody>
211 </table>
212         <?php
213         return $maxrows;
214     }
215
216     /* 指定したコードのデータを表示 */
217     function m_viewdata($con, $code) {
218         /* コードに該当するデータを検索 */
219         $query = "
220 select p.code
221       ,p.name
222       ,p.email
223       ,p.pseudonym
224       ,s.name as job
225       ,p.profile
226       ,to_char(p.editdate, 'YYYY/MM/DD HH24:MI:SS') as editdate
227   from inet_profile p left join inet_job s on p.job = s.code
228  where p.code = $code";
229         $rs = m_query($con, $query, "個人情報の取得に失敗しました。");
230         if (pg_num_rows($rs) == 0) {
231             echo("<p class=\"msg\">データが存在しません</p>\n");
232             return FALSE;
233         }
234         
235         /* フィールド数 */
236         $maxcols = pg_num_fields($rs);
237         /* 先頭行 */
238         $rowdata = pg_fetch_row($rs, 0);
239         ?>
240 <table class="view" summary="データベース上のデータを表示" border="1">
241     <tr>
242         <td class="name"><?= htmlspecialchars(pg_field_name($rs, 1)) ?></td>
243         <td><a href="edit.php?q_code=<?= $rowdata[0] ?>"
244              ><?= htmlspecialchars($rowdata[1]) ?></a></td>
245     </tr>
246     <?php for ($col = 2; $col < $maxcols; $col++) { ?>
247     <tr>
248         <td class="name"><?= htmlspecialchars(pg_field_name($rs, $col)) ?></td>
249         <td><?= htmlspecialchars($rowdata[$col]) ?></td>
250     </tr>
251     <?php } ?>
252 </table>
253         <?php
254         /* クエリーを解放 */
255         pg_free_result($rs);
256         
257         return TRUE;
258     }
259     
260
261 function printhtmlpageheader(){
262
263 $serveruri = getserveruri();
264
265 print "<p align='left'><font color='#494949'><A HREF = 'http://www.dcc-jpl.com/soft/foltia/' target=\"_blank\">foltia</A> | <A HREF = './index.php'>放映予定</A> | <A HREF = './index.php?mode=new'>新番組</A> | <A HREF = './listreserve.php'>予約一覧</A> | <A HREF = './titlelist.php'>番組一覧</A> | <A HREF = './viewepg.php'>番組表</A> | 録画一覧(<A HREF = './showplaylist.php'>録画順</A>・<A HREF = './showplaylist.php?list=title'>番組順</A>・<A HREF = './showplaylist.php?list=raw'>全</A>) | <A HREF = './showlib.php'>録画ライブラリ</A> |  <A HREF = './folcast.php'>Folcast(RSS)</A>[<a href=\"itpc://$serveruri/folcast.php\">iTunesにFolcastを登録</a>] |</font></p>\n";
266
267 }
268
269
270 function renderepgstation($con,$stationname,$start){ //戻り値 なし EPGの局表示
271
272 $now = date("YmdHi");
273 $today = date("Ymd");   
274 $tomorrow = date ("Ymd",mktime(0, 0, 0, date("m")  , date("d")+1, date("Y")));
275 //$today = "20051013";   
276 //$tomorrow = "20051014";
277 //$epgstart = $today . "2000";
278 $epgstart = $start ;
279 //$epgend = $tomorrow . "0400";
280 $epgend = calcendtime($start , (8*60));
281 $query = "
282 SELECT startdatetime , enddatetime , lengthmin , epgtitle , epgdesc , epgcategory  ,ontvchannel  ,epgid
283 FROM foltia_epg
284 WHERE foltia_epg.ontvchannel = '$stationname' AND
285 enddatetime  > $epgstart  AND
286 startdatetime  < $epgend 
287 ORDER BY foltia_epg.startdatetime  ASC
288     ";
289     $rs = m_query($con, $query, "DBクエリに失敗しました");
290     $maxrows = pg_num_rows($rs);
291 if ($maxrows == 0) {
292         print("番組データがありません<BR>");           
293 }else{
294 print "<table width=\"100%\"  border=\"0\">\n";
295 //print "<ul><!-- ($maxrows) $query -->\n";
296
297 for ($row = 0; $row < $maxrows; $row++) {
298     
299 $rowdata = pg_fetch_row($rs, $row);
300
301 $printstarttime = substr($rowdata[0],8,2) . ":" substr($rowdata[0],10,2);
302 $tdclass = "t".substr($rowdata[0],8,2) .  substr($rowdata[0],10,2);
303 $title = htmlspecialchars($rowdata[3]);
304 $title = z2h($title);
305 $desc = htmlspecialchars($rowdata[4]);
306 $desc = z2h($desc);
307 $height htmlspecialchars($rowdata[2]) * 3;
308 $epgid htmlspecialchars($rowdata[7]);
309
310 print"
311       <tr>
312         <td height = \"$height\" >$printstarttime  <A HREF=\"./reserveepg.php?epgid=$epgid\">$title</A> $desc <!-- $rowdata[0] - $rowdata[1] --></td>
313       </tr>
314 ";
315 /*print"<li style=\"height:" . $height ."px;\" class=\"$tdclass\">
316 $printstarttime  <A HREF=\"./reserveepg.php?epgid=$epgid\">$title</A> $desc($rowdata[0] - $rowdata[1])
317 </li>\n";
318 */
319 }//for
320 //print "</ul>\n";
321 print "</table>\n";
322
323 }//if
324 }//end function
325
326 function calcendtime($start,$lengthmin){//戻り値 終了時刻(Ex:200510170130)
327 $startyear =   substr($start,0,4);
328 $startmonth =   substr($start,4,2);
329 $startday =   substr($start,6,2);
330 $starthour =   substr($start,8,2);
331 $startmin =   substr($start,10,2);
332 //int mktime ( [int hour [, int minute [, int second [, int month [, int day [, int year [, int is_dst]]]]]]] )
333 $endtime = date ("YmdHi",mktime($starthour  , $startmin + $lengthmin , 0, $startmonth  , $startday, $startyear));
334
335 return ($endtime );
336 }//end function
337
338
339 function z2h($string){ //戻り値 半角化した文字
340     $stringh = mb_convert_kana($string, "a", "EUC-JP");
341  return ($stringh );
342 }
343
344 function foldate2rfc822($start){//戻り値 RFC822スタイルの時刻表記
345     $startyear =   substr($start,0,4);
346     $startmonth =   substr($start,4,2);
347     $startday =   substr($start,6,2);
348     $starthour =   substr($start,8,2);
349     $startmin =   substr($start,10,2);
350
351     $rfc822 = date ("r",mktime($starthour  , $startmin , 0, $startmonth  , $startday, $startyear));
352     
353     return ($rfc822);
354 }//end sub
355
356 function foldate2print($start){//戻り値 日本語風時刻表記
357     $startyear =   substr($start,0,4);
358     $startmonth =   substr($start,4,2);
359     $startday =   substr($start,6,2);
360     $starthour =   substr($start,8,2);
361     $startmin =   substr($start,10,2);
362
363     $printabledate = date ("Y/m/d H:i",mktime($starthour  , $startmin , 0, $startmonth  , $startday, $startyear));   
364     return ($printabledate);
365 }//end sub
366
367 function getserveruri(){//戻り値 サーバアドレス Ex.www.dcc-jpl.com:8800/soft/foltia/
368
369 //リンクURI組み立て
370 $sv6 = $_SERVER['SCRIPT_NAME'];///dameNews/sarasorjyu/archives.php
371 $sv8 = $_SERVER['SERVER_NAME'];//sync.dcc-jpl.com
372 $sv9 = $_SERVER['SERVER_PORT'];
373 if ($sv9 == 80){
374     $port = "";
375 }else{
376     $port = ":$sv9";
377 }
378 $a = split("/", $sv6);
379 array_pop($a);
380
381 $scriptpath = implode("/", $a);
382
383 $serveruri = "$sv8$port$scriptpath";
384 return ($serveruri );
385 }//end sub
386
387
388 function getserverfqdn(){//戻り値 サーバアドレス Ex.www.dcc-jpl.com:8800
389
390 //リンクURI組み立て
391 $sv6 = $_SERVER['SCRIPT_NAME'];///dameNews/sarasorjyu/archives.php
392 $sv8 = $_SERVER['SERVER_NAME'];//sync.dcc-jpl.com
393 $sv9 = $_SERVER['SERVER_PORT'];
394 if ($sv9 == 80){
395     $port = "";
396 }else{
397     $port = ":$sv9";
398 }
399 $a = split("/", $sv6);
400 array_pop($a);
401
402 $scriptpath = implode("/", $a);
403
404 $serveruri = "$sv8$port";
405 return ($serveruri );
406 }//end sub
407
408
409 function printdiskusage(){//戻り値 なし
410 list (, $all, $use , $free, $usepercent) =  getdiskusage();
411
412 print "
413 <div style=\"width:100%;border:1px solid black;text-align:left;\"><span style=\"float:right;\">$free</span>
414 <div style=\"width:$usepercent;border:1px solid black;background:white;\">$use/$all($usepercent)</div>
415 </div>
416 ";
417 //exec('ps ax | grep ffmpeg |grep MP4 ' ,$ffmpegprocesses);
418 }//end sub
419
420
421 function getdiskusage(){//戻り値 配列 [,全体容量, 使用容量 , 空き容量, 利用割合]
422
423 global $recfolderpath,$recfolderpath;
424
425     exec ( "df -h  $recfolderpath | grep $recfolderpath", $hdfreearea);
426     $freearea = preg_split ("/[\s,]+/", $hdfreearea[0]);
427
428     return $freearea;
429     
430 }//endsub
431
432
433 function printtrcnprocesses(){
434
435 $ffmpegprocesses = `ps ax | grep ffmpeg | grep -v grep |  wc -l `;
436 $uptime = exec('uptime');
437
438 print "<div style=\"text-align:left;\">";
439 print "$uptime<br>\n";
440 print "トラコン稼働数:$ffmpegprocesses<br>\n";
441 print "</div>";
442
443 }//endsub
444
445
446 function warndiskfreearea(){
447
448 if ($demomode){
449 print "<!-- demo mode -->";
450 }else{
451
452 global $recfolderpath,$recfolderpath;
453
454     exec ( "df   $recfolderpath | grep $recfolderpath", $hdfreearea);
455     $freearea = preg_split ("/[\s,]+/", $hdfreearea[0]);
456 $freebytes = $freearea[3];
457 if ($freebytes == "" ){
458 //
459 //print "<!-- err:\$freebytes is null -->";
460 }elseif($freebytes > 1024*1024*100 ){// 100GB以上あいてれば
461 //なにもしない
462 print "<style type=\"text/css\"><!-- --></style>";
463 }elseif($freebytes > 1024*1024*50 ){// 100GB以下
464 print "<style type=\"text/css\"><!--
465     body {
466     background-color: #CCCC99;
467      }
468 -->
469 </style>
470 ";
471 }elseif($freebytes > 1024*1024*30 ){// 50GB以下
472 print "<style type=\"text/css\"><!--
473     body {
474     background-color:#CC6666;
475      }
476 -->
477 </style>
478 ";
479 }elseif($freebytes > 0 ){// 30GB以下
480 print "<style type=\"text/css\"><!--
481     body {
482     background-color:#FF0000;
483      }
484 -->
485 </style>
486 ";
487 }else{
488 //print "<!-- no much : $freebytes -->";
489
490
491 }//endif freebytess
492
493 }//endif demomode
494
495 }//endsub
496
497
498
499 function foldatevalidation($foldate){
500
501 if (strlen($foldate) == 12 ){
502
503     $startyear =   substr($foldate,0,4);
504     $startmonth =   substr($foldate,4,2);
505     $startday =   substr($foldate,6,2);
506     $starthour =   substr($foldate,8,2);
507     $startmin =   substr($foldate,10,2);
508
509     $startepoch = date ("U",mktime($starthour  , $startmin , 0, $startmonth  , $startday, $startyear));   
510     $nowe = time();
511     if ($startepoch > $nowe){
512     //print "$foldate:$startepoch:$nowe";
513         return TRUE;
514     }else{
515         return FALSE;
516     }    //end if $startepoch > $nowe
517 }else{
518     return FALSE;
519 }//end if ($foldate) == 12
520
521 }//end function
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537 ?>
538
Note: リポジトリブラウザについてのヘルプは TracBrowser を参照してください。
track feed