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.
pmjd
Posts: 132
Joined: Fri Mar 12, 2021 10:38 am
Has thanked: 3 times
Been thanked: 1 time

User Name Instead of UserID for nuLog?

Unread post by pmjd »

Hello,

I've used the code in the code library for a simple button to display the nuLog info.
https://github.com/nuBuilder/nuBuilder- ... g_activity

However, the 15 character userID is shown in the popup for any users other than globeadmin.

Is there a way to modify the code so that the sus_name is displayed instead of the user_id?
kev1n
nuBuilder Team
Posts: 4302
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 »

It is best to create a procedure.

Run this SQL in phpMyAdmin to create one with code nulog_info

Code: Select all

INSERT INTO `zzzzsys_php` (`zzzzsys_php_id`, `sph_code`, `sph_description`, `sph_group`, `sph_php`, `sph_run`, `sph_zzzzsys_form_id`, `sph_system`, `sph_global`, `sph_hide`) VALUES ('6112751d5efe000', 'nulog_info', 'Show nulog info', NULL, '$table = \'INSERT_YOUR_TABLE_HERE\';\r\n$pk = $table.\'_id\';\r\n$nulog = $table.\'_nulog\';\r\n\r\n$S = \"SELECT $nulog FROM $table WHERE $pk = ? \";\r\n$T = nuRunQuery($S, array(\"#record_id#\"));\r\n\r\nif (db_num_rows($T) == 1) {\r\n \r\n $J = db_fetch_row($T);\r\n $J = $J[0];\r\n $jd = json_decode($J);\r\n \r\n $addedUser = isset($jd->added->user) ? getUserSusName($jd->added->user) : \'\';\r\n $addedTime = isset($jd->added->time) ? formatUnixTime($jd->added->time) : \'\';\r\n $editedUser = isset($jd->edited->user) ? getUserSusName($jd->edited->user) : \'\';\r\n $editedTime = isset($jd->edited->time) ? formatUnixTime($jd->edited->time) : \'\';\r\n $viewedUser = isset($jd->viewed->user) ? getUserSusName($jd->viewed->user) : \'\';\r\n $viewedTime = isset($jd->viewed->time) ? formatUnixTime($jd->viewed->time) : \'\';\r\n\r\n $info = \'Added User: \'. $addedUser.\'<br>\';\r\n $info .= \'Added Time: \'. $addedTime.\'<br>\'; \r\n $info .= \'Edited User: \'. $editedUser.\'<br>\'; \r\n $info .= \'Edited Time: \'. $editedTime.\'<br>\'; \r\n $info .= \'Viewed User: \'. $viewedUser.\'<br>\';\r\n $info .= \'Viewed Time: \'. $viewedTime.\'<br>\';\r\n $info = base64_encode($info);\r\n\r\n $js = \"\r\n\r\n function showNuLogInfo() {\r\n\r\n let info = atob(\'$info\');\r\n\r\n nuMessage([info]);\r\n $(\'#nuMessageDiv\').css(\'text-align\', \'left\');\r\n }\r\n\r\n showNuLogInfo();\r\n \";\r\n\r\n} else {\r\n $js = \"nuMessage(\'Error retrieving nulog Info\');\";\r\n}\r\n\r\nnuJavascriptCallback($js);\r\n\r\nfunction formatUnixTime($timestamp) {\r\n return date(\'Y-m-d H:i:s\', $timestamp); \r\n}\r\n\r\nfunction getUserSusName($id) {\r\n\r\n $u = nuUser($id);\r\n if ($u == false) {\r\n return $id;\r\n } else {\r\n return $u->sus_name == null ? $id : $u->sus_name;\r\n }\r\n \r\n}', 'hide', NULL, '0', '0', '')
Edit the Procedure and replace the $table value in the Procedure with your table name.

To run it, call the JavaScript function:

Code: Select all

nuRunPHPHidden('nulog_info',0); 
You will need the latest nucommon.php from Github.
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, where is

Code: Select all

nuRunPHPHidden('nulog_info',0);
placed in relation to the existing code in the Code Library?
kev1n
nuBuilder Team
Posts: 4302
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 »

In place of showNuLogInfo('example_nulog')
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 »

Sorry, but I tried running nuRunPHPHidden('nulog_info',0); as an onclick event for the button in place of showNuLogInfo(',myfield_nulog') but nothing happens.

I also tried replacing the second parameter 0 with the myname _nulog field name

Code: Select all

nuRunPHPHidden('nulog_info',myfield_nulog);
but also nothing.
kev1n
nuBuilder Team
Posts: 4302
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 »

Did you run the above SQL and does the Procedure nulog_info exist? If yes, check the nuDebug Results for errors.
kev1n
nuBuilder Team
Posts: 4302
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 »

I forgot to mention something essential:
Replace the $table value in the Procedure with your table name.

Code: Select all

$table = 'browse_edit';
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 »

Have replaced the browse_edit table name in the procedure and it is working now, thank you.

Is it normal for the stored Procedures listed not to be listed in the Run Procedure list?
kev1n
nuBuilder Team
Posts: 4302
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 »

Only Procedure with a "Lauch From" are listed there. If you pick "nublank", you will see it.
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 »

Hello,

I've started to impliment this code but notice that 2 hours is removed compared to the current sustem/local time. The previous use of the original nulog time stamps matched the local/system time perfectly.

Is there a way to correct this?

Thanks,
Paul
Post Reply