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

[eluser]jdfwarrior[/eluser]
I had updated a few things. I dont know why it wasnt displaying for you correctly, works perfect for me, but I made a few changes for you. With this code, load the class (via php include is how I was using it). For CI, this could be done in your controller of choice.

Then create the calendar by doing:
Code:
<?
    $cal = new phpCalendar(2,2006); //or whatever month,year you want
    $code = $cal->getCal();
?>

At that point the $code variable is all the html for the calendar. You can echo it directly from the controller, or pass it to the view to be displayed there. However you want to do it. You should not need the CI calendar class. You dont have to give it the number of days in the month. It figures all of that out using the php date function.

Here is the updated code:
phpCalendar
Code:
<?
class phpCalendar
{
    //Requires phpUser class
    //Requires phpCalendarEvent class

    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 getCal()
    {
        
        date_default_timezone_set('America/Chicago');
        
        $calendar = "<div id='phpCalendar'>";
            
            $date=1;
            $initpadding = date('w', mktime(0,0,0, $this->current['month'], 1, $this->current['year']));
                
            do
            {
                $calendar .= "<div class='week'>";
                
                for ($i=0; $i<5; $i++)
                {
                    if ($initpadding > 0 || $date > $this->current['m_last_day']) {
                        $calendar .= "<div class='day'>&nbsp;";
                        $calendar .= "</div>";
                        $initpadding--;
                    }
                    else
                    {
                        $calendar .= "<div class='day'>" .$date++. "</div>";
                    }
                }
                
                $date+=2;
                
                $calendar .= "</div>";
            }
            while($date < $this->current['m_last_day']);
            
        $calendar .= "</div>";
        
        return $calendar;
    }
    
    /*
    *****************************************************
    Name: __construct
    Function: Class constructor.  Used to initialize values required
        to generate the calendar.
    *****************************************************
    */
    function __construct($month=null, $year=null)
    {
    
        date_default_timezone_set('America/Chicago');
    
        //If month is not specified, set $month variable to the current month, otherwise, use the specified month
        $this->current['month'] = ($month ? $month : date('n e'));
        //If month is not specified, set $year variable to the current year, otherwise, use the specified year
        $this->current['year'] = ($year ? $year : date('Y e'));
        
        //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']));
        
    }
}

Css is still basic, you can tweak and change it however you see fit.
Code:
#phpCalendar
{
    border:1px solid #c4c4c4;
    margin:0 auto;
    padding:0;
    width:50%;
}

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

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


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