Custom PHP Page Permissions

kiksekage

New member
Hi.

I'm having two problems with a custom PHP page.

1. It is not appearing in the right order in the menu. I'll try to figure out if I missed something.

2. The main subject of this topic: How can I limit access to this page? I only want the page visible to certain users in the menu. Also, the page should validate access, just in case.

Thanks!


DaDaBIK version 8.0-Lerici enterprise
PHP Version: 5.6.29
mysql version: 5.6.34-log
Web server: Apache
Client: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36 Edge/15.15063
 

kiksekage

New member
Re: #1, I had it (accidentally) set as "Home", which caused it to appear on top, even if it was set to be nested under a heading.
 

eugenio

Administrator
Staff member
Hello kiksekage,
at the moment you can set granular permissions on pages based on tables and views but you cannot do it on custom pages. We'll introduce this feature in DaDaBIK 9.

Best,
 

johan

Member
Hi Eugenio,

When is the ata of DaDaBik9 ?

I was also searching for this option.
I hope soon.

regards Johan
 

eugenio

Administrator
Staff member
Hello Johan,
we can't tell a date yet; consider that DaDaBIK 8 Lerici is pretty recent (april 24th) and that normally we don't release more than one major release per year.

Best,
 

kiksekage

New member
I'd really appreciate this functionality. If you have time to add it, that would be best. Otherwise, I may consider poking around and seeing if I can get something working.
 

SHANE

New member
I have achieved this control by below tweaks:

1. Control using new table - includes group field for extra control - table format same as static page table.

SQL >>
CREATE TABLE `z_static_pages_perm` (
`Static_Page_Perm_Key` int(16) NOT NULL,
`id_static_page` int(11) NOT NULL DEFAULT '0',
`id_group` int(16) NOT NULL,
`link_static_page` varchar(255) DEFAULT NULL,
`type_static_page` varchar(10) DEFAULT '',
`file_static_page` varchar(50) DEFAULT '',
`content_static_page` text,
`is_homepage_static_page` char(1) DEFAULT NULL,
`Createts` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
`Modifyts` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

>> Manage this table by assigning static page to group ids


2. Modify -> index.php

>> Add this line

$_cp_static_pages_perm_ar = _cp_build_static_pages_perm_ar();

3. Modify -> Header.php

>> Modify the below contents
/*Modified for Custom Pages 20160907 starts*/
$_cp_static_pages_perm_page_ar = array();
$_cp_static_pages_perm_page_ar = array_column($_cp_static_pages_perm_ar,'id_static_page');
/*echo '<pre>'; var_dump($_cp_static_pages_perm_page_ar); echo '</pre>';*/

foreach ($static_pages_ar as $static_page){

if ($static_page['is_homepage_static_page'] == 'n' && (in_array($static_page['id_static_page'],$_cp_static_pages_perm_page_ar))){

if ($function === 'show_static_page' && isset($id_static_page) && (int)$id_static_page === (int)$static_page['id_static_page']){
$class_temp = 'static_pages_menu_active';
}
else{
$class_temp = 'static_pages_menu';
}
/*original 20160907 starts*/
/*


foreach ($static_pages_ar as $static_page){
if ($static_page['is_homepage_static_page'] == 'n'){


if ($function === 'show_static_page' && isset($id_static_page) && (int)$id_static_page === (int)$static_page['id_static_page']){
$class_temp = 'static_pages_menu_active';
}
else{
$class_temp = 'static_pages_menu';
}
*/
/*original 20160907 ends */
/*Modified for Custom Pages 20160907 Ends*/

4. Modify-> include/business_logic.php

>>Add below at the end.

/* custom arrays start*/

/*z_static_pages_perm*/
function _cp_build_static_pages_perm_ar()
{
global $conn, $quote, $prefix_internal_table;

$_cp_static_pages_perm_ar = array();
$cnt = 0;

$sql = "select static_page_perm_key, id_static_page, id_group, link_static_page, content_static_page, is_homepage_static_page FROM ".$quote.'z_static_pages_perm'.$quote. " where id_group = '".$_SESSION['logged_user_infos_ar']["id_group"]."'" ;
/* echo '<pre>'; var_dump($sql); echo '</pre>';*/
$res = execute_db($sql, $conn);

while($row = fetch_row_db($res)){
$_cp_static_pages_perm_ar[$cnt]['static_page_perm_key'] = $row['static_page_perm_key'];
$_cp_static_pages_perm_ar[$cnt]['id_static_page'] = $row['id_static_page'];
$_cp_static_pages_perm_ar[$cnt]['id_group'] = $row['id_group'];
$_cp_static_pages_perm_ar[$cnt]['link_static_page'] = $row['link_static_page'];
$_cp_static_pages_perm_ar[$cnt]['content_static_page'] = $row['content_static_page'];
$_cp_static_pages_perm_ar[$cnt]['is_homepage_static_page'] = $row['is_homepage_static_page'];
$cnt++;
}
return $_cp_static_pages_perm_ar;


}

/*custom arrays end*/


##########
Using above you can control the access to different groups for different static pages - and can also manage at admin level - like Users and Groups table.
##########

Regards,
Shainil (Shane)
 
Top