<?php
if (empty($_GET['id'])) {
   header("Location: " . $wo['config']['site_url']);
   exit();
}
$page = Wo_GetCustomPage($_GET['id']);
if (empty($page)) {
   header("Location: " . $wo['config']['site_url']);
   exit();
}
?>
<div class="container-fluid">
    <div class="block-header">
        <h2>Pages > Edit Custom Page</h2>
    </div>
    <!-- Vertical Layout -->
    <div class="row">
        <div class="col-lg-8 col-md-8">
            <div class="card">
                <div class="header">
                    <h2>Edit Custom Page: <?php echo $page['page_title'] ?></h2>
                </div>
                <div class="body">
                    <div class="alert alert-success add-settings-alert"></div>
                    <form class="add-settings" method="POST">
                        <div class="form-group form-float">
                            <div class="form-line">
                                <input type="text" id="page_name" name="page_name" class="form-control" value="<?php echo $page['page_name'];?>">
                                <label class="form-label">Page Name <small><?php echo $wo['config']['site_url'] . '/page/PAGE_NAME'?></small></label>
                            </div>
                        </div>
                        <div class="form-group form-float">
                            <div class="form-line">
                                <input type="text" id="page_title" name="page_title" class="form-control" value="<?php echo $page['page_title'];?>">
                                <label class="form-label">Page Name <small>The page title that will show in the footer</small></label>
                            </div>
                        </div>
                         <div class="form-group form-float">
                            <div class="form-line">
                                <textarea name="page_content" id="page_content" class="form-control" cols="30" rows="5"><?php echo br2nl($page['page_content']);?></textarea>
                                <label class="form-label">Page Content <small>The page content (HTML allowed)</small></label>
                            </div>
                        </div>
                        <label for="page_type">Page Type</label>
                        <select class="form-control show-tick " id="page_type" name="page_type">
                            <option value="1" <?php echo ($page['page_type'] == 1) ? 'selected': '';?>>Include background and header</option>
                 			<option value="0" <?php echo ($page['page_type'] == 0) ? 'selected': '';?>>Empty page</option>
                        </select>
                        <div class="clearfix"></div>
                        <br>
                        <input type="hidden" value="<?php echo $page['id'];?>" name="page_id">
                        <input type="hidden" name="hash_id" value="<?php echo Wo_CreateSession();?>">
                        <button type="submit" class="btn btn-primary m-t-15 waves-effect">Save</button>
                    </form>
                </div>
            </div>
        </div>
        <div class="clearfix"></div>
    </div>
    <!-- #END# Vertical Layout -->
<script>

$(function() {
    var form_add_settings = $('form.add-settings');
    form_add_settings.ajaxForm({
        url: Wo_Ajax_Requests_File() + '?f=admin_setting&s=edit_page',
        beforeSend: function() {
            form_add_settings.find('.waves-effect').text('Please wait..');
        },
        success: function(data) {
            if (data.status == 200) {
                $("html, body").animate({ scrollTop: 0 }, "slow");
                $('.add-settings-alert').html('<i class="fa fa-check"></i> Page updated successfully');
                setTimeout(function () {
		            window.location.href = '<?php echo Wo_LoadAdminLinkSettings('manage-custom-pages'); ?>';
		        }, 1000);
            } else if (data.status == 400) {
	          alert(data.message);
	        }
	        form_add_settings.find('.waves-effect').text('Save');
        }
    });
});
</script>