Beispiel #1
0
/**
*   Upgrade to version 1.3.0
*   Many changes in this version, so a function was created to
*   hold them all.
*
*   @return boolean     True on success, False on failure
*/
function evlist_upgrade_1_3_0()
{
    global $_CONF, $_EV_CONF, $_TABLES, $_DB_dbms, $c, $CONF_EVLIST_DEFAULT;
    USES_evlist_class_event();
    $c->add('default_view', $CONF_EVLIST_DEFAULT['default_view'], 'select', 0, 1, 14, 90, true, 'evlist');
    $c->add('max_upcoming_days', $CONF_EVLIST_DEFAULT['max_upcoming_days'], 'text', 0, 1, 0, 100, true, 'evlist');
    // Combine users allowed to add events into one variable
    $can_add = 0;
    if ($EV_CONF['allow_anon_add'] > 0) {
        $can_add += EV_ANON_CAN_ADD;
    }
    if ($EV_CONF['allow_user_add'] > 0) {
        $can_add += EV_USER_CAN_ADD;
    }
    $c->add('can_add', $can_add, 'select', 0, 1, 15, 20, true, 'evlist');
    $c->del('allow_user_add', 'evlist');
    $c->del('allow_anon_add', 'evlist');
    // Add new options for plugin integration
    $c->add('use_locator', $CONF_EVLIST_DEFAULT['use_locator'], 'select', 0, 1, 0, 110, true, 'evlist');
    $c->add('use_weather', $CONF_EVLIST_DEFAULT['use_weather'], 'select', 0, 1, 0, 120, true, 'evlist');
    // Date & Time formats moved from the DB to simple $_CONF  variables
    $format = DB_getItem($_TABLES['evlist_dateformat'], 'format', "id='{$_EV_CONF['date_format']}'");
    if (empty($format)) {
        $format = '%a %b %d, %Y';
    }
    $c->set_default('date_format', $format, 'evlist');
    $c->set('date_format', $format, 'evlist');
    $format = DB_getItem($_TABLES['evlist_timeformat'], 'format', "id='{$_EV_CONF['date_format']}'");
    if (empty($format)) {
        $format = '%I:%M %p';
    }
    $c->set_default('time_format', $format, 'evlist');
    $c->set('time_format', $format, 'evlist');
    DB_query("DROP TABLE {$_TABLES['evlist_dateformat']}");
    DB_query("DROP TABLE {$_TABLES['evlist_timeformat']}");
    // Change feature name
    DB_query("UPDATE {$_TABLES['features']}\n                SET ft_name='evlist.admin' WHERE ft_name='evlist.edit'");
    // Add new "submit" feature & map to Root group
    DB_query("INSERT INTO {$_TABLES['features']} (ft_name, ft_descr)\n            VALUES ('evlist.submit', \n                    'Allowed to bypass the evList submission queue')", 1);
    if (!DB_error()) {
        $ft_id = (int) DB_insertId();
        if ($ft_id > 0) {
            DB_query("INSERT INTO {$_TABLES['access']} (acc_ft_id, acc_grp_id)\n                    VALUES('{$ft_id}', '1')");
        }
    }
    EVLIST_do_upgrade_sql('1.3.0');
    // Add the new fields to the event & submission tables
    /*$new_sql = "ADD det_id int(10) NOT NULL,
              ADD show_upcoming tinyint(1) unsigned NOT NULL DEFAULT '1',
              ADD cal_id int(10) unsigned NOT NULL DEFAULT '1',
              ADD options varchar(255)";
      DB_query("ALTER TABLE {$_TABLES['evlist_events']} $new_sql");
      DB_query("ALTER TABLE {$_TABLES['evlist_submissions']} $new_sql");*/
    // Create the new tables
    /*DB_query($_SQL['evlist_repeat']);
      DB_query($_SQL['evlist_calendars']);
      DB_query($_SQL['evlist_detail']);
      DB_query($DEFVALUES['evlist_calendars']);*/
    // Now split out the detail and create the repeats
    $result = DB_query("SELECT * FROM {$_TABLES['evlist_events']}");
    $error = 0;
    while ($A = DB_fetchArray($result, false)) {
        $A = array_map('DB_escapeString', $A);
        $sql = "INSERT INTO {$_TABLES['evlist_detail']} (\n                    ev_id, title, summary, full_description, url, location,\n                    street, city, province, country, postal, contact,\n                    email, phone\n                ) VALUES (\n                    '{$A['id']}', '{$A['title']}', '{$A['summary']}', \n                    '{$A['full_description']}', '{$A['url']}',\n                    '{$A['location']}', '{$A['street']}',\n                    '{$A['city']}', '{$A['province']}',\n                    '{$A['country']}', '{$A['postal']}',\n                    '{$A['contact']}', '{$A['email']}','{$A['phone']}'\n                )";
        DB_query($sql, 1);
        if (DB_error()) {
            $error = 1;
            break;
        } else {
            $DB_det_id = DB_insertID();
        }
        $rec_data = array();
        if ($A['recurring'] == 1) {
            $rec_data['type'] = $A['rec_option'];
            switch ($A['rec_option']) {
                case EV_RECUR_DAILY:
                case EV_RECUR_MONTHLY:
                case EV_RECUR_YEARLY:
                    list($stop, $skip) = explode(';', $A['rec_data']);
                    if (!empty($skip)) {
                        $rec_data['skip'] = (int) $skip;
                    }
                    break;
                case EV_RECUR_WEEKLY:
                    list($listdays, $stop) = explode(';', $A['rec_data']);
                    $rec_data['listdays'] = explode(',', $listdays);
                    break;
                case EV_RECUR_DOM:
                    list($interval, $weekday, $stop) = explode(';', $A['rec_data']);
                    $rec_data['weekday'] = $weekday;
                    $rec_data['interval'] = $interval;
                    break;
                case EV_RECUR_DATES:
                    $rec_data['custom'] = explode(',', $A['rec_data']);
                    $stop = 'XX';
                    // unused flag
                    break;
            }
            // switch recurring type
            // Check the stop date for validity and format it properly
            if ($stop != 'XX') {
                if (strtotime($stop) > strtotime('2037-01-01') || $stop < '1970-01-01') {
                    $stop = '2037-12-31';
                }
                list($y, $m, $d) = explode('-', $stop);
                $rec_data['stop'] = sprintf('%d-%02d-%02d', $y, $m, $d);
            }
        } else {
            // not a recurring event
            $rec_data['type'] = 0;
        }
        $DB_rec_data = DB_escapeString(serialize($rec_data));
        $sql = "UPDATE {$_TABLES['evlist_events']} SET\n                    rec_data = '{$DB_rec_data}',\n                    det_id = '{$DB_det_id}'\n                WHERE id='{$A['id']}'";
        DB_query($sql, 1);
        if (DB_error()) {
            $error = 1;
            break;
        }
        // Now that the updated info is saved to the event record,
        // use the evEvent class to create the repeats
        $Ev = new evEvent($A['id']);
        $Ev->UpdateRepeats();
    }
    // for each event record
    if ($error == 0) {
        // Now drop the no-longer-used fields
        $alter_sql = "DROP title, DROP summary, DROP full_description,\n                DROP date_start2, DROP date_end2,\n                DROP url, DROP location, DROP street, DROP city,\n                DROP province, DROP country, DROP postal, DROP contact,\n                DROP email, DROP phone";
        DB_query("ALTER TABLE {$_TABLES['evlist_events']} {$alter_sql}");
        DB_query("ALTER TABLE {$_TABLES['evlist_submissions']} {$alter_sql}");
        DB_query("ALTER TABLE {$_TABLES['evlist_remlookup']}\n                DROP id,\n                ADD rp_id int(10) unsigned NOT NULL default 0 AFTER eid,\n                DROP date_start,\n                DROP timestamp");
        // Add new options.  Set values to emulate current behavior.
        $options = array('contactlink' => 1);
        $opt_str = DB_escapeString(serialize($options));
        DB_query("UPDATE {$_TABLES['evlist_events']} SET options='{$opt_str}'");
        DB_query("UPDATE {$_TABLES['evlist_submissions']} SET options='{$opt_str}'");
    }
    CTL_clearCache();
    // Clear cache to activate new configuration items.
    return $error;
}
Beispiel #2
0
/**
*   Post-installation activity.
*   Create the repeating event records for the sample data that was loaded.
*/
function X_plugin_postinstall_evlist()
{
    global $_TABLES, $_CONF, $_EV_CONF;
    require_once $_CONF['path'] . '/plugins/evlist/functions.inc';
    // Now create the repeat records for the default events
    USES_evlist_class_event();
    $sql = "SELECT id FROM {$_TABLES['evlist_events']}";
    $res = DB_query($sql);
    $Ev = new evEvent();
    while ($A = DB_fetchArray($res, false)) {
        $Ev->Read($A['id']);
        $Ev->UpdateRepeats();
    }
    // Clear the template cache since we've introduced some new css.
    // Might not be needed outside of testing where the plugin is repeatedly
    // installed & removed, but doesn't hurt.
    CTL_clearCache();
}