tempfun.php 63 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838
<?php
//修改留言板模板
function EditGbooktemp($temptext,$userid,$username){
	global $empire,$public_r,$dbtbpre;
	if(!$temptext)
	{printerror("EmptyTemptext","history.go(-1)");}
	//驗證權限
	CheckLevel($userid,$username,$classid,"template");
	$temptext=RepPhpAspJspcode($temptext);
	$gid=(int)$_POST['gid'];
	$sql=$empire->query("update ".GetDoTemptb("enewspubtemp",$gid)." set gbooktemp='".eaddslashes2($temptext)."' limit 1");
	//備份模板
	AddEBakTemp('pubgbooktemp',$gid,1,'',$temptext,0,0,'',0,0,'',0,0,0,$userid,$username);
	if($gid==$public_r['deftempid']||(!$public_r['deftempid']&&($gid==1||$gid==0)))
	{
		ReGbooktemp();
	}
	if($sql)
	{
		//操作日誌
		insert_dolog("gid=$gid");
		printerror("EditGbooktempSuccess","template/EditPublicTemp.php?tname=gbooktemp&gid=$gid".hReturnEcmsHashStrHref2(0)."#gbooktemp");
	}
	else
	{printerror("DbError","history.go(-1)");}
}

//修改控制面板模板
function EditCptemp($temptext,$userid,$username){
	global $empire,$public_r,$dbtbpre;
	if(!$temptext)
	{printerror("EmptyTemptext","history.go(-1)");}
	//驗證權限
	CheckLevel($userid,$username,$classid,"template");
	$temptext=RepPhpAspJspcode($temptext);
	$gid=(int)$_POST['gid'];
	$sql=$empire->query("update ".GetDoTemptb("enewspubtemp",$gid)." set cptemp='".eaddslashes2($temptext)."' limit 1");
	//備份模板
	AddEBakTemp('pubcptemp',$gid,1,'',$temptext,0,0,'',0,0,'',0,0,0,$userid,$username);
	if($gid==$public_r['deftempid']||(!$public_r['deftempid']&&($gid==1||$gid==0)))
	{
		ReCptemp();
	}
	if($sql)
	{
		//操作日誌
		insert_dolog("gid=$gid");
		printerror("EditCptempSuccess","template/EditPublicTemp.php?tname=cptemp&gid=$gid".hReturnEcmsHashStrHref2(0)."#cptemp");
	}
	else
	{printerror("DbError","history.go(-1)");}
}

//修改登陸狀態模板
function EditLoginIframe($temptext,$userid,$username){
	global $empire,$public_r,$dbtbpre;
	if(!$temptext)
	{printerror("EmptyTemptext","history.go(-1)");}
	//驗證權限
	CheckLevel($userid,$username,$classid,"template");
	$temptext=RepPhpAspJspcode($temptext);
	$gid=(int)$_POST['gid'];
	$sql=$empire->query("update ".GetDoTemptb("enewspubtemp",$gid)." set loginiframe='".eaddslashes2($temptext)."' limit 1");
	//備份模板
	AddEBakTemp('publoginiframe',$gid,1,'',$temptext,0,0,'',0,0,'',0,0,0,$userid,$username);
	if($gid==$public_r['deftempid']||(!$public_r['deftempid']&&($gid==1||$gid==0)))
	{
		ReLoginIframe();
	}
	if($sql)
	{
		//操作日誌
		insert_dolog("gid=$gid");
		printerror("EditLoginIframeSuccess","template/EditPublicTemp.php?tname=loginiframe&gid=$gid".hReturnEcmsHashStrHref2(0)."#loginiframe");
	}
	else
	{printerror("DbError","history.go(-1)");}
}

//修改JS調用登陸狀態模板
function EditLoginJstemp($temptext,$userid,$username){
	global $empire,$public_r,$dbtbpre;
	if(!$temptext)
	{printerror("EmptyTemptext","history.go(-1)");}
	//驗證權限
	CheckLevel($userid,$username,$classid,"template");
	$temptext=RepPhpAspJspcode($temptext);
	$gid=(int)$_POST['gid'];
	$sql=$empire->query("update ".GetDoTemptb("enewspubtemp",$gid)." set loginjstemp='".eaddslashes2($temptext)."' limit 1");
	//備份模板
	AddEBakTemp('publoginjstemp',$gid,1,'',$temptext,0,0,'',0,0,'',0,0,0,$userid,$username);
	if($gid==$public_r['deftempid']||(!$public_r['deftempid']&&($gid==1||$gid==0)))
	{
		ReLoginIframe();
	}
	if($sql)
	{
		//操作日誌
		insert_dolog("gid=$gid");
		printerror("EditLoginJstempSuccess","template/EditPublicTemp.php?tname=loginjstemp&gid=$gid".hReturnEcmsHashStrHref2(0)."#loginjstemp");
	}
	else
	{printerror("DbError","history.go(-1)");}
}

//修改全站搜索模板
function EditSchallTemp($temptext,$sub,$formatdate,$userid,$username){
	global $empire,$public_r,$dbtbpre;
	if(!$temptext)
	{printerror("EmptyTemptext","history.go(-1)");}
	//驗證權限
	CheckLevel($userid,$username,$classid,"template");
	$temptext=RepPhpAspJspcode($temptext);
	$gid=(int)$_POST['gid'];
	$sub=(int)$sub;
	$sql=$empire->query("update ".GetDoTemptb("enewspubtemp",$gid)." set schalltemp='".eaddslashes2($temptext)."',schallsubnum='$sub',schalldate='".eaddslashes($formatdate)."' limit 1");
	//備份模板
	AddEBakTemp('pubschalltemp',$gid,1,'',$temptext,$sub,0,'',0,0,$formatdate,0,0,0,$userid,$username);
	if($gid==$public_r['deftempid']||(!$public_r['deftempid']&&($gid==1||$gid==0)))
	{
		ReSchAlltemp();
	}
	if($sql)
	{
		//操作日誌
		insert_dolog("gid=$gid");
		printerror("EditSchallTempSuccess","template/EditPublicTemp.php?tname=schalltemp&gid=$gid".hReturnEcmsHashStrHref2(0)."#schalltemp");
	}
	else
	{printerror("DbError","history.go(-1)");}
}

//增加標籤
function AddBq($add,$bqsay,$userid,$username){
	global $empire,$dbtbpre;
	if(!$add[bqname]||!$add[funname]||!$add[bq])
	{printerror("EmptyBqname","history.go(-1)");}
	//驗證權限
	CheckLevel($userid,$username,$classid,"bq");
	//標籤重複
	$num=$empire->gettotal("select count(*) as total from {$dbtbpre}enewsbq where bq='$add[bq]' limit 1");
	if($num)
	{printerror("ReBq","history.go(-1)");}
	//函數是否存在
	if(!function_exists($add[funname]))
	{
		printerror("NotFun","history.go(-1)");
    }
	$classid=(int)$add['classid'];
	$add[isclose]=(int)$add[isclose];
	$myorder=(int)$add[myorder];
	$bqsay=RepPhpAspJspcodeText($bqsay);
	$sql=$empire->query("insert into {$dbtbpre}enewsbq(bqname,bqsay,funname,bq,issys,bqgs,isclose,classid,myorder) values('".$add[bqname]."','".eaddslashes2($bqsay)."','$add[funname]','$add[bq]',0,'".eaddslashes2($add[bqgs])."',$add[isclose],$classid,'$myorder');");
	$bqid=$empire->lastid();
	if($sql)
	{
		//操作日誌
		insert_dolog("bqid=".$bqid."<br>bqname=".$add[bqname]);
		printerror("AddBqSuccess","template/AddBq.php?enews=AddBq".hReturnEcmsHashStrHref2(0));
	}
	else
	{printerror("DbError","history.go(-1)");}
}

//修改標籤
function EditBq($add,$bqsay,$userid,$username){
	global $empire,$dbtbpre;
	$add[bqid]=(int)$add[bqid];
	if(!$add[bqname]||!$add[funname]||!$add[bq]||!$add[bqid])
	{printerror("EmptyBqname","history.go(-1)");}
	//驗證權限
	CheckLevel($userid,$username,$classid,"bq");
	//標籤重複
	$num=$empire->gettotal("select count(*) as total from {$dbtbpre}enewsbq where bq='$add[bq]' and bqid<>'$add[bqid]' limit 1");
	if($num)
	{printerror("ReBq","history.go(-1)");}
	//函數是否存在
	if(!function_exists($add[funname]))
	{
		printerror("NotFun","history.go(-1)");
    }
	$bqsay=RepPhpAspJspcodeText($bqsay);
	$classid=(int)$add['classid'];
	$add[isclose]=(int)$add[isclose];
	$myorder=(int)$add[myorder];
	$sql=$empire->query("update {$dbtbpre}enewsbq set bqname='$add[bqname]',bqsay='".eaddslashes2($bqsay)."',funname='$add[funname]',bq='$add[bq]',bqgs='".eaddslashes2($add[bqgs])."',isclose=$add[isclose],classid=$classid,myorder='$myorder' where bqid='$add[bqid]'");
	if($sql)
	{
		//操作日誌
	    insert_dolog("bqid=".$add[bqid]."<br>bqname=".$add[bqname]);
		printerror("EditBqSuccess","template/ListBq.php?classid=$add[cid]".hReturnEcmsHashStrHref2(0));
	}
	else
	{printerror("DbError","history.go(-1)");}
}

//刪除標籤
function DelBq($bqid,$cid,$userid,$username){
	global $empire,$dbtbpre;
	$bqid=(int)$bqid;
	if(empty($bqid))
	{printerror("NotDelBqid","history.go(-1)");}
	//驗證權限
	CheckLevel($userid,$username,$classid,"bq");
	$num=$empire->gettotal("select count(*) as total from {$dbtbpre}enewsbq where bqid='$bqid' and issys=0");
	if(empty($num))
	{printerror("NotDelSysBq","history.go(-1)");}
	$r=$empire->fetch1("select bqname from {$dbtbpre}enewsbq where bqid='$bqid'");
	$sql=$empire->query("delete from {$dbtbpre}enewsbq where bqid='$bqid'");
	if($sql)
	{
		//操作日誌
	    insert_dolog("bqid=".$bqid."<br>bqname=".$r[bqname]);
		printerror("DelBqSuccess","template/ListBq.php?classid=$cid".hReturnEcmsHashStrHref2(0));
	}
	else
	{printerror("DbError","history.go(-1)");}
}

