Welcome Guest, Not a member yet? Register   Sign In
Why am I getting these notices? I haven't before. Undefined offset / index for a custom calendar class.
#1

[eluser]Kinsbane[/eluser]
Hi folks,

Recently my work bought a new webserver with the latest LAMP setup. Our current server is PHP4, and this one is PHP 5.2.x. Not sure if this is related or not, but I was hoping I could get some troubleshooting assistance so my log files with CodeIgniter don't fill up with thousands of PHP Notice Errors.

So, here's the stuff that grabs the events for the current month:
Code:
//***** INSIDE Events controller
function calendar($month = '', $year = '')
    {
        //load the calendar library
        $this->load->library('DCCalendar');
        
        if(!$month) $month = date("n");
        if(!$year) $year = date("Y");
        $nextyear = $lastyear = $year;

        $nextmonth = $month + 1;
        if($nextmonth > 12) {
            $nextmonth -= 12;
            $nextyear ++;
        }
        $lastmonth = $month - 1;
        if($lastmonth <= 0) {
            $lastmonth += 12;
            $lastyear --;
        }
        $month_start = mktime(0,0,0,$month,1,$year,1);
        $month_end = mktime(0,0,0,$month+1,1,$year,1);
        $this->dccalendar->set_cal_url($this->config->item('base_url')."events/calendar/$lastmonth/$lastyear", $this->config->item('base_url')."calendar/$nextmonth/$nextyear");
                //get events for the month from the database
        $calevents = $this->DC->getEvents($month, $year);
        foreach($calevents->result_array() as $row)
        {
            
            if($row['event_date'] > $month_start and $row['event_date'] < $month_end) {
                //send the current event's data to the add_event function so the object can make a list of this month's events for sorting
                $this->dccalendar->add_event($row['event_title'], $row['event_date'], $row['event_length'], $this->config->item('base_url')."events/event/{$row['event_id']}", $row['event_status'], $row['event_id']);
            }
        }
        $data['page']['page_title'] = 'MRV Events Calendar &mdash; '.$month.'/'.$year;
        //the library returns an HTML string, which is displayed with the
                // display() function - we're just passing it the current month/year we're looking at
        $data['calbody'] = $this->dccalendar->display(mktime(0,0,0,$month,1,$year));
                //this displays a color key index to match events with their colors in the calendar view
        $data['calbody'] .= $this->dccalendar->display_colors();
        $this->load->view('general/start_page', $data);
        $this->load->view('general/menu_primary');
        $this->load->view('general/menu_secondary');
        $this->load->view('events/calendar_view', $data);
        $this->load->view('general/end_page');
    }

I have uploaded the CI Library I have here: http://www.kinsbane.net/temp/ci-class.dccalendar.txt

Was hoping someone could take a look and help me figure out why I'm getting a whole bunch of these Undefined offset errors. Here's a sample of the final array that the class works with. The $array[$date][$x][0] is the link to the event in the calendar, [1] is its current status, [2] is the name of the event, and [3] is the color assigned to the event in the calendar. Funnily enough, the undefined offset errors are because of the timestamps being used as indexes but I guess they get seen as offsets?
Code:
Array
(
    [1235894400] => Array
        (
            [0] => Array
                (
                    [0] => /events/event/1183
                    [1] => on schedule
                    [2] => CITA 2009 Showcase
                    [3] => #ad2323
                )
        )
)
Array
(
    [1235894400] => Array
        (
            [0] => Array
                (
                    [0] => events/event/1183
                    [1] => on schedule
                    [2] => CITA 2009 Showcase
                    [3] => #ad2323
                )
        )
    [1235980800] => Array
        (
            [0] => Array
                (
                    [0] => events/event/1183
                    [1] => on schedule
                    [2] => CITA 2009 Showcase
                    [3] => #ad2323
                )

            [1] => Array
                (
                    [0] => events/event/1163
                    [1] => on schedule
                    [2] => Comptel Spring 2009
                    [3] => #2a4bd7
                )
        )
    [1236067200] => Array
        (
            [1] => Array
                (
                    [0] => events/event/1163
                    [1] => on schedule
                    [2] => Comptel Spring 2009
                    [3] => #2a4bd7
                )
        )
    [1236153600] => Array
        (
            [1] => Array
                (
                    [0] => events/event/1163
                    [1] => on schedule
                    [2] => Comptel Spring 2009
                    [3] => #2a4bd7
                )
        )
)
Array
(
    [1235894400] => Array
        (
            [0] => Array
                (
                    [0] => events/event/1183
                    [1] => on schedule
                    [2] => CITA 2009 Showcase
                    [3] => #ad2323
                )
        )
    [1235980800] => Array
        (
            [0] => Array
                (
                    [0] => events/event/1183
                    [1] => on schedule
                    [2] => CITA 2009 Showcase
                    [3] => #ad2323
                )

            [1] => Array
                (
                    [0] => events/event/1163
                    [1] => on schedule
                    [2] => Comptel Spring 2009
                    [3] => #2a4bd7
                )
        )
)

