Skip to content

Commit

Permalink
Merge pull request #820 from Evarisk/develop
Browse files Browse the repository at this point in the history
1.2.1
  • Loading branch information
nicolas-eoxia authored Jan 19, 2024
2 parents ef08605 + 9c72f66 commit b0c328e
Show file tree
Hide file tree
Showing 43 changed files with 1,349 additions and 531 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@
## Informations

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

### Version

- Version : 1.2.0
- Compatibilité : Dolibarr 16.0.0 - 18.0.3
- Version : 1.2.1
- PHP : 7.4.33
- Compatibilité : Dolibarr 16.0.0 - 18.0.4

## Liens

Expand Down
2 changes: 1 addition & 1 deletion admin/documents.php
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@
saturne_header(0, '', $title, $help_url);

$parameters = [];
$reshook = $hookmanager->executeHooks('SaturneAdminDocumentData', $parameters); // Note that $action and $object may have been modified by some hooks
$reshook = $hookmanager->executeHooks('saturneAdminDocumentData', $parameters); // Note that $action and $object may have been modified by some hooks
if (empty($reshook)) {
$types = $hookmanager->resArray;
}
Expand Down
126 changes: 126 additions & 0 deletions admin/pwa.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
<?php
/* Copyright (C) 2022-2023 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
* 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/pwa.php
* \ingroup saturne
* \brief Progressive web apps page of module Saturne
*/

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

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

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

// Load Module Libraries
require_once __DIR__ . '/../../' . $moduleNameLowerCase . '/lib/' . $moduleNameLowerCase . '.lib.php';

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

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

// Initialize view objects
$form = new Form($db);

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

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

/*
* Actions
*/

if ($action == 'generate_QRCode') {
$urlToEncode = GETPOST('urlToEncode');

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

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

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

/*
* View
*/

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

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

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

// PWA QR Code generation
print load_fiche_titre($langs->transnoentities('PWAQRCodeGenerationManagement'), '', '');

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 '<table class="noborder centpercent">';
print '<tr class="liste_titre">';
print '<td>' . $langs->trans('Parameters') . '</td>';
print '<td>' . $langs->trans('Description') . '</td>';
print '<td class="center">' . $langs->trans('Value') . '</td>';
print '</tr>';

print '<tr class="oddeven"><td>' . $langs->trans('GeneratePWAQRCode') . '</td>';
print '<td>' . $langs->trans('GeneratePWAQRCodeDescription') . '</td>';
print '<td class="center">' . saturne_show_medias_linked($moduleNameLowerCase, $conf->$moduleNameLowerCase->multidir_output[$conf->entity] . '/pwa/qrcode/', 'small', 1, 0, 0, 0, 80, 80, 0, 0, 0, 'pwa/qrcode/', null, '', 0, 0, 0, 0, 'center') . '</td></tr>';

print '</table>';
print $form->buttonsSaveCancel('Generate', '');
print '</form>';

// Page end
print dol_get_fiche_end();
llxFooter();
$db->close();
133 changes: 131 additions & 2 deletions class/actions_saturne.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
* \brief Saturne hook overload.
*/

// Load Saturne Libraries
require_once __DIR__ . '/../../saturne/lib/object.lib.php';

/**
* Class ActionsSaturne
*/
Expand Down Expand Up @@ -210,8 +213,103 @@ public function printCommonFooter($parameters)

<?php
}
} elseif (preg_match('/categorycard/', $parameters['context']) && preg_match('/viewcat.php/', $_SERVER['PHP_SELF'])) {
$id = GETPOST('id');
$type = GETPOST('type');

// Temporary exclude DoliMeet and native Dolibarr objects
if ($type == 'meeting' || $type == 'audit' || $type == 'trainingsession' || !empty(saturne_get_objects_metadata($type))) {
return 0;
}

// Load variable for pagination
$limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
$sortfield = GETPOST('sortfield', 'aZ09comma');
$sortorder = GETPOST('sortorder', 'aZ09comma');
$page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
if (empty($page) || $page == -1) {
$page = 0;
} // If $page is not defined, or '' or -1 or if we click on clear filters or if we select empty mass action
$offset = $limit * $page;

$objects = saturne_fetch_all_object_type($type);
$objectArrays = [];
if (is_array($objects) && !empty($objects)) {
foreach ($objects as $object) {
$objectArrays[$object->id] = $object->ref;
}
}

$category = new Categorie($this->db);
$category->fetch($id);
$objectCategories = $category->getObjectsInCateg($type, 0, $limit, $offset);

$out = '<br>';

$out .= '<form method="post" action="' . $_SERVER['PHP_SELF'] . '?id=' . $id . '&type=' . $type . '">';
$out .= '<input type="hidden" name="token" value="' . newToken() . '">';
$out .= '<input type="hidden" name="action" value="addintocategory">';

$out .= '<table class="noborder centpercent">';
$out .= '<tr class="liste_titre"><td>';
$out .= $langs->trans('AddObjectIntoCategory') . ' ';
$out .= $form::selectarray('element_id', $objectArrays, '', 1);
$out .= '<input type="submit" class="button buttongen" value="' . $langs->trans('ClassifyInCategory') . '"></td>';
$out .= '</tr>';
$out .= '</table>';
$out .= '</form>';

$out .= '<br>';

if (is_array($objects) && !empty($objects)) {
$object = array_shift($objects);
$picto = $object->picto;
}

$out .= load_fiche_titre($langs->transnoentities(ucfirst($type)), '', 'object_' . $picto);
$out .= '<table class="noborder centpercent">';
$out .= '<tr class="liste_titre"><td colspan="3">' . $langs->trans('Ref') . '</td></tr>';

if (is_array($objectCategories) && !empty($objectCategories)) {
// Form to add record into a category
if (count($objectCategories) > 0) {
$i = 0;
foreach ($objectCategories as $object) {
$i++;
if ($i > $limit) break;

$out .= '<tr class="oddeven">';
$out .= '<td class="nowrap">';
$object->picto = $picto;
$object->element = $type;
$out .= $object->getNomUrl(1);
$out .= '</td>';
// Link to delete from category
$out .= '<td class="right">';
if ($user->rights->categorie->creer) {
$out .= '<a href="' . $_SERVER['PHP_SELF'] . '?action=delintocategory&id=' . $id . '&type=' . $type . '&element_id=' . $object->id . '&token=' . newToken() . '">';
$out .= $langs->trans('DeleteFromCat');
$out .= img_picto($langs->trans('DeleteFromCat'), 'unlink', '', false, 0, 0, '', 'paddingleft');
$out .= '</a>';
}
$out .= '</td>';
$out .= '</tr>';
}
} else {
$out .= '<tr class="oddeven"><td colspan="2" class="opacitymedium">' . $langs->trans('ThisCategoryHasNoItems') . '</td></tr>';
}
} else {
$out .= '<tr class="oddeven"><td colspan="2" class="opacitymedium">' . $langs->trans('ThisCategoryHasNoItems') . '</td></tr>';
}

$out .= '</table>'; ?>

<script>
jQuery('.fichecenter').last().after(<?php echo json_encode($out); ?>)
</script>
<?php
}

}
if (!$error) {
$this->results = array('myreturn' => 999);
return 0; // or return 1 to replace standard code
Expand Down Expand Up @@ -261,8 +359,39 @@ public function doActions(array $parameters, $object, string $action): int
}
}
}
} elseif (preg_match('/categorycard/', $parameters['context'])) {
global $langs;

}
$elementId = GETPOST('element_id');
$type = GETPOST('type');

