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 declare(strict_types=1); namespace App\Controllers\Admin; use App\Controllers\Bas..

Decoded Output download

<?php

declare(strict_types=1);

namespace App\Controllers\Admin;

use App\Controllers\BaseController;
use App\Models\Ticket;
use App\Models\User;
use App\Services\LLM;
use App\Services\Notification;
use App\Utils\Tools;
use Exception;
use GuzzleHttp\Exception\GuzzleException;
use Psr\Http\Client\ClientExceptionInterface;
use Psr\Http\Message\ResponseInterface;
use Slim\Http\Response;
use Slim\Http\ServerRequest;
use Telegram\Bot\Exceptions\TelegramSDKException;
use function array_merge;
use function count;
use function json_decode;
use function json_encode;
use function time;

final class TicketController extends BaseController
{
    private static array $details =
        [
            'field' => [
                'op' => '',
                'id' => 'ID',
                'title' => '',
                'status' => '',
                'type' => '',
                'userid' => '',
                'datetime' => '',
            ],
        ];

    private static string $err_msg = '';

    /**
     * 
     *
     * @throws Exception
     */
    public function index(ServerRequest $request, Response $response, array $args): ResponseInterface
    {
        return $response->write(
            $this->view()
                ->assign('details', self::$details)
                ->fetch('admin/ticket/index.tpl')
        );
    }

    /**
     * @throws TelegramSDKException
     * @throws GuzzleException
     * @throws ClientExceptionInterface
     */
    public function update(ServerRequest $request, Response $response, array $args): ResponseInterface
    {
        $id = $args['id'];
        $comment = $request->getParam('comment') ?? '';

        if ($comment === '') {
            return $response->withJson([
                'ret' => 0,
                'msg' => self::$err_msg,
            ]);
        }

        $ticket = (new Ticket())->where('id', $id)->first();

        if ($ticket === null) {
            return $response->withJson([
                'ret' => 0,
                'msg' => self::$err_msg,
            ]);
        }

        $content_old = json_decode($ticket->content, true);
        $content_new = [
            [
                'comment_id' => $content_old[count($content_old) - 1]['comment_id'] + 1,
                'commenter_name' => 'Admin',
                'comment' => $comment,
                'datetime' => time(),
            ],
        ];

        $user = (new User())->find($ticket->userid);

        Notification::notifyUser(
            $user,
            $_ENV['appName'] . '-',
            '<a href="' . $_ENV['baseUrl'] . '/user/ticket/' . $ticket->id . '/view"></a>'
        );

        $ticket->content = json_encode(array_merge($content_old, $content_new));
        $ticket->status = 'open_wait_user';
        $ticket->save();

        return $response->withJson([
            'ret' => 1,
            'msg' => '',
        ]);
    }

    /**
     * @throws GuzzleException
     * @throws TelegramSDKException
     * @throws ClientExceptionInterface
     */
    public function updateAI(ServerRequest $request, Response $response, array $args): ResponseInterface
    {
        $id = $args['id'];

        $ticket = (new Ticket())->where('id', $id)->first();

        if ($ticket === null) {
            return $response->withJson([
                'ret' => 0,
                'msg' => self::$err_msg,
            ]);
        }

        $content_old = json_decode($ticket->content, true);
        //  LLM 
        $ai_reply = LLM::genTextResponse($content_old[0]['comment']);
        $content_new = [
            [
                'comment_id' => $content_old[count($content_old) - 1]['comment_id'] + 1,
                'commenter_name' => 'AI Admin',
                'comment' => $ai_reply,
                'datetime' => time(),
            ],
        ];

        $user = (new User())->find($ticket->userid);

        Notification::notifyUser(
            $user,
            $_ENV['appName'] . '-',
            'AI <a href="' . $_ENV['baseUrl'] . '/user/ticket/' . $ticket->id . '/view"></a>'
        );

        $ticket->content = json_encode(array_merge($content_old, $content_new));
        $ticket->status = 'open_wait_user';
        $ticket->save();

        return $response->withJson([
            'ret' => 1,
            'msg' => '',
        ]);
    }

    /**
     * 
     *
     * @throws Exception
     */
    public function detail(ServerRequest $request, Response $response, array $args): ResponseInterface
    {
        $id = $args['id'];
        $ticket = (new Ticket())->where('id', '=', $id)->first();

        if ($ticket === null) {
            return $response->withRedirect('/admin/ticket');
        }

        $comments = json_decode($ticket->content);

        foreach ($comments as $comment) {
            $comment->datetime = Tools::toDateTime((int) $comment->datetime);
        }

        return $response->write(
            $this->view()
                ->assign('ticket', $ticket)
                ->assign('comments', $comments)
                ->fetch('admin/ticket/view.tpl')
        );
    }

