<?php
define('CURSCRIPT','file_manage');

require dirname(__FILE__)."/global.php";
require MYMPS_DATA."/config.inc.php";
require MYMPS_INC."/db.class.php";

if($admin_cityid) write_msg('您没有权限访问该页！');

$part = $part ? $part : 'template' ;
write_msg("为了您的服务器安全考虑，该功能暂停开放使用");
exit;

if($downfile) {
	!is_file($downfile) && write_msg("您要下载的文件不存在！");
	FileExt($downfile) == 'php' && write_msg("该文件不允许下载!");
	$filename = basename($downfile);
	$filename_info = explode('.', $filename);
	$fileext = $filename_info[count($filename_info)-1];
	header('Content-type: application/x-'.$fileext);
	header('Content-Disposition: attachment; filename='.$filename);
	header('Content-Description: PHP3 Generated Data');
	readfile($downfile);
	exit;
}

/*if($delfile!=""){
	$part == 'template' && write_msg("模板文件不能删除，请手动在FTP目录中将其删除！");
	(FileExt($delfile) == 'php' || FileExt($delfile) == 'css' || FileExt($delfile) == 'js' || FileExt($delfile) == 'html') && write_msg("该文件不允许删除，请在FTP目录中手动删除！");
	if(file_exists($delfile)) {
		@unlink($delfile);
		$msgs[]="成功删除文件<br /><br />".$delfile;
		$msgs[]="<a href=\"".$url."\">点此返回 &raquo;</a>";
		show_msg($msgs);
	} else {
		write_msg("文件已不存在！");
	}
	exit;
}*/

$cfg_if_tpledit = ($mymps_mymps['cfg_if_tpledit'] == 0) ? "<font color=green>已关闭</font>" : "<font color=red>已开启</font>";

switch ($part){
	case 'template':
		!chk_adm_purview("purview_模板管理")&& write_msg("很抱歉，您所在会员组没有当前菜单的操作权限！");
		$here = "模板在线管理";
		$mulu = "Mymps模板目录";
		$showdir= MYMPS_TPL.'/default';
		
		if ($editfile && $do=='update'){
			
			if($mymps_mymps['cfg_if_tpledit']=='0'){
				write_msg("操作失败！系统管理员关闭了在线编辑风格的功能!<br /><br />您可以修改/dat/config.inc.php来开启它");
			}
			
			$content=str_replace('&amp;','&',trim($content));
			$content=str_replace('&quot;','"',trim($content));
			$nowfile = trim($editfile);
			
			if(!is_file($nowfile)){
				write_msg("对不起，该文件不存在！");
			}
			
			$norootfile = str_replace(MYMPS_ROOT."/template",'',$nowfile);
			
			if($db->getOne("SELECT content FROM `{$db_mymps}template` WHERE filepath LIKE '$norootfile'")){
				$update_sql=$db->query("UPDATE `{$db_mymps}template` SET content = '$content' WHERE filepath = '$norootfile'");
			}else{
				$db->query("INSERT INTO `{$db_mymps}template` (filepath,content) VALUES ('$norootfile','$content')");
			}

			$row=$db->getRow("SELECT filepath,content FROM `{$db_mymps}template` WHERE filepath = '$norootfile'");
			if(!$row){write_msg("操作失败！");exit();}
			$create_c = createfile($nowfile,$row[content]);
			if($create_c){
				write_msg("模板文件".$nowfile."<br /><br />修改成功",$url,"MyMps");
			}else{
				write_msg("模板文件".$nowfile."无法修改<br /><br />请检查template目录的操作权限!");
			}
			
		} elseif ($editfile&&empty($do)){
		
			$ext = FileExt($editfile);
			
			if($ext!="html" && $ext!="css" && $ext!="htm" && $ext!="js"){
				write_msg("该文件不能在线编辑!");
			}
			
			if(!$edit = file_get_contents($editfile)){
				write_msg("该文件不可读，请检查该文件的操作权限");
			}
			$patha = explode("/",$editfile);
			$path1= "/".end($patha);
			$path = @str_replace($path1,"",$editfile);
			$edit = htmlspecialchars($edit);
			$acontent = "<textarea name=\"content\" cols=\"110\" rows=\"25\">".$edit."</textarea>";
			include(mayi_tpl("template_edit"));
			exit();
			
		}
	break;
	case 'upload':
	
		!chk_adm_purview("purview_附件管理")&& write_msg("很抱歉，您所在会员组没有当前菜单的操作权限！");
		$here = "系统上传附件管理";
		$mulu = "系统附件目录";
		$showdir= MYMPS_UPLOAD;
		
	break;
}

$path	   = trim($path) ? trim($path) : $showdir;
if(!@strstr($path,'/attachment') && !@strstr($path,'/template/default')){exit;}
$path2	   = @explode("/",$path);
$path2	   = "/".end($path2);
$LastPath  = str_replace($path2,"",$path);
$con 	   = @explode($showdir,$CurrentPath);

include mayi_tpl(CURSCRIPT);
is_object($db) && $db->Close();
$db = $mymps_global = $part = $action = $here = NULL;
?>