function execute($requests)
 {
     $u = $GLOBALS['KTAI_C_MEMBER_ID'];
     $tail = $GLOBALS['KTAI_URL_TAIL'];
     if (!biz_isPermissionSchedule($u, $requests['schedule_id'])) {
         handle_kengen_error();
     }
     $schedule = biz_getScheduleInfo($requests['schedule_id']);
     $requests['sc_b_year'] = $requests['sc_b_year'] + 2000;
     //ERROR----------------
     //存在しない日付
     if (!checkdate($requests['sc_b_month'], $requests['sc_b_date'], $requests['sc_b_year'])) {
         $redirect_script = '?m=ktai_biz&a=page_fh_biz_schedule_edit&' . $tail;
         $msg = urlencode('存在しない日付が指定されました。');
         $schedule = biz_getScheduleInfo($requests['schedule_id']);
         $begin_date = $schedule['begin_date'];
         //日付関連の引数は返さなくてもよい
         $url = $redirect_script . '&msg=' . $msg . '&begin_date=' . $begin_date . '&title=' . $requests['sc_title'] . '&sc_rp=' . $requests['sc_rp'] . '&value=' . $requests['sc_memo'] . '&members=' . $requests['sc_j_mem'] . '&writer=' . $requests['writer'] . '&schedule_id=' . $requests['schedule_id'];
         $_REQUEST['schedule_id'] = $requests['schedule_id'];
         $_REQUEST['msg'] = '存在しない日付が指定されました。';
         openpne_forward('ktai_biz', 'page', "fh_biz_schedule_edit");
         exit;
     }
     //---------------------
     //ERROR----------------
     //タイトル未入力
     if (empty($requests['sc_title'])) {
         $redirect_script = '?m=ktai_biz&a=page_fh_biz_schedule_edit&id=' . $requests['schedule_id'] . '&' . $tail;
         $msg = urlencode('タイトルを入力してください。');
         $begin_date = $requests['sc_b_year'] . '-' . $requests['sc_b_month'] . '-' . $requests['sc_b_date'];
         $url = $redirect_script . '&msg=' . $msg . '&begin_date=' . $begin_date . '&sc_rp=' . $requests['sc_rp'] . '&sc_memo=' . $requests['sc_memo'] . '&members=' . $requests['sc_j_mem'] . '&writer=' . $requests['writer'] . '&sc_rwk_enc=' . serialize($requests['sc_rwk_enc']) . '&sc_rcount=' . $requests['sc_rcount'] . '&schedule_id=' . $requests['schedule_id'];
         $_REQUEST['schedule_id'] = $requests['schedule_id'];
         $_REQUEST['msg'] = 'タイトルを入力してください。';
         openpne_forward('ktai_biz', 'page', "fh_biz_schedule_edit");
         exit;
     }
     //---------------------
     if ($requests['sc_b_hour'] && !$requests['sc_b_minute']) {
         $requests['sc_b_minute'] = '00';
     }
     if ($requests['sc_f_hour'] && !$requests['sc_f_minute']) {
         $requests['sc_f_minute'] = '00';
     }
     //日付のフォーマットを設定
     $begin_date = $requests['sc_b_year'] . '-' . $requests['sc_b_month'] . '-' . $requests['sc_b_date'];
     $begin_time = $requests['sc_b_hour'] . ':' . $requests['sc_b_minute'];
     $finish_time = $requests['sc_f_hour'] . ':' . $requests['sc_f_minute'];
     //ERROR---------------
     if (strtotime($finish_time) < strtotime($begin_time) && $finish_time != ':') {
         //終了時間と開始時間が変
         $redirect_script = '?m=ktai_biz&a=page_fh_biz_schedule_edit&id=' . $requests['schedule_id'] . '&' . $tail;
         $msg = urlencode('終了時刻が開始時刻より先です。');
         $begin_date = $requests['sc_b_year'] . '-' . $requests['sc_b_month'] . '-' . $requests['sc_b_date'];
         $url = $redirect_script . '&msg=' . $msg . '&begin_date=' . $begin_date . '&sc_title=' . $requests['sc_title'] . '&sc_rp=' . $requests['sc_rp'] . '&sc_memo=' . $requests['sc_memo'] . '&members=' . $requests['sc_j_mem'] . '&writer=' . $requests['writer'] . '&sc_rwk_enc=' . serialize($requests['sc_rwk_enc']) . '&sc_rcount=' . $requests['sc_rcount'] . '&schedule_id=' . $requests['schedule_id'];
         $_REQUEST['schedule_id'] = $requests['schedule_id'];
         $_REQUEST['msg'] = '終了時刻が開始時刻より先です。';
         openpne_forward('ktai_biz', 'page', "fh_biz_schedule_edit");
         exit;
     }
     //--------------------
     $mem = unserialize($requests['sc_j_mem']);
     $requests['sc_j_mem'] = array();
     $i = 0;
     if ($mem) {
         foreach ($mem as $key => $value) {
             $requests['sc_j_mem'][$i] = $key;
             $i++;
         }
     }
     if (!($requests['sc_b_hour'] || $requests['sc_b_minute'] || $requests['sc_f_hour'] || $requests['sc_f_minute'])) {
         //時刻指定なし
         $begin_time = $finish_time = null;
     } elseif (!($requests['sc_f_hour'] || $requests['sc_f_minute'])) {
         $finish_time = null;
     }
     $finish_date = $begin_date;
     //当日中に終わる予定は、開始日と終了日は同一でなければならない
     $schedule_id = '';
     $biz_schedule_member = biz_getJoinIdSchedule($requests['schedule_id']);
     biz_editSchedule($requests['sc_title'], $schedule['c_member_id'], $begin_date, $finish_date, $begin_time, $finish_time, $requests['sc_memo'], $rp_rule, 0, $requests['sc_j_mem'], $requests['public_flag'], $requests['schedule_id'], $biz_schedule_member);
     $schedule_id = $requests['schedule_id'];
     $first_id = biz_getScheduleMax() + 1;
     //登録される予定のプライマリキー
     $week = date("W", abs(strtotime($begin_date) - strtotime(date("Y-m-d")))) - 1;
     if (strtotime($begin_date) - strtotime(date('Y-m-d')) < 0) {
         $week = $week - $week * 2;
     }
     $_REQUEST['msg'] = '予定を編集しました。';
     $_REQUEST['w'] = $week;
     $_REQUEST['target_id'] = $requests['target_id'];
     $_REQUEST['id'] = biz_getScheduleMax();
     openpne_forward('ktai_biz', 'page', "fh_calendar_week");
     exit;
 }
 function execute($requests)
 {
     $u = $GLOBALS['AUTH']->uid();
     $sessid = session_id();
     if (!biz_isPermissionSchedule($u, $requests['schedule_id'])) {
         handle_kengen_error();
     }
     $schedule = biz_getScheduleInfo($requests['schedule_id']);
     if ($requests['sc_b_hour'] && !$requests['sc_b_minute']) {
         $requests['sc_b_minute'] = '00';
     }
     if ($requests['sc_f_hour'] && !$requests['sc_f_minute']) {
         $requests['sc_f_minute'] = '00';
     }
     //日付のフォーマットを設定
     $begin_date = $requests['sc_b_year'] . '-' . $requests['sc_b_month'] . '-' . $requests['sc_b_date'];
     if ($requests['sc_b_hour'] && $requests['sc_b_minute']) {
         $begin_time = $requests['sc_b_hour'] . ':' . $requests['sc_b_minute'];
     }
     if ($requests['sc_f_hour'] && $requests['sc_f_minute']) {
         $finish_time = $requests['sc_f_hour'] . ':' . $requests['sc_f_minute'];
     }
     // エラー遷移用
     $_REQUEST['begin_date'] = $begin_date;
     $_REQUEST['begin_time'] = $begin_time;
     $_REQUEST['finish_time'] = $finish_time;
     if (!checkdate($requests['sc_b_month'], $requests['sc_b_date'], $requests['sc_b_year'])) {
         $_REQUEST['msg'] = '存在しない日付が指定されました。';
         openpne_forward('biz', 'page', 'fh_biz_schedule_edit');
         exit;
     }
     if ($requests['sc_rp'] && empty($requests['sc_rwk'])) {
         $_REQUEST['msg'] = '繰り返し予定を登録する場合は、曜日を指定してください。';
         openpne_forward('biz', 'page', 'fh_biz_schedule_edit');
         exit;
     }
     if (strtotime($finish_time) < strtotime($begin_time) && isset($finish_time)) {
         $_REQUEST['msg'] = '終了時刻が開始時刻より先です。';
         openpne_forward('biz', 'page', 'fh_biz_schedule_edit');
         exit;
     }
     if ($requests['public_flag'] == 'group' && empty($requests['biz_group_id'])) {
         $_REQUEST['msg'] = '「グループまで公開」予定の場合はグループを指定してください';
         openpne_forward('biz', 'page', 'fh_biz_schedule_edit');
         exit;
     }
     //施設、参加者のチェック
     if (in_array('0', $requests['sc_j_mem'])) {
         //「全員」が含まれている場合は、配列を空に
         $requests['sc_j_mem'] = array();
     }
     if (!($requests['sc_b_hour'] || $requests['sc_b_minute'] || $requests['sc_f_hour'] || $requests['sc_f_minute'])) {
         //時刻指定なし
         $begin_time = $finish_time = null;
     } elseif (!($requests['sc_f_hour'] || $requests['sc_f_minute'])) {
         $finish_time = null;
     }
     if (!$requests['sc_rp'] && $requests['sc_bn'] == 1) {
         //当日中に終わる予定は、開始日と終了日は同一でなければならない
         $finish_date = $begin_date;
     }
     $schedule_id = '';
     if (!$requests['sc_rp']) {
         //繰り返しなし
         $finish_date = date("Y-m-d", strtotime($requests['sc_b_year'] . '-' . $requests['sc_b_month'] . '-' . ($requests['sc_b_date'] + ($requests['sc_bn'] - 1))));
         //繰り返しをしない予定登録
         biz_editSchedule($requests['sc_title'], $schedule['c_member_id'], $begin_date, $finish_date, $begin_time, $finish_time, $requests['sc_memo'], $rp_rule, 0, $requests['biz_group_id'], $requests['public_flag'], $requests['schedule_id'], $requests['sc_j_mem']);
         $schedule_id = $requests['schedule_id'];
     } else {
         //終了日の決定
         if (in_array(date('w', strtotime($begin_date)), $requests['sc_rwk'])) {
             $finish_date = date("Y-m-d", strtotime($begin_date . ' + ' . ($requests['sc_rcount'] - 1) * 7 . 'days'));
         } else {
             $finish_date = date("Y-m-d", strtotime($begin_date . ' + ' . $requests['sc_rcount'] * 7 . 'days'));
         }
         //繰り返しルールの決定
         foreach ($requests['sc_rwk'] as $value) {
             $rp_rule += 1 << $value;
         }
         //繰り返し予定
         $tmp = strtotime($begin_date);
         //処理中の日付
         if ($requests['iskeep']) {
             //繰り返し予定グループの維持(同予定から派生した繰り返し予定を一斉に編集)
             $replist = biz_getRepeatScheduleID($requests['schedule_id']);
             foreach ($replist as $value) {
                 biz_deleteSchedule($value);
                 //既存の繰り返し予定をすべて削除(予定日数の追加、削除のケースがありうるため)
             }
         }
         $first_id = biz_getScheduleMax() + 1;
         //登録される予定のプライマリキー
         for ($i = 0; $tmp < strtotime($finish_date); $i++) {
             //終了日に達するまで新規予定追加を繰り返す
             $nowday = strtotime($begin_date . ' +' . $i . 'days');
             $tmp = $nowday;
             if ($rp_rule & 1 << date("w", $nowday)) {
                 biz_insertSchedule($requests['sc_title'], $schedule['c_member_id'], date("Y-m-d", $tmp), date("Y-m-d", $tmp), $begin_time, $finish_time, $requests['sc_memo'], $rp_rule, $first_id, $requests['biz_group_id'], $requests['public_flag'], $requests['sc_j_mem']);
             }
         }
         $schedule_id = biz_getScheduleMax();
     }
     $week = date("W", abs(strtotime($begin_date) - strtotime(date("Y-m-d")))) - 1;
     $p = array('w' => $week, 'msg' => '予定を編集しました。', 'id' => $schedule_id, 'target_id' => $target_id);
     openpne_redirect('biz', 'page_fh_biz_schedule_view', $p);
 }