Files
c-cms-legacy/app/Http/Controllers/FilesController.php
Mathieu Lagacé 4f83774200 File systeme V3
2020-10-19 18:45:05 -04:00

220 lines
5.4 KiB
PHP

<?php
namespace App\Http\Controllers;
use App\GoogleDriveFile;
use Illuminate\Http\Request;
use function Symfony\Component\VarDumper\Dumper\esc;
class FilesController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
return view('admin.files.index');
}
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
//
}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
//
}
/**
* Display the specified resource.
*
* @param $path
* @return \Symfony\Component\HttpFoundation\StreamedResponse
*/
public function show(String $path)
{
$all_rules = collect(\DB::table('acl_rules')->get()->all());
foreach ($all_rules as $rule)
{
if ($rule->path == "*")
{
if (\Auth::check())
{
if (\Auth::user()->checkACLRules($rule) > 0)
{
if (\Storage::exists($path))
{
return \Storage::download($path);
}
else
{
abort(404);
}
}
}
}
}
$path_array = explode('/',$path);
$checkedPath = $path_array[0];
unset($path_array[0]);
$path_array = array_values($path_array);
while ($checkedPath != $path)
{
$rules = $all_rules->where('path','=',$checkedPath.'/*');
if ($rules->isNotEmpty())
{
$access_level = 0;
foreach ($rules as $r)
{
if (\Auth::check())
{
$temp_access_level = \Auth::user()->checkACLRules($r);
if ($temp_access_level > $access_level)
{
$access_level = $temp_access_level;
}
}
else
{
if ($r->user_id == '*')
{
if ($r->access > $access_level)
{
$access_level = $r->access;
}
}
}
if ($access_level > 0)
{
if (\Storage::exists($path))
{
return \Storage::download($path);
}
else
{
abort(404);
}
}
}
}
$checkedPath = $checkedPath.'/'.$path_array[0];
unset($path_array[0]);
$path_array = array_values($path_array);
}
abort(403);
}
/**
* Show the form for editing the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function edit($id)
{
//
}
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
{
//
}
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function destroy($id)
{
//
}
public function guide()
{
return redirect('/admin/files?leftPath=Prive/Staff/Guide');
}
public function instruction()
{
return redirect('/admin/files?leftPath=Prive/Staff/Instruction');
}
public function cadet()
{
return redirect('/admin/files?leftPath=Prive/Cadet');
}
public function staff()
{
return redirect('/admin/files?leftPath=Prive/Staff');
}
public function etamas()
{
return redirect('/admin/files?leftPath=Prive/ETAMAS');
}
public function officier()
{
return redirect('/admin/files?leftPath=Prive/Officier');
}
public function publique()
{
return redirect('/admin/files?leftPath=Publique');
}
public function show_nominativeList()
{
return view('admin.files.list.index');
}
public function download_nominativeList()
{
if (\Storage::exists('/Systeme/Fichier/ListeNominative.pdf'))
{
return \Storage::download('/Systeme/Fichier/ListeNominative.pdf');
}
return view('admin.files.list.index');
}
public function edit_nominativeList()
{
return view('admin.files.list.edit');
}
public function update_nominativeList()
{
\Storage::putFileAs('Systeme/Fichier',\request()->file('nominativeList'),'ListeNominative.pdf');
clog('edit','success','a modifié la liste nominative');
return redirect('/admin/nominativelist')->with('success','Modification sauvegarder avec succès !');
}
}