PageRenderTime 106ms CodeModel.GetById 35ms app.highlight 15ms RepoModel.GetById 52ms app.codeStats 0ms

/webapp_biz/modules/biz/page/fh_biz_schedule_edit.php

https://github.com/openpne/OpenPNE2
PHP | 261 lines | 202 code | 46 blank | 13 comment | 54 complexity | 3b2f7aa1c4264cfe2e419264b0f3a341 MD5 | raw file
  1<?php
  2/**
  3 * @copyright 2005-2008 OpenPNE Project
  4 * @license   http://www.php.net/license/3_01.txt PHP License 3.01
  5 */
  6
  7class biz_page_fh_biz_schedule_edit extends OpenPNE_Action
  8{
  9    function execute($requests)
 10    {
 11        $u = $GLOBALS['AUTH']->uid();
 12
 13        if (!biz_isPermissionSchedule($u, $requests['schedule_id'])) {
 14            handle_kengen_error();
 15        }
 16        $form_val['subject'] = $requests['subject'];
 17        $form_val['body'] = $requests['body'];
 18
 19        $this->set('banner', $requests['sc_bn']);
 20
 21        if ($requests['sc_title']) {
 22            $requests['title'] = $requests['sc_title'];
 23        }
 24
 25        if ($requests['sc_memo']) {
 26            $requests['value'] = $requests['sc_memo'];
 27        }
 28
 29        if ($requests['sc_b_year'] && $requests['sc_b_month'] && $requests['sc_b_date']) {
 30            $requests['begin_date'] = $requests['sc_b_year'].'-'.$requests['sc_b_month'].'-'.$requests['sc_b_date'];
 31        }
 32
 33        if ($requests['sc_b_hour'] && $requests['sc_b_minute']) {
 34            $requests['begin_time'] = $requests['sc_b_hour'].':'.$requests['sc_b_minute'];
 35        }
 36
 37        if ($requests['sc_f_hour'] && $requests['sc_f_minute']) {
 38            $requests['finish_time'] = $requests['sc_f_hour'].':'.$requests['sc_f_minute'];
 39        }
 40
 41        $sessid = session_id();
 42
 43        $schedule = biz_getScheduleInfo($requests['schedule_id']);
 44
 45        if ($schedule['c_member_id'] == $u) {
 46            //自分自身
 47            $target_id = $u;
 48            $this->set('is_h', true);  //判別フラグ
 49            $this->set('inc_navi',fetch_inc_navi('h'));
 50        } else {
 51            //他人
 52            $target_id = $requests['target_id'];
 53            $this->set('is_f', true);  //判別フラグ
 54            $this->set('inc_navi',fetch_inc_navi('f'));
 55        }
 56
 57        //プロフィール
 58        $this->set("target_member", db_member_c_member4c_member_id($u));
 59        $this->set("form_val", $form_val);
 60
 61        //カレンダー関係
 62        //カレンダー開始用変数
 63        $year = date("Y");
 64        $month= date("n");
 65        //カレンダー用変数
 66        $date_val=  array(
 67            'year' => $year,
 68            'month' => $month,
 69            'day' => null,
 70        );
 71        $this->set("date_val", $date_val);
 72
 73        //日記のカレンダー
 74        $calendar = db_common_diary_monthly_calendar($year, $month, $u);
 75
 76        $this->set("calendar", $calendar['days']);
 77        $this->set("ym", $calendar['ym']);
 78
 79        //日付関連
 80        if ($requests['rep_type']) {
 81            $begin_date = biz_getRepeatBegin($requests['schedule_id']);
 82        } else {
 83            $begin_date = $requests['begin_date'];
 84        }
 85
 86        $nowyear = date("Y", strtotime($begin_date));
 87        $nowmonth = date("m", strtotime($begin_date));
 88        $nowday = date("d", strtotime($begin_date));
 89
 90        for ($i = $nowyear; $i <= $nowyear+10; $i++) {
 91            if ($i == $nowyear) {
 92                $years = '<option value="'.$i.'" selected="selected">';
 93            } else {
 94                $years .= '<option value="'.$i.'">';
 95            }
 96            $years .= $i.'年';
 97            $years .= '</option>';
 98        }
 99
100        for ($i = 1; $i <= 12; $i++) {
101            $i_f = sprintf("%02d",$i);  //月は常に二桁
102            if ($i == $nowmonth) {
103                $monthes .= '<option value="'.$i_f.'" selected="selected">';
104            } else {
105                $monthes .= '<option value="'.$i_f.'">';
106            }
107            $monthes .= $i.'月';
108            $monthes .= '</option>';
109        }
110
111        for ($i = 1; $i <= 31; $i++) {
112            $i_f = sprintf("%02d",$i);  //日は常に二桁
113            if ($i == $nowday) {
114                $days .= '<option value="'.$i_f.'" selected="selected">';
115            } else {
116                $days .= '<option value="'.$i_f.'">';
117            }
118            $days .= $i.'日';
119            $days .= '</option>';
120        }
121
122        $hours = biz_makeSerialArray(23);  //時
123        $mins = biz_makeSerialArray(55, 0, 5);  //分
124        $wk = array('日', '月', '火', '水', '木', '金', '土');  //週
125        $rp_count = biz_makeSerialArray(12, 1);  //繰り返し回数
126        $bn_num = biz_makeSerialArray(31, 1);  //日数
127
128        $this->set('years', $years);
129        $this->set('monthes', $monthes);
130        $this->set('days', $days);
131        $this->set('hours', $hours);
132        $this->set('mins', $mins);
133        $this->set('wk', $wk);
134        $this->set('rp_count', $rp_count);
135        $this->set('bn_num', $bn_num);
136
137        $this->set('title', $requests['title']);
138        $this->set('value', $requests['value']);
139
140
141        if (!is_null($requests['begin_time'])) {
142            $this->set('begin_hour', date("G", strtotime($requests['begin_time'])));
143        }
144
145        if (!is_null($requests['begin_time'])) {
146            $begin_min = date("i", strtotime($requests['begin_time']));
147            if (substr($begin_min, 0, 1) == '0') {
148                $begin_min = substr($begin_min, 1,1);
149            }
150        }
151
152        if (!is_null($requests['begin_time'])) {
153            $this->set('begin_min', $begin_min);
154        }
155        if (!is_null($requests['finish_time'])) {
156            $this->set('finish_hour', date("G", strtotime($requests['finish_time'])));
157        } else {
158            $this->set('finish_hour', null);
159        }
160
161        if (!is_null($requests['finish_time'])) {
162            $finish_min = date("i", strtotime($requests['finish_time']));
163        }
164        if (substr($finish_min, 0, 1) == '0') {
165            $finish_min = substr($finish_min, 1,1);
166        }
167
168        if (!is_null($requests['begin_time'])) {
169            $this->set('finish_min', $finish_min);
170        } else {
171            $this->set('finish_min', null);
172        }
173
174        if ($requests['rep_type']) {
175            $is_rep = true;
176        } else {
177            if ($requests['sc_rp']) {
178                $is_rep = true;
179            } else {
180                $is_rep = false;
181            }
182        }
183
184        $dayofweek = array();
185
186        if (empty($requests['rep_type'])) {
187            foreach ($requests['sc_rwk'] as $value) {
188                $rp_rule += 1 << $value;
189            }
190            $requests['rep_type'] = $rp_rule;
191        }
192
193        for ($i = 0; $i <= 6; $i++) {
194            if ($requests['rep_type'] & (1 << $i)) {
195                array_push($dayofweek, 1);
196            } else {
197                array_push($dayofweek, 0);
198            }
199        }
200        $this->set('rep_type', $dayofweek);
201        $this->set('is_rep', $is_rep);
202
203        $this->set('schedule_id', $requests['schedule_id']);
204
205        $repeat_begin = biz_getRepeatBegin($requests['schedule_id']);
206        $repeat_finish = biz_getRepeatFinish($requests['schedule_id']);
207        $repeat_term = strtotime($repeat_finish) - strtotime($repeat_begin);
208
209        $daycount = $repeat_term / (24 * 60 * 60) / 6;
210
211        $this->set('repeat_begin_date', $repeat_begin);
212        if (isset($requests["sc_rcount"])) {
213            $daycount = $requests["sc_rcount"];
214        }
215        $this->set('repeat_term', ceil($daycount));
216
217        $biz_group_count = biz_getGroupCount($target_id);
218        $biz_group_list = biz_getJoinGroupList($target_id, 1, $biz_group_count);
219
220        $this->set('biz_group_list', $biz_group_list[0]);
221        $this->set('target_biz_group_id', $schedule['biz_group_id']);
222
223        if ($requests['public_flag']) {
224            $this->set('public_flag', $requests['public_flag']);
225        } else {
226            $this->set('public_flag', $schedule['public_flag']);
227        }
228
229        //追加
230        if ($requests['members']) {
231            $j_members = array_keys(unserialize($requests['members']));
232            sort($j_members);
233        } elseif($requests['sc_j_mem']) {
234            $j_members = $requests['sc_j_mem'];
235        } else {
236            $j_members = biz_getJoinMemberSchedule($requests['schedule_id']);
237        }
238        $this->set('j_members', $j_members);
239        $members = array();
240
241        $sql = 'SELECT c_member_id, nickname FROM c_member';
242        $members = db_get_all($sql, $params);
243        $i = 0;
244        foreach ($members as $key => $value) {
245            if (in_array($value['c_member_id'], $j_members)) {
246                $members[$key]['checkflag'] = 1;
247                $i++;
248            }
249
250            if (count($j_members) < $i) {
251                break;
252            }
253        }
254
255        $this->set('members', $members);
256
257        return 'success';
258    }
259}
260
261?>