offer fileupload and comments

This commit is contained in:
2018-01-10 21:09:08 +01:00
parent 6366bbc6a8
commit 665242eb4a
270 changed files with 35840 additions and 17 deletions
@@ -0,0 +1,61 @@
<?php
/**
* Created by Pensare Software.
* User: Theo Weijmer
* Date: 10/01/2018
* Time: 14:20
*/
class CommentsController extends MY_Controller {
public function __construct()
{
parent::__construct();
if ( AUTHENTICATED == FALSE ) die( 'NO ACCESS' );
$models = [];
$libraries = [];
$this->load->model( $models );
$this->load->library( $libraries );
}
public function index()
{
}
public function getComments( $foreignID, $tablename )
{
$comments = Comment::getComments( $foreignID, $tablename );
$this->json( $comments );
}
public function getComment( $commentID )
{
$comment = Comment::find( $commentID );
$comment->comment = base64_decode( $comment->comment );
$this->json( $comment );
}
public function addComment( $foreignID, $tablename )
{
$commentID = Comment::addComment( $foreignID, $tablename );
$this->json( $commentID );
}
public function saveComment( $commentID )
{
$comment = $this->input->post( 'comment' );
$comment = base64_encode( $comment );
Comment::whereId( $commentID )->update( ['comment' => $comment] );
}
}
@@ -0,0 +1,51 @@
<?php
/**
* Created by Pensare Software.
* User: Theo Weijmer
* Date: 10/01/2018
* Time: 20:22
*/
class DocumentsController extends MY_Controller {
public function __construct()
{
parent::__construct();
if ( AUTHENTICATED == FALSE ) die( 'NO ACCESS' );
$models = [];
$libraries = [];
$this->load->model( $models );
$this->load->library( $libraries );
}
public function getDocuments( $foreignID, $tablename )
{
$documents = Document::getDocuments( $foreignID, $tablename );
$this->json( $documents );
}
public function downloadDocument( $documentID )
{
$this->load->helper( 'download' );
$document = Document::find( $documentID );
$data = file_get_contents( MYROOTPATH . 'documents/' . $document->storagename );
force_download( $document->originalname, $data );
}
public function removeDocument( $documentID )
{
$document = Document::find( $documentID );
unlink( MYROOTPATH . 'documents/' . $document->storagename );
Document::whereId( $documentID )->delete();
}
}
@@ -0,0 +1,71 @@
<?php
defined( 'BASEPATH' ) OR exit( 'No direct script access allowed' );
/**
* Created by Pensare Software.
* User: Theo Weijmer
* Date: 05/01/2018
* Time: 15:03
*/
class ProjectsController extends MY_Controller {
public function __construct()
{
parent::__construct();
if ( AUTHENTICATED == FALSE ) die( 'NO ACCESS' );
$models = [];
$libraries = [];
$this->load->model( $models );
$this->load->library( $libraries );
}
public function index()
{
}
public function getAllProjects( $archive = 'F' )
{
$projects = Project::getAllProjects( $archive );
$this->json( $projects );
}
public function saveProject()
{
$projectValidation = new ProjectValidation();
if ( ! $projectValidation->getValidationResult() )
return $this->json( [
'success' => FALSE, 'messages' => $projectValidation->getErrorMessages()] );
$project = $this->input->post();
$projectID = $project['id'];
unset( $project['id'] );
$projectID = Project::saveProject( $projectID, $project );
$this->json( ['success' => TRUE, 'projectID' => $projectID] );
}
public function archiveProject( $projectID, $status )
{
Project::whereId( $projectID )->update( ['archive' => $status] );
}
public function removeProject( $projectID )
{
$removeProject = new RemoveProject( $projectID );
if ( $removeProject->getAllowDelete() === FALSE ) return $this->json( ['result' => FALSE] );
Project::removeProject( $projectID );
$this->json( ['result' => TRUE] );
}
}
@@ -0,0 +1,76 @@
<?php
/**
* Created by Pensare Software.
* User: Theo Weijmer
* Date: 10/01/2018
* Time: 19:03
*/
class FileUpload extends MY_Controller {
private $storagename;
public function __construct()
{
parent::__construct();
if ( AUTHENTICATED == FALSE ) die( 'NO ACCESS' );
$models = [];
$libraries = [];
$this->load->model( $models );
$this->load->library( $libraries );
}
public function upload( $foreignID, $tablename )
{
$config['upload_path'] = MYROOTPATH . 'documents/temp';
$config['allowed_types'] = '*';
$config['remove_spaces'] = FALSE;
$this->load->library( 'upload', $config );
if ( ! $this->upload->do_upload( 'userfile' ) )
{
$error = ['error' => $this->upload->display_errors()];
$this->load->view( 'upload_form', $error );
}
else
{
$data = ['upload_data' => $this->upload->data()];
$this->setStoragename();
$this->persistDocument( $data['upload_data'], $foreignID, $tablename );
$this->renameDocument( $data['upload_data']['full_path'] );
}
}
private function setStoragename()
{
$this->load->helper( 'string' );
$this->storagename = sha1( random_string( 'alnum', 16 ) );
}
private function persistDocument( $data, $foreignID, $tablename )
{
$file = [
'storagename' => $this->storagename,
'originalname' => $data['file_name'],
'user_id' => USERID,
'uploaddate' => date( 'Y-m-d H:i:s' ),
'foreign_id' => $foreignID,
'foreign_table' => $tablename
];
Document::create( $file );
}
private function renameDocument( $original )
{
rename( $original, MYROOTPATH . 'documents/' . $this->storagename );
}
}