function prereq_new_settings_page()
{
    $semantic = WP_PLUGIN_URL . '/panomanager/css/semantic.css';
    $domains = get_domains();
    $items = get_items();
    $item_types = get_item_types();
    $pano_id = null;
    if (isset($_GET['pano_id']) && is_numeric($_GET['pano_id'])) {
        $pano_id = $_GET['pano_id'];
    }
    ?>
<link rel="stylesheet" type="text/css" href="<?php 
    echo $semantic;
    ?>
"/>
<h2>Create a new Prereq!</h2>
<hr>
<form method="post" enctype="multipart/form-data" action="<?php 
    echo get_admin_url() . 'admin-post.php';
    ?>
">
  <!-- pano processing hook -->
  <input type="hidden" name="action" value="create_new_prereq" />
  <input type="hidden" name="pano_id" value="<?php 
    echo $pano_id;
    ?>
" />
  <div class="ui form segment new_prereq_form">
    <div class="ui form">
      <div class="field">
        <div class="ui left labeled icon input">
          <label for="prereq_pts">Prereq Points</label>
          <input type="number" name="prereq_pts" id="prereq_pts" placeholder="100" required />
        </div>
      </div>
    </div>
    <div class="ui form">
      <div class="field">
        <label for="prereq_domain_id">Select a Prereq Domain</label>
        <select name="prereq_domain_id">
          <option value="NA">...</option>
          <?php 
    foreach ($domains as $domain) {
        ?>
          <option value="<?php 
        echo $domain->id;
        ?>
"><?php 
        echo $domain->name;
        ?>
</option>
          <?php 
    }
    ?>
        </select>
      </div>
    </div>
    <div class="ui form">
      <div class="field">
        <label for="prereq_desc">Prereq Info</label>
        <textarea name="prereq_desc" id="prereq_desc"  required ></textarea>
      </div>
    </div>
    <div class="ui form">
      <div class="field">
        <label for="item_type">Filter by Item Type</label>
        <select name="item_type" id="item_type" class="ui dropdown">
          <option value="">All items</option>
          <?php 
    foreach ($item_types as $item_type) {
        ?>
          <option value="<?php 
        echo $item_type->id;
        ?>
"><?php 
        echo $item_type->name;
        ?>
</option>
          <?php 
    }
    ?>
        </select>
      </div>
    </div>
    <div class="ui form">
      <div class="field">
        <label>Items</label>
        <ul>
          <?php 
    foreach ($items as $item) {
        ?>
          <li class="games_form">
            <input type="checkbox" id="<?php 
        echo $item->id;
        ?>
" name="items[]" value="<?php 
        echo $item->id;
        ?>
">
            <label for="<?php 
        echo $item->id;
        ?>
"><?php 
        echo $item->name;
        ?>
</label>
          </li>
          <?php 
    }
    ?>
        </ul>
      </div>
    </div>
    <?php 
    submit_button();
    ?>
  </div>
</form>
<?php 
}
function edit_item_settings_page()
{
    $semantic = WP_PLUGIN_URL . '/panomanager/css/semantic.css';
    $item = null;
    if (isset($_GET['id']) && is_numeric($_GET['id'])) {
        $item = build_item($_GET['id']);
    }
    $item_types = get_item_types();
    ?>
<link rel="stylesheet" type="text/css" href="<?php 
    echo $semantic;
    ?>
"/>
<h2>Edit your item!</h2>
<hr>
<style type="text/css">
    #wpfooter{
        display: none;
    }

    #file_input {
        border: 1px solid #cccccc;
        padding: 5px;
    }

    .new_pano_form{
        width:85%;
        margin: 0px auto;
    }
</style>
<?php 
    if (isset($_GET['settings-saved'])) {
        ?>
    <div class="updated"><p>Item updated successfully.</p></div>
<?php 
    } elseif (isset($_GET['error'])) {
        ?>
    <div class="error"><p>Error updating item.</p></div>
<?php 
    }
    ?>
<form method="post" enctype="multipart/form-data" action="<?php 
    echo get_admin_url() . 'admin-post.php';
    ?>
" >
    <input type="hidden" name="action" value="edit_item"/>
    <input type="hidden" name="item_id" value="<?php 
    echo $item->get_id();
    ?>
