Advertisement
Guest User

Untitled

a guest
Jan 6th, 2017
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 45.00 KB | None | 0 0
  1. <?php
  2. /**
  3.  * Admin Controller
  4.  *
  5.  * PHP version 5
  6.  *
  7.  * @category Admin
  8.  * @package  App\Http\Controller
  9.  * @author   Jordan Kniest <jkniest@gena-clusters.net>
  10.  * @license  Standard copyright
  11.  * @link     https://gena-render.net
  12.  */
  13.  
  14. namespace App\Http\Controllers;
  15.  
  16. use App\Apikey;
  17. use App\Job;
  18. use App\Language;
  19. use App\Permission;
  20. use App\Role;
  21. use App\Setting;
  22. use App\Slave;
  23. use App\Text;
  24. use App\Translation;
  25. use App\User;
  26. use App\Util;
  27. use App\Word;
  28. use Illuminate\Http\Request;
  29. use Illuminate\Support\Facades\Lang;
  30. use Validator;
  31. use Auth;
  32. use App\Frame;
  33. use Response;
  34.  
  35. /**
  36.  * This class handles all Admin requests and routes.
  37.  * For example: /admin/*
  38.  *
  39.  * This class contains all actions an admin can do.. for example
  40.  * create new jobs or users.
  41.  *
  42.  * @category Admin
  43.  * @package  App\Http\Controller
  44.  * @author   Jordan Kniest <jkniest@gena-clusters.net>
  45.  * @license  Standard copyright
  46.  * @link     https://gena-render.net
  47.  */
  48. class AdminController extends Controller
  49. {
  50.     /**
  51.      * AdminController constructor.
  52.      *
  53.      * This method defines the middleware that is used for all the methods.
  54.      * In this case the "admin.permission" middleware is used.
  55.      */
  56.     public function __construct()
  57.     {
  58.         $this->middleware('admin.permission');
  59.     }
  60.  
  61.     /**
  62.      * Route: /admin -- GET
  63.      *
  64.      * This method will simply redirect the user to the front page
  65.      *
  66.      * @param Request $request The incoming request
  67.      *
  68.      * @return \Illuminate\Http\RedirectResponse
  69.      */
  70.     public function index(Request $request)
  71.     {
  72.         return redirect('/');
  73.     }
  74.  
  75.     /**
  76.      * Route: /admin/roles - GET
  77.  
  78.      * This method handles the requests for the user role overview.
  79.      * If the user does not have the necessary permissions, he will
  80.      * be redirected to the "/admin" route.
  81.      *
  82.      * Otherwise the view "backend/admin/jobs" will be returned
  83.      *
  84.      * @param Request $request The incoming request
  85.      *
  86.      * @return mixed
  87.      */
  88.     public function roles(Request $request)
  89.     {
  90.         if (!Auth::user()->can('admin_roles')) {
  91.             return redirect('/admin');
  92.         }
  93.  
  94.         return view('backend.admin.roles');
  95.     }
  96.  
  97.     /**
  98.      * Route: /admin/roles/{id} - GET
  99.      *
  100.      * This method handles the requests for the detail page of a
  101.      * single user role. If the user does not have the necessary
  102.      * permissions, he will be redirected to the "/admin" route.
  103.      *
  104.      * Otherwise the role and user are loaded and the
  105.      * "backend/admin/role-details" view will be returned.
  106.      *
  107.      * @param Request $request The incoming request
  108.      * @param integer $id      The id of the user role
  109.      *
  110.      * @return mixed
  111.      */
  112.     public function roleDetails(Request $request, $id)
  113.     {
  114.         if (!Auth::user()->can('admin_roles')) {
  115.             return redirect('/admin');
  116.         }
  117.  
  118.         $role = Role::find($id);
  119.         if ($role == null) {
  120.             return redirect('/roles');
  121.         }
  122.  
  123.         $users = $role->users()->get();
  124.         $perms = $role->perms()->get();
  125.  
  126.         return view(
  127.             'backend.admin.roles-details',
  128.             ['role' => $role, 'users' => $users, 'perms' => $perms]
  129.         );
  130.     }
  131.  
  132.     /**
  133.      * Route: /admin/roles/delete/{id} - DELETE
  134.      *
  135.      * This method will handle incoming delete requests for user
  136.      * roles. If the user does not have the necessary permissions
  137.      * he will be redirected to the "/admin" route.
  138.      *
  139.      * Otherwise the route will be deleted and the user will be
  140.      * redirected to the "/admin/roles" route.
  141.      *
  142.      * @param Request $request The incoming request
  143.      * @param integer $id      The id of the user role
  144.      *
  145.      * @return mixed
  146.      */
  147.     public function roleDelete(Request $request, $id)
  148.     {
  149.         if (!Auth::user()->can('admin_roles')) {
  150.             return redirect('/admin');
  151.         }
  152.  
  153.         $role = Role::find($id);
  154.         if ($role == null) {
  155.             return redirect('/admin/roles');
  156.         }
  157.  
  158.         if ($role->name == 'admin' || $role->name == 'default') {
  159.             return redirect('/admin/roles/' . $id);
  160.         }
  161.  
  162.         foreach ($users = $role->users()->get() as $user) {
  163.             $user->attachRole(4);
  164.         }
  165.  
  166.         $role->delete();
  167.         $role->users()->sync([]);
  168.         $role->perms()->sync([]);
  169.         $role->forceDelete();
  170.  
  171.         return redirect('/admin/roles');
  172.     }
  173.  
  174.     /**
  175.      * Route: /admin/roles/edit/{id} - GET
  176.      *
  177.      * This method handles the requests for the user role edit
  178.      * form. If the user does not have the necessary permissions
  179.      * he will be redirected to the "/admin" route.
  180.      *
  181.      * Otherwise the role-edit view will be loaded
  182.      *
  183.      * @param Request $request The incoming request
  184.      * @param integer $id      The id of the user role
  185.      *
  186.      * @return mixed
  187.      */
  188.     public function roleEdit(Request $request, $id)
  189.     {
  190.         if (!Auth::user()->can('admin_roles')) {
  191.             return redirect('/admin');
  192.         }
  193.  
  194.         $role = Role::find($id);
  195.         if ($role == null) {
  196.             return redirect('/admin/roles');
  197.         }
  198.  
  199.         if ($role->name == 'admin') {
  200.             return redirect('/admin/roles/' . $id);
  201.         }
  202.  
  203.         return view(
  204.             'backend.admin.roles-edit',
  205.             ['role' => $role]
  206.         );
  207.     }
  208.  
  209.     /**
  210.      * Route: /admin/roles/edit/{id} - POST
  211.      *
  212.      * This route handles incoming edit requests for the user roles.
  213.      * If the user does not have the necessary permissions he will
  214.      * be redirected to the "/admin" route.
  215.      *
  216.      * Otherwise the role details will be validated and saved.
  217.      * Afterwards the "/admin/routes/edit" view will be loaded
  218.      *
  219.      * @param Request $request The incoming request
  220.      * @param integer $id      The id of the user role
  221.      *
  222.      * @return mixed
  223.      */
  224.     public function roleSaveFields(Request $request, $id)
  225.     {
  226.         if (!Auth::user()->can('admin_roles')) {
  227.             return redirect('/admin');
  228.         }
  229.  
  230.         $this->validate(
  231.             $request,
  232.             [
  233.                 'name' => 'required|max:255',
  234.                 'max-priority' => 'required|numeric|min:1',
  235.                 'max-parallel-jobs' => 'required|numeric|min:-1|not:0'
  236.             ]
  237.         );
  238.  
  239.         $role = Role::find($id);
  240.         if ($role == null) {
  241.             return redirect('/admin/roles');
  242.         }
  243.  
  244.         if ($role->name == 'admin') {
  245.             return redirect('/admin/roles/' . $id);
  246.         }
  247.  
  248.         $role->display_name = $request->name;
  249.         $role->max_priority = $request->input('max-priority');
  250.         $role->max_parallel_jobs = $request->input('max-parallel-jobs');
  251.         $role->save();
  252.  
  253.         return redirect('/admin/roles/edit/' . $id)->with('successfull-fields', '1');
  254.     }
  255.  
  256.     /**
  257.      * Route: /admin/roles/permissions/{id} - POST
  258.      *
  259.      * This method handles incoming permission save requests.
  260.      * If the user does not have necessary permission he will
  261.      * be redirected to the "/admin" route.
  262.      *
  263.      * Otherwise the permissions are being saved in the database
  264.      * and the "/admin/roles/edit" route will be loaded.
  265.      *
  266.      * @param Request $request The incoming request
  267.      * @param integer $id      The id of the user role
  268.      *
  269.      * @return mixed
  270.      */
  271.     public function roleSavePerms(Request $request, $id)
  272.     {
  273.         if (!Auth::user()->can('admin_roles')) {
  274.             return redirect('/admin');
  275.         }
  276.  
  277.         $role = Role::find($id);
  278.         if ($role == null) {
  279.             return redirect('/admin/roles');
  280.         }
  281.  
  282.         if ($role->name == 'admin') {
  283.             return redirect('/admin/roles/' . $id);
  284.         }
  285.  
  286.         foreach (Permission::get() as $perm) {
  287.             if ($perm->display_name == '') {
  288.                 continue;
  289.             }
  290.  
  291.             if ($request->has('perm-' . $perm->name)) {
  292.                 if (!$role->hasPermission($perm->name)) {
  293.                     $role->attachPermission($perm);
  294.                 }
  295.             } else {
  296.                 $role->detachPermission($perm);
  297.             }
  298.         }
  299.  
  300.         return redirect('/admin/roles/edit/' . $id)
  301.             ->with('successfull-permissions', '1');
  302.     }
  303.  
  304.     /**
  305.      * Route: /admin/roles/create - POST
  306.      *
  307.      * This method handles incoming user role create requests. If
  308.      * the user does not have the necessary permissions he will be
  309.      * redirected to the "/admin" route.
  310.      *
  311.      * Otherwise the input will be validated and the role will be
  312.      * created. Afterwards the "/admin/roles/{newroleid}" view will
  313.      * be loaded.
  314.      *
  315.      * @param Request $request The incoming request
  316.      *
  317.      * @return mixed
  318.      */
  319.     public function roleCreate(Request $request)
  320.     {
  321.         if (!Auth::user()->can('admin_roles')) {
  322.             return redirect('/admin');
  323.         }
  324.  
  325.         $this->validate(
  326.             $request,
  327.             [
  328.                 'display-name' => 'required|max:255',
  329.                 'max-priority' => 'required|numeric|min:1',
  330.                 'max-parallel-jobs' => 'required|numeric|min:-1|not:0',
  331.                 'name' => 'required|max:255|unique:roles'
  332.             ]
  333.         );
  334.  
  335.         $role = new Role();
  336.         $role->name = $request->input('name');
  337.         $role->display_name = $request->input('display-name');
  338.         $role->max_priority = $request->input('max-priority');
  339.         $role->max_parallel_jobs = $request->input('max-parallel-jobs');
  340.         $role->save();
  341.  
  342.         foreach (Permission::get() as $perm) {
  343.             if ($perm->display_name == '') {
  344.                 continue;
  345.             }
  346.  
  347.             if ($request->has('perm-' . $perm->name)) {
  348.                 $role->attachPermission($perm);
  349.             }
  350.         }
  351.  
  352.         $role->attachPermission(Permission::find('global'));
  353.  
  354.         return redirect('/admin/roles/' . $role->id);
  355.     }
  356.  
  357.     /**
  358.      * Route: /admin/users - GET
  359.      *
  360.      * This method handles the user overview page requests.
  361.      * If the user does not have the necessary permissions he will
  362.      * be redirected to the "/admin" route.
  363.      *
  364.      * Otherwise the "backend/admin/users" view will be loaded
  365.      *
  366.      * @param Request $request The incoming request
  367.      *
  368.      * @return mixed
  369.      */
  370.     public function users(Request $request)
  371.     {
  372.         if (!Auth::user()->can('admin_users')) {
  373.             return redirect('/admin');
  374.         }
  375.  
  376.         return view('backend.admin.users');
  377.     }
  378.  
  379.     /**
  380.      * Route: /admin/users/{id} - GET
  381.      *
  382.      * This method handles the user detail page. If the
  383.      * user does not have the necessary permissions he
  384.      * will be redirected to the "/admin" route.
  385.      *
  386.      * Otherwise the user will be loaded and the
  387.      * "backend/admin/user-details" view will be shown.
  388.      *
  389.      * @param Request $request The incoming request
  390.      * @param integer $id      The id of the user
  391.      *
  392.      * @return mixed
  393.      */
  394.     public function userDetails(Request $request, $id)
  395.     {
  396.         if (!Auth::user()->can('admin_users')) {
  397.             return redirect('/admin');
  398.         }
  399.  
  400.         $user = User::find($id);
  401.         if ($user == null) {
  402.             return redirect('/admin/users');
  403.         }
  404.  
  405.         return view(
  406.             'backend.admin.user-details',
  407.             ['user' => $user]
  408.         );
  409.     }
  410.  
  411.     /**
  412.      * Route: /admin/users/delete/{id} - DELETE
  413.      *
  414.      * This method handles all incoming user delete requests.
  415.      * If the user does not have the necessary permissions he will be
  416.      * redirected to the "/admin" route.
  417.      *
  418.      * Otherwise the user will be deleted (also all jobs of him)
  419.      * Afterwards the "/admin/users" route will be loaded
  420.      *
  421.      * @param Request $request The incoming request
  422.      * @param integer $id      The id of the user
  423.      *
  424.      * @return mixed
  425.      */
  426.     public function userDelete(Request $request, $id)
  427.     {
  428.         if (!Auth::user()->can('admin_users')) {
  429.             return redirect('/admin');
  430.         }
  431.  
  432.         $user = User::find($id);
  433.         if ($user == null) {
  434.             return redirect('/admin/users');
  435.         }
  436.  
  437.         if ($user->id == 1) {
  438.             return redirect('/admin/users/' . $id);
  439.         }
  440.  
  441.         foreach ($user->jobs()->get() as $job) {
  442.             $job->delete(); // TODO: Delete all related files
  443.         }
  444.  
  445.         $user->delete();
  446.         return redirect('/admin/users');
  447.     }
  448.  
  449.     /**
  450.      * Route: /admin/users/create - POST
  451.      *
  452.      * This method handles the user creation. If the user does not
  453.      * have the necessary permissions he will be redirected to the
  454.      * "/admin" route.
  455.      *
  456.      * Otherwise the input will be validated and a new user will be
  457.      * created. Afterwards the user detail page will be shown.
  458.      *
  459.      * @param Request $request The incoming request
  460.      *
  461.      * @return mixed
  462.      */
  463.     public function userCreate(Request $request)
  464.     {
  465.         if (!Auth::user()->can('admin_users')) {
  466.             return redirect('/admin');
  467.         }
  468.  
  469.         $this->validate(
  470.             $request,
  471.             [
  472.                 'username' => 'required|max:255|unique:users',
  473.                 'email' => 'required|email|max:255|unique:users',
  474.                 'password' => 'required|max:255|min:6',
  475.                 'role' => 'numeric|required'
  476.             ]
  477.         );
  478.  
  479.         $user = new User();
  480.         $user->username = $request->input('username');
  481.         $user->email = $request->input('email');
  482.         $user->password = bcrypt($request->input('password'));
  483.         $user->save();
  484.  
  485.         $user->attachRole($request->input('role'));
  486.         return redirect('/admin/users/' . $user->id);
  487.     }
  488.  
  489.     /**
  490.      * Route: /admin/users/edit/{id} - GET
  491.      *
  492.      * This method shows the user edit form. If the user does
  493.      * not have the necessary permissions he will be redirected
  494.      * to the "/admin" route.
  495.      *
  496.      * Otherwise the user will be loaded and the
  497.      * "backend/admin/users-edit" view will be shown.
  498.      *
  499.      * @param Request $request The incoming request
  500.      * @param integer $id      The id of the user
  501.      *
  502.      * @return mixed
  503.      */
  504.     public function userEdit(Request $request, $id)
  505.     {
  506.         if (!Auth::user()->can('admin_users')) {
  507.             return redirect('/admin');
  508.         }
  509.  
  510.         $user = User::find($id);
  511.         if ($user == null) {
  512.             return redirect('/admin/users');
  513.         }
  514.  
  515.         return view(
  516.             'backend.admin.users-edit',
  517.             ['user' => $user]
  518.         );
  519.     }
  520.  
  521.     /**
  522.      * Route: /admin/users/edit/{id} - POST
  523.      *
  524.      * This method handles all incoming user edit requests.
  525.      * If the user does not have the necessary permissions he
  526.      * will be redirected to the "/admin" route.
  527.      *
  528.      * Otherwise the input will be validated and the user
  529.      * will be changed in database. Afterwards  the edit
  530.      * form will be loaded.
  531.      *
  532.      * @param Request $request The incoming request
  533.      * @param integer $id      The id of the user
  534.      *
  535.      * @return mixed
  536.      */
  537.     public function userSaveData(Request $request, $id)
  538.     {
  539.         if (!Auth::user()->can('admin_users')) {
  540.             return redirect('/admin');
  541.         }
  542.  
  543.         $this->validate(
  544.             $request,
  545.             [
  546.                 'username' => 'required|max:255|unique:users,username,' . $id,
  547.                 'email' => 'required|email|max:255|unique:users,email,' . $id,
  548.                 'password' => 'max:255|min:6'
  549.             ]
  550.         );
  551.  
  552.         $user = User::find($id);
  553.         if ($user == null) {
  554.             return redirect('/admin/users');
  555.         }
  556.  
  557.         $user->username = $request->input('username');
  558.         $user->email = $request->input('email');
  559.  
  560.         if ($request->input('password') != '') {
  561.             $user->password = bcrypt($request->input('password'));
  562.         }
  563.  
  564.         $user->save();
  565.  
  566.         if ($user->id != 1) {
  567.             $role = $user->roles()->first();
  568.             $user->detachRole($role);
  569.  
  570.             $user->attachRole($request->input('role'));
  571.         }
  572.  
  573.         return redirect('/admin/users/edit/' . $id)->with('successfull-fields', '1');
  574.     }
  575.  
  576.     /**
  577.      * Route: /admin/jobs - GET
  578.      *
  579.      * This method shows the job overview. If the user
  580.      * does not have the necessary permissions he will
  581.      * be redirected to the "/admin" route.
  582.      *
  583.      * Otherwise the job list will be loaded (with filters)
  584.      * and the "backend/admin/jobs" route will be shown.
  585.      *
  586.      * @param Request $request The incoming request
  587.      * @param String  $filter  The filter that should be used
  588.      *
  589.      * @return mixed
  590.      */
  591.     public function jobs(Request $request, $filter = 'none')
  592.     {
  593.         if (!Auth::user()->can('admin_jobs')) {
  594.             return redirect('/admin');
  595.         }
  596.  
  597.         switch($filter) {
  598.         case 'active':
  599.             $jobs = Job::globalActiveJobs();
  600.             $useFilter = true;
  601.             break;
  602.  
  603.         case 'inactive':
  604.             $jobs = Job::globalInactiveJobs();
  605.             $useFilter = true;
  606.             break;
  607.  
  608.         case 'finished':
  609.             $jobs = Job::globalFinishedJobs();
  610.             $useFilter = true;
  611.             break;
  612.  
  613.         default:
  614.             $jobs = Job::where('enabled', '=', 1)->get();
  615.             $useFilter = false;
  616.             break;
  617.         }
  618.  
  619.         return view(
  620.             'backend.admin.jobs',
  621.             ['jobs' => $jobs, 'filter' => $useFilter]
  622.         );
  623.     }
  624.  
  625.     /**
  626.      * Route: /admin/jobs/{id} - GET
  627.      *
  628.      * This method will show the job detail page. If the user
  629.      * does not have the necessary permissions he will be
  630.      * redirected to the "/admin" route.
  631.      *
  632.      * Otherwise the "backend/admin/job-details" view will be
  633.      * shown.
  634.      *
  635.      * @param Request $request The incoming request
  636.      * @param integer $id      The id of the job
  637.      *
  638.      * @return mixed
  639.      */
  640.     public function jobDetails(Request $request, $id)
  641.     {
  642.         if (!Auth::user()->can('admin_jobs')) {
  643.             return redirect('/admin');
  644.         }
  645.  
  646.         $job = Job::find($id);
  647.         if ($job == null) {
  648.             return redirect('/admin/jobs');
  649.         }
  650.  
  651.         return view(
  652.             'backend.admin.job-details',
  653.             ['job' => $job]
  654.         );
  655.     }
  656.  
  657.     /**
  658.      * Route: /admin/jobs/delete/{id} - DELETE
  659.      *
  660.      * This method handles all incoming job deletion requests. If
  661.      * the user does not have the necessary permissions he will be
  662.      * redirected to the "/admin" route.
  663.      *
  664.      * Otherwise the job and all frames of the job will be deleted
  665.      * and the user will be redirected to the job overview page.
  666.      *
  667.      * @param Request $request The incoming request
  668.      * @param integer $id      The id of the job
  669.      *
  670.      * @return mixed
  671.      */
  672.     public function jobDelete(Request $request, $id)
  673.     {
  674.         if (!Auth::user()->can('admin_jobs')) {
  675.             return redirect('/admin');
  676.         }
  677.  
  678.         $job = Job::find($id);
  679.         if ($job == null) {
  680.             return redirect('/admin/jobs');
  681.         }
  682.  
  683.         foreach (Frame::where('job_id', '=', $job->id)->get() as $frame) {
  684.             $framePath = storage_path('frames/'.$frame->id.'.png');
  685.             if (@file_exists($framePath)) {
  686.                 unlink($framePath);
  687.             }
  688.  
  689.             $thumbPath = storage_path('thumbs/'.$frame->id.'.png');
  690.             if (@file_exists($thumbPath)) {
  691.                 unlink($thumbPath);
  692.             }
  693.  
  694.             $frame->delete();
  695.         }
  696.  
  697.         // Delete the model file
  698.         $path = storage_path('models/'.$job->id.'.zip');
  699.         if (@file_exists($path)) {
  700.             unlink($path);
  701.         }
  702.  
  703.         $job->delete();
  704.         return redirect('/admin/jobs');
  705.     }
  706.  
  707.     /**
  708.      * Route: /admin/jobs/download/{id} -- GET
  709.      *
  710.      * This method handles all download requests for the model file.
  711.      * If the user does not have the necessary permissions he will be
  712.      * redirected to the "/admin" route.
  713.      *
  714.      * Otherwise the model archive file will be loaded and send as a
  715.      * response to the user.
  716.      *
  717.      * @param Request $request The incoming request
  718.      * @param integer $id      The id of the job
  719.      *
  720.      * @return mixed
  721.      */
  722.     public function jobDownload(Request $request, $id)
  723.     {
  724.         if (!Auth::user()->can('admin_jobs')) {
  725.             return redirect('/admin');
  726.         }
  727.  
  728.         $job = Job::find($id);
  729.         if ($job == null) {
  730.             return redirect('/admin/jobs');
  731.         }
  732.  
  733.         $zip = new \ZipArchive();
  734.         $path = storage_path($job->id . '.zip');
  735.         $zip->open($path, \ZipArchive::CREATE);
  736.  
  737.         foreach (Frame::where('job_id', '=', $job->id)->get() as $frame) {
  738.             $framePath = storage_path('frames/'.$frame->id.'.png');
  739.             $zip->addFile($framePath, $frame->frame.'.png');
  740.         }
  741.  
  742.         $zip->close();
  743.         return Response::download($path, $job->title.'.zip')
  744.             ->deleteFileAfterSend(true);
  745.     }
  746.  
  747.     /**
  748.      * Route: /admin/jobs/upload - POST
  749.      *
  750.      * This method handles all incoming job creations. If the user
  751.      * does not have the necessary permissions he will be redirected
  752.      * to the "/admin" route.
  753.      *
  754.      * Otherwise the input will be validated and the model file will
  755.      * be copied.
  756.      *
  757.      * If the uploaded file is an archive with multiple blender files
  758.      * all the filename's are returned.
  759.      *
  760.      * If the uploaded file is an archive with only one blender file
  761.      * this file is taken as the job file
  762.      *
  763.      * If the uploaded file is a blender file itself than it will be
  764.      * zipped.
  765.      *
  766.      * @param Request $request The incoming request
  767.      *
  768.      * @return mixed
  769.      */
  770.     public function jobUpload(Request $request)
  771.     {
  772.         if (!Auth::user()->can('admin_jobs')) {
  773.             return redirect('/admin');
  774.         }
  775.  
  776.         $validator = Validator::make(
  777.             $request->all(),
  778.             [
  779.                 'title' => 'required|max:255',
  780.                 'priority' => 'numeric|min:1|',
  781.                 'firstFrame' => 'numeric|min:1',
  782.                 'lastFrame' => 'numeric|greater_or_equals:firstFrame',
  783.                 'renderEngine' => 'required',
  784.                 'user' => 'required|numeric'
  785.             ]
  786.         );
  787.  
  788.         if ($validator->fails()) {
  789.             return $validator->errors()->all();
  790.         } else {
  791.             return JobController::createJob($request, $request->input('user'));
  792.         }
  793.     }
  794.  
  795.     /**
  796.      * Route: /admin/jobs/set -- POST
  797.      *
  798.      * This method handles incoming job filename set requests.
  799.      * If the user does not have the necessary permissions a 500 server
  800.      * error will be returned. (This should be changed to 403)
  801.      *
  802.      * Otherwise the filename of the job will be set and the frames
  803.      * are generated in the database.
  804.      *
  805.      * @param Request $request The incoming request
  806.      *
  807.      * @return string|void
  808.      */
  809.     public function setModel(Request $request)
  810.     {
  811.         if (!Auth::user()->can('admin_jobs')) {
  812.             return abort(500);
  813.         }
  814.  
  815.         if (!$request->has('id') || !$request->has('filename')) {
  816.             return abort(500);
  817.         }
  818.  
  819.         $job = Job::find($request->input('id'));
  820.         if ($job == null) {
  821.             return abort(500);
  822.         }
  823.  
  824.         $job->filename = $request->input('filename');
  825.         $job->enabled = true;
  826.         $job->save();
  827.  
  828.         for ($i = $job->firstFrame; $i <= $job->lastFrame; $i++) {
  829.             $frame = new Frame();
  830.             $frame->job_id = $job->id;
  831.             $frame->frame = $i;
  832.             $frame->render_engine = $job->render_engine;
  833.             $frame->user_id = $request->input('userid');
  834.             $frame->filename = $request->input('filename');
  835.             $frame->save();
  836.         }
  837.  
  838.         return "true";
  839.     }
  840.  
  841.     /**
  842.      * Route: /admin/slaves - GET
  843.      *
  844.      * This method shows the slave overview. If the user does not have
  845.      * the necessary permissions he will be redirected to the "/admin"
  846.      * route.
  847.      *
  848.      * Otherwise the "backend/admin/slaves" view will be shown
  849.      *
  850.      * @param Request $request The incoming request
  851.      *
  852.      * @return mixed
  853.      */
  854.     public function slaves(Request $request)
  855.     {
  856.         if (!Auth::user()->can('admin_slaves')) {
  857.             return redirect('/admin');
  858.         }
  859.  
  860.         return view('backend.admin.slaves');
  861.     }
  862.  
  863.     /**
  864.      * Route: /admin/slaves/enable/{id} - GET
  865.      *
  866.      * This method enables a specific slave. If the user does
  867.      * not have the necessary permissions he will be redirected
  868.      * to the "/admin" route.
  869.      *
  870.      * Otherwise the slave will be enabled and the user will be
  871.      * redirected to the slave overview (/admin/slaves)
  872.      *
  873.      * @param Request $request The incoming requests
  874.      * @param integer $id      The id of the slave
  875.      *
  876.      * @return mixed
  877.      */
  878.     public function slaveEnable(Request $request, $id)
  879.     {
  880.         if (!Auth::user()->can('admin_slaves')) {
  881.             return redirect('/admin');
  882.         }
  883.  
  884.         $slave = Slave::find($id);
  885.         if ($slave == null) {
  886.             return redirect('/admin/slaves');
  887.         }
  888.  
  889.         $slave->enabled = 1;
  890.         $slave->save();
  891.  
  892.         return redirect('/admin/slaves');
  893.     }
  894.  
  895.     /**
  896.      * Route: /admin/slaves/disable/{id} - GET
  897.      *
  898.      * This method disabled a specific slave. If the user does not have
  899.      * the necessary permissions he will be redirected to the
  900.      * "/admin" route.
  901.      *
  902.      * Otherwise the slave will be disabled and the user will be
  903.      * redirected to the slave overview (/admin/slaves)
  904.      *
  905.      * @param Request $request The incoming request
  906.      * @param integer $id      The id of the slave
  907.      *
  908.      * @return mixed
  909.      */
  910.     public function slaveDisable(Request $request, $id)
  911.     {
  912.         if (!Auth::user()->can('admin_slaves')) {
  913.             return redirect('/admin');
  914.         }
  915.  
  916.         $slave = Slave::find($id);
  917.         if ($slave == null) {
  918.             return redirect('/admin/slaves');
  919.         }
  920.  
  921.         $slave->enabled = 0;
  922.         $slave->save();
  923.  
  924.         return redirect('/admin/slaves');
  925.     }
  926.  
  927.     /**
  928.      * Route: /admin/slaves/delete/{id} - GET
  929.      *
  930.      * This method handles incoming slave deleting requests.
  931.      * If the user does not have the necessary permissions he will
  932.      * be redirected to the "/admin" route.
  933.      *
  934.      * Otherwise the slave will be deleted and the user will
  935.      * be redirected to the slave overview (/admin/slaves)
  936.      *
  937.      * @param Request $request The incoming request
  938.      * @param integer $id      The id of the slave
  939.      *
  940.      * @return mixed
  941.      */
  942.     public function slaveDelete(Request $request, $id)
  943.     {
  944.         if (!Auth::user()->can('admin_slaves')) {
  945.             return redirect('/admin');
  946.         }
  947.  
  948.         $slave = Slave::find($id);
  949.         if ($slave == null || $slave->enabled == 1) {
  950.             return redirect('/admin/slaves');
  951.         }
  952.  
  953.         $slave->delete();
  954.         return redirect('/admin/slaves');
  955.     }
  956.  
  957.     /**
  958.      * Route: /admin/slaves/{id} -- GET
  959.      *
  960.      * This method shows the slave detail page. If the user does not
  961.      * have the necessary permissions he will be redirected to the
  962.      * "/admin" route.
  963.      *
  964.      * Otherwise the slave will be loaded and the "backend/admin/slave-details"
  965.      * view will be shown.
  966.      *
  967.      * @param Request $request The incoming request
  968.      * @param integer $id      The id of the slave
  969.      *
  970.      * @return mixed
  971.      */
  972.     public function slaveDetails(Request $request, $id)
  973.     {
  974.         if (!Auth::user()->can('admin_slaves')) {
  975.             return redirect('/admin');
  976.         }
  977.  
  978.         $slave = Slave::find($id);
  979.         if ($slave == null) {
  980.             return redirect('/admin/slaves');
  981.         }
  982.  
  983.         $currentJob = null;
  984.         $currentFrame = 0;
  985.  
  986.         $frame = Frame::find($slave->current_job);
  987.         if ($frame != null) {
  988.             $currentJob = Job::find($frame->job_id);
  989.             $currentFrame = $frame->frame;
  990.         }
  991.  
  992.         return view(
  993.             'backend.admin.slave-details',
  994.             [
  995.                 'slave' => $slave,
  996.                 'currentJob' => $currentJob,
  997.                 'currentFrame' => $currentFrame
  998.             ]
  999.         );
  1000.     }
  1001.  
  1002.     /**
  1003.      * Route: /admin/settings - GET
  1004.      *
  1005.      * This method shows the settings form. If the user does not have
  1006.      * the necessary permission he will be redirected to the
  1007.      * "/admin" route.
  1008.      *
  1009.      * Otherwise the "backend/admin/settings" view will be shown.
  1010.      *
  1011.      * @param Request $request The incoming request
  1012.      *
  1013.      * @return mixed
  1014.      */
  1015.     public function settings(Request $request)
  1016.     {
  1017.         if (!Auth::user()->can('admin_settings')) {
  1018.             return redirect('/admin');
  1019.         }
  1020.  
  1021.         return view('backend.admin.settings');
  1022.     }
  1023.  
  1024.     /**
  1025.      * Route: /admin/users/edit/{id} - POST
  1026.      *
  1027.      * This method saves the website settings. If the user does not have
  1028.      * the necessary permissions he will be redirected to the
  1029.      * "/admin" route.
  1030.      *
  1031.      * Otherwise the input will ve validated and saved. Afterwards the user
  1032.      * will be redirected to the "/admin/settings" page
  1033.      *
  1034.      * @param Request $request The incoming request
  1035.      *
  1036.      * @return mixed
  1037.      */
  1038.     public function settingsSaveWebsite(Request $request)
  1039.     {
  1040.         if (!Auth::user()->can('admin_users')) {
  1041.             return redirect('/admin');
  1042.         }
  1043.  
  1044.         $this->validate(
  1045.             $request,
  1046.             [
  1047.                 'title' => 'required|max:255',
  1048.                 'logo' => 'image'
  1049.             ]
  1050.         );
  1051.  
  1052.         $title = Setting::where('name', 'LIKE', 'title')->first();
  1053.         $title->value = $request->input('title');
  1054.         $title->save();
  1055.  
  1056.         if ($request->hasFile('logo') && $request->file('logo')->isValid()) {
  1057.             $request->file('logo')->move(public_path() . '/img', 'logo.png');
  1058.         }
  1059.  
  1060.         return redirect('/admin/settings')->with('successfull-fields', '1')
  1061.             ->header('Cache-Control', 'no-store, no-cache, must-revalidate');
  1062.     }
  1063.  
  1064.     /**
  1065.      * Route: /admin/texts - GET
  1066.      *
  1067.      * This method shows the text overview. If the user does
  1068.      * not have the necessary permissions he will be
  1069.      * redirected to the "/admin" route.
  1070.      *
  1071.      * Otherwise the "backend/admin/texts" view will be shown
  1072.      *
  1073.      * @param Request $request The incoming request
  1074.      *
  1075.      * @return mixed
  1076.      */
  1077.     public function texts(Request $request)
  1078.     {
  1079.         if (!Auth::user()->can('admin_texts')) {
  1080.             return redirect('/admin');
  1081.         }
  1082.  
  1083.         return view('backend.admin.texts');
  1084.     }
  1085.  
  1086.     /**
  1087.      * Route: /admin/texts/{id} - GET
  1088.      *
  1089.      * This method will show the specific details of a text. If the
  1090.      * user does not have the necessary permission he will be
  1091.      * redirected to the "/admin" route.
  1092.      *
  1093.      * Otherwise the "backend/admin/text-view" view will be loaded
  1094.      * with the specific text.
  1095.      *
  1096.      * @param Request $request The incoming request
  1097.      * @param integer $id      The id of the text
  1098.      *
  1099.      * @return mixed
  1100.      */
  1101.     public function textView(Request $request, $id)
  1102.     {
  1103.         if (!Auth::user()->can('admin_texts')) {
  1104.             return redirect('/admin');
  1105.         }
  1106.  
  1107.         $text = Text::find($id);
  1108.         if ($text == null) {
  1109.             return redirect('/texts');
  1110.         }
  1111.  
  1112.         return view(
  1113.             'backend.admin.text-view',
  1114.             ['text' => $text]
  1115.         );
  1116.     }
  1117.  
  1118.     /**
  1119.      * Route: /admin/texts/edit/{id} - GET
  1120.      *
  1121.      * This method will show the form to edit a specific text.
  1122.      * If the user does not have the necessary permissions he
  1123.      * will be redirected to the "/admin" route.
  1124.      *
  1125.      * Otherwise the "backend/admin/text-edit" view will be shown
  1126.      * with the specific text.
  1127.      *
  1128.      * @param Request $request The incoming request
  1129.      * @param integer $id      The id of the text
  1130.      *
  1131.      * @return mixed
  1132.      */
  1133.     public function textEdit(Request $request, $id)
  1134.     {
  1135.         if (!Auth::user()->can('admin_texts')) {
  1136.             return redirect('/admin');
  1137.         }
  1138.  
  1139.         $text = Text::find($id);
  1140.         if ($text == null) {
  1141.             return redirect('/admin/texts');
  1142.         }
  1143.  
  1144.         return view(
  1145.             'backend.admin.text-edit',
  1146.             ['text' => $text]
  1147.         );
  1148.     }
  1149.  
  1150.     /**
  1151.      * Route: /admin/texts/edit/{id} - POST
  1152.      *
  1153.      * This method will save a specific text. If the user does
  1154.      * not have the necessary permissions he will be redirected
  1155.      * to the "/admin" route.
  1156.      *
  1157.      * Otherwise the text will be saved and the user will be
  1158.      * redirected to the edit form of the text.
  1159.      *
  1160.      * @param Request $request The incoming request
  1161.      * @param integer $id      The id of the text
  1162.      *
  1163.      * @return mixed
  1164.      */
  1165.     public function textSave(Request $request, $id)
  1166.     {
  1167.         if (!Auth::user()->can('admin_texts')) {
  1168.             return redirect('/admin');
  1169.         }
  1170.  
  1171.         $text = Text::find($id);
  1172.         if ($text == null) {
  1173.             return redirect('/admin/texts');
  1174.         }
  1175.  
  1176.         $text->value = $request->input('value');
  1177.         $text->save();
  1178.  
  1179.         return redirect('/admin/texts/edit/' . $id)->with('successfull-fields', '1');
  1180.     }
  1181.  
  1182.     /**
  1183.      * Route: /admin/api - GET
  1184.      *
  1185.      * This method will show the api key overview. If the user
  1186.      * does not have the necessary permissions he will be
  1187.      * redirected to the "/admin" route.
  1188.      *
  1189.      * Otherwise the "backend/admin/api" view will be shown.
  1190.      *
  1191.      * @param Request $request The incoming request
  1192.      *
  1193.      * @return mixed
  1194.      */
  1195.     public function api(Request $request)
  1196.     {
  1197.         if (!Auth::user()->can('admin_api')) {
  1198.             return redirect('/admin');
  1199.         }
  1200.  
  1201.         return view('backend.admin.api');
  1202.     }
  1203.  
  1204.     /**
  1205.      * Route: /admin/api/delete/{id} - DELETE
  1206.      *
  1207.      * This method will handle all incoming delete requests for api keys.
  1208.      * If the user does not have the necessary permissions he will be
  1209.      * redirected to the "/admin" route.
  1210.      *
  1211.      * Otherwise the api key will be deleted and the user will be redirected
  1212.      * to the api key overview.
  1213.      *
  1214.      * @param Request $request The incoming request
  1215.      * @param integer $id      The id of the api key
  1216.      *
  1217.      * @return mixed
  1218.      */
  1219.     public function apiDelete(Request $request, $id)
  1220.     {
  1221.         if (!Auth::user()->can('admin_api')) {
  1222.             return redirect('/admin');
  1223.         }
  1224.  
  1225.         $key = Apikey::find($id);
  1226.         if ($key == null) {
  1227.             return redirect('/admin/api');
  1228.         }
  1229.  
  1230.         $key->delete();
  1231.         return redirect('/admin/api');
  1232.     }
  1233.  
  1234.     /**
  1235.      * Route: /admin/languages -- GET
  1236.      *
  1237.      * This method will show the language overview. If the user
  1238.      * does not have the necessary permissions he will be
  1239.      * redirected to the "/admin" route.
  1240.      *
  1241.      * Otherwise the "backend/admin/languages" view will be
  1242.      * shown.
  1243.      *
  1244.      * @param Request $request The incoming request
  1245.      *
  1246.      * @return mixed
  1247.      */
  1248.     public function languages(Request $request)
  1249.     {
  1250.         if (!Auth::user()->can('admin_languages')) {
  1251.             return redirect('/admin');
  1252.         }
  1253.  
  1254.         return view('backend.admin.languages');
  1255.     }
  1256.  
  1257.     /**
  1258.      * Route: /admin/languages/{id} -- GET
  1259.      *
  1260.      * This method shows the edit form for the languages. If the user
  1261.      * does not have the necessary permissions he will be redirected
  1262.      * to the "/admin" route.
  1263.      *
  1264.      * Otherwise the "backend/admin/languages-edit" view will be
  1265.      * shown.
  1266.      *
  1267.      * @param Request $request The incoming request
  1268.      * @param integer $id      The id of the language
  1269.      *
  1270.      * @return mixed
  1271.      */
  1272.     public function languagesEdit(Request $request, $id)
  1273.     {
  1274.         if (!Auth::user()->can('admin_languages')) {
  1275.             return redirect('/admin');
  1276.         }
  1277.  
  1278.         $language = Language::find($id);
  1279.         if ($language == null) {
  1280.             return redirect('/admin/languages');
  1281.         }
  1282.  
  1283.         return view(
  1284.             'backend.admin.languages-edit',
  1285.             [
  1286.                 'lang'  => $language,
  1287.             ]
  1288.         );
  1289.     }
  1290.  
  1291.     /**
  1292.      * Route: /admin/languages/{id} -- POST
  1293.      *
  1294.      * This method will save the language file. If the user does not
  1295.      * have the necessary permissions he will be redirected to the
  1296.      * "/admin" route.
  1297.      *
  1298.      * First it saves the translations into the database. Afterwards
  1299.      * the "Translation::recreate.." method is called to recreate
  1300.      * all files
  1301.      *
  1302.      * @param Request $request The incoming request
  1303.      * @param integer $id      The id of the language
  1304.      *
  1305.      * @return mixed
  1306.      */
  1307.     public function languageSave(Request $request, $id)
  1308.     {
  1309.         if (!Auth::user()->can('admin_languages')) {
  1310.             return redirect('/admin');
  1311.         }
  1312.  
  1313.         $language = Language::find($id);
  1314.         if ($language == null) {
  1315.             return redirect('/admin/languages');
  1316.         }
  1317.  
  1318.         foreach ($request->input() as $name => $input) {
  1319.             if (!starts_with($name, 'lang|')) {
  1320.                 continue;
  1321.             }
  1322.  
  1323.             $key = substr($name, 5);
  1324.             $word = Word::where('key', $key)->first();
  1325.  
  1326.             $translation = $language->translations()
  1327.                 ->where('word_id', $word->id)->first();
  1328.             $translation->translation = $input;
  1329.             $translation->save();
  1330.         }
  1331.  
  1332.         // Regenerate the files
  1333.         Translation::regenerateFiles($language);
  1334.  
  1335.         return back()->with('successful');
  1336.     }
  1337.  
  1338.     /**
  1339.      * Route: /admin/languages/create -- POST
  1340.      *
  1341.      * This method creates a new language. If the user does not have
  1342.      * the necessary permissions he will be redirected to the
  1343.      * "/admin" route.
  1344.      *
  1345.      * Otherwise the input will be validated, a new database entry
  1346.      * will be created and the folder structure will be copied.
  1347.      *
  1348.      * @param Request $request The incoming request
  1349.      *
  1350.      * @return \Illuminate\Http\RedirectResponse
  1351.      */
  1352.     public function languageCreate(Request $request)
  1353.     {
  1354.         if (!Auth::user()->can('admin_languages')) {
  1355.             return redirect('/admin');
  1356.         }
  1357.  
  1358.         $this->validate(
  1359.             $request,
  1360.             [
  1361.                 'name' => 'required|max:255',
  1362.                 'code' => 'required|max:255|unique:languages'
  1363.             ]
  1364.         );
  1365.  
  1366.         $lang = new Language();
  1367.         $lang->name = $request->input('name');
  1368.         $lang->code = strtolower($request->input('code'));
  1369.         $lang->save();
  1370.  
  1371.         if (file_exists(resource_path('lang/'.$lang->code))) {
  1372.             Util::rmdir(resource_path('lang/'.$lang->code));
  1373.         }
  1374.  
  1375.         mkdir(resource_path('lang/'.$lang->code));
  1376.         return back();
  1377.     }
  1378.  
  1379.     /**
  1380.      * Route: /admin/languages/translate/{id} -- GET
  1381.      *
  1382.      * This method will show the translation view. If the user does not
  1383.      * have the necessary permissions he will be redirected to the
  1384.      * "/admin" route.
  1385.      *
  1386.      * @param Request $request The incoming request
  1387.      * @param integer $id      The id of the language
  1388.      *
  1389.      * @return mixed
  1390.      */
  1391.     public function languagesTranslate(Request $request, $id)
  1392.     {
  1393.         if (!Auth::user()->can('admin_languages')) {
  1394.             return redirect('/admin');
  1395.         }
  1396.  
  1397.         $language = Language::find($id);
  1398.         if ($language == null) {
  1399.             return redirect('/admin/languages');
  1400.         }
  1401.  
  1402.         $translation = $language->translations()->where('translation', '')->first();
  1403.         if ($translation == null) {
  1404.             $fieldname = null;
  1405.         } else {
  1406.             $fieldname = $translation->word()->first()->key;
  1407.         }
  1408.  
  1409.         return view(
  1410.             'backend.admin.languages-translate',
  1411.             [
  1412.                 'lang' => $language,
  1413.                 'field' => $fieldname
  1414.             ]
  1415.         );
  1416.     }
  1417.  
  1418.     /**
  1419.      * Route: /admin/languages/translate/{id} -- GET
  1420.      *
  1421.      * This method saves the translated line and calls the regenerate
  1422.      * function to recreate all language files.
  1423.      *
  1424.      * @param Request $request The incoming request
  1425.      * @param integer $id      The id of the language
  1426.      *
  1427.      * @return \Illuminate\Http\RedirectResponse
  1428.      */
  1429.     public function languageSaveTranslation(Request $request, $id)
  1430.     {
  1431.         if (!Auth::user()->can('admin_languages')) {
  1432.             return redirect('/admin');
  1433.         }
  1434.  
  1435.         $language = Language::find($id);
  1436.         if ($language == null) {
  1437.             return redirect('/admin/languages');
  1438.         }
  1439.  
  1440.         $fieldname = "";
  1441.         $value = "";
  1442.         foreach ($request->input() as $field => $input) {
  1443.             if (starts_with($field, 'lang|')) {
  1444.                 $fieldname = str_replace('lang|', '', $field);
  1445.                 $value = $input;
  1446.                 break;
  1447.             }
  1448.         }
  1449.  
  1450.         $word = Word::where('key', $fieldname)->first();
  1451.         $translation = $language->translations()
  1452.             ->where('word_id', $word->id)->first();
  1453.         $translation->translation = $value;
  1454.         $translation->save();
  1455.  
  1456.         Translation::regenerateFiles($language);
  1457.  
  1458.         return redirect('/admin/languages/translate/'.$id.'?s='.str_random(5));
  1459.     }
  1460.  
  1461.     /**
  1462.      * Route: /admin/languages/reset -- DELETE
  1463.      *
  1464.      * This method recreates all language files and data.
  1465.      *
  1466.      * 1.) Deleting all languages in database
  1467.      * 2.) Deleting all translations in database
  1468.      * 3.) Deleting all words in database
  1469.      * 4.) Deleting the "lang" folder
  1470.      * 5.) Copying the "default_lang" folder to "lang"
  1471.      * 6.) Creating a language, named "English"
  1472.      * 7.) Regenerating the structure and default content
  1473.      *
  1474.      * @param Request $request The incoming request
  1475.      *
  1476.      * @return \Illuminate\Http\RedirectResponse
  1477.      */
  1478.     public function languagesReset(Request $request)
  1479.     {
  1480.         if (!Auth::user()->can('admin_languages')) {
  1481.             return redirect('/admin');
  1482.         }
  1483.  
  1484.         foreach (Language::all() as $language) {
  1485.             $language->delete();
  1486.         }
  1487.  
  1488.         foreach (Translation::all() as $translation) {
  1489.             $translation->delete();
  1490.         }
  1491.  
  1492.         foreach (Word::all() as $word) {
  1493.             $word->delete();
  1494.         }
  1495.  
  1496.         Util::rmdir(resource_path('lang/'));
  1497.  
  1498.         mkdir(resource_path('lang'));
  1499.         Util::cpy(resource_path('default_lang'), resource_path('lang'));
  1500.  
  1501.         $en = new Language();
  1502.         $en->name = 'English';
  1503.         $en->code = 'en';
  1504.         $en->save();
  1505.  
  1506.         Word::createBasedOnStructure(true, $en->id);
  1507.  
  1508.         return back();
  1509.     }
  1510.  
  1511.     /**
  1512.      * Route: /admin/languages/delete/{id} -- DELETE
  1513.      *
  1514.      * This method deletes a language and all translations and folders.
  1515.      *
  1516.      * @param Request $request The incoming request
  1517.      * @param integer $id      The id of the language
  1518.      *
  1519.      * @return \Illuminate\Http\RedirectResponse
  1520.      */
  1521.     public function languageDelete(Request $request, $id)
  1522.     {
  1523.         if (!Auth::user()->can('admin_languages')) {
  1524.             return redirect('/admin');
  1525.         }
  1526.  
  1527.         $language = Language::find($id);
  1528.         if ($language == null || $language->code == 'en') {
  1529.             return redirect('/admin/languages');
  1530.         }
  1531.  
  1532.         foreach ($language->translations()->get() as $translation) {
  1533.             $translation->delete();
  1534.         }
  1535.  
  1536.         Util::rmdir(resource_path('lang/'.$language->code));
  1537.         $language->delete();
  1538.  
  1539.         return back();
  1540.     }
  1541.  
  1542.     /**
  1543.      * Route: /admin/languages/missing -- GET
  1544.      *
  1545.      * This method adds missing words from the default language to the
  1546.      * database
  1547.      *
  1548.      * @param Request $request The incoming request
  1549.      *
  1550.      * @return \Illuminate\Http\RedirectResponse
  1551.      */
  1552.     public function addMissingWords(Request $request)
  1553.     {
  1554.         if (!Auth::user()->can('admin_languages')) {
  1555.             return redirect('/admin');
  1556.         }
  1557.  
  1558.         Word::addMissingWords();
  1559.         return back();
  1560.     }
  1561.  
  1562.     /**
  1563.      * Route: /admin/languages/recreate -- GET
  1564.      *
  1565.      * This method regenerates the language files for every language.
  1566.      *
  1567.      * @param Request $request The incoming request
  1568.      *
  1569.      * @return \Illuminate\Http\RedirectResponse
  1570.      */
  1571.     public function recreateFiles(Request $request)
  1572.     {
  1573.         foreach (Language::all() as $language) {
  1574.             Translation::regenerateFiles($language);
  1575.         }
  1576.  
  1577.         return back();
  1578.     }
  1579. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement