* * 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. */ /** * \file importzugferd/admin/setup.php * \ingroup importzugferd * \brief ImportZugferd setup page. */ // Load Dolibarr environment $res = 0; if (!$res && !empty($_SERVER["CONTEXT_DOCUMENT_ROOT"])) { $res = @include $_SERVER["CONTEXT_DOCUMENT_ROOT"]."/main.inc.php"; } $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"; } 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"); } // Libraries require_once DOL_DOCUMENT_ROOT."/core/lib/admin.lib.php"; require_once '../lib/importzugferd.lib.php'; // Translations $langs->loadLangs(array("admin", "importzugferd@importzugferd")); // Parameters $action = GETPOST('action', 'aZ09'); $backtopage = GETPOST('backtopage', 'alpha'); // Access control if (!$user->admin) { accessforbidden(); } // Form setup using FormSetup class if (!class_exists('FormSetup')) { require_once DOL_DOCUMENT_ROOT.'/core/class/html.formsetup.class.php'; } $formSetup = new FormSetup($db); /* * Setup configuration items */ // IMAP Settings Section $formSetup->newItem('IMAPSettings')->setAsTitle(); $item = $formSetup->newItem('IMPORTZUGFERD_IMAP_HOST'); $item->defaultFieldValue = ''; $item->cssClass = 'minwidth300'; $item->fieldAttr['placeholder'] = 'imap.example.com'; $item = $formSetup->newItem('IMPORTZUGFERD_IMAP_PORT'); $item->defaultFieldValue = '993'; $item->cssClass = 'width100'; $item = $formSetup->newItem('IMPORTZUGFERD_IMAP_USER'); $item->defaultFieldValue = ''; $item->cssClass = 'minwidth300'; $item->fieldAttr['placeholder'] = 'invoices@example.com'; $item = $formSetup->newItem('IMPORTZUGFERD_IMAP_PASSWORD'); $item->cssClass = 'minwidth300'; $item->fieldAttr['type'] = 'password'; $item = $formSetup->newItem('IMPORTZUGFERD_IMAP_FOLDER'); $item->defaultFieldValue = 'INBOX'; $item->cssClass = 'minwidth200'; $formSetup->newItem('IMPORTZUGFERD_IMAP_SSL')->setAsYesNo(); // Import Settings Section $formSetup->newItem('ImportSettings')->setAsTitle(); $formSetup->newItem('IMPORTZUGFERD_AUTO_CREATE_INVOICE')->setAsYesNo(); // Folder Import Settings Section $formSetup->newItem('FolderImportSettings')->setAsTitle(); $item = $formSetup->newItem('IMPORTZUGFERD_WATCH_FOLDER'); $item->defaultFieldValue = ''; $item->cssClass = 'minwidth400'; $item->fieldAttr['placeholder'] = '/path/to/invoices'; $item = $formSetup->newItem('IMPORTZUGFERD_ARCHIVE_FOLDER'); $item->defaultFieldValue = ''; $item->cssClass = 'minwidth400'; $item->fieldAttr['placeholder'] = '/path/to/archive'; $item = $formSetup->newItem('IMPORTZUGFERD_IMAP_ARCHIVE_FOLDER'); $item->defaultFieldValue = 'Archive'; $item->cssClass = 'minwidth200'; /* * Actions */ if (versioncompare(explode('.', DOL_VERSION), array(15)) < 0 && $action == 'update' && !empty($user->admin)) { $formSetup->saveConfFromPost(); } include DOL_DOCUMENT_ROOT.'/core/actions_setmoduleoptions.inc.php'; /* * View */ $form = new Form($db); $title = "ImportZugferdSetup"; llxHeader('', $langs->trans($title), '', '', 0, 0, '', '', '', 'mod-importzugferd page-admin'); // Subheader $linkback = ''.$langs->trans("BackToModuleList").''; print load_fiche_titre($langs->trans($title), $linkback, 'title_setup'); // Configuration header $head = importzugferdAdminPrepareHead(); print dol_get_fiche_head($head, 'settings', $langs->trans($title), -1, "importzugferd@importzugferd"); // Setup page description print ''.$langs->trans("ImportZugferdSetupPage").'

