781f5cb192cf0eed64ffac861d1332dbeffd5231
[lineal.git] / src / webui / save-restore.lisp
blob781f5cb192cf0eed64ffac861d1332dbeffd5231
2 (in-package :lineal.webui)
4 ;V URL: capture_session
5 ;V Return a file for the user to download V
6 ;V containing all session variables. V
7 (defun capture-session ()
8 (setf (content-type) "application/octet-stream")
9 (with-output-to-string (strm)
10 (save-to-stream strm)))
12 ;V URL: /save_restore
13 ;V The main save and restore page which allows V
14 ;V the user to save and restore session variables.V
15 (defun save-restore-page (&optional (message ""))
16 (with-html-output-to-string
17 (strm nil :prologue t)
18 (:html
19 (:head
20 (:title "Save/Restore Variables"))
21 (:body
22 (:div
23 (:a :href "/input_matrix" "Create and edit")
24 " vectors and matrices" :br
25 (calcupage-link strm) :br
26 (:a :href "/" "Main") " Page")
27 :hr
28 (:div (:a :href "/capture_session" "Get file")
29 " containing current session's variables.")
30 :hr
31 (:div
32 (:form :action "/restore_from_upload"
33 :enctype "multipart/form-data" :method "post"
34 "Add variables from session-restore file: " :br
35 (:input :type "file" :name "restorefile" :size "40") :br
36 (:input :type "submit" :value "Send")))
37 :hr (:pre (princ message strm))))))
39 ;V URL: /restore_from_upload
40 ;V Add variables described in the uploaded file, V
41 ;V overwriting any whose name already exists. V
42 (defun restore-from-upload
43 (&aux (file (car (post-parameter "restorefile"))))
44 (with-open-file (strm file :direction :input)
45 (save-restore-page
46 (restore-from-stream strm))))