Avatar billede sabumnim Novice
20. januar 2009 - 22:16 Der er 11 kommentarer og
1 løsning

Kalender system, virker allerede

Hej xperter

Jeg har fundet et kalender system som virker fint og kan sættes op til at køre på en MySql DB, hvilket jeg lokalt har gjort.

Det virker fint og alt er peachy..... eller næsten.

Mit problem er at når jeg har lavet en entry i min DB som f.eks gælder den 10. feb, så går jeg ind på kalenderen i frontend og ser hvordan det spiller der.

Når jeg klikker på den pågældende dato (10. feb) så åbnes der et pop-up vindue hvor min entry står, men tabel headeren står der den 10. marts og ikke den 10. feb, som der skulle.

Kan simpelthen ikke finde ud af hvorfor den tæller forkert, og håber en af jer kan hjælpe mig lidt hurtigt.

Jeg kan sagtens smide noget kode hvis det er nødvendigt ellers smider jeg lige et download link i alle tilfælde.
Download her: http://www.my-php.tk/ >>>> Scripts >>>>> CalendarV2.0
og et virkende eksempel (dog uden DB tilknyttet):
http://www.pcdummy.nl/~myphp/script/example/6

//Carsten
Avatar billede expnet Seniormester
21. januar 2009 - 05:22 #1
vi mangler nu lidt kode og nogle af de fejl du for i dit system da jeg kan forstå at du har prøve at programmer en database tabel på systemet??

//rene
Avatar billede majbom Novice
21. januar 2009 - 07:01 #2
prøv at smid den kode hvor du henter og udskriver datoen på din frontend, det er vel der det ikke virker? det virker fint på backenden?
Avatar billede sabumnim Novice
21. januar 2009 - 12:11 #3
Hej begge

Jeg smider lige noget kode her og nede i koden har jeg sat nogle heftige markeringer hvor jeg tror der opstår et eller andet mismatch:

Kode (dette er al koden):
//
    $calendar_script          = "calendar2.php"; //The location of this script
    $calendar_language        = "uk";      //The extension of the calendar language file.

    $content_background_color = "#EEEEEE";  //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  = "white";  //Background color of the column
    $today_font_color        = "green";  //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    = "#DDDDDD";  //Background color of the column
    $head_font_color          = "green";  //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 = "#DDDDDD";  //Background color of the column
    $days_head_font_color      = "gray";  //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          = "green";    //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    = true;        //Set to true if you want to retrieve events
    $database                = "caltest";  //Name of the database within the event_table
  $server                  = "localhost"; //Name of the server
  $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>
  ";
    //
    /////////////////////////////////////////////
//HERFRA STARTER KODEN SOM LAVER POP-UP OG JEG TROR DET ER HERI DER LIGGER NOGET//

    /////////////////////////////////////////////
    //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
// HER LUKKES TABELLEN SÅ SOM ER AT FINDE I POP-UP VINDUET//

//Carsten
Avatar billede majbom Novice
21. januar 2009 - 12:51 #4
er det her den ikke skriver det korrekt:

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

?
Avatar billede sabumnim Novice
21. januar 2009 - 13:45 #5
Hej Splazz

Ja, det er netop der.

HTML koden her er sakset fra netop pop-up vinduet og det output der kommer er her fra den datoen den 11. marts, men der står følgende i headeren:
<tr>
<td class="cal_head" align="center" colspan="2">11 April 2009</td>
</tr>

//Carsten
Avatar billede majbom Novice
21. januar 2009 - 14:01 #6
echo "<tr><td align=\"center\" class=\"cal_head\" colspan=\"2\">".$day." " . $monthname[$month] . " ".$year."</td></tr>";

skal være:

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

da den starter ved nul i dit array, og januar er 1, februar 2 osv. - get it?
Avatar billede sabumnim Novice
22. januar 2009 - 14:55 #7
Hej Splazz

I get it, og tester i aften.

Har haft en syg søn de sidste to dage og har derfor ikke været ved min comp.

Men tester og vender tilbage :0)

//Carsten
Avatar billede majbom Novice
22. januar 2009 - 19:43 #8
helt i orden, kender det alt for godt selv :S

god bedring med ham :)
Avatar billede sabumnim Novice
22. januar 2009 - 19:57 #9
Hej igen Splazz

Har nu testet og det virker jo upåklageligt, så det er superduper nice :0)

Læg et svar, så kaster jeg nogle i din retning.

Og tusinde tak for hjælpen, det var kanon du gad at tage et kig på det.

//Carsten
Avatar billede majbom Novice
22. januar 2009 - 20:38 #10
super!

selv tak :)
Avatar billede sabumnim Novice
22. januar 2009 - 20:54 #11
Kanonas :0)

Er gået igang med at lave en admin del til kalenderen nu, så det gr8

//Carsten
Avatar billede sabumnim Novice
22. januar 2009 - 21:28 #12
For de der efterfølgende læser denne post, kommer her en omgang php kode til at inserte entries i kalenderen, som dog kun er testet lokalt så jeg vil ikke lægge hovedet på blokken og garantere at det virker uden på en webserver, men måske kan det hjælpe nogen alligevel.

KODE:
<?

