質問編集履歴

3

誤字を修正しました

2019/10/24 05:04

投稿

kenichi_myk
kenichi_myk

スコア14

test CHANGED
File without changes
test CHANGED
@@ -26,7 +26,7 @@
26
26
 
27
27
 
28
28
 
29
- $base_url = 'http://****/calender_test/';
29
+ $base_url = 'http://****/calendar_test/';
30
30
 
31
31
 
32
32
 

2

同じソースを記載していた為

2019/10/24 05:04

投稿

kenichi_myk
kenichi_myk

スコア14

test CHANGED
File without changes
test CHANGED
@@ -206,256 +206,68 @@
206
206
 
207
207
  ```
208
208
 
209
+
210
+
209
211
  ```php
210
212
 
213
+ data.php
214
+
211
215
  <?php
212
216
 
213
- require './data.php';
214
-
215
-
216
-
217
- $base_url = 'http://******/****/calender_test/';
218
-
219
-
220
-
221
- function funcIsAjax(){
222
-
223
- if(isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest')
224
-
225
- return true;
226
-
227
-
228
-
229
- return false;
230
-
231
- }
232
-
233
-
234
-
235
- if(funcIsAjax()) header("Content-type: text/plain; charset=UTF-8");
236
-
237
- else {header("Location: {$base_url}"); exit;}
238
-
239
-
240
-
241
- date_default_timezone_set('Asia/Tokyo'); //タイムゾーンの設定
242
-
243
-
244
-
245
- $today = $_POST;
246
-
247
- extract($today);
248
-
249
-
250
-
251
- $thisMonth = new DateTime($today);
252
-
253
- $dt = clone $thisMonth;
254
-
255
- $prev = $dt->modify('-1 month')->format('Y-m');
256
-
257
- $dt = clone $thisMonth;
258
-
259
- $next = $dt->modify('+1 month')->format('Y-m');
260
-
261
-
262
-
263
- $yearMonth = $thisMonth->format('Y F');
264
-
265
- $month = $thisMonth->format('Y-m');
266
-
267
-
268
-
269
- // カレンダー表示
270
-
271
- // 前月表示
272
-
273
- $tr = '<div class="cal_tr">';
274
-
275
- $tail = null;
276
-
277
- //前月の最終日を習得
278
-
279
- $lastDayOfPrevMonth = new DateTime('last day of ' . $yearMonth . ' -1 month');
280
-
281
- while ($lastDayOfPrevMonth->format('N') < 7) {
282
-
283
- $tail = sprintf('<div></div>', $lastDayOfPrevMonth->format('d')) . $tail;
284
-
285
- $tail = sprintf('<div class="cal cal_td empty"><div class="cal_body"></div></div>', $lastDayOfPrevMonth->format('d')) . $tail;
286
-
287
- $lastDayOfPrevMonth->sub(new DateInterval('P1D'));
288
-
289
- $prevmanth = $lastDayOfPrevMonth->format('Y-m');
290
-
291
- }
292
-
293
-
294
-
295
- // 当月表示
296
-
297
- $body = null;
298
-
299
- $period = new DatePeriod (
300
-
301
- new DateTime('first day of' . $yearMonth),
302
-
303
- new DateInterval('P1D'),
304
-
305
- new DateTime('first day of' . $yearMonth . '+1 month')
306
-
307
- );
308
-
309
-
310
-
311
- $today = new DateTime('today');
312
-
313
- foreach ($period as $day) {
314
-
315
- if ($day->format('N') === '1'){
316
-
317
- $body .= '</div></div>';
318
-
319
- $body .= '<div class="cal_tr">';
320
-
321
- }
322
-
323
- $days = $day->format('Y-m-d');
324
-
325
-
326
-
327
- foreach($holiday as $key) {
328
-
329
- $id = $key['id'];
330
-
331
- $user = $key['account_id'];
332
-
333
- $kana = $key['account_kana'];
334
-
335
- $from = $key['datetime_from'];
336
-
337
- $to = $key['datetime_from'];
338
-
339
- $type = $key['holiday_type'];
340
-
341
- }
342
-
343
- if($from == $days) {
344
-
345
- $todayClass = ($day->format('Y-m-d') === $today->format('Y-m-d')) ? 'today' : '';
346
-
347
- $body .= sprintf('<div class="cal cal_td" data-date="' . $days . '"><div class="cal_date day_%d %s">%d</div><div class="cal_plan"></div><div class="cal_body"><div class="area_btn" data-user="' . $user . ' data-user="' . $kana . ' "data-from="' . $from . '" data-to="' . $to . '" data-type="' . $type . '">' . $type . '/' . ' ' .$user .'</div></div></div>', $day->format('w'), $todayClass, $day->format('d'));
348
-
349
- } else {
350
-
351
- $todayClass = ($day->format('Y-m-d') === $today->format('Y-m-d')) ? 'today' : '';
352
-
353
- $body .= sprintf('<div class="cal cal_td" data-date="' . $days . '"><div class="cal_date day_%d %s">%d</div><div class="cal_plan"></div><div class="cal_body"></div></div>', $day->format('w'), $todayClass, $day->format('d'));
354
-
355
-
356
-
357
- }
358
-
359
- }
360
-
361
-
362
-
363
- // 次月表示
364
-
365
- $head = null;
366
-
367
- $firstDayOfNextMonth = new DateTime('first day of' . $yearMonth . '+1 month');
368
-
369
- // var_dump($firstDayOfNextMonth->format('N'));
370
-
371
- while($firstDayOfNextMonth->format('N') > 1) {
372
-
373
- $head .= '<div class="cal cal_td empty">' . $firstDayOfNextMonth->format('d');
374
-
375
- $head .= '<div class="cal_body"></div>';
376
-
377
- $head .= '</div>';
378
-
379
-
380
-
381
- $firstDayOfNextMonth->add(new DateInterval('P1D'));
382
-
383
- $nextMonth = $firstDayOfNextMonth->format('Y-m');
384
-
385
- }
386
-
387
-
388
-
389
- echo $tr . $tail . $body . $head;
217
+ $holiday[] = array(
218
+
219
+ 'id'=> '0111'
220
+
221
+ ,'account_id' => '山田 太郎'
222
+
223
+ ,'account_kana' => 'ヤマダ タロウ'
224
+
225
+ ,'datetime_from' => '2019-10-23'
226
+
227
+ ,'datetime_to' => '2019-10-23'
228
+
229
+ ,'holiday_type' => '有休'
230
+
231
+ );
232
+
233
+ $holiday[] = array(
234
+
235
+ 'id'=> '0112'
236
+
237
+ ,'account_id' => '山本 次郎'
238
+
239
+ ,'account_kana' => 'ヤマモト ジロウ'
240
+
241
+ ,'datetime_from' => '2019-11-10'
242
+
243
+ ,'datetime_to' => '2019-10-12'
244
+
245
+ ,'holiday_type' => '有休'
246
+
247
+ );
248
+
249
+ $holiday[] = array(
250
+
251
+ 'id' => '0113'
252
+
253
+ ,'account_id' => '田中 三郎'
254
+
255
+ ,'account_kana' => 'タナカ サブロウ'
256
+
257
+ ,'datetime_from' => '2019-09-10'
258
+
259
+ ,'datetime_to' => '2019-09-11'
260
+
261
+ ,'holiday_type' => '有休'
262
+
263
+ );
390
264
 
391
265
 
392
266
 
393
267
  ?>
394
268
 
395
-
396
-
397
269
  ```
398
270
 
399
- ```php
400
-
401
- data.php
402
-
403
- <?php
404
-
405
- $holiday[] = array(
406
-
407
- 'id'=> '0111'
408
-
409
- ,'account_id' => '山田 太郎'
410
-
411
- ,'account_kana' => 'ヤマダ タロウ'
412
-
413
- ,'datetime_from' => '2019-10-23'
414
-
415
- ,'datetime_to' => '2019-10-23'
416
-
417
- ,'holiday_type' => '有休'
418
-
419
- );
420
-
421
- $holiday[] = array(
422
-
423
- 'id'=> '0112'
424
-
425
- ,'account_id' => '山本 次郎'
426
-
427
- ,'account_kana' => 'ヤマモト ジロウ'
428
-
429
- ,'datetime_from' => '2019-11-10'
430
-
431
- ,'datetime_to' => '2019-10-12'
432
-
433
- ,'holiday_type' => '有休'
434
-
435
- );
436
-
437
- $holiday[] = array(
438
-
439
- 'id' => '0113'
440
-
441
- ,'account_id' => '田中 三郎'
442
-
443
- ,'account_kana' => 'タナカ サブロウ'
444
-
445
- ,'datetime_from' => '2019-09-10'
446
-
447
- ,'datetime_to' => '2019-09-11'
448
-
449
- ,'holiday_type' => '有休'
450
-
451
- );
452
-
453
-
454
-
455
- ?>
456
-
457
- ```
458
-
459
271
  ##試したこと
460
272
 
461
273
  index.phpをロードしたらAjaxでcalendar.phpを読みに行く仕組みになっています。

1

内容の追加編集を行いました。

2019/10/24 03:25

投稿

kenichi_myk
kenichi_myk

スコア14

test CHANGED
File without changes
test CHANGED
@@ -457,3 +457,11 @@
457
457
  ```
458
458
 
459
459
  ##試したこと
460
+
461
+ index.phpをロードしたらAjaxでcalendar.phpを読みに行く仕組みになっています。
462
+
463
+ foreachの入れ子の仕方、if文の分岐の仕方等トライしてみましたがうまくいきません。
464
+
465
+
466
+
467
+ プログラミングを始めてまだ初心者で、まだまだ理解できていない点も多々あるかと思いますがよろしくお願いします。