Skip to content

Commit

Permalink
Merge pull request #958 from Evarisk/develop
Browse files Browse the repository at this point in the history
1.5.0
  • Loading branch information
nicolas-eoxia authored Jun 3, 2024
2 parents 3d2a3fd + efcef3b commit 277a954
Show file tree
Hide file tree
Showing 19 changed files with 256 additions and 292 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
## Informations

- Numéro du module : 436318
- Dernière mise à jour : 17/05/2024
- Dernière mise à jour : 03/06/2024
- Éditeur : [Evarisk](https://evarisk.com)
- Thème : Eldy Menu
- Licence : GPLv3
- Disponible sur : Windows - MacOS - Linux

### Version

- Version : 1.4.0
- Version : 1.5.0
- PHP : 7.4.33
- Compatibilité : Dolibarr 16.0.0 - 19.0.2

Expand Down
55 changes: 25 additions & 30 deletions admin/documents.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,12 @@

// Get parameters
$action = GETPOST('action', 'alpha');
$value = GETPOST('value', 'alpha');
$modelName = GETPOST('model_name', 'alpha');
$type = GETPOST('type', 'alpha');
$const = GETPOST('const', 'alpha');
$label = GETPOST('label', 'alpha');
$modulepart = GETPOST('modulepart', 'aZ09'); // Used by actions_setmoduleoptions.inc.php
$pageY = GETPOST('page_y', 'int');

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

Expand All @@ -73,20 +74,20 @@

// Activate a model
if ($action == 'set') {
addDocumentModel($value, $type, $label, $const);
header('Location: ' . $_SERVER['PHP_SELF'] . '?module_name=' . $moduleName . '#' . $type);
addDocumentModel($modelName, $type, $label, $const);
header('Location: ' . $_SERVER['PHP_SELF'] . '?module_name=' . $moduleName . '&page_y=' . $pageY);
exit;
} elseif ($action == 'del') {
delDocumentModel($value, $type);
header('Location: ' . $_SERVER['PHP_SELF'] . '?module_name=' . $moduleName . '#' . $type);
delDocumentModel($modelName, $type);
header('Location: ' . $_SERVER['PHP_SELF'] . '?module_name=' . $moduleName . '&page_y=' . $pageY);
exit;
}

// Set default model
if ($action == 'setdoc') {
$confName = dol_strtoupper($moduleName . '_' . $type) . '_DEFAULT_MODEL';
dolibarr_set_const($db, $confName, $value, 'chaine', 0, '', $conf->entity);
header('Location: ' . $_SERVER['PHP_SELF'] . '?module_name=' . $moduleName . '#' . $type);
dolibarr_set_const($db, $confName, $modelName, 'chaine', 0, '', $conf->entity);
header('Location: ' . $_SERVER['PHP_SELF'] . '?module_name=' . $moduleName . '&page_y=' . $pageY);
exit;
}

Expand Down Expand Up @@ -116,7 +117,7 @@
$result = dol_delete_file($filetodelete);
if ($result > 0) {
setEventMessages($langs->trans('FileWasRemoved', GETPOST('file')), null);
header('Location: ' . $_SERVER['PHP_SELF'] . '?module_name=' . $moduleName . '#' . $type);
header('Location: ' . $_SERVER['PHP_SELF'] . '?module_name=' . $moduleName . '&page_y=' . $pageY);
exit;
}
}
Expand Down Expand Up @@ -187,36 +188,30 @@
}

if ($action == 'specimen') {

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

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

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

// Search template files
$dir = __DIR__ . "/../../". $moduleNameLowerCase . "/core/modules/" . $moduleNameLowerCase . "/" . $moduleNameLowerCase . "documents/" . $documentType . '/';
$file = 'pdf_' . $modele . ".modules.php";
$dir = __DIR__ . '/../../' . $moduleNameLowerCase . '/core/modules/' . $moduleNameLowerCase . '/' . $moduleNameLowerCase . 'documents/' . $documentType . '/';
$file = 'pdf_' . $modelName . '.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;
$moreParams['object'] = new stdClass();
$moreParams['user'] = $user;
$moreParams['specimen'] = 1;
$moreParams['zone'] = 'public';
$moreParams['objectType'] = str_replace('document', '', $documentType);

$result = $document->generateDocument($modelName, $langs, 0, 0, 0, $moreParams);
if ($result <= 0) {
setEventMessages($document->error, $document->errors, 'errors');
} else {
setEventMessages($obj->error, $obj->errors, 'errors');
dol_syslog($obj->error, LOG_ERR);
setEventMessages($langs->trans('FileGenerated') . ' - ' . '<a href=' . DOL_URL_ROOT . '/document.php?modulepart=' . $moreParams['objectType'] . '&file=' . urlencode('public_specimen/' . $document->last_main_doc) . '&entity=' . $conf->entity . '"' . '>' . $document->last_main_doc . '</a>', []);
header('Location: ' . $_SERVER['PHP_SELF'] . '?module_name=' . $moduleName . '&page_y=' . $pageY);
exit;
}
} else {
setEventMessages($langs->trans("ErrorModuleNotFound"), null, 'errors');
dol_syslog($langs->trans("ErrorModuleNotFound"), LOG_ERR);
}
}

