Example #1
0
 function setUp()
 {
     parent::setUp();
     require_code('calendar2');
     $this->eventtype_id = add_event_type('test_event_type', 'calendar/testtype', '');
     // Test the forum was actually created
     $this->assertTrue('test_event_type' == get_translated_text($GLOBALS['SITE_DB']->query_value('calendar_types', 't_title ', array('id' => $this->eventtype_id))));
 }
Example #2
0
 /**
  * Standard import function.
  *
  * @param  object			The DB connection to import from
  * @param  string			The table prefix the target prefix is using
  * @param  PATH			The base directory we are importing from
  */
 function import_calendar($db, $table_prefix, $file_base)
 {
     require_code('calendar2');
     $rows = $db->query('SELECT * FROM ' . $table_prefix . 'calendar_types', NULL, NULL, true);
     if (is_null($rows)) {
         return;
     }
     foreach ($rows as $row) {
         if ($row['id'] == db_get_first_id()) {
             import_id_remap_put('event_type', strval($row['id']), db_get_first_id());
             continue;
         }
         if (import_check_if_imported('event_type', strval($row['id']))) {
             continue;
         }
         $id_new = add_event_type($this->get_lang_string($db, $row['t_title']), $row['t_logo'], array_key_exists('t_external_feed', $row) ? $row['t_external_feed'] : '');
         import_id_remap_put('event_type', strval($row['id']), $id_new);
     }
     $rows = $db->query('SELECT * FROM ' . $table_prefix . 'calendar_interests', NULL, NULL, true);
     if (is_null($rows)) {
         $rows = $db->query('SELECT * FROM ' . $table_prefix . 'calendar_declarations_of_interest');
     }
     $on_same_msn = $this->on_same_msn($file_base);
     foreach ($rows as $row) {
         $member = $on_same_msn ? $row['i_member_id'] : import_id_remap_get('member', $row['i_member_id'], true);
         if (is_null($member)) {
             continue;
         }
         $type = import_id_remap_get('event_type', strval($row['t_type']), true);
         if (is_null($type)) {
             continue;
         }
         $GLOBALS['SITE_DB']->query_delete('calendar_interests', array('i_member_id' => $member, 't_type' => $type), '', 1);
         $GLOBALS['SITE_DB']->query_insert('calendar_interests', array('i_member_id' => $member, 't_type' => $type));
     }
     $event_rows = $db->query('SELECT * FROM ' . $table_prefix . 'calendar_events ORDER BY id');
     foreach ($event_rows as $row) {
         if (import_check_if_imported('event', strval($row['id']))) {
             continue;
         }
         $submitter = $on_same_msn ? $row['e_submitter'] : import_id_remap_get('member', strval($row['e_submitter']), true);
         if (is_null($submitter)) {
             $submitter = $GLOBALS['FORUM_DRIVER']->get_guest_id();
         }
         $type = import_id_remap_get('event_type', strval($row['e_type']), true);
         if (is_null($type)) {
             continue;
         }
         if (!array_key_exists('validated', $row)) {
             $row['validated'] = 1;
         }
         if (!array_key_exists('notes', $row)) {
             $row['notes'] = '';
         }
         if (!array_key_exists('allow_rating', $row)) {
             $row['allow_rating'] = 1;
         }
         if (!array_key_exists('allow_comments', $row)) {
             $row['allow_comments'] = 1;
         }
         if (!array_key_exists('allow_trackbacks', $row)) {
             $row['allow_trackbacks'] = 1;
         }
         $id = get_param_integer('keep_preserve_ids', 0) == 0 ? NULL : $row['id'];
         $id_new = add_calendar_event($type, $row['e_recurrence'], $row['e_recurrences'], array_key_exists('e_seg_recurrences', $row) ? $row['e_seg_recurrences'] : 0, $this->get_lang_string($db, $row['e_title']), $this->get_lang_string($db, $row['e_content']), $row['e_priority'], $row['e_is_public'], $row['e_start_year'], $row['e_start_month'], $row['e_start_day'], $row['e_start_hour'], $row['e_start_minute'], $row['e_end_year'], $row['e_end_month'], $row['e_end_day'], $row['e_end_hour'], $row['e_end_minute'], array_key_exists('e_timezone', $row) ? $row['e_timezone'] : NULL, array_key_exists('e_do_timezone_conv', $row) ? $row['e_do_timezone_conv'] : 1, $row['validated'], $row['allow_rating'], $row['allow_comments'], $row['allow_trackbacks'], $row['notes'], $submitter, $row['e_views'], $row['e_add_date'], $row['e_edit_date'], $id);
         import_id_remap_put('event', strval($row['id']), $id_new);
     }
     $this->_import_review_supplement($db, $table_prefix, 'events', 'event');
     $this->_import_catalogue_entry_linkage($db, $table_prefix, 'event', 'event');
     $rows = $db->query('SELECT * FROM ' . $table_prefix . 'calendar_reminders');
     foreach ($rows as $row) {
         $event = import_id_remap_get('event', strval($row['e_id']), true);
         if (is_null($event)) {
             continue;
         }
         $member = $on_same_msn ? $row['n_member_id'] : import_id_remap_get('member', strval($row['n_member_id']), true);
         if (is_null($member)) {
             continue;
         }
         $GLOBALS['SITE_DB']->query_insert('calendar_reminders', array('e_id' => $event, 'n_member_id' => $member, 'n_seconds_before' => $row['n_seconds_before']));
     }
     require_code('calendar');
     foreach ($event_rows as $row) {
         regenerate_event_reminder_jobs(import_id_remap_get('event', strval($row['id'])));
     }
 }
