Tryck inte ner mig i skorna och fixa en snygg kalender på en dag nu Mickecarlsson


Du kan köra i servermode med en fullskärmsbrowser.Electron, the app wrapper around MagicMirror², only supports the Raspberry Pi 2/3.


Kod: Markera allt
// Set your timezone!!
date_default_timezone_set('Europe/Stockholm');
// Get prev & next month
if (isset($_GET['ym'])) {
    $ym = $_GET['ym'];
} else {
    // This month
    $ym = date('Y-m');
}
// Check format
$timestamp = strtotime($ym . '-01');  // the first day of the month
if ($timestamp === false) {
    $ym = date('Y-m');
    $timestamp = strtotime($ym . '-01');
}
// Today (Format:2018-08-8)
$today = date('Y-m-j');
// Week number
$weeknum = date('W');
// Title (Format:August, 2018)
$title = date('F, Y', $timestamp);
// Create prev & next month link
$prev = date('Y-m', strtotime('-1 month', $timestamp));
$next = date('Y-m', strtotime('+1 month', $timestamp));
// Number of days in the month
$day_count = date('t', $timestamp);
// 1:Mon 2:Tue 3: Wed ... 7:Sun
$str = date('N', $timestamp);
// Array for calendar
$weeks = [];
$week = '';
// Add empty cell(s)
$week .= str_repeat('<td></td>', $str - 1);
for ($day = 1; $day <= $day_count; $day++, $str++) {
    $date = $ym . '-' . $day;
    if ($today == $date) {
        $week .= '<td class="today">';
    } else {
        $week .= '<td>';
    }
    $week .= $day . '</td>';
    // Sunday OR last day of the month
    if ($str % 7 == 0 || $day == $day_count) {
        // last day of the month
        if ($day == $day_count && $str % 7 != 0) {
            // Add empty cell(s)
            $week .= str_repeat('<td></td>', 7 - $str % 7);
        }
        $weeks[] = '<tr>' . $week . '</tr>';
        $week = '';
    }
}
?>
<!DOCTYPE html>
<html lang="en">
<head>    
    <meta charset="utf-8">
    <title>index</title>
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css" integrity="sha384-GJzZqFGwb1QTTN6wy59ffF1BuGJpLSa9DkKMp0DgiMDm4iYMj70gZWKYbI706tWS" crossorigin="anonymous">
    <link href="https://fonts.googleapis.com/css?family=Montserrat" rel="stylesheet">
    <style>
        .container {
            font-family: 'Montserrat', sans-serif;
            margin: 60px auto;
        }
        .list-inline {
            text-align: center;
            margin-bottom: 20px;
        }
        .title {
            font-weight: bold;
            font-size: 26px;
        }
        th {
            text-align: center;
        }
        td {
            height: 120px;
            width: 100px;
        }
        th:nth-of-type(6), td:nth-of-type(6) {
            color: blue;
        }
        th:nth-of-type(7), td:nth-of-type(7) {
            color: red;
        }
        .today {
            background-color: DarkGray;
        }
        div img.center {
            margin:o auto;
        }
    </style>
</head>
<body>
    <div class="container">
        <ul class="list-inline">
            <li class="list-inline-item"><a href="?ym=<?= $prev; ?>" class="btn btn-link">< prev</a></li>
            <li class="list-inline-item"><span class="title"><?= $title; ?></span></li>
            <li class="list-inline-item"><a href="?ym=<?= $next; ?>" class="btn btn-link">next ></a></li>
        </ul>
        <p class="text-right"><a href="index.php">Today</a></p>
	    <table class="table table-bordered">
            <thead>
                <tr>
                    <th>MÅN</th>
                    <th>TIS</th>
                    <th>ONS</th>
                    <th>TORS</th>
                    <th>FRE</th>
                    <th>LÖR</th>
                    <th>SÖN</th>
                </tr>
            </thead>
            <tbody>
                <?php
                    foreach ($weeks as $week) {
                        echo $week;
                    }
                ?>
            </tbody>
        </table>
    </div>
</body>
</html>Kod: Markera allt
<tr>
<td>...</td>
...
</tr>Kod: Markera allt
$weeks[] = '<tr><td>'.$weeknum.'</td>' . $week . '</tr>';Kod: Markera allt
$weeks[] = '<tr data-week="'.$weeknum.'">' . $week . '</tr>';Kod: Markera allt
<!DOCTYPE html>
<html lang="en">
<head>    
    <meta charset="utf-8">
    <title>index</title>
	<script src="https://code.jquery.com/jquery-3.3.1.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous"></script>
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css" integrity="sha384-GJzZqFGwb1QTTN6wy59ffF1BuGJpLSa9DkKMp0DgiMDm4iYMj70gZWKYbI706tWS" crossorigin="anonymous">
    <link href="https://fonts.googleapis.com/css?family=Montserrat" rel="stylesheet">
    <style>
        .container {
            font-family: 'Montserrat', sans-serif;
            margin: 60px auto;
        }
        .list-inline {
            text-align: center;
            margin-bottom: 20px;
        }
        .title {
            font-weight: bold;
            font-size: 26px;
        }
        th {
            text-align: center;
        }
        td {
            height: 120px;
            width: 100px;
        }
        th:nth-of-type(6), td:nth-of-type(6) {
            color: blue;
        }
        th:nth-of-type(7), td:nth-of-type(7) {
            color: red;
        }
        .today {
            background-color: DarkGray;
        }
        div img.center {
            margin:o auto;
        }
    </style>
	<script type="text/javascript">
	$(function(){
		$("tbody tr").each(function(){
			var wni = document.createElement("span");
			$(wni).append($(this).data("week"));
			$(wni).addClass("week-number-indicator");
			$(this).children().first().append(wni);
		});
	});
	</script>
</head>
<body>
    <div class="container">
        <ul class="list-inline">
            <li class="list-inline-item"><a href="?ym=<?= $prev; ?>" class="btn btn-link">< prev</a></li>
            <li class="list-inline-item"><span class="title"><?= $title; ?></span></li>
            <li class="list-inline-item"><a href="?ym=<?= $next; ?>" class="btn btn-link">next ></a></li>
        </ul>
        <p class="text-right"><a href="index.php">Today</a></p>
        <table class="table table-bordered">
            <thead>
                <tr>
                    <th>MÅN</th>
                    <th>TIS</th>
                    <th>ONS</th>
                    <th>TORS</th>
                    <th>FRE</th>
                    <th>LÖR</th>
                    <th>SÖN</th>
                </tr>
            </thead>
            <tbody>
                <tr data-week="1">
					<td>MÅN</td>
                    <td>TIS</td>
                    <td>ONS</td>
                    <td>TOR</td>
                    <td>FRE</td>
                    <td>LÖR</td>
                    <td>SÖN</td>
				</tr>
                <tr data-week="2">
					<td>MÅN</td>
                    <td>TIS</td>
                    <td>ONS</td>
                    <td>TOR</td>
                    <td>FRE</td>
                    <td>LÖR</td>
                    <td>SÖN</td>
				</tr>
            </tbody>
        </table>
    </div>
</body>
</html>Nja. Du kan ju ändra rad 37/39 (din kod) så att du petar in aktuellt datum som data-attribut på tdn.Det kommer ju inte bara vara veckonummer utan måste klura ut ett sätt att "adressera/namnge" varje ruta men det går knappast med nuvarande sätt att skapa tabellen va?