Forums / Developer / Change siteaccees temporarily

Change siteaccees temporarily

Author Message

Davide Garzetti

Tuesday 03 November 2009 9:02:02 am

Hello I need help to complete an important program part of a new extension I will delivery as GPL for all ezPublish users probably this month.It's the last thing left open.

Inside a module program I need to change a site access then do some work and then restore the previuos site access. I have relized this piece of code that works:

//begin code snippet

$old_access = $GLOBALS['eZCurrentAccess'];

$new_access = array( 'name' => 'newaccess', 'type' => EZ_ACCESS_TYPE_DEFAULT );

require_once( "access.php" );
$access = changeAccess( $new_access);

//do some php work

$restored_access = changeAccess($old_access);

.....

//end code snippet

The problem arise when in my "do some php work" I fetch a template so this doesn't work:

//begin code snippet

$old_access = $GLOBALS['eZCurrentAccess'];

$new_access = array( 'name' => 'newaccess', 'type' => EZ_ACCESS_TYPE_DEFAULT );

require_once( "access.php" );
$access = changeAccess( $new_access);

$templ_tpl = templateInit();
$templ_tpl->setVariable( "module", $module );

$result['text']=$templ_tpl->fetch( "design:/mytpl.tpl");

$restored_access = changeAccess($old_access);

....

//end code snippet

The fetch function works but the program doesn't restore to the previuos siteaccess.

Before post this I've already searched inside EzPublish code but without success.

Thanks for your help.