//修改搜索頁面
function EditSearchTemp($tempname,$temptext,$userid,$username){
	global $empire,$dbtbpre,$public_r;
	if(empty($temptext)||empty($tempname))
	{printerror("EmptySearchTemp","history.go(-1)");}
	//操作權限
	CheckLevel($userid,$username,$classid,"template");
	$temptext=RepPhpAspJspcode($temptext);
	$tempname=RepPostVar($tempname);
	if($tempname=="searchtemp")//搜索表單模板
	{
		$f="searchtemp";
		$tname="searchformtemp";
		$temptype='pubsearchtemp';
	}
	elseif($tempname=="searchjstemp")//搜索JS模板(橫向)
	{
		$temptext=str_replace("\r\n","",$temptext);
		$f="searchjstemp";
		$tname="searchformjs";
		$temptype='pubsearchjstemp';
	}
	else//搜索JS模板(縱向)
	{
		$temptext=str_replace("\r\n","",$temptext);
		$f="searchjstemp1";
		$tname="searchformjs1";
		$temptype='pubsearchjstemp1';
    }
	$gid=(int)$_POST['gid'];
	$sql=$empire->query("update ".GetDoTemptb("enewspubtemp",$gid)." set ".$f."='".eaddslashes2($temptext)."'");
	//備份模板
	AddEBakTemp($temptype,$gid,1,'',$temptext,0,0,'',0,0,'',0,0,0,$userid,$username);
	if($gid==$public_r['deftempid']||(!$public_r['deftempid']&&($gid==1||$gid==0)))
	{
		GetSearch();
	}
	if($sql)
	{
		//操作日誌
		insert_dolog("temp=$f&gid=$gid");
		printerror("EditSearchTempSuccess","template/EditPublicTemp.php?tname=$tname&gid=$gid".hReturnEcmsHashStrHref2(0)."#$tempname");
	}
	else
	{printerror("DbError","history.go(-1)");}
}

//修改相關鏈接模板
function EditOtherLinkTemp($tempname,$temptext,$userid,$username){
	global $empire,$dbtbpre;
	if(empty($temptext)||empty($tempname))
	{printerror("EmptyOtherLinkTemp","history.go(-1)");}
	//操作權限
	CheckLevel($userid,$username,$classid,"template");
	$tempname=RepPostVar($tempname);
	$temptext=RepPhpAspJspcode($temptext);
	$f="otherlinktemp";
	$tname="otherlinktemp";
	$otherlinktempsub=(int)$_POST['otherlinktempsub'];
	$otherlinktempdate=$_POST['otherlinktempdate'];
	$gid=(int)$_POST['gid'];
	$sql=$empire->query("update ".GetDoTemptb("enewspubtemp",$gid)." set ".$f."='".eaddslashes2($temptext)."',otherlinktempsub=$otherlinktempsub,otherlinktempdate='".eaddslashes($otherlinktempdate)."'");
	//備份模板
	AddEBakTemp('pubotherlinktemp',$gid,1,'',$temptext,0,0,'',0,0,$otherlinktempdate,$otherlinktempsub,0,0,$userid,$username);
	if($sql)
	{
		//操作日誌
		insert_dolog("temp=$f&gid=$gid");
		printerror("EditOtherLinkTempSuccess","template/EditPublicTemp.php?tname=$tname&gid=$gid".hReturnEcmsHashStrHref2(0)."#$tempname");
	}
	else
	{printerror("DbError","history.go(-1)");}
}

//修改其它公共模板
function EditOtherPubTemp($tempname,$temptext,$userid,$username){
	global $empire,$dbtbpre,$public_r;
	if(empty($temptext)||empty($tempname))
	{printerror("EmptyEditDownTemp","history.go(-1)");}
	//操作權限
	CheckLevel($userid,$username,$classid,"template");
	$edittemplist=',pljstemp,downpagetemp,downsofttemp,onlinemovietemp,listpagetemp,';
	$temptext=RepPhpAspJspcode($temptext);
	$tempname=RepPostVar($tempname);
	if(!strstr($edittemplist,','.$tempname.','))
	{
		printerror("EmptyEditDownTemp","history.go(-1)");
	}
	if($tempname=='downsofttemp')
	{
		$temptype='pubdownsofttemp';
	}
	elseif($tempname=='onlinemovietemp')
	{
		$temptype='pubonlinemovietemp';
	}
	elseif($tempname=='listpagetemp')
	{
		$temptype='publistpagetemp';
	}
	elseif($tempname=='pljstemp')
	{
		$temptype='pubpljstemp';
	}
	elseif($tempname=='downpagetemp')
	{
		$temptype='pubdownpagetemp';
	}
	$gid=(int)$_POST['gid'];
	$sql=$empire->query("update ".GetDoTemptb("enewspubtemp",$gid)." set ".$tempname."='".eaddslashes2($temptext)."'");
	//備份模板
	AddEBakTemp($temptype,$gid,1,'',$temptext,0,0,'',0,0,'',0,0,0,$userid,$username);
	if($gid==$public_r['deftempid']||(!$public_r['deftempid']&&($gid==1||$gid==0)))
	{
		if($tempname=="downsofttemp"||$tempname=="onlinemovietemp"||$tempname=="listpagetemp")
		{
			GetConfig();
		}
		elseif($tempname=="downpagetemp")
		{
			GetDownloadPage();
		}
		elseif($tempname=="pljstemp")
		{
			GetPlJsPage();
		}
		else
		{
		}
	}
	if($sql)
	{
		//操作日誌
		insert_dolog("temp=$tempname&gid=$gid");
		printerror("EditDownTempSuccess","template/EditPublicTemp.php?tname=$tempname&gid=$gid".hReturnEcmsHashStrHref2(0)."#$tempname");
	}
	else
	{printerror("DbError","history.go(-1)");}
}

//修改首頁模板
function EditIndextemp($temptext,$userid,$username){
	global $empire,$dbtbpre,$public_r;
	if(!$temptext)
	{
		printerror("EmptyIndexTemp","history.go(-1)");
	}
	CheckLevel($userid,$username,$classid,"template");//操作權限
	$temptext=RepPhpAspJspcode($temptext);
	$gid=(int)$_POST['gid'];
	$sql=$empire->query("update ".GetDoTemptb("enewspubtemp",$gid)." set indextemp='".eaddslashes2($temptext)."'");
	//備份模板
	AddEBakTemp('pubindextemp',$gid,1,'',$temptext,0,0,'',0,0,'',0,0,0,$userid,$username);
	//刷新首頁
	if($gid==$public_r['deftempid']||(!$public_r['deftempid']&&($gid==1||$gid==0)))
	{
		NewsBq($classid,eaddslashes($temptext),1,0);
		//刪除動態模板緩存文件
		DelOneTempTmpfile('indexpage');
	}
	if($sql)
	{
	    insert_dolog("gid=$gid");//操作日誌
		printerror("EditPublicTempSuccess","template/EditPublicTemp.php?tname=indextemp&gid=$gid".hReturnEcmsHashStrHref2(0));
	}
	else
	{
		printerror("DbError","history.go(-1)");
	}
}

//預覽首頁方案
function PreviewIndexpage($tempid,$userid,$username){
	global $empire,$dbtbpre,$public_r,$emod_r,$class_r,$class_zr,$fun_r,$navclassid,$navinfor,$class_tr,$level_r,$etable_r;
	//驗證權限
	CheckLevel($userid,$username,$classid,"template");
	$tempid=(int)$tempid;
	if(!$tempid)
	{
		printerror('ErrorUrl','');
	}
	$tempr=$empire->fetch1("select tempid,temptext from {$dbtbpre}enewsindexpage where tempid='$tempid'");
	if(!$tempr['tempid'])
	{
		printerror('ErrorUrl','');
	}
	$indextext=stripSlashes($tempr['temptext']);
	$indextext=ReplaceTempvar($indextext);//替換全局模板變量
	$pr=$empire->fetch1("select sitekey,siteintro from {$dbtbpre}enewspublic limit 1");
	//頁面
	$pagetitle=ehtmlspecialchars($public_r['sitename']);
	$pagekey=ehtmlspecialchars($pr['sitekey']);
	$pagedes=ehtmlspecialchars($pr['siteintro']);
	$url="<a href=\"".ReturnSiteIndexUrl()."\">".$fun_r['index']."</a>";//欄目導航
	$onclick='';
	$file=ECMS_PATH.'e/data/tmp/indexpage'.$tempid.'.php';
	$indextext=ReplaceSvars($indextext,$url,0,$pagetitle,$pagekey,$pagedes,$add,0);
	$indextext=str_replace("[!--page.stats--]",$onclick,$indextext);
	//替換標籤
	$indextext=DoRepEcmsLoopBq($indextext);
	$indextext=RepBq($indextext);
	//寫文件
	WriteFiletext($file,AddCheckViewTempCode().$indextext);
	//讀取文件內容
	ob_start();
	include($file);
	$string=ob_get_contents();
	ob_end_clean();
	$string=RepExeCode($string);//解析代碼
	echo stripSlashes($string);
	exit();
}

//批量導入欄目模板
function LoadTempInClass($path,$start,$userid,$username){
	global $empire,$public_r,$dbtbpre;
	//驗證權限
	CheckLevel($userid,$username,$classid,"template");
	$start=(int)$start;
	if(empty($public_r[loadtempnum]))
	{$public_r[loadtempnum]=50;}
	$b=0;
	$sql=$empire->query("select classid,classtempid,islist from {$dbtbpre}enewsclass where islast=0 and islist<>1 and classid>$start order by classid limit ".$public_r[loadtempnum]);
	while($r=$empire->fetch($sql))
	{
		$b=1;
		$newstart=$r[classid];
		if($r[islist]==3)
		{
			continue;
		}
		$file="../data/LoadTemp/".$r[classid].".htm";
		if(file_exists($file))
		{
			$data=addslashes(addslashes(ReadFiletext($file)));
			$data=RepPhpAspJspcode($data);
			if($r[islist]==2)
			{
				$usql=$empire->query("update {$dbtbpre}enewsclassadd set classtext='".$data."' where classid='$r[classid]'");
			}
			else
			{
				$usql=$empire->query("update {$dbtbpre}enewsclasstemp set temptext='".$data."' where tempid='$r[classtempid]'");
			}
			NewsBq($r[classid],$data,0,0);
	    }
    }
	if(empty($b))
	{
		//操作日誌
	    insert_dolog("");
		printerror("LoadClassTempSuccess","template/LoadTemp.php".hReturnEcmsHashStrHref2(1));
	}
	echo $fun_r['LoadOneTempSuccess']."(ID:<font color=red><b>".$newstart."</b></font>)<script>self.location.href='ecmstemp.php?enews=LoadTempInClass&start=$newstart".hReturnEcmsHashStrHref(0)."';</script>";
	exit();
}

