root / pykota / trunk / cgi-bin / pykotadmin.cgi @ 1066

Revision 986, 3.6 kB (checked in by jalet, 22 years ago)

First shot at the complete web-based administrative interface.

  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
Line 
1#! /usr/bin/env python
2
3# PyKota - Print Quotas for CUPS and LPRng
4#
5# (c) 2003 Jerome Alet <alet@librelogiciel.com>
6# This program is free software; you can redistribute it and/or modify
7# it under the terms of the GNU General Public License as published by
8# the Free Software Foundation; either version 2 of the License, or
9# (at your option) any later version.
10#
11# This program is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14# GNU General Public License for more details.
15#
16# You should have received a copy of the GNU General Public License
17# along with this program; if not, write to the Free Software
18# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
19#
20# $Id$
21#
22# $Log$
23# Revision 1.1  2003/05/03 17:33:08  jalet
24# First shot at the complete web-based administrative interface.
25#
26#
27#
28
29import sys
30import os
31import cgi
32from pykota.tool import PyKotaTool, PyKotaToolError
33
34header = """Content-type: text/html
35
36<?xml version="1.0" encoding="iso-8859-1"?>
37<html>
38  <head>
39    <title>PyKota Administration</title>
40  </head>
41  <body>
42    <form action="pykotadmin.cgi" method="POST">
43      <table>
44        <tr>
45          <td>
46            <p>
47              <a href="http://www.librelogiciel.com/software/"><img src="http://www.librelogiciel.com/software/PyKota/calllogo" alt="PyKota's Logo" /></a>
48              <br />
49              <a href="http://www.librelogiciel.com/software/">PyKota</a>
50            </p>
51          </td>
52          <td colspan="2">
53            <h2>PyKota Administration</h2>
54          </td>
55        </tr>
56        <tr>
57          <td>
58            <input type="submit" name="action" value="Report" />
59          </td>
60          <td>
61            <input type="submit" name="action" value="Modify" />
62          </td>
63          <td>
64            <input type="submit" name="action" value="Warn" />
65          </td>
66        </tr>
67      </table>"""
68   
69footer = """
70    </form>
71  </body>
72</html>""" 
73
74
75class PyKotaAdminGUI(PyKotaTool) :
76    """PyKota Administrative GUI"""
77    def guiDisplay(self) :
78        """Displays the administrative interface."""
79        global header, footer
80        print header
81        print self.body
82        print footer
83       
84    def error(self, message) :
85        """Adds an error message to the GUI's body."""
86        if message :
87            self.body = '<p><font color="red">%s</font></p>\n%s' % (message, self.body)
88       
89    def htmlListPrinters(self) :   
90        """Displays the printers multiple selection list."""
91        printers = self.storage.getMatchingPrinters("*")
92        message = 'Printer : <select name="printers" multiple="multiple">'
93        for (printerid, printername) in printers :
94            message += '<option value="%s">%s</option>' % (printerid, printername)
95        message += '</select>'
96        return message
97       
98    def guiAction(self) :
99        """Main function"""
100        self.body = "<p>Please click on the menu above</p>\n"
101        form = cgi.FieldStorage()
102        if form.has_key("action") :
103            action = form["action"].value
104            if action == "Modify" :
105                self.error("Not implemented yet ! Sorry.")
106            elif action == "Warn" :
107                self.error("Not implemented yet ! Sorry.")
108            elif action == "Report" :
109                self.error("Not implemented yet ! Sorry.")
110            else :
111                self.error(body, "Invalid action [%s]" % action)
112        self.body = self.body + self.htmlListPrinters()           
113   
114if __name__ == "__main__" :
115    admin = PyKotaAdminGUI()
116    admin.guiAction()
117    admin.guiDisplay()
Note: See TracBrowser for help on using the browser.