#! /usr/bin/python
# -*- coding: ISO-8859-15 -*-
# PyKota Print Quota Reports generator
#
# PyKota - Print Quotas for CUPS and LPRng
#
# (c) 2003, 2004, 2005, 2006, 2007 Jerome Alet
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# $Id$
#
#
import sys
import os
import cgi
import urllib
from mx import DateTime
from pykota import version
from pykota.tool import PyKotaTool, PyKotaToolError
from pykota.reporter import PyKotaReporterError, openReporter
from pykota.cgifuncs import getLanguagePreference, getCharsetPreference
header = """Content-type: text/html;charset=%s
%s
\n" % _("Please click on the above button")
if self.form.has_key("report") :
if self.form.has_key("printers") :
printersfield = self.form["printers"]
if type(printersfield) != type([]) :
printersfield = [ printersfield ]
printers = [self.storage.getPrinter(p.value) for p in printersfield]
else :
printers = self.storage.getMatchingPrinters("*")
if remuser == "root" :
if self.form.has_key("ugmask") :
ugmask = self.form["ugmask"].value
else :
ugmask = "*"
else :
if self.form.has_key("isgroup") :
user = self.storage.getUser(remuser)
if user.Exists :
ugmask = " ".join([ g.Name for g in self.storage.getUserGroups(user) ])
else :
ugmask = remuser # result will probably be empty, we don't care
else :
ugmask = remuser
if self.form.has_key("isgroup") :
isgroup = 1
else :
isgroup = 0
self.body += self.htmlListPrinters(printers or [])
self.body += " "
self.body += self.htmlUGNamesInput(ugmask)
self.body += " "
self.body += self.htmlGroupsCheckbox(isgroup)
try :
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 :
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
if self.form.has_key("hostname") :
hostname = self.form["hostname"].value
else :
hostname = None
if self.form.has_key("billingcode") :
billingcode = self.form["billingcode"].value
else :
billingcode = None
self.report = ["
%s
" % _("History")]
history = self.storage.retrieveHistory(user=user, printer=printer, hostname=hostname, billingcode=billingcode, end=datelimit)
if not history :
self.report.append("