//批量更換欄目列表模板
function ChangeClassListtemp($classid,$listtempid,$userid,$username){
	global $empire,$class_r,$dbtbpre;
	if(empty($listtempid))
	{printerror("EmptChangeListtempid","history.go(-1)");}
	//驗證權限
	CheckLevel($userid,$username,$classid,"template");
	$listtempid=(int)$listtempid;
	$classid=(int)$classid;
	if(empty($classid))
	{$where="classid<>0";}
	else
	{
		//中級欄目
		if(empty($class_r[$classid][islast]))
		{
			$where=ReturnClass($class_r[$classid][sonclass]);
		}
		//終極欄目
		else
		{
			$where="classid='$classid'";
		}
	}
	$sql=$empire->query("update {$dbtbpre}enewsclass set listtempid=$listtempid where ".$where);
	GetClass();
	if($sql)
	{
		//操作日誌
		insert_dolog("classid=$classid&listtempid=$listtempid");
		printerror("ChangeClassListtempSuccess","history.go(-1)");
	}
	else
	{printerror("DbError","history.go(-1)");}
}

//導出標籤
function LoadOutBq($add,$userid,$username){
	global $empire,$dbtbpre;
	$bqid=(int)$add['bqid'];
	if(!$bqid||!$add['funvalue'])
	{
		printerror("EmptyLoadBqid","history.go(-1)");
	}
	//驗證權限
    CheckLevel($userid,$username,$classid,"bq");
	$r=$empire->fetch1("select bqid,bqname,bqsay,funname,bq,bqgs from {$dbtbpre}enewsbq where bqid=$bqid");
	if(!$r[bqid])
	{
		printerror("NotThisBqid","history.go(-1)");
	}
	$add['funvalue']=ClearAddsData($add['funvalue']);
	$field="<!--#empirecms.bq-phome.net#--!>";
	$str=$r['bqname'].$field.stripSlashes($r['bqsay']).$field.$r['funname'].$field.$r['bq'].$field.stripSlashes($r['bqgs']).$field.$add['funvalue'];
	$filename=$r['bq'].time().".bq";
	$filepath=ECMS_PATH.'e/data/tmp/temp/'.$filename;
	WriteFiletext_n($filepath,$str);
	DownLoadFile($filename,$filepath,1);
	//操作日誌
	insert_dolog("bqid=".$bqid."<br>bqname=".$r[bqname]);
	exit();
}

//導入標籤
function LoadInBq($add,$file,$file_name,$file_type,$file_size,$userid,$username){
	global $empire,$dbtbpre;
	//驗證權限
    CheckLevel($userid,$username,$classid,"bq");
	$classid=(int)$add['classid'];
	if(!$file_name||!$file_size)
	{
		printerror("EmptyLoadInBqFile","history.go(-1)");
	}
	//擴展名
	$filetype=GetFiletype($file_name);
	if($filetype!=".bq")
	{
		printerror("LoadInBqMustBq","history.go(-1)");
	}
	$field="<!--#empirecms.bq-phome.net#--!>";
	$path=ECMS_PATH.'e/data/tmp/temp/uploadbq'.time().'.bq';
	//上傳文件
	$cp=@move_uploaded_file($file,$path);
	DoChmodFile($path);
	$data=ReadFiletext($path);
	DelFiletext($path);
	$r=explode($field,$data);
	$num=$empire->gettotal("select count(*) as total from {$dbtbpre}enewsbq where bq='$r[3]' or funname='$r[2]' limit 1");
	if($num)
	{
		printerror("ReLoadInBq","history.go(-1)");
	}
	$sql=$empire->query("insert into {$dbtbpre}enewsbq(bqname,bqsay,funname,bq,issys,bqgs,isclose,classid,myorder) values('".addslashes($r[0])."','".addslashes(addslashes($r[1]))."','".addslashes($r[2])."','".addslashes($r[3])."',0,'".addslashes(addslashes($r[4]))."',0,$classid,0);");
	$bqid=$empire->lastid();
	//操作日誌
	insert_dolog("bqid=".$bqid."<br>bqname=".$r[0]);
	return $r;
}

//-----------------------批量替換模板字符
function DoRepTemp($add,$userid,$username){
	global $empire,$dbtbpre;
	//驗證權限
	CheckLevel($userid,$username,$classid,"template");
	$oldword=RepPhpAspJspcode(eaddslashes2($add['oldword']));
	$newword=RepPhpAspJspcode(eaddslashes2($add['newword']));
	if(!$oldword)
	{
		printerror("EmptyRepTemp","history.go(-1)");
    }
	$gid=(int)$add['gid'];
	//公共表
	if($add['indextemp']||$add['cptemp']||$add['sformtemp']||$add['otherlinktemp']||$add['gbooktemp']||$add['loginiframe']||$add['pljstemp']||$add['schalltemp']||$add['loginjstemp']||$add['downpagetemp'])
	{
		$set='';
		//首頁模板
		if($add['indextemp'])
		{
			
			$set.=",indextemp=REPLACE(indextemp,'".$oldword."','".$newword."')";
		}
		//控制面板模板
		if($add['cptemp'])
		{
			$set.=",cptemp=REPLACE(cptemp,'".$oldword."','".$newword."')";
		}
		//搜索表單模板
		if($add['sformtemp'])
		{
			$set.=",searchtemp=REPLACE(searchtemp,'".$oldword."','".$newword."')";
		}
		//相關信息模板
		if($add['otherlinktemp'])
		{
			$set.=",otherlinktemp=REPLACE(otherlinktemp,'".$oldword."','".$newword."')";
		}
		//留言板模板
		if($add['gbooktemp'])
		{
			$set.=",gbooktemp=REPLACE(gbooktemp,'".$oldword."','".$newword."')";
		}
		//登陸狀態模板
		if($add['loginiframe'])
		{
			$set.=",loginiframe=REPLACE(loginiframe,'".$oldword."','".$newword."')";
		}
		//評論JS模板
		if($add['pljstemp'])
		{
			$set.=",pljstemp=REPLACE(pljstemp,'".$oldword."','".$newword."')";
		}
		//全站搜索模板
		if($add['schalltemp'])
		{
			$set.=",schalltemp=REPLACE(schalltemp,'".$oldword."','".$newword."')";
		}
		//JS調用登陸狀態模板
		if($add['loginjstemp'])
		{
			$set.=",loginjstemp=REPLACE(loginjstemp,'".$oldword."','".$newword."')";
		}
		//最終下載頁模板
		if($add['downpagetemp'])
		{
			$set.=",downpagetemp=REPLACE(downpagetemp,'".$oldword."','".$newword."')";
		}
		$empire->query("update ".GetDoTemptb("enewspubtemp",$gid)." set id=1".$set." limit 1");
	}
	//修改欄目封面模板
	if($add['classtemp'])
	{
		$empire->query("update ".GetDoTemptb("enewsclasstemp",$gid)." set temptext=REPLACE(temptext,'".$oldword."','".$newword."')");
    }
	//修改標籤模板
	if($add['bqtemp'])
	{
		$empire->query("update ".GetDoTemptb("enewsbqtemp",$gid)." set temptext=REPLACE(temptext,'".$oldword."','".$newword."'),listvar=REPLACE(listvar,'".$oldword."','".$newword."')");
    }
	//修改列表模板
	if($add['listtemp'])
	{
		$empire->query("update ".GetDoTemptb("enewslisttemp",$gid)." set temptext=REPLACE(temptext,'".$oldword."','".$newword."'),listvar=REPLACE(listvar,'".$oldword."','".$newword."')");
    }
	//修改內容模板
	if($add['newstemp'])
	{
		$empire->query("update ".GetDoTemptb("enewsnewstemp",$gid)." set temptext=REPLACE(temptext,'".$oldword."','".$newword."')");
	}
	//修改搜索模板
	if($add['searchtemp'])
	{
		$empire->query("update ".GetDoTemptb("enewssearchtemp",$gid)." set temptext=REPLACE(temptext,'".$oldword."','".$newword."'),listvar=REPLACE(listvar,'".$oldword."','".$newword."')");
	}
	//修改自定義頁面
	if($add['userpage'])
	{
		$empire->query("update {$dbtbpre}enewspage set pagetext=REPLACE(pagetext,'".$oldword."','".$newword."')");
	}
	//修改自定義頁面模板
	if($add['pagetemp'])
	{
		$empire->query("update ".GetDoTemptb("enewspagetemp",$gid)." set temptext=REPLACE(temptext,'".$oldword."','".$newword."')");
    }
	//評論列表模板
	if($add['pltemp'])
	{
		$empire->query("update ".GetDoTemptb("enewspltemp",$gid)." set temptext=REPLACE(temptext,'".$oldword."','".$newword."')");
    }
	//打印模板
	if($add['printtemp'])
	{
		$empire->query("update ".GetDoTemptb("enewsprinttemp",$gid)." set temptext=REPLACE(temptext,'".$oldword."','".$newword."')");
    }
	//模板變量
	if($add['tempvar'])
	{
		$empire->query("update ".GetDoTemptb("enewstempvar",$gid)." set varvalue=REPLACE(varvalue,'".$oldword."','".$newword."')");
	}
	//修改JS模板
	if($add['jstemp'])
	{
		$empire->query("update ".GetDoTemptb("enewsjstemp",$gid)." set temptext=REPLACE(temptext,'".$oldword."','".$newword."')");
    }
	//修改投票模板
	if($add['votetemp'])
	{
		$empire->query("update ".GetDoTemptb("enewsvotetemp",$gid)." set temptext=REPLACE(temptext,'".$oldword."','".$newword."')");
    }
	//反饋表單模板
	if($add['feedbackbtemp'])
	{
		$empire->query("update {$dbtbpre}enewsfeedbackclass set btemp=REPLACE(btemp,'".$oldword."','".$newword."')");
	}
	//操作日誌
	insert_dolog("gid=$gid");
	printerror("RepTempSuccess","history.go(-1)");
}

