Files
zoneminder/web/includes/actions/ai_class.php
Isaac Connor 787722d103 feat: add AI dataset/model/class management UI to Options
Add three Options tabs (AI Datasets, AI Models, AI Classes) with full
CRUD, backed by the AI_* tables:

- List views (_options_ai_{datasets,models,classes}.php), edit modals
  (ajax/modals/ai_{dataset,model,class}.php) and action handlers
  (actions/ai_{dataset,model,class}.php).
- options.js loads the modals over ajax, wires the Add/edit buttons and
  the AI Classes dataset filter.
- options.php dispatches the new tab includes; functions.php registers
  the three tabs in the Options sub-menu with readable labels (they are
  not Config categories, so they need explicit entries).
- actions/options.php routes object=ai_* deletes to the matching
  handler; saves post directly to view=ai_*.

All tabs and actions are gated on System permission.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-02 20:24:50 -04:00

59 lines
1.9 KiB
PHP

<?php
//
// ZoneMinder web action file
// Copyright (C) 2024 ZoneMinder LLC
//
// 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 2
// 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, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
//
// AI Object Class edit actions
if (!canEdit('System')) {
ZM\Warning('Need System permissions to manage AI object classes');
return;
}
if ($action == 'save') {
if (!empty($_REQUEST['id'])) {
$dbClass = dbFetchOne('SELECT * FROM AI_Object_Classes WHERE Id=?', NULL, [$_REQUEST['id']]);
} else {
$dbClass = array();
}
$types = array();
$changes = getFormChanges($dbClass, $_REQUEST['newClass'], $types);
if (count($changes)) {
if (!empty($_REQUEST['id'])) {
dbQuery('UPDATE AI_Object_Classes SET '.implode(', ', $changes).' WHERE Id = ?',
array($_REQUEST['id']) );
} else {
dbQuery('INSERT INTO AI_Object_Classes SET '.implode(', ', $changes));
}
$refreshParent = true;
}
$redirect = '?view=options&tab=ai_classes';
} else if ($action == 'delete') {
if ( !empty($_REQUEST['markIds']) ) {
foreach ($_REQUEST['markIds'] as $Id) {
dbQuery('DELETE FROM AI_Object_Classes WHERE Id=?', array($Id));
}
$refreshParent = true;
}
$redirect = '?view=options&tab=ai_classes';
} else {
ZM\Error("Unknown action $action in saving AI Object Class");
}
?>