source: pro-violet-viettel/www/deploy/20150304/application/modules/ajax/controllers/privatecontent.php @ 933

Last change on this file since 933 was 933, checked in by dungnv, 10 years ago
File size: 7.5 KB
Line 
1<?php
2
3if (! defined ( 'BASEPATH' ))
4        exit ( 'No direct script access allowed' );
5/**
6 * PrivateContent Class
7 *
8 * @author dzungnv02
9 *
10 */
11
12
13class PrivateContent extends MX_Controller {
14        public function __construct() {
15                parent::__construct ();
16                $user = $this->session->userdata ( 'userInfo' );
17                $this->vservices->setApiUrl ( $this->config->item ( 'api_url' ) );
18                $this->vservices->setConnection ( $this->curl );
19                $this->vservices->setUserId ( $user ['us_id'] );
20        }
21
22        public function getContent() {
23                $xmlData = $this->vservices->getPrivateTree ();
24
25                $this->xml->parse ( $xmlData );
26
27                $aryDirs = array ();
28                $aryFiles = array ();
29                write_file ( 'log.txt', var_export ( $xmlData, true ) );
30
31                if (! isset ( $this->xml->tree )) {
32                        $aryError = array (
33                                        'err' => 'KhÃŽng thể kết nối đến máy chá»§!',
34                                        'errCode' => '-1'
35                        );
36                        $aryData = array (
37                                        'DIRECTORIES' => array (),
38                                        'FILES' => array (),
39                                        'ERROR' => $aryError
40                        );
41                        echo json_encode ( $aryData );
42                        return;
43                }
44
45                $aryError = array (
46                                'err' => $this->xml->tree->_param ['err'],
47                                'errCode' => ( int ) $this->xml->tree->_param ['errCode']
48                );
49
50                if (isset ( $this->xml->tree->folderlist->folder )) {
51                        if (is_array ( $this->xml->tree->folderlist->folder )) {
52                                foreach ( $this->xml->tree->folderlist->folder as $key => $value ) {
53                                        $aryDirs [] = array (
54                                                        'id' => $value->_param ['id'],
55                                                        'name' => $value->_value,
56                                                        'parentID' => $value->_param ['parentid'] == - 1 ? 0 : $value->_param ['parentid']
57                                        );
58                                }
59                        } else {
60                                $folder = $this->xml->tree->folderlist->folder;
61                                $aryDirs [] = array (
62                                                'id' => $folder->_param ['id'],
63                                                'name' => $folder->_value,
64                                                'parentID' => $folder->_param ['parentid'] == - 1 ? 0 : $folder->_param ['parentid']
65                                );
66                        }
67                }
68
69                if (isset ( $this->xml->tree->filelist->file )) {
70                        if (is_array ( $this->xml->tree->filelist->file )) {
71                                foreach ( $this->xml->tree->filelist->file as $key => $value ) {
72                                        // $fileUrl = dirname(dirname(dirname($value->_param['fileurl'])));
73                                        $fileUrl = "";
74                                        if ($value->_param ['fileurl'] != "") {
75                                                $fileUrl = $this->config->item ( 'api_url' ) . $value->_param ['fileurl'];
76                                        }
77
78                                        $thumbnail = "";
79                                        if ($value->_param ['thumbnail'] != "") {
80                                                $thumbnail = $this->config->item ( 'api_url' ) . $value->_param ['thumbnail'];
81                                        }
82
83                                        $aryFiles [] = array (
84                                                        'id' => $value->_param ['id'],
85                                                        'name' => $value->_value,
86                                                        'parentID' => $value->_param ['parentid'] == - 1 ? 0 : $value->_param ['parentid'],
87                                                        'minetype' => $value->_param ['filetype'],
88                                                        'size' => $value->_param ['size'],
89                                                        'thumbnail' => $thumbnail,
90                                                        'fileurl' => $fileUrl
91                                        );
92                                }
93                        } else {
94                                $file = $this->xml->tree->filelist->file;
95                                $aryFiles [] = array (
96                                                'id' => $file->_param ['id'],
97                                                'name' => $file->_value,
98                                                'parentID' => $file->_param ['parentid'] == - 1 ? 0 : $file->_param ['parentid'],
99                                                'minetype' => $file->_param ['filetype'],
100                                                'size' => $file->_param ['size'],
101                                                'thumbnail' => $value->_param ['thumbnail'],
102                                                'fileurl' => $value->_param ['fileurl']
103                                );
104                        }
105                }
106
107                $user = $this->session->userdata ( 'userInfo' );
108                $aryData = array (
109                                'DIRECTORIES' => $aryDirs,
110                                'FILES' => $aryFiles,
111                                'ERROR' => $aryError,
112                                'userinfo' => $user
113                );
114                echo json_encode ( $aryData );
115        }
116
117        public function createDir() {
118                $parentDir = $this->input->post ( 'fparentid', TRUE );
119                $name = $this->input->post ( 'fname', TRUE );
120
121                $xmlData = $this->vservices->actionExecute ( 'mkdir', array (
122                                'name' => $name,
123                                'parent_id' => $parentDir == 0 ? - 1 : $parentDir
124                ) );
125
126                $this->xml->parse ( $xmlData );
127
128                $aryError = array (
129                                'err' => $this->xml->status->_param ['err'],
130                                'errCode' => ( int ) $this->xml->status->_param ['errCode']
131                );
132                $aryData = array (
133                                'id' => $this->xml->status->_param ['id'],
134                                'name' => $this->xml->status->_param ['name'],
135                                'parentID' => $parentDir,
136                                'ERROR' => $aryError
137                );
138                echo json_encode ( $aryData );
139        }
140
141        public function delete() {
142                $delobj = $this->input->post ( 'delobj', TRUE );
143                $xmlData = $this->vservices->actionExecute ( 'deletemulti', array (
144                                'delobj' => $delobj
145                ) );
146                $this->xml->parse ( $xmlData );
147                $aryFolders = array ();
148
149                if (isset ( $this->xml->tree->folder )) {
150                        if (is_array ( $this->xml->tree->folder )) {
151                                foreach ( $this->xml->tree->folder as $key => $folder ) {
152                                        $aryFolders ['DIRECTORIES'] [] = $folder->_param ['id'];
153                                }
154                        } else {
155                                $aryFolders ['DIRECTORIES'] [] = $this->xml->tree->folder->_param ['id'];
156                        }
157                }
158
159                if (isset ( $this->xml->tree->file )) {
160                        if (is_array ( $this->xml->tree->file )) {
161                                foreach ( $this->xml->tree->file as $key => $file ) {
162                                        $aryFolders ['FILES'] [] = $file->_param ['id'];
163                                }
164                        } else {
165                                $aryFolders ['FILES'] [] = $this->xml->tree->file->_param ['id'];
166                        }
167                }
168
169                $aryError = array (
170                                'err' => $this->xml->tree->_param ['err'],
171                                'errCode' => ( int ) $this->xml->tree->_param ['errCode']
172                );
173                $aryData = array (
174                                'DIRECTORIES' => isset ( $aryFolders ['DIRECTORIES'] ) ? $aryFolders ['DIRECTORIES'] : array (),
175                                'FILES' => isset ( $aryFolders ['FILES'] ) ? $aryFolders ['FILES'] : array (),
176                                'ERROR' => $aryError
177                );
178                echo json_encode ( $aryData );
179        }
180
181        public function rename() {
182                $item = $this->input->post ( 'data', TRUE );
183                $objItem = json_decode($item);
184
185                $xmlData = $this->vservices->actionExecute ('rename', array ('id' => $objItem->id, 'name' => $objItem->name, 'type' => $objItem->type, 'parentid' => $objItem->parentID == 0 ? -1:$objItem->parentID, 'newName' => $objItem->newName));
186                $this->xml->parse ( $xmlData );
187                $err = $this->xml->tree->_param ['err'];
188                $errCode = ( int ) $this->xml->tree->_param ['errCode'];
189                $aryItem = array('id' => (int) $this->xml->tree->item->_param['id'],'name' => $this->xml->tree->item->_param['name'],'parentID' => $this->xml->tree->item->_param['parentId'] == -1 ? 0 : $this->xml->tree->item->_param['parentId']);
190
191                $aryData ['DIRECTORIES'] = $objItem->type == 'directory' ? $aryItem :array();
192                $aryData ['FILES'] = $objItem->type == 'file' ? $aryItem :array();
193                $aryData ['ERROR'] = array ('err' => $err, 'errCode' => $errCode);
194
195                echo json_encode ( $aryData );
196        }
197
198        public function copy() {
199                $destination = $this->input->post ( 'destination', TRUE );
200                $data = $this->input->post ( 'data', TRUE );
201                $act = $this->input->post ( 'act', TRUE );
202
203                $xmlData = $this->vservices->actionExecute ( 'copy', array (
204                                'act' => $act,
205                                'data' => $data,
206                                'destination' => $destination == 0 ? - 1 : $destination
207                ) );
208
209                error_log ( date ( 'YmdHis' ) . ' - $xmlData: ' . var_export ( $xmlData, TRUE ), 3, '/srv/www/sbg/log/file.log' );
210
211                $this->xml->parse ( $xmlData );
212
213                $aryNewDirs = isset ( $this->xml->data->folderdata ) ? json_decode ( $this->xml->data->folderdata->_value ) : array ();
214                $aryNewFiles = isset ( $this->xml->data->filedata ) ? json_decode ( $this->xml->data->filedata->_value ) : array ();
215
216                $aryData = array (
217                                'DIRECTORIES' => $aryNewDirs,
218                                'FILES' => $aryNewFiles
219                );
220                $aryData ['ERROR'] = array (
221                                'err' => $this->xml->data->_param ['err'],
222                                'errCode' => ( int ) $this->xml->data->_param ['errCode']
223                );
224                echo json_encode ( $aryData );
225        }
226}
227
228/* End of file privatecontent.php */
229/* Location: ./application/modules/ajax/controllers/privatecontent.php */
Note: See TracBrowser for help on using the repository browser.