//修改模板組
function EditTempGroup($add,$userid,$username){
	global $empire,$dbtbpre;
	//驗證權限
	CheckLevel($userid,$username,$classid,"tempgroup");
	$gid=$add['gid'];
	$gname=$add['gname'];
	$count=count($gid);
	for($i=0;$i<$count;$i++)
	{
		$usql=$empire->query("update {$dbtbpre}enewstempgroup set gname='".$gname[$i]."' where gid='".$gid[$i]."'");
	}
	//操作日誌
	insert_dolog("");
	printerror("EditTempGroupSuccess","TempGroup.php".hReturnEcmsHashStrHref2(1));
}

//默認模板組
function DefTtempGroup($add,$userid,$username){
	global $empire,$dbtbpre;
	//驗證權限
	CheckLevel($userid,$username,$classid,"tempgroup");
	$gid=(int)$add['changegid'];
	if(!$gid)
	{
		printerror("EmptyTempGroup","");
	}
	$r=$empire->fetch1("select gid,gname from {$dbtbpre}enewstempgroup where gid=$gid");
	if(!$r['gid'])
	{
		printerror("EmptyTempGroup","");
	}
	$usql=$empire->query("update {$dbtbpre}enewstempgroup set isdefault=0");
	$sql=$empire->query("update {$dbtbpre}enewstempgroup set isdefault=1 where gid=$gid");
	$upsql=$empire->query("update {$dbtbpre}enewspublic set deftempid=$gid limit 1");
	if($usql&&$sql&&$upsql)
	{
		GetConfig();
		//操作日誌
		insert_dolog("gid=$gid&gname=$r[gname]");
		printerror("DefTempGroupSuccess","TempGroup.php".hReturnEcmsHashStrHref2(1));
	}
	else
	{
		printerror("DbError","");
	}
}

//返回模板表
function ReturnTemptbList(){
	$templist="enewsbqtemp,enewsjstemp,enewslisttemp,enewsnewstemp,enewspubtemp,enewssearchtemp,enewstempvar,enewsvotetemp,enewsclasstemp,enewspltemp,enewsprinttemp,enewspagetemp";
	return $templist;
}

//刪除模板數據表
function DelTempTb($gid){
	global $empire,$dbtbpre;
	if($gid==1)
	{
		return "";
	}
	$templist=ReturnTemptbList();
	$r=explode(",",$templist);
	$count=count($r);
	$droptb="";
	for($i=0;$i<$count;$i++)
	{
		$dh=",";
		if($i==0)
		{
			$dh="";
		}
		$droptb.=$dh.$dbtbpre.$r[$i]."_".$gid;
	}
	$sql=$empire->query("DROP TABLE IF EXISTS ".$droptb.";");
	return $sql;
}

//清空模板數據表
function ClearTempTb($gid,$en){
	global $empire,$dbtbpre;
	$templist=ReturnTemptbList();
	$r=explode(",",$templist);
	$count=count($r);
	for($i=0;$i<$count;$i++)
	{
		$tb=$dbtbpre.$r[$i].$en;
		$empire->query("TRUNCATE `".$tb."`;");
	}
}

//新建模板數據表
function CreateTempTb($gid,$en){
	global $empire,$dbtbpre;
	if($gid==1)
	{
		return "";
	}
	$templist=ReturnTemptbList();
	$r=explode(",",$templist);
	$count=count($r);
	for($i=0;$i<$count;$i++)
	{
		$otb=$dbtbpre.$r[$i];
		$tb=$dbtbpre.$r[$i].$en;
		CopyEcmsTb($otb,$tb);
	}
}

//刪除模板組
function DelTempGroup($add,$userid,$username){
	global $empire,$dbtbpre;
	//驗證權限
	CheckLevel($userid,$username,$classid,"tempgroup");
	$gid=(int)$add['changegid'];
	if(!$gid)
	{
		printerror("EmptyDelTempGroup","");
	}
	if($gid==1)
	{
		printerror("NotDelDefTempGroup","");
	}
	$r=$empire->fetch1("select gid,gname,isdefault from {$dbtbpre}enewstempgroup where gid=$gid");
	if(!$r['gid'])
	{
		printerror("EmptyDelTempGroup","");
	}
	$sql=$empire->query("delete from {$dbtbpre}enewstempgroup where gid=$gid");
	if($r['isdefault'])
	{
		$upsql=$empire->query("update {$dbtbpre}enewspublic set deftempid=0 limit 1");
		GetConfig();
	}
	DelTempTb($gid);
	//刪除備份記錄
	$empire->query("delete from {$dbtbpre}enewstempbak where gid='$gid'");
	if($sql)
	{
		//操作日誌
		insert_dolog("gid=$gid&gname=$r[gname]");
		printerror("DelTempGroupSuccess","TempGroup.php".hReturnEcmsHashStrHref2(1));
	}
	else
	{
		printerror("DbError","");
	}
}

//導出模板組
function LoadTempGroup($add,$userid,$username){
	global $empire,$dbtbpre;
	//驗證權限
	CheckLevel($userid,$username,$classid,"tempgroup");
	$gid=(int)$add['changegid'];
	if(!$gid)
	{
		printerror("EmptyLoadTempGroup","");
	}
	$r=$empire->fetch1("select gid,gname from {$dbtbpre}enewstempgroup where gid=$gid");
	if(!$r['gid'])
	{
		printerror("EmptyLoadTempGroup","");
	}
	//版本
	$thistempver=LoadTGAddVer();
	$pageexp="<!---ecms.temp--->";
	$record="<!---ecms.record--->";
	$field="<!---ecms.field--->";
	if($gid==1)
	{
		$en="";
	}
	else
	{
		$en="_".$gid;
	}
	$bqtemp=LoadTGBqtemp($gid,$en,$pageexp,$record,$field);//標籤模板
	$jstemp=LoadTGJstemp($gid,$en,$pageexp,$record,$field);//JS模板
	$listtemp=LoadTGListtemp($gid,$en,$pageexp,$record,$field);//列表模板
	$newstemp=LoadTGNewstemp($gid,$en,$pageexp,$record,$field);//內容模板
	$pubtemp=LoadTGPubtemp($gid,$en,$pageexp,$record,$field);//公共模板
	$searchtemp=LoadTGSearchtemp($gid,$en,$pageexp,$record,$field);//搜索模板
	$tempvar=LoadTGTempvar($gid,$en,$pageexp,$record,$field);//模板變量
	$votetemp=LoadTGVotetemp($gid,$en,$pageexp,$record,$field);//投票模板
	$classtemp=LoadTGClasstemp($gid,$en,$pageexp,$record,$field);//欄目模板
	$pltemp=LoadTGPltemp($gid,$en,$pageexp,$record,$field);//評論模板
	$printtemp=LoadTGPrinttemp($gid,$en,$pageexp,$record,$field);//打印模板
	$pagetemp=LoadTGPagetemp($gid,$en,$pageexp,$record,$field);//自定義頁面模板
	$loadtemptext=$r['gname'].$thistempver.$pageexp.$bqtemp.$pageexp.$jstemp.$pageexp.$listtemp.$pageexp.$newstemp.$pageexp.$pubtemp.$pageexp.$searchtemp.$pageexp.$tempvar.$pageexp.$votetemp.$pageexp.$classtemp.$pageexp.$pltemp.$pageexp.$printtemp.$pageexp.$pagetemp;
	$loadtemptext=stripSlashes($loadtemptext);
	$file="e".time().".temp";
	$filepath=ECMS_PATH.'e/data/tmp/temp/'.$file;
	WriteFiletext_n($filepath,$loadtemptext);
	DownLoadFile($file,$filepath,1);
	//操作日誌
	insert_dolog("gid=$gid&gname=$r[gname]");
	exit();
}

//模板轉編碼
function LoadInTempChangeChar($tempchar,$text){
	global $ecms_config;
	@include_once(ECMS_PATH.'e/class/EmpireCMS_version.php');
	if($tempchar=='GB2312')//簡體GB2312
	{
		if($ecms_config['sets']['pagechar']=='gb2312')
		{
			return $text;
		}
		if($ecms_config['sets']['pagechar']=='utf-8')
		{
			if(EmpireCMS_CHARVER=='TC-UTF-8')//繁體
			{
				$text=DoIconvVal("GB2312","BIG5",$text,1);
				$text=DoIconvVal("BIG5","UTF8",$text);
			}
			else//簡體
			{
				$text=DoIconvVal("GB2312","UTF8",$text,1);
			}
			$text=preg_replace(array('/charset=gbk/i','/charset=gb2312/i'),array('charset=utf-8','charset=utf-8'),$text);
		}
		elseif($ecms_config['sets']['pagechar']=='big5')
		{
			$text=DoIconvVal("GB2312","BIG5",$text,1);
			$text=preg_replace(array('/charset=gbk/i','/charset=gb2312/i'),array('charset=big5','charset=big5'),$text);
		}
	}
	elseif($tempchar=='UTF8')//簡體UTF-8
	{
		if($ecms_config['sets']['pagechar']=='utf-8'&&EmpireCMS_CHARVER=='UTF-8')
		{
			return $text;
		}
		if($ecms_config['sets']['pagechar']=='gb2312')
		{
			$text=DoIconvVal("UTF8","GB2312",$text,1);
			$text=preg_replace('/charset=utf-8/i','charset=gb2312',$text);
		}
		elseif($ecms_config['sets']['pagechar']=='big5')
		{
			$text=DoIconvVal("UTF8","GB2312",$text,1);
			$text=DoIconvVal("GB2312","BIG5",$text);
			$text=preg_replace('/charset=utf-8/i','charset=big5',$text);
		}
		elseif($ecms_config['sets']['pagechar']=='utf-8')//繁體
		{
			$text=DoIconvVal("UTF8","GB2312",$text,1);
			$text=DoIconvVal("GB2312","BIG5",$text);
			$text=DoIconvVal("BIG5","UTF8",$text);
		}
	}
	elseif($tempchar=='BIG5')//繁體BIG5
	{
		if($ecms_config['sets']['pagechar']=='big5')
		{
			return $text;
		}
		if($ecms_config['sets']['pagechar']=='gb2312')
		{
			$text=DoIconvVal("BIG5","GB2312",$text,1);
			$text=preg_replace('/charset=big5/i','charset=gb2312',$text);
		}
		elseif($ecms_config['sets']['pagechar']=='utf-8')
		{
			if(EmpireCMS_CHARVER=='UTF-8')//簡體
			{
				$text=DoIconvVal("BIG5","GB2312",$text,1);
				$text=DoIconvVal("GB2312","UTF8",$text);
			}
			else//繁體
			{
				$text=DoIconvVal("BIG5","UTF8",$text,1);
			}
			$text=preg_replace('/charset=big5/i','charset=utf-8',$text);
		}
	}
	elseif($tempchar=='TCUTF8')//繁體UTF-8
	{
		if($ecms_config['sets']['pagechar']=='utf-8'&&EmpireCMS_CHARVER=='TC-UTF-8')
		{
			return $text;
		}
		if($ecms_config['sets']['pagechar']=='gb2312')
		{
			$text=DoIconvVal("UTF8","BIG5",$text,1);
			$text=DoIconvVal("BIG5","GB2312",$text);
			$text=preg_replace('/charset=utf-8/i','charset=gb2312',$text);
		}
		elseif($ecms_config['sets']['pagechar']=='big5')
		{
			$text=DoIconvVal("UTF8","BIG5",$text,1);
			$text=preg_replace('/charset=utf-8/i','charset=big5',$text);
		}
		elseif($ecms_config['sets']['pagechar']=='utf-8')//簡體
		{
			$text=DoIconvVal("UTF8","BIG5",$text,1);
			$text=DoIconvVal("BIG5","GB2312",$text);
			$text=DoIconvVal("GB2312","UTF8",$text);
		}
	}
	return $text;
}

