<?php

/**
 * Provide a admin view for the "create"-action for answers
 *
 * @link       http://www.weedesign.de/weebotLite.html
 * @since      1.0.0
 *
 * @package    weebotLite
 * @subpackage weebotLite/admin/template
 */
 

	/* 
	*	get answer-files
	*/
	$files = $this->get_answer_files();
	
	/* 
	*	get active chat user
	*/
	$chat_user = (isset($parameter["chat"])) ? $parameter["chat"]->user : $parameter["user"];
	
?>
<h2 class="nav-tab-wrapper"><?php esc_attr_e( 'Create answer', $this->plugin_name ); ?></h2>
<form method="post" action="<?php echo admin_url( 'admin.php?page=' . $this->plugin_name . '-answers' ); ?>" id="<?php echo $this->plugin_name; ?>-form-<?php echo $parameter["question"]->id; ?>" class="<?php echo $this->plugin_name; ?>-form<?php if(isset($_GET["existing"])) { ?> existing-form<?php } ?>">
	<input type="hidden" name="<?php echo $this->plugin_name; ?>[create]" />
	<input type="hidden" name="<?php echo $this->plugin_name; ?>[question]" class="question-id" value="<?php echo $parameter["question"]->id; ?>" />
	<input type="hidden" name="<?php echo $this->plugin_name; ?>[user]" class="user-id" value="<?php echo $chat_user; ?>" />
	<input type="hidden" name="<?php echo $this->plugin_name; ?>[subject]" class="subject" value="<?php esc_attr_e( 'Answer for your Question', $this->plugin_name ); ?>" />
	<table class="form-table">
		<tbody>
			<tr class="question-row">
				<th scope="row"><span><?php esc_attr_e( 'Question', $this->plugin_name ); ?></span></th>
				<td> 
					<?php echo esc_html($parameter["question"]->question); ?>
					<a href="<?php echo admin_url( 'admin.php?page=' . $this->plugin_name . '-questions&amp;action=view&amp;post='.$parameter["question"]->id ); ?>" class="button"><?php esc_attr_e( 'View question', $this->plugin_name ); ?></a>
				</td>
			</tr>
			<tr class="existing-row">
				<th scope="row"><span><?php esc_attr_e( 'Use existing Answer', $this->plugin_name ); ?></span></th>
				<td> 
					<input type="text" id="<?php echo $this->plugin_name; ?>-lookup-answers" data-id="<?php echo $parameter["question"]->id; ?>" />
					<div id="<?php echo $this->plugin_name; ?>-lookup-answers-submit" data-id="<?php echo $parameter["question"]->id; ?>" data-error="<?php esc_attr_e( 'Enter a Search-Query', $this->plugin_name ); ?>" class="button"><?php esc_attr_e( 'Search', $this->plugin_name ); ?></div>
					<p class="description"><?php esc_attr_e( 'Search for an existing answer and use it as your response', $this->plugin_name ); ?>.</p>
					<div id="<?php echo $this->plugin_name; ?>-lookup-answers-results"></div>
				</td>
			</tr>
			<tr class="type-row">
				<th scope="row"><span><?php esc_attr_e( 'Type', $this->plugin_name ); ?></span></th>
				<td> 
					<fieldset>
						<legend class="screen-reader-text"><span><?php esc_attr_e( 'Type', $this->plugin_name ); ?></span></legend>
						<label for="<?php echo $this->plugin_name . "-" . $parameter["question"]->id;?>-type">
							<select id="<?php echo $this->plugin_name . "-" . $parameter["question"]->id;?>-type" class="type" name="<?php echo $this->plugin_name;?>[type]" data-question-id="<?php echo $parameter["question"]->id; ?>">
								<option value="-1"><?php esc_attr_e( 'Gossip', $this->plugin_name ); ?></option>
								<option value="0"><?php esc_attr_e( 'Answer', $this->plugin_name ); ?></option>
								<option value="1"><?php esc_attr_e( 'Question', $this->plugin_name ); ?></option>
								<option value="2"><?php esc_attr_e( 'URL', $this->plugin_name ); ?></option>
								<?php if($files!==false) { ?><option value="3"><?php esc_attr_e( 'File', $this->plugin_name ); ?></option><?php } ?>
							</select>
							<p class="description"><?php esc_attr_e( 'The type of the response (gossip will not be remembered)', $this->plugin_name ); ?></p>
						</label>
					</fieldset>
				</td>
			</tr>
			<?php if($files!==false) { ?>
			<tr class="files hidden" id="answer_files_<?php echo $parameter["question"]->id; ?>">
				<th scope="row"><span><?php esc_attr_e( 'File', $this->plugin_name ); ?></span></th>
				<td> 
					<fieldset>
						<legend class="screen-reader-text"><span><?php esc_attr_e( 'File', $this->plugin_name ); ?></span></legend>
						<label for="<?php echo $this->plugin_name . "-" . $parameter["question"]->id;?>-file">
							<select id="<?php echo $this->plugin_name . "-" . $parameter["question"]->id;?>-file" class="files" name="<?php echo $this->plugin_name;?>[file]">
								<?php
									foreach($files as $file) {
										?><option value="<?php echo $file; ?>"><?php echo str_replace(".phtml","",$file);; ?></option><?php
									}
								?>
							</select>
							<p class="description"><?php esc_attr_e( 'The file for the response', $this->plugin_name ); ?></p>
						</label>
					</fieldset>
				</td>
			</tr>
			<?php } ?>
			<tr class="answers answers-row" id="answer_<?php echo $parameter["question"]->id; ?>">
				<th scope="row"><span><?php esc_attr_e( 'Action', $this->plugin_name ); ?></span></th>
				<td> 
					<fieldset>
						<legend class="screen-reader-text"><span><?php esc_attr_e( 'Action', $this->plugin_name ); ?></span></legend>
						<label for="<?php echo $this->plugin_name . "-" . $parameter["question"]->id;?>-action">
							<input type="text" id="<?php echo $this->plugin_name . "-" . $parameter["question"]->id;?>-action" class="action" name="<?php echo $this->plugin_name;?>[action]" />
							<p class="description"><?php esc_attr_e( 'The answer, question or filename', $this->plugin_name ); ?></p>
						</label>
					</fieldset>
				</td>
			</tr>
			<tr class="page-row">
				<th scope="row"><span><?php esc_attr_e( 'Page', $this->plugin_name ); ?></span></th>
				<td> 
					<fieldset>
						<legend class="screen-reader-text"><span><?php esc_attr_e( 'Page', $this->plugin_name ); ?></span></legend>
						<label for="<?php echo $this->plugin_name . "-" . $parameter["page"]->id;?>-page">
							<input type="checkbox" id="<?php echo $this->plugin_name . "-" . $parameter["page"]->id;?>-page" class="page" value="<?php echo $parameter["page"]->id;?>" name="<?php echo $this->plugin_name;?>[page]" />
							<p class="description"><?php esc_attr_e( 'This answer is page-related', $this->plugin_name ); ?></p>
							<a class="url" href="<?php echo $parameter["page"]->page; ?>" target="_blank"><?php echo $parameter["page"]->page; ?></a>
						</label>
					</fieldset>
				</td>
			</tr>
		</tbody>
	</table>
	<p class="submit"><input type="submit" name="submit" id="submit" class="button button-primary" value="<?php esc_attr_e( 'Create answer', $this->plugin_name ); ?>"></p>
</form>