Posts: 339 
	Threads: 42 
	Joined: Apr 2010
	
 Reputation: 
 2
	 
 
	
	
		I would suggest creating a field that shows "Last Updated By:" and the name of the account holder that updated the entry. 
 
Although the submission history is great, I can't pull that info out of the database and display it on a web page.  For example, I pull the content of the database entry out, and display it on a web page.  I would like to have a field that shows "Last Updated by John Doe on 9/21/2011 at 0000 hours."  I can already do the time part by using the modified date and time.. but can't pull that user's name out. 
 
Alex
	 
	
	
	
		
	 
 
 
	
	
	
		
	Posts: 2,456 
	Threads: 39 
	Joined: Dec 2008
	
 Reputation: 
 6
	 
 
	
	
		Yeah, that would be a nice feature. But I think I'd just extend the module to return that info if requested (e.g. sh_get_last_updated_info($submission_id)). 
 
Is this something you already do on your own site (I mean, display the submission data)?  
 
- Ben
	 
	
	
	
		
	 
 
 
	
	
	
		
	Posts: 339 
	Threads: 42 
	Joined: Apr 2010
	
 Reputation: 
 2
	 
 
	
	
		Ben - that would work perfect.  Yes, - it's the press release application you helped me with.  :-) 
 (Sep 22nd, 2011, 1:19 PM)Ben Wrote:  Yeah, that would be a nice feature. But I think I'd just extend the module to return that info if requested (e.g. sh_get_last_updated_info($submission_id)). 
 
Is this something you already do on your own site (I mean, display the submission data)?  
 
- Ben 
	 
	
	
	
		
	 
 
 
	
	
	
		
	Posts: 2,456 
	Threads: 39 
	Joined: Dec 2008
	
 Reputation: 
 6
	 
 
	
		
		
		Sep 25th, 2011, 8:51 PM 
(This post was last modified: Sep 25th, 2011, 8:54 PM by Ben.)
		
	 
	
		Hey Alex, 
Sorry! Brain like a sieve. 
 
Here: just add this function to the bottom of your /modules/submission_history/code/general.php file:
 PHP Code: /**  * This returns information about who last modified the submission. Added in 1.1.2.  *  * @param integer $form_id  * @param integer $submission_id  * @return array has_history  - true/false  *               account_type - admin/client/unknown  *               account_id   - the ID of the admin/client  *               first_name   - the admin/client last name  *               last_name    - the admin/client last name  */ function sh_get_last_modified_info($form_id, $submission_id) {   global $g_table_prefix;
    $query = mysql_query("     SELECT sh___change_account_type, sh___change_account_id     FROM   {$g_table_prefix}form_{$form_id}_history     WHERE  submission_id = $submission_id     ORDER BY     sh___history_id DESC     LIMIT 1   ");
    $return_info = array("has_been_modified" => false);   if (mysql_num_rows($query) == 0)   {     return $return_info;   }
    $result = mysql_fetch_assoc($query);   $return_info = array(     "has_been_modified" => true,     "account_type"      => $result["sh___change_account_type"],     "account_id"        => $result["sh___change_account_id"]   );
    if (is_numeric($result["sh___change_account_id"]))   {     $account_info = ft_get_account_info($result["sh___change_account_id"]);     $return_info["first_name"] = $account_info["first_name"];     $return_info["last_name"] = $account_info["last_name"];   }
    return $return_info; } 
 
 
