hasTable('icm428m')) {
$profile = DB::connection($connection)->table('icm428m')->where('R428US',strtoUpper(m3_user()))->first();
}
$co=$profile->R428CO ?? ''; $whs=$profile->R428WH ?? '';
$ICM428M = \Illuminate\Support\Facades\Schema::connection($connection)->hasTable('icm428m')
? DB::connection($connection)->table('icm428m')->where('R428CO',$co)->where('R428WH',$whs)->get() : collect();
$USER_INFO = \Illuminate\Support\Facades\Schema::connection($connection)->hasTable('icm428m')
? DB::connection($connection)->table('icm428m')->selectRaw('R428US as USERPRF, R428STS as STATUS, NULL as DATE_EXPIRED, NULL as EXPIRED')->get()->all() : [];
$power_user = [(object)['R428PWRUSR'=>$profile->R428PWRUSR ?? 'N','R428CO'=>$co,'R428PL'=>$profile->R428PL ?? '','R428WH'=>$whs]];
$IC670M = \Illuminate\Support\Facades\Schema::connection($connection)->hasTable('ic670m')
? DB::connection($connection)->table('ic670m')->get() : collect();
return view('m3::liberty-theme.pages.userControl', compact('ICM428M','IC670M','power_user','USER_INFO'));
}
//
// Process data from Add modal
//
public static function saveUserAdd(Request $request) {
if($request->R428EMPCDE=="") {
$request->R428EMPCDE=0;
}
// Insert record to ICM428M
#dump($request);
// Validate user profile exists on the system
$usrprf = [(object) ['COUNT' => 0]]; // PostgreSQL/Core owns M3 profiles; no QSYS2 lookup.
// Validate employee code exists in LBPF file
#if($request->R428EMPCDE>0) {
# $empcde=DB::connection(config('m3.connection', 'pgsql'))->select("select count(*) as COUNT2 from LBPF where EMPNO='$request->R428EMPCDE'");
# if($empcde[0]->COUNT2=="0") {
# #echo "";
# return "error empcd";
# }
#}
$icm428m=DB::connection(config('m3.connection', 'pgsql'))->select("select count(*) as COUNT1 from ICM428M where R428US='$request->R428US'");
if($icm428m[0]->COUNT1=="1") {
return "error exists";
} else {
if($usrprf[0]->COUNT=="1") {
DB::connection(config('m3.connection', 'pgsql'))->insert("insert into ICM428M
(R428CO, R428PL, R428WH, R428STS, R428US, R428FIRST, R428FAMILY, R428EMAIL, R428EMPCDE, R428ADMUSR, R428PWRUSR, MENU2OPT, MENU3OPT, MENU4OPT, MENU5OPT, MENU6OPT, R42811A)
values ('$request->R428CO', '$request->R428PL', '$request->R428WH', '$request->R428STS', '$request->R428US', '$request->R428FIRST',
'$request->R428FAMILY', '$request->R428EMAIL', $request->R428EMPCDE, '$request->R428ADMUSR', '$request->R428PWRUSR',
'NN".$request->MENU2OPT3."NNN".$request->MENU2OPT7.$request->MENU2OPT8."N', '".$request->MENU3OPT1.$request->MENU3OPT2."NNNNNNN',
'".$request->MENU4OPT1.$request->MENU4OPT2.$request->MENU4OPT3."NNNNNN',
'".$request->MENU5OPT1.$request->MENU5OPT2.$request->MENU5OPT3."N".$request->MENU5OPT5."NNNN','".$request->MENU6OPT1.$request->MENU6OPT2.$request->MENU6OPT3."','".$request->R42811A."')");
return "success";
} else {
#echo "";
# CL program call here (ewobjtst.)ICMUSRPRF parms(R428US, R428FIRST, R428FAMILY)
// connect to toolkit using DB2 credentials (can also leave blank for default authority)
try {
$conn = app(\Modules\M3\Services\PostgresProgramBridge::class);
}
catch (\Exception $e)
{
// Determine reason for failure.
// Probably database authentication error or invalid or unreachable database.
$code = $e->getCode();
$msg = $e->getMessage();
switch ($code) {
case 8001:
// "Authorization failure on distributed database connection attempt"
// Usually means a wrong DB2 user or password
$PGMERRORS = 'Could not connect due to wrong user or password.';
return "error profile3";
break;
case 42705:
$PGMERRORS = 'Database not found. Try WRKRDBDIRE to check.';
return "error profile4";
break;
default:
$PGMERRORS = 'Could not connect. Error: ' . $code . ' ' . $msg;
return "error profile5";
break;
}
}
$conn->setOptions(array('persistent' => false, 'stateless' => true, 'debug' => true,'debugLogFile' => '/www/sentm3test/htdocs/M3/storage/logs/toolkit_debug.log'));
// Add LIB
// $result = $conn->CLCommand('ADDLIBLE LIB(MPDAT10)');
// define several input/output params
$params = [];
$params[] = $conn->AddParameterChar('in',10,'User profile','E#iUsrPrf',$request->R428US);
$params[] = $conn->AddParameterChar('in',20,'First name','FIRST',$request->R428FIRST);
$params[] = $conn->AddParameterChar('in',30,'Family name','FAMILY',$request->R428FAMILY);
## $result = $conn->PgmCall(Config::get('eproconf.misc.PGM1'), Config::get('eproconf.misc.libname4'), $params, array(), array());
$result = $conn->PgmCall('ICMUSRPRF', 'EWOBJ', $params, array(), array());
if (!$result) {
$PGMERRORS = 'Error calling program. Code: ' . $conn->getErrorCode() . ' Msg: ' . $conn->getErrorMsg();
//echo "";
return "error profile2";
} else {
// Successful Call : User profile created with default password
//dd($result);
//echo "";
DB::connection(config('m3.connection', 'pgsql'))->insert("insert into ICM428M
(R428CO, R428PL, R428WH, R428STS, R428US, R428FIRST, R428FAMILY, R428EMAIL, R428EMPCDE, R428ADMUSR, R428PWRUSR, MENU2OPT, MENU3OPT, MENU4OPT, MENU5OPT, MENU6OPT, R42811A,R42821A)
values ('$request->R428CO', '$request->R428PL', '$request->R428WH', '$request->R428STS', '$request->R428US', '$request->R428FIRST',
'$request->R428FAMILY', '$request->R428EMAIL', $request->R428EMPCDE, '$request->R428ADMUSR', '$request->R428PWRUSR',
'NN".$request->MENU2OPT3."NNN".$request->MENU2OPT7.$request->MENU2OPT8."N', '".$request->MENU3OPT1.$request->MENU3OPT2."NNNNNNN',
'".$request->MENU4OPT1.$request->MENU4OPT2.$request->MENU4OPT3."NNNNNN',
'".$request->MENU5OPT1.$request->MENU5OPT2.$request->MENU5OPT3."N".$request->MENU5OPT5."NNNN','".$request->MENU6OPT1.$request->MENU6OPT2.$request->MENU6OPT3."','".$request->R42811A."','".$request->R42821A."')");
return "success2";
}
##kd return "error profile";
}
}
}
//
// Process data from Edit modal
//
public static function saveUserEdit(Request $request) {
#dump($request);
if($request->R428EMPCDE=="") {
$request->R428EMPCDE=0;
}
// Validate employee code exists in LBPF file
//dump($request->R428EMPCDE);
#if($request->R428EMPCDE>0) {
# $sqlstmt="select count(*) as COUNT from LBPF where EMPNO='$request->R428EMPCDE'";
# #echo "$sqlstmt
";
# $empcde=DB::connection(config('m3.connection', 'pgsql'))->select($sqlstmt);
# #dump($empcde);
# if($empcde[0]->COUNT=="0") {
# #echo "";
# return "error empcd";
# }
#}
// Update record to ICM428M
$ICM428M=DB::connection(config('m3.connection', 'pgsql'))->select("select * from ICM428M where R428US='$request->R428US'");
//var_dump($ICM428M);
DB::connection(config('m3.connection', 'pgsql'))->update("update ICM428M
set R428CO='$request->R428CO', R428PL='$request->R428PL', R428WH='$request->R428WH', R428STS='$request->R428STS', R428FIRST='$request->R428FIRST',
R428FAMILY='$request->R428FAMILY', R428EMAIL='$request->R428EMAIL', R428EMPCDE=$request->R428EMPCDE, R428ADMUSR='$request->R428ADMUSR',
R428PWRUSR='$request->R428PWRUSR',
MENU2OPT='".substr($ICM428M[0]->MENU2OPT,0,2).$request->MENU2OPT3.substr($ICM428M[0]->MENU2OPT,3,3).$request->MENU2OPT7.$request->MENU2OPT8."',
MENU3OPT='".$request->MENU3OPT1.$request->MENU3OPT2.substr($ICM428M[0]->MENU3OPT,2,-1)."',
MENU4OPT='".$request->MENU4OPT1.$request->MENU4OPT2.$request->MENU4OPT3.substr($ICM428M[0]->MENU4OPT,3,-1)."',
MENU5OPT='".$request->MENU5OPT1.$request->MENU5OPT2.$request->MENU5OPT3.substr($ICM428M[0]->MENU5OPT,3,1).$request->MENU5OPT5.substr($ICM428M[0]->MENU5OPT,5,-1)."',
MENU6OPT='".$request->MENU6OPT1.$request->MENU6OPT2.$request->MENU6OPT3.substr($ICM428M[0]->MENU6OPT,3,-1)."',
R42811A='".$request->R42811A."',R42821A='".$request->R42821A."'
where R428US='$request->R428US'");
return "success";
}
#590
public static function callCL(Request $request) {
$PGMERRORS = '';
// connect to toolkit using DB2 credentials (can also leave blank for default authority)
try {
$conn = app(\Modules\M3\Services\PostgresProgramBridge::class);
}
catch (\Exception $e)
{
// Determine reason for failure.
// Probably database authentication error or invalid or unreachable database.
$code = $e->getCode();
$msg = $e->getMessage();
switch ($code) {
case 8001:
// "Authorization failure on distributed database connection attempt"
// Usually means a wrong DB2 user or password
$PGMERRORS = 'Could not connect due to wrong user or password.';
break;
case 42705:
$PGMERRORS = 'Database not found. Try WRKRDBDIRE to check.';
break;
default:
$PGMERRORS = 'Could not connect. Error: ' . $code . ' ' . $msg;
break;
}
}
// $conn->setOptions(array('persistent' => false, 'stateless' => true, 'debug' => true,'debugLogFile' => '/www/sentm3test/htdocs/M3/storage/logs/toolkit_debug.log'));
// Add LIB
// $result = $conn->CLCommand('ADDLIBLE LIB(MPDAT10)');
// define several input/output params
$params = [];
// AddParameterChar($io, $size, $comment, $varName, $value, $varying, $dimension)
# Add Warehouse Param
$params[] = $conn->AddParameterChar('in', 10, 'userid','USERID',$request->USERID);
$params[] = $conn->AddParameterChar('in', 1, 'action','ACTION',$request->ACTION);
// AddParameterPackDec($io, $length, $scale, $comment, $varName, $value,$dimension)
// Add Delivery Note Param
//$params[] = $conn->AddParameterPackDec('in', 11, 0, 'ParamIn','','00000087125');
// $params[] = $conn->AddParameterZoned('in', 11, 0, 'ParamIn');
// Start Time Tracking
// $start = microtime(true);
//dump('Calling: EWOBJ/ICMCHGPRF action='.$request->ACTION.' user='.$request->USERID);
// Config::get('eproconf.misc.PGM1'), Config::get('eproconf.misc.libname4')
// ICM700C EWOBJTST ICM700C ICM700CSBM
$result = $conn->PgmCall('ICMCHGPRF', 'EWOBJ', $params, array(), array());
if (!$result) {
$PGMERRORS = 'Error calling program. Code: ' . $conn->getErrorCode() . ' Msg: ' . $conn->getErrorMsg();
//dump($PGMERRORS);
echo "";
return "error";
die();
}
// Successful Call
else{
//dump($result);
// $AWREQN = $result['io_param']["var0"];
//return "success";
if($request->ACTION=="P") {
echo "";
}
if($request->ACTION=="R") {
echo "";
}
echo "";
}
// if ($PGMERRORS!="") {
// // return back()->withMessage('Can not Create PR: '.$PGMERRORS);
// dump($PGMERRORS);
// }
// else{
// // return $AWREQN;
// }
}
#765
public static function savePassword(Request $request) {
#dd('B4');
ini_set('max_execution_time', Config::get('arrays.PHPTimeOut'));
ini_set('max_input_time', Config::get('arrays.PHPTimeOut'));
ini_set('default_socket_timeout', Config::get('arrays.PHPTimeOut'));
$PGMERRORS = '';
#console_log("request> ");
#echo "request="; var_dump($request);
#echo "B3
";
// connect to toolkit using DB2 credentials (can also leave blank for default authority)
try {
$conn = app(\Modules\M3\Services\PostgresProgramBridge::class);
#dump($conn);
#echo "B4
";
}
catch (\Exception $e)
{
#echo "B5
";
// Determine reason for failure.
// Probably database authentication error or invalid or unreachable database.
### $conn->setOptions(array('persistent' => false, 'stateless' => true, 'debug' => true,'debugLogFile' => '/www/sentm3test/htdocs/storage/logs/toolkit_debug.log'));
$code = $e->getCode();
$msg = $e->getMessage();
switch ($code) {
case 8001:
// "Authorization failure on distributed database connection attempt"
// Usually means a wrong DB2 user or password
$PGMERRORS = 'Could not connect due to wrong user or password.';
break;
case 42705:
$PGMERRORS = 'Database not found. Try WRKRDBDIRE to check.';
break;
default:
$PGMERRORS = 'Could not connect. Error: ' . $code . ' ' . $msg;
break;
}
}
#$params = [];
#$params[] = $conn->AddParameterChar('in', 10, 'userid','USRPRF',$request->USERID);
#$params[] = $conn->AddParameterChar('in', 10, 'pwd','PASSWORD',$request->PASSWORD);
#$params[] = $conn->AddParameterChar('in', 9, 'sts','STATUS','*ENABLED');
#$params[] = $conn->AddParameterChar('in', 4, 'pwdexp','PWDEXP','*NO');
//dump('Before CHGUSRPRF');
$result = $conn->CLCommand('QSYS/CHGUSRPRF USRPRF('.$request->R428US_PWD.') PASSWORD('.$request->NEW_PASSWORD.') STATUS(*ENABLED) PWDEXP(*NO)');
#$result = $conn->PgmCall('CHGUSRPRF', 'QSYS', $params, array(), array());
#echo "";
if (!$result) {
$PGMERRORS = 'Error calling program. Code: ' . $conn->getErrorCode() . ' Msg: ' . $conn->getErrorMsg();
dump($PGMERRORS);
echo "";
return "error pwd";
}
// Successful Call
else{
return "success";
}
}
}