Beispiel #1
0
function award_lib_decorate_tribe($db_game, $tag, $awardIDs)
{
    if (sizeof($awardIDs)) {
        $awards = award_lib_get_awards($db_game, $awardIDs);
        if ($awards === false) {
            return false;
        }
        $tags = array();
        foreach ($awards as $award) {
            $tags[] = $award['tag'];
        }
        $tags = implode("|", $tags);
    } else {
        $tags = "";
    }
    $sql = "UPDATE Tribe SET awards = '{$tags}' WHERE tag = '{$tag}' LIMIT 1";
    $result = $db_game->query($sql);
    return $result != FALSE;
}
Beispiel #2
0
function Module_Awards_decorate_tribe()
{
    global $db_game, $params;
    // init msgs
    $msgs = array();
    // open template
    $template = tmpl_open("modules/Module_Awards/templates/decorate_tribe.ihtml");
    // get all awards
    $awards = award_lib_get_awards($db_game);
    // there are awards; continue
    if (sizeof($awards)) {
        // *** tribe chosen ***
        if (isset($params->decorate_choose)) {
            // ERROR: tag is empty
            if (empty($params->decorateTribe)) {
                $msgs[] = "A tribe's tag must be filled in!";
                // tag is properly filled
            } else {
                // get tribe
                $tribe = getTribeByTag($db_game, $params->decorateTribe);
                if (!sizeof($tribe)) {
                    $msgs[] = "No such tribe: '{$params->decorateTribe}'!";
                } else {
                    // get awards
                    $p_awards = $tribe['awards'];
                    // create array from packed awards field of that tribe
                    if (!empty($p_awards)) {
                        $p_awards = explode('|', $p_awards);
                    } else {
                        $p_awards = array();
                    }
                    $p_awards = array_unique($p_awards);
                    $p_awards = array_filter($p_awards, create_function('$tag', 'return ereg("^[0-9a-zA-Z]+$", $tag);'));
                    foreach ($awards as $award) {
                        if (in_array($award['tag'], $p_awards)) {
                            $award['CHOSEN'] = array('dummy' => "");
                        }
                        tmpl_iterate($template, "/FORM_DECORATE/AWARD");
                        tmpl_set($template, "/FORM_DECORATE/AWARD", $award);
                    }
                    tmpl_set($template, "/FORM_DECORATE", $tribe);
                }
            }
            // *** decorate tribe ***
        } else {
            if (isset($params->decorator)) {
                // get tag
                $tag = $params->decorateTribe;
                // ERROR: Could not decorate Tribe.
                if (!award_lib_decorate_tribe($db_game, $tag, $params->decorateAward)) {
                    $msgs[] = "Error while decorating '{$tag}'!";
                    // tribe decorated
                } else {
                    $msgs[] = "'{$tag}' decorated!";
                    // get tribe
                    $tribe = getTribeByTag($db_game, $tag);
                    // ERROR: no such tribe
                    if (!sizeof($tribe)) {
                        $msgs[] = "No such tribe: '{$tag}'!";
                        // show awards
                    } else {
                        // get awards
                        $p_awards = $tribe['awards'];
                        // create array from packed awards field of that tribe
                        if (!empty($p_awards)) {
                            $p_awards = explode('|', $p_awards);
                        } else {
                            $p_awards = array();
                        }
                        $p_awards = array_unique($p_awards);
                        $p_awards = array_filter($p_awards, create_function('$tag', 'return ereg("^[0-9a-zA-Z]+$", $tag);'));
                        foreach ($awards as $award) {
                            if (in_array($award['tag'], $p_awards)) {
                                $award['CHOSEN'] = array('dummy' => "");
                            }
                            tmpl_iterate($template, "/FORM_DECORATE/AWARD");
                            tmpl_set($template, "/FORM_DECORATE/AWARD", $award);
                        }
                        tmpl_set($template, "/FORM_DECORATE", $tribe);
                    }
                }
            }
        }
        // *** insert tribe's tag ***
        tmpl_set($template, "/FORM_CHOOSE/tag", $params->decorateTribe);
        // no awards yet
    } else {
        $msgs[] = "There are no awards.. Create at least one first...";
    }
    // show messages
    if (sizeof($msgs)) {
        foreach ($msgs as $msg) {
            tmpl_iterate($template, "MESSAGE");
            tmpl_set($template, "MESSAGE/message", $msg);
        }
    }
    return tmpl_parse($template);
}