4 * smsnotification script.
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
;
25 if (!AclMain
::aclCheckCore('admin', 'notification')) {
26 echo (new TwigContainer(null, $GLOBALS['kernel']))->getTwig()->render('core/unauthorized.html.twig', ['pageTitle' => xl("SMS Notification")]);
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).
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'],
63 $query = "REPLACE INTO `automatic_notification` $sql_text VALUES $sql_value";
65 $id = sqlInsert($query, $values);
66 $sql_msg = xl("ERROR!... in Update");
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);
79 $notification_id = $result['notification_id'];
80 $sms_gateway_type = $result['sms_gateway_type'];
81 $provider_name = $result['provider_name'];
82 $message = $result['message'];
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....
95 <?php Header
::setupHeader(); ?
>
96 <title
><?php
echo xlt("SMS Notification"); ?
></title
>
98 <body
class="body_top container">
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
>
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); ?>">
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); ?>"
128 if ($sms_gateway_type == $value) {
131 echo ">" . text($value);
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'); ?>">
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
>
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
>