openstamanager/templates/dashboard/body.php

225 lines
8.5 KiB
PHP
Raw Normal View History

2018-05-08 15:55:46 +02:00
<?php
include_once __DIR__.'/../../core.php';
2018-05-08 16:57:55 +02:00
$height = '80';
2018-05-08 15:55:46 +02:00
2018-05-22 17:42:19 +02:00
if (isset($_SESSION['period']['month'])) {
$period = explode(' ', $_SESSION['period']['month']);
$month = $period[0];
$year = $period[1];
2018-05-08 15:55:46 +02:00
2018-08-11 15:49:46 +02:00
$months = ['Gennaio' => '01', 'Febbraio' => '02', 'Marzo' => '03', 'Aprile' => '04', 'Maggio' => '05', 'Giugno' => '06', 'Luglio' => '07', 'Agosto' => '08', 'Settembre' => '09', 'Ottobre' => '10', 'Novembre' => '11', 'Dicembre' => '12'];
2018-05-22 17:42:19 +02:00
$month = $months[$month];
$title = $_SESSION['period']['month'];
//numero di giorni nel mese
$maxday = cal_days_in_month(CAL_GREGORIAN, $month, $year) + 1;
2018-05-08 15:55:46 +02:00
2018-05-22 17:42:19 +02:00
$mindate = $year.'-'.$month.'-'.'01';
$maxdate = $year.'-'.$month.'-'.$maxday;
$where = ' (in_interventi_tecnici.orario_inizio) <= '.prepare($maxdate).' AND (in_interventi_tecnici.orario_inizio) >= '.prepare($mindate).' AND ';
2018-05-08 15:55:46 +02:00
}
2018-05-22 17:42:19 +02:00
if (isset($_SESSION['period']['week'])) {
$period = explode(' ', $_SESSION['period']['week']);
$day = $period[0];
if (count($period) == 5) {
$maxmonth = $period[3];
$maxday_ = $period[2];
$month = $period[3];
$year = $period[4];
}
if (count($period) == 6) {
$maxmonth = $period[1];
$maxday_ = $period[3];
$month = $period[4];
$year = $period[5];
}
2018-05-08 15:55:46 +02:00
2018-08-11 15:49:46 +02:00
$months = ['gen' => '01', 'feb' => '02', 'mar' => '03', 'apr' => '04', 'mag' => '05', 'giu' => '06', 'lug' => '07', 'ago' => '08', 'set' => '09', 'ott' => '10', 'nov' => '11', 'dic' => '12'];
2018-05-22 17:42:19 +02:00
$month = $months[$month];
$maxmonth = $months[$maxmonth];
2018-05-08 15:55:46 +02:00
2018-05-22 17:42:19 +02:00
$title = $_SESSION['period']['week'];
//numero di giorni nel mese
$maxday = cal_days_in_month(CAL_GREGORIAN, $month, $year) + 1;
$mindate = $year.'-'.$month.'-'.$day;
$maxdate = $year.'-'.$maxmonth.'-'.$maxday_;
//aggiungo un giorno
$maxdate = date('Y-m-d', date(strtotime('+1 day', strtotime($maxdate))));
$where = ' (in_interventi_tecnici.orario_inizio) <= '.prepare($maxdate).' AND (in_interventi_tecnici.orario_inizio) >= '.prepare($mindate).' AND ';
}
2018-05-08 15:55:46 +02:00
$report_name = sanitizeFilename('dashboard_'.$year.'_'.$month.'.pdf');
//$date_start = $_SESSION['period_start'];
//$date_end = $_SESSION['period_end'];
$stati = (array) $_SESSION['dashboard']['idstatiintervento'];
$tipi = (array) $_SESSION['dashboard']['idtipiintervento'];
$tecnici = (array) $_SESSION['dashboard']['idtecnici'];
2018-08-11 15:49:46 +02:00
//in_interventi_tecnici.idintervento, colore, in_interventi_tecnici.id, idtecnico, orario_inizio, orario_fine,(SELECT ragione_sociale FROM an_anagrafiche WHERE idanagrafica=idtecnico) AS nome_tecnico, (SELECT colore FROM an_anagrafiche WHERE idanagrafica=idtecnico) AS colore_tecnico,
2018-11-19 16:46:41 +01:00
$query = 'SELECT DAY(in_interventi_tecnici.orario_inizio) AS giorno, orario_inizio AS data, GROUP_CONCAT(CONCAT((SELECT ragione_sociale FROM an_anagrafiche WHERE idanagrafica=in_interventi.idanagrafica), \'<br><small>\', (SELECT ragione_sociale FROM an_anagrafiche WHERE idanagrafica=in_interventi_tecnici.idtecnico), \'</small>\' ) SEPARATOR \'<br>\') AS attivita FROM in_interventi_tecnici INNER JOIN (in_interventi LEFT OUTER JOIN in_statiintervento ON in_interventi.idstatointervento=in_statiintervento.idstatointervento) ON in_interventi_tecnici.idintervento=in_interventi.id WHERE '.$where.' idtecnico IN('.implode(',', $tecnici).') AND in_interventi.idstatointervento IN('.implode(',', $stati).') AND in_interventi_tecnici.idtipointervento IN('.implode(',', $tipi).') '.Modules::getAdditionalsQuery('Interventi').' GROUP BY giorno ORDER BY CAST(giorno AS UNSIGNED)';
2018-05-08 15:55:46 +02:00
//echo $query;
2018-05-22 17:42:19 +02:00
2018-05-08 15:55:46 +02:00
$sessioni = $dbo->fetchArray($query);
2018-05-22 17:42:19 +02:00
//echo $query;
$rs = [];
for ($i = 0; $i < 33; ++$i) {
2018-11-19 16:46:41 +01:00
$rs[$sessioni[$i]['giorno']]['cliente'] = $sessioni[$i]['attivita'];
2018-05-22 17:42:19 +02:00
$rs[$sessioni[$i]['giorno']]['data'] = $sessioni[$i]['data'];
}
2018-05-08 15:55:46 +02:00
2018-05-22 17:42:19 +02:00
function showMonth($month, $year, &$rs, &$height)
{
$date = mktime(12, 0, 0, $month, 1, $year);
$daysInMonth = date('t', $date);
// calculate the position of the first day in the calendar (sunday = 1st column, etc)
$offset = (date('w', $date) - 1) % 7;
2018-05-08 15:55:46 +02:00
2018-05-22 17:42:19 +02:00
if ($offset < 0) {
$offset = 7 + $offset;
}
2018-05-08 15:55:46 +02:00
2018-05-22 17:42:19 +02:00
//echo $date."<br>";
//echo date("w", $date)."<br>";
//echo $offset;
2018-05-08 15:55:46 +02:00
2018-05-22 17:42:19 +02:00
$rows = 1;
//echo "<h1>Displaying calendar for " . date("F Y", $date) . "</h1>\n";
$header = [];
$row = [];
2018-05-08 15:55:46 +02:00
2018-05-22 17:42:19 +02:00
//$table .= "<table border=\"1\">\n";
//echo "\t<tr><th>Su</th><th>M</th><th>Tu</th><th>W</th><th>Th</th><th>F</th><th>Sa</th></tr>";
// $table .= "\t<tr><th>Lun</th><th>Mar</th><th>Mer</th><th>Gio</th><th>Ven</th><th>Sab</th><th>Dom</th></tr>";
2018-05-08 15:55:46 +02:00
2018-05-22 17:42:19 +02:00
//$header[$rows] = "\n\t<tr>";
//$row[$rows] = "\n\t<tr>";
2018-05-08 15:55:46 +02:00
2018-05-22 17:42:19 +02:00
//giorni prima
for ($i = 1; $i <= $offset; ++$i) {
$current_month = $month;
if ($current_month == 1) {
$current_month = 12;
$current_year = $year - 1;
} else {
$current_month = $month - 1;
$current_year = $year;
}
2018-05-08 15:55:46 +02:00
2018-05-22 17:42:19 +02:00
$lastdateofmonth = date('t', $current_month);
2018-05-08 15:55:46 +02:00
2018-05-22 17:42:19 +02:00
//$lastdate = $lastdateofmonth."/".$current_month."/".$current_year;
2018-05-08 15:55:46 +02:00
2018-05-22 17:42:19 +02:00
$day = (($lastdateofmonth - $offset) + ($i));
$weekday = date('l', strtotime($current_year.'-'.$current_month.'-'.(sprintf('%02d', $day))));
2018-08-11 15:49:46 +02:00
$weekdays = ['Monday' => 'Lunedi\'', 'Tuesday' => 'Martedi\'', 'Wednesday' => 'Mercoledi\'', 'Thursday' => 'Giovedi\'', 'Friday' => 'Venerdi\'', 'Saturday' => 'Sabato', 'Sunday' => 'Domenica'];
2018-05-22 17:42:19 +02:00
$weekday = $weekdays[$weekday];
2018-05-08 15:55:46 +02:00
2018-05-22 17:42:19 +02:00
$header[$rows] .= '<th>'.tr($weekday.' '.(sprintf('%02d', $day)).'/'.(sprintf('%02d', $current_month)), [], ['upper' => true])."</th>\n";
$row[$rows] .= "<td style=\"background:lightgray;\" ><b> </b></td>\n";
}
2018-05-08 15:55:46 +02:00
2018-05-22 17:42:19 +02:00
//giorni del mese
for ($day = 1; $day <= $daysInMonth; ++$day) {
if (($day + $offset - 1) % 7 == 0 && $day != 1) {
// $table .= "\t<tr><th>Lun ".$day."</th><th>Mar ".($day+1)."</th><th>Mer ".($day+2)."</th><th>Gio ".($day+3)."</th><th>Ven ".($day+4)."</th><th>Sab ".($day+5)."</th><th>Dom ".($day+6)."</th></tr>";
2018-05-08 15:55:46 +02:00
2018-05-22 17:42:19 +02:00
// $header[$rows] .= "</tr>\n\t<tr>";
//$row[$rows] .= "</tr>\n\t<tr>";
2018-05-08 15:55:46 +02:00
2018-05-22 17:42:19 +02:00
++$rows;
}
2018-05-08 15:55:46 +02:00
2018-05-22 17:42:19 +02:00
$weekday = date('l', strtotime($year.'-'.$month.'-'.(sprintf('%02d', $day))));
2018-08-11 15:49:46 +02:00
$weekdays = ['Monday' => 'Lunedi\'', 'Tuesday' => 'Martedi\'', 'Wednesday' => 'Mercoledi\'', 'Thursday' => 'Giovedi\'', 'Friday' => 'Venerdi\'', 'Saturday' => 'Sabato', 'Sunday' => 'Domenica'];
2018-05-22 17:42:19 +02:00
$weekday = $weekdays[$weekday];
2018-05-08 15:55:46 +02:00
2018-05-22 17:42:19 +02:00
$header[$rows] .= '<th>'.tr($weekday.' '.(sprintf('%02d', $day)).'/'.$month, [], ['upper' => true])."</th>\n";
if (empty($rs[$day]['cliente'])) {
$rs[$day]['cliente'] = ' ';
}
2018-05-08 15:55:46 +02:00
2018-05-22 17:42:19 +02:00
$row[$rows] .= "<td style='height:".$height."px' >".'<b>'.$rs[$day]['cliente']."</b></td>\n";
}
2018-05-08 15:55:46 +02:00
2018-05-22 17:42:19 +02:00
//$i = 1;
//giorni dopo
//while( ($day + $offset) <= $rows * 7){
2018-05-08 15:55:46 +02:00
2018-05-22 17:42:19 +02:00
for ($i = 1; ($day + $offset) <= ($rows * 7); ++$i) {
$current_month = $month;
if ($current_month == 12) {
$current_month = 1;
$current_year = $year + 1;
} else {
$current_month = $month + 1;
$current_year = $year;
}
2018-05-08 15:55:46 +02:00
2018-05-22 17:42:19 +02:00
//$lastdateofmonth = date('t',$current_month);
//$lastdate = $lastdateofmonth."/".$current_month."/".$current_year;
$weekday = date('l', strtotime($current_year.'-'.$current_month.'-'.(sprintf('%02d', $i))));
2018-08-11 15:49:46 +02:00
$weekdays = ['Monday' => 'Lunedi\'', 'Tuesday' => 'Martedi\'', 'Wednesday' => 'Mercoledi\'', 'Thursday' => 'Giovedi\'', 'Friday' => 'Venerdi\'', 'Saturday' => 'Sabato', 'Sunday' => 'Domenica'];
2018-05-22 17:42:19 +02:00
$weekday = $weekdays[$weekday];
$header[$rows] .= '<th> '.tr($weekday.' '.(sprintf('%02d', $i)).'/'.(sprintf('%02d', $current_month)), [], ['upper' => true])." </th>\n";
//$row[$rows] .= "<td> ".($offset+$day)."<br>".($rows * 7)." </td>\n";
$row[$rows] .= "<td style=\"background:lightgray;\" ><b> </b> </td>\n";
++$day;
2018-05-08 15:55:46 +02:00
}
2018-05-22 17:42:19 +02:00
//$header[$rows] .= "</tr>";
//$row[$rows] .= "</tr>";
//print_r($header);
//echo "<br>";
//print_r($row);
echo '<table class="table table-bordered">\n';
//creo righe
for ($i = 1; $i <= count($row); ++$i) {
echo "<tr>\n";
echo $header[$i];
echo "</tr>\n";
echo "<tr>\n";
echo $row[$i];
echo "</tr>\n";
2018-05-08 15:55:46 +02:00
}
2018-05-22 17:42:19 +02:00
echo '</table>';
2018-05-08 15:55:46 +02:00
2018-05-22 17:42:19 +02:00
//$table .= "</table>\n";
2018-05-08 15:55:46 +02:00
2018-05-22 17:42:19 +02:00
//echo $table;
}
2018-05-08 15:55:46 +02:00
// Intestazione tabella per righe
echo "
<h3 class='text-bold'>".tr('Calendario _PERIOD_', [
2018-05-22 17:42:19 +02:00
'_PERIOD_' => $title,
], ['upper' => true]).'</h3>';
2018-05-08 15:55:46 +02:00
2018-05-22 17:42:19 +02:00
showMonth($month, $year, $rs, $height);