}
if (isset($_SESSION["user_id"])) {
    $is_logged = true;
}
if ($is_logged && $_SESSION["user_id"] == $file->user_id) {
    $is_owner = true;
}
if ($is_public) {
    $go = true;
}
if (!$is_logged) {
    Core::alert("Acceso Denegado!");
    Core::redir("./");
} else {
    if ($go == false && !$is_owner) {
        $ps = PermisionData::getAllbyFileId($file->id);
        $found = false;
        foreach ($ps as $p) {
            if ($p->user_id == $_SESSION["user_id"]) {
                $found = true;
            }
        }
        if ($found == true) {
            $go = true;
        } else {
            Core::alert("Acceso Denegado!");
            Core::redir("./?view=shared");
        }
    }
}
?>
<?php

if (!empty($_GET)) {
    $fp = PermisionData::getById($_GET["id"]);
    //	print_r($fp);
    $file = FileData::getById($fp->file_id);
    $fp->del();
    Core::redir("./?view=filepermisions&id=" . $file->code);
}

</div>
</div>

<div class="row">
<!--<div class="col-md-3">
<div class="list-group">
<a class="list-group-item">Archivos</a>
</div>
</div>
-->
<div class="col-md-12">

<?php 
$files = PermisionData::getAllByUserId($_SESSION["user_id"]);
?>

<?php 
if (count($files) > 0) {
    ?>
<table class="table table-bordered">
<thead>
	<th></th>
	<th>Archivo</th>
	<th>Descripcion</th>
	<th>Fecha</th>
</thead>
<?php 
    foreach ($files as $fx) {
        $file = $fx->getFile();
  <select name="p_id" class="form-control">
    <option value="1"> Ver, Dercargar y Comentar</option>
  </select>
  </div>

  <div class="col-md-2">
  <button type="submit" class="btn btn-primary">Agregar</button>
  </div>
  </div>
</form>



<div class="clearfix"></div><br>
<?php 
$permisions = PermisionData::getAllByFileId($file->id);
//echo count($permisions);
?>

<?php 
if (count($permisions) > 0) {
    ?>
  <table class="table table-bordered table-hover">
  <thead>
    <th>Usuario</th>
    <th>Permiso</th>
    <th>Fecha</th>
    <th></th>
    </thead>
  </thead>
    <?php 
<?php

if (!empty($_POST)) {
    $user = UserData::getByNick($_POST["email"]);
    $file = FileData::getById($_POST["file_id"]);
    if ($user != null) {
        if ($user->id != $_SESSION["user_id"]) {
            $p = new PermisionData();
            $p->user_id = $user->id;
            $p->file_id = $file->id;
            $p->p_id = $_POST["p_id"];
            $p->add();
            Core::alert("Agregado exitosamente!");
        } else {
            Core::alert("No puedes agregarte ati mismo!");
        }
    } else {
        Core::alert("El usuario no existe!");
    }
    Core::redir("./?view=filepermisions&id=" . $file->code);
}