dolibarr/htdocs/core/lib/doleditor.lib.php
Frédéric FRANCE 840538d702
FIX: Resolve possibly-undefined-variable cases flagged by PHPStan (#39523)
* FIX: Resolve possibly-undefined-variable cases flagged by PHPStan

Fixes several cases of the variable.undefined PHPStan rule instead of
just excluding them via the baseline: a wrong variable used to build a
delete link (dir_add_card.php), an uninitialized $result across a
try/catch (CMailFile), missing GETPOST reads ($mode, $fk_project/$date
reset via unset() creating cross-branch ambiguity), a missing $r
contract check (commonfieldsinimport.inc.php), missing @var/global
annotations for $conf/$langs/$bc, dead extrafields-display code
guarded by the wrong condition (expedition/card.php), and an
undefined $soc passed to formAddObjectLine() where objects have no
buyer thirdparty (replaced with null). Corresponding entries removed
from dev/build/phpstan/phpstan-baseline.neon.

* FIX: Resolve more possibly-undefined-variable cases flagged by PHPStan

Second batch of variable.undefined fixes removed from the baseline:
- Complex conditional flows PHPStan can't prove exhaustive (Stripe key
  selection in commoninvoice.class.php, a situation-invoice loop var in
  pdf_sponge.modules.php, a product loop var in stock/movement_list.php)
  fixed by adding a definite initialization before the ambiguous branch.
- A commented-out $linkback assignment restored in
  expensereport/payment/info.php.
- Missing GETPOST reads added (holiday/list.php update-date filters,
  product/stock/info.php $action/$socid, projet/comment.php $mode).
- A dead-code $mesg call to dol_htmloutput_mesg() removed from
  admin_hrm.php (messages are already shown via setEventMessages()).
- Redundant isset() checks removed in product/reassort.php and
  reassortlot.php where $type is unconditionally set earlier in the
  same file, so the isset()-false branch was unreachable dead code.
- $user documented as always available in public/bookcal/index.php
  (NOREQUIREUSER is not defined on that page).
- A genuinely missing $tmpcode initialization fixed in
  attendee_new.php, suggestbooth.php and suggestconference.php: when
  an existing thirdparty is reused (or SOCIETE_CODECLIENT_ADDON has no
  auto-numbering), $tmpcode was never set before being assigned to
  code_client/code_fournisseur.

* add phan fix

* add phan fix

* fix

* fix

* fix
2026-08-15 18:33:12 +02:00

121 lines
3.9 KiB
PHP

<?php
/* Copyright (C) 2006-2012 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2010-2012 Regis Houssin <regis.houssin@inodbox.com>
* Copyright (C) 2015 Alexandre Spangaro <aspangaro@open-dsi.fr>
* Copyright (C) 2026 Frédéric France <frederic.france@free.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
* or see https://www.gnu.org/
*/
/**
* \file htdocs/core/lib/doleditor.lib.php
* \brief Ensemble de functions de base pour la gestion des utilisaterus et groups
*/
/**
* Show list of ckeditor's themes.
*
* @param User|null $fuser User concerned or null for global theme
* @param int $edit 1 to add edit form
* @return void
*/
function show_skin($fuser, $edit = 0)
{
global $conf, $langs, $db;
global $bc;
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
$formother = new FormOther($db);
$dirskins = array('/public/includes/ckeditor/ckeditor/skins');
if (!empty($conf->modules_parts['theme'])) { // Using this feature slow down application
foreach ($conf->modules_parts['theme'] as $reldir) {
$dirskins = array_merge($dirskins, (array) ($reldir.'theme'));
}
}
$dirskins = array_unique($dirskins);
// Now dir_themes=array('/themes') or dir_themes=array('/theme','/mymodule/theme')
$selected_theme = getDolGlobalString('FCKEDITOR_SKIN', 'moono-lisa');
$colspan = 2;
print '<table class="noborder centpercent">';
$var = 0;
// Title
print '<tr class="liste_titre"><th width="35%">'.$langs->trans("DefaultSkin").'</th>';
print '<th class="right">';
print '</th></tr>';
print '<tr class="oddeven">';
print '<td>'.$langs->trans("ThemeDir").'</td>';
print '<td>';
foreach ($dirskins as $dirskin) {
echo '"'.$dirskin.'" ';
}
print '</td>';
print '</tr>';
//
print '<tr class="oddeven"><td colspan="'.$colspan.'">';
print '<table class="nobordernopadding" width="100%"><tr><td><div class="center">';
$i = 0;
foreach ($dirskins as $dir) {
//print $dirroot.$dir;exit;
$dirskin = dol_buildpath($dir, 0); // This include loop on $conf->file->dol_document_root
$urltheme = dol_buildpath($dir, 1);
if (is_dir($dirskin)) {
$handle = opendir($dirskin);
if (is_resource($handle)) {
while (($subdir = readdir($handle)) !== false) {
if (is_dir($dirskin."/".$subdir) && substr($subdir, 0, 1) != '.'
&& substr($subdir, 0, 3) != 'CVS' && !preg_match('/common|phones/i', $subdir)) {
// Disable not stable themes (dir ends with _exp or _dev)
if (getDolGlobalInt('MAIN_FEATURES_LEVEL') < 2 && preg_match('/_dev$/i', $subdir)) {
continue;
}
if (getDolGlobalInt('MAIN_FEATURES_LEVEL') < 1 && preg_match('/_exp$/i', $subdir)) {
continue;
}
print '<div class="inline-block" style="margin-top: 10px; margin-bottom: 10px; margin-right: 20px; margin-left: 20px;">';
if ($subdir == $selected_theme) {
print '<input '.($edit ? '' : 'disabled').' type="radio" '.$bc[$var].' style="border: 0px;" checked name="fckeditor_skin" value="'.$subdir.'"> <b>'.$subdir.'</b>';
} else {
print '<input '.($edit ? '' : 'disabled').' type="radio" '.$bc[$var].' style="border: 0px;" name="fckeditor_skin" value="'.$subdir.'"> '.$subdir;
}
print '</div>';
$i++;
}
}
}
}
}
print '</div></td></tr></table>';
print '</td></tr>';
print '</table>';
}