<?php $this->load->view('templates_admin/_header'); ?>

<?php $this->load->view('templates_admin/_sidebar'); ?>

<div class="col-md-8">

<section class="panel panel-default">
	<div class="panel-body">

<pre>
<?php
print_r($post);
?>
</pre>


	<?php
	if (empty($post['id'])) { // create post
		$id = '';
	} else { // edit post
		$id = $post['id'];
	}
	$form_attributes = array('class' => 'form-horizontal post-edit-form');
	echo form_open(base_url().'admin/post_edit/'.$id, $form_attributes);
	?>


	<div class="form-group">
		<div class="col-sm-offset-3 col-sm-9">
			<h2><?php
				if (empty($post['id'])) {
					echo 'Add a new post';
				} else {
					echo 'Edit post: ' . $post['title'];
				}
			?></h2>

			<div class="btn-group">
				<?php
				if ( !empty($post['id']) ) :
				$input_delete_attributes = array(
					'class' => 'btn btn-danger',
					'onClick' => "return confirm('Are you sure you want to delete?')"
				);
				echo anchor(base_url().'admin/post_delete/'.$post['id'], 'Delete', $input_delete_attributes);

				$input_view_attributes = array(
					'class' => 'btn btn-default'
				);
				echo anchor(base_url().'posts/view/'.$post['id'], 'View', $input_view_attributes);
				endif;
				?>
			</div>

			<?php echo validation_errors('<div class="alert alert-danger">', '</div>'); ?>

		</div>
	</div>


	<div class="form-group">
		<?php
		$label_title_attributes = array(
			'class' => 'col-sm-3 control-label'
		);
		echo form_label('Title', 'id_title', $label_title_attributes);
		?>
		<div class="col-sm-9">
			<?php
			$input_title_attributes = array(
				'class' => 'form-control input-lg',
				'name' => 'title',
				'id' => 'id_title',
				'value' => set_value('title', $post['title']), // get value from POST array or use saved value by default
				'maxlength' => '100',
				'required' => 'true'
			);
			echo form_input($input_title_attributes);
			?>
		</div>
	</div>


	<div class="form-group">
		<?php
		$label_slug_attributes = array(
			'class' => 'col-sm-3 control-label'
		);
		echo form_label('Slug', 'id_slug', $label_slug_attributes);
		?>
		<div class="col-sm-9">
			<?php
			$input_slug_attributes = array(
				'class' => 'form-control input-lg',
				'name' => 'slug',
				'id' => 'id_slug',
				'value' => set_value('slug', $post['slug']), // get value from POST array or use saved value by default
				'maxlength' => '100',
				'required' => 'true'
			);
			echo form_input($input_slug_attributes);
			?>
		</div>
	</div>


	<div class="form-group">
		<?php
		$label_published_attributes = array(
			'class' => 'col-sm-3 control-label'
		);
		echo form_label('Published', 'id_published', $label_published_attributes);
		?>
		<div class="col-sm-9">
			<?php
			if (empty($post['id'])) { // create post
				$published_date = date('Y-m-d H:i:s');
			} else { // edit post
				$published_date = $post['published'];
			}
			$input_published_attributes = array(
				'class' => 'form-control input-lg',
				'name' => 'published',
				'id' => 'id_published',
				'value' => set_value('published', $post['published']), // get value from POST array or use saved value by default
				'maxlength' => '100',
				'required' => 'true'
			);
			echo form_input($input_published_attributes);
			?>
		</div>
	</div>

	<div class="form-group">
		<?php
		$label_content_attributes = array(
			'class' => 'col-sm-3 control-label'
		);
		echo form_label('Content', 'id_content', $label_content_attributes);
		?>
		<div class="col-sm-9">
			<?php
			$input_content_attributes = array(
				'class' => 'form-control input-lg',
				'name' => 'content',
				'id' => 'id_content',
				'value' => set_value('content', $post['content']), // get value from POST array or use saved value by default
				'maxlength' => '100',
				'required' => 'true'
			);
			echo form_textarea($input_content_attributes);
			?>
		</div>
	</div>


	<div class="form-group">
		<div class="col-sm-offset-3 col-sm-9">
			<?php
			$input_submit_attributes = array(
				'class' => 'btn btn-lg btn-primary btn-block',
				'name' => 'submit',
				'value' => 'Save'
			);
			echo form_submit($input_submit_attributes);
			?>
		</div>
	</div>

	<?php
	//if ( !empty($post['id']) ) {
	//	echo form_hidden('id', $post['id']);
	//}
	?>

	<?php echo form_close(); ?>

	</div>
</section>

</div>

<?php $this->load->view('templates_admin/_footer'); ?>