コード例 #1
0
 /**
  * Get the translatable country name for the search area.
  * 
  * @global type $WT_TREE
  * @param type $area
  * @return string
  */
 static function getSearchAreaName($area)
 {
     global $WT_TREE;
     $stats = new Stats($WT_TREE);
     $countries = $stats->getAllCountries();
     if (array_key_exists($area, $countries)) {
         $area = $countries[$area];
     } else {
         $area = I18N::translate("International");
     }
     return $area;
 }
コード例 #2
0
ファイル: GoogleMapsModule.php プロジェクト: bxbroze/webtrees
    /**
     * Select a flag.
     */
    private function flags()
    {
        global $WT_TREE;
        $controller = new SimpleController();
        $controller->setPageTitle(I18N::translate('Select flag'))->pageHeader();
        $stats = new Stats($WT_TREE);
        $countries = $stats->getAllCountries();
        $action = Filter::post('action');
        $countrySelected = Filter::get('countrySelected', null, 'Countries');
        $stateSelected = Filter::get('stateSelected', null, 'States');
        $country = array();
        if (is_dir(WT_ROOT . WT_MODULES_DIR . 'googlemap/places/flags')) {
            $rep = opendir(WT_ROOT . WT_MODULES_DIR . 'googlemap/places/flags');
            while ($file = readdir($rep)) {
                if (stristr($file, '.png')) {
                    $country[] = substr($file, 0, strlen($file) - 4);
                }
            }
            closedir($rep);
            sort($country);
        }
        if ($countrySelected == 'Countries') {
            $flags = $country;
        } else {
            $flags = array();
            if (is_dir(WT_ROOT . WT_MODULES_DIR . 'googlemap/places/' . $countrySelected . '/flags')) {
                $rep = opendir(WT_ROOT . WT_MODULES_DIR . 'googlemap/places/' . $countrySelected . '/flags');
                while ($file = readdir($rep)) {
                    if (stristr($file, '.png')) {
                        $flags[] = substr($file, 0, strlen($file) - 4);
                    }
                }
                closedir($rep);
                sort($flags);
            }
        }
        $flags_s = array();
        if ($stateSelected != 'States' && is_dir(WT_ROOT . WT_MODULES_DIR . 'googlemap/places/' . $countrySelected . '/flags/' . $stateSelected)) {
            $rep = opendir(WT_ROOT . WT_MODULES_DIR . 'googlemap/places/' . $countrySelected . '/flags/' . $stateSelected);
            while ($file = readdir($rep)) {
                if (stristr($file, '.png')) {
                    $flags_s[] = substr($file, 0, strlen($file) - 4);
                }
            }
            closedir($rep);
            sort($flags_s);
        }
        if ($action == 'ChangeFlag' && isset($_POST['FLAGS'])) {
            ?>
			<script>
		<?php 
            if ($_POST['selcountry'] == 'Countries') {
                ?>
					window.opener.document.editplaces.icon.value = 'places/flags/<?php 
                echo $flags[$_POST['FLAGS']];
                ?>
.png';
					window.opener.document.getElementById('flagsDiv').innerHTML = "<img src=\"<?php 
                echo WT_STATIC_URL . WT_MODULES_DIR;
                ?>
googlemap/places/flags/<?php 
                echo $country[$_POST['FLAGS']];
                ?>
.png\">&nbsp;&nbsp;<a href=\"#\" onclick=\"change_icon();return false;\"><?php 
                echo I18N::translate('Change flag');
                ?>
</a>&nbsp;&nbsp;<a href=\"#\" onclick=\"remove_icon();return false;\"><?php 
                echo I18N::translate('Remove flag');
                ?>
</a>";
		<?php 
            } elseif ($_POST['selstate'] != "States") {
                ?>
					window.opener.document.editplaces.icon.value = 'places/<?php 
                echo $countrySelected . '/flags/' . $_POST['selstate'] . '/' . $flags_s[$_POST['FLAGS']];
                ?>
.png';
					window.opener.document.getElementById('flagsDiv').innerHTML = "<img src=\"<?php 
                echo WT_STATIC_URL . WT_MODULES_DIR;
                ?>
googlemap/places/<?php 
                echo $countrySelected . "/flags/" . $_POST['selstate'] . '/' . $flags_s[$_POST['FLAGS']];
                ?>
.png\">&nbsp;&nbsp;<a href=\"#\" onclick=\"change_icon();return false;\"><?php 
                echo I18N::translate('Change flag');
                ?>
</a>&nbsp;&nbsp;<a href=\"#\" onclick=\"remove_icon();return false;\"><?php 
                echo I18N::translate('Remove flag');
                ?>
</a>";
		<?php 
            } else {
                ?>
					window.opener.document.editplaces.icon.value = "places/<?php 
                echo $countrySelected . '/flags/' . $flags[$_POST['FLAGS']];
                ?>
.png";
					window.opener.document.getElementById('flagsDiv').innerHTML = "<img src=\"<?php 
                echo WT_STATIC_URL . WT_MODULES_DIR;
                ?>
googlemap/places/<?php 
                echo $countrySelected . '/flags/' . $flags[$_POST['FLAGS']];
                ?>
.png\">&nbsp;&nbsp;<a href=\"#\" onclick=\"change_icon();return false;\"><?php 
                echo I18N::translate('Change flag');
                ?>
</a>&nbsp;&nbsp;<a href=\"#\" onclick=\"remove_icon();return false;\"><?php 
                echo I18N::translate('Remove flag');
                ?>
</a>";
		<?php 
            }
            ?>
					window.opener.updateMap();
					window.close();
			</script>
		<?php 
            exit;
        } else {
            ?>
		<script>
			function selectCountry() {
				if (document.flags.COUNTRYSELECT.value == 'Countries') {
					window.location="module.php?mod=googlemap&mod_action=flags&countrySelected=Countries";
				} else if (document.flags.STATESELECT.value != 'States') {
					window.location="module.php?mod=googlemap&mod_action=flags&countrySelected=" + document.flags.COUNTRYSELECT.value + "&stateSelected=" + document.flags.STATESELECT.value;
				} else {
					window.location="module.php?mod=googlemap&mod_action=flags&countrySelected=" + document.flags.COUNTRYSELECT.value;
				}
			}
		</script>
		<?php 
        }
        $countryList = array();
        $placesDir = scandir(WT_MODULES_DIR . 'googlemap/places/');
        for ($i = 0; $i < count($country); $i++) {
            if (count(preg_grep('/' . $country[$i] . '/', $placesDir)) != 0) {
                $rep = opendir(WT_MODULES_DIR . 'googlemap/places/' . $country[$i] . '/');
                while ($file = readdir($rep)) {
                    if (stristr($file, 'flags')) {
                        if (isset($countries[$country[$i]])) {
                            $countryList[$country[$i]] = $countries[$country[$i]];
                        } else {
                            $countryList[$country[$i]] = $country[$i];
                        }
                    }
                }
                closedir($rep);
            }
        }
        asort($countryList);
        $stateList = array();
        if ($countrySelected != 'Countries') {
            $placesDir = scandir(WT_MODULES_DIR . 'googlemap/places/' . $countrySelected . '/flags/');
            for ($i = 0; $i < count($flags); $i++) {
                if (in_array($flags[$i], $placesDir)) {
                    $rep = opendir(WT_MODULES_DIR . 'googlemap/places/' . $countrySelected . '/flags/' . $flags[$i] . '/');
                    while ($file = readdir($rep)) {
                        $stateList[$flags[$i]] = $flags[$i];
                    }
                    closedir($rep);
                }
            }
            asort($stateList);
        }
        ?>
		<h4><?php 
        echo I18N::translate('Change flag');
        ?>
</h4>

		<p class="small text-muted">
			<?php 
        echo I18N::translate('Using the pull down menu it is possible to select a country, of which a flag can be selected.  If no flags are shown, then there are no flags defined for this country.');
        ?>
		</p>

		<form method="post" id="flags" name="flags" action="module.php?mod=googlemap&amp;mod_action=flags&amp;countrySelected=<?php 
        echo $countrySelected;
        ?>
&amp;stateSelected=<?php 
        echo $stateSelected;
        ?>
">
			<input type="hidden" name="action" value="ChangeFlag">
			<input type="hidden" name="selcountry" value="<?php 
        echo $countrySelected;
        ?>
">
			<input type="hidden" name="selstate" value="<?php 
        echo $stateSelected;
        ?>
">
			<table class="facts_table">
				<tr>
					<td class="optionbox" colspan="4">
						<select name="COUNTRYSELECT" dir="ltr" onchange="selectCountry()">
							<option value="Countries"><?php 
        echo I18N::translate('Countries');
        ?>
</option>
							<?php 
        foreach ($countryList as $country_key => $country_name) {
            echo '<option value="', $country_key, '" ';
            if ($countrySelected == $country_key) {
                echo 'selected';
            }
            echo '>', $country_name, '</option>';
        }
        ?>
						</select>
					</td>
				</tr>
				<tr>
		<?php 
        $j = 1;
        for ($i = 0; $i < count($flags); $i++) {
            if ($countrySelected == 'Countries') {
                $tempstr = '<td><input type="radio" dir="ltr" name="FLAGS" value="' . $i . '"><img src="' . WT_STATIC_URL . WT_MODULES_DIR . 'googlemap/places/flags/' . $flags[$i] . '.png" alt="' . $flags[$i] . '"  title="';
                if ($flags[$i] != 'blank') {
                    if (isset($countries[$flags[$i]])) {
                        $tempstr .= $countries[$flags[$i]];
                    } else {
                        $tempstr .= $flags[$i];
                    }
                } else {
                    $tempstr .= $countries['???'];
                }
                echo $tempstr, '">&nbsp;&nbsp;', $flags[$i], '</input></td>';
            } else {
                echo '<td><input type="radio" dir="ltr" name="FLAGS" value="', $i, '"><img src="', WT_STATIC_URL, WT_MODULES_DIR, 'googlemap/places/', $countrySelected, '/flags/', $flags[$i], '.png">&nbsp;&nbsp;', $flags[$i], '</input></td>';
            }
            if ($j == 4) {
                echo '</tr><tr>';
                $j = 0;
            }
            $j++;
        }
        echo '</tr><tr';
        if ($countrySelected == 'Countries' || count($stateList) == 0) {
            echo ' style=" visibility: hidden"';
        }
        echo '>';
        ?>
					<td class="optionbox" colspan="4">
						<select name="STATESELECT" dir="ltr" onchange="selectCountry()">
							<option value="States"><?php 
        echo I18N::translate('Subdivision');
        ?>
</option>
							<?php 
        foreach ($stateList as $state_key => $state_name) {
            echo '<option value="', $state_key, '" ';
            if ($stateSelected == $state_key) {
                echo 'selected';
            }
            echo '>', $state_name, '</option>';
        }
        ?>
						</select>
					</td>
				</tr>
				<tr>
		<?php 
        $j = 1;
        for ($i = 0; $i < count($flags_s); $i++) {
            if ($stateSelected != 'States') {
                echo '<td><input type="radio" dir="ltr" name="FLAGS" value="', $i, '"><img src="', WT_STATIC_URL . WT_MODULES_DIR, 'googlemap/places/', $countrySelected, '/flags/', $stateSelected, '/', $flags_s[$i], '.png">&nbsp;&nbsp;', $flags_s[$i], '</input></td>';
            }
            if ($j == 4) {
                echo '</tr><tr>';
                $j = 0;
            }
            $j++;
        }
        ?>
				</tr>
			</table>
			<p id="save-cancel">
				<input type="submit" class="save" value="<?php 
        echo I18N::translate('save');
        ?>
">
				<input type="button" class="cancel" value="<?php 
        echo I18N::translate('close');
        ?>
" onclick="window.close();">
			</p>
		</form>
		<?php 
    }
