/** * Import events from the Calendar plugin to evList. * This function checks that the event ID isn't already in use to avoid * re-importing events. * * @return integer 0 = success, -1 = event table missing, >0 = error count */ function evlist_import_calendar_events() { global $_TABLES, $LANG_EVLIST; if (!isset($_TABLES['events']) || empty($_TABLES['events'])) { return -1; } $errors = 0; // Keep track of errors $result = DB_query("SELECT * FROM {$_TABLES['events']}", 1); while ($A = DB_fetchArray($result, false)) { if (empty($A['timestart'])) { $A['timestart'] = '00:00:00'; } list($s_hour, $s_min, $s_sec) = explode(':', $A['timestart']); if (empty($A['timeend'])) { $A['timeend'] = '00:00:00'; } list($e_hour, $e_min, $e_sec) = explode(':', $A['timeend']); $s_ampm = $s_hour == 0 || $s_hour > 12 ? 'pm' : 'am'; $e_ampm = $e_hour == 0 || $e_hour > 12 ? 'pm' : 'am'; $E = array('eid' => $A['eid'], 'title' => $A['title'], 'summary' => $A['description'], 'full_description' => '', 'date_start1' => $A['datestart'], 'date_end1' => $A['dateend'], 'starthour1' => $s_hour, 'startminute1' => $s_min, 'start_ampm' => $s_ampm, 'endhour1' => $e_hour, 'endminute1' => $e_min, 'end_ampm' => $e_ampm, 'url' => $A['url'], 'street' => $A['address1'], 'city' => $A['city'], 'province' => $A['state'], 'postal' => $A['zipcode'], 'allday' => $A['allday'] == 1 ? 1 : 0, 'location' => $A['location'], 'owner_id' => (int) $A['owner_id'], 'group_id' => (int) $A['group_id'], 'perm_owner' => (int) $A['perm_owner'], 'perm_group' => (int) $A['perm_group'], 'perm_members' => (int) $A['perm_members'], 'perm_anon' => (int) $A['perm_anon'], 'show_upcoming' => 1, 'status' => $A['status'] == 1 ? 1 : 0, 'hits' => (int) $A['hits'], 'cal_id' => 1); // We'll let the event object handle most things, saving the // event and detail records. // Create the event object, while checking if the eid exists $Ev = new evEvent($A['eid']); if ($Ev->id != '') { // Oops, dup ID, must already be done. continue; } // Skip possible duplicates // Force it to be a new event even though we have an event ID $Ev->isNew = true; if ($Ev->Save($E, 'evlist_events', true) !== '') { COM_errorLog(sprintf($LANG_EVLIST['err_import_event'], $A['eid'])); $errors++; continue; // This one failed, keep trying the others } // PITA, but perms don't get updated right by Save(). We can do this // or convert them to form-style checkbox values before saving. This // seems simpler $sql = "UPDATE {$_TABLES['evlist_events']} SET\n perm_owner = '{$E['perm_owner']}',\n perm_group = '{$E['perm_members']}',\n perm_members = '{$E['perm_anon']}',\n perm_anon = '{$E['perm_anon']}'\n WHERE id='{$Ev->id}'"; //echo $sql;die; DB_query($sql, 1); if (DB_error()) { $error = 1; continue; } } return $errors; }
/** * Sets the "enabled" field to the specified value. * * @param integer $id ID number of element to modify * @param integer $value New value to set * @return New value, or old value upon failure */ public function toggleEnabled($oldvalue, $ev_id = '') { $oldvalue = $oldvalue == 0 ? 0 : 1; if ($ev_id == '') { if (is_object($this)) { $ev_id = $this->id; } else { return $oldvalue; } } else { $ev_id = COM_sanitizeID($ev_id, false); } return evEvent::_toggle($oldvalue, 'status', $ev_id); }
$content .= $Ev->Edit(0, $actionval); } break; case 'event': default: USES_evlist_class_event(); $Ev = new evEvent($_REQUEST['eid']); $Ev->AdminMode = $admin; $content .= $Ev->Edit('', $rp_id, 'save' . $actionval); break; } break; case 'clone': if (isset($_GET['eid'])) { USES_evlist_class_event(); $Ev = new evEvent($_GET['eid']); if ($Ev->id == '') { // Event not found break; } // Now prep it to be saved as a new record $Ev->id = ''; $Ev->isNew = true; $content .= $Ev->Edit(); } break; case 'none': // Don't display anything, it was already taken care of break; case 'home': if (!empty($msg)) {
/** * 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; }
/** * Import events from a CSV file into the database. * * @return string Completion message */ function EVLIST_importEvents() { global $_CONF, $_TABLES, $LANG_EVLIST, $_USER; // Setting this to true will cause import to print processing status to // webpage and to the error.log file $verbose_import = true; $retval = ''; // First, upload the file USES_class_upload(); $upload = new upload(); $upload->setPath($_CONF['path_data']); $upload->setAllowedMimeTypes(array('text/plain' => '.txt, .csv', 'application/octet-stream' => '.txt, .csv')); $upload->setFileNames('evlist_import_file.txt'); $upload->setFieldName('importfile'); if ($upload->uploadFiles()) { // Good, file got uploaded, now install everything $filename = $_CONF['path_data'] . 'evlist_import_file.txt'; if (!file_exists($filename)) { // empty upload form $retval = $LANG_EVLIST['err_invalid_import']; return $retval; } } else { // A problem occurred, print debug information $retval .= $upload->printErrors(false); return $retval; } $fp = fopen($filename, 'r'); if (!$fp) { $retval = $LANG_EVLIST['err_invalid_import']; return $retval; } USES_evlist_class_event(); $success = 0; $failures = 0; // Set owner_id to the current user and group_id to the default $owner_id = (int) $_USER['uid']; if ($owner_id < 2) { $owner_id = 2; } // last resort, use Admin $group_id = (int) DB_getItem($_TABLES['groups'], 'grp_id', 'grp_name="evList Admin"'); if ($group_id < 2) { $group_id = 2; } // last resort, use Root while (($event = fgetcsv($fp)) !== false) { $Ev = new evEvent(); $Ev->isNew = true; $i = 0; $A = array('date_start1' => $event[$i++], 'date_end1' => $event[$i++], 'time_start1' => $event[$i++], 'time_end1' => $event[$i++], 'title' => $event[$i++], 'summary' => $event[$i++], 'full_description' => $event[$i++], 'url' => $event[$i++], 'location' => $event[$i++], 'street' => $event[$i++], 'city' => $event[$i++], 'province' => $event[$i++], 'country' => $event[$i++], 'postal' => $event[$i++], 'contact' => $event[$i++], 'email' => $event[$i++], 'phone' => $event[$i++], 'cal_id' => 1, 'status' => 1, 'hits' => 0, 'recurring' => 0, 'split' => 0, 'time_start2' => '00:00:00', 'time_end2' => '00:00:00', 'owner_id' => $owner_id, 'group_id' => $group_id); if ($_CONF['hour_mode'] == 12) { list($hour, $minute, $second) = explode(':', $A['time_start1']); if ($hour > 12) { $hour -= 12; $am = 'pm'; } elseif ($hour == 0) { $hour = 12; $am = 'am'; } else { $am = 'am'; } $A['start1_ampm'] = $am; $A['starthour1'] = $hour; $A['startminute1'] = $minute; list($hour, $minute, $second) = explode(':', $A['time_end1']); if ($hour > 12) { $hour -= 12; $am = 'pm'; } elseif ($hour == 0) { $hour = 12; $am = 'am'; } else { $am = 'am'; } $A['end1_ampm'] = $am; $A['endhour1'] = $hour; $A['endminute1'] = $minute; } if ($A['time_start1'] == '00:00:00' && $A['time_end1'] == '00:00:00') { $A['allday'] = 1; } else { $A['allday'] = 0; } $msg = $Ev->Save($A); if (empty($msg)) { $successes++; } else { $failures++; } } return "{$successes} Succeeded<br />{$failures} Failed"; }
/** * 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(); }
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); echo '<?xml version="1.0" encoding="ISO-8859-1"?> <info>'. "\n"; echo "<newval>$newval</newval>\n"; echo "<id>{$_REQUEST['id']}</id>\n"; echo "<type>{$_REQUEST['type']}</type>\n"; echo "<component>{$_REQUEST['component']}</component>\n"; echo "<baseurl>" . EVLIST_ADMIN_URL . "</baseurl>\n"; echo "</info>\n";*/ break; case 'event': USES_evlist_class_event(); switch ($_GET['type']) { case 'enabled': $newval = evEvent::toggleEnabled($_REQUEST['oldval'], $_REQUEST['id']); break; default: exit; } /*header('Content-Type: text/xml'); header("Cache-Control: no-cache, must-revalidate"); //A date in the past header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); echo '<?xml version="1.0" encoding="ISO-8859-1"?> <info>'. "\n"; echo "<newval>$newval</newval>\n"; echo "<id>{$_REQUEST['id']}</id>\n"; echo "<type>{$_REQUEST['type']}</type>\n"; echo "<component>{$_REQUEST['component']}</component>\n";