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

Last change on this file since 780 was 780, checked in by dungnv, 10 years ago
File size: 7.4 KB
Line 
1<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
2/**
3 * PrivateContent Class
4 *
5 * @author dzungnv02
6 *
7 */
8
9/* private $_aryDir = array(
10 0 => array ('id' => 1, 'name' => 'Dir 1', 'parentID' => 0),
11                1 => array ('id' => 2, 'name' => 'Dir 2', 'parentID' => 0),
12                2 => array ('id' => 3, 'name' => 'Dir 1.1', 'parentID' => 1),
13                3 => array ('id' => 4, 'name' => 'Dir 1.1.1', 'parentID' => 3),
14                4 => array ('id' => 5, 'name' => 'Dir 1.1.1.1', 'parentID' => 4),
15                5 => array ('id' => 6, 'name' => 'Dir 1.1.2', 'parentID' => 3),
16                6 => array ('id' => 7, 'name' => 'Dir 3', 'parentID' => 0),
17                7 => array ('id' => 8, 'name' => 'Dir 3.1', 'parentID' => 7)
18);
19
20private $_aryFile = array(
21                0 => array('id' => 1, 'name' => 'File 1', 'minetype' => 'text', 'size' => '1.5MB', 'parentID' => 1),
22                1 => array('id' => 2, 'name' => 'File 2', 'minetype' => 'text', 'size' => '1.6MB', 'parentID' => 1),
23                2 => array('id' => 3, 'name' => 'File 3', 'minetype' => 'text', 'size' => '1.7MB', 'parentID' => 2),
24                3 => array('id' => 4, 'name' => 'File 4', 'minetype' => 'text', 'size' => '1.8MB', 'parentID' => 2),
25                4 => array('id' => 5, 'name' => 'File 5', 'minetype' => 'text', 'size' => '1.8MB', 'parentID' => 0),
26                5 => array('id' => 6, 'name' => 'File 6', 'minetype' => 'text', 'size' => '1.8MB', 'parentID' => 3),
27                5 => array('id' => 7, 'name' => 'File 7', 'minetype' => 'text', 'size' => '1.8MB', 'parentID' => 5)
28); */
29
30class PrivateContent extends MX_Controller
31{
32
33        private $user_info = null;
34
35        public function __construct() {
36                parent::__construct();
37                $this->vservices->setApiUrl($this->config->item('api_url'));
38                $this->vservices->setConnection($this->curl);
39                $user_info = $this->session->userdata('userInfo');
40                parse_str($user_info['user'],$user);
41                $aryTemp = array_merge($user_info,$user);
42                $this->user_info = array('username' => $aryTemp['username'], 'us_id' => $aryTemp['us_id'], 'fullname' => $aryTemp['fullname']);
43                $this->vservices->setUserId($this->user_info['us_id']);
44        }
45       
46        public function getContent () {
47               
48                $xmlData = $this->vservices->getPrivateTree();
49        $this->xml->parse($xmlData);               
50                $aryDirs = array();
51                $aryFiles = array();
52               
53                error_log(var_export($xmlData, TRUE). "\n", 3, '/srv/www/vspacedemo/20150304/log/123.log');
54
55                if (!isset($this->xml->tree)) {
56                        $aryError = array('err' => 'KhÃŽng thể kết nối đến máy chá»§!', 'errCode' => '-1');
57                        $aryData = array('DIRECTORIES' =>  array() , 'FILES' => array(), 'ERROR' => $aryError);
58                        echo json_encode($aryData);
59                        return;
60                }
61               
62                $aryError = array('err' => $this->xml->tree->_param['err'], 'errCode' => (int)$this->xml->tree->_param['errCode']);
63               
64                if (isset($this->xml->tree->folderlist->folder)) {
65                        if (is_array($this->xml->tree->folderlist->folder)) {
66                                foreach($this->xml->tree->folderlist->folder as $key=>$value){
67                                        $aryDirs[] = array('id' => $value->_param['id'], 'name' => $value->_value, 'parentID' => $value->_param['parentid'] == -1 ? 0:$value->_param['parentid']);
68                                }
69                        }
70                        else {
71                                $folder = $this->xml->tree->folderlist->folder;
72                                $aryDirs[] = array('id' => $folder->_param['id'], 'name' => $folder->_value,'parentID' => $folder->_param['parentid'] == -1 ? 0:$folder->_param['parentid']);
73                        }
74                }
75               
76                if (isset($this->xml->tree->filelist->file)) {
77                        if (is_array($this->xml->tree->filelist->file)) {
78                                foreach($this->xml->tree->filelist->file as $key=>$value){
79                                        $aryFiles[] = array('fileurl' => $value->_param['fileurl'], 'id' => $value->_param['id'], 'name' => $value->_value, 'parentID' => $value->_param['parentid'] == -1 ? 0:$value->_param['parentid'], 'minetype' => $value->_param['filetype']);
80                                }
81                        }else {
82                                $file = $this->xml->tree->filelist->file;
83                                $aryFiles[] = array('fileurl' => $file->_param['fileurl'],'id' => $file->_param['id'], 'name' => $file->_value,'parentID' => $file->_param['parentid'] == -1 ? 0:$file->_param['parentid'], 'minetype' => $file->_param['filetype']);
84                        }
85                }
86               
87                $aryData = array('DIRECTORIES' =>  $aryDirs , 'FILES' => $aryFiles, 'ERROR' => $aryError, 'userinfo' => $this->user_info);
88                echo json_encode($aryData);
89        }
90
91        public function createDir () {
92                $parentDir =  $this->input->post('fparentid',TRUE);
93                $name =  $this->input->post('fname',TRUE);
94               
95                $xmlData = $this->vservices->actionExecute('mkdir',array('name' => $name, 'parent_id' => $parentDir == 0 ? -1:$parentDir));
96               
97                $this->xml->parse($xmlData);
98                $aryError = array('err' => $this->xml->status->_param['err'], 'errCode' => (int)$this->xml->status->_param['errCode']);
99                $aryData = array('id' => $this->xml->status->_param['id'], 'name' => $name, 'parentID' => $parentDir, 'ERROR' => $aryError);
100                echo json_encode($aryData);
101        }
102       
103        public function delete () {
104                $delobj =  $this->input->post('delobj',TRUE);
105                $xmlData = $this->vservices->actionExecute('deletemulti',array('delobj' => $delobj));
106
107                $this->xml->parse($xmlData);
108                $aryFolders = array();
109                error_log(date('YmdHis').': delete:'. var_export(isset($this->xml->tree), TRUE) . "\n", 3, '/srv/www/vspacedemo/20150304/log/apidel.log');
110                if (isset($this->xml->tree->folder)) {
111                        if (is_array($this->xml->tree->folder)) {
112                                foreach ($this->xml->tree->folder as $key => $folder) {                                 
113                                        $aryFolders['DIRECTORIES'][] = $folder->_param['id'];
114                                }
115                        }
116                        else {
117                                $aryFolders['DIRECTORIES'][] = $this->xml->tree->folder->_param['id'];
118                        }
119                }
120               
121                if (isset($this->xml->tree->file)) {
122                        if (is_array($this->xml->tree->file)) {
123                                foreach ($this->xml->tree->file as $key => $file) {
124                                        $aryFolders['FILES'][] = $file->_param['id'];
125                                }
126                        }
127                        else {
128                                $aryFolders['FILES'][] = $this->xml->tree->file->_param['id'];
129                        }
130                }
131               
132                $aryError = array('err' => $this->xml->tree->_param['err'], 'errCode' => (int)$this->xml->tree->_param['errCode']);
133                $aryData = array('DIRECTORIES' => isset($aryFolders['DIRECTORIES']) ? $aryFolders['DIRECTORIES'] : array(), 'FILES' => isset($aryFolders['FILES'])? $aryFolders['FILES'] : array() ,'ERROR' => $aryError);
134                echo json_encode($aryData);
135        }
136       
137        public function rename() {
138                $id =  $this->input->post('id',TRUE);
139                $data =  $this->input->post('data',TRUE);
140               
141                /* $aryData = array();
142                $aryData['RESULT'] = $this->objDirectory->rename($id, $newName, $objectType);;
143                $aryData['UPDATED'] = array('id' => $id, 'name' => $newName, 'type' => $objectType);
144                echo json_encode($aryData); */
145        }
146
147        public function copy () {
148                $destination =  $this->input->post('destination',TRUE);
149                $data =  $this->input->post('data',TRUE);
150                $act =  $this->input->post('act',TRUE);
151               
152                $xmlData = $this->vservices->actionExecute('copy' ,array('act' => $act,'data' => $data, 'destination' => $destination == 0 ? -1:$destination));
153                $this->xml->parse($xmlData);
154               
155                $aryNewDirs =   isset($this->xml->data->folderdata) ? json_decode($this->xml->data->folderdata->_value) : array();
156                $aryNewFiles =  isset($this->xml->data->filedata) ? json_decode($this->xml->data->filedata->_value) : array();
157               
158                $aryData = array('DIRECTORIES' => $aryNewDirs, 'FILES' => $aryNewFiles);
159                $aryData['ERROR'] = array('err' => $this->xml->data->_param['err'], 'errCode' => (int)$this->xml->data->_param['errCode']);;
160                echo json_encode($aryData);
161        }
162       
163        public function upload() {
164               
165        }
166}
167
168/* End of file privatecontent.php */
169/* Location: ./application/modules/ajax/controllers/privatecontent.php */
Note: See TracBrowser for help on using the repository browser.