Skip to content

Commit

Permalink
Merge pull request #725 from Evarisk/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
nicolas-eoxia authored Nov 15, 2023
2 parents a3c8051 + 7451c51 commit d853374
Show file tree
Hide file tree
Showing 53 changed files with 1,301 additions and 530 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
## Informations

- Numéro du module : 436318
- Dernière mise à jour : 14/09/2023
- Dernière mise à jour : 15/11/2023
- Éditeur : [Evarisk](https://evarisk.com)
- Thème : Eldy Menu
- Licence : GPLv3
- Disponible sur : Windows - MacOS - Linux

### Version

- Version : 1.1.2
- Compatibilité : Dolibarr 16.0.0 - 18.0.1
- Version : 1.2.0
- Compatibilité : Dolibarr 16.0.0 - 18.0.3

## Liens

Expand Down
58 changes: 55 additions & 3 deletions admin/documents.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,39 @@
}
}

if ($action == 'specimen') {

$modele = GETPOST('module', 'alpha');
$documentType = preg_split('/_/', $modele)[1];

require_once __DIR__ . '/../../' . $moduleNameLowerCase . '/class/' . $moduleNameLowerCase . 'documents/' . $documentType . '.class.php';

$objectDocument = new $documentType($db);
$objectDocument->initAsSpecimen();

// Search template files
$dir = __DIR__ . "/../../". $moduleNameLowerCase . "/core/modules/" . $moduleNameLowerCase . "/" . $moduleNameLowerCase . "documents/" . $documentType . '/';
$file = 'pdf_' . $modele . ".modules.php";
if (file_exists($dir . $file)) {
$classname = 'pdf_' . $modele;
require_once $dir . $file;

$obj = new $classname($db);

$modulePart = str_replace('document', '', $documentType);

if ($obj->write_file($objectDocument, $langs, ['object' => $objectDocument]) > 0) {
header("Location: " . DOL_URL_ROOT . "/document.php?modulepart=". $modulePart ."&file=SPECIMEN.pdf");
return;
} else {
setEventMessages($obj->error, $obj->errors, 'errors');
dol_syslog($obj->error, LOG_ERR);
}
} else {
setEventMessages($langs->trans("ErrorModuleNotFound"), null, 'errors');
dol_syslog($langs->trans("ErrorModuleNotFound"), LOG_ERR);
}
}

/*
* View
Expand Down Expand Up @@ -277,6 +310,24 @@
print '</td><td class="center">';
print '<input type="submit" class="button" name="save" value="' . $langs->trans('Save') . '">';
print '</td></tr>';

$reshook = $hookmanager->executeHooks('saturneAdminAdditionalConfig', $parameters); // Note that $action and $object may have been modified by some hooks
if (empty($reshook)) {
$additionalConfig = $hookmanager->resArray;
}
if (is_array($additionalConfig) && !empty($additionalConfig)) {
foreach($additionalConfig as $configName => $configCode) {
print '<tr class="oddeven"><td>';
print $langs->trans($configName);
print '</td><td>';
print $langs->trans($configName . 'Description');
print '</td>';
print '<td class="center">';
print ajax_constantonoff($configCode);
print '</td></td><td></tr>';
}
}

print '</form>';
print '</table>';

Expand All @@ -287,10 +338,11 @@
$documentParentType = $documentType[0];
$documentType = $documentType[1];
} else {
$documentParentType = $documentData['documentType'];
$documentParentType = ($documentData['className'] ?? $documentData['documentType']);
$documentType = $documentData['documentType'];
}

require_once __DIR__ . '/../../' . $moduleNameLowerCase . '/class/' . $moduleNameLowerCase . 'documents/' . $documentData['documentType'] . '.class.php';
require_once __DIR__ . '/../../' . $moduleNameLowerCase . '/class/' . $moduleNameLowerCase . 'documents/' . ($documentData['className'] ?? $documentData['documentType']) . '.class.php';

$object = new $type($db);

Expand All @@ -308,4 +360,4 @@
// Page end
print dol_get_fiche_end();
llxFooter();
$db->close();
$db->close();
77 changes: 77 additions & 0 deletions admin/information.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?php
/* Copyright (C) 2022-2023 EVARISK <technique@evarisk.com>
*
* 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 admin/information.php
* \ingroup saturne
* \brief Information page of module Saturne and other
*/

// Load Saturne environment
if (file_exists('../saturne.main.inc.php')) {
require_once __DIR__ . '/../saturne.main.inc.php';
} elseif (file_exists('../../saturne.main.inc.php')) {
require_once __DIR__ . '/../../saturne.main.inc.php';
} else {
die('Include of saturne main fails');
}

// Load Dolibarr libraries
require_once DOL_DOCUMENT_ROOT . '/includes/parsedown/Parsedown.php';

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

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

// 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');

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

/*
* View
*/

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

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');

// 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');
$content = file_get_contents($filePath);
print $parsedown->text($content);

// Page end
print dol_get_fiche_end();
llxFooter();
$db->close();
3 changes: 0 additions & 3 deletions admin/object.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,6 @@