Example #3
0
/**
 * Import ical events to members's event calendar.
 *
 * @param  PATH		File path
*/
function ical_import($file_name)
{
    $data = unixify_line_format(file_get_contents($file_name));
    $whole = end(explode('BEGIN:VCALENDAR', $data));
    $events = explode('BEGIN:VEVENT', $whole);
    $calendar_nodes = array();
    foreach ($events as $key => $items) {
        $items = preg_replace('#(.+)\\n +(.*)\\n#', '${1}${2}' . "\n", $items);
        // Merge split lines
        $nodes = explode("\n", $items);
        foreach ($nodes as $_child) {
            if (strpos($_child, ':') === false) {
                continue;
            }
            $child = array('', '');
            $in_quotes = false;
            $j = 0;
            for ($i = 0; $i < strlen($_child); $i++) {
                $char = $_child[$i];
                if ($char == '"') {
                    $in_quotes = !$in_quotes;
                }
                if ($j != 1 && !$in_quotes && $char == ':') {
                    $j++;
                } else {
                    $child[$j] .= $char;
                }
            }
            $matches = array();
            if (preg_match('#;TZID=(.*)#', $child[0], $matches)) {
                $calendar_nodes[$key]['TZID'] = $matches[1];
            }
            $child[0] = preg_replace('#;.*#', '', $child[0]);
            if (array_key_exists(1, $child) && $child[0] !== 'PRODID' && $child[0] !== 'VERSION' && $child[0] !== 'END') {
                $calendar_nodes[$key][$child[0]] = trim($child[1]);
            }
        }
        if ($key != 0) {
            list(, $type_id, $type, $recurrence, $recurrences, $seg_recurrences, $title, $content, $priority, $is_public, $start_year, $start_month, $start_day, $start_hour, $start_minute, $end_year, $end_month, $end_day, $end_hour, $end_minute, $timezone, $validated, $allow_rating, $allow_comments, $allow_trackbacks, $notes) = get_event_data_ical($calendar_nodes[$key]);
            if (is_null($type_id)) {
                require_code('calendar2');
                $type_id = add_event_type(ucfirst($type), 'calendar/general');
            }
            $id = add_calendar_event($type, $recurrence, $recurrences, $seg_recurrences, $title, $content, $priority, $is_public, $start_year, $start_month, $start_day, $start_hour, $start_minute, $end_year, $end_month, $end_day, $end_hour, $end_minute, $timezone, 1, $validated, $allow_rating, $allow_comments, $allow_trackbacks, $notes);
        }
    }
}
Example #4
0
 /**
  * Standard aed_module add actualiser.
  *
  * @return ID_TEXT		The entry added
  */
 function add_actualisation()
 {
     require_code('themes2');
     $id = add_event_type(post_param('title'), get_theme_img_code('calendar'), post_param('external_feed'));
     $this->set_permissions(strval($id));
     return strval($id);
 }
