Welcome Guest, Not a member yet? Register   Sign In
.ics, .ical export script
#1

[eluser]codepotato[/eluser]
Hi all,

First post! Woop!

I just wanted to add something that may have already been done in the community but i couldn't find anything, so here goes.

I've created a very basic (but working) script that exports data into an ics file format.

This is very basic, but should give you enough to get started. Feel free to message me if you need a hand.

Code:
class Ics_model extends Model {

    var $name   = '' // THIS WILL BE THE FILENAME;

    function Ics_model()
    {
        // Call the Model constructor
        parent::Model();
        
        $this->load->helper('file');
        $this->load->helper('date');
    }
    
    
    function create($name, $operator_id)
    {
    
        // get all incomplete reminders
        
        $data = $this->db->get_where()) // AT THIS POINT, GET THE DATA YOU WANT IN YOUR ICS;
        
        if($data->num_rows() > 0)
        {
            // data exists
            
            $ics =
'BEGIN:VCALENDAR
CALSCALE:GREGORIAN
X-WR-TIMEZONE;VALUE=TEXT:US/Pacific
METHOD:PUBLISH
PRODID:-//Codepotato //iCal 1.0//EN
X-WR-CALNAME;VALUE=TEXT:Example
VERSION:2.0';            
            
            foreach($data->result() as $row)
            {
                $datestring = "%Y%m%d";
                $date = mdate($datestring, $row->reminder);
                
                $ics .=
'
BEGIN:VEVENT
SEQUENCE:5
DTSTART;TZID=Europe/London:'.$date.'T120000 // THIS LINE DECLARES THE START TIME / DATE
SUMMARY:'.$row->task.' THIS LINE DECLARES THE TASK LABEL
DTEND;TZID=Europe/London:'.$date.'T121500 // THIS LINE DECLARES THE FINISH TIME / DATE
BEGIN:VALARM
TRIGGER;VALUE=DURATION:-P1D
ACTION:DISPLAY
DESCRIPTION:Event reminder
END:VALARM
END:VEVENT';
                
            }
            
            $ics .=
'
END:VCALENDAR';
            
        }
          

        if (!write_file('./ics/'.$name.'.ics', $ics)) // AT THIS PART, WRITE THE FILE TO THE SERVER
        {
             return('error');
        }
        else
        {
             return('success');
        }
    }
    
}


Messages In This Thread
.ics, .ical export script - by El Forum - 12-31-2009, 08:32 AM
.ics, .ical export script - by El Forum - 01-02-2010, 05:52 PM
.ics, .ical export script - by El Forum - 01-03-2010, 11:19 AM



Theme © iAndrew 2016 - Forum software by © MyBB