Русское сообщество fluxbb

Быстрый лёгкий надёжный форумный движок

Вы не вошли.

Объявление

Вы можете внести свой вклад в содержание сайта. Жертвователи попадут в почетную группу "Спонсоры". Поддержать сайт.

#1 2017-03-04 10:39:57

gandi
Участник
Зарегистрирован: 2017-03-04
Сообщений: 19

Add map for users location on userlist.php

Hy everybody, especially to Mr. Visman long time no see

today I try to add maps for my users location on my USERLIST.PHP

so I add this to userlist.php

<div class="panel-body">
      	  	  <div id="map"></div>
	  </div>
	    <script>
    var marker;
      function initialize() {
        // Variabel untuk menyimpan informasi (desc)
        var infoWindow = new google.maps.InfoWindow;
        //  Variabel untuk menyimpan peta Roadmap
        var mapOptions = {
          mapTypeId: google.maps.MapTypeId.ROADMAP
        } 
        // Pembuatan petanya
        var map = new google.maps.Map(document.getElementById('map'), mapOptions);
        // Variabel untuk menyimpan batas kordinat
        var bounds = new google.maps.LatLngBounds();

        // Fetch user data from database
        <?php
$result = $db->query('SELECT username, lat, lng FROM '.$db->prefix.'users') or error('Unable to fetch user locations', __FILE__, __LINE__, $db->error());
while ($udata = $db->fetch_assoc($result))
             $nama = $udata['username'];
               
              $lat = $udata['lat'];
              if ($udata['lat'] === NULL)
              $lat = '-7.4103038335291105';
              
              $lon = $udata['lng'];
              if ($udata['lng'] === NULL)
              $lon = '109.24630353125008';
              
                echo ("addMarker($lat, $lon, 'Lokasi : $nama<br/>Latitude : $lat<br/>Longitude : $lon');\n");  
                    
          ?>
          
        // Proses membuat marker 
        function addMarker(lat, lng, info) {
            var lokasi = new google.maps.LatLng(lat, lng);
            bounds.extend(lokasi);
            var marker = new google.maps.Marker({
                map: map,
                position: lokasi
            });       
            map.fitBounds(bounds);
            bindInfoWindow(marker, map, infoWindow, info);
         }
        
        // Menampilkan informasi pada masing-masing marker yang diklik
        function bindInfoWindow(marker, map, infoWindow, html) {
          google.maps.event.addListener(marker, 'click', function() {
            infoWindow.setContent(html);
            infoWindow.open(map, marker);
          });
        }
 
        }
      google.maps.event.addDomListener(window, 'load', initialize);
   </script>

But, unfortunately it always get error to fetch data from database. Anybody know whats the problem? And how to solve it?

Редактировался gandi (2017-03-04 10:49:47)

Offline

#2 2017-03-04 11:00:34

gandi
Участник
Зарегистрирован: 2017-03-04
Сообщений: 19

Re: Add map for users location on userlist.php

hi anybody here?

Offline

#3 2017-03-04 13:46:07

Visman
Administrator
Из Сибирь
Зарегистрирован: 2009-06-08
Сообщений: 2,236
Сайт

Re: Add map for users location on userlist.php

Columns lat and lng exist in the users table?

        <?php
$result = $db->query('SELECT username, lat, lng FROM '.$db->prefix.'users') or error('Unable to fetch user locations', __FILE__, __LINE__, $db->error());
while ($udata = $db->fetch_assoc($result))
             $nama = $udata['username'];
               
              $lat = $udata['lat'];
              if ($udata['lat'] === NULL)
              $lat = '-7.4103038335291105';
              
              $lon = $udata['lng'];
              if ($udata['lng'] === NULL)
              $lon = '109.24630353125008';
              
                echo ("addMarker($lat, $lon, 'Lokasi : $nama<br/>Latitude : $lat<br/>Longitude : $lon');\n");  
                    
          ?>

-->