//替換以往版本地址
function LoadInTGReptext_pubvar($text){
	//shop
	$text=str_replace('/enews/?enews=AddBuycar','/ShopSys/doaction.php?enews=AddBuycar',$text);
	$text=str_replace('/enews?enews=AddBuycar','/ShopSys/doaction.php?enews=AddBuycar',$text);
	//pl
	$text=str_replace('/enews/?enews=DoForPl','/pl/doaction.php?enews=DoForPl',$text);
	$text=str_replace('/enews?enews=DoForPl','/pl/doaction.php?enews=DoForPl',$text);
	//member
	$text=str_replace('/enews/?enews=exit','/member/doaction.php?enews=exit',$text);
	$text=str_replace('/enews?enews=exit','/member/doaction.php?enews=exit',$text);
	//report
	$text=str_replace('/DownSys/report','/public/report',$text);
	return $text;
}

//替換以往版本地址
function LoadInTGReptext_othervar($text,$type='pl'){
	if($type=='pl')
	{
		$text=str_replace('/enews/index.php','/pl/doaction.php',$text);
	}
	elseif($type=='member')
	{
		$text=str_replace('/enews/index.php','/member/doaction.php',$text);
	}
	elseif($type=='shop')
	{
		$text=str_replace('/enews/index.php','/ShopSys/doaction.php',$text);
	}
	return $text;
}

//加版本號
function LoadTGAddVer(){
	@include_once(ECMS_PATH.'e/class/EmpireCMS_version.php');
	$ver=' ,-- '.EmpireCMS_VERSION.','.EmpireCMS_CHARVER;
	return $ver;
}

//替換版本號
function LoadInTGReturnVer($gname){
	$exp=' ,-- ';
	$r=explode($exp,$gname);
	$returnr['gname']=$r[0];
	$returnr['ver']='';
	$returnr['tempchar']='';
	if($r[1])
	{
		$vr=explode(',',$r[1]);
		$returnr['ver']=$vr[0];
		$returnr['tempchar']=$vr[1];
	}
	return $returnr;
}

//導入模板組
function LoadInTempGroup($add,$file,$file_name,$file_type,$file_size,$userid,$username){
	global $empire,$dbtbpre;
	//驗證權限
	CheckLevel($userid,$username,$classid,"tempgroup");
	if(!$file_name||!$file_size)
	{
		printerror("EmptyLoadInTempGroup","");
	}
	$gid=(int)$add['gid'];
	//擴展名
	$filetype=GetFiletype($file_name);
	if($filetype!=".temp")
	{
		printerror("LoadInTempGroupMusttemp","");
	}
	//上傳文件
	$path=ECMS_PATH.'e/data/tmp/temp/uploadtg'.time().make_password(10).'.temp';
	$cp=@move_uploaded_file($file,$path);
	DoChmodFile($path);
	$data=ReadFiletext($path);
	DelFiletext($path);
	//轉碼
	if($add['ChangeChar'])
	{
		$data=LoadInTempChangeChar($add['tempchar'],$data);
	}
	if(empty($data))
	{
		printerror("EmptyLoadInTempGroup","");
	}
	//返回版本
	$pageexp="<!---ecms.temp--->";
	$checkpr=explode($pageexp,$data);
	$tempverr=LoadInTGReturnVer($checkpr[0]);
	$gname=$tempverr['gname'];
	$thistempver=$tempverr['ver'];
	$thistempchar=$tempverr['tempchar'];
	//替換舊地址
	$GLOBALS['loadtempver']=$thistempver;
	if(empty($thistempver))
	{
		$data=LoadInTGReptext_pubvar($data);
	}
	//入庫
	$pageexp="<!---ecms.temp--->";
	$record="<!---ecms.record--->";
	$field="<!---ecms.field--->";
	$pr=explode($pageexp,$data);
	if(empty($gid))//新建模板組
	{
		$sql=$empire->query("insert into {$dbtbpre}enewstempgroup(gname,isdefault) values('".addslashes($gname)."',0);");
		$gid=$empire->lastid();
		$gname=$pr[0];
		$en="_".$gid;
		CreateTempTb($gid,$en);//複製表
	}
	else//覆蓋模板組
	{
		$r=$empire->fetch1("select gid,gname from {$dbtbpre}enewstempgroup where gid=$gid");
		if(!$r['gid'])
		{
			printerror("LoadInTempGroupMusttemp","");
		}
		if($gid==1)
		{
			$en="";
		}
		else
		{
			$en="_".$gid;
		}
		$gname=$r['gname'];
		ClearTempTb($gid,$en);//清空表
	}
	//版本
	$isold=0;
	$ckcount=count($pr);
	if($ckcount<=10)//5.1
	{
		$isold=1;
	}
	elseif($ckcount<=11)//6.0
	{
		$isold=2;
	}
	LoadInTGBqtemp($gid,$en,$record,$field,$pr[1]);//標籤模板
	LoadInTGJstemp($gid,$en,$record,$field,$pr[2]);//JS模板
	LoadInTGListtemp($gid,$en,$record,$field,$pr[3]);//列表模板
	LoadInTGNewstemp($gid,$en,$record,$field,$pr[4]);//內容模板
	LoadInTGPubtemp($gid,$en,$record,$field,$pr[5],$isold);//公共模板
	LoadInTGSearchtemp($gid,$en,$record,$field,$pr[6]);//搜索模板
	LoadInTGTempvar($gid,$en,$record,$field,$pr[7]);//模板變量
	LoadInTGVotetemp($gid,$en,$record,$field,$pr[8]);//投票模板
	LoadInTGClasstemp($gid,$en,$record,$field,$pr[9]);//欄目模板
	if($isold!=1)
	{
		LoadInTGPltemp($gid,$en,$record,$field,$pr[10]);//評論模板
	}
	if($isold==0)
	{
		LoadInTGPrinttemp($gid,$en,$record,$field,$pr[11]);//打印模板
	}
	LoadInTGPagetemp($gid,$en,$record,$field,$pr[12]);//自定義頁面模板
	//操作日誌
	insert_dolog("gid=$gid&gname=$gname");
	printerror("LoadInTempGroupSuccess","TempGroup.php".hReturnEcmsHashStrHref2(1));
}

//替換模板組存放格式
function ReplaceLoadTGTemp($pageexp,$record,$field,$text){
	$text=str_replace($pageexp,"",$text);
	$text=str_replace($record,"",$text);
	$text=str_replace($field,"",$text);
	return $text;
}

//標籤模板
function LoadTGBqtemp($gid,$en,$pageexp,$record,$field){
	global $empire,$dbtbpre;
	$tb=$dbtbpre."enewsbqtemp".$en;
	$sql=$empire->query("select * from ".$tb." order by tempid");
	$classid=0;
	while($r=$empire->fetch($sql))
	{
		$r['temptext']=ReplaceLoadTGTemp($pageexp,$record,$field,$r['temptext']);
		$r['listvar']=ReplaceLoadTGTemp($pageexp,$record,$field,$r['listvar']);
		$text.=$r['tempid'].$field.$r['tempname'].$field.$r['modid'].$field.$r['temptext'].$field.$r['showdate'].$field.$r['listvar'].$field.$r['subnews'].$field.$r['rownum'].$field.$classid.$field.$r['docode'].$record;
	}
	return $text;
}

function LoadInTGBqtemp($gid,$en,$record,$field,$text){
	global $empire,$dbtbpre;
	if(empty($text))
	{
		return "";
	}
	$tb=$dbtbpre."enewsbqtemp".$en;
	$rr=explode($record,$text);
	$count=count($rr);
	for($i=0;$i<$count-1;$i++)
	{
		$r=explode($field,$rr[$i]);
		$sql=$empire->query("insert into ".$tb."(tempid,tempname,modid,temptext,showdate,listvar,subnews,rownum,classid,docode) values('$r[0]','".addslashes($r[1])."','$r[2]','".addslashes(addslashes($r[3]))."','".addslashes($r[4])."','".addslashes(addslashes($r[5]))."','$r[6]','$r[7]','$r[8]','$r[9]');");
	}
}

//JS模板
function LoadTGJstemp($gid,$en,$pageexp,$record,$field){
	global $empire,$dbtbpre;
	$tb=$dbtbpre."enewsjstemp".$en;
	$sql=$empire->query("select * from ".$tb." order by tempid");
	$classid=0;
	while($r=$empire->fetch($sql))
	{
		$r['temptext']=ReplaceLoadTGTemp($pageexp,$record,$field,$r['temptext']);
		$text.=$r['tempid'].$field.$r['tempname'].$field.$r['temptext'].$field.$classid.$field.$r['isdefault'].$field.$r['showdate'].$field.$r['modid'].$field.$r['subnews'].$field.$r['subtitle'].$record;
	}
	return $text;
}

function LoadInTGJstemp($gid,$en,$record,$field,$text){
	global $empire,$dbtbpre;
	if(empty($text))
	{
		return "";
	}
	$tb=$dbtbpre."enewsjstemp".$en;
	$rr=explode($record,$text);
	$count=count($rr);
	for($i=0;$i<$count-1;$i++)
	{
		$r=explode($field,$rr[$i]);
		if(empty($r[6]))
		{
			$r[6]=1;
		}
		$sql=$empire->query("insert into ".$tb."(tempid,tempname,temptext,classid,isdefault,showdate,modid,subnews,subtitle) values('$r[0]','".addslashes($r[1])."','".addslashes(addslashes($r[2]))."','$r[3]','$r[4]','".addslashes($r[5])."','$r[6]','$r[7]','$r[8]');");
	}
}

