<?php

require_once('include/admin.inc.php');

auth_redirect(); // Require logged in user to access this page.

$last_type = $mtdb->getOne( 'SELECT type FROM strip ORDER BY id DESC limit 1' );
$last_strip_id = $mtdb->getOne( 'SELECT MAX(id) FROM strip' );

adminhead('Post Comic');
adminmenu('post-comic.php');

$tomorrow = strtotime('tomorrow');
$post_date = time();

if(isset($_REQUEST['next']) && $_REQUEST['next'] == "yes")
{
	//in general, this is the case that is desired
	//	the next monday, wednesday, or friday that isn't today
	$post_date = min( strtotime("next Monday +1 hour", $tomorrow), strtotime("next Wednesday +1 hour", $tomorrow), strtotime("next Friday +1 hour", $tomorrow) );

	//however, if it is monday, wednesday, or friday AND before 1 AM
	// then we want to post at 1 AM on this day
	$today = date("l");
	if(($today == "Monday" || $today == "Wednesday" || $today == "Friday") && date("G") == 0)
	{
		$post_date = "today +1 hour";
	}
}

?>

<h2>Post New Comic</h2>

<form enctype="multipart/form-data" action="edit-comic.php" method="post" name="post" id="post">
<?php nonce_field('new-strip'); ?>
<input type="hidden" name="action" value="new_comic" />
<div id="poststuff">

<div id="moremeta">
<div id="grabit" class="dbx-group">

<fieldset id="slugdiv" class="dbx-box">
<h3 class="dbx-handle">Comic Type</h3>
<div class="dbx-content"><select name="strip_type">
<?php
$types = $mtdb->getAll( 'SELECT id, description FROM strip_t ORDER BY id' );
foreach( $types as $k=>$v )
	printf('<option value="%s" %s>%s</option>', htmlentities($v->id), ($last_type == $v->id ? 'selected="selected"' : '' ), $v->description);
?>
</select></div>
</fieldset>

<fieldset id="pubdatediv" class="dbx-box">
<h3 class="dbx-handle">Post Date</h3>
<div class="dbx-content"> <input type="text" name="strip_date" value="<?php echo date('Y-m-d H:i:s', $post_date); ?>" /> </div>
</fieldset>

<fieldset id="pubdatediv" class="dbx-box">
<h3 class="dbx-handle">Strip Number</h3>
<div class="dbx-content"> <input type="text" name="strip_new_id" size="6" value="<?php echo $last_strip_id + 1; ?>" id="strip_id" /> </div>
</fieldset>

<fieldset id="stripdiv" class="dbx-box">
<h3 class="dbx-handle">Upload Comic</h3>
<div class="dbx-content">
	<input type="hidden" name="MAX_FILE_SIZE" value="10000000" />
	<input name="comicFile" type="file" tabindex="2" size="12" />
</div>
</fieldset>

<fieldset id="bookpagenumberdiv" class="dbx-box">
	<h3 class="dbx-handle">Book Page Number</h3>
	<div class="dbx-content"> <input type="text" name="book" size="3" value="" />-<input type="text" name="page" size="4" value=""/> </div>
</fieldset>

</div>
</div>

<fieldset id="titlediv">
	<legend>Title</legend>
	<div><input type="text" name="strip_title" size="40" tabindex="1" value="" id="title" /></div>
</fieldset>

<fieldset id="postdivrich">
	<legend>Transcript</legend>
	<style type="text/css">
		#postdivrich table, #postdivrich #quicktags {border-top: none;}
		#quicktags {border-bottom: none; padding-bottom: 2px; margin-bottom: -1px;}
		#edButtons {border-bottom: 1px solid #ccc;}
	</style>
	<div><textarea class="mceEditor" rows="27" cols="40" name="content" tabindex="3" id="content"></textarea></div>
</fieldset>

<p class="submit">
 <input name="post_comic" type="submit" id="post_comic" tabindex="4" accesskey="p" value="Post Comic" />
</p>

</div>
</form>
<?php
adminfooter();
?>
