function pof_content_status_images_get_form() { $ret = ""; $ret .= "<form method=\"POST\">"; $ret .= "Valitse ikäkausi: <br />"; $ret .= '<select name="agegroup">'; $agegroups = pof_taxonomy_translate_get_agegroups(); foreach ($agegroups as $agegroup) { if ($agegroup->id == 0) { continue; } $selected = ""; if (isset($_POST) && isset($_POST["agegroup"])) { if ($_POST["agegroup"] == $agegroup->id) { $selected = " selected=\"selected\""; } } $ret .= "<option" . $selected . " value=\"" . $agegroup->id . "\">" . $agegroup->title . "</option>\n"; } $ret .= '</select>'; $ret .= '<br /><br /><input type="submit" name="Submit" value="Näytä" />'; $ret .= "</form>"; return $ret; }
function pof_importer_suggestionsdriveimport2() { echo '<div class="wrap">'; echo '<h1>POF Importer, vinkit google drivestä</h1>'; if (!isset($_POST) || !isset($_POST["drive_file_id"])) { $service = pof_importer_get_google_service(); echo '<form method="post" action="">'; // Print the names and IDs for up to 10 files. $optParams = array('maxResults' => 999, 'q' => "mimeType = 'application/vnd.google-apps.spreadsheet' and (title contains 'vinki' or title contains 'vinkki' or title contains '_vinkit_')", 'orderBy' => 'folder,modifiedDate desc,title'); $results = $service->files->listFiles($optParams); if (count($results->getItems()) == 0) { print "No files found.\n"; } else { print "Valitse importoitava tiedosto:<br />"; echo '<select name="drive_file_id">'; foreach ($results->getItems() as $file) { $fileLastModified = strtotime($file->getModifiedDate()); printf("<option value=\"%s\">%s (%s)</option>\n", $file->getId(), $file->getTitle(), date('d.m.Y', $fileLastModified)); } echo "</select>"; echo "<br />"; print "Valitse ikäkausi: <br />"; echo '<select name="agegroup">'; $agegroups = pof_taxonomy_translate_get_agegroups(); foreach ($agegroups as $agegroup) { if ($agegroup->id == 0) { continue; } printf("<option value=\"%s\">%s</option>\n", $agegroup->id, $agegroup->title); } echo '</select>'; echo "<br />"; echo "<br />"; echo '<input type="submit" name="Submit" value="Valitse tiedosto" />'; echo '</form>'; } } else { if (!isset($_POST["SaveToDatabase"])) { echo '<form method="post" action="">'; echo '<input type="hidden" name="drive_file_id" value="' . $_POST["drive_file_id"] . '" />'; echo '<input type="hidden" name="agegroup" value="' . $_POST["agegroup"] . '" />'; echo '<input type="submit" name="SaveToDatabase" value="Tallenna tietokantaan" />'; echo '<br /><br />'; echo '<input type="submit" name="RunAgain" value="Aja uudestaan" />'; echo '</form>'; pof_importer_suggestionsdriveimport_run2($_POST["drive_file_id"], $_POST["agegroup"]); } else { echo '<form method="post" action="">'; echo '<input type="hidden" name="drive_file_id" value="' . $_POST["drive_file_id"] . '" />'; echo '<input type="hidden" name="agegroup" value="' . $_POST["agegroup"] . '" />'; echo '<input type="submit" name="SaveToDatabase" value="Tallenna tietokantaan" />'; echo '<br /><br />'; echo '<input type="submit" name="RunAgain" value="Aja uudestaan" />'; echo '</form>'; pof_importer_suggestionsdriveimport_run2($_POST["drive_file_id"], $_POST["agegroup"], true); } } echo "</div>"; }
function pof_importer_suggestionsdriveimport_run2($fileId, $agegroup_id, $saveToDataBase = false) { $service = pof_importer_get_google_service(); $agegroups = pof_taxonomy_translate_get_agegroups(); $agegroup = new stdClass(); foreach ($agegroups as $agegroup_tmp) { if ($agegroup_tmp->id == $agegroup_id) { $agegroup = $agegroup_tmp; break; } } try { $file = $service->files->get($fileId); $lang = substr($file->getTitle(), -2, 2); echo '<table cellpadding="2" cellspacing="2" border="2">'; echo '<tr>'; echo '<th>Otsikko</th>'; echo '<td>' . $file->getTitle() . '</td>'; echo '</tr>'; echo '<tr>'; echo '<th>Kieli</th>'; echo '<td>' . $lang . '</td>'; echo '</tr>'; echo '<tr>'; echo '<th>Avaa drivessä</th>'; echo '<td><a href="' . $file->getAlternateLink() . '" target="_blank">' . $file->getAlternateLink() . '</a></td>'; echo '</tr>'; echo '<tr>'; echo '<th>Ikäkausi</th>'; echo '<td>' . $agegroup->title . '</td>'; echo '</tr>'; echo '<tr>'; echo '<th>Kirjoittaja</th>'; echo '<td>Suomen partiolaiset</td>'; echo '</tr>'; echo '<tr>'; echo '<th>Kuvaus</th>'; echo '<td>' . $file->getDescription() . '</td>'; echo '</tr>'; echo '<tr>'; echo '<th>Viimeksi muokattu</th>'; $fileLastModified = strtotime($file->getModifiedDate()); echo '<td>' . date('d.m.Y', $fileLastModified) . '</td>'; echo '</tr>'; echo '<tr>'; echo '<th>Muokkaaja</th>'; echo '<td>' . $file->getLastModifyingUserName() . '</td>'; echo '</tr>'; echo '</table>'; $filepath = pof_importer_download_drive_file($service, $file); $objReader = pof_imported_get_phpExcel_objReader(); $objPHPExcel = $objReader->load($filepath); $sheetData = $objPHPExcel->getActiveSheet()->toArray(null, true, true, true); if (pof_importer_tasksdriveimport_checkThatHeadersMatchSuggestions2($sheetData[1])) { $headers = $sheetData[1]; $i = 0; foreach ($sheetData as $sheetDataRow) { $i++; if ($i < 2) { continue; } if (trim($sheetDataRow['A']) == '') { continue; } pof_importer_suggestionssdriveimport_importRow2($sheetDataRow, $i, $agegroup_id, $lang, $saveToDataBase); } } else { echo "<h1>Unvalid excel, or failed to read excel at all.</h1>"; } } catch (Exception $e) { echo "An error occurred: " . $e->getMessage(); } }
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>'; }
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ää 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>'; }