HEX
Server: Apache/2.4.6 (CentOS) OpenSSL/1.0.2k-fips PHP/7.4.30
System: Linux iZj6c1151k3ad370bosnmsZ 3.10.0-1160.76.1.el7.x86_64 #1 SMP Wed Aug 10 16:21:17 UTC 2022 x86_64
User: root (0)
PHP: 7.4.30
Disabled: NONE
Upload Files
File: /var/www/html/inventory.breadsecret.com/class/Utility/WebSystem.php
<?php
namespace Utility;

use Requests\Request;

class WebSystem {

    public static function redirect($url, $method='header') {
        if (empty($url)) $url = '/';
        if ($method == 'header') {
            header("Location: ".$url);
            exit(0);
        } else if ($method == 'js') {
            echo "window.location = '".$url."';";
        } else {
            echo "<meta http-equiv='location' content='".$url."' />";
        }
    }

    public static function refresh($timeout, $method='header', $url="") {
        $content = $timeout;
        if (!empty($url)) $content .= ";url=".$url;
        if ($method == 'header') {
            header("Refresh: ".$content);
            exit();
        } else {
            echo "<meta http-equiv='refresh' content='".$content."' />";
        }
    }

    public static function writeLog($filename, $msg) {
        $logmsg = date("Y-m-d_H:i:s_O")." ".$msg."\r\n";
        file_put_contents($filename, $logmsg, FILE_APPEND);
    }
    
    public static function path($url, $echo = true, $slash = true) {
		$baseUrl = Request::get()->baseUrl();
		$path = $baseUrl.(($slash)?'/':'').$url;
        if ($echo) {
            echo $path;
        }
        return $path;
    }

    public static function displayDate($date, $format=\DateTime::RFC850, $timezone="", $timeZoneFrom='UTC') {
    	if (strtotime($date) <= 0) return '';
        $tz = "Asia/Hong_Kong";
        if (!empty($timezone)) {
            $tz = $timezone;
        } else if (!empty(cfg('global')['timezone'])) {
            $tz = cfg('global')['timezone'];
        }
        $time = new \DateTime($date, new \DateTimeZone($timeZoneFrom));
        $time->setTimezone(new \DateTimeZone($tz));
        return $time->format($format);
    }

    public static function displayPrice($price, $dp="2", $sign="$") {
        return $sign.number_format($price, $dp);
    }    

    public static function generateStringHash($n=8, $mode="ALL", $format="A"){       
        
        if($mode=="ALL"){
            $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
        } elseif($mode=="HEX"){
            $characters = '0123456789abcdefABCDEF';
        } elseif($mode=="LETTER"){
            $characters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
        } elseif($mode=="DEC"){
            $characters = '0123456789';
        }        
        
        $randomString = '';
        
        for ($i = 0; $i < $n; $i++) {
            $index = rand(0, strlen($characters) - 1);
            $randomString .= $characters[$index];
        }
        
        if($format=="U"){
            return strtoupper($randomString);
        } else if($format=="L"){
            return strtolower($randomString);
        } else {
            return $randomString;
        }

    }
}