Skip to content

Commit

Permalink
Evarisk#4053 [PublicInterface] fix: display logo according to society
Browse files Browse the repository at this point in the history
  • Loading branch information
evarisk-micka committed Jul 25, 2024
1 parent 105ead0 commit 77e42d1
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 292 deletions.
283 changes: 0 additions & 283 deletions lib/digiriskdolibarr_function.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -555,289 +555,6 @@ function show_category_image($object, $upload_dir, $noprint = 0)
}
}

/**
* Show header for public page ticket
*
* @param string $title Title
* @param string $head Head array
* @param int $disablejs More content into html header
* @param int $disablehead More content into html header
* @param array $arrayofjs Array of complementary js files
* @param array $arrayofcss Array of complementary css files
* @return void
*/
function digiriskdolibarr_ticket_header($title, $head = "", $disablejs = 0, $disablehead = 0,$arrayofjs = array(), $arrayofcss = array())
{
global $conf, $mysoc;

require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php';

top_htmlhead($head, $title, $disablejs, $disablehead, $arrayofjs, $arrayofcss, 0, 1); // Show html headers

if (!empty($conf->global->DIGIRISKDOLIBARR_TICKET_SHOW_COMPANY_LOGO)) {
$urllogo = DOL_URL_ROOT . '/viewimage.php?modulepart=mycompany&entity=' . $conf->entity . '&file=' . urlencode('/logos/thumbs/'.$mysoc->logo_small);

// Output html code for logo
if ($urllogo) {
print '<div class="center signature-logo">';
print '<img src="' . $urllogo . '">';
print '</div>';
}
print '<div class="underbanner clearboth"></div>';
}
}

/**
* @param $sdir
* @param string $size
* @param int $maxHeight
* @param int $maxWidth
* @return string
*/
function digirisk_show_medias($sdir, $size = '', $maxHeight = 80, $maxWidth = 80)
{
global $conf, $langs;

include_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php';
include_once DOL_DOCUMENT_ROOT . '/core/lib/images.lib.php';

$sortfield = 'date';
$sortorder = 'desc';
$dir = $sdir . '/';

$return = '<!-- Photo -->' . "\n";
$nbphoto = 0;

$filearray = dol_dir_list($dir, "files", 0, '', '(\.meta|_preview.*\.png)$', $sortfield, SORT_DESC, 1);
$j = 0;

if (count($filearray)) {
print '<div class="wpeo-gridlayout grid-4 grid-gap-3 grid-margin-2 ecm-photo-list ecm-photo-list">';
if ($sortfield && $sortorder) {
$filearray = dol_sort_array($filearray, $sortfield, $sortorder);
}
foreach ($filearray as $key => $val) {
if (preg_match('/' . $size . '/', $val['name'])) {
$file = $val['name'];

if (image_format_supported($file) >= 0) {
$nbphoto++;

if ($size == 'small') { // Format vignette
$relativepath = 'digiriskdolibarr/medias/thumbs';
$modulepart = 'ecm';
$path = DOL_URL_ROOT . '/document.php?modulepart=' . $modulepart . '&attachment=0&file=' . str_replace('/', '%2F', $relativepath);
?>

<div class="center clickable-photo clickable-photo<?php echo $j; ?>" value="<?php echo $j; ?>" element="risk-evaluation">
<figure class="photo-image">
<?php
$urladvanced = getAdvancedPreviewUrl($modulepart, 'digiriskdolibarr/medias/' . preg_replace('/_' . $size . '/', '', $val['relativename']), 0, 'entity=' . $conf->entity); ?>
<a class="clicked-photo-preview" href="<?php echo $urladvanced; ?>">
<div class="wpeo-button button-square-30 button-transparent wpeo-tooltip-event" aria-label="<?php echo $langs->trans('Preview'); ?>">
<i class="fas fa-search-plus"></i>
</div>
</a>
<?php if (image_format_supported($val['name']) >= 0) : ?>
<?php $fullpath = $path . '/' . urlencode($val['relativename']) . '&entity=' . $conf->entity; ?>
<input class="filename" type="hidden" value="<?php echo preg_replace('/_' . $size . '/', '', $val['name']) ?>">
<img class="photo photo<?php echo $j ?>" height="<?php echo $maxHeight; ?>" width="<?php echo $maxWidth; ?>" src="<?php echo $fullpath; ?>">
<?php endif; ?>
</figure>
<div class="title"><?php echo preg_replace('/_' . $size . '/', '', $val['name']); ?></div>
</div><?php
$j++;
}
}
}
}
print '</div>';
} else {
// Display media library is empty if no media uploaded
if (!is_array($_FILES['userfile']['tmp_name'])) {
print($langs->trans("EmptyMediaLibrary"));
}
}

return $return;
}

