Avatar billede sanderstar Nybegynder
05. oktober 2005 - 13:01 Der er 8 kommentarer

PHP kalender

Jeg har lavet en hjemmeside hvor der er en kalender, den kan ses her : http://www.niceferie.com/reservation.php.

Jeg ville gerne have lavet en MySQL database og linke den til min PHP. Det der skal være muligt er at give dage en anden farve.. Meget enkelt hvis man kan, men det kan jeg ikke.. Håber der er nogle der kan hjælpe.

Vh Alexander
Avatar billede morten-vadskaer Praktikant
05. oktober 2005 - 13:54 #1
Skal du hjælpes på vej eller forventer du en færdig løsning??..
Har du googlet efter "calender php mysql"? -Kan du fortælle, hvad du har lavet og hvor du er gået i stå?

P.S. Hvis du vil have en færdig løsning, så skal der nok nogle grunker på bordet. -Det må der være råd til med de priser, hva'? ;o)
Avatar billede sanderstar Nybegynder
05. oktober 2005 - 14:03 #2
Jeg ville nok også betale mig fra det hvis jeg selv fik noget ud af det, men det er en tjeneste for en ven, og så så jeg det som en mulighed ti lat komme lidt i gang med php/Mysql

Ja, jeg har googlet en hel del.. og min PHP er da også fundet på denne måde.

Jeg havde håbet p åat nogle havde haft det samme projekt og lige kunne smide løsningen, men god hjælp til at nå målet ville også være værdsat..

Her er php'en...