'; // Display the form print $formSetup->generateOutput(true); // Test IMAP connection button and folder selection if (getDolGlobalString('IMPORTZUGFERD_IMAP_HOST')) { print '
'; print '
'; print ''; print ''; print ''; print ''; // Check if IMAP extension is available $imap_available = function_exists('imap_open'); // Test connection action $imap_folders = array(); $connection_ok = false; if (!$imap_available) { print ''; print ''; print ''; } elseif ($action == 'test_imap' || $action == 'select_folder') { $host = getDolGlobalString('IMPORTZUGFERD_IMAP_HOST'); $port = getDolGlobalString('IMPORTZUGFERD_IMAP_PORT', '993'); $imap_user = getDolGlobalString('IMPORTZUGFERD_IMAP_USER'); $password = getDolGlobalString('IMPORTZUGFERD_IMAP_PASSWORD'); $ssl = getDolGlobalString('IMPORTZUGFERD_IMAP_SSL'); $mailbox_base = '{' . $host . ':' . $port . '/imap' . ($ssl ? '/ssl' : '') . '/novalidate-cert}'; $mailbox = $mailbox_base . 'INBOX'; $connection = @imap_open($mailbox, $imap_user, $password); if ($connection) { $connection_ok = true; setEventMessages($langs->trans('ConnectionSuccessful'), null, 'mesgs'); // Get list of folders $folders_raw = imap_list($connection, $mailbox_base, '*'); if ($folders_raw) { foreach ($folders_raw as $folder) { // Remove the mailbox base from folder name $folder_name = str_replace($mailbox_base, '', $folder); // Decode folder name (IMAP uses modified UTF-7) $folder_name_decoded = imap_utf7_decode($folder_name); $imap_folders[$folder_name] = $folder_name_decoded; } } imap_close($connection); } else { setEventMessages($langs->trans('ConnectionFailed') . ': ' . imap_last_error(), null, 'errors'); } } // Save selected folder if ($action == 'select_folder' && GETPOST('imap_folder', 'alpha')) { $selected_folder = GETPOST('imap_folder', 'alpha'); dolibarr_set_const($db, 'IMPORTZUGFERD_IMAP_FOLDER', $selected_folder, 'chaine', 0, '', $conf->entity); setEventMessages($langs->trans('FolderSelected').': '.$selected_folder, null, 'mesgs'); } // Only show status and folder selection if IMAP is available if ($imap_available) { print ''; print ''; print ''; print ''; } // Show folder selection if connection was successful if ($imap_available && $connection_ok && !empty($imap_folders)) { print ''; print ''; print ''; print ''; print ''; } // Only show test button if IMAP extension is available if ($imap_available) { print ''; print ''; print ''; } print '
'.$langs->trans('TestConnection').'
'; print ''; print $langs->trans('IMAPExtensionNotInstalled'); print '
'; print ''.$langs->trans('IMAPExtensionHelp').''; print '
'.$langs->trans('Status').''; if ($action == 'test_imap' || $action == 'select_folder') { if ($connection_ok) { print ''.$langs->trans('ConnectionSuccessful').''; } else { print ''.$langs->trans('ConnectionFailed').''; } } else { print ''.$langs->trans('ClickTestToCheck').''; } print '
'.$langs->trans('SelectFolder').''; print '
'; print ''; print ''; $current_folder = getDolGlobalString('IMPORTZUGFERD_IMAP_FOLDER', 'INBOX'); print ''; print ' '; print '
'; print '
'; print ''.$langs->trans('FoundFolders').': '.count($imap_folders).''; print '
'; print ''; print ''.$langs->trans('TestConnection'); print ''; print '
'; print '
'; } print '
'; // Page end print dol_get_fiche_end(); llxFooter(); $db->close();