Uname:Linux localhost.localdomain 5.14.0-596.el9.x86_64 #1 SMP PREEMPT_DYNAMIC Fri Jun 27 16:02:33 UTC 2025 x86_64

403WebShell
403Webshell
Server IP : 14.225.216.240  /  Your IP : 216.73.217.114
Web Server : nginx/1.20.1
System : Linux localhost.localdomain 5.14.0-596.el9.x86_64 #1 SMP PREEMPT_DYNAMIC Fri Jun 27 16:02:33 UTC 2025 x86_64
User : taidh ( 1001)
PHP Version : 8.3.19
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : ON
Directory :  /home/pts/app/Module/Admin/Model/System/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /home/pts/app/Module/Admin/Model/System/Field.php
<?php
// phpcs:ignore
namespace App\Module\Admin\Model\System;

use App\Module\Admin\Model\Base;
use App\PTS\Utils\Strings;
use PDO;
use stdClass;

/**
 * Field Model
 *
 * @category Class
 * @package  App\Module\Admin\Model\System
 * @author   Phung, Truong K <truongkimphung1982@gmail.com>
 * @license  https://www.gnu.org/licenses/gpl-3.0.html GNU General Public License
 * @link     https://pts-digital.com/ PTS Digital Technology Co.,Ltd
 */
class Field extends Base
{

    public const ENCRYPT = 1<<0;
    public const DATE_SYSTEM = 1<<1;
    public const DECIMAL = 1<<2;
    public const JSON_FORMAT = 1<<3;

    static $removed = [];

    /**
     * Reformat object
     *
     * @param mixed $item : The object field
     *
     * @return mixed $object
     */
    public static function format($item)
    {
        $item = Field::baseFormat($item);
        if (isset($item->status)) {
            $item->status = Field::status($item->status ?? -1);
        }
        Field::props($item, self::$removed);
        return $item;
    }

