function new_word_settings_page()
{
    $semantic = WP_PLUGIN_URL . '/vocabulary-plugin/css/semantic.css';
    $domains = get_domains();
    $categories = get_word_categories();
    ?>
<link rel="stylesheet" type="text/css" href="<?php 
    echo $semantic;
    ?>
"/>
<h2>Create a new word!</h2>
<hr>
<form id="myform" method="post" enctype="multipart/form-data" action="<?php 
    echo get_admin_url() . 'admin-post.php';
    ?>
">
    <input type="hidden" name="action" value="create_new_word" />
    <div class="ui form segment new_word_form">
	    <div class="ui form">
	      <div class="field">
	        <label for="domain_id">Select a Domain</label>
	        <select name="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="category_id">Select a Category</label>
	        <select name="category_id">
				 <option value="NA">...</option>
                 <?php 
    foreach ($categories as $category) {
        ?>
                    <option value="<?php 
        echo $category->id;
        ?>
"><?php 
        echo $category->name;
        ?>
</option>
                <?php 
    }
    ?>
			</select>
	      </div>
	    </div>
	    <div class="ui form">
	      <div class="field">
	      	<div class="ui left labeled icon input">
	        	<label for="word_name">Word Name</label>
	    		<input type="text" name="word_name" id="name" required />
     	 	</div>
	      </div>
	    </div>
	    <div class="ui form">
	      <div class="field">
	        <label for="word_description">Description</label>
	        <textarea name="word_description" id="word_description" required ></textarea>
	        <p class="error" id="description_too_big">* Description must be smaller than 255 char</p>
	      </div>
	    </div>
        <div class="ui form">
	      <div class="field">
	        <label for="word_description">Points per word</label>
	         <select name="word_points">
	            <option value="30">30</option>
	            <option value="20">20</option>
	            <option value="10">10</option>
            </select>
	      </div>
	    </div>
       <div class="ui form">
	      <div class="field">
	      	<div class="ui left labeled icon input">
	        	<label for="word_image">Choose a image <b>(Preferably 120x120)</b></label>
	    		<input type="file" name="word_image" id="word_image"  />
     	 	</div>
	      </div>
	    </div>
        <div class="ui form">
	      <div class="field">
	      	<div class="ui left labeled icon input">
	        	<label for="word_audio">Audio</label>
	    		<input type="file" name="word_audio" id="word_audio"  />
     	 	</div>
	      </div>
	    </div>
	    <?php 
    submit_button();
    ?>
	</div>
</form>
</div>

<script>

jQuery('#myform').submit(function(e){
       max_description_size(e);
   });

   function max_description_size(e){
       var size = jQuery("#word_description").val().length;
       if(size > 255){
           document.getElementById("description_too_big").style.display = "block";
           e.preventDefault();
       }else{
           document.getElementById("description_too_big").style.display = "none";
       }
   }

	jQuery(document).ready(function(){
		jQuery("#pano_id").change(function(){
			var quest_id = jQuery("option:selected", this).attr("data-quest-id");
			jQuery("#quest_id").val(quest_id);
		});
	});

</script>
<?php 
}
function edit_hatplehgame_settings_page()
{
    $semantic = WP_PLUGIN_URL . '/vocabulary-plugin/css/semantic.css';
    $game_id = filter_input(INPUT_POST, 'id');
    $game = get_deck($game_id);
    $categories = get_word_categories();
    $domains = get_domains();
    $words = get_words();
    if (isset($_GET['id']) && is_numeric($_GET['id'])) {
        $game = build_deck($_GET['id']);
        $deck_words = get_all_game_words_ids($_GET['id']);
    }
    $selected_words_ids = array();
    for ($j = 0; $j < sizeof($deck_words); $j++) {
        $selected_words_ids[$j] = $deck_words[$j]->id;
    }
    ?>
<link rel="stylesheet" type="text/css" href="<?php 
    echo $semantic;
    ?>
"/>
<h2>Edit a Game!</h2>
<hr>

<?php 
    if (isset($_GET['settings-saved'])) {
        ?>
        <div class="updated"><p>Game updated successfully.</p></div>
    <?php 
    } elseif (isset($_GET['error'])) {
        ?>
        <div class="error"><p>Error updating game.</p></div>
    <?php 
    }
    ?>
<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_hatgame" />

    <?php 
    if (isset($_GET['action']) && $_GET['action'] == "edit") {
        $game_id_to_form = $game->get_id();
    } elseif (isset($_GET['action']) && $_GET['action'] == "copy") {
        $game_id_to_form = "copy";
    }
    ?>

    <input type="hidden" name="game_id" value="<?php 
    echo $game_id_to_form;
    ?>
"/>
    <div class="ui form segment edit_word_form">

	    <div class="ui form">
	      <div class="field">
	      	<div class="ui left labeled icon input">
	        	<label for="game_name">Game Name: </label>
	    		<input name="game_name" id="name" value="<?php 
    echo $game->get_name();
    ?>
" required />
     	 	</div>
	      </div>
	    </div>

        <div class="ui form">
	      <div class="field">
                <label for="word_image">Choose an image for winning the game: <b>(Preferably 120x120)</b></label>
                <img class="word_image" src="<?php 
    echo content_url() . '/' . $game->get_image();
    ?>
" alt="Image"/>
                <input type="file" name="game_image" id="game_image"  />
                <input type="hidden" name="game_image" value="<?php 
    echo $game->get_image();
    ?>
"/>
	      </div>
	    </div>

	    <div class="ui form">
	      <div class="field">
	        <label for="filter">Filter by</label>
            <select name="domain_id" id="domain_id">
				 <option value="NA">Select a Domain</option>
                 <?php 
    foreach ($domains as $domain) {
        ?>
                    <option value="<?php 
        echo $domain->id;
        ?>
"><?php 
        echo $domain->name;
        ?>
</option>
                <?php 
    }
    ?>
            </select>
            <select name="category_id" id="category_id">
                 <option value="NA">Select a Category</option>
                 <?php 
    foreach ($categories as $category) {
        ?>
                    <option value="<?php 
        echo $category->id;
        ?>
"><?php 
        echo $category->name;
        ?>
</option>
                 <?php 
    }
    ?>
            </select>
          </div>
        </div>

        <div class="ui form">
	      <div class="field">
	        <ul>
                <?php 
    foreach ($words as $word) {
        ?>
                    <?php 
        if (in_array($word->id, $selected_words_ids)) {
            ?>
                        <li class="games_form">
                            <input type="checkbox" id="<?php 
            echo $word->id;
            ?>
" class="dom<?php 
            echo $word->domain_id;
            ?>
 cat<?php 
            echo $word->word_category_id;
            ?>
" name="words[]" value="<?php 
            echo $word->id;
            ?>
" checked>
                            <label for="<?php 
            echo $word->id;
            ?>
" class="dom_option cat_option dom<?php 
            echo $word->domain_id;
            ?>
 cat<?php 
            echo $word->word_category_id;
            ?>
"><?php 
            echo $word->word;
            ?>
</label>
                        </li>
                    <?php 
        } else {
            ?>
                        <li class="games_form">
                            <input type="checkbox" id="<?php 
            echo $word->id;
            ?>
" class="dom<?php 
            echo $word->domain_id;
            ?>
 cat<?php 
            echo $word->word_category_id;
            ?>
" name="words[]" value="<?php 
            echo $word->id;
            ?>
">
                            <label for="<?php 
            echo $word->id;
            ?>
" class="dom_option cat_option dom<?php 
            echo $word->domain_id;
            ?>
 cat<?php 
            echo $word->word_category_id;
            ?>
"><?php 
            echo $word->word;
            ?>
</label>
                        </li>
                    <?php 
        }
        ?>
                <?php 
    }
    ?>
            </ul>
	      </div>
        </div>

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

<script>
	jQuery(document).ready(function(){
		jQuery("#pano_id").change(function(){
			var quest_id = jQuery("option:selected", this).attr("data-quest-id");
			jQuery("#quest_id").val(quest_id);
		});
	});

    jQuery("#category_id").change(function(){
        filter_words();
    });

    jQuery("#domain_id").change(function(){
        filter_words();
    });

function filter_words()
{
    var cat_selected = jQuery( "#category_id option:selected" ).val();
    var dom_selected = jQuery( "#domain_id option:selected" ).val();

    jQuery(".cat_option").hide();
    //jQuery("input:checkbox").hide();

    if(cat_selected == "NA" && dom_selected == "NA")
    {
        jQuery(".cat_option").show();
    }
    else if(cat_selected != "NA" && dom_selected == "NA")
    {
        jQuery(".cat_option").hide();
        jQuery(".cat" + cat_selected).show();
    }
    else if(cat_selected == "NA" && dom_selected != "NA")
    {
        jQuery(".cat_option").hide();
        jQuery(".dom" + dom_selected).show();
    }
    else
    {
        jQuery(".cat_option").hide();
        jQuery(".dom" + dom_selected + ".cat" + cat_selected).show();
    }
    jQuery("input:checkbox").hide();
}
</script>

<?php 
}
function new_spotgame_settings_page()
{
    $semantic = WP_PLUGIN_URL . '/vocabulary-plugin/css/semantic.css';
    $decks = get_decks('flashcard');
    $deck_words = get_deck_words('');
    $domains = get_domains();
    $categories = get_word_categories();
    $words = get_words();
    ?>
<link rel="stylesheet" type="text/css" href="<?php 
    echo $semantic;
    ?>
"/>
<h2>Create New Game!</h2>
<hr>

<form id="form" method="post" enctype="multipart/form-data" action="<?php 
    echo get_admin_url() . 'admin-post.php';
    ?>
">
    <input type="hidden" name="action" value="create_new_spotgame" />
    <div class="ui form segment new_word_form">

       <div class="ui form">
        <div class="field">
            <label>Choose a deck:</label>
            <select name="decks" id="deck_id">
				 <option value="NA">Select a Deck</option>
                 <?php 
    foreach ($decks as $deck) {
        ?>
                    <option value="<?php 
        echo $deck->id;
        ?>
"><?php 
        echo $deck->name;
        ?>
</option>
                <?php 
    }
    ?>
            </select>
        </div>
       </div>

	   <div class="ui form">
	      <div class="field">
	      	<div class="ui left labeled icon input">
	        	<label for="game_name">Create a question to display in the game: </label>
	    		<input name="game_name" id="name" required />
     	 	</div>
	      </div>
	    </div>

	    <p class="error" id="not_enough_words">* Select just one word</p>

       <div class="ui form">
	      <div class="field">
	        <label>Word to be guessed:</label>
	        <label for="filter">Filter by</label>
            <select name="domain_id" id="domain_id">
				 <option value="NA">Select a Domain</option>
                 <?php 
    foreach ($domains as $domain) {
        ?>
                    <option value="<?php 
        echo $domain->id;
        ?>
"><?php 
        echo $domain->name;
        ?>
</option>
                <?php 
    }
    ?>
            </select>
            <select name="category_id" id="category_id">
				 <option value="NA">Select a Category</option>
                 <?php 
    foreach ($categories as $category) {
        ?>
                    <option value="<?php 
        echo $category->id;
        ?>
"><?php 
        echo $category->name;
        ?>
</option>
                <?php 
    }
    ?>
            </select>
          </div>
        </div>

        <div class="ui form">
	      <div class="field">
	        <ul>
            <?php 
    foreach ($words as $word) {
        ?>
                <li class="games_form">
                    <input type="checkbox" id="<?php 
        echo $word->id;
        ?>
" class="dom<?php 
        echo $word->domain_id;
        ?>
 cat<?php 
        echo $word->word_category_id;
        ?>
" name="words[]" value="<?php 
        echo $word->id;
        ?>
">
                    <label for="<?php 
        echo $word->id;
        ?>
" class="dom_option cat_option dom<?php 
        echo $word->domain_id;
        ?>
 cat<?php 
        echo $word->word_category_id;
        ?>
" ><?php 
        echo $word->word;
        ?>
</label>
                </li>
            <?php 
    }
    ?>
            </ul>
	      </div>
        </div>

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

<script>
	jQuery(document).ready(function(){
		jQuery("#pano_id").change(function(){
			var quest_id = jQuery("option:selected", this).attr("data-quest-id");
			jQuery("#quest_id").val(quest_id);
		});
	});

    function addForm() {
        document.getElementById("buttonDomain").style.display = "none";
        document.getElementById("domain_form").style.display = "block";
    }

    jQuery('#form').submit(function(e){
        user_selected_enough_words(e);
    });

    jQuery('#game_number_of_words').change(function(){
        document.getElementById("words_error").style.display = "none";
        document.getElementById("not_enough_words").style.display = "none";
    });

    jQuery("input:checkbox").change(function(){
       document.getElementById("words_error").style.display = "none";
       document.getElementById("not_enough_words").style.display = "none";
    });


    function user_selected_enough_words(e){
        var n = jQuery("input:checkbox:checked").length;
        var game_number_of_words = jQuery('#game_number_of_words').prop('value');

        if(n > 1 || n < 1){
            e.preventDefault();
            document.getElementById("not_enough_words").style.display = "block";
            document.getElementById("words_error").style.display = "none";
        }
        else if(n < Number(game_number_of_words)){
            e.preventDefault();
            document.getElementById("words_error").style.display = "block";
            document.getElementById("not_enough_words").style.display = "none";
        }else{
            document.getElementById("words_error").style.display = "none";
            document.getElementById("not_enough_words").style.display = "none";
        }

    }

    jQuery("#category_id").change(function(){
        filter_words();
    });

    jQuery("#domain_id").change(function(){
        filter_words();
    });

    function filter_words()
    {
        var cat_selected = jQuery( "#category_id option:selected" ).val();
        var dom_selected = jQuery( "#domain_id option:selected" ).val();

        var checkboxes = jQuery("input:checkbox");

        jQuery(".cat_option").hide();
        //jQuery("input:checkbox").hide();

        if(cat_selected == "NA" && dom_selected == "NA")
        {
            jQuery(".cat_option").show();
        }
        else if(cat_selected != "NA" && dom_selected == "NA")
        {
            jQuery(".cat_option").hide();
            jQuery(".cat" + cat_selected).show();

            var category = "cat" + cat_selected;

            for(var k = 0; k < checkboxes.length; k++){
                if(!checkboxes[k].classList.contains(category)){
                   checkboxes[k].checked = false;
                }
            }
        }
        else if(cat_selected == "NA" && dom_selected != "NA")
        {
            jQuery(".cat_option").hide();
            jQuery(".dom" + dom_selected).show();

            var domain = "dom" + dom_selected;

            for(var k = 0; k < checkboxes.length; k++){
                if(!checkboxes[k].classList.contains(domain)){
                   checkboxes[k].checked = false;
                }
            }
        }
        else
        {
            jQuery(".cat_option").hide();
            jQuery(".dom" + dom_selected + ".cat" + cat_selected).show();

            var category = "cat" + cat_selected;

            for(var k = 0; k < checkboxes.length; k++){
                if(!checkboxes[k].classList.contains(category)){
                   checkboxes[k].checked = false;
                }
            }

            var domain = "dom" + dom_selected;

            for(var k = 0; k < checkboxes.length; k++){
                if(!checkboxes[k].classList.contains(domain)){
                   checkboxes[k].checked = false;
                }
            }
        }
        jQuery("input:checkbox").hide();


    }

//    function filter_words(){
//
//        var selected        = jQuery( "#category_id option:selected" ).val();
//        var checkboxes = jQuery("input:checkbox");
//
//        if(!(selected == "NA")){
//            jQuery("label").hide();
//            var category = ".cat" + selected;
//
//            jQuery(category).show();
//            jQuery("input:checkbox").hide();
//
//            var category_selected = "";
//
//            for(var k = 0; k < checkboxes.length; k++){
//                category_selected = "." + checkboxes[k].className;
//                if(category_selected != category){
//                   checkboxes[k].checked = false;
//                }
//            }
//        }else{
//            jQuery("label").show();
//            jQuery("input:checkbox").hide();
//        }
//
//    }


</script>
<?php 
}
function edit_spotgame_settings_page()
{
    $semantic = WP_PLUGIN_URL . '/vocabulary-plugin/css/semantic.css';
    $game_id = filter_input(INPUT_POST, 'id');
    $game = get_deck($game_id);
    $domains = get_domains();
    $categories = get_word_categories();
    $words = get_words();
    $decks = get_decks('flashcard');
    //Will be empty if it's a copy or
    //Will have the id if it's an update
    $game_id_to_form = "";
    if (isset($_GET['id']) && is_numeric($_GET['id'])) {
        $game = build_deck($_GET['id']);
        $deck_words = get_number_of_words_for_game($_GET['id']);
    }
    $selected_words_ids = array($deck_words->number_of_words);
    //echo var_dump($selected_words_ids);
    //    for($j = 0; $j < sizeof($deck_words); $j++){
    //        $selected_words_ids[$j] = $deck_words[$j]->id;
    //    }
    ?>
<link rel="stylesheet" type="text/css" href="<?php 
    echo $semantic;
    ?>
"/>
<h2>Edit a Game!</h2>
<hr>

<?php 
    if (isset($_GET['settings-saved'])) {
        ?>
        <div class="updated"><p>Game updated successfully.</p></div>
    <?php 
    } elseif (isset($_GET['error'])) {
        ?>
        <div class="error"><p>Error updating game.</p></div>
    <?php 
    }
    ?>
<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_spotgame" />

    <?php 
    if (isset($_GET['action']) && $_GET['action'] == "edit") {
        $game_id_to_form = $game->get_id();
    } elseif (isset($_GET['action']) && $_GET['action'] == "copy") {
        $game_id_to_form = "copy";
    }
    ?>

    <input type="hidden" name="game_id" value="<?php 
    echo $game_id_to_form;
    ?>
"/>
    <div class="ui form segment edit_word_form">

        <div class="ui form">
        <div class="field">
            <label>Choose a deck:</label>
            <select name="decks" id="deck_id">
				 <option value="NA">Select a Deck</option>
                 <?php 
    foreach ($decks as $deck) {
        ?>
                    <option value="<?php 
        echo $deck->id;
        ?>
"><?php 
        echo $deck->name;
        ?>
</option>
                <?php 
    }
    ?>
            </select>
        </div>
       </div>

	    <div class="ui form">
	      <div class="field">
	      	<div class="ui left labeled icon input">
	        	<label for="game_name">Question that will display in the game: </label>
	    		<input name="game_name" id="name" value="<?php 
    echo $game->get_name();
    ?>
" required />
     	 	</div>
	      </div>
	    </div>

	    <p class="error" id="not_enough_words">* Select just one word</p>

	    <div class="ui form">
	      <div class="field">
	        <label for="category_id">Filter by</label>
	        <select name="domain_id" id="domain_id">
				 <option value="NA">Select a Domain</option>
                 <?php 
    foreach ($domains as $domain) {
        ?>
        <option value="<?php 
        echo $domain->id;
        ?>
"><?php 
        echo $domain->name;
        ?>
</option>
    <?php 
    }
    ?>
            </select>
	        <select name="category_id" id="category_id">
				 <option value="NA">Select a Category</option>
                 <?php 
    foreach ($categories as $category) {
        ?>
        <option value="<?php 
        echo $category->id;
        ?>
"><?php 
        echo $category->name;
        ?>
</option>
    <?php 
    }
    ?>
            </select>
          </div>
        </div>

         <div class="ui form">
	      <div class="field">
	        <ul>
                <?php 
    foreach ($words as $word) {
        ?>
        <?php 
        if (in_array($word->id, $selected_words_ids)) {
            ?>
            <li class="games_form">
                <input type="checkbox" id="<?php 
            echo $word->id;
            ?>
" class="dom<?php 
            echo $word->domain_id;
            ?>
 cat<?php 
            echo $word->word_category_id;
            ?>
" name="words[]" value="<?php 
            echo $word->id;
            ?>
" checked>
                <label for="<?php 
            echo $word->id;
            ?>
" class="dom_option cat_option dom<?php 
            echo $word->domain_id;
            ?>
 cat<?php 
            echo $word->word_category_id;
            ?>
" ><?php 
            echo $word->word;
            ?>
</label>
            </li>
        <?php 
        } else {
            ?>
            <li class="games_form">
                <input type="checkbox" id="<?php 
            echo $word->id;
            ?>
" class="dom<?php 
            echo $word->domain_id;
            ?>
 cat<?php 
            echo $word->word_category_id;
            ?>
" name="words[]" value="<?php 
            echo $word->id;
            ?>
">
                <label for="<?php 
            echo $word->id;
            ?>
" class="dom_option cat_option dom<?php 
            echo $word->domain_id;
            ?>
 cat<?php 
            echo $word->word_category_id;
            ?>
" ><?php 
            echo $word->word;
            ?>
</label>
            </li>
        <?php 
        }
        ?>

    <?php 
    }
    ?>
            </ul>
	      </div>
        </div>

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

<script>
    jQuery('#form').submit(function(e){
        user_selected_enough_words(e);
    });

    jQuery('#game_number_of_words').change(function(){
        document.getElementById("words_error").style.display = "none";
    });

    jQuery("input:checkbox").change(function(){
       document.getElementById("words_error").style.display = "none";
       document.getElementById("not_enough_words").style.display = "none";
    });

    jQuery("#category_id").change(function(){
        filter_words();
    });

    jQuery("#domain_id").change(function(){
        filter_words();
    });

    function user_selected_enough_words(e){
        var n = jQuery("input:checkbox:checked").length;
        var game_number_of_words = jQuery('#game_number_of_words').prop('value');

        if(n > 1 || n < 1){
            e.preventDefault();
            document.getElementById("not_enough_words").style.display = "block";
            document.getElementById("words_error").style.display = "none";
        }
        else if(n < Number(game_number_of_words)){
            e.preventDefault();
            document.getElementById("words_error").style.display = "block";
            document.getElementById("not_enough_words").style.display = "none";
        }else{
            document.getElementById("words_error").style.display = "none";
            document.getElementById("not_enough_words").style.display = "none";
        }

    }

    function filter_words()
    {
        var cat_selected = jQuery( "#category_id option:selected" ).val();
        var dom_selected = jQuery( "#domain_id option:selected" ).val();

        var checkboxes = jQuery("input:checkbox");

        jQuery(".cat_option").hide();
        //jQuery("input:checkbox").hide();

        if(cat_selected == "NA" && dom_selected == "NA")
        {
            jQuery(".cat_option").show();
        }
        else if(cat_selected != "NA" && dom_selected == "NA")
        {
            jQuery(".cat_option").hide();
            jQuery(".cat" + cat_selected).show();

            var category = "cat" + cat_selected;

            for(var k = 0; k < checkboxes.length; k++){
                if(!checkboxes[k].classList.contains(category)){
                   checkboxes[k].checked = false;
                }
            }
        }
        else if(cat_selected == "NA" && dom_selected != "NA")
        {
            jQuery(".cat_option").hide();
            jQuery(".dom" + dom_selected).show();

            var domain = "dom" + dom_selected;

            for(var k = 0; k < checkboxes.length; k++){
                if(!checkboxes[k].classList.contains(domain)){
                   checkboxes[k].checked = false;
                }
            }
        }
        else
        {
            jQuery(".cat_option").hide();
            jQuery(".dom" + dom_selected + ".cat" + cat_selected).show();

            var category = "cat" + cat_selected;

            for(var k = 0; k < checkboxes.length; k++){
                if(!checkboxes[k].classList.contains(category)){
                   checkboxes[k].checked = false;
                }
            }

            var domain = "dom" + dom_selected;

            for(var k = 0; k < checkboxes.length; k++){
                if(!checkboxes[k].classList.contains(domain)){
                   checkboxes[k].checked = false;
                }
            }
        }
        jQuery("input:checkbox").hide();


    }


</script>

<?php 
}
function new_flashcardgame_settings_page()
{
    $semantic = WP_PLUGIN_URL . '/vocabulary-plugin/css/semantic.css';
    $domains = get_domains();
    $categories = get_word_categories();
    $words = get_words();
    ?>
<link rel="stylesheet" type="text/css" href="<?php 
    echo $semantic;
    ?>
"/>
<h2>Create New Game!</h2>
<hr>
<style type="text/css">
	#domain_form{
	    display: none;
	    width: 80%;
	    margin: 0 auto;

	}