Here's a sample of what it looks like:
http://www.kinsbane.net/temp/calendar-sample.jpg
#2

[eluser]Kinsbane[/eluser]
A pre-emptive big "THANK YOU!" to whoever can help out.
#3

[eluser]TheFuzzy0ne[/eluser]
http://www.kinsbane.net/temp/calendar-sample.php = page not found. It would really help to know what line number is causing the error, as well as where that line is in your code.
#4

[eluser]xwero[/eluser]
in the array you copied here i see some indexes start with 1
Code:
[1236153600] => Array
        (
            [1] => Array
                (
                    [0] => events/event/1163
                    [1] => on schedule
                    [2] => Comptel Spring 2009
                    [3] => #2a4bd7
                )
        )
#5

[eluser]TheFuzzy0ne[/eluser]
Well spotted, xwero!
#6

[eluser]Kinsbane[/eluser]
[quote author="TheFuzzy0ne" date="1237245815"]http://www.kinsbane.net/temp/calendar-sample.php = page not found. It would really help to know what line number is causing the error, as well as where that line is in your code.[/quote]

Sorry about that, I changed the link, it should be calendar-sample.jpg!

The actual errors I'm getting are as follows:
Code:
A PHP Error was encountered

Severity: Notice

Message: Undefined offset: 1236240000

Filename: libraries/DCCalendar.php

Line Number: 169
A PHP Error was encountered

Severity: Notice

Message: Undefined offset: 1236240000

Filename: libraries/DCCalendar.php

Line Number: 345
A PHP Error was encountered

Severity: Notice

Message: Undefined offset: 1236240000

Filename: libraries/DCCalendar.php

Line Number: 345
A PHP Error was encountered

Severity: Notice

Message: Undefined offset: 1236240000

Filename: libraries/DCCalendar.php

Line Number: 345
A PHP Error was encountered

Severity: Notice

Message: Undefined offset: 1236240000

Filename: libraries/DCCalendar.php

Line Number: 345
A PHP Error was encountered

Severity: Notice

Message: Undefined offset: 1236240000

Filename: libraries/DCCalendar.php

Line Number: 345
A PHP Error was encountered

Severity: Notice

Message: Undefined offset: 1236499200

Filename: libraries/DCCalendar.php

Line Number: 169
A PHP Error was encountered

Severity: Notice

Message: Undefined offset: 1236585600

Filename: libraries/DCCalendar.php

Line Number: 169
A PHP Error was encountered

Severity: Notice

Message: Undefined offset: 1236844800

Filename: libraries/DCCalendar.php

Line Number: 169
A PHP Error was encountered

Severity: Notice

Message: Undefined offset: 1236931200

Filename: libraries/DCCalendar.php

Line Number: 169
A PHP Error was encountered

Severity: Notice

Message: Undefined offset: 1237017600

Filename: libraries/DCCalendar.php

Line Number: 169
A PHP Error was encountered

Severity: Notice

Message: Undefined offset: 1236499200

Filename: libraries/DCCalendar.php

Line Number: 345
A PHP Error was encountered

Severity: Notice

Message: Undefined offset: 1236499200

Filename: libraries/DCCalendar.php

Line Number: 345
A PHP Error was encountered

Severity: Notice

Message: Undefined offset: 1236585600

Filename: libraries/DCCalendar.php

Line Number: 345
A PHP Error was encountered

Severity: Notice

Message: Undefined offset: 1236585600

Filename: libraries/DCCalendar.php

Line Number: 345
A PHP Error was encountered

Severity: Notice

Message: Undefined offset: 1236844800

Filename: libraries/DCCalendar.php

Line Number: 345
A PHP Error was encountered

Severity: Notice

Message: Undefined offset: 1236844800

Filename: libraries/DCCalendar.php

Line Number: 345
A PHP Error was encountered

Severity: Notice

Message: Undefined offset: 1236931200

Filename: libraries/DCCalendar.php

Line Number: 345
A PHP Error was encountered

Severity: Notice

Message: Undefined offset: 1236931200

Filename: libraries/DCCalendar.php

Line Number: 345
A PHP Error was encountered

Severity: Notice

Message: Undefined offset: 1237017600

Filename: libraries/DCCalendar.php

Line Number: 345
A PHP Error was encountered

Severity: Notice

Message: Undefined offset: 1237017600

Filename: libraries/DCCalendar.php

Line Number: 345
A PHP Error was encountered

Severity: Notice

Message: Undefined offset: 1237104000

Filename: libraries/DCCalendar.php

Line Number: 169
A PHP Error was encountered

