Page 1 of 1

CurrentUserInfo in Custom file

Posted: Mon Apr 10, 2017 10:08 pm
by btrade

Hi,

How can I to use the CurrentUserInfo in custom file or userfn13.php ? I have error in this file

echo CurrentUserInfo('t_level_id');
( ! ) Warning: Creating default object from empty value in J:\home\site\www\search\ewshared13.php on line 1540


Re: CurrentUserInfo in Custom file

Posted: Tue Apr 11, 2017 10:44 am
by arbei

Can you show the code around ewshared13.php line 1540?

Normally, enabled the option "include common files" and "Use Existing Table" in [Security] and the CurrentUserIfo() will work fine.


Re: CurrentUserInfo in Custom file

Posted: Wed Apr 12, 2017 6:48 pm
by btrade

arbei wrote:
Normally, enabled the option "include common files" and "Use Existing Table" in [Security]
and the CurrentUserIfo() will work fine.

This is enabled.

echo CurrentUserInfo('login');
The function work in all scripts.
This dont work only in custom files.

( ! ) Warning: Creating default object from empty value in J:\home\translator\www\backoffice\ewshared13.php on line 1522
( ! ) Fatal error: Call to undefined method stdClass::Execute() in J:\home\translator\www\backoffice\ewshared13.php on line 1523

// Load recordset
if (!function_exists('ew_LoadRecordset')) {

function &ew_LoadRecordset($SQL, $c = NULL) {
	if (is_string($c))
		$c = &Conn($c);
	$conn = ($c) ? $c : $GLOBALS["conn"];
	$conn->raiseErrorFn = $GLOBALS["EW_ERROR_FN"];
	$rs = $conn->Execute($SQL);
	$conn->raiseErrorFn = '';
	return $rs;
}

}

I use the data of Linked Table for autorization.


Re: CurrentUserInfo in Custom file

Posted: Thu Apr 13, 2017 11:34 am
by danielc

Normally, enabled the option "include common files" and "Use Existing Table" in [Security] and the CurrentUserIfo() will work fine.

Make sure you have enabled the option "include common files". When you create a new Custom File from your PHPMaker project, then you should see "Include common files" option in the "Custom File" dialog box.

If you write the code in Custom File (Content), rememeber to use:
<?php echo CurrentUserInfo("t_level_id"); ?>

Also, the field name is case sensitive.


Re: CurrentUserInfo in Custom file

Posted: Mon Apr 17, 2017 5:32 pm
by btrade

I use <?php echo CurrentUserInfo("t_level_id"); ?> in userfn13.php and i have error

( ! ) Warning: Creating default object from empty value in J:\home\site\www\search\ewshared13.php on line 1540


Re: CurrentUserInfo in Custom file

Posted: Tue Apr 18, 2017 10:05 am
by mobhar

Please note that the generated code in "userfn13.php" file is PHP code and basically the code in this file is the global functions that you wrote in "Global Code" of server event. You don't need to enclose it with PHP tags anymore.

In addition, in which line did you put that code, and what for? You should use that code in your own global function from "Global Code" section, and not customizing the generated "userfn13.php" file.


Re: CurrentUserInfo in Custom file

Posted: Tue Apr 18, 2017 5:36 pm
by btrade

mobhar wrote:
Please note that the generated code in "userfn13.php" file is PHP code and basically
the code in this file is the global functions that you wrote in "Global Code" of
server event. You don't need to enclose it with PHP tags anymore.

I understand it.

In addition, in which line did you put that code, and what for? You should use that
code in your own global function from "Global Code" section, and not customizing
the generated "userfn13.php" file.

I use this function to extract data from a table of user profile. This function works in the project in other files. It does not work only in "Global Code".


Re: CurrentUserInfo in Custom file

Posted: Wed Apr 19, 2017 10:26 am
by mobhar

Then please post your code in "Global Code" for more discussion.


Re: CurrentUserInfo in Custom file

Posted: Wed Apr 19, 2017 9:22 pm
by btrade

