<?php
/* Copyright (C) 2004-2017 Laurent Destailleur  <eldy@users.sourceforge.net>
 * Copyright (C) 2020      MB Informatique      <info@mb-informatique.fr>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) 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 General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */

/**
 * \file    mbisignature/admin/setup.php
 * \ingroup mbisignature
 * \brief   MBISignature setup page.
 */

// Load Dolibarr environment
$res = 0;
// Try main.inc.php into web root known defined into CONTEXT_DOCUMENT_ROOT (not always defined)
if (!$res && !empty($_SERVER["CONTEXT_DOCUMENT_ROOT"])) $res = @include $_SERVER["CONTEXT_DOCUMENT_ROOT"]."/main.inc.php";
// Try main.inc.php into web root detected using web root calculated from SCRIPT_FILENAME
$tmp = empty($_SERVER['SCRIPT_FILENAME']) ? '' : $_SERVER['SCRIPT_FILENAME']; $tmp2 = realpath(__FILE__); $i = strlen($tmp) - 1; $j = strlen($tmp2) - 1;
while ($i > 0 && $j > 0 && isset($tmp[$i]) && isset($tmp2[$j]) && $tmp[$i] == $tmp2[$j]) { $i--; $j--; }
if (!$res && $i > 0 && file_exists(substr($tmp, 0, ($i + 1))."/main.inc.php")) $res = @include substr($tmp, 0, ($i + 1))."/main.inc.php";
if (!$res && $i > 0 && file_exists(dirname(substr($tmp, 0, ($i + 1)))."/main.inc.php")) $res = @include dirname(substr($tmp, 0, ($i + 1)))."/main.inc.php";
// Try main.inc.php using relative path
if (!$res && file_exists("../../main.inc.php")) $res = @include "../../main.inc.php";
if (!$res && file_exists("../../../main.inc.php")) $res = @include "../../../main.inc.php";
if (!$res) die("Include of main fails");

global $langs, $user, $conf, $db;

// Libraries
require_once DOL_DOCUMENT_ROOT."/core/lib/admin.lib.php";
require_once '../lib/mbisignature.lib.php';
require_once '../scripts/style.css.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
dol_include_once("/mbisignature/core/modules/modMBISignature.class.php");

$langs->loadLangs(array("admin", "mbisignature@mbisignature", "install"));

// Access control
if (!$user->admin) accessforbidden();

// Parameters
$action = GETPOST('action', 'alpha');
$backtopage = GETPOST('backtopage', 'alpha');

$arrayofparameters = array(
	'SIGNATURE_CONFIRMATION_MAIL'=>array('css'=>'minwidth500', 'enabled'=>1),
    'DOUBLE_SIGNATURE'=>array('css'=>'minwidth500', 'enabled'=>1),
    'SIGNATURE_DISPLAY_NAME'=>array('css'=>'minwidth500', 'enabled'=>1),
    'SIGNATURE_SOCIAL_LINKS'=>array('css'=>'minwidth500', 'enabled'=>1),
    'SIGNATURE_DOCUMENT_PREVIEW'=>array('css'=>'minwidth500', 'enabled'=>1),
    'SIGNATURE_URL'=>array('css'=>'minwidth500', 'enabled'=>1),
    'SIGNATURE_DOC_PATH'=>array('css'=>'minwidth500', 'enabled'=>1),
    'SIGNATURE_ENABLE_PROPAL'=>array('css'=>'minwidth500', 'enabled'=>1),
    'SIGNATURE_ENABLE_ORDER'=>array('css'=>'minwidth500', 'enabled'=>1),
    'SIGNATURE_ENABLE_ORDER_SUPPLIER'=>array('css'=>'minwidth500', 'enabled'=>1),
    'SIGNATURE_ENABLE_EXPEDITION'=>array('css'=>'minwidth500', 'enabled'=>1),
    'SIGNATURE_ENABLE_DELIVERY'=>array('css'=>'minwidth500', 'enabled'=>1),
    'SIGNATURE_ENABLE_INTERVENTION'=>array('css'=>'minwidth500', 'enabled'=>1),
    'SIGNATURE_ENABLE_CONTRACT'=>array('css'=>'minwidth500', 'enabled'=>1),
    'SIGNATURE_ENABLE_SEPA_MANDATE'=>array('css'=>'minwidth500', 'enabled'=>1),
    'SIGNATURE_ENABLE_HOLIDAY'=>array('css'=>'minwidth500', 'enabled'=>1),
    'SIGNATURE_ENABLE_EXPENSE_REPORT'=>array('css'=>'minwidth500', 'enabled'=>1),
    'SIGNATURE_USE_CERTIFICATE'=>array('css'=>'minwidth500', 'enabled'=>1),
    'SIGNATURE_CRT'=>array('css'=>'minwidth500', 'enabled'=>1),
    'SIGNATURE_CRT_PRIVATE_KEY'=>array('css'=>'minwidth500', 'enabled'=>1),
    'SIGNATURE_SEND_HOLIDAY_TO'=>array('css'=>'minwidth500', 'enabled'=>1),
    'SIGNATURE_SEND_EXPENSE_REPORT_TO'=>array('css'=>'minwidth500', 'enabled'=>1),
    'SIGNATURE_DISPLAY_LINE_AND_RIBBON'=>array('css'=>'minwidth500', 'enabled'=>1),
    'SIGNATURE_PROPAL_CAN_BE_REFUSED'=>array('css'=>'minwidth500', 'enabled'=>1),
    'SIGNATURE_COMPANY_STAMP'=>array('css'=>'minwidth500', 'enabled'=>1),
    'SIGNATURE_DISPLAY_COMMENT_SECTION'=>array('css'=>'minwidth500', 'enabled'=>1),
    'SIGNATURE_USE_ANOTHER_LOGO'=>array('css'=>'minwidth500', 'enabled'=>1)
);

