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 878)
+++ pro-violet-viettel/www/deploy/api/platform/modules/space/actions/actions.class.php	(revision 887)
@@ -18,7 +18,21 @@
         $this->forward('default', 'module');
     }
-    
+
+    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);
@@ -26,27 +40,24 @@
     	$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;
     }
 
     private function CreateSpaceDir($folderName, $parentId, $userId, &$objNewDir = null) {
-        /* $c = new Criteria();
+        $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);
-        error_log(var_export($category, TRUE) . "\n", 3, '/srv/www/sbg/log/filename.log');
-        
+
         if (!is_null($category)) {
             $folderName = 'Copy of ' . $folderName;
-        } */
-        
-    	$folderName = $this->autoDirName($folderName, $parentId, $userId);
-    	
+        }
+
         $category = new Tblspacecategory();
         $category->setCatName($folderName);
@@ -55,5 +66,5 @@
         $category->setCatDate(date('Y-m-d H:i:s'));
         $category->save();
-        
+
         $objNewDir = $category;
         return $category->getCatId();
@@ -102,8 +113,8 @@
         rmdir($path);
     }
-    
+
     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;        
+    	$dirId = $sourceObj->id;
         $c = new Criteria();
         $c->add(TblspacecategoryPeer::CAT_ID, $dirId);
@@ -111,14 +122,14 @@
         $currentDir = TblspacecategoryPeer::doSelectOne($c);
         $objNewDir = null;
-        
+
         $newDirID = $this->CreateSpaceDir($currentDir->getCatName(), $destination, $userId, $objNewDir);
-        
+
         $newDir = new stdClass();
         $newDir->id = $newDirID;
         $newDir->name = $objNewDir->getCatName();
         $newDir->parentID = $destination;
-        
+
         $aryNewTree['DIRECTORIES'][] = $newDir;
-        
+
         if (isset($sourceObj->childDirs)) {
         	foreach ($sourceObj->childDirs as $key => $dir) {
@@ -126,5 +137,5 @@
         	}
         }
-        
+
         if (isset($sourceObj->childFiles)) {
         	foreach ($sourceObj->childFiles as $key => $file) {
@@ -132,5 +143,5 @@
         	}
         }
-        
+
     }
 
@@ -150,12 +161,12 @@
         $tblfile->setFileDate(date('Y-m-d H:i:s'));
         $tblfile->save();
-        
+
         $c = new Criteria();
         $c->add(TblspaceresourcePeer::RES_ID, $currentFile->getFileResource());
         $res = TblspaceresourcePeer::doSelectOne($c);
-   
+
         $thumbnailUrl = file_exists("previews/$userId/".$tblfile->getFileId()."/0.png") ? "http://sbgapi.violet.vn/previews/$userId/".$tblfile->getFileId()."/0.png" : '';
-        
-        $newFile = new stdClass();        
+
+        $newFile = new stdClass();
         $newFile->id = $tblfile->getFileId();
         $newFile->name = $fileName;
@@ -165,5 +176,5 @@
         $newFile->thumbnail = $thumbnailUrl;
         $newFile->size = $res->getResFilesize();
-        
+
         return $newFile;
     }
@@ -183,5 +194,5 @@
         return $item;
     }
-    
+
     private function createPreview($fileurl, $userId, $fileid) {
     	$url = "https://docs.google.com/gview?url=" .urlencode($fileurl) . "";
@@ -210,26 +221,26 @@
     			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');
@@ -239,12 +250,12 @@
         $c->add(TblspacefilePeer::FILE_USER, $userId);
         $currentFile = TblspacefilePeer::doSelectOne($c);
-        
+
         $files = scandir("previews/".$userId."/".$fileId);
         $count=(count($files)-2);
-       
+
         if ($count < 1)
         {
             $tblres = TblspacefilePeer::retrieveByPk($fileId)->getTblspaceresource();
-            $fileName = $tblres->getFullFilename(); 
+            $fileName = $tblres->getFullFilename();
             $fileUrl = str_replace("/srv/www/violet/web", "http://sbgapi.violet.vn", $fileName);
             $count=$this->createPreview($fileUrl, $userId, $fileId);
@@ -346,7 +357,7 @@
                 if ($tblfile)
                     $tblfile->delete();
-                
-                
-                
+
+
+
                 break;
         }
@@ -417,5 +428,5 @@
         $aryTreeObj = json_decode($data);
         if (is_array($aryTreeObj)) {
-            foreach ($aryTreeObj as $key => $treeObj) {           	
+            foreach ($aryTreeObj as $key => $treeObj) {
             	if ($act == 'copy') {
             		if ($treeObj->type == 'directory'){
@@ -429,5 +440,5 @@
             }
         }
-        
+
         $this->errMsg = '';
         $this->errCode = '';
@@ -472,13 +483,19 @@
             $fileUrl = str_replace("/srv/www/violet/web", "http://sbgapi.violet.vn", $filePath);
         }
-        
+
         $ext = pathinfo($fileUrl, PATHINFO_EXTENSION);
         $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);
@@ -493,5 +510,5 @@
             );
             $aryData = array('DIRECTORIES' => array(), 'FILES' => $aryFiles, 'ERROR' => $aryError);
-            
+
             $jsonData = json_encode($aryData);
             echo $jsonData;