//列表模板
function LoadTGListtemp($gid,$en,$pageexp,$record,$field){
	global $empire,$dbtbpre;
	$tb=$dbtbpre."enewslisttemp".$en;
	$sql=$empire->query("select * from ".$tb." order by tempid");
	$classid=0;
	while($r=$empire->fetch($sql))
	{
		$r['temptext']=ReplaceLoadTGTemp($pageexp,$record,$field,$r['temptext']);
		$r['listvar']=ReplaceLoadTGTemp($pageexp,$record,$field,$r['listvar']);
		$text.=$r['tempid'].$field.$r['tempname'].$field.$r['temptext'].$field.$r['subnews'].$field.$r['isdefault'].$field.$r['listvar'].$field.$r['rownum'].$field.$r['modid'].$field.$r['showdate'].$field.$r['subtitle'].$field.$classid.$field.$r['docode'].$record;
	}
	return $text;
}

function LoadInTGListtemp($gid,$en,$record,$field,$text){
	global $empire,$dbtbpre;
	if(empty($text))
	{
		return "";
	}
	$tb=$dbtbpre."enewslisttemp".$en;
	$rr=explode($record,$text);
	$count=count($rr);
	for($i=0;$i<$count-1;$i++)
	{
		$r=explode($field,$rr[$i]);
		$sql=$empire->query("insert into ".$tb."(tempid,tempname,temptext,subnews,isdefault,listvar,rownum,modid,showdate,subtitle,classid,docode) values('$r[0]','".addslashes($r[1])."','".addslashes(addslashes($r[2]))."','$r[3]','$r[4]','".addslashes(addslashes($r[5]))."','$r[6]','$r[7]','".addslashes($r[8])."','$r[9]','$r[10]','$r[11]');");
	}
}

//內容模板
function LoadTGNewstemp($gid,$en,$pageexp,$record,$field){
	global $empire,$dbtbpre;
	$tb=$dbtbpre."enewsnewstemp".$en;
	$sql=$empire->query("select * from ".$tb." order by tempid");
	$classid=0;
	while($r=$empire->fetch($sql))
	{
		$r['temptext']=ReplaceLoadTGTemp($pageexp,$record,$field,$r['temptext']);
		$text.=$r['tempid'].$field.$r['tempname'].$field.$r['isdefault'].$field.$r['temptext'].$field.$r['showdate'].$field.$r['modid'].$field.$classid.$record;
	}
	return $text;
}

function LoadInTGNewstemp($gid,$en,$record,$field,$text){
	global $empire,$dbtbpre;
	if(empty($text))
	{
		return "";
	}
	$text=RepTemplateJsUrl($text,1,0);//替換JS地址
	$tb=$dbtbpre."enewsnewstemp".$en;
	$rr=explode($record,$text);
	$count=count($rr);
	for($i=0;$i<$count-1;$i++)
	{
		$r=explode($field,$rr[$i]);
		$sql=$empire->query("insert into ".$tb."(tempid,tempname,isdefault,temptext,showdate,modid,classid) values('$r[0]','".addslashes($r[1])."','$r[2]','".addslashes(addslashes($r[3]))."','".addslashes($r[4])."','$r[5]','$r[6]');");
	}
}

//公共模板
function LoadTGPubtemp($gid,$en,$pageexp,$record,$field){
	global $empire,$dbtbpre;
	$tb=$dbtbpre."enewspubtemp".$en;
	$r=$empire->fetch1("select * from ".$tb." limit 1");
	$r['indextemp']=ReplaceLoadTGTemp($pageexp,$record,$field,$r['indextemp']);
	$r['cptemp']=ReplaceLoadTGTemp($pageexp,$record,$field,$r['cptemp']);
	$r['searchtemp']=ReplaceLoadTGTemp($pageexp,$record,$field,$r['searchtemp']);
	$r['searchjstemp']=ReplaceLoadTGTemp($pageexp,$record,$field,$r['searchjstemp']);
	$r['searchjstemp1']=ReplaceLoadTGTemp($pageexp,$record,$field,$r['searchjstemp1']);
	$r['otherlinktemp']=ReplaceLoadTGTemp($pageexp,$record,$field,$r['otherlinktemp']);
	$r['downsofttemp']=ReplaceLoadTGTemp($pageexp,$record,$field,$r['downsofttemp']);
	$r['onlinemovietemp']=ReplaceLoadTGTemp($pageexp,$record,$field,$r['onlinemovietemp']);
	$r['listpagetemp']=ReplaceLoadTGTemp($pageexp,$record,$field,$r['listpagetemp']);
	$r['gbooktemp']=ReplaceLoadTGTemp($pageexp,$record,$field,$r['gbooktemp']);
	$r['loginiframe']=ReplaceLoadTGTemp($pageexp,$record,$field,$r['loginiframe']);
	$r['loginjstemp']=ReplaceLoadTGTemp($pageexp,$record,$field,$r['loginjstemp']);
	$r['downpagetemp']=ReplaceLoadTGTemp($pageexp,$record,$field,$r['downpagetemp']);
	$r['pljstemp']=ReplaceLoadTGTemp($pageexp,$record,$field,$r['pljstemp']);
	$r['schalltemp']=ReplaceLoadTGTemp($pageexp,$record,$field,$r['schalltemp']);
	$text.=$r['id'].$field.$r['indextemp'].$field.''.$field.$r['cptemp'].$field.$r['searchtemp'].$field.$r['searchjstemp'].$field.$r['searchjstemp1'].$field.$r['otherlinktemp'].$field.''.$field.$r['downsofttemp'].$field.$r['onlinemovietemp'].$field.$r['listpagetemp'].$field.$r['gbooktemp'].$field.$r['loginiframe'].$field.$r['otherlinktempsub'].$field.$r['otherlinktempdate'].$field.$r['loginjstemp'].$field.$r['downpagetemp'].$field.$r['pljstemp'].$field.$r['schalltemp'].$field.$r['schallsubnum'].$field.$r['schalldate'].$record;
	return $text;
}

function LoadInTGPubtemp($gid,$en,$record,$field,$text,$isold=0){
	global $empire,$dbtbpre,$fun_r;
	if(empty($text))
	{
		return "";
	}
	$tb=$dbtbpre."enewspubtemp".$en;
	$rr=explode($record,$text);
	$r=explode($field,$rr[0]);
	//相關鏈接設置
	if(empty($r[14]))
	{
		$r[14]=30;
	}
	if(empty($r[15]))
	{
		$r[15]='Y-m-d H:i:s';
	}
	if(empty($r[21]))
	{
		$r[21]='Y-m-d H:i:s';
	}
	//替換舊地址
	if(empty($GLOBALS['loadtempver']))
	{
		//登錄狀態模板
		$r[13]=LoadInTGReptext_othervar($r[13],'member');
		$r[16]=LoadInTGReptext_othervar($r[16],'member');
		//評論
		$r[18]=LoadInTGReptext_othervar($r[18],'pl');
	}
	$sql=$empire->query("insert into ".$tb."(id,indextemp,cptemp,searchtemp,searchjstemp,searchjstemp1,otherlinktemp,downsofttemp,onlinemovietemp,listpagetemp,gbooktemp,loginiframe,otherlinktempsub,otherlinktempdate,loginjstemp,downpagetemp,pljstemp,schalltemp,schallsubnum,schalldate) values('$r[0]','".addslashes(addslashes($r[1]))."','".addslashes(addslashes($r[3]))."','".addslashes(addslashes($r[4]))."','".addslashes(addslashes($r[5]))."','".addslashes(addslashes($r[6]))."','".addslashes(addslashes($r[7]))."','".addslashes(addslashes($r[9]))."','".addslashes(addslashes($r[10]))."','".addslashes(addslashes($r[11]))."','".addslashes(addslashes($r[12]))."','".addslashes(addslashes($r[13]))."','$r[14]','$r[15]','".addslashes(addslashes($r[16]))."','".addslashes(addslashes($r[17]))."','".addslashes(addslashes($r[18]))."','".addslashes(addslashes($r[19]))."','$r[20]','$r[21]');");
	//5.1以下版本
	if($isold==1&&$r[2])
	{
		$pltb=$dbtbpre."enewspltemp".$en;
		$pltempname=$fun_r['PlListTempname'];
		//替換舊地址
		if(empty($GLOBALS['loadtempver']))
		{
			$r[2]=LoadInTGReptext_othervar($r[2],'pl');
		}
		$empire->query("insert into ".$pltb."(tempid,tempname,temptext,isdefault) values(NULL,'".addslashes($pltempname)."','".addslashes(addslashes($r[2]))."',1);");
	}
	//6.0以下版本
	if(($isold==1||$isold==2)&&$r[8])
	{
		$printtb=$dbtbpre."enewsprinttemp".$en;
		$printtempname=$fun_r['PrintTempname'];
		$empire->query("insert into ".$printtb."(tempid,tempname,temptext,isdefault,showdate,modid) values(NULL,'".addslashes($printtempname)."','".addslashes(addslashes($r[8]))."',1,'Y-m-d H:i:s',1);");
	}
}

//搜索模板
function LoadTGSearchtemp($gid,$en,$pageexp,$record,$field){
	global $empire,$dbtbpre;
	$tb=$dbtbpre."enewssearchtemp".$en;
	$sql=$empire->query("select * from ".$tb." order by tempid");
	$classid=0;
	while($r=$empire->fetch($sql))
	{
		$r['temptext']=ReplaceLoadTGTemp($pageexp,$record,$field,$r['temptext']);
		$r['listvar']=ReplaceLoadTGTemp($pageexp,$record,$field,$r['listvar']);
		$text.=$r['tempid'].$field.$r['tempname'].$field.$r['temptext'].$field.$r['subnews'].$field.$r['isdefault'].$field.$r['listvar'].$field.$r['rownum'].$field.$r['modid'].$field.$r['showdate'].$field.$r['subtitle'].$field.$classid.$field.$r['docode'].$record;
	}
	return $text;
}

