国内流行的内容管理系统(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.

mychannel_field_edit.php 5.4KB

2 年之前
1 年之前
2 年之前
2 年之前
2 年之前
2 年之前
2 年之前
2 年之前
2 年之前
2 年之前
2 年之前
2 年之前
2 年之前
2 年之前
2 年之前
2 年之前
2 年之前
2 年之前
2 年之前
2 年之前
2 年之前
1 年之前
2 年之前
2 年之前
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <?php
  2. /**
  3. * 自定义模型字段修改
  4. *
  5. * @version $id:mychannel_field_edit.php 15:22 2010年7月20日 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. CheckPurview('c_New');
  13. require_once(DEDEINC."/dedetag.class.php");
  14. require_once(dirname(__FILE__)."/inc/inc_admin_channel.php");
  15. if (empty($action)) $action = '';
  16. $id = isset($id) && is_numeric($id) ? $id : 0;
  17. $mysql_version = $dsql->GetVersion();
  18. //获取模型信息
  19. $row = $dsql->GetOne("SELECT fieldset,'' as maintable,addtable,issystem FROM `#@__channeltype` WHERE id='$id'");
  20. $fieldset = stripslashes($row['fieldset']);
  21. $trueTable = $row['addtable'];
  22. $dtp = new DedeTagParse();
  23. $dtp->SetNameSpace("field", "<", ">");
  24. $dtp->LoadSource($fieldset);
  25. foreach ($dtp->CTags as $ctag) {
  26. if (strtolower($ctag->GetName()) == strtolower($fname)) break;
  27. }
  28. //字段类型信息
  29. $ds = file(dirname(__FILE__)."/inc/fieldtype.txt");
  30. foreach ($ds as $d) {
  31. $dds = explode(',', trim($d));
  32. $fieldtypes[$dds[0]] = $dds[1];
  33. }
  34. //获取栏目模型
  35. $dsql->SetQuery("SELECT id,typename,nid FROM `#@__channeltype` WHERE id<>-1 AND isshow=1 ORDER BY id");
  36. $dsql->Execute();
  37. while ($crow = $dsql->GetObject()) {
  38. $channelArray[$crow->id]['typename'] = $crow->typename;
  39. $channelArray[$crow->id]['nid'] = $crow->nid;
  40. }
  41. //保存修改
  42. /*--------------------
  43. function _SAVE()
  44. ----------------------*/
  45. if ($action == 'save') {
  46. if (!isset($fieldtypes[$dtype])) {
  47. ShowMsg("您修改的是系统专用类型的数据,禁止操作", "-1");
  48. exit();
  49. }
  50. $dfvalue = $vdefault;
  51. if (preg_match("#^(select|radio|checkbox)#", $dtype)) {
  52. if (!preg_match("#,#", $dfvalue)) {
  53. ShowMsg("您设定了字段为<span class='text-primary'>{$dtype}</span>类型,必须在默认值中指定元素列表,如:'a,b,c' ", "-1");
  54. exit();
  55. }
  56. }
  57. if ($dtype == 'stepselect') {
  58. $arr = $dsql->GetOne("SELECT * FROM `#@__stepselect` WHERE egroup='$fname' ");
  59. if (!is_array($arr)) {
  60. ShowMsg("您设定了字段为联动类型,但系统中没找到与您定义的字段名相同的联动组名", "-1");
  61. exit();
  62. }
  63. }
  64. //检测数据库是否存在附加表,不存在则新建一个
  65. $tabsql = "CREATE TABLE IF NOT EXISTS `{$row['addtable']}`( `aid` int(11) NOT NULL default '0',\r\n `typeid` int(11) NOT NULL default '0',\r\n ";
  66. if ($mysql_version < 4.1) {
  67. $tabsql .= " PRIMARY KEY (`aid`), KEY `".$trueTable."_index` (`typeid`)\r\n) TYPE=MyISAM; ";
  68. } else {
  69. $tabsql .= " PRIMARY KEY (`aid`), KEY `".$trueTable."_index` (`typeid`)\r\n) ENGINE=MyISAM DEFAULT CHARSET=".$cfg_db_language."; ";
  70. }
  71. $dsql->ExecuteNoneQuery($tabsql);
  72. //检测附加表里含有的字段
  73. $fields = array();
  74. $rs = $dsql->SetQuery("SHOW fields FROM `{$row['addtable']}`");
  75. $dsql->Execute('a');
  76. while ($nrow = $dsql->GetArray('a', MYSQL_ASSOC)) {
  77. $fields[strtolower($nrow['Field'])] = $nrow['Type'];
  78. }
  79. //修改字段配置信息
  80. $isnull = ($isnull == 1 ? "true" : "false");
  81. $mxlen = $maxlength;
  82. $fieldname = strtolower($fname);
  83. //检测被修改的字段类型,并更新数据表
  84. $fieldinfos = GetFieldMake($dtype, $fieldname, $dfvalue, $mxlen);
  85. $ntabsql = $fieldinfos[0];
  86. $buideType = $fieldinfos[1];
  87. $tabsql = '';
  88. //检测旧数据类型,并替换为新配置
  89. foreach ($dtp->CTags as $tagid => $ctag) {
  90. if ($fieldname == strtolower($ctag->GetName())) {
  91. if (isset($fields[$fieldname]) && $fields[$fieldname] != $buideType) {
  92. $tabsql = "ALTER TABLE `$trueTable` CHANGE `$fieldname` ".$ntabsql;
  93. $dsql->ExecuteNoneQuery($tabsql);
  94. } else if (!isset($fields[$fieldname])) {
  95. $tabsql = "ALTER TABLE `$trueTable` ADD ".$ntabsql;
  96. $dsql->ExecuteNoneQuery($tabsql);
  97. } else {
  98. $tabsql = '';
  99. }
  100. $dtp->Assign($tagid, stripslashes($fieldstring), false);
  101. break;
  102. }
  103. }
  104. $oksetting = $dtp->GetResultNP();
  105. $addlist = GetAddFieldList($dtp, $oksetting);
  106. $oksetting = addslashes($oksetting);
  107. $dsql->ExecuteNoneQuery("UPDATE `#@__channeltype` SET fieldset='$oksetting',listfields='$addlist' WHERE id='$id' ");
  108. ShowMsg("成功修改一个字段的配置", "mychannel_edit.php?id={$id}&dopost=edit&openfield=1");
  109. exit();
  110. }
  111. /*------------------
  112. 删除字段
  113. function _DELETE()
  114. -------------------*/
  115. else if ($action == "delete") {
  116. if ($row['issystem'] == 1) {
  117. ShowMsg("系统模型的字段不允许删除", "-1");
  118. exit();
  119. }
  120. //检测旧数据类型,并替换为新配置
  121. foreach ($dtp->CTags as $tagid => $ctag) {
  122. if (strtolower($ctag->GetName()) == strtolower($fname)) {
  123. $dtp->Assign($tagid, "#@Delete@#");
  124. }
  125. }
  126. $oksetting = addslashes($dtp->GetResultNP());
  127. $dsql->ExecuteNoneQuery("UPDATE `#@__channeltype` SET fieldset='$oksetting' WHERE id='$id' ");
  128. $dsql->ExecuteNoneQuery("ALTER TABLE `$trueTable` DROP `$fname` ");
  129. ShowMsg("成功删除一个字段", "mychannel_edit.php?id={$id}&dopost=edit&openfield=1");
  130. exit();
  131. }
  132. require_once(DEDEADMIN."/templets/mychannel_field_edit.htm");
  133. ?>