- Removed body tag from footer.php and header.php

- Added permission fs/dms to dump.sql and fhcomplete.php
- Added FilesystemLib to read and write from/in filesystem
- Added FS_Model to manage filesystem with the same permission system of DB_Model
- Added more models to handle the Dms
- Modified Dms controller to use the new models
This commit is contained in:
paolo
2016-06-21 11:10:55 +02:00
parent 68963a962a
commit 5a5a22e0d5
10 changed files with 463 additions and 182 deletions
+170
View File
@@ -0,0 +1,170 @@
<?php
class FS_Model extends FHC_Model
{
protected $filepath; // Path of the file
protected $acl; // Name of the permissions array index for FS writing, reading...
function __construct($filepath = null)
{
parent::__construct();
$this->load->library('FilesystemLib');
$this->acl = $this->config->item('fhc_acl');
$this->filepath = $filepath;
}
/** ---------------------------------------------------------------
* Read data from file system
*
* @return array
*/
public function read($filename)
{
// Check Class-Attributes
if (is_null($this->filepath))
return $this->_error(lang('fhc_'.FHC_ERROR), FHC_MODEL_ERROR);
// Check method parameters
if (is_null($filename))
return $this->_error(lang('fhc_'.FHC_ERROR), FHC_MODEL_ERROR);
// Check rights
if (! $this->fhc_db_acl->isBerechtigt($this->acl[$this->filepath], 's'))
return $this->_error(lang('fhc_'.FHC_NORIGHT).' -> '.$this->acl[$this->filepath], FHC_MODEL_ERROR);
if (!is_null($data = $this->filesystemlib->read($this->filepath, $filename)))
{
return $this->_success(base64_encode($data));
}
else
{
return $this->_error(lang('fhc_'.FHC_ERROR), FHC_MODEL_ERROR);
}
}
/** ---------------------------------------------------------------
* Writing data to file system
*
* @param string $fileContent File content
* @return object
*/
public function write($filename, $content)
{
// Check Class-Attributes
if (is_null($this->filepath))
return $this->_error(lang('fhc_'.FHC_ERROR), FHC_MODEL_ERROR);
// Check method parameters
if (is_null($filename))
return $this->_error(lang('fhc_'.FHC_ERROR), FHC_MODEL_ERROR);
if (is_null($content))
return $this->_error(lang('fhc_'.FHC_ERROR), FHC_MODEL_ERROR);
// Check rights
if (! $this->fhc_db_acl->isBerechtigt($this->acl[$this->filepath], 'i'))
return $this->_error(lang('fhc_'.FHC_NORIGHT).' -> '.$this->acl[$this->filepath], FHC_MODEL_ERROR);
if ($this->filesystemlib->write($this->filepath, $filename, base64_decode($content)) === true)
{
return $this->_success(FHC_SUCCESS);
}
else
{
return $this->_error(lang('fhc_'.FHC_ERROR), FHC_MODEL_ERROR);
}
}
/** ---------------------------------------------------------------
* Append data to a file
*
* @param array $data File content
* @return array
*/
public function append($filename, $content)
{
// Check Class-Attributes
if (is_null($this->filepath))
return $this->_error(lang('fhc_'.FHC_ERROR), FHC_MODEL_ERROR);
// Check method parameters
if (is_null($filename))
return $this->_error(lang('fhc_'.FHC_ERROR), FHC_MODEL_ERROR);
if (is_null($content))
return $this->_error(lang('fhc_'.FHC_ERROR), FHC_MODEL_ERROR);
// Check rights
if (! $this->fhc_db_acl->isBerechtigt($this->acl[$this->filepath], 'i'))
return $this->_error(lang('fhc_'.FHC_NORIGHT).' -> '.$this->acl[$this->filepath], FHC_MODEL_ERROR);
if ($this->filesystemlib->append($this->filepath, $filename, base64_decode($content)) === true)
{
return $this->_success(FHC_SUCCESS);
}
else
{
return $this->_error(lang('fhc_'.FHC_ERROR), FHC_MODEL_ERROR);
}
}
/** ---------------------------------------------------------------
* Delete data from file system
*
* @param string $id Primary Key for DELETE
* @return array
*/
public function remove($filename)
{
// Check Class-Attributes
if (is_null($this->filepath))
return $this->_error(lang('fhc_'.FHC_ERROR), FHC_MODEL_ERROR);
// Check method parameters
if (is_null($filename))
return $this->_error(lang('fhc_'.FHC_ERROR), FHC_MODEL_ERROR);
// Check rights
if (! $this->fhc_db_acl->isBerechtigt($this->acl[$this->filepath], 'd'))
return $this->_error(lang('fhc_'.FHC_NORIGHT).' -> '.$this->acl[$this->filepath], FHC_MODEL_ERROR);
if ($this->filesystemlib->remove($this->filepath, $filename) === true)
{
return $this->_success(FHC_SUCCESS);
}
else
{
return $this->_error(lang('fhc_'.FHC_ERROR), FHC_MODEL_ERROR);
}
}
/** ---------------------------------------------------------------
* Rename a file
*
* @param string $id Primary Key for DELETE
* @return array
*/
public function rename($filename, $newFilename)
{
// Check Class-Attributes
if (is_null($this->filepath))
return $this->_error(lang('fhc_'.FHC_ERROR), FHC_MODEL_ERROR);
// Check method parameters
if (is_null($filename))
return $this->_error(lang('fhc_'.FHC_ERROR), FHC_MODEL_ERROR);
if (is_null($newFilename))
return $this->_error(lang('fhc_'.FHC_ERROR), FHC_MODEL_ERROR);
// Check rights
if (! $this->fhc_db_acl->isBerechtigt($this->acl[$this->filepath], 'u'))
return $this->_error(lang('fhc_'.FHC_NORIGHT).' -> '.$this->acl[$this->filepath], FHC_MODEL_ERROR);
if ($this->filesystemlib->rename($this->filepath, $filename, $this->filepath, $newFilename) === true)
{
return $this->_success(FHC_SUCCESS);
}
else
{
return $this->_error(lang('fhc_'.FHC_ERROR), FHC_MODEL_ERROR);
}
}
}