| Server IP : 14.225.216.240 / Your IP : 216.73.216.26 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/Crm/Controller/ |
Upload File : |
<?php
// phpcs:ignore
namespace App\Module\Crm\Controller;
use App\PTS\Utils\Repository\User;
use App\PTS\Helpers\Plugins\Common;
use stdClass;
use Validator;
use Exception;
/**
* Homepage CRM
*
* @category Class
* @package App\Module\Crm\Controller
* @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 HomeController extends BaseController
{
/**
* Homepage
* ------------------------------------------------
* GET /
* ------------------------------------------------
*
* @return mixed $view
*/
public function index()
{
$result = [];
if (auth()->check()) {
return view('home.index', $result);
}
$previousRouteName = app('router')
->getRoutes()
->match(app('request')->create(url()->previous()))
->getName();
if (!session()->has('url.intended')
&& !in_array($previousRouteName, ['home.index','auth.login','auth.logout'])
) {
session(['url.intended' => url()->previous()]);
}
return view('auth.login', $result);
}
/**
* Collapse sidebar?
* ------------------------------------------------
* POST /sidebar
* ------------------------------------------------
*
* @return mixed $json
*/
public function sidebar()
{
$httpStatus = self::METHOD_NOT_ALLOWED;
$response = new stdClass;
if (request()->ajax()) {
$key = 'pts_sidebar';
$sidebar = (int)request()->cookie($key, 1);
$sidebar = ($sidebar == 1) ? 0 : 1;
$expiry = 365 * 24 * 60;
$cookie = cookie($key, $sidebar, $expiry);
return response()->json(
(object)[
'sidebar' => $sidebar
]
)->cookie($cookie);
}
return response()->json($response, $httpStatus);
}
/**
* Change language
* ------------------------------------------------
* ANY /locale
* ------------------------------------------------
*
* @param string $locale Locale default
*
* @return mixed $redirect
*/
public function locale($locale)
{
$params = request()->all();
$expiry = 365 * 24 * 60;
$cookie = cookie('locale', $locale, $expiry);
return redirect()->back()->withInput($params)->cookie($cookie);
}
/**
* Write cookie collapse card
*
* @return mixed $json
*/
public function card()
{
$card = request()->get('card', '');
$collapse = request()->get('collapse', 'false');
if (!empty($card)) {
$key = 'pts_card';
$cards = request()->cookie($key, '');
if (!empty($cards)) {
$cards = (array)json_decode($cards);
} else {
$cards = [];
}
$cards[Common::camelCase($card)] = ($collapse != 'true');
$expiry = 365 * 24 * 60;
$cookie = cookie($key, json_encode($cards), $expiry);
return response()->json(request()->all())->cookie($cookie);
}
}
/**
* Tracking email
*
* @return mixed string
*/
public function tracking()
{
$args = request()->all();
try {
logger()->info($args);
} catch (Exception $e) {
logger()->error($e);
}
header('Content-Type: image/png');
echo file_get_contents(realpath(base_path() . '/st/img/bg-white.png'));
exit();
}
/**
* Change application
*
* @param string $guid The GUID's application
*
* @return mixed string
*/
public function changeApp($guid)
{
$params = [
'guid' => $guid ?? null,
];
$rules = [
'guid' => 'required|uuid'
];
$messages = [
'guid.required' => trans('message.application.required'),
'guid.between' => trans('message.application.required')
];
$validator = Validator::make($params, $rules, $messages);
if ($validator->passes()) {
$statusCode = self::SUCCESS;
$resp = User::getInstance()->updateAppId($guid, $statusCode);
if (($resp->error_no ?? self::ERROR_UNDEFINED) == self::SUCCESS) {
return redirect()->back();
}
$errorCode = $resp->error_code ?? '';
$msg = null;
if ($statusCode != self::SUCCESS) {
$msg = $this->getError($statusCode);
} else {
$errors = trans('errors');
$msg = $errors[$errorCode] ?? '';
}
$validator->messages()->add('error', $msg);
}
return redirect()->back()->withErrors($validator)->withInput();
}
}