annotate Reservation.class.php @ 92:e2c37cc736db

merged with upstream
author Yoshiki Yazawa <yaz@honeyplanet.jp>
date Tue, 02 Mar 2010 23:20:06 +0900
parents f6b909678e51 36ac7c416bd7
children 49145003e6a3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
1 <?php
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
2 include_once('config.php');
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
3 include_once( INSTALL_PATH . "/DBRecord.class.php" );
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
4 include_once( INSTALL_PATH . "/reclib.php" );
39
8965ef108821 change: modify all scripts for web base setting.
Sushi-k <epgrec@park.mda.or.jp>
parents: 15
diff changeset
5 include_once( INSTALL_PATH . "/Settings.class.php" );
8965ef108821 change: modify all scripts for web base setting.
Sushi-k <epgrec@park.mda.or.jp>
parents: 15
diff changeset
6
1
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
7
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
8 // 予約クラス
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
9
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
10 class Reservation {
75
11f63ae04a96 delete trailing white space
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 71
diff changeset
11
1
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
12 public static function simple( $program_id , $autorec = 0, $mode = 0) {
39
8965ef108821 change: modify all scripts for web base setting.
Sushi-k <epgrec@park.mda.or.jp>
parents: 15
diff changeset
13 $settings = Settings::factory();
1
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
14 $rval = 0;
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
15 try {
39
8965ef108821 change: modify all scripts for web base setting.
Sushi-k <epgrec@park.mda.or.jp>
parents: 15
diff changeset
16 $prec = new DBRecord( PROGRAM_TBL, "id", $program_id );
75
11f63ae04a96 delete trailing white space
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 71
diff changeset
17
1
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
18 $rval = self::custom(
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
19 $prec->starttime,
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
20 $prec->endtime,
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
21 $prec->channel_id,
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
22 $prec->title,
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
23 $prec->description,
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
24 $prec->category_id,
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
25 $program_id,
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
26 $autorec,
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
27 $mode );
75
11f63ae04a96 delete trailing white space
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 71
diff changeset
28
1
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
29 }
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
30 catch( Exception $e ) {
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
31 throw $e;
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
32 }
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
33 return $rval;
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
34 }
75
11f63ae04a96 delete trailing white space
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 71
diff changeset
35
1
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
36 public static function custom(
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
37 $starttime, // 開始時間Datetime型
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
38 $endtime, // 終了時間Datetime型
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
39 $channel_id, // チャンネルID
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
40 $title = "none", // タイトル
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
41 $description = "none", // 概要
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
42 $category_id = 0, // カテゴリID
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
43 $program_id = 0, // 番組ID
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
44 $autorec = 0, // 自動録画
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
45 $mode = 0 // 録画モード
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
46 ) {
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
47 global $RECORD_MODE;
39
8965ef108821 change: modify all scripts for web base setting.
Sushi-k <epgrec@park.mda.or.jp>
parents: 15
diff changeset
48 $settings = Settings::factory();
8965ef108821 change: modify all scripts for web base setting.
Sushi-k <epgrec@park.mda.or.jp>
parents: 15
diff changeset
49
1
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
50 // 時間を計算
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
51 $start_time = toTimestamp( $starttime );
39
8965ef108821 change: modify all scripts for web base setting.
Sushi-k <epgrec@park.mda.or.jp>
parents: 15
diff changeset
52 $end_time = toTimestamp( $endtime ) + $settings->extra_time;
75
11f63ae04a96 delete trailing white space
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 71
diff changeset
53
1
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
54 if( $start_time < (time() + PADDING_TIME + 10) ) { // 現在時刻より3分先より小さい=すでに開始されている番組
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
55 $start_time = time() + PADDING_TIME + 10; // 録画開始時間を3分10秒先に設定する
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
56 }
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
57 $at_start = $start_time - PADDING_TIME;
39
8965ef108821 change: modify all scripts for web base setting.
Sushi-k <epgrec@park.mda.or.jp>
parents: 15
diff changeset
58 $sleep_time = PADDING_TIME - $settings->former_time;
8965ef108821 change: modify all scripts for web base setting.
Sushi-k <epgrec@park.mda.or.jp>
parents: 15
diff changeset
59 $rec_start = $start_time - $settings->former_time;
75
11f63ae04a96 delete trailing white space
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 71
diff changeset
60
1
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
61 // durationを計算しておく
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
62 $duration = $end_time - $rec_start;
39
8965ef108821 change: modify all scripts for web base setting.
Sushi-k <epgrec@park.mda.or.jp>
parents: 15
diff changeset
63 if( $duration < ($settings->former_time + 60) ) { // 60秒以下の番組は弾く
1
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
64 throw new Exception( "終わりつつある/終わっている番組です" );
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
65 }
75
11f63ae04a96 delete trailing white space
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 71
diff changeset
66
1
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
67 $rrec = null;
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
68 try {
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
69 // 同一番組予約チェック
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
70 if( $program_id ) {
39
8965ef108821 change: modify all scripts for web base setting.
Sushi-k <epgrec@park.mda.or.jp>
parents: 15
diff changeset
71 $num = DBRecord::countRecords( RESERVE_TBL, "WHERE program_id = '".$program_id."'" );
1
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
72 if( $num ) {
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
73 throw new Exception("同一の番組が録画予約されています");
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
74 }
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
75 }
75
11f63ae04a96 delete trailing white space
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 71
diff changeset
76
39
8965ef108821 change: modify all scripts for web base setting.
Sushi-k <epgrec@park.mda.or.jp>
parents: 15
diff changeset
77 $crec = new DBRecord( CHANNEL_TBL, "id", $channel_id );
75
11f63ae04a96 delete trailing white space
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 71
diff changeset
78
1
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
79 // 既存予約数 = TUNER番号
39
8965ef108821 change: modify all scripts for web base setting.
Sushi-k <epgrec@park.mda.or.jp>
parents: 15
diff changeset
80 $tuners = ($crec->type == "GR") ? $settings->gr_tuners : $settings->bs_tuners;
91
f6b909678e51 fix: CSBSפȥ塼ʡʾνʣͽ󤬽ƤޤХ
Sushi-k <epgrec@park.mda.or.jp>
parents: 79
diff changeset
81 $type_str = ($crec->type == "GR") ? "type = 'GR' " : "(type = 'BS' OR type = 'CS') ";
f6b909678e51 fix: CSBSפȥ塼ʡʾνʣͽ󤬽ƤޤХ
Sushi-k <epgrec@park.mda.or.jp>
parents: 79
diff changeset
82
39
8965ef108821 change: modify all scripts for web base setting.
Sushi-k <epgrec@park.mda.or.jp>
parents: 15
diff changeset
83 $battings = DBRecord::countRecords( RESERVE_TBL, "WHERE complete = '0' ".
91
f6b909678e51 fix: CSBSפȥ塼ʡʾνʣͽ󤬽ƤޤХ
Sushi-k <epgrec@park.mda.or.jp>
parents: 79
diff changeset
84 "AND ".$type_str.
39
8965ef108821 change: modify all scripts for web base setting.
Sushi-k <epgrec@park.mda.or.jp>
parents: 15
diff changeset
85 "AND starttime < '".toDatetime($end_time) ."' ".
8965ef108821 change: modify all scripts for web base setting.
Sushi-k <epgrec@park.mda.or.jp>
parents: 15
diff changeset
86 "AND endtime > '".toDatetime($rec_start)."'"
1
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
87 );
75
11f63ae04a96 delete trailing white space
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 71
diff changeset
88
1
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
89 if( $battings >= $tuners ) {
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
90 // 重複を発見した
40
a935b4789aff fix: bug
Sushi-k <epgrec@park.mda.or.jp>
parents: 39
diff changeset
91 if( $settings->force_cont_rec == 1 ) {
1
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
92 // 解消可能な重複かどうかを調べる
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
93 // 前後の予約数
39
8965ef108821 change: modify all scripts for web base setting.
Sushi-k <epgrec@park.mda.or.jp>
parents: 15
diff changeset
94 $nexts = DBRecord::countRecords( RESERVE_TBL, "WHERE complete = '0' ".
91
f6b909678e51 fix: CSBSפȥ塼ʡʾνʣͽ󤬽ƤޤХ
Sushi-k <epgrec@park.mda.or.jp>
parents: 79
diff changeset
95 "AND ".$type_str.
39
8965ef108821 change: modify all scripts for web base setting.
Sushi-k <epgrec@park.mda.or.jp>
parents: 15
diff changeset
96 "AND starttime = '".toDatetime($end_time - $settings->former_time)."'");
75
11f63ae04a96 delete trailing white space
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 71
diff changeset
97
39
8965ef108821 change: modify all scripts for web base setting.
Sushi-k <epgrec@park.mda.or.jp>
parents: 15
diff changeset
98 $prevs = DBRecord::countRecords( RESERVE_TBL, "WHERE complete = '0' ".
91
f6b909678e51 fix: CSBSפȥ塼ʡʾνʣͽ󤬽ƤޤХ
Sushi-k <epgrec@park.mda.or.jp>
parents: 79
diff changeset
99 "AND ".$type_str.
39
8965ef108821 change: modify all scripts for web base setting.
Sushi-k <epgrec@park.mda.or.jp>
parents: 15
diff changeset
100 "AND endtime = '".$starttime."'" );
75
11f63ae04a96 delete trailing white space
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 71
diff changeset
101
1
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
102 // 前後を引いてもチューナー数と同数以上なら重複の解消は無理
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
103 if( ($battings - $nexts - $prevs) >= $tuners )
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
104 throw new Exception( "重複予約を解消できません" );
75
11f63ae04a96 delete trailing white space
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 71
diff changeset
105
1
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
106 // 直後の番組はあるか?
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
107 if( $nexts ) {
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
108 // この番組の終わりをちょっとだけ早める
39
8965ef108821 change: modify all scripts for web base setting.
Sushi-k <epgrec@park.mda.or.jp>
parents: 15
diff changeset
109 $end_time = $end_time - $settings->former_time - $settings->rec_switch_time;
1
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
110 $duration = $end_time - $rec_start; // durationを計算しなおす
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
111 }
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
112 $battings -= $nexts;
75
11f63ae04a96 delete trailing white space
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 71
diff changeset
113
1
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
114 // 直前の録画予約を見付ける
39
8965ef108821 change: modify all scripts for web base setting.
Sushi-k <epgrec@park.mda.or.jp>
parents: 15
diff changeset
115 $trecs = DBRecord::createRecords(RESERVE_TBL, "WHERE complete = '0' ".
91
f6b909678e51 fix: CSBSפȥ塼ʡʾνʣͽ󤬽ƤޤХ
Sushi-k <epgrec@park.mda.or.jp>
parents: 79
diff changeset
116 "AND ".$type_str.
39
8965ef108821 change: modify all scripts for web base setting.
Sushi-k <epgrec@park.mda.or.jp>
parents: 15
diff changeset
117 "AND endtime = '".$starttime."'" );
1
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
118 // 直前の番組をずらす
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
119 for( $i = 0; $i < count($trecs) ; $i++ ) {
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
120 if( $battings < $tuners ) break; // 解消終了のハズ?
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
121 // 予約修正に必要な情報を取り出す
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
122 $prev_id = $trecs[$i]->id;
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
123 $prev_program_id = $trecs[$i]->program_id;
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
124 $prev_channel_id = $trecs[$i]->channel_id;
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
125 $prev_title = $trecs[$i]->title;
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
126 $prev_description = $trecs[$i]->description;
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
127 $prev_category_id = $trecs[$i]->category_id;
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
128 $prev_starttime = $trecs[$i]->starttime;
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
129 $prev_endtime = $trecs[$i]->endtime;
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
130 $prev_autorec = $trecs[$i]->autorec;
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
131 $prev_mode = $trecs[$i]->mode;
75
11f63ae04a96 delete trailing white space
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 71
diff changeset
132
1
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
133 $prev_start_time = toTimestamp($prev_starttime);
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
134 // 始まっていない予約?
39
8965ef108821 change: modify all scripts for web base setting.
Sushi-k <epgrec@park.mda.or.jp>
parents: 15
diff changeset
135 if( $prev_start_time > (time() + PADDING_TIME + $settings->former_time) ) {
1
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
136 // 開始時刻を元に戻す
39
8965ef108821 change: modify all scripts for web base setting.
Sushi-k <epgrec@park.mda.or.jp>
parents: 15
diff changeset
137 $prev_starttime = toDatetime( $prev_start_time + $settings->former_time );
1
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
138 // 終わりをちょっとだけずらす
39
8965ef108821 change: modify all scripts for web base setting.
Sushi-k <epgrec@park.mda.or.jp>
parents: 15
diff changeset
139 $prev_endtime = toDatetime( toTimestamp($prev_endtime) - $settings->former_time - $settings->rec_switch_time );
75
11f63ae04a96 delete trailing white space
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 71
diff changeset
140
1
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
141 // tryのネスト
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
142 try {
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
143 // いったん予約取り消し
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
144 self::cancel( $prev_id );
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
145 // 再予約
75
11f63ae04a96 delete trailing white space
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 71
diff changeset
146 self::custom(
1
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
147 $prev_starttime, // 開始時間Datetime型
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
148 $prev_endtime, // 終了時間Datetime型
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
149 $prev_channel_id, // チャンネルID
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
150 $prev_title, // タイトル
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
151 $prev_description, // 概要
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
152 $prev_category_id, // カテゴリID
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
153 $prev_program_id, // 番組ID
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
154 $prev_autorec, // 自動録画
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
155 $prev_mode );
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
156 }
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
157 catch( Exception $e ) {
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
158 throw new Exception( "重複予約を解消できません" );
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
159 }
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
160 }
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
161 else {
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
162 throw new Exception( "重複予約を解消できません" );
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
163 }
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
164 $battings--;
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
165 }
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
166 if( $battings < 0 ) $battings = 0;
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
167 // これで重複解消したはず
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
168 }
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
169 else {
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
170 throw new Exception( "重複予約があります" );
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
171 }
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
172 }
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
173 // チューナー番号
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
174 $tuner = $battings;
75
11f63ae04a96 delete trailing white space
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 71
diff changeset
175
1
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
176 // 改めてdurationをチェックしなおす
39
8965ef108821 change: modify all scripts for web base setting.
Sushi-k <epgrec@park.mda.or.jp>
parents: 15
diff changeset
177 if( $duration < ($settings->former_time + 60) ) { // 60秒以下の番組は弾く
1
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
178 throw new Exception( "終わりつつある/終わっている番組です" );
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
179 }
75
11f63ae04a96 delete trailing white space
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 71
diff changeset
180
11f63ae04a96 delete trailing white space
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 71
diff changeset
181
15
cbbddf99d1cd added: filename customize function
Sushi-k <epgrec@park.mda.or.jp>
parents: 8
diff changeset
182 // ここからファイル名生成
cbbddf99d1cd added: filename customize function
Sushi-k <epgrec@park.mda.or.jp>
parents: 8
diff changeset
183 /*
cbbddf99d1cd added: filename customize function
Sushi-k <epgrec@park.mda.or.jp>
parents: 8
diff changeset
184 %TITLE% 番組タイトル
cbbddf99d1cd added: filename customize function
Sushi-k <epgrec@park.mda.or.jp>
parents: 8
diff changeset
185 %ST% 開始日時(ex.200907201830)
cbbddf99d1cd added: filename customize function
Sushi-k <epgrec@park.mda.or.jp>
parents: 8
diff changeset
186 %ET% 終了日時
91
f6b909678e51 fix: CSBSפȥ塼ʡʾνʣͽ󤬽ƤޤХ
Sushi-k <epgrec@park.mda.or.jp>
parents: 79
diff changeset
187 %TYPE% GR/BS/CS
15
cbbddf99d1cd added: filename customize function
Sushi-k <epgrec@park.mda.or.jp>
parents: 8
diff changeset
188 %CH% チャンネル番号
cbbddf99d1cd added: filename customize function
Sushi-k <epgrec@park.mda.or.jp>
parents: 8
diff changeset
189 %DOW% 曜日(Sun-Mon)
cbbddf99d1cd added: filename customize function
Sushi-k <epgrec@park.mda.or.jp>
parents: 8
diff changeset
190 %DOWJ% 曜日(日-土)
cbbddf99d1cd added: filename customize function
Sushi-k <epgrec@park.mda.or.jp>
parents: 8
diff changeset
191 %YEAR% 開始年
cbbddf99d1cd added: filename customize function
Sushi-k <epgrec@park.mda.or.jp>
parents: 8
diff changeset
192 %MONTH% 開始月
cbbddf99d1cd added: filename customize function
Sushi-k <epgrec@park.mda.or.jp>
parents: 8
diff changeset
193 %DAY% 開始日
cbbddf99d1cd added: filename customize function
Sushi-k <epgrec@park.mda.or.jp>
parents: 8
diff changeset
194 %HOUR% 開始時
cbbddf99d1cd added: filename customize function
Sushi-k <epgrec@park.mda.or.jp>
parents: 8
diff changeset
195 %MIN% 開始分
cbbddf99d1cd added: filename customize function
Sushi-k <epgrec@park.mda.or.jp>
parents: 8
diff changeset
196 %SEC% 開始秒
cbbddf99d1cd added: filename customize function
Sushi-k <epgrec@park.mda.or.jp>
parents: 8
diff changeset
197 %DURATION% 録画時間(秒)
cbbddf99d1cd added: filename customize function
Sushi-k <epgrec@park.mda.or.jp>
parents: 8
diff changeset
198 */
cbbddf99d1cd added: filename customize function
Sushi-k <epgrec@park.mda.or.jp>
parents: 8
diff changeset
199
cbbddf99d1cd added: filename customize function
Sushi-k <epgrec@park.mda.or.jp>
parents: 8
diff changeset
200 $day_of_week = array( "日","月","火","水","木","金","土" );
39
8965ef108821 change: modify all scripts for web base setting.
Sushi-k <epgrec@park.mda.or.jp>
parents: 15
diff changeset
201 $filename = $settings->filename_format;
75
11f63ae04a96 delete trailing white space
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 71
diff changeset
202
15
cbbddf99d1cd added: filename customize function
Sushi-k <epgrec@park.mda.or.jp>
parents: 8
diff changeset
203 // あると面倒くさそうな文字を全部_に
cbbddf99d1cd added: filename customize function
Sushi-k <epgrec@park.mda.or.jp>
parents: 8
diff changeset
204 $fn_title = mb_ereg_replace("[ \./\*:<>\?\\|()\'\"&]","_", trim($title) );
75
11f63ae04a96 delete trailing white space
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 71
diff changeset
205
15
cbbddf99d1cd added: filename customize function
Sushi-k <epgrec@park.mda.or.jp>
parents: 8
diff changeset
206 // %TITLE%
cbbddf99d1cd added: filename customize function
Sushi-k <epgrec@park.mda.or.jp>
parents: 8
diff changeset
207 $filename = str_replace("%TITLE%", $fn_title, $filename);
cbbddf99d1cd added: filename customize function
Sushi-k <epgrec@park.mda.or.jp>
parents: 8
diff changeset
208 // %ST% 開始日時
cbbddf99d1cd added: filename customize function
Sushi-k <epgrec@park.mda.or.jp>
parents: 8
diff changeset
209 $filename = str_replace("%ST%",date("YmdHis", $start_time), $filename );
cbbddf99d1cd added: filename customize function
Sushi-k <epgrec@park.mda.or.jp>
parents: 8
diff changeset
210 // %ET% 終了日時
cbbddf99d1cd added: filename customize function
Sushi-k <epgrec@park.mda.or.jp>
parents: 8
diff changeset
211 $filename = str_replace("%ET%",date("YmdHis", $end_time), $filename );
cbbddf99d1cd added: filename customize function
Sushi-k <epgrec@park.mda.or.jp>
parents: 8
diff changeset
212 // %TYPE% GR/BS
cbbddf99d1cd added: filename customize function
Sushi-k <epgrec@park.mda.or.jp>
parents: 8
diff changeset
213 $filename = str_replace("%TYPE%",$crec->type, $filename );
cbbddf99d1cd added: filename customize function
Sushi-k <epgrec@park.mda.or.jp>
parents: 8
diff changeset
214 // %CH% チャンネル番号
cbbddf99d1cd added: filename customize function
Sushi-k <epgrec@park.mda.or.jp>
parents: 8
diff changeset
215 $filename = str_replace("%CH%","".$crec->channel, $filename );
cbbddf99d1cd added: filename customize function
Sushi-k <epgrec@park.mda.or.jp>
parents: 8
diff changeset
216 // %DOW% 曜日(Sun-Mon)
cbbddf99d1cd added: filename customize function
Sushi-k <epgrec@park.mda.or.jp>
parents: 8
diff changeset
217 $filename = str_replace("%DOW%",date("D", $start_time), $filename );
cbbddf99d1cd added: filename customize function
Sushi-k <epgrec@park.mda.or.jp>
parents: 8
diff changeset
218 // %DOWJ% 曜日(日-土)
cbbddf99d1cd added: filename customize function
Sushi-k <epgrec@park.mda.or.jp>
parents: 8
diff changeset
219 $filename = str_replace("%DOWJ%",$day_of_week[(int)date("w", $start_time)], $filename );
cbbddf99d1cd added: filename customize function
Sushi-k <epgrec@park.mda.or.jp>
parents: 8
diff changeset
220 // %YEAR% 開始年
cbbddf99d1cd added: filename customize function
Sushi-k <epgrec@park.mda.or.jp>
parents: 8
diff changeset
221 $filename = str_replace("%YEAR%",date("Y", $start_time), $filename );
cbbddf99d1cd added: filename customize function
Sushi-k <epgrec@park.mda.or.jp>
parents: 8
diff changeset
222 // %MONTH% 開始月
cbbddf99d1cd added: filename customize function
Sushi-k <epgrec@park.mda.or.jp>
parents: 8
diff changeset
223 $filename = str_replace("%MONTH%",date("m", $start_time), $filename );
cbbddf99d1cd added: filename customize function
Sushi-k <epgrec@park.mda.or.jp>
parents: 8
diff changeset
224 // %DAY% 開始日
cbbddf99d1cd added: filename customize function
Sushi-k <epgrec@park.mda.or.jp>
parents: 8
diff changeset
225 $filename = str_replace("%DAY%",date("d", $start_time), $filename );
cbbddf99d1cd added: filename customize function
Sushi-k <epgrec@park.mda.or.jp>
parents: 8
diff changeset
226 // %HOUR% 開始時
cbbddf99d1cd added: filename customize function
Sushi-k <epgrec@park.mda.or.jp>
parents: 8
diff changeset
227 $filename = str_replace("%HOUR%",date("H", $start_time), $filename );
cbbddf99d1cd added: filename customize function
Sushi-k <epgrec@park.mda.or.jp>
parents: 8
diff changeset
228 // %MIN% 開始分
cbbddf99d1cd added: filename customize function
Sushi-k <epgrec@park.mda.or.jp>
parents: 8
diff changeset
229 $filename = str_replace("%MIN%",date("i", $start_time), $filename );
cbbddf99d1cd added: filename customize function
Sushi-k <epgrec@park.mda.or.jp>
parents: 8
diff changeset
230 // %SEC% 開始秒
cbbddf99d1cd added: filename customize function
Sushi-k <epgrec@park.mda.or.jp>
parents: 8
diff changeset
231 $filename = str_replace("%SEC%",date("s", $start_time), $filename );
cbbddf99d1cd added: filename customize function
Sushi-k <epgrec@park.mda.or.jp>
parents: 8
diff changeset
232 // %DURATION% 録画時間(秒)
cbbddf99d1cd added: filename customize function
Sushi-k <epgrec@park.mda.or.jp>
parents: 8
diff changeset
233 $filename = str_replace("%DURATION%","".$duration, $filename );
75
11f63ae04a96 delete trailing white space
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 71
diff changeset
234
15
cbbddf99d1cd added: filename customize function
Sushi-k <epgrec@park.mda.or.jp>
parents: 8
diff changeset
235 // 文字コード変換
76
69e0dabc765a fixed: Reservation.class.php
Sushi-k <epgrec@park.mda.or.jp>
parents: 56
diff changeset
236 if( defined("FILESYSTEM_ENCODING") ) {
75
11f63ae04a96 delete trailing white space
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 71
diff changeset
237 // $filename = mb_convert_encoding( $filename, FILESYSTEM_ENCODING, "UTF-8" );
11f63ae04a96 delete trailing white space
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 71
diff changeset
238 $filename = mb_convert_encoding( $filename, FILESYSTEM_ENCODING, "auto" );
15
cbbddf99d1cd added: filename customize function
Sushi-k <epgrec@park.mda.or.jp>
parents: 8
diff changeset
239 }
76
69e0dabc765a fixed: Reservation.class.php
Sushi-k <epgrec@park.mda.or.jp>
parents: 56
diff changeset
240 $filename .= $RECORD_MODE["$mode"]['suffix'];
47
a701aaf6d216 add: gen-thumbnail.sh
Sushi-k <epgrec@park.mda.or.jp>
parents: 40
diff changeset
241 $thumbname = $filename.".jpg";
75
11f63ae04a96 delete trailing white space
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 71
diff changeset
242
56
be9e4520cfec change: GEN_THUMBNAIL
yoneda <yoneda@recorder.localnet.mda.or.jp>
parents: 48
diff changeset
243 // サムネール
be9e4520cfec change: GEN_THUMBNAIL
yoneda <yoneda@recorder.localnet.mda.or.jp>
parents: 48
diff changeset
244 $gen_thumbnail = INSTALL_PATH."/gen-thumbnail.sh";
75
11f63ae04a96 delete trailing white space
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 71
diff changeset
245 if( defined("GEN_THUMBNAIL") )
56
be9e4520cfec change: GEN_THUMBNAIL
yoneda <yoneda@recorder.localnet.mda.or.jp>
parents: 48
diff changeset
246 $gen_thumbnail = GEN_THUMBNAIL;
75
11f63ae04a96 delete trailing white space
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 71
diff changeset
247
15
cbbddf99d1cd added: filename customize function
Sushi-k <epgrec@park.mda.or.jp>
parents: 8
diff changeset
248 // ファイル名生成終了
75
11f63ae04a96 delete trailing white space
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 71
diff changeset
249
1
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
250 // 予約レコードを埋める
39
8965ef108821 change: modify all scripts for web base setting.
Sushi-k <epgrec@park.mda.or.jp>
parents: 15
diff changeset
251 $rrec = new DBRecord( RESERVE_TBL );
1
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
252 $rrec->channel_disc = $crec->channel_disc;
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
253 $rrec->channel_id = $crec->id;
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
254 $rrec->program_id = $program_id;
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
255 $rrec->type = $crec->type;
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
256 $rrec->channel = $crec->channel;
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
257 $rrec->title = $title;
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
258 $rrec->description = $description;
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
259 $rrec->category_id = $category_id;
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
260 $rrec->starttime = toDatetime( $rec_start );
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
261 $rrec->endtime = toDatetime( $end_time );
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
262 $rrec->path = $filename;
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
263 $rrec->autorec = $autorec;
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
264 $rrec->mode = $mode;
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
265 $rrec->reserve_disc = md5( $crec->channel_disc . toDatetime( $start_time ). toDatetime( $end_time ) );
75
11f63ae04a96 delete trailing white space
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 71
diff changeset
266
1
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
267 // 予約実行
39
8965ef108821 change: modify all scripts for web base setting.
Sushi-k <epgrec@park.mda.or.jp>
parents: 15
diff changeset
268 $cmdline = $settings->at." ".date("H:i m/d/Y", $at_start);
1
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
269 $descriptor = array( 0 => array( "pipe", "r" ),
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
270 1 => array( "pipe", "w" ),
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
271 2 => array( "pipe", "w" ),
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
272 );
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
273 $env = array( "CHANNEL" => $crec->channel,
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
274 "DURATION" => $duration,
39
8965ef108821 change: modify all scripts for web base setting.
Sushi-k <epgrec@park.mda.or.jp>
parents: 15
diff changeset
275 "OUTPUT" => INSTALL_PATH.$settings->spool."/".$filename,
1
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
276 "TYPE" => $crec->type,
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
277 "TUNER" => $tuner,
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
278 "MODE" => $mode,
47
a701aaf6d216 add: gen-thumbnail.sh
Sushi-k <epgrec@park.mda.or.jp>
parents: 40
diff changeset
279 "THUMB" => INSTALL_PATH.$settings->thumbs."/".$thumbname,
a701aaf6d216 add: gen-thumbnail.sh
Sushi-k <epgrec@park.mda.or.jp>
parents: 40
diff changeset
280 "FORMER" => "".$settings->former_time,
a701aaf6d216 add: gen-thumbnail.sh
Sushi-k <epgrec@park.mda.or.jp>
parents: 40
diff changeset
281 "FFMPEG" => "".$settings->ffmpeg,
79
6eabffb0ccac add SID: Reservation.class.php
Sushi-k <epgrec@park.mda.or.jp>
parents: 76
diff changeset
282 "SID" => $crec->sid,
1
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
283 );
75
11f63ae04a96 delete trailing white space
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 71
diff changeset
284
1
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
285 // ATで予約する
39
8965ef108821 change: modify all scripts for web base setting.
Sushi-k <epgrec@park.mda.or.jp>
parents: 15
diff changeset
286 $process = proc_open( $cmdline , $descriptor, $pipes, INSTALL_PATH.$settings->spool, $env );
1
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
287 if( is_resource( $process ) ) {
39
8965ef108821 change: modify all scripts for web base setting.
Sushi-k <epgrec@park.mda.or.jp>
parents: 15
diff changeset
288 fwrite($pipes[0], $settings->sleep." ".$sleep_time."\n" );
1
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
289 fwrite($pipes[0], DO_RECORD . "\n" );
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
290 fwrite($pipes[0], COMPLETE_CMD." ".$rrec->id."\n" );
48
8fbe3913f214 fix: bug
Sushi-k <epgrec@park.mda.or.jp>
parents: 47
diff changeset
291 if( $settings->use_thumbs == 1 ) {
56
be9e4520cfec change: GEN_THUMBNAIL
yoneda <yoneda@recorder.localnet.mda.or.jp>
parents: 48
diff changeset
292 fwrite($pipes[0], $gen_thumbnail."\n" );
1
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
293 }
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
294 fclose($pipes[0]);
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
295 // 標準エラーを取る
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
296 $rstring = stream_get_contents( $pipes[2]);
75
11f63ae04a96 delete trailing white space
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 71
diff changeset
297
1
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
298 fclose( $pipes[2] );
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
299 proc_close( $process );
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
300 }
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
301 else {
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
302 $rrec->delete();
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
303 throw new Exception("AT実行エラー");
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
304 }
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
305 // job番号を取り出す
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
306 $rarr = array();
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
307 $tok = strtok( $rstring, " \n" );
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
308 while( $tok !== false ) {
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
309 array_push( $rarr, $tok );
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
310 $tok = strtok( " \n" );
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
311 }
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
312 $key = array_search("job", $rarr);
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
313 if( $key !== false ) {
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
314 if( is_numeric( $rarr[$key+1]) ) {
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
315 $rrec->job = $rarr[$key+1];
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
316 return $rrec->job; // 成功
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
317 }
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
318 }
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
319 // エラー
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
320 $rrec->delete();
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
321 throw new Exception( "job番号の取得に失敗" );
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
322 }
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
323 catch( Exception $e ) {
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
324 if( $rrec != null ) {
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
325 if( $rrec->id ) {
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
326 // 予約を取り消す
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
327 $rrec->delete();
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
328 }
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
329 }
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
330 throw $e;
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
331 }
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
332 }
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
333 // custom 終了
75
11f63ae04a96 delete trailing white space
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 71
diff changeset
334
1
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
335 // 取り消し
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
336 public static function cancel( $reserve_id = 0, $program_id = 0 ) {
39
8965ef108821 change: modify all scripts for web base setting.
Sushi-k <epgrec@park.mda.or.jp>
parents: 15
diff changeset
337 $settings = Settings::factory();
1
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
338 $rec = null;
75
11f63ae04a96 delete trailing white space
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 71
diff changeset
339
1
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
340 try {
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
341 if( $reserve_id ) {
39
8965ef108821 change: modify all scripts for web base setting.
Sushi-k <epgrec@park.mda.or.jp>
parents: 15
diff changeset
342 $rec = new DBRecord( RESERVE_TBL, "id" , $reserve_id );
1
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
343 }
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
344 else if( $program_id ) {
39
8965ef108821 change: modify all scripts for web base setting.
Sushi-k <epgrec@park.mda.or.jp>
parents: 15
diff changeset
345 $rec = new DBRecord( RESERVE_TBL, "program_id" , $program_id );
1
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
346 }
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
347 if( $rec == null ) {
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
348 throw new Exception("IDの指定が無効です");
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
349 }
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
350 if( ! $rec->complete ) {
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
351 // 未実行の予約である
39
8965ef108821 change: modify all scripts for web base setting.
Sushi-k <epgrec@park.mda.or.jp>
parents: 15
diff changeset
352 if( toTimestamp($rec->starttime) < (time() + PADDING_TIME + $settings->former_time) )
1
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
353 throw new Exception("過去の録画予約です");
39
8965ef108821 change: modify all scripts for web base setting.
Sushi-k <epgrec@park.mda.or.jp>
parents: 15
diff changeset
354 exec( $settings->atrm . " " . $rec->job );
1
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
355 }
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
356 $rec->delete();
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
357 }
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
358 catch( Exception $e ) {
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
359 throw $e;
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
360 }
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
361 }
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
362 }
48
8fbe3913f214 fix: bug
Sushi-k <epgrec@park.mda.or.jp>
parents: 47
diff changeset
363 ?>