Avatar billede haniball Nybegynder
30. november 2001 - 12:28 Der er 4 kommentarer og
1 løsning

problem med kallender

Hejsa all
jeg har disse funktioner, som venligst er udleveret af codebase, fra hans site http://www.codebase.dk/test/statistik.php
meen problemet er at jeg fatter simpelthend ikke hvordam jeg kalder funktionerne jeg har prøvet på alle mulige måder meen intet hjælper
jeg ville gerne have det stillet op på en måde alla den han selv bruger nederst på denne site, bare den måde at liste dagende på
er det plzz en der kan hjælpe med dette
filen med funktionerne ser sådan her ud

<?
//
// $Id: dato.php,v 1.00 2001/06/09 14:13:39 bf Exp $
//
//
// Janus Hansen <janus@codebase.dk>
// Created on: <09-June-2001 13:50:24 bf>
//
// This source file is part of codebase publish, publishing software.
// Copyright (C) 1999-2001 codebase systems as
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, US
//

// dato funktioner .......
function GetTheDay($dato,$style){
if (strlen($dato)==7) $dato=$dato.\"0\";
  $dayof = substr($dato, 6, 2);
  $monthof = substr($dato, 4, 2);
  $yearof = substr($dato, 0, 4);
  $dateof=DayCounter($dato,0);
  $countday=$dateof;
  while ($dateof<-7) { $dateof=$dateof+7; }
  while ($dateof>6)  { $dateof=$dateof-7; }
  if((($dateof== -7)&&($yearof<2001)) || (($dateof==1)||($dateof==01))) { if ($style==0) $day=$countday; if ($style==1) $day=\"Mandag \"; if ($style==2) $day=1; }
  if((($dateof==-6)&&($yearof<2001)) || (($dateof==2)||($dateof==02))) { if ($style==0) $day=$countday; if ($style==1) $day=\"Tirsdag \";if ($style==2) $day=2; }
  if((($dateof==-5)&&($yearof<2001)) || (($dateof==3)||($dateof==03))) { if ($style==0) $day=$countday; if ($style==1) $day=\"Onsdag \"; if ($style==2) $day=3; }
  if((($dateof==-4)&&($yearof<2001)) || (($dateof==4)||($dateof==04))) { if ($style==0) $day=$countday; if ($style==1) $day=\"Torsdag \";if ($style==2) $day=4; }
  if((($dateof==-3)&&($yearof<2001)) || (($dateof==5)||($dateof==05))) { if ($style==0) $day=$countday; if ($style==1) $day=\"Fredag \"; if ($style==2) $day=5; }
  if((($dateof==-2)&&($yearof<2001)) || (($dateof==6)||($dateof==06))) { if ($style==0) $day=$countday; if ($style==1) $day=\"Lørdag \"; if ($style==2) $day=6; }
  if((($dateof==-1)&&($yearof<2001)) || (($dateof==0)||($dateof==00))) { if ($style==0) $day=$countday; if ($style==1) $day=\"Søndag \"; if ($style==2) $day=7; }
  $skud=SkudAar($yearof,0);
  $monthtot=DayCounter($dato,1);
  return \"\".$day;
}

function DayCounter($dato,$style){
  $dayof = substr($dato, 6, 2);
  $monthof = substr($dato, 4, 2);
  $yearof = substr($dato, 0, 4);
  if ($dato){
    if ($monthof >=1) { $daytot=$daytot+31; $themonnum=31;$themonnumdown=SkudAar($yearof,0)+306; }                  //JAN
    if ($monthof >=2) { $daytot=$daytot+SkudAar($yearof,0);$themonnum=SkudAar($yearof,0);$themonnumdown=306; }    //FEB
    if ($monthof >=3) { $daytot=$daytot+31; $themonnum=31; $themonnumdown=275;}                                        //MAR
    if ($monthof >=4) { $daytot=$daytot+30; $themonnum=30; $themonnumdown=245;}                                        //APR
    if ($monthof >=5) { $daytot=$daytot+31; $themonnum=31; $themonnumdown=214;}                                        //MAJ
    if ($monthof >=6) { $daytot=$daytot+30; $themonnum=30; $themonnumdown=184;}                                        //JUN
    if ($monthof >=7) { $daytot=$daytot+31; $themonnum=31; $themonnumdown=153;}                                        //JUL
    if ($monthof >=8) { $daytot=$daytot+31; $themonnum=31; $themonnumdown=122;}                                        //AUG
    if ($monthof >=9) { $daytot=$daytot+30; $themonnum=30; $themonnumdown=92; }                                        //SEP
    if ($monthof >=10){ $daytot=$daytot+31; $themonnum=31; $themonnumdown=61; }                                        //OKT
    if ($monthof >=11){ $daytot=$daytot+30; $themonnum=30; $themonnumdown=31; }                                        //NOV
    if ($monthof >=12){ $daytot=$daytot+31; $themonnum=31; $themonnumdown=0;  }                                        //DEC
    $datox=2001;
    $rulyear=$yearof;
    if ($rulyear<$datox) {                                                                                                        // Fra den 31.12.2000 og tilbage i tiden
      while ($rulyear<$datox) {
        if (SkudAar($rulyear,0)==29) {$line=$line+1; $skud=$skud+1; }
        $aar=$aar+1;
        if (!$aarm) $aarm=-1; else $aarm--;
        $yearsdaytotal=(337+(SkudAar($rulyear,0)));                                                        // summen 365 eller 366 (337+[28 eller 29]]
        $yx=$yx+$yearsdaytotal*-1;                   
        $aartotdif=$aartotdif+$yearsdaytotal;
        $rulyear=$rulyear+1;
      }
      $yearsdaytotal=$yearsdaytotal*-1;
      $go=($aartotdif*-1)+(337+(SkudAar($yearof,0))-$themonnum-$themonnumdown+$dayof-1);
    }
    if ($yearof>=$datox) {                                                                                                        // Fra den 01.01.2001 og frem i tiden
      while ($yearof>$datox) {                                           
        if (SkudAar($datox,0)==29) {$line=$line+1; $skud=$skud+1; }
        $aar=$aar+1; 
        if (!$aarm) $aarm=1; else $aarm++;
        $yearsdaytotal=(337+(SkudAar($datox,0)));                                                            // summen 365 eller 366 (337+[28 eller 29]]
        $yx=$yx+$yearsdaytotal;               
        $aartotdif=$aartotdif+$yearsdaytotal;
        $datox=$datox+1; 
      }
      $go=$daytot-$themonnum+$dayof+$aartotdif;
    }
    if($style==0) { return \"\".$go; }
    if($style==1) { return \"\".$daytot; } 
    if($style==2) { return \"\".$themonnumdown; }
    if($style==3) { return \"\".$themonnum; }
    if($style==10){ return \"\".$aarm; }
    if($style==11){ return \"\".$yearsdaytotal; }
    if($style==12){ return \"\".$yx; }
  }       
}     

function GetTotalWeek($dato,$style) {
if (strlen($dato)>4) {
  $dayof = substr($dato, 6, 2);
  $monthof = substr($dato, 4, 2);
  $yearof = substr($dato, 0, 4);
  $firstday=\"$yearof$monthof$dayof\";
  $skud=SkudAar($yearof,1);
}
else if (strlen($dato)==4){
  $firstday=$dato.\"0101\";
  $skud=SkudAar($dato,1);
}
$daynum=GetTheDay($firstday,2);
IF (($daynum==4)||(($daynum+$skud)==4)) { 
  if ($style==0) $week=53;
  if ($style==1)$week=53;
  if ($style==2)$week=1;
}
else {
  if ($style==0) $week=1;
  if ($style==1) $week=52;
  if ($style==2) $week=0;
}
return \"\".$week;
}

function GetTheWeek($dato,$week,$antal,$look) {
  if (strlen($antal)!=1) {
    if ($antal==\"Mandag\")  $antal=1;
    if ($antal==\"Tirsdag\") $antal=2;
    if ($antal==\"Onsdag\")  $antal=3;
    if ($antal==\"Torsdag\") $antal=4;
    if ($antal==\"Fredag\")  $antal=5;
    if ($antal==\"Lørdag\")  $antal=6; 
    if ($antal==\"Søndag\")  $antal=7;
}

  if (strlen($dato)==8) {
    $dayof = substr($dato, 6, 2);
    $monthof = substr($dato, 4, 2);
    $yearof = substr($dato, 0, 4);
    $y=$yearof;
  }
  $d=1; 
  $m=1;
  if (strlen($dato)!=8) { $y=$dato;}
  $ylast=$y-1;
  $maxweek=GetTotalWeek($y,1);
  $storemax=$maxweek;
  $maxweeklast=GetTotalWeek($ylast,1);
  if (strlen($d)==1) $d=\"0\".$d;
  if (strlen($m)==1) $m=\"0\".$m;
  $startdag=GetTheDay($y.$m.$d,2);
  while ($foo<$maxweek) { 
    if ($maxweek==$uge) $uge0;
    $foo++;
    if ($foo==1){                                                                                                                          // fin gamle dage i uge 1   
      if ($startdag<=4) $uge=0; else  $uge=$maxweeklast-1;
      $y=$y-1;
      $m=12;
      $d=31-$startdag+1;
      if ($storemax!=53) $maxweek=$maxweek+1;
    }
    $uge++;
    if(($uge==53)&&($storemax!=53)&&($maxweeklast!=53)) { $uge=1;  }
    while ($goo<7) {
      if (($goo%7==0)||(!$goo))  {
        $t++;
        if (($t==2)&&($uge!=2)) { $uge=1; }
      }
      $goo++;
      $alldays=NumDaysInMonth ($y.$m);
      if ($d>=$alldays) {
        $d=0;
        if ($m==12) {$m=1;$y++;} else $m++;
      }
      $d++;
      if (strlen($d)==1) $d=\"0\".$d;
      if (strlen($m)==1) $m=\"0\".$m;   
      if (($look==0)&&($week==$uge)&&($antal==$goo)&&($gotit!=1)){ $gotit=1; $thisweek=\"$d.$m.$y\"; }
      if (($look==1)&&($week==$uge)&&($antal==$goo)&&($gotit!=1)){ $gotit=1; $thisweek=\"$y$m$d\"; }     
      if (($d == $dayof)&&($m==$monthof)&&($y==$yearof)&&($gotit!=1)){ $gotit=1; $thisweek=\"$uge\"; }
    }
    $goo=0;
  }
  return \"\".$thisweek;
} 

function NiceDay ($dato,$look) {
  if ($look==1) {   
    $dayof = substr($dato, 6, 2);
    $monthof = substr($dato, 4, 2);
    $yearof = substr($dato, 0, 4);
    return \"\".$dayof.\".\".$monthof.\".\".$yearof;
  }
  if ($look==0) {   
    $dayof = substr($dato, 6, 2);
    $monthof = substr($dato, 4, 2);
    $yearof = substr($dato, 0, 4);
    return \"\".$yearof.$monthof.$dayof;
  }
}

function SkudAar($dato){
  $yearof = substr($dato, 0, 4);   
  if ((($yearof%4==0)&&($yearof%100!=0))||($yearof%400==0)) { $numfeb=29;  }
  else { $numfeb=28; }
  return \"\".$numfeb;
}

function NumDaysInMonth ($dato) {
if (strlen($dato)==5) $dato=\"0\".$dato;
$monthof = substr($dato, 4, 2);
$yearof = substr($dato, 0, 4);
$monthoffeb=$monthof;
  if ($monthoffeb==1) { $thenum=31; }                                                                                                          //JAN
  if ($monthoffeb==2) { $thenum=SkudAar($yearof,0); }                                                                                            //FEB
  if ($monthoffeb==3) { $thenum=31; }                                                                                                          //MAR
  if ($monthoffeb==4) { $thenum=30; }                                                                                                          //APR
  if ($monthoffeb==5) { $thenum=31; }                                                                                                          //MAJ
  if ($monthoffeb==6) { $thenum=30; }                                                                                                          //JUN
  if ($monthoffeb==7) { $thenum=31; }                                                                                                          //JUL
  if ($monthoffeb==8) { $thenum=31; }                                                                                                          //AUG
  if ($monthoffeb==9) { $thenum=30; }                                                                                                          //SEP
  if ($monthoffeb==10){ $thenum=31; }                                                                                                          //OKT
  if ($monthoffeb==11){ $thenum=30; }                                                                                                          //NOV
  if ($monthoffeb==12){ $thenum=31; }                                                                                                          //DEC
return \"\".$thenum;
}


function NextDate ($dato,$goto,$action,$look) {   

$dayof = substr($dato, 6, 2);
$monthof = substr($dato, 4, 2);
$yearof = substr($dato, 0, 4);
if ($action==0){
  if ($dayof-$goto>=1) {                                                                                                                                                                                                                                                     
    $dayof=$dayof-$goto;                                                                                                                                                                                                                                                                                                                   
    if (strlen($dayof)==1) $dayof=\"0\".$dayof;
  }                                                                                                                                                                                                                                                                                                                                         
  else {
    if ($monthof-1<1) { $monthof=13; $yearof--; }
    $monminus=$monthof-1;
    if (strlen($monminus)==1) $monminus=\"0\".$monminus;
    $mon_year=\"$yearof\".$monminus;
    $dayof=(NumDaysInMonth($mon_year))-$goto+$dayof; $monthof--;
    if (strlen($monthof)==1) $monthof=\"0\".$monthof;
    if (strlen($dayof)==1) $dayof=\"0\".$dayof;                                                                                                                                                                                                                                                                                               
  }                                                                                                                                                                                                                                                                                                                                         
}
if ($action==1){
  if ($dayof+$goto<= NumDaysInMonth($yearof.$monthof)) {                                                                                                                                                                                                                                                                                   
    $dayof=$dayof+$goto;                                                                                                                                                                                                                                                                                                                   
    if (strlen($dayof)==1) $dayof=\"0\".$dayof;                                                                                                                                                                                                                                                                                               
  }                                                                                                                                                                                                                                                                                                                                         
  else {                                                                                                                                                                                                                                                                                                                                   
    $mon_year=$yearof.$monthof;                                                                                                                                                                                                                                                                                                             
    $dayof=((NumDaysInMonth($mon_year)-$dayof)*-1)+$goto; $monthof++;                                                                                                                                                                                                                                                                       
    if (strlen($dayof)==1) $dayof=\"0\".$dayof;                                                                                                                                                                                                                                                                                               
  }                                                                                                                                                                                                                                                                                                                                         
  if ($monthof>12)  {                                                                                                                                                                                                                                                                                                                       
    $monthof=1; $yearof++;                                                                                                                                                                                                                                                                                                                 
    if (strlen($monthof)==1) $monthof=\"0\".$monthof;                                                                                                                                                                                                                                                                                         
  }
}                                                                                                                                                                                                                                                                                                                                         
if ($look==0) $result=$yearof.$monthof.$dayof;                                                                                                                                                                                                                                                                                           
if ($look==1) $result=$dayof.\".\".$monthof.\".\".$yearof;                                                                                                                                                                                                                                                                                   
return \"\".$result;                                                                                                                                                                                                                                                                                                                       
}
function GetPaaskeDay($dato){ 
  // datoformat: eks. 2001
  $y =$dato;
  $goldnum=$y%19 + 1;
   
  if ($y <= 1582) {            //Juliansk kalender
    $extra = (5*$y)/4;
    $epact = (11*$goldnum-4)%30 + 1;
  } 
  else {                //Gregoriansk kalender
    $century =$y/100 + 1;
    $gregcorr = ((3*$century)/4) - 12;  // X
    $gregcorr=floor($gregcorr);
    $clavcorr = ((8*$century + 5)/25) - 5;
    $extra = ((5*$y)/4) - $gregcorr - 10;
    $epact = (11*$goldnum + 20 + $clavcorr - $gregcorr)%30;
    if (($epact == 24)||($epact == 25)&&($goldnum > 11)) ++$epact;
}
$d = 44 - $epact; 
if ($d < 21) $d += 30;
$d = $d + 7 - ($extra+$d)%7;
$m = 3;
if ($d > 31) { 
  $m = 4; 
  $d -= 31;
}
$paaske=\"$d $m $y\";
return \"\".$paaske;
}

?>
Avatar billede wizprod.com Nybegynder
30. november 2001 - 13:52 #1
Jeg tror det kun er codebase der kan finde hoved og ryvang i denne kode. Den er rimeligt slamkodet, nogle af tingene kunne have forkertet drastisk. Og nej, jeg kan heller ikke lige se sammenhængende, men jeg tror du selv skal ud og være kreativ! Måske lade være med at starte på et sådant niveau.
Avatar billede haniball Nybegynder
30. november 2001 - 15:07 #2
tjaa men det hjælper mig ikke så meget lige nu (desvære)
jeg har selv prøvet at lave det, meen det ikke engang lignede det som det skulle være, såå derfor prøvede jeg denne, meen kan simpelthend ikke gennemskuge den :-((
Avatar billede aslan Nybegynder
30. november 2001 - 18:19 #3
Det her er den fedeste kalender der lige er til at smide ind på dit hp og det hele bliver forklaret skridt for skridt .Jeg har personligt lært meget fra denne :)

http://www.melonfire.com/community/columns/trog/article.php3?id=47
Avatar billede haniball Nybegynder
01. december 2001 - 16:32 #4
aslan
det var nu godt nok ikke det jeg søgte meeen det hjalp mig da igang med at bikse noget sammen selv, og har sikkert også lært mig en del om det pis sååå takker for tippet :-))
Avatar billede aslan Nybegynder
02. december 2001 - 00:57 #5
np m8:) takker for point!
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