Changeset 11 for pro-bachkim-filespace


Ignore:
Timestamp:
Jun 4, 2014 5:53:33 PM (11 years ago)
Author:
dungnv
Message:
 
Location:
pro-bachkim-filespace/sourcecode
Files:
2 added
4 edited

Legend:

Unmodified
Added
Removed
  • pro-bachkim-filespace/sourcecode/application/modules/ajax/controllers/privatecontent.php

    r10 r11  
    99class PrivateContent extends MX_Controller
    1010{
    11        
    12         public function __construct() {
    13                 parent::__construct();
    14         }
    15        
    16         public function getContent () {
    17                 $aryDir = array(
     11        /* private $_aryDir = array(
    1812                                0 => array ('id' => 1, 'name' => 'Dir 1', 'parentID' => 0),
    1913                                1 => array ('id' => 2, 'name' => 'Dir 2', 'parentID' => 0),
     
    2519                                7 => array ('id' => 8, 'name' => 'Dir 3.1', 'parentID' => 7)
    2620                );
    27                
    28                 $aryFile = array(
     21       
     22        private $_aryFile = array(
    2923                                0 => array('id' => 1, 'name' => 'File 1', 'minetype' => 'text', 'size' => '1.5MB', 'parentID' => 1),
    3024                                1 => array('id' => 2, 'name' => 'File 2', 'minetype' => 'text', 'size' => '1.6MB', 'parentID' => 1),
     
    3428                                5 => array('id' => 6, 'name' => 'File 6', 'minetype' => 'text', 'size' => '1.8MB', 'parentID' => 3),
    3529                                5 => array('id' => 7, 'name' => 'File 7', 'minetype' => 'text', 'size' => '1.8MB', 'parentID' => 5)
    36                 );
    37                
    38                 $aryData = array('DIRECTORIES' => $aryDir, 'FILES' => $aryFile);
    39                
     30                ); */
     31       
     32        public function __construct() {
     33                parent::__construct();
     34                $this->load->model('Directory_model', 'objDirectory', TRUE);
     35        }
     36       
     37        public function getContent () {
     38                $aryData = array('DIRECTORIES' =>  $this->objDirectory->getAllDirectory() , 'FILES' => $this->objDirectory->getAllFile());
    4039                echo json_encode($aryData);
    4140        }
    4241
    4342        public function createDir () {
     43                $parentDir =  $this->input->post('parentID',TRUE);
     44                $name =  $this->input->post('name',TRUE);
    4445               
     46                if (!is_null($parentDir) && !is_null($name)) {
     47                       
     48                        $maxID = $this->objDirectory->getMaxID (true);
     49                        $aryDir = array('id' => (int)$maxID + 1, 'name' => $name, 'parentID' => $parentDir, 'maxID' => $maxID);
     50                       
     51                        $result = $this->objDirectory->createDir($aryDir);
     52                        echo json_encode($aryDir);
     53                }
    4554        }
    4655       
    4756        public function deleteDir () {
     57                $dirID =  $this->input->post('id',TRUE);
     58                $delAllChild = $this->input->post('delallchild',TRUE);
    4859               
     60                $aryChild = $this->objDirectory->getAllChild($dirID);
     61                echo json_encode($aryChild);
    4962        }
    5063
  • pro-bachkim-filespace/sourcecode/application/modules/ajax/models/directory_model.php

    r1 r11  
    99{
    1010
    11         function __construct()
     11        public function __construct()
    1212        {
    1313                // Call the Model constructor
    1414                parent::__construct();
    1515        }
     16       
     17        public function getAllDirectory () {
     18                $dbFile = 'directory.db';
     19                $h = fopen($dbFile, 'r');
     20                $line = '';
     21                $aryDir = array();
     22                $aryField = array ('id', 'name', 'parentID');
     23               
     24                while (($line = fgets($h, 4096)) !== false) {
     25                        $aryTmp = explode(',', trim($line));
     26                        $aryDir[] = array_combine($aryField, $aryTmp);
     27                }
     28                if (!feof($h)) {
     29                        echo "Error: unexpected fgets() fail\n";
     30                }
     31                fclose($h);
     32               
     33                return $aryDir;
     34        }
     35       
     36        public function getAllFile () {
     37                $dbFile = 'file.db';
     38                $h = fopen($dbFile, 'r');
     39                $line = '';
     40                $aryFile = array();
     41                $aryField = array ('id', 'name', 'minetype', 'size', 'parentID');
     42       
     43                while (($line = fgets($h, 4096)) !== false) {
     44                        $aryTmp = explode(',', trim($line));
     45                        $aryFile[] = array_combine($aryField, $aryTmp);
     46                }
     47                if (!feof($h)) {
     48                        echo "Error: unexpected fgets() fail\n";
     49                }
     50                fclose($h);
     51       
     52                return $aryFile;
     53        }
     54       
     55        public function createDir($aryDir) {
     56                $dbFile = 'directory.db';
     57                $aryField = array ('id', 'name', 'parentID');
     58                $aryTmp = array();
     59                $h = fopen($dbFile, 'a');
     60                $line = '';
     61                foreach ($aryField as $key => $field) {
     62                        $aryTmp[$field] = $aryDir[$field];
     63                }
     64                $line = implode(',',$aryTmp);
     65                fwrite($h, $line."\n");
     66                fclose($h);
     67                return true;
     68        }
     69       
     70        public function createFile($aryFile) {
     71                $dbFile = 'file.db';
     72                $aryField = array ('id', 'name', 'minetype', 'size', 'parentID');
     73                $aryTmp = array();
     74                $h = fopen($dbFile, 'a+');
     75                $line = '';
     76                foreach ($aryField as $key => $field) {
     77                        $aryTmp[$field] = $aryFile[$field];
     78                }
     79                $line = implode(',',$aryTmp);
     80                fwrite($line."\n", $h);
     81                fclose($h);
     82                return true;
     83        }
     84       
     85        public function deleteDir ($dirID, $delAllChild = FALSE) {
     86                $dbFile = 'directory.db';
     87                $dirList = $this->getAllDirectory();
     88               
     89                $lineNumber = 0;
     90               
     91                foreach ($dirList as $key => $dir) {
     92                        if ($dir[0] == $dirID) {
     93                                $lineNumber = $key;
     94                        }
     95                }       
     96               
     97                //$aryChildDir = 
     98               
     99                if ($delAllChild) {
     100                       
     101                }
     102               
     103                unset($dirList[$lineNumber]);
     104                return $this->writeDB ($dbFile, $dirList);
     105        }
     106       
     107        public function deleteFile ($fileID) {
     108                $dbFile = 'file.db';
     109                $fileList = $this->getAllFile();
     110               
     111                $lineNumber = 0;
     112               
     113                foreach ($fileList as $key => $file) {
     114                        if ($dir[0] == $dirID) {
     115                                $lineNumber = $key;
     116                        }
     117                }
     118               
     119                unset($fileList[$lineNumber]);
     120                return $this->writeDB ($dbFile, $fileList);
     121        }
     122       
     123        public function getAllFileChild ($dirID) {
     124                $fileList = $this->getAllFile();
     125                $aryChild = array();
     126               
     127                $aryDirChild = $this->getAllDirChild($dirID);
     128               
     129        }
     130       
     131        public function getAllDirChild ($dirID) {
     132                $dirList = $this->getAllDirectory();
     133                $aryChild = array();
     134               
     135                foreach ($dirList as $key => $dir) {
     136                        if ($dir['parentID'] == $dirID) {
     137                                $aryChild[$dir['id']] = $dir;
     138                               
     139                                $aryChild[$dir['id']]['child'] = $this->getAllDirChild($dir['id']);
     140                                if (count($aryChild[$dir['id']]['child']) == 0) unset($aryChild[$dir['id']]['child']);
     141                        }
     142                }
     143               
     144                return $aryChild;
     145        }
     146       
     147        private function writeDB ($file, $aryDataSet, $flag = '') {
     148                $flag = ($flag == 'append') ? 'a' : 'w';
     149               
     150                if (file_exists($file) && count($aryDataSet) > 0) {
     151                        $h = fopen ($file, $flag);
     152                        foreach ($aryDataSet as $key => $line) {
     153                                $line = implode(',',$aryTmp);
     154                                fwrite($line."\n", $h);
     155                        }
     156                        fclose ($h);
     157                       
     158                        return true;
     159                }else {
     160                        return false;
     161                }
     162        }
     163       
     164        public function getMaxID($isDir) {
     165                $list = $isDir = true ? $this->getAllDirectory() : $this->getAllFile();
     166                $maxID = 0;
     167                foreach ($list as $key => $e) {
     168                        if ($e['id'] > $maxID) $maxID = $e['id'];
     169                }
     170               
     171                return $maxID;
     172        }
     173       
    16174}
  • pro-bachkim-filespace/sourcecode/assets/js/filemanager/filemanager.js

    r10 r11  
    5252
    5353                var privateTree =  $('#treeview-container').violetTree({
    54                         script:'http://localhost/ajax/privatecontent/getcontent',
    5554                        expandEasing: 'easeOutBounce',
    5655                        collapseEasing: 'easeOutBounce',
  • pro-bachkim-filespace/sourcecode/assets/js/vsfilemanager.js

    r9 r11  
    66                        if( o.user == undefined ) o.user = null;
    77                        if( o.homeDirNameDisplay == undefined ) o.homeDirNameDisplay = 'Home';
    8                         if( o.script == undefined ) o.script = null;
     8                        if( o.host == undefined ) o.host = 'http://localhost/';
     9                        if( o.script == undefined ) o.script = 'ajax/privatecontent/getcontent';
    910                        if( o.container == undefined ) o.container = $(this);
    1011                        if( o.dirIDprefix == undefined ) o.dirIDprefix = 'vsdir_';
     
    2122                        var sendCommand = function (p) {
    2223                                if( p.postdata == undefined ) p.postdata = null;
     24                                if( p.script == undefined ) p.script = o.script;
    2325                                if( p.callbackSuccess == undefined ) p.callbackSuccess = null;
    2426                                if( p.callbackDone == undefined ) p.callbackDone = null;
     
    2628                                if( p.callbackAlways == undefined ) p.callbackAlways = null;
    2729
    28                                 if (o.script != null) {
    29                                         $.post(o.script, p.postdata, function (data){
     30                                if (p.script != null) {
     31                                        $.post(o.host + p.script, p.postdata, function (data){
    3032                                                if (data) {
    3133                                                        parseData = $.parseJSON(data);
     
    181183
    182184                                var dirName = prompt("Please enter new directory name", "");
    183 
     185                                var script = 'ajax/privatecontent/createdir';
    184186                                sendCommand({
    185                                         postdata:{action:"create_dir",parentID:pid,name:dirName},
     187                                        script: script,
     188                                        postdata:{parentID:pid,name:dirName},
    186189                                        callbackSuccess: function (parsedData) {createNode({
    187190                                                                                id: parsedData.id,
     
    210213
    211214                                if (confirmDel && confirmChild) {
    212                                         var postdata = {action:"delete_dir",id:pid}
     215                                        var postdata = {id:pid,delallchild:true}
    213216                                        sendCommand({
     217                                                script:'ajax/privatecontent/deletedir',
    214218                                                postdata:postdata,
    215219                                                callbackSuccess: function (parsedData) {deleteNode(parsedData)}
    216220                                        });
    217                                 }       
     221                                }
    218222                        }
    219223
Note: See TracChangeset for help on using the changeset viewer.