From 50d4ab3596abf593c5189f50f0a4413bb032a89d Mon Sep 17 00:00:00 2001 From: Nicolas Domenech Date: Fri, 17 Jan 2025 17:11:54 +0100 Subject: [PATCH] #80 [PublicShortener] add: action assign_qrcode --- langs/fr_FR/easyurl.lang | 6 +- lib/easyurl_function.lib.php | 2 +- public/shortener/public_shortener.php | 91 ++++++++++++++++++++------- 3 files changed, 75 insertions(+), 24 deletions(-) diff --git a/langs/fr_FR/easyurl.lang b/langs/fr_FR/easyurl.lang index 5f4ef46..a363ffe 100644 --- a/langs/fr_FR/easyurl.lang +++ b/langs/fr_FR/easyurl.lang @@ -123,4 +123,8 @@ ShortUrl = URL raccourcie UrlType = Type d'URL # Public interface - Interface publique -AssignQRCode = Affectation de QR Code +AssignQRCode = Affectation de QR Code +NumProductLot = N° du lot/série +NumQRCode = N° du QRCode +AssignQRCodeSuccess = Affectation réussie du QRCode +AssignQRCodeErrors = Erreur : affectation du QRCode diff --git a/lib/easyurl_function.lib.php b/lib/easyurl_function.lib.php index 2633fe6..86d7dc6 100644 --- a/lib/easyurl_function.lib.php +++ b/lib/easyurl_function.lib.php @@ -200,7 +200,7 @@ function update_easy_url_link(CommonObject $object): int 'action' => 'update', 'signature' => $conf->global->EASYURL_SIGNATURE_TOKEN_YOURLS_API, 'format' => 'json', - 'shorturl' => $object->label, + 'shorturl' => $object->short_url, 'url' => $object->original_url ]); diff --git a/public/shortener/public_shortener.php b/public/shortener/public_shortener.php index f9e27a4..1bd6beb 100644 --- a/public/shortener/public_shortener.php +++ b/public/shortener/public_shortener.php @@ -56,7 +56,8 @@ require_once DOL_DOCUMENT_ROOT.'/product/stock/class/productlot.class.php'; // Load EasyURL libraries -require_once __DIR__ . '/../../../easyurl/class/shortener.class.php'; +require_once __DIR__ . '/../../class/shortener.class.php'; +require_once __DIR__ . '/../../lib/easyurl_function.lib.php'; // Global variables definitions global $conf, $db, $hookmanager, $langs; @@ -65,12 +66,13 @@ saturne_load_langs(); // Get parameters -$track_id = GETPOST('track_id', 'alpha'); -$entity = GETPOST('entity'); +$action = GETPOST('action', 'aZ09'); +$entity = GETPOST('entity'); // Initialize technical objects -$shortener = new Shortener($db); +$object = new Shortener($db); $productLot = new ProductLot($db); +$user = new User($db); $hookmanager->initHooks(['publicshortener', 'saturnepublicinterface']); // Note that conf->hooks_modules contains array @@ -80,14 +82,58 @@ $conf->setEntityValues($db, $entity); -// Load object +/* + * Actions + */ +$parameters = []; +$resHook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $project may have been modified by some hooks +if ($resHook < 0) { + setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); +} + +if (empty($resHook)) { + if ($action == 'assign_qrcode') { + $fkElementID = GETPOSTINT('fk_element'); + $shortenerID = GETPOSTINT('shortener'); + + $productLot->fetch($fkElementID); + $object->fetch($shortenerID); + + if ($productLot->id > 0 && $object->id > 0) { + $object->element_type = 'productlot'; + $object->fk_element = $productLot->id; + $object->status = Shortener::STATUS_ASSIGN; + $object->type = 0; // TODO : Changer ça pour mettre une vrai valeur du dico ? + + $publicControlInterfaceUrl = dol_buildpath('custom/digiquali/public/control/public_control_history.php?track_id=' . $productLot->array_options['options_control_history_link'] . '&entity=' . $conf->entity, 3); + $object->original_url = $publicControlInterfaceUrl; + + $result = update_easy_url_link($object); + if ($result > 0) { + $object->update($user); + + $productLot->array_options['options_easy_url_all_link'] = $object->short_url; + $productLot->updateExtraField('easy_url_all_link'); + + setEventMessages('AssignQRCodeSuccess', []); + } else { + setEventMessages('AssignQRCodeErrors', [], 'errors'); + } + } else { + setEventMessages('EasyURLNotAvailable', [], 'errors'); + } + + header('Location: ' . $_SERVER['PHP_SELF'] . '?entity=' . $entity); + exit; + } +} /* * View */ -$title = $langs->trans('PublicShortener'); +$title = $langs->trans('PublicInterfaceObject', $langs->transnoentities('OfAssignShortener')) . ''; $conf->dol_hide_topmenu = 1; $conf->dol_hide_leftmenu = 1; @@ -95,7 +141,8 @@ saturne_header(1, '', $title, '', '', 0, 0, [], [], '', 'page-public-card page-signature'); print '
'; -print ''; ?> +print ''; +print ''; ?>
@@ -108,31 +155,31 @@
id] = $productLot->batch; + $productLotArrays = []; + $productLots = saturne_fetch_all_object_type('ProductLot'); + if (is_array($productLots) && !empty($productLots)) { + foreach ($productLots as $productLot) { + $productLotArrays[$productLot->id] = $productLot->batch; + } } - } - print Form::selectarray('fk_element', $productLotArrays); + print Form::selectarray('fk_element', $productLotArrays, '', $langs->transnoentities('NumProductLot')); ?>
fetchAll('', '', 0, 0, ['customsql' => 't.status = ' . Shortener::STATUS_VALIDATED]); - if (is_array($shorteners) && !empty($shorteners)) { - foreach ($shorteners as $shortener) { - $shortenerArrays[$shortener->id] = $shortener->label; + $shortenerArrays = []; + $shorteners = $object->fetchAll('', '', 0, 0, ['customsql' => 't.status = ' . Shortener::STATUS_VALIDATED]); + if (is_array($shorteners) && !empty($shorteners)) { + foreach ($shorteners as $shortener) { + $shortenerArrays[$shortener->id] = $shortener->label; + } } - } - print Form::selectarray('label', $shortenerArrays); + print Form::selectarray('shortener', $shortenerArrays, '', $langs->transnoentities('NumQRCode')); ?>
- +