Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#1123 [Admin] fix: clean admin files #1124

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 22 additions & 26 deletions admin/about.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
/* Copyright (C) 2022-2023 EVARISK <[email protected]>
/* Copyright (C) 2022-2024 EVARISK <[email protected]>
*
* 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
Expand All @@ -18,10 +18,10 @@
/**
* \file admin/about.php
* \ingroup saturne
* \brief About page of module Saturne.
* \brief About page of module Saturne
*/

// Load Saturne environment.
// Load Saturne environment
if (file_exists('../saturne.main.inc.php')) {
require_once __DIR__ . '/../saturne.main.inc.php';
} elseif (file_exists('../../saturne.main.inc.php')) {
Expand All @@ -30,52 +30,48 @@
die('Include of saturne main fails');
}

// Get module parameters.
// Get module parameters
$moduleName = GETPOST('module_name', 'alpha');
$moduleNameLowerCase = strtolower($moduleName);
$moduleNameLowerCase = dol_strtolower($moduleName);

// Load Module Libraries.
require_once __DIR__ . '/../../' . $moduleNameLowerCase . '/lib/' . $moduleNameLowerCase . '.lib.php';
require_once __DIR__ . '/../../' . $moduleNameLowerCase . '/core/modules/mod' . $moduleName . '.class.php';
// Load Module libraries
saturne_load_module_files($moduleName, []);

// Global variables definitions.
// Global variables definitions
global $db, $langs, $user;

// Load translation files required by the page.
// Load translation files required by the page
saturne_load_langs(['admin']);

// Initialize technical objects.
// Initialize technical objects
$className = 'mod' . $moduleName;
$modModule = new $className($db);

// Get parameters.
$backtopage = GETPOST('backtopage', 'alpha');

// Security check - Protection if external user.
$permissiontoread = $user->rights->$moduleNameLowerCase->adminpage->read;
saturne_check_access($permissiontoread);
// Security check - Protection if external user
$permissionToRead = $user->hasRight($moduleNameLowerCase, 'adminpage', 'read');
saturne_check_access($permissionToRead);

/*
* View
*/

$title = $langs->trans('ModuleSetup', $moduleName);
$help_url = 'FR:Module_' . $moduleName;
$title = $langs->trans('ModuleSetup', $moduleName);
$helpUrl = 'FR:Module_' . $moduleName;

saturne_header(0, '', $title, $help_url);
saturne_header(0, '', $title, $helpUrl);

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

// Configuration header.
// Configuration header
$preHead = $moduleNameLowerCase . '_admin_prepare_head';
$head = $preHead();
$head = $preHead();
print dol_get_fiche_head($head, 'about', $title, -1, $moduleNameLowerCase . '_color@' . $moduleNameLowerCase);

print $modModule->getDescLong();

// Page end.
// Page end
print dol_get_fiche_end();
llxFooter();
$db->close();
25 changes: 14 additions & 11 deletions admin/information.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
/* Copyright (C) 2022-2023 EVARISK <[email protected]>
/* Copyright (C) 2022-2024 EVARISK <[email protected]>
*
* 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
Expand Down Expand Up @@ -37,37 +37,40 @@
require_once __DIR__ . '/../lib/saturne.lib.php';

// Global variables definitions
global $db, $langs;
global $db, $langs, $user;

// Load translation files required by the page
saturne_load_langs(['admin']);

// Get parameters
$filename = GETPOST('filename', 'alpha');
$tabName = GETPOST('tab_name', 'alpha');
$backtopage = GETPOST('backtopage', 'alpha');
$fileName = GETPOST('filename', 'alpha');
$tabName = GETPOST('tab_name', 'alpha');

// Initialize technical objects
$parsedown = new Parsedown();

// Security check - Protection if external user
$permissionToRead = $user->hasRight('saturne', 'adminpage', 'read');
saturne_check_access($permissionToRead);

/*
* View
*/

$title = $langs->trans('ModuleSetup', 'Saturne');
$help_url = 'FR:Module_Saturne';
$title = $langs->trans('ModuleSetup', 'Saturne');
$helpUrl = 'FR:Module_Saturne';

saturne_header(0, '', $title, $help_url);
saturne_header(0, '', $title, $helpUrl);

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

