123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255 |
- <?php
- class GroupController
- {
-
- private $returnJson = array('type' => 'group');
-
- public function __construct()
- {
-
- $server = new GuestModule;
- if (!$server->checkLogin()) {
- $this->returnJson['statusCode'] = '120005';
- exitOutput($this->returnJson);
- }
- }
-
- public function addGroup()
- {
- $nameLen = mb_strlen(quickInput('groupName'), 'utf8');
- $projectID = securelyInput('projectID');
- $module = new ProjectModule();
- $userType = $module->getUserType($projectID);
- if ($userType < 0 || $userType > 2) {
- $this->returnJson['statusCode'] = '120007';
- exitOutput($this->returnJson);
- }
- $groupName = securelyInput('groupName');
- $parentGroupID = securelyInput('parentGroupID', NULL);
-
- if (preg_match('/^[0-9]{1,11}$/', $projectID) && $nameLen >= 1 && $nameLen <= 30) {
-
- $service = new GroupModule();
- $result = $service->addGroup($projectID, $groupName, $parentGroupID);
-
- if ($result) {
-
- $this->returnJson['statusCode'] = '000000';
- $this->returnJson['groupID'] = $result;
- } else
-
- $this->returnJson['statusCode'] = '150001';
- } else {
- $this->returnJson['statusCode'] = '150002';
- }
- exitOutput($this->returnJson);
- }
-
- public function deleteGroup()
- {
- $groupID = securelyInput('groupID');
- $module = new GroupModule();
- $userType = $module->getUserType($groupID);
- if ($userType < 0 || $userType > 2) {
- $this->returnJson['statusCode'] = '120007';
- exitOutput($this->returnJson);
- }
-
- if (preg_match('/^[0-9]{1,11}$/', $groupID)) {
-
- $service = new GroupModule();
- $result = $service->deleteGroup($groupID);
-
- if ($result)
-
- $this->returnJson['statusCode'] = '000000';
- else
-
- $this->returnJson['statusCode'] = '150003';
- } else {
-
- $this->returnJson['statusCode'] = '150004';
- }
- exitOutput($this->returnJson);
- }
-
- public function getGroupList()
- {
- $projectID = securelyInput('projectID');
- if (preg_match('/^[0-9]{1,11}$/', $projectID)) {
- $service = new GroupModule;
- $result = $service->getGroupList($projectID);
- $orderList = $service->getGroupOrderList($projectID);
- if ($result) {
- $this->returnJson['statusCode'] = '000000';
- $this->returnJson['groupList'] = $result;
- $this->returnJson['groupOrder'] = $orderList;
- } else {
- $this->returnJson['statusCode'] = '150008';
- }
- } else {
- $this->returnJson['statusCode'] = '150007';
- }
- exitOutput($this->returnJson);
- }
-
- public function editGroup()
- {
- $nameLen = mb_strlen(quickInput('groupName'), 'utf8');
- $groupID = securelyInput('groupID');
- $parentGroupID = securelyInput('parentGroupID');
- $module = new GroupModule();
- $userType = $module->getUserType($groupID);
- if ($userType < 0 || $userType > 2) {
- $this->returnJson['statusCode'] = '120007';
- exitOutput($this->returnJson);
- }
- $groupName = securelyInput('groupName');
-
- if (preg_match('/^[0-9]{1,11}$/', $groupID) && $nameLen >= 1 && $nameLen <= 30) {
- if ($groupID == $parentGroupID) {
- $this->returnJson['statusCode'] = '150008';
- exitOutput($this->returnJson);
- }
- $service = new GroupModule();
- $result = $service->editGroup($groupID, $groupName, $parentGroupID);
- if ($result)
-
- $this->returnJson['statusCode'] = '000000';
- else
-
- $this->returnJson['statusCode'] = '150005';
- } else {
-
- $this->returnJson['statusCode'] = '150002';
- }
- exitOutput($this->returnJson);
- }
-
- public function sortGroup()
- {
- $projectID = securelyInput('projectID');
- $module = new ProjectModule();
- $userType = $module->getUserType($projectID);
- if ($userType < 0 || $userType > 2) {
- $this->returnJson['statusCode'] = '120007';
- exitOutput($this->returnJson);
- }
-
- $orderList = quickInput('orderList');
-
- if (!preg_match('/^[0-9]{1,11}$/', $projectID)) {
- $this->returnJson['statusCode'] = '150007';
- } else if (empty($orderList)) {
-
- $this->returnJson['statusCode'] = '150004';
- } else {
- $service = new GroupModule;
- $result = $service->sortGroup($projectID, $orderList);
-
- if ($result) {
- $this->returnJson['statusCode'] = '000000';
- } else {
- $this->returnJson['statusCode'] = '150000';
- }
- }
- exitOutput($this->returnJson);
- }
-
- public function exportGroup()
- {
-
- $group_id = securelyInput('groupID');
- if (!preg_match('/^[0-9]{1,11}$/', $group_id)) {
-
- $this->returnJson['statusCode'] = '150003';
- } else {
- $service = new GroupModule();
- $user_type = $service->getUserType($group_id);
- if ($user_type < 0 || $user_type > 2) {
- $this->returnJson['statusCode'] = '120007';
- } else {
- $result = $service->exportGroup($group_id);
- if ($result) {
- $this->returnJson['statusCode'] = '000000';
- $this->returnJson['fileName'] = $result;
- } else {
- $this->returnJson['statusCode'] = '150000';
- }
- }
- }
- exitOutput($this->returnJson);
- }
-
- public function importGroup()
- {
- $project_id = securelyInput('projectID');
- $json = quickInput('data');
- $data = json_decode($json, TRUE);
- if (!preg_match('/^[0-9]{1,11}$/', $project_id)) {
- $this->returnJson['statusCode'] = '150007';
- }
- elseif (empty($data)) {
- $this->returnJson['statusCode'] = '150005';
- exitOutput($this->returnJson);
- } else {
- $service = new ProjectModule();
- $user_type = $service->getUserType($project_id);
- if ($user_type < 0 || $user_type > 2) {
- $this->returnJson['statusCode'] = '120007';
- }
- $server = new GroupModule();
- $result = $server->importGroup($project_id, $data);
-
- if ($result) {
- $this->returnJson['statusCode'] = '000000';
- } else {
- $this->returnJson['statusCode'] = '150000';
- }
- }
- exitOutput($this->returnJson);
- }
- }
- ?>
|