function LoadInTGSearchtemp($gid,$en,$record,$field,$text){
	global $empire,$dbtbpre;
	if(empty($text))
	{
		return "";
	}
	$tb=$dbtbpre."enewssearchtemp".$en;
	$rr=explode($record,$text);
	$count=count($rr);
	for($i=0;$i<$count-1;$i++)
	{
		$r=explode($field,$rr[$i]);
		$sql=$empire->query("insert into ".$tb."(tempid,tempname,temptext,subnews,isdefault,listvar,rownum,modid,showdate,subtitle,classid,docode) values('$r[0]','".addslashes($r[1])."','".addslashes(addslashes($r[2]))."','$r[3]','$r[4]','".addslashes(addslashes($r[5]))."','$r[6]','$r[7]','".addslashes($r[8])."','$r[9]','$r[10]','$r[11]');");
	}
}

//模板變量
function LoadTGTempvar($gid,$en,$pageexp,$record,$field){
	global $empire,$dbtbpre;
	$tb=$dbtbpre."enewstempvar".$en;
	$sql=$empire->query("select * from ".$tb." order by varid");
	$classid=0;
	while($r=$empire->fetch($sql))
	{
		$r['varvalue']=ReplaceLoadTGTemp($pageexp,$record,$field,$r['varvalue']);
		$text.=$r['varid'].$field.$r['myvar'].$field.$r['varname'].$field.$r['varvalue'].$field.$classid.$field.$r['isclose'].$field.$r['myorder'].$record;
	}
	return $text;
}

function LoadInTGTempvar($gid,$en,$record,$field,$text){
	global $empire,$dbtbpre;
	if(empty($text))
	{
		return "";
	}
	$tb=$dbtbpre."enewstempvar".$en;
	$rr=explode($record,$text);
	$count=count($rr);
	for($i=0;$i<$count-1;$i++)
	{
		$r=explode($field,$rr[$i]);
		//評論變量
		if(!$GLOBALS['loadtempver']&&$r[1]=='pl')
		{
			$r[3]=LoadInTGReptext_othervar($r[3],'pl');
		}
		$sql=$empire->query("insert into ".$tb."(varid,myvar,varname,varvalue,classid,isclose,myorder) values('$r[0]','".addslashes($r[1])."','".addslashes($r[2])."','".addslashes(addslashes($r[3]))."','$r[4]','$r[5]','$r[6]');");
	}
}

//投票模板
function LoadTGVotetemp($gid,$en,$pageexp,$record,$field){
	global $empire,$dbtbpre;
	$tb=$dbtbpre."enewsvotetemp".$en;
	$sql=$empire->query("select * from ".$tb." order by tempid");
	$classid=0;
	while($r=$empire->fetch($sql))
	{
		$r['temptext']=ReplaceLoadTGTemp($pageexp,$record,$field,$r['temptext']);
		$text.=$r['tempid'].$field.$r['tempname'].$field.$r['temptext'].$record;
	}
	return $text;
}

function LoadInTGVotetemp($gid,$en,$record,$field,$text){
	global $empire,$dbtbpre;
	if(empty($text))
	{
		return "";
	}
	$tb=$dbtbpre."enewsvotetemp".$en;
	$rr=explode($record,$text);
	$count=count($rr);
	for($i=0;$i<$count-1;$i++)
	{
		$r=explode($field,$rr[$i]);
		$sql=$empire->query("insert into ".$tb."(tempid,tempname,temptext) values('$r[0]','".addslashes($r[1])."','".addslashes(addslashes($r[2]))."');");
	}
}

//欄目封面模板
function LoadTGClasstemp($gid,$en,$pageexp,$record,$field){
	global $empire,$dbtbpre;
	$tb=$dbtbpre."enewsclasstemp".$en;
	$sql=$empire->query("select * from ".$tb." order by tempid");
	$classid=0;
	while($r=$empire->fetch($sql))
	{
		$r['temptext']=ReplaceLoadTGTemp($pageexp,$record,$field,$r['temptext']);
		$text.=$r['tempid'].$field.$r['tempname'].$field.$r['temptext'].$field.$classid.$record;
	}
	return $text;
}

function LoadInTGClasstemp($gid,$en,$record,$field,$text){
	global $empire,$dbtbpre;
	if(empty($text))
	{
		return "";
	}
	$tb=$dbtbpre."enewsclasstemp".$en;
	$rr=explode($record,$text);
	$count=count($rr);
	for($i=0;$i<$count-1;$i++)
	{
		$r=explode($field,$rr[$i]);
		$sql=$empire->query("insert into ".$tb."(tempid,tempname,temptext,classid) values('$r[0]','".addslashes($r[1])."','".addslashes(addslashes($r[2]))."','$r[3]');");
	}
}

//評論列表模板
function LoadTGPltemp($gid,$en,$pageexp,$record,$field){
	global $empire,$dbtbpre;
	$tb=$dbtbpre."enewspltemp".$en;
	$sql=$empire->query("select * from ".$tb." order by tempid");
	while($r=$empire->fetch($sql))
	{
		$r['temptext']=ReplaceLoadTGTemp($pageexp,$record,$field,$r['temptext']);
		$text.=$r['tempid'].$field.$r['tempname'].$field.$r['temptext'].$field.$r['isdefault'].$record;
	}
	return $text;
}

function LoadInTGPltemp($gid,$en,$record,$field,$text){
	global $empire,$dbtbpre;
	if(empty($text))
	{
		return "";
	}
	$tb=$dbtbpre."enewspltemp".$en;
	$rr=explode($record,$text);
	$count=count($rr);
	for($i=0;$i<$count-1;$i++)
	{
		$r=explode($field,$rr[$i]);
		//替換舊地址
		if(empty($GLOBALS['loadtempver']))
		{
			$r[2]=LoadInTGReptext_othervar($r[2],'pl');
		}
		$sql=$empire->query("insert into ".$tb."(tempid,tempname,temptext,isdefault) values('$r[0]','".addslashes($r[1])."','".addslashes(addslashes($r[2]))."','$r[3]');");
	}
}

//打印模板
function LoadTGPrinttemp($gid,$en,$pageexp,$record,$field){
	global $empire,$dbtbpre;
	$tb=$dbtbpre."enewsprinttemp".$en;
	$sql=$empire->query("select * from ".$tb." order by tempid");
	while($r=$empire->fetch($sql))
	{
		$r['temptext']=ReplaceLoadTGTemp($pageexp,$record,$field,$r['temptext']);
		$text.=$r['tempid'].$field.$r['tempname'].$field.$r['temptext'].$field.$r['isdefault'].$field.$r['showdate'].$field.$r['modid'].$record;
	}
	return $text;
}

function LoadInTGPrinttemp($gid,$en,$record,$field,$text){
	global $empire,$dbtbpre;
	if(empty($text))
	{
		return "";
	}
	$tb=$dbtbpre."enewsprinttemp".$en;
	$rr=explode($record,$text);
	$count=count($rr);
	for($i=0;$i<$count-1;$i++)
	{
		$r=explode($field,$rr[$i]);
		$sql=$empire->query("insert into ".$tb."(tempid,tempname,temptext,isdefault,showdate,modid) values('$r[0]','".addslashes($r[1])."','".addslashes(addslashes($r[2]))."','$r[3]','".addslashes($r[4])."','$r[5]');");
	}
}

//自定義頁面模板
function LoadTGPagetemp($gid,$en,$pageexp,$record,$field){
	global $empire,$dbtbpre;
	$tb=$dbtbpre."enewspagetemp".$en;
	$sql=$empire->query("select * from ".$tb." order by tempid");
	$classid=0;
	while($r=$empire->fetch($sql))
	{
		$r['temptext']=ReplaceLoadTGTemp($pageexp,$record,$field,$r['temptext']);
		$text.=$r['tempid'].$field.$r['tempname'].$field.$r['temptext'].$record;
	}
	return $text;
}

function LoadInTGPagetemp($gid,$en,$record,$field,$text){
	global $empire,$dbtbpre;
	if(empty($text))
	{
		return "";
	}
	$tb=$dbtbpre."enewspagetemp".$en;
	$rr=explode($record,$text);
	$count=count($rr);
	for($i=0;$i<$count-1;$i++)
	{
		$r=explode($field,$rr[$i]);
		$sql=$empire->query("insert into ".$tb."(tempid,tempname,temptext) values('$r[0]','".addslashes($r[1])."','".addslashes(addslashes($r[2]))."');");
	}
}

//----------------------備份模板-------------------

//刪除多餘備份記錄
function DelEBakTemp($temptype,$gid,$tempid){
	global $empire,$dbtbpre;
	$pr=$empire->fetch1("select baktempnum from {$dbtbpre}enewspublic limit 1");
	if(!$pr['baktempnum'])
	{
		return $pr;
	}
	$num=$empire->gettotal("select count(*) as total from {$dbtbpre}enewstempbak where temptype='$temptype' and gid='$gid' and tempid='$tempid'");
	if($num+1>$pr['baktempnum'])
	{
		$limitnum=$num+1-$pr['baktempnum'];
		$ids='';
		$dh='';
		$sql=$empire->query("select bid from {$dbtbpre}enewstempbak where temptype='$temptype' and gid='$gid' and tempid='$tempid' order by bid limit ".$limitnum);
		while($r=$empire->fetch($sql))
		{
			$ids.=$dh.$r['bid'];
			$dh=',';
		}
		$empire->query("delete from {$dbtbpre}enewstempbak where bid in ($ids)");
	}
	return $pr;
}

//刪除所有備份記錄
function DelEbakTempAll($temptype,$gid,$tempid){
	global $empire,$dbtbpre;
	$tempid=(int)$tempid;
	$gid=(int)$gid;
	if(!$gid)
	{
		$gid=GetDoTempGid();
	}
	if($temptype=='indexpage')
	{
		$gid=1;
	}
	$empire->query("delete from {$dbtbpre}enewstempbak where temptype='$temptype' and gid='$gid' and tempid='$tempid'");
}

//模板備份記錄
function AddEBakTemp($temptype,$gid,$tempid,$tempname,$temptext,$subnews,$isdefault,$listvar,$rownum,$modid,$showdate,$subtitle,$classid,$docode,$userid,$username){
	global $empire,$dbtbpre;
	$tempid=(int)$tempid;
	$gid=(int)$gid;
	if(!$gid)
	{
		$gid=GetDoTempGid();
	}
	if($temptype=='indexpage')
	{
		$gid=1;
	}
	$pr=DelEBakTemp($temptype,$gid,$tempid);
	if(!$pr['baktempnum'])
	{
		return '';
	}
	$subnews=(int)$subnews;
	$isdefault=(int)$isdefault;
	$rownum=(int)$rownum;
	$modid=(int)$modid;
	$subtitle=(int)$subtitle;
	$classid=(int)$classid;
	$docode=(int)$docode;
	$baktime=time();
	$empire->query("insert into {$dbtbpre}enewstempbak(tempid,tempname,temptext,subnews,isdefault,listvar,rownum,modid,showdate,subtitle,classid,docode,baktime,temptype,gid,lastuser) values('$tempid','".eaddslashes($tempname)."','".eaddslashes2($temptext)."','$subnews','$isdefault','".eaddslashes2($listvar)."','$rownum','$modid','".eaddslashes($showdate)."','$subtitle','$classid','$docode','$baktime','$temptype','$gid','$username');");
}

