Welcome to the nuBuilder Forums!
Register and log in to access exclusive forums and content available only to registered users.
Register and log in to access exclusive forums and content available only to registered users.
User Name Instead of UserID for nuLog?
User Name Instead of UserID for nuLog?
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?
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?
-
- 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?
It is best to create a procedure.
Run this SQL in phpMyAdmin to create one with code nulog_info
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.
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', '')
To run it, call the JavaScript function:
Code: Select all
nuRunPHPHidden('nulog_info',0);
Re: User Name Instead of UserID for nuLog?
Thanks kev1n, where is placed in relation to the existing code in the Code Library?
Code: Select all
nuRunPHPHidden('nulog_info',0);
-
- 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?
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 but also nothing.
I also tried replacing the second parameter 0 with the myname _nulog field name
Code: Select all
nuRunPHPHidden('nulog_info',myfield_nulog);
-
- 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?
Did you run the above SQL and does the Procedure nulog_info exist? If yes, check the nuDebug Results for errors.
-
- 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?
I forgot to mention something essential:
Replace the $table value in the Procedure with your table name.
Replace the $table value in the Procedure with your table name.
Code: Select all
$table = 'browse_edit';
Re: User Name Instead of UserID for nuLog?
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?
Is it normal for the stored Procedures listed not to be listed in the Run Procedure list?
-
- 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?
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?
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
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