Welcome Guest, Not a member yet? Register   Sign In
calendar advice
#7

[eluser]jdfwarrior[/eluser]
Very basic example obviously. Used by including the phpCalendar.php file and creating a new instance of it by:

Code:
<?
   $calendar = new phpCalendar();
   $calendar->showCalendar();
?>

Pass numeric value of the month and year into the constructor to display different months. From your explanation, all you would have to do is query the database and get a list of available, free, etc dates, and then in the phpCalendar.php, where it displays the day, add an extra class depending on the availability on that day.

phpCalendar.php
Code:
<?
class phpCalendar
{
    private $month, $year, $display, $weeks;
    private $current, $prev, $next;
    
    /*
    *****************************************************
    Name: getNextMonth
    Function: This function will determine what the month following
        the specified month will be, and store information
        about this month including: name, abbreviated name, etc.
    *****************************************************
    */
    private function getNextMonth()
    {
        if ($this->current['month']==12)
            $this->next['month']=1;
            $this->next['year']=$this->current['year']+1;
        if ($this->current['month']!=12)
            $this->next['month']=$this->current['month']+1;
            $this->next['year']=$this->current['year'];
    }
    
    /*
    *****************************************************
    Name: getPrevMonth
    Function: This function will determine what the month preceding
        the specified month will be, and store information
        about this month including: name, abbreviated name, etc.
    *****************************************************
    */
    private function getPrevMonth()
    {
        if ($this->current['month']==1)
            $this->prev['month']=12;
            $this->prev['year']=$this->current['year']-1;    
        if ($this->current['month']!=1)
            $this->prev['month']=$this->current['month']-1;
            $this->prev['year']=$this->current['year'];
    }

    /*
    *****************************************************
    Name: showCalendar
    Function: This function generate and display the specified calendar
    *****************************************************
    */
    public function showCalendar()
    {
        
        echo "<div id='phpCalendar'>";
            
            $date=1;
            $initpadding = @date('w', mktime(0,0,0, $this->current['month'], 1, $this->current['year']));
                
            do
            {
                echo "<div class='week'>";
                
                for ($i=0; $i<5; $i++)
                {
                    if ($initpadding > 0 || $date > $this->current['m_last_day']) {
                        echo "<div class='day'>&nbsp;";
                        echo "</div>";
                        $initpadding--;
                    }
                    else
                    {
                        echo "<div class='day'>" .$date++. "</div>";
                    }
                }
                
                $date+=2;
                
                echo "</div>";
            }
            while($date < $this->current['m_last_day']);
            
        echo "</div>";
    }
    
    /*
    *****************************************************
    Name: __construct
    Function: Class constructor.  Used to initialize values required
        to generate the calendar.
    *****************************************************
    */
    function __construct($month=null, $year=null)
    {
        //If month is not specified, set $month variable to the current month, otherwise, use the specified month
        $this->current['month'] = ($month ? $month : @date('n'));
        //If month is not specified, set $year variable to the current year, otherwise, use the specified year
        $this->current['year'] = ($year ? $year : @date('Y'));
        
        //If name is not default, query name in database and store information about the desired
        //calendar in appropriate variables.
        
        //Set variables of the full text and abbreviated version of the specified month
        $this->current['m_text'] = @date('F', mktime(0,0,0,$this->current['month'], 1, $this->current['year']));
        $this->current['m_abbr'] = @date('M', mktime(0,0,0,$this->current['month'], 1, $this->current['year']));
        //Set variable of what todays date is
        $this->current['m_date'] = @date('j');
        
        //Initialize variables for the previous and next month information
        $this->getNextMonth();
        $this->getPrevMonth();
        
        //Set variable of what the last day of the month is
        $this->current['m_last_day'] = @date('j', mktime(0,0,0, $this->next['month'], 0, $this->next['year']));
        
    }
}

Basic Css
Code:
#phpCalendar
{
    margin:0 auto;
}

#phpCalendar .week
{
    margin:0 auto;
    width:100%;
    height:100px;
}

#phpCalendar .day
{
    background:#ededed;
    float:left;
    height:100px;
    margin:1px;
    width:19.8%;
}


Messages In This Thread
calendar advice - by El Forum - 02-16-2009, 08:15 AM
calendar advice - by El Forum - 02-16-2009, 08:31 AM
calendar advice - by El Forum - 02-16-2009, 09:41 AM
calendar advice - by El Forum - 02-16-2009, 10:00 AM
calendar advice - by El Forum - 02-16-2009, 10:19 AM
calendar advice - by El Forum - 02-16-2009, 10:28 AM
calendar advice - by El Forum - 02-16-2009, 11:12 AM
calendar advice - by El Forum - 02-17-2009, 04:56 AM
calendar advice - by El Forum - 02-17-2009, 07:34 AM
calendar advice - by El Forum - 02-17-2009, 08:07 AM
calendar advice - by El Forum - 02-17-2009, 08:25 AM
calendar advice - by El Forum - 02-17-2009, 08:52 AM
calendar advice - by El Forum - 02-17-2009, 08:54 AM
calendar advice - by El Forum - 02-17-2009, 09:03 AM
calendar advice - by El Forum - 02-17-2009, 09:29 AM
calendar advice - by El Forum - 02-17-2009, 09:43 AM
calendar advice - by El Forum - 02-17-2009, 09:47 AM



Theme © iAndrew 2016 - Forum software by © MyBB