412 $langs->load(
"products");
415 $last_month =
dol_now() - (30 * 24 * 60 * 60);
416 $dolibarrversiontouse = DOL_VERSION;
418 $this->products = array();
421 $installedModules = array();
422 if (is_array($modules)) {
423 foreach ($modules as $objMod) {
424 if (is_object($objMod) && $objMod->isCoreOrExternalModule() !=
'core') {
425 $moduleName = strtolower($objMod->name);
426 $moduleVersion = $objMod->getVersion(0);
427 $installedModules[$moduleName] = $moduleVersion;
432 $this->categorie = $options[
'categorie'] ?? 0;
433 $this->per_page = $options[
'per_page'] ?? 11;
434 $this->no_page = $options[
'no_page'] ?? 1;
435 $this->search = $options[
'search'] ??
'';
437 $this->per_page = 11;
440 if (!empty($this->search) && strlen(str_replace(
' ',
'', (
string) $this->search)) < 2) {
441 $html .=
'<tr class=""><td colspan="3" class="center">';
443 $html .= $langs->trans(
"SearchStringMinLength").
'...';
445 $html .=
'</td></tr>';
450 'categorieid' => $this->categorie,
451 'limit' => $this->per_page,
452 'page' => $this->no_page,
453 'search' => $this->search,
454 'lang' => $this->lang
458 $this->numberTotalOfProducts = 0;
461 if ($this->categorie == 87) {
462 $html =
'<div class="shop-container">
463 <div class="shop-image">
464 <a href="https://merch.dolibarr.org/" target="_blank">
465 <img src="https://www.dolistore.com/medias/image/marketplace/img/goodies-shop.jpg" width="50%" alt="DoliStore Merch and Gifts" />
466 <div class="shop-overlay">
467 <button target="new" class="shop-button">'.$langs->trans(
"GoodiesButtonTitle").
' <i class="icon-chevron-right"></i></button>
478 $dolistoreProducts = array();
479 $dolistoreProductsTotal = 0;
480 if ($this->dolistoreApiStatus > 0 &&
getDolGlobalInt(
'MAIN_ENABLE_EXTERNALMODULES_DOLISTORE')) {
481 $getDolistoreProducts = $this->
callApi(
'products', $data);
483 if (!isset($getDolistoreProducts[
'response']) || !is_array($getDolistoreProducts[
'response']) || ($getDolistoreProducts[
'status_code'] != 200 && $getDolistoreProducts[
'status_code'] != 201)) {
484 $dolistoreProducts = array();
485 $dolistoreProductsTotal = 0;
487 $dolistoreProducts = $this->
adaptData($getDolistoreProducts[
'response'][
'products'],
'dolistore');
488 $dolistoreProductsTotal = (int) $getDolistoreProducts[
'response'][
'total'];
489 $this->numberTotalOfProducts += $dolistoreProductsTotal;
495 $fileProducts = array();
496 $fileProductsTotal = 0;
497 if (!empty($this->githubFileStatus) &&
getDolGlobalInt(
'MAIN_ENABLE_EXTERNALMODULES_COMMUNITY')) {
500 $fileProducts = $this->
adaptData($fileProducts,
'githubcommunity');
502 $fileProducts = $this->
applyFilters($fileProducts, $data);
504 $fileProductsTotal = $fileProducts[
'total'];
506 $this->numberTotalOfProducts += $fileProductsTotal;
508 $fileProducts = $fileProducts[
'data'];
513 $customFileProducts = array();
514 $customFileProductsTotalMax = 0;
515 foreach ($this->custom_sources as $key => $customsource) {
516 if (empty($customsource[
'status']) || !
getDolGlobalInt($customsource[
'const_enable'])) {
521 $tmpProducts = $this->
adaptData($tmpProducts,
'githubcustom', $key);
523 $tmpProducts = $this->
applyFilters($tmpProducts, $data);
525 $customFileProductsTotalMax = max($customFileProductsTotalMax, $tmpProducts[
'total']);
527 $this->numberTotalOfProducts += $tmpProducts[
'total'];
529 $customFileProducts = array_merge($customFileProducts, $tmpProducts[
'data']);
533 $this->numberTotalOfPages = (int) ceil(max($fileProductsTotal / $this->per_page, $customFileProductsTotalMax / $this->per_page, $dolistoreProductsTotal / $this->per_page));
536 $this->products = $dolistoreProducts;
537 foreach (array_merge($fileProducts, $customFileProducts) as $fileProduct) {
538 $id = $fileProduct[
'id'];
540 if (empty($this->products[
$id])) {
541 array_unshift($this->products, $fileProduct);
543 $this->products[
$id] = $fileProduct;
544 $this->products[
$id][
'category'] = $fileProduct[
'category'];
547 array_unshift($this->products, $fileProduct);
553 foreach ($this->products as $product) {
558 if ($last_month < strtotime($product[
'datec']) && $product[
"status"] !=
'soon' && $product[
"status"] !=
'development' && $product[
"status"] !=
'experimental') {
559 $newapp .=
'<span class="newApp" title="'.$product[
'tms'].
'">'.$langs->trans(
'New').
'</span> ';
563 if ($newapp ==
'' && $last_month < strtotime($product[
'tms']) && $product[
"status"] !=
'soon' && $product[
"status"] !=
'development' && $product[
"status"] !=
'experimental') {
564 $newapp .=
'<span class="updatedApp" title="'.$product[
'tms'].
'">'.$langs->trans(
'UpdatedRecently').
'</span> ';
568 if ($product[
"cover_photo_url"] !=
'' && $product[
"cover_photo_url"] !=
'#') {
569 $images =
'<a href="'.$product[
"cover_photo_url"].
'" class="documentpreview" target="_blank" rel="noopener noreferrer" mime="image/png" title="'.
dol_escape_htmltag($product[
"label"].
', '.$langs->trans(
'Version').
' '.$product[
"module_version"]).
'">';
570 $images .=
'<img class="imgstore" src="'.$product[
"cover_photo_url"].
'" alt="" /></a>';
572 $images =
'<img class="imgstore" src="'.DOL_URL_ROOT.
'/public/theme/common/nophoto.png" />';
578 if ($product[
"status"] ==
'soon' || $product[
"status"] ==
'development' || $product[
"status"] ==
'experimental') {
579 $version =
'<span class="warning">'.$langs->trans(
"NotYetAvailable").
' - '.$langs->trans(
"StillInDevelopment").
'</span>';
580 $compatible =
'NotCompatible';
583 $minknown = (!empty($product[
"dolibarr_min"]) && !in_array($product[
"dolibarr_min"], array(
'auto',
'unknown')));
584 $maxknown = (!empty($product[
"dolibarr_max"]) && !in_array($product[
"dolibarr_max"], array(
'auto',
'unknown')));
586 if ($minknown && $this->
versionCompare($product[
"dolibarr_min"], $dolibarrversiontouse) > 0) {
588 $version =
'<span class="compatibleafterupdate">'.$langs->trans(
589 'CompatibleAfterUpdate',
590 $dolibarrversiontouse,
591 $product[
"dolibarr_min"],
592 $product[
"dolibarr_max"]
594 $compatible =
'NotCompatible';
595 } elseif ($maxknown && $this->
versionCompare($product[
"dolibarr_max"], $dolibarrversiontouse) >= 0) {
597 $version =
'<span class="compatible hideonsmartphone">'.$langs->trans(
599 $dolibarrversiontouse,
600 $product[
"dolibarr_min"],
601 $product[
"dolibarr_max"]
606 $version =
'<span class="warning">'.$langs->trans(
608 $dolibarrversiontouse,
609 $product[
"dolibarr_min"],
610 $product[
"dolibarr_max"]
612 $compatible =
'NotCompatible';
618 if (array_key_exists(
'price_ht', $product) &&
price2num($product[
"price_ht"]) > 0) {
619 $price =
'<h3>'.price(
price2num($product[
"price_ht"],
'MT'), 0, $langs, 1, -1, -1,
'EUR').
' '.$langs->trans(
"HT").
'</h3>';
621 $download_link =
'<a class="paddingleft paddingright valignmiddle" target="_blank" title="'.$langs->trans(
"View").
'" href="'.$this->shop_url.
'/product.php?id='.((int) $product[
'id']).
'">';
622 $download_link .= img_picto(
'',
'url',
'class="size2x paddingright"');
623 $download_link .=
'</a>';
625 $download_link =
'#';
626 if ($product[
'source'] ===
'dolistore') {
627 $urlview = $this->shop_url.
'/product.php?id='.((int) $product[
"id"]);
628 $price =
'<h3><a href="'.$urlview.
'" target="_blank">'.$langs->trans(
'SeeOnDoliStore').
'</a></h3>';
629 } elseif (in_array($product[
'source'], array(
'githubcommunity',
'githubcustom'))) {
630 if (array_key_exists(
'price_ht', $product) && empty($product[
'price_ht'])) {
631 if ($product[
'status'] ==
'soon') {
632 $price =
'<h3>'.$langs->trans(
'StillInDevelopment').
'</h3>';
634 $price =
'<h3>'.$langs->trans(
'Free').
'</h3>';
637 if ($product[
"dolistore-download"]) {
638 $price =
'<h3><a href="'.$product[
"dolistore-download"].
'" target="_blank">'.$langs->trans(
'SeeOnDoliStore').
'</a></h3>';
640 $price =
'<h3>'.$langs->trans(
'Unknown').
'</h3>';
644 $price =
'<h3>'.$langs->trans(
'Unknown').
'</h3>';
647 if (in_array($product[
'source'], array(
'githubcommunity',
'githubcustom'))) {
648 $download_link =
'<a class="paddingleft paddingright valignmiddle" target="_blank" title="'.$langs->trans(
"Sources").
'" href="'.$product[
"link"].
'">';
649 $download_link .= img_picto(
'',
'file-code',
'class="size2x paddingright colorgrey"');
650 $download_link .=
'</a>';
652 $urlview = $product[
"dolistore-download"];
654 $download_link .=
'<a class="paddingleft paddingright valignmiddle" target="_blank" title="'.$langs->trans(
"View").
'" href="'.$urlview.
'" rel="noopener noreferrer">';
655 $download_link .= img_picto(
'',
'url',
'class="size2x"');
656 $download_link .=
'</a>';
659 if (!empty($product[
'direct-download']) && $product[
'direct-download'] ==
'yes') {
661 if (preg_match(
'/https:.*\?id=(\d+)$/', $urlview, $reg)) {
662 $urldownload =
'https://www.dolistore.com/_service_download.php?t=free&p='.$reg[1];
663 $download_link .=
'<a class="paddingleft paddingright valignmiddle" target="_blank" title="'.$langs->trans(
"Download").
'" href="'.$urldownload.
'" rel="noopener noreferrer">';
664 $download_link .= img_picto(
'',
'download',
'class="size2x paddingright"');
665 $download_link .=
'</a>';
668 } elseif ($product[
'source'] ===
'dolistore') {
669 $urlview = $this->shop_url.
'/product.php?id='.((int) $product[
"id"]);
670 $urldownload =
'https://www.dolistore.com/_service_download.php?t=free&p=' . $product[
'id'];
671 $download_link =
'<a class="paddingleft paddingright valignmiddle" target="_blank" title="'.$langs->trans(
"View").
'" href="'.$urlview.
'">';
672 $download_link .= img_picto(
'',
'url',
'class="size2x"');
673 $download_link .=
'</a>';
674 $download_link .=
'<a class="paddingleft paddingright valignmiddle" target="_blank" title="'.$langs->trans(
"Download").
'" href="'.$urldownload.
'" rel="noopener noreferrer">';
675 $download_link .= img_picto(
'',
'download',
'class="size2x paddingright"');
676 $download_link .=
'</a>';
680 if ((!empty($product[
'direct-download']) && in_array($product[
'direct-download'], array(
'yes',
'dolistore'))) || $product[
'source'] ===
'dolistore') {
683 if (in_array($product[
'source'], array(
'githubcommunity',
'githubcustom'))) {
684 $current_version = $product[
'module_version'] ??
'';
685 $module_name = strtolower(preg_replace(
'/@.*$/',
'', $product[
'ref'] ??
''));
688 $module_name = preg_replace(
'/-' . preg_quote($current_version,
'/') .
'$/',
'', $module_name);
690 $urldownload = $this->
getGithubRawBaseUrl($product[
'source'], $product[
'custom_source_key'] ??
'').
'/dev/build/bin/module_' . $module_name .
'-' . $current_version .
'.zip';
693 $urlview = $product[
"dolistore-download"];
697 if (($product[
"direct-download"] ??
'') ==
'dolistore' ||
getDolGlobalString(
"MAIN_DOWNLOAD_FROM_DOLISTORE_IN_PRIORITY")) {
698 if (preg_match(
'/https:.*\?id=(\d+)$/', $urlview, $reg)) {
699 $urldownload =
'https://www.dolistore.com/_service_download.php?t=free&p='.$reg[1];
703 if ($product[
'source'] ===
'dolistore') {
704 $urldownload =
'https://www.dolistore.com/_service_download.php?t=free&p=' . $product[
'id'];
708 $disableInstall = ($compatible ===
'NotCompatible') && !
getDolGlobalInt(
'MAIN_FEATURES_LEVEL');
711 $fields = [
'action' =>
'install',
'token' =>
newToken()];
712 foreach ($product as $key => $value) {
713 $fields[
'producttoinstall['.$key.
']'] = $value;
716 $installConfirmMessage = $langs->transnoentities(
717 "extModuleConfirmInstallText",
718 $product[
'label'] ??
'',
719 $product[
'module_version'] ??
'',
720 $product[
'ref'] ??
'',
721 !empty($product[
'tms']) ?
dol_print_date($product[
'tms'],
'%d/%m/%Y') :
''
723 $installConfirmMessage .= $langs->trans(
"Path").
' : '.$urldownload;
726 $buttonLabel = $langs->trans(
"Install");
727 $remoteVersion = $product[
'module_version'] ??
'';
728 $remoteModuleName = strtolower(preg_replace(
'/@.*$/',
'', $product[
'ref'] ??
''));
730 $remoteModuleName = preg_replace(
'/-' . preg_quote($remoteVersion,
'/') .
'$/',
'', $remoteModuleName);
731 if (!empty($installedModules[$remoteModuleName]) && $remoteVersion && $remoteVersion !=
'unknown') {
732 $localVersion = $installedModules[$remoteModuleName];
734 if ($localVersion !=
'unknown') {
735 $versionDiff = $this->
versionCompare($localVersion, $remoteVersion);
736 if ($versionDiff < 0) {
737 $buttonLabel = $langs->trans(
"Upgrade");
738 } elseif ($versionDiff == 0) {
739 $buttonLabel = $langs->trans(
"ReInstall");
744 $install_link =
'<button class="valignmiddle ' . ($disableInstall ?
'butActionRefused' :
'butAction') .
' paddingleft paddingright"'
746 . (!$disableInstall ?
' data-confirm' :
'')
747 . (!$disableInstall ?
' data-fields="' .
dol_escape_htmltag(json_encode($fields)) .
'"' :
'')
749 . (!$disableInstall ?
' data-confirm-title="' .
dol_escape_htmltag($langs->trans(
"extModuleConfirmInstallTitle")) .
'"' :
'')
750 . (!$disableInstall ?
' data-confirm-text="' .
dol_escape_htmltag($installConfirmMessage) .
'"' :
'')
751 . (!$disableInstall ?
' data-confirm-label="' .
dol_escape_htmltag($buttonLabel) .
'"' :
'')
752 .
'>' . $buttonLabel .
'</button>';
757 $html .=
'<tr class="'.(getDolOptimizeSmallScreen() ?
'app' :
'app app2').
' oddeven nohover '.
dol_escape_htmltag($compatible).
'">';
760 $html .=
'<td class="center width150"><div class="newAppParent">';
761 $html .= $newapp.$images;
762 $html .=
'</div></td>';
765 $html .=
'<td class="margeCote minwidth400imp"><h2 class="appTitle">';
767 if (!empty($product[
'author']) && $product[
'author'] !=
'unkownauthor') {
768 $html .=
'<span class="small"> - '.img_picto(
'',
'company',
'class="pictofixedwidth"');
769 if (!empty($product[
'author_url'])) {
770 $html .=
'<a href="'.$product[
'author_url'].
'" target="_blank">'.$product[
'author'].
'</a>';
772 $html .= $product[
'author'];
776 $html .=
'<br><span class="small">';
781 $html .=
'<small class="appDateCreation appRef"> ';
782 if (empty($product[
'tms'])) {
783 $html .= img_picto($langs->trans(
'DateCreation'),
'calendar',
'class="pictofixedwidth"').
'<span class="opacitymedium"><span class="hideonsmartphone">'.$langs->trans(
"DateCreation").
': </span>';
786 $html .= img_picto($langs->trans(
'DateModification'),
'calendar',
'class="pictofixedwidth"').
'<span class="opacitymedium">'.
dol_print_date(
dol_stringtotime($product[
'tms']),
'day').
'</span>';
788 $html .=
' ';
790 $html .=
'<div class="appSource inline-block valigntop">';
791 if ($product[
"source"] ==
'dolistore') {
792 $html .=
'<img border="0" title="'.dolPrintHTML($langs->trans(
'Source').
": DoliStore").
'" class="imgautosize valignmiddle inline-block pictofixedwidth" style="height: 14px" src="'.DOL_URL_ROOT.
'/theme/dolistore_squarred.svg">';
793 } elseif ($product[
"source"] ==
'githubcommunity') {
794 $html .= img_picto($langs->trans(
'Source').
': GitHub community repo',
'group',
'class="pictofixedwidth valignmiddle"');
795 } elseif ($product[
"source"] ==
'githubcustom') {
796 $html .= img_picto($langs->trans(
'Source').
': '.($this->custom_sources[$product[
'custom_source_key']][
'url'] ??
''),
'fa-code-branch',
'class="pictofixedwidth valignmiddle"');
798 $html .= img_picto($langs->trans(
'Source').
': '.$langs->trans(
'Other'),
'generic',
'class="pictofixedwidth"');
802 $html .= $langs->trans(
'Ref').
' '.dolPrintHTML(preg_replace(
'/@.*$/',
'', $product[
"ref"]));
803 $html .=
'</small><br>';
807 if (!empty($product[
'phpmin']) && $product[
'phpmin'] !=
'unknown') {
808 $html .=
' <span class="badge-secondary small" style="padding: 3px; border-radius: 5px">PHP min '.$product[
'phpmin'].
'</span>';
810 if (!empty($product[
'phpmax']) && $product[
'phpmax'] !=
'unknown') {
811 $html .=
' <span class="badge-secondary small" style="padding: 3px; border-radius: 5px">PHP max '.$product[
'phpmax'].
'</span>';
816 $html .=
'<div class="storedesc">'.dolPrintHTML(
dol_string_nohtmltag($product[
"description"])).
'</div>';
820 $html .=
'</tr><tr class="app2 oddeven nohover borderbottom '.dol_escape_htmltag($compatible).
'">';
824 $html .=
'<td class="margeCote center amount'.(getDolOptimizeSmallScreen() ?
' left" colspan="2"' :
'"').
'>';
826 if ((!empty($product[
'direct-download']) && in_array($product[
'direct-download'], array(
'yes',
'dolistore'))) || ($product[
'source'] ===
'dolistore' && empty((
float) $product[
'price_ht']))) {
828 $html .= $install_link;
834 $html .=
'<td class="margeCote nowraponall">';
838 $html .= $download_link;
844 if (empty($this->products)) {
846 $langs->load(
"website");
848 $html .=
'<tr class=""><td colspan="'.$colspan.
'" class="center">';
850 $html .= $langs->trans(
"noResultsWereFound").
'...';
852 $html .=
'</td></tr>';
856 $confirmLabel = $langs->trans(
"Install");
857 $cancelLabel = $langs->trans(
"Cancel");
859 $(document).on("click","[data-confirm]",function(){
860 var button = $(this);
861 var confirmTitle = button.data("confirm-title");
862 var confirmText = button.data("confirm-text");
864 buttons[button.data("confirm-label")||\'' .
dol_escape_js($confirmLabel) .
'\'] =
function(){
865 var form = $(
"<form method=\'POST\' style=\'display:none\'>").attr(
"action",
button.data(
"url"));
866 $.each(
button.data(
"fields"),
function(
name, value){
867 form.append($(
"<input type=\'hidden\'>").attr(
"name", name).val(value));
869 $(
"body").append(form);
871 $(
this).dialog(
"close");
873 buttons[\
'' .
dol_escape_js($cancelLabel) .
'\'] =
function(){$(
this).dialog(
"close");};
874 $(
"<div>").html(confirmText).dialog({
883 $this->numberOfProducts = count($this->products);