Page 1 of 2
User Name Instead of UserID for nuLog?
Posted: Tue Aug 10, 2021 11:12 am
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?
Re: User Name Instead of UserID for nuLog?
Posted: Tue Aug 10, 2021 3:35 pm
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:
You will need the latest
nucommon.php from Github.
Re: User Name Instead of UserID for nuLog?
Posted: Tue Aug 10, 2021 4:45 pm
by pmjd
Thanks kev1n, where is
placed in relation to the existing code in the Code Library?
Re: User Name Instead of UserID for nuLog?
Posted: Tue Aug 10, 2021 4:52 pm
by kev1n
In place of showNuLogInfo('example_nulog')
Re: User Name Instead of UserID for nuLog?
Posted: Tue Aug 10, 2021 5:44 pm
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.
Re: User Name Instead of UserID for nuLog?
Posted: Tue Aug 10, 2021 6:50 pm
by kev1n
Did you run the above SQL and does the Procedure nulog_info exist? If yes, check the nuDebug Results for errors.
Re: User Name Instead of UserID for nuLog?
Posted: Wed Aug 11, 2021 12:03 am
by kev1n
I forgot to mention something essential:
Replace the $table value in the Procedure with your table name.
Re: User Name Instead of UserID for nuLog?
Posted: Wed Aug 11, 2021 10:45 am
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?
Re: User Name Instead of UserID for nuLog?
Posted: Wed Aug 11, 2021 10:54 am
by kev1n
Only Procedure with a "Lauch From" are listed there. If you pick "nublank", you will see it.
Re: User Name Instead of UserID for nuLog?
Posted: Tue Aug 17, 2021 3:54 pm
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