<?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', 'sendsms');
script('sms_relentless', 'showsmstables');
script('sms_relentless', 'deleteoldsms');
style('sms_relentless', 'style');

?>


<div id="smsrelentless_vbar">

       <div id="currentbaldiv" class="cllridcls">
            <div id="showsum">Balance:</div>
            <select id="smsprovider" class="optselectprov">
                    <option value="" selected="selected" disabled hidden class="selectsmsprov">select</option>
                    <option value="Telnyx" class='selectsmsprov'>Telnyx</option>
                    <option value="Plivo" class='selectsmsprov'>Plivo</option>
            </select>           
            <span id="currentbalance"></span>
            <div class="tooltipbalanceid">
                <div id="infobalance">i</div>
                <span class="balancetooltip">To see the current balance, select a provider from the drop-down list. The balance will be rounded to 3 decimal places and the
                      currency will be the one set up in that respective account. You can see Telnyx prices <a href="https://telnyx.com/pricing/messaging" style="color:#1b60ba"
                      target="_blank" rel="noreferrer noopener">here</a> and Plivo prices <a href="https://www.plivo.com/sms/pricing/us/" style="color:#1b60ba" target="_blank"
                      rel="noreferrer noopener">here</a>.
                </span>
            </div>
       </div>

       <div id="smsnumbersdiv" class="cllridcls">
            <div id="pickid">Set ID:</div>
            <select id="currentsmsnmbrs" class="optselectsmsnb">
                  <option value='' selected="selected" disabled hidden class="optselectsmsnb">click refresh button</option>
            </select>
            <button id="selectcalleridbttn" title="Refresh the list of Sender IDs."></button>
            <div class="tooltipsetid">
                <div id="infotipid">i</div>
                <span class="calleridtooltip">First refresh the list, then select a Sender ID from the drop-down list. The Sender ID is the 'From' field that is displayed on
                    the user's phone when receiving your message. It can be a phone number or an alphanumeric sequence. You must choose as Sender ID one of
                    your numbers, or an alphanumeric sequence that you have set in Settings > SMS Relentless > 'Telnyx/Plivo alphanumeric Sender ID' field. Please note that
                    <font style="color:#aa2e4b">there are local restrictions based on market regulations or carrier-specific, that can prevent SMS
                    messages to reach their destination because of their Sender ID.</font> For example, in USA and Canada, incoming SMS messages with alphanumeric Sender IDs
                    are not accepted. All messages to phone numbers in USA and Canada must have a phone number as Sender ID. Before sending SMS messages to a country,
                    please read about the Sender ID restrictions specific to that country, on websites like
                    <a href="https://help.nexmo.com/hc/en-us/sections/200622473-Country-Specific-Features-and-Restrictions" style="color:#1b60ba" target="_blank" 
                    rel="noreferrer noopener">this</a>. If you use alphanumeric Sender IDs, there are even
                    <a href="https://support.plivo.com/hc/en-us/articles/360048268071" style="color:#1b60ba" target="_blank" rel="noreferrer noopener">countries</a> that require
                    that you pre-register your Sender ID. If you use Telnyx, to be able to select a phone number as Sender ID, you must have a 'Messaging Profile' associated
                    with that phone number.
               </span>
            </div>
       </div>

       <div  class="srheader">
            Enter the recipient's number as:
       </div>
       <div class="smsnbformat">
            <a href="https://en.wikipedia.org/wiki/List_of_country_calling_codes#Alphabetical_listing_by_country_or_region" style="color:#1b60ba"
               target="_blank" rel="noreferrer noopener">country_code</a><font style="color:#aa2e4b">phone_number</font>
       </div>
       <div class="fortooltip"><font class="texttooltip">i</font>
         <span class="fortooltiptext">
            For example, to send an SMS to the German number 1212121212 you should enter 491212121212, where 49 is the calling code of Germany. The
            <a href="https://en.wikipedia.org/wiki/List_of_country_calling_codes#Alphabetical_listing_by_country_or_region"
            style="color:#1b60ba" target="_blank" rel="noreferrer noopener">country calling code</a> must be always included, even if the SMS is sent locally. Don't add the '+'
            sign or '00' in front of the number. Please note that <font style="color:#aa2e4b">in different countries there are market regulations and restrictions that
            can prevent certain SMS messages to reach their destination (such as when the text contains repetitive URLs) or can make them illegal
            (such as when sending messages that advertise money-lending services).</font> Before sending SMS messages to a country, please read about the
            restrictions that apply to that country, on websites like
            <a href="https://help.nexmo.com/hc/en-us/sections/200622473-Country-Specific-Features-and-Restrictions" style="color:#1b60ba" target="_blank" rel="noreferrer noopener">
            this</a>. You cannot send SMS messages from a Plivo 10 digit number to itself. To send the same message to multiple recipients, you can enter their phone numbers one after 
            the other separated by comma, in the phone number box. If you want to send the same message to more than 10 phone numbers at once, it's recommended to upload a txt/csv file 
            containing the recipients' phone numbers, by using the option from below. If you check the checkbox from below, you will be able to upload a file containing phone numbers, 
            to set up a sending rate different from the default 1 message per second and the info note will explain what are the sending rate restrictions that you will have to 
            consider.
         </span>
       </div>

   <div id="smstodiv">
       <input type="text" id="smsto" name="smsto" />
   </div>

   <div id="sendtomultiple">
      Upload file with phone numbers:
   </div>

   <div id="tomultiplechck">
      <input type="checkbox" id="tomultchckbx"/>
   </div>

   <div id="multiplerecivers">
       <div class="fortooltipsec"><font class="texttooltip">i</font>
          <span class="fortooltiptextsec">To send an SMS to a large number of recipients, please upload a file containing the recipients' phone numbers.
              Supported formats are txt and csv. The phone numbers can be separated by comma (,) , semicolon (;) , vertical bar (|) , or by new line.
              The duplicate phone numbers will be automatically removed. If the numbers contain dots, hyphens or plus signs, they will be also automatically removed.
              After uploading the file, enter the time interval (in milliseconds; 1 second has 1000 milliseconds) between two consecutive message sending requests,
              in the box from below. Please note that there are country specific and carrier imposed sending rate restrictions. For Telnyx, if you have rented a US or Canadian long 
              code (10 digit number), the allowed SMS sending rate will be 
              <a href="https://support.telnyx.com/en/articles/96934-throughput-limit-for-outbound-long-code-sms" style="color:#1b60ba" target="_blank" rel="noreferrer noopener">1 
              message per 6 seconds per number</a> and 200 messages per day per number (imposed by cell phone carriers). If you need a higher throughput, you can rent toll-free numbers 
              (with sending rates of 20 messages per second per number and no daily limit) or short codes (with sending rates of 1000 messages per second per number and no daily limit). 
              For Plivo, if you have rented a US or Canadian 10 digit number, you can send SMS messages at a rate of 
              <a href="https://support.plivo.com/hc/en-us/articles/360041314852-What-s-the-outgoing-rate-limit-for-SMS-messages-" style="color:#1b60ba" target="_blank" 
              rel="noreferrer noopener">1 message per 4 seconds</a> and 
              <a href="https://support.plivo.com/hc/en-us/articles/360041799611-How-do-I-send-6000-or-more-SMS-per-day-using-a-long-code-in-the-US-" style="color:#1b60ba" target="_blank"
              rel="noreferrer noopener">200 messages per day per number.</a> If you need a higher throughput, you can rent toll-free numbers (with rates of 10 messages per second per 
              number and no daily limit) or short codes (with rates of 100 messages per second per number and no daily limit). These sending rate limits don't necessarily apply when 
              using non-US and non-Canadian phone numbers to send SMS messages to non-US and non-Canadian phone numbers. Also, in general, custom sending rates may be obtained if you 
              contact Telnyx/Plivo support and explain your use case. Starting from 2021, if you want to send A2P (Application-To-Person) SMS messages to phone numbers belonging to 
              certain carriers in the US, such as AT&T, you will need to register your brand and your campaign with those carriers via 
              <a href="https://support.telnyx.com/en/articles/3679260-10dlc-faq-s" style="color:#1b60ba" target="_blank" rel="noreferrer noopener">Telnyx</a> or
              <a href="https://www.plivo.com/blog/a2p-10dlc/" style="color:#1b60ba" target="_blank" rel="noreferrer noopener">Plivo</a>. If you leave the box from below empty, the 
              application will try to send all the messages with the default sending rate of 1 message per second. If you send messages from a US or Canadian long code number and you 
              surpass the limit of 1 message per 6 seconds for Telnyx and 1 message per 4 seconds for Plivo, both Telnyx and Plivo will queue your messages and will send them at the
              specified rates in the order they were received. However, if you send a large number of messages, when the queue becomes full, new messages can be rejected and lost, 
              therefore, to prevent message loss, it's recommended to set the right sending rate in the box from below.
          </span>
       </div>
       <div id="multsetrows">
          <div id="fileuploadednm" class="fileuploadstl"></div>
          <div class="uploadfiledv">
              <form class="uploadflbt"  enctype="multipart/form-data" >
                  <label for="uploadfileforsms" class="pfprompt"><span id="uploadflprmpt"><?php p($l->t('Upload the file ')) ?></span></label>
                  <input id="uploadfileforsms" class="fileupload" name="uploadedtosms" type="file" />
                  <label for="uploadfileforsms" class="button icon-upload svg" id="uploadfileforsms" </label>
              </form>
          </div>
          <span id="sms_upload_msg"></span>
          <span class="entertime">Enter the time interval between consecutive messages, in milliseconds:</span><input type="text"
          id="multsmsinterval" placeholder="Eg.: 10000" />
       </div>
   </div>
   <div id="unicodesection">
     <div class="sendunicodedv"><font class="texttooltip">i</font>
         <span class="unicodedescr">If you use Telnyx, check this option to encode your message in Unicode, only if your message contains special characters (such as "ë" or "â")
            that don't exist in the
            <a href="https://en.wikipedia.org/wiki/GSM_03.38#GSM_7-bit_default_alphabet_and_extension_table_of_3GPP_TS_23.038_.2F_GSM_03.38" style="color:#1b60ba"
            target="_blank" rel="noreferrer noopener"> GSM 7-bit default alphabet table.</a> If your message contains the specified type of characters and you don't encode it in Unicode,
            the respective characters will be replaced with '?' or other symbols. If you use Plivo, you don't need to check this option because if your message contains
            characters that are not in the GSM 7-bit default alphabet table, the entire message will be automatically encoded using the UCS-2 character encoding (similar to Unicode).
         </span>
     </div>
     <div id="sendinunicode">Send SMS in Unicode:</div>
     <div id="sendunicodesms"><input type="checkbox" id="unicodechckbx"/></div>
   </div>

   <textarea id="smstext"  name="smstext" placeholder="Enter a message, then press 'Send SMS'."></textarea>

   <div class="maxmessagelength"><font class="texttooltip">i</font>
       <span class="maxlengthtooltip">
            The maximum length allowed for messages using the standard GSM 03.38 encoding is 160 characters (fewer in some countries),
            while for Unicode encoded messages is 70 characters (fewer in some countries).
            If you send a message longer than 160 characters for standard GSM encoding or longer than 70 characters for Unicode encoding, the message will be sent
            as a 'concatenated' message: it will be split into smaller pieces by Telnyx/Plivo and it will be reassembled as one message at its destination. However, you
            will be charged for each piece as for a separate SMS. Thus, if the initial message is 385 GSM encoded characters in length, you will be charged for 3
            SMS messages. The maximum number of characters per concatenated message is slightly smaller than the standard 160 for GSM encoded characters and 70 for
            Unicode, due to the inclusion of concatenation headers. Some symbols in the GSM 7-bit alphabet table (like "£" or "€") will count as two characters, so
            not always 160 characters will fit into a single GSM encoded SMS.
       </span>
   </div>

   <div id="char_count"><span id="countchnb"></span><span> characters</span></div>

   <input type="submit" id="submitsms" value="Send SMS" />
   <span id="sms_submit_msg"></span>

   <div id="dirbuttons">
       <button id="receivedsmstable" class="opensmsfolder">Received SMS Messages</button>
       <button id="sentsmstable" class="opensmsfolder">Sent SMS Messages</button>
   </div>


   <div id="deleteoldmssgs">
      Remove old messages:
   </div>

   <div id="deleteoldchck">
      <input type="checkbox" id="deleteoldchckbox" />
   </div>

   <div id="deleteoldsms">
       <div class="fortooltiptert"><font class="texttooltip">i</font>
          <span class="fortooltiptexttert">Since this application records all incoming and outgoing SMS messages, in time, its database can become very large, which
              can slow it down. To avoid having to work with extremely large tables, it's recommended that you delete from time to time all the sent/received messages older than 
              a specified number of days (for example 180 days). All the messages deleted using the options from below will be preserved, because they will be saved as csv files
              before being deleted from the database. The csv files will contain all the data of the deleted messages, they will bear the date of the removal and they will be
              stored in the 'SMS_Relentless/ removed_sent_messages' and 'SMS_Relentless/ removed_received_messages' directories. Being structured as 'csv',
              the data can then be viewed and analyzed with other applications to create statistics, graphs etc. Therefore, as long as the 'csv' files are preserved,
              the deleted messages are not lost. (Please note that this 'save before delete' mechanism is not used when messages are deleted by selecting their respective table 
              rows and clicking on the 'Permanently delete' upper-left corner icon).
          </span>
       </div>
       <div id="delsetrows">
          <span class="deletesmsolder">Delete from the database all the <font style="color: #ba3555;">received</font> messages that are older than <input type="text" id="oldrecSmsInterval" title="Enter the number of days." /> days.</span>
          <input type="submit" id="delOldrecSMS" value="Delete received messages" />
          <span id="sms_deleterecmsg"></span><br><br>

          <span class="deletesmsolder">Delete from the database all the <font style="color: #ba3555;">sent</font> messages that are older than </span><input type="text" id="oldsentSmsInterval" title="Enter the number of days."/>
          <span class="deletesmsolder"> days.</span>
          <input type="submit" id="delOldsentSMS" value="Delete sent messages" />
          <span id="sms_deletesentmsg"></span>
       </div>
   </div>

</div>
