<?php  



if (isset($_POST['GroupSaveSettingName'])&&isset($_POST['FileData'])) {
	CreateGroupSaveSettingFile($_POST['GroupSaveSettingName'],$_POST['FileData']);
}
elseif (isset($_POST['ReadGroupSaveSettingName'])){
	ReadingGroupSaveSettingFile($_POST['ReadGroupSaveSettingName']);
}
elseif(isset($_POST['ReadingSettingFile'])){
	ReadingDeviceSettingInformation();
}
elseif(isset($_POST['DelectSettingFile'])){
	DelectGroupSaveSettingFile($_POST['DelectSettingFile']);
}
elseif (isset($_POST['CheckFileExist'])) {
	if (file_exists('../GroupSaveSetting/'.$_POST['CheckFileExist'].'.txt')) {
		echo "1";
	}
	else{
		echo "0";
	}
}

function DelectGroupSaveSettingFile($path){
	$fp = fopen('../GroupSaveSetting/'.$path.'.txt', 'w+b');
	$_data='';
	if (!$fp) {
		# code...
		return 'err';
	}
	fwrite($fp,$_data,strlen($_data));
	fclose($fp);
	//unlink($path);
}
// 保存组别里的设备设置
function CreateGroupSaveSettingFile($_name,$_data){
	$fp = fopen('../GroupSaveSetting/'.$_name.'.txt', 'w+b');
	fwrite($fp,$_data,strlen($_data));
	fclose($fp);
}

// 读取组别里的设备设置
function ReadingGroupSaveSettingFile($_name){
	$fp = fopen('../GroupSaveSetting/'.$_name.'.txt', 'rb');
	// while (!feof($fp)) {
	// 	$data = fread($fp,999);
	// }
	$_data='';
	do{
		$data=fread($fp,100);
		$_data.=$data;
	}while($data!='');
	
	echo $_data;
	fclose($fp);
}
// 读取所有设备设置信息
function ReadingDeviceSettingInformation(){
	//扫描文件夹
	$_dataTmp ='';
	$file = scandir('../GroupSaveSetting');
	//显示
	foreach ($file as $key => $value) {
		if ($value!='.'&&$value!='..') {
			echo ReadSettingFile($value).'=';
		}	
	}
	//echo $_dataTmp;
}
function ReadSettingFile($_name){
	$fp = fopen('../GroupSaveSetting/'.$_name, 'rb');
	// while (!feof($fp)) {
	// 	$data = fread($fp,999);
	// }
	$_data='';
	do{
		$data=fread($fp,100);
		$_data.=$data;
	}while($data!='');
	echo $_data;
	fclose($fp);

	
	
}
?>