Then, to call it, just add this code to your PHP page (the first line is only necessary if you haven't already included the API or library.php file):
 PHP Code: require_once('path/to/global/library.php'); ft_include_module("submission_history"); $form_id = 123; $submission_id = 456; $last_modified_info = sh_get_last_modified_info($form_id, $submission_id); 
 
 
Then, $last_modified_info contains all the important details about who last modified it. 
 
Here's what it contains:
 PHP Code: // boolean. This will contain "true" if there's a record in the history table; false otherwise. $last_modified_info["has_been_modified"];
  // *** the following keys are only populated if has_been_modified == true
  // string. this contains "admin", "client" or "unknown" $last_modified_info["account_type"];
  // integer. This only has a value if account_type == "admin" or "client" $last_modified_info["account_id"];
  // strings. These are only populated if account_type == "admin" or "client" $last_modified_info["first_name"]; $last_modified_info["last_name"]; 
 
 
Let me know how it goes. If all looks good, I'll add it to the next version of the module! 
 
- Ben
	  
	
	
	
		
	 
 
 
	
	
	
		
	Posts: 339 
	Threads: 42 
	Joined: Apr 2010
	
 Reputation: 
 2
	 
 
	
	
		Thanks Ben!  So I added the code your provided to the general.php file, and then added this to the php file I want to display the info: 
Code: <?php require_once('/path/to/global/library.php'); 
ft_include_module("submission_history"); 
$form_id = form_16; 
$submission_id = id; 
$last_modified_info = sh_get_last_modified_info($form_id, $submission_id); 
?>
 
(I updated the path, and the form_id to the correct value.  "id" will be obtained from the url, test.php?id=1)
 
So, there are no errors on the page. yay!  But now to print the info I need on the page...so I would assume
 Code: echo $last_modified_info["first_name"];
 
Of course, with my limited (but learning!) php knowledge, I have missed something.. because nothing is displayed :-)
  (Sep 25th, 2011, 8:51 PM)Ben Wrote:  Hey Alex, 
 
Sorry! Brain like a sieve.  
 
Here: just add this function to the bottom of your /modules/submission_history/code/general.php file: 
 
PHP Code: /**  * This returns information about who last modified the submission. Added in 1.1.2.  *  * @param integer $form_id  * @param integer $submission_id  * @return array has_history  - true/false  *               account_type - admin/client/unknown  *               account_id   - the ID of the admin/client  *               first_name   - the admin/client last name  *               last_name    - the admin/client last name  */ function sh_get_last_modified_info($form_id, $submission_id) {   global $g_table_prefix;
    $query = mysql_query("     SELECT sh___change_account_type, sh___change_account_id     FROM   {$g_table_prefix}form_{$form_id}_history     WHERE  submission_id = $submission_id     ORDER BY     sh___history_id DESC     LIMIT 1   ");
    $return_info = array("has_been_modified" => false);   if (mysql_num_rows($query) == 0)   {     return $return_info;   }
    $result = mysql_fetch_assoc($query);   $return_info = array(     "has_been_modified" => true,     "account_type"      => $result["sh___change_account_type"],     "account_id"        => $result["sh___change_account_id"]   );
    if (is_numeric($result["sh___change_account_id"]))   {     $account_info = ft_get_account_info($result["sh___change_account_id"]);     $return_info["first_name"] = $account_info["first_name"];     $return_info["last_name"] = $account_info["last_name"];   }
    return $return_info; } 
 
  
