bug fix march continued (#1921)
[openemr.git] / interface / batchcom / emailnotification.php
blobec319376fb14badda4df65e806867b6c4e8c3b43
1 <?php
2 /**
3 * emailnotification script.
5 * @package OpenEMR
6 * @author cfapress
7 * @author Jason 'Toolbox' Oettinger <jason@oettinger.email>
8 * @link http://www.open-emr.org
9 * @copyright Copyright (c) 2008 cfapress
10 * @copyright Copyright (c) 2017 Jason 'Toolbox' Oettinger <jason@oettinger.email>
11 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
13 require_once("../globals.php");
14 require_once("$srcdir/registry.inc");
15 require_once("../../library/acl.inc");
16 require_once("batchcom.inc.php");
18 use OpenEMR\Core\Header;
20 // gacl control
21 if (!acl_check('admin', 'notification')) {
22 echo "<html>\n<body>\n<h1>";
23 echo xlt('You are not authorized for this.');
24 echo "</h1>\n</body>\n</html>\n";
25 exit();
28 // default value
29 $next_app_date = date("Y-m-d");
30 $hour="12";
31 $min="15";
32 $provider_name="EMR Group";
33 $message="Welcome to EMR Group";
34 $type = "Email";
35 $email_sender = "EMR Group";
36 $email_subject = "Welcome to EMR Group";
37 // process form
38 if ($_POST['form_action']=='save') {
39 if (!verifyCsrfToken($_POST["csrf_token_form"])) {
40 csrfNotVerified();
43 //validation uses the functions in notification.inc.php
44 if ($_POST['email_sender']=="") {
45 $form_err .= xl('Empty value in "Email Sender"') . '<br>';
48 if ($_POST['email_subject']=="") {
49 $form_err .= xl('Empty value in "Email Subject"') . '<br>';
52 //validate dates
53 if (!check_date_format($_POST['next_app_date'])) {
54 $form_err .= xl('Date format for "Next Appointment" is not valid') . '<br>';
57 // validates and or
58 if ($_POST['provider_name']=="") {
59 $form_err .= xl('Empty value in "Name of Provider"') . '<br>';
62 if ($_POST['message']=="") {
63 $form_err .= xl('Empty value in "Email Text"') . '<br>';
66 //process sql
67 if (!$form_err) {
68 $next_app_time = $_POST['hour'].":".$_POST['min'];
69 $sql_text = " ( `notification_id` , `sms_gateway_type` , `next_app_date` , `next_app_time` , `provider_name` , `message` , `email_sender` , `email_subject` , `type` ) ";
70 $sql_value = " (?, ?, ?, ?, ?, ?, ?, ?, ?) ";
71 $values = array($_POST['notification_id'], $_POST['sms_gateway_type'], $_POST['next_app_date'], $next_app_time,
72 $_POST['provider_name'], $_POST['message'], $_POST['email_sender'], $_POST['email_subject'],
73 $type);
74 $query = "REPLACE INTO `automatic_notification` $sql_text VALUES $sql_value";
75 //echo $query;
76 $id = sqlInsert($query, $values);
77 $sql_msg = xl("ERROR!... in Update");
78 if ($id) {
79 $sql_msg = xl("Email Notification Settings Updated Successfully");
84 // fetch data from table
85 $sql="select * from automatic_notification where type='Email'";
86 $result = sqlQuery($sql);
87 if ($result) {
88 $notification_id = $result['notification_id'];
89 $sms_gateway_type = $result['sms_gateway_type'];
90 $next_app_date = $result['next_app_date'];
91 list($hour,$min) = @explode(":", $result['next_app_time']);
92 $provider_name = $result['provider_name'];
93 $email_sender = $result['email_sender'];
94 $email_subject = $result['email_subject'];
95 $message = $result['message'];
98 //my_print_r($result);
100 // menu arrays (done this way so it's easier to validate input on validate selections)
101 $hour_array =array('00','01','02','03','04','05','06','07','08','09','10','11','12','13','14','15','16','17','18','19','21','21','22','23');
102 $min_array = array('00','05','10','15','20','25','30','35','40','45','50','55');
104 //START OUT OUR PAGE....
106 <html>
107 <head>
108 <?php Header::setupHeader(); ?>
109 <title><?php echo xlt("Email Notification"); ?></title>
110 </head>
111 <body class="body_top container">
112 <header class="row">
113 <?php require_once("batch_navigation.php");?>
114 <h1 class="col-md-12">
115 <a href="batchcom.php"><?php echo xlt('Batch Communication Tool'); ?></a>
116 <small><?php echo xlt('Email Notification'); ?></small>
117 </h1>
118 </header>
119 <main>
120 <?php
121 if ($form_err) {
122 echo '<div class="alert alert-danger">' . xlt('The following errors occurred') . ': ' . text($form_err) . '</div>';
125 if ($sql_msg) {
126 echo '<div class="alert alert-info">' . xlt('The following occurred') . ': ' . text($sql_msg) . '</div>';
129 <form name="select_form" method="post" action="">
130 <input type="hidden" name="csrf_token_form" value="<?php echo attr(collectCsrfToken()); ?>" />
131 <input type="Hidden" name="type" value="Email">
132 <input type="Hidden" name="notification_id" value="<?php echo attr($notification_id);?>">
133 <div class="row">
134 <div class="col-md-4 form-group">
135 <label for="email_sender"><?php echo xlt('Email Sender')?>:</label>
136 <input class="form-control" type="text" name="email_sender" size="40" value="<?php echo attr($email_sender); ?>" placeholder="<?php xla('sender name'); ?>">
137 </div>
138 <div class="col-md-4 form-group">
139 <label for="email_subject"><?php echo xlt('Email Subject')?>:</label>
140 <input class="form-control" type="text" name="email_subject" size="40" value="<?php echo attr($email_subject); ?>" placeholder="<?php xla('email subject'); ?>">
141 </div>
142 <div class="col-md-4 form-group">
143 <label for="provider_name"><?php echo xlt('Name of Provider')?>:</label>
144 <input class="form-control" type="text" name="provider_name" size="40" value="<?php echo attr($provider_name); ?>" placeholder="<?php xla('provider name'); ?>">
145 </div>
146 </div>
147 <div class="row">
148 <div class="col-md-12 form-group">
149 <label for="message"><?php echo xlt('SMS Text Usable Tags'); ?>: ***NAME***, ***PROVIDER***, ***DATE***, ***STARTTIME***, ***ENDTIME*** (i.e. Dear ***NAME***):</label>
150 <textarea class="form-control" cols="35" rows="8" name="message"><?php echo text($message); ?></textarea>
151 </div>
152 </div>
153 <div class="row">
154 <div class="col-md-12 form-group">
155 <button class="btn btn-default btn-save" type="submit" name="form_action" value="save"><?php echo xlt('Save'); ?></button>
156 </div>
157 </div>
158 </form>
159 </main>
160 </body>
161 </html>