The following warnings occurred:
Warning [2] Undefined array key "avatartype" - Line: 783 - File: global.php PHP 8.1.31 (Linux)
File Line Function
/global.php 783 errorHandler->error
/printthread.php 16 require_once
Warning [2] Undefined array key "avatartype" - Line: 783 - File: global.php PHP 8.1.31 (Linux)
File Line Function
/global.php 783 errorHandler->error
/printthread.php 16 require_once
Warning [2] Undefined variable $newpmmsg - Line: 40 - File: global.php(841) : eval()'d code PHP 8.1.31 (Linux)
File Line Function
/global.php(841) : eval()'d code 40 errorHandler->error
/global.php 841 eval
/printthread.php 16 require_once
Warning [2] Undefined array key "style" - Line: 909 - File: global.php PHP 8.1.31 (Linux)
File Line Function
/global.php 909 errorHandler->error
/printthread.php 16 require_once
Warning [2] Undefined property: MyLanguage::$lang_select_default - Line: 5024 - File: inc/functions.php PHP 8.1.31 (Linux)
File Line Function
/inc/functions.php 5024 errorHandler->error
/global.php 909 build_theme_select
/printthread.php 16 require_once
Warning [2] Undefined array key "additionalgroups" - Line: 7162 - File: inc/functions.php PHP 8.1.31 (Linux)
File Line Function
/inc/functions.php 7162 errorHandler->error
/inc/functions.php 5044 is_member
/global.php 909 build_theme_select
/printthread.php 16 require_once
Warning [2] Undefined array key 1 - Line: 1415 - File: inc/functions.php PHP 8.1.31 (Linux)
File Line Function
/inc/functions.php 1415 errorHandler->error
/inc/functions.php 1370 fetch_forum_permissions
/printthread.php 76 forum_permissions
Warning [2] Undefined property: MyLanguage::$archive_pages - Line: 2 - File: printthread.php(257) : eval()'d code PHP 8.1.31 (Linux)
File Line Function
/printthread.php(257) : eval()'d code 2 errorHandler->error
/printthread.php 257 eval
/printthread.php 117 printthread_multipage
Warning [2] Undefined array key "showimages" - Line: 160 - File: printthread.php PHP 8.1.31 (Linux)
File Line Function
/printthread.php 160 errorHandler->error
Warning [2] Undefined array key "showvideos" - Line: 165 - File: printthread.php PHP 8.1.31 (Linux)
File Line Function
/printthread.php 165 errorHandler->error
Warning [2] Undefined array key "showimages" - Line: 160 - File: printthread.php PHP 8.1.31 (Linux)
File Line Function
/printthread.php 160 errorHandler->error
Warning [2] Undefined array key "showvideos" - Line: 165 - File: printthread.php PHP 8.1.31 (Linux)
File Line Function
/printthread.php 165 errorHandler->error
Warning [2] Undefined array key "showimages" - Line: 160 - File: printthread.php PHP 8.1.31 (Linux)
File Line Function
/printthread.php 160 errorHandler->error
Warning [2] Undefined array key "showvideos" - Line: 165 - File: printthread.php PHP 8.1.31 (Linux)
File Line Function
/printthread.php 165 errorHandler->error
Warning [2] Undefined array key "showimages" - Line: 160 - File: printthread.php PHP 8.1.31 (Linux)
File Line Function
/printthread.php 160 errorHandler->error
Warning [2] Undefined array key "showvideos" - Line: 165 - File: printthread.php PHP 8.1.31 (Linux)
File Line Function
/printthread.php 165 errorHandler->error
Warning [2] Undefined array key "showimages" - Line: 160 - File: printthread.php PHP 8.1.31 (Linux)
File Line Function
/printthread.php 160 errorHandler->error
Warning [2] Undefined array key "showvideos" - Line: 165 - File: printthread.php PHP 8.1.31 (Linux)
File Line Function
/printthread.php 165 errorHandler->error
Warning [2] Undefined array key "showimages" - Line: 160 - File: printthread.php PHP 8.1.31 (Linux)
File Line Function
/printthread.php 160 errorHandler->error
Warning [2] Undefined array key "showvideos" - Line: 165 - File: printthread.php PHP 8.1.31 (Linux)
File Line Function
/printthread.php 165 errorHandler->error
Warning [2] Undefined array key "showimages" - Line: 160 - File: printthread.php PHP 8.1.31 (Linux)
File Line Function
/printthread.php 160 errorHandler->error
Warning [2] Undefined array key "showvideos" - Line: 165 - File: printthread.php PHP 8.1.31 (Linux)
File Line Function
/printthread.php 165 errorHandler->error
Warning [2] Undefined array key "showimages" - Line: 160 - File: printthread.php PHP 8.1.31 (Linux)
File Line Function
/printthread.php 160 errorHandler->error
Warning [2] Undefined array key "showvideos" - Line: 165 - File: printthread.php PHP 8.1.31 (Linux)
File Line Function
/printthread.php 165 errorHandler->error
Warning [2] Undefined array key "showimages" - Line: 160 - File: printthread.php PHP 8.1.31 (Linux)
File Line Function
/printthread.php 160 errorHandler->error
Warning [2] Undefined array key "showvideos" - Line: 165 - File: printthread.php PHP 8.1.31 (Linux)
File Line Function
/printthread.php 165 errorHandler->error
Warning [2] Undefined array key "showimages" - Line: 160 - File: printthread.php PHP 8.1.31 (Linux)
File Line Function
/printthread.php 160 errorHandler->error
Warning [2] Undefined array key "showvideos" - Line: 165 - File: printthread.php PHP 8.1.31 (Linux)
File Line Function
/printthread.php 165 errorHandler->error



Form Tools
Last Updated By Field - Printable Version

+- Form Tools (https://forums.formtools.org)
+-- Forum: Form Tools (https://forums.formtools.org/forumdisplay.php?fid=1)
+--- Forum: Feature Suggestions (https://forums.formtools.org/forumdisplay.php?fid=7)
+--- Thread: Last Updated By Field (/showthread.php?tid=1651)

Pages: 1 2


Last Updated By Field - alexh - Sep 21st, 2011

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


RE: Last Updated By Field - Ben - Sep 22nd, 2011

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


RE: Last Updated By Field - alexh - Sep 22nd, 2011

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




RE: Last Updated By Field - Ben - Sep 25th, 2011

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


RE: Last Updated By Field - alexh - Sep 28th, 2011

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




RE: Last Updated By Field - Ben - Sep 29th, 2011

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:
PHP Code:
$form_id 16

For the second line, do you have the ID in a variable? If so, include the variable name with the dollar sign:
PHP Code:
$submission_id $id

(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


RE: Last Updated By Field - alexh - Sep 29th, 2011

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:
PHP Code:
$form_id 16

For the second line, do you have the ID in a variable? If so, include the variable name with the dollar sign:
PHP Code:
$submission_id $id

(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




RE: Last Updated By Field - alexh - Sep 29th, 2011

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


RE: Last Updated By Field - alexh - Oct 24th, 2011

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;
}



RE: Last Updated By Field - Ben - Oct 25th, 2011

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