Index: pykota/trunk/pykota/reporters/html.py
===================================================================
--- pykota/trunk/pykota/reporters/html.py (revision 1257)
+++ pykota/trunk/pykota/reporters/html.py (revision 1274)
@@ -22,4 +22,7 @@
 #
 # $Log$
+# Revision 1.6  2004/01/12 14:35:01  jalet
+# Printing history added to CGI script.
+#
 # Revision 1.5  2004/01/08 14:10:33  jalet
 # Copyright year changed.
@@ -37,4 +40,5 @@
 #
 
+import os
 from mx import DateTime
 
@@ -75,4 +79,6 @@
                     else :    
                         oddevenclass = "warn"
+                if not self.tool.config.getDisableHistory() :
+                    name = '<a href="%s?username=%s&printername=%s&history=1">%s</a>' % (os.environ.get("SCRIPT_NAME", ""), name, printer.Name, name)
                 self.report.append('<tr class="%s">%s</tr>' % (oddevenclass, "".join(["<td>%s</td>" % h for h in (name, reached, pagecounter, soft, hard, balance, datelimit or "&nbsp;", lifepagecounter, lifetimepaid)])))
                 total += pages
Index: pykota/trunk/pykota/storages/pgstorage.py
===================================================================
--- pykota/trunk/pykota/storages/pgstorage.py (revision 1269)
+++ pykota/trunk/pykota/storages/pgstorage.py (revision 1274)
@@ -22,4 +22,7 @@
 #
 # $Log$
+# Revision 1.32  2004/01/12 14:35:02  jalet
+# Printing history added to CGI script.
+#
 # Revision 1.31  2004/01/10 09:44:02  jalet
 # Fixed potential accuracy problem if a user printed on several printers at
@@ -128,5 +131,5 @@
 #
 
-from pykota.storage import PyKotaStorageError,BaseStorage,StorageObject,StorageUser,StorageGroup,StoragePrinter,StorageLastJob,StorageUserPQuota,StorageGroupPQuota
+from pykota.storage import PyKotaStorageError,BaseStorage,StorageObject,StorageUser,StorageGroup,StoragePrinter,StorageJob,StorageLastJob,StorageUserPQuota,StorageGroupPQuota
 
 try :
@@ -533,4 +536,41 @@
             self.doModify("INSERT INTO printergroupsmembers (groupid, printerid) VALUES (%s, %s)" % (self.doQuote(pgroup.ident), self.doQuote(printer.ident)))
         
+    def retrieveHistory(self, user=None, printer=None, datelimit=None, limit=100) :    
+        """Retrieves all print jobs for user on printer (or all) before date, limited to first 100 results."""
+        query = "SELECT * FROM jobhistory"
+        where = []
+        if (user is not None) and user.Exists :
+            where.append("userid=%s" % self.doQuote(user.ident))
+        if (printer is not None) and printer.Exists :
+            where.append("printerid=%s" % self.doQuote(printer.ident))
+        if datelimit is not None :    
+            where.append("jobdate<=%s" % self.doQuote(datelimit))
+        if where :    
+            query += "WHERE %s" % " AND ".join(where)
+        query += " ORDER BY id DESC"
+        if limit :
+            query += " LIMIT %s" % self.doQuote(int(limit))
+        jobs = []    
+        result = self.doSearch(query)    
+        if result :
+            for fields in result :
+                job = StorageJob(self)
+                job.ident = fields.get("id")
+                job.JobId = fields.get("jobid")
+                job.PrinterPageCounter = fields.get("pagecounter")
+                job.JobSize = fields.get("jobsize")
+                job.JobPrice = fields.get("jobprice")
+                job.JobAction = fields.get("action")
+                job.JobFileName = fields.get("filename")
+                job.JobTitle = fields.get("title")
+                job.JobCopies = fields.get("copies")
+                job.JobOptions = fields.get("options")
+                job.JobDate = fields.get("jobdate")
+                job.User = self.getUser(fields.get("userid"))
+                job.Printer = self.getPrinter(fields.get("printerid"))
+                job.Exists = 1
+                jobs.append(job)
+        return jobs
+        
     def deleteUser(self, user) :    
         """Completely deletes an user from the Quota Storage."""
Index: pykota/trunk/pykota/storages/ldapstorage.py
===================================================================
--- pykota/trunk/pykota/storages/ldapstorage.py (revision 1269)
+++ pykota/trunk/pykota/storages/ldapstorage.py (revision 1274)
@@ -22,4 +22,7 @@
 #
 # $Log$
+# Revision 1.48  2004/01/12 14:35:02  jalet
+# Printing history added to CGI script.
+#
 # Revision 1.47  2004/01/10 09:44:02  jalet
 # Fixed potential accuracy problem if a user printed on several printers at
@@ -192,5 +195,5 @@
 import md5
 