<?php
$result = $db->query('SELECT username, lat, lng FROM '.$db->prefix.'users WHERE id>1 AND group_id!='.PUN_UNVERIFIED) or error('Unable to fetch user locations', __FILE__, __LINE__, $db->error());
while ($udata = $db->fetch_assoc($result)) {
    $nama = $udata['username'];
    $lat = empty($udata['lat']) ? '-7.4103038335291105' : $udata['lat'];
    $lon = empty($udata['lng']) ? '109.24630353125008' : $udata['lng'];

    echo ("addMarker($lat, $lon, 'Lokasi : $nama<br/>Latitude : $lat<br/>Longitude : $lon');\n");
}
?>

Offline

#4 2017-03-04 14:43:52

gandi
Участник
Зарегистрирован: 2017-03-04
Сообщений: 19

Re: Add map for users location on userlist.php

Yes it already exist on my users table. OK I'll try it and reporting the result soon.

Offline

#5 2017-03-04 15:54:23

gandi
Участник
Зарегистрирован: 2017-03-04
Сообщений: 19

Re: Add map for users location on userlist.php

I have try this, but it doesn't give any result to the map. I need to fetch all username, lat, & lng to displayed together in one map.

Here is the full of my userlist.php after this addition.

<?php

/**
 * Copyright (C) 2008-2012 FluxBB
 * based on code by Rickard Andersson copyright (C) 2002-2008 PunBB
 * License: http://www.gnu.org/licenses/gpl.html GPL version 2 or higher
 */

define('PUN_ROOT', dirname(__FILE__).'/');
require PUN_ROOT.'include/common.php';


if ($pun_user['g_read_board'] == '0')
	message($lang_common['No view'], false, '403 Forbidden');
else if ($pun_user['g_view_users'] == '0')
	message($lang_common['No permission'], false, '403 Forbidden');

// Load the userlist.php language file
require PUN_ROOT.'lang/'.$pun_user['language'].'/userlist.php';

// Load the search.php language file
require PUN_ROOT.'lang/'.$pun_user['language'].'/search.php';


// Determine if we are allowed to view post counts
$show_post_count = ($pun_config['o_show_post_count'] == '1' || $pun_user['is_admmod']) ? true : false;

$username = isset($_GET['username']) && $pun_user['g_search_users'] == '1' ? '*'.pun_trim($_GET['username']).'*' : '';
$show_group = isset($_GET['show_group']) ? intval($_GET['show_group']) : -1;
$sort_by = isset($_GET['sort_by']) && (in_array($_GET['sort_by'], array('username', 'registered')) || ($_GET['sort_by'] == 'num_posts' && $show_post_count)) ? $_GET['sort_by'] : 'username';
$sort_dir = isset($_GET['sort_dir']) && $_GET['sort_dir'] == 'DESC' ? 'DESC' : 'ASC';

// Create any SQL for the WHERE clause
$where_sql = array();
$like_command = ($db_type == 'pgsql') ? 'ILIKE' : 'LIKE';

if ($username != '')
	$where_sql[] = 'u.username '.$like_command.' \''.$db->escape(str_replace('*', '%', $username)).'\'';
if ($show_group > -1)
	$where_sql[] = 'u.group_id='.$show_group;

// Fetch user count
$result = $db->query('SELECT COUNT(id) FROM '.$db->prefix.'users AS u WHERE u.id>1 AND u.group_id!='.PUN_UNVERIFIED.(!empty($where_sql) ? ' AND '.implode(' AND ', $where_sql) : '')) or error('Unable to fetch user list count', __FILE__, __LINE__, $db->error());
$num_users = $db->result($result);

// Determine the user offset (based on $_GET['p'])
$num_pages = ceil($num_users / 50);

$p = (!isset($_GET['p']) || $_GET['p'] <= 1 || $_GET['p'] > $num_pages) ? 1 : intval($_GET['p']);
$start_from = 50 * ($p - 1);

$page_title = array(pun_htmlspecialchars($pun_config['o_board_title']), $lang_common['User list']);
if ($pun_user['g_search_users'] == '1')
	$focus_element = array('userlist', 'username');

// Generate paging links
$paging_links = '<span class="pages-label">'.$lang_common['Pages'].' </span>'.paginate($num_pages, $p, 'userlist.php?username='.urlencode($username).'&amp;show_group='.$show_group.'&amp;sort_by='.$sort_by.'&amp;sort_dir='.$sort_dir);


