fix: Update patient_tracker.php (#6595)
[openemr.git] / interface / batchcom / emailnotification.php
blobd40c4452d078d29e09e1016f2ca9d613b2b3a64c
1 <?php
3 /**
4 * emailnotification script.
6 * @package OpenEMR
7 * @author cfapress
8 * @author Jason 'Toolbox' Oettinger <jason@oettinger.email>
9 * @link http://www.open-emr.org
10 * @copyright Copyright (c) 2008 cfapress
11 * @copyright Copyright (c) 2017 Jason 'Toolbox' Oettinger <jason@oettinger.email>
12 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
15 require_once("../globals.php");
16 require_once("$srcdir/registry.inc.php");
17 require_once("batchcom.inc.php");
19 use OpenEMR\Common\Acl\AclMain;
20 use OpenEMR\Common\Csrf\CsrfUtils;
21 use OpenEMR\Common\Twig\TwigContainer;
22 use OpenEMR\Core\Header;
24 // gacl control
25 if (!AclMain::aclCheckCore('admin', 'notification')) {
26 echo (new TwigContainer(null, $GLOBALS['kernel']))->getTwig()->render('core/unauthorized.html.twig', ['pageTitle' => xl("Email Notification")]);
27 exit;
30 // process form
31 if (!empty($_POST['form_action']) && ($_POST['form_action'] == 'save')) {
32 if (!CsrfUtils::verifyCsrfToken($_POST["csrf_token_form"])) {
33 CsrfUtils::csrfNotVerified();
36 if (! is_numeric($_POST['notification_id'])) { // shouldn't happen
37 $form_err .= xl('Missing/invalid notification id') . '<br />';
40 if (empty($_POST['email_sender'])) {
41 $form_err .= xl('Empty value in "Email Sender"') . '<br />';
44 if (empty($_POST['email_subject'])) {
45 $form_err .= xl('Empty value in "Email Subject"') . '<br />';
48 if (empty($_POST['provider_name'])) {
49 $form_err .= xl('Empty value in "Name of Provider"') . '<br />';
52 if (empty($_POST['message'])) {
53 $form_err .= xl('Empty value in "Email Text"') . '<br />';
56 // Store the new settings. sms_gateway_type is not used for email.
57 // notification_id is the pk, and should always be 2 for email settings.
59 if (!$form_err) {
60 $sql_text = " ( `notification_id` , `sms_gateway_type` , `provider_name` , `message` , `email_sender` , `email_subject` , `type` ) ";
61 $sql_value = " (?, ?, ?, ?, ?, ?, ?) ";
62 $values = array($_POST['notification_id'], '', $_POST['provider_name'],
63 $_POST['message'], $_POST['email_sender'],
64 $_POST['email_subject'], 'Email');
65 $query = "REPLACE INTO `automatic_notification` $sql_text VALUES $sql_value";
66 //echo $query;
67 $id = sqlInsert($query, $values);
68 $sql_msg = xl("ERROR!... in Update");
69 if ($id) {
70 $sql_msg = xl("Email Notification Settings Updated Successfully");
75 // fetch email config from table. This should never fail, because one row
76 // of each type is seeded when the db is created.
77 $sql = "select * from automatic_notification where type='Email'";
78 $result = sqlQuery($sql);
79 if ($result) {
80 $notification_id = $result['notification_id'];
81 $provider_name = $result['provider_name'];
82 $email_sender = $result['email_sender'];
83 $email_subject = $result['email_subject'];
84 $message = $result['message'];
85 } else {
86 $sql_msg = xl('Missing email config record');
89 //my_print_r($result);
91 //START OUT OUR PAGE....
93 <html>
94 <head>
95 <?php Header::setupHeader(); ?>
96 <title><?php echo xlt("Email Notification"); ?></title>
97 </head>
98 <body class="body_top container">
99 <header class="row">
100 <?php require_once("batch_navigation.php");?>
101 <h1 class="col-md-12">
102 <a href="batchcom.php"><?php echo xlt('Batch Communication Tool'); ?></a>
103 <small><?php echo xlt('Email Notification'); ?></small>
104 </h1>
105 </header>
106 <main class="mx-4">
107 <?php
108 if (!empty($form_err)) {
109 echo '<div class="alert alert-danger">' . xlt('The following errors occurred') . ': ' . text($form_err) . '</div>';
112 if (!empty($sql_msg)) {
113 echo '<div class="alert alert-info">' . xlt('The following occurred') . ': ' . text($sql_msg) . '</div>';
116 <form name="select_form" method="post" action="">
117 <input type="hidden" name="csrf_token_form" value="<?php echo attr(CsrfUtils::collectCsrfToken()); ?>" />
118 <input type="Hidden" name="type" value="Email">
119 <input type="Hidden" name="notification_id" value="<?php echo attr($notification_id);?>">
120 <div class="row">
121 <div class="col-md-4 form-group">
122 <label for="email_sender"><?php echo xlt('Email Sender')?>:</label>
123 <input class="form-control" type="text" name="email_sender" size="40" value="<?php echo attr($email_sender); ?>" placeholder="<?php xla('sender name'); ?>">
124 </div>
125 <div class="col-md-4 form-group">
126 <label for="email_subject"><?php echo xlt('Email Subject')?>:</label>
127 <input class="form-control" type="text" name="email_subject" size="40" value="<?php echo attr($email_subject); ?>" placeholder="<?php xla('email subject'); ?>">
128 </div>
129 <div class="col-md-4 form-group">
130 <label for="provider_name"><?php echo xlt('Name of Provider')?>:</label>
131 <input class="form-control" type="text" name="provider_name" size="40" value="<?php echo attr($provider_name); ?>" placeholder="<?php xla('provider name'); ?>">
132 </div>
133 </div>
134 <div class="row">
135 <div class="col-md-12 form-group">
136 <label for="message"><?php echo xlt('Email Text Usable Tags'); ?>: ***NAME***, ***PROVIDER***, ***DATE***, ***STARTTIME***, ***ENDTIME*** (i.e. Dear ***NAME***):</label>
137 <textarea class="form-control" cols="35" rows="8" name="message"><?php echo text($message); ?></textarea>
138 </div>
139 </div>
140 <div class="row">
141 <div class="col-md-12 form-group">
142 <button class="btn btn-secondary btn-save" type="submit" name="form_action" value="save"><?php echo xlt('Save'); ?></button>
143 </div>
144 </div>
145 </form>
146 </main>
147 </body>
148 </html>