Severity: Notice

Message: Undefined offset: 1237190400

Filename: libraries/DCCalendar.php

Line Number: 169
A PHP Error was encountered

Severity: Notice

Message: Undefined offset: 1237276800

Filename: libraries/DCCalendar.php

Line Number: 169
A PHP Error was encountered

Severity: Notice

Message: Undefined offset: 1237363200

Filename: libraries/DCCalendar.php

Line Number: 169
A PHP Error was encountered

Severity: Notice

Message: Undefined offset: 1237449600

Filename: libraries/DCCalendar.php

Line Number: 169
A PHP Error was encountered

Severity: Notice

Message: Undefined offset: 1237536000

Filename: libraries/DCCalendar.php

Line Number: 169
A PHP Error was encountered

Severity: Notice

Message: Undefined offset: 1237622400

Filename: libraries/DCCalendar.php

Line Number: 169
A PHP Error was encountered

Severity: Notice

Message: Undefined offset: 1237104000

Filename: libraries/DCCalendar.php

Line Number: 345
A PHP Error was encountered

Severity: Notice

Message: Undefined offset: 1237104000

Filename: libraries/DCCalendar.php

Line Number: 345
A PHP Error was encountered

Severity: Notice

Message: Undefined offset: 1237190400

Filename: libraries/DCCalendar.php

Line Number: 345
A PHP Error was encountered

Severity: Notice

Message: Undefined offset: 1237190400

Filename: libraries/DCCalendar.php

Line Number: 345
A PHP Error was encountered

Severity: Notice

Message: Undefined offset: 1237276800

Filename: libraries/DCCalendar.php

Line Number: 345
A PHP Error was encountered

Severity: Notice

Message: Undefined offset: 1237276800

Filename: libraries/DCCalendar.php

Line Number: 345
A PHP Error was encountered

Severity: Notice

Message: Undefined offset: 1237363200

Filename: libraries/DCCalendar.php

Line Number: 345
A PHP Error was encountered

Severity: Notice

Message: Undefined offset: 1237363200

Filename: libraries/DCCalendar.php

Line Number: 345
A PHP Error was encountered

Severity: Notice

Message: Undefined offset: 1237449600

Filename: libraries/DCCalendar.php

Line Number: 345
A PHP Error was encountered

Severity: Notice

Message: Undefined offset: 1237449600

Filename: libraries/DCCalendar.php

Line Number: 345
A PHP Error was encountered

Severity: Notice

Message: Undefined offset: 1237536000

Filename: libraries/DCCalendar.php

Line Number: 345
A PHP Error was encountered

Severity: Notice

Message: Undefined offset: 1237536000

Filename: libraries/DCCalendar.php

Line Number: 345
A PHP Error was encountered

Severity: Notice

etc.. etc...
#7

[eluser]Kinsbane[/eluser]
[quote author="xwero" date="1237246226"]in the array you copied here i see some indexes start with 1
Code:
[1236153600] => Array
        (
            [1] => Array
                (
                    [0] => events/event/1163
                    [1] => on schedule
                    [2] => Comptel Spring 2009
                    [3] => #2a4bd7
                )
        )
[/quote]

The reason for that is so when the HTML part is written, when it writes the events for the day inside the table cell, it keeps all the events on the same line. Say you have an event that is for the 5th and 6th, and another event for the 6th and 7th - when it gets to the 7th, the program knows that it needs to make space for the event that came before it, so in the days that come after one that had an event, it adjusts that particular index to make space. If you look at http://www.kinsbane.net/temp/calendar-sample.jpg you'll see.

The structure of the array is as follows:

$array[*date*] (each day of the month gets an array)
$array[*date*][*position*] (for each event in a day, this determines the events position, from top (0) to bottom ( > 0 ) within that day)
$array[*date*][*position*][*event-info*] (each event has an array of info to link to the event display page, the title, the event's status, and the unique color that event block link should be)
#8

[eluser]TheFuzzy0ne[/eluser]
I still need to know which line of your code is line number 345. Smile

EDIT: Err... scrap that. I forgot about the links you posted.
#9

[eluser]Kinsbane[/eluser]
At least, I think that's why it does that... I didn't write the original class, this was pretty much a copy/paste for use with CI since I couldn't get assistance with modifying CI's class to allow for events that span multiple days and keep the same formatting as the class that I have now.

I've always had trouble mapping out the data flow with this class, and now I'm literally at a brick wall because I just can't figure out why it would tell me these are undefined offsets NOW, as opposed to when this was used on a PHP4 system. Maybe just cause it wasn't reporting E_NOTICE??
#10

[eluser]pistolPete[/eluser]
Did you remove some comment at the beginning of the file?
I don't see any array in line 169 or 345...




Theme © iAndrew 2016 - Forum software by © MyBB