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

diy_field_add.php 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <?php
  2. /**
  3. * 增加自定义表单字段
  4. *
  5. * @version $Id: diy_field_add.php 1 18:31 2010年7月12日Z tianya $
  6. * @package DedeCMS.Administrator
  7. * @copyright Copyright (c) 2020, 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(DEDEADMIN.'/inc/inc_admin_channel.php');
  14. if(empty($action)) $action = '';
  15. $mysql_version = $dsql->GetVersion();
  16. $mysql_versions = explode(".",trim($mysql_version));
  17. $mysql_version = $mysql_versions[0].".".$mysql_versions[1];
  18. /*----------------------
  19. function Save()
  20. ---------------------*/
  21. if($action=='save')
  22. {
  23. //模型信息
  24. $fieldname = strtolower($fieldname);
  25. $row = $dsql->GetOne("SELECT `table`,`info` FROM #@__diyforms WHERE diyid='$diyid'");
  26. $fieldset = $row['info'];
  27. require_once(DEDEINC."/dedetag.class.php");
  28. $dtp = new DedeTagParse();
  29. $dtp->SetNameSpace("field","<",">");
  30. $dtp->LoadSource($fieldset);
  31. $trueTable = $row['table'];
  32. //修改字段配置信息
  33. $dfvalue = trim($vdefault);
  34. $isnull = ($isnull==1 ? "true" : "false");
  35. $mxlen = $maxlength;
  36. //检测被修改的字段类型
  37. $fieldinfos = GetFieldMake($dtype,$fieldname,$dfvalue,$mxlen);
  38. $ntabsql = $fieldinfos[0];
  39. $buideType = $fieldinfos[1];
  40. $rs = $dsql->ExecuteNoneQuery(" ALTER TABLE `$trueTable` ADD $ntabsql ");
  41. if(!$rs)
  42. {
  43. $gerr = $dsql->GetError();
  44. ShowMsg("增加字段失败,错误提示为:".$gerr,"javascript:;");
  45. exit();
  46. }
  47. $ok = FALSE;
  48. //检测旧配置信息,并替换为新配置
  49. if(is_array($dtp->CTags))
  50. {
  51. //遍历旧配置
  52. foreach($dtp->CTags as $tagid=>$ctag)
  53. {
  54. if($fieldname == strtolower($ctag->GetName()))
  55. {
  56. $dtp->Assign($tagid,stripslashes($fieldstring), FALSE);
  57. $ok = TRUE;
  58. break;
  59. }
  60. }
  61. $oksetting = $ok ? $dtp->GetResultNP() : $fieldset."\n".stripslashes($fieldstring);
  62. }
  63. else
  64. {
  65. //原来的配置为空
  66. $oksetting = $fieldset."\n".stripslashes($fieldstring);
  67. }
  68. $addlist = GetAddFieldList($dtp,$oksetting);
  69. $oksetting = addslashes($oksetting);
  70. $rs = $dsql->ExecuteNoneQuery("Update #@__diyforms set `info`='$oksetting' where diyid='$diyid' ");
  71. if(!$rs)
  72. {
  73. $grr = $dsql->GetError();
  74. ShowMsg("保存节点配置出错!".$grr,"javascript:;");
  75. exit();
  76. }
  77. ShowMsg("成功增加一个字段!","diy_edit.php?diyid=$diyid");
  78. exit();
  79. }
  80. //检测模型相关信息,并初始化相关数据
  81. /*----------------------
  82. function ShowPage()
  83. ---------------------*/
  84. $row = $dsql->GetOne("SELECT `table` FROM #@__diyforms WHERE diyid='$diyid'");
  85. $trueTable = $row['table'];
  86. $tabsql = "CREATE TABLE IF NOT EXISTS `$trueTable`(
  87. `id` int(10) unsigned NOT NULL auto_increment,
  88. `ifcheck` tinyint(1) NOT NULL default '0',
  89. ";
  90. if($mysql_version < 4.1)
  91. {
  92. $tabsql .= " PRIMARY KEY (`id`)\r\n) TYPE=MyISAM; ";
  93. }
  94. else
  95. {
  96. $tabsql .= " PRIMARY KEY (`id`)\r\n) ENGINE=MyISAM DEFAULT CHARSET=".$cfg_db_language."; ";
  97. }
  98. $dsql->ExecuteNoneQuery($tabsql);
  99. //检测附加表里含有的字段
  100. $fields = array();
  101. $rs = $dsql->SetQuery("show fields from `$trueTable`");
  102. $dsql->Execute('a');
  103. while($nrow = $dsql->GetArray('a',MYSQL_ASSOC))
  104. {
  105. $fields[strtolower($nrow['Field'])] = 1;
  106. }
  107. $f = '';
  108. foreach($fields as $k=>$v)
  109. {
  110. $f .= ($f=='' ? $k : ' '.$k);
  111. }
  112. require_once(DEDEADMIN."/templets/diy_field_add.htm");