function pof_pages_get_tags($languages, $items, $item_tax_key)
{
    global $filter_langs;
    $items_arr = array();
    foreach ($languages as $lang_key => $lang) {
        if ($filter_langs != "all" && !strstr($filter_langs, $lang_key)) {
            continue;
        }
        $tmp = new stdClass();
        $tmp->lang = $lang_key;
        $tmp->items = array();
        foreach ($items as $item_key => $item) {
            $tmp_item = new stdClass();
            $tmp_item->key = $item_key;
            $tmp_name = pof_taxonomy_translate_get_translation($item_tax_key, $item_key, 0, $lang_key, false);
            if (!empty($tmp_name)) {
                $tmp_item->value = $tmp_name[0]->content;
            } else {
                $tmp_item->value = $item;
            }
            array_push($tmp->items, $tmp_item);
        }
        array_push($items_arr, $tmp);
    }
    return $items_arr;
}
function get_post_tags_taskgroup_JSON($post_id, $agegroup_id, $lang)
{
    $ret = new stdClass();
    $pakollisuus = array();
    if (get_post_meta($post_id, "taskgroup_mandatory", true)) {
        $pakollinen = new stdClass();
        $tmp_name = pof_taxonomy_translate_get_translation('mandatory', 'mandatory', $agegroup_id, $lang, true);
        if (!empty($tmp_name)) {
            $pakollinen->name = $tmp_name[0]->content;
        } else {
            $pakollinen->name = 'Pakollinen';
        }
        $pakollinen->slug = 'mandatory';
        $icon = pof_taxonomy_icons_get_icon('mandatory', 'mandatory', $agegroup_id, true);
        if (!empty($icon)) {
            $icon_src = wp_get_attachment_image_src($icon[0]->attachment_id);
            if (!empty($icon_src)) {
                $pakollinen->icon = $icon_src[0];
            }
        }
        array_push($pakollisuus, $pakollinen);
    }
    if (count($pakollisuus) > 0) {
        $ret->pakollisuus = $pakollisuus;
    } else {
        $pakollinen = new stdClass();
        $tmp_name = pof_taxonomy_translate_get_translation('mandatory', 'not_mandatory', $agegroup_id, $lang, true);
        if (!empty($tmp_name)) {
            $pakollinen->name = $tmp_name[0]->content;
        } else {
            $pakollinen->name = 'Ei pakollinen';
        }
        $pakollinen->slug = 'not_mandatory';
        $icon = pof_taxonomy_icons_get_icon('mandatory', 'not_mandatory', $agegroup_id, true);
        if (!empty($icon)) {
            $icon_src = wp_get_attachment_image_src($icon[0]->attachment_id);
            if (!empty($icon_src)) {
                $pakollinen->icon = $icon_src[0];
            }
        }
        array_push($pakollisuus, $pakollinen);
        $ret->pakollisuus = $pakollisuus;
    }
    return $ret;
}
function pof_taxonomy_translate_form_view()
{
    $taxonomies = array();
    $taxonomies['place_of_performance'] = "Suorituspaikat";
    $taxonomies['groupsize'] = "Ryhmäkoot";
    $taxonomies['mandatory'] = "Pakollisuus";
    $taxonomies['taskduration'] = "Aktiviteetin kestot";
    $taxonomies['taskpreaparationduration'] = "Aktiviteetin valmistelun kestot";
    $taxonomies['equpment'] = "Tarvikkeet";
    $taxonomies['skillarea'] = "Taitoalueet";
    $taxonomies['growth_target'] = "Kasvatustavoitteen avainsanat";
    $taxonomies['taskgroup_term'] = "Aktiviteettipaketin yläkäsite";
    global $wpdb;
    $table_name = pof_taxonomy_translate_get_table_name();
    $languages = pof_taxonomy_translate_get_languages();
    $agegroups = pof_taxonomy_translate_get_agegroups();
    $selected_lang = 'fi';
    $taxonomy_base_key = "place_of_performance";
    if (isset($_POST['language'])) {
        $selected_lang = $_POST['language'];
    }
    if (isset($_POST['taxonomy'])) {
        $taxonomy_base_key = $_POST['taxonomy'];
    }
    $items = pof_taxonomy_translate_get_items_by_taxonomy_base_key($taxonomy_base_key);
    $title = $taxonomies[$taxonomy_base_key];
    echo '<div class="wrap">';
    echo '<h1>' . $title . '</h1>';
    echo '<form method="post" action="">';
    echo 'Valitse taksonomia:';
    echo '<select name="taxonomy">';
    foreach ($taxonomies as $taxonomy_key => $taxonomy_title) {
        if ($taxonomy_key == $taxonomy_base_key) {
            echo '<option selected="selected" value="' . $taxonomy_key . '">' . $taxonomy_title . '</option>';
        } else {
            echo '<option value="' . $taxonomy_key . '">' . $taxonomy_title . '</option>';
        }
    }
    echo '</select>';
    echo '<br />';
    echo 'Valitse kieli:';
    echo '<select name="language">';
    foreach ($languages as $lang_key => $lang) {
        if ($lang_key == $selected_lang) {
            echo '<option selected="selected" value="' . $lang_key . '">' . $lang . '</option>';
        } else {
            echo '<option value="' . $lang_key . '">' . $lang . '</option>';
        }
    }
    echo '</select>';
    echo '<br />';
    echo '<input type="submit" value="Vaihda" />';
    echo '</form>';
    echo '<br /><br /><br />';
    echo '<h2>Kieli: ' . $languages[$selected_lang] . ' (' . $selected_lang . ')</h2>';
    echo '<table cellpadding="2" cellspacing="2" border="2">';
    echo '<thead>';
    echo '<tr>';
    echo '<th></th>';
    foreach ($agegroups as $agegroup) {
        echo '<th><h2>' . $agegroup->title . '</h2></th>';
    }
    echo '</tr>';
    echo '</thead>';
    echo '<tbody>';
    foreach ($items as $tmp_key => $tmp_title) {
        echo '<tr>';
        echo '<td>' . $tmp_title . '<br /> (' . $tmp_key . ')</td>';
        foreach ($agegroups as $agegroup) {
            echo '<td>';
            $translation = pof_taxonomy_translate_get_translation($taxonomy_base_key, $tmp_key, $agegroup->id, $selected_lang, false);
            $translation_content = "";
            if (!empty($translation)) {
                $translation_content = $translation[0]->content;
            }
            echo $translation_content;
            echo '</td>';
        }
        echo '</tr>';
    }
    echo '</tbody>';
    echo '</table>';
    echo '</div>';
}
            echo $tmp;
        }
        echo ", ";
    }
}
?>
		</p>

		<h3>Kesto</h3>
		<p>

		<?php 
