<?php

/**
 *
 * @copyright  2010-2015 izend.org
 * @version    29
 * @link       http://www.izend.org
 */
?>
<?php extract($errors); ?>
<h3<?php if ($thread_title): ?> title="<?php echo $thread_id; ?>"<?php endif; ?>><?php echo htmlspecialchars($thread_title ? $thread_title : $thread_id, ENT_COMPAT, 'UTF-8'); ?></h3>
<form class="compact" action="" method="post">
<input name="clang" type="hidden" value="<?php echo $clang; ?>" />
<p>
<?php echo $inlanguages; ?>
<span id="thread_hidy" class="hidy">+</span>
</p>
<div id="thread">
<p>
<input id="thread_title" name="thread_title" type="text" size="40" maxlength="100" value="<?php echo htmlspecialchars($thread_title, ENT_COMPAT, 'UTF-8'); ?>" title="Title" onkeypress="return submitonenter(event, 'thread_edit')"/>
<label>URL:</label>
<input id="thread_name" name="thread_name" type="text" size="40" maxlength="100" value="<?php echo $thread_name; ?>" onkeypress="return submitonenter(event, 'thread_edit')"/>
</p>
<p><label>Abstract:</label></p>
<p>
<textarea name="thread_abstract" cols="80" rows="3"><?php echo htmlspecialchars($thread_abstract, ENT_COMPAT, 'UTF-8'); ?></textarea>
<br/><span class="grippie btn_edit btn_grippie">===</span>
</p>
<p><label>Cloud:</label></p>
<p>
<textarea name="thread_cloud" cols="80" rows="2"><?php echo htmlspecialchars($thread_cloud, ENT_COMPAT, 'UTF-8'); ?></textarea>
<br/><span class="grippie btn_edit btn_grippie">===</span>
</p>
<p><label>Image:</label></p>
<p>
<input name="thread_image" type="text" size="40" maxlength="200" value="<?php echo htmlspecialchars($thread_image, ENT_COMPAT, 'UTF-8'); ?>" title="File" />
</p>
<p>
<label>Type:</label>
<select name="thread_type" size="1">
<option value="thread"<?php if ($thread_type == 'thread'): ?> selected="selected"<?php endif; ?>>Thread</option>
<?php foreach ($supported_threads as $type): ?>
<?php if ($type == 'folder'): ?>
<option value="folder"<?php if ($thread_type == 'folder'): ?> selected="selected"<?php endif; ?>>Folder</option>
<?php elseif ($type == 'story'): ?>
<option value="story"<?php if ($thread_type == 'story'): ?> selected="selected"<?php endif; ?>>Article</option>
<?php elseif ($type == 'book'): ?>
<option value="book"<?php if ($thread_type == 'book'): ?> selected="selected"<?php endif; ?>>Manual</option>
<?php elseif ($type == 'rss'): ?>
<option value="rss"<?php if ($thread_type == 'rss'): ?> selected="selected"<?php endif; ?>>RSS</option>
<?php elseif ($type == 'newsletter'): ?>
<option value="newsletter"<?php if ($thread_type == 'newsletter'): ?> selected="selected"<?php endif; ?>>Newsletter</option>
<?php elseif ($type == 'campaign'): ?>
<option value="campaign"<?php if ($thread_type == 'campaign'): ?> selected="selected"<?php endif; ?>>Campaign</option>
<?php endif; ?>
<?php endforeach; ?>
</select>
</p>
<fieldset id="thread_options">
<legend>Options</legend>
<span class="nowrap"><input id="thread_search" name="thread_search" type="checkbox"<?php if ($thread_search): ?> checked="checked"<?php endif; ?> /><label for="thread_search"><span class="btn_edit btn_search">search</span></label></span>
<span class="nowrap"><input id="thread_tag" name="thread_tag" type="checkbox"<?php if ($thread_tag): ?> checked="checked"<?php endif; ?> /><label for="thread_tag"><span class="btn_edit btn_tag">cloud</span></label></span>
<span class="nowrap"><input id="thread_visits" name="thread_visits" type="checkbox"<?php if ($thread_visits): ?> checked="checked"<?php endif; ?> /><label for="thread_visits"><span class="btn_edit btn_visits">visits</span></label></span>
<span class="nowrap"><input id="thread_comment" name="thread_comment" type="checkbox"<?php if ($thread_comment): ?> checked="checked"<?php endif; ?> /><label for="thread_comment"><span class="btn_edit btn_comment">comment</span></label></span>
<span class="nowrap"><input id="thread_morecomment" name="thread_morecomment" type="checkbox"<?php if ($thread_morecomment): ?> checked="checked"<?php endif; ?> /><label for="thread_morecomment"><span class="btn_edit btn_morecomment">comment+</span></label></span>
<span class="nowrap"><input id="thread_vote" name="thread_vote" type="checkbox"<?php if ($thread_vote): ?> checked="checked"<?php endif; ?> /><label for="thread_vote"><span class="btn_edit btn_vote">vote</span></label></span>
<span class="nowrap"><input id="thread_morevote" name="thread_morevote" type="checkbox"<?php if ($thread_morevote): ?> checked="checked"<?php endif; ?> /><label for="thread_morevote"><span class="btn_edit btn_morevote">vote+</span></label></span>
<span class="nowrap"><input id="thread_ilike" name="thread_ilike" type="checkbox"<?php if ($thread_ilike): ?> checked="checked"<?php endif; ?> /><label for="thread_ilike"><span class="btn_edit btn_ilike">facebook</span></label></span>
<span class="nowrap"><input id="thread_tweet" name="thread_tweet" type="checkbox"<?php if ($thread_tweet): ?> checked="checked"<?php endif; ?> /><label for="thread_tweet"><span class="btn_edit btn_tweet">twitter</span></label></span>
<span class="nowrap"><input id="thread_plusone" name="thread_plusone" type="checkbox"<?php if ($thread_plusone): ?> checked="checked"<?php endif; ?> /><label for="thread_plusone"><span class="btn_edit btn_plusone">google+</span></label></span>
<span class="nowrap"><input id="thread_linkedin" name="thread_linkedin" type="checkbox"<?php if ($thread_linkedin): ?> checked="checked"<?php endif; ?> /><label for="thread_linkedin"><span class="btn_edit btn_linkedin">linkedin</span></label></span>
<span class="nowrap"><input id="thread_pinit" name="thread_pinit" type="checkbox"<?php if ($thread_pinit): ?> checked="checked"<?php endif; ?> /><label for="thread_pinit"><span class="btn_edit btn_pinit">pinit</span></label></span>
</fieldset>
<p>
<input class="submit submit_edit" id="thread_edit" name="thread_edit" type="submit" value="Edit" />
</p>
</div>
<script type="text/javascript">
$(document).ready(function() {
	$('.grippie').each(function() {
		var grippie = $(this);
		var textarea = grippie.prev().prev();
		var offset;

		grippie.mousedown(startDrag);

	    function startDrag(e) {
	      offset = textarea.height() - e.pageY;
	      textarea.css('opacity', 0.25);
	      $(document).mousemove(performDrag).mouseup(endDrag);
	      return false;
	    }

	    function performDrag(e) {
	      textarea.height(Math.max(32, offset + e.pageY) + 'px');
	      return false;
	    }

	    function endDrag(e) {
	      $(document).unbind('mousemove', performDrag).unbind('mouseup', endDrag);
	      textarea.css('opacity', 1);
	    }
	});
});
</script>
<h4>Contents</h4>
<p>
<input class="submit submit_add" id="node_create" name="node_create" type="submit" value="Add" />
content
<input id="new_node_title" name="new_node_title" type="text" size="50" maxlength="100" value="<?php echo htmlspecialchars($new_node_title, ENT_COMPAT, 'UTF-8'); ?>" title="Title" onkeypress="return focusonenter(event, 'new_node_number')"/>
<span class="nowrap">
#
<input id="new_node_number" name="new_node_number" type="text" size="2" maxlength="3" value="<?php echo htmlspecialchars($new_node_number, ENT_COMPAT, 'UTF-8'); ?>" title="Number" onkeypress="return submitonenter(event, 'node_create')"/>
</span>
<?php if ($thread_contents): ?>
<span id="threadcontent_hidy" class="hidy">+</span>
<?php endif; ?>
</p>
<?php if ($thread_contents): ?>
<div id="threadcontent">
<fieldset class="block">
<legend>Summary</legend>
<table cellpadding="2" cellspacing="0">
<tbody>
<?php
$i=1;
$maxlen=strlen(count($thread_contents))+1;
foreach ($thread_contents as $c) {
	extract($c);	/* pos, node_id node_title, node_url, node_number, node_ignored */
	$node_url .= '?' . 'clang=' . $clang;
?>
<tr>
<td><input name="p[<?php echo $i; ?>]" type="text" size="2" maxlength="<?php echo $maxlen; ?>" value="<?php echo $pos; ?>" /></td>
<td><a href="<?php echo $node_url; ?>" title="<?php echo $node_id; ?>"><?php echo $node_title ? htmlspecialchars($node_title, ENT_COMPAT, 'UTF-8') : $node_id; ?></a></td>
<?php if ($node_ignored): ?>
<td><span class="btn_edit btn_ignored">X</span></td>
<?php endif; ?>
</tr>
<?php
	$i++;
}
?>
</tbody>
</table>
</fieldset>
<p>
<input class="submit submit_sort" id="thread_reorder" name="thread_reorder" type="submit" value="Sort" />
thread or
<input class="submit submit_hide" id="node_hide" name="node_hide" type="submit" value="Hide" />
<input class="submit submit_show" id="node_show" name="node_show" type="submit" value="Show" />
<input class="submit submit_copy" id="node_copy" name="node_copy" type="submit" value="Copy" />
<input class="submit submit_delete" id="node_delete" name="node_delete" type="submit" value="Delete" />
content
<span class="nowrap">
#
<input id="old_node_number" name="old_node_number" type="text" size="2" maxlength="3" value="<?php echo htmlspecialchars($old_node_number, ENT_COMPAT, 'UTF-8'); ?>" title="Number" onkeypress="return submitonenter(event, 'node_delete')"/>
</span>
<?php if ($confirm_delete_node): ?>
<input class="submit submit_confirm" id="node_confirmdelete" name="node_confirmdelete" type="submit" value="Confirm" />
<?php endif; ?>
</p>
</div>
<?php endif; ?>
</form>
<?php head('javascript', 'jquery.cookie'); ?>
<script type="text/javascript">
if ($.cookie('hidethread') == 1) {
	$('#thread').hide();
}
$('#thread_hidy').click(function() {
	$('#thread').toggle();
	$.cookie('hidethread', $('#thread').is(':hidden') ? 1 : 0, { path: '/' });
});
</script>
<?php if ($thread_contents): ?>
<script type="text/javascript">
if ($.cookie('hidethreadcontent') == 1) {
	$('#threadcontent').hide();
}
$('#threadcontent_hidy').click(function() {
	$('#threadcontent').toggle();
	$.cookie('hidethreadcontent', $('#threadcontent').is(':hidden') ? 1 : 0, { path: '/' });
});
</script>
<?php endif; ?>
<?php
$focus=false;
if ($missing_thread_name or $bad_thread_name) {
	$focus='#thread_name';
}
else if ($missing_new_node_title or $bad_new_node_title) {
	$focus='#new_node_title';
}
else if ($bad_new_node_number) {
	$focus='#new_node_number';
}
else if ($missing_old_node_number or $bad_old_node_number) {
	$focus='#old_node_number';
}
else if ($confirm_delete_node) {
	$focus='#old_node_number';
}
?>
<?php if ($focus): ?>
<?php head('javascript', 'jquery.scrollTo', 'screen'); ?>
<script type="text/javascript">
$(function() {$('<?php echo $focus; ?>').focus(); $.scrollTo('<?php echo $focus; ?>', {offset: -200}); });
</script>
<?php endif; ?>
