Welcome to the nuBuilder Forums!

Register and log in to access exclusive forums and content available only to registered users.

User Name Instead of UserID for nuLog?

Questions related to customising nuBuilder Forte with JavaScript or PHP.
kev1n
nuBuilder Team
Posts: 4299
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 445 times
Contact:

Re: User Name Instead of UserID for nuLog?

Unread post by kev1n »

Try setting your time zone in the php function:

Code: Select all

date_default_timezone_set('YOUR_Timezone_HERE'); 
List of Supported Timezones:
https://www.php.net/manual/en/timezones.php
pmjd
Posts: 132
Joined: Fri Mar 12, 2021 10:38 am
Has thanked: 3 times
Been thanked: 1 time

Re: User Name Instead of UserID for nuLog?

Unread post by pmjd »

Thanks kev1n, added it as the first line and now showing the correct time.
pmjd
Posts: 132
Joined: Fri Mar 12, 2021 10:38 am
Has thanked: 3 times
Been thanked: 1 time

Re: User Name Instead of UserID for nuLog?

Unread post by pmjd »

kev1n is it possible to use phpHiddenWithParams to add the table name as a parameter? So it can be specified in the button onclick event rather than creating lots of indivdual procedures?

So far I've tried

Code: Select all

nuRunPHPHiddenWithParams('nulog_psn',$table_name,'prepared_solution',0);
in conjunction with

Code: Select all

date_default_timezone_set('Europe/London'); 
$table = $table_name;
$pk = $table.'_id';
$nulog = $table.'_nulog';


$S = "SELECT $nulog FROM $table WHERE $pk = ? ";
$T = nuRunQuery($S, array("#record_id#"));

$js = 'Error retrieving nulog Info';

if (db_num_rows($T) == 1) {
 
 $J = db_fetch_row($T);
 $J = $J[0];
 $jd = json_decode($J);
 
 $addedUser = isset($jd->added->user) ? getUserSusName($jd->added->user) : '';
 $addedTime = isset($jd->added->time) ? formatUnixTime($jd->added->time) : '';
 
 $editedUser = isset($jd->edited->user) ? getUserSusName($jd->edited->user) : '';
 $editedTime = isset($jd->edited->time) ? formatUnixTime($jd->edited->time) : '';
 
 //$viewedUser = isset($jd->viewed->user) ? getUserSusName($jd->viewed->user) : '';
 //$viewedTime = isset($jd->viewed->time) ? formatUnixTime($jd->viewed->time) : '';
 
 $info = '<b>Created by:</b> '. $addedUser.'<br>';
 $info .= '<b>Created on:</b> '. $addedTime.'<br>'; 
 $info .= '<b>Last Edited by:</b> '. $editedUser.'<br>'; 
 $info .= '<b>Last Edited on:</b> '. $editedTime.'<br><br>';
 $info .= '<b>View Audit Trail for full record history</b><br>';  
 //$info .= 'Viewed User: '. $viewedUser.'<br>';
 //$info .= 'Viewed Time: '. $viewedTime.'<br>'; 
 $info = base64_encode($info);
 
 $js = "
 
 function showNuLogInfo() {

 let info = atob('$info');
 
 nuMessage([info]);
 $('#nuMessageDiv').css('text-align', 'left');
 }
 
 showNuLogInfo();
 
 ";

 
}

nuJavascriptCallback($js);
function formatUnixTime($timestamp) {
 return date('d-M-Y H:i:s', $timestamp); 
}

function getUserSusName($id) {

 $u = nuUser($id);
 if ($u == false) {
 return $id;
 } else {
 return $u->sus_name == null ? $id : $u->sus_name;
 }
 
}
But this doesn't work.

Is there a way to do it or is it not possible?
kev1n
nuBuilder Team
Posts: 4299
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 445 times
Contact:

Re: User Name Instead of UserID for nuLog?

Unread post by kev1n »

Try:

Code: Select all

   nuRunPHPHiddenWithParams('nulog_psn', 'param', {table_name: 'prepared_solution'}, 0);   
pmjd
Posts: 132
Joined: Fri Mar 12, 2021 10:38 am
Has thanked: 3 times
Been thanked: 1 time

Re: User Name Instead of UserID for nuLog?

Unread post by pmjd »

Afraid that hasn't worked
kev1n
nuBuilder Team
Posts: 4299
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 445 times
Contact:

Re: User Name Instead of UserID for nuLog?

Unread post by kev1n »

Instead of:

Code: Select all

$table = $table_name;
write

Code: Select all

$param = json_decode(base64_decode('#param#')); // retrieve the parameters
$table  = $param->table_name;
pmjd
Posts: 132
Joined: Fri Mar 12, 2021 10:38 am
Has thanked: 3 times
Been thanked: 1 time

Re: User Name Instead of UserID for nuLog?

Unread post by pmjd »

That has got it working now, thank you :D
Post Reply