Ejemplo n.º 1
0
function link_to($path, $caption, $options = array())
{
    set_if_not_set($options["goto"], false);
    if (!in_array(substr($path, 0, 7), array("mailto:", "http://", "https:/")) && substr($path, 0, 1) != "#") {
        $path = "/" . $path;
    }
    if (isset($GLOBALS["full_path_links"]) && $GLOBALS["full_path_links"]) {
        $path = full_path($path);
    }
    if ($options["goto"]) {
        $parameters = array_intersect_key($options, array_flip(array("class", "id", "title")));
        return insert_properties_in_html_tag(str_replace("\n", "", $caption), array_merge($parameters, array("onclick" => "goto('" . $path . "')", "style" => "cursor:pointer")));
    } else {
        if (!is_empty($options['modal'])) {
            set_if_not_set($options['modal']['title'], "");
            // The message should be set if the 'modal' options is used, but we provide a default one
            set_if_not_set($options['modal']['message'], " Es-tu sûr de vouloir faire cela ?");
            // A modal toggle should at least be a button and not only a text in a div
            set_if_not_set($options['modal']['class'], "btn");
            $modal_id = is_empty($options['modal']["id"]) ? $options["id"] . "_modal_auto_id" : $options['modal']["id"];
            $button_in_modal = link_to($path, "<div> Confirmer </div>", array("class" => "btn"));
            $content = $options['modal']['message'] . "<div class=\"button-container\">" . $button_in_modal . "</div>";
            $modal = modal($modal_id, array("title" => $options['modal']["title"]), $content);
            return modal_toggle($options["id"], $caption, $options["class"], $modal_id) . "\n" . $modal;
        } else {
            $parameters = is_empty($options["class"]) ? "" : " class=\"" . $options["class"] . "\"";
            $parameters .= is_empty($options["id"]) ? "" : " id=\"" . $options["id"] . "\"";
            $parameters .= is_empty($options["title"]) ? "" : " title=\"" . $options["title"] . "\"";
            return "<a href=\"" . $path . "\"" . $parameters . ">" . $caption . "</a>";
        }
    }
}
Ejemplo n.º 2
0
function search_by_tag_path($tag)
{
    $binet_prefix = isset($_GET["prefix"]) && $_GET["prefix"] == "binet" ? binet_prefix(binet, term) : "";
    $query_array = is_selected_tag($tag, $GLOBALS["query_array"]) ? query_array_unselecting_tag($tag, $GLOBALS["query_array"]) : query_array_selecting_tag($tag, $GLOBALS["query_array"]);
    set_if_exists($id, $_GET[$_GET["controller"]]);
    set_if_not_set($id, "");
    return path($_GET["action"], $_GET["controller"], $id, $binet_prefix, $query_array);
}
Ejemplo n.º 3
0
function form_group_textarea($label, $field, $prefill_value, $form_name, $html_decoration = array())
{
    set_if_not_set($html_decoration["class"], "");
    $html_decoration["class"] .= " form-control";
    $html_decoration_string = "";
    foreach ($html_decoration as $property => $value) {
        $html_decoration_string .= " " . $property . "=\"" . $value . "\"";
    }
    return form_group($label, $field, "<textarea " . $html_decoration_string . " id=\"" . $field . "\" name=\"" . $field . "\">" . $prefill_value . "</textarea>", $form_name);
}
Ejemplo n.º 4
0
function write_controller_rules($hash)
{
    set_if_not_set($hash["except"], array());
    set_if_not_set($hash["binet_prefix"], false);
    set_if_not_set($hash["action_on_collection"], array());
    set_if_not_set($hash["action_on_member"], array());
    set_if_not_set($hash["root"], "index");
    $collection_actions = array_merge(array_diff(array("index", "new", "create"), $hash["except"]), $hash["action_on_collection"]);
    $member_actions = array_merge(array_diff(array("show", "edit", "update", "delete"), $hash["except"]), $hash["action_on_member"]);
    if (!in_array("index", $hash["except"])) {
        write_path_rule(path("", $hash["controller"], "", $hash["binet_prefix"] ? "binet/([" . allowed_clean_string_characters() . "]+)/([0-9]+)" : ""), true_path($hash["root"], $hash["controller"], "", $hash["binet_prefix"] ? "binet/\$1/\$2" : ""));
    }
    foreach ($collection_actions as $action) {
        write_path_rule(path($action, $hash["controller"], "", $hash["binet_prefix"] ? "binet/([" . allowed_clean_string_characters() . "]+)/([0-9]+)" : ""), true_path($action, $hash["controller"], "", $hash["binet_prefix"] ? "binet/\$1/\$2" : ""));
    }
    foreach ($member_actions as $action) {
        write_path_rule(path($action, $hash["controller"], "([0-9]+)", $hash["binet_prefix"] ? "binet/([" . allowed_clean_string_characters() . "]+)/([0-9]+)" : ""), true_path($action, $hash["controller"], "\$" . ($hash["binet_prefix"] ? "3" : "1"), $hash["binet_prefix"] ? "binet/\$1/\$2" : ""));
    }
}
Ejemplo n.º 5
0
     foreach ($_POST["known_cards"] as $card) {
         add_card_owner_status($card, $_POST["identity"], owned);
     }
     foreach (select_suspects() as $player) {
         if (select_cards_player($player["id"]) == 0) {
             foreach (select_cards() as $card) {
                 add_card_owner_status($card["id"], $player["id"], not_owned);
             }
         }
     }
     $game["id"] = game;
     redirect_to_action("show");
     break;
 case "turn":
     define("turn", create_turn($_POST));
     set_if_not_set($_POST["witness"], get_current_player());
     foreach (players_between(get_current_player(), $_POST["witness"]) as $player) {
         add_card_owner_status($_POST["weapon"], $player, not_owned);
         add_card_owner_status($_POST["room"], $player, not_owned);
         add_card_owner_status($_POST["suspect"], $player, not_owned);
     }
     if (!is_empty($_POST["evidence"])) {
         switch ($_POST["evidence"]) {
             case room:
                 add_card_owner_status($_POST["room"], $_POST["witness"], owned);
                 break;
             case weapon:
                 add_card_owner_status($_POST["weapon"], $_POST["witness"], owned);
                 break;
             case suspect:
                 add_card_owner_status($_POST["suspect"], $_POST["witness"], owned);
Ejemplo n.º 6
0
function create_name_field($human_name, $properties = array())
{
    set_if_not_set($properties["max"], MAX_NAME_LENGTH);
    return create_form_field("name", $human_name, $properties);
}
Ejemplo n.º 7
0
function get_current_player()
{
    set_if_exists($current_player, $_SESSION["current_player"]);
    set_if_not_set($current_player, select_players()[0]["id"]);
    return $current_player;
}
Ejemplo n.º 8
0
function select_turns($criteria = array(), $order_by = "", $ascending = true)
{
    set_if_not_set($criteria["game"], game);
    return select_entries("turn", array("id", "player", "room", "weapon", "suspect", "witness", "evidence", "game"), array(), array(), $criteria, $order_by, $ascending);
}