</style>
<form id="form" method="post" enctype="multipart/form-data" action="<?php 
    echo get_admin_url() . 'admin-post.php';
    ?>
">
    <input type="hidden" name="action" value="create_new_flashcard" />
    <div class="ui form segment new_word_form">

	   <div class="ui form">
	      <div class="field">
	      	<div class="ui left labeled icon input">
	        	<label for="game_name">Game Name: </label>
	    		<input name="game_name" id="name" required />
     	 	</div>
	      </div>
	    </div>

	    <div class="ui form">
	      <div class="field">
	      	<div class="ui left labeled icon input">
	        	<label for="game_number_of_words">Defined number of words to be guessed: </label>
	    		<input name="game_number_of_words" id="game_number_of_words" required />
     	 	</div>
	      </div>
	    </div>

	    <p class="error" id="words_error">* Number of words in the game can not be lower than words selected</p>
	    <p class="error" id="not_enough_words">* Must select at least 6 words</p>

       <div class="ui form">
	      <div class="field">
	        <label for="filter">Filter by</label>
            <select name="domain_id" id="domain_id">
				 <option value="NA">Select a Domain</option>
                 <?php 
    foreach ($domains as $domain) {
        ?>
                    <option value="<?php 
        echo $domain->id;
        ?>
"><?php 
        echo $domain->name;
        ?>
</option>
                <?php 
    }
    ?>
            </select>
            <select name="category_id" id="category_id">
				 <option value="NA">Select a Category</option>
                 <?php 
    foreach ($categories as $category) {
        ?>
                    <option value="<?php 
        echo $category->id;
        ?>
"><?php 
        echo $category->name;
        ?>
</option>
                <?php 
    }
    ?>
            </select>
          </div>
        </div>

        <div class="ui form">
	      <div class="field">
	        <ul>
            <?php 
    foreach ($words as $word) {
        ?>
                <li class="games_form">
                    <input type="checkbox" id="<?php 
        echo $word->id;
        ?>
" class="dom<?php 
        echo $word->domain_id;
        ?>
 cat<?php 
        echo $word->word_category_id;
        ?>
" name="words[]" value="<?php 
        echo $word->id;
        ?>
">
                    <label for="<?php 
        echo $word->id;
        ?>
" class="dom_option cat_option dom<?php 
        echo $word->domain_id;
        ?>
 cat<?php 
        echo $word->word_category_id;
        ?>
" ><?php 
        echo $word->word;
        ?>
</label>
                </li>
            <?php 
    }
    ?>
            </ul>
	      </div>
        </div>

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