-from pykota.storage import PyKotaStorageError,BaseStorage,StorageObject,StorageUser,StorageGroup,StoragePrinter,StorageLastJob,StorageUserPQuota,StorageGroupPQuota
+from pykota.storage import PyKotaStorageError,BaseStorage,StorageObject,StorageUser,StorageGroup,StoragePrinter,StorageJob,StorageLastJob,StorageUserPQuota,StorageGroupPQuota
 
 try :
@@ -861,4 +864,49 @@
                      }  
             self.doModify(pgroup.ident, fields)         
+            
+    def retrieveHistory(self, user=None, printer=None, datelimit=None, limit=100) :    
+        """Retrieves all print jobs for user on printer (or all) before date, limited to first 100 results."""
+        precond = "(objectClass=pykotaJob)"
+        where = []
+        if (user is not None) and user.Exists :
+            where.append("(pykotaUserName=%s)" % user.Name)
+        if (printer is not None) and printer.Exists :
+            where.append("(pykotaPrinterName=%s)" % printer.Name)
+        if where :    
+            where = "(&%s)" % "".join([precond] + where)
+        else :    
+            where = precond
+        jobs = []    
+        result = self.doSearch(where, fields=["pykotaUserName", "pykotaPrinterName", "pykotaJobId", "pykotaPrinterPageCounter", "pykotaAction", "pykotaJobSize", "pykotaJobPrice", "pykotaFileName", "pykotaTitle", "pykotaCopies", "pykotaOptions", "createTimestamp"], base=self.info["jobbase"])
+        if result :
+            for (ident, fields) in result :
+                job = StorageJob(self)
+                job.ident = ident
+                job.JobId = fields.get("pykotaJobId")[0]
+                job.PrinterPageCounter = int(fields.get("pykotaPrinterPageCounter")[0] or 0)
+                job.JobSize = int(fields.get("pykotaJobSize", [0])[0])
+                job.JobPrice = float(fields.get("pykotaJobPrice", [0.0])[0])
+                job.JobAction = fields.get("pykotaAction")[0]
+                job.JobFileName = fields.get("pykotaFileName", [""])[0]
+                job.JobTitle = fields.get("pykotaTitle", [""])[0]
+                job.JobCopies = int(fields.get("pykotaCopies", [0])[0])
+                job.JobOptions = fields.get("pykotaOptions", [""])[0]
+                date = fields.get("createTimestamp")[0]
+                year = int(date[:4])
+                month = int(date[4:6])
+                day = int(date[6:8])
+                hour = int(date[8:10])
+                minute = int(date[10:12])
+                second = int(date[12:14])
+                job.JobDate = "%04i-%02i-%02i %02i:%02i:%02i" % (year, month, day, hour, minute, second)
+                if (datelimit is None) or (job.JobDate <= datelimit) :
+                    job.User = self.getUser(fields.get("pykotaUserName")[0])
+                    job.Printer = self.getPrinter(fields.get("pykotaPrinterName")[0])
+                    job.Exists = 1
+                    jobs.append(job)
+            jobs.sort(lambda x,y : cmp(y.JobDate, x.JobDate))        
+            if limit :    
+                jobs = jobs[:int(limit)]
+        return jobs
         
     def deleteUser(self, user) :    
Index: pykota/trunk/pykota/storage.py
===================================================================
--- pykota/trunk/pykota/storage.py (revision 1269)
+++ pykota/trunk/pykota/storage.py (revision 1274)
@@ -22,4 +22,7 @@
 #
 # $Log$
+# Revision 1.37  2004/01/12 14:35:01  jalet
+# Printing history added to CGI script.
+#
 # Revision 1.36  2004/01/10 09:44:02  jalet
 # Fixed potential accuracy problem if a user printed on several printers at
@@ -338,11 +341,11 @@
         self.HardLimit = hardlimit
         
-class StorageLastJob(StorageObject) :
+class StorageJob(StorageObject) :
     """Printer's Last Job class."""
-    def __init__(self, parent, printer) :
+    def __init__(self, parent) :
         StorageObject.__init__(self, parent)
-        self.Printer = printer
+        self.User = None
+        self.Printer = None
         self.JobId = None
-        self.User = None
         self.PrinterPageCounter = None
         self.JobSize = None
@@ -355,4 +358,10 @@
         self.JobOptions = None
         
+class StorageLastJob(StorageJob) :
+    """Printer's Last Job class."""
+    def __init__(self, parent, printer) :
+        StorageJob.__init__(self, parent)
+        self.Printer = printer
+        
     def setSize(self, jobsize) :
         """Sets the last job's size."""
@@ -361,5 +370,5 @@
         self.JobSize = jobsize
         self.JobPrice = jobprice
-    
+        
 class BaseStorage :
     def __init__(self, pykotatool) :
