CodeCharge Studio
search Register Login  

Web Reports

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

YesSoftware Forums -> CodeCharge Studio -> PHP

 Problem with PHP function

Print topic Send  topic

Author Message
MarioM1977

Posts: 23
Posted: 01/10/2011, 8:49 AM

Hello,

I'm really PHP begginer and unfortunately need your help.

I have a grid with field "Site". It shows list of countries. I have also SQL table "budgetowners" with fields: ownerlogin, siteid. Table contains few records:
AAAAA, 101
AAAAA, 102
BBBBB, 103
CCCCC, 104

If user AAAAA will open a page, he should see only site with ID 101 and 102 and all records from table "investments" where "investments.siteid" = "budgetowners.siteid".

What I did:

I created a function called "ApplySiteRestriction" in Common.php file at the end of the file:
function ApplySiteRestriction(& $Sender, $sJoinStr, $sLogin) {  
  if (True == isMasterAdmin()) {  
    return;  
}  
$DB = new clsDBCCEBudget;  
$sJOIN=" INNER JOIN budgetowners ON budgetowners.siteid = ".$sJoinStr." AND budgetowners.ownerlogin= ".$DB->ToSQL(strtoupper($_SERVER["LOGON_USER"]), ccsText);  
$Sender->SQL=str_replace(" {SQL_Where} ",$sJOIN." {SQL_Where} ",$Sender->SQL);  
if (strlen($Sender->CountSQL)) {  
$Sender->CountSQL.=$sJOIN;  
 }  
}

Then I run this function on page investments -> grid -> before build select -> custom code using:
ApplySiteRestriction($Sender, " investments.siteid ", strtoupper($_SERVER["LOGON_USER"]));

Now if I open the page I get an error message:
Notice: Trying to get property of non-object in D:\Web\CCEBudget\Common.php on line 1875  
Notice: Undefined property: stdClass::$CountSQL in D:\Web\CCEBudget\Common.php on line 1876

I used some ASP to PHP converter to convert my ASP code to PHP code regarding definition of "ApplySiteRestriction" function in common.php file. I supose something is wrong here but have no idea what.

Thanks in advance for help.
Brgds
Mariusz
View profile  Send private message
datadoit
Posted: 01/10/2011, 9:27 AM

Mario, no coding needed at all to accomplish what you need. Use the
Visual Query Builder to link your tables accordingly, along with a Where
parameter for the currently logged in user (CCGetUserLogin(), or
UserLogin session variable).

Some more advice:

1. Don't do custom coding in Common.php.

2. Don't do custom coding in Common.php.

3. Reference #1 and #2 above.

:)

If you custom code anywhere, do it in the appropriate page's _events.php
file. Ex: Page -> BeforeShow -> Custom Code.
MarioM1977

Posts: 23
Posted: 01/13/2011, 6:05 AM

Quote datadoit:
Mario, no coding needed at all to accomplish what you need. Use the
Visual Query Builder to link your tables accordingly, along with a Where
parameter for the currently logged in user (CCGetUserLogin(), or
UserLogin session variable).

Some more advice:

1. Don't do custom coding in Common.php.

2. Don't do custom coding in Common.php.

3. Reference #1 and #2 above.

:)

If you custom code anywhere, do it in the appropriate page's _events.php
file. Ex: Page -> BeforeShow -> Custom Code.

Hi,

I solved my problem. It works now.

Brgds
Mariusz
View profile  Send private message

Add new topic Subscribe to topic   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

PHP Reports

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright © 2003-2004 by UltraApps.com  and YesSoftware, Inc.