/** * @param $sql * @param $table * @param $event * @param $record * @param $display * @param string $descrip * @param string $change_reason * @param null $project_id * @param null $event_id * @return bool|mysqli_result */ function target_log_event($sql, $table, $event, $record, $display, $descrip = "", $change_reason = "", $project_id = NULL, $event_id = null) { global $user_firstactivity, $rc_connection; // Log the event in the redcap_log_event table $ts = str_replace(array("-", ":", " "), array("", "", ""), NOW); $page = (defined("PAGE") ? PAGE : ""); // $userid = (in_array(PAGE_FULL, non_auth_pages()) ? "[CRON]" : defined("USERID") ? USERID : ""); // Pages that do not have authentication should have USERID set to [CRON] if (defined("USERID")) { $userid = USERID; } elseif (defined("CRON_PAGE") && in_array(CRON_PAGE, non_auth_pages())) { $userid = '[CRON]'; } else { $userid = ""; } $ip = (isset($userid) && $userid == "[survey respondent]") ? "" : getIpAddress(); // Don't log IP for survey respondents $event = strtoupper($event); if (!isset($event_id)) { $event_id = (isset($_GET['event_id']) && is_numeric($_GET['event_id'])) ? $_GET['event_id'] : "NULL"; } /** * project_id override, for cross-project logging * if project_id has not been passed in the call to this function, * get it from the default constant. Otherwise, use the one passed in. */ if (!isset($project_id)) { $project_id = defined("PROJECT_ID") ? PROJECT_ID : 0; } // Query $sql = "INSERT INTO redcap_log_event (project_id, ts, user, ip, page, event, object_type, sql_log, pk, event_id, data_values, description, change_reason) VALUES ($project_id, $ts, '" . prep($userid) . "', " . checkNull($ip) . ", '$page', '$event', '$table', " . checkNull($sql) . ", " . checkNull($record) . ", $event_id, " . checkNull($display) . ", " . checkNull($descrip) . ", " . checkNull($change_reason) . ")"; $q = db_query($sql, $rc_connection); // FIRST/LAST ACTIVITY TIMESTAMP: Set timestamp of last activity (and first, if applicable) if (defined("USERID") && strpos(USERID, "[") === false) { // SET FIRST ACTIVITY TIMESTAMP: If this is the user's first activity to be logged in the log_event table, then log the time in the user_information table $sql_firstact = ""; if ((!isset($user_firstactivity) || (isset($user_firstactivity) && empty($user_firstactivity)))) { $sql_firstact = ", user_firstactivity = '" . NOW . "'"; } // SET LAST ACTIVITY TIMESTAMP $sql = "update redcap_user_information set user_lastactivity = '" . NOW . "' $sql_firstact where username = '******' limit 1"; db_query($sql, $rc_connection); } // Return true/false success for logged event return $q; }
*/ $sql = "INSERT INTO $table_name $columns VALUES\n" . implode(",\n", $query); if (!$debug) { if (db_query($table_create_query)) { echo "$table_name exists<br />"; } if (db_query($truncate_query)) { echo "$table_name has been truncated<br />"; if (db_query($sql)) { echo "$table_name has been updated<br />"; /** * prep for download */ if (defined("USERID")) { $userid = USERID; } else if (in_array(CRON_PAGE, non_auth_pages())) { $userid = "[CRON]"; } else { $userid = ''; } error_log("USER $userid attempted to create user file for domain {$constants['DOMAIN']}"); if (is_array($fields_collection)) { foreach ($fields_collection AS $field_collection) { foreach ($field_collection AS $key => $val) { $chkd_fields_array[] = $key; } } $chkd_fields = "'" . implode("', '", array_unique($chkd_fields_array)) . "'"; } create_cdisc_download($table_name, $lang, $app_title, $userid, $user_rights, $chkd_fields, '', $project_id, $constants['DOMAIN'], $debug); } else {
/** * @param $subject_id string * @param $project_id string * @param $event_id string * @param $value string * @param $compare_value string * @param $field string * @param $debug boolean * @param $message string */ function update_field_compare($subject_id, $project_id, $event_id, $value, $compare_value, $field, $debug, $message = null, $userid = null) { if (!isset($userid)) { if (defined("USERID")) { $userid = USERID; } elseif (defined("CRON_PAGE") && in_array(CRON_PAGE, non_auth_pages())) { $userid = '[CRON]'; } else { $userid = ""; } } $update_message = 'Update record'; $insert_message = 'Create record'; $delete_message = 'Delete record'; $compare_value = htmlspecialchars_decode($compare_value); $_GET['event_id'] = $event_id; // for logging if ((isset($compare_value) && $compare_value != '' && $value != '') && $value != $compare_value) { $update_query = "UPDATE redcap_data SET value = '" . prep($value) . "' WHERE record = '$subject_id' AND project_id = '$project_id' AND event_id = '$event_id' AND field_name = '$field' AND value = '$compare_value'"; if (!$debug) { if (db_query($update_query)) { target_log_event($update_query, 'redcap_data', 'update', $subject_id, "$field = '$value'", $update_message, $message, $project_id, $event_id, $userid); //REDCap::logEvent('Update record', "$field = '$value'", $update_query, $subject_id, $event_id); } else { error_log("SQL UPDATE FAILED: " . db_error() . ': ' . $update_query); echo db_error() . "<br />" . $update_query; } } else { show_var($update_query); error_log("DEBUG: " . $update_query); } } elseif ((!isset($compare_value) || $compare_value == '') && $value != '') { $insert_query = "INSERT INTO redcap_data SET record = '$subject_id', project_id = '$project_id', event_id = '$event_id', value = '" . prep($value) . "', field_name = '$field'"; if (!$debug) { if (db_query($insert_query)) { target_log_event($insert_query, 'redcap_data', 'insert', $subject_id, "$field = '$value'", $insert_message, $message, $project_id, $event_id, $userid); //REDCap::logEvent('Create record', "$field = '$value'", $insert_query, $subject_id, $event_id); } else { error_log("SQL INSERT FAILED: " . db_error() . ': ' . $insert_query); echo db_error() . "<br />" . $insert_query; } } else { show_var($insert_query); error_log("DEBUG: " . $insert_query); } } elseif ((isset($compare_value) && $compare_value != '') && $value == '') { $delete_query = "DELETE FROM redcap_data WHERE record = '$subject_id' AND project_id = '$project_id' AND event_id = '$event_id' AND field_name = '$field' AND value = '" . prep($compare_value) . "'"; if (!$debug) { if (db_query($delete_query)) { target_log_event($delete_query, 'redcap_data', 'delete', $subject_id, "$field = '$compare_value'", $delete_message, $message, $project_id, $event_id, $userid); //REDCap::logEvent('Delete record', "$field = '$value'", $delete_query, $subject_id, $event_id); } else { error_log("SQL DELETE FAILED: " . db_error() . ': ' . $delete_query); echo db_error() . "<br />" . $delete_query; } } else { show_var($delete_query); error_log("DEBUG: " . $delete_query); } } }