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

77 lines
2.7KB

  1. <?php
  2. /**
  3. * 增加自定义表单
  4. *
  5. * @version $Id: diy_add.php 1 14:31 2010年7月12日Z tianya $
  6. * @package DedeCMS.Administrator
  7. * @copyright Copyright (c) 2007 - 2019, DesDev, Inc.
  8. * @license http://help.dedecms.com/usersguide/license.html
  9. * @link http://www.dedecms.com
  10. */
  11. require_once(dirname(__FILE__)."/config.php");
  12. CheckPurview('c_New');
  13. $mysql_version = $dsql->GetVersion();
  14. $mysql_versions = explode(".",trim($mysql_version));
  15. $mysql_version = $mysql_versions[0].".".$mysql_versions[1];
  16. if(empty($action))
  17. {
  18. $row = $dsql->GetOne("SELECT diyid FROM #@__diyforms ORDER BY diyid DESC LIMIT 0,1 ");
  19. if(is_array($row)) $newdiyid = $row['diyid']+1;
  20. else $newdiyid = 1;
  21. include(DEDEADMIN."/templets/diy_add.htm");
  22. }
  23. else
  24. {
  25. if(preg_match("#[^0-9-]#", $diyid) || empty($diyid))
  26. {
  27. ShowMsg("<font color=red>'自定义表单diyid'</font>必须为数字!","-1");
  28. exit();
  29. }
  30. if($table=="")
  31. {
  32. ShowMsg("表名不能为空!", "-1");
  33. exit();
  34. }
  35. $public = isset($public) && is_numeric($public) ? $public : 0;
  36. $name = dede_htmlspecialchars($name);
  37. $row = $dsql->GetOne("SELECT * FROM #@__diyforms WHERE diyid='$diyid' OR `table` LIKE '$table' OR name LIKE '$name' ");
  38. if(is_array($row))
  39. {
  40. ShowMsg("可能自定义表单的‘diyid’、‘名称’在数据库中已存在,不能重复使用!","-1");
  41. exit();
  42. }
  43. $query = "SHOW TABLES FROM {$dsql->dbName} ";
  44. $dsql->SetQuery($query);
  45. $dsql->Execute();
  46. while($row = $dsql->getarray())
  47. {
  48. if(empty($row[0])) $row[0] = '';
  49. if($table == $row[0])
  50. {
  51. showmsg('指定的表在数据库中重复', '-1');
  52. exit();
  53. }
  54. }
  55. $sql = "CREATE TABLE IF NOT EXISTS `$table`(
  56. `id` int(10) unsigned NOT NULL auto_increment,
  57. `ifcheck` tinyint(1) NOT NULL default '0',
  58. ";
  59. if($mysql_version < 4.1)
  60. {
  61. $sql .= " PRIMARY KEY (`id`)\r\n) TYPE=MyISAM; ";
  62. }
  63. else
  64. {
  65. $sql .= " PRIMARY KEY (`id`)\r\n) ENGINE=MyISAM DEFAULT CHARSET=".$cfg_db_language."; ";
  66. }
  67. if($dsql->ExecuteNoneQuery($sql))
  68. {
  69. $query = "INSERT INTO #@__diyforms (`diyid`, `name`, `table`, `info`, `listtemplate`, `viewtemplate`, `posttemplate`, `public` ) VALUES ('$diyid', '$name', '$table', '', '$listtemplate', '$viewtemplate', '$posttemplate', '$public')";
  70. $dsql->ExecuteNoneQuery($query);
  71. showmsg('自定义表单创建成功,请自行添加字段', 'diy_main.php');
  72. }
  73. else
  74. {
  75. showmsg('自定义表单创建失败', '-1');
  76. }
  77. }