Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#1128 [Dashboard] clean php8 warning #1129

Open
wants to merge 10 commits into
base: develop
Choose a base branch
from
32 changes: 18 additions & 14 deletions class/saturnedashboard.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public function load_dashboard(?array $moreParams = []): array
*/
public function show_dashboard(?array $moreParams = [])
{
global $conf, $form, $langs, $moduleNameLowerCase, $user;
global $conf, $form, $langs, $moduleNameLowerCase;

$width = DolGraph::getDefaultGraphSizeForStats('width');
$height = DolGraph::getDefaultGraphSizeForStats('height');
Expand All @@ -115,10 +115,10 @@ public function show_dashboard(?array $moreParams = [])
print '<input type="hidden" name="action" value="view">';

$confName = dol_strtoupper($moduleNameLowerCase) . '_DASHBOARD_CONFIG';
$disableWidgetList = json_decode($user->conf->$confName);
$disableWidgetList = json_decode(getDolUserString($confName));
$disableWidgetList = $disableWidgetList->widgets ?? new stdClass();
$dashboardWidgetsArray = [];
if (is_array($dashboards['widgets']) && !empty($dashboards['widgets'])) {
if (isset($dashboards['widgets']) && is_array($dashboards['widgets'])) {
foreach ($dashboards['widgets'] as $dashboardWidgets) {
foreach ($dashboardWidgets as $key => $dashboardWidget) {
if (isset($disableWidgetList->$key) && $disableWidgetList->$key == 0) {
Expand All @@ -136,7 +136,7 @@ public function show_dashboard(?array $moreParams = [])
}
print '</div>';

if (is_array($dashboards['widgets']) && !empty($dashboards['widgets'])) {
if (isset($dashboards['widgets']) && is_array($dashboards['widgets'])) {
$widget = '';
foreach ($dashboards['widgets'] as $dashboardWidgets) {
foreach ($dashboardWidgets as $key => $dashboardWidget) {
Expand Down Expand Up @@ -179,7 +179,7 @@ public function show_dashboard(?array $moreParams = [])
}
}
$widget .= '</ul>';
if (is_array($dashboardWidget['moreParams']) && (!empty($dashboardWidget['moreParams']))) {
if (!empty($dashboardWidget['moreParams']) && is_array($dashboardWidget['moreParams'])) {
$widget .= '<div class="body__content">';
foreach ($dashboardWidget['moreParams'] as $dashboardWidgetMoreParamsKey => $dashboardWidgetMoreParams) {
switch ($dashboardWidgetMoreParamsKey) {
Expand Down Expand Up @@ -248,7 +248,7 @@ public function show_dashboard(?array $moreParams = [])

print '<div class="graph-dashboard wpeo-grid grid-2" id="graph-dashboard">';

if (is_array($dashboards['graphs']) && !empty($dashboards['graphs'])) {
if (isset($dashboards['graphs']) && is_array($dashboards['graphs'])) {
foreach ($dashboards['graphs'] as $dashboardGraphs) {
if (is_array($dashboardGraphs) && !empty($dashboardGraphs)) {
foreach ($dashboardGraphs as $keyElement => $dashboardGraph) {
Expand Down Expand Up @@ -315,8 +315,8 @@ public function show_dashboard(?array $moreParams = [])
$graph->SetHeight($dashboardGraph['height'] ?? $height);
$graph->setShowLegend($dashboardGraph['showlegend'] ?? 2);
$graph->draw($fileName[$uniqueKey], $fileUrl[$uniqueKey]);
print '<div class="' . $dashboardGraph['moreCSS'] . '" id="graph-' . $dashboardGraph['name'] . '">';
print '<div' . (isset($dashboardGraph['moreCSS']) ? ' class="' . $dashboardGraph['moreCSS'] . '"' : '') . ' id="graph-' . $dashboardGraph['name'] . '">';

$downloadCSV = '<div class="flex flex-row justify-end">';
$downloadCSV .= '<input type="hidden" name="graph" value="' . dol_escape_htmltag(json_encode($dashboardGraph, JSON_UNESCAPED_UNICODE)) . '">';
$downloadCSV .= '<button class="wpeo-button no-load button-grey" id="export-csv" data-graph-name="' . dol_sanitizeFileName(dol_strtolower($dashboardGraph['title'])) . '">';
Expand All @@ -328,8 +328,12 @@ public function show_dashboard(?array $moreParams = [])
$downloadCSV .= '</button>';
}
$downloadCSV .= '</div>';
$dashboardGraph['morehtmlright'] .= $downloadCSV;

if (isset($dashboardGraph['morehtmlright'])) {
$dashboardGraph['morehtmlright'] .= $downloadCSV;
} else {
$dashboardGraph['morehtmlright'] = $downloadCSV;
}

print load_fiche_titre($dashboardGraph['title'], $dashboardGraph['morehtmlright'], $dashboardGraph['picto']);
print $graph->show();
print '</div>';
Expand All @@ -340,19 +344,19 @@ public function show_dashboard(?array $moreParams = [])
}
}

if (is_array($dashboards['lists']) && !empty($dashboards['lists'])) {
if (isset($dashboards['lists']) && is_array($dashboards['lists'])) {
foreach ($dashboards['lists'] as $dashboardLists) {
foreach ($dashboardLists as $dashboardList) {
if (is_array($dashboardList['data']) && !empty($dashboardList['data'])) {
print '<div id="graph-' . $dashboardList['name'] . '" style="width: 100%">';
print '<div id="graph-' . ($dashboardList['name'] ?? '') . '" style="width: 100%">';

if (!empty($dashboardList['name'])) {
$dashboardList['morehtmlright'] = '<button class="wpeo-button button-transparent" type="button" data-item-type="graph" data-item-name="' . $dashboardList['name'] . '" data-item-suppress="graph-' . $dashboardList['name'] . '" data-item-refresh="add-graph-box" id="dashboard-close-item">';
$dashboardList['morehtmlright'] .= img_picto('Close', 'fontawesome_times_fas_light-grey_1em', '', '', '', '', '', 'close-dashboard-widget');
$dashboardList['morehtmlright'] .= '</button>';
}

print load_fiche_titre($dashboardList['title'], $dashboardList['morehtmlright'], $dashboardList['picto']);
print load_fiche_titre($dashboardList['title'], $dashboardList['morehtmlright'] ?? '', $dashboardList['picto'] ?? '');
print '<table class="noborder centpercent">';
print '<tr class="liste_titre">';
foreach ($dashboardList['labels'] as $key => $dashboardListLabel) {
Expand All @@ -362,7 +366,7 @@ public function show_dashboard(?array $moreParams = [])
foreach ($dashboardList['data'] as $dashboardListDatasets) {
print '<tr class="oddeven">';
foreach ($dashboardListDatasets as $key => $dashboardGraphDataset) {
print '<td class="' . ($conf->browser->layout == 'classic' ? 'nowraponall tdoverflowmax200 ' : '') . (($key != 'Ref') ? 'center ' : '') . $dashboardGraphDataset['morecss'] . '"' . $dashboardGraphDataset['moreAttr'] . '>' . $dashboardGraphDataset['value'] . '</td>';
print '<td class="' . ($conf->browser->layout == 'classic' ? 'nowraponall tdoverflowmax200 ' : '') . (($key != 'Ref') ? 'center ' : '') . ($dashboardGraphDataset['morecss'] ?? '') . '"' . ($dashboardGraphDataset['moreAttr'] ?? '') . '>' . $dashboardGraphDataset['value'] . '</td>';
}
print '</tr>';
}
Expand Down
2 changes: 1 addition & 1 deletion class/saturneobject.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ public function fetchAll(string $sortorder = '', string $sortfield = '', int $li
foreach ($filter as $key => $value) {
if ($key == 't.rowid') {
$sqlwhere[] = $key . ' = ' . ((int) $value);
} elseif (in_array($this->fields[$key]['type'], ['date', 'datetime', 'timestamp'])) {
} elseif (isset($this->fields[$key]['type']) && in_array($this->fields[$key]['type'], ['date', 'datetime', 'timestamp'])) {
$sqlwhere[] = $key . " = '" . $this->db->idate($value) . "'";
} elseif ($key == 'customsql') {
$sqlwhere[] = $value;
Expand Down
2 changes: 1 addition & 1 deletion class/saturnesignature.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ public function fetchAll(string $sortorder = '', string $sortfield = '', int $li
foreach ($filter as $key => $value) {
if ($key == 't.rowid') {
$sqlwhere[] = $key . '=' . $value;
} elseif (in_array($this->fields[$key]['type'], ['date', 'datetime', 'timestamp'])) {
} elseif (isset($this->fields[$key]['type']) && in_array($this->fields[$key]['type'], ['date', 'datetime', 'timestamp'])) {
$sqlwhere[] = $key . ' = \'' . $this->db->idate($value) . '\'';
} elseif ($key == 'customsql') {
$sqlwhere[] = $value;
Expand Down
5 changes: 2 additions & 3 deletions class/task/saturnetask.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,10 @@ public function __construct($db)
*/
public function load_dashboard($projectId): array
{
global $user, $langs;
global $langs;

$confName = dol_strtoupper($this->module) . '_DASHBOARD_CONFIG';
$dashboardConfig = json_decode($user->conf->$confName);
$dashboardConfig = json_decode(getDolUserString($confName));
$array = ['graphs' => [], 'disabledGraphs' => []];

if (empty($dashboardConfig->graphs->TasksRepartition->hide)) {
Expand Down Expand Up @@ -346,7 +346,6 @@ public function fetchAllTimeSpentAllUsers($morewherefilter = '', $sortfield = ''
$newobj->fk_project = $obj->project_id;
$newobj->project_ref = $obj->project_ref;
$newobj->project_label = $obj->project_label;
$newobj->public = $obj->project_public;

$newobj->fk_task = $obj->task_id;
$newobj->task_ref = $obj->task_ref;
Expand Down
2 changes: 1 addition & 1 deletion core/tpl/index/index_view.tpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@

saturne_header(0, '', $title . ' ' . $modModule->version, $helpUrl);

print load_fiche_titre($title . ' ' . $modModule->version, $morehtmlright, $moduleNameLowerCase . '_color.png@' . $moduleNameLowerCase);
print load_fiche_titre($title . ' ' . $modModule->version, $morehtmlright ?? '', $moduleNameLowerCase . '_color.png@' . $moduleNameLowerCase);

$moduleJustUpdated = strtoupper($moduleName) . '_JUST_UPDATED';
$moduleVersion = strtoupper($moduleName) . '_VERSION';
Expand Down
12 changes: 6 additions & 6 deletions core/tpl/medias/medias_gallery_modal.tpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -359,18 +359,18 @@
<div>
<div>
<?php print img_picto($langs->trans('Link'), 'link') . ' ' . $form->textwithpicto($langs->trans('UnlinkedMedias'), $langs->trans('ShowOnlyUnlinkedMedias'));
if (isset($user->conf->SATURNE_MEDIA_GALLERY_SHOW_UNLINKED_MEDIAS) && $user->conf->SATURNE_MEDIA_GALLERY_SHOW_UNLINKED_MEDIAS) {
print '<span id="del_unlinked_medias" value="0" class="valignmiddle linkobject toggle-unlinked-medias ' . (!empty($user->conf->SATURNE_MEDIA_GALLERY_SHOW_UNLINKED_MEDIAS) ? '' : 'hideobject') . '">' . img_picto($langs->trans('Enabled'), 'switch_on') . '</span>';
if (getDolUserInt('SATURNE_MEDIA_GALLERY_SHOW_UNLINKED_MEDIAS')) {
print '<span id="del_unlinked_medias" value="0" class="valignmiddle linkobject toggle-unlinked-medias ' . (getDolUserInt('SATURNE_MEDIA_GALLERY_SHOW_UNLINKED_MEDIAS') ? '' : 'hideobject') . '">' . img_picto($langs->trans('Enabled'), 'switch_on') . '</span>';
} else {
print '<span id="set_unlinked_medias" value="1" class="valignmiddle linkobject toggle-unlinked-medias ' . (!empty($user->conf->SATURNE_MEDIA_GALLERY_SHOW_UNLINKED_MEDIAS) ? 'hideobject' : '') . '">' . img_picto($langs->trans('Disabled'), 'switch_off') . '</span>';
print '<span id="set_unlinked_medias" value="1" class="valignmiddle linkobject toggle-unlinked-medias ' . (getDolUserInt('SATURNE_MEDIA_GALLERY_SHOW_UNLINKED_MEDIAS') ? 'hideobject' : '') . '">' . img_picto($langs->trans('Disabled'), 'switch_off') . '</span>';
} ?>
</div>
<div>
<?php print img_picto($langs->trans('Calendar'), 'calendar') . ' ' . $form->textwithpicto($langs->trans('Today'), $langs->trans('ShowOnlyMediasAddedToday'));
if (isset($user->conf->SATURNE_MEDIA_GALLERY_SHOW_TODAY_MEDIAS) && $user->conf->SATURNE_MEDIA_GALLERY_SHOW_TODAY_MEDIAS) {
print '<span id="del_today_medias" value="0" class="valignmiddle linkobject toggle-today-medias ' . (!empty($user->conf->SATURNE_MEDIA_GALLERY_SHOW_TODAY_MEDIAS) ? '' : 'hideobject') . '">' . img_picto($langs->trans('Enabled'), 'switch_on') . '</span>';
if (getDolUserInt('SATURNE_MEDIA_GALLERY_SHOW_TODAY_MEDIAS')) {
print '<span id="del_today_medias" value="0" class="valignmiddle linkobject toggle-today-medias ' . (getDolUserInt('SATURNE_MEDIA_GALLERY_SHOW_TODAY_MEDIAS') ? '' : 'hideobject') . '">' . img_picto($langs->trans('Enabled'), 'switch_on') . '</span>';
} else {
print '<span id="set_today_medias" value="1" class="valignmiddle linkobject toggle-today-medias ' . (!empty($user->conf->SATURNE_MEDIA_GALLERY_SHOW_TODAY_MEDIAS) ? 'hideobject' : '') . '">' . img_picto($langs->trans('Disabled'), 'switch_off') . '</span>';
print '<span id="set_today_medias" value="1" class="valignmiddle linkobject toggle-today-medias ' . (getDolUserInt('SATURNE_MEDIA_GALLERY_SHOW_TODAY_MEDIAS') ? 'hideobject' : '') . '">' . img_picto($langs->trans('Disabled'), 'switch_off') . '</span>';
} ?>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion lib/documents.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ function saturne_show_documents(string $modulepart, $modulesubdir, $filedir, str

// Preview
if (!empty($conf->use_javascript_ajax) && ($conf->browser->layout != 'phone')) {
$tmparray = getAdvancedPreviewUrl($modulepart, $relativepath, 1, '&entity=' . $entity);
$tmparray = getAdvancedPreviewUrl($modulepart, $relativepath, 1, '&entity=' . $conf->entity);
if ($tmparray && $tmparray['url']) {
$out .= '<a href="'.$tmparray['url'].'"'.($tmparray['css'] ? ' class="'.$tmparray['css'].'"' : '').($tmparray['mime'] ? ' mime="'.$tmparray['mime'].'"' : '').($tmparray['target'] ? ' target="'.$tmparray['target'].'"' : '').'>';
//$out.= img_picto('','detail');
Expand Down
21 changes: 12 additions & 9 deletions lib/medias.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ function saturne_show_medias(string $moduleName, string $modulepart = 'ecm', str

$filearray = dol_dir_list($dir, 'files', 0, '', '(\.meta|_preview.*\.png)$', $sortfield, (strtolower($sortorder) == 'desc' ? SORT_DESC : SORT_ASC));

if ($user->conf->SATURNE_MEDIA_GALLERY_SHOW_TODAY_MEDIAS == 1) {
if (getDolUserInt('SATURNE_MEDIA_GALLERY_SHOW_TODAY_MEDIAS')) {
$yesterdayTimeStamp = dol_time_plus_duree(dol_now(), -1, 'd');
$filearray = array_filter($filearray, function($file) use ($yesterdayTimeStamp) {
return $file['date'] > $yesterdayTimeStamp;
});
}
if ($user->conf->SATURNE_MEDIA_GALLERY_SHOW_UNLINKED_MEDIAS == 1) {
if (getDolUserInt('SATURNE_MEDIA_GALLERY_SHOW_UNLINKED_MEDIAS')) {
$moduleObjectMedias = dol_dir_list($conf->$moduleNameLowerCase->multidir_output[$conf->entity ?? 1], 'files', 1, '', '.odt|.pdf|barcode|_mini|_medium|_small|_large');
$filearray = array_filter($filearray, function($file) use ($conf, $moduleNameLowerCase, $moduleObjectMedias) {
$fileExists = array_search($file['name'], array_column($moduleObjectMedias, 'name'));
Expand All @@ -71,10 +71,11 @@ function saturne_show_medias(string $moduleName, string $modulepart = 'ecm', str
$filearray = dol_sort_array($filearray, $sortfield, $sortorder);
}

$moduleImageNumberPerPageConf = strtoupper($moduleName) . '_DISPLAY_NUMBER_MEDIA_GALLERY';
for ($i = (($offset - 1) * $conf->global->$moduleImageNumberPerPageConf); $i < ($conf->global->$moduleImageNumberPerPageConf + (($offset - 1) * $conf->global->$moduleImageNumberPerPageConf)); $i++) {
$confName = strtoupper($moduleName) . '_DISPLAY_NUMBER_MEDIA_GALLERY';
$moduleImageNumberPerPageConf = getDolGlobalInt($confName);
for ($i = (($offset - 1) * $moduleImageNumberPerPageConf); $i < ($moduleImageNumberPerPageConf + (($offset - 1) * $moduleImageNumberPerPageConf)); $i++) {

$fileName = $filearray[$i]['name'];
$fileName = $filearray[$i]['name'] ?? '';
if (image_format_supported($fileName) >= 0) {
$nbphoto++;

Expand Down Expand Up @@ -343,7 +344,7 @@ function saturne_show_medias_linked(string $modulepart = 'ecm', string $sdir, $s
}
}
} else {
$return .= '<img width="' . $maxWidth . '" height="' . $maxHeight . '" class="photo '. $morecss .' photowithmargin" src="' . DOL_URL_ROOT . '/public/theme/common/nophoto.png" title="' . $langs->trans('NoPhotoYet') . '" data-object-id="' . $object->id . '">';
$return .= '<img width="' . $maxWidth . '" height="' . $maxHeight . '" class="photo '. $morecss .' photowithmargin" src="' . DOL_URL_ROOT . '/public/theme/common/nophoto.png" title="' . $langs->trans('NoPhotoYet') . '" data-object-id="' . (!empty($object) ? $object->id : '') . '">';
}

if (is_object($object)) {
Expand Down Expand Up @@ -371,7 +372,7 @@ function saturne_get_thumb_name(string $filename, string $thumbType = 'small'):
* Return media linked elements count
*
* @param string $moduleName Module name
* @param string $fileName File name
* @param string $fileName File name
* @return string $output Show media linked element count
*
*/
Expand All @@ -398,14 +399,16 @@ function saturne_get_media_linked_elements(string $moduleName, string $fileName)
$object = new $className($db);

$mediaLinkedElements[$fileArray['name']][$element[0]]['picto'] = $object->picto;
$mediaLinkedElements[$fileArray['name']][$element[0]]['value']++;
if (isset($mediaLinkedElements[$fileArray['name']][$element[0]]['value'])) {
$mediaLinkedElements[$fileArray['name']][$element[0]]['value']++;
}
}

$output = '<div class="linked-element">';
foreach ($mediaLinkedElements as $mediaLinkedElement) {
foreach ($mediaLinkedElement as $key => $linkedElement) {
$output .= '<span class="paddingleft paddingright">' . img_picto($langs->trans(ucfirst($key)), $linkedElement['picto'], 'class="paddingright"');
$output .= $linkedElement['value'];
$output .= $linkedElement['value'] ?? 0;
$output .= '</span>';
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/object.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ function saturne_fetch_all_object_type(string $className = '', string $sortorder
foreach ($filter as $key => $value) {
if ($key == 't.rowid') {
$sqlwhere[] = $key . ' = ' . $value;
} elseif (in_array($object->fields[$key]['type'], ['date', 'datetime', 'timestamp'])) {
} elseif (isset($object->fields[$key]['type']) && in_array($object->fields[$key]['type'], ['date', 'datetime', 'timestamp'])) {
$sqlwhere[] = $key .' = \'' . $object->db->idate($value) . '\'';
} elseif ($key == 'customsql') {
$sqlwhere[] = $value;
Expand Down
Loading