<?php
// this file needs to be utf8 without BOM. Check accentuated chars : é à è ù
header("content-type: application/xml");
$folder = "";
$not_access = 0;
//includes
require_once('includes.php');

echo '<'.'?xml version="1.0" encoding="UTF-8"?'.'>';
?>
<Module>
<Content><![CDATA[
<head>
</head>
<body>
<div id="searchcontainer__MODULE_ID__" style="float: right;margin-right: 6px;"></div>
<div class="float_correction"></div>
<div id="searchtext__MODULE_ID__" style="margin: 3px 0 0 6px"></div>
<div class="float_correction"></div>
<div id="container__MODULE_ID__" style="padding: 4px;"></div>
</body>
<script>

init__MODULE_ID__=function()
{
	initSearch__MODULE_ID__();
	loadUsers__MODULE_ID__(0);
}
initSearch__MODULE_ID__=function()
{
	var l_s = '<form onsubmit="search__MODULE_ID__(this);return false;">'
		+ '<div class="searchbox" style="float: left;">'
		+ '<input class="searchboxtext" autocomplete="off" id="inputsearchwidget" name="inputsearchwidget" type="text" onFocus=\'$p.app.tools.inputFocus(this,"'+lg("searchModuleByKeywords")+'")\' onBlur=\'$p.app.tools.inputLostFocus(this,"'+lg("searchModuleByKeywords")+'");$p.tags.autocompletion.hide();\' value="'+lg("searchModuleByKeywords")+'" onkeyup=\'$p.tags.autocompletion.get("inputsearchwidget")\' style="color:#aaaaaa;font-size: 0.85em;width:180px;" /> '
		+ '<input type="image" name="buts" class="searchboxbtn" src="../styles/themes/classic_blue/header_menu_searchbtn.png" />'
		+ '</div>'
		+ '</form>';
	
	$p.print('searchcontainer__MODULE_ID__',l_s);
}
search__MODULE_ID__=function(v_form,v_page)
{
	var l_search = v_form.inputsearchwidget.value;
	
	var l_type = ($p.app.tools.checkmail(l_search) ? 'm' : 't');
	
	if (l_type == 't')
		l_search = $p.string.formatForSearch(l_search);
	
	if (v_page == indef) v_page = 0;
	
	if (l_search != '')
	{
		var l_s = lg('searchResultsFor')
			+ ' "' + l_search + '" &nbsp; '
			+ '<a href="#" onclick="loadUsers__MODULE_ID__(0);return false;">'
			+ lg('allUsers')
			+ '</a>';
		$p.print('searchtext__MODULE_ID__',l_s);
		$p.show('searchtext__MODULE_ID__','');
	}

	$p.ajax.call('../portal/' + pep["xmlnetwork_search"] + '?p=' + v_page + '&search=' + $p.string.esc(l_search) + '&type=' + l_type,
		{
			'type':'load',
			'callback':
			{
				'function':displayUsers__MODULE_ID__,
				'variables':
				{
					'search':l_search,
					'page':v_page
				}
			}
		}
	);
}
loadUsers__MODULE_ID__=function(v_page)
{
	$p.print('searchtext__MODULE_ID__','');
	$p.show('searchtext__MODULE_ID__','none');
	
	if ($p.app.user.id == 0)
	{
		$p.print('container__MODULE_ID__', lg('youNeedToConnectToUseThisWidget'));
		return;
	}
	
	$p.ajax.call('../portal/' + pep["xmlnetwork_users"]+'?kwid=0&s='+(v_page*20),
		{
			'type':'load',
			'priority':3,
			'callback':
			{
				'function':displayUsers__MODULE_ID__,
				'variables':{
					'page':v_page
				}
			}
		}
	);
}
displayUsers__MODULE_ID__=function(response, vars)
{
	var l_s = '';

	var result = response.getElementsByTagName("user");

	if (result.length == 0)
	{

		l_s += lg('noResultForThisSearch');
	}
	else
	{
		l_s	+= '<div>'
			+ '<ul class="card-outer">';

		if (0==$p.network.dashboard.filterKw)  {
			$p.network.dashboard.nbUsersInMyNetwork=result.length;
		}

		var l_iter = _min(result.length,20);
		if (l_iter==0) {
			l_s += lg('noResultForThisSearch');
		}
		else {
			for (var i=0;i<l_iter;i++)
			{
				l_id=$p.ajax.getVal(result[i],"id","int",false,0);
				var l_picture=$p.ajax.getVal(result[i],"picture","str",false,"");
				var l_status=$p.ajax.getVal(result[i],"status","str",false,"");
				if (l_picture=="") l_picture="../images/nopicture.gif";

				l_options=[];
				if (l_id != $p.app.user.id && l_status == '') l_options.push($p.img('ico_friend_add.gif',16,16,'','imgmid')+" <a href='#' onclick='$p.network.card.load("+l_id+")'>" + (__NETWORK_TYPE == 'R' ? lg("addInMyNetwork") : lg('followThisPerson')) + " </a>");
				if (l_status == 'I')
				{
					l_options.push($p.img('ico_accept.gif',16,16,'','imgmid')+" <a href='#' style='color: #000' onclick='$p.network.dashboard.acceptInvitation("+l_id+",\"loadUsers__MODULE_ID__(0)\");return false;'>" + lg('acceptInvitation') + "</a>");
					l_options.push($p.img('ico_stop.gif',16,16,'','imgmid')+" <a href='#' style='color: #000' onclick='$p.network.dashboard.rejectInvitation("+l_id+",\"loadUsers__MODULE_ID__(0)\");return false;'>" + lg('reject') + "</a>");
				}
				else
				{
					l_options.push("<a href='#' style='color: #000' onclick='return $p.network.suppress("+l_id+")'>" + (__NETWORK_TYPE == 'R' ? lg("suppressFromMyNetwork") : lg('stopFollowing')) + "</a>");
				}
				// if($p.app.user.id != l_id) {
					// l_options.push($p.img('ico_group_add.gif',16,16,'','imgmid')+" <a style='color: #000' onclick='$p.group.card.load("+l_id+", "+$p.app.user.id+")' href='#'>"+lg("addInMyGroups")+"</a>");
				// }
				
				l_s += buildElement__MODULE_ID__(l_id,l_picture,$p.ajax.getVal(result[i],"longname","str",false,"..."),$p.ajax.getVal(result[i],"email","str",false,"..."),$p.ajax.getVal(result[i],"stat","str",false,"")+' -'+$p.date.formatDelai($p.date.delayFromNow($p.date.convertFromDb($p.ajax.getVal(result[i],"statdate","str",false,"")))),$p.ajax.getVal(result[i],"description","str",false,""),$p.ajax.getVal(result[i],"keywords","str",false,""),l_options,indef,$p.chat.computeActivity($p.ajax.getVal(result[i],'activity','str',false,''),$p.ajax.getVal(result[i],'lastconndate','str',false,''),$p.ajax.getVal(result[i],'dbdate','str',false,'')));
			}
		}

		l_s+= '</ul>'
			+ '</div>'
			+ '<div style="clear: both;float: none;"></div>';
	}
	//page results management
	var l_page = vars['page'] == indef ? 0 : vars['page'].toInt();
	if (l_page > 0 || result.length > 20) {
		l_s+=$p.html.buildPageNavigator('previous',(l_page==0 ? '' : "loadUsers__MODULE_ID__("+(l_page-1)+")"),lg("page")+" "+(l_page+1),'next',(result.length>20 ? "loadUsers__MODULE_ID__("+(l_page+1)+")" : ''));
	}

	$p.print('container__MODULE_ID__',l_s);
	return false;
}
buildElement__MODULE_ID__ = function(v_id,v_img,v_name,v_email,v_status,v_description,v_keywords,v_options,v_isCreator,v_activity)
{
	var l_options = [],
		l_s = '<li id="card_'+v_id+'">'
			+ '<div class="card-inner" style="padding:0;margin:0;">'
			+ '<div class="card-content">'
			+ '<table cellpadding="8">'
			+ '<tr>'
			+ '<td valign="top" width="35">'
			+ '<a href="#" onclick="$p.network.card.load('+v_id+')">'
			+ '<div class="picture_image_medium">'
			+ '<img src="'+v_img+'" />'
			+ '</div>'
			+ '<div class="picture_frame_white_medium"> </div>'
			+ '</td>'
			+ '<td valign="top">';

	if (v_isCreator != indef && v_isCreator == true) 
	{
		l_s += '<div class="card-bar-creator">'
			+ '<b>'+lg("manager")+'</b>'
			+ '&nbsp;-&nbsp;';
	}
	else
	{
		l_s += '<div class="card-bar">';
	}

	l_s += '<b>'
		+ '<a href="#" onclick="$p.network.card.load('+v_id+')">'
		+ v_name
		+ '</a>';
		if (__useChat && (v_activity == 'o' || v_activity == 'a' || v_activity == 'b') && v_id != $p.app.user.id)
		{
			l_s += '&nbsp;' + $p.img("ico_activityround"+v_activity+".gif",18,18,lg('activity'+v_activity),"imgmid");
		}
		l_s += '</b>';

	//l_s+=$p.network.dashboard.displayNotInNetwork(inhisnetwork);

	l_s += '</div>';
	
	if (checkEmail(v_email) && __EMAIL_ADRESS_ARE_SHOWN)
		l_options.push(' <a style="color: #000" href="mailto:'+v_email+'" title="'+v_email+'" >'+$p.img('ico_mymessages.gif',16,11,'','imgmid')+' ' + lg('contact') + '</a>');

	if (__useNotebook)
	{
		l_options.push($p.img("ico_notebook.gif",16,16,lg("seeHisNotebook"),"imgmid")
			+ ' <a href="#" style="color: #000" onclick=\'$p.notebook.open('+v_id+',"note","'+v_name+'",indef,indef,"'+v_img+'")\'>'
			+ lg("seehisprofil")
			+ '</a>');
	}
	if (__useChat && (v_activity == 'o' || v_activity == 'a') && v_id != $p.app.user.id)
	{
		l_options.push($p.img("ico_chat.gif",16,16,'',"imgmid")
			+ '<a href="#" style="color: #000" onclick=\'$p.chat.discussion.open(0,'+v_id+',"'+v_name+'","'+v_img+'");\'> '
			+ lg("chat")+'</a>');
	}
	for (var i = 0;i < v_options.length;i ++)
	{
		l_options.push(v_options[i]);
	}
	
	l_s += l_options.join(' | ')
		+ '</td>'
		+ '</tr>'
		+ '</table>'
		+ '<div class="float_correction"></div>'
		+ '</div>'
		+ '</div>'
		+ '</li>';

	return l_s;
}
init__MODULE_ID__();
</script>

]]></Content>
</Module>