EscalateSEO Posted June 6, 2015 Share Posted June 6, 2015 I'm trying to track which files have been downloaded by which users. I'm using this action hook to track the downloads: http://docs.whmcs.com/Hooks:FileDownload Here's the code I have for my action hook: <?php add_hook("FileDownload",0,"track_FileDownload",""); function track_FileDownload($vars) { logactivity("File Downloaded"); } ?> Right now it's displaying this in my activity log: File Downloaded But what I would like is for the log to also display the title of the file that was downloaded, like this: File Downloaded - Name Of File Does anyone know how to do this or if it's possible? 0 Quote Link to comment Share on other sites More sharing options...
sentq Posted June 6, 2015 Share Posted June 6, 2015 there is no values inside $vars passed to function but we can access $_REQUEST to get file ID and using it we can get the information of that file, the following code will give you what you need: <?php # Track Files Downloaded function hook_trackFilesDownloaded($vars){ $fileID = intval($_GET['id']); if ($fileID!=0){ $getFileInfo = full_query("SELECT `title` FROM `tbldownloads` WHERE `id`='{$fileID}' LIMIT 1"); $getFileInfo = mysql_fetch_assoc($getFileInfo); logActivity("File Downloaded - " . $getFileInfo['title']); } } add_hook("FileDownload", 1, "hook_trackFilesDownloaded"); 0 Quote Link to comment Share on other sites More sharing options...
Plambee Posted June 6, 2015 Share Posted June 6, 2015 great Hook, but I have one question: is it possible to add the client id in the logActivity? (I can't find a $_REQUEST to get the current client id) Thanks! 0 Quote Link to comment Share on other sites More sharing options...
sentq Posted June 6, 2015 Share Posted June 6, 2015 use the following one and it will add the clientID to log message only if the client is logged, try it <?php # Track Files Downloaded function hook_trackFilesDownloaded($vars){ $fileID = intval($_GET['id']); $userID = $_SESSION['uid']; if ($fileID!=0){ $getFileInfo = full_query("SELECT `title` FROM `tbldownloads` WHERE `id`='{$fileID}' LIMIT 1"); $getFileInfo = mysql_fetch_assoc($getFileInfo); $logText = ''; $logText .= "File Downloaded - " . $getFileInfo['title']; if ($userID!=0){ $logText .= " - User ID: " . $userID; } logActivity($logText); } } add_hook("FileDownload", 1, "hook_trackFilesDownloaded"); 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.