<?php
$section = $db->where('id',Wo_Secure($_GET['id']))->getOne(T_FORUM_SEC);
if (empty($section)) {
   header("Location: " . $wo['config']['site_url']);
   exit();
}
?>
<div class="container-fluid">
    <div>
        <h3>Edit Section</h3>
        <nav aria-label="breadcrumb">
            <ol class="breadcrumb">
                <li class="breadcrumb-item">
                    <a href="#">Home</a>
                </li>
                <li class="breadcrumb-item">
                    <a href="#">Manage Features</a>
                </li>
                <li class="breadcrumb-item">
                    <a href="#">Forums</a>
                </li>
                <li class="breadcrumb-item active" aria-current="page">Edit Section</li>
            </ol>
        </nav>
    </div>
    <!-- Vertical Layout -->
    <div class="row">
        <div class="col-lg-6 col-md-6">
            <div class="card">
                <div class="card-body">
                    <h6 class="card-title">Edit Section</h6>
                    <div class="newsection-alert"></div>
                    <div class="newsection-error-alert"></div>
                    <form class="newsection" method="POST">
                        <div class="form-group form-float">
                            <div class="form-line">
                                <label class="form-label">Name</label>
                                <input type="text" id="name" name="name" class="form-control" value="<?php echo($section->section_name); ?>">
                            </div>
                        </div>
                        <div class="form-group form-float">
                            <div class="form-line">
                                <label class="form-label">Description</label>
                                <textarea name="description" id="description" class="form-control" cols="30" rows="3"><?php echo($section->description); ?></textarea>
                            </div>
                        </div>
                        <input type="hidden" name="hash_id" value="<?php echo Wo_CreateSession();?>">
                        <input type="hidden" name="id" value="<?php echo($section->id); ?>">
                        <button type="submit" class="btn btn-primary m-t-15 waves-effect">Edit Section</button>
                    </form>
                </div>
            </div>
        </div>
        <div class="clearfix"></div>
    </div>
    <!-- #END# Vertical Layout -->
<script>

$(function() {
    var form_new_section = $('form.newsection');
    form_new_section.ajaxForm({
        url: Wo_Ajax_Requests_File()+"?f=admin_setting&s=edit-forum-section&hash=" + $('.main_session').val(),
        beforeSend: function() {
            form_new_section.find('button').text('Please wait..');
        },
        success: function(data) {
            if (data.status == 200) {
                $("html, body").animate({ scrollTop: 0 }, "slow");
                $('.newsection-alert').html('<div class="alert alert-success"><i class="fa fa-check"></i> New section created successfully.</div>');
                setTimeout(function () {
                    $('.newsection-alert').empty();
                }, 2000);
            } else {
                $('.newsection-alert').html('<div class="alert alert-danger">'+data['message']+'</div>');
                setTimeout(function () {
                    $('.newsection-alert').empty();
                }, 2000);
            } 
            form_new_section.find('button').text('Create Section');
        }
    });
});
</script>