コード例 #3
0
    /**
     * Select a flag.
     */
    private function flags()
    {
        global $WT_TREE;
        $controller = new SimpleController();
        $controller->setPageTitle(I18N::translate('Select flag'))->pageHeader();
        $stats = new Stats($WT_TREE);
        $countries = $stats->getAllCountries();
        $action = Filter::post('action');
        $countrySelected = Filter::get('countrySelected', null, 'Countries');
        $stateSelected = Filter::get('stateSelected', null, 'States');
        $country = array();
        if (is_dir(WT_ROOT . WT_MODULES_DIR . 'googlemap/places/flags')) {
            $files = glob(WT_ROOT . WT_MODULES_DIR . 'googlemap/places/flags/*.png');
            foreach ($files as $file) {
                $country[] = basename($file, '.png');
            }
        }
        if ($countrySelected == 'Countries') {
            $flags = $country;
        } else {
            $flags = array();
            if (is_dir(WT_ROOT . WT_MODULES_DIR . 'googlemap/places/' . $countrySelected . '/flags')) {
                $files = glob(WT_ROOT . WT_MODULES_DIR . 'googlemap/places/' . $countrySelected . '/flags/*.png');
                foreach ($files as $file) {
                    $flags[] = basename($file, '.png');
                }
            }
        }
        $flags_s = array();
        if ($stateSelected != 'States' && is_dir(WT_ROOT . WT_MODULES_DIR . 'googlemap/places/' . $countrySelected . '/flags/' . $stateSelected)) {
            $files = glob(WT_ROOT . WT_MODULES_DIR . 'googlemap/places/' . $countrySelected . '/flags/' . $stateSelected . '/*.png');
            foreach ($files as $file) {
                $flags_s[] = basename($file, '.png');
            }
        }
        if ($action == 'ChangeFlag' && Filter::post('FLAGS') !== null) {
            ?>
			<script>
		<?php 
            if (Filter::post('selcountry') == 'Countries') {
                ?>
					window.opener.document.editplaces.icon.value = 'places/flags/<?php 
                echo $flags[Filter::post('FLAGS')];
                ?>
.png';
					window.opener.document.getElementById('flagsDiv').innerHTML = "<img src=\"<?php 
                echo WT_STATIC_URL . WT_MODULES_DIR;
                ?>
googlemap/places/flags/<?php 
                echo $country[Filter::post('FLAGS')];
                ?>
.png\">&nbsp;&nbsp;<a href=\"#\" onclick=\"change_icon();return false;\"><?php 
                echo I18N::translate('Change flag');
                ?>
</a>&nbsp;&nbsp;<a href=\"#\" onclick=\"remove_icon();return false;\"><?php 
                echo I18N::translate('Remove flag');
                ?>
</a>";
		<?php 
            } elseif (Filter::post('selstate') != "States") {
                ?>
					window.opener.document.editplaces.icon.value = 'places/<?php 
                echo $countrySelected . '/flags/' . Filter::post('selstate') . '/' . $flags_s[Filter::post('FLAGS')];
                ?>
.png';
					window.opener.document.getElementById('flagsDiv').innerHTML = "<img src=\"<?php 
                echo WT_STATIC_URL . WT_MODULES_DIR;
                ?>
googlemap/places/<?php 
                echo $countrySelected . "/flags/" . Filter::post('selstate') . '/' . $flags_s[Filter::post('FLAGS')];
                ?>
.png\">&nbsp;&nbsp;<a href=\"#\" onclick=\"change_icon();return false;\"><?php 
                echo I18N::translate('Change flag');
                ?>
</a>&nbsp;&nbsp;<a href=\"#\" onclick=\"remove_icon();return false;\"><?php 
                echo I18N::translate('Remove flag');
                ?>
</a>";
		<?php 
            } else {
                ?>
					window.opener.document.editplaces.icon.value = "places/<?php 
                echo $countrySelected . '/flags/' . $flags[Filter::post('FLAGS')];
                ?>
.png";
					window.opener.document.getElementById('flagsDiv').innerHTML = "<img src=\"<?php 
                echo WT_STATIC_URL . WT_MODULES_DIR;
                ?>
googlemap/places/<?php 
                echo $countrySelected . '/flags/' . $flags[Filter::post('FLAGS')];
                ?>
.png\">&nbsp;&nbsp;<a href=\"#\" onclick=\"change_icon();return false;\"><?php 
                echo I18N::translate('Change flag');
                ?>
</a>&nbsp;&nbsp;<a href=\"#\" onclick=\"remove_icon();return false;\"><?php 
                echo I18N::translate('Remove flag');
                ?>
</a>";
		<?php 
            }
            ?>
					window.opener.updateMap();
					window.close();
			</script>
		<?php 
            return;
        } else {
            ?>
		<script>
			function selectCountry() {
				if (document.flags.COUNTRYSELECT.value == 'Countries') {
					window.location="module.php?mod=googlemap&mod_action=flags&countrySelected=Countries";
				} else if (document.flags.STATESELECT.value != 'States') {
					window.location="module.php?mod=googlemap&mod_action=flags&countrySelected=" + document.flags.COUNTRYSELECT.value + "&stateSelected=" + document.flags.STATESELECT.value;
				} else {
					window.location="module.php?mod=googlemap&mod_action=flags&countrySelected=" + document.flags.COUNTRYSELECT.value;
				}
			}
		</script>
		<?php 
        }
        $countryList = array();
        foreach ($country as $item) {
            if (is_dir(WT_MODULES_DIR . 'googlemap/places/' . $item . '/flags')) {
                if (isset($countries[$item])) {
                    $countryList[$item] = $countries[$item];
                } else {
                    $countryList[$item] = $item;
                }
            }
        }
        asort($countryList);
        $stateList = array();
        if ($countrySelected != 'Countries') {
            $placesDir = scandir(WT_MODULES_DIR . 'googlemap/places/' . $countrySelected . '/flags/');
            foreach ($flags as $flag) {
                if (in_array($flag, $placesDir)) {
                    $rep = opendir(WT_MODULES_DIR . 'googlemap/places/' . $countrySelected . '/flags/' . $flag . '/');
                    while ($file = readdir($rep)) {
                        $stateList[$flag] = $flag;
                    }
                    closedir($rep);
                }
            }
            asort($stateList);
        }
        ?>
		<h4><?php 
        echo I18N::translate('Change flag');
        ?>
</h4>

		<p class="small text-muted">
			<?php 
        echo I18N::translate('Using the pull down menu it is possible to select a country, of which a flag can be selected. If no flags are shown, then there are no flags defined for this country.');
        ?>
		</p>

		<form method="post" id="flags" name="flags" action="module.php?mod=googlemap&amp;mod_action=flags&amp;countrySelected=<?php 
        echo $countrySelected;
        ?>
&amp;stateSelected=<?php 
        echo $stateSelected;
        ?>
">
			<input type="hidden" name="action" value="ChangeFlag">
			<input type="hidden" name="selcountry" value="<?php 
        echo $countrySelected;
        ?>
">
			<input type="hidden" name="selstate" value="<?php 
        echo $stateSelected;
        ?>
">
			<table class="facts_table" style="margin: 0 auto 20px">
				<tr>
					<td class="optionbox" colspan="4">
						<select name="COUNTRYSELECT" dir="ltr" onchange="selectCountry()">
							<option value="Countries"><?php 
        echo I18N::translate('Countries');
        ?>
</option>
							<?php 
        foreach ($countryList as $country_key => $country_name) {
            echo '<option value="', $country_key, '" ';
            if ($countrySelected == $country_key) {
                echo 'selected';
            }
            echo '>', $country_name, '</option>';
        }
        ?>
						</select>
					</td>
				</tr>

				<?php 
        $i = 0;
        $path = WT_STATIC_URL . WT_MODULES_DIR . 'googlemap/places/';
        $path .= $countrySelected == 'Countries' ? 'flags/' : $countrySelected . '/flags/';
        foreach (array_chunk($flags, 4) as $row) {
            echo "<tr>";
            foreach ($row as $flag) {
                if ($flag != 'blank') {
                    if (isset($countries[$flag])) {
                        $title = $countries[$flag];
                    } else {
                        $title = $flag;
                    }
                } else {
                    $title = $countries['???'];
                }
                echo '<td>';
                echo '<input type="radio" dir="ltr" name="FLAGS" value="' . $i++ . '">';
                echo '<img style="width:25px; height:15px; margin-right:15px" src="' . $path . $flag . '.png" alt="' . $flag . '" title="' . $title . '">';
                echo $flag . '</td>';
            }
            echo str_repeat('<td></td>', 4 - count($row));
            echo "</tr>";
        }
        echo '<tr style="visibility:' . ($countrySelected == 'Countries' || count($stateList) == 0 ? 'hidden' : 'visible') . '">';
        ?>

				<td class="optionbox" colspan="4">
					<select name="STATESELECT" dir="ltr" onchange="selectCountry()">
						<option value="States"><?php 
        echo I18N::translate('Subdivision');
        ?>
</option>
						<?php 
        foreach ($stateList as $state_key => $state_name) {
            echo '<option value="', $state_key, '" ';
            if ($stateSelected == $state_key) {
                echo 'selected';
            }
            echo '>', $state_name, '</option>';
        }
        ?>
					</select>
				</td>
			</tr>

			<?php 
        $i = 0;
        if (!empty($flags_s)) {
            foreach (array_chunk($flags_s, 4) as $row) {
                echo "<tr>";
                foreach ($row as $flag) {
                    echo '<td><input type="radio" dir="ltr" name="FLAGS" value="', $i++, '"><img src="', WT_STATIC_URL . WT_MODULES_DIR, 'googlemap/places/', $countrySelected, '/flags/', $stateSelected, '/', $flag, '.png">&nbsp;&nbsp;', $flag, '</td>';
                }
                echo str_repeat('<td></td>', 4 - count($row));
                echo '</tr>';
            }
        }
        ?>

			</table>
			<p id="save-cancel">
				<input type="submit" class="save" value="<?php 
        echo I18N::translate('save');
        ?>
">
				<input type="button" class="cancel" value="<?php 
        echo I18N::translate('close');
        ?>
" onclick="window.close();">
			</p>
		</form>
		<?php 
    }