1 /* Copyright (C) 2000-2004 Thomas Bopp, Thorsten Hampel, Ludger Merkens
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 * $Id: read_documents.pike,v 1.1 2008/03/31 13:39:57 exodusd Exp $
19 inherit "/kernel/secure_mapping";
21 #include <attributes.h>
22 #include <exception.h>
24 //! This module keeps track about what document is read by which users.
25 //! It adds a global EVENT_DOWNLOAD and stores the user downloading
27 class read_documents : public secure_mapping{
34 mapping mReaders = ([ ]);
40 add_global_event(EVENT_DOWNLOAD, download_document, PHASE_NOTIFY);
41 LOG("table:documents - init_module()");
47 void download_document(int event, object obj, object caller)
49 object user = geteuid() || this_user();
50 array readers = get_value(obj->get_object_id());
51 if ( !arrayp(readers) ) readers = ({ });
52 if ( search(readers, user) == -1 )
53 readers += ({ user });
54 if ( mappingp(mReaders[obj]) )
55 mReaders[obj][user] = 1;
57 mReaders[obj] = ([ ]);
58 foreach( readers, object r )
61 set_value(obj->get_object_id(), readers);
64 array get_readers(object doc)
66 array readers = get_value(doc->get_object_id());
67 if ( !arrayp(readers) ) return ({ });
71 bool is_reader(object doc, object user)
73 if ( mappingp(mReaders[doc]) )
74 return mReaders[doc][user];
76 array readers = get_readers(doc);
77 int res = search(readers, user) >= 0;
80 mReaders[doc] = ([ ]);
81 foreach ( readers, object u ) {
87 string get_identifier() { return "table:read-documents"; }
88 string get_table_name() { return "read_documents"; }