// Configuration header
$head = saturne_admin_prepare_head();
print dol_get_fiche_head($head, $tabName, $title, -1, 'saturne_color@saturne');

$filePath = dol_buildpath('saturne/' . $filename . '.md');
$filePath = dol_buildpath('saturne/' . $fileName . '.md');
$content = file_get_contents($filePath);
print $parsedown->text($content);

Expand Down
28 changes: 14 additions & 14 deletions admin/object.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
/* Copyright (C) 2021-2023 EVARISK <[email protected]>
/* Copyright (C) 2021-2024 EVARISK <[email protected]>
*
* 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
Expand All @@ -18,7 +18,7 @@
/**
* \file admin/object/object.php
* \ingroup saturne
* \brief Saturne object config page.
* \brief Saturne object config page
*/

// Load Saturne environment
Expand All @@ -34,7 +34,7 @@
$moduleName = GETPOST('module_name', 'alpha');
$objectType = GETPOST('object_type', 'alpha');

// If the previous action is from extrafields, the return value is PHP_SELF without querys
// If the previous action is from extra fields, the return value is PHP_SELF without query's
// So we need to fill moduleName and objectType using the previous url (HTTP_REFERER)
if (empty($moduleName) && empty($objectType)) {
$lastUrl = $_SERVER['HTTP_REFERER'];
Expand All @@ -50,12 +50,13 @@
}
}

$moduleNameLowerCase = strtolower($moduleName);
$moduleNameLowerCase = dol_strtolower($moduleName);

// Libraries
// Load Dolibarr libraries
require_once DOL_DOCUMENT_ROOT . '/core/lib/admin.lib.php';

require_once __DIR__ . '/../../' . $moduleNameLowerCase . '/lib/' . $moduleNameLowerCase . '.lib.php';
// Load Module libraries
saturne_load_module_files($moduleName, []);
require_once __DIR__ . '/../../' . $moduleNameLowerCase . '/class/' . $objectType . '.class.php';

// Global variables definitions
Expand All @@ -65,8 +66,7 @@
saturne_load_langs(['admin']);

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

// Initialize technical objects
$className = ucfirst($objectType);
Expand All @@ -75,11 +75,11 @@
// Initialize view objects
$form = new Form($db);

$hookmanager->initHooks([$objectType . 'admin']); // Note that conf->hooks_modules contains array.
$hookmanager->initHooks([$objectType . 'admin']); // Note that conf->hooks_modules contains array

// Security check - Protection if external user
$permissiontoread = $user->rights->$moduleNameLowerCase->adminpage->read;
saturne_check_access($permissiontoread);
$permissionToRead = $user->hasRight($moduleNameLowerCase, 'adminpage', 'read');
saturne_check_access($permissionToRead);

