<?php
/**
 * @copyright 2021 Double Bastion LLC <www.doublebastion.com>
 *
 * @author Double Bastion LLC
 *
 * @license GNU AGPL version 3 or any later version
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
 * License as published by the Free Software Foundation; either
 * version 3 of the License, or any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
 *
 * You should have received a copy of the GNU Affero General Public
 * License along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

declare(strict_types=1);

script('sms_relentless', 'settings');
style('sms_relentless', 'style');

?>

<div id="sms_relentless_adm">
        <div class="section">
           <h2><?php p($l->t('SMS Relentless'));?></h2>
           <p id="settings-dscr"><h3><?php p($l->t('Please enter your credentials and options in the fields from below. As SMS service provider you can use Telnyx or Plivo or 
              both.')); ?></h3></p><br>
           <div class="sms_followupsection">

                <form id="prov_credentials" action="#" >

                   <div class="providerSettings">
                   <p style="font-size:18px;font-weight:bold;margin-bottom:20px;">Telnyx Settings</p>
                   <p><label for="telapi_key" class="setlabeltext"><b>Telnyx API Secret Key</b> (Log in to Telnyx, click on 'API Keys' on the left panel, click 'Create API Key',
                          copy the Key somewhere safe, then enter it in the field from below.):</label></p>
                   <input type="password" class="smsr_textbox" id="telapi_key" name="telapi_key" autocomplete="false"
                          placeholder="<?php p($l->t('e.g. d6f172ce92e4f2 ...')); ?>" /><br>

                   <p><label for="tel_pub_key" class="setlabeltext"><b>Telnyx Account Public Key</b> (While logged in to Telnyx, click on 'API Keys' on the left panel, click on 'Public
                          Key' on the upper bar, then copy the public key from the 'Key' field and enter it in the field from below.):</label></p>
                   <input type="password" class="smsr_textbox" id="tel_pub_key" name="tel_pub_key" autocomplete="false"
                          placeholder="<?php p($l->t('e.g. KLCnMsTSp8utW3RRHx0FiXxbf5BxK2Y5q8mMTCn0jgv=')); ?>" /><br>

                   <p><label for="messaging_profile_id" class="setlabeltext"><b>Messaging Profile ID</b> (While logged in to Telnyx, click on 'Messaging' on the left panel, click on 
                       the name of the messaging profile that you want to use, then under 'Profile ID' you will find the messaging profile ID. Copy it and enter it in the field from 
                       below.):
                   </label></p>
                   <input type="password" class="smsr_textbox" id="messaging_profile_id" name="messaging_profile_id" autocomplete="false"
                          placeholder="<?php p($l->t('e.g. 9d4f47b6-26c9-d25c-c2f5 ...')); ?>" /><br>

                   <p><label for="telapi_url_rec" class="setlabeltext"><b>Telnyx webhook URL for incoming SMS</b> (You have to first generate and then copy this URL into your Telnyx
                       account, so that Telnyx knows where to deliver the SMS messages received by your Telnyx phone number(s). First generate the URL by pressing the button from
                       below, copy it, then, in your Telnyx account click on 'Messaging' on the left panel, click on the name of the messaging profile that you associated with your
                       phone number(s), then, under 'Inbound Settings', enter the webhook URL generated here in the field 'Send a webhook to this URL' and click 'Save'. Don't forget
                       to also click the 'Save' button at the bottom of this page to save all the settings to the database.)</label></p>
                   <input type="button" id="generate_tel_rcpt" value="<?php p($l->t('Generate new webhook URL for incoming SMS')) ?>" />
                   <input type="text" class="smsr_textboxspec" id="telapi_url_rec" name="telapi_url_rec" autocomplete="false" />
                   <span id="copyToClipboardtel" class="icon icon-clippy" title="Copy to clipboard"></span><br><br>

                   <p><label for="telapi_url" class="setlabeltext"><b>Telnyx webhook URL for delivery receipts</b> (This URL will be included by SMS Relentless in SMS
                       message sending requests, so that Telnyx will know where to send the delivery receipts. Just generate it by pressing the button from below.
                       You don't have to enter this URL into your Telnyx account. Don't forget to click the 'Save' button at the bottom of this page to save all the
                       settings to the database.)</label></p>
                   <input type="button" id="generate_tel_delrcpt" value="<?php p($l->t('Generate new webhook URL for delivery receipts')) ?>" />
                   <input type="text" id="telapi_url" name="telapi_url" autocomplete="false" /><br><br>

                   <p><label for="tel_sender_name" class="setlabeltext"><b>Telnyx alphanumeric Sender ID</b> (It should be an alphanumeric sequence of up to 11 characters in the range
                          of a-z, A-Z, 0-9 and space. In certain countries there are regulations that accept only shorter alphanumeric Sender IDs, such as up to 6 characters. You cannot
                          send SMS messages with alphanumeric Sender IDs to USA or Canada. There are even 
                          <a href="https://support.plivo.com/hc/en-us/articles/360041448032" style="color:#1b60ba" target="_blank" rel="noreferrer noopener">countries</a> that require
                          preregistration of alphanumeric Sender IDs. Before sending SMS messages to a country please read the
                          <a href="https://help.nexmo.com/hc/en-us/sections/200622473-Country-Specific-Features-and-Restrictions" style="color:#1b60ba" target="_blank"
                          rel="noreferrer noopener">country specific features and restrictions.</a> Some carriers won't accept messages with an alphanumeric Sender ID): </label></p>
                   <input type="text" class="smsr_textbox" id="tel_sender_name" name="tel_sender_name" autocomplete="false"
                          placeholder="<?php p($l->t('e.g. Smart Inc')); ?>" />
                   </div><br><br><br>

                   <div class="providerSettings">
                   <p style="font-size:18px;font-weight:bold;margin-bottom:20px;">Plivo Settings</p>
                   <p><label for="nexapi_key" class="setlabeltext"><b>Plivo Auth ID</b> (Log in to Plivo; on the first page which is the Overview page, under Account, copy the 'Auth ID'
                          and enter it in the field from below.):</label></p>
                   <input type="password" class="smsr_textbox" id="nexapi_key" name="nexapi_key" autocomplete="false"
                          placeholder="<?php p($l->t('e.g. r5g974cb92e4t1 ...')); ?>" /><br>

                   <p><label for="nexapi_secret" class="setlabeltext"><b>Plivo Auth Token</b> (While logged in to Plivo, on the Overview page, under Account, copy the 'Auth Token' and
                          enter it in the field from below.):</label></p>
                   <input type="password" class="smsr_textbox" id="nexapi_secret" name="nexapi_secret" autocomplete="false"
                          placeholder="<?php p($l->t('e.g. k6f489d8awn4p9 ...')); ?>" /><br>

                   <p><label for="nexapi_url_rec" class="setlabeltext"><b>Plivo webhook URL for incoming SMS</b> (You have to first generate and then copy this URL into your Plivo
                       account, so that Plivo knows where to deliver the SMS messages received by your Plivo phone number(s). First generate the URL by pressing the button from
                       below, copy it, then, in your Plivo account click on 'Messaging' on the left vertical bar, click on 'Applications', then, under 'Application name' click on
                       'Inbound SMS Messages', next, under 'Message', enter the webhook URL generated here in the field 'Message URL' and select 'POST' next to it, then click the
                       'Update Application' button. Don't forget to also click the 'Save' button at the bottom of this page to save all the settings to the database.)</label></p>
                   <input type="button" id="generate_nex_rcpt" value="<?php p($l->t('Generate new webhook URL for incoming SMS')) ?>" />
                   <input type="text" class="smsr_textboxspec" id="nexapi_url_rec" name="nexapi_url_rec" autocomplete="false" />
                   <span id="copyToClipboardnex" class="icon icon-clippy" title="Copy to clipboard"></span><br><br>

                   <p><label for="nexapi_url" class="setlabeltext"><b>Plivo webhook URL for delivery receipts</b> (This URL will be included by SMS Relentless in SMS
                       message sending requests, so that Plivo will know where to send the delivery receipts. Just generate it by pressing the button from below.
                       You don't have to enter this URL into your Plivo account. Don't forget to click the 'Save' button at the bottom of this page to save all the settings
                       to the database.)</label></p>
                   <input type="button" id="generate_nex_delrcpt" value="<?php p($l->t('Generate new webhook URL for delivery receipts')) ?>" />
                   <input type="text" id="nexapi_url" name="nexapi_url" autocomplete="false" /><br><br>

                   <p><label for="nex_sender_name" class="setlabeltext"><b>Plivo alphanumeric Sender ID:</b> (It should be an alphanumeric sequence of up to 11 characters in the range
                          of a-z, A-Z, 0-9 and space. In certain countries there are regulations that accept only shorter alphanumeric Sender IDs, such as up to 6 characters. You cannot
                          send SMS messages with alphanumeric Sender IDs to USA or Canada. There are even 
                          <a href="https://support.plivo.com/hc/en-us/articles/360041448032" style="color:#1b60ba" target="_blank" rel="noreferrer noopener">countries</a> that require
                          preregistration of alphanumeric Sender IDs. Before sending SMS messages to a country please read the
                          <a href="https://help.nexmo.com/hc/en-us/sections/200622473-Country-Specific-Features-and-Restrictions" style="color:#1b60ba" target="_blank"
                          rel="noreferrer noopener">country specific features and restrictions.</a> Some carriers won't accept messages with an alphanumeric Sender ID): </label></p>
                   <input type="text" class="smsr_textbox" id="nex_sender_name" name="nex_sender_name" autocomplete="false"
                          placeholder="<?php p($l->t('e.g. Global Inc')); ?>" />
                   </div><br><br><br>

                   <p><label for="messagesperpage" class="setlabeltext"><b>Number of messages per page</b> (Enter the number of messages to be displayed on one page of the
                          received and sent messages tables. If you don't enter anything in this field, the default of 100 messages per page will be used.):</label></p>
                   <input type="number" class="smsr_textbox" id="messagesperpage" name="messagesperpage" autocomplete="false" placeholder="<?php p($l->t('e.g. 100')); ?>"/><br>

                   <p><label for="get_notify" class="setlabeltext"><b>I want to see a notification in Nextcloud when a new SMS is received:</b></label></p>
                   <input type="checkbox" class="sms_rel_checkbox" id="get_notify" name="get_notify" autocomplete="false" /><br>

                   <p class="setlabeltext">To enable email notifications for every received SMS, the "sendmail" utility ("/usr/sbin/sendmail" on Debian Linux),
                      has to be present on the server. "sendmail" is a binary which gets installed when Postfix is installed. Also the server user (www-data) has to be
                      allowed to send emails from command line (by specifying "authorized_submit_users = www-data" in "/etc/postfix/main.cf" for Postfix on a Debian based
                      Linux).</p><br>

                   <p><label for="notification_email" class="setlabeltext"><b>I want to receive a notification to the email address from below, when a new SMS is
                      received:</b></label></p>
                   <input type="text" class="smsr_textbox" id="notification_email" name="notification_email" autocomplete="false"
                          placeholder="<?php p($l->t('e.g. john.doe@example.com')); ?>" /><br>

                   <p><label for="includesmsinemail" class="setlabeltext"><b>Include the SMS message in the email notification itself:</b></label></p>
                   <input type="checkbox" class="sms_rel_checkbox" id="includesmsinemail" name="includesmsinemail" autocomplete="false" /><br>

                   <input type="hidden" id="user_id" name="user_id" />

                   <input id="save_sms_settings" type="submit" value="<?php p($l->t('Save')) ?>" />

                   <span id="smsr_save_msg"></span>

               </form>
           </div>
        </div>
</div>