This repository has been archived by the owner on Nov 10, 2022. It is now read-only.
/
admin-question.xqy
110 lines (95 loc) · 3.1 KB
/
admin-question.xqy
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
(:
: Copyright (c) 2004 Mark Logic Corporation
:
: Licensed under the Apache License, Version 2.0 (the "License");
: you may not use this file except in compliance with the License.
: You may obtain a copy of the License at
:
: http://www.apache.org/licenses/LICENSE-2.0
:
: Unless required by applicable law or agreed to in writing, software
: distributed under the License is distributed on an "AS IS" BASIS,
: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
: See the License for the specific language governing permissions and
: limitations under the License.
:
: The use of the Apache License does not indicate that this project is
: affiliated with the Apache Software Foundation.
:)
xquery version "1.0-ml";
import module namespace xfl = "http://www.marklogic.com/xfaqtor-lib" at "xfaqtor-lib.xqy";
import module namespace xfd = "http://www.marklogic.com/xfaqtor-display" at "xfaqtor-display.xqy";
xdmp:set-response-content-type("text/html"),
<html xml:space="preserve">
<!-- @Template href="/default.tmpl" -->
<head>
<link rel="stylesheet" type="text/css" href="style.css" />
<!-- @BeginEditable id="title" -->
<title>XFAQtor</title>
<!-- @EndEditable -->
</head>
<!-- @BeginEditable id="bodytagstart" -->
<body class="help">
<!-- @EndEditable -->
<!-- @BeginEditable id="body" -->
{
let $sel := <x selected="selected"/>/@selected
let $questid := xdmp:get-request-field("questid")
return
(: Do some input data checking :)
if ($questid = "") then
<span>
<div class="error">The 'questid' parameter is missing</div>
{ xfd:print-go-home() }
</span>
else if (not($questid castable as xs:integer)) then
<span>
<div class="error">The 'questid' parameter must be an integer</div>
{ xfd:print-go-home() }
</span>
else
let $question := xfl:get-question(xs:integer($questid))
return
if (empty($question)) then
<span>
<div class="error">Question id '{ $questid }' unknown</div>
{ xfd:print-go-admin() }
</span>
else
<form action="admin-question-go.xqy" method="post" class="xfaq-ask">
<input type="hidden" name="questid" value="{$questid}"/>
<dl class="entrybox">
<dt>Edit Question:</dt>
<dd><textarea name="text" cols="40" rows="5">{$question/text/text()}</textarea></dd>
</dl>
<dl>
<dt>Edit Category:</dt>
{
<dd>
<select name="old-category">
{
for $cat in xfl:get-all-category-names()
return
<option>
{ if ($question/category = $cat) then $sel else () } {$cat}
</option>
}
</select>
</dd>
}
</dl>
<dl>
<dt>Or Create a New Category</dt>
<dd><input type="text" name="new-category"/></dd>
</dl>
<dl>
<dt>Edit Stat</dt>
<dd> { xfd:print-state-select("state", $question/state) } </dd>
</dl>
<input type="submit" name="change" value="Change!"/>
<input type="submit" name="cancel" value="Cancel"/>
</form>
}
<!-- @EndEditable -->
</body>
</html>