I have a seperate homepage (As found on these forums, adjusting the Frontpage module) but I now want to restrict access certain pages to only logged in members i.e don’t want pilots public profiels or pireps accessible to ‘outsiders’.
Thanks for that, I just tried that with the roster (pilots_list.tpl), code shown below (just for a test) and it still listed the hubs with the not allowed under each heading, all I really wanted was a message saying not allowed. COuld you add any further pointers?
Cheers,
Graham
<h3><?php echo $title?></h3>
<? if(Auth::LoggedIn()){ ?>
<?php
if(!$allpilots)
{
echo 'There are no pilots!';
return;
}
?>
<table id="tabledlist" class="tablesorter">
<thead>
<tr>
<th>Pilot ID</th>
<th>Name</th>
<th>Rank</th>
<th>Flights</th>
<th>Hours</th>
</tr>
</thead>
<tbody>
<?php
foreach($allpilots as $pilot)
{
/*
To include a custom field, use the following example:
<td>
<?php echo PilotData::GetFieldValue($pilot->pilotid, 'VATSIM ID'); ?>
</td>
For instance, if you added a field called "IVAO Callsign":
echo PilotData::GetFieldValue($pilot->pilotid, 'IVAO Callsign');
*/
// To skip a retired pilot, uncomment the next line:
//if($pilot->retired == 1) { continue; }
?>
<tr>
<td width="1%" nowrap><a href="<?php echo url('/profile/view/'.$pilot->pilotid);?>">
<?php echo PilotData::GetPilotCode($pilot->code, $pilot->pilotid)?></a>
</td>
<td>
<img src="<?php echo Countries::getCountryImage($pilot->location);?>"
alt="<?php echo Countries::getCountryName($pilot->location);?>" />
<?php echo $pilot->firstname.' '.$pilot->lastname?>
</td>
<td><img src="<?php echo $pilot->rankimage?>" alt="<?php echo $pilot->rank;?>" /></td>
<td><?php echo $pilot->totalflights?></td>
<td><?php echo Util::AddTime($pilot->totalhours, $pilot->transferhours); ?></td>
<?php
}
?>
</tbody>
</table>
<? } else { ?>
Not allowed
<? } ?>
Because of the way the list works, you’ll want to just include the title as well. Problem is if you have multiple hubs it will display the error multiple times, so this would be one of the modules where editing the php would look better.
Here’s the code:
<? if(Auth::LoggedIn()){ ?>
<h3><?php echo $title?></h3>
<?php
if(!$allpilots)
{
echo 'There are no pilots!';
return;
}
?>
<table id="tabledlist" class="tablesorter">
<thead>
<tr>
<th>Pilot ID</th>
<th>Name</th>
<th>Rank</th>
<th>Flights</th>
<th>Hours</th>
</tr>
</thead>
<tbody>
<?php
foreach($allpilots as $pilot)
{
/*
To include a custom field, use the following example:
<td>
<?php echo PilotData::GetFieldValue($pilot->pilotid, 'VATSIM ID'); ?>
</td>
For instance, if you added a field called "IVAO Callsign":
echo PilotData::GetFieldValue($pilot->pilotid, 'IVAO Callsign');
*/
// To skip a retired pilot, uncomment the next line:
//if($pilot->retired == 1) { continue; }
?>
<tr>
<td width="1%" nowrap><a href="<?php echo url('/profile/view/'.$pilot->pilotid);?>">
<?php echo PilotData::GetPilotCode($pilot->code, $pilot->pilotid)?></a>
</td>
<td>
<img src="<?php echo Countries::getCountryImage($pilot->location);?>"
alt="<?php echo Countries::getCountryName($pilot->location);?>" />
<?php echo $pilot->firstname.' '.$pilot->lastname?>
</td>
<td><img src="<?php echo $pilot->rankimage?>" alt="<?php echo $pilot->rank;?>" /></td>
<td><?php echo $pilot->totalflights?></td>
<td><?php echo Util::AddTime($pilot->totalhours, $pilot->transferhours); ?></td>
<?php
}
?>
</tbody>
</table>
<? } else { ?>
Not allowed
<? } ?>
I wouldn’t confess to being a php expert but I do have some knowledge, what changes could I make, module wise, to make it a bit ‘cleaner’ in the restricting of access?
For the pilots list, open core/modules/Pilots/Pilots.php
Find:
public function index()
{
// Get all of our hubs, and list pilots by hub
$allhubs = OperationsData::GetAllHubs();
if(!$allhubs) $allhubs = array();
foreach($allhubs as $hub)
{
$this->set('title', $hub->name);
$this->set('icao', $hub->icao);
$this->set('allpilots', PilotData::findPilots(array('p.hub'=>$hub->icao)));
$this->render('pilots_list.tpl');
}
$nohub = PilotData::findPilots(array('p.hub'=>''));
if(!$nohub)
{
return;
}
$this->set('title', 'No Hub');
$this->set('icao', '');
$this->set('allpilots', $nohub);
$this->render('pilots_list.tpl');
}
Replace:
public function index()
{
if(!Auth::LoggedIn()){
$this->set('message', 'Not allowed');
$this->render('core_error.tpl');
return;
}
// Get all of our hubs, and list pilots by hub
$allhubs = OperationsData::GetAllHubs();
if(!$allhubs) $allhubs = array();
foreach($allhubs as $hub)
{
$this->set('title', $hub->name);
$this->set('icao', $hub->icao);
$this->set('allpilots', PilotData::findPilots(array('p.hub'=>$hub->icao)));
$this->render('pilots_list.tpl');
}
$nohub = PilotData::findPilots(array('p.hub'=>''));
if(!$nohub)
{
return;
}
$this->set('title', 'No Hub');
$this->set('icao', '');
$this->set('allpilots', $nohub);
$this->render('pilots_list.tpl');
}
Yep it’ll work in any of the module php files. Just make sure you’re putting it in the index (unless it’s somewhere else you want it) - and you’ll probably want to put it before any other actions.