Avatar billede vango6 Praktikant
10. september 2006 - 11:51 Der er 4 kommentarer og
1 løsning

En tekst under en enkelæ dato

Hej

Jeg har fundet denne kalender (coderdk)
http://php.coder.dk/cal.php
jeg kan ikke finde ud af at få skrevet fødselsdage ind så de vises rigtigt, håber at der er en der kan hjælpe mig

PÅ forhånd TAK!
Avatar billede coderdk Praktikant
10. september 2006 - 20:36 #1
Her er et eksempel på hvordan man kunne gøre:

<?php

    $HUSK = array(
            '20060910' => array( 'Guy Richtie\'s fødselsdag' )
            ,'20060921' => array( 'Husk fisk', 'Tæsk til lillebror' )
        );
    $FOEDSELSDAG = mktime( 0, 0, 0, 9, 10, 2006 ); // I dag

    setlocale( LC_TIME, 'da_DK' );

    $today = time();
    if ( !empty( $_GET['m'] ) && !empty( $_GET['y'] ) && is_numeric( $_GET['m'] ) && is_numeric( $_GET['y'] ) )
    {
        $today = mktime( 0, 0, 0, $_GET['m'], 1, $_GET['y'] );
    }

    $mname = ucfirst( strftime( '%B', $today ) );
    $thism = date( 'm', $today );
    $thisy = date( 'Y', $today );
    $startd = mktime( 0, 0, 0, $thism, 1, $thisy );
    $endd = mktime( 23, 59, 59, $thism + 1, 0, $thisy );
    $nodays = date( 'd', $endd );
    $startwd = strftime( '%u', $startd );
    $endwd = strftime( '%u', $endd );
    $startw = strftime( '%V', $startd );
    $endw = strftime( '%V', $endd );
    $startpad = ( $startwd == 1 ? 0 : $startwd - 1 );
    $realstart = mktime( 0, 0, 0, $thism, -$startpad + 1, $thisy );
    $startpadreal = date( 'd', $realstart );
    $endpad = ( $endwd == 7 ? 0 : 7 - $endwd );
    $realend = strtotime( '+' . $endpad . ' days', $endd );

    $lastm = date( 'm', strtotime( '-1 month', $today ) );
    $lastmy = date( 'Y', strtotime( '-1 month', $today ) );
    $nextm = date( 'm', strtotime( '+1 month', $today ) );
    $nextmy = date( 'Y', strtotime( '+1 month', $today ) );

    $days = array();
    $w = $startw;
    $n = 0;
    if ( $startpad > 0 )
    {
        for ( $i = $startpadreal; $i < $startpadreal + $startpad; $i++ )
        {
            $days[$w][] = $i;
            $n++;
        }
    }
    for ( $i = 1; $i <= $nodays; $i++ )
    {
        $n %= 7;
        if ( $n == 0 )
        {
            $w = strftime( '%V', mktime( 0, 0, 0, $thism, $i, $thisy ) );
        }
        $days[$w][] = $i;
        $n++;
    }
    if ( $endpad > 0 )
    {
        for ( $i = 1; $i <= $endpad; $i++ )
        {
            $days[$endw][] = $i;
        }
    }

?>
<html>
    <head>
        <title>Kalender for <?= $mname ?></title>
        <style>
            body {
                background-color: white;
                font-family: tahoma, verdana, arial, helveica;
                font-size: 11pt;
            }
            .mnav {
                background-color: #eeeeee;
                font-size: 14pt;
                text-align: center;
            }
            .hdr {
                text-align: center;
                font-size: 16pt;
            }
            th { background-color: #eeeeee; }
            .wkn {
                background-color: #eeeeee;
                text-align: center;
            }
            .notnow {
                background-color: #eeeeee;
                color: #888888;
            }
            .satd { background-color: #ddffdd; }
            .sund { background-color: #ffdddd; }
            .date { font-size: 9pt; }
        </style>
    </head>
    <body>
        <h1>Kalender for <?= $mname ?></h1>
        <table id="cal" width="760px" border="1" cellspacing="0" cellpadding="0">
            <tr>
                <td class='mnav'><a title="Forrige måned" href="<?= $_SERVER['PHP_SELF'] . '?y=' . $lastmy . '&amp;m=' . $lastm ?>">&laquo;</a></td>
                <td class="hdr" colspan="6"><?= $mname . ', ' . $thisy ?></td>
                <td class='mnav'><a title="Næste måned" href="<?= $_SERVER['PHP_SELF'] . '?y=' . $nextmy . '&amp;m=' . $nextm ?>">&raquo;</a></td>
            </tr>
            <tr>
                <th style="width: 50px">Uge</th>
                <th>Man</th>
                <th>Tir</th>
                <th>Ons</th>
                <th>Tor</th>
                <th>Fre</th>
                <th style="width: 75px">Lør</th>
                <th style="width: 75px">Søn</th>
            </tr>
<?php

    foreach ( $days as $wk => $dayar )
    {
        echo "<tr><td class=\"wkn\">$wk</td>";
        for ( $d = 0; $d < 7; $d++ )
        {
            $c = '';
            if ( $d == 5 )
            {
                $c .= ' satd';
            }
            elseif ( $d == 6 )
            {
                $c .= ' sund';
            }
            $tm = $thism;
            $ty = $thisy;
            if ( ( $wk == $startw && $dayar[$d] > 10 ) ||
                ( $wk == $endw && $dayar[$d] < 10 ) )
            {
                $c .= ' notnow';
                if ( $dayar[$d] > 10 )
                {
                    $tm = $lastm;
                }
                else
                {
                    $tm = $nextm;
                }
                if ( $thism == 1 && $dayar[$d] > 10 )
                {
                    $ty = $thisy - 1;
                }
                else if ( $thism == 12 && $dayar[$d] < 10 )
                {
                    $ty = $thisy + 1;
                }
            }
            $tstamp = mktime( 0, 0, 0, $tm, $dayar[$d], $ty );
            if ( $c != '' )
            {
                $c = ' class="' . $c . '"';
            }
            $td = sprintf( '%02d', $dayar[$d] );
            $typ = ( $d > 4 ? 'dwecnt' : 'dcnt' );
            $cb = '';
            printf( "<td$c><div class='%s'><div class='date'>%d%s</div>", $typ, $td, $cb );
            $thedate = date( 'Ymd', $tstamp );
            if ( array_key_exists( $thedate, $HUSK ) )
            {
                foreach ( $HUSK[$thedate] as $item )
                {
                    echo "$item<br>"
                }
            }
            else
            {
                echo "&nbsp;";
            }
            echo '</div></td>';
        }
        echo "</tr>\n";
    }
   
?>
        </table>
    </body>
</html>
Avatar billede coderdk Praktikant
10. september 2006 - 20:37 #2
$FOEDSELSDAG skal så ikke lige bruges ;P
Avatar billede vango6 Praktikant
11. september 2006 - 00:00 #3
Tusind tak!!
Hvordan er det lige du får dine point?
Avatar billede coderdk Praktikant
11. september 2006 - 00:24 #4
Jeg skal først svare :)
Avatar billede vango6 Praktikant
11. september 2006 - 17:07 #5
Super
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Vi tilbyder markedets bedste kurser inden for webudvikling

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester