comparison demo/more/conference.ur @ 1009:59097824f19b

Viewing papers
author Adam Chlipala <adamc@hcoop.net>
date Thu, 22 Oct 2009 12:16:31 -0400
parents 1911e84df461
children 6b0f3853cc81
comparison
equal deleted inserted replaced
1008:1911e84df461 1009:59097824f19b
9 con review :: {(Type * Type)} 9 con review :: {(Type * Type)}
10 constraint [Paper, User] ~ review 10 constraint [Paper, User] ~ review
11 val review : $(map meta review) 11 val review : $(map meta review)
12 12
13 val submissionDeadline : time 13 val submissionDeadline : time
14 val summarizePaper : $(map fst paper) -> xbody
14 end) = struct 15 end) = struct
15 16
16 table user : {Id : int, Nam : string, Password : string, Chair : bool, OnPc : bool} 17 table user : {Id : int, Nam : string, Password : string, Chair : bool, OnPc : bool}
17 PRIMARY KEY Id, 18 PRIMARY KEY Id,
18 CONSTRAINT Nam UNIQUE Nam 19 CONSTRAINT Nam UNIQUE Nam
39 | Some r => 40 | Some r =>
40 oneOrNoRows1 (SELECT user.Id, user.Nam, user.Chair, user.OnPc 41 oneOrNoRows1 (SELECT user.Id, user.Nam, user.Chair, user.OnPc
41 FROM user 42 FROM user
42 WHERE user.Id = {[r.Id]} 43 WHERE user.Id = {[r.Id]}
43 AND user.Password = {[r.Password]}) 44 AND user.Password = {[r.Password]})
45
46 fun checkPaper id =
47 ro <- checkLogin;
48 if (case ro of
49 None => False
50 | Some r => r.OnPc) then
51 return ()
52 else
53 error <xml>You must be logged in to do that.</xml>
44 54
45 structure Users = BulkEdit.Make(struct 55 structure Users = BulkEdit.Make(struct
46 con keyName = #Id 56 con keyName = #Id
47 val visible = {Nam = string "Name", 57 val visible = {Nam = string "Name",
48 Chair = bool "Chair?", 58 Chair = bool "Chair?",
120 {if me.Chair then 130 {if me.Chair then
121 <xml><li><a link={Users.main ()}>Manage users</a></li></xml> 131 <xml><li><a link={Users.main ()}>Manage users</a></li></xml>
122 else 132 else
123 <xml/>} 133 <xml/>}
124 134
135 {if me.OnPc then
136 <xml><li><a link={all ()}>All papers</a></li></xml>
137 else
138 <xml/>}
139
125 {if now < M.submissionDeadline then 140 {if now < M.submissionDeadline then
126 <xml><li><a link={submit ()}>Submit</a></li></xml> 141 <xml><li><a link={submit ()}>Submit</a></li></xml>
127 else 142 else
128 <xml/>} 143 <xml/>}
129 </xml>} 144 </xml>}
133 m <- main' (); 148 m <- main' ();
134 return <xml><body>{m}</body></xml> 149 return <xml><body>{m}</body></xml>
135 150
136 and submit () = 151 and submit () =
137 let 152 let
138 fun doSubmit r = return <xml><body> 153 fun doSubmit r =
139 MIME type: {[fileMimeType r.Document]}<br/> 154 id <- nextval paperId;
140 Length: {[blobSize (fileData r.Document)]} 155 dml (insert paper ({Id = sql_inject id, Document = sql_inject (fileData r.Document)}
141 </body></xml> 156 ++ ensql M.paper (r -- #Document) M.paperFolder));
157 return <xml><body>
158 OK, done!
159 </body></xml>
142 in 160 in
143 return <xml><body> 161 return <xml><body>
144 <h1>Submit a Paper</h1> 162 <h1>Submit a Paper</h1>
145 163
146 <form> 164 <form>
149 <submit value="Submit" action={doSubmit}/> 167 <submit value="Submit" action={doSubmit}/>
150 </form> 168 </form>
151 </body></xml> 169 </body></xml>
152 end 170 end
153 171
172 and all () =
173 ps <- queryX (SELECT paper.Id, paper.{{map fst M.paper}} FROM paper)
174 (fn r => <xml><li><a link={one r.Paper.Id}>{M.summarizePaper (r.Paper -- #Id)}</a></li></xml>);
175 return <xml><body>
176 <h1>All Papers</h1>
177
178 <ul>
179 {ps}
180 </ul>
181 </body></xml>
182
183 and one id =
184 checkPaper id;
185 ro <- oneOrNoRows (SELECT paper.{{map fst M.paper}}, octet_length(paper.Document) AS N
186 FROM paper
187 WHERE paper.Id = {[id]});
188 case ro of
189 None => error <xml>Paper not found!</xml>
190 | Some r => return <xml><body>
191 <h1>Paper #{[id]}</h1>
192
193 {allContent M.paper r.Paper M.paperFolder}<br/>
194
195 {if r.N = 0 then
196 <xml><div>No paper uploaded yet.</div></xml>
197 else
198 <xml><a link={download id}>Download paper</a> ({[r.N]} bytes)</xml>}
199 </body></xml>
200
201 and download id =
202 checkPaper id;
203 ro <- oneOrNoRows (SELECT paper.Document
204 FROM paper
205 WHERE paper.Id = {[id]});
206 case ro of
207 None => error <xml>Paper not found!</xml>
208 | Some r => returnBlob r.Paper.Document (blessMime "application/pdf")
209
154 end 210 end