質問編集履歴
1
解決したコードの追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -184,198 +184,20 @@
|
|
184
184
|
|
185
185
|
|
186
186
|
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
i
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
e
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
//不定休日の値を取得する処理
|
204
|
-
|
205
|
-
$iholiday = [];
|
206
|
-
|
207
|
-
$sql = "SELECT Iholiday FROM table3 WHERE Cusid=?";
|
208
|
-
|
209
|
-
$sth = $dbh -> prepare($sql);
|
210
|
-
|
211
|
-
$array = array($_SESSION['cusid']);
|
212
|
-
|
213
|
-
$sth -> execute($array);
|
214
|
-
|
215
|
-
$result = $sth->fetchall(PDO::FETCH_ASSOC);
|
216
|
-
|
217
|
-
foreach($result as $row){
|
218
|
-
|
219
|
-
$iholidays = new DateTime($row['Iholiday']);
|
220
|
-
|
221
|
-
$iholiday[] = $iholidays -> format('Y/n/j');
|
222
|
-
|
223
|
-
}
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
function make_date_list($year,$month){
|
228
|
-
|
229
|
-
//毎週の定休日
|
230
|
-
|
231
|
-
global $weeks;
|
232
|
-
|
233
|
-
$regular_holiday = explode(',', $weeks);
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
//祝日
|
238
|
-
|
239
|
-
$public_holidays = get_public_holidays();
|
240
|
-
|
241
|
-
//不定休
|
242
|
-
|
243
|
-
global $iholiday;
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
$target = new \DateTime("{$year}-{$month}-01");
|
248
|
-
|
249
|
-
$date = [];
|
250
|
-
|
251
|
-
for($i = 0; $i < intval($target->format('t')); $i++){
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
if($i > 0) $target->modify('+1day');
|
256
|
-
|
257
|
-
//祝日
|
258
|
-
|
259
|
-
if(isset($public_holidays[$target->format('Y/n/j')])){
|
260
|
-
|
261
|
-
$holiday = true;
|
262
|
-
|
263
|
-
//定休日
|
264
|
-
|
265
|
-
}else if(in_array($target->format('w'),(array)$regular_holiday)){
|
266
|
-
|
267
|
-
$holiday = true;
|
268
|
-
|
269
|
-
//不定休
|
270
|
-
|
271
|
-
}else if(in_array($target->format('Y/n/j'),(array)$iholiday)){
|
272
|
-
|
273
|
-
$holiday = true;
|
274
|
-
|
275
|
-
//今日
|
276
|
-
|
277
|
-
}
|
278
|
-
|
279
|
-
else{
|
280
|
-
|
281
|
-
$holiday = false;
|
282
|
-
|
283
|
-
}
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
$dates[$i] = [
|
288
|
-
|
289
|
-
'day' => $target->format('j'),
|
290
|
-
|
291
|
-
'week' => $target->format('w'),
|
292
|
-
|
293
|
-
'holiday' => $holiday,
|
294
|
-
|
295
|
-
];
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
}
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
/*カレンダーの空欄箇所*/
|
304
|
-
|
305
|
-
$first_date = current($dates);
|
306
|
-
|
307
|
-
$end_date = end($dates);
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
$damy_num = intval($first_date['week']);
|
312
|
-
|
313
|
-
if($damy_num > 0){
|
314
|
-
|
315
|
-
$damy = [];
|
316
|
-
|
317
|
-
for($i = $damy_num - 1;0 <= $i;$i--){
|
318
|
-
|
319
|
-
array_unshift($dates,['week'=>$i,'day'=>' ']);
|
320
|
-
|
321
|
-
}
|
322
|
-
|
323
|
-
}
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
$damy_num = intval($end_date['week']);
|
328
|
-
|
329
|
-
if($damy_num < 6){
|
330
|
-
|
331
|
-
$damy = [];
|
332
|
-
|
333
|
-
for($i = $damy_num; $i < 6;$i++){
|
334
|
-
|
335
|
-
array_push($dates,['week'=>$i,'day'=>' ']);
|
336
|
-
|
337
|
-
}
|
338
|
-
|
339
|
-
}
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
return $dates;
|
344
|
-
|
345
|
-
}
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
if(isset($_GET['y']) and $_GET['y']){
|
350
|
-
|
351
|
-
$year = $_GET['y'];
|
352
|
-
|
353
|
-
}else{
|
354
|
-
|
355
|
-
$year = date('Y');
|
356
|
-
|
357
|
-
}
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
if(isset($_GET['m']) and $_GET['m']){
|
362
|
-
|
363
|
-
$month = $_GET['m'];
|
364
|
-
|
365
|
-
}else{
|
366
|
-
|
367
|
-
$month = date('m');
|
368
|
-
|
369
|
-
}
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
$dates = make_date_list($year,$month);
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
echo json_encode($dates);
|
378
|
-
|
379
|
-
?>
|
187
|
+
以下の年を跨ぐことを考慮したコードを追加して解決できました。
|
188
|
+
|
189
|
+
ありがとうございました。
|
190
|
+
|
191
|
+
|
192
|
+
|
193
|
+
```javascript
|
194
|
+
|
195
|
+
if(nowDate.getFullYear() < year ){
|
196
|
+
|
197
|
+
c += '<a href="" onClick="prev();return false;" class="cal_prev"></a>';
|
198
|
+
|
199
|
+
c += '<p>'+year+'年'+month+'月</p>';
|
200
|
+
|
201
|
+
}
|
380
202
|
|
381
203
|
```
|