function activity_log_install() { global $wpdb; global $activity_log_db_version; $table_name = $wpdb->prefix . "activity_log"; if ($wpdb->get_var("show tables like '{$table_name}'") != $table_name) { $sql = "CREATE TABLE " . $table_name . " (\n\t\t\tid mediumint(9) NOT NULL AUTO_INCREMENT,\n\t\t\ttime bigint(11) DEFAULT '0' NOT NULL,\n\t\t\ttype tinytext NOT NULL,\n\t\t\tentry text NOT NULL,\n\t\t\tUNIQUE KEY id (id)\n\t\t);"; require_once ABSPATH . 'wp-admin/includes/upgrade.php'; dbDelta($sql); add_option("activity_log_db_version", $activity_log_db_version); } $rows_affected = activity_log(array('type' => 'admin', 'entry' => 'Activity Log plugin activated')); }
/** * Authenticate * * Checks if the user has a valid username and password by: * 1) Checking for proper authentication from UIowa, and * 2) Checking if the user is allowed to use this site * * @author David Dellsperger * @author Sean Ephraim * @access public * @param array Array of variables to use * @return mixed Username on success, else FALSE */ public function authenticate($vars = NULL) { if (isset($_GET['uip_ticket'])) { $uip_ticket = $_GET['uip_ticket']; $url = "https://login.uiowa.edu/uip/checkticket.page?service=" . $this->auth_URL . "&uip_ticket=" . $uip_ticket; $rsp = file_get_contents($url); $rsp = str_replace("\n", '&', $rsp); parse_str($rsp); // Get the HawkID (username) from the response if (!isset($error)) { $this->load->library('ion_auth'); if ($this->ion_auth->username_check($hawkid)) { // Valid user! $this->load->model('auth_model'); if ($this->auth_model->force_login($hawkid)) { // login successful! $user = $this->ion_auth->user()->row(); // Who should the welcome message be addressed to? if ($user->first_name) { $name = $user->first_name; } else { $name = $user->username; } // Set welcome message if ($name) { $this->session->set_flashdata('success', 'Welcome, ' . $name . '!'); } else { $this->session->set_flashdata('success', 'Welcome!'); } // Log the login! $username = $user->username; activity_log("User '{$username}' logged in", 'login'); redirect('variations/unreleased'); } else { // ERROR: could not login $this->session->set_flashdata('error', 'There was an error logging in. Please try again.'); } } else { // ERROR: non-registered user of this site $this->session->set_flashdata('error', 'You are not registered to use this site.'); } } else { // ERROR: UI login tools returned an error $this->session->set_flashdata('error', "There was an error logging in: '{$error}'"); } // Redirect to local login if an error occurred redirect('login'); } // Redirect to the UIowa login page redirect('https://login.uiowa.edu/uip/login.page?service=' . $this->auth_URL); }
if ($event_owner == $login || user_is_assistant($login, $event_owner)) { $can_delete = true; } } dbi_free_result($res); } } if (empty($error) && !$can_delete) { $error = print_not_auth(6); } if (empty($error) && $can_delete) { if (!dbi_execute('DELETE FROM webcal_blob WHERE cal_blob_id = ?', array($blid))) { $error = db_error(); } else { if ($event_id > 0) { $removeStr = translate('Removed'); if ($type == 'A') { activity_log($event_id, $login, $login, LOG_ATTACHMENT, $removeStr . ': ' . $name); } elseif ($type == 'C') { activity_log($event_id, $login, $login, LOG_COMMENT, $removeStr); } } if ($event_id > 0) { do_redirect('view_entry.php?id=' . $event_id); } do_redirect(get_preferred_view()); } } // Some kind of error... print_header(); echo print_error($error) . print_trailer();
} $msg .= " " . $login_fullname . ". " . translate("The subject is") . " \"" . $name . "\"\n\n" . translate("The description is") . " \"" . $description . "\"\n" . translate("Date") . ": " . date_to_str($fmtdate) . "\n" . (empty($user_hour) && empty($minute) ? "" : translate("Time") . ": " . display_time($user_hour * 10000 + $minute * 100, true) . "\n") . translate("Please look on") . " " . translate($application_name) . " " . ($require_approvals == "Y" ? translate("to accept or reject this appointment") : translate("to view this appointment")) . "."; // add URL to event, if we can figure it out /* if ( ! empty ( $server_url ) ) { $url = $server_url . "view_entry.php?id=" . $id; $msg .= "\n\n" . $url; } */ if (strlen($from)) { $extra_hdrs = "From: {$from}\r\nX-Mailer: " . translate($application_name); } else { $extra_hdrs = "X-Mailer: " . translate($application_name); } mail($tempemail, translate($application_name) . " " . translate("Notification") . ": " . $name, utf8_decode(html_to_8bits($msg)), $extra_hdrs); activity_log($id, $login, $participants[$i], $LOG_NOTIFICATION, ""); } } } } // add external participants // send notification if enabled. if (is_array($ext_names) && is_array($ext_emails)) { for ($i = 0; $i < count($ext_names); $i++) { if (strlen($ext_names[$i])) { $sql = "INSERT INTO webcal_entry_ext_user " . "( cal_id, cal_fullname, cal_email ) VALUES ( " . "{$id}, '{$ext_names[$i]}', "; if (strlen($ext_emails[$i])) { $sql .= "'{$ext_emails[$i]}' )"; } else { $sql .= "NULL )"; }
function send_reminder($id, $event_date) { global $ALLOW_EXTERNAL_USERS, $debug, $def_tz, $emails, $EXTERNAL_REMINDERS, $attachics, $htmlmail, $is_task, $LANGUAGE, $languages, $names, $only_testing, $SERVER_URL, $site_extras, $t_format, $tz; $ext_participants = $participants = array(); $num_ext_participants = $num_participants = 0; $pri[1] = translate('High'); $pri[2] = translate('Medium'); $pri[3] = translate('Low'); // Get participants first... $res = dbi_execute('SELECT cal_login, cal_percent FROM webcal_entry_user WHERE cal_id = ? AND cal_status IN ( \'A\',\'W\' ) ORDER BY cal_login', array($id)); if ($res) { while ($row = dbi_fetch_row($res)) { $participants[$num_participants++] = $row[0]; $percentage[$row[0]] = $row[1]; } } $partcnt = count($participants); // Get external participants. if (!empty($ALLOW_EXTERNAL_USERS) && $ALLOW_EXTERNAL_USERS == 'Y' && !empty($EXTERNAL_REMINDERS) && $EXTERNAL_REMINDERS == 'Y') { $res = dbi_execute('SELECT cal_fullname, cal_email FROM webcal_entry_ext_user WHERE cal_id = ? AND cal_email IS NOT NULL ORDER BY cal_fullname', array($id)); if ($res) { while ($row = dbi_fetch_row($res)) { $ext_participants[$num_ext_participants] = $row[0]; $ext_participants_email[$num_ext_participants++] = $row[1]; } } } $ext_partcnt = count($ext_participants); if (!$num_participants && !$num_ext_participants) { if ($debug) { echo 'No participants found for event id' . ": {$id}<br />\n"; } return; } // Get event details. $res = dbi_execute('SELECT cal_create_by, cal_date, cal_time, cal_mod_date, cal_mod_time, cal_duration, cal_priority, cal_type, cal_access, cal_name, cal_description, cal_due_date, cal_due_time FROM webcal_entry WHERE cal_id = ?', array($id)); if (!$res) { echo translate('Database error') . ': ' . translate('could not find event id') . " {$id}.\n"; return; } if (!($row = dbi_fetch_row($res))) { echo translate('Error') . ': ' . str_replace('XXX', $id, translate('could not find event id XXX in database.')) . "\n"; return; } // Send mail. We send one user at a time so that we can switch // languages between users if needed (as well as HTML vs plain text). $mailusers = $recipients = array(); if (isset($single_user) && $single_user == 'Y') { $mailusers[] = $emails[$single_user_login]; $recipients[] = $single_user_login; } else { for ($i = 0; $i < $partcnt; $i++) { if (strlen($emails[$participants[$i]])) { $mailusers[] = $emails[$participants[$i]]; $recipients[] = $participants[$i]; } else { if ($debug) { echo "No email for user {$participants[$i]}.<br />\n"; } } } for ($i = 0; $i < $ext_partcnt; $i++) { $mailusers[] = $ext_participants_email[$i]; $recipients[] = $ext_participants[$i]; } } $mailusercnt = count($mailusers); if ($debug) { echo 'Found ' . $mailusercnt . " with email addresses<br />\n"; } for ($j = 0; $j < $mailusercnt; $j++) { $recip = $mailusers[$j]; $user = $recipients[$j]; $isExt = !in_array($user, $participants); $userlang = empty($languages[$user]) ? $LANGUAGE : $languages[$user]; $userTformat = !empty($t_format[$user]) ? $t_format[$user] : 24; // Gotta pick something. if ($userlang == 'none') { $userlang = 'English-US'; } // Gotta pick something. if ($debug) { echo "Setting language to \"{$userlang}\".<br />\n"; } reset_language($userlang); $adminStr = translate('Administrator'); // Reset timezone setting for current user. if (!empty($tz[$user])) { $display_tzid = 2; // Display TZ. $user_TIMEZONE = $tz[$user]; } else { if (!empty($def_tz)) { $display_tzid = 2; $user_TIMEZONE = $def_tz; } else { $display_tzid = 3; // Do not use offset & display TZ. // I think this is the only real timezone set to UTC...since 1972 at least. $user_TIMEZONE = 'Africa/Monrovia'; } } // This will allow date functions to use the proper TIMEZONE. set_env('TZ', $user_TIMEZONE); $useHtml = !empty($htmlmail[$user]) ? 'Y' : 'N'; $padding = !empty($htmlmail[$user]) ? ' ' : ' '; $body = str_replace('XXX', $is_task ? translate('task') : translate('event'), translate('This is a reminder for the XXX detailed below.')) . "\n\n"; $create_by = $row[0]; $event_time = date_to_epoch($row[1] . ($row[2] != -1 ? sprintf("%06d", $row[2]) : '')); $name = $row[9]; $description = $row[10]; // Add trailing '/' if not found in server_url. // Don't include link for External users. if (!empty($SERVER_URL) && !$isExt) { $eventURL = $SERVER_URL . (substr($SERVER_URL, -1, 1) == '/' ? '' : '/') . 'view_entry.php?id=' . $id . '&em=1'; if ($useHtml == 'Y') { $eventURL = activate_urls($eventURL); } $body .= $eventURL . "\n\n"; } $body .= strtoupper($name) . "\n\n" . translate('Description') . ":\n" . $padding . $description . "\n" . ($is_task ? translate('Start Date') : translate('Date')) . ': ' . date_to_str($row[2] > 0 ? date('Ymd', $event_date) : gmdate('Ymd', $event_date)) . "\n" . ($row[2] > 0 ? ($is_task ? translate('Start Time') : translate('Time')) . ': ' . display_time('', $display_tzid, $event_time, $userTformat) . "\n" : ($row[2] == 0 && ($row[5] = 1440) ? translate('Time') . ': ' . translate('All day event') . "\n" : '')) . ($row[5] > 0 && !$is_task ? translate('Duration') . ': ' . $row[5] . ' ' . translate('minutes') . "\n" : ($is_task ? translate('Due Date') . ': ' . date_to_str($row[11]) . "\n" . translate('Due Time') . ': ' . display_time($row[12], $display_tzid, '', $userTformat) . "\n" : '')) . ($is_task && isset($percentage[$user]) ? translate('Pecentage Complete') . ': ' . $percentage[$user] . "%\n" : '') . (empty($DISABLE_PRIORITY_FIELD) || $DISABLE_PRIORITY_FIELD != 'Y' ? translate('Priority') . ': ' . $row[6] . '-' . $pri[ceil($row[6] / 3)] . "\n" : ''); if (empty($DISABLE_ACCESS_FIELD) || $DISABLE_ACCESS_FIELD != 'Y') { $body .= translate('Access') . ': '; if ($row[8] == 'C') { $body .= translate('Confidential') . "\n"; } elseif ($row[8] == 'P') { $body .= translate('Public') . "\n"; } elseif ($row[8] == 'R') { $body .= translate('Private') . "\n"; } } $body .= (!empty($single_user_login) && !$single_user_login ? translate('Created by') . ': ' . $row[0] . "\n" : '') . translate('Updated') . ': ' . date_to_str($row[3]) . ' ' . display_time($row[3] . sprintf("%06d", $row[4]), $display_tzid, '', $userTformat) . "\n"; // Site extra fields. $extras = get_site_extra_fields($id); $site_extracnt = count($site_extras); for ($i = 0; $i < $site_extracnt; $i++) { if ($site_extras[$i] == 'FIELDSET') { continue; } $extra_name = $site_extras[$i][0]; $extra_descr = $site_extras[$i][1]; $extra_type = $site_extras[$i][2]; $extra_arg1 = $site_extras[$i][3]; $extra_arg2 = $site_extras[$i][4]; if (!empty($site_extras[$i][5])) { $extra_view = $site_extras[$i][5] & EXTRA_DISPLAY_REMINDER; } if (!empty($extras[$extra_name]['cal_name']) && $extras[$extra_name]['cal_name'] != '' && !empty($extra_view)) { $val = ''; $body .= $extra_descr; if ($extra_type == EXTRA_DATE) { $body .= ': ' . $extras[$extra_name]['cal_date'] . "\n"; } elseif ($extra_type == EXTRA_MULTILINETEXT) { $body .= "\n" . $padding . $extras[$extra_name]['cal_data'] . "\n"; } elseif ($extra_type == EXTRA_RADIO) { $body .= ': ' . $extra_arg1[$extras[$extra_name]['cal_data']] . "\n"; } else { // Default method for EXTRA_URL, EXTRA_TEXT, etc... $body .= ': ' . $extras[$extra_name]['cal_data'] . "\n"; } } } if ((empty($single_user) || $single_user != 'Y') && (empty($DISABLE_PARTICIPANTS_FIELD) || $DISABLE_PARTICIPANTS_FIELD != 'N')) { $body .= translate('Participants') . ":\n"; for ($i = 0; $i < $partcnt; $i++) { $body .= $padding . $names[$participants[$i]] . "\n"; } for ($i = 0; $i < $ext_partcnt; $i++) { $body .= $padding . $ext_participants[$i] . ' ( ' . translate('External User') . ")\n"; } } $subject = translate('Reminder') . ': ' . stripslashes($name); if ($debug) { echo "Sending mail to {$recip} (in {$userlang}).<br />\n"; } if ($only_testing) { if ($debug) { echo '<hr /> <pre> To: ' . $recip . ' Subject: ' . $subject . ' From:' . $adminStr . ' ' . $body . ' </pre> '; } } else { $mail = new WebCalMailer(); user_load_variables($user, 'temp'); $recipName = $isExt ? $user : $GLOBALS['tempfullname']; // Send ics attachment to External Users or // or users who explicitly chose to receive it. $attach = $isExt || isset($attachics[$user]) ? $id : ''; $mail->WC_Send($adminStr, $recip, $recipName, $subject, $body, $useHtml, $GLOBALS['EMAIL_FALLBACK_FROM'], $attach); $cal_text = ($isExt ? translate('External User') : '') . $recipName; activity_log($id, 'system', $user, LOG_REMINDER, $cal_text); } } }
// This error should get caught before here anyhow, // so no need to translate this. This is just in case. :-) $error = 'Invalid characters in login.'; } else { if (empty($user)) { // Username cannot be blank. This is currently the only place // that calls addUser that is located in $user_inc. $error = $blankUserStr; } else { user_add_user($user, $upassword1, $ufirstname, $ulastname, $uemail, $uis_admin, $u_enabled); activity_log(0, $login, $user, LOG_USER_ADD, "{$ufirstname} {$ulastname}" . (empty($uemail) ? '' : " <{$uemail}>")); } } } } else { if (!empty($add) && !access_can_access_function(ACCESS_USER_MANAGEMENT)) { $error = print_not_auth(15); } else { // Don't allow a user to change themself to an admin by setting // uis_admin in the URL by hand. They must be admin beforehand. if (!$is_admin) { $uis_admin = 'N'; } user_update_user($user, $ufirstname, $ulastname, $uemail, $uis_admin, $uenabled); activity_log(0, $login, $user, LOG_USER_UPDATE, "{$ufirstname} {$ulastname}" . (empty($uemail) ? '' : " <{$uemail}>")); } } } } } echo error_check('users.php', false);
// logged in) if $REMEMBER_LAST_LOGIN is set to "Y" (in admin.php). if (!empty($remember) && $remember == 'yes') { SetCookie('webcalendar_login', $login, time() + 24 * 3600 * 365, $cookie_path); } else { SetCookie('webcalendar_login', $login, 0, $cookie_path); } if (!empty($GLOBALS['newUserUrl'])) { $url = $GLOBALS['newUserUrl']; } do_redirect($url); } else { // Invalid login if (empty($error) || !$showLoginFailureReason) { $error = translate('Invalid login', true); } activity_log(0, 'system', '', LOG_LOGIN_FAILURE, translate('Username') . ": " . $login . ", IP: " . $_SERVER['REMOTE_ADDR']); } } else { // No login info... just present empty login page //$error = "Start"; } // delete current user SetCookie('webcalendar_session', '', 0, $cookie_path); // In older versions the cookie path had no trailing slash and NS 4.78 // thinks "path/" and "path" are different, so the line above does not // delete the "old" cookie. This prohibits the login. So we delete the // cookie with the trailing slash removed if (substr($cookie_path, -1) == '/') { SetCookie('webcalendar_session', '', 0, substr($cookie_path, 0, -1)); } }
if ($send_user_mail == "Y" && strlen($tempemail) && $send_email != "N") { if ($GLOBALS['LANGUAGE'] != $user_language && !empty($user_language) && $user_language != 'none') { reset_language($user_language); } $msg = translate("Hello") . ", " . $tempfullname . ".\n\n" . translate("An appointment has been rejected by") . " " . $login_fullname . ". " . translate("The subject was") . " \"" . $name . " \"\n" . translate("The description is") . " \"" . $description . "\"\n" . translate("Date") . ": " . date_to_str($fmtdate) . "\n" . (empty($hour) && empty($minute) ? "" : translate("Time") . ": " . display_time($hour * 10000 + $minute * 100)) . "\n\n\n"; if (!empty($server_url)) { $url = $server_url . "view_entry.php?id=" . $id; $msg .= "\n\n" . $url; } $from = $email_fallback_from; if (strlen($login_email)) { $from = $login_email; } $extra_hdrs = "From: {$from}\r\nX-Mailer: " . translate("Title"); mail($tempemail, translate($application_name) . " " . translate("Notification") . ": " . $name, html_to_8bits($msg), $extra_hdrs); activity_log($id, $login, $partlogin[$i], $LOG_NOTIFICATION, "Event rejected by {$app_user}"); } } } if (empty($error)) { if ($ret == "list") { do_redirect("list_unapproved.php?user={$app_user}"); } else { do_redirect("view_entry.php?id={$id}&user={$app_user}"); } exit; } print_header(); echo "<h2>" . translate("Error") . "</h2>\n"; echo "<p>" . $error . "</p>\n"; print_trailer();
if ($is_admin || $my_event || $can_edit && $is_assistant || access_is_enabled() && access_user_calendar('edit', $user)) { $del_user = $user; } else { // Error: user cannot delete from other user's calendar. $error = print_not_auth(6); } } if (empty($error)) { if ($override_repeat) { dbi_execute('INSERT INTO webcal_entry_repeats_not ( cal_id, cal_date, cal_exdate ) VALUES ( ?, ?, ? )', array($id, $date, 1)); // Should we log this to the activity log??? } else { dbi_execute('UPDATE webcal_entry_user SET cal_status = ? WHERE cal_id = ? AND cal_login = ?', array('D', $id, $del_user)); activity_log($id, $login, $login, $log_reject, ''); } } } } $ret = getValue('ret'); $return_view = get_last_view(); if (!empty($ret)) { if ($ret == 'listall') { $url = 'list_unapproved.php'; } else { if ($ret == 'list') { $url = 'list_unapproved.php' . (empty($user) ? '' : '?user=' . $user); } } } else {
load_user_preferences(); load_user_layers(); load_user_categories(); include "includes/translate.php"; $error = ""; // Allow administrators to approve public events if ($public_access == "Y" && !empty($public) && $is_admin) { $app_user = "******"; } else { $app_user = $login; } if ($id > 0) { if (!dbi_query("UPDATE webcal_entry_user SET cal_status = 'A' " . "WHERE cal_login = '******' AND cal_id = {$id}")) { $error = translate("Error approving event") . ": " . dbi_error(); } else { activity_log($id, $login, $app_user, $LOG_APPROVE, ""); } // Update any extension events related to this one. $res = dbi_query("SELECT cal_id FROM webcal_entry " . "WHERE cal_ext_for_id = {$id}"); if ($res) { if ($row = dbi_fetch_row($res)) { $ext_id = $row[0]; if (!dbi_query("UPDATE webcal_entry_user SET cal_status = 'A' " . "WHERE cal_login = '******' AND cal_id = {$ext_id}")) { $error = translate("Error approving event") . ": " . dbi_error(); } } dbi_free_result($res); } } if ($ret == "list") { do_redirect("list_unapproved.php");
function lcs_import_data($data, $overwrite, $type) { global $login, $count_con, $count_suc, $error_num, $ImportType; global $single_user, $single_user_login, $numDeleted, $errormsg; global $ALLOW_CONFLICTS, $ALLOW_CONFLICT_OVERRIDE, $H2COLOR; global $calUser, $sqlLog, $message; $oldUIDs = array(); $oldIds = array(); $firstEventId = $count_suc = 0; $ImportType = 'ICAL'; // $importId = -1; $importId = 1; $subType = ''; if ($type == 'icalclient') { $ImportType = 'ICAL'; $type = 'ical'; $subType = 'icalclient'; } else { if ($type == 'remoteics' || $type == 'hcal') { $ImportType = 'RMTICS'; $type = 'rmtics'; $subType = 'remoteics'; } } if ($overwrite) { //on efface tous les evenement edt du user //recherche du cat_id $res = dbi_execute('SELECT cat_id FROM webcal_categories WHERE cat_owner = ? AND cat_name = ?', array($login, 'EDT')); if ($res) { if ($row = dbi_fetch_row($res)) { $id_cat = $row[0]; } dbi_free_result($res); } //recherche des cal_id $res = dbi_execute('SELECT cal_id FROM webcal_entry_categories WHERE cat_id = ' . $id_cat); if ($res) { $i = 0; while ($row = dbi_fetch_row($res)) { $id_cals[$i] = $row[0]; $i++; } dbi_free_result($res); } $message .= 'Evénements supprimés : ' . count($id_cals) . '<br />'; if (isset($id_cals)) { foreach ($id_cals as $id_cals) { // Delete event for this user dbi_execute('DELETE FROM webcal_entry WHERE cal_id = ?', array($id_cals)); dbi_execute('DELETE FROM webcal_entry_user WHERE cal_id = ?', array($id_cals)); dbi_execute('DELETE FROM webcal_import_data WHERE cal_id = ?', array($id_cals)); dbi_execute('DELETE FROM webcal_entry_log WHERE cal_entry_id = ?', array($id_cals)); } } dbi_execute('DELETE FROM webcal_entry_categories WHERE cat_id = ' . $id_cat); } // Generate a unique import id $res = dbi_execute('SELECT MAX(cal_import_id) FROM webcal_import'); if ($res) { if ($row = dbi_fetch_row($res)) { $importId = $row[0] + 1; } dbi_free_result($res); } $sql = 'INSERT INTO webcal_import ( cal_import_id, cal_name, cal_date, cal_type, cal_login ) VALUES ( ?, NULL, ?, ?, ? )'; if (!dbi_execute($sql, array($importId, date('Ymd'), $type, $login))) { $errormsg = db_error(); $my_errormsg .= db_error(); return; } if (!is_array($data)) { return false; } foreach ($data as $Entry) { // do_debug ( "Entry Array " . print_r ( $Entry, true ) ); $participants[0] = $calUser; // $participants[0] = $login; $Entry['start_date'] = gmdate('Ymd', $Entry['StartTime']); $Entry['start_time'] = gmdate('His', $Entry['StartTime']); $Entry['end_date'] = gmdate('Ymd', $Entry['EndTime']); $Entry['end_time'] = gmdate('His', $Entry['EndTime']); // not in icalclient if ($overwrite && !empty($Entry['UID'])) { if (empty($oldUIDs[$Entry['UID']])) { $oldUIDs[$Entry['UID']] = 1; } else { $oldUIDs[$Entry['UID']]++; } } // Check for untimed if (!empty($Entry['Untimed']) && $Entry['Untimed'] == 1) { $Entry['start_time'] = 0; } // Check for all day if (!empty($Entry['AllDay']) && $Entry['AllDay'] == 1) { $Entry['start_time'] = 0; $Entry['end_time'] = 0; $Entry['Duration'] = '1440'; } $priority = !empty($Entry['Priority']) ? $Entry['Priority'] : 5; if (!empty($Entry['Completed'])) { $cal_completed = substr($Entry['Completed'], 0, 8); } else { $cal_completed = ''; } if (strlen($cal_completed < 8)) { $cal_completed = ''; } $months = !empty($Entry['Repeat']['ByMonth']) ? $Entry['Repeat']['ByMonth'] : ''; $updateMode = false; // See if event already is there from prior import. // The same UID is used for all events imported at once with iCal. // So, we still don't have enough info to find the exact // event we want to replace. We could just delete all // existing events that correspond to the UID. // NOTE:(cek) commented out 'publish'. Will not work if event // was originally created from importing. if (!empty($Entry['UID'])) { $res = dbi_execute('SELECT wid.cal_id ' . 'FROM webcal_import_data wid, webcal_entry_user weu WHERE ' . 'wid.cal_id = weu.cal_id AND ' . 'weu.cal_login = ? AND ' . 'cal_external_id = ?', array($login, $Entry['UID'])); if ($res) { if ($row = dbi_fetch_row($res)) { if (!empty($row[0])) { $id = $row[0]; $updateMode = true; // update rather than add a new event } } } } if (!$updateMode && $subType != 'icalclient' && $subType != 'remoteics') { // first check for any schedule conflicts if ($ALLOW_CONFLICT_OVERRIDE == 'N' && $ALLOW_CONFLICTS == 'N' && $Entry['Duration'] != 0) { $ex_days = array(); if (!empty($Entry['Repeat']['Exceptions'])) { foreach ($Entry['Repeat']['Exceptions'] as $ex_date) { $ex_days[] = gmdate('Ymd', $ex_date); } } $inc_days = array(); if (!empty($Entry['Repeat']['Inclusions'])) { foreach ($Entry['Repeat']['Inclusions'] as $inc_date) { $inc_days[] = gmdate('Ymd', $inc_date); } } // test if all Repeat Elements exist $rep_interval = !empty($Entry['Repeat']['Interval']) ? $Entry['Repeat']['Interval'] : ''; $rep_bymonth = !empty($Entry['Repeat']['ByMonth']) ? $Entry['Repeat']['ByMonth'] : ''; $rep_byweekno = !empty($Entry['Repeat']['ByWeekNo']) ? $Entry['Repeat']['ByWeekNo'] : ''; $rep_byyearday = !empty($Entry['Repeat']['ByYearDay']) ? $Entry['Repeat']['ByYearDay'] : ''; $rep_byweekno = !empty($Entry['Repeat']['ByWeekNo']) ? $Entry['Repeat']['ByWeekNo'] : ''; $rep_byweekno = !empty($Entry['Repeat']['ByWeekNo']) ? $Entry['Repeat']['ByWeekNo'] : ''; $rep_byweekno = !empty($Entry['Repeat']['ByWeekNo']) ? $Entry['Repeat']['ByWeekNo'] : ''; $rep_bymonthday = !empty($Entry['Repeat']['ByMonthDay']) ? $Entry['Repeat']['ByMonthDay'] : ''; $rep_byday = !empty($Entry['Repeat']['ByDay']) ? $Entry['Repeat']['ByDay'] : ''; $rep_bysetpos = !empty($Entry['Repeat']['BySetPos']) ? $Entry['Repeat']['BySetPos'] : ''; $rep_count = !empty($Entry['Repeat']['Count']) ? $Entry['Repeat']['Count'] : ''; $rep_until = !empty($Entry['Repeat']['Until']) ? $Entry['Repeat']['Until'] : ''; $rep_wkst = !empty($Entry['Repeat']['Wkst']) ? $Entry['Repeat']['Wkst'] : ''; $dates = get_all_dates($Entry['StartTime'], RepeatType($Entry['Repeat']['Frequency']), $rep_interval, array($rep_bymonth, $rep_byweekno, $rep_byyearday, $rep_bymonthday, $rep_byday, $rep_bysetpos), $rep_count, $rep_until, $rep_wkst, $ex_days, $inc_days); $overlap = check_for_conflicts($dates, $Entry['Duration'], $Entry['StartTime'], $participants, $login, 0); } } //end $subType != 'icalclient' && != 'remoteics' if (empty($error)) { if (!$updateMode) { // Add the Event $res = dbi_execute('SELECT MAX(cal_id) FROM webcal_entry'); if ($res) { $row = dbi_fetch_row($res); $id = $row[0] + 1; dbi_free_result($res); } else { $id = 1; } } // not in icalclient if ($firstEventId == 0) { $firstEventId = $id; } $names = array(); $values = array(); $names[] = 'cal_id'; $values[] = $id; if (!$updateMode) { $names[] = 'cal_create_by'; $values[] = $ImportType == 'RMTICS' ? $calUser : $login; } $names[] = 'cal_date'; $values[] = $Entry['start_date']; $names[] = 'cal_time'; $values[] = !empty($Entry['Untimed']) && $Entry['Untimed'] == 1 ? '-1' : $Entry['start_time']; $names[] = 'cal_mod_date'; $values[] = gmdate('Ymd'); $names[] = 'cal_mod_time'; $values[] = gmdate('Gis'); $names[] = 'cal_duration'; $values[] = sprintf("%d", $Entry['Duration']); $names[] = 'cal_priority'; $values[] = $priority; if (!empty($Entry['Class'])) { $names[] = 'cal_access'; $entryclass = $Entry['Class']; $values[] = $entryclass; } if (!empty($Entry['Location'])) { $names[] = 'cal_location'; $entryclass = $Entry['Location']; $values[] = $entryclass; } if (!empty($Entry['URL'])) { $names[] = 'cal_url'; $entryclass = $Entry['URL']; $values[] = $entryclass; } if (!empty($cal_completed)) { $names[] = 'cal_completed'; $values[] = $cal_completed; } if (!empty($Entry['Due'])) { $names[] = 'cal_due_date'; $values[] = sprintf("%d", substr($Entry['Due'], 0, 8)); $names[] = 'cal_due_time'; $values[] = sprintf("%d", substr($Entry['Due'], 9, 6)); } if (!empty($Entry['CalendarType'])) { $names[] = 'cal_type'; if ($Entry['CalendarType'] == 'VEVENT' || $Entry['CalendarType'] == 'VFREEBUSY') { $values[] = !empty($Entry['Repeat']) ? 'M' : 'E'; } else { if ($Entry['CalendarType'] == 'VTODO') { $values[] = !empty($Entry['Repeat']) ? 'N' : 'T'; } } } if (strlen($Entry['Summary']) == 0) { $Entry['Summary'] = translate('Unnamed Event'); } if (empty($Entry['Description'])) { $Entry['Description'] = $Entry['Summary']; } $Entry['Summary'] = str_replace("\\n", "\n", $Entry['Summary']); $Entry['Summary'] = str_replace("\\'", "'", $Entry['Summary']); $Entry['Summary'] = str_replace("\\\"", "\"", $Entry['Summary']); $Entry['Summary'] = str_replace("'", "\\'", $Entry['Summary']); $names[] = 'cal_name'; $values[] = $Entry['Summary']; $Entry['Description'] = str_replace("\\n", "\n", $Entry['Description']); $Entry['Description'] = str_replace("\\'", "'", $Entry['Description']); $Entry['Description'] = str_replace("\\\"", "\"", $Entry['Description']); $Entry['Description'] = str_replace("'", "\\'", $Entry['Description']); // added these to try and compensate for Sunbird escaping html $Entry['Description'] = str_replace("\\;", ";", $Entry['Description']); $Entry['Description'] = str_replace("\\,", ",", $Entry['Description']); // Mozilla will send this goofy string, so replace it with real html $Entry['Description'] = str_replace('=0D=0A=', '<br />', $Entry['Description']); $Entry['Description'] = str_replace('=0D=0A', '', $Entry['Description']); // Allow option to not limit description size // This will only be practical for mysql and MSSQL/Postgres as // these do not have limits on the table definition // TODO Add this option to preferences if (empty($LIMIT_DESCRIPTION_SIZE) || $LIMIT_DESCRIPTION_SIZE == 'Y') { // limit length to 1024 chars since we setup tables that way if (strlen($Entry['Description']) >= 1024) { $Entry['Description'] = substr($Entry['Description'], 0, 1019) . '...'; } } $names[] = 'cal_description'; $values[] = $Entry['Description']; // do_debug ( "descr='" . $Entry['Description'] . "'" ); $sql_params = array(); $namecnt = count($names); if ($updateMode) { $sql = 'UPDATE webcal_entry SET '; for ($f = 0; $f < $namecnt; $f++) { if ($f > 0) { $sql .= ', '; } $sql .= $names[$f] . ' = ?'; $sql_params[] = $values[$f]; } $sql .= ' WHERE cal_id = ?'; $sql_params[] = $id; } else { $string_names = ''; $string_values = ''; for ($f = 0; $f < $namecnt; $f++) { if ($f > 0) { $string_names .= ', '; $string_values .= ', '; } $string_names .= $names[$f]; $string_values .= '?'; $sql_params[] = $values[$f]; } $sql = 'INSERT INTO webcal_entry ( ' . $string_names . ' ) VALUES ( ' . $string_values . ' )'; } //do_debug ( date("H:i:s")." entry SQL> $sql" ); if (empty($error)) { if (!dbi_execute($sql, $sql_params)) { $error .= db_error(); // do_debug ( $error ); break; } else { if ($ImportType == 'RMTICS') { $count_suc++; } } } // log add/update if ($Entry['CalendarType'] == 'VTODO') { activity_log($id, $login, $calUser, $updateMode ? LOG_UPDATE_T : LOG_CREATE_T, 'Import from ' . $ImportType); } else { activity_log($id, $login, $calUser, $updateMode ? LOG_UPDATE : LOG_CREATE, 'Import from ' . $ImportType); } // not in icalclient if ($single_user == 'Y') { $participants[0] = $single_user_login; } // Now add to webcal_import_data if (!$updateMode) { // only in icalclient // add entry to webcal_import and webcal_import_data $uid = generate_uid($id); $uid = empty($Entry['UID']) ? $uid : $Entry['UID']; if ($importId < 0) { $importId = create_import_instance(); } if ($ImportType == 'PALMDESKTOP') { $sql = 'INSERT INTO webcal_import_data ( cal_import_id, cal_id, cal_login, cal_import_type, cal_external_id ) VALUES ( ?, ?, ?, ?, ? )'; $sqlLog .= $sql . "<br />\n"; if (!dbi_execute($sql, array($importId, $id, $calUser, 'palm', $Entry['RecordID']))) { $error = db_error(); break; } } else { if ($ImportType == 'VCAL') { $uid = empty($Entry['UID']) ? null : $Entry['UID']; if (strlen($uid) > 200) { $uid = null; } $sql = 'INSERT INTO webcal_import_data ( cal_import_id, cal_id, cal_login, cal_import_type, cal_external_id ) VALUES ( ?, ?, ?, ?, ? )'; $sqlLog .= $sql . "<br />\n"; if (!dbi_execute($sql, array($importId, $id, $calUser, 'vcal', $uid))) { $error = db_error(); break; } } else { if ($ImportType == 'ICAL') { $uid = empty($Entry['UID']) ? null : $Entry['UID']; // This may cause problems if (strlen($uid) > 200) { $uid = substr($uid, 0, 200); } $sql = 'INSERT INTO webcal_import_data ( cal_import_id, cal_id, cal_login, cal_import_type, cal_external_id ) VALUES ( ?, ?, ?, ?, ? )'; $sqlLog .= $sql . "<br />\n"; if (!dbi_execute($sql, array($importId, $id, $calUser, 'ical', $uid))) { $error = db_error(); break; } } } } } // Now add participants $status = !empty($Entry['Status']) ? $Entry['Status'] : 'A'; $percent = !empty($Entry['Percent']) ? $Entry['Percent'] : '0'; if (!$updateMode) { $sql = 'INSERT INTO webcal_entry_user ( cal_id, cal_login, cal_status, cal_percent ) VALUES ( ?, ?, ?, ? )'; //( date("H:i:s")."add part SQL> $sql" ); if (!dbi_execute($sql, array($id, $participants[0], $status, $percent))) { $error = db_error(); // do_debug ( "Error: " . $error ); break; } } else { // ( date("H:i:s")." up part SQL> $sql" ); $sql = 'UPDATE webcal_entry_user SET cal_status = ? WHERE cal_id = ?'; if (!dbi_execute($sql, array($status, $id))) { $error = db_error(); // do_debug ( "Error: " . $error ); break; } // update percentage only if set if ($percent != '') { $sql = 'UPDATE webcal_entry_user SET cal_percent = ? WHERE cal_id = ?'; if (!dbi_execute($sql, array($percent, $id))) { $error = db_error(); // do_debug ( "Error: " . $error ); break; } } dbi_execute('DELETE FROM webcal_entry_categories WHERE cal_id = ?', array($id)); } // update Categories if (!empty($Entry['Categories'])) { $cat_ids = $Entry['Categories']; $cat_order = 1; foreach ($cat_ids as $cat_id) { $sql = 'INSERT INTO webcal_entry_categories ( cal_id, cat_id, cat_order, cat_owner ) VALUES ( ?, ?, ?, ? )'; if (!dbi_execute($sql, array($id, $cat_id, $cat_order++, $login))) { $error = db_error(); // do_debug ( "Error: " . $error ); break; } } } // Add repeating info if ($updateMode) { // remove old repeating info dbi_execute('DELETE FROM webcal_entry_repeats WHERE cal_id = ?', array($id)); dbi_execute('DELETE FROM webcal_entry_repeats_not WHERE cal_id = ?', array($id)); } $names = array(); $values = array(); if (!empty($Entry['Repeat']['Frequency'])) { $names[] = 'cal_id'; $values[] = $id; $names[] = 'cal_type'; $values[] = RepeatType($Entry['Repeat']['Frequency']); $names[] = 'cal_frequency'; $values[] = !empty($Entry['Repeat']['Interval']) ? $Entry['Repeat']['Interval'] : 1; if (!empty($Entry['Repeat']['ByMonth'])) { $names[] = 'cal_bymonth'; $values[] = $Entry['Repeat']['ByMonth']; } if (!empty($Entry['Repeat']['ByMonthDay'])) { $names[] = 'cal_bymonthday'; $values[] = $Entry['Repeat']['ByMonthDay']; } if (!empty($Entry['Repeat']['ByDay'])) { $names[] = 'cal_byday'; $values[] = $Entry['Repeat']['ByDay']; } if (!empty($Entry['Repeat']['BySetPos'])) { $names[] = 'cal_bysetpos'; $values[] = $Entry['Repeat']['BySetPos']; } if (!empty($Entry['Repeat']['ByWeekNo'])) { $names[] = 'cal_byweekno'; $values[] = $Entry['Repeat']['ByWeekNo']; } if (!empty($Entry['Repeat']['ByYearDay'])) { $names[] = 'cal_byyearday'; $values[] = $Entry['Repeat']['ByYearDay']; } if (!empty($Entry['Repeat']['Wkst'])) { $names[] = 'cal_wkst'; $values[] = $Entry['Repeat']['Wkst']; } if (!empty($Entry['Repeat']['Count'])) { $names[] = 'cal_count'; $values[] = $Entry['Repeat']['Count']; } if (!empty($Entry['Repeat']['Until'])) { $REND = localtime($Entry['Repeat']['Until']); if (!empty($Entry['Repeat']['Count'])) { // Get end time from DTSTART $RENDTIME = $Entry['start_time']; } else { $RENDTIME = gmdate('His', $Entry['Repeat']['Until']); } $names[] = 'cal_end'; $values[] = gmdate('Ymd', $Entry['Repeat']['Until']); // if ( $RENDTIME != '000000' ) { $names[] = 'cal_endtime'; $values[] = $RENDTIME; // } } $string_names = ''; $string_values = ''; $sql_params = array(); $namecnt = count($names); for ($f = 0; $f < $namecnt; $f++) { if ($f > 0) { $string_names .= ', '; $string_values .= ', '; } $string_names .= $names[$f]; $string_values .= '?'; $sql_params[] = $values[$f]; } $sql = 'INSERT INTO webcal_entry_repeats ( ' . $string_names . ' ) VALUES ( ' . $string_values . ' )'; if (!dbi_execute($sql, $sql_params)) { $error = 'Unable to add to webcal_entry_repeats: ' . dbi_error() . "<br /><br />\n<b>SQL:</b> {$sql}"; break; } // Repeating Exceptions... if (!empty($Entry['Repeat']['Exceptions'])) { foreach ($Entry['Repeat']['Exceptions'] as $ex_date) { $ex_date = gmdate('Ymd', $ex_date); $sql = 'INSERT INTO webcal_entry_repeats_not ( cal_id, cal_date, cal_exdate ) VALUES ( ?,?,? )'; if (!dbi_execute($sql, array($id, $ex_date, 1))) { $error = 'Unable to add to webcal_entry_repeats_not: ' . dbi_error() . "<br /><br />\n<b>SQL:</b> {$sql}"; break; } } } // Repeating Inclusions... if (!empty($Entry['Repeat']['Inclusions'])) { foreach ($Entry['Repeat']['Inclusions'] as $inc_date) { $inc_date = gmdate('Ymd', $inc_date); $sql = 'INSERT INTO webcal_entry_repeats_not ( cal_id, cal_date, cal_exdate ) VALUES ( ?,?,? )'; if (!dbi_execute($sql, array($id, $inc_date, 0))) { $error = 'Unable to add to webcal_entry_repeats_not: ' . dbi_error() . "<br /><br />\n<b>SQL:</b> {$sql}"; break; } } } } // End Repeat // Add Alarm info if ($updateMode) { dbi_execute('DELETE FROM webcal_reminders WHERE cal_id = ?', array($id)); } if (!empty($Entry['AlarmSet']) && $Entry['AlarmSet'] == 1) { $names = array(); $values = array(); $names[] = 'cal_id'; $values[] = $id; if (!empty($Entry['ADate'])) { $names[] = 'cal_date'; $values[] = $Entry['ADate']; } if (!empty($Entry['AOffset'])) { $names[] = 'cal_offset'; $values[] = $Entry['AOffset']; } if (!empty($Entry['ADuration'])) { $names[] = 'cal_duration'; $values[] = $Entry['ADuration']; } if (!empty($Entry['ARepeat'])) { $names[] = 'cal_repeats'; $values[] = $Entry['ARepeat']; } if (!empty($Entry['ABefore'])) { $names[] = 'cal_before'; $values[] = $Entry['ABefore']; } if (!empty($Entry['ARelated'])) { $names[] = 'cal_related'; $values[] = $Entry['ARelated']; } if (!empty($Entry['AAction'])) { $names[] = 'cal_action'; $values[] = $Entry['AAction']; } $string_names = ''; $string_values = ''; $sql_params = array(); $namecnt = count($names); for ($f = 0; $f < $namecnt; $f++) { if ($f > 0) { $string_names .= ', '; $string_values .= ', '; } $string_names .= $names[$f]; $string_values .= '?'; $sql_params[] = $values[$f]; } $sql = 'INSERT INTO webcal_reminders (' . $string_names . ' ) ' . ' VALUES ( ' . $string_values . ' )'; if (!dbi_execute($sql, $sql_params)) { $error = db_error(); } } } // here to end not in icalclient if ($subType != 'icalclient' && $subType != 'remoteics') { if (!empty($error) && empty($overlap)) { $error_num++; echo print_error($error) . "\n<br />\n"; } if ($Entry['Duration'] > 0) { $time = trim(display_time('', 0, $Entry['StartTime']) . '-' . display_time('', 2, $Entry['EndTime'])); } // Conflicting if (!empty($overlap)) { $message .= '<b><h2>' . translate('Scheduling Conflict') . ': '; $count_con++; $message .= '</h2></b>'; $dd = date('m-d-Y', $Entry['StartTime']); $Entry['Summary'] = str_replace("''", "'", $Entry['Summary']); $Entry['Summary'] = str_replace("'", "\\'", $Entry['Summary']); $message .= htmlspecialchars($Entry['Summary']); $message .= ' (' . $dd; if (!empty($time)) { $message .= ' ' . $time; } $message .= ")<br />\n"; etranslate('conflicts with the following existing calendar entries'); $message .= ":<ul>\n" . $overlap . "</ul>\n"; } else { // No Conflict if ($count_suc == 0) { //echo '<b><h2>' . //translate ( 'Event Imported' ) . ":</h2></b><br />\n"; } $count_suc++; $dd = $Entry['start_date']; } // Reset Variables $overlap = $error = $dd = $time = ''; } } }
$user_language = get_pref_setting($creator, 'LANGUAGE'); if ($send_user_mail == 'Y' && strlen($tempemail) && $SEND_EMAIL != 'N') { reset_language(empty($user_language) || $user_language == 'none' ? $LANGUAGE : $user_language); // translate ( 'Hello' ) $msg = str_replace('XXX', $tempfullname, translate('Hello, XXX.')) . "\n\n" . str_replace('XXX', $login_fullname, translate('XXX has approved an appointment and added comments.')) . "\n\n" . str_replace('XXX', $name, translate('Subject XXX')) . "\n" . str_replace('XXX', $description, translate('Description XXX')) . "\n" . str_replace('XXX', date_to_str($fmtdate), translate('Date XXX')) . ' ' . (empty($hour) && empty($minute) ? '' : str_replace('XXX', display_time('', 2, $eventstart, get_pref_setting($creator, 'TIME_FORMAT')), translate('Time XXX'))) . "\n"; if (!empty($SERVER_URL)) { // DON'T change & to & here. email will handle it $url = $SERVER_URL . 'view_entry.php?id=' . $id . '&em=1'; if ($htmlmail == 'Y') { $url = activate_urls($url); } $msg .= "\n" . $url; } if (!empty($comments)) { // translate ( 'Comments' ) $msg .= "\n\n" . str_replace('XXX', $comments, translate('Comments XXX')); } $from = strlen($login_email) ? $login_email : $EMAIL_FALLBACK_FROM; // Send mail. $mail->WC_Send($login_fullname, $tempemail, $tempfullname, $name, $msg, $htmlmail, $from); activity_log($id, $login, $creator, LOG_NOTIFICATION, str_replace('XXX', $app_user, translate('Approved w/Comments by XXX.'))); } } // Return to login TIMEZONE. set_env('TZ', $TIMEZONE); if (empty($error) && empty($mailerError)) { do_redirect(!empty($ret) && $ret == 'listall' ? 'list_unapproved.php' : (!empty($ret) && $ret == 'list' ? 'list_unapproved.php?' : 'view_entry.php?id=' . $id . '&') . 'user=' . $app_user); exit; } // Process errors. $mail->MailError($mailerError, $error);
function processViewingBooking($vars) { require_once ABSPATH . WPINC . '/registration.php'; $username = $vars['booked_by']; $useremail = $username; $address = $vars['address']; $datetime = $vars['booking_datetime']; $booked_by_name = $vars['booked_by_name']; $booked_by_phone = $vars['booked_by_phone']; $vars_string = implode($vars, "~~"); activity_log(array('type' => 'viewing', 'entry' => $vars_string)); if ($username && $address && $datetime) { // create account if necessary $user_id = username_exists($username); if (!$user_id) { if (!$booked_by_name) { $booked_by_name = $username; } $random_password = wp_generate_password(12, false); $user_id = wp_insert_user(array('user_login' => $username, 'user_pass' => $random_password, 'user_email' => $useremail, 'display_name' => $booked_by_name, 'role' => 'applicant')); update_user_meta($user_id, 'phone', $booked_by_phone); echo "New account created for " . $useremail . ", ID: " . $user_id; wp_new_user_notification($user_id, $random_password); } else { echo "Account identified for " . $useremail . ", ID: " . $user_id; } // store event $new_event = array(); $new_event['post_title'] = time(); $new_event['post_type'] = 'viewings'; $new_event['post_content'] = 'This is my new viewing.'; $new_event['post_status'] = 'publish'; $new_event['post_author'] = $user_id; $event_id = wp_insert_post($new_event); if ($event_id) { update_post_meta($event_id, "address", $address); update_post_meta($event_id, "datetime", $datetime); } } else { $out = "please send booked_by, address and booking_datetime parameters. I found: "; foreach ($vars as $key => $value) { $out .= $key . ": " . $value . "; "; } echo $out; } }
$data .= fgets($fd, 4096); } } fclose($fd); $comment = getValue('description'); if (!dbi_execute('INSERT INTO webcal_blob ( cal_blob_id, cal_id, cal_login, cal_name, cal_description, cal_size, cal_mime_type, cal_type, cal_mod_date, cal_mod_time, cal_blob ) VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? )', array($nextid, $id, $login, $filename, $description, $filesize, $mimetype, 'A', date('Ymd'), date('His'), NULL))) { $error = db_error(); } else { if (!dbi_update_blob('webcal_blob', 'cal_blob', "cal_blob_id = {$nextid}", $data)) { $error = db_error(); } else { // success! redirect to view event page activity_log($id, $login, $login, LOG_ATTACHMENT, $filename); do_redirect("view_entry.php?id={$id}"); } } } else { die_miserable_death('Unsupported type'); // programmer error } } if (!empty($error)) { print_header(); echo print_error($error); echo print_trailer(); exit; } }
/** * Logout */ function logout() { $this->data['title'] = "Logout"; // Log the logout! $username = $this->ion_auth->user()->row()->username; activity_log("User '{$username}' logged out", 'logout'); // log the user out $logout = $this->ion_auth->logout(); // redirect them to the login page $this->session->set_flashdata('message', $this->ion_auth->messages()); redirect('login', 'refresh'); $this->load->view($this->editor_layout, $data); }
$tempName = trim($ufirstname . ' ' . $ulastname); $msg = str_replace(', XXX.', strlen($tempName) ? ', ' . $tempName . '.' : '.', translate('Hello, XXX.')) . "\n\n" . translate('A new WebCalendar account has been set up for you.') . "\n\n" . str_replace('XXX', $user, translate('Your username is XXX.')) . "\n\n" . str_replace('XXX', $new_pass, translate('Your password is XXX.')) . "\n\n" . str_replace('XXX', $appStr, translate('Please visit XXX to log in and start using your account!')) . "\n"; // Add URL to event, if we can figure it out. if (!empty($SERVER_URL)) { $url = $SERVER_URL . 'login.php'; if ($htmlmail == 'Y') { $url = activate_urls($url); } $msg .= "\n\n" . $url; } $msg .= "\n\n" . translate('You may change your password after logging in the first time.') . "\n\n" . translate('If you received this email in error') . "\n\n"; $adminStr = translate('Administrator', true); $name = $appStr . ' ' . translate('Welcome') . ': ' . $ufirstname; // Send via WebCalMailer class. $mail->WC_Send($adminStr, $uemail, $ufirstname . ' ' . $ulastname, $name, $msg, $htmlmail, $EMAIL_FALLBACK_FROM); activity_log(0, 'system', $user, LOG_NEWUSER_EMAIL, translate('New user via email.')); } } echo send_doctype($appStr); echo ' <script type="text/javascript" src="includes/js/prototype.js"></script> <script type="text/javascript"> var validform = false; function valid_form () { if ( document.selfreg.upassword1.value.length == 0 ) { alert ( "' . translate('You have not entered a password.', true) . '" ); return false; } if ( document.selfreg.user.value.length == 0 ) { alert ( "' . translate('Username cannot be blank.', true) . '" );
function import_data($data, $overwrite, $type) { global $login, $count_con, $count_suc, $error_num, $ImportType, $LOG_CREATE; global $single_user, $single_user_login, $allow_conflicts; global $numDeleted, $errormsg; global $calUser, $H2COLOR, $sqlLog; $oldUIDs = array(); $oldIds = array(); $firstEventId = 0; $importId = 1; // Generate a unique import id $res = dbi_query("SELECT MAX(cal_import_id) FROM webcal_import"); if ($res) { if ($row = dbi_fetch_row($res)) { $importId = $row[0] + 1; } dbi_free_result($res); } $sql = "INSERT INTO webcal_import ( cal_import_id, cal_name, " . "cal_date, cal_type, cal_login ) VALUES ( {$importId}, NULL, " . date("Ymd") . ", '{$type}', '{$login}' )"; if (!dbi_query($sql)) { $errormsg = translate("Database error") . ": " . dbi_error(); return; } foreach ($data as $Entry) { $priority = 2; $participants[0] = $calUser; // Some additional date/time info $START = $Entry['StartTime'] > 0 ? localtime($Entry['StartTime']) : 0; $END = $Entry['EndTime'] > 0 ? localtime($Entry['EndTime']) : 0; $Entry['StartMinute'] = sprintf("%02d", $START[1]); $Entry['StartHour'] = sprintf("%02d", $START[2]); $Entry['StartDay'] = sprintf("%02d", $START[3]); $Entry['StartMonth'] = sprintf("%02d", $START[4] + 1); $Entry['StartYear'] = sprintf("%04d", $START[5] + 1900); $Entry['EndMinute'] = sprintf("%02d", $END[1]); $Entry['EndHour'] = sprintf("%02d", $END[2]); $Entry['EndDay'] = sprintf("%02d", $END[3]); $Entry['EndMonth'] = sprintf("%02d", $END[4] + 1); $Entry['EndYear'] = sprintf("%04d", $END[5] + 1900); if ($overwrite && !empty($Entry['UID'])) { $oldUIDs[$Entry['UID']]++; } // Check for untimed if ($Entry['Untimed'] == 1) { $Entry['StartMinute'] = ''; $Entry['StartHour'] = ''; $Entry['EndMinute'] = ''; $Entry['EndHour'] = ''; } // first check for any schedule conflicts if (empty($allow_conflicts) && $Entry['Duration'] != 0) { $date = mktime(0, 0, 0, $Entry['StartMonth'], $Entry['StartDay'], $Entry['StartYear']); $endt = !empty($Entry['Repeat']['EndTime']) ? $Entry['Repeat']['EndTime'] : 'NULL'; $dayst = !empty($Entry['Repeat']['RepeatDays']) ? $Entry['Repeat']['RepeatDays'] : "nnnnnnn"; $ex_days = array(); if (!empty($Entry['Repeat']['Exceptions'])) { foreach ($Entry['Repeat']['Exceptions'] as $ex_date) { $ex_days[] = date("Ymd", $ex_date); } } $dates = get_all_dates($date, RepeatType($Entry['Repeat']['Interval']), $endt, $dayst, $ex_days, $Entry['Repeat']['Frequency']); $overlap = overlap($dates, $Entry['Duration'], $Entry['StartHour'], $Entry['StartMinute'], $participants, $login, 0); } if (empty($error) && !empty($overlap)) { $error = translate("The following conflicts with the suggested time") . ":<ul>{$overlap}</ul>\n"; } if (empty($error)) { $updateMode = false; // See if event already is there from prior import. // The same UID is used for all events imported at once with iCal. // So, we still don't have enough info to find the exact // event we want to replace. We could just delete all // existing events that correspond to the UID. /************************************************************************ Not sure what to do with this code since I don't know how Palm and vCal use the UID stuff yet... if ( ! empty ( $Entry['UID'] ) ) { $res = dbi_query ( "SELECT webcal_import_data.cal_id " . "FROM webcal_import_data, webcal_entry_user " . "WHERE cal_import_type = 'ical' AND " . "webcal_import_data.cal_id = webcal_entry_user.cal_id AND " . "webcal_entry_user.cal_login = '******' AND " . "cal_external_id = '$Entry[UID]'" ); if ( $res ) { if ( $row = dbi_fetch_row ( $res ) ) { if ( ! empty ( $row[0] ) ) { $id = $row[0]; $updateMode = true; // update rather than add a new event } } } } ************************************************************************/ // Add the Event $res = dbi_query("SELECT MAX(cal_id) FROM webcal_entry"); if ($res) { $row = dbi_fetch_row($res); $id = $row[0] + 1; dbi_free_result($res); } else { $id = 1; //$error = "Unable to select MAX cal_id: " . dbi_error () . "<br /><br />\n<b>SQL:</b> $sql"; //break; } if ($firstEventId == 0) { $firstEventId = $id; } $names = array(); $values = array(); $names[] = 'cal_id'; $values[] = "{$id}"; if (!$updateMode) { $names[] = 'cal_create_by'; $values[] = "'{$login}'"; } $names[] = 'cal_date'; $values[] = sprintf("%04d%02d%02d", $Entry['StartYear'], $Entry['StartMonth'], $Entry['StartDay']); $names[] = 'cal_time'; $values[] = $Entry['Untimed'] == 1 ? "-1" : sprintf("%02d%02d00", $Entry['StartHour'], $Entry['StartMinute']); $names[] = 'cal_mod_date'; $values[] = date("Ymd"); $names[] = 'cal_mod_time'; $values[] = date("Gis"); $names[] = 'cal_duration'; $values[] = sprintf("%d", $Entry['Duration']); $names[] = 'cal_priority'; $values[] = $priority; $names[] = 'cal_access'; $values[] = $Entry['Private'] == 1 ? "'R'" : "'P'"; $names[] = 'cal_type'; $values[] = $Entry['Repeat'] ? "'M'" : "'E'"; if (strlen($Entry['Summary']) == 0) { $Entry['Summary'] = translate("Unnamed Event"); } if (strlen($Entry['Description']) == 0) { $Entry['Description'] = $Entry['Summary']; } $Entry['Summary'] = str_replace("\\n", "\n", $Entry['Summary']); $Entry['Summary'] = str_replace("\\'", "'", $Entry['Summary']); $Entry['Summary'] = str_replace("\\\"", "\"", $Entry['Summary']); $Entry['Summary'] = str_replace("'", "\\'", $Entry['Summary']); $names[] = 'cal_name'; $values[] = "'" . $Entry['Summary'] . "'"; $Entry['Description'] = str_replace("\\n", "\n", $Entry['Description']); $Entry['Description'] = str_replace("\\'", "'", $Entry['Description']); $Entry['Description'] = str_replace("\\\"", "\"", $Entry['Description']); $Entry['Description'] = str_replace("'", "\\'", $Entry['Description']); // limit length to 1024 chars since we setup tables that way if (strlen($Entry['Description']) >= 1024) { $Entry['Description'] = substr($Entry['Description'], 0, 1019) . "..."; } $names[] = 'cal_description'; $values[] = "'" . $Entry['Description'] . "'"; //echo "Summary:<p>" . nl2br ( htmlspecialchars ( $Entry['Summary'] ) ) . "</p>"; //echo "Description:<p>" . nl2br ( htmlspecialchars ( $Entry['Description'] ) ) . "</p>"; exit; if ($updateMode) { $sql = "UPDATE webcal_entry SET "; for ($f = 0; $f < count($names); $f++) { if ($f > 0) { $sql .= ", "; } $sql .= $names[$f] . " = " . $values[$f]; } $sql .= " WHERE cal_id = {$id}"; } else { $sql = "INSERT INTO webcal_entry ( " . implode(", ", $names) . " ) VALUES ( " . implode(", ", $values) . " )"; } if (empty($error)) { $sqlLog .= $sql . "<br />\n"; //echo "SQL: $sql <br />\n"; if (!dbi_query($sql)) { $error .= "<p>" . translate("Database error") . ": " . dbi_error() . "</p>\n"; break; } } // log add/update activity_log($id, $login, $login, $updateMode ? $LOG_UPDATE : $LOG_CREATE, "Import from {$ImportType}"); if ($single_user == "Y") { $participants[0] = $single_user_login; } // Now add to webcal_import_data if (!$updateMode) { if ($ImportType == "PALMDESKTOP") { $sql = "INSERT INTO webcal_import_data ( cal_import_id, cal_id, " . "cal_login, cal_import_type, cal_external_id ) VALUES ( " . "{$importId}, {$id}, '{$calUser}', 'palm', '{$Entry['RecordID']}' )"; $sqlLog .= $sql . "<br />\n"; if (!dbi_query($sql)) { $error = translate("Database error") . ": " . dbi_error(); break; } } else { if ($ImportType == "VCAL") { $uid = empty($Entry['UID']) ? "null" : "'{$Entry['UID']}'"; if (strlen($uid) > 200) { $uid = "NULL"; } $sql = "INSERT INTO webcal_import_data ( cal_import_id, cal_id, " . "cal_login, cal_import_type, cal_external_id ) VALUES ( " . "{$importId}, {$id}, '{$calUser}', 'vcal', {$uid} )"; $sqlLog .= $sql . "<br />\n"; if (!dbi_query($sql)) { $error = translate("Database error") . ": " . dbi_error(); break; } } else { if ($ImportType == "ICAL") { $uid = empty($Entry['UID']) ? "null" : "'{$Entry['UID']}'"; if (strlen($uid) > 200) { $uid = "NULL"; } $sql = "INSERT INTO webcal_import_data ( cal_import_id, cal_id, " . "cal_login, cal_import_type, cal_external_id ) VALUES ( " . "{$importId}, {$id}, '{$calUser}', 'ical', {$uid} )"; $sqlLog .= $sql . "<br />\n"; if (!dbi_query($sql)) { $error = translate("Database error") . ": " . dbi_error(); break; } } } } } // Now add participants if (!$updateMode) { $status = $login == "__public__" ? 'W' : 'A'; if (empty($cat_id)) { $cat_id = 'NULL'; } $sql = "INSERT INTO webcal_entry_user " . "( cal_id, cal_login, cal_status, cal_category ) VALUES ( {$id}, '" . $participants[0] . "', '{$status}', {$cat_id} )"; $sqlLog .= $sql . "<br />\n"; if (!dbi_query($sql)) { $error = translate("Database error") . ": " . dbi_error(); break; } } // Add repeating info if ($updateMode) { // remove old repeating info dbi_query("DELETE FROM webcal_entry_repeats WHERE cal_id = {$id}"); dbi_query("DELETE FROM webcal_entry_repeats_not WHERE cal_id = {$id}"); } if (!empty($Entry['Repeat']['Interval'])) { //while ( list($k,$v) = each ( $Entry['Repeat'] ) ) { // echo "$k: $v <br />\n"; //} $rpt_type = RepeatType($Entry['Repeat']['Interval']); $freq = $Entry['Repeat']['Frequency'] ? $Entry['Repeat']['Frequency'] : 1; if (strlen($Entry['Repeat']['EndTime'])) { $REND = localtime($Entry['Repeat']['EndTime']); $end = sprintf("%04d%02d%02d", $REND[5] + 1900, $REND[4] + 1, $REND[3]); } else { $end = 'NULL'; } $days = !empty($Entry['Repeat']['RepeatDays']) ? "'" . $Entry['Repeat']['RepeatDays'] . "'" : 'NULL'; $sql = "INSERT INTO webcal_entry_repeats ( cal_id, " . "cal_type, cal_end, cal_days, cal_frequency ) VALUES " . "( {$id}, '{$rpt_type}', {$end}, {$days}, {$freq} )"; $sqlLog .= $sql . "<br />\n"; if (!dbi_query($sql)) { $error = "Unable to add to webcal_entry_repeats: " . dbi_error() . "<br /><br />\n<b>SQL:</b> {$sql}"; break; } // Repeating Exceptions... if (!empty($Entry['Repeat']['Exceptions'])) { foreach ($Entry['Repeat']['Exceptions'] as $ex_date) { $ex_date = date("Ymd", $ex_date); $sql = "INSERT INTO webcal_entry_repeats_not ( cal_id, cal_date ) VALUES ( {$id}, {$ex_date} )"; $sqlLog .= $sql . "<br />\n"; if (!dbi_query($sql)) { $error = "Unable to add to webcal_entry_repeats_not: " . dbi_error() . "<br /><br />\n<b>SQL:</b> {$sql}"; break; } } } } // End Repeat // Add Alarm info -> site_extras if ($updateMode) { dbi_query("DELETE FROM webcal_site_extras WHERE cal_id = {$id}"); } if ($Entry['AlarmSet'] == 1) { $RM = $Entry['AlarmAdvanceAmount']; if ($Entry['AlarmAdvanceType'] == 1) { $RM = $RM * 60; } if ($Entry['AlarmAdvanceType'] == 2) { $RM = $RM * 60 * 24; } $sql = "INSERT INTO webcal_site_extras ( cal_id, " . "cal_name, cal_type, cal_remind, cal_data ) VALUES " . "( {$id}, 'Reminder', 7, 1, {$RM} )"; $sqlLog .= $sql . "<br />\n"; if (!dbi_query($sql)) { $error = translate("Database error") . ": " . dbi_error(); } } } if (!empty($error) && empty($overlap)) { $error_num++; echo "<h2>" . translate("Error") . "</h2>\n<blockquote>\n"; echo $error . "</blockquote>\n<br />\n"; } // Conflicting if (!empty($overlap)) { echo "<b><h2>" . translate("Scheduling Conflict") . ": "; $count_con++; echo "</h2></b>"; if ($Entry['Duration'] > 0) { $time = display_time($Entry['StartHour'] . $Entry['StartMinute'] . "00") . " - " . display_time($Entry['EndHour'] . $Entry['EndMinute'] . "00"); } $dd = $Entry['StartMonth'] . "-" . $Entry['StartDay'] . "-" . $Entry['StartYear']; echo "<a class=\"entry\" href=\"view_entry.php?id={$id}"; echo "\" onmouseover=\"window.status='" . translate("View this entry") . "'; return true;\" onmouseout=\"window.status=''; return true;\">"; $Entry['Summary'] = str_replace("''", "'", $Entry['Summary']); $Entry['Summary'] = str_replace("'", "\\'", $Entry['Summary']); echo htmlspecialchars($Entry['Summary']); echo "</a> (" . $dd; $time = trim($time); if (!empty($time)) { echo " " . $time; } echo ")<br />\n"; etranslate("conflicts with the following existing calendar entries"); echo ":<ul>\n" . $overlap . "</ul>\n"; } else { // No Conflict echo "<b><h2>" . translate("Event Imported") . ":</h2></b>\n"; $count_suc++; if ($Entry['Duration'] > 0) { $time = display_time($Entry['StartHour'] . $Entry['StartMinute'] . "00") . " - " . display_time($Entry['EndHour'] . $Entry['EndMinute'] . "00"); } $dateYmd = sprintf("%04d%02d%02d", $Entry['StartYear'], $Entry['StartMonth'], $Entry['StartDay']); $dd = date_to_str($dateYmd); echo "<a class=\"entry\" href=\"view_entry.php?id={$id}"; echo "\" onmouseover=\"window.status='" . translate("View this entry") . "'; return true;\" onmouseout=\"window.status=''; return true;\">"; $Entry['Summary'] = str_replace("''", "'", $Entry['Summary']); $Entry['Summary'] = str_replace("\\", "", $Entry['Summary']); echo htmlspecialchars($Entry['Summary']); echo "</a> (" . $dd; if (!empty($time)) { echo " " . $time; } echo ")<br />\n"; } // Reset Variables $overlap = $error = $dd = $time = ''; } // Mark old events from prior import as deleted. if ($overwrite && count($oldUIDs) > 0) { // We could do this with a single SQL using sub-select, but // I'm pretty sure MySQL does not support it. $old = array_keys($oldUIDs); for ($i = 0; $i < count($old); $i++) { $sql = "SELECT cal_id FROM webcal_import_data WHERE " . "cal_import_type = '{$type}' AND " . "cal_external_id = '{$old[$i]}' AND " . "cal_login = '******' AND " . "cal_id < {$firstEventId}"; $res = dbi_query($sql); if ($res) { while ($row = dbi_fetch_row($res)) { $oldIds[] = $row[0]; } dbi_free_result($res); } else { echo translate("Database error") . ": " . dbi_error() . "<br />\n"; } } for ($i = 0; $i < count($oldIds); $i++) { $sql = "UPDATE webcal_entry_user SET cal_status = 'D' " . "WHERE cal_id = {$oldIds[$i]}"; $sqlLog .= $sql . "<br />\n"; dbi_query($sql); $numDeleted++; } } //echo "<b>SQL:</b><br />\n$sqlLog\n"; }
/** * Push Data Live * * Pushes data to live production. * * Note that by default, the table with the highest version number * will automatically be the production data. Therefore, for example, * if you have variation data stored in tables 'dvd_1', 'dvd_2', and * 'dvd_3', then the 'dvd_3' data will be displayed on the public site. * This function will: * - Copy the current production data (e.g. 'dvd_3') to a new table (e.g. * 'dvd_4'), then update the new table (e.g. 'dvd_4') to reflect the * new changes * - Update the 'versions' table * - Create a new 'variant_count_' table * - Backup the '_queue' table and 'reviews' table * - Clear the '_queue' table and 'reviews' table of variants that were * just released * * By default, only changes that have been confirmed for release are acutally * released. As an optional first parameter, you can turn this setting off * and release all changes regardless of confirmation status. To do this, * pass in FALSE for the first parameter. * * @author Sean Ephraim * @access public * @param boolean $confirmed_only * (optional) Only release confirmed variants? * @return boolean TRUE on success, else FALSE */ public function push_data_live($confirmed_only = TRUE) { // Set unlimited memory/time when retrieving all variants in the queue (queue could be quite large) ini_set('memory_limit', '-1'); set_time_limit(0); // Get all variants to update $new_records = $this->variations_model->get_all_variants($this->tables['vd_queue']); if ($confirmed_only === TRUE) { // Get only variants confirmed for deletion $delete_records = $this->db->get_where($this->tables['reviews'], array('scheduled_for_deletion' => 1, 'confirmed_for_release' => 1))->result(); // Remove unconfirmed variants from update list foreach ($new_records as $key => $new_record) { $query = $this->db->get_where($this->tables['reviews'], array('variant_id' => $new_record->id, 'confirmed_for_release' => 0)); if ($query->num_rows > 0) { unset($new_records[$key]); } } } else { // Get all variants scheduled for deletion (confirmed or not) $delete_records = $this->db->get_where($this->tables['reviews'], array('scheduled_for_deletion' => 1))->result(); } if (empty($new_records) && empty($delete_records) && $this->version != 0) { // ERROR: no new records to update // NOTE: an empty update is only allowed for Version 0 return FALSE; } // Create new variation table $new_live_table = $this->variations_model->get_new_version_name($this->tables['vd_live']); $copy_success = $this->variations_model->copy_table($this->tables['vd_live'], $new_live_table); if (!$copy_success) { // ERROR: problem copying live table return FALSE; } // Create new queue table $new_queue_table = $this->variations_model->get_new_version_name($this->tables['vd_queue']); $copy_success = $this->variations_model->copy_table($this->tables['vd_queue'], $new_queue_table); if (!$copy_success) { // ERROR: problem copying queue table return FALSE; } // Create new reviews table $new_reviews_table = $this->variations_model->get_new_version_name($this->tables['reviews']); $copy_success = $this->variations_model->copy_table($this->tables['reviews'], $new_reviews_table); if (!$copy_success) { // ERROR: problem copying reviews table return FALSE; } // Create new variant count table $new_count_table = $this->variations_model->get_new_version_name($this->tables['variant_count']); $copy_success = $this->variations_model->copy_table($this->tables['variant_count'], $new_count_table, FALSE); if (!$copy_success) { // ERROR: problem copying table return FALSE; } // Update the *new* live table with the new changes foreach ($new_records as $record) { $this->db->update($new_live_table, $record, 'id = ' . $record->id); } // Remove variants from the *new* live table that were scheduled for deletion foreach ($delete_records as $delete_record) { $this->db->delete($new_live_table, array('id' => $delete_record->variant_id)); $this->db->delete($new_queue_table, array('id' => $delete_record->variant_id)); $this->db->delete($new_reviews_table, array('variant_id' => $delete_record->variant_id)); } // Get genes and associated variant counts, insert into new variant count table $this->load->model('genes_model'); $genes = $this->genes_model->get_genes(); foreach ($genes as $gene) { $variant_count = $this->db->get_where($new_live_table, array('gene' => $gene))->num_rows(); $data = array('id' => NULL, 'gene' => $gene, 'count' => $variant_count); $this->db->insert($new_count_table, $data); } // Delete empty records from the new and previous live tables // --> if a record doesn't have a 'variation' or a 'hgvs_nucleotide_change' then it shouldn't be here $this->db->delete($this->tables['vd_live'], array('variation' => NULL, 'hgvs_nucleotide_change' => NULL)); $this->db->delete($new_live_table, array('variation' => NULL, 'hgvs_nucleotide_change' => NULL)); // Delete all review information and queue data for ONLY the records // that were released $delete_records = $new_records; foreach ($delete_records as $delete_record) { $this->db->delete($new_queue_table, array('id' => $delete_record->id)); $this->db->delete($new_reviews_table, array('variant_id' => $delete_record->id)); } // Get new version number $new_version = (int) $this->version + 1; // Update versions table $datetime = date('Y-m-d H:i:s'); $data = array('id' => NULL, 'version' => $new_version, 'created' => $datetime, 'updated' => $datetime, 'variants' => $this->db->count_all($new_live_table), 'genes' => count($genes)); $this->db->insert($this->tables['versions'], $data); // Delete any intial import data/tables (they aren't needed anymore) // NOTE: initial import data is equal to Version 0 $initial_live = $this->variations_model->get_new_version_name($this->tables['vd_live'], -1); // i.e. "variations_0" if ($this->db->table_exists($initial_live)) { $this->load->dbforge(); // Drop initial live table $this->dbforge->drop_table($initial_live); // Drop initial queue table $initial_queue = $this->variations_model->get_new_version_name($this->tables['vd_queue'], -1); // i.e. "variations_queue_0" $this->dbforge->drop_table($initial_queue); // Drop variant count table $initial_count = $this->variations_model->get_new_version_name($this->tables['variant_count'], -1); // i.e. "variant_count_0" $this->dbforge->drop_table($initial_count); // Drop reviews table $initial_reviews = $this->variations_model->get_new_version_name($this->tables['reviews'], -1); // i.e. "reviews_0" $this->dbforge->drop_table($initial_reviews); // Delete version 0 from the versions table $this->db->delete($this->tables['versions'], array('version' => 0)); } // Log it! $username = $this->ion_auth->user()->row()->username; activity_log("User '{$username}' released a new version of the database -- Version {$new_version}", 'release'); return TRUE; }
function send_reminder($id, $event_date) { global $names, $emails, $site_extras, $debug, $only_testing, $server_url, $languages, $tzoffset, $application_name; global $EXTRA_TEXT, $EXTRA_MULTILINETEXT, $EXTRA_URL, $EXTRA_DATE, $EXTRA_EMAIL, $EXTRA_USER, $EXTRA_REMINDER, $LANGUAGE, $LOG_REMINDER; global $allow_external_users, $external_reminders; $pri[1] = translate("Low"); $pri[2] = translate("Medium"); $pri[3] = translate("High"); // get participants first... $sql = "SELECT cal_login FROM webcal_entry_user " . "WHERE cal_id = {$id} AND cal_status IN ('A','W') " . "ORDER BY cal_login"; $res = dbi_query($sql); $participants = array(); $num_participants = 0; if ($res) { while ($row = dbi_fetch_row($res)) { $participants[$num_participants++] = $row[0]; } } // get external participants $ext_participants = array(); $num_ext_participants = 0; if (!empty($allow_external_users) && $allow_external_users == "Y" && !empty($external_reminders) && $external_reminders == "Y") { $sql = "SELECT cal_fullname, cal_email FROM webcal_entry_ext_user " . "WHERE cal_id = {$id} AND cal_email IS NOT NULL " . "ORDER BY cal_fullname"; $res = dbi_query($sql); if ($res) { while ($row = dbi_fetch_row($res)) { $ext_participants[$num_ext_participants] = $row[0]; $ext_participants_email[$num_ext_participants++] = $row[1]; } } } if (!$num_participants && !$num_ext_participants) { if ($debug) { echo "No participants found for event id: {$id} <br />\n"; } return; } // get event details $res = dbi_query("SELECT cal_create_by, cal_date, cal_time, cal_mod_date, " . "cal_mod_time, cal_duration, cal_priority, cal_type, cal_access, " . "cal_name, cal_description FROM webcal_entry WHERE cal_id = {$id}"); if (!$res) { echo "Db error: could not find event id {$id}.\n"; return; } if (!($row = dbi_fetch_row($res))) { echo "Error: could not find event id {$id} in database.\n"; return; } // send mail. we send one user at a time so that we can switch // languages between users if needed. $mailusers = array(); $recipients = array(); if (isset($single_user) && $single_user == "Y") { $mailusers[] = $emails[$single_user_login]; $recipients[] = $single_user_login; } else { for ($i = 0; $i < count($participants); $i++) { if (strlen($emails[$participants[$i]])) { $mailusers[] = $emails[$participants[$i]]; $recipients[] = $participants[$i]; } else { if ($debug) { echo "No email for user {$participants[$i]} <br />\n"; } } } for ($i = 0; $i < count($ext_participants); $i++) { $mailusers[] = $ext_participants_email[$i]; $recipients[] = $ext_participants[$i]; } } if ($debug) { echo "Found " . count($mailusers) . " with email addresses <br />\n"; } for ($j = 0; $j < count($mailusers); $j++) { $recip = $mailusers[$j]; $user = $participants[$j]; if (!empty($languages[$user])) { $userlang = $languages[$user]; } else { $userlang = $LANGUAGE; } // system default if ($userlang == "none") { $userlang = "English-US"; } // gotta pick something if ($debug) { echo "Setting language to \"{$userlang}\" <br />\n"; } reset_language($userlang); // reset timezone setting for current user if (empty($tzoffset[$user])) { $GLOBALS["TZ_OFFSET"] = 0; } else { $GLOBALS["TZ_OFFSET"] = $tzoffset[$user]; } $body = translate("This is a reminder for the event detailed below.") . "\n\n"; $create_by = $row[0]; $name = $row[9]; $description = $row[10]; // add trailing '/' if not found in server_url if (!empty($server_url)) { if (substr($server_url, -1, 1) == "/") { $body .= $server_url . "view_entry.php?id=" . $id . "\n\n"; } else { $body .= $server_url . "/view_entry.php?id=" . $id . "\n\n"; } } $body .= strtoupper($name) . "\n\n"; $body .= translate("Description") . ":\n"; $body .= indent($description) . "\n"; $body .= translate("Date") . ": " . date_to_str($event_date) . "\n"; if ($row[2] >= 0) { $body .= translate("Time") . ": " . display_time($row[2]) . "\n"; } if ($row[5] > 0) { $body .= translate("Duration") . ": " . $row[5] . " " . translate("minutes") . "\n"; } if (!empty($disable_priority_field) && !$disable_priority_field) { $body .= translate("Priority") . ": " . $pri[$row[6]] . "\n"; } if (!empty($disable_access_field) && !$disable_access_field) { $body .= translate("Access") . ": " . ($row[8] == "P" ? translate("Public") : translate("Confidential")) . "\n"; } if (!empty($single_user_login) && $single_user_login == false) { $body .= translate("Created by") . ": " . $row[0] . "\n"; } $body .= translate("Updated") . ": " . date_to_str($row[3]) . " " . display_time($row[4]) . "\n"; // site extra fields $extras = get_site_extra_fields($id); for ($i = 0; $i < count($site_extras); $i++) { $extra_name = $site_extras[$i][0]; $extra_descr = $site_extras[$i][1]; $extra_type = $site_extras[$i][2]; if ($extras[$extra_name]['cal_name'] != "") { $body .= translate($extra_descr) . ": "; if ($extra_type == $EXTRA_DATE) { $body .= date_to_str($extras[$extra_name]['cal_date']) . "\n"; } else { if ($extra_type == $EXTRA_MULTILINETEXT) { $body .= "\n" . indent($extras[$extra_name]['cal_data']) . "\n"; } else { if ($extra_type == $EXTRA_REMINDER) { $body .= ($extras[$extra_name]['cal_remind'] > 0 ? translate("Yes") : translate("No")) . "\n"; } else { // default method for $EXTRA_URL, $EXTRA_TEXT, etc... $body .= $extras[$extra_name]['cal_data'] . "\n"; } } } } } if (!empty($single_user) && $single_user != "Y" && !empty($disable_participants_field) && !$disable_participants_field) { $body .= translate("Participants") . ":\n"; for ($i = 0; $i < count($participants); $i++) { $body .= " " . $names[$participants[$i]] . "\n"; } for ($i = 0; $i < count($ext_participants); $i++) { $body .= " " . $ext_participants[$i] . " (" . translate("External User") . ")\n"; } } $subject = translate("Reminder") . ": " . $name; if (strlen($GLOBALS["email_fallback_from"])) { $extra_hdrs = "From: " . $GLOBALS["email_fallback_from"] . "\r\n" . "X-Mailer: " . translate($application_name); } else { $extra_hdrs = "X-Mailer: " . translate($application_name); } if ($debug) { echo "Sending mail to {$recip} (in {$userlang})\n"; } if ($only_testing) { if ($debug) { echo "<hr /><pre>To: {$recip}\nSubject: {$subject}\n{$extra_hdrs}\n\n{$body}\n\n</pre>\n"; } } else { mail($recip, $subject, $body, $extra_hdrs); activity_log($id, "system", $user, $LOG_REMINDER, ""); } } }
dbi_free_result($res); } // Update the task percentage for this user. if (!empty($_POST) && $is_my_event) { $upercent = getPostValue('upercent'); if ($upercent >= 0 && $upercent <= 100) { dbi_execute('UPDATE webcal_entry_user SET cal_percent = ? WHERE cal_login = ? AND cal_id = ?', array($upercent, $login, $id)); activity_log($id, $login, $creator, LOG_UPDATE_T, translate('Update Task Percentage') . ' ' . $upercent . '%'); } // Check if all other user percent is 100%, if so, set cal_complete date. $others_complete = getPostValue('others_complete'); if ($upercent == 100 && $others_complete == 'yes') { dbi_execute('UPDATE webcal_entry SET cal_completed = ? WHERE cal_id = ?', array(gmdate('Ymd', time()), $id)); activity_log($id, $login, $creator, LOG_UPDATE_T, translate('Completed')); } } // Load event info now. $res = dbi_execute('SELECT cal_create_by, cal_date, cal_time, cal_mod_date, cal_mod_time, cal_duration, cal_priority, cal_type, cal_access, cal_name, cal_description, cal_location, cal_url, cal_due_date, cal_due_time, cal_completed FROM webcal_entry WHERE cal_id = ?', array($id)); if (!$res) { $error = str_replace('XXX', $id, translate('Invalid entry id XXX.')); } else { $row = dbi_fetch_row($res); if ($row) { $create_by = $row[0]; $orig_date = $row[1]; $event_time = $row[2];
} } } } } // Now, mark event as deleted for all users. dbi_query("UPDATE webcal_entry_user SET cal_status = 'D' " . "WHERE cal_id = {$id}"); } } else { // Not the owner of the event and are not the admin. // Just delete the event from this user's calendar. // We could just set the status to 'D' instead of deleting. // (but we would need to make some changes to edit_entry_handler.php // to accomodate this). dbi_query("DELETE FROM webcal_entry_user " . "WHERE cal_id = {$id} AND cal_login = '******'"); activity_log($id, $login, $login, $LOG_REJECT, ""); } } if (strlen(get_last_view())) { $url = get_last_view(); } else { $redir = ""; if ($thisdate != "") { $redir = "?date={$thisdate}"; } if ($user != "") { if ($redir != "") { $redir .= "&"; } $redir .= "user={$user}"; }
function update_status($status, $user, $id, $type = 'E') { global $error, $login; if (empty($status)) { return; } $log_type = ''; switch ($type) { case 'N': case 'T': $log_type = '_T'; break; case 'J': case 'O': $log_type = '_J'; } switch ($status) { case 'A': $log_type = constant('LOG_APPROVE' . $log_type); // translate ( 'Error approving event' ) $error_msg = translate('Error approving event XXX.'); break; case 'D': $log_type = constant('LOG_DELETE' . $log_type); // translate ( 'Error deleting event' ) $error_msg = translate('Error deleting event XXX.'); break; case 'R': $log_type = constant('LOG_REJECT' . $log_type); // translate ( 'Error rejecting event' ) $error_msg = translate('Error rejecting event XXX.'); } if (!dbi_execute('UPDATE webcal_entry_user SET cal_status = ? WHERE cal_login = ? AND cal_id = ?', array($status, $user, $id))) { $error = str_replace('XXX', dbi_error(), $error_msg); } else { activity_log($id, $login, $user, $log_type, ''); } }
function sweetspot_mail($to_address, $subject, $body, $no_reply = FALSE) { $headers = ''; if ($no_reply) { $headers .= "Reply-To: no-reply@sweetspot.com\r\n"; $headers .= "From: SweetSpot <*****@*****.**>\r\n"; } else { $headers .= "Reply-To: glenn@sweetspot.com\r\n"; $headers .= "From: SweetSpot <*****@*****.**>\r\n"; } $log_string = $to_address . "~~" . $headers . "~~" . $body; activity_log(array('type' => 'email', 'entry' => $log_string)); wp_mail($to_address, $subject, $body, $headers); }
/** * Submit changes * * This has 2 different functions: * 1.) Save the variant confirmation selection, OR * 2.) Release all variant changes * * 1.) Saves the confirmation selection for variant change * quality control. * * 2.) Releases all changes currently within the queue. * A backup is first created, then the changes are made, and finally * the changes are emptied from the queue. * * @author Sean Ephraim * @access public * @return void */ public function submit_changes() { redirect_all_nonmembers(); // Refuse access to wanderers if (!isset($_POST['save-changes']) && !isset($_POST['release-changes'])) { die("Hmmm... you must have wandered here by mistake."); } // Update confirmation status of all variants on this page $post = $this->input->post(); $variants = isset($post['variants-on-this-page']) ? $post['variants-on-this-page'] : NULL; if (is_array($variants)) { foreach ($variants as $variant_id) { $old_review = $this->variations_model->get_variant_review_info($variant_id); $data['confirmed_for_release'] = TRUE; if (isset($post['unconfirmed-variants']) && array_search($variant_id, $post['unconfirmed-variants']) !== FALSE) { // variant was found in list of unconfirmed variants $data['confirmed_for_release'] = FALSE; } $this->variations_model->update_variant_review_info($variant_id, $data); // Log the activity if the review changed if (!empty($old_review) && $data['confirmed_for_release'] != (bool) $old_review->confirmed_for_release) { $username = $this->ion_auth->user()->row()->username; $variation = $this->db->get_where($this->tables['vd_queue'], array('id' => $variant_id))->row_array(); $gene = empty($variation['gene']) ? 'MISSING_GENE' : $variation['gene']; $protein = empty($variation['hgvs_protein_change']) ? 'MISSING_PROTEIN_CHANGE' : $variation['hgvs_protein_change']; $variation = empty($variation['variation']) ? 'MISSING_VARIATION' : $variation['variation']; if ($data['confirmed_for_release']) { activity_log("User '{$username}' confirmed changes for variant {$gene}|{$protein}|{$variation}", 'confirm'); } else { activity_log("User '{$username}' unconfirmed changes for variant {$gene}|{$protein}|{$variation}", 'unconfirm'); } } } } if (isset($_POST['save-changes'])) { // Confirmation changes saved $html = 'Changes saved.'; $this->session->set_flashdata('success', $html); } else { if (isset($_POST['release-changes'])) { // Attempt to RELEASE all changes /* NOTE: A release can only be successful if all variant changes have been * confirmed for release. This means that 'unconfirmed-variants' must be * empty. If any checkboxes in the name of 'unconfirmed-variants' are checked, * then this element will not be empty, and the attempt to release will fail. */ if ($_POST['special-release'] === 'none') { $found_unconfirmed = FALSE; if (isset($_POST['unconfirmed-variants']) && count($_POST['unconfirmed-variants']) > 0) { // ERROR: found unconfirmed variants on this page $found_unconfirmed = TRUE; } // Check that all variants in queue have been confirmed for release $all_queue_variants = $this->variations_model->get_unreleased_changes(); foreach ($all_queue_variants as $variant_id => $values) { $variant_review = $this->variations_model->get_variant_review_info($variant_id); if ($variant_review->confirmed_for_release == 0) { // ERROR: found unconfirmed variants in the queue (not necessarily on this page) $found_unconfirmed = TRUE; } } if ($found_unconfirmed) { // Release failed! Not all variants have been confirmed for release $html = 'All changes must be confirmed prior to release. Check the boxes on the right side to confirm each change, or see the bottom of this page for special release options.'; $this->session->set_flashdata('error', $html); redirect('variations/unreleased'); } } if ($_POST['special-release'] === 'force-all' || $this->version == 0) { // Release all variants regardless of confirmation status $success = $this->variations_model->push_data_live(FALSE); } else { // Only release the confirmed variants $success = $this->variations_model->push_data_live(); } if ($success === TRUE) { // Successful release $confirmed = ''; if ($_POST['special-release'] === 'force-confirmed') { $confirmed = 'confirmed '; } $html = '<p>' . ' <p><i class="icon-ok"></i> Backup created</p>' . ' <p><i class="icon-ok"></i> All ' . $confirmed . 'changes released</p>' . '</p>'; $this->session->set_flashdata('success', $html); } else { // ERROR: Problem with releasing changes $html = '<p>There was an error releasing changes. Please make sure that any changes you would like to release have been confirmed and/or any special release options have been selected.</p>'; $this->session->set_flashdata('error', $html); } } } // Redirect to proper page $refer_url = $this->session->flashdata('refer_url'); if (isset($_POST['release-changes']) || empty($refer_url)) { // Return to default URL if there's no reference URL or after releasing changes redirect('variations/unreleased'); } else { // Return to reference URL redirect($refer_url); } }