<?php
$included_pages = array( 197, 199, 201 );
$pages = get_pages( array( 'post_status' => 'publish,draft', 'sort_column' => 'menu_order', 'include' => $included_pages ) );
if ( !empty($_POST['forms-client-area'] ) ) {
	if ( $_SERVER["REQUEST_METHOD"] == "POST" ) {
		foreach( $pages as $page ) {
			if( array_key_exists( $page->ID, $_POST ) && ( isset( $_POST[$page->ID] ) || $_POST[$page->ID] == 'checked' ) ) {
				wp_update_post( array('ID' => $page->ID, 'post_status' => 'publish' ) );
			} else {
				wp_update_post( array('ID' => $page->ID, 'post_status' => 'draft' ) );
			}
		}
		unset($_POST);
		echo '<div class="notice notice-success is-dismissible custom-notice"><p><strong>Successfully updated.</strong></p><p>To add pages into the main navigation, please go to the <a href="'.site_url( 'wp-admin/nav-menus.php' ).'">Manage menus</a> page.</p></div>';
	}
}
?>
<form id="form-forms" method="post" action="<?php echo get_permalink(); ?>#client-area">
	<?php
	$pages = get_pages( array( 'post_status' => 'publish,draft', 'sort_column' => 'menu_order', 'include' => $included_pages ) );
	foreach( $pages as $page ) {
		if( $page->post_status == 'publish' ) {
			$checked = 'checked';
		} else {
			$checked = NULL;
		}
		echo '<p class="services-item"><input type="checkbox" id="check-'.$page->ID.'" name="'.$page->ID.'" value="'.$checked.'" '.$checked.'/><label for="check-'.$page->ID.'">'.$page->post_title.'</label></p>';
	}
	?>
	<div class="update-wrap">
		<p class="alert"><strong>Changing the options above will take time to update, please be patient.</strong></p>
		<p>Please note: When turning a page on, you will need to manually add it to the site navigation via the <a href="<?php echo site_url( 'wp-admin/nav-menus.php' ); ?>">Manage menus</a> page.</p>
		<p><input type="checkbox" id="confirm-update-client-area" required/><label for="confirm-update-client-area">Are you sure you want to update the pages selected?</label></p>
		<p><input type="submit" name="forms-client-area" value="Update Client Area" class="button button-primary"/></p>
	</div>
	<i class="clearfix"></i>
</form>