    /**
     * 
     */
    public function close(ServerRequest $request, Response $response, array $args): ResponseInterface
    {
        $id = $args['id'];
        $ticket = (new Ticket())->where('id', '=', $id)->first();

        if ($ticket === null) {
            return $response->withJson([
                'ret' => 0,
                'msg' => self::$err_msg,
            ]);
        }

        if ($ticket->status === 'closed') {
            return $response->withJson([
                'ret' => 0,
                'msg' => self::$err_msg,
            ]);
        }

        $ticket->status = 'closed';
        $ticket->save();

        return $response->withJson([
            'ret' => 1,
            'msg' => '',
        ]);
    }

    /**
     * 
     */
    public function delete(ServerRequest $request, Response $response, array $args): ResponseInterface
    {
        $id = $args['id'];
        (new Ticket())->where('id', '=', $id)->delete();

        return $response->withJson([
            'ret' => 1,
            'msg' => '',
        ]);
    }

    /**
     *  Ajax
     */
    public function ajax(ServerRequest $request, Response $response, array $args): ResponseInterface
    {
        $tickets = (new Ticket())->orderBy('id', 'desc')->get();

        foreach ($tickets as $ticket) {
            $ticket->op = '<button class="btn btn-red" id="delete-ticket" 
            onclick="deleteTicket(' . $ticket->id . ')"></button>';

            if ($ticket->status !== 'closed') {
                $ticket->op .= '
                <button class="btn btn-orange" id="close-ticket" 
                onclick="closeTicket(' . $ticket->id . ')"></button>';
            }

            $ticket->op .= '
            <a class="btn btn-primary" href="/admin/ticket/' . $ticket->id . '/view"></a>';
            $ticket->status = $ticket->status();
            $ticket->type = $ticket->type();
            $ticket->datetime = Tools::toDateTime((int) $ticket->datetime);
        }

        return $response->withJson([
            'tickets' => $tickets,
        ]);
    }
}
 ?>

Did this file decode correctly?

Original Code

<?php

declare(strict_types=1);

namespace App\Controllers\Admin;

use App\Controllers\BaseController;
use App\Models\Ticket;
use App\Models\User;
use App\Services\LLM;
use App\Services\Notification;
use App\Utils\Tools;
use Exception;
use GuzzleHttp\Exception\GuzzleException;
use Psr\Http\Client\ClientExceptionInterface;
use Psr\Http\Message\ResponseInterface;
use Slim\Http\Response;
use Slim\Http\ServerRequest;
use Telegram\Bot\Exceptions\TelegramSDKException;
use function array_merge;
use function count;
use function json_decode;
use function json_encode;
use function time;

final class TicketController extends BaseController
{
    private static array $details =
        [
            'field' => [
                'op' => '',
                'id' => 'ID',
                'title' => '',
                'status' => '',
                'type' => '',
                'userid' => '',
                'datetime' => '',
            ],
        ];

    private static string $err_msg = '';

    /**
     * 
     *
     * @throws Exception
     */
    public function index(ServerRequest $request, Response $response, array $args): ResponseInterface
    {
        return $response->write(
            $this->view()
                ->assign('details', self::$details)
                ->fetch('admin/ticket/index.tpl')
        );
    }

    /**
     * @throws TelegramSDKException
     * @throws GuzzleException
     * @throws ClientExceptionInterface
     */
    public function update(ServerRequest $request, Response $response, array $args): ResponseInterface
    {
        $id = $args['id'];
        $comment = $request->getParam('comment') ?? '';

        if ($comment === '') {
            return $response->withJson([
                'ret' => 0,
                'msg' => self::$err_msg,
            ]);
        }

        $ticket = (new Ticket())->where('id', $id)->first();

        if ($ticket === null) {
            return $response->withJson([
                'ret' => 0,
                'msg' => self::$err_msg,
            ]);
        }

        $content_old = json_decode($ticket->content, true);
        $content_new = [
            [
                'comment_id' => $content_old[count($content_old) - 1]['comment_id'] + 1,
                'commenter_name' => 'Admin',
                'comment' => $comment,
                'datetime' => time(),
            ],
        ];

        $user = (new User())->find($ticket->userid);

        Notification::notifyUser(
            $user,
            $_ENV['appName'] . '-',
            '<a href="' . $_ENV['baseUrl'] . '/user/ticket/' . $ticket->id . '/view"></a>'
        );

        $ticket->content = json_encode(array_merge($content_old, $content_new));
        $ticket->status = 'open_wait_user';
        $ticket->save();

        return $response->withJson([
            'ret' => 1,
            'msg' => '',
        ]);
    }