Index: pykota/trunk/cgi-bin/printquota.cgi
===================================================================
--- pykota/trunk/cgi-bin/printquota.cgi (revision 1262)
+++ pykota/trunk/cgi-bin/printquota.cgi (revision 1274)
@@ -23,4 +23,7 @@
 #
 # $Log$
+# Revision 1.23  2004/01/12 14:35:01  jalet
+# Printing history added to CGI script.
+#
 # Revision 1.22  2004/01/09 07:58:53  jalet
 # Changed URL to PyKota's logo
@@ -96,4 +99,5 @@
 import os
 import cgi
+import urllib
 
 from pykota import version
@@ -107,5 +111,5 @@
   <head>
     <title>PyKota Reports</title>
-    <link rel="stylesheet" type="text/css" href="pykota.css" />
+    <link rel="stylesheet" type="text/css" href="/pykota.css" />
   </head>
   <body>
@@ -221,8 +225,59 @@
         self.body += "<br />"
         self.body += self.htmlGroupsCheckbox(isgroup)
-        if printers and ugmask :
-            self.reportingtool = openReporter(admin, "html", printers, ugmask.split(), isgroup)
-            # self.body += "<pre>%s</pre>" % self.reportingtool.generateReport()
-            self.body += "%s" % self.reportingtool.generateReport()
+        if not self.form.has_key("history") :
+            if printers and ugmask :
+                self.reportingtool = openReporter(admin, "html", printers, ugmask.split(), isgroup)
+                self.body += "%s" % self.reportingtool.generateReport()
+        else :        
+            remuser = os.environ.get("REMOTE_USER", "root")    
+            if remuser != "root" :
+                username = remuser
+            elif self.form.has_key("username") :    
+                username = self.form["username"].value
+            else :    
+                username = None
+            if username is not None :    
+                user = self.storage.getUser(username)
+            else :    
+                user =None
+            if self.form.has_key("printername") :
+                printer = self.storage.getPrinter(self.form["printername"].value)
+            else :    
+                printer = None
+            if self.form.has_key("datelimit") :    
+                datelimit = self.form["datelimit"].value
+            else :    
+                datelimit = None
+            self.report = ["<h2>History</h2>"]    
+            history = self.storage.retrieveHistory(user, printer, datelimit)
+            if not history :
+                self.report.append("<h3>Empty</h3>")
+            else :
+                self.report.append('<table class="pykotatable" border="1">')
+                headers = ["Date", "User", "Printer", "PageCounter", "JobId", "JobSize", "JobPrice", "Copies", "Title", "Filename", "Options", "Action"]
+                self.report.append('<tr class="pykotacolsheader">%s</tr>' % "".join(["<th>%s</th>" % h for h in headers]))
+                oddeven = 0
+                for job in history :
+                    oddeven += 1
+                    if oddeven % 2 :
+                        oddevenclass = "odd"
+                    else :    
+                        oddevenclass = "even"
+                    if job.JobAction == "DENY" :
+                        oddevenclass = "deny"
+                    elif job.JobAction == "WARN" :    
+                        oddevenclass = "warn"
+                    self.report.append('<tr class="%s">%s</tr>' % (oddevenclass, "".join(["<td>%s</td>" % h for h in (job.JobDate, job.User.Name, job.Printer.Name, job.PrinterPageCounter, job.JobId, job.JobSize, job.JobPrice, job.JobCopies, job.JobTitle, job.JobFileName, job.JobOptions, job.JobAction)])))
+                self.report.append('</table>')
+                dico = { "history" : 1,
+                         "datelimit" : job.JobDate,
+                       }
+                if user and user.Exists :
+                    dico.update({ "username" : user.Name })
+                if printer and printer.Exists :
+                    dico.update({ "printername" : printer.Name })
+                prevurl = "%s?%s" % (os.environ.get("SCRIPT_NAME", ""), urllib.urlencode(dico))
+                self.report.append('<a href="%s">Previous page</a>' % prevurl)
+            self.body = "\n".join(self.report)    
             
 if __name__ == "__main__" :
Index: pykota/trunk/NEWS
===================================================================
--- pykota/trunk/NEWS (revision 1272)
+++ pykota/trunk/NEWS (revision 1274)
@@ -24,4 +24,6 @@
     - 1.16alpha24 :
     
+        - CGI script now can show the printing history.
+        
         - Bug wrt number of copies should be fixed.
         
Index: pykota/trunk/stylesheets/README
===================================================================
--- pykota/trunk/stylesheets/README (revision 1263)
+++ pykota/trunk/stylesheets/README (revision 1274)
@@ -21,5 +21,6 @@
 
 This directory contains CSS stylesheets for use with PyKota's web based 
-tools. Just copy them in the same directory (e.g. /usr/lib/cgi-bin)
+tools. Just copy them in your web server's DocumentRoot (e.g. /var/www)
+so that the CGI scripts will find them.
 
 ====================================================================
