function has_auth($auth, $userclass = null) { if ($userclass === null) { $userclass = userclass(); } return $userclass == $auth or $userclass == 'user' and in_array($auth, array('guest')) or $userclass == 'admin' and in_array($auth, array('guest', 'user')); // un admin es también un guest y un user }
} } return $data; } function set_fields($entity_class, $data = array()) { return set_data($entity_class, $data, 'fields'); } function set_pk($entity_class, $data = array()) { return set_data($entity_class, $data, 'pk'); } if (array_key_exists('action', $_POST)) { $an = $_POST['action']; if (array_key_exists($an, $actions)) { $a = $actions[$an]; $auth = $a['authorization']; if (has_auth($auth)) { call_user_func($a['action']); } else { error_log('Fantasy: intento de llamar función del controlador ' . $an . ' por usuario no autorizado de clase ' . userclass()); } } else { error_log('Fantasy: intento de llamar la función inexistente del controlador "' . $an . '" por usuario de clase ' . userclass()); } } if (array_key_exists('goto', $_POST)) { header('Location: ' . $_POST['goto']); } else { header('Location: index'); }