Find this useful? Enter your email to receive occasional updates for securing PHP code.

Signing you up...

Thank you for signing up!

PHP Decode

<?php namespace App\Controllers; use App\Core\Sentinel; use App\Core\Utils; use Ap..

Decoded Output download

<?php 
 
namespace App\Controllers; 
 
use App\Core\Sentinel; 
use App\Core\Utils; 
use App\Models\AdminDepartments as AdminDepartmentsModel; 
use Psr\Http\Message\ResponseInterface; 
use Psr\Http\Message\ServerRequestInterface; 
use App\Models\Departments as DepartmentModel; 
use Respect\Validation\Validator as V; 
 
class AdminDepartments extends Controller 
{ 
 
    protected $admin_id; 
    protected $slug; 
 
    public function index(ServerRequestInterface $request, ResponseInterface $response) 
    { 
        $this->render($response, 'dashboard/admin-departments.twig', [ 
            'pageName' => ' ', 
        ]); 
    } 
 
    public function datatables(ServerRequestInterface $request, ResponseInterface $response) 
    { 
        $check = new Sentinel($this->container); 
        if (!$check->hasPerm('departments.view')) { 
            return $this->redirect($response, 'dashboard'); 
        } 
 
        $totalData = DepartmentModel::count(); 
 
        $totalFiltered = $totalData; 
 
        $limit = $request->getParam('length'); 
        $start = $request->getParam('start'); 
        $order = $request->getParam('columns')[$request->getParam('order')[0]['column']]['data']; 
        $dir = $request->getParam('order')[0]['dir']; 
 
        $departments = DepartmentModel::select( 
            'departments.id', 
            'departments.name', 
            'departments.slug', 
            'departments.address', 
            'departments.phone_1', 
            'departments.phone_2', 
            'departments.admin_of_department_id', 
            'admin_departments.name as adminDepartment' 
        ) 
            ->leftJoin('admin_departments', 'departments.admin_of_department_id', '=', 'admin_departments.id') 
            ->orderBy($order, $dir) 
            ->skip($start) 
            ->take($limit); 
 
        if (!empty($request->getParam('search')['value'])) { 
            $search = $request->getParam('search')['value']; 
 
 
            $departments = $departments->where('departments.name', 'LIKE', "%{$search}%") 
                ->orWhere('departments.slug', 'LIKE', "%{$search}%") 
                ->orWhere('admin_departments.name', 'LIKE', "%{$search}%"); 
 
            $totalFiltered = DepartmentModel::select( 
                'departments.id', 
                'departments.name', 
                'departments.slug', 
                'departments.address', 
                'departments.phone_1', 
                'departments.phone_2', 
                'departments.admin_of_department_id', 
                'admin_departments.name as adminDepartment' 
            )->leftJoin('admin_departments', 'departments.admin_of_department_id', '=', 'admin_departments.id') 
                ->where('departments.name', 'LIKE', "%{$search}%") 
                ->orWhere('departments.slug', 'LIKE', "%{$search}%") 
                ->orWhere('admin_departments.name', 'LIKE', "%{$search}%"); 
 
            $totalFiltered = $totalFiltered->count(); 
        } 
        $getJESON = array( 
            'draw' => intval($request->getParam('draw')), 
            'recordsTotal' => intval($totalData), 
            'recordsFiltered' => intval($totalFiltered), 
            'data' => $departments->get()->toArray() 
        ); 
        return $response->withJson($getJESON, 200); 
    } 
 
    public function departmentAdd(ServerRequestInterface $request, ResponseInterface $response) 
    { 
        $sentinel = new Sentinel($this->container); 
        if (!$sentinel->hasPerm('departments.create')) { 
            return $this->redirect($response, 'dashboard'); 
        } 
 
        $requestParams = $request->getParams(); 
 
        if ($request->isPost()) { 
 
            $this->validateNamePhoneAddress(); 
//            $this->processAdminDepartment(); 
 
            $admin_departments = AdminDepartmentsModel::find($requestParams['admin_department']); 
            if (!$admin_departments) { 
                $add_new_admin_department = new AdminDepartmentsModel; 
                $add_new_admin_department->name = $requestParams['admin_department']; 
                $add_new_admin_department->slug = Utils::slugify($requestParams['admin_department']); 
                $add_new_admin_department->save(); 
                $admin_department_id = $add_new_admin_department->id; 
            } else { 
                $admin_department_id = $admin_departments->id; 
            } 
            if ($this->validator->isValid()) { 
                $newDepartment = new DepartmentModel; 
                $newDepartment->name = $requestParams['name']; 
                $slug = Utils::slugify($requestParams['name']); 
                $newDepartment->address = $requestParams['address']; 
                $newDepartment->phone_1 = $requestParams['phone_1']; 
                $newDepartment->phone_2 = $requestParams['phone_2']; 
                $newDepartment->admin_of_department_id = $admin_department_id; 
                $newDepartment->slug = $slug; 
                $newDepartment->save(); 
                $this->flash('success', '  '); 
                return $this->redirect($response, 'admin-departments'); 
            } 
        } 
 
        $this->render($response, 'dashboard/admin-departments-add.twig', [ 
            'admin_departments' => AdminDepartmentsModel::get(), 
            'pageName' => ' ' 
        ]); 
    } 
 
