From: Sebastian Stark (seb_at_todesplanet.de)
Date: 27. Mar 2002
Messingschlager, Wolfgang wrote:
> für die rege Diskussion. Wenn ich ehrlich bin, dann habe ich
> ungefähr so ein Ergebnis erwartet.
>
> Zusammenfassend kann man wohl sagen:
> RDBMS: entweder MySQL oder Postgres, wobei Postgres besser
> ist, aber evtl. schieriger
>
> grafisches Interface: entweder PHP mit dynamischem HTML code
> oder Perl/Tk
> Braucht man für PHP auch noch einen Webserver z.B. apache?
>
> Reports oder Drucken: Latex
Ich habe sowas kürzlich gemacht, für einen bestimmten Zweck, nähmlich
phpgroupware Adressen auszudrucken. Da ich PHP generell für eine
ungeeignete Sprache halte, habe ich das in Python gemacht. Ist sozusagen
"Version 1.0", also noch verbesserungswürdig, aber funktional.
Die Feldnamen und den Datenbanknamen umzuändern, im Falle, daß man nicht
phpgroupware verwendet, sollte trivial sein.
Schöner wäre das nun tatsächlich mit einem template file, wie von
Michael vorgeschlagen.
Ich mache das immer so:
./nt_address.py > adr.tex; latex adr.tex; dvips adr.dvi; lpr adr.ps
Und fertig ist der Lack.
----- nt_address.py:
#! /usr/bin/env python2.1
import MySQLdb, sys, traceback, re, string, getopt
host = 'kyber'
db = 'phpgroupware'
user = 'phpgroupware'
passwd = '<pass>'
notprint = ['id', 'email_type', 'cat_id', 'lid', 'tid', 'owner', 'tz',
'access', 'email_home_type', 'adr_two_type']
organisation = ['org_name', 'org_unit']
name = ['n_prefix', 'n_family', 'n_middle', 'n_given', 'n_suffix',
'title']
urls = ['url', 'email', 'email_home']
address1 = ['adr_one_street', 'adr_one_postalcode', 'adr_one_region',
'adr_one_locality']
address2 = ['adr_two_street', 'adr_two_postalcode', 'adr_two_region',
'adr_two_locality']
phones = ['tel_work', 'tel_home', 'tel_voice', 'tel_fax', 'tel_msg',
'tel_cell', 'tel_pager', 'tel_bbs', 'tel_modem', 'tel_car',
'tel_isdn', 'tel_video']
other = ['note']
cols = ''
def latextop():
if cols == '2':
print "\\documentclass[10pt, a4paper, twocolumn]{scrartcl}",
else:
print "\\documentclass[10pt, a4paper]{scrartcl}",
print """
\\usepackage[latin1]{inputenc}
\\usepackage[T1]{fontenc}
\\usepackage{tabularx, ngerman, times}
\\parindent 0cm
\\parskip 1ex
\\setlength{\\oddsidemargin}{-2 cm}
\\setlength{\\textwidth}{19 cm}
\\setlength{\\textheight}{25 cm}
\\begin{document}
\\pagestyle{empty}
"""
def latexbottom():
print """
\end{document}
"""
def lq(in_text):
#['$', '&', '%', '#', '_', '{', '}', '~', '^', '"', '\\', '|', '<', '>']
rules = [(re.compile(r"\\\\"), r"\textbackslash"),
(re.compile(r"{"), r"\{"),
(re.compile(r"}"), r"\}"),
(re.compile(r"_"), r"\_"),
(re.compile(r"&"), r"\&")]
text = str(in_text)
for (old, new) in rules:
text = old.sub(new, text)
return text
def sortdict(adict):
keys = adict.keys()
keys.sort()
return map(adict.get, keys)
def dbexec(stmt):
try:
cursor.execute(stmt)
except:
print "\nexecute error\n"
traceback.print_exc()
sys.exit()
def dbconn():
global cursor, db
try:
db = MySQLdb.Connect(host, user, passwd, db)
cursor = db.cursor()
except:
print "\nconnect error\n"
traceback.print_exc()
sys.exit()
def usage():
print "phpGroupware print module"
# main
try:
opts, args = getopt.getopt(sys.argv[1:], "h2", ["help", "twocolumns"])
except getopt.GetoptError:
# print help information and exit:
usage()
print "opt error"
sys.exit(2)
for o, a in opts:
if o in ("-h", "--help"):
usage()
sys.exit()
if o in ("-2", "--twocolumns"):
cols = '2'
dbconn()
stmt = """DESC phpgw_addressbook"""
dbexec(stmt)
tabledescr = cursor.fetchall()
stmt = """SELECT * FROM phpgw_addressbook
ORDER BY org_name, org_unit, n_family"""
dbexec(stmt)
latextop()
for hits in range(cursor.rowcount):
try:
row = cursor.fetchone()
except:
print "\nfetch error\n"
traceback.print_exc()
sys.exit()
dict = {}
for i in range(len(tabledescr)):
dict[tabledescr[i][0]] = row[i]
print "\\begin{tabularx}{\\linewidth}{|r|X|}"
print "\\hline"
print "& \\large{%s %s}\\\\" % (lq(dict['org_name']), lq(dict['org_unit']))
print "\\hline"
print "\\textbf{Name} &\\\\"
for field in name:
if (dict[field] != "") & (notprint.count(field) == 0):
print "& %s \\\\" % lq(dict[field])
print "\\textbf{Adresse} &\\\\"
for field in address1:
if (dict[field] != "") & (notprint.count(field) == 0):
print "& %s \\\\" % lq(dict[field])
print "\\textbf{Adresse 2} &\\\\"
for field in address2:
if (dict[field] != "") & (notprint.count(field) == 0):
print "& %s \\\\" % lq(dict[field])
print "\\textbf{Telefon} &\\\\"
for field in phones:
if (dict[field] != "") & (notprint.count(field) == 0):
print "%s & %s \\\\" % (lq(field), lq(dict[field]))
print "\\textbf{Internet} &\\\\"
for field in urls:
if (dict[field] != "") & (notprint.count(field) == 0):
print "%s & %s \\\\" % (lq(field), lq(dict[field]))
print "\\textbf{Sonstiges} &\\\\"
for field in other:
if (dict[field] != "") & (notprint.count(field) == 0):
print "%s & %s \\\\" % (lq(field), lq(dict[field]))
print "\\hline"
print "\\end{tabularx}"
print
latexbottom()
db.close()
-- Free your mind and your ass will follow -- http://www.funkaffair.de
Dieses Archiv wurde generiert von hypermail 2.1.2 : 27. Mar 2002 CET