aboutsummaryrefslogtreecommitdiff
path: root/cgi-bin/nea.cgi.in
blob: b26714f2bdcf96d00dd62d9d8a1106819800afc1 (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
#! =GUILE_BINDIR=/guile -s
=AUTOGENERATED=
!#
;;;; News page for Ellinika
;;;; 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)

(define tmpl (if (and monima-nea-template-file-name
		      (cgi:value "timestamp"))
		 monima-nea-template-file-name
		 nea-template-file-name))

(ellinika-cgi-init tmpl)

(define conn #f)
(define article #f)

(define (permalink tag timestamp)
  (display (string-append "<" tag " class=\"permalink\">"))
  (display "<a href=\"")
  (display (make-cgi-name nea-cgi-path "timestamp" timestamp))
  (display "\">[permanent link]</a>")
  (display (string-append "</" tag ">")))

(define (summary)
  (if 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>")
	     (display "\n</tr>\n"))
	   result)
	  (display "</table>"))))
      (format #t "<H1>~A</H1>\n"
	      "ΣΦΆΛΜΑ: σύνδεση με το λέξικο απέτυχε.")))

(define (main)
  (if article
      (if (null? article)
	  (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 (list-ref item 2))
	     (display "</span> ")

	     (if (not (cgi:value "timestamp"))
		 (permalink "span" (list-ref item 1)))
	     
	     (display "<div class=\"itemtext\">")
	     (display (list-ref item 3))
	     (display "</div>"))
	   article))))

(define (title)
  (if article
      (display (if (null? article) "No item" (list-ref (car article) 2)))))
      

(define (nea-html)
  (let ((explist (list (cons "@@main@@"     main)
		       (cons "@@summary@@"  summary)
		       (cons "@@title@@"    title))))
  
    (do ((line (read-line) (read-line)))
	((eof-object? line) #f)
      (expand-template explist line)
      (newline))))

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

(set! conn (sql-connect
	    sql-iface sql-host sql-port sql-database
	    sql-username sql-password))

(if (or (cgi:value "timestamp") (cgi:value "id"))
    (set! article (sql-query conn
			     (cond
			      ((cgi:value "timestamp")
			       (string-append
				"SELECT date,unix_timestamp(date),header,text FROM news WHERE unix_timestamp(date)="
				(cgi:value "timestamp")))
			      ((cgi:value "id")
			       (string-append
				"SELECT date,unix_timestamp(date),header,text FROM news WHERE ident="
				(cgi:value "id")))))))

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

(sql-connect-close conn)

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

Return to:

Send suggestions and report system problems to the System administrator.