mirror of
https://github.com/ZoneMinder/zoneminder.git
synced 2026-11-30 12:14:36 -05:00
Merge pull request #5759 from AJ0070/tag-fixes
fix: tag name encoding, create/add errors and negated tag filters
This commit is contained in:
4 files changed
+22
-9
No files matched your search
+3
-1
@@ -250,7 +250,9 @@ if ( canEdit('Events') ) {
|
||||
if ($tagId === '') ajaxError('addtag requires a numeric tid and id');
|
||||
$eventId = $Event->Id();
|
||||
|
||||
$sql = 'INSERT INTO Events_Tags (TagId, EventId, AssignedBy) VALUES (?, ?, ?)';
|
||||
if (!dbFetchOne('SELECT Id FROM Tags WHERE Id = ?', 'Id', array($tagId))) ajaxError('No such tag');
|
||||
|
||||
$sql = 'INSERT IGNORE INTO Events_Tags (TagId, EventId, AssignedBy) VALUES (?, ?, ?)';
|
||||
$values = array($tagId, $eventId, $user->Id());
|
||||
$response = dbFetchAll($sql, NULL, $values);
|
||||
|
||||
|
||||
+12
-6
@@ -42,13 +42,19 @@ switch ( $_REQUEST['action'] ) {
|
||||
if (!canEdit('Events')) {
|
||||
ajaxError('Insufficient permissions to create tags');
|
||||
}
|
||||
$sql = 'INSERT INTO Tags (Name, CreatedBy) VALUES (?, ?)';
|
||||
$values = array($_REQUEST['tname'], $user->Id());
|
||||
$result = dbFetchAll($sql, NULL, $values);
|
||||
$tagName = is_scalar($_REQUEST['tname'] ?? null) ? trim($_REQUEST['tname']) : '';
|
||||
if ($tagName === '') ajaxError('createtag requires a tag name');
|
||||
|
||||
$sql = 'SELECT * FROM Tags WHERE Id = ?';
|
||||
$values = array(dbInsertId());
|
||||
$dbFetchResult = dbFetchAll($sql, NULL, $values);
|
||||
$dbFetchResult = dbFetchAll('SELECT * FROM Tags WHERE Name = ?', NULL, array($tagName));
|
||||
if (!count($dbFetchResult)) {
|
||||
$sql = 'INSERT INTO Tags (Name, CreatedBy) VALUES (?, ?)';
|
||||
$values = array($tagName, $user->Id());
|
||||
if (!dbQuery($sql, $values)) ajaxError('Failed to create tag');
|
||||
|
||||
$sql = 'SELECT * FROM Tags WHERE Id = ?';
|
||||
$values = array(dbInsertId());
|
||||
$dbFetchResult = dbFetchAll($sql, NULL, $values);
|
||||
}
|
||||
|
||||
ajaxResponse(array('response'=>$dbFetchResult));
|
||||
break;
|
||||
|
||||
@@ -473,7 +473,12 @@ class FilterTerm {
|
||||
|
||||
$operator = $this->sql_operator();
|
||||
$values = $this->sql_values();
|
||||
if ((count($values) > 1) and !(($operator == ' IN ') or ($operator == ' NOT IN ') or ($operator == ' =[] ') or ($operator == ' ![] '))) {
|
||||
if (($this->attr === 'Tags') and count($values) and !array_intersect($values, ["'0'", "'-1'"])
|
||||
and in_array($operator, [' = ', ' != ', ' IN ', ' NOT IN ', ' =[] ', ' ![] '])) {
|
||||
// Comparing the joined tag row by row gets "is not" wrong for events with several tags or none.
|
||||
$negate = in_array($operator, [' != ', ' NOT IN ', ' ![] ']);
|
||||
$sql .= ($negate ? 'NOT ' : '').'EXISTS (SELECT NULL FROM Events_Tags AS ET WHERE ET.EventId = E.Id AND ET.TagId IN ('.join(',', $values).'))';
|
||||
} elseif ((count($values) > 1) and !(($operator == ' IN ') or ($operator == ' NOT IN ') or ($operator == ' =[] ') or ($operator == ' ![] '))) {
|
||||
$subterms = [];
|
||||
foreach ($values as $value) {
|
||||
$subterm = $this->sql_attr();
|
||||
|
||||
@@ -2112,7 +2112,7 @@ function removeTag(tag) {
|
||||
|
||||
function createTag(tagName, buttonPressed = null) {
|
||||
if (!canEdit.Events) return;
|
||||
$j.getJSON(thisUrl + '?request=tags&action=createtag&tname=' + tagName)
|
||||
$j.getJSON(thisUrl + '?request=tags&action=createtag&tname=' + encodeURIComponent(tagName))
|
||||
.done(function(data) {
|
||||
if (data.result != 'Ok') {
|
||||
console.error('createtag refused', data.message);
|
||||
|
||||
Reference in new issue
Block a user