source: pro-bachkim-filespace/sourcecode/application/modules/ajax/controllers/privatecontent.php @ 228

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