<?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('pax_fax', 'settings');
style('pax_fax', 'style');

?>

<div id="pax_fax_adm">
	<div class="section">
           <h2><?php p($l->t('Pax Fax'));?></h2>
	   <p id="settings-dscr"><?php p($l->t('Enter your credentials and options in the fields from below:')); ?></p><br>

           <div class="stp_followupsection">

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

                   <p><label for="api_key" class="setlabeltext"><b><?php p($l->t('Phaxio API Key:'));?></b> (Log in to your Phaxio account, click 'API Keys' on the left
                          panel, then, under 'Live Keys' you will find the 'API Key'. Enter the 'API Key' in the field from below):</label></p>
                   <input type="password" class="pax_fax_box" id="api_key" name="api_key" autocomplete="false"
                          placeholder="<?php p($l->t('E.g.: d6f172ce92e4f2 ...')); ?>" /><br>

                   <p><label for="api_secret" class="setlabeltext"><b><?php p($l->t('Phaxio API Secret:'));?></b> (While logged in to your Phaxio account, click 'API Keys' on the left
                          panel, then, under 'Live Keys' you will find the 'API Secret'. Enter the 'API Secret' in the field from below):</label></p>
                   <input type="password" class="pax_fax_box" id="api_secret" name="api_secret" autocomplete="false"
                          placeholder="<?php p($l->t('E.g.: 8af589b8ad9579 ...')); ?>" /><br>

                   <p><label for="webhook_token" class="setlabeltext"><b><?php p($l->t('Phaxio Webhook Token:'));?></b> (While logged in to your Phaxio account, click 'Webhooks' on the
                          left panel, then copy the token found under 'Webhook Token' and enter it in the field from below):</label></p>
                   <input type="password" class="pax_fax_box" id="webhook_token" name="webhook_token" autocomplete="false"
                          placeholder="<?php p($l->t('E.g.: b6d90b72ab6cce450025abd46f4d697')); ?>" /><br>

                   <p><label for="receive_url" class="setlabeltext"><b>Phaxio callback URL for incoming faxes</b> (This URL must have the form:
                          <b>https://<font style="color:#a11a1a;">username</font>:<font
                          style="color:#a11a1a;">6VTGs-c36j4-qK2wm-RgJcl-9pjUD</font>@<font style="color:#a11a1a;">cloud.example.com</font>/apps/pax_fax/api/recfaxphaxio</b> if 
                          Nextcloud is served on a subdomain, or <b>https://<font style="color:#a11a1a;">username</font>:<font
                          style="color:#a11a1a;">6VTGs-c36j4-qK2wm-RgJcl-9pjUD</font>@<font style="color:#a11a1a;">example.com/nextcloud</font>/apps/pax_fax/api/recfaxphaxio</b> 
                          if Nextcloud is served on a subdirectory, where <b><font style="color:#a11a1a;">username</font></b> is the Nextcloud user who has a Phaxio phone number 
                          in her/his Phaxio account (Callback URLs can only be configured one per Phaxio phone number. If <b><font style="color:#a11a1a;">username</font></b> 
                          contains an <b>@</b> , replace <b>@</b> with <b>&amp;commat;</b> otherwise the URL won't function), 
                          <b><font style="color:#a11a1a;">6VTGs-c36j4-qK2wm-RgJcl-9pjUD</font></b> is the 'application password' created for this purpose as explained below, and 
                          <b><font style="color:#a11a1a;">cloud.example.com</font></b> is your Nextcloud domain. To create the Nextcloud 'application password' click on the user 
                          picture in the upper right corner, then click 'Personal settings', then, on the left panel, under 'Personal' click 'Security', then under 'Devices & sessions', 
                          in the 'App name' field enter Pax_Fax, then click the 'Create new app password' button. The password will be displayed only when created. Copy the password, 
                          click the 'Done' button, enter the password in the constructed callback URL between ':' and '@' as shown above, copy the entire callback URL to a safe 
                          location, then enter the callback URL in the field from below. The next step is to enter the callback URL that you have just created in your Phaxio account: 
                          log in to Phaxio, click 'Phone Numbers' on the left panel, click the settings wheel on the row of the phone number for which you want to set up the callback 
                          URL, enter the URL in the 'Callback URL' field, then click 'Save'. Also, click on 'Webhooks' on the left panel, then scroll down to 'Webhook Version' and 
                          choose 'Version 2.1.0', then click the 'Update' 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="password" class="pax_fax_boxspec" id="receive_url" name="receive_url" autocomplete="false"
                          placeholder="<?php p($l->t('E.g.:  https://username:6VTGs-c36j4-qK2wm-RgJcl-9pjUD@cloud.example.com/apps/pax_fax/api/recfaxphaxio')); ?>" /><br><br><br>

                   <p><label for="get_notification" class="setlabeltext"><b><?php p($l->t('I want to see a notification in Nextcloud when a new fax is received:'));?></b></label></p>
                   <input type="checkbox" class="pax_fax_checkbox" id="get_notification" name="get_notification" autocomplete="false" /><br>

                       <p>To enable email notifications for every received fax, 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 web 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 distribution).
                       </p><br>

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

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

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

                   <span id="paxfax_save_msg"></span>

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