Index: pro-violet-viettel/www/deploy/20150304/application/modules/ajax/controllers/download.php
===================================================================
--- pro-violet-viettel/www/deploy/20150304/application/modules/ajax/controllers/download.php	(revision 861)
+++ pro-violet-viettel/www/deploy/20150304/application/modules/ajax/controllers/download.php	(revision 862)
@@ -1,76 +1,142 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
 
+if (!defined('BASEPATH'))
+    exit('No direct script access allowed');
 
-class Download extends MX_Controller 
-{
+class Download 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 getFile () {
-                $data=  $this->input->post('data');
-                $treeArray=  json_decode($data,TRUE);
-           
-                if ((count($treeArray)==1) && ($treeArray[0]['type']=='file'))
+    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 getFile() {
+        $user = $this->session->userdata('userInfo');
+        $data = $this->input->post('data');
+        $treeArray = json_decode($data, TRUE);
+
+        if ((count($treeArray) == 1) && ($treeArray[0]['type'] == 'file')) {
+            $file = $treeArray[0];
+            $local_file = "downloads/" . $file['name'];
+            $download_file = $file['name'];
+            $filecontent = file_get_contents($file['fileurl']);
+            file_put_contents($local_file, $filecontent);
+        } else {
+            $download_file=$user['username']."_".date("d-m-Y");
+            $folder = "downloads/" . $download_file;
+            mkdir($folder, 0777);
+            foreach ($treeArray as $tree)
+            {
+                if($tree['type']=='file')
                 {
-                    $file=$treeArray[0];
-                    echo $file['name'];
-                    $file = file_get_contents($treeArray[0]['fileurl']);  
-                    $local_file="".$treeArray[0]['name'];
-                    file_put_contents($local_file, $file);
-                    $download_rate = 512;
-                    $download_file = $treeArray[0]['name']; 
+                    $path=$folder."/".$tree['name'];
+                    $filecontent = file_get_contents($file['fileurl']);
+                    file_put_contents($path, $filecontent);
                 }
-                die();
-                
-                
-                
-                
-                
-                
-                
-                
-                
-               
+                if($tree['type']=='directory')
+                {
+                    mkdir($folder."/".$tree['name']);
+                    $childDirs = $this->aasort($tree['childDirs'],"id");
+                    foreach ($childDirs as $index=>$dir)
+                    {
+                        if($dir['parentID']==$tree['id'])
+                        {
+                           
+                        $path=$folder."/".$tree['name']."/".$dir['name'];
+                        mkdir($path,0777);
+                        $childDirs[$index]['path']=$path;
+                        }
+                        else
+                        {
+                            foreach ($childDirs as $index2=>$dir2)
+                            {
+                                if($dir2['id']==$dir['parentID'])
+                                {
+                                   $path=$childDirs[$index2]['path']."/".$dir['name'];
+                                   mkdir($path,0777);
+                                   $childDirs[$index]['path']=$path;
+                                }
+                            }
+                        
+                        }
+                    }
+                    $childFiles = $tree['childFiles'];
+                    foreach ($childFiles as $index=>$file)
+                    {
+                        if ($file['parentID']==$tree['id'])
+                        {
+                            $path=$folder."/".$tree['name']."/".$file['name'];
+                            
+                            $filecontent = file_get_contents($file['fileurl']);
+                            file_put_contents($path, $filecontent);
+                        }
+                        else
+                        {
+                            foreach ($childDirs as $index2=>$dir2)
+                            {
+                                if($dir2['id']==$file['parentID'])
+                                {
+                                   $path=$childDirs[$index2]['path']."/".$file['name'];
+                                   $filecontent = file_get_contents($file['fileurl']);
+                                   file_put_contents($path, $filecontent);
+                                }
+                            }
+                        }
+                    }
+                }
+            }
+            $local_file = $folder.".zip";
+            $download_file = $download_file.".zip";
+            exec("zip -r ".$folder.".zip"." $folder/*");
+            
+        }
 
+        header('Cache-control: private');
+        header('Content-Type: application/zip');
+        header('Content-Length: ' . filesize($local_file));
+        header('Content-Disposition: filename=' . $download_file);
+        $download_rate = 512;
 
-   // send headers
+        // flush content
+        flush();
 
-    header('Cache-control: private');
-    header('Content-Type: application/octet-stream');
-    header('Content-Length: '.filesize($local_file));
-    header('Content-Disposition: filename='.$download_file);
- 
-    
-    // flush content
-    flush();
- 
-    // open file stream
-    $file = fopen($local_file, "r");
- 
-    while (!feof($file)) {
- 
-        // send the current file part to the browser
-        print fread($file, round($download_rate * 1024));
- 
-        // flush the content to the browser
-        flush();
- 
-        // sleep one second
-        sleep(1);
+        // open file stream
+        $file = fopen($local_file, "r");
+
+        while (!feof($file)) {
+
+            // send the current file part to the browser
+            print fread($file, round($download_rate * 1024));
+
+            // flush the content to the browser
+            flush();
+
+            // sleep one second
+            sleep(1);
+        }
+
+        // close file stream
+        fclose($file);
+
+        exit;
     }
- 
-    // close file stream
-    fclose($file);
-    
-                exit;
-            
-	}
-       
+
+    public function aasort($array, $key) {
+        $sorter = array();
+        $ret = array();
+        reset($array);
+        foreach ($array as $ii => $va) {
+            $sorter[$ii] = $va[$key];
+        }
+        asort($sorter);
+        foreach ($sorter as $ii => $va) {
+            $ret[$ii] = $array[$ii];
+        }
+        $array = $ret;
+        return $array;
+    }
 
 }
Index: pro-violet-viettel/www/deploy/20150304/assets/js/manager.js
===================================================================
--- pro-violet-viettel/www/deploy/20150304/assets/js/manager.js	(revision 861)
+++ pro-violet-viettel/www/deploy/20150304/assets/js/manager.js	(revision 862)
@@ -424,7 +424,9 @@
                                     }
 
-                                    var postdata = {
-                                        data: JSON.stringify(items)
-                                    };
+                                    for (var i = 0; i < items.length; i++) {
+                                        if (items[i].type == 'directory') {
+                                            items[i] = self.getAllDirChilds(items[i]);
+                                        }
+                                    }
                                     var url = o.host + "download/getFile/";
                                     self.redirectPost(url, {
@@ -1269,5 +1271,5 @@
                                     var form = '';
                                     $.each(args, function (key, value) {
-                                        alert (value);
+                                       
                                         form += "<input type='hidden' name='"
                                                 + key + "' value='" + value
