dolibarr.netdiag/netdiagindex.php
Eduard Wisch c576726a26
Some checks are pending
Deploy netdiag / deploy (push) Waiting to run
Initiales Commit — Dolibarr-Modul NetDiag [deploy]
Netzwerk-Diagnose-Modul mit JSON-API für die NetDiag-App:
- 3 Tabellen (protocol/device/measurement), generisches JSON-result
- JSON-API: auth, customers, orders, protocols (idempotenter Sync), pdf
- JWT-Auth (HS256), CORS für die Capacitor-App
- Tabs an Thirdparty + Auftrag, Protokoll-Card, PDF-Generator
- QR-Code zum App-Download in der Modul-Konfiguration
- de_DE + en_US, Rechtesystem netdiag->protocol read/write/delete

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-19 12:12:11 +02:00

158 lines
5.4 KiB
PHP

<?php
/* Copyright (C) 2026 Eduard Wisch <data@data-it-solution.de>
*
* 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 netdiag/netdiagindex.php
* \ingroup netdiag
* \brief Liste aller Netzwerk-Diagnose-Protokolle (Backend)
*/
// Dolibarr-Umgebung laden
$res = 0;
if (!$res && !empty($_SERVER["CONTEXT_DOCUMENT_ROOT"])) {
$res = @include $_SERVER["CONTEXT_DOCUMENT_ROOT"]."/main.inc.php";
}
$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";
}
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");
}
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
require_once __DIR__.'/class/netdiagprotocol.class.php';
/**
* @var DoliDB $db
* @var Translate $langs
* @var User $user
*/
$langs->loadLangs(array("netdiag@netdiag", "companies", "orders"));
if (!$user->hasRight('netdiag', 'protocol', 'read')) {
accessforbidden();
}
$search_ref = GETPOST('search_ref', 'alpha');
$search_soc = GETPOST('search_soc', 'alpha');
$limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit;
$page = GETPOSTINT('page');
if ($page < 0) {
$page = 0;
}
$offset = $limit * $page;
/*
* Ansicht
*/
$form = new Form($db);
$title = $langs->trans("NetDiagProtocols");
llxHeader('', $title, '', '', 0, 0, '', '', '', 'mod-netdiag page-list');
// Datensätze laden
$sql = "SELECT p.rowid, p.ref, p.label, p.date_diag, p.standort, p.subnet, p.status,";
$sql .= " s.rowid as socid, s.nom as socname,";
$sql .= " (SELECT COUNT(*) FROM ".$db->prefix()."netdiag_device d WHERE d.fk_protocol = p.rowid) as devcount";
$sql .= " FROM ".$db->prefix()."netdiag_protocol as p";
$sql .= " LEFT JOIN ".$db->prefix()."societe as s ON s.rowid = p.fk_soc";
$sql .= " WHERE p.entity IN (".getEntity('netdiagprotocol').")";
if ($search_ref) {
$sql .= natural_search('p.ref', $search_ref);
}
if ($search_soc) {
$sql .= natural_search('s.nom', $search_soc);
}
$sql .= " ORDER BY p.date_diag DESC, p.rowid DESC";
$sql .= $db->plimit($limit, $offset);
$resql = $db->query($sql);
$rows = array();
if ($resql) {
while ($obj = $db->fetch_object($resql)) {
$rows[] = $obj;
}
}
print load_fiche_titre($title, '', 'fa-network-wired');
print '<form method="GET" action="'.$_SERVER["PHP_SELF"].'">';
print '<div class="div-table-responsive">';
print '<table class="tagtable liste">';
print '<tr class="liste_titre">';
print '<td><input type="text" name="search_ref" class="maxwidth100" value="'.dol_escape_htmltag($search_ref).'" placeholder="'.$langs->trans("Ref").'"></td>';
print '<td><input type="text" name="search_soc" class="maxwidth150" value="'.dol_escape_htmltag($search_soc).'" placeholder="'.$langs->trans("ThirdParty").'"></td>';
print '<td colspan="4" class="right"><input type="submit" class="button small" value="'.$langs->trans("Search").'"></td>';
print '</tr>';
print '<tr class="liste_titre">';
print '<th>'.$langs->trans("Ref").'</th>';
print '<th>'.$langs->trans("ThirdParty").'</th>';
print '<th>'.$langs->trans("DateDiag").'</th>';
print '<th>'.$langs->trans("Location").'</th>';
print '<th class="right">'.$langs->trans("NetDiagDevices").'</th>';
print '<th class="center">'.$langs->trans("Status").'</th>';
print '</tr>';
$proto = new NetDiagProtocol($db);
foreach ($rows as $obj) {
$proto->id = $obj->rowid;
$proto->status = $obj->status;
$cardurl = dol_buildpath('/netdiag/netdiagprotocol_card.php', 1).'?id='.$obj->rowid;
print '<tr class="oddeven">';
print '<td><a href="'.$cardurl.'">'.img_picto('', 'fa-network-wired').' '.dol_escape_htmltag($obj->ref).'</a></td>';
if ($obj->socid) {
print '<td><a href="'.DOL_URL_ROOT.'/societe/card.php?socid='.$obj->socid.'">'.dol_escape_htmltag($obj->socname).'</a></td>';
} else {
print '<td></td>';
}
print '<td>'.dol_print_date($db->jdate($obj->date_diag), 'dayhour').'</td>';
print '<td>'.dol_escape_htmltag($obj->standort).'</td>';
print '<td class="right">'.((int) $obj->devcount).'</td>';
print '<td class="center">'.$proto->getLibStatut(3).'</td>';
print '</tr>';
}
if (empty($rows)) {
print '<tr><td colspan="6" class="opacitymedium center">'.$langs->trans("NoRecordFound").'</td></tr>';
}
print '</table>';
print '</div>';
print '</form>';
llxFooter();
$db->close();