if (isset($_POST["submit"])){

    echo "<span class=\"broed\">Nyheden er tilf&oslash;jet</span>";
    require_once "fil_forbind_til_mysql.php";

    $EventId = $_POST["EventId"];
    $EventYear = $_POST["EventYear"];
    $EventMonth = $_POST["EventMonth"];
    $EventDay = $_POST["EventDay"];
    $EventTime = $_POST["EventTime"];
    $Event = $_POST["Event"];
   
    if(!get_magic_quotes_gpc()){
    $EventYear = addslashes($EventYear);
    $EventMonth = addslashes($EventMonth);
    $EventDay = addslashes($EventDay);
    $EventTime = addslashes($EventTime);
    $Event= addslashes($Event);
   

    }

    mysql_query("INSERT INTO calendar_events(EventId, EventYear, EventMonth, EventDay, EventTime, Event)VALUES('$EventId','$EventYear','$EventMonth', '$EventDay', '$EventTime', '$Event')");
    } else {

    ?>
    <form method="post" action="<? echo $PHP_SELF; ?>">
    <table width="500" border="0" cellspacing="2" cellpadding="0">
    <tr>
        <td><span class="uberskrift">Event year:</span><br />
        <select name="EventYear">
            <option>V&aelig;lg &aring;r</option>
            <option>2009</option>
            <option>2010</option>
            <option>2011</option>
            <option>2012</option>
            <option>2013</option>
            <option>2014</option>
            <option>2015</option>
            <option>2016</option>
            <option>2017</option>
        </select>     
        </td>
    </tr>
    <tr>
        <td><span class="uberskrift">EventMonth:</span><br />
        <select name="EventMonth">
            <option>V&aelig;lg m&aring;ned</option>
            <option value="01" <?php if ($EventMonth == "01") {echo "selected";} ?>>Januar
            <option value="02" <?php if ($EventMonth == "02") {echo "selected";} ?>>Februar
            <option value="03" <?php if ($EventMonth == "03") {echo "selected";} ?>>Marts
            <option value="04" <?php if ($EventMonth == "04") {echo "selected";} ?>>April
            <option value="05" <?php if ($EventMonth == "05") {echo "selected";} ?>>Maj
            <option value="06" <?php if ($EventMonth == "06") {echo "selected";} ?>>Juni
            <option value="07" <?php if ($EventMonth == "07") {echo "selected";} ?>>Juli
            <option value="08" <?php if ($EventMonth == "08") {echo "selected";} ?>>August
            <option value="09" <?php if ($EventMonth == "09") {echo "selected";} ?>>September
            <option value="10" <?php if ($EventMonth == "10") {echo "selected";} ?>>Oktober
            <option value="11" <?php if ($EventMonth == "11") {echo "selected";} ?>>November
            <option value="12" <?php if ($EventMonth == "12") {echo "selected";} ?>>December
        </select>
      </td>
    </tr>
    <tr>
        <td><span class="uberskrift">EventDay:</span><br />
        <select name="EventDay">
            <option>V&aelig;lg dato</option>
            <option value="01" <?php if ($EventDay == "01") {echo "selected";} ?>>1
            <option value="02" <?php if ($EventDay == "02") {echo "selected";} ?>>2
            <option value="03" <?php if ($EventDay == "03") {echo "selected";} ?>>3
            <option value="04" <?php if ($EventDay == "04") {echo "selected";} ?>>4
            <option value="05" <?php if ($EventDay == "05") {echo "selected";} ?>>5
            <option value="06" <?php if ($EventDay == "06") {echo "selected";} ?>>6
            <option value="07" <?php if ($EventDay == "07") {echo "selected";} ?>>7
            <option value="08" <?php if ($EventDay == "08") {echo "selected";} ?>>8
            <option value="09" <?php if ($EventDay == "09") {echo "selected";} ?>>9
            <option <?php if ($EventDay == "10") {echo "selected";} ?>>10
            <option <?php if ($EventDay == "11") {echo "selected";} ?>>11
            <option <?php if ($EventDay == "12") {echo "selected";} ?>>12
            <option <?php if ($EventDay == "13") {echo "selected";} ?>>13
            <option <?php if ($EventDay == "14") {echo "selected";} ?>>14
            <option <?php if ($EventDay == "15") {echo "selected";} ?>>15
            <option <?php if ($EventDay == "16") {echo "selected";} ?>>16
            <option <?php if ($EventDay == "17") {echo "selected";} ?>>17
            <option <?php if ($EventDay == "18") {echo "selected";} ?>>18
            <option <?php if ($EventDay == "19") {echo "selected";} ?>>19
            <option <?php if ($EventDay == "20") {echo "selected";} ?>>20
            <option <?php if ($EventDay == "21") {echo "selected";} ?>>21
            <option <?php if ($EventDay == "22") {echo "selected";} ?>>22
            <option <?php if ($EventDay == "23") {echo "selected";} ?>>23
            <option <?php if ($EventDay == "24") {echo "selected";} ?>>24
            <option <?php if ($EventDay == "25") {echo "selected";} ?>>25
            <option <?php if ($EventDay == "26") {echo "selected";} ?>>26
            <option <?php if ($EventDay == "27") {echo "selected";} ?>>27
            <option <?php if ($EventDay == "28") {echo "selected";} ?>>28
            <option <?php if ($EventDay == "29") {echo "selected";} ?>>29
            <option <?php if ($EventDay == "30") {echo "selected";} ?>>30
            <option <?php if ($EventDay == "31") {echo "selected";} ?>>31
        </select>
      </td>
    </tr>
    <tr>
        <td><span class="uberskrift">EventTime: (format 00:00)</span><br />   
            <input type="text" name="EventTime" size="24" class="felt">
        </td>
    </tr>
    <tr>
        <td><span class="uberskrift">Event:</span><br />
        <textarea name="Event" rows="6" cols="40" class="felt"></textarea>
        </td>
    </tr>
    <tr>
        <td><input type="submit" name="submit" value="Skriv nyhed" class="button">&nbsp;<input type="reset" value="Ryd alt" class="button"></td>
    </tr>
</table>
</form>
<?
}
?>
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