Files
c-cms-legacy/app/Http/Controllers/CalendarController.php
TheGamecraft 54cdc12680 ALPHA 3.0.1h
2018-08-20 13:12:20 -04:00

472 lines
21 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 \App\Local;
use \App\User;
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.calendar_display');
}
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 = $text.'<div style="color:blue;"><i class="fa fa-plane" aria-hidden="true"></i>'.ucfirst($activity->data['event_name'])."</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');
$Requestdate = request('date');
$url = str_replace("-","_", $Requestdate);
/** Dont work ... API stuff
* Log::saveLog("a consulté l'horaire du ".$date);
**/
$today = Schedule::where('date','=',$Requestdate)->get();
$isEmpty = $today->isEmpty();
echo '<div class="modal-content"><div class="modal-header"><h5 class="modal-title" id="scrollmodalLabel">'.ucfirst(strftime("%A le %e %B %Y", strtotime($Requestdate))).'</h5><button type="button" class="close" data-dismiss="modal" aria-label="Close"> <span aria-hidden="true">×</span></button></div><div class="modal-body">';
foreach ($today as $date) {
if ($date->data['is_event_mandatory'] == "on") {
$is_mandatory = "<div class='btn btn-block btn-warning m-l-10 m-b-10 float-right'>Activité obligatoire</div>";
} else {
$is_mandatory = "<div class='btn btn-block btn-primary m-l-10 m-b-10 float-right'>Activité n'est pas obligatoire</div>";
}
echo(
'<div class="row">'.
'<div class="col-7">'.
'<p>'.$date->data['event_name'].trans('calendar.begin_at').$date->data['event_begin_time'].trans('calendar.end_at').$date->data['event_end_time'].'</p>'.
'</div>'.
'<div class="col-3">'.
$is_mandatory.
'</div>'.
'<div class="col-1">'.
'<a href="/admin/calendar/edit/'.$date->id.'" type="button" class="btn btn-secondary"><i class="fa fa-cog"></i>&nbsp; Modifier</a>'.
'</div>'.
'<div class="col-1">'.
'<a type="button" class="btn btn-danger" onclick="deleteEvent('.$date->id.');"><i class="fa fa-times-circle" style="color:white;"></i></a>'.
'</div>'.
'</div>'.
'<p>'.
"L'activité auras lieux a l'escadron entre 18h30 et 21h30".
'</p>'.
'<p>'.$date->data['event_desc'].
'</p>'
);
if ($date->type == "regular") {
if($date->data['n1_p1_plandone'] == "on")
{
$isdone_n1_p1 = '<span class="badge badge-success">Remis</span></i>';
} else {
$isdone_n1_p1 = '<span class="badge badge-danger">Non remis</span>';
}
if($date->data['n1_p2_plandone'] == "on")
{
$isdone_n1_p2 = '<span class="badge badge-success">Remis</span></i>';
} else {
$isdone_n1_p2 = '<span class="badge badge-danger">Non remis</span>';
}
if($date->data['n2_p1_plandone'] == "on")
{
$isdone_n2_p1 = '<span class="badge badge-success">Remis</span></i>';
} else {
$isdone_n2_p1 = '<span class="badge badge-danger">Non remis</span>';
}
if($date->data['n2_p2_plandone'] == "on")
{
$isdone_n2_p2 = '<span class="badge badge-success">Remis</span></i>';
} else {
$isdone_n2_p2 = '<span class="badge badge-danger">Non remis</span>';
}
if($date->data['n3_p1_plandone'] == "on")
{
$isdone_n3_p1 = '<span class="badge badge-success">Remis</span></i>';
} else {
$isdone_n3_p1 = '<span class="badge badge-danger">Non remis</span>';
}
if($date->data['n3_p2_plandone'] == "on")
{
$isdone_n3_p2 = '<span class="badge badge-success">Remis</span></i>';
} else {
$isdone_n3_p2 = '<span class="badge badge-danger">Non remis</span>';
}
echo '<table class="table">
<thead class="thead-dark">
<tr>
<th>Niveau</th>
<th style="width:45%">1er Période</th>
<th style="width:45%">2e Période</th>
</tr>
</thead>
<tbody>
<tr>
<th>1</th>
<td>
<table class="table float center" style="border:none; max-width:80%; margin:auto;">
<tbody>
<tr style="border:none;">
<td style="border:none;">'.User::find($date->data['n1_p1_instructor'])->fullname().'</td>
<td style="border:none;">'.$isdone_n1_p1.'</td>
</tr>
<tr style="border:none;">
<td style="border:none;">'.$date->data['n1_p1_ocom'].' - '.$date->data['n1_p1_name'].'</td>
<td style="border:none;">'.Local::find($date->data['n1_p1_local'])->name.'</td>
</tr>
</tbody>
</table>
</td>
<td>
<table class="table float center" style="border:none; max-width:80%; margin:auto;">
<tbody>
<tr style="border:none;">
<td style="border:none;">'.User::find($date->data['n1_p2_instructor'])->fullname().'</td>
<td style="border:none;">'.$isdone_n1_p2.'</td>
</tr>
<tr style="border:none;">
<td style="border:none;">'.$date->data['n1_p2_ocom'].' - '.$date->data['n1_p2_name'].'</td>
<td style="border:none;">'.Local::find($date->data['n1_p2_local'])->name.'</td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr>
<th>2</th>
<td>
<table class="table float center" style="border:none; max-width:80%; margin:auto;">
<tbody>
<tr style="border:none;">
<td style="border:none;">'.User::find($date->data['n2_p1_instructor'])->fullname().'</td>
<td style="border:none;">'.$isdone_n2_p1.'</td>
</tr>
<tr style="border:none;">
<td style="border:none;">'.$date->data['n2_p1_ocom'].' - '.$date->data['n2_p1_name'].'</td>
<td style="border:none;">'.Local::find($date->data['n2_p1_local'])->name.'</td>
</tr>
</tbody>
</table>
</td>
<td>
<table class="table float center" style="border:none; max-width:80%; margin:auto;">
<tbody>
<tr style="border:none;">
<td style="border:none;">'.User::find($date->data['n2_p2_instructor'])->fullname().'</td>
<td style="border:none;">'.$isdone_n2_p2.'</td>
</tr>
<tr style="border:none;">
<td style="border:none;">'.$date->data['n2_p2_ocom'].' - '.$date->data['n2_p2_name'].'</td>
<td style="border:none;">'.Local::find($date->data['n2_p2_local'])->name.'</td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr>
<th>3</th>
<td>
<table class="table float center" style="border:none; max-width:80%; margin:auto;">
<tbody>
<tr style="border:none;">
<td style="border:none;">'.User::find($date->data['n3_p1_instructor'])->fullname().'</td>
<td style="border:none;">'.$isdone_n3_p1.'</td>
</tr>
<tr style="border:none;">
<td style="border:none;">'.$date->data['n3_p1_ocom'].' - '.$date->data['n3_p1_name'].'</td>
<td style="border:none;">'.Local::find($date->data['n3_p1_local'])->name.'</td>
</tr>
</tbody>
</table>
</td>
<td>
<table class="table float center" style="border:none; max-width:80%; margin:auto;">
<tbody>
<tr style="border:none;">
<td style="border:none;">'.User::find($date->data['n3_p2_instructor'])->fullname().'</td>
<td style="border:none;">'.$isdone_n3_p2.'</td>
</tr>
<tr style="border:none;">
<td style="border:none;">'.$date->data['n3_p2_ocom'].' - '.$date->data['n3_p2_name'].'</td>
<td style="border:none;">'.Local::find($date->data['n3_p2_local'])->name.'</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>';
}
}
echo '<a href="/admin/calendar/add/'.$url.'" type="button" class="btn btn-primary btn-lg btn-block">'.trans('calendar.add_to_schedule').'</a></div><div class="modal-footer"><button type="button" class="btn btn-secondary" data-dismiss="modal">'.trans('pagination.close').'</button></div></div>';
}
public function add($date)
{
$lang = str_replace('_', '-', app()->getLocale());
setlocale(LC_ALL, $lang.'_'.strtoupper($lang).'.utf8','fra');
$date = str_replace("_", "-", $date);
$UserList = User::all();
$LocalList = Local::all();
return view('admin.calendar.calendar_add' ,['RequestDate' => $date, 'Userslist' => $UserList, 'LocalsList' => $LocalList]);
}
public function edit($id)
{
$schedule = Schedule::find($id);
$UserList = User::all();
$LocalList = Local::all();
return view('admin.calendar.calendar_edit' ,['RequestSchedule' => $schedule, 'Userslist' => $UserList, 'LocalsList' => $LocalList]);
}
public function store()
{
$schedule = new Schedule;
$schedule->date = request('event_date');
$schedule->type = request('event_type');
if(request('event_type') == "regular")
{
$eventData = [
"event_name" => request('event_name'),
"is_event_mandatory" => request('is_event_mandatory'),
"event_date" => request('event_date'),
"event_begin_time" => request('event_begin_time'),
"event_end_time" => request('event_end_time'),
"event_location" => request('event_location'),
"event_desc" => request('event_desc'),
"n1_p1_name" => request('n1_p1_name'),
"n1_p1_ocom" => request('n1_p1_ocom'),
"n1_p1_instructor" => request('n1_p1_instructor'),
"n1_p1_local" => request('n1_p1_local'),
"n1_p1_plandone" => request('n1_p1_plandone'),
"n1_p2_name" => request('n1_p2_name'),
"n1_p2_ocom" => request('n1_p2_ocom'),
"n1_p2_instructor" => request('n1_p2_instructor'),
"n1_p2_local" => request('n1_p2_local'),
"n1_p2_plandone" => request('n1_p2_plandone'),
"n2_p1_name" => request('n2_p1_name'),
"n2_p1_ocom" => request('n2_p1_ocom'),
"n2_p1_instructor" => request('n2_p1_instructor'),
"n2_p1_local" => request('n2_p1_local'),
"n2_p1_plandone" => request('n2_p1_plandone'),
"n2_p2_name" => request('n2_p2_name'),
"n2_p2_ocom" => request('n2_p2_ocom'),
"n2_p2_instructor" => request('n2_p2_instructor'),
"n2_p2_local" => request('n2_p2_local'),
"n2_p2_plandone" => request('n2_p2_plandone'),
"n3_p1_name" => request('n3_p1_name'),
"n3_p1_ocom" => request('n3_p1_ocom'),
"n3_p1_instructor" => request('n3_p1_instructor'),
"n3_p1_local" => request('n3_p1_local'),
"n3_p1_plandone" => request('n3_p1_plandone'),
"n3_p2_name" => request('n3_p2_name'),
"n3_p2_ocom" => request('n3_p2_ocom'),
"n3_p2_instructor" => request('n3_p2_instructor'),
"n3_p2_local" => request('n3_p2_local'),
"n3_p2_plandone" => request('n3_p2_plandone'),
];
} else {
$eventData = [
"event_name" => request('event_name'),
"is_event_mandatory" => request('is_event_mandatory'),
"event_date" => request('event_date'),
"event_begin_time" => request('event_begin_time'),
"event_end_time" => request('event_end_time'),
"event_location" => request('event_location'),
"event_desc" => request('event_desc'),
];
}
$schedule->data = $eventData;
$schedule->save();
}
public function patch($id)
{
$schedule = Schedule::find($id);
$schedule->date = request('event_date');
$schedule->type = request('event_type');
if(request('event_type') == "regular")
{
$eventData = [
"event_name" => request('event_name'),
"is_event_mandatory" => request('is_event_mandatory'),
"event_date" => request('event_date'),
"event_begin_time" => request('event_begin_time'),
"event_end_time" => request('event_end_time'),
"event_location" => request('event_location'),
"event_desc" => request('event_desc'),
"n1_p1_name" => request('n1_p1_name'),
"n1_p1_ocom" => request('n1_p1_ocom'),
"n1_p1_instructor" => request('n1_p1_instructor'),
"n1_p1_local" => request('n1_p1_local'),
"n1_p1_plandone" => request('n1_p1_plandone'),
"n1_p2_name" => request('n1_p2_name'),
"n1_p2_ocom" => request('n1_p2_ocom'),
"n1_p2_instructor" => request('n1_p2_instructor'),
"n1_p2_local" => request('n1_p2_local'),
"n1_p2_plandone" => request('n1_p2_plandone'),
"n2_p1_name" => request('n2_p1_name'),
"n2_p1_ocom" => request('n2_p1_ocom'),
"n2_p1_instructor" => request('n2_p1_instructor'),
"n2_p1_local" => request('n2_p1_local'),
"n2_p1_plandone" => request('n2_p1_plandone'),
"n2_p2_name" => request('n2_p2_name'),
"n2_p2_ocom" => request('n2_p2_ocom'),
"n2_p2_instructor" => request('n2_p2_instructor'),
"n2_p2_local" => request('n2_p2_local'),
"n2_p2_plandone" => request('n2_p2_plandone'),
"n3_p1_name" => request('n3_p1_name'),
"n3_p1_ocom" => request('n3_p1_ocom'),
"n3_p1_instructor" => request('n3_p1_instructor'),
"n3_p1_local" => request('n3_p1_local'),
"n3_p1_plandone" => request('n3_p1_plandone'),
"n3_p2_name" => request('n3_p2_name'),
"n3_p2_ocom" => request('n3_p2_ocom'),
"n3_p2_instructor" => request('n3_p2_instructor'),
"n3_p2_local" => request('n3_p2_local'),
"n3_p2_plandone" => request('n3_p2_plandone'),
];
} else {
$eventData = [
"event_name" => request('event_name'),
"is_event_mandatory" => request('is_event_mandatory'),
"event_date" => request('event_date'),
"event_begin_time" => request('event_begin_time'),
"event_end_time" => request('event_end_time'),
"event_location" => request('event_location'),
"event_desc" => request('event_desc'),
];
}
$schedule->data = $eventData;
$schedule->save();
$check = Schedule::find($id);
dd($check);
}
}