]> mj.ucw.cz Git - pciids.git/blobdiff - PciIds/DBQ.pm
Administration interface works
[pciids.git] / PciIds / DBQ.pm
index 219bc08d5b83d35d5ccc941ddb8b89b304232f0b..c6de46c4bc0f6aeb01007b8de4976420cd56123b 100644 (file)
@@ -29,17 +29,18 @@ sub new( $ ) {
                'rights' => 'SELECT rightId FROM rights WHERE userId = ?',
                'newitem' => 'INSERT INTO locations (id, parent) VALUES(?, ?)',
                'newhistory' => 'INSERT INTO history (location, owner, discussion, nodename, nodenote) VALUES(?, ?, ?, ?, ?)',
-               'history' => 'SELECT history.id, history.discussion, history.time, history.nodename, history.nodenote, history.seen, users.login FROM history LEFT OUTER JOIN users ON history.owner = users.id WHERE history.location = ? ORDER BY history.time',
+               'history' => 'SELECT history.id, history.discussion, history.time, history.nodename, history.nodenote, history.seen, users.login, users.email FROM history LEFT OUTER JOIN users ON history.owner = users.id WHERE history.location = ? ORDER BY history.time',
                'admindump' => 'SELECT
-                       locations.id, locations.name, locations.note, locations.mainhistory, musers.login, main.discussion,
-                       history.id, history.discussion, history.nodename, history.nodenote, users.login
+                       locations.id, locations.name, locations.note, locations.mainhistory, musers.email, main.discussion,
+                       history.id, history.discussion, history.nodename, history.nodenote, users.email
                FROM
                        locations INNER JOIN history ON history.location = locations.id
                        LEFT OUTER JOIN users ON history.owner = users.id
                        LEFT OUTER JOIN history AS main ON locations.mainhistory = main.id
-                       LEFT OUTER JOIN users AS musers ON main.owner = musers.id WHERE history.seen = "0"
+                       LEFT OUTER JOIN users AS musers ON main.owner = musers.id
+               WHERE history.seen = "0" AND locations.id LIKE ?
                ORDER BY locations.id, history.id
-               LIMIT 15',#Dumps new discussion submits with their senders and corresponding main history and names
+               LIMIT 100',#Dumps new discussion submits with their senders and corresponding main history and names
                'delete-hist' => 'DELETE FROM history WHERE id = ?',
                'mark-checked' => 'UPDATE history SET seen = 1 WHERE id = ?',
                'delete-item' => 'DELETE FROM locations WHERE id = ?',
@@ -91,11 +92,24 @@ sub new( $ ) {
                                pending.user, pending.reason, history.time, history.location',
                'dropnotifsxmpp' => 'DELETE FROM pending WHERE notification = 1 AND EXISTS ( SELECT 1 FROM users WHERE users.id = pending.user AND nextxmpp <= ? )',
                'dropnotifsmail' => 'DELETE FROM pending WHERE notification = 0 AND EXISTS ( SELECT 1 FROM users WHERE users.id = pending.user AND nextmail <= ? )',
-               'time' => 'SELECT NOW()'
-
+               'time' => 'SELECT NOW()',
+               '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'
        } );
 }
 
+sub hasChildren( $$ ) {
+       my( $self, $parent ) = @_;
+       return scalar @{$self->query( 'hasChildren', [ $parent ] )};
+}
+
+sub hasMain( $$ ) {
+       my( $self, $id ) = @_;
+       return scalar @{$self->query( 'hasMain', [ $id ] )};
+}
+
 my %sorts = ( 'id' => 1, 'rid' => 1, 'name' => 1, 'rname' => 1 );
 
 sub nodes( $$$$ ) {
@@ -184,11 +198,14 @@ sub history( $$ ) {
 sub submitItem( $$$ ) {
        my( $self, $data, $auth ) = @_;
        my( $addr ) = ( $data->{'address'} );
+       foreach( @{$addr->addressDeps()} ) {
+               my( $dep, $error ) = @{$_};
+               return ( $error, undef ) unless defined $self->item( $dep->get(), 0 );
+       }
        return( 'exists', undef ) if( defined( $self->item( $addr->get(), 0 ) ) );
        eval {
                $self->command( 'newitem', [ $addr->get(), $addr->parent()->get() ] );
                $self->command( 'newhistory', [ $addr->get(), $auth->{'authid'}, $data->{'discussion'}, $data->{'name'}, $data->{'note'} ] );
-
        };
        if( $@ ) {
                $self->rollback();
@@ -199,12 +216,18 @@ sub submitItem( $$$ ) {
 
 sub submitHistory( $$$$ ) {
        my( $self, $data, $auth, $address ) = @_;
-       $self->command( 'newhistory', [ $address->get(), $auth->{'authid'}, $data->{'text'}, $data->{'name'}, $data->{'note'} ], 1 );
+       if( $data->{'delete'} ) {
+               $self->command( 'newhistory', [ $address->get(), $auth->{'authid'}, $data->{'text'}, '', $data->{'note'} ], 1 );
+       } else {
+               $data->{'name'} = undef if defined $data->{'name'} && $data->{'name'} eq '';
+               $self->command( 'newhistory', [ $address->get(), $auth->{'authid'}, $data->{'text'}, $data->{'name'}, $data->{'note'} ], 1 );
+       }
        return $self->last();
 }
 
-sub adminDump( $ ) {
-       return shift->query( 'admindump', [] );
+sub adminDump( $$ ) {
+       my( $self, $prefix ) = @_;
+       return $self->query( 'admindump', [ "$prefix%" ] );
 }
 
 sub deleteHistory( $$ ) {
@@ -313,4 +336,10 @@ sub dropNotifs( $$ ) {
        $self->command( 'dropnotifsxmpp', [ $time ] );
 }
 
+sub searchName( $$$ ) {
+       my( $self, $search, $prefix ) = @_;
+       return $self->query( 'searchlocalname', [ "%$search%", "$prefix/%" ] ) if defined $prefix;
+       return $self->query( 'searchname', [ "%$search%" ] );
+}
+
 1;