|
| 1 | +<?php |
| 2 | +/* Copyright (C) 2021-2023 EVARISK <technique@evarisk.com> |
| 3 | + * |
| 4 | + * This program is free software: you can redistribute it and/or modify |
| 5 | + * it under the terms of the GNU General Public License as published by |
| 6 | + * the Free Software Foundation, either version 3 of the License, or |
| 7 | + * (at your option) any later version. |
| 8 | + * |
| 9 | + * This program is distributed in the hope that it will be useful, |
| 10 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | + * GNU General Public License for more details. |
| 13 | + * |
| 14 | + * You should have received a copy of the GNU General Public License |
| 15 | + * along with this program. If not, see <https://www.gnu.org/licenses/>. |
| 16 | + */ |
| 17 | + |
| 18 | +/** |
| 19 | + * \file admin/config/digiai.php |
| 20 | + * \ingroup digiriskdolibarr |
| 21 | + * \brief Digiriskdolibarr digiai page. |
| 22 | + */ |
| 23 | + |
| 24 | +// Load DigiriskDolibarr environment |
| 25 | +if (file_exists('../digiriskdolibarr.main.inc.php')) { |
| 26 | + require_once __DIR__ . '/../digiriskdolibarr.main.inc.php'; |
| 27 | +} elseif (file_exists('../../digiriskdolibarr.main.inc.php')) { |
| 28 | + require_once __DIR__ . '/../../digiriskdolibarr.main.inc.php'; |
| 29 | +} else { |
| 30 | + die('Include of digiriskdolibarr main fails'); |
| 31 | +} |
| 32 | + |
| 33 | +global $conf, $db, $langs, $user; |
| 34 | + |
| 35 | +// Libraries |
| 36 | +require_once DOL_DOCUMENT_ROOT . "/core/class/html.formprojet.class.php"; |
| 37 | +require_once DOL_DOCUMENT_ROOT . "/core/lib/admin.lib.php"; |
| 38 | + |
| 39 | +require_once __DIR__ . '/../../lib/digiriskdolibarr.lib.php'; |
| 40 | + |
| 41 | +// Translations |
| 42 | +saturne_load_langs(["admin"]); |
| 43 | + |
| 44 | +// Parameters |
| 45 | +$action = GETPOST('action', 'alpha'); |
| 46 | +$backtopage = GETPOST('backtopage', 'alpha'); |
| 47 | +$openAiApiKey = GETPOST('OpenAIApiKey', 'alpha'); |
| 48 | + |
| 49 | +// Security check - Protection if external user |
| 50 | +$permissiontoread = $user->rights->digiriskdolibarr->adminpage->read; |
| 51 | +saturne_check_access($permissiontoread); |
| 52 | + |
| 53 | +/* |
| 54 | + * Actions |
| 55 | + */ |
| 56 | + |
| 57 | +$error = 0; |
| 58 | + |
| 59 | +if ($action == 'update') { |
| 60 | + if (!empty($openAiApiKey) || $openAiApiKey === '0') { |
| 61 | + dolibarr_set_const($db, "DIGIRISKDOLIBARR_CHATGPT_API_KEY", $openAiApiKey, 'integer', 0, '', $conf->entity); |
| 62 | + } |
| 63 | +} |
| 64 | +// Actions set_mod, update_mask |
| 65 | +require_once __DIR__ . '/../../../saturne/core/tpl/actions/admin_conf_actions.tpl.php'; |
| 66 | + |
| 67 | +/* |
| 68 | + * View |
| 69 | + */ |
| 70 | + |
| 71 | +if (isModEnabled('project')) { |
| 72 | + $formproject = new FormProjets($db); |
| 73 | +} |
| 74 | + |
| 75 | +$form = new Form($db); |
| 76 | + |
| 77 | +$title = $langs->trans("ModuleSetup", $moduleName); |
| 78 | +$helpUrl = 'FR:Module_Digirisk'; |
| 79 | + |
| 80 | +saturne_header(0,'', $title, $helpUrl); |
| 81 | + |
| 82 | +// Subheader |
| 83 | +$linkback = '<a href="' . ($backtopage ?: DOL_URL_ROOT . '/admin/modules.php?restore_lastsearch_values=1') . '">' . $langs->trans("BackToModuleList") . '</a>'; |
| 84 | +print load_fiche_titre($title, $linkback, 'title_setup'); |
| 85 | + |
| 86 | +// Configuration header |
| 87 | +$head = digiriskdolibarr_admin_prepare_head(); |
| 88 | +print dol_get_fiche_head($head, 'digiai', $title, -1, "digiriskdolibarr_color@digiriskdolibarr"); |
| 89 | + |
| 90 | +print '<form method="POST" action="' . $_SERVER["PHP_SELF"] . '">'; |
| 91 | +print '<input type="hidden" name="token" value="' . newToken() . '">'; |
| 92 | +print '<input type="hidden" name="action" value="update">'; |
| 93 | +print '<table class="noborder centpercent editmode">'; |
| 94 | +print '<tr class="liste_titre">'; |
| 95 | +print '<td>' . $langs->trans("Name") . '</td>'; |
| 96 | +print '<td>' . $langs->trans("Description") . '</td>'; |
| 97 | +print '<td>' . $langs->trans("Value") . '</td>'; |
| 98 | +print '<td>' . $langs->trans("Action") . '</td>'; |
| 99 | +print '</tr>'; |
| 100 | + |
| 101 | +print '<tr class="oddeven"><td><label for="OpenAIApiKey">' . $langs->trans("OpenAIApiKey") . '</label></td>'; |
| 102 | +print '<td>' . $langs->trans("OpenAIApiKeyDescription") . '</td>'; |
| 103 | +print '<td><input type="text" name="OpenAIApiKey" value="' . $conf->global->DIGIRISKDOLIBARR_CHATGPT_API_KEY . '"></td>'; |
| 104 | +print '<td><input type="submit" class="button" name="save" value="' . $langs->trans("Save") . '">'; |
| 105 | +print '</td></tr>'; |
| 106 | + |
| 107 | +print '</table>'; |
| 108 | +print '</form>'; |
| 109 | + |
| 110 | +// Page end |
| 111 | +print dol_get_fiche_end(); |
| 112 | +llxFooter(); |
| 113 | +$db->close(); |
0 commit comments