* Copyright (C) 2022 Alice Adminson * * 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 . */ /** * \file cfdixml/admin/setup.php * \ingroup cfdixml * \brief Cfdixml setup page. */ // echo '
';print_r($_POST);echo '
';exit; // 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; // Libraries require_once DOL_DOCUMENT_ROOT."/core/lib/admin.lib.php"; require_once '../lib/cfdixml.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php'; //require_once "../class/myclass.class.php"; // Translations $langs->loadLangs(array("admin", "cfdixml@cfdixml")); // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context $hookmanager->initHooks(array('cfdixmlsetup', 'globalsetup')); // Access control if (!$user->admin) { accessforbidden(); } // Parameters $action = GETPOST('action', 'aZ09'); $backtopage = GETPOST('backtopage', 'alpha'); $modulepart = GETPOST('modulepart', 'aZ09'); // Used by actions_setmoduleoptions.inc.php $value = GETPOST('value', 'alpha'); $label = GETPOST('label', 'alpha'); $scandir = GETPOST('scan_dir', 'alpha'); $type = 'myobject'; $typeEndpoint = 0; $error = 0; $setupnotempty = 0; // Set this to 1 to use the factory to manage constants. Warning, the generated module will be compatible with version v15+ only $useFormSetup = 1; if (!class_exists('FormSetup')) { // For retrocompatibility Dolibarr < 16.0 if (floatval(DOL_VERSION) < 16.0 && !class_exists('FormSetup')) { require_once __DIR__.'/../backport/v16/core/class/html.formsetup.class.php'; } else { require_once DOL_DOCUMENT_ROOT.'/core/class/html.formsetup.class.php'; } } $formSetup = new FormSetup($db); $formcompany = new FormCompany($db); // Hôte $item = $formSetup->newItem('NO_PARAM_JUST_TEXT'); $item->fieldOverride = (empty($_SERVER['HTTPS']) ? 'http://' : 'https://') . $_SERVER['HTTP_HOST']; $item->cssClass = 'minwidth500'; // Verificar si los archivos de certificados existen $csd = $conf->global->CFDIXML_CER_FILE; $key = $conf->global->CFDIXML_KEY_FILE; $csd_exists = !empty($csd) && file_exists($csd); $key_exists = !empty($key) && file_exists($key); //print '
';
//print "CSD Path: " . $csd . "\n";
//print "CSD Exists: " . ($csd_exists ? 'Yes' : 'No') . "\n";
//print "file_exists() result: " . (file_exists($csd) ? 'True' : 'False') . "\n";
//print "KEY Path: " . $key . "\n";
//print "KEY Exists: " . ($key_exists ? 'Yes' : 'No') . "\n";
//print "file_exists() result: " . (file_exists($key) ? 'True' : 'False') . "\n";
//print '
'; /* * Actions */ // For retrocompatibility Dolibarr < 15.0 if ( versioncompare(explode('.', DOL_VERSION), array(15)) < 0 && $action == 'update' && !empty($user->admin)) { $formSetup->saveConfFromPost(); } include DOL_DOCUMENT_ROOT.'/core/actions_setmoduleoptions.inc.php'; if($action == 'save'){ //Upload files if (!empty($_FILES["csd"]["name"]) || !empty($_FILES["key"]["name"])) { $upload_dir = $conf->cfdixml->dir_output . '/' . get_exdir(0, 0, 0, 1, $object, 'cfdimx'); // Crear el directorio si no existe if (!file_exists($upload_dir)) { dol_mkdir($upload_dir); } $flag = 0; $error_message = ''; // Procesar archivo CSD if (!empty($_FILES["csd"]["name"])) { $cer_file = $upload_dir . '/' . dol_sanitizeFileName($_FILES["csd"]["name"]); // Verificar extensión del archivo $file_extension = strtolower(pathinfo($_FILES["csd"]["name"], PATHINFO_EXTENSION)); if ($file_extension != 'cer') { $error_message .= 'El archivo CSD debe tener extensión .cer. '; } else if (move_uploaded_file($_FILES["csd"]["tmp_name"], $cer_file)) { $flag++; dolibarr_set_const($db, "CFDIXML_CER_FILE", $cer_file, 'chaine', 1, '', $conf->entity); setEventMessages($langs->trans("CertificateUploaded"), null, 'mesgs'); } else { $error_message .= 'Error al subir el archivo CSD. '; } } // Procesar archivo KEY if (!empty($_FILES["key"]["name"])) { $key_file = $upload_dir . '/' . dol_sanitizeFileName($_FILES["key"]["name"]); // Verificar extensión del archivo $file_extension = strtolower(pathinfo($_FILES["key"]["name"], PATHINFO_EXTENSION)); if ($file_extension != 'key') { $error_message .= 'El archivo KEY debe tener extensión .key. '; } else if (move_uploaded_file($_FILES["key"]["tmp_name"], $key_file)) { $flag++; dolibarr_set_const($db, "CFDIXML_KEY_FILE", $key_file, 'chaine', 1, '', $conf->entity); setEventMessages($langs->trans("KeyUploaded"), null, 'mesgs'); } else { $error_message .= 'Error al subir el archivo KEY. '; } } // Mostrar errores si los hay if (!empty($error_message)) { setEventMessages($error_message, null, 'errors'); } } // Guardar el resto de configuraciones if (GETPOST('passkey')) dolibarr_set_const($db, "CFDIXML_CERKEY_PASS", GETPOST('passkey', 'alpha'), 'chaine', 1, '', $conf->entity); if (GETPOST('setep')) dolibarr_set_const($db, "CFDIXML_WS_MODE", GETPOST('setep'), 'chaine', 1, '', $conf->entity); if (GETPOST('epprod')) dolibarr_set_const($db, "CFDIXML_WS_PRODUCTION", GETPOST('epprod'), 'chaine', 1, '', $conf->entity); if (GETPOST('eptest')) dolibarr_set_const($db, "CFDIXML_WS_TEST", GETPOST('eptest'), 'chaine', 1, '', $conf->entity); if (GETPOST('passtoken')) dolibarr_set_const($db, "CFDIXML_WS_TOKEN", GETPOST('passtoken'), 'chaine', 1, '', $conf->entity); if (GETPOST('typent_id')) dolibarr_set_const($db, "CFDIXML_RESICO", GETPOST('typent_id'), 'chaine', 1, '', $conf->entity); } if($conf->global->CFDIXML_WS_MODE == 'PRODUCTION') $epprod = 'checked'; if($conf->global->CFDIXML_WS_MODE == 'TEST') $eptest = 'checked'; if(!$conf->global->CFDIXML_WS_MODE) $eptest = 'checked'; if($conf->global->CFDIXML_WS_MODE){ if($conf->global->CFDIXML_WS_MODE == 'PRODUCTION') $endpoint = $conf->global->CFDIXML_WS_PRODUCTION; if($conf->global->CFDIXML_WS_MODE == 'TEST') $endpoint = $conf->global->CFDIXML_WS_TEST; $check = curl_init($endpoint); dolibarr_set_const($db,'CFDIXML_WS_URL',$endpoint,'chaine',0,'',$conf->entity); if(!$check) setEventMessage('Error en el webservice seleccionado','warnings'); } $emisor = getEmisor($conf->global->MAIN_INFO_SOCIETE_FORME_JURIDIQUE); $rfiscal = $emisor['RegimenFiscal']; /* * View */ $form = new Form($db); $help_url = ''; $page_name = "CfdixmlSetup"; llxHeader('', $langs->trans($page_name), $help_url); // Subheader $linkback = ''.$langs->trans("BackToModuleList").''; print load_fiche_titre($langs->trans($page_name), $linkback, 'title_setup'); // Configuration header $head = cfdixmlAdminPrepareHead(); print dol_get_fiche_head($head, 'settings', $langs->trans($page_name), -1, "cfdixml@cfdixml"); // Setup page goes here echo '' . $langs->trans("CfdiutilsSetupPage") . '

