Language
Site Infrastructure / Language

[show modes: view edit move]
[direct modes: move]

[begin preamble]
if(title2id_i(_title) != _id)
	_bestlink = {id=[_id]}
else if(strcount(_title, "&"))
	_bestlink = {id=[_id]}
else
	_bestlink = urlencode(_title);

parent_dropdown = function {
  
  <select name="parid" style="width: 80%;">
  [
    tmp = title2id({Universe});
    foreach (query_run("id", query("universes", 0, "title collate utf8mb4_general_ci", "template", tmp))) _data = {[
      if(can_comment(_data)) {
        <option value="[_data]">[get_title(_data)] (Universe)</option>
      }
    ]};

    tmp = title2id({Language Family});
    foreach (query_run("id", query("families", 0, "title collate utf8mb4_general_ci", "template", tmp))) _data = {[
      if(can_comment(_data)) {
        <option value="[_data]">[get_title(_data)] (Family)</option>
      }
    ]}
  ]
  </select>
};

setgrc = function($page, $g) {[

  var old_group = get_group($page);
  if ($g == old_group) {[
    return
  ]}
  set_group($page, $g);

  var hcount = 1;
  var hsum = 0;

  while(hcount > 0) {[
    mute command({update entries as A
      inner join entries as B on A.parent = B.id
      set A.group = [$g]
      where B.group = [$g];
    });

    $remaining = retrieve({
      select count(A.id) as e
      from entries as A
      inner join entries as B on A.parent = B.id
      where B.group = [$g] and A.group = [old_group];
    });

    hcount = $remaining[0]["e"];
    debug($remaining);
    debug("hcount: " & hcount & " children of " & $g);
    hsum += hcount;
  ]};

  {
    Page moved! [if(hsum > 0) {[hsum] child pages also changed to the new parent's group.}]
  };
]};
[end preamble]

[begin mode move_submit]
[
if(can_direct() && can_comment($_params.parid)) {
  [
    $_lastp = $_parent;
    $grp = get_group($_params.parid);
    setgrc($_id, $grp);
    set_parent($_id, $_params.parid);  
  ]
	<p><b>[$_title]</b> has been moved from <b>[get_title($_parent)]</b>
  to <b>[get_title($_params.parid)]</b>.</p>
} else {
	<p><b>[$_title]</b> could not be moved from <b>[get_title($_parent)]</b> to
  <b>[get_title($_parent)]</b> by you ([$_viewer.name]). If you feel that
  should be able to do so, now might be a good time to
	<a href="mailto:[$_globals.ADMIN_EMAIL]"> write a letter to the administrator</a>.</p>
}]

<p><a href="/?id=[$_parent]">Return to [get_title($_parent)]</a> or <br>
<a href="/?id=[$_params.parid]">Go to [get_title($_params.parid)]</a></p>
[end mode move_submit]

[begin mode move]
  <table class="front_table">
  <form method="post" action="/">
    <input type="hidden" name="id" value="[$_id]">
    <input type="hidden" name="create" value="1">
    <input type="hidden" name="mode" value="move_submit">
    <tr>
    <td>[parent_dropdown()]<label for="submit"><input type="submit" id="submit" value="Move">Move the language to this family.</label>
    </tr>
  </form>
  </table>
[end mode move]

[begin mode index][if(and(_body == "", count(_children()) == 0))
	""
else if(getv("redirect") == "") {
<li><a href="/?[_bestlink]"><b>[$_title]</b></a> <i>[$_subtitle]</i>
<span style="font-size: 70%; display: block">started by: [if(_owner.profile_id != 0) {<a href="/?id=[_owner.profile_id]">[_owner.name]</a>} else _owner.name]
</li>}]
[end mode index]

[begin mode delete_submit]
[$n = delete_page($_id);
mute children("delete", $_id);
mute children("delete_submit", $_id);
if($n == "1") {
	<p><b>[$_title]</b> has been removed from <b>[get_title($_parent)]</b>.</p>
} else {
	<p><b>[$_title]</b> could not be removed from <b>[get_title($_parent)]</b>
	by you ([$_viewer.name]). If you feel that should be able to do so, now
	might be a good time to
	<a href="mailto:[$_globals.ADMIN_EMAIL]"> write a letter to the administrator</a>.</p>
}]
<p><a href="/?id=[$_parent]">Return to [get_title($_parent)]</a></p>
[end mode delete_submit]

[begin mode table]
<tr><th>[if(getv("redirect") != "") {
	<a href="./?id=[getv("redirect")]">[$_title]</a>
} else {
	<a href="./?[_bestlink]">[$_title]</a>
}]
<td>[_wiki_format(getv("synopsis"), "inline")]
[if(getv("redirect") != "") {
	<span style="font-size: 60%; display: inline-block; vertical-align: top">
		[if(can_edit()) {<a href="./?id=[_id]&mode=edit">(edit)</a> }]
	</span>
}]
[end mode table]
[begin mode floatpic]
[$e = getv("picture");
if($e != "") {
<p style="text-align: right">
<a href="/?[_bestlink]"><img src="[info_display($e)]" title="[$_title]" style="max-height: 60px;"></a>
</p>
}]
[end mode floatpic]

[begin mode abbr]
[
iif(can_read(), {
	<li>[if(getv("redirect") != "") {<b><a href="./?id=[getv("redirect")]">[$_title]</a></b><span style="font-size: 60%; display: inline-block; vertical-align: top"> ↗[if(can_edit()) { <a href="./?id=[_id]&mode=edit">(edit)</a> }]</span>} else {<b><a href="./?[_bestlink]">[$_title]</a></b>}]</li>
	});
]
[end mode abbr]
[begin mode view]
[if(getv("redirect") != "") {[
	http_header({HTTP/1.1 307 Temporary Redirect});
	http_header({Location: [bare_url()]?id=[getv("redirect")]});
]};

page("view", 278);

if(_group != 0) {[
	gpid = get_group_profile_id(_group);
	if(gpid != 0) page("css", gpid);
]};

$e = getv("picture");
if($e != "") {<img src="[info_display($e)]" style="max-width: 50%; float: right; margin-left: 10px; margin-bottom: 10px;">};]

[_wiki_format(getv("description"), "1");]

[$d = search("abbr", "parent", $_id, "template", title2id("Recursive Wiki Page"));]
[$di = search("abbr", "parent", $_id, "template", title2id("Dictionary"));]

[if($d != "") {
<h2>Articles</h2>
<ul>
[$d]
</ul>
};]


[if($di != "") {
<h2>Dictionaries</h2>
<ul>
[$di]
</ul>
};]

[if(can_comment()) {
<p><b>Create New</b>: <a href="/?id=[$_id]&mode=add">Article</a> · <a href="/?id=[$_id]&mode=add_dict">Dictionary</a></p>
};]

[if(can_direct()) {
	[msg_start({clear: both; text-align: center;})]
	<!-- <a href="/edit_group.star?id=[$_group]">Edit Users and Permissions</a> · --> <a href="/?id=[$_id]&mode=edit">Edit This Page</a>
	[msg_end()]
};
]
<div style="clear: both;"></div>
[end mode view]
[begin mode edit]
<form action="/" method="post">
	<input type="hidden" name="id" value="[$_id]">
	<input type="hidden" name="mode" value="submit">
	<table style="width: 100%">
	<tr><th>Name:<td><input type="text" name="title" value="[edit_display($_title)]" style="width: 100%">
	<tr><th>Subtitle:	<td><input type="text" name="subtitle" value="[edit_display($_subtitle)]" style="width: 100%">
	<tr><th>Synopsis:<td><input type="text" name="synopsis" value="[edit_display(getv("synopsis"))]" style="width: 100%">
	<tr><th>Picture URL:<td><input type="text" name="picture" value="[edit_display(getv("picture"))]" style="width: 100%;">
	<tr><th>Redirect:<td><input type="text" name="redirect" value="[edit_display(getv("redirect"))]"> (specify the ID number of another page to redirect to.)
	<tr><th>Description:<td><textarea name="description" rows="10" style="width: 100%;">[edit_display(getv("description"));]</textarea>
<br>
<span style="font-size: 80%">You can use some formatting here. See <a href="/?Formatting and Markup" target="_new">this page</a> for more details.</span>
<tr><td><td><input type="submit" value="Submit">
<br><a href="/?id=[_id]&mode=delete">delete this language</a>
<br><a href="/?id=[_id]&mode=move">move this language</a>
</table>
</form>
[end mode edit]
[begin mode submit]
[
	$_title = $_params.title;
//	set_group_name($_group, $_params.title);
	$_subtitle = $_params.subtitle;
	putv("picture", $_params.picture);
	putv("description", $_params.description);
	putv("synopsis", $_params.synopsis);
	putv("redirect", $_params.redirect);

	if(title2id(_title) != _id)
		_bestlink = {id=[_id]}
	else
		_bestlink = urlencode(_title);

	refresh_to({./?[_bestlink]}, 1);
]
<h2>Update Complete</h2>
<p><a href="/?[_bestlink]">Click here to return to the language</a>.</p>
[end mode submit]
[begin mode add]
<form method="post" action="/">
	<input type="hidden" name="id" value="[$_id]">
	<input type="hidden" name="mode" value="add_submit">
	<b>Article Title</b>: <input type="text" name="title">
	<input type="submit" value="Submit">
</form>
[end mode add]
[begin mode add_submit]
[
$e = new_page($_params.title, $_id);
if($e > 0) {
    [
    set_template($e, title2id("Recursive Wiki Page"));
    set_group($e, $_group);
    set_permissions($e, "cadrecadrecadre---r-");
    page("edit", $e);
    ]
} else {
    [msg_start();]
    Disaster. It failed! Maybe you should check the error log.
    [msg_end();]
};
]
[end mode add_submit]

[begin mode add_dict]
<form method="post" action="/">
	<input type="hidden" name="id" value="[$_id]">
	<input type="hidden" name="mode" value="add_dict_submit">
	<b>Dictionary Title</b>: <input type="text" name="title">
	<input type="submit" value="Submit">
</form>
[end mode add_dict]
[begin mode add_dict_submit]
[
$e = new_page($_params.title, $_id);
if($e > 0) {
    [
    set_template($e, title2id("Dictionary"));
    set_group($e, $_group);
    set_permissions($e, "cadrecadrecadre---r-");
    page("edit", $e);
    ]
} else {
    [msg_start();]
    Disaster. It failed! Maybe you should check the error log.
    [msg_end();]
};
]
[end mode add_dict_submit]