Files
c-cms-legacy/app/Http/Controllers/CalendarController.php
TheGamecraft 636c17441e ALPHA 3.0.1e
2018-07-18 21:24:34 -04:00

179 lines
6.6 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use \App\Log;
use \App\Schedule;
use Carbon\Carbon;
class CalendarController extends Controller
{
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('auth', ['except' => ['generate','load']]);
}
/**
* Show the application dashboard.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
Log::saveLog("Affichage de l'horaire");
return view('admin.calendar');
}
public function generate()
{
$lang = str_replace('_', '-', app()->getLocale());
setlocale(LC_ALL, $lang.'_'.strtoupper($lang).'.utf8','fra');
$month = request('month');
$year = request('year');
$nextMonth = $month + 1;
$nextYear = $year;
if ($nextMonth > 12) {
$nextMonth = 1;
$nextYear = $nextYear + 1;
}
$prevMonth = $month - 1;
$prevYear = $year;
if ($prevMonth < 1) {
$prevMonth = 12;
$prevYear = $prevYear - 1;
}
$calendar = array();
$dayinmonth = cal_days_in_month(CAL_GREGORIAN, $month, $year);
$firstdaymonth = date("w", strtotime("01-".$month."-".$year));
$addingday = 0;
for ($i=$firstdaymonth ; $addingday < $dayinmonth ; $i++) {
$addingday = $addingday + 1;
$calendar[$i] = $addingday;
}
echo '<table class="table calendar">';
echo '<thead class="thead-dark">';
echo '<td><a class="btn" onclick="generate('.$prevMonth.','.$prevYear.')"><i class="fa fa-chevron-left" aria-hidden="true"></i></a></td><td colspan="5">'.ucfirst(strftime("%B %Y", strtotime("01-".$month."-".$year))).'</td><td><a class="btn" onclick="generate('.$nextMonth.','.$nextYear.')"><i class="fa fa-chevron-right" aria-hidden="true"></i></a></td>';
echo '<tr><td>Dimanche</td><td>Lundi</td><td>Mardi</td><td>Mercredi</td><td>Jeudi</td><td>Vendredi</td><td>Samedi</td></tr>';
echo '</thead>';
for ($i=0; $i < 6 ; $i++)
{
echo '<tr>';
for ($a=0; $a < 7 ; $a++)
{
if (isset($calendar[(($i*7) + $a)]))
{
echo '<td class="calendar-container">';
$today = date("Y-m-d", strtotime($year."-".$month."-".$calendar[(($i*7) + $a)]));
$activityToday = Schedule::where('date','=',$today)->get();
if ($activityToday->isEmpty()) {
echo '<div><a name="'.$today.'" type="button" data-toggle="modal" data-target="#scrollmodal" id="calendar_'.$calendar[(($i*7) + $a)].'" class="btn btn-block btn-calendar" onclick="openCalendar(this.name)"><div class="calendar-date">'.date("j", strtotime($today)).'</div></a></div>';
} else {
$text = "";
foreach ($activityToday as $activity) {
$text = '<div style="color:blue;"><i class="fa fa-plane" aria-hidden="true"></i>'.$text.ucfirst($activity->type)."</div><br>";
}
echo '<div><a name="'.$today.'" type="button" data-toggle="modal" data-target="#scrollmodal" id="calendar_'.$calendar[(($i*7) + $a)].'" class="btn btn-block btn-calendar" onclick="openCalendar(this.name)"><div class="calendar-date">'.date("j", strtotime($today)).'</div><div class="calendar-text">'.$text.'</div></a></div>';
}
echo '</td>';
} else {
echo '<td class="calendar-container" style="border:none !important"></td>';
}
}
echo '</tr>';
}
echo '</table>';
}
public function load()
{
$lang = str_replace('_', '-', app()->getLocale());
setlocale(LC_ALL, $lang.'_'.strtoupper($lang).'.utf8','fra');
$date = request('date');
$today = Schedule::where('date','=',$date)->get();
$isEmpty = $today->isEmpty();
if ($isEmpty) { ?>
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="scrollmodalLabel"><?php echo ucfirst(strftime("%A le %e %B %Y", strtotime($date))) ?></h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<p><?php echo trans('calendar.nothing_today'); ?></p>
<button type="button" class="btn btn-primary btn-lg btn-block"><?php echo trans('calendar.add_to_schedule'); ?></button>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal"><?php echo trans('pagination.close'); ?></button>
</div>
</div><?php
} else {
foreach ($today as $date) {
if ($date->id) {
switch ($date->type) {
case 'pilotage':
$this->loadPilotage($date);
break;
case 'instruction':
$this->loadInstruction($date);
break;
default:
# code...
break;
}
}
}
}
}
private function loadPilotage($schedule)
{ ?>
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="scrollmodalLabel"><?php echo ucfirst(strftime("%A le %e %B %Y", strtotime($schedule->date))) ?></h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<p><?php echo trans('calendar.pilotage_title'); ?></p>
<p><?php echo trans('calendar.begin_at').$schedule->data['begin_at'].trans('calendar.end_at').$schedule->data['end_at'];?></p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal"><?php echo trans('pagination.close'); ?></button>
</div>
</div>
<?php }
}