define('PUN_ALLOW_INDEX', 1);
define('PUN_ACTIVE_PAGE', 'userlist');
require PUN_ROOT.'header.php';

?>
<div class="blockform">
	<h2><span><?php echo $lang_search['User search'] ?></span></h2>
	<div class="box">
	  <div class="panel-body">
      	  	  <div id="map"></div>
	  </div>
	  <span><?php echo pun_htmlspecialchars($data['subject']) ?></span>
	    <script>
    var marker;
      function initialize() {
        // Variabel untuk menyimpan informasi (desc)
        var infoWindow = new google.maps.InfoWindow;
        //  Variabel untuk menyimpan peta Roadmap
        var mapOptions = {
          mapTypeId: google.maps.MapTypeId.ROADMAP
        } 
        // Pembuatan petanya
        var map = new google.maps.Map(document.getElementById('map'), mapOptions);
        // Variabel untuk menyimpan batas kordinat
        var bounds = new google.maps.LatLngBounds();

        // Pengambilan data dari database
       <?php
$result = $db->query('SELECT username, lat, lng FROM '.$db->prefix.'users WHERE id>1 AND group_id!='.PUN_UNVERIFIED) or error('Unable to fetch user locations', __FILE__, __LINE__, $db->error());
while ($udata = $db->fetch_assoc($result)) {
    $nama = $udata['username'];
    $lat = empty($udata['lat']) ? '-7.4103038335291105' : $udata['lat'];
    $lon = empty($udata['lng']) ? '109.24630353125008' : $udata['lng'];

    echo ("addMarker($lat, $lon, 'Lokasi : $nama<br/>Latitude : $lat<br/>Longitude : $lon');\n");
}
?>
          
        // Proses membuat marker 
        function addMarker(lat, lng, info) {
            var lokasi = new google.maps.LatLng(lat, lng);
            bounds.extend(lokasi);
            var marker = new google.maps.Marker({
                map: map,
                position: lokasi
            });       
            map.fitBounds(bounds);
            bindInfoWindow(marker, map, infoWindow, info);
         }
        
        // Menampilkan informasi pada masing-masing marker yang diklik
        function bindInfoWindow(marker, map, infoWindow, html) {
          google.maps.event.addListener(marker, 'click', function() {
            infoWindow.setContent(html);
            infoWindow.open(map, marker);
          });
        }
 
        }
      google.maps.event.addDomListener(window, 'load', initialize);
   </script>
		<form id="userlist" method="get" action="userlist.php">
			<div class="inform">
				<fieldset>
					<legend><?php echo $lang_ul['User find legend'] ?></legend>
					<div class="infldset">
<?php if ($pun_user['g_search_users'] == '1'): ?>						<label class="conl"><?php echo $lang_common['Username'] ?><br /><input type="text" name="username" value="<?php echo pun_htmlspecialchars($username) ?>" size="25" maxlength="25" /><br /></label>
<?php endif; ?>						<label class="conl"><?php echo $lang_ul['User group']."\n" ?>
						<br /><select name="show_group">
							<option value="-1"<?php if ($show_group == -1) echo ' selected="selected"' ?>><?php echo $lang_ul['All users'] ?></option>
<?php

$result = $db->query('SELECT g_id, g_title FROM '.$db->prefix.'groups WHERE g_id!='.PUN_GUEST.' ORDER BY g_id') or error('Unable to fetch user group list', __FILE__, __LINE__, $db->error());

while ($cur_group = $db->fetch_assoc($result))
{
	if ($cur_group['g_id'] == $show_group)
		echo "\t\t\t\t\t\t\t".'<option value="'.$cur_group['g_id'].'" selected="selected">'.pun_htmlspecialchars($cur_group['g_title']).'</option>'."\n";
	else
		echo "\t\t\t\t\t\t\t".'<option value="'.$cur_group['g_id'].'">'.pun_htmlspecialchars($cur_group['g_title']).'</option>'."\n";
}

?>
						</select>
						<br /></label>
						<label class="conl"><?php echo $lang_search['Sort by']."\n" ?>
						<br /><select name="sort_by">
							<option value="username"<?php if ($sort_by == 'username') echo ' selected="selected"' ?>><?php echo $lang_common['Username'] ?></option>
							<option value="registered"<?php if ($sort_by == 'registered') echo ' selected="selected"' ?>><?php echo $lang_common['Registered'] ?></option>