Example #5
0
/**
 * Edit a bookable.
 *
 * @param  AUTO_LINK	Bookable ID.
 * @param  array		Bookable details.
 * @param  array		List of codes.
 * @param  ?array		List of black-outs (NULL: no change).
 * @param  ?array		List of supplements (NULL: no change).
 */
function edit_bookable($bookable_id, $bookable_details, $codes, $blacked = NULL, $supplements = NULL)
{
    $_old_bookable = $GLOBALS['SITE_DB']->query_select('bookable', array('*'), array('id' => $bookable_id), '', 1);
    if (!array_key_exists(0, $_old_bookable)) {
        warn_exit(do_lang_tempcode('MISSING_RESOURCE'));
    }
    $title = $bookable_details['title'];
    $bookable_details['title'] = lang_remap($_old_bookable[0]['title'], $bookable_details['title']);
    $bookable_details['description'] = lang_remap($_old_bookable[0]['description'], $bookable_details['description']);
    $bookable_details['categorisation'] = lang_remap($_old_bookable[0]['categorisation'], $bookable_details['categorisation']);
    $bookable_details['edit_date'] = time();
    $bookable_details['calendar_type'] = $_old_bookable[0]['calendar_type'];
    require_code('calendar2');
    $external_feed = find_script('bookings_ical') . '?id=' . strval($bookable_id) . '&pass='******'booking_salt_' . $GLOBALS['SITE_INFO']['admin_password']);
    if (is_null($bookable_details['calendar_type']) && is_null($GLOBALS['SITE_DB']->query_value_null_ok('calendar_types', 'id', array('id' => $bookable_details['calendar_type'])))) {
        $bookable_details['calendar_type'] = add_event_type($title, 'calendar/booking', $external_feed);
    } else {
        edit_event_type($bookable_details['calendar_type'], $title, 'calendar/booking', $external_feed);
    }
    $GLOBALS['SITE_DB']->query_update('bookable', $bookable_details, array('id' => $bookable_id), '', 1);
    $GLOBALS['SITE_DB']->query_delete('bookable_codes', array('bookable_id' => $bookable_id));
    foreach ($codes as $code) {
        $GLOBALS['SITE_DB']->query_insert('bookable_codes', array('bookable_id' => $bookable_id, 'code' => $code));
    }
    if (!is_null($blacked)) {
        $GLOBALS['SITE_DB']->query_delete('bookable_blacked_for', array('bookable_id' => $bookable_id));
        foreach ($blacked as $blacked_id) {
            $GLOBALS['SITE_DB']->query_insert('bookable_blacked_for', array('blacked_id' => $blacked_id, 'bookable_id' => $bookable_id));
        }
    }
    if (!is_null($supplements)) {
        $GLOBALS['SITE_DB']->query_delete('bookable_supplement_for', array('bookable_id' => $bookable_id));
        foreach ($supplements as $supplement_id) {
            $GLOBALS['SITE_DB']->query_insert('bookable_supplement_for', array('supplement_id' => $supplement_id, 'bookable_id' => $bookable_id));
        }
    }
    log_it('EDIT_BOOKABLE', strval($bookable_id), $title);
}