DatabaseTableController.class.php 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. <?php
  2. /**
  3. * @name eolinker ams open source,eolinker开源版本
  4. * @link https://www.eolinker.com/
  5. * @package eolinker
  6. * @author www.eolinker.com 广州银云信息科技有限公司 ©2015-2018
  7. * eoLinker是目前全球领先、国内最大的在线API接口管理平台,提供自动生成API文档、API自动化测试、Mock测试、团队协作等功能,旨在解决由于前后端分离导致的开发效率低下问题。
  8. * 如在使用的过程中有任何问题,欢迎加入用户讨论群进行反馈,我们将会以最快的速度,最好的服务态度为您解决问题。
  9. *
  10. * eoLinker AMS开源版的开源协议遵循Apache License 2.0,如需获取最新的eolinker开源版以及相关资讯,请访问:https://www.eolinker.com/#/os/download
  11. *
  12. * 官方网站:https://www.eolinker.com/
  13. * 官方博客以及社区:http://blog.eolinker.com/
  14. * 使用教程以及帮助:http://help.eolinker.com/
  15. * 商务合作邮箱:market@eolinker.com
  16. * 用户讨论QQ群:284421832
  17. */
  18. class DatabaseTableController
  19. {
  20. //return json object
  21. //返回Json类型
  22. private $returnJson = array('type' => 'database_table');
  23. /**
  24. * checkout login status
  25. * 检查登录状态
  26. */
  27. public function __construct()
  28. {
  29. // identify authentication
  30. // 身份验证
  31. $server = new GuestModule;
  32. if (!$server->checkLogin()) {
  33. $this->returnJson['statusCode'] = '120005';
  34. exitOutput($this->returnJson);
  35. }
  36. }
  37. /**
  38. * add database table
  39. * 添加数据表
  40. */
  41. public function addTable()
  42. {
  43. $dbID = securelyInput('dbID');
  44. $module = new DatabaseModule();
  45. $userType = $module->getUserType($dbID);
  46. if ($userType < 0 || $userType > 2) {
  47. $this->returnJson['statusCode'] = '120007';
  48. exitOutput($this->returnJson);
  49. }
  50. $nameLen = mb_strlen(quickInput('tableName'), 'utf8');
  51. $tableName = securelyInput('tableName');
  52. $descLen = mb_strlen(quickInput('tableDescription'), 'utf8');
  53. $tableDesc = securelyInput('tableDescription');
  54. $fieldDefaultValue = securelyInput('defaultValue');
  55. //illegal dbID
  56. //数据库ID格式非法
  57. if (!preg_match('/^[0-9]{1,11}$/', $dbID)) {
  58. $this->returnJson['statusCode'] = '230001';
  59. } elseif (!($nameLen >= 1 && $nameLen <= 255)) {
  60. //illegal tableName
  61. //表名长度非法
  62. $this->returnJson['statusCode'] = '230002';
  63. } elseif (!($descLen >= 0 && $descLen <= 255)) {
  64. //illegal tableDescription
  65. //表描述长度非法
  66. $this->returnJson['statusCode'] = '230003';
  67. } else {
  68. $service = new DatabaseTableModule;
  69. $result = $service->addTable($dbID, $tableName, $tableDesc);
  70. if ($result) {
  71. $this->returnJson['statusCode'] = '000000';
  72. $this->returnJson['tableID'] = $result;
  73. } else {
  74. $this->returnJson['statusCode'] = '230004';
  75. }
  76. }
  77. exitOutput($this->returnJson);
  78. }
  79. /**
  80. * delete database table
  81. * 删除数据表
  82. */
  83. public function deleteTable()
  84. {
  85. $tableID = securelyInput('tableID');
  86. $module = new DatabaseTableModule();
  87. $userType = $module->getUserType($tableID);
  88. if ($userType < 0 || $userType > 2) {
  89. $this->returnJson['statusCode'] = '120007';
  90. exitOutput($this->returnJson);
  91. }
  92. //illegal tableID
  93. //数据表ID格式非法
  94. if (!preg_match('/^[0-9]{1,11}$/', $tableID)) {
  95. $this->returnJson['statusCode'] = '230005';
  96. } else {
  97. $service = new DatabaseTableModule;
  98. $result = $service->deleteTable($tableID);
  99. if ($result) {
  100. $this->returnJson['statusCode'] = '000000';
  101. } else {
  102. $this->returnJson['statusCode'] = '230006';
  103. }
  104. }
  105. exitOutput($this->returnJson);
  106. }
  107. /**
  108. * get database table list
  109. * 获取数据表列表
  110. */
  111. public function getTable()
  112. {
  113. $dbID = securelyInput('dbID');
  114. //illegal dbID
  115. //数据库ID格式非法
  116. if (!preg_match('/^[0-9]{1,11}$/', $dbID)) {
  117. $this->returnJson['statusCode'] = '230001';
  118. } else {
  119. $service = new DatabaseTableModule;
  120. $result = $service->getTable($dbID);
  121. if ($result) {
  122. $this->returnJson['statusCode'] = '000000';
  123. $this->returnJson['tableList'] = $result;
  124. } else {
  125. $this->returnJson['statusCode'] = '230007';
  126. }
  127. }
  128. exitOutput($this->returnJson);
  129. }
  130. /**
  131. * edit database table
  132. * 修改数据表
  133. */
  134. public function editTable()
  135. {
  136. $tableID = securelyInput('tableID');
  137. $module = new DatabaseTableModule();
  138. $userType = $module->getUserType($tableID);
  139. if ($userType < 0 || $userType > 2) {
  140. $this->returnJson['statusCode'] = '120007';
  141. exitOutput($this->returnJson);
  142. }
  143. $nameLen = mb_strlen(quickInput('tableName'), 'utf8');
  144. $tableName = securelyInput('tableName');
  145. $descLen = mb_strlen(quickInput('tableDescription'), 'utf8');
  146. $tableDesc = securelyInput('tableDescription');
  147. $fieldDefaultValue = securelyInput('defaultValue');
  148. //illegal tableID
  149. //数据表ID格式非法
  150. if (!preg_match('/^[0-9]{1,11}$/', $tableID)) {
  151. $this->returnJson['statusCode'] = '230005';
  152. } elseif (!($nameLen >= 1 && $nameLen <= 255)) {
  153. //illegal tableName
  154. //表名长度非法
  155. $this->returnJson['statusCode'] = '230002';
  156. } elseif (!($descLen >= 0 && $descLen <= 255)) {
  157. //illegal tableDescription
  158. //表描述长度非法
  159. $this->returnJson['statusCode'] = '230003';
  160. } else {
  161. $service = new DatabaseTableModule;
  162. $result = $service->editTable($tableID, $tableName, $tableDesc);
  163. if ($result) {
  164. $this->returnJson['statusCode'] = '000000';
  165. } else {
  166. $this->returnJson['statusCode'] = '230008';
  167. }
  168. }
  169. exitOutput($this->returnJson);
  170. }
  171. }
  172. ?>