<?
/*
실험주소
http://www.owllab.com/ios/login_proc.php
*/

header("Cache-Control: no-cache, must-revalidate");
header("Content-type: application/xml; charset=UTF-8");

include_once ("session.php");
include_once ("dbcon_light.php");

$usert = "user_demo";
$result = -1;
$msg = "죄송합니다.\n시스템장애로 작업을 취소했습니다.\n나중에 다시 시도해 주세요.";

if ($mode=="logout") {
	$result = 1;
	$msg = "로그아웃했습니다.";
	$suserdb = array();
	$suserdb[userid] = "";
	$suserdb[userlevel] = -1;
} else {
	$sql = " select * from $usert where userid='$userid' ";
	$rs = mysql_select_list($sql);
	if ($rs[userid][0]!=$userid || strlen($userid)==0) {
			$result = -1;
			$msg = "인증실패!!\n아이디가 올바르지 않습니다.";
	} else if ($rs[passwd][0]!=md5($passwd)) {
			$result = -2;
			$msg = "인증실패!!\n암호가 올바르지 않습니다.";
	} else if ($rs[userlevel][0]<0) {
			$result = -3;
			$msg = "죄송합니다.\n접근이 제한된 계정입니다.\n시스템 관리자에게 문의하세요.";
	} else {
		$result = 1;
		$msg = "로그인했습니다.";
		$suserdb[userid] = $rs[userid][0];
		$suserdb[userlevel] = $rs[userlevel][0];
		$suserdb[alias] = $rs[alias][0];
	}//if
}// mode

if ($result<=0) {
	$suserdb = array();
	$suserdb[userid] = "";
	$suserdb[userlevel] = -1;
	$rs = array();
}

if ($result==1) {
	if ($suserdb[userlevel] < 0) $_cookieLifeTime = -100;
	setcookie ("suserdb.addhint", "", time() + $_cookieLifeTime, "/", $_SERVER["HTTP_HOST"]);
	setcookie ("suserdb.userid", $suserdb[userid], time() + $_cookieLifeTime, "/", $_SERVER["HTTP_HOST"]);
	setcookie ("suserdb.userlevel", $suserdb[userlevel], time() + $_cookieLifeTime, "/", $_SERVER["HTTP_HOST"]);
	setcookie ("suserdb.alias", $suserdb[alias], time() + $_cookieLifeTime, "/", $_SERVER["HTTP_HOST"]);
}

?>
<?php echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?".">"; ?>
<lists>
	<info>
		<result><? echo $result;?></result>
		<msg><![CDATA[<? echo $msg;?>]]></msg>
	</info>
	<? $i=0; // for ($i=0;$i<count($rs[rowid]);$i++) { ?>  
	<data>
		<rowid><? echo $rs[rowid][$i];?></rowid>
		<phone><![CDATA[<? echo $rs[phone][$i];?>]]></phone>
		<userid><![CDATA[<? echo $rs[userid][$i];?>]]></userid>
		<name><![CDATA[<? echo $rs[name][$i];?>]]></name>
		<alias><![CDATA[<? echo $rs[alias][$i];?>]]></alias>
		<email><![CDATA[<? echo $rs[email][$i];?>]]></email>
		<postal><![CDATA[<? echo $rs[postal][$i];?>]]></postal>
		<address><![CDATA[<? echo $rs[address][$i];?>]]></address>
		<userlevel><![CDATA[<? echo $rs[userlevel][$i];?>]]></userlevel>
	</data>
	<? // }// for i?>
</lists>

