<?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>
                    <option value="Twilio" class='selectsmsprov'>Twilio</option>
                    <option value="Flowroute" class='selectsmsprov'>Flowroute</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 that of the respective account. You can see Telnyx prices <a href="https://telnyx.com/pricing/messaging" style="color:#1b60ba"
                      target="_blank" rel="noreferrer noopener">here</a>, Plivo prices <a href="https://www.plivo.com/sms/pricing/us/" style="color:#1b60ba" target="_blank"
                      rel="noreferrer noopener">here</a>, Twilio prices <a href="https://www.twilio.com/sms/pricing/ro" style="color:#1b60ba" target="_blank" 
                      rel="noreferrer noopener">here</a> and Flowroute prices <a href="https://flowroute.com/pricing-details/"  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>
                <div id="setcalleridtp">
                    <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 entered in Settings > SMS Relentless > 'Telnyx/Plivo/Twilio/Flowroute 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,
                        it's recommended to read about the <a href="https://support.twilio.com/hc/en-us/articles/223133767-International-support-for-Alphanumeric-Sender-ID" 
                        style="color:#1b60ba" target="_blank" rel="noreferrer noopener">Sender ID restrictions</a> specific to that country. 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 preregister 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>

       <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>
         <div id="tonmbrformat">
            <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, it's recommended to read about the 
               <a href="https://support.twilio.com/hc/en-us/articles/223133767-International-support-for-Alphanumeric-Sender-ID" style="color:#1b60ba" target="_blank" rel="noreferrer noopener">
               restrictions</a> that apply to that country. 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 that checkbox, you will be able to upload a file containing phone numbers, and set up a sending rate different 
               from the default 1 message per second. The info note will explain what are the sending rate restrictions that you will have to consider.
            </span>
         </div>
       </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>
          <div id="uploadfileinfo">
          <span class="fortooltiptextsec">To send an SMS to a large number of recipients, 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 (by listing one number per 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, the allowed SMS sending rate of US or 
              Canadian long code numbers (10 digit numbers) is 
              <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> . If you need a higher throughput per number, you can rent toll-free numbers (with sending rates of 20 messages per second per number)
              or short codes (with sending rates of 1000 messages per second per number). 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 per number</a>. If you need a higher throughput, you can rent toll-free numbers (with rates of 10 messages per second per 
              number) or short codes (with rates of 100 messages per second per number). For Twilio, a US or Canadian 10 digit number can send 
              <a href="https://support.twilio.com/hc/en-us/articles/115002943027-Understanding-Twilio-Rate-Limits-and-Message-Queues" style="color:#1b60ba" target="_blank"
              rel="noreferrer noopener">1 message per second</a>. If you need a higher throughput, you can send 3 messages per second per number with toll-free numbers, or 100 messages 
              per second per number with short codes. For Flowroute, using a US or Canadian 10 digit number or toll-free number, you can send 
              <a href="https://developer.flowroute.com/docs/flowroute-messaging-rate-limits/" style="color:#1b60ba" target="_blank" rel="noreferrer noopener">4 messages per second
              per account</a> (accross all phone numbers). 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 numbers. Also, in general, custom sending rates may be obtained by contacting Telnyx/Plivo/Twilio/Flowroute support. Starting from 2021, if you 
              want to send A2P (<a href="https://www.plivo.com/docs/sms/concepts/terminology" style="color:#1b60ba" target="_blank" rel="noreferrer noopener">Application-To-Person</a>) 
              SMS messages to phone numbers or from phone numbers belonging to certain carriers in the US, such as AT&T and T-Mobile, you will need to register your brand and your 
              campaign via
              <a href="https://support.telnyx.com/en/articles/3679260-frequently-asked-questions-about-10dlc" style="color:#1b60ba" target="_blank" rel="noreferrer noopener">Telnyx</a>/
              <a href="https://support.plivo.com/hc/en-us/articles/4682352262809-How-to-Register-10DLC-Brands-and-Campaigns" style="color:#1b60ba" target="_blank" rel="noreferrer noopener">Plivo</a>/
              <a href="https://support.twilio.com/hc/en-us/articles/1260801864489-How-do-I-register-to-use-A2P-10DLC-messaging-" style="color:#1b60ba" target="_blank" rel="noreferrer noopener">Twilio</a>/ 
              <a href="https://support.flowroute.com/265034-Messaging-Guidelines---10DLC-Carrier-Fees-and-Registration" style="color:#1b60ba" target="_blank" rel="noreferrer noopener">Flowroute</a>. 
              Registered campaigns also benefit from a much higher message throughput. 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 or 1 message per 4 seconds for Plivo, or 1 message per 1 second for Twilio, or 4 messages per second for Flowroute, Telnyx/Plivo/Twilio/Flowroute 
              respectively 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>
       <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>

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

   <div class="maxmessagelength"><font class="texttooltip">i</font>
       <div id="maxlengthinfo">
           <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/Twilio/Flowroute 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>

   <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>
          <div id="deleteoldinfo">
             <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>
       <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>