"/>
    <div class="ui form segment new_item_form">
        <div class="ui form ">
            <div class="field">
                <div class="ui left labeled icon input">
                    <label>Item Name</label>
                    <input name="item_name" id="name" placeholder="Name" value="<?php 
    echo $item->get_name();
    ?>
" required/>
                </div>
            </div>
        </div>
        <div class="ui form ">
            <div class="field">
                <div class="ui left labeled icon input">
                    <label>Item Info</label>
                    <input name="item_description" id="description" placeholder="Description" value="<?php 
    echo $item->get_description();
    ?>
" required />
                </div>
            </div>
        </div>
        <div class="ui form">
            <div class="field">
                <div class="ui left labeled icon input">
                    <label for="image">Choose an image: <b>(Preferably 120x120)</b> </label>
                    <img class="item_image" src="<?php 
    echo content_url() . '/' . $item->get_image();
    ?>
" alt="Image"/>
                    <input type="file" name="item_image" id="image"  />
                </div>
            </div>
        </div>
        <div class="ui form ">
            <div class="field">
                <div class="ui left labeled icon input">
                    <label>Item Price</label>
                    <input name="item_price" id="price" placeholder="Price" value="<?php 
    echo $item->get_price();
    ?>
"/>
                </div>
            </div>
        </div>
        <div class="ui form">
            <div class="field">
                <label>Select an item type</label>
                <select name="item_type_id">
                    <option value="NA">...</option>
                    <?php 
    foreach ($item_types as $item_type) {
        ?>
                        <option value="<?php 
        echo $item_type->id;
        ?>
" <?php 
        echo $item_type->id === $item->get_type_id() ? "selected" : "";
        ?>
><?php 
        echo $item_type->name;
        ?>
</option>
                    <?php 
    }
    ?>
                </select>
            </div>
        </div>
        <?php 
    submit_button();
    ?>
    </div>
</form>
<?php 
}
function item_types_settings_page()
{
    $item_types = get_item_types();
    $semantic = WP_PLUGIN_URL . '/panomanager/css/semantic.css';
    $new_item_type_url = admin_url() . 'admin.php?page=new_item_type_settings';
    $edit_item_type_url = admin_url() . 'admin.php?page=edit_item_type_settings';
    ?>

<link rel="stylesheet" type="text/css" href="<?php 
    echo $semantic;
    ?>
"/>
<style>
#wpfooter{
  display: none;
}
</style>
<p>Manage your item types!</p>
<hr>

<?php 
    if (isset($_GET['settings-saved'])) {
        ?>
    <div class="updated"><p>Settings updated successfully.</p></div>
<?php 
    }
    ?>

<h2>Item Types</h2>
<table class="ui table segment">
  <tr>
    <th>Item Type</th>
    <th>Edit</th>
    <th>Delete</th>
  </tr>
  <?php 
    foreach ($item_types as $item_type) {
        ?>

    <tr>
        <td><?php 
        echo $item_type->name;
        ?>
</td>
        <td><a class="ui blue icon button" style="padding: 7px" href="<?php 
        echo $edit_item_type_url;
        ?>
&id=<?php 
        echo $item_type->id;
        ?>
">Edit</a></td>
        <td>
            <form method="post" action="admin-post.php" id="delete_item_type_form<?php 
        echo $item_type->id;
        ?>
">

                <input type="hidden" name="action" value="delete_item_type" />
                <input type="hidden" name="item_type_id" value="<?php 
        echo $item_type->id;
        ?>
" />

                <input type="submit" class="ui blue icon button" style="padding: 7px" value="Delete">
            </form>
        </td>
    </tr>

    <?php 
    }
    ?>
</table>
<a class="ui blue icon button" style="padding: 7px" href="<?php 
    echo $new_item_type_url;
    ?>
">New Item Type</a>
</div>

