<?php
if (empty($_GET['id'])) {
   header("Location: " . $wo['config']['site_url']);
   exit();
}
$forum = $db->where('id',Wo_Secure($_GET['id']))->getOne(T_FORUMS);
if (empty($forum)) {
   header("Location: " . $wo['config']['site_url']);
   exit();
}
?>
<div class="container-fluid">
    <div>
        <h3>Edit Forum</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 Forum</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 Forum</h6>
                    <div class="newforum-alert"></div>
                    <div class="newforum-error-alert"></div>
                    <form class="newforum" 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($forum->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($forum->description) ?></textarea>
                            </div>
                        </div>
                        <label for="section">Section</label>
                        <select class="form-control show-tick" id="section" name="section">
                          <?php foreach (Wo_GetForumSec(array('forums'=>false,'limit'=>500)) as $section): ?>
							<option value="<?php echo $section['id']; ?>" <?php echo $section['id'] == $forum->sections ? 'selected' : '' ?>>
								<?php echo $section['section_name_lang']; ?>
							</option>
						<?php endforeach ?>
                        </select>
                        <div class="clearfix"></div>
                        <br><br>
                        <input type="hidden" name="hash_id" value="<?php echo Wo_CreateSession();?>">
                        <input type="hidden" name="id" value="<?php echo($forum->id) ?>">
                        <button type="submit" class="btn btn-primary m-t-15 waves-effect">Edit Forum</button>
                    </form>
                </div>
            </div>
        </div>
        <div class="clearfix"></div>
    </div>
    <!-- #END# Vertical Layout -->
<script>

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