From 771cdd2e4f470a05c85359b0f853ed32cbadf81a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20David?= Date: Wed, 21 Dec 2022 17:41:00 +0100 Subject: [PATCH 001/170] #595 [Question] add: framework interaction for media library --- core/modules/modDoliSMQ.class.php | 4 ++-- view/question/question_card.php | 21 +++------------------ 2 files changed, 5 insertions(+), 20 deletions(-) diff --git a/core/modules/modDoliSMQ.class.php b/core/modules/modDoliSMQ.class.php index 37617bed..1bdeeb0d 100644 --- a/core/modules/modDoliSMQ.class.php +++ b/core/modules/modDoliSMQ.class.php @@ -136,7 +136,7 @@ public function __construct($db) // A condition to hide module $this->hidden = false; // List of module class names as string that must be enabled if this module is enabled. Example: array('always1'=>'modModuleToEnable1','always2'=>'modModuleToEnable2', 'FR1'=>'modModuleToEnableFR'...) - $this->depends = ['modFckeditor', 'modProduct', 'modProductBatch', 'modAgenda', 'modECM', 'modProjet', 'modCategorie']; + $this->depends = ['modFckeditor', 'modProduct', 'modProductBatch', 'modAgenda', 'modECM', 'modProjet', 'modCategorie', 'modSaturne']; $this->requiredby = []; // List of module class names as string to disable if this one is disabled. Example: array('modModuleToDisable1', ...) $this->conflictwith = []; // List of module class names as string this module is in conflict with. Example: array('modModuleToDisable1', ...) @@ -217,7 +217,7 @@ public function __construct($db) // Array to add new pages in new tabs $this->tabs = []; $pictopath = dol_buildpath('/custom/dolismq/img/dolismq_color.png', 1); - $pictoDoliSMQ = img_picto('', $pictopath, '', 1, 0, 0, '', 'pictoDoliSMQ'); + $pictoDoliSMQ = img_picto('', $pictopath, '', 1, 0, 0, '', 'pictoSaturne'); $this->tabs[] = ['data' => 'productlot:+control:' . $pictoDoliSMQ . $langs->trans('Controls') . ':dolismq@dolismq:$user->rights->dolismq->control->read:/custom/dolismq/view/control/control_list.php?fromid=__ID__&fromtype=productbatch']; $this->tabs[] = ['data' => 'product:+control:' . $pictoDoliSMQ . $langs->trans('Controls') . ':dolismq@dolismq:$user->rights->dolismq->control->read:/custom/dolismq/view/control/control_list.php?fromid=__ID__&fromtype=product']; $this->tabs[] = ['data' => 'project:+control:' . $pictoDoliSMQ . $langs->trans('Controls') . ':dolismq@dolismq:$user->rights->dolismq->control->read:/custom/dolismq/view/control/control_list.php?fromid=__ID__&fromtype=project']; diff --git a/view/question/question_card.php b/view/question/question_card.php index 133facc0..862ee88d 100644 --- a/view/question/question_card.php +++ b/view/question/question_card.php @@ -22,20 +22,7 @@ */ // Load Dolibarr environment -$res = 0; -// Try main.inc.php into web root known defined into CONTEXT_DOCUMENT_ROOT (not always defined) -if (!$res && !empty($_SERVER["CONTEXT_DOCUMENT_ROOT"])) $res = @include $_SERVER["CONTEXT_DOCUMENT_ROOT"]."/main.inc.php"; -// Try main.inc.php into web root detected using web root calculated from SCRIPT_FILENAME -$tmp = empty($_SERVER['SCRIPT_FILENAME']) ? '' : $_SERVER['SCRIPT_FILENAME']; $tmp2 = realpath(__FILE__); $i = strlen($tmp) - 1; $j = strlen($tmp2) - 1; -while ($i > 0 && $j > 0 && isset($tmp[$i]) && isset($tmp2[$j]) && $tmp[$i] == $tmp2[$j]) { $i--; $j--; } -if (!$res && $i > 0 && file_exists(substr($tmp, 0, ($i + 1))."/main.inc.php")) $res = @include substr($tmp, 0, ($i + 1))."/main.inc.php"; -if (!$res && $i > 0 && file_exists(dirname(substr($tmp, 0, ($i + 1)))."/main.inc.php")) $res = @include dirname(substr($tmp, 0, ($i + 1)))."/main.inc.php"; -// Try main.inc.php using relative path -if (!$res && file_exists("../main.inc.php")) $res = @include "../main.inc.php"; -if (!$res && file_exists("../../main.inc.php")) $res = @include "../../main.inc.php"; -if (!$res && file_exists("../../../main.inc.php")) $res = @include "../../../main.inc.php"; -if ( ! $res && file_exists("../../../../main.inc.php")) $res = @include "../../../../main.inc.php"; -if (!$res) die("Include of main fails"); +if (file_exists("../../../saturne/saturne.main.inc.php")) $res = @include "../../../saturne/saturne.main.inc.php"; // Libraries require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php'; @@ -54,7 +41,7 @@ require_once '../../lib/dolismq_function.lib.php'; // Global variables definitions -global $conf, $db, $hookmanager, $langs, $user; +global $conf, $db, $hookmanager, $langs, $user, $langs; // Load translation files required by the page $langs->loadLangs(array("dolismq@dolismq", "other")); @@ -498,7 +485,7 @@ $morejs = array("/dolismq/js/dolismq.js"); $morecss = array("/dolismq/css/dolismq.css"); -llxHeader('', $title, $help_url, '', '', '', $morejs, $morecss); +saturneHeader('dolismq','', $title, $help_url, '', '', '', $morejs, $morecss); // Part to create if ($action == 'create') { @@ -609,8 +596,6 @@ dol_set_focus('input[name="label"]'); } -include DOL_DOCUMENT_ROOT . '/custom/dolismq/core/tpl/dolismq_medias_gallery_modal.tpl.php'; - // Part to edit record if (($id || $ref) && $action == 'edit') { print load_fiche_titre($langs->trans("ModifyQuestion"), '', $object->picto); From 25aa873413d7e1c93c402fc6b9e47fd27bcd3de5 Mon Sep 17 00:00:00 2001 From: David Date: Mon, 26 Dec 2022 18:03:11 +0100 Subject: [PATCH 002/170] #595 [Control] add: framework interaction for media gallery --- js/dolismq.js | 836 ++++++++++++++++---------------- view/control/control_card.php | 103 +--- view/question/question_card.php | 83 +--- 3 files changed, 445 insertions(+), 577 deletions(-) diff --git a/js/dolismq.js b/js/dolismq.js index d3a0602b..e1ad4dae 100644 --- a/js/dolismq.js +++ b/js/dolismq.js @@ -177,7 +177,9 @@ window.eoxiaJS.modal.openModal = function ( event ) { if ($(this).hasClass('open-media-gallery')) { $('#media_gallery').addClass('modal-active'); $('#media_gallery').attr('value', idSelected); - $('#media_gallery').find('.type-from').attr('value', $(this).find('.type-from').val()); + $('#media_gallery').find('.from-id').attr('value', $(this).find('.from-id').val()); + $('#media_gallery').find('.from-type').attr('value', $(this).find('.from-type').val()); + $('#media_gallery').find('.from-subtype').attr('value', $(this).find('.from-subtype').val()); $('#media_gallery').find('.wpeo-button').attr('value', idSelected); } @@ -217,422 +219,422 @@ window.eoxiaJS.modal.closeModal = function ( event ) { window.eoxiaJS.modal.refreshModal = function ( event ) { window.location.reload(); }; - -/** - * Initialise l'objet "mediaGallery" ainsi que la méthode "init" obligatoire pour la bibliothèque EoxiaJS. - * - * @since 1.0.0 - * @version 8.2.0 - */ -window.eoxiaJS.mediaGallery = {}; - -/** - * La méthode appelée automatiquement par la bibliothèque EoxiaJS. - * - * @since 1.0.0 - * @version 8.2.0 - * - * @return {void} - */ -window.eoxiaJS.mediaGallery.init = function() { - window.eoxiaJS.mediaGallery.event(); -}; - -/** - * La méthode contenant tous les événements pour le mediaGallery. - * - * @since 1.0.0 - * @version 1.0.0 - * - * @return {void} - */ -window.eoxiaJS.mediaGallery.event = function() { - // Photos - $( document ).on( 'click', '.clickable-photo', window.eoxiaJS.mediaGallery.selectPhoto ); - $( document ).on( 'click', '.save-photo', window.eoxiaJS.mediaGallery.savePhoto ); - $( document ).on( 'change', '.flat.minwidth400.maxwidth200onsmartphone', window.eoxiaJS.mediaGallery.sendPhoto ); - $( document ).on( 'click', '.clicked-photo-preview', window.eoxiaJS.mediaGallery.previewPhoto ); - $( document ).on( 'input', '.form-element #search_in_gallery', window.eoxiaJS.mediaGallery.handleSearch ); - $( document ).on( 'click', '.media-gallery-unlink', window.eoxiaJS.mediaGallery.unlinkFile ); - $( document ).on( 'click', '.media-gallery-favorite', window.eoxiaJS.mediaGallery.addToFavorite ); - $( document ).on( 'submit', '#fast-upload-photo-ok', window.eoxiaJS.mediaGallery.fastUpload ); - $( document ).on( 'click', '.selected-page', window.eoxiaJS.mediaGallery.selectPage ); -} - -/** - * Select photo. - * - * @since 8.2.0 - * @version 8.2.0 - * - * @return {void} - */ -window.eoxiaJS.mediaGallery.selectPhoto = function( event ) { - let photoID = $(this).attr('value'); - let parent = $(this).closest('.modal-content') - - if ($(this).hasClass('clicked-photo')) { - $(this).removeClass('clicked-photo') - - if ($('.clicked-photo').length === 0) { - $(this).closest('.modal-container').find('.save-photo').addClass('button-disable'); - } - - } else { - parent.closest('.modal-container').find('.save-photo').removeClass('button-disable'); - - parent.find('.clickable-photo'+photoID).addClass('clicked-photo'); - } -}; - -/** - * Action save photo to an object. - * - * @since 8.2.0 - * @version 9.0.0 - * - * @return {void} - */ -window.eoxiaJS.mediaGallery.savePhoto = function( event, photo, typeFrom, id) { - let parent = $('#media_gallery') - let mediaGalleryModal = $(this).closest('.modal-container') - - let filesLinked = '' - if (photo) { - photo = photo[0].name - filesLinked = photo - } else { - filesLinked = mediaGalleryModal.find('.clicked-photo') - } - - let rowId = 0 - if (id > 0) { - rowId = id - } else { - rowId = parent.attr('value') - } - - let linkedMedias = $('.table-id-'+rowId+' .linked-medias') - - let type = '' - if (typeFrom) { - type = typeFrom - } else { - type = $(this).find('.type-from').val() - } - - let filenames = '' - if (photo) { - filenames = photo - if (document.URL.match(/control_card/)) { - window.eoxiaJS.loader.display(linkedMedias); - } - } else { - if (filesLinked.length > 0) { - filesLinked.each(function( ) { - filenames += $( this ).find('.filename').val() + 'vVv' - }); - } - window.eoxiaJS.loader.display($(this)); - } - - let token = $('.fiche').find('input[name="token"]').val(); - - let favorite = filenames - if (favorite.match('vVv')) { - favorite = favorite.split('vVv')[0] - favorite = favorite.replace(/\ /, '') - } - - let url = document.URL + '&' - let separator = '&' - if (url.match(/action=/)) { - url = document.URL.split(/\?/)[0] - separator = '?' - } - - $.ajax({ - url: url + separator + "action=addFiles&token=" + token, - type: "POST", - data: JSON.stringify({ - filenames: filenames, - questionId: rowId, - type: type - }), - processData: false, - contentType: false, - success: function ( resp ) { - $('.wpeo-loader').removeClass('wpeo-loader') - parent.removeClass('modal-active') - if (document.URL.match(/control_card/)) { - linkedMedias.html($(resp).find('.table-id-'+rowId+' .linked-medias')) - window.eoxiaJS.control.updateButtonsStatus() - - } else if (document.URL.match(/question_card/)) { - favorite = favorite.replace(/\ /g, '%20') - favorite = favorite.replace(/\(/g, '%28') - favorite = favorite.replace(/\)/g, '%29') - favorite = favorite.replace(/\+/g, '%2B') - - $('.tabBar .linked-medias.'+type+' .linked-medias-list').load(document.URL + '&favorite_' + type + '=' + favorite + ' .tabBar .linked-medias.'+type+' .linked-medias-list', () => { - $('.linked-medias.'+type).find('.media-container').find('.media-gallery-favorite .fa-star').first().removeClass('far').addClass('fas') - $('.linked-medias.'+type).find('.media-container').find('.media-gallery-favorite').first().addClass('favorite') - let favoriteMedia = $('.linked-medias.'+type).find('.media-container').find('.media-gallery-favorite .filename').attr('value') - $('#'+type).val(favoriteMedia) - }) - } - - $('.wpeo-modal.modal-photo').html($(resp).find('.wpeo-modal.modal-photo .modal-container')) - }, - error: function ( ) { - //modalFrom.find('.messageErrorSavePhoto').removeClass('hidden') - } - }); -}; - -/** - * Action handle search in medias - * - * @since 8.2.0 - * @version 8.2.0 - * - * @return {void} - */ -window.eoxiaJS.mediaGallery.handleSearch = function( event ) { - let searchQuery = $('#search_in_gallery').val() - let photos = $('.center.clickable-photo') - - photos.each(function( ) { - $( this ).text().trim().match(searchQuery) ? $(this).show() : $(this).hide() - }); -}; - -/** - * Action send photo. - * - * @since 1.0.0 - * @version 1.0.0 - * - * @return {void} - */ -window.eoxiaJS.mediaGallery.sendPhoto = function( event, file, typeFrom, id ) { - if (event) { - event.preventDefault() - } - - let files = ''; - if (file) { - files = file; - } else { - files = $(this).prop("files"); - } - - let formdata = new FormData(); - let elementParent = $('.modal-container').find('.ecm-photo-list-content'); - let actionContainerSuccess = $('.messageSuccessSendPhoto'); - let actionContainerError = $('.messageErrorSendPhoto'); - - window.eoxiaJS.loader.display($('#media_gallery').find('.modal-content')); - $.each(files, function(index, file) { - formdata.append("userfile[]", file); - }) - let url = document.URL + '&' - let separator = '&' - if (url.match(/action=/)) { - url = document.URL.split(/\?/)[0] - separator = '?' - } - - let token = $('.fiche').find('input[name="token"]').val(); - - $.ajax({ - url: url + separator + "action=uploadPhoto&token=" + token, - type: "POST", - data: formdata, - processData: false, - contentType: false, - success: function ( resp ) { - $('.wpeo-loader').removeClass('wpeo-loader') - window.eoxiaJS.loader.display(elementParent); - elementParent.load( document.URL + ' .ecm-photo-list'); - elementParent.removeClass('wpeo-loader'); - actionContainerSuccess.removeClass('hidden'); - if (file) { - window.eoxiaJS.mediaGallery.savePhoto('', files, typeFrom, id) - } - - }, - error: function ( ) { - actionContainerError.removeClass('hidden'); - } - }) -}; - -/** - * Action preview photo. - * - * @since 1.0.0 - * @version 1.0.0 - * - * @return {void} - */ -window.eoxiaJS.mediaGallery.previewPhoto = function( event ) { - var checkExist = setInterval(function() { - if ($('.ui-dialog').length) { - clearInterval(checkExist); - $( document ).find('.ui-dialog').addClass('preview-photo'); - } - }, 100); -}; - -/** - * Action fast upload. - * - * @since 1.0.0 - * @version 1.0.0 - * - * @return {void} - */ -window.eoxiaJS.mediaGallery.fastUpload = function( typeFrom ) { - let id = 0 - - if (typeFrom == 'photo_ok') { - var files = $('#fast-upload-photo-ok').prop('files'); - } else if (typeFrom == 'photo_ko') { - var files = $('#fast-upload-photo-ko').prop('files'); - } else if (typeFrom.match(/answer_photo/)) { - id = typeFrom.split(/_photo/)[1] - typeFrom = 'answer_photo' - var files = $('#fast-upload-answer-photo'+id).prop('files'); - } - window.eoxiaJS.mediaGallery.sendPhoto('', files, typeFrom, id) -}; - -/** - * Action unlink photo. - * - * @since 8.2.0 - * @version 9.0.0 - * - * @return {void} - */ -window.eoxiaJS.mediaGallery.unlinkFile = function( event ) { - - event.preventDefault() - let element_linked_id = $(this).find('.element-linked-id').val() - let filename = $(this).find('.filename').val() - let querySeparator = '?' - let type = $(this).closest('tr').find('.type-from').val() - var params = new window.URLSearchParams(window.location.search); - var currentElementID = params.get('id') - - let mediaContainer = $(this).closest('.media-container') - let previousPhoto = null - let previousName = '' - let newPhoto = '' - - let token = $('.fiche').find('input[name="token"]').val(); - - //window.eoxiaJS.loader.display($(this).closest('.media-container')); - - document.URL.match('/?/') ? querySeparator = '&' : 1 - - //let riskAssessmentPhoto = $('.risk-evaluation-photo-'+element_linked_id) - //previousPhoto = $(this).closest('.tabBar').find('.clicked-photo-preview') - //previousName = previousPhoto[0].src.trim().split(/thumbs%2F/)[1].split(/"/)[0] - // - //if (previousName == filename.replace(/\./, '_small.')) { - // newPhoto = previousPhoto[0].src.replace(previousName, '') - //} else { - // newPhoto = previousPhoto[0].src - //} - let url = document.URL + '&' - let separator = '&' - if (url.match(/action=/)) { - url = document.URL.split(/\?/)[0] - separator = '?' - } - $.ajax({ - url: url + separator + "action=unlinkFile&token=" + token, - type: "POST", - data: JSON.stringify({ - filename: filename, - type: type, - id: currentElementID - }), - processData: false, - success: function ( ) { - $('.wpeo-loader').removeClass('wpeo-loader') - //riskAssessmentPhoto.each( function() { - // $(this).find('.clicked-photo-preview').attr('src',newPhoto ) - //}); - mediaContainer.hide() - } - }); - -}; - -/** - * Action add photo to favorite. - * - * @since 8.2.0 - * @version 9.0.0 - * - * @return {void} - */ -window.eoxiaJS.mediaGallery.addToFavorite = function( event ) { - event.preventDefault() - let filename = $(this).closest('.media-gallery-favorite').find('.filename').attr('value') - - //change star button style - let previousFavorite = $(this).closest('.linked-medias').find('.fas.fa-star') - let newFavorite = $(this).find('.far.fa-star') - - previousFavorite.removeClass('fas') - previousFavorite.addClass('far') - previousFavorite.closest('.media-gallery-favorite').removeClass('favorite') - newFavorite.addClass('fas') - newFavorite.removeClass('far') - newFavorite.closest('.media-gallery-favorite').addClass('favorite') - - if (filename.length > 0) { - $(this).closest('.linked-medias').find('.favorite-photo').val(filename) - } - -}; - -/** - * Action select page. - * - * @since 1.0.0 - * @version 1.0.0 - * - * @return {void} - */ -window.eoxiaJS.mediaGallery.selectPage = function( event ) { - let offset = $(this).attr('value'); - $(this).closest('.wpeo-pagination').find('.pagination-element').removeClass('pagination-current'); - $(this).closest('.pagination-element').addClass('pagination-current'); - - let elementParent = $('.modal-container').find('.ecm-photo-list-content'); - let querySeparator = '?'; - document.URL.match(/\?/) ? querySeparator = '&' : 1 - let token = $('.fiche').find('input[name="token"]').val(); - window.eoxiaJS.loader.display($('#media_gallery').find('.modal-content')); - - $.ajax({ - url: document.URL + querySeparator + "token=" + token + "&offset=" + offset, - type: "POST", - processData: false, - contentType: false, - success: function ( resp ) { - $('.wpeo-loader').removeClass('wpeo-loader') - elementParent.html($(resp).find('.ecm-photo-list-content')); - }, - error: function ( ) { - } - }) -}; +// +// /** +// * Initialise l'objet "mediaGallery" ainsi que la méthode "init" obligatoire pour la bibliothèque EoxiaJS. +// * +// * @since 1.0.0 +// * @version 8.2.0 +// */ +// window.eoxiaJS.mediaGallery = {}; +// +// /** +// * La méthode appelée automatiquement par la bibliothèque EoxiaJS. +// * +// * @since 1.0.0 +// * @version 8.2.0 +// * +// * @return {void} +// */ +// window.eoxiaJS.mediaGallery.init = function() { +// window.eoxiaJS.mediaGallery.event(); +// }; +// +// /** +// * La méthode contenant tous les événements pour le mediaGallery. +// * +// * @since 1.0.0 +// * @version 1.0.0 +// * +// * @return {void} +// */ +// window.eoxiaJS.mediaGallery.event = function() { +// // Photos +// $( document ).on( 'click', '.clickable-photo', window.eoxiaJS.mediaGallery.selectPhoto ); +// $( document ).on( 'click', '.save-photo', window.eoxiaJS.mediaGallery.savePhoto ); +// $( document ).on( 'change', '.flat.minwidth400.maxwidth200onsmartphone', window.eoxiaJS.mediaGallery.sendPhoto ); +// $( document ).on( 'click', '.clicked-photo-preview', window.eoxiaJS.mediaGallery.previewPhoto ); +// $( document ).on( 'input', '.form-element #search_in_gallery', window.eoxiaJS.mediaGallery.handleSearch ); +// $( document ).on( 'click', '.media-gallery-unlink', window.eoxiaJS.mediaGallery.unlinkFile ); +// $( document ).on( 'click', '.media-gallery-favorite', window.eoxiaJS.mediaGallery.addToFavorite ); +// $( document ).on( 'submit', '#fast-upload-photo-ok', window.eoxiaJS.mediaGallery.fastUpload ); +// $( document ).on( 'click', '.selected-page', window.eoxiaJS.mediaGallery.selectPage ); +// } +// +// /** +// * Select photo. +// * +// * @since 8.2.0 +// * @version 8.2.0 +// * +// * @return {void} +// */ +// window.eoxiaJS.mediaGallery.selectPhoto = function( event ) { +// let photoID = $(this).attr('value'); +// let parent = $(this).closest('.modal-content') +// +// if ($(this).hasClass('clicked-photo')) { +// $(this).removeClass('clicked-photo') +// +// if ($('.clicked-photo').length === 0) { +// $(this).closest('.modal-container').find('.save-photo').addClass('button-disable'); +// } +// +// } else { +// parent.closest('.modal-container').find('.save-photo').removeClass('button-disable'); +// +// parent.find('.clickable-photo'+photoID).addClass('clicked-photo'); +// } +// }; +// +// /** +// * Action save photo to an object. +// * +// * @since 8.2.0 +// * @version 9.0.0 +// * +// * @return {void} +// // */ +// window.eoxiaJS.mediaGallery.savePhoto = function( event, photo, typeFrom, id) { +// let parent = $('#media_gallery') +// let mediaGalleryModal = $(this).closest('.modal-container') +// +// let filesLinked = '' +// if (photo) { +// photo = photo[0].name +// filesLinked = photo +// } else { +// filesLinked = mediaGalleryModal.find('.clicked-photo') +// } +// +// let rowId = 0 +// if (id > 0) { +// rowId = id +// } else { +// rowId = parent.attr('value') +// } +// +// let linkedMedias = $('.table-id-'+rowId+' .linked-medias') +// +// let type = '' +// if (typeFrom) { +// type = typeFrom +// } else { +// type = $(this).find('.type-from').val() +// } +// +// let filenames = '' +// if (photo) { +// filenames = photo +// if (document.URL.match(/control_card/)) { +// window.eoxiaJS.loader.display(linkedMedias); +// } +// } else { +// if (filesLinked.length > 0) { +// filesLinked.each(function( ) { +// filenames += $( this ).find('.filename').val() + 'vVv' +// }); +// } +// window.eoxiaJS.loader.display($(this)); +// } +// +// let token = $('.fiche').find('input[name="token"]').val(); +// +// let favorite = filenames +// if (favorite.match('vVv')) { +// favorite = favorite.split('vVv')[0] +// favorite = favorite.replace(/\ /, '') +// } +// +// let url = document.URL + '&' +// let separator = '&' +// if (url.match(/action=/)) { +// url = document.URL.split(/\?/)[0] +// separator = '?' +// } +// +// $.ajax({ +// url: url + separator + "action=addFiles&token=" + token, +// type: "POST", +// data: JSON.stringify({ +// filenames: filenames, +// questionId: rowId, +// type: type +// }), +// processData: false, +// contentType: false, +// success: function ( resp ) { +// $('.wpeo-loader').removeClass('wpeo-loader') +// parent.removeClass('modal-active') +// if (document.URL.match(/control_card/)) { +// linkedMedias.html($(resp).find('.table-id-'+rowId+' .linked-medias')) +// window.eoxiaJS.control.updateButtonsStatus() +// +// } else if (document.URL.match(/question_card/)) { +// favorite = favorite.replace(/\ /g, '%20') +// favorite = favorite.replace(/\(/g, '%28') +// favorite = favorite.replace(/\)/g, '%29') +// favorite = favorite.replace(/\+/g, '%2B') +// +// $('.tabBar .linked-medias.'+type+' .linked-medias-list').load(document.URL + '&favorite_' + type + '=' + favorite + ' .tabBar .linked-medias.'+type+' .linked-medias-list', () => { +// $('.linked-medias.'+type).find('.media-container').find('.media-gallery-favorite .fa-star').first().removeClass('far').addClass('fas') +// $('.linked-medias.'+type).find('.media-container').find('.media-gallery-favorite').first().addClass('favorite') +// let favoriteMedia = $('.linked-medias.'+type).find('.media-container').find('.media-gallery-favorite .filename').attr('value') +// $('#'+type).val(favoriteMedia) +// }) +// } +// +// $('.wpeo-modal.modal-photo').html($(resp).find('.wpeo-modal.modal-photo .modal-container')) +// }, +// error: function ( ) { +// //modalFrom.find('.messageErrorSavePhoto').removeClass('hidden') +// } +// }); +// }; +// +// /** +// * Action handle search in medias +// * +// * @since 8.2.0 +// * @version 8.2.0 +// * +// * @return {void} +// */ +// window.eoxiaJS.mediaGallery.handleSearch = function( event ) { +// let searchQuery = $('#search_in_gallery').val() +// let photos = $('.center.clickable-photo') +// +// photos.each(function( ) { +// $( this ).text().trim().match(searchQuery) ? $(this).show() : $(this).hide() +// }); +// }; +// +// /** +// * Action send photo. +// * +// * @since 1.0.0 +// * @version 1.0.0 +// * +// // * @return {void} +// */ +// window.eoxiaJS.mediaGallery.sendPhoto = function( event, file, typeFrom, id ) { +// if (event) { +// event.preventDefault() +// } +// +// let files = ''; +// if (file) { +// files = file; +// } else { +// files = $(this).prop("files"); +// } +// +// let formdata = new FormData(); +// let elementParent = $('.modal-container').find('.ecm-photo-list-content'); +// let actionContainerSuccess = $('.messageSuccessSendPhoto'); +// let actionContainerError = $('.messageErrorSendPhoto'); +// +// window.eoxiaJS.loader.display($('#media_gallery').find('.modal-content')); +// $.each(files, function(index, file) { +// formdata.append("userfile[]", file); +// }) +// let url = document.URL + '&' +// let separator = '&' +// if (url.match(/action=/)) { +// url = document.URL.split(/\?/)[0] +// separator = '?' +// } +// +// let token = $('.fiche').find('input[name="token"]').val(); +// +// $.ajax({ +// url: url + separator + "action=uploadPhoto&token=" + token, +// type: "POST", +// data: formdata, +// processData: false, +// contentType: false, +// success: function ( resp ) { +// $('.wpeo-loader').removeClass('wpeo-loader') +// window.eoxiaJS.loader.display(elementParent); +// elementParent.load( document.URL + ' .ecm-photo-list'); +// elementParent.removeClass('wpeo-loader'); +// actionContainerSuccess.removeClass('hidden'); +// if (file) { +// window.eoxiaJS.mediaGallery.savePhoto('', files, typeFrom, id) +// } +// +// }, +// error: function ( ) { +// actionContainerError.removeClass('hidden'); +// } +// }) +// }; +// +// /** +// * Action preview photo. +// * +// * @since 1.0.0 +// * @version 1.0.0 +// * +// * @return {void} +// */ +// window.eoxiaJS.mediaGallery.previewPhoto = function( event ) { +// var checkExist = setInterval(function() { +// if ($('.ui-dialog').length) { +// clearInterval(checkExist); +// $( document ).find('.ui-dialog').addClass('preview-photo'); +// } +// }, 100); +// }; +// +// /** +// * Action fast upload. +// * +// * @since 1.0.0 +// * @version 1.0.0 +// * +// * @return {void} +// */ +// window.eoxiaJS.mediaGallery.fastUpload = function( typeFrom ) { +// let id = 0 +// +// if (typeFrom == 'photo_ok') { +// var files = $('#fast-upload-photo-ok').prop('files'); +// } else if (typeFrom == 'photo_ko') { +// var files = $('#fast-upload-photo-ko').prop('files'); +// } else if (typeFrom.match(/answer_photo/)) { +// id = typeFrom.split(/_photo/)[1] +// typeFrom = 'answer_photo' +// var files = $('#fast-upload-answer-photo'+id).prop('files'); +// } +// window.eoxiaJS.mediaGallery.sendPhoto('', files, typeFrom, id) +// }; +// +// /** +// * Action unlink photo. +// * +// * @since 8.2.0 +// * @version 9.0.0 +// * +// * @return {void} +// */ +// window.eoxiaJS.mediaGallery.unlinkFile = function( event ) { +// +// event.preventDefault() +// let element_linked_id = $(this).find('.element-linked-id').val() +// let filename = $(this).find('.filename').val() +// let querySeparator = '?' +// let type = $(this).closest('tr').find('.type-from').val() +// var params = new window.URLSearchParams(window.location.search); +// var currentElementID = params.get('id') +// +// let mediaContainer = $(this).closest('.media-container') +// let previousPhoto = null +// let previousName = '' +// let newPhoto = '' +// +// let token = $('.fiche').find('input[name="token"]').val(); +// +// //window.eoxiaJS.loader.display($(this).closest('.media-container')); +// +// document.URL.match('/?/') ? querySeparator = '&' : 1 +// +// //let riskAssessmentPhoto = $('.risk-evaluation-photo-'+element_linked_id) +// //previousPhoto = $(this).closest('.tabBar').find('.clicked-photo-preview') +// //previousName = previousPhoto[0].src.trim().split(/thumbs%2F/)[1].split(/"/)[0] +// // +// //if (previousName == filename.replace(/\./, '_small.')) { +// // newPhoto = previousPhoto[0].src.replace(previousName, '') +// //} else { +// // newPhoto = previousPhoto[0].src +// //} +// let url = document.URL + '&' +// let separator = '&' +// if (url.match(/action=/)) { +// url = document.URL.split(/\?/)[0] +// separator = '?' +// } +// $.ajax({ +// url: url + separator + "action=unlinkFile&token=" + token, +// type: "POST", +// data: JSON.stringify({ +// filename: filename, +// type: type, +// id: currentElementID +// }), +// processData: false, +// success: function ( ) { +// $('.wpeo-loader').removeClass('wpeo-loader') +// //riskAssessmentPhoto.each( function() { +// // $(this).find('.clicked-photo-preview').attr('src',newPhoto ) +// //}); +// mediaContainer.hide() +// } +// }); +// +// }; +// +// /** +// * Action add photo to favorite. +// * +// * @since 8.2.0 +// * @version 9.0.0 +// * +// * @return {void} +// */ +// window.eoxiaJS.mediaGallery.addToFavorite = function( event ) { +// event.preventDefault() +// let filename = $(this).closest('.media-gallery-favorite').find('.filename').attr('value') +// +// //change star button style +// let previousFavorite = $(this).closest('.linked-medias').find('.fas.fa-star') +// let newFavorite = $(this).find('.far.fa-star') +// +// previousFavorite.removeClass('fas') +// previousFavorite.addClass('far') +// previousFavorite.closest('.media-gallery-favorite').removeClass('favorite') +// newFavorite.addClass('fas') +// newFavorite.removeClass('far') +// newFavorite.closest('.media-gallery-favorite').addClass('favorite') +// +// if (filename.length > 0) { +// $(this).closest('.linked-medias').find('.favorite-photo').val(filename) +// } +// +// }; +// +// /** +// * Action select page. +// * +// * @since 1.0.0 +// * @version 1.0.0 +// * +// * @return {void} +// */ +// window.eoxiaJS.mediaGallery.selectPage = function( event ) { +// let offset = $(this).attr('value'); +// $(this).closest('.wpeo-pagination').find('.pagination-element').removeClass('pagination-current'); +// $(this).closest('.pagination-element').addClass('pagination-current'); +// +// let elementParent = $('.modal-container').find('.ecm-photo-list-content'); +// let querySeparator = '?'; +// document.URL.match(/\?/) ? querySeparator = '&' : 1 +// let token = $('.fiche').find('input[name="token"]').val(); +// window.eoxiaJS.loader.display($('#media_gallery').find('.modal-content')); +// +// $.ajax({ +// url: document.URL + querySeparator + "token=" + token + "&offset=" + offset, +// type: "POST", +// processData: false, +// contentType: false, +// success: function ( resp ) { +// $('.wpeo-loader').removeClass('wpeo-loader') +// elementParent.html($(resp).find('.ecm-photo-list-content')); +// }, +// error: function ( ) { +// } +// }) +// }; /** diff --git a/view/control/control_card.php b/view/control/control_card.php index 59178953..c8ab712d 100644 --- a/view/control/control_card.php +++ b/view/control/control_card.php @@ -22,20 +22,8 @@ */ // Load Dolibarr environment -$res = 0; -// Try main.inc.php into web root known defined into CONTEXT_DOCUMENT_ROOT (not always defined) -if (!$res && !empty($_SERVER['CONTEXT_DOCUMENT_ROOT'])) $res = @include $_SERVER['CONTEXT_DOCUMENT_ROOT']. '/main.inc.php'; -// Try main.inc.php into web root detected using web root calculated from SCRIPT_FILENAME -$tmp = empty($_SERVER['SCRIPT_FILENAME']) ? '' : $_SERVER['SCRIPT_FILENAME']; $tmp2 = realpath(__FILE__); $i = strlen($tmp) - 1; $j = strlen($tmp2) - 1; -while ($i > 0 && $j > 0 && isset($tmp[$i]) && isset($tmp2[$j]) && $tmp[$i] == $tmp2[$j]) { $i--; $j--; } -if (!$res && $i > 0 && file_exists(substr($tmp, 0, ($i + 1)). '/main.inc.php')) $res = @include substr($tmp, 0, ($i + 1)). '/main.inc.php'; -if (!$res && $i > 0 && file_exists(dirname(substr($tmp, 0, ($i + 1))). '/main.inc.php')) $res = @include dirname(substr($tmp, 0, ($i + 1))). '/main.inc.php'; -// Try main.inc.php using relative path -if (!$res && file_exists('../main.inc.php')) $res = @include '../main.inc.php'; -if ( ! $res && file_exists('../../main.inc.php')) $res = @include '../../main.inc.php'; -if ( ! $res && file_exists('../../../main.inc.php')) $res = @include '../../../main.inc.php'; -if ( ! $res && file_exists('../../../../main.inc.php')) $res = @include '../../../../main.inc.php'; -if (!$res) die('Include of main fails'); +if (file_exists("../../../saturne/saturne.main.inc.php")) $res = @include "../../../saturne/saturne.main.inc.php"; + // Libraries require_once DOL_DOCUMENT_ROOT . '/core/class/html.formcompany.class.php'; @@ -74,6 +62,7 @@ $id = GETPOST('id', 'int'); $ref = GETPOST('ref', 'alpha'); $action = GETPOST('action', 'aZ09'); +$subaction = GETPOST('subaction', 'aZ09'); $confirm = GETPOST('confirm', 'alpha'); $cancel = GETPOST('cancel', 'aZ09'); $contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'controlcard'; // To manage different context of search @@ -216,72 +205,6 @@ // Actions cancel, add, update, update_extras, confirm_validate, confirm_delete, confirm_deleteline, confirm_clone, confirm_close, confirm_setdraft, confirm_reopen include DOL_DOCUMENT_ROOT.'/core/actions_addupdatedelete.inc.php'; - if ( ! $error && $action == 'addFiles') { - $data = json_decode(file_get_contents('php://input'), true); - - $filenames = $data['filenames']; - $questionId = $data['questionId']; - $type = $data['type']; - - $object->fetch($id); - $question->fetch($questionId); - if (dol_strlen($object->ref) > 0) { - $pathToQuestionPhoto = $conf->dolismq->multidir_output[$conf->entity] . '/control/' . $object->ref . '/' . $type; - dol_mkdir($pathToQuestionPhoto); - $pathToQuestionPhoto = $conf->dolismq->multidir_output[$conf->entity] . '/control/' . $object->ref . '/' . $type . '/' . $question->ref; - dol_mkdir($pathToQuestionPhoto); - } else { - $pathToQuestionPhoto = $conf->dolismq->multidir_output[$conf->entity] . '/control/'. $object->ref . 'tmp/' . 'QU0/' . $type ; - } - - if (preg_match('/vVv/', $filenames)) { - $filenames = preg_split('/vVv/', $filenames); - array_pop($filenames); - } else { - $filenames = array($filenames); - } - - - if ( ! (empty($filenames))) { - if ( ! is_dir($conf->dolismq->multidir_output[$conf->entity] . '/control/tmp/')) { - dol_mkdir($conf->dolismq->multidir_output[$conf->entity] . '/control/tmp/'); - } - - if ( ! is_dir($conf->dolismq->multidir_output[$conf->entity] . '/control/' . (dol_strlen($object->ref) > 0 ? $object->ref : 'tmp/QU0') )) { - dol_mkdir($conf->dolismq->multidir_output[$conf->entity] . '/control/' . (dol_strlen($object->ref) > 0 ? $object->ref : 'tmp/QU0')); - } - - foreach ($filenames as $filename) { - $entity = ($conf->entity > 1) ? '/' . $conf->entity : ''; - - if (is_file($conf->ecm->multidir_output[$conf->entity] . '/dolismq/medias/' . $filename)) { - $pathToECMPhoto = $conf->ecm->multidir_output[$conf->entity] . '/dolismq/medias/' . $filename; - -// if ( ! is_dir($pathToQuestionPhoto)) { -// mkdir($pathToQuestionPhoto); -// } - - copy($pathToECMPhoto, $pathToQuestionPhoto . '/' . $filename); - $ecmfile->fetch(0,'',(($conf->entity > 1) ? $conf->entity.'/ecm/dolismq/medias/' : 'ecm/dolismq/medias/') . $filename); - $date = dol_print_date(dol_now(),'dayxcard'); - $extension = preg_split('/\./', $filename); - $newFilename = $conf->entity . '_' . $ecmfile->id . '_' . $object->ref . '_' . $question->ref . '_' . $date . '.' . $extension[1]; - rename($pathToQuestionPhoto . '/' . $filename, $pathToQuestionPhoto . '/' . $newFilename); - - global $maxwidthmini, $maxheightmini, $maxwidthsmall,$maxheightsmall ; - $destfull = $pathToQuestionPhoto . '/' . $newFilename; - - // Create thumbs - $imgThumbLarge = vignette($destfull, 1280, 720, '_large', 50, 'thumbs'); - $imgThumbMedium = vignette($destfull, 854, 480, '_medium', 50, 'thumbs'); - $imgThumbSmall = vignette($destfull, $maxwidthsmall, $maxheightsmall, '_small', 50, 'thumbs'); - // Create mini thumbs for image (Ratio is near 16/9) - $imgThumbMini = vignette($destfull, $maxwidthmini, $maxheightmini, '_mini', 50, 'thumbs'); - } - } - } - } - if ( ! $error && $action == 'unlinkFile' && $permissiontodelete) { $data = json_decode(file_get_contents('php://input'), true); @@ -613,7 +536,7 @@ $morejs = array('/dolismq/js/dolismq.js'); $morecss = array('/dolismq/css/dolismq.css'); -llxHeader('', $title, $help_url, '', 0, 0, $morejs, $morecss); +saturneHeader('dolismq', $action, $subaction,'', $title, $help_url, '', 0, 0, $morejs, $morecss); // Part to create if ($action == 'create') { @@ -1267,26 +1190,24 @@
authorize_answer_photo > 0) : ?> -
- status > 0 ) : ?> - dolismq->multidir_output[$conf->entity] . '/control/'. $object->ref . '/answer_photo/' . $item->ref, 'small', '', 0, 0, 0, 50, 50, 0, 0, 0, 'control/'. $object->ref . '/answer_photo/' . $item->ref, null, (GETPOST('favorite_answer_photo') ? GETPOST('favorite_answer_photo') : $itemControlDet->answer_photo ), 0, 0, 1); - print ''; ?> - +
+ status == 0 ) : ?> id.'" name="userfile'.$item->id.'[]" nonce="answer_photo'.$item->id.'" multiple capture="environment" accept="image/*" onchange="window.eoxiaJS.mediaGallery.fastUpload(this.nonce)">'; ?> + - - dolismq->multidir_output[$conf->entity] . '/control/'. $object->ref . '/answer_photo/' . $item->ref, 'small', '', 0, 0, 0, 50, 50, 0, 0, 0, 'control/'. $object->ref . '/answer_photo/' . $item->ref, null, (GETPOST('favorite_answer_photo') ? GETPOST('favorite_answer_photo') : $itemControlDet->answer_photo ), 0, 1, 1); ?> + dolismq->multidir_output[$conf->entity] . '/control/'. $object->ref . '/answer_photo_' . $item->id, 'small', '', 0, 0, 0, 50, 50, 0, 0, 0, 'control/'. $object->ref . '/answer_photo_' . $item->id, null, (GETPOST('favorite_answer_photo') ? GETPOST('favorite_answer_photo') : $itemControlDet->answer_photo ), 0, $object->status == 0, 1); ?>
diff --git a/view/question/question_card.php b/view/question/question_card.php index 862ee88d..e43ab050 100644 --- a/view/question/question_card.php +++ b/view/question/question_card.php @@ -28,8 +28,6 @@ require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php'; -require_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmfiles.class.php'; -require_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmdirectory.class.php'; require_once DOL_DOCUMENT_ROOT . '/core/class/doleditor.class.php'; require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php'; require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php'; @@ -50,6 +48,7 @@ $id = GETPOST('id', 'int'); $ref = GETPOST('ref', 'alpha'); $action = GETPOST('action', 'aZ09'); +$subaction = GETPOST('subaction', 'aZ09'); $confirm = GETPOST('confirm', 'alpha'); $cancel = GETPOST('cancel', 'aZ09'); $contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'questioncard'; // To manage different context of search @@ -60,8 +59,6 @@ // Technical objets $object = new Question($db); $extrafields = new ExtraFields($db); -$ecmfile = new EcmFiles($db); -$ecmdir = new EcmDirectory($db); $refQuestionMod = new $conf->global->DOLISMQ_QUESTION_ADDON($db); // View objects @@ -354,66 +351,6 @@ // Actions cancel, add, update, update_extras, confirm_validate, confirm_delete, confirm_deleteline, confirm_clone, confirm_close, confirm_setdraft, confirm_reopen include DOL_DOCUMENT_ROOT.'/core/actions_addupdatedelete.inc.php'; - if ( ! $error && $action == "addFiles") { - $data = json_decode(file_get_contents('php://input'), true); - - $filenames = $data['filenames']; - $questionId = $data['questionId']; - $type = $data['type']; - - $object->fetch($questionId); - if (dol_strlen($object->ref) > 0) { - $pathToQuestionPhoto = $conf->dolismq->multidir_output[$conf->entity] . '/question/' . $object->ref . '/' . $type; - } else { - $pathToQuestionPhoto = $conf->dolismq->multidir_output[$conf->entity] . '/question/tmp/' . 'QU0/' . $type ; - } - - if (preg_match('/vVv/', $filenames)) { - $filenames = preg_split('/vVv/', $filenames); - array_pop($filenames); - } else { - $filenames = array($filenames); - } - - if ( ! (empty($filenames))) { - if ( ! is_dir($conf->dolismq->multidir_output[$conf->entity] . '/question/tmp/')) { - dol_mkdir($conf->dolismq->multidir_output[$conf->entity] . '/question/tmp/'); - } - - if ( ! is_dir($conf->dolismq->multidir_output[$conf->entity] . '/question/' . (dol_strlen($object->ref) > 0 ? $object->ref : 'tmp/QU0') )) { - - dol_mkdir($conf->dolismq->multidir_output[$conf->entity] . '/question/' . (dol_strlen($object->ref) > 0 ? $object->ref : 'tmp/QU0')); - } - - foreach ($filenames as $filename) { - $entity = ($conf->entity > 1) ? '/' . $conf->entity : ''; - - if (is_file($conf->ecm->multidir_output[$conf->entity] . '/dolismq/medias/' . $filename)) { - $pathToECMPhoto = $conf->ecm->multidir_output[$conf->entity] . '/dolismq/medias/' . $filename; - - if ( ! is_dir($pathToQuestionPhoto)) { - mkdir($pathToQuestionPhoto); - } - - copy($pathToECMPhoto, $pathToQuestionPhoto . '/' . $filename); - $ecmfile->fetch(0,'',($conf->entity > 1 ? $conf->entity . '/' : ''). 'ecm/dolismq/medias/' . $filename); - $date = dol_print_date(dol_now(),'dayxcard'); - $extension = pathinfo($filename, PATHINFO_EXTENSION); - $newFilename = $conf->entity . '_' . $ecmfile->id . '_' . (dol_strlen($object->ref) > 0 ? $object->ref : $refQuestionMod->getNextValue($object)) . '_' . $date . '.' . $extension; - rename($pathToQuestionPhoto . '/' . $filename, $pathToQuestionPhoto . '/' . $newFilename); - - global $maxwidthmini, $maxheightmini, $maxwidthsmall,$maxheightsmall ; - $destfull = $pathToQuestionPhoto . '/' . $newFilename; - - // Create thumbs - $imgThumbSmall = vignette($destfull, $maxwidthsmall, $maxheightsmall, '_small', 50, "thumbs"); - // Create mini thumbs for image (Ratio is near 16/9) - $imgThumbMini = vignette($destfull, $maxwidthmini, $maxheightmini, '_mini', 50, "thumbs"); - } - } - } - } - if ( ! $error && $action == "unlinkFile" && $permissiontodelete) { $data = json_decode(file_get_contents('php://input'), true); @@ -485,7 +422,7 @@ $morejs = array("/dolismq/js/dolismq.js"); $morecss = array("/dolismq/css/dolismq.css"); -saturneHeader('dolismq','', $title, $help_url, '', '', '', $morejs, $morecss); +saturneHeader('dolismq', $action,$subaction, '', $title, $help_url, '', '', '', $morejs, $morecss); // Part to create if ($action == 'create') { @@ -546,7 +483,9 @@ Date: Mon, 26 Dec 2022 18:03:37 +0100 Subject: [PATCH 003/170] #596 [Control] fix: medias directory rename after ref attribution --- class/control.class.php | 38 +++++++++++--------------------------- 1 file changed, 11 insertions(+), 27 deletions(-) diff --git a/class/control.class.php b/class/control.class.php index 67e33bd2..bf4a062e 100644 --- a/class/control.class.php +++ b/class/control.class.php @@ -318,16 +318,15 @@ public function setValidated($user, $notrigger = 0) // Define new ref if ((preg_match('/^\(?PROV/i', $this->ref) || empty($this->ref))) { // empty should not happen, but when it occurs, the test save life - $num = $this->getNextNumRef(); + $newref = $this->getNextNumRef(); } else { - $num = $this->ref; + $newref = $this->ref; } - $this->newref = $num; - if (!empty($num)) { + if (!empty($newref)) { // Validate $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element; - $sql .= " SET ref = '".$this->db->escape($num)."',"; + $sql .= " SET ref = '".$this->db->escape($newref)."',"; $sql .= " status = ".self::STATUS_VALIDATED; $sql .= " WHERE rowid = ".($this->id); @@ -350,45 +349,30 @@ public function setValidated($user, $notrigger = 0) } if (!$error) { - $this->oldref = $this->ref; - // Rename directory if dir was a temporary ref if (preg_match('/^\(?PROV/i', $this->ref)) { // Now we rename also files into index - $sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filename = CONCAT('".$this->db->escape($this->newref)."', SUBSTR(filename, ".(strlen($this->ref) + 1).")), filepath = 'control/".$this->db->escape($this->newref)."'"; + $sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filename = CONCAT('".$this->db->escape($newref)."', SUBSTR(filename, ".(strlen($this->ref) + 1).")), filepath = 'control/".$this->db->escape($newref)."'"; $sql .= " WHERE filename LIKE '".$this->db->escape($this->ref)."%' AND filepath = 'control/".$this->db->escape($this->ref)."' and entity = ".$conf->entity; $resql = $this->db->query($sql); if (!$resql) { $error++; $this->error = $this->db->lasterror(); } - // We rename directory ($this->ref = old ref, $num = new ref) in order not to lose the attachments + // We rename directory ($this->ref = old ref, $newref = new ref) in order not to lose the attachments $oldref = dol_sanitizeFileName($this->ref); - $newref = dol_sanitizeFileName($num); + $newref = dol_sanitizeFileName($newref); + $dirsource = $conf->dolismq->dir_output.'/control/'.$oldref; $dirdest = $conf->dolismq->dir_output.'/control/'.$newref; - if (!$error && file_exists($dirsource)) { - dol_syslog(get_class($this)."::validate() rename dir ".$dirsource." into ".$dirdest); - - if (@rename($dirsource, $dirdest)) { - dol_syslog("Rename ok"); - // Rename docs starting with $oldref with $newref - $listoffiles = dol_dir_list($conf->dolismq->dir_output.'/control/'.$newref, 'files', 1, '^'.preg_quote($oldref, '/')); - foreach ($listoffiles as $fileentry) { - $dirsource = $fileentry['name']; - $dirdest = preg_replace('/^'.preg_quote($oldref, '/').'/', $newref, $dirsource); - $dirsource = $fileentry['path'].'/'.$dirsource; - $dirdest = $fileentry['path'].'/'.$dirdest; - @rename($dirsource, $dirdest); - } - } - } + + rename($dirsource, $dirdest); } } // Set new ref and current status if (!$error) { - $this->ref = $num; + $this->ref = $newref; $this->status = self::STATUS_VALIDATED; } From ac5b1ea6d8532563844a0278506f8aaa09de9481 Mon Sep 17 00:00:00 2001 From: David Date: Tue, 27 Dec 2022 14:03:38 +0100 Subject: [PATCH 004/170] #595 [MediaGallery] fix: addToFavorite action --- view/question/question_card.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/view/question/question_card.php b/view/question/question_card.php index e43ab050..071349fa 100644 --- a/view/question/question_card.php +++ b/view/question/question_card.php @@ -490,7 +490,7 @@
dolismq->multidir_output[$conf->entity] . '/question/tmp/QU0/photo_ok', 'small', '', 0, 0, 0, 50, 50, 1, 0, 0, 'question/tmp/QU0/photo_ok', null, GETPOST('favorite_photo_ok')); + print saturne_show_medias_linked('dolismq', $conf->dolismq->multidir_output[$conf->entity] . '/question/tmp/QU0/photo_ok', 'small', '', 0, 0, 0, 50, 50, 1, 0, 0, 'question/tmp/QU0/photo_ok', $object, 'photo_ok'); print ''; // Photo KO -- Photo KO print ''; ?> @@ -508,7 +508,7 @@
dolismq->multidir_output[$conf->entity] . '/question/tmp/QU0/photo_ko', 'small', '', 0, 0, 0, 50, 50, 1, 0, 0, 'question/tmp/QU0/photo_ko', null, GETPOST('favorite_photo_ko')); + print saturne_show_medias_linked('dolismq', $conf->dolismq->multidir_output[$conf->entity] . '/question/tmp/QU0/photo_ko', 'small', '', 0, 0, 0, 50, 50, 1, 0, 0, 'question/tmp/QU0/photo_ko', $object, 'photo_ko'); print ''; // Categories @@ -611,7 +611,7 @@ dolismq->multidir_output[$conf->entity] . '/question/'. $object->ref . '/photo_ok', 'small', '', 0, 0, 0, 50, 50, 1, 0, 0, 'question/'. $object->ref . '/photo_ok', null, (GETPOST('favorite_photo_ok') ? GETPOST('favorite_photo_ok') : $object->photo_ok )); + print saturne_show_medias_linked('dolismq', $conf->dolismq->multidir_output[$conf->entity] . '/question/'. $object->ref . '/photo_ok', 'small', '', 0, 0, 0, 50, 50, 1, 0, 0, 'question/'. $object->ref . '/photo_ok', $object, 'photo_ok'); print ''; // Photo KO -- Photo KO @@ -630,7 +630,7 @@ dolismq->multidir_output[$conf->entity] . '/question/'. $object->ref . '/photo_ko', 'small', '', 0, 0, 0, 50, 50, 1, 0, 0, 'question/'. $object->ref . '/photo_ko', null,(GETPOST('favorite_photo_ko') ? GETPOST('favorite_photo_ko') : $object->photo_ko )); + print saturne_show_medias_linked('dolismq', $conf->dolismq->multidir_output[$conf->entity] . '/question/'. $object->ref . '/photo_ko', 'small', '', 0, 0, 0, 50, 50, 1, 0, 0, 'question/'. $object->ref . '/photo_ko', $object, 'photo_ko'); print ''; // Tags-Categories From 494cc426590de74f587fb94e11c256e41ea63a92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20David?= Date: Wed, 28 Dec 2022 16:44:12 +0100 Subject: [PATCH 005/170] #595 [MediaGallery] fix: fastUpload action --- view/question/question_card.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/view/question/question_card.php b/view/question/question_card.php index 071349fa..252268e5 100644 --- a/view/question/question_card.php +++ b/view/question/question_card.php @@ -475,7 +475,7 @@ // Photo OK -- Photo OK print ''; ?> - '; ?> +