$groupsize = get_post_meta($post->ID, "task_duration", false);
if (count($groupsize) > 0) {
    foreach ($groupsize as $tmp) {
        $foo = pof_taxonomy_translate_get_translation('taskduration', $tmp, 0, 'fi', true);
        if (isset($foo[0]->content)) {
            echo $foo[0]->content;
        } else {
            echo $tmp;
        }
        echo ", ";
    }
}
?>
		</p>

		<h3>Aktiviteetin yl&auml;k&auml;site</h3>
		<?php 
echo get_post_meta($post->ID, "task_task_term", true);
?>
function pof_taxonomy_translate_form($taxonomy_base_key, $items, $title, $title2, $additional_text = "")
{
    if (!current_user_can('manage_options')) {
        wp_die(__('You do not have sufficient permissions to access this page.'));
    }
    global $wpdb;
    $table_name = pof_taxonomy_translate_get_table_name();
    $languages = pof_taxonomy_translate_get_languages();
    $agegroups = pof_taxonomy_translate_get_agegroups();
    $selected_lang = 'fi';
    if (isset($_POST['language'])) {
        $selected_lang = $_POST['language'];
    }
    if (isset($_POST['Change_lang'])) {
        $selected_lang = $_POST['language'];
    }
    if (isset($_POST['Submit'])) {
        foreach ($_POST as $key => $item) {
            if (substr($key, 0, 19) == "taxonomy_translate_") {
                $tmp = pof_taxonomy_translate_parser_taxonomy_key($key);
                $taxonomy_key = trim($tmp["key"]);
                if (strlen($taxonomy_key) == 0) {
                    continue;
                }
                $taxonomy_full_key = $taxonomy_base_key . "::" . $taxonomy_key;
                $agegroup_id = $tmp["agegroup_id"];
                $translation = pof_taxonomy_translate_get_translation($taxonomy_base_key, $taxonomy_key, $agegroup_id, $selected_lang, false);
                if (empty($translation) && $item != "") {
                    $tmp = $wpdb->insert($table_name, array('taxonomy_slug' => $taxonomy_full_key, 'agegroup_id' => (int) $agegroup_id, 'lang' => $selected_lang, 'content' => $item), array('%s', '%d', '%s', '%s'));
                    echo "<br />Added " . $key . "";
                } else {
                    if (!empty($translation) && $item != "") {
                        if ($translation[0]->content != $item) {
                            $tmp = $wpdb->update($table_name, array('content' => $item), array('id' => $translation[0]->id), array('%s'), array('%d'));
                            echo "<br />Updated" . $key . "";
                        }
                    } else {
                        if (!empty($translation) && $item == "") {
                            $wpdb->delete($table_name, array('id' => $translation[0]->id), array('%d'));
                            echo "<br />Deleted " . $key . "";
                        }
                    }
                }
            }
        }
        if (isset($_POST['add_taxonomy_translate_key']) && !empty($_POST['add_taxonomy_translate_key']) && strlen($_POST['add_taxonomy_translate_key']) > 0) {
            $taxonomy_key = trim($_POST['add_taxonomy_translate_key']);
            $taxonomy_key = str_replace(" ", "_", $taxonomy_key);
            $default = pof_taxonomy_translate_get_translation($taxonomy_base_key, $taxonomy_key, 0, 0, false);
            if (count($default) == 0) {
                $taxonomy_full_key = $taxonomy_base_key . "::" . $taxonomy_key;
                $tmp = $wpdb->insert($table_name, array('taxonomy_slug' => $taxonomy_full_key, 'agegroup_id' => 0, 'lang' => 'fi', 'content' => $_POST['add_taxonomy_translate_key_0']), array('%s', '%d', '%s', '%s'));
                foreach ($agegroups as $agegroup) {
                    if ($agegroup->id == 0) {
                        continue;
                    }
                    $tmp = $wpdb->insert($table_name, array('taxonomy_slug' => $taxonomy_full_key, 'agegroup_id' => $agegroup->id, 'lang' => 'fi', 'content' => $_POST['add_taxonomy_translate_key_' . $agegroup->id]), array('%s', '%d', '%s', '%s'));
                }
            }
        }
        // reload items:
        $items = pof_taxonomy_translate_get_items_by_taxonomy_base_key($taxonomy_base_key);
    }
    echo '<div class="wrap">';
    echo '<h1>' . $title . '</h1>';
    echo '<form id="featured_upload" method="post" action="">';
    echo 'Valitse kieli:';
    echo '<select name="language">';
    foreach ($languages as $lang_key => $lang) {
        if ($lang_key == $selected_lang) {
            echo '<option selected="selected" value="' . $lang_key . '">' . $lang . '</option>';
        } else {
            echo '<option value="' . $lang_key . '">' . $lang . '</option>';
        }
    }
    echo '</select>';
    echo '<br />';
    echo '<input type="submit" name="Change_lang" id="Change_lang" value="Vaihda kieli" />';
    echo '</form>';
    echo '<br /><br /><br />';
    echo '<form id="featured_upload" method="post" action="">';
    echo '<input type="hidden" name="language" value="' . $selected_lang . '" />';
    echo '<h2>Kieli: ' . $languages[$selected_lang] . ' (' . $selected_lang . ')</h2>';
    echo '<table cellpadding="2" cellspacing="2" border="2">';
    echo '<thead>';
    echo '<tr>';
    echo '<th><h2>' . $title2 . '</h2></th>';
    foreach ($agegroups as $agegroup) {
        echo '<th><h2>' . $agegroup->title . '</h2></th>';
    }
    echo '</tr>';
    echo '</thead>';
    echo '<tbody>';
    foreach ($items as $tmp_key => $tmp_title) {
        $tmp_key = trim($tmp_key);
        if (strlen($tmp_key) == 0) {
            continue;
        }
        echo '<tr>';
        echo '<th>' . $tmp_title . '<br /> (' . $tmp_key . ')</th>';
        foreach ($agegroups as $agegroup) {
            echo '<td>';
            $translation = pof_taxonomy_translate_get_translation($taxonomy_base_key, $tmp_key, $agegroup->id, $selected_lang, false);
            $translation_content = "";
            if (!empty($translation)) {
                $translation_content = $translation[0]->content;
            }
            echo '<input type="text" name="taxonomy_translate_' . $tmp_key . '_' . $agegroup->id . '" id="taxonomy_translate_' . $tmp_key . '_' . $agegroup->id . '" value="' . $translation_content . '" />';
            echo '</td>';
        }
        echo '</tr>';
    }
    echo '<tr>';
    echo '<th align="left" colspan="' . (count($agegroups) + 1) . '"><h3>Lis&auml;&auml; uusi</h3></th>';
    echo '</tr>';
    echo '<tr>';
    echo '<th valign="bottom">Koodi:<br /><input type="text" name="add_taxonomy_translate_key" id="add_taxonomy_translate_key" /></th>';
    foreach ($agegroups as $agegroup) {
        echo '<td valign="bottom">';
        echo '<input type="text" name="add_taxonomy_translate_key_' . $agegroup->id . '" id="add_taxonomy_translate_key_' . $agegroup->id . '" />';
        echo '</td>';
    }
    echo '</tr>';
    if ($additional_text != "") {
        echo '<tr>';
        echo '<th align="left" colspan="' . (count($agegroups) + 1) . '"><strong>' . $additional_text . '</strong></th>';
        echo '</tr>';
    }
    echo '</tbody>';
    echo '</table>';
    echo '<br /><input type="submit" name="Submit" value="Submit" />';
    echo '</form>';
    echo '</div>';
}