/**
* Show photos of an object (nbmax maximum), into several columns
*
* @param string $modulepart 'product', 'ticket', ...
* @param string $sdir Directory to scan (full absolute path)
* @param string $size 0=original size, 1='small' use thumbnail if possible
* @param int $nbmax Nombre maximum de photos (0=pas de max)
* @param int $nbbyrow Number of image per line or -1 to use div. Used only if size=1.
* @param int $showfilename 1=Show filename
* @param int $showaction 1=Show icon with action links (resize, delete)
* @param int $maxHeight Max height of original image when size='small' (so we can use original even if small requested). If 0, always use 'small' thumb image.
* @param int $maxWidth Max width of original image when size='small'
* @param int $nolink Do not add a href link to view enlarged imaged into a new tab
* @param int $notitle Do not add title tag on image
* @param int $usesharelink Use the public shared link of image (if not available, the 'nophoto' image will be shown instead)
* @param string $subdir Subdirectory to scan
* @param object $object Object element
* @return string Html code to show photo. Number of photos shown is saved in this->nbphoto
*/
function digirisk_show_medias_linked($modulepart, $sdir, $size = '', $nbmax = 0, $nbbyrow = 5, $showfilename = 0, $showaction = 0, $maxHeight = 120, $maxWidth = 160, $nolink = 0, $notitle = 0, $usesharelink = 0, $subdir = "", $object = null)
{
global $conf, $langs;

include_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php';
include_once DOL_DOCUMENT_ROOT . '/core/lib/images.lib.php';

$sortfield = 'position_name';
$sortorder = 'desc';

$dir = $sdir . '/' . $object->ref . '/';
$pdir = $subdir . '/' . $object->ref . '/';

// Defined relative dir to DOL_DATA_ROOT
if ($dir) {
$relativedir = preg_replace('/^' . preg_quote(DOL_DATA_ROOT, '/') . '/', '', $dir);
$relativedir = preg_replace('/^[\\/]/', '', $relativedir);
preg_replace('/[\\/]$/', '', $relativedir);
}

$dirthumb = $dir . 'thumbs/';
$pdirthumb = $pdir . 'thumbs/';

$return = '<!-- Photo -->' . "\n";
$nbphoto = 0;

$filearray = dol_dir_list($dir, "files", 0, '', '(\.meta|_preview.*\.png)$', $sortfield, SORT_DESC, 1);
if (count($filearray)) {
if ($sortfield && $sortorder) {
$filearray = dol_sort_array($filearray, $sortfield, $sortorder);
}
$return .= '<div class=" wpeo-gridlayout grid-4 grid-gap-3 grid-margin-2 valigntop center centpercent" style="height:50%; border: 0; padding: 2px; border-spacing: 2px; border-collapse: separate;">';

foreach ($filearray as $key => $val) {
$return .= '<div class="media-container">';
$photo = '';
$file = $val['name'];

//if (! utf8_check($file)) $file=utf8_encode($file); // To be sure file is stored in UTF8 in memory

//if (dol_is_file($dir.$file) && image_format_supported($file) >= 0)
if (image_format_supported($file) >= 0) {
$nbphoto++;
$photo = $file;
$viewfilename = $file;

if ($size == 1 || $size == 'small') { // Format vignette
// Find name of thumb file
$photo_vignette = basename(getImageFileNameForSize($dir . $file, '_small'));
if ( ! dol_is_file($dirthumb . $photo_vignette)) $photo_vignette = '';

// Get filesize of original file
$imgarray = dol_getImageSize($dir . $photo);

if ($nbbyrow > 0) {
if ($nbphoto == 1) $return .= '<table class="valigntop center centpercent" style="border: 0; padding: 2px; border-spacing: 2px; border-collapse: separate;">';

if ($nbphoto % $nbbyrow == 1) $return .= '<tr class="center valignmiddle" style="border: 1px">';
$return .= '<td style="width: ' . ceil(100 / $nbbyrow) . '%" class="photo">';
} elseif ($nbbyrow < 0) $return .= '<div class="inline-block">';

$return .= "\n";

$relativefile = preg_replace('/^\//', '', $pdir . $photo);
if (empty($nolink)) {
$urladvanced = getAdvancedPreviewUrl($modulepart, $relativefile, 0, 'entity=' . $conf->entity);
if ($urladvanced) $return .= '<a href="' . $urladvanced . '">';
else $return .= '<a href="' . DOL_URL_ROOT . '/viewimage.php?modulepart=' . $modulepart . '&entity=' . $conf->entity . '&file=' . urlencode($pdir . $photo) . '" class="aphoto" target="_blank">';
}

// Show image (width height=$maxHeight)
// Si fichier vignette disponible et image source trop grande, on utilise la vignette, sinon on utilise photo origine
$alt = $langs->transnoentitiesnoconv('File') . ': ' . $relativefile;
$alt .= ' - ' . $langs->transnoentitiesnoconv('Size') . ': ' . $imgarray['width'] . 'x' . $imgarray['height'];
if ($notitle) $alt = '';
if ($usesharelink) {
if ($val['share']) {
if (empty($maxHeight) || $photo_vignette && $imgarray['height'] > $maxHeight) {
$return .= '<!-- Show original file (thumb not yet available with shared links) -->';
$return .= '<img width="65" height="65" class="photo photowithmargin clicked-photo-preview" height="' . $maxHeight . '" src="' . DOL_URL_ROOT . '/viewimage.php?hashp=' . urlencode($val['share']) . '" title="' . dol_escape_htmltag($alt) . '">';
} else {
$return .= '<!-- Show original file -->';
$return .= '<img width="65" height="65" class="photo photowithmargin clicked-photo-preview" height="' . $maxHeight . '" src="' . DOL_URL_ROOT . '/viewimage.php?hashp=' . urlencode($val['share']) . '" title="' . dol_escape_htmltag($alt) . '">';
}
} else {
$return .= '<!-- Show nophoto file (because file is not shared) -->';
$return .= '<img width="65" height="65" class="photo photowithmargin" height="' . $maxHeight . '" src="' . DOL_URL_ROOT . '/public/theme/common/nophoto.png" title="' . dol_escape_htmltag($alt) . '">';
}
} elseif (empty($maxHeight) || $photo_vignette && $imgarray['height'] > $maxHeight) {
$return .= '<!-- Show thumb -->';
$return .= '<img width="' . $maxWidth . '" height="' . $maxHeight . '" class="photo clicked-photo-preview" src="' . DOL_URL_ROOT . '/viewimage.php?modulepart=' . $modulepart . '&entity=' . $conf->entity . '&file=' . urlencode($pdirthumb . $photo_vignette) . '" title="' . dol_escape_htmltag($alt) . '">';
} else {
$return .= '<!-- Show original file -->';
$return .= '<img width="' . $maxWidth . '" height="' . $maxHeight . '" class="photo photowithmargin clicked-photo-preview" height="' . $maxHeight . '" src="' . DOL_URL_ROOT . '/viewimage.php?modulepart=' . $modulepart . '&entity=' . $conf->entity . '&file=' . urlencode($pdir . $photo) . '" title="' . dol_escape_htmltag($alt) . '">';
}

if (empty($nolink)) $return .= '</a>';
$return .= "\n";
if ($showfilename) $return .= '<br>' . $viewfilename;
if ($showaction) {
$return .= '<br>';
// On propose la generation de la vignette si elle n'existe pas et si la taille est superieure aux limites
if ($photo_vignette && (image_format_supported($photo) > 0) && ($object->imgWidth > $maxWidth || $object->imgHeight > $maxHeight)) {
$return .= '<a href="' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . '&amp;action=addthumb&amp;file=' . urlencode($pdir . $viewfilename) . '">' . img_picto($langs->trans('GenerateThumb'), 'refresh') . '&nbsp;&nbsp;</a>';
}
}
$return .= "\n";

if ($nbbyrow > 0) {
$return .= '</td>';
if (($nbphoto % $nbbyrow) == 0) $return .= '</tr>';
} elseif ($nbbyrow < 0) $return .= '</div>';
}

if (empty($size)) { // Format origine
$return .= '<img class="photo photowithmargin" src="' . DOL_URL_ROOT . '/viewimage.php?modulepart=' . $modulepart . '&entity=' . $conf->entity . '&file=' . urlencode($pdir . $photo) . '">';

if ($showfilename) $return .= '<br>' . $viewfilename;
}

// On continue ou on arrete de boucler ?
if ($nbmax && $nbphoto >= $nbmax) break;
}
$return .= '<div>
<div class="wpeo-button button-square-50 button-blue media-gallery-favorite" value="' . $object->id . '">
<input class="element-linked-id" type="hidden" value="' . ($object->id > 0 ? $object->id : 0) . '">
<input class="filename" type="hidden" value="' . $photo . '">
<i class="' . (GETPOST('favorite') == $photo ? 'fas' : ($object->photo == $photo ? 'fas' : 'far')) . ' fa-star button-icon"></i>
</div>
<div class="wpeo-button button-square-50 button-grey media-gallery-unlink" value="' . $object->id . '">
<input class="element-linked-id" type="hidden" value="' . ($object->id > 0 ? $object->id : 0) . '">
<input class="filename" type="hidden" value="' . $photo . '">
<i class="fas fa-unlink button-icon"></i>
</div></div></div>';
}
$return .= "</div>\n";

if ($size == 1 || $size == 'small') {
if ($nbbyrow > 0) {
// Ferme tableau
while ($nbphoto % $nbbyrow) {
$return .= '<td style="width: ' . ceil(100 / $nbbyrow) . '%">&nbsp;</td>';
$nbphoto++;
}

if ($nbphoto) $return .= '</table>';
}
}
} else {
print $langs->trans('NoMediaLinked');
}
if (is_object($object)) {
$object->nbphoto = $nbphoto;
}
return $return;
}