<?php
    /******************************************************
    Calender 2.22
    Written by Erik Holman at 6 May 2004
    Started at 16:00 and ended at 17:00
   
    CHANGES by Daniele Russolillo, 18 May 2004
      + variables for CSS definition of week days
      + variables for easy translation of week days and months
      + infotitles for previous/following URLS on the calendar
      Personal homepage at http://daniele.nkoni.org  If you like
      the changes have a look at http://www.nkoni.org/ and
      pass it on to help 500 Ugandan AIDS Orphans.

    CHANGES by Erik Holman, 19 May 2004
      + variables for the language file.
      + added possibility to load language files
     
  CHANGES by Erik Holman, 17 June 2004
    + Added possibility to load events from MySQL database
   
  BUG SOLVED by Erik Holman, 24 June 2004
    - Instead of loading one event, all the events will be shown now.

    To look for from Erik Holman changes just FIND e-man within this script...
    To look for from darussol changes just FIND darussol within this script...

    ===================================
    This scripts prints  a calendar  into a table on the
    page.  You can set some variables to get a differend
    layout.

    Visit www.my-php.tk for more free PHP scripts.
    ******************************************************/

    /////////////////////////////////////////////
    //Declare some variables
    //
    $calendar_script          = "calendar2.php"; //The location of this script
    $calendar_language        = "uk";      //The extension of the calendar language file.

    $content_background_color = "#ddd8c8";  //Background color of the column
    $content_font_color      = "#000000";  //The font color
    $content_font_size        = 10;          //Font-size in pixels
    $content_font_style      = "normal";    //Set to italic or normal
    $content_font_weight      = "normal";    //Set to bold or normal

    $today_background_color  = "693d1f";  //Background color of the column
    $today_font_color        = "white";  //The font color
    $today_font_size          = 10;          //Font-size in pixels
    $today_font_style        = "normal";    //Set to italic or normal
    $today_font_weight        = "bold";      //Set to bold or normal

    $event_background_color  = "#DDDDDD";  //Background color of the column
    $event_background_color2  = "#EEEEEE";  //Background color of the 2nd column (event popup)
    $event_font_color        = "#000000";  //The font color
    $event_font_size          = 10;          //Font-size in pixels
    $event_font_style        = "normal";    //Set to italic or normal
    $event_font_weight        = "bold";      //Set to bold or normal
  $event_popup_width        = "250";      //Width  of the popup for the events
  $event_popup_height      = "350";      //Height of the popup for the events
   
    $head_background_color    = "#693d1f";  //Background color of the column
    $head_font_color          = "white";  //The font color
    $head_font_size          = 11;          //Font-size in pixels
    $head_font_style          = "normal";    //Set to italic or normal
    $head_font_weight        = "bold";      //Set to bold or normal
   
    //darussol: CSS OPTIONS FOR WEEK DAYS
    $days_head_background_color = "#693d1f";  //Background color of the column
    $days_head_font_color      = "white";  //The font color
    $days_head_font_size        = 11;          //Font-size in pixels
    $days_head_font_style      = "normal";    //Set to italic or normal
    $days_head_font_weight      = "bold";      //Set to bold or normal
   
    $table_border            = 0;          //The border of the table
    $table_cellspacing        = 1;          //Cellspacing of the table
    $table_cellpadding        = 2;          //Cellpadding of the table
    $table_width              = '';          //Table width in pixels or %'s
    $table_height            = '';          //Table height in pixels or %'s
   
    $head_link_color          = "white";    //The color of the link for previous/next month
   
    $font_family = "Verdana";
   
    /* 17 June 2004 : Check readme.txt for MySQL code for the database table */

    $events_from_database    = false;        //Set to true if you want to retrieve events
    $database                = "database";  //Name of the database within the event_table
  $server                  = "localhost"; //Name of the server
  $username                = "username";  //MySQL username
  $password                = "********";  //MySQL password
  $event_table              = "calendar_events"; //Name of the calendar_events
    //
    /////////////////////////////////////////////
   
    /////////////////////////////////////////////
    //Load the language into usable variables
    //

    //darussol: TRANSLATION (18 May 2004)
    //        : Fill in the names of the days/months in variables
    //e-man  : LOAD TRANSLATION FILE INTO VARIABLES (from darussol)(19 May 2004)
    //        : Put the days/months names from language file into a array   

    $language_file  = "calendar." . $calendar_language;        //Language file into variable
    $fd            = fopen( $language_file, "r" );            //Open the language file
    $fd            = fread( $fd, filesize( $language_file ) ); //Read the opened file
    $language_array = explode( "\n" , $fd );                    //Put file info into array

    $dayname  = array_slice($language_array,0,7); //The names of the days

    $monthname = array_slice($language_array,7);  //The rest of the language file are the monthnames
    //
    /////////////////////////////////////////////
   
   
    /////////////////////////////////////////////
    //Use the date to build up the calendar. From the Query_string or the current date
    //   
    if( isset( $_GET['date'] ) )
        list($month,$year) = explode("-",$_GET['date']);
    else
    {
        $month = date("m");
        $year  = date("Y");
    }
    //
    /////////////////////////////////////////////

    $date_string = mktime(0,0,0,$month,1,$year); //The date string we need for some info... saves space ^_^

    $day_start = date("w",$date_string);  //The number of the 1st day of the week

   

    /////////////////////////////////////////////
    //Filter the current $_GET['date'] from the QUERY_STRING
    //
    $QUERY_STRING = ereg_replace("&date=".$month."-".$year,"",$_SERVER['QUERY_STRING']);
    //
    /////////////////////////////////////////////
   

    /////////////////////////////////////////////
    //Calculate the previous/next month/year
    //
    if( $month < 12 )
    {
        $next_month = $month+1;
        $next_date = $next_month."-".$year;
    }
    else
    {
        $next_year = $year+1;
        $next_date = "1-".$next_year;
        $next_month = 1;
    }
    if( $month > 1 )
    {
        $previous_month = $month-1;
        $next_month    = $month+1;
        $previous_date = $previous_month."-".$year;
    }
    else
    {
        $previous_year = $year-1;
        $previous_date = "12-".$previous_year;
        $previous_month = 12;
    }
    //
    /////////////////////////////////////////////

    // darussol: DEFINITION OF THETRANSLATED MONTH+YEAR TO BE USED IN THE TABLE AND INFO-TITLES (18 May 2004)
    // e-man  : USING THE VALUES OF THE PREVIOUS AND NEXT MONTH FOR THE TITLE DAY (19 May 2004);
    $table_caption_prev = $monthname[$previous_month-1] . " " . $year; // previous
    $table_caption      = $monthname[date("n",$date_string)-1] . " " . $year; // current
  if ($next_month == 13){
    $next_month = 1;
    $year++;
  }
    $table_caption_foll = $monthname[$next_month-1] . " " . $year;  // following
   
    /////////////////////////////////////////////
    //Print the calendar css code
    //
  echo "
        <style type=\"text/css\">
            a.cal_head
            {
                color: " . $head_link_color . ";
            }
            a.cal_head:hover
            {
                text-decoration: none;
            }
            .cal_head
            {
                background-color: " . $head_background_color . ";
                color:            " . $head_font_color . ";
                font-family:      " . $font_family . ";
                font-size:        " . $head_font_size . ";
                font-weight:      " . $head_font_weight . ";
                font-style:      " . $head_font_style . ";
            }
            .cal_days /*darussol*/
            {
                background-color: " . $days_head_background_color . ";
                color:            " . $days_head_font_color . ";
                font-family:      " . $font_family . ";
                font-size:        " . $days_head_font_size . ";
                font-weight:      " . $days_head_font_weight . ";
                font-style:      " . $days_head_font_style . ";
            }
            .cal_content
            {
                background-color: " . $content_background_color . ";
                color:            " . $content_font_color . ";
                font-family:      " . $font_family . ";
                font-size:        " . $content_font_size . ";
                font-weight:      " . $content_font_weight . ";
                font-style:      " . $content_font_style . ";
            }
            .cal_today
            {
                background-color: " . $today_background_color . ";
                color:            " . $today_font_color . ";
                font-family:      " . $font_family . ";
                font-size:        " . $today_font_size . ";
                font-weight:      " . $today_font_weight . ";
                font-style:      " . $today_font_style . ";
            }
            .cal_event, a.cal_event /* e-man 17-06-04 */
            {
                background-color: " . $event_background_color . ";
                color:            " . $event_font_color . ";
                font-family:      " . $font_family . ";
                font-size:        " . $event_font_size . ";
                font-weight:      " . $event_font_weight . ";
                font-style:      " . $event_font_style . ";
            }
        </style>
  ";
    //
    /////////////////////////////////////////////
   

    /////////////////////////////////////////////
    //show events in popup?
    //
    if (isset ($_GET['show_event'])){
    list ($year, $month, $day) = explode ("-", $_GET['event_date']);
    $query = "
      SELECT *
      FROM " . $event_table . "
      WHERE EventYear  = '" . $year . "'
      AND  EventMonth = '" . $month . "'
      AND  EventDay  = '" . $day . "'
      ORDER BY EventTime ASC
    ";

    /* connect to the database */
    $database_connection = mysql_connect ($server, $username, $password);
    mysql_select_db ($database, $database_connection);
    $result = mysql_query ($query) or die(mysql_error());

    /* initize the variabele color_alternated (boolean) */
    $color_alternated = false;

    /* header of the table */
    echo "<table width=\"100%\" border=\"" . $table_border . "\" cellpadding=\"" . $table_cellpadding . "\" cellspacing=\"" . $table_cellspacing . "\">";

    $date_string = mktime(0,0,0,$month,$day,$year);
    $month = sprintf("%01d",$month);

    echo "<tr><td align=\"center\" class=\"cal_head\" colspan=\"2\">".$day." " . $monthname[$month] . " ".$year."</td></tr>";

    /* loop through the results via a mysql_fetch_assoc () */
    while ($record = mysql_fetch_assoc ($result)){
      if ($color_alternated){
        $color_alternated = false;
        $background_color_row = $event_background_color;
      }
      else{
        $color_alternated = true;
        $background_color_row = $event_background_color2;
      }
      echo "<tr class=\"cal_event\">
              <td style=\"background-color:".$background_color_row."\" width=\"1\">" . $record['EventTime'] . "</td>
              <td style=\"background-color:".$background_color_row."\">" . nl2br($record['Event']) . "</td>
            </tr>";
    }
    /* close the table */
    echo "</table>";

    /* bring an exit so the script will terminate*/
    exit;
    }
    //
    /////////////////////////////////////////////
   
    /////////////////////////////////////////////
    //Print the calendar table header
    //
    echo "
        <script language=\"javascript\">
      function open_event(date_stamp){
        window.open(\"" . $calendar_script . "?show_event=true&event_date=\" + date_stamp, \"calendar_popup\",\"height=" . $event_popup_height . ",width=".$event_popup_width."\");
      }
        </script>
        <table border=\"" . $table_border . "\" cellpadding=\"" . $table_cellpadding . "\" cellspacing=\"" . $table_cellspacing . "\" style=\"height:" . $table_height . "\" width=\"" . $table_width . "\">
            <tr>
                <td align=\"center\" class=\"cal_head\"><a class=\"cal_head\" href=\"" . $_SERVER['PHP_SELF'] . "?" . $QUERY_STRING . "&amp;date=" .
                $previous_date . "\" title=\"" . $table_caption_prev . "\">&laquo;</a></td>
                <td align=\"center\" class=\"cal_head\" colspan=\"5\">" . $table_caption . "</td>
                <td align=\"center\" class=\"cal_head\"><a class=\"cal_head\" href=\"" . $_SERVER['PHP_SELF'] . "?" . $QUERY_STRING . "&amp;date=" .
                $next_date . "\" title=\"" . $table_caption_foll . "\">&raquo;</a></td>
            </tr>
            <tr>
                <td class=\"cal_days\">".$dayname[0]."</td>
                <td class=\"cal_days\">".$dayname[1]."</td>
                <td class=\"cal_days\">".$dayname[2]."</td>
                <td class=\"cal_days\">".$dayname[3]."</td>
                <td class=\"cal_days\">".$dayname[4]."</td>
                <td class=\"cal_days\">".$dayname[5]."</td>
                <td class=\"cal_days\">".$dayname[6]."</td>
            </tr><tr>
            ";
    //
    /////////////////////////////////////////////
   
    /////////////////////////////////////////////
    //The empty columns before the 1st day of the week
    //
    for( $i = 0 ; $i < $day_start; $i++ )
    {
        echo "<td class=\"cal_content\">&nbsp;</td>";
    }
    //
    /////////////////////////////////////////////
   
    $current_position = $day_start; //The current (column) position of the current day from the loop
   
    $total_days_in_month = date("t",$date_string); //The total days in the month for the end of the loop

    /////////////////////////////////////////////
    //Retrieve events for the current month + year
    //e-man : added 07 June 04
  if ($events_from_database)
  {
    $database_connection = mysql_connect ($server, $username, $password);
    mysql_select_db ($database, $database_connection);
    $result = mysql_query("
      SELECT *
      FROM " . $event_table . "
      WHERE
        EventYear = '" . $year . "'
      AND
        EventMonth = '" . $month . "'
    ");
    while ($record = mysql_fetch_assoc($result)){
      $event[$record['EventDay']] = $record;
    }
  }
    //
    /////////////////////////////////////////////

    /////////////////////////////////////////////
    //Loop all the days from the month
    //
    for( $i = 1; $i <= $total_days_in_month ; $i++)
    {
        $class = "cal_content";
       
        if( $i == date("j") && $month == date("n") && $year == date("Y") )
            $class = "cal_today";
       
        $current_position++;

    /* is there any event on this day? Yes, create a link. No clear the (previous) string */
        $link_start = "";
        $link_end  = "";


    /* if there is an event do */
        if( isset($event[$i]) )
    {
      $link_start = "<a href=\"java script:;\" class=\"cal_event\" onclick=\"java script: open_event('".$year."-".$month."-".$i."');\">";
      $link_end  = "</a>";
      $class      = "cal_event";
    }

    /* for the event filter */
    /* e-man : added 07 June 04 */
    $date_stamp = $year."-".$month."-".sprintf( "%02d",$i);
   
        echo "<td align=\"center\" class=\"" . $class . "\">" . $link_start . $i . $link_end . "</td>";
        if( $current_position == 7 )
        {
            echo "</tr><tr>\n";
            $current_position = 0;
        }
    }
    //
    /////////////////////////////////////////////
   
    $end_day = 7-$current_position; //There are
   
    /////////////////////////////////////////////
    //Fill the last columns
    //   
    for( $i = 0 ; $i < $end_day ; $i++ )
        echo "<td class=\"cal_content\"></td>\n";
    //
    /////////////////////////////////////////////
   
    echo "</tr></table>";  // Close the table
?>
Avatar billede morten-vadskaer Praktikant
05. oktober 2005 - 14:19 #3
Har du lavet tabellen, hvor reservationerne ligger i?

Har du set denne linje:
17 June 2004 : Check readme.txt for MySQL code for the database table ??
Der skal du nok lede efter "guldet".
Avatar billede sanderstar Nybegynder
05. oktober 2005 - 14:33 #4
Ja den har jeg set, men mit problem er at jeg ingen erfaring har i MySQL,

det der står i text filen er :

  CREATE TABLE calendar_events (
    EventId bigint(20) NOT NULL auto_increment,
    EventYear int(4) NOT NULL default '0',
    EventMonth int(2) NOT NULL default '0',
    EventDay int(2) NOT NULL default '0',
    EventTime time NOT NULL default '00:00:00',
    Event text NOT NULL,
    PRIMARY KEY  (EventId)
  ) TYPE=MyISAM;

Men hvordan??

Jeg har indstalleret phpmyadmin, men kan ikke se hvor jeg kan sætte ovenstående ind..
Avatar billede morten-vadskaer Praktikant
05. oktober 2005 - 14:43 #5
I phpmyadmin opretter du en tabel, der hedder calender_events og så fyrer du de nævnte antal felter af.

Prøv evt. at læse WebCafe.dks artikler om SQL, så er du klædt godt på:
http://www.webcafe.dk/artikler/sql/
Avatar billede sanderstar Nybegynder
05. oktober 2005 - 15:38 #6
So far so good.. Men hvordan kalder jeg den så over min php?? Lad os sige jeg vil have de datoer der er ført ind i tabellen røde..
Avatar billede sanderstar Nybegynder
07. oktober 2005 - 09:37 #7
Anyone??
Avatar billede sanderstar Nybegynder
14. oktober 2005 - 10:05 #8
Ok jeg har selv klaret det sidste, men havde du ikke lige guidet mig havde jeg ikke løst det.. Tak.. Smid et svar
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