Skip to content

Commit

Permalink
#1045 [QRCode] fix: CRUD
Browse files Browse the repository at this point in the history
  • Loading branch information
theodaviddd committed Aug 6, 2024
1 parent 18a6991 commit a62fc6f
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 22 deletions.
88 changes: 69 additions & 19 deletions admin/qrcode.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,17 +69,41 @@

// Add a redirection
if ($action == 'add') {
if (dol_strlen($url) == 0) {
setEventMessage('URLToEncodeRequired', 'errors');
header('Location: ' . $_SERVER['PHP_SELF']);
exit;
}
$saturneQRCode->url = $url;
$saturneQRCode->encoded_qr_code = $saturneQRCode->getQRCodeBase64($url);
$saturneQRCode->module_name = 'saturne';
$saturneQRCode->status = 1;
$saturneQRCode->create($user);

setEventMessage('QRCodeCreated');
header('Location: ' . $_SERVER['PHP_SELF']);
exit;
}

if ($action == 'update') {
$saturneQRCode->fetch(GETPOST('id'));
$saturneQRCode->url = GETPOST('url');
$saturneQRCode->encoded_qr_code = $saturneQRCode->getQRCodeBase64($saturneQRCode->url);
$saturneQRCode->update($user);

setEventMessage('QRCodeUpdated');
header('Location: ' . $_SERVER['PHP_SELF']);
exit;
}

// Remove a redirection
if ($action == 'remove') {
$saturneQRCode->fetch(GETPOST('id'));
$saturneQRCode->delete($user, false, false);

setEventMessage('QRCodeRemoved');
header('Location: ' . $_SERVER['PHP_SELF']);
exit;
}

/*
Expand Down Expand Up @@ -120,29 +144,55 @@
print '<td>' . $langs->trans('URL') . '</td>';
print '<td class="center">' . $langs->trans('QR Code') . '</td>';
print '<td class="center">' . $langs->trans('ModuleName') . '</td>';
print '<td class="center">' . $langs->trans('Action') . '</td>';
print '<td class="center">' . $langs->trans('Actions') . '</td>';
print '</tr>';

if (is_array($QRCodes) && !empty($QRCodes)) {
foreach ($QRCodes as $QRCode) {
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="remove">';
print '<tr class="oddeven"><td>';
print $QRCode->url;
print '</td>';
print '<td class="right preview-qr-code">';
print '<input hidden class="qrcode-base64" value="'. $QRCode->encoded_qr_code .'">';
print img_picto($langs->trans("QRCodeGeneration"), 'fontawesome_fa-qrcode_fas_blue');
print ' ' . $form->textwithpicto('', $langs->trans('QRCodeGenerationTooltip'));
print '</td>';
print '</td><td class="center">';
print ucfirst($QRCode->module_name);
print '</td><td class="center">';
print '<input type="hidden" name="id" value="' . $QRCode->id . '">';
print '<input type="submit" class="button" value="' . $langs->trans('Remove') . '">';
print '</td></tr>';
print '</form>';
if ($action == 'edit' && $QRCode->id == GETPOST('id')) {
print '<tr class="oddeven" id="qrcode-'. $QRCode->id .'"><td>';
print '<form method="POST" action="' . $_SERVER['PHP_SELF'] . '">';
print '<input type="hidden" name="token" value="' . newToken() . '">';
print '<input type="hidden" name="action" value="update">';
print '<input type="hidden" name="id" value="' . $QRCode->id . '">';
print '<input type="text" class="minwidth500" name="url" value="' . $QRCode->url . '">';
print '</td><td class="center">';
print '</td><td class="center">';
print '</td><td class="center">';
print '<input hidden class="qrcode-base64" value="'. $QRCode->encoded_qr_code .'">';
print '<button type="submit" class="butAction">' . $langs->trans('Save') . '</button>';
print '</td></tr>';
print '</form>';
} else {
print '<tr class="oddeven"><td>';
print $QRCode->url;
print '</td>';
print '<td class="right preview-qr-code">';
print '<input hidden class="qrcode-base64" value="'. $QRCode->encoded_qr_code .'">';
print img_picto($langs->trans("QRCodeGeneration"), 'fontawesome_fa-qrcode_fas_blue');
print ' ' . $form->textwithpicto('', $langs->trans('QRCodeGenerationTooltip'));
print '</td>';
print '</td><td class="center">';
print ucfirst($QRCode->module_name);
print '</td><td class="center">';

// Modify this section to use anchor tags for edit and delete actions
print '<a href="' . $_SERVER['PHP_SELF'] . '?module_name=' . $moduleName . '&action=edit&id=' . $QRCode->id . '#qrcode-'. $QRCode->id .'" class="edit-button">';
print img_picto($langs->trans('Edit'), 'edit');
print '</a> ';
// Form for Remove action using a form with token and a styled submit button
print '<form method="POST" action="' . $_SERVER['PHP_SELF'] . '?module_name=' . $moduleName . '" style="display:inline;">';
print '<input type="hidden" name="token" value="' . newToken() . '">'; // Token for CSRF protection
print '<input type="hidden" name="action" value="remove">'; // Action to remove the QR code
print '<input type="hidden" name="id" value="' . $QRCode->id . '">'; // ID of the QR code to be removed
print '<button type="submit" class="" title="' . $langs->trans('Remove') . '">';
print '<i class="fas fa-trash-alt"></i>'; // Font Awesome icon for the delete action
print '</button>';
print '</form>';


print '</td></tr>';
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion class/saturneqrcode.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class SaturneQRCode extends SaturneObject
/**
* @var int Does object support extrafields ? 0 = No, 1 = Yes
*/
public $isextrafieldmanaged = 1;
public $isextrafieldmanaged = 0;