    /**
     * @throws GuzzleException
     * @throws TelegramSDKException
     * @throws ClientExceptionInterface
     */
    public function updateAI(ServerRequest $request, Response $response, array $args): ResponseInterface
    {
        $id = $args['id'];

        $ticket = (new Ticket())->where('id', $id)->first();

        if ($ticket === null) {
            return $response->withJson([
                'ret' => 0,
                'msg' => self::$err_msg,
            ]);
        }

        $content_old = json_decode($ticket->content, true);
        //  LLM 
        $ai_reply = LLM::genTextResponse($content_old[0]['comment']);
        $content_new = [
            [
                'comment_id' => $content_old[count($content_old) - 1]['comment_id'] + 1,
                'commenter_name' => 'AI Admin',
                'comment' => $ai_reply,
                'datetime' => time(),
            ],
        ];

        $user = (new User())->find($ticket->userid);

        Notification::notifyUser(
            $user,
            $_ENV['appName'] . '-',
            'AI <a href="' . $_ENV['baseUrl'] . '/user/ticket/' . $ticket->id . '/view"></a>'
        );

        $ticket->content = json_encode(array_merge($content_old, $content_new));
        $ticket->status = 'open_wait_user';
        $ticket->save();

        return $response->withJson([
            'ret' => 1,
            'msg' => '',
        ]);
    }

    /**
     * 
     *
     * @throws Exception
     */
    public function detail(ServerRequest $request, Response $response, array $args): ResponseInterface
    {
        $id = $args['id'];
        $ticket = (new Ticket())->where('id', '=', $id)->first();

        if ($ticket === null) {
            return $response->withRedirect('/admin/ticket');
        }

        $comments = json_decode($ticket->content);

        foreach ($comments as $comment) {
            $comment->datetime = Tools::toDateTime((int) $comment->datetime);
        }

        return $response->write(
            $this->view()
                ->assign('ticket', $ticket)
                ->assign('comments', $comments)
                ->fetch('admin/ticket/view.tpl')
        );
    }

    /**
     * 
     */
    public function close(ServerRequest $request, Response $response, array $args): ResponseInterface
    {
        $id = $args['id'];
        $ticket = (new Ticket())->where('id', '=', $id)->first();

        if ($ticket === null) {
            return $response->withJson([
                'ret' => 0,
                'msg' => self::$err_msg,
            ]);
        }

        if ($ticket->status === 'closed') {
            return $response->withJson([
                'ret' => 0,
                'msg' => self::$err_msg,
            ]);
        }

        $ticket->status = 'closed';
        $ticket->save();

        return $response->withJson([
            'ret' => 1,
            'msg' => '',
        ]);
    }

    /**
     * 
     */
    public function delete(ServerRequest $request, Response $response, array $args): ResponseInterface
    {
        $id = $args['id'];
        (new Ticket())->where('id', '=', $id)->delete();

        return $response->withJson([
            'ret' => 1,
            'msg' => '',
        ]);
    }

    /**
     *  Ajax
     */
    public function ajax(ServerRequest $request, Response $response, array $args): ResponseInterface
    {
        $tickets = (new Ticket())->orderBy('id', 'desc')->get();

        foreach ($tickets as $ticket) {
            $ticket->op = '<button class="btn btn-red" id="delete-ticket" 
            onclick="deleteTicket(' . $ticket->id . ')"></button>';

            if ($ticket->status !== 'closed') {
                $ticket->op .= '
                <button class="btn btn-orange" id="close-ticket" 
                onclick="closeTicket(' . $ticket->id . ')"></button>';
            }

            $ticket->op .= '
            <a class="btn btn-primary" href="/admin/ticket/' . $ticket->id . '/view"></a>';
            $ticket->status = $ticket->status();
            $ticket->type = $ticket->type();
            $ticket->datetime = Tools::toDateTime((int) $ticket->datetime);
        }

        return $response->withJson([
            'tickets' => $tickets,
        ]);
    }
}

Function Calls

None

Variables

None

Stats

MD5 809f7586e5eecf4e1f8b30b7f5dfdab2
Eval Count 0
Decode Time 111 ms