/**
* Load list of objects in memory from the database.
*
Expand Down
31 changes: 22 additions & 9 deletions public/ticket/create_ticket.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@

require_once __DIR__ . '/../../../saturne/lib/saturne_functions.lib.php';

global $conf, $db, $hookmanager, $langs, $mc, $user;
global $conf, $db, $hookmanager, $langs, $mc, $mysoc, $user;

// Load translation files required by the page
saturne_load_langs(['companies', 'other', 'mails', 'ticket']);
Expand Down Expand Up @@ -97,6 +97,7 @@
}

$conf->setEntityValues($db, $entity);
$mysoc->setMysoc($conf);

//ici charger les conf de la bonne entité
$upload_dir = $conf->categorie->multidir_output[isset($entity) ? $entity : 1];
Expand Down Expand Up @@ -253,10 +254,10 @@
$subCategoryCat->add_type($object, Categorie::TYPE_TICKET);

//Add files linked
$ticket_upload_dir = $conf->digiriskdolibarr->multidir_output[isset($conf->entity) ? $conf->entity : 1] . '/temp';
$ticket_upload_dir = $conf->digiriskdolibarr->multidir_output[isset($entity) ? $entity : 1] . '/temp';
$fileList = dol_dir_list($ticket_upload_dir . '/ticket/' . $ticketTmpId . '/');
$thumbsList = dol_dir_list($ticket_upload_dir . '/ticket/' . $ticketTmpId . '/thumbs/');
$ticketDirPath = $conf->ticket->multidir_output[isset($conf->entity) ? $conf->entity : 1] . '/';
$ticketDirPath = $conf->ticket->multidir_output[isset($entity) ? $entity : 1] . '/';
$fullTicketPath = $ticketDirPath . $object->ref . '/';
$thumbsTicketPath = $ticketDirPath . $object->ref . '/thumbs/';

Expand Down Expand Up @@ -302,7 +303,7 @@
if ($action == 'sendfile') {
include_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php';

$ticket_upload_dir = $conf->digiriskdolibarr->multidir_output[isset($conf->entity) ? $conf->entity : 1] . '/temp';
$ticket_upload_dir = $conf->digiriskdolibarr->multidir_output[isset($entity) ? $entity : 1] . '/temp';
if ( ! is_dir($ticket_upload_dir)) {
dol_mkdir($ticket_upload_dir);
}
Expand Down Expand Up @@ -348,9 +349,9 @@
include_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php';
$filetodelete = GETPOST('filetodelete');

$ticket_upload_dir = $conf->digiriskdolibarr->multidir_output[isset($conf->entity) ? $conf->entity : 1] . '/temp';
$ticket_upload_dir = $conf->digiriskdolibarr->multidir_output[isset($entity) ? $entity : 1] . '/temp';
//Add files linked
$ticket_upload_dir = $conf->digiriskdolibarr->multidir_output[isset($conf->entity) ? $conf->entity : 1] . '/temp/ticket/' . $ticketTmpId . '/';
$ticket_upload_dir = $conf->digiriskdolibarr->multidir_output[isset($entity) ? $entity : 1] . '/temp/ticket/' . $ticketTmpId . '/';
$fileList = dol_dir_list($ticket_upload_dir);

if (is_file($ticket_upload_dir . $filetodelete)) {
Expand Down Expand Up @@ -381,7 +382,19 @@
$arrayofjs = array("/digiriskdolibarr/js/digiriskdolibarr.min.js", "/saturne/js/saturne.min.js");
$arrayofcss = array('/opensurvey/css/style.css', '/ticket/css/styles.css.php', "/digiriskdolibarr/css/digiriskdolibarr.css", "/saturne/css/saturne.css");

digiriskdolibarr_ticket_header($langs->trans("CreateTicket"), "", 0, 0, $arrayofjs, $arrayofcss);
top_htmlhead('', $langs->trans("CreateTicket"), 0, 0, $arrayofjs, $arrayofcss, 0, 1); // Show html headers

if (!empty($conf->global->DIGIRISKDOLIBARR_TICKET_SHOW_COMPANY_LOGO)) {
$urllogo = DOL_URL_ROOT . '/viewimage.php?modulepart=mycompany&entity=' . $entity . '&file=' . urlencode('/logos/thumbs/'.$mysoc->logo_small);

// Output html code for logo
if ($urllogo) {
print '<div class="center signature-logo">';
print '<img src="' . $urllogo . '">';
print '</div>';
}
print '<div class="underbanner clearboth"></div>';
}

if ($entity > 0) {
if ( ! $conf->global->DIGIRISKDOLIBARR_TICKET_ENABLE_PUBLIC_INTERFACE) {
Expand Down Expand Up @@ -495,15 +508,15 @@

<div id="sendFileForm">
<div id="fileLinkedTable" class="tableforinputfields">
<?php $fileLinkedList = dol_dir_list($conf->digiriskdolibarr->multidir_output[isset($conf->entity) ? $conf->entity : 1] . '/temp/ticket/' . $ticketTmpId . '/thumbs/'); ?>
<?php $fileLinkedList = dol_dir_list($conf->digiriskdolibarr->multidir_output[isset($entity) ? $entity : 1] . '/temp/ticket/' . $ticketTmpId . '/thumbs/'); ?>
<div class="wpeo-table table-flex table-3 files-uploaded">
<?php
if ( ! empty($fileLinkedList)) {
foreach ($fileLinkedList as $fileLinked) {
if (preg_match('/mini/', $fileLinked['name'])) { ?>
<div class="table-row">
<div class="table-cell table-50 table-padding-0">
<?php print '<img class="photo" width="' . $maxHeight . '" src="' . DOL_URL_ROOT . '/viewimage.php?modulepart=digiriskdolibarr&entity=' . $conf->entity . '&file=' . urlencode('/temp/ticket/' . $ticketTmpId . '/thumbs/' . $fileLinked['name']) . '" title="' . dol_escape_htmltag($alt) . '">'; ?>
<?php print '<img class="photo" width="' . $maxHeight . '" src="' . DOL_URL_ROOT . '/viewimage.php?modulepart=digiriskdolibarr&entity=' . $entity . '&file=' . urlencode('/temp/ticket/' . $ticketTmpId . '/thumbs/' . $fileLinked['name']) . '" title="' . dol_escape_htmltag($alt) . '">'; ?>
</div>
<div class="table-cell">
<?php print preg_replace('/_mini/', '', $fileLinked['name']); ?>
Expand Down

0 comments on commit 77e42d1

Please sign in to comment.