国内流行的内容管理系统(CMS)多端全媒体解决方案 https://www.dedebiz.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

112 lines
4.2KB

  1. <?php
  2. /**
  3. * 修改自定义表单字段
  4. *
  5. * @version $id:diy_field_edit.php 18:31 2010年7月12日 tianya $
  6. * @package DedeBIZ.Administrator
  7. * @copyright Copyright (c) 2022 DedeBIZ.COM
  8. * @license https://www.dedebiz.com/license
  9. * @link https://www.dedebiz.com
  10. */
  11. require_once(dirname(__FILE__)."/config.php");
  12. //增加权限检查
  13. require_once(DEDEINC."/dedetag.class.php");
  14. require_once(DEDEADMIN."/inc/inc_admin_channel.php");
  15. if (empty($action)) $action = '';
  16. //获取模型信息
  17. $mysql_version = $dsql->GetVersion();
  18. $mysql_versions = explode(".", trim($mysql_version));
  19. $mysql_version = $mysql_versions[0].".".$mysql_versions[1];
  20. $row = $dsql->GetOne("SELECT `table`,`info` FROM `#@__diyforms` WHERE diyid='$diyid'");
  21. $fieldset = stripslashes($row['info']);
  22. $trueTable = $row['table'];
  23. $dtp = new DedeTagParse();
  24. $dtp->SetNameSpace("field", "<", ">");
  25. $dtp->LoadSource($fieldset);
  26. foreach ($dtp->CTags as $ctag) {
  27. if (strtolower($ctag->GetName()) == strtolower($fname)) break;
  28. }
  29. //字段类型信息
  30. $ds = file(DEDEADMIN."/inc/fieldtype.txt");
  31. foreach ($ds as $d) {
  32. $dds = explode(',', trim($d));
  33. $fieldtypes[$dds[0]] = $dds[1];
  34. }
  35. //保存修改
  36. /*--------------------
  37. function _SAVE()
  38. ----------------------*/
  39. if ($action == 'save') {
  40. if (!isset($fieldtypes[$dtype])) {
  41. ShowMsg("您修改的是系统专用类型的数据,禁止操作", "-1");
  42. exit();
  43. }
  44. //检测数据库是否存在附加表,不存在则新建一个
  45. $tabsql = "CREATE TABLE IF NOT EXISTS `$trueTable`(
  46. `id` int(10) unsigned NOT NULL auto_increment,
  47. `ifcheck` tinyint(1) NOT NULL default '0',
  48. ";
  49. if ($mysql_version < 4.1) {
  50. $tabsql .= " PRIMARY KEY (`id`)\r\n) TYPE=MyISAM; ";
  51. } else {
  52. $tabsql .= " PRIMARY KEY (`id`)\r\n) ENGINE=MyISAM DEFAULT CHARSET=".$cfg_db_language."; ";
  53. }
  54. $dsql->ExecuteNoneQuery($tabsql);
  55. //检测表里含有的字段
  56. $fields = array();
  57. $rs = $dsql->SetQuery("show fields from `$trueTable`");
  58. $dsql->Execute('a');
  59. while ($nrow = $dsql->GetArray('a', MYSQL_ASSOC)) {
  60. $fields[strtolower($nrow['Field'])] = $nrow['Type'];
  61. }
  62. //修改字段配置信息
  63. $dfvalue = $vdefault;
  64. $isnull = ($isnull == 1 ? "true" : "false");
  65. $mxlen = $maxlength;
  66. $fieldname = strtolower($fname);
  67. //检测被修改的字段类型,并更新数据表
  68. $fieldinfos = GetFieldMake($dtype, $fieldname, $dfvalue, $mxlen);
  69. $ntabsql = $fieldinfos[0];
  70. $buideType = $fieldinfos[1];
  71. $tabsql = '';
  72. //检测旧数据类型,并替换为新配置
  73. foreach ($dtp->CTags as $tagid => $ctag) {
  74. if (trim($fieldname) == trim(strtolower($ctag->GetName()))) {
  75. if (isset($fields[$fieldname]) && $fields[$fieldname] != $buideType) {
  76. $tabsql = "ALTER TABLE `$trueTable` CHANGE `$fieldname` ".$ntabsql;
  77. $dsql->ExecuteNoneQuery($tabsql);
  78. } else if (!isset($fields[$fieldname])) {
  79. $tabsql = "ALTER TABLE `$trueTable` ADD ".$ntabsql;
  80. $dsql->ExecuteNoneQuery($tabsql);
  81. } else {
  82. $tabsql = '';
  83. }
  84. $dtp->Assign($tagid, stripslashes($fieldstring), FALSE);
  85. break;
  86. }
  87. }
  88. $oksetting = $dtp->GetResultNP();
  89. $oksetting = addslashes($oksetting);
  90. $dsql->ExecuteNoneQuery("UPDATE `#@__diyforms` SET info='$oksetting' WHERE diyid='$diyid' ");
  91. ShowMsg("成功修改一个字段的配置", "diy_edit.php?diyid={$diyid}");
  92. exit();
  93. }
  94. /*------------------
  95. 删除字段
  96. function _DELETE()
  97. -------------------*/
  98. else if ($action == "delete") {
  99. //检测旧数据类型,并替换为新配置
  100. foreach ($dtp->CTags as $tagid => $ctag) {
  101. if (strtolower($ctag->GetName()) == strtolower($fname)) {
  102. $dtp->Assign($tagid, "#@Delete@#");
  103. }
  104. }
  105. $oksetting = addslashes($dtp->GetResultNP());
  106. $dsql->ExecuteNoneQuery("UPDATE `#@__diyforms` SET info='$oksetting' WHERE diyid='$diyid' ");
  107. $dsql->ExecuteNoneQuery("ALTER TABLE `$trueTable` DROP `$fname` ");
  108. ShowMsg("成功删除一个字段", "diy_edit.php?diyid=$diyid");
  109. exit();
  110. }
  111. require_once(DEDEADMIN."/templets/diy_field_edit.htm");
  112. ?>