'searchname' => 'SELECT l.id, l.name, p.name FROM locations AS l JOIN locations AS p ON l.parent = p.id WHERE l.name LIKE ? ORDER BY l.id',
'searchlocalname' => 'SELECT l.id, l.name, p.name FROM locations AS l JOIN locations AS p ON l.parent = p.id WHERE l.name LIKE ? AND l.id LIKE ? ORDER BY l.id',
'hasChildren' => 'SELECT DISTINCT 1 FROM locations WHERE parent = ?',
- 'hasMain' => 'SELECT DISTINCT 1 FROM locations WHERE id = ? AND mainhistory IS NOT NULL'
+ 'hasMain' => 'SELECT DISTINCT 1 FROM locations WHERE id = ? AND mainhistory IS NOT NULL',
+ 'notif-exists' => 'SELECT DISTINCT 1 FROM notifications WHERE user = ? AND ( location = ? OR ( recursive = 1 AND type <= 1 AND SUBSTR( ?, 1, LENGTH( location ) ) = location ) )'
} );
}
$self->command( 'newtime-xmpp', [ $priority, $location, $location ] );
}
+sub notifExists( $$$ ) {
+ my( $self, $user, $location ) = @_;
+ return scalar @{$self->query( 'notif-exists', [ $user, $location, $location ] )};
+}
+
sub mailNotifs( $$ ) {
my( $self, $time ) = @_;
return $self->query( 'mailout', [ $time ] );
return undef;
},
'note' => sub { return ( length shift > 1024 ) ? 'Note can not be longer than 1024 characters' : undef; },
- 'discussion' => sub { return ( length shift > 1024 ) ? 'Discussion can not be longer than 1024 characters' : undef; }
+ 'discussion' => sub { return ( length shift > 1024 ) ? 'Discussion can not be longer than 1024 characters' : undef; },
+ 'subscribe' => undef
}, [ sub { my( $data ) = @_;
my $errstr;
return undef unless( length $data->{'id'} );#No address, so let it for the first check
return genNewItemForm( $req, $args, $auth, $tables, $result, $data );
}
notify( $tables, $data->{'address'}->parent()->get(), $comName, 2, 0 );#Notify the parent (parent gets new items)
- $tables->submitNotification( $auth->{'authid'}, $data->{'address'}->get(), { 'recursive' => 0, 'notification' => 1, 'way' => 0 } );
+ $tables->submitNotification( $auth->{'authid'}, $data->{'address'}->get(), { 'recursive' => 0, 'notification' => 1, 'way' => 0 } ) if( defined $data->{'subscribe'} && $data->{'subscribe'} eq 'subscribe' );
tulog( $auth->{'authid'}, "Item created ".$data->{'address'}->get()." ".logEscape( $data->{'name'} )." ".logEscape( $data->{'note'} )." ".logEscape( $data->{'discussion'} )." $comName" );
return HTTPRedirect( $req, '/read/'.$data->{'address'}->get().'?action=list' );
} else {
[ 'input', 'Request deletion', 'checkbox', 'delete', 'value="delete"' ],
[ 'input', 'Name:', 'text', 'name', 'maxlength="200"' ],
[ 'input', 'Note:', 'text', 'note', 'maxlength="1024"' ],
+ !$tables->notifExists( $auth->{'authid'}, $address->get() ) ? [ 'input', 'Subscribe:', 'checkbox', 'subscribe', "value='subscribe' checked='checked'" ] : (),
[ 'input', '', 'submit', 'submit', 'value="Submit"' ] ], $values );
print '</table></form>';
genHtmlTail();
return undef if $delete eq 'delete';
return 'Invalid form value';
return undef;
- }
+ },
+ 'subscribe' => undef
}, [ sub { my( $data ) = @_;
return 'You must provide either name, text or request a deletion' if( ! length $data->{'name'} && ! length $data->{'text'} && ! $data->{'delete'} );
return undef;
my $hid = $tables->submitHistory( $data, $auth, $address );
tulog( $auth->{'authid'}, "Discussion created $hid ".$address->get()." ".logEscape( $data->{'name'} )." ".logEscape( $data->{'description'} )." ".logEscape( $data->{'text'} ) );
notify( $tables, $address->get(), $hid, ( defined $name && ( $name ne '' ) ) ? 1 : 0, 1 );
+ $tables->submitNotification( $auth->{'authid'}, $address->get(), { 'recursive' => 0, 'notification' => 1, 'way' => 0 } ) if( defined $data->{'subscribe'} && $data->{'subscribe'} eq 'subscribe' );
return HTTPRedirect( $req, '/read/'.$address->get().'?action=list' );
} else {
return notLoggedComplaint( $req, $args, $auth );