<?php if ($show_post_count): ?>							<option value="num_posts"<?php if ($sort_by == 'num_posts') echo ' selected="selected"' ?>><?php echo $lang_ul['No of posts'] ?></option>
<?php endif; ?>						</select>
						<br /></label>
						<label class="conl"><?php echo $lang_search['Sort order']."\n" ?>
						<br /><select name="sort_dir">
							<option value="ASC"<?php if ($sort_dir == 'ASC') echo ' selected="selected"' ?>><?php echo $lang_search['Ascending'] ?></option>
							<option value="DESC"<?php if ($sort_dir == 'DESC') echo ' selected="selected"' ?>><?php echo $lang_search['Descending'] ?></option>
						</select>
						<br /></label>
						<p class="clearb"><?php echo ($pun_user['g_search_users'] == '1' ? $lang_ul['User search info'].' ' : '').$lang_ul['User sort info']; ?></p>
					</div>
				</fieldset>
			</div>
			<p class="buttons"><input type="submit" name="search" value="<?php echo $lang_common['Submit'] ?>" accesskey="s" /></p>
		</form>
	</div>
</div>

<div class="linkst">
	<div class="inbox">
		<p class="pagelink"><?php echo $paging_links ?></p>
		<div class="clearer"></div>
	</div>
</div>

<div id="users1" class="blocktable">
	<h2><span><?php echo $lang_common['User list'] ?></span></h2>
	<div class="box">
		<div class="inbox">
			<table>
			<thead>
				<tr>
					<th class="tc_avatar" scope="col"></th>
					<th class="tcl" scope="col"><?php echo $lang_common['Username'] ?></th>
					<th class="tc2" scope="col"><?php echo $lang_common['Title'] ?></th>
<?php if ($show_post_count): ?>					<th class="tc3" scope="col"><?php echo $lang_common['Posts'] ?></th>
<?php endif; ?>					<th class="tcr" scope="col"><?php echo $lang_common['Registered'] ?></th>
				</tr>
			</thead>
			<tbody>
<?php

// Retrieve a list of user IDs, LIMIT is (really) expensive so we only fetch the IDs here then later fetch the remaining data
$result = $db->query('SELECT u.id FROM '.$db->prefix.'users AS u WHERE u.id>1 AND u.group_id!='.PUN_UNVERIFIED.(!empty($where_sql) ? ' AND '.implode(' AND ', $where_sql) : '').' ORDER BY '.$sort_by.' '.$sort_dir.', u.id ASC LIMIT '.$start_from.', 50') or error('Unable to fetch user IDs', __FILE__, __LINE__, $db->error());