// Temporary exclude DoliMeet and native Dolibarr objects
if ($type == 'meeting' || $type == 'audit' || $type == 'trainingsession' || !empty(saturne_get_objects_metadata($type))) {
return 0;
}

$objects = saturne_fetch_all_object_type($type);
$newObject = $objects[$elementId];

if (GETPOST('action') == 'addintocategory') {
$result = $object->add_type($newObject, $type);
if ($result >= 0) {
setEventMessages($langs->trans("WasAddedSuccessfully", $newObject->ref), array());
} else {
if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
setEventMessages($langs->trans("ObjectAlreadyLinkedToCategory"), array(), 'warnings');
} else {
setEventMessages($object->error, $object->errors, 'errors');
}
}
} elseif (GETPOST('action') == 'delintocategory') {
$result = $object->del_type($newObject, $type);
if ($result < 0) {
dol_print_error('', $object->error);
}
$action = '';
}
}
return 0;
}
}
7 changes: 3 additions & 4 deletions class/saturneobject.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,7 @@ public function getTriggerDescription(SaturneObject $object): string
{
global $conf, $db, $langs, $mysoc;

$langs->load('other');
saturne_load_langs(['other', 'companies']);

$user = new User($db);
$now = dol_now();
Expand All @@ -689,7 +689,7 @@ public function getTriggerDescription(SaturneObject $object): string
require_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php';
$societe = new Societe($db);
$societe->fetch($object->fk_soc);
$ret .= $langs->transnoentities('ThirdParty') . ' : ' . dol_strlen($societe->name) > 0 ? $societe->name : $langs->transnoentities('NoData') . '</br>';
$ret .= $langs->transnoentities('ThirdParty') . ' : ' . (dol_strlen($societe->name) > 0 ? $societe->name : $langs->transnoentities('NoData')) . '</br>';
}
if (array_key_exists('fk_project', $object->fields) && isModEnabled('project')) {
require_once DOL_DOCUMENT_ROOT . '/projet/class/project.class.php';
Expand All @@ -699,8 +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>' : '');

$ret .= (isset($object->status) && dol_strlen($object->status) > 0 && isset($object->fields['status']['arrayofkeyval'][$object->status]) ? $langs->transnoentities('Status') . ' : ' . $langs->transnoentities($object->fields['status']['arrayofkeyval'][$object->status]) . '<br>' : '');
return $ret;
}

Expand Down
4 changes: 2 additions & 2 deletions class/saturneschedules.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ class SaturneSchedules extends SaturneObject
public $date_creation;

/**
* @var int Timestamp
* @var int|string Timestamp
*/
public int $tms;
public $tms;

/**
* @var int Status
Expand Down
Loading

0 comments on commit b0c328e

Please sign in to comment.