Changeset 11 for pro-bachkim-filespace
- Timestamp:
- Jun 4, 2014 5:53:33 PM (11 years ago)
- 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 9 9 class PrivateContent extends MX_Controller 10 10 { 11 12 public function __construct() { 13 parent::__construct(); 14 } 15 16 public function getContent () { 17 $aryDir = array( 11 /* private $_aryDir = array( 18 12 0 => array ('id' => 1, 'name' => 'Dir 1', 'parentID' => 0), 19 13 1 => array ('id' => 2, 'name' => 'Dir 2', 'parentID' => 0), … … 25 19 7 => array ('id' => 8, 'name' => 'Dir 3.1', 'parentID' => 7) 26 20 ); 27 28 $aryFile = array(21 22 private $_aryFile = array( 29 23 0 => array('id' => 1, 'name' => 'File 1', 'minetype' => 'text', 'size' => '1.5MB', 'parentID' => 1), 30 24 1 => array('id' => 2, 'name' => 'File 2', 'minetype' => 'text', 'size' => '1.6MB', 'parentID' => 1), … … 34 28 5 => array('id' => 6, 'name' => 'File 6', 'minetype' => 'text', 'size' => '1.8MB', 'parentID' => 3), 35 29 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()); 40 39 echo json_encode($aryData); 41 40 } 42 41 43 42 public function createDir () { 43 $parentDir = $this->input->post('parentID',TRUE); 44 $name = $this->input->post('name',TRUE); 44 45 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 } 45 54 } 46 55 47 56 public function deleteDir () { 57 $dirID = $this->input->post('id',TRUE); 58 $delAllChild = $this->input->post('delallchild',TRUE); 48 59 60 $aryChild = $this->objDirectory->getAllChild($dirID); 61 echo json_encode($aryChild); 49 62 } 50 63 -
pro-bachkim-filespace/sourcecode/application/modules/ajax/models/directory_model.php
r1 r11 9 9 { 10 10 11 function __construct()11 public function __construct() 12 12 { 13 13 // Call the Model constructor 14 14 parent::__construct(); 15 15 } 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 16 174 } -
pro-bachkim-filespace/sourcecode/assets/js/filemanager/filemanager.js
r10 r11 52 52 53 53 var privateTree = $('#treeview-container').violetTree({ 54 script:'http://localhost/ajax/privatecontent/getcontent',55 54 expandEasing: 'easeOutBounce', 56 55 collapseEasing: 'easeOutBounce', -
pro-bachkim-filespace/sourcecode/assets/js/vsfilemanager.js
r9 r11 6 6 if( o.user == undefined ) o.user = null; 7 7 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'; 9 10 if( o.container == undefined ) o.container = $(this); 10 11 if( o.dirIDprefix == undefined ) o.dirIDprefix = 'vsdir_'; … … 21 22 var sendCommand = function (p) { 22 23 if( p.postdata == undefined ) p.postdata = null; 24 if( p.script == undefined ) p.script = o.script; 23 25 if( p.callbackSuccess == undefined ) p.callbackSuccess = null; 24 26 if( p.callbackDone == undefined ) p.callbackDone = null; … … 26 28 if( p.callbackAlways == undefined ) p.callbackAlways = null; 27 29 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){ 30 32 if (data) { 31 33 parseData = $.parseJSON(data); … … 181 183 182 184 var dirName = prompt("Please enter new directory name", ""); 183 185 var script = 'ajax/privatecontent/createdir'; 184 186 sendCommand({ 185 postdata:{action:"create_dir",parentID:pid,name:dirName}, 187 script: script, 188 postdata:{parentID:pid,name:dirName}, 186 189 callbackSuccess: function (parsedData) {createNode({ 187 190 id: parsedData.id, … … 210 213 211 214 if (confirmDel && confirmChild) { 212 var postdata = { action:"delete_dir",id:pid}215 var postdata = {id:pid,delallchild:true} 213 216 sendCommand({ 217 script:'ajax/privatecontent/deletedir', 214 218 postdata:postdata, 215 219 callbackSuccess: function (parsedData) {deleteNode(parsedData)} 216 220 }); 217 } 221 } 218 222 } 219 223
Note: See TracChangeset
for help on using the changeset viewer.