if ($db->num_rows($result))
{
	$user_ids = array();
	for ($i = 0;$cur_user_id = $db->result($result, $i);$i++)
		$user_ids[] = $cur_user_id;

	// Grab the users
	$result = $db->query('SELECT u.id, u.username, u.lat, u.lng, u.title, u.num_posts, u.registered, g.g_id, g.g_user_title FROM '.$db->prefix.'users AS u LEFT JOIN '.$db->prefix.'groups AS g ON g.g_id=u.group_id WHERE u.id IN('.implode(',', $user_ids).') ORDER BY '.$sort_by.' '.$sort_dir.', u.id ASC') or error('Unable to fetch user list', __FILE__, __LINE__, $db->error());

	while ($user_data = $db->fetch_assoc($result))
	{
		 		
		$user_title_field = get_title($user_data);

		// Retrieve the id for the avatar (and their respective poster/online status)
		if ($pun_config['o_avatars'] == '1' && $pun_user['show_avatars'] != '0')
		{
			if ($img_size = @getimagesize($pun_config['o_avatars_dir'].'/'.$user_data['id'].'.gif'))
				$user_avatar = '<img src="'.$pun_config['o_avatars_dir'].'/'.$user_data['id'].'.gif" class="maxavatar" alt="" />';
			else if ($img_size = @getimagesize($pun_config['o_avatars_dir'].'/'.$user_data['id'].'.jpg'))
				$user_avatar = '<img src="'.$pun_config['o_avatars_dir'].'/'.$user_data['id'].'.jpg" class="maxavatar" alt="" />';
			else if ($img_size = @getimagesize($pun_config['o_avatars_dir'].'/'.$user_data['id'].'.png'))
				$user_avatar = '<img src="'.$pun_config['o_avatars_dir'].'/'.$user_data['id'].'.png" class="maxavatar" alt="" />';
			else
				$user_avatar = '<img src="'.$pun_config['o_avatars_dir'].'/avatar_defaut.gif" class="maxavatar" alt="" />';						 
		}
		else
			$user_avatar = '';

?>
				<tr>
					<td class="tc7"><?php echo $user_avatar ?></td>
					<td class="tcl"><div class="tclcon"><?php echo '<a href="profile.php?id='.$user_data['id'].'">'.pun_htmlspecialchars($user_data['username']).'</a>' ?></td></div>

					<td class="tc2"><?php echo $user_title_field ?></td>
<?php if ($show_post_count): ?>					<td class="tc3"><?php echo forum_number_format($user_data['num_posts']) ?></td>
<?php endif; ?>
					<td class="tcr"><?php echo format_time($user_data['registered'], true) ?></td>
				</tr>
<?php

	}
}
else
	echo "\t\t\t".'<tr>'."\n\t\t\t\t\t".'<td class="tcl" colspan="'.(($show_post_count) ? 4 : 3).'">'.$lang_search['No hits'].'</td></tr>'."\n";

?>
			</tbody>
			</table>
		</div>
	</div>
</div>

<div class="linksb">
	<div class="inbox">
		<p class="pagelink"><?php echo $paging_links ?></p>
		<div class="clearer"></div>
	</div>
</div>

<?php

require PUN_ROOT.'footer.php';

Can you give me more advice or guidance?  hmm

Offline

#6 2017-03-04 16:26:50

gandi
Участник
Зарегистрирован: 2017-03-04
Сообщений: 19

Re: Add map for users location on userlist.php

I want the result would be like this suaraguru.com/alluser-location/semua.php. And merge it on userlist.php.

Offline

#7 2017-03-04 17:42:14

Visman
Administrator
Из Сибирь
Зарегистрирован: 2009-06-08
Сообщений: 2,236
Сайт

Re: Add map for users location on userlist.php

The error of the database remained?
If yes, add to config.php this line

define('PUN_DEBUG', 1);

and show the complete text of an error.

If not, then it is possible at you javascript error in the browser.

Offline

#8 2017-03-05 03:08:01

gandi
Участник
Зарегистрирован: 2017-03-04
Сообщений: 19

Re: Add map for users location on userlist.php

No, the error doesn't remained. But it doesn't fetch data from all user. Its only give me result from one user. However the map need all user data to displayed together in one map.

Offline

#9 2017-03-05 06:26:26

Visman
Administrator
Из Сибирь
Зарегистрирован: 2009-06-08
Сообщений: 2,236
Сайт

Re: Add map for users location on userlist.php

@gandi, This user is guilty -> Anam ma'ruff smile
replace

$nama = $udata['username'];

to

$nama = addcslashes($udata['username'], '\\\'');

Offline

#10 2017-03-05 06:31:37

Visman
Administrator
Из Сибирь
Зарегистрирован: 2009-06-08
Сообщений: 2,236
Сайт

Re: Add map for users location on userlist.php

And it is better to replace

$nama = pun_htmlspecialchars($udata['username']);

Offline

  • Нравится: 1

#11 2017-03-05 07:31:55

gandi
Участник
Зарегистрирован: 2017-03-04
Сообщений: 19

Re: Add map for users location on userlist.php

