Dictionary
[show modes: view fullview by_date add_entry add_category edit export search]

[begin mode search]
[
override_parent({./?id=[$_id]}, $_title);

if($_params.r == "") {

<h2>Dictionary Search</h2>
<form method="get" action="/" style="text-align: center">
	<input type="hidden" name="id" value="[$_id]">
	<input type="hidden" name="mode" value="search">
	<input type="text" name="q" value="" accesskey="q" title="Query (Shift-Alt-Q)"[if($_args[0] == "") { autofocus="autofocus"}]>
	<input type="submit" value="Search Definitions" name="r" accesskey="s" title="Shift-Alt-S">
	<input type="number" name="l" value="3" size="3" title="Correction threshold (Shift-Alt-T)" accesskey="t">
	<input type="submit" value="Look Up" name="r" accesskey="l" title="Shift-Alt-L">
	<br><br>
[if($_args[0] == "") {
	[$q = query("qc", 0, "title collate utf8_unicode_ci", "parent", $_id, "template", title2id("Dictionary Entry"));
	query_count($q);] entries.
}]
</form>

} else {
	[
	if($_params.r == "Search Definitions") {
	<h2>Dictionary Search Results</h2>
	<style type="text/css">
		ul.added {
			margin-top: 0px;
			margin-bottom: 0px;
		}
	</style>
	[
	target = list();
	target.value = {%[$_params.q]%};
	target.collate = "utf8_general_ci";
	$q = query("searchresults", 0, "title collate utf8_unicode_ci", "template", title2id("Dictionary Entry"), "body", target, "parent", $_id);
	$qr = query_run("abbr", $q);
	$qr = replace(replace($qr, "<li>", {<ul class="added"><li>}), "</li>", "</li></ul>");
	]

	[
	target = list();
	target.value = {%[$_params.q]%};
	target.collate = "utf8_general_ci";
	$q2 = query("searchresults", 0, "title collate utf8_unicode_ci", "template", title2id("Dictionary Entry"), "title", target, "parent", $_id);
	$qr2 = query_run("abbr", $q2);
	$qr2 = replace(replace($qr2, "<li>", {<ul class="added"><li>}), "</li>", "</li></ul>");
	if($qr2 != "") $qr = {[$qr]<h2>Headwords</h2>[$qr2]};

	if($qr != "") {
		[$qr]
		<br><br>
		[query_count($q) + query_count($q2)] result(s).
	} else {
		<i>No results. Try different synonyms for your search term.</i>
	};
	]

	} else {
		<h2>Dictionary Lookup Results</h2>
	[$q = query("cc", 0, "title collate utf8_unicode_ci", "parent", $_id, "template", title2id("Dictionary Entry"));
	$qr = query_run("compare", $q, list($_params.q, $_params.l));
	if($qr != "") {<ul>[$qr]</ul>} else {<i>No results. Try increasing your threshold or throwing in some typos.</i>};
	]
	}
	]
	<br><br><center><a href="/?id=[$_id]&mode=search">New Search</a></center>
}
]
[end mode search]

[begin mode printable][suppress_template()]
<html>
<head>
<title>[$_title]</title>
<style type="text/css">
body {
	background: white;
	color: black;
	font-family: "Garamond", Palatino, "Palatino Linotype", "Book Antiqua", serif;
}
a {
	color: black !important;
}
</style>
</head>
<body>
<center>
<h1>[$_title]</h1>
<h2>[$_subtitle]</h2>
<i>as of:</i> [now()]
</center>
<br>
[
$q = query("dump", 0, "title collate utf8_unicode_ci", "parent", $_id, "template", title2id("Dictionary Entry"));

query_run("view", $q, list("nocats"));
]
</body>
</html>
[end mode printable]

[begin mode export]
<pre>[
suppress_template();
$sortby = "title collate utf8_unicode_ci";
if($_params.sortby != "") $sortby = $_params.sortby;
if($_params.q != "") $qstr = $_params.q;
if($qstr == "")
	$q = query("dump", 0, $sortby, "parent", $_id, "template", title2id("Dictionary Entry"))
else
	$q = query("dump", 0, $sortby, "parent", $_id, "template", title2id("Dictionary Entry"), "body", {%[$qstr]%});

$q.pagesize = query_count($q);

query_run("export", $q);
]</pre>
[end mode export]

[begin mode export_headwords]
<pre>[
suppress_template();
search("title", "parent", $_id, "template", title2id("Dictionary Entry"));
]</pre>
[end mode export_headwords]

[begin mode abbr]
<li><a href="/?id=[$_id]"><b>[$_title]</b></a>
<br><i>[$_subtitle]</i>
</li>
[end mode abbr]

