aboutsummaryrefslogtreecommitdiff
path: root/cgi-bin/nea.cgi.in
blob: 56e8bc5e7fc8e5bf58697ea026fbed817e85936c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#! =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)

(define (summary)
  (let ((conn (sql-connect
	       sql-iface sql-host sql-port sql-database
	       sql-username sql-password)))
    (cond
     (conn
      (let ((result (sql-query conn "SELECT date,header,ident FROM news ORDER BY date")))
	(cond
	 ((null? result)
	  (display "<div align=\"center\">No news</div>"))
	 (else
	  (display "<table class=\"newssummary\">\n")
	  (for-each
	   (lambda (entry)
	     (display "<tr>\n")
	     (display "<td class=\"date\">")
	     (display (list-ref entry 0))
	     (display "</td>")
	     (display "<td class=\"subject\"><a href=\"")
	     (display (make-cgi-name nea-cgi-path "id" (list-ref entry 2)))
	     (display "\">")
	     (display (list-ref entry 1))
	     (display "</a></td>\n")
	     (display "</tr>\n"))
	   result)
	  (display "</table>"))))
      (sql-connect-close conn))
     (else
      (format #t "<H1>~A</H1>\n"
	      "ΣΦΆΛΜΑ: σύνδεση με το λέξικο απέτυχε.")))))

(define (main)
  (cond
   ((cgi:value "id") =>
    (lambda (id)
      (let ((conn (sql-connect
		   sql-iface sql-host sql-port sql-database
		   sql-username sql-password)))
	(cond
	 (conn
	  (let ((result (sql-query conn
				   (string-append
				    "SELECT date,header,text FROM news WHERE ident="
				    id))))
	    (if (null? result)
		(format #t "<H1>No item found</H1>\n")
		(for-each
		 (lambda (item)
		   (format #t "<span class=\"itemdate\">~A</span>\n" (car item))
		   (display "<span class=\"itemheader\">\n")
		   (display (cadr item))
		   (display "</span>")

		   (display "<div class=\"itemtext\">")
		   (display (caddr item)))
		 result))))
	 (else
	  (format #t "<H1>~A</H1>\n"
		  "ΣΦΆΛΜΑ: σύνδεση με το λέξικο απέτυχε."))))))))


(define explist
  (list (cons "@@program-name@@"  (lambda (id)
				    (make-cgi-name nea-cgi-path)))
	(cons "@@main@@"          main)
	(cons "@@summary@@"	  summary)))

; FIXME: Again, share it with dict.cgi
(define (expand-template template)
  (let loop ((template template))
    (cond
     ((string-index template #\@) =>
      (lambda (w)
	(display (substring template 0 w))
	(if (and (< (+ w 2) (string-length template))
		 (char=? (string-ref template (1+ w)) #\@))
	    (let ((end-pos (string-index template #\@ (+ w 2))))
	      (if (and end-pos
		       (< (1+ end-pos) (string-length template))
		       (char=? (string-ref template (1+ end-pos)) #\@))
		  (let* ((name (substring template w (+ end-pos 2)))
			 (entry (assoc name explist)))
		    (cond
		     (entry
		      ((cdr entry))
		      (loop (substring template (+ end-pos 2))))
		     (else
		      (display "@@")
		      (loop (substring template (+ w 2))))))
		  (begin
		    (display "@")
		    (loop (substring template (+ w 1))))))
	    (begin
	      (display "@")
	      (loop (substring template (1+ w)))))))
     (else
      (display template)))))

(define (dict-html)
  (do ((line (read-line) (read-line)))
      ((eof-object? line) #f)
    (expand-template line)))

;;; Main
(display "Content-type: text/html; charset=utf-8\r\n\r\n")

(with-input-from-file
    (template-file target-language nea-template-file-name)
  dict-html)


;;;; Local variables:
;;;; mode: Scheme
;;;; buffer-file-coding-system: utf-8
;;;; End:

Return to:

Send suggestions and report system problems to the System administrator.