<?php
	$id = (int)$_GET['edit'];
	$data = $this->source->db->get(
			$this->source->plugin_tables['links'],
			array( 'id' => $id )
	);
	if(count($data)){
		$url = $data[0]['url'];
		$anchor = $data[0]['anchor'];
		$target = $data[0]['target'];
		$index = $data[0]['do_index'];
		$follow = $data[0]['do_follow'];
	}
?>
<div class="flc-admin">
	<div class="page-header">
		<h1>Edit Link</h1>
	</div>
	<form class="form-horizontal" role="form" method="post">
<?php
	$sections = $this->source->db->get_all( $this->source->plugin_tables['sections'] );
	if(isset($this->error) && count($this->error) && isset($this->error['error'])){
?>
	<p class="alert alert-danger"><?php echo $this->error['error']?></p>
<?php
	}
?>
	  <div class="form-group">
	    <label for="url" class="col-sm-2 control-label">URL</label>
	    <div class="col-sm-10">
	      <input type="text" class="form-control" value="<?php echo $url; ?>" name="url" placeholder="Enter URL">
	    </div>
	  </div>
	  <div class="form-group">
	    <label for="anchor" class="col-sm-2 control-label">Anchor Text</label>
	    <div class="col-sm-10">
	      <input type="text" class="form-control" value="<?php echo $anchor; ?>" name="anchor" placeholder="Enter anchor text" maxlength="50">
	    </div>
	  </div>
	  <div class="form-group">
	    <label for="anchor" class="col-sm-2 control-label">Section</label>
	    <div class="col-sm-10">
<?php
	if(count($sections)){
?>
		<select class="form-control" name="section">
<?php
		foreach($sections as $section){
?>
		  <option value="<?php echo $section['id'];?>"><?php echo $section['name'];?></option>
<?php			
		}
?>
		</select>
<?php
	} else {
?>
		<p class="alert alert-danger">Please add a section first, you will not be able to add links without adding a section</p>
<?php
	}
?>
	    </div>
	  </div>
	  <div class="form-group">
	    <label for="anchor" class="col-sm-2 control-label">Browsing Options</label>
	    <div class="col-sm-10">
		<div class="radio">
		  <label>
		    <input type="radio" name="target" value="_blank" <?php echo ($target == '_blank' ) ? 'checked' : ''; ?>> Open in new tab
		  </label>
		</div>
		<div class="radio">
		  <label>
		    <input type="radio" name="target" value="_self" <?php echo ($target == '_self' ) ? 'checked' : ''; ?>> Open in the current window
		  </label>
		</div>
	    </div>
	  </div>
	  <div class="form-group">
	    <label for="anchor" class="col-sm-2 control-label">Search Engine Options</label>
	    <div class="col-sm-10">
		<div class="radio">
		  <label>
		    <input type="radio" name="follow" value="0" <?php echo (!$follow) ? 'checked' : ''; ?>> nofollow
		  </label>
		</div>
		<div class="radio">
		  <label>
		    <input type="radio" name="follow" value="1" <?php echo ($follow) ? 'checked' : ''; ?>> dofollow
		  </label>
		</div>

		<div class="radio">
		  <label>
		    <input type="radio" name="index" value="0" <?php echo (!$index) ? 'checked' : ''; ?>> noindex
		  </label>
		</div>
		<div class="radio">
		  <label>
		    <input type="radio" name="index" value="1" <?php echo ($index) ? 'checked' : ''; ?>> doindex
		  </label>
		</div>
	    </div>
	  </div>
	  <div class="form-group">
	    <div class="col-sm-offset-2 col-sm-10">
	      <button type="submit" class="btn btn-primary btn-lg col-sm-12" name="edit_link">Submit</button>
	    </div>
	  </div>
	</form>
</div>
