<?php

/**********************************************************
* show error information
**********************************************************/
function show_error($errinfo,$title)
{
	?>
	<div style="margin-top:100px;margin-left:100px;border:2px solid #65a4d7;width:500px">
		<table style="width:500px;word-break:break-all;word-wrap:break-word;">
			<tr>
				<td align="right" width=45%> <img src="images/error.gif"> </td> <td colspan="2" style="font-size:20px;font-weight:bold"><?php echo $title; ?></td>
			</tr>
			<tr bgcolor=#dddddd>
				<td colspan="3"><?php echo $errinfo ?> </td>
			</tr>
		</table>

	</div>
	<?php
}


/********************************************************
* operation success
*********************************************************/
function show_done($doneinfo,$title)
{
	?>	
	<div style="margin-top:100px;margin-left:100px;border:0px solid #65a4d7;width:500px;overflow-y:auto;height:360px;">
		<table style="width:500px;table-layout:fixed;word-break:break-all;word-wrap:break-word;border:2px solid #65a4d7;">
			<tr>
				<td align="right" width=45%> <img src="images/done.gif"> </td> <td colspan="2" style="font-size:20px;font-weight:bold"><?php echo $title; ?></td>
			</tr>
			<tr bgcolor=#dddddd>
				<td colspan="3"><?php echo $doneinfo ?> </td>
			</tr>
		</table>
	</div>
	<?php
}

/*******************************************************
/* Authentication  operation
/* return:1--succeed others--failed (0--unknown token type -1--authenticate failed)
/*************************************************/
function UniMate_Authentiation($uni_authpass, $uni_type, $uni_rand, $uni_credential, $uni_id, $uni_db)
{
	if(3 == $uni_type)//challenge-response
	{
		if($uni_authpass == md5($uni_credential.$uni_rand)) 
		{
			$sql = "update UniMateToken_UserInfo set rand=".rand(0,10000)." where RecordID='".$uni_id."'";
			if(!($result=$uni_db->query($sql)))
			{
				return -3;//update rand failed
			}
			return 1;
		}
		else
		{
			return -1;
		}
	}
	else
	{
		return 0;
	}
}
?>