Files
WMS/Modules/M3/Http/Controllers/userProfileController.php
T

80 lines
2.5 KiB
PHP

<?php
namespace Modules\M3\Http\Controllers;
use DB;
use Illuminate\Http\Request;
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)
{
$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);
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 redirect('/userprofile')->with('success', 'Profile updated successfully!');
} else {
return redirect('/userprofile')->with('success', 'Profile updated successfully!');
}
}
public static function updateUserProfileAjax(Request $request)
{
$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);
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]);
}
}
}