$day['selected'] = ""; array_push($days, $day); for ($i = 0; $i < 8; $i++) { $day['d'] = "" . date("d", time() + 24 * 3600 * $i) . "日"; $day['link'] = $get_param . "&time=" . date("Ymd", time() + 24 * 3600 * $i) . date("H", $top_time); $day['ofweek'] = $DAY_OF_WEEK[(int) date("w", time() + 24 * 3600 * $i)]; $day['selected'] = date("d", $top_time) == date("d", time() + 24 * 3600 * $i) ? 'class="selected"' : ''; array_push($days, $day); } $smarty->assign("days", $days); // 時間選択 $toptimes = array(); for ($i = 0; $i < 24; $i += 4) { $tmp = array(); $tmp['hour'] = sprintf("%02d:00", $i); $tmp['link'] = $get_param . "&time=" . date("Ymd", $top_time) . sprintf("%02d", $i); array_push($toptimes, $tmp); } $smarty->assign("toptimes", $toptimes); $smarty->assign("tvtimes", $tvtimes); $smarty->assign("programs", $programs); $smarty->assign("ch_set_width", $settings->ch_set_width); $smarty->assign("chs_width", $chs_width); $smarty->assign("height_per_hour", $settings->height_per_hour); $smarty->assign("height_per_min", $settings->height_per_hour / 60); // date("Y-m-d H:i:s", $timestamp); $sitetitle = date("Y", $top_time) . "年" . date("m", $top_time) . "月" . date("d", $top_time) . "日" . date("H", $top_time) . "時~" . ($type == "GR" ? "地上デジタル" : "BSデジタル") . "番組表"; $smarty->assign("sitetitle", $sitetitle); $smarty->assign("top_time", str_replace("-", "/", toDatetime($top_time))); $smarty->assign("last_time", str_replace("-", "/", toDatetime($last_time))); $smarty->display("index.html");
function tpFieldVal($fvalue = '', $finfo = '') { if ($finfo['field'] == 'a_id') { $ActiveTeam = M('ActiveTeam'); $map['id'] = $fvalue; return $ActiveTeam->where($map)->getField('team_name'); } if ($finfo['auto']) { if (function_exists($finfo['auto'])) { $fun = $finfo['auto']; return $fun($fvalue); } } if (strlen($fvalue) == 10 && is_numeric($fvalue)) { return str_replace("00:00:00", "", toDatetime($fvalue)); } if ($finfo['field'] == 'starttime' || $finfo['field'] == 'endtime' || $finfo['field'] == 'addtime' || $finfo['field'] == 'startime' || $finfo['field'] == 'stime' || $finfo['field'] == 'etime' || $finfo['field'] == 'addtime' || $finfo['field'] == 'show_time') { return str_replace("00:00:00", "", toDatetime($fvalue)); } if ($finfo['field'] == 'status') { if ($fvalue == 0) { return '未提交'; } elseif ($fvalue == 1) { return '待审核'; } elseif ($fvalue == 2) { return '审核通过'; } elseif ($fvalue == -1) { return '退回'; } } if ($finfo['type'] == 'select') { $list_str = str_replace("\n", "-", $finfo['list']); $list_str = str_replace(":", ":", $list_str); $list_arr = explode('-', $list_str); $list_data = array(); foreach ($list_arr as $k) { $tmp_arr = explode(':', $k); $v = array(); $v['value'] = $tmp_arr[0]; $v['label'] = $tmp_arr[1]; $list_data[] = $v; } foreach ($list_data as $k) { if ($k['value'] == $fvalue) { return $k['label']; } } } elseif ($finfo['type'] == 'datetime' && !$fvalue) { return toDatetime(time()); } foreach ($list_data as $k) { if ($k['value'] == $val) { $selected = "selected"; } $opt .= "<option " . $selected . " value=" . $k['value'] . " >" . $k['label'] . " </option>"; } return $fvalue; }
public static function custom($starttime, $endtime, $channel_id, $title = "none", $description = "none", $category_id = 0, $program_id = 0, $autorec = 0, $mode = 0) { global $RECORD_MODE; $settings = Settings::factory(); // 時間を計算 $start_time = toTimestamp($starttime); $end_time = toTimestamp($endtime) + $settings->extra_time; if ($start_time < time() + PADDING_TIME + 10) { // 現在時刻より3分先より小さい=すでに開始されている番組 $start_time = time() + PADDING_TIME + 10; // 録画開始時間を3分10秒先に設定する } $at_start = $start_time - PADDING_TIME; $sleep_time = PADDING_TIME - $settings->former_time; $rec_start = $start_time - $settings->former_time; // durationを計算しておく $duration = $end_time - $rec_start; if ($duration < $settings->former_time + 60) { // 60秒以下の番組は弾く throw new Exception("終わりつつある/終わっている番組です"); } $rrec = null; try { // 同一番組予約チェック if ($program_id) { $num = DBRecord::countRecords(RESERVE_TBL, "WHERE program_id = '" . $program_id . "'"); if ($num) { throw new Exception("同一の番組が録画予約されています"); } } $crec = new DBRecord(CHANNEL_TBL, "id", $channel_id); // 既存予約数 = TUNER番号 $tuners = $crec->type == "GR" ? $settings->gr_tuners : $settings->bs_tuners; $battings = DBRecord::countRecords(RESERVE_TBL, "WHERE complete = '0' " . "AND type = '" . $crec->type . "' " . "AND starttime < '" . toDatetime($end_time) . "' " . "AND endtime > '" . toDatetime($rec_start) . "'"); if ($battings >= $tuners) { // 重複を発見した if ($settings->force_cont_rec == 1) { // 解消可能な重複かどうかを調べる // 前後の予約数 $nexts = DBRecord::countRecords(RESERVE_TBL, "WHERE complete = '0' " . "AND type = '" . $crec->type . "' " . "AND starttime = '" . toDatetime($end_time - $settings->former_time) . "'"); $prevs = DBRecord::countRecords(RESERVE_TBL, "WHERE complete = '0' " . "AND type = '" . $crec->type . "' " . "AND endtime = '" . $starttime . "'"); // 前後を引いてもチューナー数と同数以上なら重複の解消は無理 if ($battings - $nexts - $prevs >= $tuners) { throw new Exception("重複予約を解消できません"); } // 直後の番組はあるか? if ($nexts) { // この番組の終わりをちょっとだけ早める $end_time = $end_time - $settings->former_time - $settings->rec_switch_time; $duration = $end_time - $rec_start; // durationを計算しなおす } $battings -= $nexts; // 直前の録画予約を見付ける $trecs = DBRecord::createRecords(RESERVE_TBL, "WHERE complete = '0' " . "AND type = '" . $crec->type . "' " . "AND endtime = '" . $starttime . "'"); // 直前の番組をずらす for ($i = 0; $i < count($trecs); $i++) { if ($battings < $tuners) { break; } // 解消終了のハズ? // 予約修正に必要な情報を取り出す $prev_id = $trecs[$i]->id; $prev_program_id = $trecs[$i]->program_id; $prev_channel_id = $trecs[$i]->channel_id; $prev_title = $trecs[$i]->title; $prev_description = $trecs[$i]->description; $prev_category_id = $trecs[$i]->category_id; $prev_starttime = $trecs[$i]->starttime; $prev_endtime = $trecs[$i]->endtime; $prev_autorec = $trecs[$i]->autorec; $prev_mode = $trecs[$i]->mode; $prev_start_time = toTimestamp($prev_starttime); // 始まっていない予約? if ($prev_start_time > time() + PADDING_TIME + $settings->former_time) { // 開始時刻を元に戻す $prev_starttime = toDatetime($prev_start_time + $settings->former_time); // 終わりをちょっとだけずらす $prev_endtime = toDatetime(toTimestamp($prev_endtime) - $settings->former_time - $settings->rec_switch_time); // tryのネスト try { // いったん予約取り消し self::cancel($prev_id); // 再予約 self::custom($prev_starttime, $prev_endtime, $prev_channel_id, $prev_title, $prev_description, $prev_category_id, $prev_program_id, $prev_autorec, $prev_mode); } catch (Exception $e) { throw new Exception("重複予約を解消できません"); } } else { throw new Exception("重複予約を解消できません"); } $battings--; } if ($battings < 0) { $battings = 0; } // これで重複解消したはず } else { throw new Exception("重複予約があります"); } } // チューナー番号 $tuner = $battings; // 改めてdurationをチェックしなおす if ($duration < $settings->former_time + 60) { // 60秒以下の番組は弾く throw new Exception("終わりつつある/終わっている番組です"); } // ここからファイル名生成 /* %TITLE% 番組タイトル %ST% 開始日時(ex.200907201830) %ET% 終了日時 %TYPE% GR/BS %CH% チャンネル番号 %DOW% 曜日(Sun-Mon) %DOWJ% 曜日(日-土) %YEAR% 開始年 %MONTH% 開始月 %DAY% 開始日 %HOUR% 開始時 %MIN% 開始分 %SEC% 開始秒 %DURATION% 録画時間(秒) */ $day_of_week = array("日", "月", "火", "水", "木", "金", "土"); $filename = $settings->filename_format; // あると面倒くさそうな文字を全部_に $fn_title = mb_ereg_replace("[ \\./\\*:<>\\?\\|()\\'\"&]", "_", trim($title)); // %TITLE% $filename = str_replace("%TITLE%", $fn_title, $filename); // %ST% 開始日時 $filename = str_replace("%ST%", date("YmdHis", $start_time), $filename); // %ET% 終了日時 $filename = str_replace("%ET%", date("YmdHis", $end_time), $filename); // %TYPE% GR/BS $filename = str_replace("%TYPE%", $crec->type, $filename); // %CH% チャンネル番号 $filename = str_replace("%CH%", "" . $crec->channel, $filename); // %DOW% 曜日(Sun-Mon) $filename = str_replace("%DOW%", date("D", $start_time), $filename); // %DOWJ% 曜日(日-土) $filename = str_replace("%DOWJ%", $day_of_week[(int) date("w", $start_time)], $filename); // %YEAR% 開始年 $filename = str_replace("%YEAR%", date("Y", $start_time), $filename); // %MONTH% 開始月 $filename = str_replace("%MONTH%", date("m", $start_time), $filename); // %DAY% 開始日 $filename = str_replace("%DAY%", date("d", $start_time), $filename); // %HOUR% 開始時 $filename = str_replace("%HOUR%", date("H", $start_time), $filename); // %MIN% 開始分 $filename = str_replace("%MIN%", date("i", $start_time), $filename); // %SEC% 開始秒 $filename = str_replace("%SEC%", date("s", $start_time), $filename); // %DURATION% 録画時間(秒) $filename = str_replace("%DURATION%", "" . $duration, $filename); // 文字コード変換 if (defined("FILESYSTEM_ENCODING")) { $filename = mb_convert_encoding($filename, FILESYSTEM_ENCODING, "UTF-8"); } $filename .= $RECORD_MODE["{$mode}"]['suffix']; $thumbname = $filename . ".jpg"; // サムネール $gen_thumbnail = INSTALL_PATH . "/gen-thumbnail.sh"; if (defined("GEN_THUMBNAIL")) { $gen_thumbnail = GEN_THUMBNAIL; } // ファイル名生成終了 // 予約レコードを埋める $rrec = new DBRecord(RESERVE_TBL); $rrec->channel_disc = $crec->channel_disc; $rrec->channel_id = $crec->id; $rrec->program_id = $program_id; $rrec->type = $crec->type; $rrec->channel = $crec->channel; $rrec->title = $title; $rrec->description = $description; $rrec->category_id = $category_id; $rrec->starttime = toDatetime($rec_start); $rrec->endtime = toDatetime($end_time); $rrec->path = $filename; $rrec->autorec = $autorec; $rrec->mode = $mode; $rrec->reserve_disc = md5($crec->channel_disc . toDatetime($start_time) . toDatetime($end_time)); // 予約実行 $cmdline = $settings->at . " " . date("H:i m/d/Y", $at_start); $descriptor = array(0 => array("pipe", "r"), 1 => array("pipe", "w"), 2 => array("pipe", "w")); $env = array("CHANNEL" => $crec->channel, "DURATION" => $duration, "OUTPUT" => INSTALL_PATH . $settings->spool . "/" . $filename, "TYPE" => $crec->type, "TUNER" => $tuner, "MODE" => $mode, "THUMB" => INSTALL_PATH . $settings->thumbs . "/" . $thumbname, "FORMER" => "" . $settings->former_time, "FFMPEG" => "" . $settings->ffmpeg, "SID" => $crec->sid); // ATで予約する $process = proc_open($cmdline, $descriptor, $pipes, INSTALL_PATH . $settings->spool, $env); if (is_resource($process)) { fwrite($pipes[0], $settings->sleep . " " . $sleep_time . "\n"); fwrite($pipes[0], DO_RECORD . "\n"); fwrite($pipes[0], COMPLETE_CMD . " " . $rrec->id . "\n"); if ($settings->use_thumbs == 1) { fwrite($pipes[0], $gen_thumbnail . "\n"); } fclose($pipes[0]); // 標準エラーを取る $rstring = stream_get_contents($pipes[2]); fclose($pipes[2]); proc_close($process); } else { $rrec->delete(); throw new Exception("AT実行エラー"); } // job番号を取り出す $rarr = array(); $tok = strtok($rstring, " \n"); while ($tok !== false) { array_push($rarr, $tok); $tok = strtok(" \n"); } $key = array_search("job", $rarr); if ($key !== false) { if (is_numeric($rarr[$key + 1])) { $rrec->job = $rarr[$key + 1]; return $rrec->job; // 成功 } } // エラー $rrec->delete(); throw new Exception("job番号の取得に失敗"); } catch (Exception $e) { if ($rrec != null) { if ($rrec->id) { // 予約を取り消す $rrec->delete(); } } throw $e; } }
include_once INSTALL_PATH . "/reclib.php"; include_once INSTALL_PATH . "/Reservation.class.php"; include_once INSTALL_PATH . "/Settings.class.php"; $settings = Settings::factory(); $program_id = 0; if (isset($_POST['program_id'])) { $program_id = $_POST['program_id']; } if (!(isset($_POST['shour']) && isset($_POST['smin']) && isset($_POST['smonth']) && isset($_POST['sday']) && isset($_POST['syear']) && isset($_POST['ehour']) && isset($_POST['emin']) && isset($_POST['emonth']) && isset($_POST['eday']) && isset($_POST['eyear']) && isset($_POST['channel_id']) && isset($_POST['title']) && isset($_POST['description']) && isset($_POST['category_id']) && isset($_POST['record_mode']))) { exit("Error:予約に必要な値がセットされていません"); } $start_time = @mktime($_POST['shour'], $_POST['smin'], 0, $_POST['smonth'], $_POST['sday'], $_POST['syear']); if ($start_time < 0 || $start_time === false) { exit("Error:開始時間が不正です"); } $end_time = @mktime($_POST['ehour'], $_POST['emin'], 0, $_POST['emonth'], $_POST['eday'], $_POST['eyear']); if ($end_time < 0 || $end_time === false) { exit("Error:終了時間が不正です"); } $channel_id = $_POST['channel_id']; $title = $_POST['title']; $description = $_POST['description']; $category_id = $_POST['category_id']; $mode = $_POST['record_mode']; $rval = 0; try { $rval = Reservation::custom(toDatetime($start_time), toDatetime($end_time), $channel_id, $title, $description, $category_id, $program_id, 0, $mode); } catch (Exception $e) { exit("Error:" . $e->getMessage()); } exit("" . $program_id);