123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188 |
- <?php
- class DatabaseTableFieldController
- {
-
- private $returnJson = array('type' => 'database_table_field');
-
- public function __construct()
- {
-
- $server = new GuestModule;
- if (!$server->checkLogin()) {
- $this->returnJson['statusCode'] = '120005';
- exitOutput($this->returnJson);
- }
- }
-
- public function addField()
- {
- $tableID = securelyInput('tableID');
- $module = new DatabaseTableModule();
- $userType = $module->getUserType($tableID);
- if ($userType < 0 || $userType > 2) {
- $this->returnJson['statusCode'] = '120007';
- exitOutput($this->returnJson);
- }
- $nameLen = mb_strlen(quickInput('fieldName', 'utf8'));
- $fieldName = securelyInput('fieldName');
- $typeLen = mb_strlen(quickInput('fieldType', 'utf8'));
- $fieldType = securelyInput('fieldType');
- $fieldLength = securelyInput('fieldLength');
- $isNotNull = securelyInput('isNotNull');
- $isPrimaryKey = securelyInput('isPrimaryKey');
- $descLen = mb_strlen(quickInput('fieldDescription', 'utf8'));
- $fieldDescription = securelyInput('fieldDescription');
- $fieldDefaultValue = securelyInput('defaultValue');
- if (!preg_match('/^[0-9]{1,11}$/', $tableID)) {
- $this->returnJson['statusCode'] = '240001';
- } elseif (!($nameLen >= 1 && $nameLen <= 255)) {
-
- $this->returnJson['statusCode'] = '240002';
- } elseif (!($typeLen >= 1 && $typeLen <= 255)) {
- $this->returnJson['statusCode'] = '240003';
- } elseif (!preg_match('/^[0-9]{1}$/', $isNotNull) || !preg_match('/^[0-9]{1}$/', $isPrimaryKey)) {
- $this->returnJson['statusCode'] = '240004';
- } elseif (!($descLen >= 0 && $descLen <= 255)) {
-
- $this->returnJson['statusCode'] = '240005';
- } else {
- $service = new DatabaseTableFieldModule;
- $result = $service->addField($tableID, $fieldName, $fieldType, $fieldLength, $isNotNull, $isPrimaryKey, $fieldDescription, $fieldDefaultValue);
- if ($result) {
- $this->returnJson['statusCode'] = '000000';
- $this->returnJson['fieldID'] = $result;
- } else {
- $this->returnJson['statusCode'] = '240006';
- }
- }
- exitOutput($this->returnJson);
- }
-
- public function deleteField()
- {
- $fieldID = securelyInput('fieldID');
- $module = new DatabaseTableFieldModule();
- $userType = $module->getUserType($fieldID);
- if ($userType < 0 || $userType > 2) {
- $this->returnJson['statusCode'] = '120007';
- exitOutput($this->returnJson);
- }
- if (!preg_match('/^[0-9]{1,11}$/', $fieldID)) {
- $this->returnJson['statusCode'] = '240007';
- } else {
- $service = new DatabaseTableFieldModule;
- $result = $service->deleteField($fieldID);
- if ($result) {
- $this->returnJson['statusCode'] = '000000';
- } else {
- $this->returnJson['statusCode'] = '240008';
- }
- }
- exitOutput($this->returnJson);
- }
-
- public function getField()
- {
- $tableID = securelyInput('tableID');
- if (!preg_match('/^[0-9]{1,11}$/', $tableID)) {
- $this->returnJson['statusCode'] = '240001';
- } else {
- $service = new DatabaseTableFieldModule;
- $result = $service->getField($tableID);
- if ($result) {
- $this->returnJson['statusCode'] = '000000';
- $this->returnJson['fieldList'] = $result;
- } else {
- $this->returnJson['statusCode'] = '240009';
- }
- }
- exitOutput($this->returnJson);
- }
-
- public function editField()
- {
- $fieldID = securelyInput('fieldID');
- $module = new DatabaseTableFieldModule();
- $userType = $module->getUserType($fieldID);
- if ($userType < 0 || $userType > 2) {
- $this->returnJson['statusCode'] = '120007';
- exitOutput($this->returnJson);
- }
- $nameLen = mb_strlen(quickInput('fieldName', 'utf8'));
- $fieldName = securelyInput('fieldName');
- $typeLen = mb_strlen(quickInput('fieldType', 'utf8'));
- $fieldType = securelyInput('fieldType');
- $fieldLength = securelyInput('fieldLength');
- $isNotNull = securelyInput('isNotNull');
- $isPrimaryKey = securelyInput('isPrimaryKey');
- $descLen = mb_strlen(quickInput('fieldDescription', 'utf8'));
- $fieldDescription = securelyInput('fieldDescription');
- $fieldDefaultValue = securelyInput('defaultValue');
- if (!preg_match('/^[0-9]{1,11}$/', $fieldID)) {
- $this->returnJson['statusCode'] = '240007';
- } elseif (!($nameLen >= 1 && $nameLen <= 255)) {
-
- $this->returnJson['statusCode'] = '240002';
- } elseif (!($typeLen >= 1 && $typeLen < 255)) {
- $this->returnJson['statusCode'] = '240003';
- } elseif (!preg_match('/^[0-9]{1}$/', $isNotNull) || !preg_match('/^[0-9]{1}$/', $isPrimaryKey)) {
- $this->returnJson['statusCode'] = '240004';
- } elseif (!($descLen >= 0 && $descLen <= 255)) {
-
- $this->returnJson['statusCode'] = '240005';
- } else {
- $service = new DatabaseTableFieldModule;
- $result = $service->editField($fieldID, $fieldName, $fieldType, $fieldLength, $isNotNull, $isPrimaryKey, $fieldDescription, $fieldDefaultValue);
- if ($result) {
- $this->returnJson['statusCode'] = '000000';
- } else {
- $this->returnJson['statusCode'] = '240010';
- }
- }
- exitOutput($this->returnJson);
- }
- }
- ?>
|