<?php
@set_time_limit(3600);
define('IN_INSTALL', true);
define('DS', DIRECTORY_SEPARATOR);
define('INSTALL_DIR',dirname(__FILE__).DS);//当前文件路径
define('INSTALL_DATA',INSTALL_DIR.'data'.DS);//安装数据目录
define('WEB_DIR',dirname(INSTALL_DIR).DS);
define('LIBRARY',WEB_DIR.'library'.DS);//library目录

//后台相关目录定义
define('ADMIN_CONF', WEB_DIR.'admin'.DS.'application'.DS.'config'.DS);
define('LIB_CLASS', WEB_DIR.'library'.DS.'mainone'.DS.'classes'.DS);//框架服务类目录
header('Content-Type: text/html; charset=utf-8');
define('SITE_PROTOCOL', isset($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] == '443' ? 'https://' : 'http://');
define('HOST_NAME',SITE_PROTOCOL.(isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'].'/' : ''));
define('URL_RES',HOST_NAME.'tpl_install/res/');


//连接数据库
function connectDb ($data)
{
	mysql_connect($data['hostname'],$data['username'],$data['password']);
	$res = mysql_select_db($data['dbname']);
	mysql_query('set names utf8');
	return $res;
}

//获取数据库配置
function getDbConf ($db_conf)
{
	if(is_file($db_conf))
	{
		$db_conf = include($db_conf);
		return isset($db_conf['default']) ? $db_conf['default'] : array();//数据库一维数组 配置
	}
	else
	{
		return array();
	}
}

/**
 * 生成一个目录下唯一的目录名
 * @param
 * @return
 */
function createFolderName ($name,$path)
{
	$folder = $path.$name;
	if(is_dir($folder))
	{
		$name = $name.time('YmdHis');
		createFolderName($name,$path);
	}
	return $name;
}

//设置php数组缓存数据
function setCacheData ($file,$data)
{
	file_put_contents($file,"<?php return \n ".var_export($data,true).";\n?>");
}