Jump to content

enormousrodent

New Members
  • Posts

    9
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

enormousrodent's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Honestly, it confuses the hell out of me. The Logic behind turning that into a calendar confuses me.. That is why i am asking for help..Only being honest...thanks for the links btw Here is the code that produces the array. <html> <head> <title></title> </head> <body> <?php function daysInMonths($time){ if(!$time) $time=time(); $month=strftime("%m",$time); $year=strftime("%Y",$time); return cal_days_in_month(CAL_GREGORIAN,$month,$year); } function renderCalendar($time){ if(!$time) $time=time(); //Get Month And Year $month=strftime("%m",$time); $year=strftime("%Y",$time); //Render Current Calendar $dayCount=cal_days_in_month(CAL_GREGORIAN,$month,$year); $calArray=array(); for($day=0;$day<$dayCount;$day++){ $tmNow=mktime(0,0,0,$month,$day+1,$year); $yearWeek=(int)strftime("%W",$tmNow); if($yearWeek>52) $yearWeek-=52; if(!is_array($calArray[$yearWeek])){ $calArray[$yearWeek]=array(); for($tday=0;$tday<7;$tday++){ $calArray[$yearWeek][$tday+1]=false; } } $dayInfo=array( "time" => $tmNow, "mday" => ($day+1), "wday" => (int)strftime("%w",$tmNow), "yday" => (int)strftime("%j",$tmNow) ); if(!$dayInfo['wday']) $dayInfo['wday']=7; $calArray[$yearWeek][$dayInfo['wday']]=$dayInfo; } $calInfo=array(-1=>array(),0=>array(),1=>array()); $calInfo[0]=mktime(0,0,0,$month,1,$year); //Get Next Month $nextmonth=$month+1; $nextyear=$year; if($nextmonth==13){ $nextyear++; $nextmonth-=12; } $calInfo[1]=mktime(0,0,0,$nextmonth,1,$nextyear); //Get Previous Month $prevmonth=$month-1; $prevyear=$year; if($nextmonth==0){ $prevyear--; $prevmonth+=12; } $calInfo[-1]=mktime(0,0,0,$prevmonth,1,$prevyear); //Return Calendar $cal=array('Calendar'=>$calArray,'Info'=>$calInfo); return $cal; } //----------------------------------------------------------------- ?> <pre><? print_r(renderCalendar(time())); ?> </pre> <? $Calendar = renderCalendar(time()); //Generate for current month $Months = $Calendar['Info']; $Calendar = $Calendar['Calendar']; $PreviousMonth = $Months[-1]; $CurrentMonth = $Months[0]; $NextMonth = $Months[1]; //These are the year weeks from 1-52 //that fit in the month of the calendar. $YearWeeks = array_keys($Calendar); //We parse the $Calendar array by $YearWeeks foreach($YearWeeks as $YearWeek){ $WeekDays = $Calendar[$YearWeek]; // And we further parse the $WeekDays for output foreach($WeekDays as $WeekDay){ $DayTimeStamp = $WeekDay['time']; $MonthDay = $WeekDay['mday']; $YearDay = $WeekDay['yday']; //Keep in mind on next line I loose the $WeekDay initial value //but I assigned all it's children to dedicated variable so who cares? $WeekDay = $WeekDay['wday']; //Here be dragons! Keep reading ... } } ?> </body> </html>
  2. basically, how do i turn that information into a calendar: so: S M T W T F S 1 2 3 4 5 6 7 8 9 10 11 12 13 14 etc
  3. im trying to find one that i can use to intergrate with a CMS system that i am trying to use. http://daytona.anyservers.com/~bastide/test.php This is a link to an array output, but i do not have the knowledge to turn these unix timestamps into a usable calander format. If you (or anyone) can make sense of it i would be very greatful. Thanks
  4. Hi Guys, Do you guys know somewhere where i can find a script which creates a Calendar which can be controled via a database, so if a date is "occupied" then the date will be marked at BOOKED. Rodent
  5. http://daytona.anyservers.com/~bastide/test.php This is a link to the array output! Thanks
  6. Hi there, I have been trying to use the code below (found on someone's blog) to create a calendar. What i have problems with is working out how to display the array in an actual calander layout. with the dates & days etc all lineing up. <html> <head> <title></title> </head> <body> <?php function daysInMonths($time){ if(!$time) $time=time(); $month=strftime("%m",$time); $year=strftime("%Y",$time); return cal_days_in_month(CAL_GREGORIAN,$month,$year); } function renderCalendar($time){ if(!$time) $time=time(); //Get Month And Year $month=strftime("%m",$time); $year=strftime("%Y",$time); //Render Current Calendar $dayCount=cal_days_in_month(CAL_GREGORIAN,$month,$year); $calArray=array(); for($day=0;$day<$dayCount;$day++){ $tmNow=mktime(0,0,0,$month,$day+1,$year); $yearWeek=(int)strftime("%W",$tmNow); if($yearWeek>52) $yearWeek-=52; if(!is_array($calArray[$yearWeek])){ $calArray[$yearWeek]=array(); for($tday=0;$tday<7;$tday++){ $calArray[$yearWeek][$tday+1]=false; } } $dayInfo=array( "time" => $tmNow, "mday" => ($day+1), "wday" => (int)strftime("%w",$tmNow), "yday" => (int)strftime("%j",$tmNow) ); if(!$dayInfo['wday']) $dayInfo['wday']=7; $calArray[$yearWeek][$dayInfo['wday']]=$dayInfo; } $calInfo=array(-1=>array(),0=>array(),1=>array()); $calInfo[0]=mktime(0,0,0,$month,1,$year); //Get Next Month $nextmonth=$month+1; $nextyear=$year; if($nextmonth==13){ $nextyear++; $nextmonth-=12; } $calInfo[1]=mktime(0,0,0,$nextmonth,1,$nextyear); //Get Previous Month $prevmonth=$month-1; $prevyear=$year; if($nextmonth==0){ $prevyear--; $prevmonth+=12; } $calInfo[-1]=mktime(0,0,0,$prevmonth,1,$prevyear); //Return Calendar $cal=array('Calendar'=>$calArray,'Info'=>$calInfo); return $cal; } //----------------------------------------------------------------- print_r(renderCalendar(time())); $Calendar = renderCalendar(time()); //Generate for current month $Months = $Calendar['Info']; $Calendar = $Calendar['Calendar']; $PreviousMonth = $Months[-1]; $CurrentMonth = $Months[0]; $NextMonth = $Months[1]; //These are the year weeks from 1-52 //that fit in the month of the calendar. $YearWeeks = array_keys($Calendar); //We parse the $Calendar array by $YearWeeks foreach($YearWeeks as $YearWeek){ $WeekDays = $Calendar[$YearWeek]; // And we further parse the $WeekDays for output foreach($WeekDays as $WeekDay){ $DayTimeStamp = $WeekDay['time']; $MonthDay = $WeekDay['mday']; $YearDay = $WeekDay['yday']; //Keep in mind on next line I loose the $WeekDay initial value //but I assigned all it's children to dedicated variable so who cares? $WeekDay = $WeekDay['wday']; //Here be dragons! Keep reading ... } } ?> </body> </html> If anyone could please help i would be very greatful Rodent
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.