function ew_UserFormatDateTime($field, $default) {

		$dbhelper =& DbHelper(DB_ACCOUNT);
		//$row = $dbhelper->ExecuteScalar("SELECT `".$field."` FROM `account_profiles_params` WHERE `profiles_id` = '" .CurrentUserID()."' ");
		$row = CurrentUserInfo($field);
		if ($row > 0) {
			return $row;
		} else {
			return $default;
		}
	}
	$ew_User_DATE_FORMAT = ew_UserFormatDateTime('date_format', 7);
	$ew_User_TIME_FORMAT = ew_UserFormatDateTime('time_format', 4);
	$ew_User_TIZO_FORMAT = ew_UserFormatDateTime('time_zone', 161);
	$ew_User_ZONE_FORMAT = ew_UserTimeZone($ew_User_TIZO_FORMAT);
	$ew_User_CDAT_FORMAT = ew_UserCalendar('calendar', $ew_User_DATE_FORMAT);
	$ew_User_CTIM_FORMAT = ew_UserCalendar('calendar', $ew_User_TIME_FORMAT);
	$ew_User_MDAT_FORMAT = ew_UserCalendar('mask', $ew_User_DATE_FORMAT);
	$ew_User_MTIM_FORMAT = ew_UserCalendar('mask', $ew_User_TIME_FORMAT);
	$ew_User_PDAT_FORMAT = ew_UserCalendar('placeholder', $ew_User_DATE_FORMAT);
	$ew_User_PTIM_FORMAT = ew_UserCalendar('placeholder', $ew_User_TIME_FORMAT);
	$ew_User_POINT_FORMAT = ew_UserFormatDateTime('mon_decimal_point', ',');

Re: CurrentUserInfo in Custom file

Posted: Thu Apr 20, 2017 11:45 am
by arbei

btrade wrote:
function ew_UserFormatDateTime($field, $default) {

		$dbhelper =& DbHelper(DB_ACCOUNT);

You should pass a string value or a variable to the DbHelper function.

For Example:
$dbhelper = &DbHelper("DB");


Re: CurrentUserInfo in Custom file

Posted: Thu Apr 20, 2017 12:03 pm
by mobhar
  1. No need to use dbhelper in "Global Code". Just change your code as follows:

function ew_UserFormatDateTime($field, $default) {
$row = CurrentUserInfo($field);
if ($row > 0) {
return $row;
} else {
return $default;
}
}

  1. Move this following code from "Global Code" section into your custom file (remember to enclose it with PHP tags):

$ew_User_DATE_FORMAT = ew_UserFormatDateTime('date_format', 7);
$ew_User_TIME_FORMAT = ew_UserFormatDateTime('time_format', 4);
$ew_User_TIZO_FORMAT = ew_UserFormatDateTime('time_zone', 161);
$ew_User_ZONE_FORMAT = ew_UserTimeZone($ew_User_TIZO_FORMAT);
$ew_User_CDAT_FORMAT = ew_UserCalendar('calendar', $ew_User_DATE_FORMAT);
$ew_User_CTIM_FORMAT = ew_UserCalendar('calendar', $ew_User_TIME_FORMAT);
$ew_User_MDAT_FORMAT = ew_UserCalendar('mask', $ew_User_DATE_FORMAT);
$ew_User_MTIM_FORMAT = ew_UserCalendar('mask', $ew_User_TIME_FORMAT);
$ew_User_PDAT_FORMAT = ew_UserCalendar('placeholder', $ew_User_DATE_FORMAT);
$ew_User_PTIM_FORMAT = ew_UserCalendar('placeholder', $ew_User_TIME_FORMAT);
$ew_User_POINT_FORMAT = ew_UserFormatDateTime('mon_decimal_point', ',');

  1. In addition, make sure the other functions above such as "ew_UserTimeZone" and "ew_UserCalendar" have been already defined in "Global Code" just like "ew_UserFormatDateTime" function above.

  2. If you enable "Include common files" option for your custom file, then the code in step 2 above will work properly.


Re: CurrentUserInfo in Custom file

Posted: Fri Apr 21, 2017 7:51 pm
by btrade

Thanks guys