[begin mode include]
<h2>[$_title;][$n = (substr($_viewer.permissions, 0, 1) == "c");
iif($_viewer.id == 0, $n = 0);
if($n) { &middot; 
<a href="/?id=[$_id]&mode=add_entry">+</a> <a href="/?id=[$_id]&mode=add_category">c</a> 
};]</h2>

<span style="font-size: 12pt">
[$n = (substr($_viewer.permissions, 3, 1) == "r");
iif($n, {[children("abbr", $_id);]}, "No read permission! Go away!");]
</span>
[end mode include]

[begin mode motd]
[
$entries = query("dictionary", 50, "title", "parent", $_id, "template", title2id("Dictionary Entry"));
$c = query_count($entries);

if($c == 0) return {<i>No word of the day yet. Add some words!</i>};

$mangle = function {[
	$_args[0] * 997;
]};

$n = int($time / 86400);

$_params.entries_pagenum = mangle($n) % $c;

$q = query("entries", 1, "title", "template", title2id("Dictionary Entry"), "parent", $_id);
$pid = query_run("id", $q);

$_params.entries_pagenum = mangle($n - 1) % $c;

$q = query("entries", 1, "title", "template", title2id("Dictionary Entry"), "parent", $_id);
$ypid = query_run("id", $q);

$_params.entries_pagenum = mangle($n + 1) % $c;

$q = query("entries", 1, "title", "template", title2id("Dictionary Entry"), "parent", $_id);
$tpid = query_run("id", $q);

if($pid != 0) {
<b>Word of the Day: <a href="/?id=[$pid]">[get_title($pid)]</a></b>
<hr>
<i>[page("part", $pid)]</i>. [page("desc", $pid)]
<hr>
<center>
<div style="display: inline-block; width: 50%; text-align: left;">
<i>yesterday</i><br>
<b><a href="/?id=[$ypid]">[get_title($ypid)]</a></b>
</div><div style="display: inline-block; width: 50%; text-align: right;">
<i>tomorrow</i><br>
<b><a href="/?id=[$tpid]">[get_title($tpid)]</a></b>
</div>
</center>
} else {<i>No word of the day yet. Add some words!</i>}]

[end mode motd]

[begin mode view]
[
$sortmode = "title collate utf8_unicode_ci";

$entries = query("dictionary", 50, $sortmode, "parent", $_id, "template", title2id("Dictionary Entry"));
]

<center>
Page: [page_list($entries, 5);]<br><br></center>

[
if(int($_params.dictionary_pagenum) == 0) {
<div style="float: right; max-width: 40%; margin-left: 10px; font-size: 90%;" class="mobile_nofloat mbox_parent">
	[page("motd", $_id)]
</div>
};
]

[query_view("abbr", $entries);]

<center>
<br>
[$np = next_page($entries);
$pp = previous_page($entries);

if($pp != "-1") {<a href="[$pp]">Previous Page</a> };
if($np != "-1") {<a href="[$np]">Next Page</a>};
]
<br>
[query_count($entries)] entries.
</center>

[page("search", $_id, list("no focus"))]

<div style="text-align: center;">
<br><b>Categories</b><br><br>
[search("category_abbr", "parent", $_id, "template", title2id("Dictionary Category"));]
</div>
[end mode view]

[begin mode autorepair]
[search("autorepair", "parent", $_id, "template", title2id("Dictionary Entry"));]
[end mode autorepair]

[begin mode validate]
[
	$s = search("validate", "parent", $_id, "template", title2id("Dictionary Entry"));
	if($s == "") {
		<i>No invalid entries were detected.</i>
	} else {[
		$s
	]};
]
[end mode validate]

[begin mode fullview]
[iif(can_read(), {
	[index("entry_abbr", $_id);]

<div style="text-align: center;">
<br><b>Categories</b><br><br>
[search("category_abbr", "parent", $_id, "template", title2id("Dictionary Category"));]
</div>

}, "No read permission! Go away!");
if(can_comment()) {
<p><a href="/?id=[$_id]&mode=add_entry">Add new entry</a> | <a href="/?id=[$_id]&mode=add_category">Add new category</a>
};]
[end mode fullview]

[begin mode by_date]
[
$sortmode = "date DESC, id";

$entries = query("dictionary", 50, $sortmode, "parent", $_id, "template", title2id("Dictionary Entry"));
]

<center>
Page: [page_list($entries, 1, "date");]<br><br></center>

[
if(int($_params.dictionary_pagenum) == 0) {
<div style="float: right; max-width: 40%; margin-left: 10px; font-size: 90%;" class="mobile_nofloat mbox_parent">
	[page("motd", $_id)]
</div>
};
]

