#! =GUILE_BINDIR=/guile -s
=AUTOGENERATED=
!#
;;;; Greek Dictionary Web Engine
;;;; Copyright (C) 2004, 2005 Sergey Poznyakoff
;;;;
;;;; 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
;;;;
;;; Tailor this statement to your needs if necessary.
;=GUILE_COMMENT=;(set! %load-path (cons "=GUILE_SITE=" %load-path))
(use-modules (www cgi)
(gamma sql)
(gamma gettext)
(xmltools dict)
(ellinika xlat)
(ellinika cgi))
(cgi:init)
(ellinika-cgi-init dict-template-file-name)
;; Τα μέρη του λογου
(define part-of-speech '())
(define (sql-error-handler err descr)
(format #t "
~A
\n"
(_ "ΣΦΆΛΜΑ: σύνδεση με το λέξικο απέτυχε."))
(with-output-to-port
(current-error-port)
(lambda ()
(display err)
(display ": ")
(display descr))))
(define (mk-dict-connect)
(let ((db-connection #f))
(lambda (. rest)
(cond
((null? rest)
(if (not db-connection)
(begin
(set! db-connection
(sql-connect
sql-iface sql-host sql-port sql-database
sql-username sql-password))
(sql-query db-connection "SET NAMES utf8")
)))
(else
(if db-connection
(sql-connect-close db-connection))
(set! db-connection #f)))
db-connection)))
(define dict-connect (mk-dict-connect))
(defmacro catch-sql-failure (expr)
`(catch 'gsql-error
(lambda () ,expr)
(lambda (key err descr)
(sql-error-handler err descr))))
(defmacro ignore-sql-failure (expr)
`(catch 'gsql-error
(lambda () ,expr)
(lambda (key err descr)
#f)))
(define (load-pos)
(ignore-sql-failure
(let ((conn (dict-connect)))
(let ((plist (my-sql-query
conn
"SELECT name,id FROM pos WHERE canonical='Y' order by id")))
(set! part-of-speech
(cons
(cons "κανένα μέρος του λόγου" #f)
(map
(lambda (x)
(cons (car x) (cadr x)))
plist)))))))
;; Protect occurences of " in a string.
;; Usual backslash escapes do not work in INPUT widgets, so I
;; change all quotation marks to "
;; Possibly not the better solution, though...
(define (protect string)
(list->string
(apply append
(map
(lambda (x)
(if (eq? x #\")
(list #\& #\# #\3 #\4 #\;)
(list x)))
(string->list string)))))
(define (get-topic-list)
(let ((categories #f))
(letrec ((getcat
(lambda ()
(ignore-sql-failure
(let ((conn (dict-connect)))
(let ((ctg (my-sql-query
conn
"SELECT category, title, description FROM category ORDER BY category")))
(if (null? ctg)
'()
(map
(lambda (category)
(let ((topics (my-sql-query
conn
(string-append
"SELECT ident,title FROM topic WHERE category="
(car category)
" ORDER BY title"))))
(append category (if (null? topics)
'()
(list topics)))))
ctg))))))))
(if (not categories)
(set! categories (or (getcat) '())))
categories)))
(define (join-widget widget-id tabindex)
(let* ((name (string-append "join" widget-id))
(selected-choice (or (let ((s (cgi:value name)))
(if s
(string->number s)
#f))
0)))
(display (string-append "")))
(define (main-form)
(load-pos)
(display "