<?php 

function edit_pages_cb() {
	global $post_meta;
	global $theme;
	$theme->set_templates();
	add_page_javascript('app/assets/js/page-scripts/submit.js');
	add_page_javascript('app/assets/js/page-scripts/js-functions.js');
	$post = new post;
	$pages = $post->get_post_by_meta_data(['type' => 'page']);
	$capabilities = get_system_capabilities($roles);
	$selectOption = array();
	if(_count($capabilities)) {
		foreach ($capabilities as $key => $value) {
			$selectOption[str_replace('_', ' ', $value)] = $value;
		}
	}
	$templatesOption = array();
	if(_count($theme->templates)) {
		foreach ($theme->templates as $key => $value) {
			$templatesOption[str_replace('_', ' ', $value)] = $value;
		}
	}
	?>
	<div class="row">
		<div class="col-lg-12">
			<div class="panel pl-4 pr-4">
				<!-- <div class="panel-header">
					<h1 class="panel-title mt-4">All Pages</h1>
				</div> -->
				<div class="panel-body">
					<div class="row">
						<div class="col-md-2 col-sm-12 col-xs-12 mr-0 ml-0 pr-0 pl-0">Page Title</div>
						<div class="col-md-2 col-sm-12 col-xs-12 mr-0 ml-0 pr-0 pl-0">Permalink</div>
						<div class="col-md-2 col-sm-12 col-xs-12 mr-0 ml-0 pr-0 pl-0">Availability</div>
						<div class="col-md-2 col-sm-12 col-xs-12 mr-0 ml-0 pr-0 pl-0">Access</div>
						<div class="col-md-2 col-sm-12 col-xs-12 mr-0 ml-0 pr-0 pl-0">Template</div>
						<div class="col-md-2 col-sm-12 col-xs-12 mr-0 ml-0 pr-0 pl-0">Action</div>
					</div>
						<?php $i = 1; if(_count($pages)): foreach ($pages as $page_meta): 
							$availability = isset($page_meta['availability']) ? $page_meta['availability'] : 'protected';
						?>
						<form id="edit-page-<?php echo $page_meta['id'] ?>" method="post" action="app/includes/ajax.php">
						<div class="row mb-2">
							
								
									<!-- <div class="col-md-2 col-sm-4 col-xs-4 mr-0 ml-0 pr-0 pl-0" style="width: 40px;"><?php echo $i; ?></div> -->
									<div class="col-md-2 col-lg-2 col-sm-4 col-xs-6 mr-0 ml-0 pr-0 pl-0"><input type="text" name="title" id="title-<?php echo $page_meta['id'] ?>" class="form-control" value="<?php echo $page_meta['title'] ?>"></div>
									<div class="col-md-2 col-lg-2 col-sm-4 col-xs-6 mr-0 ml-0 pr-0 pl-0"><input type="text" name="permalink" id="permalink-<?php echo $page_meta['id'] ?>" class="form-control" value="<?php echo $page_meta['permalink'] ?>"></div>
									<div class="col-md-2 col-lg-2 col-sm-4 col-xs-6 mr-0 ml-0 pr-0 pl-0">
										<select name="availability" id="availability-<?php echo $page_meta['id'] ?>" class="standardSelect">
											<option value="protected" <?php echo $availability == 'protected' ? 'selected' : ''; ?>>Protected</option>
											<option value="public" <?php echo $availability == 'public' ? 'selected' : ''; ?>>Public</option>
										</select>
									</div>
									<div class="col-md-2 col-lg-2 col-sm-4 col-xs-6 mr-0 ml-0 pr-0 pl-0">
										<select name="access" id="access-<?php echo $page_meta['id'] ?>" class="standardSelect">
											<?php if (_count($selectOption)): foreach($selectOption as $k => $v): ?>
												<option <?php echo ($page_meta['access'] == $v) ? "selected" : ""; ?> value="<?php echo $v; ?>"><?php echo $k; ?></option>
											<?php endforeach; endif; ?>
										</select>
									</div>
									<div class="col-md-2 col-lg-2 col-sm-4 col-xs-6 mr-0 ml-0 pr-0 pl-0">
										<select name="template" id="template-<?php echo $page_meta['id'] ?>" class="standardSelect">
											<option value="default">Default</option>
											<?php if (_count($templatesOption)): foreach($templatesOption as $k => $v): ?>
												<option <?php echo ($page_meta['template'] == $v) ? "selected" : ""; ?> value="<?php echo $v; ?>"><?php echo $k; ?></option>
											<?php endforeach; endif; ?>
										</select>
									</div>
									<div class="col-md-2 col-lg-2 col-sm-4 col-xs-6 mr-0 ml-0 pr-0 pl-0">
										<input type="hidden" name="id" id="id-<?php echo $page_meta['id'] ?>" class="form-control" value="<?php echo $page_meta['id'] ?>">
										<input type="hidden" name="action" value="edit_admin_page">
										<button type="submit" name="submit" class="submit btn btn-primary">Save</button>
									</div>
								
							
							</div>
							</form>
							<hr>
						<?php $i++; endforeach; endif; ?>
				</div>
			</div>
		</div>
	</div>
	<?php
}