Expand Down
4 changes: 2 additions & 2 deletions admin/pwa.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
imagepng($imageData, $file);

setEventMessage('SavedConfig');
header('Location: ' . $_SERVER['PHP_SELF'] . '?module_name=' . $moduleName);
header('Location: ' . $_SERVER['PHP_SELF'] . '?module_name=' . $moduleName . '&start_url=' . $startUrl);
exit;
}

Expand All @@ -100,7 +100,7 @@
// PWA QR Code generation
print load_fiche_titre($langs->transnoentities('PWAQRCodeGenerationManagement'), '', '');

print '<form method="POST" action="' . $_SERVER['PHP_SELF'] . '?module_name=' . $moduleName . '">';
print '<form method="POST" action="' . $_SERVER['PHP_SELF'] . '?module_name=' . $moduleName . '&start_url=' . $startUrl . '">';
print '<input type="hidden" name="token" value="' . newToken() . '">';
print '<input type="hidden" name="action" value="generate_QRCode">';
print '<input hidden name="urlToEncode" value="' . $startUrl . '">';
Expand Down
13 changes: 10 additions & 3 deletions class/saturnedashboard.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -209,10 +209,17 @@ public function show_dashboard(?array $moreParams = [])
}
if ($nbDataset > 0) {
if (is_array($dashboardGraph['labels']) && !empty($dashboardGraph['labels'])) {
foreach ($dashboardGraph['labels'] as $dashboardGraphLabel) {
foreach ($dashboardGraph['labels'] as $key => $dashboardGraphLabel) {
$dashboardGraphLegend[$uniqueKey][] = $dashboardGraphLabel['label'];
if (dol_strlen($dashboardGraphLabel['color']) > 0) {
$dashboardGraphColor[$uniqueKey][] = $dashboardGraphLabel['color'];
if (isset($dashboardGraphLabel['color'])) {
if (dol_strlen($dashboardGraphLabel['color']) > 0) {
$dashboardGraphColor[$uniqueKey][] = $dashboardGraphLabel['color'];
} else {
// If only one color is defined in category, the others will be black
// If no color is defined, all the colors will be defined by global $theme_datacolor
// To avoid black color we better define a color instead of empty
$dashboardGraphColor[$uniqueKey][] = $this->getColorRange($key);
}
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions class/saturnedocuments.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,8 @@ public function create(User $user, bool $notrigger = false, object $parentObject
$this->type = $this->element;
}
$this->module_name = $this->module;
$this->parent_id = $parentObject->id;
$this->parent_type = $parentObject->element_type ?: $parentObject->element;
$this->parent_id = $parentObject->id ?: 0;
$this->parent_type = $parentObject->element_type ?: $parentObject->element ?: '';
$this->fk_user_creat = $user->id ?: 1;

//$this->DocumentFillJSON($this);
Expand Down
11 changes: 10 additions & 1 deletion class/task/saturnetask.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ public function getTaskProgressColorClass($progress)
*/
public function getNomUrl($withpicto = 0, $option = '', $mode = 'task', $addlabel = 0, $sep = ' - ', $notooltip = 0, $saveLastSearchValue = -1, $showFavorite = 0)
{
global $conf, $langs, $user;
global $action, $conf, $hookmanager, $langs, $user;

if ( ! empty($conf->dol_no_mouse_hover)) $notooltip = 1; // Force disable tooltips

Expand Down Expand Up @@ -236,6 +236,15 @@ public function getNomUrl($withpicto = 0, $option = '', $mode = 'task', $addlabe
$result .= $favoriteStar;
}

$hookmanager->initHooks(['saturnetaskdao']);
$parameters = ['id' => $this->id, 'getnomurl' => &$result];
$resHook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
if ($resHook > 0) {
$result = $hookmanager->resPrint;
} else {
$result .= $hookmanager->resPrint;
}

return $result;
}

Expand Down
2 changes: 1 addition & 1 deletion core/modules/modSaturne.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public function __construct($db)
$this->editor_url = 'https://evarisk.com/';

// Possible values for version are: 'development', 'experimental', 'dolibarr', 'dolibarr_deprecated' or a version string like 'x.y.z'
$this->version = '1.4.0';
$this->version = '1.5.0';

// Url to the file with your last numberversion of this module
//$this->url_last_version = 'http://www.example.com/versionmodule.txt';
Expand Down
12 changes: 6 additions & 6 deletions core/tpl/admin/object/object_document_model_view.tpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
if (in_array($name, $def)) {
print img_picto($langs->trans('Enabled'), 'switch_on');
} else {
print '<a class="reposition" href="' . $_SERVER['PHP_SELF'] . '?action=set&value=' . $name . '&const=' . $module->scandir . '&label=' . urlencode($module->name) . '&type=' . explode('_', $name)[0] . '&module_name=' . $moduleName . '&token=' . newToken() . '">';
print '<a class="reposition" href="' . $_SERVER['PHP_SELF'] . '?action=set&model_name=' . $name . '&const=' . $module->scandir . '&label=' . urlencode($module->name) . '&type=' . explode('_', $name)[0] . '&module_name=' . $moduleName . '&token=' . newToken() . '">';
print img_picto($langs->trans('Disabled'), 'switch_off');
print '</a>';
}
Expand All @@ -77,7 +77,7 @@
if ($conf->global->$defaultModelConf == $name) {
print img_picto($langs->trans('Default'), 'on');
} else {
print '<a class="reposition" href="' . $_SERVER['PHP_SELF'] . '?action=setdoc&value=' . $name .'&const=' . $module->scandir . '&label=' . urlencode($module->name) . '&type=' . explode('_', $name)[0] . '&module_name=' . $moduleName . '&token=' . newToken() . '">' . img_picto($langs->trans('Disabled'), 'off') . '</a>';
print '<a class="reposition" href="' . $_SERVER['PHP_SELF'] . '?action=setdoc&model_name=' . $name .'&const=' . $module->scandir . '&label=' . urlencode($module->name) . '&type=' . explode('_', $name)[0] . '&module_name=' . $moduleName . '&token=' . newToken() . '">' . img_picto($langs->trans('Disabled'), 'off') . '</a>';
}
print '</td>';

Expand All @@ -94,7 +94,7 @@
// Preview
print '<td class="center">';
if ($module->type == 'pdf') {
print '<a href="' . $_SERVER['PHP_SELF'] . '?action=specimen&module=' . $name . '&module_name=' . $moduleName . '">' . img_object($langs->trans('Preview'), 'pdf') . '</a>';
print '<a class="reposition" href="' . $_SERVER['PHP_SELF'] . '?action=specimen&model_name=' . $name . '&module_name=' . $moduleName . '&token=' . newToken() . '">' . img_object($langs->trans('Preview'), 'pdf') . '</a>';
} else {
print img_object($langs->trans('PreviewNotAvailable'), 'generic');
}
Expand All @@ -112,10 +112,10 @@
// Active
print '<td class="center">';
if (in_array($customName, $def)) {
print '<a href="' . $_SERVER['PHP_SELF'] . '?action=del&value=' . $customName . '&type=' . explode('_', $name)[0] . '&module_name=' . $moduleName . '&token=' . newToken() . '">';
print '<a class="reposition" href="' . $_SERVER['PHP_SELF'] . '?action=del&model_name=' . $customName . '&type=' . explode('_', $name)[0] . '&module_name=' . $moduleName . '&token=' . newToken() . '">';
print img_picto($langs->trans('Enabled'), 'switch_on');
} else {
print '<a href="' . $_SERVER['PHP_SELF'] . '?action=set&value=' . $customName . '&const=' . $module->custom_scandir . '&label=' . urlencode($module->custom_name) . '&type=' . explode('_', $name)[0] . '&module_name=' . $moduleName . '&token=' . newToken() . '">';
print '<a class="reposition" href="' . $_SERVER['PHP_SELF'] . '?action=set&model_name=' . $customName . '&const=' . $module->custom_scandir . '&label=' . urlencode($module->custom_name) . '&type=' . explode('_', $name)[0] . '&module_name=' . $moduleName . '&token=' . newToken() . '">';
print img_picto($langs->trans('Disabled'), 'switch_off');
}
print '</a>';
Expand All @@ -126,7 +126,7 @@
if ($conf->global->$defaultModelConf == $customName) {
print img_picto($langs->trans('Default'), 'on');
} else {
print '<a class="reposition" href="' . $_SERVER['PHP_SELF'] . '?action=setdoc&value=' . $customName .'&const=' . $module->custom_scandir . '&label=' . urlencode($module->custom_name) . '&type=' . explode('_', $name)[0] . '&module_name=' . $moduleName . '&token=' . newToken() . '">' . img_picto($langs->trans('Disabled'), 'off') . '</a>';
print '<a class="reposition" href="' . $_SERVER['PHP_SELF'] . '?action=setdoc&model_name=' . $customName .'&const=' . $module->custom_scandir . '&label=' . urlencode($module->custom_name) . '&type=' . explode('_', $name)[0] . '&module_name=' . $moduleName . '&token=' . newToken() . '">' . img_picto($langs->trans('Disabled'), 'off') . '</a>';
}
print '</td><td colspan=2></td></tr>';
}
Expand Down
27 changes: 15 additions & 12 deletions core/tpl/documents/documents_action.tpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,16 @@
}

if (GETPOST('forcebuilddoc')) {
$model = '';
$modelList = saturne_get_list_of_models($db, $object->element . 'document');
if (!empty($modelList)) {
asort($modelList);
$modelList = array_filter($modelList, 'saturne_remove_index');
if (is_array($modelList)) {
$models = array_keys($modelList);
$model = '';
$modelLists = saturne_get_list_of_models($db, $object->element . 'document');
if (is_array($modelLists) && !empty($modelLists)) {
asort($modelLists);
$modelLists = array_filter($modelLists, 'saturne_remove_index');
foreach ($modelLists as $key => $modelList) {
$confName = dol_strtoupper($moduleNameLowerCase . '_' . $document->element) . '_DEFAULT_MODEL';
if (strpos($key, getDolGlobalString($confName)) !== false) {
$model = str_replace($object->element . 'document_custom_odt', $object->element . 'document_odt', $key);
}
}
}
} else {
Expand All @@ -78,20 +81,20 @@
$constName = get_class($object) . '::STATUS_LOCKED';
$moreParams['specimen'] = defined($constName) && $object->status < $object::STATUS_LOCKED;

if (!empty($models) || !empty($model)) {
$parameters = ['models' => $models, 'model' => $model, 'outputlangs' => $outputLangs, 'hidedetails' => $hideDetails, 'hidedesc' => $hideDesc, 'hideref' => $hideRef, 'moreparams' => $moreParams];
if (!empty($model)) {
$parameters = ['model' => $model, 'outputlangs' => $outputLangs, 'hidedetails' => $hideDetails, 'hidedesc' => $hideDesc, 'hideref' => $hideRef, 'moreparams' => $moreParams];
$hookmanager->executeHooks('saturneBuildDoc', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks

$result = $document->generateDocument((!empty($models) ? $models[0] : $model), $outputLangs, $hideDetails, $hideDesc, $hideRef, $moreParams);
$result = $document->generateDocument($model, $outputLangs, $hideDetails, $hideDesc, $hideRef, $moreParams);
if ($result <= 0) {
setEventMessages($document->error, $document->errors, 'errors');
$action = '';
} else {
$documentType = explode('_odt', (!empty($models) ? $models[0] : $model));
$documentType = explode('_odt', $model);
if ($document->element != $documentType[0]) {
$document->element = $documentType[0];
}
setEventMessages($langs->trans('FileGenerated') . ' - ' . '<a href=' . DOL_URL_ROOT . '/document.php?modulepart='. $moduleNameLowerCase . '&file=' . urlencode($document->element . '/' . (dol_strlen($object->ref) > 0 ? $object->ref . '/' : '') . $document->last_main_doc) . '&entity=' . $conf->entity . '"' . '>' . $document->last_main_doc . '</a>', []);
setEventMessages($langs->trans('FileGenerated') . ' - ' . '<a href=' . DOL_URL_ROOT . '/document.php?modulepart=' . (!empty($moreParams['modulePart']) ? $moreParams['modulePart'] : $moduleNameLowerCase) . '&file=' . urlencode((empty($moreParams['modulePart']) ? $document->element . '/' : '') . (dol_strlen($object->ref) > 0 ? $object->ref . '/' : '') . $document->last_main_doc) . '&entity=' . $conf->entity . '"' . '>' . $document->last_main_doc . '</a>', []);
$urlToRedirect = $_SERVER['REQUEST_URI'];
$urlToRedirect = preg_replace('/#builddoc$/', '', $urlToRedirect);
$urlToRedirect = preg_replace('/action=builddoc&?/', '', $urlToRedirect); // To avoid infinite loop.
Expand Down
Loading

0 comments on commit 277a954

Please sign in to comment.