    public function departmentEdit(ServerRequestInterface $request, ResponseInterface $response, $department_id) 
    { 
        $sentinel = new Sentinel($this->container); 
        if (!$sentinel->hasPerm('departments.update')) { 
            return $this->redirect($response, 'dashboard'); 
        } 
 
        $requestParams = $request->getParams(); 
 
        $departments = DepartmentModel::where('id', $department_id)->with('AdminDepartments')->first(); 
 
        if (!$departments) { 
            $this->flash('danger', '  '); 
            return $this->redirect($response, 'admin-departments'); 
        } 
 
        if ($request->isPost()) { 
 
            $this->validateNamePhoneAddress(); 
            $admin_departments = AdminDepartmentsModel::find($requestParams['admin_department']); 
            if (!$admin_departments) { 
                $add_new_admin_department = new AdminDepartmentsModel; 
                $add_new_admin_department->name = $requestParams['admin_department']; 
                $add_new_admin_department->slug = Utils::slugify($requestParams['admin_department']); 
                $add_new_admin_department->save(); 
                $admin_department_id = $add_new_admin_department->id; 
            } else { 
                $admin_department_id = $admin_departments->id; 
            } 
            if ($this->validator->isValid()) { 
                $newDepartment = new DepartmentModel; 
                $newDepartment->name = $requestParams['name']; 
                $slug = Utils::slugify($requestParams['name']); 
                $newDepartment->address = $requestParams['address']; 
                $newDepartment->phone_1 = $requestParams['phone_1']; 
                $newDepartment->phone_2 = $requestParams['phone_2']; 
                $newDepartment->admin_of_department_id = $admin_department_id; 
                $newDepartment->slug = $slug; 
                $newDepartment->save(); 
                $this->flash('success', '  '); 
                return $this->redirect($response, 'admin-departments'); 
            } 
        } 
 
        $this->render($response, 'dashboard/admin-departments-edit.twig', [ 
            'admin_departments' => AdminDepartmentsModel::get(), 
            'pageName' => ' ', 
            'departments' => $departments->toArray() 
        ]); 
    } 
 
    private function validateNamePhoneAddress() 
    { 
        $validateData = [ 
            'name' => [ 
                'rules' => V::length(6, 255)->notEmpty(), 
                'messages' => [ 
                    'length' => '      6    255 ', 
                    'notEmpty' => '    ' 
                ] 
            ], 
            'address' => [ 
                'rules' => V::length(6, 255)->notEmpty(), 
                'messages' => [ 
                    'length' => '      6    255 ', 
                    'notEmpty' => '    ' 
                ] 
            ], 
            'phone_1' => [ 
                'rules' => V::numeric()->notEmpty(), 
                'messages' => [ 
                    'numeric' => '   ', 
                    'notEmpty' => '  ' 
                ] 
            ], 
            'admin_department' => [ 
                'rules' => V::notEmpty(), 
                'messages' => [ 
                    'notEmpty' => '    ' 
                ] 
            ] 
 
        ]; 
        $this->validator->validate($this->container->request, $validateData); 
    } 
 
    private function processSlug($postId = null) 
    { 
        $slug = Utils::slugify($this->container->request->getParam('name')); 
        $checkSlug = DepartmentModel::where('slug', $slug); 
        if ($postId) { 
            $checkSlug = $checkSlug->where('id', '!=', $postId); 
        } 
        if ($checkSlug->first()) { 
            $this->validator->addError('name', '     '); 
            return false; 
        } 
 
        $this->slug = $slug; 
        return true; 
    } 
 
 
    private function processAdminDepartment() 
    { 
        $admin_id = $this->container->request->getParams(); 
        $admin_departments = AdminDepartmentsModel::find($admin_id['admin_department']); 
        if (!$admin_departments) { 
            $add_new_admin_department = new AdminDepartmentsModel; 
            $add_new_admin_department->name = $admin_id['admin_department']; 
            $add_new_admin_department->slug = Utils::slugify($admin_id['admin_department']); 
            $add_new_admin_department->save(); 
//            $admin_id = $add_new_admin_department->id; 
            $admin_id = $add_new_admin_department->admin_of_department_id; 
        } 
        $this->admin_id = $admin_id; 
    } 
 
} ?>