// Initialize technical objects
$className = ucfirst($objectType);
if (strstr($className, '_')) {
$className = preg_replace('/_/', '', $className);
}
$object = new $className($db);

// Initialize view objects
Expand Down
2 changes: 1 addition & 1 deletion class/actions_saturne.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public function printCommonFooter($parameters)
$error = 0; // Error counter

if ($parameters['currentcontext'] == 'usercard') {
$id = GETPOST('id');
$id = GETPOSTISSET('id') ? GETPOST('id') : 0;

print '<script src="'.dol_buildpath($resourcesRequired['js'], 1).((strpos($resourcesRequired['js'], '?') === false) ? '?' : '&amp;').'lang='.$langs->defaultlang.'"></script>'."\n";
print '<script src="'.dol_buildpath($resourcesRequired['signature'], 1).((strpos($resourcesRequired['signature'], '?') === false) ? '?' : '&amp;').'lang='.$langs->defaultlang.'"></script>'."\n";
Expand Down
2 changes: 1 addition & 1 deletion class/saturnecertificate.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ public function checkDateEnd(string $objectType = 'saturne_certificate'): int
{
global $langs, $user;

$certificates = self::fetchAll();
$certificates = self::fetchAll('', '', 0, 0, ['customsql' => 't.status >= 0']);
if (is_array($certificates) && !empty($certificates)){
$nbCertificate = 0;
foreach ($certificates as $certificate) {
Expand Down
43 changes: 24 additions & 19 deletions class/saturnedashboard.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,20 @@ public function __construct(DoliDB $db, string $moduleNameLowerCase = 'saturne')
}

/**
* Load dashboard info.
* Load dashboard info
*
* @param array $moreParams Parameters for load dashboard info
*
* @return array
* @throws Exception
*/
public function load_dashboard(): array
public function load_dashboard(array $moreParams = []): array
{
require_once __DIR__ . '/../../' . $this->module . '/class/' . $this->module . 'dashboard.class.php';

$className = ucfirst($this->module) . 'Dashboard';
$dashboard = new $className($this->db);
$dashboardDatas = $dashboard->load_dashboard();
$dashboardDatas = $dashboard->load_dashboard($moreParams);

$dashboardInfos = [];
if (is_array($dashboardDatas) && !empty($dashboardDatas)) {
foreach ($dashboardDatas as $key => $dashboardData) {
Expand All @@ -84,12 +86,14 @@ public function load_dashboard(): array
}

/**
* Show dashboard.
* Show dashboard
*
* @param array $moreParams Parameters for load dashboard info
*
* @return void
* @throws Exception
*/
public function show_dashboard()
public function show_dashboard(array $moreParams = [])
{
global $conf, $form, $langs, $moduleNameLowerCase, $user;

Expand All @@ -98,7 +102,7 @@ public function show_dashboard()

$conf->global->MAIN_DISABLE_TRUNC = 1;

$dashboards = $this->load_dashboard();
$dashboards = $this->load_dashboard($moreParams);

print '<form method="POST" action="' . $_SERVER['PHP_SELF'] . '" class="dashboard" id="dashBoardForm">';
print '<input type="hidden" name="token" value="' . newToken() . '">';
Expand All @@ -118,7 +122,7 @@ public function show_dashboard()
}

print '<div class="add-widget-box" style="' . (!empty((array)$disableWidgetList) ? '' : 'display:none') . '">';
print Form::selectarray('boxcombo', $dashboardWidgetsArray, -1, $langs->trans('ChooseBoxToAdd') . '...', 0, 0, '', 1, 0, 0, 'DESC', 'maxwidth150onsmartphone hideonprint add-dashboard-widget', 0, 'hidden selected', 0, 1);
print Form::selectarray('boxcombo', $dashboardWidgetsArray, -1, $langs->trans('ChooseBoxToAdd'), 0, 0, '', 1, 0, 0, 'DESC', 'maxwidth300 widthcentpercentminusx hideonprint add-dashboard-widget', 0, 'hidden selected', 0, 1);
if (!empty($conf->use_javascript_ajax)) {
include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php';
print ajax_combobox('boxcombo');
Expand Down Expand Up @@ -168,6 +172,7 @@ public function show_dashboard()
if (is_array($dashboardGraphs) && !empty($dashboardGraphs)) {
foreach ($dashboardGraphs as $keyElement => $dashboardGraph) {
$nbDataset = 0;
$uniqueKey = strip_tags($dashboardGraph['title']) . $keyElement;
if (is_array($dashboardGraph['data']) && !empty($dashboardGraph['data'])) {
if ($dashboardGraph['dataset'] >= 2) {
foreach ($dashboardGraph['data'] as $dashboardGraphDatasets) {
Expand All @@ -186,38 +191,38 @@ public function show_dashboard()
if ($nbDataset > 0) {
if (is_array($dashboardGraph['labels']) && !empty($dashboardGraph['labels'])) {
foreach ($dashboardGraph['labels'] as $dashboardGraphLabel) {
$dashboardGraphLegend[$keyElement][] = $langs->trans($dashboardGraphLabel['label']);
$dashboardGraphColor[$keyElement][] = $langs->trans($dashboardGraphLabel['color']);
$dashboardGraphLegend[$uniqueKey][] = $dashboardGraphLabel['label'];
$dashboardGraphColor[$uniqueKey][] = $dashboardGraphLabel['color'];
}
}

$arrayKeys = array_keys($dashboardGraph['data']);
foreach ($arrayKeys as $key) {
if ($dashboardGraph['dataset'] >= 2) {
$graphData[$keyElement][] = $dashboardGraph['data'][$key];
$graphData[$uniqueKey][] = $dashboardGraph['data'][$key];
} else {
$graphData[$keyElement][] = [
0 => $langs->trans($dashboardGraph['labels'][$key]['label']),
$graphData[$uniqueKey][] = [
0 => $dashboardGraph['labels'][$key]['label'],
1 => $dashboardGraph['data'][$key]
];
}
}

$fileName[$keyElement] = $keyElement . '.png';
$fileUrl[$keyElement] = DOL_URL_ROOT . '/viewimage.php?modulepart=' . $moduleNameLowerCase . '&file=' . $keyElement . '.png';
$fileName[$uniqueKey] = $uniqueKey . '.png';
$fileUrl[$uniqueKey] = DOL_URL_ROOT . '/viewimage.php?modulepart=' . $moduleNameLowerCase . '&file=' . $uniqueKey . '.png';

$graph = new DolGraph();
$graph->SetData($graphData[$keyElement]);
$graph->SetData($graphData[$uniqueKey]);

if ($dashboardGraph['dataset'] >= 2) {
$graph->SetLegend($dashboardGraphLegend[$keyElement]);
$graph->SetLegend($dashboardGraphLegend[$uniqueKey]);
}
$graph->SetDataColor($dashboardGraphColor[$keyElement]);
$graph->SetDataColor($dashboardGraphColor[$uniqueKey]);
$graph->SetType([$dashboardGraph['type'] ?? 'pie']);
$graph->SetWidth($dashboardGraph['width'] ?? $width);
$graph->SetHeight($dashboardGraph['height'] ?? $height);
$graph->setShowLegend($dashboardGraph['showlegend'] ?? 2);
$graph->draw($fileName[$keyElement], $fileUrl[$keyElement]);
$graph->draw($fileName[$uniqueKey], $fileUrl[$uniqueKey]);
print '<div>';
print load_fiche_titre($dashboardGraph['title'], $dashboardGraph['morehtmlright'], $dashboardGraph['picto']);
print $graph->show();
Expand Down
16 changes: 15 additions & 1 deletion class/saturneobject.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,18 @@ public function getLibStatut(int $mode = 0): string
return $this->LibStatut($this->status, $mode);
}


/**
* Return the status.
*
* @param int $status ID status.
* @param int $mode 0 = long label, 1 = short label, 2 = Picto + short label, 3 = Picto, 4 = Picto + long label, 5 = Short label + Picto, 6 = Long label + Picto.
* @return string Label of status.
*/
public function LibStatut(int $status, int $mode = 0): string
{
return '';
}
/**
* Load the info information in the object.
*
Expand Down Expand Up @@ -656,7 +668,8 @@ public function getTriggerDescription(SaturneObject $object): string
$now = dol_now();

$ret = $langs->trans('Ref') . ' : ' . $object->ref . '</br>';
$ret .= (isset($object->label) && !empty($object->label) ? $langs->transnoentities('Label') . ' : ' . $object->label . '</br>' : '');
$ret .= $langs->trans('TechnicalID') . ' : ' . $object->id . '<br>';
$ret .= (isset($object->label) && !empty($object->label) ? $langs->transnoentities('Label') . ' : ' . $object->label . '</br>' : '');
$ret .= (isset($object->description) && !empty($object->description) ? $langs->transnoentities('Description') . ' : ' . $object->description . '</br>' : '');
$ret .= (isset($object->type) && !empty($object->type) ? $langs->transnoentities('Type') . ' : ' . $langs->transnoentities($object->type) . '</br>' : '');
$ret .= (isset($object->value) && !empty($object->value) ? $langs->transnoentities('Value') . ' : ' . $object->value . '</br>' : '');
Expand Down Expand Up @@ -686,6 +699,7 @@ public function getTriggerDescription(SaturneObject $object): string
}
$ret .= (isset($object->note_public) && dol_strlen($object->note_public) > 0 ? $langs->transnoentities('NotePublic') . ' : ' . $object->note_public . '</br>' : '');
$ret .= (isset($object->note_private) && dol_strlen($object->note_private) > 0 ? $langs->transnoentities('NotePrivate') . ' : ' . $object->note_private . '</br>' : '');
$ret .= (isset($object->status) && dol_strlen($object->status) > 0 ? $langs->transnoentities('Status') . ' : ' . $object->status . '<br>' : '');

return $ret;
}
Expand Down
Loading

0 comments on commit d853374

Please sign in to comment.