<?php
include 'header.php';
$page_nm = "setting";
$pageUrl = "setting.php";
if ($_GET['mode'] != '') {
    $id = (int) $_REQUEST['id'];
    if (isset($_POST['btn_submit'])) {
		
$description = $_POST['description'];	
        if ($_POST['id'] != '' && $_POST['mode'] == 'edit') {
            $editqry = "UPDATE ".DB_PREFIX."setting SET 
				   description='".$description."' WHERE id=".$id;
				   
            $ai_db->aiQuery($editqry);
			
			$ai_core->aiGoPage($pageUrl . "?msg=2");
        }
    }
	if ($id != '') 
	{
        $qry = "SELECT * FROM ".DB_PREFIX."setting WHERE id=" . $id;
        $row = $ai_db->aiGetQueryObj($qry);
	}
} 
else
{
    $qry = "SELECT * FROM ".DB_PREFIX."setting";
    $result = $ai_db->aiGetQueryObj($qry);
}
?>
<div class="main-panel">
    <div class="main-content">
        <div class="content-wrapper"><!-- Basic form layout section start -->
            <section id="horizontal-form-layouts">
                <div class="row">
                    <div class="col-sm-12">
                        <div class="content-header">Manage <?php echo $page_nm; ?></div>
                    </div>
                </div>
                <?php if ($_REQUEST['mode'] != '') { ?>
                    <div class="row">
                        <div class="col-md-12">
                            <div class="card">
                                <div class="card-body">
                                    <div class="px-3">

                                        <form name="frm" id="frm" class="form form-horizontal" method="POST" action="" enctype="multipart/form-data" onsubmit="return chkFrm();">
                                            <input type="hidden" name="mode" id="mode" value="<?php echo $_REQUEST['mode']; ?>" />
                                            <input type="hidden" name="id" id="id" value="<?php echo $_REQUEST['id']; ?>" />                                            <div class="form-body">
                                                <h4 class="form-section"><i class="ft-life-buoy"></i> Setting Info</h4>
                                                
												<div class="form-group row">
												<label class="col-md-3 label-control" for="projectinput6"><?php echo $row[0]->name; ?>: </label>
												<div class="col-md-9">
												<textarea class="form-control" name="description" id="description"><?php echo $row[0]->description; ?></textarea>
												</div>
												</div>
												
												
												
												
												
												
											
						
						
						
						</div>
                                            <div class="form-actions">
                                                <button type="submit" name="btn_submit" id="btn_submit" class="btn btn-raised btn-primary"><i class="fa fa-check-square-o"></i>Submit</button>
												<a href="<?php echo ADMIN_URL . "" . $pageUrl; ?>"> <button type="button" class="btn btn-raised btn-warning mr-1">
                                                        <i class="ft-x"></i> Cancel
                                                    </button></a>
                                            </div>
                                        </form>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                <?php } else { ?>

                    
                    <div class="col-lg-12 card">
                        <?php if ($_GET['msg'] != '') { ?>
                            <div class="alert   <?php if ($_GET['msg'] == '1' || $_GET['msg'] == '2' || $_GET['msg'] == '4') { ?> alert-success <?php } else { ?> alert-danger <?php } ?> alert-dismissible mb-2" role="alert" style="margin-top: 15px;">
                                <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                                    <span aria-hidden="true">&times;</span>
                                </button>
                                <strong>
                                    <?php
                                    if ($_GET['msg'] == '1') {
                                        echo INSERT_MSG;
                                    } else if ($_GET['msg'] == "2") {
                                        echo UPDATE_MSG;
                                    } else if ($_GET['msg'] == '3') {
                                        echo DELETE_MSG;
                                    } else if ($_GET['msg'] == '4') {
										echo ACTIVE_MSG;
									} else if ($_GET['msg'] == '5') {
										echo DEACTIVE_MSG;
									}
									
                                    ?>
                                </strong>
                            </div>
                        <?php } ?>

                        <div class="card-body collapse show">

                            <div class="card-block card-dashboard">

                                <table class="table table-striped table-bordered multi-ordering">
                                    <thead>
                                        <tr>
											<th>Title</th>
											<th>Description</th>
											<th>Action</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        <?php
                                        if (COUNT($result) > 0) {
                                            foreach ($result as $row) {
                                                ?>
                                                <tr>
													<td><?php echo $row->name;?></td>
													<td><?php echo $row->description;?></td>
													<td>
                                                        <a href="<?php echo $pageUrl . "?mode=edit&id=".$row->id.""; ?>"><img src="assets/img/ico/edit.png" alt="Edit Icon" data-toggle="tooltip" data-placement="right" title="edit this row"/></a>
                                                    </td>
													
                                                </tr>
                                                <?php
                                            }
                                        }
                                        ?>

                                    </tbody>
                                </table>
                            </div>
                        </div>
                    </div>
                <?php } ?>

            </section>
            <!-- // Basic form layout section end -->
        </div>
    </div>
	
	
	
											
											
<?php include ('footer.php'); ?>
<script type="text/javascript">
function chkFrm()
{
	if(document.getElementById("description").value == "")
	{
		document.getElementById("description").focus();
		alert("Please enter description.");
		return false;
	}
return true;
}
</script>