Index: pro-violet-viettel/www/deploy/api/platform/modules/space/actions/actions.class.php
===================================================================
--- pro-violet-viettel/www/deploy/api/platform/modules/space/actions/actions.class.php	(revision 890)
+++ pro-violet-viettel/www/deploy/api/platform/modules/space/actions/actions.class.php	(revision 894)
@@ -20,31 +20,36 @@
 
     private function createImateThumbnail($fileName, &$thumnail = '') {
-    	$thumnailPath = dirname($fileName);
-    	$rawFileName = str_replace($thumnailPath, '', $fileName);
-    	$thumbnailfileName = substr($rawFileName, 0, strlen($rawFileName) - 4) . '_thumb.jpg';
-    	list($width, $height) = getimagesize($fileName);
-    	$new_width = 64;
-    	$new_height = 50;
-    	$image_p = imagecreatetruecolor($new_width, $new_height);
-    	$image = imagecreatefromjpeg($fileName);
-    	imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
-    	$thumnail = $thumnailPath.$thumbnailfileName;
-    	return imagejpeg($image_p, $thumnailPath.$thumbnailfileName, 30);
-    }
-
-    private function autoDirName ($folderName, $parentId, $userId) {
-
-    	$c = new Criteria();
-    	$c->add(TblspacecategoryPeer::CAT_PARENT, $parentId);
-    	$c->add(TblspacecategoryPeer::CAT_USER, $userId);
-    	$c->add(TblspacecategoryPeer::CAT_NAME, $folderName);
-    	$category = TblspacecategoryPeer::doSelectOne($c);
-
-    	if (!is_null($category)) {
-    		$newFolderName = 'Copy of ' . $folderName;
-    		$folderName = $this->autoDirName($newFolderName, $parentId, $userId);
-    	}
-
-    	return $folderName;
+        $thumnailPath = dirname($fileName);
+        $rawFileName = str_replace($thumnailPath, '', $fileName);
+        $thumbnailfileName = substr($rawFileName, 0, strlen($rawFileName) - 4) . '_thumb.jpg';
+        list($width, $height) = getimagesize($fileName);
+        $new_width = 64;
+        $new_height = 50;
+        $image_p = imagecreatetruecolor($new_width, $new_height);
+        $image = imagecreatefromjpeg($fileName);
+        imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
+        $thumnail = $thumnailPath . $thumbnailfileName;
+        return imagejpeg($image_p, $thumnailPath . $thumbnailfileName, 30);
+    }
+
+    public function executeTest($pathToImage="") {
+       echo violetUtil::createThumb("/srv/www/violet/web/uploads/space/4/4067/1.jpg");
+       return sfView::NONE;
+    }
+
+    private function autoDirName($folderName, $parentId, $userId) {
+
+        $c = new Criteria();
+        $c->add(TblspacecategoryPeer::CAT_PARENT, $parentId);
+        $c->add(TblspacecategoryPeer::CAT_USER, $userId);
+        $c->add(TblspacecategoryPeer::CAT_NAME, $folderName);
+        $category = TblspacecategoryPeer::doSelectOne($c);
+
+        if (!is_null($category)) {
+            $newFolderName = 'Copy of ' . $folderName;
+            $folderName = $this->autoDirName($newFolderName, $parentId, $userId);
+        }
+
+        return $folderName;
     }
 
@@ -115,6 +120,6 @@
 
     private function CopySpaceDir($sourceObj, $destination, $userId, &$aryNewTree) {
-    	error_log(date('YmdHis').' - Source Obj: '.var_export($sourceObj, TRUE), 3, '/srv/www/sgb/log/file.log');
-    	$dirId = $sourceObj->id;
+        error_log(date('YmdHis') . ' - Source Obj: ' . var_export($sourceObj, TRUE), 3, '/srv/www/sgb/log/file.log');
+        $dirId = $sourceObj->id;
         $c = new Criteria();
         $c->add(TblspacecategoryPeer::CAT_ID, $dirId);
@@ -133,15 +138,14 @@
 
         if (isset($sourceObj->childDirs)) {
-        	foreach ($sourceObj->childDirs as $key => $dir) {
-        			$this->CopySpaceDir($dir, $newDir->id, $userId , $aryNewTree);
-        	}
+            foreach ($sourceObj->childDirs as $key => $dir) {
+                $this->CopySpaceDir($dir, $newDir->id, $userId, $aryNewTree);
+            }
         }
 
         if (isset($sourceObj->childFiles)) {
-        	foreach ($sourceObj->childFiles as $key => $file) {
-        		$aryNewTree['FILES'][] = $this->CopySpaceFile($file->id, $newDirID, $userId);
-        	}
-        }
-
+            foreach ($sourceObj->childFiles as $key => $file) {
+                $aryNewTree['FILES'][] = $this->CopySpaceFile($file->id, $newDirID, $userId);
+            }
+        }
     }
 