'; // Crear estilo CSS para los indicadores // CSS mejorado para las marcas de verificación print ''; print '
'; print ''; print ''; print ''; print ''; print ''; print ''; print ''; // que funcionan mejor en diferentes sistemas print ''; print ''; print ''; print ''; // print '
';print_r(getEmisor($conf->global->MAIN_INFO_SOCIETE_FORME_JURIDIQUE));exit;
echo $rfiscal;
if($rfiscal == 626){
	print '
'; } print '
' . $langs->trans("Parameter") . '' . $langs->trans("Value") . '
Endpoint Producción
Endpoint Pruebas
'; print 'Seleccione el endpoint:'; print '
'; print '
'; print '
Archivo CSD CER'; print ''; if ($csd_exists) { print ''; // Código Unicode para checkmark print 'Certificado actual: ' . basename($csd) . ''; } else { print ''; // Código Unicode para X print 'No hay certificado cargado'; } print '
Archivo CSD KEY'; print ''; if ($key_exists) { print ''; // Código Unicode para checkmark print 'Llave actual: ' . basename($key) . ''; } else { print ''; // Código Unicode para X print 'No hay llave cargada'; } print '
Contraseña de los certificados
Token
Seleccionar tipo de RESICO'.$form->selectarray("typent_id", $formcompany->typent_array(0), $conf->global->CFDIXML_RESICO, 1, 0, 0, '', 0, 0, 0, (empty($conf->global->SOCIETE_SORT_ON_TYPEENT) ? 'ASC' : $conf->global->SOCIETE_SORT_ON_TYPEENT), '', 1).'
'; print '
'; print ''; print '
'; print '
'; print '
'; // Page end print dol_get_fiche_end(); llxFooter(); $db->close();