Dialog styles (#7797)
[openemr.git] / interface / batchcom / smsnotification.php
bloba31ed1c74a0c48f22d0ed4becb9132f07c850c16
1 <?php
3 /**
4 * smsnotification 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("SMS 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['sms_gateway_type'])) {
41 $form_err .= xl('Error in "SMS Gateway" selection') . '<br />';
44 if (empty($_POST['provider_name'])) {
45 $form_err .= xl('Empty value in "Name of Provider"') . '<br />';
48 if (empty($_POST['message'])) {
49 $form_err .= xl('Empty value in "SMS Text"') . '<br />';
52 // Store the new settings. email_sender and email_subject are not used
53 // by SMS, but must be present because they are NOT NULL. notification_id
54 // is the pk, and should always be 1 for SMS settings (because that's how
55 // the db was seeded).
57 if (!$form_err) {
58 $sql_text = " ( `notification_id` , `sms_gateway_type` , `provider_name` , `message` , `email_sender` , `email_subject` , `type` ) ";
59 $sql_value = " (?, ?, ?, ?, ?, ?, ?) ";
60 $values = array($_POST['notification_id'], $_POST['sms_gateway_type'],
61 $_POST['provider_name'], $_POST['message'],
62 '', '', 'SMS');
63 $query = "REPLACE INTO `automatic_notification` $sql_text VALUES $sql_value";
64 //echo $query;
65 $id = sqlInsert($query, $values);
66 $sql_msg = xl("ERROR!... in Update");
67 if ($id) {
68 $sql_msg = xl("SMS Notification Settings Updated Successfully");
73 // fetch SMS config from table. This should never fail, because one row
74 // of each type is seeded when the db is created.
76 $sql = "select * from automatic_notification where type='SMS'";
77 $result = sqlQuery($sql);
78 if ($result) {
79 $notification_id = $result['notification_id'];
80 $sms_gateway_type = $result['sms_gateway_type'];
81 $provider_name = $result['provider_name'];
82 $message = $result['message'];
83 } else {
84 $sql_msg = xl('Missing SMS config record');
87 // array of legal values for sms_gateway_type. This is a string field in
88 // the db, not an enum, so new values can be added here with no db change.
89 $sms_gateway = array ('CLICKATELL','TMB4');
91 //START OUT OUR PAGE....
93 <html>
94 <head>
95 <?php Header::setupHeader(); ?>
96 <title><?php echo xlt("SMS 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('SMS 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="SMS">
119 <input type="hidden" name="notification_id" value="<?php echo attr($notification_id); ?>">
120 <div class="row">
121 <div class="col-md-6 form-group">
122 <label for="sms_gateway_type"><?php echo xlt('SMS Gateway') ?>:</label>
123 <select name="sms_gateway_type" class="form-control">
124 <option value=""><?php echo xlt('Select SMS Gateway'); ?></option>
125 <?php foreach ($sms_gateway as $value) { ?>
126 <option value="<?php echo attr($value); ?>"
127 <?php
128 if ($sms_gateway_type == $value) {
129 echo "selected";
131 echo ">" . text($value);
133 </option>
134 <?php }?>
135 </select>
136 </div>
137 <div class="col-md-6 form-group">
138 <label for="provider_name"><?php echo xlt('Name of Provider'); ?>:</label>
139 <input class="form-control" type="text" name="provider_name" size="40" value="<?php echo attr($provider_name); ?>" placeholder="<?php xla('provider name'); ?>">
140 </div>
141 </div>
142 <div class="row">
143 <div class="col-md-12 form-group">
144 <label for="message"><?php echo xlt('SMS Text Usable Tags:'); ?>***NAME***, ***PROVIDER***, ***DATE***, ***STARTTIME***, ***ENDTIME*** (i.e. Dear ***NAME***):</label>
145 <textarea class="form-control" cols="35" rows="8" name="message"><?php echo text($message); ?></textarea>
146 </div>
147 </div>
148 <div class="row">
149 <div class="col-md-12 form-group">
150 <button class="btn btn-secondary btn-save" type="submit" name="form_action" value="save"><?php echo xlt('Save'); ?></button>
151 </div>
152 </div>
153 </form>
154 </main>
155 </body>
156 </html>