[query_view("abbr", $entries);]

<center>
<br>
[$np = next_page($entries);
$pp = previous_page($entries);

if($pp != "-1") {<a href="[$pp]">Previous Page</a> };
if($np != "-1") {<a href="[$np]">Next Page</a>};
]
<br>
[query_count($entries)] entries.
</center>

[page("search", $_id, list("no focus"))]

<div style="text-align: center;">
<br><b>Categories</b><br><br>
[search("category_abbr", "parent", $_id, "template", title2id("Dictionary Category"));]
</div>
[end mode by_date]

[begin mode add_entry]
<form method="post" action="/" width="100%">
<input type="hidden" name="page" value="[$_title]">
<input type="hidden" name="mode" value="entry_submit">
<table width="100%">
<tr><th>Title:</th><td><input type="text" class="textbox" name="title" value=""></td></tr>
<tr><th></th><td>
<span class="buttonbox"><input name="submitButton" class="submit" type="submit" value="Create"></span> <i>your permissions</i>: [$_viewer.permissions]</td></tr></table>
</form> 
[end mode add_entry]

[begin mode entry_submit]
[
$e = new_page($_params.title, $_id);
if($e > 0) {
    [
    set_template($e, title2id("Dictionary Entry"));
    set_group($e, $_group);
    set_permissions($e, $_permissions);
    msg_start();
    page("edit", $e);
    msg_end();
    ]
} else {
    [msg_start();]
    Disaster. It failed! Maybe you should check the error log.
    [msg_end();]
};
]
[end mode entry_submit]

[begin mode add_category]
<form method="post" action="/" width="100%">
<input type="hidden" name="page" value="[$_title]">
<input type="hidden" name="mode" value="category_submit">
<table width="100%">
<tr><th>Title:</th><td><input type="text" class="textbox" name="title" value=""></td></tr>
<tr><th></th><td>
<span class="buttonbox"><input name="submitButton" class="submit" type="submit" value="Create"></span> <i>your permissions</i>: [$_viewer.permissions]</td></tr></table>
</form> 
[end mode add_category]

[begin mode category_submit]
[
$e = new_page($_params.title, $_id);
if($e > 0) {
    [
    set_template($e, title2id("Dictionary Category"));
    set_group($e, $_group);
    set_permissions($e, $_permissions);
    set_priority($e, 1);
    msg_start();
    page("edit", $e);
    msg_end();
    ]
} else {
    [msg_start();]
    Disaster. It failed! Maybe you should check the error log.
    [msg_end();]
};
]
[end mode category_submit]

[begin mode edit]
[iif(can_edit(), {
<form method="post" action="/" width="100%">
<input type="hidden" name="page" value="[$_title]">
<input type="hidden" name="mode" value="edit_submit">
<table width="100%">
        <tr><th>Title:</th><td><input type="text" class="textbox" name="title" value="[edit_display($_title)]" style="width: 100%"></td></tr>
        <tr><th>Subtitle:</th><td><input type="text" class="textbox" name="subtitle" value="[edit_display($_subtitle)]" style="width: 100%"></td></tr>
<tr><th>Parent:</th><td><input type="text" class="textbox" name="parent" value="[$_parent]"></td></tr>
<tr><th>Permissions:</th><td><input type="text" class="textbox" name="permissions" value="[$_permissions]"></td></tr>
<tr><th>Author:</th><td><input type="text" class="textbox" name="author" value="[$_author]"></td></tr>
<tr><th>Group:</th><td><input type="text" class="textbox" name="group" value="[$_group]"></td></tr>
<tr><th>Priority:</th><td><input type="text" class="textbox" name="priority" value="[$_priority]"></td></tr>
<tr><th>Template:</th><td><input type="text" class="textbox" name="template" value="[$_template]"></td></tr>
<tr><td></td><td>
<span class="buttonbox"><input name="submitButton" class="submit" type="submit" value="Submit"></span> <i>your permissions</i>: [$_viewer.permissions]</td></tr></table>
</form>
<br><br>
<a href="/?id=[_id]&mode=delete">delete this dictionary</a> (and all of its words and categories)
}, "What are you doing? You don't even have edit permission.");]
[end mode edit]

[begin mode edit_submit]
[$_title = $_params.title]
[$_subtitle = $_params.subtitle]
[$_parent = $_params.parent]
[$_permissions = $_params.permissions]
[$_author = $_params.author]
[$_group = $_params.group]
[$_priority = $_params.priority]
[$_template = $_params.template]
<h2>It was updated.</h2>
<a href="/?[$_title]">Return to it.</a> 
[end mode edit_submit]