123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267 |
- <?php
- class DocumentGroupController
- {
- private $user_id;
-
-
- private $returnJson = array('type' => 'document_group');
-
- public function __construct()
- {
-
-
- $server = new GuestModule;
- if (!$server->checkLogin()) {
- $this->returnJson['statusCode'] = '120005';
- exitOutput($this->returnJson);
- } else {
- $this->user_id = $_SESSION['userID'];
- }
- }
-
- public function addGroup()
- {
- $project_id = securelyInput('projectID');
- $name_length = mb_strlen(quickInput('groupName'), 'utf8');
- $group_name = securelyInput('groupName');
- $parent_group_id = securelyInput('parentGroupID', NULL);
- if (!preg_match('/^[0-9]{1,11}$/', $project_id)) {
- $this->returnJson['statusCode'] = '220005';
- } elseif ($name_length < 1 || $name_length > 32) {
-
- $this->returnJson['statusCode'] = '220001';
- } elseif (!preg_match('/^[0-9]{1,11}$/', $parent_group_id) && $parent_group_id != NULL) {
-
- $this->returnJson['statusCode'] = '220002';
- } else {
- $project_module = new ProjectModule();
- $user_type = $project_module->getUserType($project_id);
- if ($user_type < 0 || $user_type > 2) {
- $this->returnJson['statusCode'] = '120007';
- } else {
- $service = new DocumentGroupModule();
- $result = $service->addGroup($project_id, $this->user_id, $group_name, $parent_group_id);
- if ($result) {
-
- $this->returnJson['statusCode'] = '000000';
- $this->returnJson['groupID'] = $result;
- } else {
-
- $this->returnJson['statusCode'] = '220000';
- }
- }
- }
- exitOutput($this->returnJson);
- }
-
- public function deleteGroup()
- {
- $group_id = securelyInput('groupID');
- if (!preg_match('/^[0-9]{1,11}$/', $group_id)) {
-
- $this->returnJson['statusCode'] = '220003';
- } else {
-
- $service = new DocumentGroupModule();
- $user_type = $service->getUserType($group_id);
- if ($user_type < 0 || $user_type > 2) {
- $this->returnJson['statusCode'] = '120007';
- } else {
- $result = $service->deleteGroup($this->user_id, $group_id);
- if ($result) {
-
- $this->returnJson['statusCode'] = '000000';
- } else {
-
- $this->returnJson['statusCode'] = '220000';
- }
- }
- }
- exitOutput($this->returnJson);
- }
-
- public function getGroupList()
- {
- $project_id = securelyInput('projectID');
- if (!preg_match('/^[0-9]{1,11}$/', $project_id)) {
- $this->returnJson['statusCode'] = '220005';
- } else {
- $service = new DocumentGroupModule();
- $result = $service->getGroupList($project_id, $this->user_id);
-
- if ($result) {
- $this->returnJson['statusCode'] = '000000';
- $this->returnJson = array_merge($this->returnJson, $result);
- } else {
- $this->returnJson['statusCode'] = '220000';
- }
- }
- exitOutput($this->returnJson);
- }
-
- public function editGroup()
- {
- $name_length = mb_strlen(quickInput('groupName'), 'utf8');
- $group_id = securelyInput('groupID');
- $group_name = securelyInput('groupName');
- $parent_group_id = securelyInput('parentGroupID', NULL);
-
- if ($name_length < 1 && $name_length > 32) {
- $this->returnJson['statusCode'] = '220001';
- } elseif (!preg_match('/^[0-9]{1,11}$/', $parent_group_id) && $parent_group_id != NULL) {
-
- $this->returnJson['statusCode'] = '220002';
- } elseif (!preg_match('/^[0-9]{1,11}$/', $group_id)) {
-
- $this->returnJson['statusCode'] = '220003';
- } elseif ($group_id == $parent_group_id) {
-
- $this->returnJson['statusCode'] = '220006';
- } else {
- $service = new DocumentGroupModule();
- $user_type = $service->getUserType($group_id);
- if ($user_type < 0 || $user_type > 2) {
- $this->returnJson['statusCode'] = '120007';
- } else {
- $result = $service->editGroup($this->user_id, $group_id, $group_name, $parent_group_id);
- if ($result)
-
- $this->returnJson['statusCode'] = '000000';
- else
-
- $this->returnJson['statusCode'] = '220000';
- }
- }
- exitOutput($this->returnJson);
- }
-
- public function sortDocumentGroup()
- {
- $project_id = securelyInput('projectID');
- $order_list = quickInput('orderList');
- if (!preg_match('/^[0-9]{1,11}$/', $project_id)) {
- $this->returnJson['statusCode'] = '220005';
- }
- elseif (empty($order_list)) {
-
- $this->returnJson['statusCode'] = '220004';
- } else {
- $project_module = new ProjectModule();
- $user_type = $project_module->getUserType($project_id);
- if ($user_type < 0 || $user_type > 2) {
- $this->returnJson['statusCode'] = '120007';
- } else {
- $service = new DocumentGroupModule();
- $result = $service->updateGroupOrder($project_id, $order_list, $this->user_id);
- if ($result) {
-
- $this->returnJson['statusCode'] = '000000';
- } else {
-
- $this->returnJson['statusCode'] = '220000';
- }
- }
- }
- exitOutput($this->returnJson);
- }
-
- public function exportGroup()
- {
-
- $group_id = securelyInput('groupID');
- if (!preg_match('/^[0-9]{1,11}$/', $group_id)) {
-
- $this->returnJson['statusCode'] = '220003';
- } else {
- $service = new DocumentGroupModule();
- $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'] = '220000';
- }
- }
- }
- 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'] = '220007';
- }
- elseif (empty($data)) {
- $this->returnJson['statusCode'] = '220005';
- 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 DocumentGroupModule();
- $result = $server->importGroup($project_id, $data);
-
- if ($result) {
- $this->returnJson['statusCode'] = '000000';
- } else {
- $this->returnJson['statusCode'] = '220000';
- }
- }
- exitOutput($this->returnJson);
- }
- }
|