<?php
// Adaptado por Juliano Frasson para integracao CSPADM - CSP
// <user-manager class="com.bowman.cardserv.XmlUserManager" allow-on-failure="true" log-failures="true" >
// <auth-config>
// <update-interval>3</update-interval>
// <user-source name="SKY">
//    <user-file-url>http://localhost/csp/genxml2a.php?idempresa=1</user-file-url>
// </user-source>
// </auth-config>
// </user-manager>


// Edit this 4 strings to match your system
include('conexao.php');
$sql = "select csp_user.name, csp_user.password, csp_user.displayname, profile.descricao as profile, csp_user.maxconnections, csp_user.enabled, csp_user.expiredate from csp_user, profile, usuario where csp_user.idprofile = profile.idprofile and csp_user.idrevendedor = usuario.idusuario and csp_user.situacao=1";
if (isset($key)){
	$sql .=" and usuario.kkey='$key'";	
}
$exe=mysql_query($sql);
//$sql = mysql_db_query($db,"select csp_user.name, csp_user.password, csp_user.displayname, profile.descricao as profile, csp_user.maxconnections, csp_user.enabled, csp_user.expiredate from csp_user, profile, usuario where csp_user.idprofile = profile.idprofile and csp_user.idrevendedor = usuario.idusuario and csp_user.situacao=1");

echo "<xml-user-manager ver=\"1.0\">\n";
while($line=mysql_fetch_array($exe)){
	$val_name=$line[name];
	$val_password=$line[password];
	$val_displayname=$line[displayname];
	$val_profile=$line[profile];
	$val_maxconnections=$line[maxconnections];
	$val_enabled=$line[enabled];
	$val_expiredate=$line[expiredate];

	if ($val_name == ""){
		$name = "";
	} else {
		$name = "name=\"".$val_name."\" ";
	}
	
	if ($val_password == "") {
		$password = "";
	} else {
		$password = "password=\"".$val_password."\" ";
	}
	
	if ($val_displayname == "") {
		$displayname = "";
	} else {
		$displayname = "display-name=\"".$val_displayname."\" ";
	}
	
	if ($val_profile == "") {
		$profiles = "";
	} else {
		$profiles = "profiles=\"".$val_profile."\" ";
	}
	
	if ($val_maxconnections == "") {
		$maxconnections = "";
	} else {
		$maxconnections = "max-connections=\"".$val_maxconnections."\" ";
	}
	
	if ($val_enabled == "") {
		$enabled = "";
	} else {
		if ($val_expiredate > "" && $val_expiredate < date("d-m-Y")) {
			$enabled = "enabled=\"false\" "; 
		} else {
			if ($val_expiredate == "") {
				$enabled = "enabled=\"".$val_enabled."\" ";
			} else {
				$enabled = "enabled=\"".$val_enabled."\" ";
			}
		}
	}
	
	echo "<user ".$name.$password.$displayname.$profiles.$maxconnections.$enabled."/>\n";
}
echo "</xml-user-manager>";

?>
