/** * Import an iCal file into the database * @param array Course info * @return boolean True on success, false otherwise * @deprecated */ function agenda_import_ical($course_info, $file) { require_once api_get_path(LIBRARY_PATH) . 'fileUpload.lib.php'; $charset = api_get_system_encoding(); $filepath = api_get_path(SYS_ARCHIVE_PATH) . $file['name']; if (!@move_uploaded_file($file['tmp_name'], $filepath)) { error_log('Problem moving uploaded file: ' . $file['error'] . ' in ' . __FILE__ . ' line ' . __LINE__); return false; } require_once api_get_path(LIBRARY_PATH) . 'icalcreator/iCalcreator.class.php'; $ical = new vcalendar(); $ical->setConfig('directory', dirname($filepath)); $ical->setConfig('filename', basename($filepath)); $return = $ical->parse(); //we need to recover: summary, description, dtstart, dtend, organizer, attendee, location (=course name), /* $ve = $ical->getComponent(VEVENT); $ttitle = $ve->getProperty('summary'); $title = api_convert_encoding($ttitle,$charset,'UTF-8'); $tdesc = $ve->getProperty('description'); $desc = api_convert_encoding($tdesc,$charset,'UTF-8'); $start_date = $ve->getProperty('dtstart'); $start_date_string = $start_date['year'].'-'.$start_date['month'].'-'.$start_date['day'].' '.$start_date['hour'].':'.$start_date['min'].':'.$start_date['sec']; $ts = $ve->getProperty('dtend'); if ($ts) { $end_date_string = $ts['year'].'-'.$ts['month'].'-'.$ts['day'].' '.$ts['hour'].':'.$ts['min'].':'.$ts['sec']; } else { //Check duration if dtend does not exist $duration = $ve->getProperty('duration'); if ($duration) { $duration = $ve->getProperty('duration'); $duration_string = $duration['year'].'-'.$duration['month'].'-'.$duration['day'].' '.$duration['hour'].':'.$duration['min'].':'.$duration['sec']; $start_date_tms = mktime(intval($start_date['hour']), intval($start_date['min']), intval($start_date['sec']), intval($start_date['month']), intval($start_date['day']), intval($start_date['year'])); //$start_date_tms = mktime(($start_date['hour']), ($start_date['min']), ($start_date['sec']), ($start_date['month']), ($start_date['day']), ($start_date['year'])); //echo date('d-m-Y - h:i:s', $start_date_tms); $end_date_string = mktime(intval($start_date['hour']) +$duration['hour'], intval($start_date['min']) + $duration['min'], intval($start_date['sec']) + $duration['sec'], intval($start_date['month']) + $duration['month'], intval($start_date['day'])+$duration['day'], intval($start_date['year']) + $duration['year']); $end_date_string = date('Y-m-d H:i:s', $end_date_string); //echo date('d-m-Y - h:i:s', $end_date_string); } } //echo $start_date.' - '.$end_date; $organizer = $ve->getProperty('organizer'); $attendee = $ve->getProperty('attendee'); $course_name = $ve->getProperty('location'); //insert the event in our database $id = agenda_add_item($course_info,$title,$desc,$start_date_string,$end_date_string,$_POST['selectedform']); $repeat = $ve->getProperty('rrule'); if(is_array($repeat) && !empty($repeat['FREQ'])) { $trans = array('DAILY'=>'daily','WEEKLY'=>'weekly','MONTHLY'=>'monthlyByDate','YEARLY'=>'yearly'); $freq = $trans[$repeat['FREQ']]; $interval = $repeat['INTERVAL']; if(isset($repeat['UNTIL']) && is_array($repeat['UNTIL'])) { $until = mktime(23,59,59,$repeat['UNTIL']['month'],$repeat['UNTIL']['day'],$repeat['UNTIL']['year']); $res = agenda_add_repeat_item($course_info,$id,$freq,$until,$_POST['selectedform']); } */ $eventcount = 0; $message = array(); $agenda_obj = new Agenda(); while (true) { //we need to recover: summary, description, dtstart, dtend, organizer, attendee, location (=course name) $ve = $ical->getComponent('VEVENT', $eventcount); if (!$ve) { break; } $ttitle = $ve->getProperty('summary'); $title = api_convert_encoding($ttitle, $charset, 'UTF-8'); $tdesc = $ve->getProperty('description'); $desc = api_convert_encoding($tdesc, $charset, 'UTF-8'); $start_date = $ve->getProperty('dtstart', false, true); if (isset($start_date['params']['VALUE'])) { $start_date_value = $start_date['value']; if ($start_date['params']['VALUE'] == 'DATE') { $start_date_string = $start_date_value['year'] . '-' . $start_date_value['month'] . '-' . $start_date_value['day'] . ''; } else { $start_date_string = $start_date_value['year'] . '-' . $start_date_value['month'] . '-' . $start_date_value['day'] . ' ' . $start_date_value['hour'] . ':' . $start_date_value['min'] . ':' . $start_date_value['sec']; } } else { continue; } $ts = $ve->getProperty('dtend'); if ($ts) { $end_date = $ve->getProperty('dtend', false, true); if (isset($end_date['params']['VALUE'])) { $end_date_value = $end_date['value']; if ($end_date['params']['VALUE'] == 'DATE') { $end_date_string = $end_date_value['year'] . '-' . $end_date_value['month'] . '-' . $end_date_value['day'] . ''; } else { $end_date_string = $end_date_value['year'] . '-' . $end_date_value['month'] . '-' . $end_date_value['day'] . ' ' . $end_date_value['hour'] . ':' . $end_date_value['min'] . ':' . $end_date_value['sec']; } } else { //Default behaviour $end_date_string = $ts['year'] . '-' . $ts['month'] . '-' . $ts['day'] . ' ' . $ts['hour'] . ':' . $ts['min'] . ':' . $ts['sec']; } } else { //Check duration if dtend does not exist $duration = $ve->getProperty('duration'); if ($duration) { $duration = $ve->getProperty('duration'); $duration_string = $duration['year'] . '-' . $duration['month'] . '-' . $duration['day'] . ' ' . $duration['hour'] . ':' . $duration['min'] . ':' . $duration['sec']; $start_date_tms = mktime(intval($start_date['hour']), intval($start_date['min']), intval($start_date['sec']), intval($start_date['month']), intval($start_date['day']), intval($start_date['year'])); //$start_date_tms = mktime(($start_date['hour']), ($start_date['min']), ($start_date['sec']), ($start_date['month']), ($start_date['day']), ($start_date['year'])); //echo date('d-m-Y - h:i:s', $start_date_tms); $end_date_string = mktime(intval($start_date['hour']) + $duration['hour'], intval($start_date['min']) + $duration['min'], intval($start_date['sec']) + $duration['sec'], intval($start_date['month']) + $duration['month'], intval($start_date['day']) + $duration['day'], intval($start_date['year']) + $duration['year']); $end_date_string = api_get_utc_datetime($end_date_string); //echo date('d-m-Y - h:i:s', $end_date_string); } } //echo $start_date.' - '.$end_date; $organizer = $ve->getProperty('organizer'); $attendee = $ve->getProperty('attendee'); $course_name = $ve->getProperty('location'); //insert the event in our database $agenda_obj->type = 'course'; $all_day = 'false'; if ($start_date_string == $end_date_string) { $all_day = 'true'; } $date = new DateTime($start_date_string); $date->add(new DateInterval('P1D')); if ($start_date_string == $date->format('Y-m-d h:i:s')) { $all_day = 'true'; } $id = $agenda_obj->add_event($start_date_string, $end_date_string, $all_day, $title, $desc, array('everyone')); $message[] = " {$title} - " . $start_date_string . " - " . $end_date_string; $repeat = $ve->getProperty('rrule'); if (is_array($repeat) && !empty($repeat['FREQ'])) { $trans = array('DAILY' => 'daily', 'WEEKLY' => 'weekly', 'MONTHLY' => 'monthlyByDate', 'YEARLY' => 'yearly'); $freq = $trans[$repeat['FREQ']]; $interval = $repeat['INTERVAL']; if (isset($repeat['UNTIL']) && is_array($repeat['UNTIL'])) { $until = mktime(23, 59, 59, $repeat['UNTIL']['month'], $repeat['UNTIL']['day'], $repeat['UNTIL']['year']); $res = agenda_add_repeat_item($course_info, $id, $freq, $until, $attendee); } //TODO: deal with count if (!empty($repeat['COUNT'])) { $count = $repeat['COUNT']; $res = agenda_add_repeat_item($course_info, $id, $freq, $count, $attendee); } } $eventcount++; } if (!empty($message)) { $message = implode('<br /> ', $message); } return $message; }
/** * Import an iCal file into the database * @param array Course info * @return boolean True on success, false otherwise */ function agenda_import_ical($course_info, $file) { require_once api_get_path(LIBRARY_PATH) . 'fileUpload.lib.php'; $charset = api_get_system_encoding(); $filepath = api_get_path(SYS_ARCHIVE_PATH) . $file['name']; if (!@move_uploaded_file($file['tmp_name'], $filepath)) { error_log('Problem moving uploaded file: ' . $file['error'] . ' in ' . __FILE__ . ' line ' . __LINE__); return false; } require_once api_get_path(LIBRARY_PATH) . 'icalcreator/iCalcreator.class.php'; $ical = new vcalendar(); $ical->setConfig('directory', dirname($filepath)); $ical->setConfig('filename', basename($filepath)); $ical->parse(); //we need to recover: summary, description, dtstart, dtend, organizer, attendee, location (=course name), // rrule $ve = $ical->getComponent(VEVENT); //print_r($ve); $ttitle = $ve->getProperty('summary'); //print_r($ttitle); $title = api_convert_encoding($ttitle, $charset, 'UTF-8'); $tdesc = $ve->getProperty('description'); $desc = api_convert_encoding($tdesc, $charset, 'UTF-8'); $ts = $ve->getProperty('dtstart'); $start_date = $ts['year'] . '-' . $ts['month'] . '-' . $ts['day'] . ' ' . $ts['hour'] . ':' . $ts['min'] . ':' . $ts['sec']; $ts = $ve->getProperty('dtend'); $end_date = $ts['year'] . '-' . $ts['month'] . '-' . $ts['day'] . ' ' . $ts['hour'] . ':' . $ts['min'] . ':' . $ts['sec']; //echo $start_date.' - '.$end_date; $organizer = $ve->getProperty('organizer'); $attendee = $ve->getProperty('attendee'); $course_name = $ve->getProperty('location'); //insert the event in our database $id = agenda_add_item($course_info, $title, $desc, $start_date, $end_date, $_POST['selectedform']); $repeat = $ve->getProperty('rrule'); if (is_array($repeat) && !empty($repeat['FREQ'])) { $trans = array('DAILY' => 'daily', 'WEEKLY' => 'weekly', 'MONTHLY' => 'monthlyByDate', 'YEARLY' => 'yearly'); $freq = $trans[$repeat['FREQ']]; $interval = $repeat['INTERVAL']; if (isset($repeat['UNTIL']) && is_array($repeat['UNTIL'])) { $until = mktime(23, 59, 59, $repeat['UNTIL']['month'], $repeat['UNTIL']['day'], $repeat['UNTIL']['year']); $res = agenda_add_repeat_item($course_info, $id, $freq, $until, $_POST['selectedform']); } //TODO: deal with count if (!empty($repeat['COUNT'])) { $count = $repeat['COUNT']; $res = agenda_add_repeat_item($course_info, $id, $freq, $count, $_POST['selectedform']); } } return true; }