<script>
	jQuery(document).ready(function(){
		jQuery("#pano_id").change(function(){
			var quest_id = jQuery("option:selected", this).attr("data-quest-id");
			jQuery("#quest_id").val(quest_id);
		});
	});

    function addForm() {
        document.getElementById("buttonDomain").style.display = "none";
        document.getElementById("domain_form").style.display = "block";
    }

    jQuery('#form').submit(function(e){
        user_selected_enough_words(e);
    });

    jQuery('#game_number_of_words').change(function(){
        document.getElementById("words_error").style.display = "none";
        document.getElementById("not_enough_words").style.display = "none";
    });

    jQuery("input:checkbox").change(function(){
       document.getElementById("words_error").style.display = "none";
       document.getElementById("not_enough_words").style.display = "none";
    });


    function user_selected_enough_words(e){
        var n = jQuery("input:checkbox:checked").length;
        var game_number_of_words = jQuery('#game_number_of_words').prop('value');

        if(n < 6){
            e.preventDefault();
            document.getElementById("not_enough_words").style.display = "block";
            document.getElementById("words_error").style.display = "none";
        }
        else if(n < Number(game_number_of_words)){
            e.preventDefault();
            document.getElementById("words_error").style.display = "block";
            document.getElementById("not_enough_words").style.display = "none";
        }else{
            document.getElementById("words_error").style.display = "none";
            document.getElementById("not_enough_words").style.display = "none";
        }

    }

    jQuery("#category_id").change(function(){
        filter_words();
    });

    jQuery("#domain_id").change(function(){
        filter_words();
    });

    function filter_words()
    {
        var cat_selected = jQuery( "#category_id option:selected" ).val();
        var dom_selected = jQuery( "#domain_id option:selected" ).val();

        jQuery(".cat_option").hide();
        //jQuery("input:checkbox").hide();

        if(cat_selected == "NA" && dom_selected == "NA")
        {
            jQuery(".cat_option").show();
        }
        else if(cat_selected != "NA" && dom_selected == "NA")
        {
            jQuery(".cat_option").hide();
            jQuery(".cat" + cat_selected).show();
        }
        else if(cat_selected == "NA" && dom_selected != "NA")
        {
            jQuery(".cat_option").hide();
            jQuery(".dom" + dom_selected).show();
        }
        else
        {
            jQuery(".cat_option").hide();
            jQuery(".dom" + dom_selected + ".cat" + cat_selected).show();
        }
        jQuery("input:checkbox").hide();
    }


