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) :    