<?php 
}
function prereq_edit_settings_page()
{
    $semantic = WP_PLUGIN_URL . '/panomanager/css/semantic.css';
    $domains = get_domains();
    $items = get_items();
    $item_types = get_item_types();
    $prereq = null;
    $prereq_id = null;
    if (isset($_GET['pano_id']) && is_numeric($_GET['pano_id'])) {
        $prereq = get_pano_prereq($_GET['pano_id']);
        $prereq_id = $prereq->id;
    }
    $prereq_items = get_prereq_items($prereq_id);
    $selected_items = array();
    foreach ($prereq_items as $selected_item) {
        array_push($selected_items, $selected_item->item_id);
    }
    ?>
<link rel="stylesheet" type="text/css" href="<?php 
    echo $semantic;
    ?>
"/>
<h2>Edit your Prereqs!</h2>
<hr>

<form id="form" method="post" enctype="multipart/form-data" action="<?php 
    echo get_admin_url() . 'admin-post.php';
    ?>
">
  <!-- pano processing hook -->
  <input type="hidden" name="action" value="edit_prereq" />
  <input type="hidden" name="id" value="<?php 
    echo $prereq->id;
    ?>
" />
  <input type="hidden" name="pano_id" value="<?php 
    echo $prereq->pano_id;
    ?>
" />
  <div class="ui form segment new_prereq_form">
    <div class="ui form">
      <div class="field">
        <label for="prereq_pts">Prereq Points</label>
        <input type="number" name="prereq_pts" id="prereq_pts" placeholder="100" value="<?php 
    echo $prereq->prereq_pts;
    ?>
"required />
      </div>
    </div>
    <input type="hidden" name="prereq_domain_id" value="NA" />
    <div class="ui form">
      <div class="field">
        <label for="prereq_desc">Prereq Info</label>
        <textarea name="prereq_desc" id="prereq_desc" required ><?php 
    echo $prereq->prereq_desc;
    ?>
</textarea>
      </div>
    </div>
    <div class="ui form">
      <div class="field">
        <label for="item_type">Filter by Item Type</label>
        <select name="item_type" id="item_type" class="ui dropdown">
          <option value="NA">All items</option>
          <?php 
    foreach ($item_types as $item_type) {
        ?>
          <option value="<?php 
        echo $item_type->id;
        ?>
"><?php 
        echo $item_type->name;
        ?>
</option>
          <?php 
    }
    ?>
        </select>
      </div>
    </div>
    <div class="ui form">
      <div class="field">
        <label>Items<span id="item_limit"> - maximum of 5 items</span></label>
        <ul>
          <?php 
    foreach ($items as $item) {
        ?>
            <?php 
        if (in_array($item->id, $selected_items)) {
            ?>
            <li class="games_form item <?php 
            echo $item->type_id;
            ?>
">
              <input type="checkbox" id="<?php 
            echo $item->id;
            ?>
" name="items[]" value="<?php 
            echo $item->id;
            ?>
" checked>
              <label for="<?php 
            echo $item->id;
            ?>
"><?php 
            echo $item->name;
            ?>
</label>
            </li>
            <?php 
        } else {
            ?>
            <li class="games_form item <?php 
            echo $item->type_id;
            ?>
">
              <input type="checkbox" id="<?php 
            echo $item->id;
            ?>
" name="items[]" value="<?php 
            echo $item->id;
            ?>
">
              <label for="<?php 
            echo $item->id;
            ?>
"><?php 
            echo $item->name;
            ?>
</label>
            </li>
            <?php 
        }
        ?>
          <?php 
    }
    ?>
        </ul>
      </div>
    </div>
    <?php 
    submit_button();
    ?>
  </div>
</form>
<script type="text/javascript">
  // Hiding error message
  jQuery('#item_limit').hide();

  // Event listener
  jQuery('#item_type').change(function(){
    filterTypes();
  });
  jQuery(':checkbox').change(function(){
    restrictItems();
  });
  jQuery('#form').submit(function(e){
    if(!restrictItems()){
      e.preventDefault();
    }
  });

  // Filters items based on user selection of item type.
  function filterTypes(){
    if(jQuery('#item_type').val() == 'NA'){
      jQuery('.item').each(function(){
        jQuery(this).show();
      });
    } else {
      var typeId = jQuery('#item_type').val();
      jQuery('.item').each(function(){
        jQuery(this).hide();
      });
      jQuery('.item').each(function(){
        jQuery('.' + typeId).each(function(){
          jQuery(this).show();
        });
      });
    }
  }

  // Displays a message if user picks more than [qty] items.
  // Prevents form submission if user picks more than [qty] items.
  function restrictItems(){
    var qty = 5;
    var allowSend = false;
    if(jQuery(':checkbox:checked').length > qty){
      jQuery('#item_limit').show();
      jQuery('#item_limit').css({'color': 'red', 'font-weight': 'bold'});
      allowSend = false;
    } else {
      jQuery('#item_limit').hide();
      allowSend = true;
    }
    return allowSend;
  }
</script>
<?php 
}