<?
	$this->title = 'Restaurants';
	$this->titleicon = 'food';

	$hasPermissionToAllRestaurants = c::admin()->permission()->check( [ 'global', 'restaurants-all', 'restaurants-crud' ] );

?>

<!-- restaurants page -->
<div class="container-fluid padded">
	<div class="row-fluid">
		<div class="box">
			<div class="box-header"><span class="title">Select a Restaurant</span></div>
			<div class="box-content padded">
	
				<select id="restaurant-id" class="chosen-select" style="width:480px;">
					<option value="" selected>Choose...</option>
					<?php  
					$restaurants = Restaurant::q('select * from restaurant order by name');
					if( $hasPermissionToAllRestaurants ){
						foreach ( $restaurants as $restaurant ) {
							?><option value="<?=$restaurant->id_restaurant?>"><?=$restaurant->name?> | <?=$restaurant->communityNames()?> | <?=$restaurant->permalink?> </option><?php 
						}
					} else {
						foreach ( $restaurants as $restaurant ) {
							if( c::admin()->permission()->check( [ "restaurant-{$restaurant->id_restaurant}-edit", "restaurant-{$restaurant->id_restaurant}-all" ] ) ){
								?><option value="<?=$restaurant->id_restaurant?>"><?=$restaurant->name?> | <?=$restaurant->communityNames()?> | <?=$restaurant->permalink?> </option><?php 
							}
						}
					}
					?>
				</select>
				<div class="divider"></div>
				<br><br>
				<?php if (c::admin()->permission()->check(['global', 'restaurants-all', 'restaurants-crud', 'restaurants-create'])) { ?>
				<button type="submit" class="btn btn-blue new-restaurant">Create New</button> &nbsp;&nbsp;
				<?php } ?>
				<a href="/restaurants/hours_override/" class="btn btn-green">
					<i class="icon-calendar"></i>&nbsp;Hours override list
				</a>
			</div>
		</div>
	</div>
</div>
<!-- // end restaurants page -->

<script type="text/javascript" src="/assets/js/admin_restaurants.js"></script>
