-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathpreviewRecordModal.php
More file actions
70 lines (60 loc) · 3.21 KB
/
Copy pathpreviewRecordModal.php
File metadata and controls
70 lines (60 loc) · 3.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
namespace Vanderbilt\EmailTriggerExternalModule;
use ExternalModules\AbstractExternalModule;
use ExternalModules\ExternalModules;
$project_id = (int)$_GET['pid'];
$index = htmlentities($_REQUEST['index_modal_alert'],ENT_QUOTES);
#get data from the DB
$form_name_event = empty($module->getProjectSetting('form-name-event'))?array():$module->getProjectSetting('form-name-event')[$index];
if($form_name_event != ""){
$form_name_event = \REDCap::getEventIdFromUniqueEvent($form_name_event);
}
$sql = "SELECT b.event_id FROM redcap_events_arms a LEFT JOIN redcap_events_metadata b ON(a.arm_id = b.arm_id) where a.project_id ='".db_escape($project_id)."'";
$q = db_query($sql);
$repeatable = false;
if (db_num_rows($q)) {
while($row = db_fetch_assoc($q)) {
$form_name = empty($module->getProjectSetting('form-name'))?array():$module->getProjectSetting('form-name');
foreach ($form_name as $form){
$project_name = db_escape(\Project::getValidProjectName($form));
$event_id = $row['event_id'];
$sql = "SELECT * FROM redcap_events_repeat WHERE event_id='".db_escape($event_id)."' AND form_name='".db_escape($project_name)."'";
$q = db_query($sql);
$row = db_fetch_assoc($q);
if ($row) {
$repeatable = true;
break;
}
}
}
}
$events_array = array();
$event_selector = "";
if(\REDCap::isLongitudinal() || $repeatable){
$event_selector = "<div style='padding-bottom: 60px;'><input type='text' name='preview_record_id' id='preview_record_id' placeholder='Type a record' style='width: 80%;float: left;'>
<a href='#' class='btn btn-default save' onclick='loadPreviewEmailAlertRecord()' id='preview_record_id_btn' style='float: left;margin-left: 20px;padding-top: 8px;padding-bottom: 7px;'>Preview</a></div>";
}else {
if($form_name_event != ""){
$data = \REDCap::getData($project_id, 'array',null,'record_id',$form_name_event);
}else{
$data = \REDCap::getData($project_id, 'array',null,'record_id');
}
if (count($data) < 500) {
foreach ($data as $record_id => $event) {
array_push($events_array, $record_id);
}
if (!empty($events_array)) {
$event_selector = '<div style="padding-bottom:10px">'.
'<select class="external-modules-input-element" name="preview_record_id" onchange="loadPreviewEmailAlertRecord()"><option value="">Select a Record</option>';
foreach ($events_array as $id) {
$event_selector .= '<option value="' . htmlentities($id,ENT_QUOTES) . '" >' . htmlentities($id,ENT_QUOTES) . '</option>';
}
$event_selector .= '</select></div>';
}
} else {
$event_selector = "<div style='margin-bottom: 60px;'><input type='text' name='preview_record_id' id='preview_record_id' placeholder='Type a record' style='width: 80%;float: left;'>
<a href='#' class='btn btn-default save' onclick='loadPreviewEmailAlertRecord()' id='preview_record_id_btn' style='float: left;margin-left: 20px;padding-top: 8px;padding-bottom: 7px;'>Preview</a></div>";
}
}
echo $event_selector;
?>