Did this file decode correctly?

Original Code

<?php

namespace App\Controllers;

use App\Core\Sentinel;
use App\Core\Utils;
use App\Models\AdminDepartments as AdminDepartmentsModel;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use App\Models\Departments as DepartmentModel;
use Respect\Validation\Validator as V;

class AdminDepartments extends Controller
{

    protected $admin_id;
    protected $slug;

    public function index(ServerRequestInterface $request, ResponseInterface $response)
    {
        $this->render($response, 'dashboard/admin-departments.twig', [
            'pageName' => ' ',
        ]);
    }

    public function datatables(ServerRequestInterface $request, ResponseInterface $response)
    {
        $check = new Sentinel($this->container);
        if (!$check->hasPerm('departments.view')) {
            return $this->redirect($response, 'dashboard');
        }

        $totalData = DepartmentModel::count();

        $totalFiltered = $totalData;

        $limit = $request->getParam('length');
        $start = $request->getParam('start');
        $order = $request->getParam('columns')[$request->getParam('order')[0]['column']]['data'];
        $dir = $request->getParam('order')[0]['dir'];

        $departments = DepartmentModel::select(
            'departments.id',
            'departments.name',
            'departments.slug',
            'departments.address',
            'departments.phone_1',
            'departments.phone_2',
            'departments.admin_of_department_id',
            'admin_departments.name as adminDepartment'
        )
            ->leftJoin('admin_departments', 'departments.admin_of_department_id', '=', 'admin_departments.id')
            ->orderBy($order, $dir)
            ->skip($start)
            ->take($limit);

        if (!empty($request->getParam('search')['value'])) {
            $search = $request->getParam('search')['value'];


            $departments = $departments->where('departments.name', 'LIKE', "%{$search}%")
                ->orWhere('departments.slug', 'LIKE', "%{$search}%")
                ->orWhere('admin_departments.name', 'LIKE', "%{$search}%");

            $totalFiltered = DepartmentModel::select(
                'departments.id',
                'departments.name',
                'departments.slug',
                'departments.address',
                'departments.phone_1',
                'departments.phone_2',
                'departments.admin_of_department_id',
                'admin_departments.name as adminDepartment'
            )->leftJoin('admin_departments', 'departments.admin_of_department_id', '=', 'admin_departments.id')
                ->where('departments.name', 'LIKE', "%{$search}%")
                ->orWhere('departments.slug', 'LIKE', "%{$search}%")
                ->orWhere('admin_departments.name', 'LIKE', "%{$search}%");

            $totalFiltered = $totalFiltered->count();
        }
        $getJESON = array(
            'draw' => intval($request->getParam('draw')),
            'recordsTotal' => intval($totalData),
            'recordsFiltered' => intval($totalFiltered),
            'data' => $departments->get()->toArray()
        );
        return $response->withJson($getJESON, 200);
    }

    public function departmentAdd(ServerRequestInterface $request, ResponseInterface $response)
    {
        $sentinel = new Sentinel($this->container);
        if (!$sentinel->hasPerm('departments.create')) {
            return $this->redirect($response, 'dashboard');
        }

        $requestParams = $request->getParams();

        if ($request->isPost()) {

            $this->validateNamePhoneAddress();
//            $this->processAdminDepartment();

            $admin_departments = AdminDepartmentsModel::find($requestParams['admin_department']);
            if (!$admin_departments) {
                $add_new_admin_department = new AdminDepartmentsModel;
                $add_new_admin_department->name = $requestParams['admin_department'];
                $add_new_admin_department->slug = Utils::slugify($requestParams['admin_department']);
                $add_new_admin_department->save();
                $admin_department_id = $add_new_admin_department->id;
            } else {
                $admin_department_id = $admin_departments->id;
            }
            if ($this->validator->isValid()) {
                $newDepartment = new DepartmentModel;
                $newDepartment->name = $requestParams['name'];
                $slug = Utils::slugify($requestParams['name']);
                $newDepartment->address = $requestParams['address'];
                $newDepartment->phone_1 = $requestParams['phone_1'];
                $newDepartment->phone_2 = $requestParams['phone_2'];
                $newDepartment->admin_of_department_id = $admin_department_id;
                $newDepartment->slug = $slug;
                $newDepartment->save();
                $this->flash('success', '  ');
                return $this->redirect($response, 'admin-departments');
            }
        }

        $this->render($response, 'dashboard/admin-departments-add.twig', [
            'admin_departments' => AdminDepartmentsModel::get(),
            'pageName' => ' '
        ]);
    }