    /**
     * List of all fields
     * ----------------------------------------------------------------
     *
     * @param mixed $args : The arguments for simple search
     *                    - $locale
     *                    - $keyword
     *                    - $page
     *                    - $limit
     *
     * @return object
     */
    public function getFields($args)
    {
        $statusCode = self::SUCCESS;
        $response = new stdClass;
        $this->auth();
        if (self::$authId > 0) {
            // Getting parameters in your request
            $args = (object)($args ?? []);
            $locale = $args->locale ?? app()->getLocale();
            $keyword = $args->q ?? '';
            $page = ($args->page ?? 1);
            $limit = (int)($args->limit ?? config('constant.limit.default'));

            $this->prepare(
                'CALL system_fields_getall(
                                ?,?,?,?,?
                            );'
            );
            $this->bindParam(1, self::$authId, PDO::PARAM_INT, 20);
            $this->bindParam(2, $locale, PDO::PARAM_STR, 10);
            $this->bindParam(3, $keyword, PDO::PARAM_STR, 255);
            $this->bindParam(4, $page, PDO::PARAM_INT, 11);
            $this->bindParam(5, $limit, PDO::PARAM_INT, 11);
            $result = $this->fetchAll($statusCode);
            
            if (isset($result) && $statusCode == self::SUCCESS) {
                $items = $this->transform($result[1] ?? []);
                $response->offset = $result[0][0]->offset ?? 0;
                $response->total = $result[0][0]->foundRows ?? 0;
                $response->count = count($items);
                $response->items = $items;
            }
        }
        return $response;
    }

     /**
      * List of all fields by search
      * ------------------------------------------------------------
      *
      * @param mixed $args       : The arguments for advance search
      *                          - $status
      *                          - $name
      *                          - $code
      *                          - $type
      *                          - $field
      *                          - $sort
      *                          - page
      *                          - limit
      * @param int   $statusCode : SQL exception
      * 
      * @return object
      */
    public function getFieldsBySearch($args, &$statusCode=0)
    {
        $response = new stdClass;
        $this->auth();
        if (self::$authId > 0) {
            // Getting parameters in your request
            $args = (object)($args ?? []);
            $locale = $args->locale ?? config('app.locale');
            $status = $args->status ?? '';
            $name = $args->name ?? '';
            $code = $args->code ?? '';
            $type = $args->type ?? '';
            $field = $args->field ?? '';
            $sort = $args->sort ?? 0;
            $page = ($args->page ?? 1);
            $limit = (int)($args->limit ?? config('constant.limit.default'));
            
            // convert from string to int
            $status = (!empty($status) && $status != -1) ? self::findStatusIndex($status) : -1;
            
            $this->prepare(
                'CALL system_fields_getall_search(
                                ?,?,?,?,?,
                                ?,?,?,?,?,
                                ?,?
                            );'
            );
            $this->bindParam(1, self::$authId, PDO::PARAM_INT, 20);
            $this->bindParam(2, self::$authAdRole, PDO::PARAM_INT, 4);
            $this->bindParam(3, self::$authRole, PDO::PARAM_INT, 4);
            $this->bindParam(4, $locale, PDO::PARAM_STR, 10);
            $this->bindParam(5, $status, PDO::PARAM_INT, 4);
            $this->bindParam(6, $name, PDO::PARAM_STR, 255);
            $this->bindParam(7, $code, PDO::PARAM_STR, 50);
            $this->bindParam(8, $type, PDO::PARAM_INT, 4);
            $this->bindParam(9, $field, PDO::PARAM_STR, 100);
            $this->bindParam(10, $sort, PDO::PARAM_INT, 4);
            $this->bindParam(11, $page, PDO::PARAM_INT, 11);
            $this->bindParam(12, $limit, PDO::PARAM_INT, 11);
            $result = $this->fetchAll($statusCode);
           
            if (isset($result) && $statusCode == self::SUCCESS) {
                $items = $this->transform($result[1] ?? []);
                $response->offset = $result[0][0]->offset ?? 0;
                $response->total = $result[0][0]->foundRows ?? 0;
                $response->count = count($items);
                $response->items = $items;
            }
        }
        return $response;
    }

    /**
     * Active fields
     * ------------------------------------------------------------
     *
     * @param string $locale : The locale
     *
     * @return array
     */
    public function getFieldsByActive($locale=null)
    {
        $locale = $locale ?? app()->getLocale();
        $this->prepare('CALL system_fields_getall_active(?);');
        $this->bindParam(1, $locale, PDO::PARAM_STR, 10);
        return $this->fetchAll();
    }

    /**
     * Getting field information by specific ID's
     * ------------------------------------------------------------
     *
     * @param int    $id     : The ID's field
     * @param string $locale : The locale
     *
     * @return mixed $object
     */
    public function getFieldById($id, $locale=null)
    {
        $response = null;
        $locale = $locale ?? app()->getLocale();
        $statusCode = self::SUCCESS;
        $this->prepare('CALL system_fields_get(?,?);');
        $this->bindParam(1, $id, PDO::PARAM_INT, 20);
        $this->bindParam(2, $locale, PDO::PARAM_STR, 10);
        $rs = $this->fetchOne($statusCode);
        if ($statusCode == self::SUCCESS) {
            $response = $this->format((object)$rs);
        }
        return $response;
    }

    /**
     * Getting field information by specific GUID's
     * ------------------------------------------------------------
     *
     * @param string $guid   : The GUID's field
     * @param string $locale : The locale
     *
     * @return mixed $object
     */
    public function getFieldByGuid($guid, $locale=null)
    {
        $response = null;
        $locale = $locale ?? app()->getLocale();
        $statusCode = self::SUCCESS;
        $this->prepare('CALL system_fields_get_guid(?,?);');
        $this->bindParam(1, $guid, PDO::PARAM_STR, 36);
        $this->bindParam(2, $locale, PDO::PARAM_STR, 10);
        $rs = $this->fetchOne($statusCode);
        if ($statusCode == self::SUCCESS) {
            $response = $this->format((object)$rs);
        }
        return $response;
    }

    /**
     * Create a new field
     * Update field information by specific ID's
     * ------------------------------------------------------------
     *
     * @param mixed $args       : Field model
     *                          - $id
     *                          - $locale
     *                          - $code
     *                          - $name
     *                          - $iseq
     *                          - $fn_type
     * @param int   $statusCode : Exception SQL
     *
     * @return object
     */
    public function addUpdate($args, &$statusCode = 0)
    {
        $this->auth();
        $response = new stdClass;
        if (self::$authId > 0) {
            $args = (object) ($args ?? []);
            // validate required field
            $name = $args->name ?? '';
            if (empty($name)) {
                $statusCode = self::BAD_REQUEST;
            } else {
                $id = (int)($args->id ?? 0);
                $locale = $args->locale ?? app()->getLocale();
                $code = $args->code ?? null;
                $type = $args->type ?? 0;
                $iseq = Strings::number($args->iseq ?? 0, $locale);
                $bw = Strings::number($args->bw ?? 0, $locale);
                $fnType = Strings::arr2Int($args->fn_type ?? []);
                $objectType = Strings::arr2Int($args->obj_type ?? []);
                $status = $args->status ?? '';

                $bw = 1<<$bw;
                // convert from string to int
                $status = self::findStatusIndex($status);
                
                $this->prepare(
                    'CALL system_fields_addupdate(
                                    ?,?,?,?,?,
                                    ?,?,?,?,?,
                                    ?,?
                                );'
                );
                $this->bindParam(1, self::$authId, PDO::PARAM_INT, 20);
                $this->bindParam(2, self::$authFullName, PDO::PARAM_STR, 64);
                $this->bindParam(3, $id, PDO::PARAM_INT, 11);
                $this->bindParam(4, $locale, PDO::PARAM_STR, 10);
                $this->bindParam(5, $name, PDO::PARAM_STR, 255);
                $this->bindParam(6, $code, PDO::PARAM_STR, 64);
                $this->bindParam(7, $type, PDO::PARAM_INT, 4);
                $this->bindParam(8, $bw, PDO::PARAM_INT, 20);
                $this->bindParam(9, $iseq, PDO::PARAM_INT, 11);
                $this->bindParam(10, $status, PDO::PARAM_INT, 4);
                $this->bindParam(11, $fnType, PDO::PARAM_INT, 4);
                $this->bindParam(12, $objectType, PDO::PARAM_INT, 4);
                $response = $this->fetchOne($statusCode);
            }
            
        } else {
            $statusCode = self::FORBIDDEN;
        }
        return $response;
    }

    /**
     * Mask as "status" to other status
     * ----------------------------------------------------------------
     *
     * @param mixed $id         : The GUID's field
     * @param mixed $status     : Value options < active, inactive >
     * @param mixed $message    : The remark for change status
     * @param int   $statusCode : SQL exception
     *
     * @return boolean
     */
    public function changeStatus($id, &$status, $message=null, &$statusCode=0)
    {
        $this->auth();
        $response = false;
        if (self::$authId > 0) {
            if (empty($id) || empty($status)) {
                $statusCode = self::BAD_REQUEST;
            } else {
                $status = self::findStatusIndex($status);
                $this->prepare(
                    'CALL system_fields_update_status(
                                    ?,?,?,?,?
                                );'
                );
                $this->bindParam(1, self::$authId, PDO::PARAM_INT, 20);
                $this->bindParam(2, self::$authFullName, PDO::PARAM_STR, 64);
                $this->bindParam(3, $id, PDO::PARAM_STR, 36);
                $this->bindParam(4, $status, PDO::PARAM_INT, 4);
                $this->bindParam(5, $message, PDO::PARAM_STR, 4000);
                $response = $this->execute($statusCode);
                if ($statusCode == self::SUCCESS) {
                    $status = self::status($status);
                }
            }
        } else {
            $statusCode = self::FORBIDDEN;
        }
        return $response;
    }

    /**
     * Mask as "status" to deleted
     * ----------------------------------------------------------------
     *
     * @param string $guid       : The GUID of field
     * @param mixed  $message    : The remark for delete data
     * @param int    $statusCode : SQL exception
     *
     * @return boolean
     */
    public function markAsDelete($guid, $message=null, &$statusCode=0)
    {
        $this->auth();
        $response = false;
        if (self::$authId > 0) {
            if (empty($guid)) {
                $statusCode = self::BAD_REQUEST;
            } else {
                $this->prepare(
                    'CALL system_fields_delete(
                                    ?,?,?,?,?,
                                    ?
                                );'
                );
                $this->bindParam(1, self::$authAdRole, PDO::PARAM_INT, 4);
                $this->bindParam(2, self::$authRole, PDO::PARAM_INT, 4);
                $this->bindParam(3, self::$authId, PDO::PARAM_INT, 20);
                $this->bindParam(4, self::$authFullName, PDO::PARAM_STR, 64);
                $this->bindParam(5, $guid, PDO::PARAM_STR, 36);
                $this->bindParam(6, $message, PDO::PARAM_STR, 4000);
                $response = $this->execute($statusCode);
            }
        } else {
            $statusCode = self::FORBIDDEN;
        }
        return $response;
    }

    /**
     * Lock/ Unlock field
     * ----------------------------------------------------------------
     *
     * @param mixed $id         : The GUID's field
     * @param int   $isLocked   : 0: unlocking, 1: locking
     * @param mixed $message    : The remark lock/ unlock data
     * @param int   $statusCode : SQL exception
     *
     * @return boolean
     */
    public function changeLocked($id, &$isLocked, $message=null, &$statusCode=0)
    {
        $this->auth();
        $response = false;
        if (self::$authId > 0) {
            $this->prepare(
                'CALL system_fields_update_locked(
                                ?,?,?,?,?
                            );'
            );
            $this->bindParam(1, self::$authId, PDO::PARAM_INT, 20);
            $this->bindParam(2, self::$authFullName, PDO::PARAM_STR, 64);
            $this->bindParam(3, $id, PDO::PARAM_STR, 36);
            $this->bindParam(4, $isLocked, PDO::PARAM_INT, 1);
            $this->bindParam(5, $message, PDO::PARAM_STR, 4000);
            $response = $this->execute($statusCode);
        } else {
            $statusCode = self::FORBIDDEN;
        }
        return $response;
    }
}

Youez - 2016 - github.com/yon3zu
LinuXploit