function create_field($field)
    {
        $field['value'] = isset($field['value']) ? $field['value'] : '';
        $type = isset($field['post_type']) ? empty($field['post_type']) ? 'post' : $field['post_type'] : 'post';
        $child_of = isset($field['child_of']) ? empty($field['child_of']) ? 0 : $field['child_of'] : 0;
        $parent = isset($field['parent']) ? empty($field['parent']) ? '' : $field['parent'] : '';
        $hide_empty = isset($field['hide_empty']) ? $field['hide_empty'] : '1';
        $hierarchical = isset($field['hierarchical']) ? $field['hierarchical'] : '1';
        $taxonomy = isset($field['taxonomy']) ? empty($field['taxonomy']) ? 'category' : $field['taxonomy'] : 'category';
        $include = isset($field['include']) ? empty($field['include']) ? '' : $field['include'] : '';
        $exclude = isset($field['exclude']) ? empty($field['exclude']) ? '' : $field['exclude'] : '';
        $orderby = isset($field['orderby']) ? empty($field['orderby']) ? 'name' : $field['orderby'] : 'name';
        $order = isset($field['order']) ? empty($field['order']) ? 'ASC' : $field['order'] : 'ASC';
        $show_all = isset($field['show_all']) ? $field['show_all'] : '1';
        $show_none = isset($field['show_none']) ? $field['show_none'] : '1';
        $show_parent = isset($field['show_none']) ? $field['show_parent'] : '1';
        $args = array('type' => $type, 'child_of' => $child_of, 'parent' => $parent, 'hide_empty' => $hide_empty, 'hierarchical' => $hierarchical, 'exclude' => $exclude, 'include' => $include, 'taxonomy' => $taxonomy, 'orderby' => 'term_group', 'order' => $order, 'pad_counts' => 1);
        $categories = get_categories($args);
        $selected_value = $field['value'];
        $is_selected = '';
        $field['value'] = $field['value'] ?: array();
        ?>

    <?php 
        if ($field['display_type'] == 'drop_down') {
            ?>
      <select id="<?php 
            echo $field['name'];
            ?>
" class="<?php 
            echo $field['class'];
            ?>
" name="<?php 
            echo $field['name'];
            ?>
">
        <?php 
            if ($show_all) {
                ?>
        <?php 
                if ($selected_value == "all") {
                    $is_selected = 'selected="selected"';
                }
                ?>
        <option value="all" <?php 
                echo $is_selected;
                ?>
>Show All</option>
        <?php 
            }
            ?>

        <?php 
            if ($show_none) {
                ?>
        <?php 
                if ($selected_value == "none") {
                    $is_selected = 'selected="selected"';
                }
                ?>
        <option value="none" <?php 
                echo $is_selected;
                ?>
>Show None</option>
        <?php 
            }
            ?>

        <?php 
            foreach ($categories as $category) {
                ?>
        <?php 
                if ($category->slug == $selected_value) {
                    $is_selected = 'selected="selected"';
                } else {
                    $is_selected = '';
                }
                ?>
        <?php 
                $category_name = $category->name;
                ?>
        <?php 
                if ($show_parent) {
                    ?>
          <?php 
                    if ($category->parent > 0) {
                        ?>
            <?php 
                        $category_name = get_cat_name($category->parent) . '->' . $category->name;
                        ?>
          <?php 
                    }
                    ?>
        <?php 
                }
                ?>
        <option value="<?php 
                echo $category->slug;
                ?>
" <?php 
                echo $is_selected;
                ?>
><?php 
                echo $category_name;
                ?>
</option>
        <?php 
            }
            ?>
      </select>
      <?php 
        }
        ?>

    <?php 
        if ($field['display_type'] == 'checkboxes') {
            ?>
      <?php 
            $results = sort_categories($categories);
            $post_count = $results['count'];
            unset($results['count']);
            $categories = $results;
            ?>
      <ul>
        <?php 
            if ($show_all) {
                ?>
        <?php 
                $is_selected = in_array("all", $field['value']) || empty($field['value']) ? 'checked' : '';
                ?>
        <li>
          <input id="<?php 
                echo $field['key'] . '_all';
                ?>
" name="<?php 
                echo $field['name'] . '[]';
                ?>
"
               type="checkbox" value="all" <?php 
                echo $is_selected;
                ?>
 />&nbsp;<span style='font-weight: bold;'>Show All</span>
        </li>
        <?php 
            }
            ?>

        <?php 
            $display_none = !$show_none ? ' style="display:none"' : '';
            $is_selected = in_array("none", $field['value']) ? 'checked' : '';
            ?>
        <li<?php 
            echo $display_none;
            ?>
>
          <input id="<?php 
            echo $field['key'] . '_none';
            ?>
" name="<?php 
            echo $field['name'] . '[]';
            ?>
"
               type="checkbox" value="none" <?php 
            echo $is_selected;
            ?>
 />&nbsp;Show None
        </li>

        <?php 
            foreach ($categories as $category) {
                if (is_array($field['value'])) {
                    $is_selected = in_array($category->slug, $field['value']) ? 'checked' : '';
                }
                ?>
        <li>
          <?php 
                $category_name = $category->name;
                if ($show_parent) {
                    if ($category->parent > 0) {
                        $category_name = $category->name;
                        $style = "margin-left: 15px;";
                        ?>
            <?php 
                    }
                    ?>
          <?php 
                }
                ?>
          <label>
            <input class="category_checkbox" style="<?php 
                echo isset($style) && $style ? $style : '';
                ?>
" id="<?php 
                echo $field['key'] . '_' . $category->slug;
                ?>
" name="<?php 
                echo $field['name'] . '[]';
                ?>
"
               type="checkbox" data-id="<?php 
                echo $category->term_id;
                ?>
" data-parent="<?php 
                echo $category->parent;
                ?>
" value="<?php 
                echo $category->slug;
                ?>
" <?php 
                echo $is_selected;
                ?>
 />
            <?php 
                echo $category_name;
                ?>
            <?php 
                if (isset($post_count[$category->term_id]) && $post_count[$category->term_id]['parent'] > $post_count[$category->term_id]['children']) {
                    ?>
              <span style="font-weight: bold; margin-left: 5px; font-size: 11px;">(You have posts that aren't assigned to a child category - <a target="_blank" href='<?php 
                    echo admin_url();
                    ?>
edit.php?category_name=<?php 
                    echo $category->slug;
                    ?>
'>Click here to manage posts</a>)</span>
            <?php 
                }
                ?>
          </label>
        </li>
        <?php 
                $style = false;
            }
            ?>
      </ul>
            <script type="text/javascript">
              jQuery('#post').submit(function() {
                  var any_checked = false;

                  jQuery('.field-categories ul li input').each(function() {
                      if(jQuery(this).is(':checked')) {
                          any_checked = true;
                      }
                      var field_name = jQuery(this).attr('name');
                  });

                  if(!any_checked) {
                     var select_none_id = '#<?php 
            echo $field['key'] . '_none';
            ?>
';
                     jQuery(select_none_id).attr('checked','checked');
                  }
              });

              /**
               * If parent is selected, select the children
               */
              jQuery('.category_checkbox').change(function() {
                var id = jQuery(this).data('id'),
                    parent_ul = jQuery(this).parents('ul'),
                    parent_id = jQuery(this).data('parent'),
                    checkboxes = parent_ul.find(".category_checkbox[data-parent=" + id + "]");

                // Check checkboxes while checking checkboxes
                checkboxes.prop('checked', jQuery(this).is(':checked'));

                // Unchecks parent if child isn't checked
                if (parent_id !== 0) {
                  if (jQuery(this).is(':checked') === false) {
                    jQuery(".category_checkbox[data-id=" + parent_id + "]").prop('checked', false);
                  } else {
                    var all_checked = true;
                    parent_ul.find(".category_checkbox[data-parent=" + parent_id + "]").each(function() {
                      if (jQuery(this).is(':checked') === false) {
                        all_checked = false;
                      }
                    });

                    // Check parent checkbox if all children are selected
                    if (all_checked) {
                      jQuery(".category_checkbox[data-id=" + parent_id + "]").prop('checked', true);
                    }
                  }
                }
              });
            </script>
    <?php 
        }
        ?>
    <?php 
    }
<?php

/**
* Front page
*/
$relative_path = "";
require $relative_path . 'settings.php';
include $relative_path . "cache.php";
$page = 'front-page';
require $relative_path . "common.php";
//get countries
$parliaments = json_decode(file_get_contents(APP_PATH . "inc/parliaments.json"));
$selected_countries = selected_countries($parliaments);
//get categories
$categories = json_decode(file_get_contents(APP_PATH . "inc/categories.json"));
$categories_sorted = sort_categories($categories);
//read jumbo.md
include 'Parsedown.php';
$mdurl = TEXT_URL . lang($page) . "/front-page/jumbo.md";
$contents = file_get_contents($mdurl);
$Parsedown = new Parsedown();
//include texts
//categories
$handle = fopen(TEXT_PATH . $lang . DIRECTORY_SEPARATOR . 'meta' . DIRECTORY_SEPARATOR . 'categories.csv', "r");
$categories_texts = csv2array($handle);
// print_r($categories_texts);die();
$smarty->assign('countries', json_encode($selected_countries));
$smarty->assign('categories', $categories_sorted);
$smarty->assign('jumbo_text', ltrim($Parsedown->text($contents), '<p>'));
$smarty->assign('categories_texts', $categories_texts);
$smarty->assign('relative_path', $relative_path);