    public function departmentEdit(ServerRequestInterface $request, ResponseInterface $response, $department_id)
    {
        $sentinel = new Sentinel($this->container);
        if (!$sentinel->hasPerm('departments.update')) {
            return $this->redirect($response, 'dashboard');
        }

        $requestParams = $request->getParams();

        $departments = DepartmentModel::where('id', $department_id)->with('AdminDepartments')->first();

        if (!$departments) {
            $this->flash('danger', '  ');
            return $this->redirect($response, 'admin-departments');
        }

        if ($request->isPost()) {

            $this->validateNamePhoneAddress();
            $admin_departments = AdminDepartmentsModel::find($requestParams['admin_department']);
            if (!$admin_departments) {
                $add_new_admin_department = new AdminDepartmentsModel;
                $add_new_admin_department->name = $requestParams['admin_department'];
                $add_new_admin_department->slug = Utils::slugify($requestParams['admin_department']);
                $add_new_admin_department->save();
                $admin_department_id = $add_new_admin_department->id;
            } else {
                $admin_department_id = $admin_departments->id;
            }
            if ($this->validator->isValid()) {
                $newDepartment = new DepartmentModel;
                $newDepartment->name = $requestParams['name'];
                $slug = Utils::slugify($requestParams['name']);
                $newDepartment->address = $requestParams['address'];
                $newDepartment->phone_1 = $requestParams['phone_1'];
                $newDepartment->phone_2 = $requestParams['phone_2'];
                $newDepartment->admin_of_department_id = $admin_department_id;
                $newDepartment->slug = $slug;
                $newDepartment->save();
                $this->flash('success', '  ');
                return $this->redirect($response, 'admin-departments');
            }
        }

        $this->render($response, 'dashboard/admin-departments-edit.twig', [
            'admin_departments' => AdminDepartmentsModel::get(),
            'pageName' => ' ',
            'departments' => $departments->toArray()
        ]);
    }

    private function validateNamePhoneAddress()
    {
        $validateData = [
            'name' => [
                'rules' => V::length(6, 255)->notEmpty(),
                'messages' => [
                    'length' => '      6    255 ',
                    'notEmpty' => '    '
                ]
            ],
            'address' => [
                'rules' => V::length(6, 255)->notEmpty(),
                'messages' => [
                    'length' => '      6    255 ',
                    'notEmpty' => '    '
                ]
            ],
            'phone_1' => [
                'rules' => V::numeric()->notEmpty(),
                'messages' => [
                    'numeric' => '   ',
                    'notEmpty' => '  '
                ]
            ],
            'admin_department' => [
                'rules' => V::notEmpty(),
                'messages' => [
                    'notEmpty' => '    '
                ]
            ]

        ];
        $this->validator->validate($this->container->request, $validateData);
    }

    private function processSlug($postId = null)
    {
        $slug = Utils::slugify($this->container->request->getParam('name'));
        $checkSlug = DepartmentModel::where('slug', $slug);
        if ($postId) {
            $checkSlug = $checkSlug->where('id', '!=', $postId);
        }
        if ($checkSlug->first()) {
            $this->validator->addError('name', '     ');
            return false;
        }

        $this->slug = $slug;
        return true;
    }


    private function processAdminDepartment()
    {
        $admin_id = $this->container->request->getParams();
        $admin_departments = AdminDepartmentsModel::find($admin_id['admin_department']);
        if (!$admin_departments) {
            $add_new_admin_department = new AdminDepartmentsModel;
            $add_new_admin_department->name = $admin_id['admin_department'];
            $add_new_admin_department->slug = Utils::slugify($admin_id['admin_department']);
            $add_new_admin_department->save();
//            $admin_id = $add_new_admin_department->id;
            $admin_id = $add_new_admin_department->admin_of_department_id;
        }
        $this->admin_id = $admin_id;
    }

}

Function Calls

None

Variables

None

Stats

MD5 0404a21bf40d658b8f78d93dc9cdc8a9
Eval Count 0
Decode Time 84 ms