CURRENT_USER multi-select access to various site pages and navigation based on items selected in multi.

2 posts by 2 authors in: Forums > CMS Builder
Last Post: August 1, 2016   (RSS)

By Mikey - July 27, 2016

Howdy - I need to figure out a solution which displays menu items listed in a navigation - based on the CURRENT_USER's department access permissions. A USER can have access to multiple departments. I have a multi-select called "department_intranet_access" in the "members" section of the CMS which is pulling a list from another section editor called "intranet_access_categories".  The CMS Editor can assign a USER multiple department(s) access using the multi-select called "department_intranet_access". I need some way to compare the (USER) member's "department_intranet_access" permissions against a department's category selected using a field called "intranet_access_categories" within a Category Menu section editor.

In the Category Menu "intranet_access_categories"  section editor many records exist, below are a few:

num = 39     name = Environmental
num = 41      name = Finance
num = 7      name = Fire

In Members a multi-select exist called "department_intranet_access" which members may or may not be assigned to based on their type of permissions. The multi-select in members pulls the list from the Category Menu "intranet_access_categories".

I've tried the following if statement.

<?php if ($CURRENT_USER['department_intranet_access'] =='41'): ?>User has access to Finance<?php endif ?>
<?php if ($CURRENT_USER['department_intranet_access'] =='7'): ?>User has access to Fire Dept.<?php endif ?>

Add a solution below which failed to produce any positive results.

  $searchString = '';
  //Create the where statement to be used to filter department access
  //if department values have been selected....
  if(is_array(@$CURRENT_USER['department_intranet_access:values'])){
    //Count the total number if items in the array.....
    $arrayCounter = count($CURRENT_USER['department_intranet_access:values']);
    //Loop through the array....
    foreach($CURRENT_USER['department_intranet_access:values'] as $key => $filterItem){
      //create the search string that searches the intranet_access_categories for the related value....
  $searchString .= " intranet_access_categories LIKE '%\t$filterItem\t%'";
      //If this is not the last item to filter by, add or to the statement....
      if(($key+1) != $arrayCounter){
        $searchString .= " OR ";
      }
    }  
  }


<?php if ($searchString == '41'): ?> 
<!-- '41' is the intranet_access_categories record num for the category "Finance" -->
<!-- if the CURRENT_USER a department_intranet_access multiselect chosen which includes "Finance" then the CURRENT_USER has access to intranet_access_categories record num '41' and should see this portion of the navigation -->
    <?php foreach ($finance_intranetNavRecords as $categoryRecord): ?> 
<div class="menu">  
    <?php foreach ($finance_intranetNavRecords as $categoryRecord): ?> 
<?php if ($categoryRecord['depth'] == 0): ?> 
<dl class="menu">
    <a href="<?php echo $categoryRecord['_link'] ?>"><?php echo $categoryRecord['name'] ?></a>
  <?php $parent=$categoryRecord['num'];?>
  <dt>
<?php foreach ($finance_intranetNavRecords as $categoryRecord): ?> 
<?php if ($categoryRecord['parentNum'] == $parent): ?>
<dd><a href="<?php echo $categoryRecord['_link'] ?>"><?php echo $categoryRecord['name'] ?></a></dd>
<?php endif ?> 
<?php endforeach; ?>
</dt>
<!-- /menu --></dl>
<?php endif ?>
<?php endforeach; ?>
<!-- /menu --></div>
     <?php break ?>
<?php endforeach; ?>
<!-- /$searchString --><?php endif ?>

<?php if ($searchString == '7'): ?> 
<!-- '7' is the intranet_access_categories record num for the category "Fire" -->
<!-- if the CURRENT_USER a department_intranet_access multiselect chosen which includes "Fire" then the CURRENT_USER has access to intranet_access_categories record num '7' and should see this portion of the navigation -->
    <?php foreach ($fire_intranetNavRecords as $categoryRecord): ?> 
<div class="menu">  
    <?php foreach ($fire_intranetNavRecords as $categoryRecord): ?> 
<?php if ($categoryRecord['depth'] == 0): ?> 
<dl class="menu">
    <a href="<?php echo $categoryRecord['_link'] ?>"><?php echo $categoryRecord['name'] ?></a>
  <?php $parent=$categoryRecord['num'];?>
  <dt>
<?php foreach ($fire_intranetNavRecords as $categoryRecord): ?> 
<?php if ($categoryRecord['parentNum'] == $parent): ?>
<dd><a href="<?php echo $categoryRecord['_link'] ?>"><?php echo $categoryRecord['name'] ?></a></dd>
<?php endif ?> 
<?php endforeach; ?>
</dt>
<!-- /menu --></dl>
<?php endif ?>
<?php endforeach; ?>
<!-- /menu --></div>
     <?php break ?>
<?php endforeach; ?>
<!-- /$searchString --><?php endif ?>

Any assistance figuring this out is much appreciated.

Zick