Files
WMS/Modules/M3/Http/Controllers/userProfileController.php
T
2026-09-16 14:28:17 +01:00

91 lines
2.8 KiB
PHP

<?php
namespace Modules\M3\Http\Controllers;
use Modules\M3\Http\Controllers\Controller;
use DB;
use Config;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\Response;
use Modules\M3\Models\ICM428M;
class userProfileController extends Controller
{
public static function index(Request $request) {
# Get Current USER
$loggedUser = strtoUpper(m3_user());
$ICM428M = DB::connection(config('m3.connection', 'pgsql'))->table('icm428m')
->select('R428US','R428CO', 'R428WH','R428PL','R428FIRST','R428FAMILY')
->where('R428US','=',$loggedUser)
->where('R42821A','=','Y')
->first();
$IC670M = DB::connection(config('m3.connection', 'pgsql'))->table('ic670m')->get();
# Check if user is eligible for Profile update
if (isset($ICM428M->R428US)) {
return view('m3::liberty-theme.pages.userProfile', compact('ICM428M','IC670M'));
}
else{
abort(404);
}
}
public static function updateUserProfile(Request $request) {
// dd($request->all());
$R428US = isset($request->R428US) ? trim($request->R428US) : '';
$R428DPW = isset($request->R428DPW) ? trim($request->R428DPW) : '';
$R428CO = substr($R428DPW, 0, 3);
$R428PL = substr($R428DPW, 3, 3);
$R428WH = substr($R428DPW, 6, 3);
// dd($R428US.'-'.$R428CO.'-'.$R428PL.'-'.$R428WH );
if ($R428US!='') {
# Update record to ICM428M
DB::connection(config('m3.connection', 'pgsql'))->update("update ICM428M
set R428CO='$R428CO', R428PL='$R428PL', R428WH='$R428WH'
where R428US='$R428US'");
// return "success";
return redirect('/userprofile')->with('success', 'Profile updated successfully!');
}
else{
return redirect('/userprofile')->with('success', 'Profile updated successfully!');
}
}
public static function updateUserProfileAjax(Request $request) {
// dd($request->all());
$R428US = isset($request->R428US) ? trim($request->R428US) : '';
$R428DPW = isset($request->R428DPW) ? trim($request->R428DPW) : '';
$R428CO = substr($R428DPW, 0, 3);
$R428PL = substr($R428DPW, 3, 3);
$R428WH = substr($R428DPW, 6, 3);
// dd($R428US.'-'.$R428CO.'-'.$R428PL.'-'.$R428WH );
if ($R428US!='') {
# Update record to ICM428M
DB::connection(config('m3.connection', 'pgsql'))->update("update ICM428M
set R428CO='$R428CO', R428PL='$R428PL', R428WH='$R428WH'
where R428US='$R428US'");
return response()->json(['success'=>true]);
}
else{
return response()->json(['success'=>false]);
}
}
}