Then, to call it, just add this code to your PHP page (the first line is only necessary if you haven't already included the API or library.php file): 
 
PHP Code: require_once('path/to/global/library.php'); ft_include_module("submission_history"); $form_id = 123; $submission_id = 456; $last_modified_info = sh_get_last_modified_info($form_id, $submission_id); 
 
  
Then, $last_modified_info contains all the important details about who last modified it.  
 
Here's what it contains: 
 
 
PHP Code: // boolean. This will contain "true" if there's a record in the history table; false otherwise. $last_modified_info["has_been_modified"];
  // *** the following keys are only populated if has_been_modified == true
  // string. this contains "admin", "client" or "unknown" $last_modified_info["account_type"];
  // integer. This only has a value if account_type == "admin" or "client" $last_modified_info["account_id"];
  // strings. These are only populated if account_type == "admin" or "client" $last_modified_info["first_name"]; $last_modified_info["last_name"]; 
 
  
Let me know how it goes. If all looks good, I'll add it to the next version of the module!  
 
- Ben 
	 
	
	
	
		
	 
 
 
	
	
	
		
	Posts: 2,456 
	Threads: 39 
	Joined: Dec 2008
	
 Reputation: 
 6
	 
 
	
	
		Hey Alex, 
Was this exactly as you added it to your page?
 PHP Code: $form_id = form_16; $submission_id = id; 
 
 
If so, change the first line to read: 
 
For the second line, do you have the ID in a variable? If so, include the variable name with the dollar sign:
 
(or just pass the variable directly to the function). 
 
One other tip: add this at the very end. That will output everything in the returned value. It should contain one array key, at least!
 PHP Code: print_r($last_modified_info); 
 
 
Let me know how it goes!
 
- Ben
	  
	
	
	
		
	 
 
 
	
	
	
		
	Posts: 339 
	Threads: 42 
	Joined: Apr 2010
	
 Reputation: 
 2
	 
 
	
	
		Aha! 
Now it prints all the good stuff!
  Quote:Array ( [has_been_modified] => 1 [account_type] => admin [account_id] => 1 [first_name] => Alex [last_name] => H )  
 (Sep 29th, 2011, 11:12 AM)Ben Wrote:  Hey Alex, 
 
Was this exactly as you added it to your page? 
 
PHP Code: $form_id = form_16; $submission_id = id; 
 
  
If so, change the first line to read:  
 
For the second line, do you have the ID in a variable? If so, include the variable name with the dollar sign: 
 
(or just pass the variable directly to the function).  
 
One other tip: add this at the very end. That will output everything in the returned value. It should contain one array key, at least! 
PHP Code: print_r($last_modified_info); 
 
  
Let me know how it goes! 
 
- Ben 
	 
	
	
	
		
	 
 
 
	
	
	
		
	Posts: 339 
	Threads: 42 
	Joined: Apr 2010
	
 Reputation: 
 2
	 
 
	
		
		
		Sep 29th, 2011, 12:55 PM 
(This post was last modified: Sep 29th, 2011, 2:20 PM by alexh.)
		
	 
	
		Ok, so this is working great!  Thank you so much! Can I pull something from an extended client field? 
 
Also - if a user CREATES the entry from within formtools (Logged in, and not thru an external form), does that make has_been_modified == 1?  Or will it still be == 0 until it is modified again? 
 
 
Alex
	 
	
	
	
		
	 
 
 
	
	
	
		
	Posts: 339 
	Threads: 42 
	Joined: Apr 2010
	
 Reputation: 
 2
	 
 
	
	
		I just upgraded, and noticed that I was getting a bunch of fatal errors on some of my pages.  I had to re-add the code to the bottom of the /modules/submission_history/global/code/general.php file.  Will this code be added to future versions so I don't have to keep adding it? 
Code: /** 
 * This returns information about who last modified the submission. Added in 1.1.2. 
 * 
 * @param integer $form_id 
 * @param integer $submission_id 
 * @return array has_history  - true/false 
 *               account_type - admin/client/unknown 
 *               account_id   - the ID of the admin/client 
 *               first_name   - the admin/client last name 
 *               last_name    - the admin/client last name 
 */ 
function sh_get_last_modified_info($form_id, $submission_id) 
{ 
  global $g_table_prefix; 
 
  $query = mysql_query(" 
    SELECT sh___change_account_type, sh___change_account_id 
    FROM   {$g_table_prefix}form_{$form_id}_history 
    WHERE  submission_id = $submission_id 
    ORDER BY     sh___history_id DESC 
    LIMIT 1 
  "); 
 
  $return_info = array("has_been_modified" => false); 
  if (mysql_num_rows($query) == 0) 
  { 
    return $return_info; 
  } 
 
  $result = mysql_fetch_assoc($query); 
  $return_info = array( 
    "has_been_modified" => true, 
    "account_type"      => $result["sh___change_account_type"], 
    "account_id"        => $result["sh___change_account_id"] 
  ); 
 
  if (is_numeric($result["sh___change_account_id"])) 
  { 
    $account_info = ft_get_account_info($result["sh___change_account_id"]); 
    $return_info["first_name"] = $account_info["first_name"]; 
    $return_info["last_name"] = $account_info["last_name"]; 
  } 
 
  return $return_info; 
}
  
	 
	
	
	
		
	 
 
 
	
	
	
		
	Posts: 2,456 
	Threads: 39 
	Joined: Dec 2008
	
 Reputation: 
 6
	 
 
	
		
		
		Oct 25th, 2011, 12:54 PM 
(This post was last modified: Oct 25th, 2011, 1:01 PM by Ben.)
		
	 
	
		Oh drat, I totally forgot to add that function in.  
 
[EDIT: I just released 1.1.3 of the Submission History module. Just download that and you're all set!] 
 
- Ben
	 
	
	
	
		
	 
 
 
	 
 |