/*
* View
Expand All @@ -91,12 +91,12 @@
saturne_header(0,'', $title, $help_url);

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

// Configuration header
$preHead = $moduleNameLowerCase . '_admin_prepare_head';
$head = $preHead();
$head = $preHead();
print dol_get_fiche_head($head, $object->element, $title, -1, $moduleNameLowerCase . '_color@' . $moduleNameLowerCase);

require_once __DIR__ . '/../core/tpl/admin/object/object_numbering_module_view.tpl.php';
Expand Down
19 changes: 9 additions & 10 deletions admin/pwa.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,19 @@
// Get module parameters
$moduleName = GETPOST('module_name', 'alpha');
$startUrl = GETPOST('start_url', 'alpha');
$moduleNameLowerCase = strtolower($moduleName);
$moduleNameLowerCase = dol_strtolower($moduleName);

// Load Dolibarr libraries
require_once TCPDF_PATH . 'tcpdf_barcodes_2d.php';

// Load Module Libraries
require_once __DIR__ . '/../../' . $moduleNameLowerCase . '/lib/' . $moduleNameLowerCase . '.lib.php';
// Load Module libraries
saturne_load_module_files($moduleName);

// Global variables definitions
global $conf, $db, $hookmanager, $langs, $user;

// Load translation files required by the page
saturne_load_langs();
saturne_load_langs(['admin']);

// Get parameters
$action = GETPOST('action', 'alpha');
Expand All @@ -56,7 +56,7 @@
$hookmanager->initHooks([$moduleNameLowerCase . 'pwaadmin', 'saturneadmin']); // Note that conf->hooks_modules contains array

// Security check - Protection if external user
$permissionToRead = $user->rights->$moduleNameLowerCase->adminpage->read;
$permissionToRead = $user->hasRight($moduleNameLowerCase, 'adminpage', 'read');
saturne_check_access($permissionToRead);

/*
Expand All @@ -66,14 +66,13 @@
if ($action == 'generate_QRCode') {
$urlToEncode = GETPOST('urlToEncode');

$barcode = new TCPDF2DBarcode($urlToEncode, 'QRCODE,L');
$barcode = new TCPDF2DBarcode($urlToEncode, 'QRCODE,H');

dol_mkdir($conf->$moduleNameLowerCase->multidir_output[$conf->entity] . '/pwa/qrcode/');
$file = $conf->$moduleNameLowerCase->multidir_output[$conf->entity] . '/pwa/qrcode/' . 'barcode_' . dol_print_date(dol_now(), 'dayhourlog') . '.png';

$imageData = $barcode->getBarcodePngData();
$imageData = imagecreatefromstring($imageData);
imagepng($imageData, $file);
file_put_contents($file, $imageData);

setEventMessage('SavedConfig');
header('Location: ' . $_SERVER['PHP_SELF'] . '?module_name=' . $moduleName . '&start_url=' . $urlToEncode);
Expand All @@ -90,7 +89,7 @@
saturne_header(0, '', $title, $helpUrl);

// Subheader
$linkBack = '<a href="' . DOL_URL_ROOT . '/admin/modules.php?restore_lastsearch_values=1' . '">' . $langs->trans('BackToModuleList') . '</a>';
$linkBack = '<a href="' . DOL_URL_ROOT . '/admin/modules.php' . '">' . $langs->trans('BackToModuleList') . '</a>';
print load_fiche_titre($title, $linkBack, 'title_setup');

// Configuration header
Expand All @@ -107,7 +106,7 @@
print '<form method="POST" action="' . $_SERVER['PHP_SELF'] . '?module_name=' . $moduleName . '">';
print '<input type="hidden" name="token" value="' . newToken() . '">';
print '<input type="hidden" name="action" value="generate_QRCode">';
print '<input hidden name="urlToEncode" value="' . $startUrl . '">';
print '<input type="hidden" name="urlToEncode" value="' . $startUrl . '">';

print '<table class="noborder centpercent">';
print '<tr class="liste_titre">';
Expand Down
10 changes: 5 additions & 5 deletions admin/redirection.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@
// Load Dolibarr libraries
require_once TCPDF_PATH . 'tcpdf_barcodes_2d.php';

// Load Module libraries
// Load Saturne libraries
require_once __DIR__ . '/../lib/saturne.lib.php';
require_once __DIR__ . '/../class/saturneredirection.class.php';

// Global variables definitions
global $conf, $db, $hookmanager, $langs, $user;

// Load translation files required by the page
saturne_load_langs();
saturne_load_langs(['admin']);

// Get parameters
$action = GETPOST('action', 'alpha');
Expand All @@ -61,7 +61,7 @@
$hookmanager->initHooks([$moduleNameLowerCase . 'redirectionadmin', 'saturneadmin']); // Note that conf->hooks_modules contains array

// Security check - Protection if external user
$permissionToRead = $user->rights->$moduleNameLowerCase->adminpage->read;
$permissionToRead = $user->hasRight($moduleNameLowerCase, 'adminpage', 'read');
saturne_check_access($permissionToRead);

/*
Expand Down Expand Up @@ -117,8 +117,8 @@
saturne_header(0, '', $title, $helpUrl);

// Subheader
$linkBack = '<a href="' . DOL_URL_ROOT . '/admin/modules.php?restore_lastsearch_values=1' . '">' . $langs->trans('BackToModuleList') . '</a>';
print load_fiche_titre($title, '', 'title_setup');
$linkBack = '<a href="' . DOL_URL_ROOT . '/admin/modules.php' . '">' . $langs->trans('BackToModuleList') . '</a>';
print load_fiche_titre($title, $linkBack, 'title_setup');

// Configuration header
$preHead = $moduleNameLowerCase . '_admin_prepare_head';
Expand Down
Loading