I had tried to use pun_htmlspecialchars before asking this question here. But my $db->query('SELECT still incorrect. That's why I'm getting db error, it was my own mistake.  big_smile
But now, its working perfectly. Thanks Mr. Visman.

Offline

#12 2017-03-13 05:09:11

gandi
Участник
Зарегистрирован: 2017-03-04
Сообщений: 19

Re: Add map for users location on userlist.php

I have one more question Mr.Visman. How to make the map only showing user location from current userlist? I mean when I select one group_id, the map will showing only locations from user on that group_id. Or when I insert username, the map only show location from that username.

Offline

#13 2017-03-13 05:25:46

Visman
Administrator
Из Сибирь
Зарегистрирован: 2009-06-08
Сообщений: 2,236
Сайт

Re: Add map for users location on userlist.php

$result = $db->query('SELECT u.username, u.lat, u.lng FROM '.$db->prefix.'users AS u WHERE u.id>1 AND u.group_id!='.PUN_UNVERIFIED.(!empty($where_sql) ? ' AND '.implode(' AND ', $where_sql) : '')) or error('Unable to fetch user locations', __FILE__, __LINE__, $db->error());

Offline

#14 2017-03-13 05:59:22

gandi
Участник
Зарегистрирован: 2017-03-04
Сообщений: 19

Re: Add map for users location on userlist.php

Visman пишет:
$result = $db->query('SELECT u.username, u.lat, u.lng FROM '.$db->prefix.'users AS u WHERE u.id>1 AND u.group_id!='.PUN_UNVERIFIED.(!empty($where_sql) ? ' AND '.implode(' AND ', $where_sql) : '')) or error('Unable to fetch user locations', __FILE__, __LINE__, $db->error());

But it dosn't show user location. Please check it using username: testuser password: password

Offline

#15 2017-03-13 10:16:21

Visman
Administrator
Из Сибирь
Зарегистрирован: 2009-06-08
Сообщений: 2,236
Сайт

Re: Add map for users location on userlist.php

Filter works.
Moderators

http://www.suaraguru.com/userlist.php?username=&show_group=2&sort_by=username&sort_dir=ASC&search=Submit

4 people

...
        // Pengambilan data dari database
       addMarker(-7.4103038335291105, 109.24630353125008, 'Lokasi : <br/>Latitude : -7.4103038335291105<br/>Longitude : 109.24630353125008');
addMarker(-7.4103038335291105, 109.24630353125008, 'Lokasi : <br/>Latitude : -7.4103038335291105<br/>Longitude : 109.24630353125008');
addMarker(-7.4103038335291105, 109.24630353125008, 'Lokasi : <br/>Latitude : -7.4103038335291105<br/>Longitude : 109.24630353125008');
addMarker(-7.4103038335291105, 109.24630353125008, 'Lokasi : <br/>Latitude : -7.4103038335291105<br/>Longitude : 109.24630353125008');
          
        // Proses membuat marker 
...

But all the coordinates are the same

    $lat = empty($udata['lat']) ? '-7.4103038335291105' : $udata['lat'];
    $lon = empty($udata['lng']) ? '109.24630353125008' : $udata['lng'];

Probably you have empty columns in the database

Offline

#16 2017-03-13 10:19:24

Visman
Administrator
Из Сибирь
Зарегистрирован: 2009-06-08
Сообщений: 2,236
Сайт

Re: Add map for users location on userlist.php

And check your page with the validator https://validator.w3.org/#validate_by_input
The page has many markup errors.

Offline

  • Нравится: 1

#17 2017-03-16 04:22:51

gandi
Участник
Зарегистрирован: 2017-03-04
Сообщений: 19

Re: Add map for users location on userlist.php

Visman пишет:

And check your page with the validator https://validator.w3.org/#validate_by_input
The page has many markup errors.

I don't realy understand about this problem. I tought that I don't type wrong character. How could this happen? roll

Редактировался gandi (2017-03-16 04:50:25)

Offline

#18 2018-07-25 07:06:56

gandi
Участник
Зарегистрирован: 2017-03-04
Сообщений: 19

Re: Add map for users location on userlist.php

Hi Mr Visman,, can you give me your contact or email addres?
I have some question out off fluxbb topic

Offline

#19 2018-07-25 10:03:01

Visman
Administrator
Из Сибирь
Зарегистрирован: 2009-06-08
Сообщений: 2,236
Сайт

Re: Add map for users location on userlist.php

or email addres?

visman(а)inbox(dot)ru

Offline

Подвал доски

Под управлением FluxBB. Хостинг Hostens