123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264 |
- <?php
- class DocumentController
- {
-
- private $returnJson = array('type' => 'document');
-
- private $user_id;
-
- public function __construct()
- {
-
-
- $server = new GuestModule;
- if (!$server->checkLogin()) {
- $this->returnJson['statusCode'] = '120005';
- exitOutput($this->returnJson);
- } else {
- $this->user_id = $_SESSION['userID'];
- }
- }
-
- public function addDocument()
- {
-
- $group_id = securelyInput('groupID');
-
- $title = securelyInput('title');
- $content = quickInput('content');
- $content_raw = quickInput('contentRaw', '');
- $content_type = quickInput('contentType');
- if (!preg_match('/^[0-9]{1,11}$/', $group_id)) {
-
- $this->returnJson['statusCode'] = '230001';
- } elseif ($content_type != 0 && $content_type != 1) {
-
- $this->returnJson['statusCode'] = '230002';
- } else {
- $group_module = new DocumentGroupModule();
- $user_type = $group_module->getUserType($group_id);
- if ($user_type < 0 || $user_type > 2) {
- $this->returnJson['statusCode'] = '120007';
- } else {
- $service = new DocumentModule();
- $result = $service->addDocument($this->user_id, $group_id, $content_type, $content, $content_raw, $title);
- if ($result) {
- $this->returnJson['statusCode'] = '000000';
- $this->returnJson['documentID'] = $result;
- } else {
- $this->returnJson['statusCode'] = '230000';
- }
- }
- }
- exitOutput($this->returnJson);
- }
-
- public function editDocument()
- {
- $document_id = securelyInput('documentID');
- $title = securelyInput('title');
- $group_id = securelyInput('groupID');
- $content = quickInput('content');
- $content_raw = quickInput('contentRaw', '');
- $content_type = securelyInput('contentType');
- if (!preg_match('/^[0-9]{1,11}$/', $document_id)) {
-
- $this->returnJson['statusCode'] = '230003';
- } elseif (!preg_match('/^[0-9]{1,11}$/', $group_id)) {
-
- $this->returnJson['statusCode'] = '230001';
- } else {
- $service = new DocumentModule();
- $user_type = $service->getUserType($document_id);
- if ($user_type < 0 || $user_type > 2) {
- $this->returnJson['statusCode'] = '120007';
- } else {
- $result = $service->editDocument($this->user_id, $group_id, $document_id, $content_type, $content, $content_raw, $title);
- if ($result) {
-
- $this->returnJson['statusCode'] = '000000';
- } else {
-
- $this->returnJson['statusCode'] = '230000';
- }
- }
- }
- exitOutput($this->returnJson);
- }
-
- public function getDocumentList()
- {
- $group_id = securelyInput('groupID');
- if (!preg_match('/^[0-9]{1,11}$/', $group_id)) {
-
- $this->returnJson['statusCode'] = '230001';
- } else {
- $service = new DocumentModule();
- $result = $service->getDocumentList($group_id, $this->user_id);
- if ($result) {
-
- $this->returnJson['statusCode'] = '000000';
- $this->returnJson['documentList'] = $result;
- } else {
-
- $this->returnJson['statusCode'] = '230000';
- }
- }
- exitOutput($this->returnJson);
- }
-
- public function getAllDocumentList()
- {
- $project_id = securelyInput('projectID');
- if (!preg_match('/^[0-9]{1,11}$/', $project_id)) {
-
- $this->returnJson['statusCode'] = '230004';
- } else {
- $service = new DocumentModule();
- $result = $service->getAllDocumentList($project_id, $this->user_id);
-
- if ($result) {
-
- $this->returnJson['statusCode'] = '000000';
- $this->returnJson['documentList'] = $result;
- } else {
-
- $this->returnJson['statusCode'] = '230000';
- }
- }
- exitOutput($this->returnJson);
- }
-
- public function searchDocument()
- {
- $tips_length = mb_strlen(quickInput('tips'), 'utf8');
- $tips = securelyInput('tips');
- $project_id = securelyInput('projectID');
- if (!preg_match('/^[0-9]{1,11}$/', $project_id)) {
-
- $this->returnJson['statusCode'] = '230004';
- } elseif ($tips_length < 1 || $tips_length > 255) {
-
- $this->returnJson['statusCode'] = '230005';
- } else {
- $service = new DocumentModule();
- $result = $service->searchDocument($project_id, $tips, $this->user_id);
-
- if ($result) {
-
- $this->returnJson['statusCode'] = '000000';
- $this->returnJson['documentList'] = $result;
- } else {
-
- $this->returnJson['statusCode'] = '230000';
- }
- }
- exitOutput($this->returnJson);
- }
-
- public function getDocument()
- {
- $document_id = securelyInput('documentID');
- if (!preg_match('/^[0-9]{1,11}$/', $document_id)) {
-
- $this->returnJson['statusCode'] = '230003';
- } else {
- $service = new DocumentModule();
- $result = $service->getDocument($document_id, $this->user_id);
- if ($result) {
-
- $this->returnJson['statusCode'] = '000000';
- $this->returnJson['documentInfo'] = $result;
- } else {
-
- $this->returnJson['statusCode'] = '230000';
- }
- }
- exitOutput($this->returnJson);
- }
-
- public function deleteDocuments()
- {
- $ids = quickInput('documentID');
- $arr = json_decode($ids);
- $arr = preg_grep('/^[0-9]{1,11}$/', $arr);
- $project_id = securelyInput('projectID');
- if (!preg_match('/^[0-9]{1,11}$/', $project_id)) {
-
- $this->returnJson['statusCode'] = '230004';
- } elseif (empty($arr)) {
-
- $this->returnJson['statusCode'] = '230003';
- } else {
- $project_module = new ProjectModule();
- $user_type = $project_module->getUserType($project_id);
- if ($user_type < 0 || $user_type > 2) {
- $this->returnJson['statusCode'] = '120007';
- } else {
- $document_ids = implode(',', $arr);
- $service = new DocumentModule();
- $result = $service->deleteDocuments($project_id, $this->user_id, $document_ids);
-
- if ($result) {
-
- $this->returnJson['statusCode'] = '000000';
- } else {
-
- $this->returnJson['statusCode'] = '230000';
- }
- }
- }
- exitOutput($this->returnJson);
- }
- }
|