} if (strlen($_GET['day']) < 2) { $_GET['day'] = "0" . $_GET['day']; } $event_date = $_GET['year'] . "-" . $_GET['month'] . "-" . $_GET['day']; //Check if it's a valid date if (!checkdate($_GET['month'], $_GET['day'], $_GET['year'])) { exit("<b>{$lang['global_01']}{$lang['colon']}</b><br>{$lang['calendar_popup_19']}"); } print "<div style='color:green;font-family:verdana;padding:5px;margin-bottom:10px;font-weight:bold;font-size:16px;border-bottom:1px solid #aaa;'>\n\t\t\t\t{$lang['calendar_popup_20']}</div>\n\t\t\t\n\t\t\t<form method='post' action='{$_SERVER['PHP_SELF']}?pid={$project_id}&width=600' name='form'>\n\t\t\t<table style='font-family:Arial;font-size:14px;' cellpadding='0' cellspacing='10'>"; // Show option to attach calendar event to a record (i.e. unscheduled cal event) if ($_GET['record'] != "") { $_GET['record'] = strip_tags(label_decode($_GET['record'])); print "\n\t\t\t<tr>\n\t\t\t\t<td valign='top'>{$table_pk_label}: </td>\n\t\t\t\t<td valign='top'>\n\t\t\t\t\t<b>" . RCView::escape(removeDDEending($_GET['record'])) . "</b>\n\t\t\t\t\t<input type='hidden' name='idnumber' value='" . RCView::escape($_GET['record']) . "'>\n\t\t\t\t</td>\n\t\t\t</tr>"; } print "<tr>\n\t\t\t\t<td valign='top'>{$lang['global_18']}{$lang['colon']}</td>\n\t\t\t\t<td valign='top'>\n\t\t\t\t\t<b>" . DateTimeRC::format_ts_from_ymd($event_date) . " (" . DateTimeRC::getDay($event_date) . ")</b>\n\t\t\t\t\t<input type='hidden' id='event_date' name='event_date' value='{$event_date}'>\n\t\t\t\t</td>\n\t\t\t</tr>\n\t\t\t<tr>\n\t\t\t\t<td valign='top'>\n\t\t\t\t\t{$lang['global_13']}{$lang['colon']}\n\t\t\t\t\t<div style='font-size:10px;color:#888;'>{$lang['global_06']}</div>\n\t\t\t\t</td>\n\t\t\t\t<td valign='top'>\n\t\t\t\t\t<input type='text' class='x-form-text x-form-field time' id='event_time' name='event_time' maxlength='5' style='width:50px;' onblur=\"redcap_validate(this,'','','soft_typed','time')\"> \n\t\t\t\t\t<span style='font-size:10px;color:#777;font-family:tahoma;'>HH:MM ({$lang['calendar_popup_22']})</span>\n\t\t\t\t</td>\n\t\t\t</tr>\n\t\t\t<tr>\n\t\t\t\t<td valign='top'>{$lang['calendar_popup_11']}{$lang['colon']}</td>\n\t\t\t\t<td valign='top'><textarea id='notes' name='notes' class='x-form-textarea x-form-field' style='font-size:12px;width:400px;height:100px;'>{$row['notes']}</textarea></td>\n\t\t\t</tr>"; // Show option to attach calendar event to a record (i.e. unscheduled cal event) if ($_GET['record'] == "") { print "<tr>\n\t\t\t\t\t<td valign='top'>{$table_pk_label}: </td>\n\t\t\t\t\t<td>\n\t\t\t\t\t\t<table cellpadding=0 cellspacing=0><tr>\n\t\t\t\t\t\t<td valign='top'>\n\t\t\t\t\t\t\t<select name='idnumber' id='idnumber' class='x-form-text x-form-field' style='height:22px;padding-right:0;font-size:11px;'>\n\t\t\t\t\t\t\t<option value=''> - {$lang['calendar_popup_23']} - </option>"; // Retrieve record list (exclude non-DAG records if user is in a DAG) foreach (array_keys(Records::getData('array', array(), $table_pk, array(), $user_rights['group_id'])) as $this_record) { print "\t\t\t<option value='{$this_record}'>" . removeDDEending($this_record) . "</option>"; } print "\t\t\t</select>\n\t\t\t\t\t\t</td>\n\t\t\t\t\t\t<td valign='top' style='font-size:11px;color:#666;padding-left:10px;'>\n\t\t\t\t\t\t\t{$lang['calendar_popup_24']} {$table_pk_label}\n\t\t\t\t\t\t</td>\n\t\t\t\t\t\t</tr></table>\n\t\t\t\t\t</td>\n\t\t\t\t</tr>"; } print "<tr>\n\t\t\t\t<td></td>\n\t\t\t\t<td valign='top'>\n\t\t\t\t\t<br><br>\n\t\t\t\t\t<input type='submit' value='{$lang['calendar_popup_25']}' onclick=\"\n\t\t\t\t\t\tif (document.getElementById('notes').value.length < 1) {\n\t\t\t\t\t\t\talert('{$lang['calendar_popup_26']}');\n\t\t\t\t\t\t\treturn false;\t\t\t\t\t\t\n\t\t\t\t\t\t}\n\t\t\t\t\t\">\n\t\t\t\t\t<br><br>\n\t\t\t\t</td>\n\t\t\t</tr>\n\t\t\t</table>\n\t\t\t</form>"; /** * DISPLAY CONFIRMATION THAT NEW CALENDAR EVENT WAS CREATED */ } elseif (!isset($_GET['cal_id']) && !empty($_POST)) { //If an existing record was selected, make sure record doesn't already exist in a DAG. If so, add its group_id to calendar event.
/** * @param $userid * @param $headers * @param $table_csv * @param array $fields * @param $parent_chkd_flds * @param $export_file_name * @param $debug * @param null $comment * @param array $to */ public static function do_sendit($userid, $headers, $table_csv, $fields = array(), $parent_chkd_flds, $export_file_name, $comment = null, $to = array(), $debug) { global $project_id, $user_rights, $app_title, $lang, $redcap_version; // we could use the global $userid, but we need control of it for setting the user as [CRON], so this is passed in args. $return_val = false; $export_type = 0; // this puts all files generated here in the Data Export category in the File Repository $today = date("Y-m-d_Hi"); //get today for filename $projTitleShort = substr(str_replace(" ", "", ucwords(preg_replace("/[^a-zA-Z0-9 ]/", "", html_entity_decode($app_title, ENT_QUOTES)))), 0, 20); // shortened project title for filename $originalFilename = $projTitleShort . "_" . $export_file_name . "_DATA_" . $today . ".csv"; // name the file for storage $today = date("Y-m-d-H-i-s"); // get today for comment, subsequent processing as needed $docs_comment_WH = $export_type ? "Data export file created by $userid on $today" : fix_case($export_file_name) . " file created by $userid on $today. $comment"; // unused, but I keep it around just in case /** * setup vars for value export logging */ $chkd_fields = implode(',', $fields); /** * turn on/off exporting per user rights */ if (($user_rights['data_export_tool'] || $userid == '[CRON]') && !$debug) { $table_csv = addBOMtoUTF8($headers . $table_csv); /** * Store the file in the file system and log the activity, handle if error */ if (!DataExport::storeExportFile($originalFilename, $table_csv, true)) { log_event("", "redcap_data", "data_export", "", str_replace("'", "", $chkd_fields) . (($parent_chkd_flds == "") ? "" : ", " . str_replace("'", "", $parent_chkd_flds)), "Data Export Failed"); } else { log_event("", "redcap_data", "data_export", "", str_replace("'", "", $chkd_fields) . (($parent_chkd_flds == "") ? "" : ", " . str_replace("'", "", $parent_chkd_flds)), "Export data for SendIt"); /** * email file link and download password in two separate emails via REDCap SendIt */ $file_info_sql = db_query("SELECT docs_id, docs_size, docs_type FROM redcap_docs WHERE project_id = $project_id ORDER BY docs_id DESC LIMIT 1"); // get required info about the file we just created if ($file_info_sql) { $docs_id = db_result($file_info_sql, 0, 'docs_id'); $docs_size = db_result($file_info_sql, 0, 'docs_size'); $docs_type = db_result($file_info_sql, 0, 'docs_type'); } $yourName = 'PRIORITIZE REDCap'; $expireDays = 3; // set the SendIt to expire in this many days /** * $file_location: * 1 = ephemeral, will be deleted on $expireDate * 2 = export file, visible only to rights in file repository */ $file_location = 2; $send = 1; // always send download confirmation $expireDate = date('Y-m-d H:i:s', strtotime("+$expireDays days")); $expireYear = substr($expireDate, 0, 4); $expireMonth = substr($expireDate, 5, 2); $expireDay = substr($expireDate, 8, 2); $expireHour = substr($expireDate, 11, 2); $expireMin = substr($expireDate, 14, 2); // Add entry to sendit_docs table $query = "INSERT INTO redcap_sendit_docs (doc_name, doc_orig_name, doc_type, doc_size, send_confirmation, expire_date, username, location, docs_id, date_added) VALUES ('$originalFilename', '" . prep($originalFilename) . "', '$docs_type', '$docs_size', $send, '$expireDate', '" . prep($userid) . "', $file_location, $docs_id, '" . NOW . "')"; db_query($query); $newId = db_insert_id(); $logDescrip = "Send file from file repository (Send-It)"; log_event($query, "redcap_sendit_docs", "MANAGE", $newId, "document_id = $newId", $logDescrip); // Set email subject $subject = "[PRIORITIZE] " . $comment; $subject = html_entity_decode($subject, ENT_QUOTES); // Set email From address $from = array('Ken Bergquist' => '*****@*****.**'); // Begin set up of email to send to recipients $email = new Message(); foreach ($from as $name => $address) { $email->setFrom($address); $email->setFromName($name); } $email->setSubject($subject); // Loop through each recipient and send email foreach ($to as $name => $address) { // If a non-blank email address if (trim($address) != '') { // create key for unique url $key = strtoupper(substr(uniqid(md5(mt_rand())), 0, 25)); // create password $pwd = generateRandomHash(8, false, true); $query = "INSERT INTO redcap_sendit_recipients (email_address, sent_confirmation, download_date, download_count, document_id, guid, pwd) VALUES ('$address', 0, NULL, 0, $newId, '$key', '" . md5($pwd) . "')"; $q = db_query($query); // Download URL $url = APP_PATH_WEBROOT_FULL . 'redcap_v' . $redcap_version . '/SendIt/download.php?' . $key; // Message from sender $note = "$comment for $today"; // Get YMD timestamp of the file's expiration time $expireTimestamp = date('Y-m-d H:i:s', mktime($expireHour, $expireMin, 0, $expireMonth, $expireDay, $expireYear)); // Email body $body = "<html><body style=\"font-family:Arial;font-size:10pt;\"> $yourName {$lang['sendit_51']} \"$originalFilename\" {$lang['sendit_52']} " . date('l', mktime($expireHour, $expireMin, 0, $expireMonth, $expireDay, $expireYear)) . ", " . DateTimeRC::format_ts_from_ymd($expireTimestamp) . "{$lang['period']} {$lang['sendit_53']}<br><br> {$lang['sendit_54']}<br> <a href=\"$url\">$url</a><br><br> $note <br>-----------------------------------------------<br> {$lang['sendit_55']} " . CONSORTIUM_WEBSITE_DOMAIN . ". </body></html>"; // Construct email and send $email->setTo($address); $email->setToName($name); $email->setBody($body); if ($email->send()) { // Now send follow-up email containing password $bodypass = "******"font-family:Arial;font-size:10pt;\"> {$lang['sendit_50']}<br><br> $pwd<br><br> </body></html>"; $email->setSubject("Re: $subject"); $email->setBody($bodypass); sleep(2); // Hold for a second so that second email somehow doesn't reach the user first $email->send(); } else { error_log("ERROR: pid=$project_id: Email to $name <$address> NOT SENT"); } } } } unset($table_csv); } }
$entry_num = isset($entry_num) ? $entry_num : ""; // Lock records $sql = "select form_name, timestamp from redcap_locking_data where project_id = $project_id and event_id = {$_GET['event_id']} and record = '" . prep($fetched.$entry_num). "'"; $q = db_query($sql); while ($row = db_fetch_array($q)) { $locked_forms[$row['form_name']] = " <img id='formlock-{$row['form_name']}' src='".APP_PATH_IMAGES."lock_small.png' title='".cleanHtml($lang['bottom_59'])." " . DateTimeRC::format_ts_from_ymd($row['timestamp']) . "'>"; } // E-signatures $sql = "select form_name, timestamp from redcap_esignatures where project_id = $project_id and event_id = {$_GET['event_id']} and record = '" . prep($fetched.$entry_num). "'"; $q = db_query($sql); while ($row = db_fetch_array($q)) { $this_esignts = " <img id='formesign-{$row['form_name']}' src='".APP_PATH_IMAGES."tick_shield_small.png' title='" . cleanHtml($lang['data_entry_224'] . " " . DateTimeRC::format_ts_from_ymd($row['timestamp'])) . "'>"; if (isset($locked_forms[$row['form_name']])) { $locked_forms[$row['form_name']] .= $this_esignts; } else { $locked_forms[$row['form_name']] = $this_esignts; } } } ## Render the form list for this project list ($form_count,$formString) = renderFormMenuList($this_app_name,$fetched,$locked_forms,$hidden_edit,$entry_num,$visit_forms); $dataEntry .= $formString; ## LOCK / UNLOCK RECORDS //If user has ability to lock a record, give option to lock it for all forms (if record is pulled up on data entry page) if ($user_rights['lock_record_multiform'] && $user_rights['lock_record'] > 0 && PAGE == "DataEntry/index.php" && isset($fetched))
continue; } //List any events for this day if (isset($events[$i])) { //Loop through all of this day's events while (list($key, $value) = each($events[$i])) { //Determine if we need to display the date (do not if repeating from previous row) $this_day = "{$month}/{$i}/{$year}"; if ($next_day != $this_day) { $day_text = date("D", mktime(0, 0, 0, $month, $i, $year)) . " " . date("M", mktime(0, 0, 0, $month, $i, $year)) . " {$i}"; $evenOrOdd = $k % 2 == 0 ? 'even' : 'odd'; $k++; } else { $day_text = ""; } print "<tr class='{$evenOrOdd}' valign='top'>\n\t\t\t\t\t\t\t<td style='padding:3px 5px 2px 8px;font-weight:bold;width:120px;'>{$day_text}</td>\n\t\t\t\t\t\t\t<td style='padding:3px 5px 1px 8px;font-family:tahoma;font-size:11px;width:40px;'>" . DateTimeRC::format_ts_from_ymd($event_info[$value]['5']) . "</td>\n\t\t\t\t\t\t\t<td class='notranslate' style='padding:1px 5px 1px 5px;'>"; renderCalEvent($event_info, $i, $value, $_GET['view']); print "\t</td>\n\t\t\t\t\t\t</tr>"; //Set next day's date $next_day = "{$month}/{$i}/{$year}"; } } } //If no events to display if ($k == 1) { print "<tr class='{$evenOrOdd}' valign='top'>\n\t\t\t\t\t<td colspan='3' style='padding:3px 5px 2px 8px;'>{$lang['calendar_table_07']}</td>\n\t\t\t\t</tr>"; } print "</table>"; print "</div><br><br>"; if (PAGE == "/plugins/Calendar/index.php") { include APP_PATH_DOCROOT . 'ProjectGeneral/footer.php';
if ($_GET['view'] == "date") { print "<div id='change_date' style='display:block;'>\n\t\t\t\t<b>" . DateTimeRC::format_ts_from_ymd($event_date) . " (" . DateTimeRC::getDay($event_date) . ")</b> "; // Dont' allow user to change date here if tied to an Event (need to change on Scheduling page where it might affect other scheduled dates) if ($row['event_id'] == "") { print "<a href='javascript:;' style='text-decoration:underline;font-size:11px;' onclick=\"\$('#change_date').css({'display':'none'});\$('#save_date').css({'display':'block'});\">{$lang['calendar_popup_ajax_03']}</a>"; } print "{$msg}\n\t\t\t</div>\n\t\t\t<div id='save_date' style='display:none;position:relative;'>\n\t\t\t\t<input type='text' id='newdate' name='newdate' onblur=\"redcap_validate(this,'','','hard','date_'+user_date_format_validation,1,1,user_date_format_delimiter);\" value='" . DateTimeRC::format_ts_from_ymd($event_date) . "' class='x-form-text x-form-field' style='width:70px;' maxlength='10'><span class='df'>(" . DateTimeRC::get_user_format_label() . ")</span>\n\t\t\t\t \n\t\t\t\t<input type='button' id='savebtndatecalpopup' style='font-size:11px;' value='" . cleanHtml($lang['calendar_popup_ajax_04']) . "' onclick='saveDateCalPopup({$_GET['cal_id']})'> \n\t\t\t\t<input type='button' style='font-size:11px;' value='" . cleanHtml($lang['global_53']) . "' onclick=\"\$('#change_date').css({'display':'block'});\$('#save_date').css({'display':'none'});\">\n\t\t\t</div>"; //TIME Field } elseif ($_GET['view'] == "time") { $time_field = "<input type='text' class='x-form-text x-form-field time' id='event_time' name='event_time' value='" . remBr(cleanHtml($_GET['event_time'])) . "' maxlength='5' style='width:50px;' onblur=\"redcap_validate(this,'','','soft_typed','time')\"> \n\t\t\t\t\t<span style='font-size:10px;color:#777;font-family:tahoma;'>HH:MM</span> \n\t\t\t\t\t<input type='button' id='savebtntimecalpopup' style='font-size:11px;' value='{$lang['calendar_popup_ajax_06']}' onclick='saveTimeCalPopup({$_GET['cal_id']})'>"; //Visit Time if ($_GET['event_time'] == "") { $visible = $time_field; $hidden = ""; } else { $visible = "<b>" . DateTimeRC::format_ts_from_ymd($_GET['event_time']) . "</b> \n\t\t\t\t\t<a href='javascript:;' style='text-decoration:underline;font-size:11px;' onclick=\"\$('#change_time').css({'display':'none'});\$('#save_time').css({'display':'block'});\">{$lang['calendar_popup_ajax_07']}</a>"; $hidden = $time_field . " \n\t\t\t\t\t<input type='button' style='font-size:11px;' value='{$lang['global_53']}' onclick=\"\$('#change_time').css({'display':'block'});\$('#save_time').css({'display':'none'});\">"; } print "<div id='change_time' style='display:block;'>\n\t\t\t\t{$visible}\n\t\t\t\t{$msg}\n\t\t\t</div>\n\t\t\t<div id='save_time' style='display:none;'>\n\t\t\t\t{$hidden}\n\t\t\t</div>"; //STATUS Field } elseif ($_GET['view'] == "status") { //Set display text for visit status switch ($_GET['event_status']) { case 0: $status = "<img src='" . APP_PATH_IMAGES . "star_empty.png' style='position:relative;top:1px;'> <b style='color:#777;'>{$lang['calendar_popup_ajax_08']}</b>"; break; case 1: $status = "<img src='" . APP_PATH_IMAGES . "star.png' style='position:relative;top:1px;'> <b style='color:#A86700;'>{$lang['calendar_popup_ajax_09']}</b>"; break; case 2: $status = "<img src='" . APP_PATH_IMAGES . "tick.png' style='position:relative;top:1px;'> <b style='color:green;'>{$lang['calendar_popup_ajax_10']}</b>";
$q = db_query($sql); $row_num = db_num_rows($q); $existing_record = $row_num > 0; ## LOCK RECORDS & E-SIGNATURES // For lock/unlock records feature, show locks by any forms that are locked (if a record is pulled up on data entry page) $locked_forms = array(); $qsql = "select event_id, form_name, timestamp from redcap_locking_data where project_id = {$project_id} and record = '" . prep($id) . "'"; $q = db_query($qsql); while ($row = db_fetch_array($q)) { $locked_forms[$row['event_id'] . "," . $row['form_name']] = " <img src='" . APP_PATH_IMAGES . "lock_small.png' title='Locked on " . DateTimeRC::format_ts_from_ymd($row['timestamp']) . "'>"; } // E-signatures $qsql = "select event_id, form_name, timestamp from redcap_esignatures where project_id = {$project_id} and record = '" . prep($id) . "'"; $q = db_query($qsql); while ($row = db_fetch_array($q)) { $this_esign_ts = " <img src='" . APP_PATH_IMAGES . "tick_shield_small.png' title='E-signed on " . DateTimeRC::format_ts_from_ymd($row['timestamp']) . "'>"; if (isset($locked_forms[$row['event_id'] . "," . $row['form_name']])) { $locked_forms[$row['event_id'] . "," . $row['form_name']] .= $this_esign_ts; } else { $locked_forms[$row['event_id'] . "," . $row['form_name']] = $this_esign_ts; } } //Check if record exists in another group, if user is in a DAG if ($user_rights['group_id'] != "" && $existing_record) { $q = db_query("select 1 from redcap_data where project_id = {$project_id} and record = '" . prep($id) . "' and\n\t\t\t\t\t\t field_name = '__GROUPID__' and value = '{$user_rights['group_id']}' limit 1"); if (db_num_rows($q) < 1) { //Record is not in user's DAG print "<div class='red'>\n\t\t\t\t\t\t<img src='" . APP_PATH_IMAGES . "exclamation.png'>\n\t\t\t\t\t\t<b>{$lang['global_49']} " . $_GET['id'] . " {$lang['grid_13']}</b><br><br>\n\t\t\t\t\t\t{$lang['grid_14']}<br><br>\n\t\t\t\t\t\t<a href='" . APP_PATH_WEBROOT . "DataEntry/grid.php?pid={$project_id}' style='text-decoration:underline'><< {$lang['grid_15']}</a>\n\t\t\t\t\t\t<br><br>\n\t\t\t\t\t</div>"; include APP_PATH_DOCROOT . 'ProjectGeneral/footer.php'; exit; }