//還原模板備份
function ReEBakTemp($add,$userid,$username){
	global $empire,$dbtbpre;
	$bid=(int)$add['bid'];
	if(!$bid)
	{
		printerror("NotBakTemp","history.go(-1)");
	}
	$r=$empire->fetch1("select * from {$dbtbpre}enewstempbak where bid='$bid'");
	if(!$r['bid'])
	{
		printerror("NotBakTemp","history.go(-1)");
	}
	//操作權限
	if($r['temptype']=='tempvar')
	{
		CheckLevel($userid,$username,$classid,"tempvar");
	}
	else
	{
		CheckLevel($userid,$username,$classid,"template");
	}
	$gid=(int)$r['gid'];
	if(!$gid)
	{
		$gid=GetDoTempGid();
	}
	if($temptype=='indexpage')
	{
		$gid=1;
	}
	if($r['temptype']=='bqtemp')//標籤模板
	{
		$sql=$empire->query("update ".GetDoTemptb("enewsbqtemp",$gid)." set tempname='".StripAddsData($r[tempname])."',temptext='".addslashes($r[temptext])."',modid='$r[modid]',showdate='".StripAddsData($r[showdate])."',listvar='".addslashes($r[listvar])."',subnews='$r[subnews]',rownum='$r[rownum]',classid='$r[classid]',docode='$r[docode]' where tempid='$r[tempid]'");
	}
	elseif($r['temptype']=='classtemp')//封面模板
	{
		$sql=$empire->query("update ".GetDoTemptb("enewsclasstemp",$gid)." set tempname='".StripAddsData($r[tempname])."',temptext='".addslashes($r[temptext])."',classid='$r[classid]' where tempid='$r[tempid]'");
	}
	elseif($r['temptype']=='jstemp')//JS模板
	{
		$sql=$empire->query("update ".GetDoTemptb("enewsjstemp",$gid)." set tempname='".StripAddsData($r[tempname])."',temptext='".addslashes($r[temptext])."',classid='$r[classid]',showdate='".StripAddsData($r[showdate])."',modid='$r[modid]',subnews='$r[subnews]',subtitle='$r[subtitle]' where tempid='$r[tempid]'");
	}
	elseif($r['temptype']=='listtemp')//列表模板
	{
		$sql=$empire->query("update ".GetDoTemptb("enewslisttemp",$gid)." set subnews='$r[subnews]',tempname='".StripAddsData($r[tempname])."',temptext='".addslashes($r[temptext])."',listvar='".addslashes($r[listvar])."',rownum='$r[rownum]',modid='$r[modid]',showdate='".StripAddsData($r[showdate])."',subtitle='$r[subtitle]',classid='$r[classid]',docode='$r[docode]' where tempid='$r[tempid]'");
	}
	elseif($r['temptype']=='newstemp')//內容模板
	{
		$sql=$empire->query("update ".GetDoTemptb("enewsnewstemp",$gid)." set tempname='".StripAddsData($r[tempname])."',temptext='".addslashes($r[temptext])."',showdate='".StripAddsData($r[showdate])."',modid='$r[modid]',classid='$r[classid]' where tempid='$r[tempid]'");
	}
	elseif($r['temptype']=='pltemp')//評論模板
	{
		$sql=$empire->query("update ".GetDoTemptb("enewspltemp",$gid)." set tempname='".StripAddsData($r[tempname])."',temptext='".addslashes($r[temptext])."' where tempid='$r[tempid]'");
	}
	elseif($r['temptype']=='printtemp')//打印模板
	{
		$sql=$empire->query("update ".GetDoTemptb("enewsprinttemp",$gid)." set tempname='".StripAddsData($r[tempname])."',temptext='".addslashes($r[temptext])."',showdate='".StripAddsData($r[showdate])."',modid='$r[modid]' where tempid='$r[tempid]'");
	}
	elseif($r['temptype']=='searchtemp')//搜索模板
	{
		$sql=$empire->query("update ".GetDoTemptb("enewssearchtemp",$gid)." set subnews='$r[subnews]',tempname='".StripAddsData($r[tempname])."',temptext='".addslashes($r[temptext])."',listvar='".addslashes($r[listvar])."',rownum='$r[rownum]',modid='$r[modid]',showdate='".StripAddsData($r[showdate])."',subtitle='$r[subtitle]',classid='$r[classid]',docode='$r[docode]' where tempid='$r[tempid]'");
	}
	elseif($r['temptype']=='tempvar')//公共模板變量
	{
		$sql=$empire->query("update ".GetDoTemptb("enewstempvar",$gid)." set myvar='".StripAddsData($r[tempname])."',varname='".StripAddsData($r[listvar])."',varvalue='".addslashes($r[temptext])."',classid='$r[classid]',isclose='$r[docode]',myorder='$r[subnews]' where varid='$r[tempid]'");
	}
	elseif($r['temptype']=='votetemp')//投票模板
	{
		$sql=$empire->query("update ".GetDoTemptb("enewsvotetemp",$gid)." set tempname='".StripAddsData($r[tempname])."',temptext='".addslashes($r[temptext])."' where tempid='$r[tempid]'");
	}
	elseif($r['temptype']=='pagetemp')//自定義頁面模板
	{
		$sql=$empire->query("update ".GetDoTemptb("enewspagetemp",$gid)." set tempname='".StripAddsData($r[tempname])."',temptext='".addslashes($r[temptext])."' where tempid='$r[tempid]'");
	}
	elseif($r['temptype']=='indexpage')//首頁方案模板
	{
		$sql=$empire->query("update {$dbtbpre}enewsindexpage set tempname='".StripAddsData($r[tempname])."',temptext='".addslashes($r[temptext])."' where tempid='$r[tempid]'");
	}
	//公共模板
	elseif($r['temptype']=='pubindextemp')//首頁模板
	{
		$sql=$empire->query("update ".GetDoTemptb("enewspubtemp",$gid)." set indextemp='".addslashes($r[temptext])."' limit 1");
	}
	elseif($r['temptype']=='pubcptemp')//控制面板模板
	{
		$sql=$empire->query("update ".GetDoTemptb("enewspubtemp",$gid)." set cptemp='".addslashes($r[temptext])."' limit 1");
	}
	elseif($r['temptype']=='pubsearchtemp')//高級搜索表單模板
	{
		$sql=$empire->query("update ".GetDoTemptb("enewspubtemp",$gid)." set searchtemp='".addslashes($r[temptext])."' limit 1");
	}
	elseif($r['temptype']=='pubsearchjstemp')//搜索JS模板[橫向]
	{
		$sql=$empire->query("update ".GetDoTemptb("enewspubtemp",$gid)." set searchjstemp='".addslashes($r[temptext])."' limit 1");
	}
	elseif($r['temptype']=='pubsearchjstemp1')//搜索JS模板[縱向]
	{
		$sql=$empire->query("update ".GetDoTemptb("enewspubtemp",$gid)." set searchjstemp1='".addslashes($r[temptext])."' limit 1");
	}
	elseif($r['temptype']=='pubotherlinktemp')//相關鏈接模板
	{
		$sql=$empire->query("update ".GetDoTemptb("enewspubtemp",$gid)." set otherlinktemp='".addslashes($r[temptext])."',otherlinktempsub='$r[subtitle]',otherlinktempdate='".StripAddsData($r[showdate])."' limit 1");
	}
	elseif($r['temptype']=='pubdownsofttemp')//下載地址模板
	{
		$sql=$empire->query("update ".GetDoTemptb("enewspubtemp",$gid)." set downsofttemp='".addslashes($r[temptext])."' limit 1");
	}
	elseif($r['temptype']=='pubonlinemovietemp')//在線播放地址模板
	{
		$sql=$empire->query("update ".GetDoTemptb("enewspubtemp",$gid)." set onlinemovietemp='".addslashes($r[temptext])."' limit 1");
	}
	elseif($r['temptype']=='publistpagetemp')//列表分頁模板
	{
		$sql=$empire->query("update ".GetDoTemptb("enewspubtemp",$gid)." set listpagetemp='".addslashes($r[temptext])."' limit 1");
	}
	elseif($r['temptype']=='pubpljstemp')//評論JS調用模板
	{
		$sql=$empire->query("update ".GetDoTemptb("enewspubtemp",$gid)." set pljstemp='".addslashes($r[temptext])."' limit 1");
	}
	elseif($r['temptype']=='pubdownpagetemp')//最終下載頁模板
	{
		$sql=$empire->query("update ".GetDoTemptb("enewspubtemp",$gid)." set downpagetemp='".addslashes($r[temptext])."' limit 1");
	}
	elseif($r['temptype']=='pubgbooktemp')//留言板模板
	{
		$sql=$empire->query("update ".GetDoTemptb("enewspubtemp",$gid)." set gbooktemp='".addslashes($r[temptext])."' limit 1");
	}
	elseif($r['temptype']=='publoginiframe')//登陸狀態模板
	{
		$sql=$empire->query("update ".GetDoTemptb("enewspubtemp",$gid)." set loginiframe='".addslashes($r[temptext])."' limit 1");
	}
	elseif($r['temptype']=='publoginjstemp')//JS調用登陸狀態模板
	{
		$sql=$empire->query("update ".GetDoTemptb("enewspubtemp",$gid)." set loginjstemp='".addslashes($r[temptext])."' limit 1");
	}
	elseif($r['temptype']=='pubschalltemp')//全站搜索模板
	{
		$sql=$empire->query("update ".GetDoTemptb("enewspubtemp",$gid)." set schalltemp='".addslashes($r[temptext])."',schallsubnum='$r[subnews]',schalldate='".StripAddsData($r[showdate])."' limit 1");
	}
	if($sql)
	{
		//操作日誌
		insert_dolog("bid=$bid&temptype=$r[temptype]<br>tempid=$r[tempid]&tempname=$r[tempname]&gid=$r[gid]");
		echo"<script>opener.ReTempBak();window.close();</script>";
		exit();
	}
	else
	{printerror("DbError","history.go(-1)");}
}
?>