/**
* @var string Last output from end job execution
Expand Down
4 changes: 4 additions & 0 deletions langs/fr_FR/saturne.lang
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,10 @@ ExportData = Exporter mes données
QRCode = QR Code
URLToEncode = URL à encoder
HowToUseURLToEncode = Ecrivez l'URL vers laquelle le QR Code doit pointer
QRCodeCreated = QR Code créé
QRCodeUpdated = QR Code mis à jour
QRCodeRemoved = QR Code supprimé
URLToEncodeRequired = L'URL à encoder est obligatoire


#
Expand Down
2 changes: 1 addition & 1 deletion lib/documents.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ function saturne_show_documents(string $modulepart, $modulesubdir, $filedir, str
if (is_array($documentQRCode) && !empty($documentQRCode)) {
$documentQRCode = array_shift($documentQRCode);
} else {
$QRCode->url = $documenturl . '?modulepart=' . $modulepart . '&amp;file=' . urlencode($relativepath) . ($param ? '&' . $param : '');
$QRCode->url = DOL_URL_ROOT . '/document.php?modulepart=' . $modulepart . '&amp;file=' . urlencode($relativepath) . ($param ? '&' . $param : '');
$QRCode->encoded_qr_code = $QRCode->getQRCodeBase64($QRCode->url);
$QRCode->status = 1;
$QRCode->module_name = $modulepart;
Expand Down
2 changes: 1 addition & 1 deletion lib/saturne.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ function saturne_admin_prepare_head(): array
$head[$h][2] = 'information';
$h++;

$head[$h][0] = dol_buildpath('/saturne/admin/qrcode.php', 1) . '?filename=saturne_dev&tab_name=qrcode';
$head[$h][0] = dol_buildpath('/saturne/admin/qrcode.php', 1);
$head[$h][1] = '<i class="fas fa-qrcode pictofixedwidth"></i>' . $langs->trans('QRCode');
$head[$h][2] = 'qrcode';
$h++;
Expand Down

0 comments on commit a62fc6f

Please sign in to comment.