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

[eluser]tim1965[/eluser]
Hi

I need to include a multi-user availability calendar into my website (with Mysql backend). For the sake of speed. I am thinking of going down the commercial route (i.e. buying one). I would use the CI version, but i thinl there would be a lot of effort involved in trying to get what i want, in the timeframe available to me. I had tried to integrate an open source calendar, but had a lot of issues with it as it made extensive use of $_GET. So my question is has anybody succesfully integrated a third party calendar product, if so which one, guesstimate of the effort involved, and pain level.
From the forums, there seems to have been some usage of easy PHP calendar in the past, but its not clear whether these were succesfully integrated.
Reaaly would appreciate peoples comments, and thanks in advance for any responses.
#2

[eluser]TheFuzzy0ne[/eluser]
If you're looking for a JavaScript calendar, I'd highly recommend [url="http://www.meanfreepath.com/javascript_calendar/"]Epoch[/url]. I'ts a fantastic script, and quite easy to set up and customise.

If you're looking for a PHP calandar, I would suggest [url="www.cascade.org.uk/software/php/calendar/"]this one[/url] (which was the first result in a Google search for "php calendar class").

EDIT: Whoops! Fixed missing URL! I do apologise.
#3

[eluser]jdfwarrior[/eluser]
Calendars are actually REALLY easy to make. Don't have code as a full fledged script that you could just integrate in, but could give you some code to pick through and modify if you'd like.

edit: Depending on what your looking for that is. From the way I read it, you looking for a calendar to display on a page or multiple that pulls info from a database and displays the events?
#4

[eluser]tim1965[/eluser]
Thefuzzyone, thanks for your input, i will look at the options you highlighted now.

jdfwarrior, i'm sure they are, my problem as always is time. So i am really wanting to make sure i dont waste any more as i burnt about a week trying to get what i thought would be a relatively painless set of open source scripts that i had seen working before. Unfortunately it was vesy painful, given the way they were written. So i wanted sure i didnt spend another chunk of time on something only to have give up as i got into the bowels of it.

Essentially all i am trying to do is display an availability calendar per user by year on each users page, with data pulled from a db. There would also be a simple controlled admin section to allow the user to specify start and end date, and an option to set booked or pending reservation, with a default of free.

I would appreciate any example code you are happy to let me have. Thank you both for your help.
#5

[eluser]jdfwarrior[/eluser]
Are you looking for a small side calendar or a large fluid calendar?
#6

[eluser]tim1965[/eluser]
Large fluid as i want to display a years worth of data using colours for the state of each day i.e. green for free, yellow for reserved.
Thanks
#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%;
}
#8

[eluser]tim1965[/eluser]
jdfwarrior

Many thanks for the code example.

I have some questions if i may and i apologise in advance if i am being very stupid ( am still on a learning curve with PHP and CI).

So i have loaded up the code and calling it as per your example.When i pass a test example of $month = 2 and $YEAR = 2006, i get a row of repeating numbers from 1-26 and then 1-26 again.

So my questions are

Should i be using this in conjunction with the CI calendar class to prep the data in advance ?
Should i be passing it as per the numeric values as per the CI class ?
Do i need to pass it the number of days per month as per the CI calendar class (i cant see where in the script these are set to 26 as per above issue ).

I realise this is a very basic script (example) for displaying the data, but i am looking at the CI library and the number of functions and then comparing it back to this script, there is obviously a significant difference in the functionality. So waroking on your basis that this is really easy, i'm obviously missing something completely obvious (apologies again if am being stupid).

I am still playing with this, but just thought i would post this on the off chance you are in my time zone. Once again i appreciate any time you can give to this.
#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:
&lt;?
    $cal = new phpCalendar(2,2006); //or whatever month,year you want
    $code = $cal->getCal();
?&gt;

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:
&lt;?
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%;
}
#10

[eluser]tim1965[/eluser]
Hi

Loaded as requested.

The phpcalendar is blowing up with the mktime function error
Quote:
A non well formed numeric value encountered
Quote:

lines 111,112,121 for phpcalendar.

From pphp.net echo date("M-d-Y", mktime(0, 0, 0, 12, 32, 1997));
from script mktime(0,0,0, $this->current['month'], 1, $this->current['year']));
I tried adding an extra 0 but that didnt fix


and
Quote:
Fatal error: Call to undefined method phpCalendar:ConfusedhowCalendar() in C:\wamp\www\ci\system\application\views\calendar\test.php on line 16
Quote:




Theme © iAndrew 2016 - Forum software by © MyBB