<?php
defined('IN_PHPCMS') or exit('No permission resources.'); 

$username = isset($_GET['username']) && trim($_GET['username']) ? trim($_GET['username']) : exit('-1');
$password = isset($_GET['password']) && trim($_GET['password']) ? trim($_GET['password']) : exit('-1');
$url = isset($_GET['url']) && trim($_GET['url']) ? trim(urldecode($_GET['url'])) : exit('-1');
$name = isset($_GET['name']) && trim($_GET['name']) ? trim($_GET['name']) : exit('-1');
$authkey = isset($_GET['authkey']) && trim($_GET['authkey']) ? trim($_GET['authkey']) : exit('-1');
$apifilename = isset($_GET['apifilename']) && trim($_GET['apifilename']) ? trim($_GET['apifilename']) : exit('-1');
$charset = isset($_GET['charset']) && trim($_GET['charset']) ? trim($_GET['charset']) : exit('-1');
$type = isset($_GET['type']) && trim($_GET['type']) ? trim($_GET['type']) : 'other';
$synlogin = isset($_GET['synlogin']) && trim($_GET['synlogin']) ? trim($_GET['synlogin']) : '1';


$db = pc_base::load_model('admin_model');
$memberinfo = $db->get_one(array('username'=>$username));
if(!empty($memberinfo)) {
	if(md5(md5($password).$memberinfo['encrypt']) == $memberinfo['password']) {
		$appdb = pc_base::load_model('applications_model');
		$appdata['authkey'] = $authkey;
		$appdata['apifilename'] = $apifilename;
		$appdata['charset'] = $charset;
		$appdata['type'] = $type;
		$appdata['synlogin'] = $synlogin;
		$appdata['url'] = $url;
		$appdata['name'] = $name;
	
		$appid = $appdb->insert($appdata, 1);
		
		if($appid > 0) {
			$applist = $appdb->listinfo('', '', 1, 100, 'appid');
			setcache('applist', $applist, 'admin');
			echo $appid;exit;
		} else {
			exit('-3');
		}
	} else {
		exit('-2');
	}
} else {
	exit('-2');
}
?>