wip workstation tms (#35126)

* wip workstation tms

* wip workstation tms

* setup

* setup

* setup

* setup

* setup
This commit is contained in:
Frédéric FRANCE
2025-08-29 17:20:20 +02:00
committed by GitHub
parent b09cfab271
commit 96130d7562
7 changed files with 187 additions and 34 deletions

View File

@@ -0,0 +1,117 @@
<?php
/* Copyright (C) 2001-2002 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2003 Jean-Louis Bergamo <jlb@j1b.org>
* Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2012 Regis Houssin <regis.houssin@inodbox.com>
* Copyright (C) 2014 Florian Henry <florian.henry@open-concept.pro>
* Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
* Copyright (C) 2024-2025 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/>.
*/
/**
* \file htdocs/modulebuilder/template/admin/workstation_extrafields.php
* \ingroup workstation
* \brief Page to setup extra fields of workstation
*/
// Load Dolibarr environment
require "../main.inc.php";
require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
require_once DOL_DOCUMENT_ROOT.'/workstation/lib/workstation.lib.php';
/**
* @var Conf $conf
* @var DoliDB $db
* @var HookManager $hookmanager
* @var Translate $langs
* @var User $user
*/
// Load translation files required by the page
$langs->loadLangs(array('workstation', 'admin'));
$extrafields = new ExtraFields($db);
$form = new Form($db);
// List of supported format
$type2label = ExtraFields::getListOfTypesLabels();
$action = GETPOST('action', 'aZ09');
$attrname = GETPOST('attrname', 'alpha');
$elementtype = 'workstation_workstation'; //Must be the $table_element of the class that manage extrafield
if (!$user->admin) {
accessforbidden();
}
/*
* Actions
*/
require DOL_DOCUMENT_ROOT.'/core/actions_extrafields.inc.php';
/*
* View
*/
$textobject = $langs->transnoentitiesnoconv("Workstation");
$help_url = '';
$page_name = "WorkstationSetup";
llxHeader('', $langs->trans("WorkstationSetup"), $help_url, '', 0, 0, '', '', '', 'mod-workstation page-admin_extrafields');
$linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.img_picto($langs->trans("BackToModuleList"), 'back', 'class="pictofixedwidth"').'<span class="hideonsmartphone">'.$langs->trans("BackToModuleList").'</span></a>';
print load_fiche_titre($langs->trans($page_name), $linkback, 'title_setup');
$head = workstationAdminPrepareHead();
print dol_get_fiche_head($head, 'workstation_extrafields', $langs->trans($page_name), -1, 'workstation');
require DOL_DOCUMENT_ROOT.'/core/tpl/admin_extrafields_view.tpl.php';
print dol_get_fiche_end();
/*
* Creation of an optional field
*/
if ($action == 'create') {
print '<br><div id="newattrib"></div>';
print load_fiche_titre($langs->trans('NewAttribute'));
require DOL_DOCUMENT_ROOT.'/core/tpl/admin_extrafields_add.tpl.php';
}
/*
* Edition of an optional field
*/
if ($action == 'edit' && !empty($attrname)) {
print "<br>";
print load_fiche_titre($langs->trans("FieldEdition", $attrname));
require DOL_DOCUMENT_ROOT.'/core/tpl/admin_extrafields_edit.tpl.php';
}
// End of page
llxFooter();
$db->close();

View File

@@ -1,5 +1,5 @@
-- ===================================================================
-- Copyright (C) 2021 Frédéric France <frederic.france@netlogic.fr>
-- Copyright (C) 2021 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

View File

@@ -0,0 +1,19 @@
-- ===================================================================
-- Copyright (C) 2025 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/>.
--
-- ===================================================================
ALTER TABLE llx_workstation_workstation_extrafields ADD INDEX idx_workstation_workstation_extrafields (fk_object);

View File

@@ -0,0 +1,27 @@
-- ===================================================================
-- Copyright (C) 2025 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/.
-- ===================================================================
--
-- Table for extrafields of workstation
--
create table llx_workstation_workstation_extrafields
(
rowid integer AUTO_INCREMENT PRIMARY KEY,
tms timestamp DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
fk_object integer NOT NULL,
import_key varchar(14) -- import key
) ENGINE=innodb;

View File

@@ -1,7 +1,7 @@
<?php
/* Copyright (C) 2017 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2020 Gauthier VERDOL <gauthier.verdol@atm-consulting.fr>
* Copyright (C) 2023-2024 Frédéric France <frederic.france@free.fr>
/* Copyright (C) 2017 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2020 Gauthier VERDOL <gauthier.verdol@atm-consulting.fr>
* Copyright (C) 2023-2025 Frédéric France <frederic.france@free.fr>
* Copyright (C) 2024-2025 MDW <mdeweerd@users.noreply.github.com>
*
* This program is free software; you can redistribute it and/or modify
@@ -47,17 +47,6 @@ class Workstation extends CommonObject
*/
public $table_element = 'workstation_workstation';
/**
* @var int<0,1>|string Does this object support multicompany module ?
* 0=No test on entity, 1=Test with field entity, 'field@table'=Test with link by field@table (example 'fk_soc@societe')
*/
public $ismultientitymanaged = 1;
/**
* @var int<0,1> Does object support extrafields ? 0=No, 1=Yes
*/
public $isextrafieldmanaged = 0;
/**
* @var string String with name of icon for workstation. Must be the part after the 'object_' into object_workstation.png
*/
@@ -194,7 +183,7 @@ class Workstation extends CommonObject
$this->db = $db;
$this->ismultientitymanaged = 1;
$this->isextrafieldmanaged = 0;
$this->isextrafieldmanaged = 1;
if (!getDolGlobalString('MAIN_SHOW_TECHNICAL_ID') && isset($this->fields['rowid'])) {
$this->fields['rowid']['visible'] = 0;
@@ -800,9 +789,10 @@ class Workstation extends CommonObject
*/
public function info($id)
{
$sql = 'SELECT rowid, date_creation as datec, tms as datem,';
$sql .= ' fk_user_creat, fk_user_modif';
$sql = 'SELECT t.rowid, t.date_creation as datec, GREATEST(t.tms, tef.tms) as datem,';
$sql .= ' t.fk_user_creat, t.fk_user_modif';
$sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.$this->table_element.'_extrafields as tef ON tef.fk_object=t.rowid';
$sql .= ' WHERE t.rowid = '.((int) $id);
$result = $this->db->query($sql);
if ($result) {

View File

@@ -1,6 +1,6 @@
<?php
/* Copyright (C) 2020 Gauthier VERDOL <gauthier.verdol@atm-consulting.fr>
* Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
/* Copyright (C) 2020 Gauthier VERDOL <gauthier.verdol@atm-consulting.fr>
* Copyright (C) 2024-2025 Frédéric France <frederic.france@free.fr>
* Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
*
* This program is free software: you can redistribute it and/or modify
@@ -30,7 +30,10 @@
*/
function workstationAdminPrepareHead()
{
global $langs, $conf;
global $conf, $db, $langs;
$extrafields = new ExtraFields($db);
$extrafields->fetch_name_optionals_label('workstation_workstation');
$langs->load("workstation");
@@ -41,17 +44,14 @@ function workstationAdminPrepareHead()
$head[$h][2] = 'settings';
$h++;
/*
$head[$h][0] = dol_buildpath("/workstation/admin/myobject_extrafields.php", 1);
$head[$h][0] = DOL_URL_ROOT."/admin/workstation_extrafields.php";
$head[$h][1] = $langs->trans("ExtraFields");
$head[$h][2] = 'myobject_extrafields';
$nbExtrafields = $extrafields->attributes['workstation_workstation']['count'];
if ($nbExtrafields > 0) {
$head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbExtrafields.'</span>';
}
$head[$h][2] = 'workstation_extrafields';
$h++;
*/
/*$head[$h][0] = require_once "/admin/about.php";
$head[$h][1] = $langs->trans("About");
$head[$h][2] = 'about';
$h++;*/
// Show more tabs from modules
// Entries must be declared in modules descriptor with line

View File

@@ -1,7 +1,7 @@
<?php
/* Copyright (C) 2017 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
/* Copyright (C) 2017 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2024-2025 Frédéric France <frederic.france@free.fr>
* Copyright (C) 2025 MDW <mdeweerd@users.noreply.github.com>
*
* This program is free software; you can redistribute it and/or modify
@@ -91,7 +91,7 @@ include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be 'inclu
// Permissions
$permissiontoread = $user->hasRight('workstation', 'workstation', 'read');
$permissiontoadd = $user->hasRight('workstation', 'workstation', 'write'); // Used by the include of actions_addupdatedelete.inc.php and actions_lineupdown.inc.php
$permissiontodelete = $user->hasRight('workstation', 'workstation', 'delete') || ($permissiontoadd && isset($object->status) && $object->status == $object::STATUS_DISABLED);
$permissiontodelete = $user->hasRight('workstation', 'workstation', 'delete') || ($permissiontoadd && isset($object->status) && $object->status == Workstation::STATUS_DISABLED);
$permissionnote = $user->hasRight('workstation', 'workstation', 'write'); // Used by the include of actions_setnotes.inc.php
$permissiondellink = $user->hasRight('workstation', 'workstation', 'write'); // Used by the include of actions_dellink.inc.php
@@ -472,7 +472,7 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
// Disable / Enable
if ($permissiontoadd) {
if ($object->status == $object::STATUS_ENABLED) {
if ($object->status == Workstation::STATUS_ENABLED) {
print dolGetButtonAction('', $langs->trans('Disable'), 'default', $_SERVER['PHP_SELF'].'?id='.$object->id.'&action=disable&token='.newToken(), '', $permissiontoadd);
} else {
print dolGetButtonAction('', $langs->trans('Enable'), 'default', $_SERVER['PHP_SELF'].'?id='.$object->id.'&action=enable&token='.newToken(), '', $permissiontoadd);