@@ -166,5 +170,5 @@
         $res = TblspaceresourcePeer::doSelectOne($c);
 
-        $thumbnailUrl = file_exists("previews/$userId/".$tblfile->getFileId()."/0.png") ? "http://sbgapi.violet.vn/previews/$userId/".$tblfile->getFileId()."/0.png" : '';
+        $thumbnailUrl = file_exists("previews/$userId/" . $tblfile->getFileId() . "/0.png") ? "http://sbgapi.violet.vn/previews/$userId/" . $tblfile->getFileId() . "/0.png" : '';
 
         $newFile = new stdClass();
@@ -196,52 +200,47 @@
 
     private function createPreview($fileurl, $userId, $fileid) {
-    	$url = "https://docs.google.com/gview?url=" .urlencode($fileurl) . "";
-    	file_put_contents("1.html", $url);
-    	$content="";
-    	$ch = curl_init();
-    	curl_setopt($ch, CURLOPT_URL, $url);
-    	curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
-    	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
-    	$content = curl_exec($ch);
-    	file_put_contents("1.html", $content);
-    	preg_match("'img\?id\\\u003d(.*?)%3D'si", $content, $matches);
-    	$count=0;
-    	if (isset($matches[1]))
-    	{
-    		$id = $matches[1];
-    		$count=0;
-    		for ($i = 0; $i <= 20; $i++) {
-    			$imgurl = "https://docs.google.com/viewerng/img?id=" . $id . "&w=600&page=" . $i;
-    			$ch = curl_init();
-    			curl_setopt($ch, CURLOPT_URL, $imgurl);
-    			curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
-    			curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
-    			$image = curl_exec($ch);
-    			$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
-    			if ($code == 200)
-    			{
-
-    				$count++;
-    				if (!file_exists('previews/'. $userId."/")) {
-    					mkdir('previews/'. $userId."/", 0777, true);
-    				}
-
-    				if (!file_exists('previews/'. $userId."/".$fileid."/")) {
-
-    					mkdir('previews/'. $userId."/".$fileid."/", 0777, true);
-
-    				}
-    				file_put_contents("previews/" . $userId . "/" . $fileid . "/" . $i . ".png", $image);
-
-    			} else {
-    				break;
-    			}
-    		}
-
-    	}
-    	return $count;
-    }
-
-    public function executePreview(){
+        $url = "https://docs.google.com/gview?url=" . urlencode($fileurl) . "";
+        file_put_contents("1.html", $url);
+        $content = "";
+        $ch = curl_init();
+        curl_setopt($ch, CURLOPT_URL, $url);
+        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
+        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
+        $content = curl_exec($ch);
+        file_put_contents("1.html", $content);
+        preg_match("'img\?id\\\u003d(.*?)%3D'si", $content, $matches);
+        $count = 0;
+        if (isset($matches[1])) {
+            $id = $matches[1];
+            $count = 0;
+            for ($i = 0; $i <= 20; $i++) {
+                $imgurl = "https://docs.google.com/viewerng/img?id=" . $id . "&w=600&page=" . $i;
+                $ch = curl_init();
+                curl_setopt($ch, CURLOPT_URL, $imgurl);
+                curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
+                curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
+                $image = curl_exec($ch);
+                $code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
+                if ($code == 200) {
+
+                    $count++;
+                    if (!file_exists('previews/' . $userId . "/")) {
+                        mkdir('previews/' . $userId . "/", 0777, true);
+                    }
+
+                    if (!file_exists('previews/' . $userId . "/" . $fileid . "/")) {
+
+                        mkdir('previews/' . $userId . "/" . $fileid . "/", 0777, true);
+                    }
+                    file_put_contents("previews/" . $userId . "/" . $fileid . "/" . $i . ".png", $image);
+                } else {
+                    break;
+                }
+            }
+        }
+        return $count;
+    }
+
+    public function executePreview() {
         $fileId = $this->getRequestParameter('fileId');
         $userId = $this->getRequestParameter('userId');
@@ -251,17 +250,16 @@
         $currentFile = TblspacefilePeer::doSelectOne($c);
 
-        $files = scandir("previews/".$userId."/".$fileId);
-        $count=(count($files)-2);
-
-        if ($count < 1)
-        {
+        $files = scandir("previews/" . $userId . "/" . $fileId);
+        $count = (count($files) - 2);
+
+        if ($count < 1) {
             $tblres = TblspacefilePeer::retrieveByPk($fileId)->getTblspaceresource();
             $fileName = $tblres->getFullFilename();
             $fileUrl = str_replace("/srv/www/violet/web", "http://sbgapi.violet.vn", $fileName);
-            $count=$this->createPreview($fileUrl, $userId, $fileId);
-        }
-        $data['fileid']=$fileId;
-        $data['folder']="previews/".$userId."/".$fileId;
-        $data['total']=$count;
+            $count = $this->createPreview($fileUrl, $userId, $fileId);
+        }
+        $data['fileid'] = $fileId;
+        $data['folder'] = "previews/" . $userId . "/" . $fileId;
+        $data['total'] = $count;
         echo json_encode($data);
         return sfView::NONE;
@@ -307,5 +305,5 @@
             $c->add(TblspacefilePeer::FILE_TYPE, explode(';', $filter), Criteria::IN);
         $c->addAscendingOrderByColumn(TblspacefilePeer::FILE_NAME);
-        $this->userId= $userId;
+        $this->userId = $userId;
         $this->tblfiles = TblspacefilePeer::doSelect($c);
         $this->isGetAll = $isGetAll;
@@ -315,5 +313,5 @@
 
     public function executeMkdir() {
-    	$objNewDir = null;
+        $objNewDir = null;
         $userId = $this->getRequestParameter('userid');
         $parentId = $this->getRequestParameter('parent_id');
@@ -403,5 +401,5 @@
                 if ($tblfile)
                     $tblfile->delete();
-                $dirPath="previews/$userId/$id/";
+                $dirPath = "previews/$userId/$id/";
                 array_map('unlink', glob("$dirPath/*.*"));
                 rmdir($dirPath);
@@ -429,13 +427,12 @@
         if (is_array($aryTreeObj)) {
             foreach ($aryTreeObj as $key => $treeObj) {
-            	if ($act == 'copy') {
-            		if ($treeObj->type == 'directory'){
-            			$this->CopySpaceDir($treeObj, $destination, $userId, $aryNewTree);
-            		}
-            		else {
-            			$newFile = $this->CopySpaceFile($treeObj->id, $destination, $userId);
-            			$aryNewTree['FILES'][] = $newFile;
-            		}
-            	}
+                if ($act == 'copy') {
+                    if ($treeObj->type == 'directory') {
+                        $this->CopySpaceDir($treeObj, $destination, $userId, $aryNewTree);
+                    } else {
+                        $newFile = $this->CopySpaceFile($treeObj->id, $destination, $userId);
+                        $aryNewTree['FILES'][] = $newFile;
+                    }
+                }
             }
         }
@@ -444,5 +441,5 @@
         $this->errCode = '';
         $this->aryNewTree = $aryNewTree;
-        error_log(date('YmdHis').' - $aryNewTree: '.var_export($aryNewTree, TRUE), 3, '/srv/www/sbg/log/file.log');
+        error_log(date('YmdHis') . ' - $aryNewTree: ' . var_export($aryNewTree, TRUE), 3, '/srv/www/sbg/log/file.log');
     }
 
@@ -487,25 +484,22 @@
         $ext = strtolower($ext);
 
-        if (in_array($ext, array("ppt","xls","doc","pdf","docx","pptx","xlsx")))
-        {
+        if (in_array($ext, array("ppt", "xls", "doc", "pdf", "docx", "pptx", "xlsx"))) {
             $this->createPreview($fileUrl, $userId, $tblfile->getFileId());
         }
 
-        if (in_array($ext, array("jpg", "jpeg", "png","gif","tiff","dvg","bmp")))
-        {
-        	$thumbnail = '';
-        	$this->createImateThumbnail($filePath, $thumnail);
-        }
+       
 
         if ($response == 1) {
             $aryError = array('err' => "", 'errCode' => 0);
             $ext = pathinfo($fileUrl, PATHINFO_EXTENSION);
-            $thumbnail="";
-            if (file_exists("previews/$userId/".$tblfile->getFileId()."/0.png"))
-            {
-                $thumbnail="http://sbgapi.violet.vn/previews/$userId/".$tblfile->getFileId()."/0.png";
+            $thumbnail = "";
+            if (in_array($ext, array("jpg", "jpeg", "png", "gif", "tiff", "dvg", "bmp"))) {
+            $thumbnail=violetUtil::createThumb($filePath);
+            }
+            if (file_exists("previews/$userId/" . $tblfile->getFileId() . "/0.png")) {
+                $thumbnail = "previews/$userId/" . $tblfile->getFileId() . "/0.png";
             }
             $aryFiles = array(
-                0 => array('id' => $tblfile->getFileId(),'thumbnail'=>$thumbnail, 'fileurl' => $fileUrl, 'name' => $fileName, 'minetype' => $ext, 'size' => $fileSize, 'parentID' => $catId),
+                0 => array('id' => $tblfile->getFileId(), 'thumbnail' => $thumbnail, 'fileurl' => $fileUrl, 'name' => $fileName, 'minetype' => $ext, 'size' => $fileSize, 'parentID' => $catId),
             );
             $aryData = array('DIRECTORIES' => array(), 'FILES' => $aryFiles, 'ERROR' => $aryError);
Index: pro-violet-viettel/www/deploy/api/platform/modules/space/templates/dirSuccess.php
===================================================================
--- pro-violet-viettel/www/deploy/api/platform/modules/space/templates/dirSuccess.php	(revision 890)
+++ pro-violet-viettel/www/deploy/api/platform/modules/space/templates/dirSuccess.php	(revision 894)
@@ -23,15 +23,32 @@
       $tblres = TblspacefilePeer::retrieveByPk($tblfile->getFileId())->getTblspaceresource();
       $fileName = $tblres->getFullFilename();
-      //$fileName = str_replace('/srv/www/violet/web', '', $fileName);
-      $fileName = str_replace(dirname(dirname(dirname($fileName))), '', $fileName);
-      //$fileName = 'http://sbgapi.violet.vn'.$fileName;
+     // $fileName = str_replace('/srv/www/violet/web', '', $fileName);
+      $fileName = str_replace(dirname(dirname(dirname(dirname(dirname($fileName))))), '', $fileName);
+     // $fileName = 'http://sbgapi.violet.vn'.$fileName;
       $fileNames = explode("/", $fileName);
       $name=$fileNames[(count($fileNames)-1)];
       $fileName = str_replace($name, "", $fileName). $name;
+      $ext = strtolower($tblfile->getFileType());
+      $filePath="";
       $thumbnail="";
-      if (file_exists("previews/$userId/".$tblfile->getFileId()."/0.png"))
+      if (in_array($ext, array("jpg","png","jpeg","bmp","gif")))
       {
-          $thumbnail="http://sbgapi.violet.vn/previews/$userId/".$tblfile->getFileId()."/0.png";
+          $names = explode(".", $name);
+          $filePath = $tblres->getFullFilename();
+          $filePath = str_replace('/srv/www/violet/web', '', $filePath);
+          $filePath = str_replace($name, "", $fileName). $names[0]."_thumb.jpg";
+      
+         
+                $thumbnail= $filePath; 
+            
       }
+      else
+      {
+        if (file_exists("previews/$userId/".$tblfile->getFileId()."/0.png"))
+        {
+            $thumbnail="previews/$userId/".$tblfile->getFileId()."/0.png";
+        }
+      }
+      
       $fileSize = $tblres->getResFilesize();
       ?>
