<?php 
$db = new SQLite3('./api/user_message.db');
$res = $db->query("SELECT * 
				  FROM messages 
				  WHERE id='".$_GET['update']."'");
$row=$res->fetchArray();
if(isset($_POST['submit'])){

$db->exec("UPDATE messages SET message='".$_POST['message']."',
							  status='".$_POST['status']."',
							  expire='".$_POST['expire']."'
						  WHERE 
							  userid='".$_POST['userid']."'");
header("Location: send_message.php");
}
include ('includes/header.php');
?>


<div class="content-wrapper">
    <div class="container-fluid">
        <div class="card mb-3">
            <div class="card-header">
                <i class="fa fa-comment"></i> Mensagem</div>
            <div class="card-body">
                <div class="alert alert-light" role="alert">
                    <div class="row">
                        <div class="col-12">
                            <h3>Editar mensagem</h3>
                        </div>
                        <div class="col-md-8">
                            <form method="post">
								                                <div class="form-group ">
                                    <label class="control-label " for="userid">
                                        Usuario *
                                    </label>
                                    <div class="input-group">
                                        <input class="form-control" id="description" name="userid"  value="<?=$row['userid'] ?>" type="text" readonly/>
                                    </div>

                                </div>
                                <div class="form-group ">
                                    <label class="control-label " for="message">
                                        Mensagem *
                                    </label>
                                    <div class="input-group">
                                        <input class="form-control" id="message" name="message" value="<?=$row['message'] ?>" type="text"/>
                                    </div>

                                </div>
                                <div class="form-group ">
                                    <label class="control-label requiredField" for="status" >
                                        Status *
                                    </label>
                                    <select class="select form-control" id="select" name="status">
									    <option value="INACTIVE"<?=$row['status']=='INACTIVE'?'selected':'' ?>>INATIVO</option>
                                        <option value="ACTIVE" <?=$row['status']=='ACTIVE'?'selected':'' ?>>ATIVO</option>
                                    </select>
                                </div>
                                <div class="form-group ">
                                    <label class="control-label " for="expire">
                                        Expiração (2018-06-17 23:30:10): *
                                    </label>
                                    <div class="input-group">
                                        <input type="text" class="form-control" name="expire" id="date" data-select="datepicker" value="<?=$row['expire'] ?>"> 
                                    </div>

                                </div>
                                <div class="form-group">
                                    <div>
                                        <button class="btn btn-info " name="submit" type="submit">
                                            <i class="fa fa-check"></i> Aceitar
                                        </button>
                                    </div>

                                </div>
                            </form>
                        </div>
                    </div>
                </div>
            </div>

        </div>
    </div>
    <br><br><br>
<?php include ('includes/footer.php');?>
</body>

</html>