annotate Reservation.class.php @ 79:6eabffb0ccac

add SID: Reservation.class.php
author Sushi-k <epgrec@park.mda.or.jp>
date Wed, 24 Feb 2010 20:27:46 +0900
parents 69e0dabc765a
children 36ac7c416bd7 f6b909678e51
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 {
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
11
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 );
1
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
17
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 );
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
28
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 }
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
35
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;
1
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
53
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;
1
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
60
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 }
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
66
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 }
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
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 );
1
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
78
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;
8965ef108821 change: modify all scripts for web base setting.
Sushi-k <epgrec@park.mda.or.jp>
parents: 15
diff changeset
81 $battings = DBRecord::countRecords( RESERVE_TBL, "WHERE complete = '0' ".
8965ef108821 change: modify all scripts for web base setting.
Sushi-k <epgrec@park.mda.or.jp>
parents: 15
diff changeset
82 "AND type = '".$crec->type."' ".
8965ef108821 change: modify all scripts for web base setting.
Sushi-k <epgrec@park.mda.or.jp>
parents: 15
diff changeset
83 "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
84 "AND endtime > '".toDatetime($rec_start)."'"
1
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
85 );
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
86
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
87 if( $battings >= $tuners ) {
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
88 // 重複を発見した
40
a935b4789aff fix: bug
Sushi-k <epgrec@park.mda.or.jp>
parents: 39
diff changeset
89 if( $settings->force_cont_rec == 1 ) {
1
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
90 // 解消可能な重複かどうかを調べる
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
91 // 前後の予約数
39
8965ef108821 change: modify all scripts for web base setting.
Sushi-k <epgrec@park.mda.or.jp>
parents: 15
diff changeset
92 $nexts = DBRecord::countRecords( RESERVE_TBL, "WHERE complete = '0' ".
8965ef108821 change: modify all scripts for web base setting.
Sushi-k <epgrec@park.mda.or.jp>
parents: 15
diff changeset
93 "AND type = '".$crec->type."' ".
8965ef108821 change: modify all scripts for web base setting.
Sushi-k <epgrec@park.mda.or.jp>
parents: 15
diff changeset
94 "AND starttime = '".toDatetime($end_time - $settings->former_time)."'");
1
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
95
39
8965ef108821 change: modify all scripts for web base setting.
Sushi-k <epgrec@park.mda.or.jp>
parents: 15
diff changeset
96 $prevs = DBRecord::countRecords( RESERVE_TBL, "WHERE complete = '0' ".
8965ef108821 change: modify all scripts for web base setting.
Sushi-k <epgrec@park.mda.or.jp>
parents: 15
diff changeset
97 "AND type = '".$crec->type."' ".
8965ef108821 change: modify all scripts for web base setting.
Sushi-k <epgrec@park.mda.or.jp>
parents: 15
diff changeset
98 "AND endtime = '".$starttime."'" );
1
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
99
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
100 // 前後を引いてもチューナー数と同数以上なら重複の解消は無理
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
101 if( ($battings - $nexts - $prevs) >= $tuners )
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
102 throw new Exception( "重複予約を解消できません" );
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
103
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
104 // 直後の番組はあるか?
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
105 if( $nexts ) {
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
106 // この番組の終わりをちょっとだけ早める
39
8965ef108821 change: modify all scripts for web base setting.
Sushi-k <epgrec@park.mda.or.jp>
parents: 15
diff changeset
107 $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
108 $duration = $end_time - $rec_start; // durationを計算しなおす
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
109 }
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
110 $battings -= $nexts;
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 // 直前の録画予約を見付ける
39
8965ef108821 change: modify all scripts for web base setting.
Sushi-k <epgrec@park.mda.or.jp>
parents: 15
diff changeset
113 $trecs = DBRecord::createRecords(RESERVE_TBL, "WHERE complete = '0' ".
8965ef108821 change: modify all scripts for web base setting.
Sushi-k <epgrec@park.mda.or.jp>
parents: 15
diff changeset
114 "AND type = '".$crec->type."' ".
8965ef108821 change: modify all scripts for web base setting.
Sushi-k <epgrec@park.mda.or.jp>
parents: 15
diff changeset
115 "AND endtime = '".$starttime."'" );
1
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
116 // 直前の番組をずらす
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
117 for( $i = 0; $i < count($trecs) ; $i++ ) {
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
118 if( $battings < $tuners ) break; // 解消終了のハズ?
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
119 // 予約修正に必要な情報を取り出す
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
120 $prev_id = $trecs[$i]->id;
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
121 $prev_program_id = $trecs[$i]->program_id;
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
122 $prev_channel_id = $trecs[$i]->channel_id;
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
123 $prev_title = $trecs[$i]->title;
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
124 $prev_description = $trecs[$i]->description;
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
125 $prev_category_id = $trecs[$i]->category_id;
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
126 $prev_starttime = $trecs[$i]->starttime;
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
127 $prev_endtime = $trecs[$i]->endtime;
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
128 $prev_autorec = $trecs[$i]->autorec;
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
129 $prev_mode = $trecs[$i]->mode;
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
130
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
131 $prev_start_time = toTimestamp($prev_starttime);
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
132 // 始まっていない予約?
39
8965ef108821 change: modify all scripts for web base setting.
Sushi-k <epgrec@park.mda.or.jp>
parents: 15
diff changeset
133 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
134 // 開始時刻を元に戻す
39
8965ef108821 change: modify all scripts for web base setting.
Sushi-k <epgrec@park.mda.or.jp>
parents: 15
diff changeset
135 $prev_starttime = toDatetime( $prev_start_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_endtime = toDatetime( toTimestamp($prev_endtime) - $settings->former_time - $settings->rec_switch_time );
1
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
138
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
139 // tryのネスト
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
140 try {
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
141 // いったん予約取り消し
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
142 self::cancel( $prev_id );
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::custom(
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
145 $prev_starttime, // 開始時間Datetime型
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
146 $prev_endtime, // 終了時間Datetime型
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
147 $prev_channel_id, // チャンネルID
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
148 $prev_title, // タイトル
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
149 $prev_description, // 概要
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
150 $prev_category_id, // カテゴリID
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
151 $prev_program_id, // 番組ID
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
152 $prev_autorec, // 自動録画
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
153 $prev_mode );
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
154 }
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
155 catch( Exception $e ) {
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
156 throw new Exception( "重複予約を解消できません" );
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
157 }
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
158 }
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
159 else {
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
160 throw new Exception( "重複予約を解消できません" );
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
161 }
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
162 $battings--;
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 if( $battings < 0 ) $battings = 0;
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 }
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
167 else {
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
168 throw new Exception( "重複予約があります" );
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
169 }
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
170 }
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 $tuner = $battings;
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 // 改めてdurationをチェックしなおす
39
8965ef108821 change: modify all scripts for web base setting.
Sushi-k <epgrec@park.mda.or.jp>
parents: 15
diff changeset
175 if( $duration < ($settings->former_time + 60) ) { // 60秒以下の番組は弾く
1
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
176 throw new Exception( "終わりつつある/終わっている番組です" );
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
177 }
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
178
15
cbbddf99d1cd added: filename customize function
Sushi-k <epgrec@park.mda.or.jp>
parents: 8
diff changeset
179
cbbddf99d1cd added: filename customize function
Sushi-k <epgrec@park.mda.or.jp>
parents: 8
diff changeset
180 // ここからファイル名生成
cbbddf99d1cd added: filename customize function
Sushi-k <epgrec@park.mda.or.jp>
parents: 8
diff changeset
181 /*
cbbddf99d1cd added: filename customize function
Sushi-k <epgrec@park.mda.or.jp>
parents: 8
diff changeset
182 %TITLE% 番組タイトル
cbbddf99d1cd added: filename customize function
Sushi-k <epgrec@park.mda.or.jp>
parents: 8
diff changeset
183 %ST% 開始日時(ex.200907201830)
cbbddf99d1cd added: filename customize function
Sushi-k <epgrec@park.mda.or.jp>
parents: 8
diff changeset
184 %ET% 終了日時
cbbddf99d1cd added: filename customize function
Sushi-k <epgrec@park.mda.or.jp>
parents: 8
diff changeset
185 %TYPE% GR/BS
cbbddf99d1cd added: filename customize function
Sushi-k <epgrec@park.mda.or.jp>
parents: 8
diff changeset
186 %CH% チャンネル番号
cbbddf99d1cd added: filename customize function
Sushi-k <epgrec@park.mda.or.jp>
parents: 8
diff changeset
187 %DOW% 曜日(Sun-Mon)
cbbddf99d1cd added: filename customize function
Sushi-k <epgrec@park.mda.or.jp>
parents: 8
diff changeset
188 %DOWJ% 曜日(日-土)
cbbddf99d1cd added: filename customize function
Sushi-k <epgrec@park.mda.or.jp>
parents: 8
diff changeset
189 %YEAR% 開始年
cbbddf99d1cd added: filename customize function
Sushi-k <epgrec@park.mda.or.jp>
parents: 8
diff changeset
190 %MONTH% 開始月
cbbddf99d1cd added: filename customize function
Sushi-k <epgrec@park.mda.or.jp>
parents: 8
diff changeset
191 %DAY% 開始日
cbbddf99d1cd added: filename customize function
Sushi-k <epgrec@park.mda.or.jp>
parents: 8
diff changeset
192 %HOUR% 開始時
cbbddf99d1cd added: filename customize function
Sushi-k <epgrec@park.mda.or.jp>
parents: 8
diff changeset
193 %MIN% 開始分
cbbddf99d1cd added: filename customize function
Sushi-k <epgrec@park.mda.or.jp>
parents: 8
diff changeset
194 %SEC% 開始秒
cbbddf99d1cd added: filename customize function
Sushi-k <epgrec@park.mda.or.jp>
parents: 8
diff changeset
195 %DURATION% 録画時間(秒)
cbbddf99d1cd added: filename customize function
Sushi-k <epgrec@park.mda.or.jp>
parents: 8
diff changeset
196 */
cbbddf99d1cd added: filename customize function
Sushi-k <epgrec@park.mda.or.jp>
parents: 8
diff changeset
197
cbbddf99d1cd added: filename customize function
Sushi-k <epgrec@park.mda.or.jp>
parents: 8
diff changeset
198 $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
199 $filename = $settings->filename_format;
8965ef108821 change: modify all scripts for web base setting.
Sushi-k <epgrec@park.mda.or.jp>
parents: 15
diff changeset
200
15
cbbddf99d1cd added: filename customize function
Sushi-k <epgrec@park.mda.or.jp>
parents: 8
diff changeset
201 // あると面倒くさそうな文字を全部_に
cbbddf99d1cd added: filename customize function
Sushi-k <epgrec@park.mda.or.jp>
parents: 8
diff changeset
202 $fn_title = mb_ereg_replace("[ \./\*:<>\?\\|()\'\"&]","_", trim($title) );
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 // %TITLE%
cbbddf99d1cd added: filename customize function
Sushi-k <epgrec@park.mda.or.jp>
parents: 8
diff changeset
205 $filename = str_replace("%TITLE%", $fn_title, $filename);
cbbddf99d1cd added: filename customize function
Sushi-k <epgrec@park.mda.or.jp>
parents: 8
diff changeset
206 // %ST% 開始日時
cbbddf99d1cd added: filename customize function
Sushi-k <epgrec@park.mda.or.jp>
parents: 8
diff changeset
207 $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
208 // %ET% 終了日時
cbbddf99d1cd added: filename customize function
Sushi-k <epgrec@park.mda.or.jp>
parents: 8
diff changeset
209 $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
210 // %TYPE% GR/BS
cbbddf99d1cd added: filename customize function
Sushi-k <epgrec@park.mda.or.jp>
parents: 8
diff changeset
211 $filename = str_replace("%TYPE%",$crec->type, $filename );
cbbddf99d1cd added: filename customize function
Sushi-k <epgrec@park.mda.or.jp>
parents: 8
diff changeset
212 // %CH% チャンネル番号
cbbddf99d1cd added: filename customize function
Sushi-k <epgrec@park.mda.or.jp>
parents: 8
diff changeset
213 $filename = str_replace("%CH%","".$crec->channel, $filename );
cbbddf99d1cd added: filename customize function
Sushi-k <epgrec@park.mda.or.jp>
parents: 8
diff changeset
214 // %DOW% 曜日(Sun-Mon)
cbbddf99d1cd added: filename customize function
Sushi-k <epgrec@park.mda.or.jp>
parents: 8
diff changeset
215 $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
216 // %DOWJ% 曜日(日-土)
cbbddf99d1cd added: filename customize function
Sushi-k <epgrec@park.mda.or.jp>
parents: 8
diff changeset
217 $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
218 // %YEAR% 開始年
cbbddf99d1cd added: filename customize function
Sushi-k <epgrec@park.mda.or.jp>
parents: 8
diff changeset
219 $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
220 // %MONTH% 開始月
cbbddf99d1cd added: filename customize function
Sushi-k <epgrec@park.mda.or.jp>
parents: 8
diff changeset
221 $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
222 // %DAY% 開始日
cbbddf99d1cd added: filename customize function
Sushi-k <epgrec@park.mda.or.jp>
parents: 8
diff changeset
223 $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
224 // %HOUR% 開始時
cbbddf99d1cd added: filename customize function
Sushi-k <epgrec@park.mda.or.jp>
parents: 8
diff changeset
225 $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
226 // %MIN% 開始分
cbbddf99d1cd added: filename customize function
Sushi-k <epgrec@park.mda.or.jp>
parents: 8
diff changeset
227 $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
228 // %SEC% 開始秒
cbbddf99d1cd added: filename customize function
Sushi-k <epgrec@park.mda.or.jp>
parents: 8
diff changeset
229 $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
230 // %DURATION% 録画時間(秒)
cbbddf99d1cd added: filename customize function
Sushi-k <epgrec@park.mda.or.jp>
parents: 8
diff changeset
231 $filename = str_replace("%DURATION%","".$duration, $filename );
cbbddf99d1cd added: filename customize function
Sushi-k <epgrec@park.mda.or.jp>
parents: 8
diff changeset
232
cbbddf99d1cd added: filename customize function
Sushi-k <epgrec@park.mda.or.jp>
parents: 8
diff changeset
233 // 文字コード変換
76
69e0dabc765a fixed: Reservation.class.php
Sushi-k <epgrec@park.mda.or.jp>
parents: 56
diff changeset
234 if( defined("FILESYSTEM_ENCODING") ) {
15
cbbddf99d1cd added: filename customize function
Sushi-k <epgrec@park.mda.or.jp>
parents: 8
diff changeset
235 $filename = mb_convert_encoding( $filename, FILESYSTEM_ENCODING, "UTF-8" );
cbbddf99d1cd added: filename customize function
Sushi-k <epgrec@park.mda.or.jp>
parents: 8
diff changeset
236 }
76
69e0dabc765a fixed: Reservation.class.php
Sushi-k <epgrec@park.mda.or.jp>
parents: 56
diff changeset
237 $filename .= $RECORD_MODE["$mode"]['suffix'];
47
a701aaf6d216 add: gen-thumbnail.sh
Sushi-k <epgrec@park.mda.or.jp>
parents: 40
diff changeset
238 $thumbname = $filename.".jpg";
15
cbbddf99d1cd added: filename customize function
Sushi-k <epgrec@park.mda.or.jp>
parents: 8
diff changeset
239
56
be9e4520cfec change: GEN_THUMBNAIL
yoneda <yoneda@recorder.localnet.mda.or.jp>
parents: 48
diff changeset
240 // サムネール
be9e4520cfec change: GEN_THUMBNAIL
yoneda <yoneda@recorder.localnet.mda.or.jp>
parents: 48
diff changeset
241 $gen_thumbnail = INSTALL_PATH."/gen-thumbnail.sh";
be9e4520cfec change: GEN_THUMBNAIL
yoneda <yoneda@recorder.localnet.mda.or.jp>
parents: 48
diff changeset
242 if( defined("GEN_THUMBNAIL") )
be9e4520cfec change: GEN_THUMBNAIL
yoneda <yoneda@recorder.localnet.mda.or.jp>
parents: 48
diff changeset
243 $gen_thumbnail = GEN_THUMBNAIL;
be9e4520cfec change: GEN_THUMBNAIL
yoneda <yoneda@recorder.localnet.mda.or.jp>
parents: 48
diff changeset
244
15
cbbddf99d1cd added: filename customize function
Sushi-k <epgrec@park.mda.or.jp>
parents: 8
diff changeset
245 // ファイル名生成終了
1
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
246
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
247 // 予約レコードを埋める
39
8965ef108821 change: modify all scripts for web base setting.
Sushi-k <epgrec@park.mda.or.jp>
parents: 15
diff changeset
248 $rrec = new DBRecord( RESERVE_TBL );
1
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
249 $rrec->channel_disc = $crec->channel_disc;
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
250 $rrec->channel_id = $crec->id;
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
251 $rrec->program_id = $program_id;
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
252 $rrec->type = $crec->type;
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
253 $rrec->channel = $crec->channel;
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
254 $rrec->title = $title;
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
255 $rrec->description = $description;
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
256 $rrec->category_id = $category_id;
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
257 $rrec->starttime = toDatetime( $rec_start );
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
258 $rrec->endtime = toDatetime( $end_time );
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
259 $rrec->path = $filename;
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
260 $rrec->autorec = $autorec;
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
261 $rrec->mode = $mode;
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
262 $rrec->reserve_disc = md5( $crec->channel_disc . toDatetime( $start_time ). toDatetime( $end_time ) );
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
263
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
264 // 予約実行
39
8965ef108821 change: modify all scripts for web base setting.
Sushi-k <epgrec@park.mda.or.jp>
parents: 15
diff changeset
265 $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
266 $descriptor = array( 0 => array( "pipe", "r" ),
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
267 1 => array( "pipe", "w" ),
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
268 2 => array( "pipe", "w" ),
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
269 );
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
270 $env = array( "CHANNEL" => $crec->channel,
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
271 "DURATION" => $duration,
39
8965ef108821 change: modify all scripts for web base setting.
Sushi-k <epgrec@park.mda.or.jp>
parents: 15
diff changeset
272 "OUTPUT" => INSTALL_PATH.$settings->spool."/".$filename,
1
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
273 "TYPE" => $crec->type,
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
274 "TUNER" => $tuner,
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
275 "MODE" => $mode,
47
a701aaf6d216 add: gen-thumbnail.sh
Sushi-k <epgrec@park.mda.or.jp>
parents: 40
diff changeset
276 "THUMB" => INSTALL_PATH.$settings->thumbs."/".$thumbname,
a701aaf6d216 add: gen-thumbnail.sh
Sushi-k <epgrec@park.mda.or.jp>
parents: 40
diff changeset
277 "FORMER" => "".$settings->former_time,
a701aaf6d216 add: gen-thumbnail.sh
Sushi-k <epgrec@park.mda.or.jp>
parents: 40
diff changeset
278 "FFMPEG" => "".$settings->ffmpeg,
79
6eabffb0ccac add SID: Reservation.class.php
Sushi-k <epgrec@park.mda.or.jp>
parents: 76
diff changeset
279 "SID" => $crec->sid,
1
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
280 );
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
281
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
282 // ATで予約する
39
8965ef108821 change: modify all scripts for web base setting.
Sushi-k <epgrec@park.mda.or.jp>
parents: 15
diff changeset
283 $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
284 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
285 fwrite($pipes[0], $settings->sleep." ".$sleep_time."\n" );
1
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
286 fwrite($pipes[0], DO_RECORD . "\n" );
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
287 fwrite($pipes[0], COMPLETE_CMD." ".$rrec->id."\n" );
48
8fbe3913f214 fix: bug
Sushi-k <epgrec@park.mda.or.jp>
parents: 47
diff changeset
288 if( $settings->use_thumbs == 1 ) {
56
be9e4520cfec change: GEN_THUMBNAIL
yoneda <yoneda@recorder.localnet.mda.or.jp>
parents: 48
diff changeset
289 fwrite($pipes[0], $gen_thumbnail."\n" );
1
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
290 }
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
291 fclose($pipes[0]);
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
292 // 標準エラーを取る
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
293 $rstring = stream_get_contents( $pipes[2]);
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
294
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
295 fclose( $pipes[2] );
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
296 proc_close( $process );
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
297 }
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
298 else {
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
299 $rrec->delete();
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
300 throw new Exception("AT実行エラー");
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
301 }
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
302 // job番号を取り出す
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
303 $rarr = array();
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
304 $tok = strtok( $rstring, " \n" );
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
305 while( $tok !== false ) {
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
306 array_push( $rarr, $tok );
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
307 $tok = strtok( " \n" );
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
308 }
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
309 $key = array_search("job", $rarr);
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
310 if( $key !== false ) {
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
311 if( is_numeric( $rarr[$key+1]) ) {
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
312 $rrec->job = $rarr[$key+1];
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
313 return $rrec->job; // 成功
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
314 }
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
315 }
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
316 // エラー
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
317 $rrec->delete();
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
318 throw new Exception( "job番号の取得に失敗" );
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 catch( Exception $e ) {
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
321 if( $rrec != null ) {
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
322 if( $rrec->id ) {
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
323 // 予約を取り消す
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
324 $rrec->delete();
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
325 }
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 throw $e;
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 // custom 終了
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 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
334 $settings = Settings::factory();
1
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
335 $rec = null;
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
336
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
337 try {
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
338 if( $reserve_id ) {
39
8965ef108821 change: modify all scripts for web base setting.
Sushi-k <epgrec@park.mda.or.jp>
parents: 15
diff changeset
339 $rec = new DBRecord( RESERVE_TBL, "id" , $reserve_id );
1
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
340 }
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
341 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
342 $rec = new DBRecord( RESERVE_TBL, "program_id" , $program_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 if( $rec == null ) {
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
345 throw new Exception("IDの指定が無効です");
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->complete ) {
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
348 // 未実行の予約である
39
8965ef108821 change: modify all scripts for web base setting.
Sushi-k <epgrec@park.mda.or.jp>
parents: 15
diff changeset
349 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
350 throw new Exception("過去の録画予約です");
39
8965ef108821 change: modify all scripts for web base setting.
Sushi-k <epgrec@park.mda.or.jp>
parents: 15
diff changeset
351 exec( $settings->atrm . " " . $rec->job );
1
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
352 }
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
353 $rec->delete();
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
354 }
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
355 catch( Exception $e ) {
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
356 throw $e;
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 }
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
359 }
48
8fbe3913f214 fix: bug
Sushi-k <epgrec@park.mda.or.jp>
parents: 47
diff changeset
360 ?>