/*
 * Actions
 */

if ((float) DOL_VERSION >= 6) { include DOL_DOCUMENT_ROOT.'/core/actions_setmoduleoptions.inc.php'; }

/*
 * View
 */

llxHeader('', $langs->trans("MBISignatureSetup"));

// Subheader
$linkback = '<a href="'.($backtopage ? $backtopage : DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1').'">'.$langs->trans("BackToModuleList").'</a>';

print load_fiche_titre($langs->trans("MBISignatureSetup"), $linkback, 'object_logo@mbisignature');

$mbisignature = new modMBISignature($db);
$context = stream_context_create(array('http' => array('header'=>'Connection: close\r\n')));
$last_version = @file_get_contents($mbisignature->url_last_version, false, $context);

// Configuration header
$head = mbisignatureAdminPrepareHead();
dol_fiche_head($head, 'settings', '', -1, "mbisignature@mbisignature");

// Setup page goes here
echo '<span class="opacitymedium">'.$langs->trans("MBISignatureSetupPage").'</span><br><br>';

$conf->global->SIGNATURE_ENABLE_PROPAL == "true" ? $db->query("UPDATE " . MAIN_DB_PREFIX . "extrafields SET list = 1 WHERE name = 'signature_link' AND elementtype = 'propal'") : $db->query("UPDATE " . MAIN_DB_PREFIX . "extrafields SET list = 0 WHERE name = 'signature_link' AND elementtype = 'propal'");
$conf->global->SIGNATURE_ENABLE_ORDER == "true" ? $db->query("UPDATE " . MAIN_DB_PREFIX . "extrafields SET list = 1 WHERE name = 'signature_link' AND elementtype = 'commande'") : $db->query("UPDATE " . MAIN_DB_PREFIX . "extrafields SET list = 0 WHERE name = 'signature_link' AND elementtype = 'commande'");
$conf->global->SIGNATURE_ENABLE_ORDER_SUPPLIER == "true" ? $db->query("UPDATE " . MAIN_DB_PREFIX . "extrafields SET list = 1 WHERE name = 'signature_link' AND elementtype = 'commande_fournisseur'") : $db->query("UPDATE " . MAIN_DB_PREFIX . "extrafields SET list = 0 WHERE name = 'signature_link' AND elementtype = 'commande_fournisseur'");
$conf->global->SIGNATURE_ENABLE_EXPEDITION == "true" ? $db->query("UPDATE " . MAIN_DB_PREFIX . "extrafields SET list = 1 WHERE name = 'signature_link' AND elementtype = 'expedition'") : $db->query("UPDATE " . MAIN_DB_PREFIX . "extrafields SET list = 0 WHERE name = 'signature_link' AND elementtype = 'expedition'");
$conf->global->SIGNATURE_ENABLE_INTERVENTION == "true" ? $db->query("UPDATE " . MAIN_DB_PREFIX . "extrafields SET list = 1 WHERE name = 'signature_link' AND elementtype = 'fichinter'") : $db->query("UPDATE " . MAIN_DB_PREFIX . "extrafields SET list = 0 WHERE name = 'signature_link' AND elementtype = 'fichinter'");
$conf->global->SIGNATURE_ENABLE_CONTRACT == "true" ? $db->query("UPDATE " . MAIN_DB_PREFIX . "extrafields SET list = 1 WHERE name = 'signature_link' AND elementtype = 'contrat'") : $db->query("UPDATE " . MAIN_DB_PREFIX . "extrafields SET list = 0 WHERE name = 'signature_link' AND elementtype = 'contrat'");
$conf->global->SIGNATURE_ENABLE_SEPA_MANDATE == "true" ? $db->query("UPDATE " . MAIN_DB_PREFIX . "extrafields SET list = 1 WHERE name = 'signature_link' AND elementtype = 'societe'") : $db->query("UPDATE " . MAIN_DB_PREFIX . "extrafields SET list = 0 WHERE name = 'signature_link' AND elementtype = 'societe'");
$conf->global->SIGNATURE_ENABLE_HOLIDAY == "true" ? $db->query("UPDATE " . MAIN_DB_PREFIX . "extrafields SET list = 1 WHERE name = 'signature_link' AND elementtype = 'holiday'") : $db->query("UPDATE " . MAIN_DB_PREFIX . "extrafields SET list = 0 WHERE name = 'signature_link' AND elementtype = 'holiday'");
$conf->global->SIGNATURE_ENABLE_DELIVERY == "true" ? $db->query("UPDATE " . MAIN_DB_PREFIX . "extrafields SET list = 1 WHERE name = 'signature_link' AND elementtype = 'delivery'") : $db->query("UPDATE " . MAIN_DB_PREFIX . "extrafields SET list = 0 WHERE name = 'signature_link' AND elementtype = 'delivery'");

if ($action === "saveOrderRef") {
    dolibarr_set_const($db, "MBI_SIGNATURE_ORDER_REF", $_POST['order_ref'], 'string', 0, '', 0);
    dolibarr_set_const($db, "MBI_SIGNATURE_LICENCE", $_POST['licence'], 'string', 0, '', 0);
}

$opts = array('http' =>
    array(
        'method'  => 'POST',
        'timeout' => 4,
        'header'  => 'Content-Type: application/x-www-form-urlencoded',
        'content' => http_build_query(
            array(
                'token' => newToken(),
                'action' => '9e0e4fdcff7fe834aabc3850f82b80b6675f88019bb5ccdfb75e3fa0ed19ca7fa45bfc307ebcb64be274055da0993602d4130471dd0e60f3cd66a94e198a9904',
                'order_ref' => $conf->global->MBI_SIGNATURE_ORDER_REF,
                'licence' => $conf->global->MBI_SIGNATURE_LICENCE,
                'instance_id' => substr($conf->file->instance_unique_id, 0, 20),
                'product' => $langs->trans('ModuleMBISignatureName')
            )
        )
    )
);

$result = @file_get_contents($mbisignature->url_activation, false, stream_context_create($opts));
if ($result === false) {
    echo $langs->trans("MBI_ACTIVATION_SERVER_NOT_AVAILABLE");
} else if ($result === "0") {
    echo "<script>function saveOrderRef(orderRef, licence) { $.post('" . $_SERVER["PHP_SELF"] . "', { token: '" . newToken() . "', action: 'saveOrderRef', order_ref: orderRef, licence: licence }).done(function(data) { setTimeout(function(){ location.reload(); }, 2000); }); }</script>";
    echo "<script>function validate() { var orderRef = document.getElementById('order_ref').value; $.post('" . $mbisignature->url_activation . "', { token: '" . newToken() . "', action: '6d4b50c21ce48ac4c9663beda738e30051c7309060ab6eb4718ae25473dd475cfbaef45f8602c8ce92085b72cdcb086ec432d5c4581ce99673aed4501f7f82c1', order_ref: orderRef, instance_id: '" . substr($conf->file->instance_unique_id, 0, 20) . "', product: '" . $langs->trans('ModuleMBISignatureName') . "' }).done(function(data) { if (data !== '0' && data !== '-1' && data !== '-2') { saveOrderRef(orderRef, data); $.jnotify('" . $langs->trans("MBI_ACTIVATION_SUCCESS") . "', {delay: 4000, fadeSpeed: 500}); } else if (data === '-1') { $.jnotify(\"" . $langs->trans("MBI_ACTIVATION_NOT_PURCHASED") . "\", {delay: 6000, fadeSpeed: 500}); } else if (data === '-2') { $.jnotify(\"" . $langs->trans("MBI_ACTIVATION_ALREADY_EXIST") . "\", {delay: 6000, fadeSpeed: 500}); } else { $.jnotify('SQL ERR : " . $langs->trans("MBI_ACTIVATION_SQL_ERROR") . "', {delay: 6000, fadeSpeed: 500}); } }); }</script>";
    echo "<div id='activate'>";
    echo "<p>" . $langs->trans("MBI_ACTIVATION_WELCOME") . "</p>";
    echo "<input type='text' name='order_ref' value='' id='order_ref'>";
    echo "<input class='button' type='submit' value='" . $langs->trans("Confirm") . "' onclick='validate();'>";
    echo "</div>";
    dolibarr_set_const($db, "SIGNATURE_ENABLE_PROPAL", "false");
    dolibarr_set_const($db, "SIGNATURE_ENABLE_ORDER", "false");
    dolibarr_set_const($db, "SIGNATURE_ENABLE_ORDER_SUPPLIER", "false");
    dolibarr_set_const($db, "SIGNATURE_ENABLE_EXPEDITION", "false");
    dolibarr_set_const($db, "SIGNATURE_ENABLE_INTERVENTION", "false");
    dolibarr_set_const($db, "SIGNATURE_ENABLE_CONTRACT", "false");
    dolibarr_set_const($db, "SIGNATURE_ENABLE_SEPA_MANDATE", "false");
    dolibarr_set_const($db, "SIGNATURE_ENABLE_HOLIDAY", "false");
    dolibarr_set_const($db, "SIGNATURE_ENABLE_DELIVERY", "false");
} else {
    $result = json_decode($result, true);

    if ($result) {

        $name = $result['name'] !== "" ? " (" . $result['name'] . ")" : "";

        echo "<div style='padding: 20px; background-color: #f0f0f0; border-radius: 5px; text-align: center; font-size: 16px;'>" . $langs->trans("MBI_VALIDATED_MODULE") . "<i class='fas fa-check-square' style='margin: 0 8px; color: green;'></i>" . $langs->trans("License") . " : <b style='font-family: Times; font-size: 18px;'>" . $conf->global->MBI_SIGNATURE_LICENCE . $name . "</b><br><br>";

        if ($result['purchase_date'] !== "") {
            $purchaseDate = strtotime($result['purchase_date']);
            $purchaseDateDisplay = date(str_replace("%", "", $langs->trans('FormatDateShort')), $purchaseDate);
            echo "<span>" . $langs->trans("OrderDate") . " : " . $purchaseDateDisplay . "</span>";
            $now = time();
            $one_year = strtotime('+1 year', strtotime($result['purchase_date']));
            $datediff = $one_year - $now;
            $datediff = round($datediff / (60 * 60 * 24));
            if ($datediff <= 0) {
                echo "<span><i class='fas fa-clock' style='margin: 0 8px; color: red;'></i><mark>" . $langs->trans("MBI_ACTIVATION_CANT_UPDATE") . "</mark></span>";
                $support = false;
            } else {
                echo "<span><i class='fas fa-clock' style='margin: 0 8px; color: green;'></i>" . $langs->trans("MBI_ACTIVATION_UPDATE_DAYS_LEFT", $datediff) . "</span>";
                $support = true;
            }
            echo '<br><br>';
        }

        if (version_compare($mbisignature->version, $last_version, '<')) {
            echo "<div style='color: red;'>";
            echo "<i class='fas fa-download'></i> " . $langs->trans('ModuleUpdateAvailable') . " : " . $mbisignature->version . " <i class='fas fa-long-arrow-alt-right'></i> " . $last_version . "<br><a href='https://www.dolistore.com/fr/modules/1270-MBI-Signature.html' target='_blank'>" . $langs->trans('AchatTelechargement') . "</a><br><hr>";
            echo "</div>";
        } else if (version_compare($mbisignature->version, $last_version, '=')) {
            echo "<div>" . $langs->trans('MBI_UPTODATE') . " <i class='fas fa-check-circle' style='color: green;'></i><br><hr></div>";
        }

        if ($support) {
            echo "<i class='fas fa-question-circle' style='margin: 0 8px; color: cornflowerblue;'></i>" . str_replace("Dolibarr", "MB Informatique", $langs->trans("DolibarrHelpCenter")) . " : <b>03 67 262 242 / web@mb-informatique.fr</b></div><br>";
        } else {
            echo "<i class='fas fa-question-circle' style='margin: 0 8px; color: cornflowerblue;'></i><span style='text-decoration: line-through;'>" . str_replace("Dolibarr", "MB Informatique", $langs->trans("DolibarrHelpCenter")) . "</span></div><br>";
        }
        print '<form method="POST" action="' . $_SERVER["PHP_SELF"] . '">';
        print '<input type="hidden" name="token" value="' . newToken() . '">';
        print '<input type="hidden" name="action" value="update">';

        print '<table class="noborder centpercent">';
        print '<tr class="liste_titre"><td class="titlefield">' . $langs->trans("Parameter") . '</td><td>' . $langs->trans("Value") . '</td></tr>';

        foreach ($arrayofparameters as $key => $val) {
            print '<tr class="oddeven"><td>';
            $tooltiphelp = (($langs->trans($key . 'Tooltip') != $key . 'Tooltip') ? $langs->trans($key . 'Tooltip') : '');
            if ($key == "SIGNATURE_URL") {
                print $form->textwithpicto($langs->trans("URLRoot"), $tooltiphelp);
            } else if ($key == "SIGNATURE_DOC_PATH") {
                print $form->textwithpicto($langs->trans("DataRootServer"), $tooltiphelp);
            } else if ($key == "SIGNATURE_USE_ANOTHER_LOGO") {
                print $form->textwithpicto($langs->trans($key) . " (" . $langs->trans("URLPhoto") . ")", $tooltiphelp);
            } else {
                print $form->textwithpicto($langs->trans($key), $tooltiphelp);
            }
            $optionThatIsSet = "<option value='" . $conf->global->$key . "' selected>" . $conf->global->$key . "</option>";
            if ($conf->global->$key == $langs->trans('OPTION1')) {
                $option2 = "<option value='" . $langs->trans('OPTION2') . "'>" . $langs->trans('OPTION2') . "</option>";
                $option3 = "<option value='" . $langs->trans('OPTION3') . "'>" . $langs->trans('OPTION3') . "</option>";
            } else if ($conf->global->$key == $langs->trans('OPTION2')) {
                $option2 = "<option value='" . $langs->trans('OPTION1') . "'>" . $langs->trans('OPTION1') . "</option>";
                $option3 = "<option value='" . $langs->trans('OPTION3') . "'>" . $langs->trans('OPTION3') . "</option>";
            } else if ($conf->global->$key == $langs->trans('OPTION3')) {
                $option2 = "<option value='" . $langs->trans('OPTION1') . "'>" . $langs->trans('OPTION1') . "</option>";
                $option3 = "<option value='" . $langs->trans('OPTION2') . "'>" . $langs->trans('OPTION2') . "</option>";
            }
            if ($key == "SIGNATURE_CONFIRMATION_MAIL") {
                print '</td><td><select name="' . $key . '"  class="flat ' . (empty($val['css']) ? 'minwidth200' : $val['css']) . '">' . $optionThatIsSet . $option2 . $option3 . '</select></td></tr>';
            } else if ($key == "DOUBLE_SIGNATURE" || $key == "SIGNATURE_ENABLE_PROPAL" || $key == "SIGNATURE_ENABLE_ORDER" || $key == "SIGNATURE_ENABLE_ORDER_SUPPLIER" || $key == "SIGNATURE_ENABLE_EXPEDITION" || $key == "SIGNATURE_ENABLE_DELIVERY" || $key == "SIGNATURE_ENABLE_INTERVENTION" || $key == "SIGNATURE_ENABLE_CONTRACT" || $key == "SIGNATURE_ENABLE_SEPA_MANDATE" || $key == "SIGNATURE_ENABLE_HOLIDAY" || $key == "SIGNATURE_ENABLE_EXPENSE_REPORT" || $key == "SIGNATURE_DISPLAY_NAME" || $key == "SIGNATURE_SOCIAL_LINKS" || $key == "SIGNATURE_DOCUMENT_PREVIEW" || $key == "SIGNATURE_USE_CERTIFICATE" || $key == "SIGNATURE_DISPLAY_LINE_AND_RIBBON" || $key == "SIGNATURE_PROPAL_CAN_BE_REFUSED" || $key == "SIGNATURE_DISPLAY_COMMENT_SECTION") {
                if ($conf->global->$key == "true") {
                    print '</td><td><select name="' . $key . '"  class="flat ' . (empty($val['css']) ? 'minwidth200' : $val['css']) . '"><option value="true" selected>' . $langs->trans("Yes") . '</option><option value="false">' . $langs->trans("No") . '</option></select></td></tr>';
                } else if ($conf->global->$key == "false") {
                    print '</td><td><select name="' . $key . '"  class="flat ' . (empty($val['css']) ? 'minwidth200' : $val['css']) . '"><option value="false" selected>' . $langs->trans("No") . '</option><option value="true">' . $langs->trans("Yes") . '</option></select></td></tr>';
                }
                // print '</td><td>' . ajax_constantonoff($conf->global->$key) . '</td></tr>'; // Add on/off buttons but doesn't work with true/false, need 1/0
            } else if ($key == "SIGNATURE_URL" || $key == "SIGNATURE_DOC_PATH") {
                print '</td><td><input type="text" name="' . $key . '" value="' . $conf->global->$key . '" class="flat ' . (empty($val['css']) ? 'minwidth200' : $val['css']) . '"></td></tr>';
            } else if ($key == "SIGNATURE_SEND_HOLIDAY_TO" || $key == "SIGNATURE_SEND_EXPENSE_REPORT_TO") {
                print '</td><td><input type="email" name="' . $key . '" value="' . $conf->global->$key . '" class="flat ' . (empty($val['css']) ? 'minwidth200' : $val['css']) . '"></td></tr>';
            } else if ($key == "SIGNATURE_CRT" || $key == "SIGNATURE_CRT_PRIVATE_KEY") {
                if ($key == "SIGNATURE_CRT" && $conf->global->SIGNATURE_USE_CERTIFICATE == "true" && file_exists($conf->global->SIGNATURE_CRT)) {
                    $okko = "<i class='fas fa-check-circle' style='color: green; position: relative; left: 4px;'></i>";
                } else if ($key == "SIGNATURE_CRT_PRIVATE_KEY" && $conf->global->SIGNATURE_USE_CERTIFICATE == "true" && file_exists($conf->global->SIGNATURE_CRT_PRIVATE_KEY)) {
                    $okko = "<i class='fas fa-check-circle' style='color: green; position: relative; left: 4px;'></i>";
                } else if ($conf->global->SIGNATURE_USE_CERTIFICATE !== "true") {
                    $okko = "";
                } else {
                    $okko = "<i class='fas fa-times' style='color: red; position: relative; left: 4px;'></i>";
                }
                print '</td><td><input type="text" name="' . $key . '" value="' . $conf->global->$key . '" class="flat ' . (empty($val['css']) ? 'minwidth200' : $val['css']) . '">' . $okko . '</td></tr>';
            } else if ($key == "SIGNATURE_COMPANY_STAMP") {
                if (file_exists($conf->global->SIGNATURE_COMPANY_STAMP)) {
                    $okko = "<i class='fas fa-check-circle' style='color: green; position: relative; left: 4px;'></i>";
                } else {
                    $okko = "";
                }
                print '</td><td><input type="text" name="' . $key . '" value="' . $conf->global->$key . '" class="flat ' . (empty($val['css']) ? 'minwidth200' : $val['css']) . '">' . $okko . '</td></tr>';
            } else if ($key == "SIGNATURE_USE_ANOTHER_LOGO") {
                print '</td><td><input type="text" name="' . $key . '" value="' . $conf->global->$key . '" class="flat ' . (empty($val['css']) ? 'minwidth200' : $val['css']) . '"></td></tr>';
            }
        }
        print '</table>';
        print '<div class="center"><input class="button" type="submit" value="' . $langs->trans("Save") . '"></div>';

        print '</form>';
    }
}

// Page end
dol_fiche_end();

llxFooter();
$db->close();