</script>
<?php 
}
function word_settings_page()
{
    $words = get_words();
    $categories = get_word_categories();
    $domains = get_domains();
    $semantic = WP_PLUGIN_URL . '/vocabulary-plugin/css/semantic.css';
    $new_word_url = admin_url() . "admin.php?page=new_word_settings";
    $edit_word_url = admin_url() . "admin.php?page=edit_word_settings";
    ?>

    <!-- style sheet so our admin page looks nice -->
    <link rel="stylesheet" type="text/css" href="<?php 
    echo $semantic;
    ?>
"/>
    <p>Manage your words!</p>
    <hr>

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

    <h2>Vocabulary</h2>

    <div class="ui form">
        <div class="field">
            <label for="filter">Filter the words by</label>
            <select name="domain_id" id="domain_id">
                <option value="NA">Select a Domain</option>
                <?php 
    foreach ($domains as $domain) {
        ?>
                    <option value="<?php 
        echo $domain->id;
        ?>
"><?php 
        echo $domain->name;
        ?>
</option>
                <?php 
    }
    ?>
            </select>
            <select name="category_id" id="category_id">
                <option value="NA">Select a Category</option>
                <?php 
    foreach ($categories as $category) {
        ?>
                    <option value="<?php 
        echo $category->id;
        ?>
"><?php 
        echo $category->name;
        ?>
</option>
                <?php 
    }
    ?>
            </select>
        </div>
    </div>

    <table id="wordTable" class="ui table segment tablesorter">
        <thead>
        <tr>
            <th>Name</th>
            <th>Description</th>
            <th>Points</th>
            <th>Image</th>
            <th>Audio</th>
            <th>Edit</th>
            <th>Delete</th>
        </tr>
        </thead>

        <tbody>
        <?php 
    foreach ($words as $word) {
        ?>
            <?php 
        $current_word = build_words($word->id);
        ?>
            <tr>
                <td class="dom_option cat_option dom<?php 
        echo $word->domain_id;
        ?>
 cat<?php 
        echo $word->word_category_id;
        ?>
"><?php 
        echo $current_word->get_word();
        ?>
</td>
                <td class="dom_option cat_option dom<?php 
        echo $word->domain_id;
        ?>
 cat<?php 
        echo $word->word_category_id;
        ?>
"><?php 
        echo $current_word->get_description();
        ?>
</td>
                <td class="dom_option cat_option dom<?php 
        echo $word->domain_id;
        ?>
 cat<?php 
        echo $word->word_category_id;
        ?>
"><?php 
        echo $current_word->get_points();
        ?>
</td>
                <td class="dom_option cat_option dom<?php 
        echo $word->domain_id;
        ?>
 cat<?php 
        echo $word->word_category_id;
        ?>
"><?php 
        echo $current_word->get_image();
        ?>
</td>
                <td class="dom_option cat_option dom<?php 
        echo $word->domain_id;
        ?>
 cat<?php 
        echo $word->word_category_id;
        ?>
"><?php 
        echo $current_word->get_audio();
        ?>
</td>

                <td class="dom_option cat_option dom<?php 
        echo $word->domain_id;
        ?>
 cat<?php 
        echo $word->word_category_id;
        ?>
"><a class="ui blue icon button" href="<?php 
        echo $edit_word_url;
        ?>
&id=<?php 
        echo $current_word->get_id();
        ?>
" style="padding: 7px">Edit</a></td>
                <td class="dom_option cat_option dom<?php 
        echo $word->domain_id;
        ?>
 cat<?php 
        echo $word->word_category_id;
        ?>
">
                    <form method="post" action="admin-post.php" id="delete_word_form<?php 
        echo $current_word->get_id();
        ?>
">
                        <!-- word processing hook -->
                        <input type="hidden" name="action" value="delete_word" />
                        <input type="hidden" name="word_id" value="<?php 
        echo $current_word->get_id();
        ?>
" />

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

        <?php 
    }
    ?>
        </tbody>
    </table>
    <a class="ui blue icon button" href="<?php 
    echo $new_word_url;
    ?>
" style="padding: 7px">New Word</a>

    <script>
        jQuery(document).ready(function(){
            jQuery("#wordTable").tablesorter();
        })

        jQuery("#category_id").change(function(){
            filter_words();
        });

        jQuery("#domain_id").change(function(){
            filter_words();
        });

        function validation()
        {

        }

        function filter_words()
        {
            var cat_selected = jQuery( "#category_id option:selected" ).val();
            var dom_selected = jQuery( "#domain_id option:selected" ).val();

            jQuery(".cat_option").hide();
            //jQuery("input:checkbox").hide();

            if(cat_selected == "NA" && dom_selected == "NA")
            {
                jQuery(".cat_option").show();
            }
            else if(cat_selected != "NA" && dom_selected == "NA")
            {
                jQuery(".cat_option").hide();
                jQuery(".cat" + cat_selected).show();
            }
            else if(cat_selected == "NA" && dom_selected != "NA")
            {
                jQuery(".cat_option").hide();
                jQuery(".dom" + dom_selected).show();
            }
            else
            {
                jQuery(".cat_option").hide();
                jQuery(".dom" + dom_selected + ".cat" + cat_selected).show();
            }
            jQuery("input:checkbox").hide();
        }
    </script>

<?php 
}
function edit_word_settings_page()
{
    $semantic = WP_PLUGIN_URL . '/vocabulary-plugin/css/semantic.css';
    $word_id = filter_input(INPUT_POST, 'id');
    $words = get_word($word_id);
    $domains = get_domains();
    $categories = get_word_categories();
    if (isset($_GET['id']) && is_numeric($_GET['id'])) {
        $words = build_words($_GET['id']);
    }
    ?>
<link rel="stylesheet" type="text/css" href="<?php 
    echo $semantic;
    ?>
"/>
<h2>Edit a word!</h2>
<hr>

<?php 
    if (isset($_GET['settings-saved'])) {
        ?>
    <div class="updated"><p>Dictionary updated successfully.</p></div>
<?php 
    } elseif (isset($_GET['error'])) {
        ?>
    <div class="error"><p>Error updating dictionary.</p></div>
<?php 
    }
    ?>
<form id="myform" 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_word" />
    <input type="hidden" name="word_id" value="<?php 
    echo $words->get_id();
    ?>
"/>

    <div class="ui form segment edit_word_form">

        <div class="ui form">
              <div class="field">
                <label for="domain_id">Select a Domain</label>
                <select name="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="category_id">Select a Category</label>
                <select name="category_id">
                     <option value="NA">...</option>
                     <?php 
    foreach ($categories as $category) {
        ?>
                        <option value="<?php 
        echo $category->id;
        ?>
"><?php 
        echo $category->name;
        ?>
</option>
                    <?php 
    }
    ?>
                </select>
              </div>
            </div>

	    <div class="ui form">
	      <div class="field">
	      	<div class="ui left labeled icon input">
	        	<label for="word_name">Word Name</label>
	    		<input name="word_name" id="name" value="<?php 
    echo $words->get_word();
    ?>
" required />
     	 	</div>
	      </div>
	    </div>
	    <div class="ui form">
	      <div class="field">
	        <label for="word_description">Description</label>
	        <textarea name="word_description" id="word_description" required ><?php 
    echo $words->get_description();
    ?>
</textarea>
	        <p class="error" id="description_too_big">* Description must be smaller than 255 char</p>
	      </div>
	    </div>
        <div class="ui form">
	      <div class="field">
	        <label for="word_points">Points</label>
	        <select name="word_points">
	            <option value="30">30</option>
	            <option value="20">20</option>
	            <option value="10">10</option>
            </select>
	      </div>
	    </div>
        <div class="ui form">
	      <div class="field">
	        <div class="ui left labeled icon input">
                <label for="word_image">Choose an image: <b>(Preferably 120x120)</b> </label>
                <img class="word_image" src="<?php 
    echo content_url() . '/' . $words->get_image();
    ?>
" alt="Image"/>
                <input type="file" name="word_image" id="word_image"  />
            </div>
	      </div>
	    </div>
        <div class="ui form">
	      <div class="field">
	        <div class="ui left labeled icon input">
                <label for="word_audio">Choose an audio: </label>
                <input type="file" name="word_audio" id="word_audio" />
	        </div>
	      </div>
	    </div>

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

<script>

jQuery('#myform').submit(function(e){
       max_description_size(e);
   });

   function max_description_size(e){
       var size = jQuery("#word_description").val().length;
       if(size > 255){
           document.getElementById("description_too_big").style.display = "block";
           e.preventDefault();
       }else{
           document.getElementById("description_too_big").style.display = "none";
       }
   }
            jQuery(document).ready(function(){
                jQuery("#wordTable").tablesorter();
            })
</script>
<?php 
}
function category_settings_page()
{
    $categories = get_word_categories();
    $semantic = WP_PLUGIN_URL . '/vocabulary-plugin/css/semantic.css';
    $new_category_url = admin_url() . "admin.php?page=new_category_settings";
    $edit_category_url = admin_url() . "admin.php?page=edit_category_settings";
    ?>

<!-- style sheet so our admin page looks nice -->
<link rel="stylesheet" type="text/css" href="<?php 
    echo $semantic;
    ?>
"/>
<p>Manage your categories!</p>
<hr>

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

<h2>Categories</h2>
<table class="ui table segment">
  <tr>
    <th>Category</th>
    <th>Edit</th>
    <th>Delete</th>
  </tr>
  <?php 
    foreach ($categories as $category) {
        ?>

        <tr>
            <td><?php 
        echo $category->name;
        ?>
</td>
            <td><a class="ui blue icon button" href="<?php 
        echo $edit_category_url;
        ?>
&id=<?php 
        echo $category->id;
        ?>
" style="padding: 7px">Edit</a></td>
            <td>
                <form method="post" action="admin-post.php" id="delete_category_form<?php 
        echo $category->id;
        ?>
">
                    <!-- pano processing hook -->
                    <input type="hidden" name="action" value="delete_category" />
                    <input type="hidden" name="category_id" value="<?php 
        echo $category->id;
        ?>
" />

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

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

<?php 
}
function edit_flashcardgame_settings_page()
{
    $semantic = WP_PLUGIN_URL . '/vocabulary-plugin/css/semantic.css';
    $game_id = filter_input(INPUT_POST, 'id');
    $game = get_deck($game_id);
    $domains = get_domains();
    $categories = get_word_categories();
    $words = get_words();
    //Will be empty if it's a copy or
    //Will have the id if it's an update
    $game_id_to_form = "";
    if (isset($_GET['id']) && is_numeric($_GET['id'])) {
        $game = build_deck($_GET['id']);
        $deck_words = get_all_game_words_ids($_GET['id']);
    }
    $selected_words_ids = array();
    for ($j = 0; $j < sizeof($deck_words); $j++) {
        $selected_words_ids[$j] = $deck_words[$j]->id;
    }
    ?>
<link rel="stylesheet" type="text/css" href="<?php 
    echo $semantic;
    ?>
"/>
<h2>Edit a Game!</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>Game updated successfully.</p></div>
    <?php 
    } elseif (isset($_GET['error'])) {
        ?>
        <div class="error"><p>Error updating game.</p></div>
    <?php 
    }
    ?>
<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_flashcard" />

    <?php 
    if (isset($_GET['action']) && $_GET['action'] == "edit") {
        $game_id_to_form = $game->get_id();
    } elseif (isset($_GET['action']) && $_GET['action'] == "copy") {
        $game_id_to_form = "copy";
    }
    ?>

    <input type="hidden" name="game_id" value="<?php 
    echo $game_id_to_form;
    ?>
"/>
    <div class="ui form segment edit_word_form">

	    <div class="ui form">
	      <div class="field">
	      	<div class="ui left labeled icon input">
	        	<label for="game_name">Game Name: </label>
	    		<input name="game_name" id="name" value="<?php 
    echo $game->get_name();
    ?>
" required />
     	 	</div>
	      </div>
	    </div>

	    <div class="ui form">
	      <div class="field">
	      	<div class="ui left labeled icon input">
	        	<label for="game_number_of_words">Defined number of words to be guessed: </label>
	    		<input name="game_number_of_words" id="game_number_of_words" value="<?php 
    echo $game->get_number_of_words();
    ?>
" required />
     	 	</div>
	      </div>
	    </div>

	    <p class="error" id="words_error">* Number of words in the game can not be lower than words selected</p>
	    <p class="error" id="not_enough_words">* Must select at least 6 words</p>

	    <div class="ui form">
	      <div class="field">
	        <label for="category_id">Filter by</label>
	        <select name="category_id" id="category_id">
				 <option value="NA">Select a Category</option>
                 <?php 
    foreach ($categories as $category) {
        ?>
                    <option value="<?php 
        echo $category->id;
        ?>
"><?php 
        echo $category->name;
        ?>
</option>
                <?php 
    }
    ?>
            </select>
          </div>
        </div>

         <div class="ui form">
	      <div class="field">
	        <ul>
                <?php 
    foreach ($words as $word) {
        ?>
                    <?php 
        if (in_array($word->id, $selected_words_ids)) {
            ?>
                        <li class="games_form">
                            <input type="checkbox" id="<?php 
            echo $word->id;
            ?>
" class="cat<?php 
            echo $word->word_category_id;
            ?>
" name="words[]" value="<?php 
            echo $word->id;
            ?>
" checked>
                            <label for="<?php 
            echo $word->id;
            ?>
" class="cat<?php 
            echo $word->word_category_id;
            ?>
"><?php 
            echo $word->word;
            ?>
</label>
                        </li>
                    <?php 
        } else {
            ?>
                        <li class="games_form">
                            <input type="checkbox" id="<?php 
            echo $word->id;
            ?>
" class="cat<?php 
            echo $word->word_category_id;
            ?>
" name="words[]" value="<?php 
            echo $word->id;
            ?>
">
                            <label for="<?php 
            echo $word->id;
            ?>
" class="cat<?php 
            echo $word->word_category_id;
            ?>
"><?php 
            echo $word->word;
            ?>
</label>
                        </li>
                    <?php 
        }
        ?>

                <?php 
    }
    ?>
            </ul>
	      </div>
        </div>

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

<script>
    jQuery('#form').submit(function(e){
        user_selected_enough_words(e);
    });

    jQuery('#game_number_of_words').change(function(){
        document.getElementById("words_error").style.display = "none";
    });

    jQuery("input:checkbox").change(function(){
       document.getElementById("words_error").style.display = "none";
    });

    jQuery("#category_id").change(function(){
        filter_words();
    });

    function user_selected_enough_words(e){
        var n = jQuery("input:checkbox:checked").length;
        var game_number_of_words = jQuery('#game_number_of_words').prop('value');

        if(n < 6){
            e.preventDefault();
            document.getElementById("not_enough_words").style.display = "block";
            document.getElementById("words_error").style.display = "none";
        }
        else if(n < Number(game_number_of_words)){
            e.preventDefault();
            document.getElementById("words_error").style.display = "block";
            document.getElementById("not_enough_words").style.display = "none";
        }else{
            document.getElementById("words_error").style.display = "none";
            document.getElementById("not_enough_words").style.display = "none";
        }

    }

    function filter_words(){

        var selected = jQuery( "#category_id option:selected" ).val();

        //jQuery("input:checkbox").hide();
        //jQuery("label").hide();

        if(!(selected == "NA")){
            jQuery("label").hide();
            var category = ".cat" + selected;

            jQuery(category).show();
            jQuery("input:checkbox").hide();
        }else{
            jQuery("label").show();
            jQuery("input:checkbox").hide();
        }


    }


</script>

<?php 
}
function new_hatplehgame_settings_page()
{
    $semantic = WP_PLUGIN_URL . '/vocabulary-plugin/css/semantic.css';
    $categories = get_word_categories();
    $domains = get_domains();
    $words = get_words();
    ?>
<link rel="stylesheet" type="text/css" href="<?php 
    echo $semantic;
    ?>
"/>
<h2>Create a new HatPlã game!</h2>
<hr>
<form method="post" enctype="multipart/form-data" action="<?php 
    echo get_admin_url() . 'admin-post.php';
    ?>
">
    <input type="hidden" name="action" value="create_new_hatgame" />
    <div class="ui form segment new_word_form">

	   <div class="ui form">
	      <div class="field">
	      	<div class="ui left labeled icon input">
	        	<label for="game_name">Game Name: </label>
	    		<input name="game_name" id="name" required />
     	 	</div>
	      </div>
	    </div>

        <div class="ui form">
	      <div class="field">
	      	<div class="ui left labeled icon input">
	        	<label for="word_image">Choose an image for winning the game: <b>(Preferably 120x120)</b></label>
	    		<input type="file" name="word_image" id="word_image" required/>
     	 	</div>
	      </div>
	    </div>

        <div class="ui form">
	      <div class="field">
	        <label for="filter">Filter by</label>
            <select name="domain_id" id="domain_id">
				 <option value="NA">Select a Domain</option>
                 <?php 
    foreach ($domains as $domain) {
        ?>
                    <option value="<?php 
        echo $domain->id;
        ?>
"><?php 
        echo $domain->name;
        ?>
</option>
                 <?php 
    }
    ?>
            </select>
            <select name="category_id" id="category_id">
				 <option value="NA">Select a Category</option>
                 <?php 
    foreach ($categories as $category) {
        ?>
                    <option value="<?php 
        echo $category->id;
        ?>
"><?php 
        echo $category->name;
        ?>
</option>
                <?php 
    }
    ?>
            </select>
          </div>
        </div>

        <div class="ui form">
	      <div class="field">
	        <ul>
            <?php 
    foreach ($words as $word) {
        ?>
                <li class="games_form">
                    <input type="checkbox" id="<?php 
        echo $word->id;
        ?>
" class="dom<?php 
        echo $word->domain_id;
        ?>
 cat<?php 
        echo $word->word_category_id;
        ?>
" name="words[]" value="<?php 
        echo $word->id;
        ?>
">
                    <label for="<?php 
        echo $word->id;
        ?>
" class="dom_option cat_option dom<?php 
        echo $word->domain_id;
        ?>
 cat<?php 
        echo $word->word_category_id;
        ?>
" ><?php 
        echo $word->word;
        ?>
</label>
                </li>
            <?php 
    }
    ?>
            </ul>
	      </div>
        </div>

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

<script>
	jQuery(document).ready(function(){
		jQuery("#pano_id").change(function(){
			var quest_id = jQuery("option:selected", this).attr("data-quest-id");
			jQuery("#quest_id").val(quest_id);
		});
	});

    jQuery("#category_id").change(function(){
        filter_words();
    });

    jQuery("#domain_id").change(function(){
        filter_words();
    });

function filter_words()
{
    var cat_selected = jQuery( "#category_id option:selected" ).val();
    var dom_selected = jQuery( "#domain_id option:selected" ).val();

    jQuery(".cat_option").hide();
    //jQuery("input:checkbox").hide();

    if(cat_selected == "NA" && dom_selected == "NA")
    {
        jQuery(".cat_option").show();
    }
    else if(cat_selected != "NA" && dom_selected == "NA")
    {
        jQuery(".cat_option").hide();
        jQuery(".cat" + cat_selected).show();
    }
    else if(cat_selected == "NA" && dom_selected != "NA")
    {
        jQuery(".cat_option").hide();
        jQuery(".dom" + dom_selected).show();
    }
    else
    {
        jQuery(".cat_option").hide();
        jQuery(".dom" + dom_selected + ".cat" + cat_selected).show();
    }
    jQuery("input:checkbox").hide();
}
</script>
<?php 
}