Index: pro-violet-viettel/www/deploy/20150304/application/modules/ajax/controllers/privatecontent.php
===================================================================
--- pro-violet-viettel/www/deploy/20150304/application/modules/ajax/controllers/privatecontent.php	(revision 893)
+++ pro-violet-viettel/www/deploy/20150304/application/modules/ajax/controllers/privatecontent.php	(revision 923)
@@ -1,3 +1,6 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
+
+if (! defined ( 'BASEPATH' ))
+	exit ( 'No direct script access allowed' );
 /**
  * PrivateContent Class
@@ -7,166 +10,217 @@
  */
 
-/* private $_aryDir = array(
- 0 => array ('id' => 1, 'name' => 'Dir 1', 'parentID' => 0),
-		1 => array ('id' => 2, 'name' => 'Dir 2', 'parentID' => 0),
-		2 => array ('id' => 3, 'name' => 'Dir 1.1', 'parentID' => 1),
-		3 => array ('id' => 4, 'name' => 'Dir 1.1.1', 'parentID' => 3),
-		4 => array ('id' => 5, 'name' => 'Dir 1.1.1.1', 'parentID' => 4),
-		5 => array ('id' => 6, 'name' => 'Dir 1.1.2', 'parentID' => 3),
-		6 => array ('id' => 7, 'name' => 'Dir 3', 'parentID' => 0),
-		7 => array ('id' => 8, 'name' => 'Dir 3.1', 'parentID' => 7)
-);
-
-private $_aryFile = array(
-		0 => array('id' => 1, 'name' => 'File 1', 'minetype' => 'text', 'size' => '1.5MB', 'parentID' => 1),
-		1 => array('id' => 2, 'name' => 'File 2', 'minetype' => 'text', 'size' => '1.6MB', 'parentID' => 1),
-		2 => array('id' => 3, 'name' => 'File 3', 'minetype' => 'text', 'size' => '1.7MB', 'parentID' => 2),
-		3 => array('id' => 4, 'name' => 'File 4', 'minetype' => 'text', 'size' => '1.8MB', 'parentID' => 2),
-		4 => array('id' => 5, 'name' => 'File 5', 'minetype' => 'text', 'size' => '1.8MB', 'parentID' => 0),
-		5 => array('id' => 6, 'name' => 'File 6', 'minetype' => 'text', 'size' => '1.8MB', 'parentID' => 3),
-		5 => array('id' => 7, 'name' => 'File 7', 'minetype' => 'text', 'size' => '1.8MB', 'parentID' => 5)
-); */
-
-class PrivateContent extends MX_Controller
-{
-
+
+class PrivateContent extends MX_Controller {
 	public function __construct() {
-		parent::__construct();
-                $user = $this->session->userdata ( 'userInfo' );
-		$this->vservices->setApiUrl($this->config->item('api_url'));
-		$this->vservices->setConnection($this->curl);
-		$this->vservices->setUserId($user['us_id']);
-	}
-
-	public function getContent () {
-		$xmlData = $this->vservices->getPrivateTree();
-
-                $this->xml->parse($xmlData);
-
-		$aryDirs = array();
-		$aryFiles = array();
-		write_file('log.txt', var_export($xmlData, true));
-
-		if (!isset($this->xml->tree)) {
-			$aryError = array('err' => 'KhÃŽng thá» káº¿t ná»i Äáº¿n mÃ¡y chá»§!', 'errCode' => '-1');
-			$aryData = array('DIRECTORIES' =>  array() , 'FILES' => array(), 'ERROR' => $aryError);
-			echo json_encode($aryData);
+		parent::__construct ();
+		$user = $this->session->userdata ( 'userInfo' );
+		$this->vservices->setApiUrl ( $this->config->item ( 'api_url' ) );
+		$this->vservices->setConnection ( $this->curl );
+		$this->vservices->setUserId ( $user ['us_id'] );
+	}
+
+	public function getContent() {
+		$xmlData = $this->vservices->getPrivateTree ();
+
+		$this->xml->parse ( $xmlData );
+
+		$aryDirs = array ();
+		$aryFiles = array ();
+		write_file ( 'log.txt', var_export ( $xmlData, true ) );
+
+		if (! isset ( $this->xml->tree )) {
+			$aryError = array (
+					'err' => 'KhÃŽng thá» káº¿t ná»i Äáº¿n mÃ¡y chá»§!',
+					'errCode' => '-1'
+			);
+			$aryData = array (
+					'DIRECTORIES' => array (),
+					'FILES' => array (),
+					'ERROR' => $aryError
+			);
+			echo json_encode ( $aryData );
 			return;
 		}
 
-		$aryError = array('err' => $this->xml->tree->_param['err'], 'errCode' => (int)$this->xml->tree->_param['errCode']);
-
-		if (isset($this->xml->tree->folderlist->folder)) {
-			if (is_array($this->xml->tree->folderlist->folder)) {
-				foreach($this->xml->tree->folderlist->folder as $key=>$value){
-					$aryDirs[] = array('id' => $value->_param['id'], 'name' => $value->_value, 'parentID' => $value->_param['parentid'] == -1 ? 0:$value->_param['parentid']);
-				}
-			}
-			else {
+		$aryError = array (
+				'err' => $this->xml->tree->_param ['err'],
+				'errCode' => ( int ) $this->xml->tree->_param ['errCode']
+		);
+
+		if (isset ( $this->xml->tree->folderlist->folder )) {
+			if (is_array ( $this->xml->tree->folderlist->folder )) {
+				foreach ( $this->xml->tree->folderlist->folder as $key => $value ) {
+					$aryDirs [] = array (
+							'id' => $value->_param ['id'],
+							'name' => $value->_value,
+							'parentID' => $value->_param ['parentid'] == - 1 ? 0 : $value->_param ['parentid']
+					);
+				}
+			} else {
 				$folder = $this->xml->tree->folderlist->folder;
-				$aryDirs[] = array('id' => $folder->_param['id'], 'name' => $folder->_value,'parentID' => $folder->_param['parentid'] == -1 ? 0:$folder->_param['parentid']);
-			}
-		}
-
-		if (isset($this->xml->tree->filelist->file)) {
-			if (is_array($this->xml->tree->filelist->file)) {
-				foreach($this->xml->tree->filelist->file as $key=>$value){
-					//$fileUrl = dirname(dirname(dirname($value->_param['fileurl'])));
-					$fileUrl="";
-                                        if ($value->_param['fileurl']!=""){
-                                        $fileUrl = $this->config->item('api_url').$value->_param['fileurl'];
-                                        }
-                                        $thumbnail="";
-                                        if ($value->_param['thumbnail']!=""){
-                                        $thumbnail = $this->config->item('api_url').$value->_param['thumbnail'];
-                                        }
-                                        $aryFiles[] = array('id' => $value->_param['id'], 'name' => $value->_value, 'parentID' => $value->_param['parentid'] == -1 ? 0:$value->_param['parentid'], 'minetype' => $value->_param['filetype'], 'size' => $value->_param['size'],'thumbnail' => $thumbnail,'fileurl' => $fileUrl);
-				}
-			}else {
+				$aryDirs [] = array (
+						'id' => $folder->_param ['id'],
+						'name' => $folder->_value,
+						'parentID' => $folder->_param ['parentid'] == - 1 ? 0 : $folder->_param ['parentid']
+				);
+			}
+		}
+
+		if (isset ( $this->xml->tree->filelist->file )) {
+			if (is_array ( $this->xml->tree->filelist->file )) {
+				foreach ( $this->xml->tree->filelist->file as $key => $value ) {
+					// $fileUrl = dirname(dirname(dirname($value->_param['fileurl'])));
+					$fileUrl = "";
+					if ($value->_param ['fileurl'] != "") {
+						$fileUrl = $this->config->item ( 'api_url' ) . $value->_param ['fileurl'];
+					}
+
+					$thumbnail = "";
+					if ($value->_param ['thumbnail'] != "") {
+						$thumbnail = $this->config->item ( 'api_url' ) . $value->_param ['thumbnail'];
+					}
+
+					$aryFiles [] = array (
+							'id' => $value->_param ['id'],
+							'name' => $value->_value,
+							'parentID' => $value->_param ['parentid'] == - 1 ? 0 : $value->_param ['parentid'],
+							'minetype' => $value->_param ['filetype'],
+							'size' => $value->_param ['size'],
+							'thumbnail' => $thumbnail,
+							'fileurl' => $fileUrl
+					);
+				}
+			} else {
 				$file = $this->xml->tree->filelist->file;
-				$aryFiles[] = array('id' => $file->_param['id'], 'name' => $file->_value,'parentID' => $file->_param['parentid'] == -1 ? 0:$file->_param['parentid'], 'minetype' => $file->_param['filetype'], 'size' => $file->_param['size'], 'thumbnail' => $value->_param['thumbnail'],'fileurl' => $value->_param['fileurl']);
-			}
-		}
+				$aryFiles [] = array (
+						'id' => $file->_param ['id'],
+						'name' => $file->_value,
+						'parentID' => $file->_param ['parentid'] == - 1 ? 0 : $file->_param ['parentid'],
+						'minetype' => $file->_param ['filetype'],
+						'size' => $file->_param ['size'],
+						'thumbnail' => $value->_param ['thumbnail'],
+						'fileurl' => $value->_param ['fileurl']
+				);
+			}
+		}
+
 		$user = $this->session->userdata ( 'userInfo' );
-		$aryData = array('DIRECTORIES' =>  $aryDirs , 'FILES' => $aryFiles, 'ERROR' => $aryError, 'userinfo'=>$user);
-		echo json_encode($aryData);
-	}
-
-	public function createDir () {
-		$parentDir =  $this->input->post('fparentid',TRUE);
-		$name =  $this->input->post('fname',TRUE);
-
-		$xmlData = $this->vservices->actionExecute('mkdir',array('name' => $name, 'parent_id' => $parentDir == 0 ? -1:$parentDir));
-
-		$this->xml->parse($xmlData);
-
-		$aryError = array('err' => $this->xml->status->_param['err'], 'errCode' => (int)$this->xml->status->_param['errCode']);
-		$aryData = array('id' => $this->xml->status->_param['id'], 'name' => $this->xml->status->_param['name'], 'parentID' => $parentDir, 'ERROR' => $aryError);
-		echo json_encode($aryData);
-	}
-
-	public function delete () {
-		$delobj =  $this->input->post('delobj',TRUE);
-		$xmlData = $this->vservices->actionExecute('deletemulti',array('delobj' => $delobj));
-		$this->xml->parse($xmlData);
-		$aryFolders = array();
-
-		if (isset($this->xml->tree->folder)) {
-			if (is_array($this->xml->tree->folder)) {
-				foreach ($this->xml->tree->folder as $key => $folder) {
-					$aryFolders['DIRECTORIES'][] = $folder->_param['id'];
-				}
-			}
-			else {
-				$aryFolders['DIRECTORIES'][] = $this->xml->tree->folder->_param['id'];
-			}
-		}
-
-		if (isset($this->xml->tree->file)) {
-			if (is_array($this->xml->tree->file)) {
-				foreach ($this->xml->tree->file as $key => $file) {
-					$aryFolders['FILES'][] = $file->_param['id'];
-				}
-			}
-			else {
-				$aryFolders['FILES'][] = $this->xml->tree->file->_param['id'];
-			}
-		}
-
-		$aryError = array('err' => $this->xml->tree->_param['err'], 'errCode' => (int)$this->xml->tree->_param['errCode']);
-		$aryData = array('DIRECTORIES' => isset($aryFolders['DIRECTORIES']) ? $aryFolders['DIRECTORIES'] : array(), 'FILES' => isset($aryFolders['FILES'])? $aryFolders['FILES'] : array() ,'ERROR' => $aryError);
-		echo json_encode($aryData);
+		$aryData = array (
+				'DIRECTORIES' => $aryDirs,
+				'FILES' => $aryFiles,
+				'ERROR' => $aryError,
+				'userinfo' => $user
+		);
+		echo json_encode ( $aryData );
+	}
+
+	public function createDir() {
+		$parentDir = $this->input->post ( 'fparentid', TRUE );
+		$name = $this->input->post ( 'fname', TRUE );
+
+		$xmlData = $this->vservices->actionExecute ( 'mkdir', array (
+				'name' => $name,
+				'parent_id' => $parentDir == 0 ? - 1 : $parentDir
+		) );
+
+		$this->xml->parse ( $xmlData );
+
+		$aryError = array (
+				'err' => $this->xml->status->_param ['err'],
+				'errCode' => ( int ) $this->xml->status->_param ['errCode']
+		);
+		$aryData = array (
+				'id' => $this->xml->status->_param ['id'],
+				'name' => $this->xml->status->_param ['name'],
+				'parentID' => $parentDir,
+				'ERROR' => $aryError
+		);
+		echo json_encode ( $aryData );
+	}
+
+	public function delete() {
+		$delobj = $this->input->post ( 'delobj', TRUE );
+		$xmlData = $this->vservices->actionExecute ( 'deletemulti', array (
+				'delobj' => $delobj
+		) );
+		$this->xml->parse ( $xmlData );
+		$aryFolders = array ();
+
+		if (isset ( $this->xml->tree->folder )) {
+			if (is_array ( $this->xml->tree->folder )) {
+				foreach ( $this->xml->tree->folder as $key => $folder ) {
+					$aryFolders ['DIRECTORIES'] [] = $folder->_param ['id'];
+				}
+			} else {
+				$aryFolders ['DIRECTORIES'] [] = $this->xml->tree->folder->_param ['id'];
+			}
+		}
+
+		if (isset ( $this->xml->tree->file )) {
+			if (is_array ( $this->xml->tree->file )) {
+				foreach ( $this->xml->tree->file as $key => $file ) {
+					$aryFolders ['FILES'] [] = $file->_param ['id'];
+				}
+			} else {
+				$aryFolders ['FILES'] [] = $this->xml->tree->file->_param ['id'];
+			}
+		}
+
+		$aryError = array (
+				'err' => $this->xml->tree->_param ['err'],
+				'errCode' => ( int ) $this->xml->tree->_param ['errCode']
+		);
+		$aryData = array (
+				'DIRECTORIES' => isset ( $aryFolders ['DIRECTORIES'] ) ? $aryFolders ['DIRECTORIES'] : array (),
+				'FILES' => isset ( $aryFolders ['FILES'] ) ? $aryFolders ['FILES'] : array (),
+				'ERROR' => $aryError
+		);
+		echo json_encode ( $aryData );
 	}
 
 	public function rename() {
-		$id =  $this->input->post('id',TRUE);
-		$data =  $this->input->post('data',TRUE);
-
-		/* $aryData = array();
-		$aryData['RESULT'] = $this->objDirectory->rename($id, $newName, $objectType);;
-		$aryData['UPDATED'] = array('id' => $id, 'name' => $newName, 'type' => $objectType);
-		echo json_encode($aryData); */
-	}
-
-	public function copy () {
-		$destination =  $this->input->post('destination',TRUE);
-		$data =  $this->input->post('data',TRUE);
-		$act =  $this->input->post('act',TRUE);
-
-		$xmlData = $this->vservices->actionExecute('copy' ,array('act' => $act,'data' => $data, 'destination' => $destination == 0 ? -1:$destination));
-
-		error_log(date('YmdHis').' - $xmlData: '.var_export($xmlData, TRUE), 3, '/srv/www/sbg/log/file.log');
-
-		$this->xml->parse($xmlData);
-
-		$aryNewDirs =	isset($this->xml->data->folderdata) ? json_decode($this->xml->data->folderdata->_value) : array();
-		$aryNewFiles =	isset($this->xml->data->filedata) ? json_decode($this->xml->data->filedata->_value) : array();
-
-		$aryData = array('DIRECTORIES' => $aryNewDirs, 'FILES' => $aryNewFiles);
-		$aryData['ERROR'] = array('err' => $this->xml->data->_param['err'], 'errCode' => (int)$this->xml->data->_param['errCode']);;
-		echo json_encode($aryData);
-	}
-
-	
+		$item = $this->input->post ( 'data', TRUE );
+		$objItem = json_decode($item);
+		error_log(var_export($objItem->id, TRUE)."\n", 3, '/srv/www/sbg/log/rename.log');
+		$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));
+
+		//error_log(var_export($item, TRUE), 3, '/srv/www/sbg/log/rename.log');
+/* 		$aryData ['DATA'] = json_decode($data);
+		$aryData ['ERROR'] = array (
+				'err' => '',
+				'errCode' => 0
+		);
+
+		echo json_encode ( $aryData ); */
+	}
+
+	public function copy() {
+		$destination = $this->input->post ( 'destination', TRUE );
+		$data = $this->input->post ( 'data', TRUE );
+		$act = $this->input->post ( 'act', TRUE );
+
+		$xmlData = $this->vservices->actionExecute ( 'copy', array (
+				'act' => $act,
+				'data' => $data,
+				'destination' => $destination == 0 ? - 1 : $destination
+		) );
+
+		error_log ( date ( 'YmdHis' ) . ' - $xmlData: ' . var_export ( $xmlData, TRUE ), 3, '/srv/www/sbg/log/file.log' );
+
+		$this->xml->parse ( $xmlData );
+
+		$aryNewDirs = isset ( $this->xml->data->folderdata ) ? json_decode ( $this->xml->data->folderdata->_value ) : array ();
+		$aryNewFiles = isset ( $this->xml->data->filedata ) ? json_decode ( $this->xml->data->filedata->_value ) : array ();
+
+		$aryData = array (
+				'DIRECTORIES' => $aryNewDirs,
+				'FILES' => $aryNewFiles
+		);
+		$aryData ['ERROR'] = array (
+				'err' => $this->xml->data->_param ['err'],
+				'errCode' => ( int ) $this->xml->data->_param ['errCode']
+		);
+		echo json_encode ( $aryData );
+	}
 }
 
